Skip to content

Commit

Permalink
lib: adapt to version 2 of libyang
Browse files Browse the repository at this point in the history
Compile with v2.0.0 tag of `libyang2` branch of:
https://github.com/CESNET/libyang

staticd init load time of 10k routes now 6s vs ly1 time of 150s

Signed-off-by: Christian Hopps <chopps@labn.net>
  • Loading branch information
choppsv1 committed May 13, 2021
1 parent 17daea8 commit 3bb513c
Show file tree
Hide file tree
Showing 71 changed files with 1,226 additions and 1,267 deletions.
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ ForEachMacros:
- FOR_ALL_INTERFACES_ADDRESSES
- JSON_FOREACH
# libyang
- LY_FOR_KEYS
- LY_LIST_FOR
- LY_TREE_FOR
- LY_TREE_DFS_BEGIN
- LYD_TREE_DFS_BEGIN
# zebra
- RE_DEST_FOREACH_ROUTE
- RE_DEST_FOREACH_ROUTE_SAFE
Expand Down
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ services:
- docker
jobs:
include:
- script:
- docker/centos-7/build.sh
- docker images
name: centos7
- script:
- docker/centos-8/build.sh
- docker images
name: centos8
# - script:
# - docker/centos-7/build.sh
# - docker images
# name: centos7
# - script:
# - docker/centos-8/build.sh
# - docker images
# name: centos8
- script:
- sudo apt install -y linux-modules-extra-$(uname -r)
- docker build -t frr-ubuntu18:latest -f docker/ubuntu18-ci/Dockerfile .
Expand Down
8 changes: 4 additions & 4 deletions bfdd/bfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2195,13 +2195,13 @@ void bfd_session_update_vrf_name(struct bfd_session *bs, struct vrf *vrf)
snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']/vrf",
bs->key.vrfname);

