@@ -76,19 +76,6 @@ int core_post_hook(sr_session_ctx_t *session, uint32_t sub_id, const char *modul
7676 return SR_ERR_SYS ;
7777 }
7878
79- /* skip reload in bootstrap, implicit reload in runlevel change */
80- if (systemf ("runlevel >/dev/null 2>&1" )) {
81- /* trigger any tasks waiting for confd to have applied *-config */
82- system ("initctl -nbq cond set bootstrap" );
83- return SR_ERR_OK ;
84- }
85-
86- if (systemf ("initctl -b reload" )) {
87- EMERG ("initctl reload: failed applying new configuration!" );
88- return SR_ERR_SYS ;
89- }
90-
91- AUDIT ("The new configuration has been applied." );
9279
9380 return SR_ERR_OK ;
9481}
@@ -215,40 +202,29 @@ static confd_dependency_t handle_dependencies(struct lyd_node **diff, struct lyd
215202static int change_cb (sr_session_ctx_t * session , uint32_t sub_id , const char * module_name ,
216203 const char * xpath , sr_event_t event , uint32_t request_id , void * _confd )
217204{
218- <<<<<<< HEAD
219- struct confd * confd = _confd ;
220- char * output = NULL ;
221- struct lyd_node * diff = NULL , * config = NULL ;
222- sr_data_t * cfg = NULL ;
223- confd_dependency_t result ;
224- int rc = SR_ERR_OK ;
225- static uint32_t last_id = 0 ;
226- static uint32_t last_event = -1 ;
205+ struct lyd_node * diff = NULL , * config = NULL ;
206+ static uint32_t last_event = -1 ;
207+ struct confd * confd = _confd ;
208+ static uint32_t last_id = 0 ;
209+ confd_dependency_t result ;
210+ sr_data_t * cfg = NULL ;
211+ int rc = SR_ERR_OK ;
227212 int max_dep = 10 ;
228213
229- if (request_id == last_id && last_event == event )
230- return SR_ERR_OK ;
231- last_id = request_id ;
232- last_event = event ;
233-
234- if (event == SR_EV_CHANGE || event == SR_EV_DONE ) {
235- rc = srx_get_diff (session , & diff );
236- if (rc != SR_ERR_OK ) {
237- ERROR ("Failed to get diff: %d" , rc );
238- return rc ;
239- }
240- rc = sr_get_data (session , "//." , 0 , 0 , 0 , & cfg );
241- if (rc || !cfg )
242- goto free_diff ;
243-
244- config = cfg -> tree ;
245- }
246- while ((result = handle_dependencies (& diff , config )) != CONFD_DEP_DONE ) {
247- if (result == CONFD_DEP_ERROR ) {
248- ERROR ("Failed to add dependencies" );
249- break ;
250- }
251- }
214+ if (request_id == last_id && last_event == event )
215+ return SR_ERR_OK ;
216+ last_id = request_id ;
217+ last_event = event ;
218+
219+ if (event == SR_EV_CHANGE || event == SR_EV_DONE ) {
220+ rc = srx_get_diff (session , & diff );
221+ if (rc != SR_ERR_OK ) {
222+ ERROR ("Failed to get diff: %d" , rc );
223+ return rc ;
224+ }
225+ rc = sr_get_data (session , "//." , 0 , 0 , 0 , & cfg );
226+ if (rc || !cfg )
227+ goto free_diff ;
252228
253229 config = cfg -> tree ;
254230 while ((result = handle_dependencies (& diff , config )) != CONFD_DEP_DONE ) {
@@ -271,46 +247,66 @@ static int change_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *mod
271247 }
272248#endif
273249 }
274- /* ietf-interfaces */
275- ietf_interfaces_change (session , config , diff , event , confd );
276250
277- /* infix-dhcp-client*/
278- infix_dhcp_client_change (session , config , diff , event , confd );
251+ /* ietf-interfaces */
252+ ietf_interfaces_change (session , config , diff , event , confd );
253+
254+ /* infix-dhcp-client*/
255+ infix_dhcp_client_change (session , config , diff , event , confd );
256+
257+ /* ietf-keystore */
258+ ietf_keystore_change (session , config , diff , event , confd );
279259
280- /* ietf-keystore */
281- ietf_keystore_change (session , config , diff , event , confd );
260+ /* infix-services */
261+ infix_services_change (session , config , diff , event , confd );
282262
283- /* infix-services */
284- infix_services_change (session , config , diff , event , confd );
263+ /* ietf-syslog */
264+ ietf_syslog_change (session , config , diff , event , confd );
285265
286- /* ietf-syslog */
287- ietf_syslog_change (session , config , diff , event , confd );
266+ /* ietf-system */
267+ ietf_system_change (session , config , diff , event , confd );
288268
289- /* ietf-system */
290- ietf_system_change (session , config , diff , event , confd );
269+ /* infix-containers */
270+ infix_containers_change (session , config , diff , event , confd );
291271
292- /* infix-containers */
293- infix_containers_change (session , config , diff , event , confd );
272+ /* ietf-hardware */
273+ ietf_hardware_change (session , config , diff , event , confd );
294274
295- /* ietf-hardware */
296- ietf_hardware_change (session , config , diff , event , confd );
275+ /* ietf-routing */
276+ ietf_routing_change (session , config , diff , event , confd );
297277
298- /* ietf-routing */
299- ietf_routing_change (session , config , diff , event , confd );
278+ /* infix-dhcp-server */
279+ infix_dhcp_server_change (session , config , diff , event , confd );
300280
301- /* infix-dhcp-server */
302- infix_dhcp_server_change (session , config , diff , event , confd );
281+ /* infix-firewall */
282+ infix_firewall_change (session , config , diff , event , confd );
303283
304- /* infix-firewall */
305- infix_firewall_change (session , config , diff , event , confd );
284+ if (cfg )
285+ sr_release_data (cfg );
286+
287+ if (event == SR_EV_DONE ) {
288+ /* skip reload in bootstrap, implicit reload in runlevel change */
289+ if (systemf ("runlevel >/dev/null 2>&1" )) {
290+ /* trigger any tasks waiting for confd to have applied *-config */
291+ system ("initctl -nbq cond set bootstrap" );
292+ return SR_ERR_OK ;
293+ }
306294
307- if (cfg )
308- sr_release_data (cfg );
295+ if (systemf ("initctl -b reload" )) {
296+ EMERG ("initctl reload: failed applying new configuration!" );
297+ return SR_ERR_SYS ;
298+ }
299+
300+ AUDIT ("The new configuration has been applied." );
301+ }
309302free_diff :
310303 lyd_free_tree (diff );
311304 return rc ;
312- }
305+ }
313306
307+ static int subscribe_module (char * model , struct confd * confd , int flags ) {
308+ return sr_module_change_subscribe (confd -> session , model , "//." , change_cb , confd , CB_PRIO_PRIMARY , SR_SUBSCR_CHANGE_ALL_MODULES | SR_SUBSCR_DEFAULT | flags , & confd -> sub );
309+ }
314310
315311int sr_plugin_init_cb (sr_session_ctx_t * session , void * * priv )
316312{
@@ -356,78 +352,120 @@ int sr_plugin_init_cb(sr_session_ctx_t *session, void **priv)
356352 */
357353 confd .ifquirks = json_load_file ("/etc/product/interface-quirks.json" , 0 , NULL );
358354
359- REGISTER_CHANGE (confd .session , "ietf-interfaces" , "//." ,
360- SR_SUBSCR_CHANGE_ALL_MODULES , change_cb , & confd , & confd .sub );
361- REGISTER_CHANGE (confd .session , "infix-dhcp-client" , "//." ,
362- SR_SUBSCR_CHANGE_ALL_MODULES , change_cb , & confd , & confd .sub );
363- REGISTER_CHANGE (confd .session , "ietf-keystore" , "//." ,
364- SR_SUBSCR_CHANGE_ALL_MODULES , change_cb , & confd , & confd .sub );
365- REGISTER_CHANGE (confd .session , "ietf-syslog" , "//." ,
366- SR_SUBSCR_CHANGE_ALL_MODULES , change_cb , & confd , & confd .sub );
367- REGISTER_CHANGE (confd .session , "infix-services" , "//." ,
368- SR_SUBSCR_CHANGE_ALL_MODULES , change_cb , & confd , & confd .sub );
369- REGISTER_CHANGE (confd .session , "ietf-system" , "//." ,
370- SR_SUBSCR_CHANGE_ALL_MODULES , change_cb , & confd , & confd .sub );
371- REGISTER_CHANGE (confd .session , "ieee802-dot1ab-lldp" , "//." ,
372- SR_SUBSCR_CHANGE_ALL_MODULES , change_cb , & confd , & confd .sub );
355+ rc = subscribe_module ("ietf-interfaces" , & confd , 0 );
356+ if (rc ) {
357+ ERROR ("Failed to subscribe to ietf-interfaces" );
358+ goto err ;
359+ }
360+ rc = subscribe_module ("ietf-netconf-acm" , & confd , 0 );
361+ if (rc ) {
362+ ERROR ("Failed to subscribe to ietf-netconf-acm" );
363+ goto err ;
364+ }
365+ rc = subscribe_module ("infix-dhcp-client" , & confd , 0 );
366+ if (rc ) {
367+ ERROR ("Failed to subscribe to infix-dhcp-client" );
368+ goto err ;
369+ }
370+ rc = subscribe_module ("ietf-keystore" , & confd , SR_SUBSCR_UPDATE );
371+ if (rc ) {
372+ ERROR ("Failed to subscribe to ietf-keystore" );
373+ goto err ;
374+ }
375+ rc = subscribe_module ("infix-services" , & confd , 0 );
376+ if (rc ) {
377+ ERROR ("Failed to subscribe to infix-services" );
378+ goto err ;
379+ }
380+ rc = subscribe_module ("ietf-system" , & confd , 0 );
381+ if (rc ) {
382+ ERROR ("Failed to subscribe to ietf-system" );
383+ goto err ;
384+ }
385+ rc = subscribe_module ("ieee802-dot1ab-lldp" , & confd , 0 );
386+ if (rc ) {
387+ ERROR ("Failed to subscribe to ieee802-dot1ab-lldp" );
388+ goto err ;
389+ }
373390#ifdef CONTAINERS
374- REGISTER_CHANGE (confd .session , "infix-containers" , "//." ,
375- SR_SUBSCR_CHANGE_ALL_MODULES , change_cb , & confd , & confd .sub );
391+ rc = subscribe_module ("infix-containers" , & confd , 0 );
392+ if (rc ) {
393+ ERROR ("Failed to subscribe to infix-containers" );
394+ goto err ;
395+ }
376396#endif
377- REGISTER_CHANGE (confd .session , "infix-dhcp-server" , "//." ,
378- SR_SUBSCR_CHANGE_ALL_MODULES , change_cb , & confd , & confd .sub );
379-
380- REGISTER_CHANGE (confd .session , "ietf-routing" , "//." ,
381- SR_SUBSCR_CHANGE_ALL_MODULES , change_cb , & confd , & confd .sub );
382-
383- REGISTER_CHANGE (confd .session , "ietf-hardware" , "//." ,
384- SR_SUBSCR_CHANGE_ALL_MODULES , change_cb , & confd , & confd .sub );
385- REGISTER_CHANGE (confd .session , "infix-firewall" , "//." ,
386- SR_SUBSCR_CHANGE_ALL_MODULES , change_cb , & confd , & confd .sub );
397+ rc = subscribe_module ("infix-dhcp-server" , & confd , 0 );
398+ if (rc ) {
399+ ERROR ("Failed to subscribe to infix-dhcp-server" );
400+ goto err ;
401+ }
402+ rc = subscribe_module ("ietf-routing" , & confd , 0 );
403+ if (rc ) {
404+ ERROR ("Failed to subscribe to ietf-routing" );
405+ goto err ;
406+ }
407+ rc = subscribe_module ("ietf-hardware" , & confd , 0 );
408+ if (rc ) {
409+ ERROR ("Failed to subscribe to ietf-hardware" );
410+ goto err ;
411+ }
412+ rc = subscribe_module ("infix-firewall" , & confd , 0 );
413+ if (rc ) {
414+ ERROR ("Failed to subscribe to infix-firewall" );
415+ goto err ;
416+ }
417+ rc = subscribe_module ("infix-meta" , & confd , SR_SUBSCR_UPDATE );
418+ if (rc ) {
419+ ERROR ("Failed to subscribe to infix-meta" );
420+ goto err ;
421+ }
387422
388- rc = ietf_keystore_update_init (& confd );
389- if (rc )
423+ rc = ietf_system_rpc_init (& confd );
424+ if (rc )
390425 goto err ;
391- rc = ietf_system_init (& confd );
426+ rc = infix_containers_rpc_init (& confd );
392427 if (rc )
393428 goto err ;
394- rc = infix_containers_init (& confd );
429+ rc = infix_dhcp_server_rpc_init (& confd );
395430 if (rc )
396431 goto err ;
397432
398- rc = infix_dhcp_server_init (& confd );
433+ rc = infix_factory_rpc_init (& confd );
399434 if (rc )
400435 goto err ;
401436
402- rc = infix_factory_init (& confd );
437+ rc = ietf_factory_default_rpc_init (& confd );
403438 if (rc )
404439 goto err ;
405440
406- rc = ietf_factory_default_init (& confd );
441+ rc = infix_firewall_rpc_init (& confd );
407442 if (rc )
408443 goto err ;
409444
410- rc = infix_meta_init (& confd );
445+ rc = infix_system_sw_rpc_init (& confd );
411446 if (rc )
412447 goto err ;
413448
414- rc = infix_system_sw_init (& confd );
449+ /* Candidate infer configurations */
450+ rc = ietf_hardware_candidate_init (& confd );
415451 if (rc )
416452 goto err ;
417453
418- rc = ietf_hardware_init (& confd );
454+ rc = infix_firewall_candidate_init (& confd );
419455 if (rc )
420456 goto err ;
421457
422- rc = infix_firewall_init (& confd );
458+ rc = infix_dhcp_server_candidate_init (& confd );
423459 if (rc )
424460 goto err ;
425461
462+ rc = infix_dhcp_client_candidate_init (& confd );
463+ if (rc )
464+ goto err ;
426465 /* YOUR_INIT GOES HERE */
427466
428467 return SR_ERR_OK ;
429468err :
430- fail :
431469 ERROR ("init failed: %s" , sr_strerror (rc ));
432470 if (confd .root )
433471 json_decref (confd .root );
0 commit comments