From 722e430fd5b07b8f5746295339b64562107abf50 Mon Sep 17 00:00:00 2001 From: Ruslan Babayev Date: Mon, 11 Oct 2021 19:43:52 -0700 Subject: [PATCH 1/8] lib: confd: fix compilation broken with libyang2 Fixes the following compilation errors: In file included from /home/ruslan/sdk/sysroots/corei7-64-poky-linux/usr/include/libyang/tree_data.h:30, from /home/ruslan/sdk/sysroots/corei7-64-poky-linux/usr/include/libyang/context.h:22, from /home/ruslan/sdk/sysroots/corei7-64-poky-linux/usr/include/libyang/libyang.h:24, from ../../src/frr/lib/yang.h:25, from ../../src/frr/lib/northbound.h:27, from ../../src/frr/lib/vty.h:36, from ../../src/frr/lib/ferr.h:28, from ../../src/frr/lib/lib_errors.h:24, from ../../src/frr/lib/northbound_confd.c:23: ../../src/frr/lib/northbound_confd.c: In function 'frr_confd_init_cdb': ../../src/frr/lib/northbound_confd.c:533:28: error: 'const struct lys_module' has no member named 'data' 533 | LY_LIST_FOR (module->info->data, snode) { | ^~ ../../src/frr/lib/northbound_confd.c: In function 'frr_confd_data_get_next_object': ../../src/frr/lib/northbound_confd.c:921:3: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 921 | LY_LIST_FOR (lysc_node_child(nb_node->snode), child) { | ^~~~~~~~~~~ Signed-off-by: Ruslan Babayev --- lib/northbound_confd.c | 83 ++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/lib/northbound_confd.c b/lib/northbound_confd.c index e62a83cee2..0d8f348288 100644 --- a/lib/northbound_confd.c +++ b/lib/northbound_confd.c @@ -491,6 +491,47 @@ static void *thread_cdb_trigger_subscriptions(void *data) return NULL; } +static int frr_confd_subscribe(const struct lysc_node *snode, void *arg) +{ + struct yang_module *module = arg; + struct nb_node *nb_node; + int *spoint; + int ret; + + switch (snode->nodetype) { + case LYS_CONTAINER: + case LYS_LEAF: + case LYS_LEAFLIST: + case LYS_LIST: + break; + default: + return YANG_ITER_CONTINUE; + } + + if (CHECK_FLAG(snode->flags, LYS_CONFIG_R)) + return YANG_ITER_CONTINUE; + + nb_node = snode->priv; + if (!nb_node) + return YANG_ITER_CONTINUE; + + DEBUGD(&nb_dbg_client_confd, "%s: subscribing to '%s'", __func__, + nb_node->xpath); + + spoint = XMALLOC(MTYPE_CONFD, sizeof(*spoint)); + ret = cdb_subscribe2(cdb_sub_sock, CDB_SUB_RUNNING_TWOPHASE, + CDB_SUB_WANT_ABORT_ON_ABORT, 3, spoint, + module->confd_hash, nb_node->xpath); + if (ret != CONFD_OK) { + flog_err_confd("cdb_subscribe2"); + XFREE(MTYPE_CONFD, spoint); + return YANG_ITER_CONTINUE; + } + + listnode_add(confd_spoints, spoint); + return YANG_ITER_CONTINUE; +} + static int frr_confd_init_cdb(void) { struct yang_module *module; @@ -514,8 +555,6 @@ static int frr_confd_init_cdb(void) /* Subscribe to all loaded YANG data modules. */ confd_spoints = list_new(); RB_FOREACH (module, yang_modules, &yang_modules) { - struct lysc_node *snode; - module->confd_hash = confd_str2hash(module->info->ns); if (module->confd_hash == 0) { flog_err( @@ -530,42 +569,8 @@ static int frr_confd_init_cdb(void) * entire YANG module. So we have to find the top level * nodes ourselves and subscribe to their paths. */ - LY_LIST_FOR (module->info->data, snode) { - struct nb_node *nb_node; - int *spoint; - int ret; - - switch (snode->nodetype) { - case LYS_CONTAINER: - case LYS_LEAF: - case LYS_LEAFLIST: - case LYS_LIST: - break; - default: - continue; - } - - if (CHECK_FLAG(snode->flags, LYS_CONFIG_R)) - continue; - - nb_node = snode->priv; - if (!nb_node) - continue; - - DEBUGD(&nb_dbg_client_confd, "%s: subscribing to '%s'", - __func__, nb_node->xpath); - - spoint = XMALLOC(MTYPE_CONFD, sizeof(*spoint)); - ret = cdb_subscribe2( - cdb_sub_sock, CDB_SUB_RUNNING_TWOPHASE, - CDB_SUB_WANT_ABORT_ON_ABORT, 3, spoint, - module->confd_hash, nb_node->xpath); - if (ret != CONFD_OK) { - flog_err_confd("cdb_subscribe2"); - XFREE(MTYPE_CONFD, spoint); - } - listnode_add(confd_spoints, spoint); - } + yang_snodes_iterate(module->info, frr_confd_subscribe, 0, + module); } if (cdb_subscribe_done(cdb_sub_sock) != CONFD_OK) { @@ -868,7 +873,7 @@ static int frr_confd_data_get_next_object(struct confd_trans_ctx *tctx, memset(objects, 0, sizeof(objects)); for (int j = 0; j < CONFD_OBJECTS_PER_TIME; j++) { struct confd_next_object *object; - struct lysc_node *child; + const struct lysc_node *child; struct yang_data *data; size_t nvalues = 0; From 7f88892d96d56828e6fbf141a0482f48c3491451 Mon Sep 17 00:00:00 2001 From: Ruslan Babayev Date: Mon, 11 Oct 2021 20:16:21 -0700 Subject: [PATCH 2/8] lib: confd: fix non-void return-type warning Signed-off-by: Ruslan Babayev --- lib/northbound_confd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/northbound_confd.c b/lib/northbound_confd.c index 0d8f348288..d477062b74 100644 --- a/lib/northbound_confd.c +++ b/lib/northbound_confd.c @@ -1194,6 +1194,8 @@ static int frr_confd_dp_ctl_read(struct thread *thread) thread_add_read(master, frr_confd_dp_ctl_read, dctx, fd, &t_dp_ctl); frr_confd_dp_read(dctx, fd); + + return 0; } static int frr_confd_dp_worker_read(struct thread *thread) @@ -1204,6 +1206,8 @@ static int frr_confd_dp_worker_read(struct thread *thread) thread_add_read(master, frr_confd_dp_worker_read, dctx, fd, &t_dp_worker); frr_confd_dp_read(dctx, fd); + + return 0; } static int frr_confd_subscribe_state(const struct lysc_node *snode, void *arg) From fc3ebe1235821426f1456e85a50de577ab065590 Mon Sep 17 00:00:00 2001 From: Ruslan Babayev Date: Mon, 11 Oct 2021 19:57:25 -0700 Subject: [PATCH 3/8] lib: confd: fix format-truncation warnings Signed-off-by: Ruslan Babayev --- lib/northbound_confd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/northbound_confd.c b/lib/northbound_confd.c index d477062b74..e1c8983fca 100644 --- a/lib/northbound_confd.c +++ b/lib/northbound_confd.c @@ -710,7 +710,7 @@ static int frr_confd_data_get_next(struct confd_trans_ctx *tctx, confd_data_reply_next_key(tctx, v, keys.num, (long)nb_next); } else { - char pointer_str[16]; + char pointer_str[32]; /* * ConfD 6.6 user guide, chapter 6.11 (Operational data @@ -848,7 +848,7 @@ static int frr_confd_data_get_next_object(struct confd_trans_ctx *tctx, const void *nb_next; #define CONFD_OBJECTS_PER_TIME 100 struct confd_next_object objects[CONFD_OBJECTS_PER_TIME + 1]; - char pseudo_keys[CONFD_OBJECTS_PER_TIME][16]; + char pseudo_keys[CONFD_OBJECTS_PER_TIME][32]; int nobjects = 0; frr_confd_get_xpath(kp, xpath, sizeof(xpath)); From 688c536fb3bd933f27324b68dfc756a0cccc9269 Mon Sep 17 00:00:00 2001 From: Ruslan Babayev Date: Sun, 17 Oct 2021 22:03:46 -0700 Subject: [PATCH 4/8] yang: confd: compile yang modules to fxs Signed-off-by: Ruslan Babayev --- configure.ac | 1 + yang/subdir.am | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/configure.ac b/configure.ac index c5e5d64aa0..f223b07c1b 100644 --- a/configure.ac +++ b/configure.ac @@ -1883,6 +1883,7 @@ if test "$enable_confd" != "" -a "$enable_confd" != "no"; then if test "$CONFD" = "/bin/false"; then AC_MSG_ERROR([confd was not found on your system.])] fi + AC_CHECK_PROG([CONFDC], [confdc], [confdc], [/bin/false], "${enable_confd}/bin") CONFD_CFLAGS="-I${enable_confd}/include -L${enable_confd}/lib" AC_SUBST([CONFD_CFLAGS]) CONFD_LIBS="-lconfd" diff --git a/yang/subdir.am b/yang/subdir.am index a2243fb8e4..0f2bb00278 100644 --- a/yang/subdir.am +++ b/yang/subdir.am @@ -97,3 +97,29 @@ CLEANFILES += \ yang/ietf/*.c \ yang/confd/*.c \ # + +if CONFD + +SUBMODULES = $(shell cd $(top_srcdir); grep -l belongs-to $(dist_yangmodels_DATA)) +EXCLUDED_MODULES = $(SUBMODULES) yang/frr-module-translator.yang +YANG_MODULES = $(filter-out $(EXCLUDED_MODULES),$(dist_yangmodels_DATA)) + +fxsdir = $(sysconfdir)/confd +fxs_DATA = $(YANG_MODULES:.yang=.fxs) + +SUFFIXES += .fxs +CLEANFILES += $(fxs_DATA) + +AM_V_CONFDC = $(AM_V_CONFDC_@AM_V@) +AM_V_CONFDC_ = $(AM_V_CONFDC_@AM_DEFAULT_V@) +AM_V_CONFDC_0 = @echo " CONFDC " $@; + +CONFDC_FLAGS = --yangpath $(srcdir)/yang --yangpath $(srcdir)/yang/ietf + +yang/%.fxs: yang/%.yang yang/confd/confd.%.yang + $(AM_V_CONFDC)$(CONFDC) $(CONFDC_FLAGS) -c -o $@ -a $(srcdir)/yang/confd/confd.$*.yang -- $< + +yang/%.fxs: yang/%.yang + $(AM_V_CONFDC)$(CONFDC) $(CONFDC_FLAGS) -c -o $@ -- $< + +endif From 084dfdc03c379007630b6baddd02c7887df88d61 Mon Sep 17 00:00:00 2001 From: Ruslan Babayev Date: Sun, 17 Oct 2021 22:17:04 -0700 Subject: [PATCH 5/8] yang, ripd, ripngd: fix annotate statements Add missing annotate-statement for the 'instance' list. Signed-off-by: Ruslan Babayev --- yang/confd/confd.frr-ripd.yang | 6 ++++-- yang/confd/confd.frr-ripngd.yang | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/yang/confd/confd.frr-ripd.yang b/yang/confd/confd.frr-ripd.yang index 9b21c0756f..7bbe54cca9 100644 --- a/yang/confd/confd.frr-ripd.yang +++ b/yang/confd/confd.frr-ripd.yang @@ -11,8 +11,10 @@ module confd.frr-ripd { tailf:annotate-module "frr-ripd" { tailf:annotate-statement "container[name='ripd']" { - tailf:annotate-statement "container[name='state']" { - tailf:callpoint "state"; + tailf:annotate-statement "list[name='instance']" { + tailf:annotate-statement "container[name='state']" { + tailf:callpoint "state"; + } } } tailf:annotate-statement "rpc[name='clear-rip-route']" { diff --git a/yang/confd/confd.frr-ripngd.yang b/yang/confd/confd.frr-ripngd.yang index 5d876ff4d3..83383fb454 100644 --- a/yang/confd/confd.frr-ripngd.yang +++ b/yang/confd/confd.frr-ripngd.yang @@ -11,8 +11,10 @@ module confd.frr-ripngd { tailf:annotate-module "frr-ripngd" { tailf:annotate-statement "container[name='ripngd']" { - tailf:annotate-statement "container[name='state']" { - tailf:callpoint "state"; + tailf:annotate-statement "list[name='instance']" { + tailf:annotate-statement "container[name='state']" { + tailf:callpoint "state"; + } } } tailf:annotate-statement "rpc[name='clear-ripng-route']" { From 3f5af3d50be7ae17fbb35ca672bc5c47fbea4d69 Mon Sep 17 00:00:00 2001 From: Ruslan Babayev Date: Sun, 17 Oct 2021 22:19:34 -0700 Subject: [PATCH 6/8] yang, bgpd: add missing includes Signed-off-by: Ruslan Babayev --- yang/frr-bgp-bmp.yang | 2 ++ yang/frr-bgp-common-structure.yang | 2 ++ yang/frr-bgp-neighbor.yang | 4 ++++ yang/frr-bgp-peer-group.yang | 4 ++++ 4 files changed, 12 insertions(+) diff --git a/yang/frr-bgp-bmp.yang b/yang/frr-bgp-bmp.yang index 2417874ea0..cf945cabef 100644 --- a/yang/frr-bgp-bmp.yang +++ b/yang/frr-bgp-bmp.yang @@ -13,6 +13,8 @@ submodule frr-bgp-bmp { prefix frr-bt; } + include "frr-bgp-common-multiprotocol"; + organization "FRRouting"; contact diff --git a/yang/frr-bgp-common-structure.yang b/yang/frr-bgp-common-structure.yang index 2ad22a1435..3378c10c03 100644 --- a/yang/frr-bgp-common-structure.yang +++ b/yang/frr-bgp-common-structure.yang @@ -25,6 +25,8 @@ submodule frr-bgp-common-structure { prefix frr-bt; } + include "frr-bgp-common"; + organization "FRRouting"; contact diff --git a/yang/frr-bgp-neighbor.yang b/yang/frr-bgp-neighbor.yang index 03af643ba2..6d73580661 100644 --- a/yang/frr-bgp-neighbor.yang +++ b/yang/frr-bgp-neighbor.yang @@ -5,6 +5,10 @@ submodule frr-bgp-neighbor { prefix "bgp"; } + include "frr-bgp-common-multiprotocol"; + + include "frr-bgp-common-structure"; + organization "FRRouting"; contact diff --git a/yang/frr-bgp-peer-group.yang b/yang/frr-bgp-peer-group.yang index 80c9ecff2a..15c31bf010 100644 --- a/yang/frr-bgp-peer-group.yang +++ b/yang/frr-bgp-peer-group.yang @@ -13,6 +13,10 @@ submodule frr-bgp-peer-group { prefix frr-bt; } + include "frr-bgp-common-structure"; + + include "frr-bgp-neighbor"; + organization "FRRouting"; contact From 56fd4d34602a2da6fc9514df819e2f8e510d619f Mon Sep 17 00:00:00 2001 From: Ruslan Babayev Date: Sun, 17 Oct 2021 22:20:06 -0700 Subject: [PATCH 7/8] yang, ospfd: build frr-ospfd.yang when ospfd is enabled Signed-off-by: Ruslan Babayev --- yang/subdir.am | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/yang/subdir.am b/yang/subdir.am index 0f2bb00278..828ebd9086 100644 --- a/yang/subdir.am +++ b/yang/subdir.am @@ -88,6 +88,10 @@ dist_yangmodels_DATA += yang/frr-bgp-types.yang dist_yangmodels_DATA += yang/frr-bgp.yang endif +if OSPFD +dist_yangmodels_DATA += yang/frr-ospfd.yang +endif + if PATHD dist_yangmodels_DATA += yang/frr-pathd.yang endif From 99d0e85479df6c310e99e1ddb603aa3097ef31cb Mon Sep 17 00:00:00 2001 From: Ruslan Babayev Date: Mon, 1 Nov 2021 19:41:59 -0700 Subject: [PATCH 8/8] yang: fix frr-routing prefix Signed-off-by: Ruslan Babayev --- yang/frr-routing.yang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yang/frr-routing.yang b/yang/frr-routing.yang index f8441669af..6a721b2924 100644 --- a/yang/frr-routing.yang +++ b/yang/frr-routing.yang @@ -1,7 +1,7 @@ module frr-routing { yang-version "1.1"; namespace "http://frrouting.org/yang/routing"; - prefix "rt"; + prefix "frr-routing"; import ietf-yang-types { prefix "yang";