bfd_dnode = yang_dnode_get(running_config->dnode, xpath,
bs->key.vrfname);
bfd_dnode = yang_dnode_getf(running_config->dnode, xpath,
bs->key.vrfname);
if (bfd_dnode) {
yang_dnode_get_path(bfd_dnode->parent, oldpath,
yang_dnode_get_path(lyd_parent(bfd_dnode), oldpath,
sizeof(oldpath));
yang_dnode_change_leaf(bfd_dnode, vrf->name);
yang_dnode_get_path(bfd_dnode->parent, newpath,
yang_dnode_get_path(lyd_parent(bfd_dnode), newpath,
sizeof(newpath));
nb_running_move_tree(oldpath, newpath);
running_config->version++;
Expand Down
3 changes: 0 additions & 3 deletions bgpd/bgp_nb.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,6 @@ const struct frr_yang_module_info frr_bgp_info = {
.xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/neighbors/neighbor/local-as/no-prepend",
.cbs = {
.modify = bgp_neighbors_neighbor_local_as_no_prepend_modify,
.destroy = bgp_neighbors_neighbor_local_as_no_prepend_destroy,
}
},
{
Expand Down Expand Up @@ -923,7 +922,6 @@ const struct frr_yang_module_info frr_bgp_info = {
.xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/neighbors/unnumbered-neighbor/local-as/no-prepend",
.cbs = {
.modify = bgp_neighbors_unnumbered_neighbor_local_as_no_prepend_modify,
.destroy = bgp_neighbors_unnumbered_neighbor_local_as_no_prepend_destroy,
}
},
{
Expand Down Expand Up @@ -1215,7 +1213,6 @@ const struct frr_yang_module_info frr_bgp_info = {
.xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/peer-groups/peer-group/local-as/no-prepend",
.cbs = {
.modify = bgp_peer_groups_peer_group_local_as_no_prepend_modify,
.destroy = bgp_peer_groups_peer_group_local_as_no_prepend_destroy,
}
},
{
Expand Down
6 changes: 0 additions & 6 deletions bgpd/bgp_nb.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ int bgp_neighbors_neighbor_local_as_local_as_destroy(
struct nb_cb_destroy_args *args);
int bgp_neighbors_neighbor_local_as_no_prepend_modify(
struct nb_cb_modify_args *args);
int bgp_neighbors_neighbor_local_as_no_prepend_destroy(
struct nb_cb_destroy_args *args);
int bgp_neighbors_neighbor_local_as_no_replace_as_modify(
struct nb_cb_modify_args *args);
int bgp_neighbors_neighbor_bfd_options_enable_modify(
Expand Down Expand Up @@ -367,8 +365,6 @@ int bgp_neighbors_unnumbered_neighbor_local_as_local_as_destroy(
struct nb_cb_destroy_args *args);
int bgp_neighbors_unnumbered_neighbor_local_as_no_prepend_modify(
struct nb_cb_modify_args *args);
int bgp_neighbors_unnumbered_neighbor_local_as_no_prepend_destroy(
struct nb_cb_destroy_args *args);
int bgp_neighbors_unnumbered_neighbor_local_as_no_replace_as_modify(
struct nb_cb_modify_args *args);
int bgp_neighbors_unnumbered_neighbor_bfd_options_enable_modify(
Expand Down Expand Up @@ -501,8 +497,6 @@ int bgp_peer_groups_peer_group_local_as_local_as_destroy(
struct nb_cb_destroy_args *args);
int bgp_peer_groups_peer_group_local_as_no_prepend_modify(
struct nb_cb_modify_args *args);
int bgp_peer_groups_peer_group_local_as_no_prepend_destroy(
struct nb_cb_destroy_args *args);
int bgp_peer_groups_peer_group_local_as_no_replace_as_modify(
struct nb_cb_modify_args *args);
int bgp_peer_groups_peer_group_bfd_options_enable_modify(
Expand Down
62 changes: 6 additions & 56 deletions bgpd/bgp_nb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ int bgp_global_local_as_modify(struct nb_cb_modify_args *args)
* If the instance already exists - return the validation
* error.
*/
bgp = nb_running_get_entry_non_rec(args->dnode->parent->parent,
NULL, false);
bgp = nb_running_get_entry_non_rec(
lyd_parent(lyd_parent(args->dnode)), NULL, false);
if (bgp) {
snprintf(args->errmsg, args->errmsg_len,
"Changing AS number is not allowed");
Expand Down Expand Up @@ -580,16 +580,11 @@ int bgp_global_route_reflector_route_reflector_cluster_id_modify(

struct bgp *bgp;
struct in_addr cluster_id;
const struct lyd_node_leaf_list *dleaf;

bgp = nb_running_get_entry(args->dnode, NULL, true);

dleaf = (const struct lyd_node_leaf_list *)args->dnode;
if (dleaf->value_type == LY_TYPE_STRING)
yang_dnode_get_ipv4(&cluster_id, args->dnode, NULL);
else
(void)inet_aton(dleaf->value_str, &cluster_id);

/* cluster-id is either dotted-quad or a uint32 */
(void)inet_aton(lyd_get_value(args->dnode), &cluster_id);
bgp_cluster_id_set(bgp, &cluster_id);

if (bgp_clear_star_soft_out(bgp->name, args->errmsg, args->errmsg_len))
Expand Down Expand Up @@ -1495,8 +1490,8 @@ int bgp_global_instance_type_view_modify(struct nb_cb_modify_args *args)
* If the instance already exists - return the validation
* error.
*/
bgp = nb_running_get_entry_non_rec(args->dnode->parent->parent,
NULL, false);
bgp = nb_running_get_entry_non_rec(
lyd_parent(lyd_parent(args->dnode)), NULL, false);
if (bgp) {
snprintf(args->errmsg, args->errmsg_len,
"Changing instance type is not allowed");
Expand Down Expand Up @@ -3560,21 +3555,6 @@ int bgp_neighbors_neighbor_local_as_no_prepend_modify(
return NB_OK;
}

int bgp_neighbors_neighbor_local_as_no_prepend_destroy(
struct nb_cb_destroy_args *args)
{
switch (args->event) {
case NB_EV_VALIDATE:
case NB_EV_PREPARE:
case NB_EV_ABORT:
case NB_EV_APPLY:
/* TODO: implement me. */
break;
}

return NB_OK;
}

/*
* XPath:
* /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/neighbors/neighbor/local-as/no-replace-as
Expand Down Expand Up @@ -5576,21 +5556,6 @@ int bgp_neighbors_unnumbered_neighbor_local_as_no_prepend_modify(
return NB_OK;
}

int bgp_neighbors_unnumbered_neighbor_local_as_no_prepend_destroy(
struct nb_cb_destroy_args *args)
{
switch (args->event) {
case NB_EV_VALIDATE:
case NB_EV_PREPARE:
case NB_EV_ABORT:
case NB_EV_APPLY:
/* TODO: implement me. */
break;
}

return NB_OK;
}

/*
* XPath:
* /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/neighbors/unnumbered-neighbor/local-as/no-replace-as
Expand Down Expand Up @@ -7493,21 +7458,6 @@ int bgp_peer_groups_peer_group_local_as_no_prepend_modify(
return NB_OK;
}

int bgp_peer_groups_peer_group_local_as_no_prepend_destroy(
struct nb_cb_destroy_args *args)
{
switch (args->event) {
case NB_EV_VALIDATE:
case NB_EV_PREPARE:
case NB_EV_ABORT:
case NB_EV_APPLY:
/* TODO: implement me. */
break;
}

return NB_OK;
}

/*
* XPath:
* /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-bgp:bgp/peer-groups/peer-group/local-as/no-replace-as
Expand Down
48 changes: 24 additions & 24 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -4372,12 +4372,12 @@ DEFUN_YANG(neighbor_remote_as,
snprintf(prgrp_xpath, sizeof(prgrp_xpath),
FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");

if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
VTY_CURR_XPATH, unnbr_xpath + 1)) {
if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
VTY_CURR_XPATH, unnbr_xpath + 1)) {
strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
} else if (yang_dnode_exists(vty->candidate_config->dnode,
"%s%s", VTY_CURR_XPATH,
prgrp_xpath + 1)) {
} else if (yang_dnode_existsf(vty->candidate_config->dnode,
"%s%s", VTY_CURR_XPATH,
prgrp_xpath + 1)) {
snprintf(base_xpath, sizeof(base_xpath),
FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg,
"");
Expand Down Expand Up @@ -4648,8 +4648,8 @@ DEFUN_YANG(no_neighbor,
if (str2sockunion(argv[idx_peer]->arg, &su) == 0) {
snprintf(num_xpath, sizeof(num_xpath),
FRR_BGP_NEIGHBOR_NUM_XPATH, argv[idx_peer]->arg, "");
if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
VTY_CURR_XPATH, num_xpath + 1)) {
if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
VTY_CURR_XPATH, num_xpath + 1)) {
strlcpy(base_xpath, num_xpath, sizeof(base_xpath));
}
} else {
Expand All @@ -4659,12 +4659,12 @@ DEFUN_YANG(no_neighbor,
snprintf(prgrp_xpath, sizeof(prgrp_xpath),
FRR_BGP_PEER_GROUP_XPATH, argv[idx_peer]->arg, "");

if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
VTY_CURR_XPATH, unnbr_xpath + 1)) {
if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
VTY_CURR_XPATH, unnbr_xpath + 1)) {
strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
} else if (yang_dnode_exists(vty->candidate_config->dnode,
"%s%s", VTY_CURR_XPATH,
prgrp_xpath + 1)) {
} else if (yang_dnode_existsf(vty->candidate_config->dnode,
"%s%s", VTY_CURR_XPATH,
prgrp_xpath + 1)) {
strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
} else {
vty_out(vty,
Expand Down Expand Up @@ -4740,11 +4740,11 @@ DEFUN_YANG(no_neighbor_interface_peer_group_remote_as,
snprintf(prgrp_xpath, sizeof(prgrp_xpath), FRR_BGP_PEER_GROUP_XPATH,
argv[idx_peer]->arg, "");

if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
VTY_CURR_XPATH, unnbr_xpath + 1)) {
if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
VTY_CURR_XPATH, unnbr_xpath + 1)) {
strlcpy(base_xpath, unnbr_xpath, sizeof(base_xpath));
} else if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
VTY_CURR_XPATH, prgrp_xpath + 1)) {
} else if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
VTY_CURR_XPATH, prgrp_xpath + 1)) {
strlcpy(base_xpath, prgrp_xpath, sizeof(base_xpath));
} else {
vty_out(vty, "%% Create the peer-group or interface first\n");
Expand Down Expand Up @@ -7036,8 +7036,8 @@ static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
if (str2sockunion(peer_str, &su) == 0) {
snprintf(num_xpath, sizeof(num_xpath),
"/neighbors/neighbor[remote-address='%s']", peer_str);
if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
VTY_CURR_XPATH, num_xpath)) {
if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
VTY_CURR_XPATH, num_xpath)) {
snprintf(base_xpath, xpath_len,
FRR_BGP_NEIGHBOR_NUM_XPATH, peer_str,
xpath ? xpath : "");
Expand All @@ -7056,14 +7056,14 @@ static int peer_and_group_lookup_nb(struct vty *vty, const char *peer_str,
"/peer-groups/peer-group[peer-group-name='%s']",
peer_str);

if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s",
VTY_CURR_XPATH, unnbr_xpath)) {
if (yang_dnode_existsf(vty->candidate_config->dnode, "%s%s",
VTY_CURR_XPATH, unnbr_xpath)) {
snprintf(base_xpath, xpath_len,
FRR_BGP_NEIGHBOR_UNNUM_XPATH, peer_str,
xpath ? xpath : "");
} else if (yang_dnode_exists(vty->candidate_config->dnode,
"%s%s", VTY_CURR_XPATH,
prgrp_xpath)) {
} else if (yang_dnode_existsf(vty->candidate_config->dnode,
"%s%s", VTY_CURR_XPATH,
prgrp_xpath)) {
snprintf(base_xpath, xpath_len,
FRR_BGP_PEER_GROUP_XPATH, peer_str,
xpath ? xpath : "");
Expand Down Expand Up @@ -8085,7 +8085,7 @@ DEFPY_YANG(
bgp_afi_safi_get_container_str(afi, safi));

if (!no) {
if (!yang_dnode_exists(
if (!yang_dnode_existsf(
vty->candidate_config->dnode,
"/frr-route-map:lib/route-map[name='%s']",
rmap_str)) {
Expand Down
4 changes: 2 additions & 2 deletions bgpd/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ bgpd_bgpd_SOURCES = bgpd/bgp_main.c
bgpd_bgp_btoa_SOURCES = bgpd/bgp_btoa.c

# RFPLDADD is set in bgpd/rfp-example/librfp/subdir.am
bgpd_bgpd_LDADD = bgpd/libbgp.a $(RFPLDADD) lib/libfrr.la $(LIBCAP) $(LIBM) $(UST_LIBS)
bgpd_bgp_btoa_LDADD = bgpd/libbgp.a $(RFPLDADD) lib/libfrr.la $(LIBCAP) $(LIBM) $(UST_LIBS)
bgpd_bgpd_LDADD = bgpd/libbgp.a $(RFPLDADD) lib/libfrr.la $(LIBYANG_LIBS) $(LIBCAP) $(LIBM) $(UST_LIBS)
bgpd_bgp_btoa_LDADD = bgpd/libbgp.a $(RFPLDADD) lib/libfrr.la $(LIBYANG_LIBS) $(LIBCAP) $(LIBM) $(UST_LIBS)

bgpd_bgpd_snmp_la_SOURCES = bgpd/bgp_snmp.c bgpd/bgp_mplsvpn_snmp.c
bgpd_bgpd_snmp_la_CFLAGS = $(AM_CFLAGS) $(SNMP_CFLAGS) -std=gnu11
Expand Down
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1866,8 +1866,8 @@ AC_SUBST([SNMP_CFLAGS])
dnl ---------------
dnl libyang
dnl ---------------
PKG_CHECK_MODULES([LIBYANG], [libyang >= 1.0.184 libyang < 2.0], , [
AC_MSG_ERROR([libyang (>= 1.0.184) was not found on your system.])
PKG_CHECK_MODULES([LIBYANG], [libyang >= 2.0.0], , [
AC_MSG_ERROR([libyang (>= 2.0.0) was not found on your system.])
])
ac_cflags_save="$CFLAGS"
CFLAGS="$CFLAGS $LIBYANG_CFLAGS"
Expand Down
4 changes: 2 additions & 2 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Build-Depends: bison,
libelf-dev,
libjson-c-dev | libjson0-dev,
libpam0g-dev | libpam-dev,
libpcre3-dev,
libpcre2-dev,
libpython3-dev,
libreadline-dev,
librtr-dev <!pkg.frr.nortrlib>,
libsnmp-dev,
libssh-dev <!pkg.frr.nortrlib>,
libsystemd-dev <!pkg.frr.nosystemd>,
libyang-dev (>= 1.0.184),
libyang2-dev,
lsb-base,
pkg-config,
python3,
Expand Down
Loading

0 comments on commit 3bb513c

Please sign in to comment.