88struct confd confd ;
99
1010
11- int core_startup_save (sr_session_ctx_t * session , uint32_t sub_id , const char * module ,
12- const char * xpath , sr_event_t event , unsigned request_id , void * priv )
11+ static int startup_save (sr_session_ctx_t * session , uint32_t sub_id , const char * model ,
12+ const char * xpath , sr_event_t event , unsigned request_id , void * priv )
1313{
14- sr_event_t last_event = -1 ;
15- static unsigned int last_request = -1 ;
16- if (last_event == event && last_request == request_id )
17- return SR_ERR_OK ;
18- last_event = event ;
19- last_request = request_id ;
20-
2114 /* skip in bootstrap, triggered by load script to initialize startup datastore */
2215 if (systemf ("runlevel >/dev/null 2>&1" ))
2316 return SR_ERR_OK ;
@@ -33,9 +26,10 @@ static confd_dependency_t add_dependencies(struct lyd_node **diff, const char *x
3326 struct lyd_node * new_node = NULL ;
3427 struct lyd_node * target = NULL ;
3528 struct lyd_node * root = NULL ;
36- int rc ;
3729
3830 if (!lydx_get_xpathf (* diff , "%s" , xpath )) {
31+ int rc ;
32+
3933 /* Create the path, potentially creating a new tree */
4034 rc = lyd_new_path (NULL , LYD_CTX (* diff ), xpath , value , LYD_NEW_PATH_UPDATE , & new_node );
4135 if (rc != LY_SUCCESS || !new_node ) {
@@ -147,7 +141,7 @@ static confd_dependency_t handle_dependencies(struct lyd_node **diff, struct lyd
147141 return result ;
148142}
149143
150- static int change_cb (sr_session_ctx_t * session , uint32_t sub_id , const char * module_name ,
144+ static int change_cb (sr_session_ctx_t * session , uint32_t sub_id , const char * model_name ,
151145 const char * xpath , sr_event_t event , uint32_t request_id , void * _confd )
152146{
153147 struct lyd_node * diff = NULL , * config = NULL ;
@@ -258,16 +252,20 @@ static int change_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *mod
258252
259253 AUDIT ("The new configuration has been applied." );
260254 }
255+
261256free_diff :
262- lyd_free_tree (diff );
263- return rc ;
257+ lyd_free_tree (diff );
258+ return rc ;
264259}
265260
266- static inline int subscribe_module (char * model , struct confd * confd , int flags ) {
267- return sr_module_change_subscribe (confd -> session , model , "//." , change_cb , confd ,
268- CB_PRIO_PRIMARY , SR_SUBSCR_CHANGE_ALL_MODULES | SR_SUBSCR_DEFAULT | flags , & confd -> sub ) &&
269- sr_module_change_subscribe (confd -> startup , model , "//." , core_startup_save , NULL ,
270- CB_PRIO_PASSIVE , SR_SUBSCR_PASSIVE | SR_SUBSCR_CHANGE_ALL_MODULES , & confd -> sub );
261+ static inline int subscribe_model (char * model , struct confd * confd , int flags )
262+ {
263+ return sr_module_change_subscribe (confd -> session , model , "//." , change_cb , confd ,
264+ CB_PRIO_PRIMARY , SR_SUBSCR_CHANGE_ALL_MODULES |
265+ SR_SUBSCR_DEFAULT | flags , & confd -> sub ) ||
266+ sr_module_change_subscribe (confd -> startup , model , "//." , startup_save , NULL ,
267+ CB_PRIO_PASSIVE , SR_SUBSCR_CHANGE_ALL_MODULES |
268+ SR_SUBSCR_PASSIVE , & confd -> sub );
271269}
272270
273271int sr_plugin_init_cb (sr_session_ctx_t * session , void * * priv )
@@ -295,7 +293,7 @@ int sr_plugin_init_cb(sr_session_ctx_t *session, void **priv)
295293 if (!confd .conn )
296294 goto err ;
297295
298- /* The startup datastore is used for the core_startup_save () hook */
296+ /* The startup datastore is used for the startup_save () hook */
299297 rc = sr_session_start (confd .conn , SR_DS_STARTUP , & confd .startup );
300298 if (rc )
301299 goto err ;
@@ -314,69 +312,69 @@ int sr_plugin_init_cb(sr_session_ctx_t *session, void **priv)
314312 */
315313 confd .ifquirks = json_load_file ("/etc/product/interface-quirks.json" , 0 , NULL );
316314
317- rc = subscribe_module ("ietf-interfaces" , & confd , 0 );
315+ rc = subscribe_model ("ietf-interfaces" , & confd , 0 );
318316 if (rc ) {
319317 ERROR ("Failed to subscribe to ietf-interfaces" );
320318 goto err ;
321319 }
322- rc = subscribe_module ("ietf-netconf-acm" , & confd , 0 );
320+ rc = subscribe_model ("ietf-netconf-acm" , & confd , 0 );
323321 if (rc ) {
324322 ERROR ("Failed to subscribe to ietf-netconf-acm" );
325323 goto err ;
326324 }
327- rc = subscribe_module ("infix-dhcp-client" , & confd , 0 );
325+ rc = subscribe_model ("infix-dhcp-client" , & confd , 0 );
328326 if (rc ) {
329327 ERROR ("Failed to subscribe to infix-dhcp-client" );
330328 goto err ;
331329 }
332- rc = subscribe_module ("ietf-keystore" , & confd , SR_SUBSCR_UPDATE );
330+ rc = subscribe_model ("ietf-keystore" , & confd , SR_SUBSCR_UPDATE );
333331 if (rc ) {
334332 ERROR ("Failed to subscribe to ietf-keystore" );
335333 goto err ;
336334 }
337- rc = subscribe_module ("infix-services" , & confd , 0 );
335+ rc = subscribe_model ("infix-services" , & confd , 0 );
338336 if (rc ) {
339337 ERROR ("Failed to subscribe to infix-services" );
340338 goto err ;
341339 }
342- rc = subscribe_module ("ietf-system" , & confd , 0 );
340+ rc = subscribe_model ("ietf-system" , & confd , 0 );
343341 if (rc ) {
344342 ERROR ("Failed to subscribe to ietf-system" );
345343 goto err ;
346344 }
347- rc = subscribe_module ("ieee802-dot1ab-lldp" , & confd , 0 );
345+ rc = subscribe_model ("ieee802-dot1ab-lldp" , & confd , 0 );
348346 if (rc ) {
349347 ERROR ("Failed to subscribe to ieee802-dot1ab-lldp" );
350348 goto err ;
351349 }
352350#ifdef CONTAINERS
353- rc = subscribe_module ("infix-containers" , & confd , 0 );
351+ rc = subscribe_model ("infix-containers" , & confd , 0 );
354352 if (rc ) {
355353 ERROR ("Failed to subscribe to infix-containers" );
356354 goto err ;
357355 }
358356#endif
359- rc = subscribe_module ("infix-dhcp-server" , & confd , 0 );
357+ rc = subscribe_model ("infix-dhcp-server" , & confd , 0 );
360358 if (rc ) {
361359 ERROR ("Failed to subscribe to infix-dhcp-server" );
362360 goto err ;
363361 }
364- rc = subscribe_module ("ietf-routing" , & confd , 0 );
362+ rc = subscribe_model ("ietf-routing" , & confd , 0 );
365363 if (rc ) {
366364 ERROR ("Failed to subscribe to ietf-routing" );
367365 goto err ;
368366 }
369- rc = subscribe_module ("ietf-hardware" , & confd , 0 );
367+ rc = subscribe_model ("ietf-hardware" , & confd , 0 );
370368 if (rc ) {
371369 ERROR ("Failed to subscribe to ietf-hardware" );
372370 goto err ;
373371 }
374- rc = subscribe_module ("infix-firewall" , & confd , 0 );
372+ rc = subscribe_model ("infix-firewall" , & confd , 0 );
375373 if (rc ) {
376374 ERROR ("Failed to subscribe to infix-firewall" );
377375 goto err ;
378376 }
379- rc = subscribe_module ("infix-meta" , & confd , SR_SUBSCR_UPDATE );
377+ rc = subscribe_model ("infix-meta" , & confd , SR_SUBSCR_UPDATE );
380378 if (rc ) {
381379 ERROR ("Failed to subscribe to infix-meta" );
382380 goto err ;
0 commit comments