@@ -3801,6 +3801,175 @@ nc_server_config_parse_netconf_server(const struct lyd_node *node, NC_OPERATION
38013801 return 0 ;
38023802}
38033803
3804+ int
3805+ nc_server_config_ln2_netconf_server (const struct lyd_node * node , NC_OPERATION op )
3806+ {
3807+ (void ) node ;
3808+
3809+ assert ((op == NC_OP_CREATE ) || (op == NC_OP_DELETE ));
3810+
3811+ if (op == NC_OP_DELETE ) {
3812+
3813+ #ifdef NC_ENABLED_SSH_TLS
3814+ /* delete the intervals */
3815+ pthread_mutex_lock (& server_opts .cert_exp_notif_thread_lock );
3816+ free (server_opts .intervals );
3817+ server_opts .intervals = NULL ;
3818+ server_opts .interval_count = 0 ;
3819+ pthread_mutex_unlock (& server_opts .cert_exp_notif_thread_lock );
3820+ #endif /* NC_ENABLED_SSH_TLS */
3821+
3822+ }
3823+
3824+ return 0 ;
3825+ }
3826+
3827+ #ifdef NC_ENABLED_SSH_TLS
3828+
3829+ static int
3830+ nc_server_config_yang_value2cert_exp_time (const char * value , struct nc_cert_exp_time * cert_exp_time )
3831+ {
3832+ char unit ;
3833+ long val ;
3834+
3835+ unit = value [strlen (value ) - 1 ];
3836+ val = strtol (value , NULL , 10 );
3837+ switch (unit ) {
3838+ case 'm' :
3839+ cert_exp_time -> months = val ;
3840+ break ;
3841+ case 'w' :
3842+ cert_exp_time -> weeks = val ;
3843+ break ;
3844+ case 'd' :
3845+ cert_exp_time -> days = val ;
3846+ break ;
3847+ case 'h' :
3848+ cert_exp_time -> hours = val ;
3849+ break ;
3850+ default :
3851+ ERR (NULL , "Unexpected unit in the certificate expiration time \"%s\"." , value );
3852+ return 1 ;
3853+ }
3854+
3855+ return 0 ;
3856+ }
3857+
3858+ static int
3859+ nc_server_config_create_interval (const char * anchor , const char * period )
3860+ {
3861+ int ret = 0 ;
3862+ struct nc_cert_exp_time cert_exp_time = {0 };
3863+
3864+ server_opts .intervals = nc_realloc (server_opts .intervals , (server_opts .interval_count + 1 ) * sizeof * server_opts .intervals );
3865+ NC_CHECK_ERRMEM_RET (!server_opts .intervals , 1 );
3866+
3867+ ret = nc_server_config_yang_value2cert_exp_time (anchor , & cert_exp_time );
3868+ if (ret ) {
3869+ goto cleanup ;
3870+ }
3871+ memcpy (& server_opts .intervals [server_opts .interval_count ].anchor , & cert_exp_time , sizeof cert_exp_time );
3872+
3873+ ret = nc_server_config_yang_value2cert_exp_time (period , & cert_exp_time );
3874+ if (ret ) {
3875+ goto cleanup ;
3876+ }
3877+ memcpy (& server_opts .intervals [server_opts .interval_count ].period , & cert_exp_time , sizeof cert_exp_time );
3878+
3879+ ++ server_opts .interval_count ;
3880+
3881+ cleanup :
3882+ return ret ;
3883+ }
3884+
3885+ static void
3886+ nc_server_config_del_interval (const char * anchor , const char * period )
3887+ {
3888+ int i ;
3889+ struct nc_cert_exp_time anchor_time = {0 }, period_time = {0 };
3890+
3891+ if (nc_server_config_yang_value2cert_exp_time (anchor , & anchor_time )) {
3892+ return ;
3893+ }
3894+ if (nc_server_config_yang_value2cert_exp_time (period , & period_time )) {
3895+ return ;
3896+ }
3897+
3898+ for (i = 0 ; i < server_opts .interval_count ; ++ i ) {
3899+ if (!memcmp (& server_opts .intervals [i ].anchor , & anchor_time , sizeof anchor_time ) &&
3900+ !memcmp (& server_opts .intervals [i ].period , & period_time , sizeof period_time )) {
3901+ break ;
3902+ }
3903+ }
3904+ if (i == server_opts .interval_count ) {
3905+ ERR (NULL , "Interval \"%s %s\" not found." , anchor , period );
3906+ return ;
3907+ }
3908+
3909+ server_opts .interval_count -- ;
3910+ if (!server_opts .interval_count ) {
3911+ free (server_opts .intervals );
3912+ server_opts .intervals = NULL ;
3913+ } else if (i != server_opts .interval_count ) {
3914+ memcpy (& server_opts .intervals [i ], & server_opts .intervals [server_opts .interval_count ], sizeof * server_opts .intervals );
3915+ }
3916+ }
3917+
3918+ static int
3919+ nc_server_config_interval (const struct lyd_node * node , NC_OPERATION op )
3920+ {
3921+ int ret = 0 ;
3922+ struct lyd_node * anchor , * period ;
3923+
3924+ assert (!strcmp (LYD_NAME (node ), "interval" ));
3925+
3926+ anchor = lyd_child (node );
3927+ assert (anchor );
3928+ period = anchor -> next ;
3929+ assert (period );
3930+
3931+ /* LOCK */
3932+ pthread_mutex_lock (& server_opts .cert_exp_notif_thread_lock );
3933+
3934+ if ((op == NC_OP_CREATE ) || (op == NC_OP_REPLACE )) {
3935+ ret = nc_server_config_create_interval (lyd_get_value (anchor ), lyd_get_value (period ));
3936+ if (ret ) {
3937+ goto cleanup ;
3938+ }
3939+ } else {
3940+ nc_server_config_del_interval (lyd_get_value (anchor ), lyd_get_value (period ));
3941+ }
3942+
3943+ cleanup :
3944+ pthread_mutex_unlock (& server_opts .cert_exp_notif_thread_lock );
3945+ return ret ;
3946+ }
3947+
3948+ #endif /* NC_ENABLED_SSH_TLS */
3949+
3950+ static int
3951+ nc_server_config_parse_libnetconf2_netconf_server (const struct lyd_node * node , NC_OPERATION op )
3952+ {
3953+ const char * name = LYD_NAME (node );
3954+ int ret = 0 ;
3955+
3956+ if (!strcmp (name , "ln2-netconf-server" )) {
3957+ ret = nc_server_config_ln2_netconf_server (node , op );
3958+ }
3959+ #ifdef NC_ENABLED_SSH_TLS
3960+ else if (!strcmp (name , "interval ")) {
3961+ ret = nc_server_config_interval (node , op );
3962+ }
3963+ #endif /* NC_ENABLED_SSH_TLS */
3964+
3965+ if (ret ) {
3966+ ERR (NULL , "Configuring node \"%s\" failed." , LYD_NAME (node ));
3967+ return 1 ;
3968+ }
3969+
3970+ return 0 ;
3971+ }
3972+
38043973int
38053974nc_server_config_parse_tree (const struct lyd_node * node , NC_OPERATION parent_op , NC_MODULE module )
38063975{
@@ -3847,8 +4016,13 @@ nc_server_config_parse_tree(const struct lyd_node *node, NC_OPERATION parent_op,
38474016 ret = nc_server_config_parse_truststore (node , current_op );
38484017 } else
38494018#endif /* NC_ENABLED_SSH_TLS */
3850- {
4019+ if (module == NC_MODULE_LIBNETCONF2_NETCONF_SERVER ) {
4020+ ret = nc_server_config_parse_libnetconf2_netconf_server (node , current_op );
4021+ } else if (module == NC_MODULE_NETCONF_SERVER ) {
38514022 ret = nc_server_config_parse_netconf_server (node , current_op );
4023+ } else {
4024+ ERRINT ;
4025+ ret = 1 ;
38524026 }
38534027 if (ret ) {
38544028 return ret ;
@@ -3994,6 +4168,34 @@ nc_server_config_fill_netconf_server(const struct lyd_node *data, NC_OPERATION o
39944168 return ret ;
39954169}
39964170
4171+ static int
4172+ nc_server_config_fill_libnetconf2_netconf_server (const struct lyd_node * data , NC_OPERATION op )
4173+ {
4174+ int ret = 0 ;
4175+ struct lyd_node * tree ;
4176+ uint32_t log_options = 0 ;
4177+
4178+ /* silently search for ln2-netconf-server, it may not be present */
4179+ ly_temp_log_options (& log_options );
4180+
4181+ ret = lyd_find_path (data , "/libnetconf2-netconf-server:ln2-netconf-server" , 0 , & tree );
4182+ if (ret || (tree -> flags & LYD_DEFAULT )) {
4183+ /* not found */
4184+ ret = 0 ;
4185+ goto cleanup ;
4186+ }
4187+
4188+ if (nc_server_config_parse_tree (tree , op , NC_MODULE_LIBNETCONF2_NETCONF_SERVER )) {
4189+ ret = 1 ;
4190+ goto cleanup ;
4191+ }
4192+
4193+ cleanup :
4194+ /* reset the logging options back to what they were */
4195+ ly_temp_log_options (NULL );
4196+ return ret ;
4197+ }
4198+
39974199API int
39984200nc_server_config_setup_diff (const struct lyd_node * data )
39994201{
@@ -4008,25 +4210,41 @@ nc_server_config_setup_diff(const struct lyd_node *data)
40084210 /* configure keystore */
40094211 ret = nc_server_config_fill_keystore (data , NC_OP_UNKNOWN );
40104212 if (ret ) {
4011- ERR (NULL , "Filling keystore failed." );
4213+ ERR (NULL , "Applying ietf- keystore configuration failed." );
40124214 goto cleanup ;
40134215 }
40144216
40154217 /* configure truststore */
40164218 ret = nc_server_config_fill_truststore (data , NC_OP_UNKNOWN );
40174219 if (ret ) {
4018- ERR (NULL , "Filling truststore failed." );
4220+ ERR (NULL , "Applying ietf- truststore configuration failed." );
40194221 goto cleanup ;
40204222 }
40214223#endif /* NC_ENABLED_SSH_TLS */
40224224
40234225 /* configure netconf-server */
40244226 ret = nc_server_config_fill_netconf_server (data , NC_OP_UNKNOWN );
40254227 if (ret ) {
4026- ERR (NULL , "Filling netconf-server failed." );
4228+ ERR (NULL , "Applying ietf- netconf-server configuration failed." );
40274229 goto cleanup ;
40284230 }
40294231
4232+ /* configure libnetconf2-netconf-server */
4233+ ret = nc_server_config_fill_libnetconf2_netconf_server (data , NC_OP_UNKNOWN );
4234+ if (ret ) {
4235+ ERR (NULL , "Applying libnetconf2-netconf-server configuration failed." );
4236+ goto cleanup ;
4237+ }
4238+
4239+ #ifdef NC_ENABLED_SSH_TLS
4240+ /* wake up the cert expiration notif thread if it's running */
4241+ pthread_mutex_lock (& server_opts .cert_exp_notif_thread_lock );
4242+ if (server_opts .cert_exp_notif_thread_running ) {
4243+ pthread_cond_signal (& server_opts .cert_exp_notif_thread_cond );
4244+ }
4245+ pthread_mutex_unlock (& server_opts .cert_exp_notif_thread_lock );
4246+ #endif /* NC_ENABLED_SSH_TLS */
4247+
40304248cleanup :
40314249 /* UNLOCK */
40324250 pthread_rwlock_unlock (& server_opts .config_lock );
@@ -4073,25 +4291,41 @@ nc_server_config_setup_data(const struct lyd_node *data)
40734291 /* configure keystore */
40744292 ret = nc_server_config_fill_keystore (data , NC_OP_CREATE );
40754293 if (ret ) {
4076- ERR (NULL , "Filling keystore failed." );
4294+ ERR (NULL , "Applying ietf- keystore configuration failed." );
40774295 goto cleanup ;
40784296 }
40794297
40804298 /* configure truststore */
40814299 ret = nc_server_config_fill_truststore (data , NC_OP_CREATE );
40824300 if (ret ) {
4083- ERR (NULL , "Filling truststore failed." );
4301+ ERR (NULL , "Applying ietf- truststore configuration failed." );
40844302 goto cleanup ;
40854303 }
40864304#endif /* NC_ENABLED_SSH_TLS */
40874305
40884306 /* configure netconf-server */
40894307 ret = nc_server_config_fill_netconf_server (data , NC_OP_CREATE );
40904308 if (ret ) {
4091- ERR (NULL , "Filling netconf-server failed." );
4309+ ERR (NULL , "Applying ietf-netconf-server configuration failed." );
4310+ goto cleanup ;
4311+ }
4312+
4313+ /* configure libnetconf2-netconf-server */
4314+ ret = nc_server_config_fill_libnetconf2_netconf_server (data , NC_OP_CREATE );
4315+ if (ret ) {
4316+ ERR (NULL , "Applying libnetconf2-netconf-server configuration failed." );
40924317 goto cleanup ;
40934318 }
40944319
4320+ #ifdef NC_ENABLED_SSH_TLS
4321+ /* wake up the cert expiration notif thread if it's running */
4322+ pthread_mutex_lock (& server_opts .cert_exp_notif_thread_lock );
4323+ if (server_opts .cert_exp_notif_thread_running ) {
4324+ pthread_cond_signal (& server_opts .cert_exp_notif_thread_cond );
4325+ }
4326+ pthread_mutex_unlock (& server_opts .cert_exp_notif_thread_lock );
4327+ #endif /* NC_ENABLED_SSH_TLS */
4328+
40954329cleanup :
40964330 /* UNLOCK */
40974331 pthread_rwlock_unlock (& server_opts .config_lock );
0 commit comments