diff --git a/.clang-format b/.clang-format index 1b18323348..d16263da2e 100644 --- a/.clang-format +++ b/.clang-format @@ -1,92 +1,209 @@ +# SPDX-License-Identifier: GPL-2.0 +# clang-format configuration file. Intended for clang-format >= 11. +# +# For more information, see: +# +# Documentation/process/clang-format.rst +# https://clang.llvm.org/docs/ClangFormat.html +# https://clang.llvm.org/docs/ClangFormatStyleOptions.html +# --- -BasedOnStyle: LLVM -Language: Cpp -IndentWidth: 8 -UseTab: Always -BreakBeforeBraces: Linux -AlwaysBreakBeforeMultilineStrings: true -AllowShortIfStatementsOnASingleLine: false -AllowShortLoopsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -IndentCaseLabels: false -AlignEscapedNewlinesLeft: false +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +# FRR: Right +AlignEscapedNewlines: Right +AlignOperands: Align +# FRR: true AlignTrailingComments: true +# FRR: true +AlignConsecutiveMacros: true AllowAllParametersOfDeclarationOnNextLine: false -AlignAfterOpenBracket: true -SpaceAfterCStyleCast: false -MaxEmptyLinesToKeep: 2 -BreakBeforeBinaryOperators: None +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: false +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: false +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeComma +BreakAfterJavaFieldAnnotations: false BreakStringLiterals: false -SortIncludes: false -IncludeCategories: - - Regex: '^(<|lib)' - Priority: 0 +ColumnLimit: 80 +# Linux: CommentPragmas: '^ IWYU pragma:' CommentPragmas: '\$(FRR|clippy)' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 8 ContinuationIndentWidth: 8 +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +# Some taken from: +# git grep -h '^#define [^[:space:]]*frr_(each|with)[^[:space:]]*(' ./ \ +# | sed "s,^#define \([^[:space:]]*frr_(each|with)[^[:space:]]*\)(.*$, - '\1'," \ +# | LC_ALL=C sort -u +# and +# git grep -h '^#define [^[:space:]]*FOREACH[^[:space:]]*(' ./ +# | sed "s,^#define \([^[:space:]]*FOREACH[^)]*\)(.*, - '\1'," +# | LC_ALL=C sort -u ForEachMacros: - # lib - - frr_each - - frr_each_safe - - frr_each_from - - frr_rev_each - - frr_rev_each_safe - - frr_rev_each_from - - frr_with_mutex - - frr_with_privs - - LIST_FOREACH - - LIST_FOREACH_SAFE - - SLIST_FOREACH - - SLIST_FOREACH_SAFE - - SLIST_FOREACH_PREVPTR - - STAILQ_FOREACH - - STAILQ_FOREACH_SAFE - - TAILQ_FOREACH - - TAILQ_FOREACH_SAFE - - TAILQ_FOREACH_REVERSE - - TAILQ_FOREACH_REVERSE_SAFE - - RB_FOREACH - - RB_FOREACH_SAFE - - RB_FOREACH_REVERSE - - RB_FOREACH_REVERSE_SAFE - - SPLAY_FOREACH - - FOR_ALL_INTERFACES - - FOR_ALL_INTERFACES_ADDRESSES - - JSON_FOREACH - - FOREACH_BE_TXN_BATCH_IN_LIST - - FOREACH_BE_APPLY_BATCH_IN_LIST - - FOREACH_BE_TXN_IN_LIST - - FOREACH_SESSION_IN_LIST - - FOREACH_MGMTD_BE_CLIENT_ID - # 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 - - RNODE_FOREACH_RE - - RNODE_FOREACH_RE_SAFE - # bgpd - - UPDGRP_FOREACH_SUBGRP - - UPDGRP_FOREACH_SUBGRP_SAFE - - SUBGRP_FOREACH_PEER - - SUBGRP_FOREACH_PEER_SAFE - - SUBGRP_FOREACH_ADJ - - SUBGRP_FOREACH_ADJ_SAFE - - AF_FOREACH - - FOREACH_AFI_SAFI - - FOREACH_AFI_SAFI_NSF - - FOREACH_SAFI - # ospfd - - LSDB_LOOP - # mgmtd - - FOREACH_CMT_REC - - FOREACH_TXN_CFG_BATCH_IN_LIST - - FOREACH_TXN_REQ_IN_LIST - - FOREACH_TXN_IN_LIST - - FOREACH_MGMTD_DB_ID - - FOREACH_ADAPTER_IN_LIST - - FOREACH_SESSION_IN_LIST - - FOREACH_SESSION_IN_LIST_SAFE + # lib: outliers: + - 'FOR_ALL_INTERFACES' + # libyang outliers: + - 'LY_FOR_KEYS' + - 'LY_LIST_FOR' + - 'LYD_LIST_FOR_INST' + - 'LYD_LIST_FOR_INST_SAFE' + - 'LY_TREE_FOR' + - 'LY_TREE_DFS_BEGIN' + - 'LYD_TREE_DFS_BEGIN' + # ospfd outliers: + - 'LSDB_LOOP' + # first git grep + - 'darr_foreach_p' + - 'darr_foreach_i' + - 'frr_each' + - 'frr_each_safe' + - 'frr_each_from' + - 'frr_rev_each' + - 'frr_rev_each_safe' + - 'frr_rev_each_from' + - 'frr_with_mutex' + - 'frr_with_privs' + # second git grep + - 'AF_FOREACH' + - 'FOREACH_ADAPTER_IN_LIST' + - 'FOREACH_AFI_SAFI' + - 'FOREACH_AFI_SAFI_NSF' + - 'FOREACH_BE_APPLY_BATCH_IN_LIST' + - 'FOREACH_BE_CLIENT_BITS' + - 'FOREACH_BE_TXN_BATCH_IN_LIST' + - 'FOREACH_BE_TXN_IN_LIST' + - 'FOREACH_CMT_REC' + - 'FOREACH_MGMTD_BE_CLIENT_ID' + - 'FOREACH_MGMTD_DS_ID' + - 'FOREACH_SAFI' + - 'FOREACH_SESSION_IN_LIST' + - 'FOREACH_TXN_CFG_BATCH_IN_LIST' + - 'FOREACH_TXN_IN_LIST' + - 'FOREACH_TXN_REQ_IN_LIST' + - 'JSON_FOREACH' + - 'LIST_FOREACH' + - 'LIST_FOREACH_SAFE' + - 'RB_FOREACH' + - 'RB_FOREACH_REVERSE' + - 'RB_FOREACH_REVERSE_SAFE' + - 'RB_FOREACH_SAFE' + - 'RE_DEST_FOREACH_ROUTE' + - 'RE_DEST_FOREACH_ROUTE_SAFE' + - 'RNODE_FOREACH_RE' + - 'RNODE_FOREACH_RE_SAFE' + - 'SIMPLEQ_FOREACH' + - 'SIMPLEQ_FOREACH_SAFE' + - 'SLIST_FOREACH' + - 'SLIST_FOREACH_PREVPTR' + - 'SLIST_FOREACH_SAFE' + - 'SPLAY_FOREACH' + - 'STAILQ_FOREACH' + - 'STAILQ_FOREACH_SAFE' + - 'SUBGRP_FOREACH_ADJ' + - 'SUBGRP_FOREACH_ADJ_SAFE' + - 'SUBGRP_FOREACH_PEER' + - 'SUBGRP_FOREACH_PEER_SAFE' + - 'TAILQ_FOREACH' + - 'TAILQ_FOREACH_REVERSE' + - 'TAILQ_FOREACH_REVERSE_SAFE' + - 'TAILQ_FOREACH_SAFE' + - 'UPDGRP_FOREACH_SUBGRP' + - 'UPDGRP_FOREACH_SUBGRP_SAFE' + - 'XSIMPLEQ_FOREACH' + - 'XSIMPLEQ_FOREACH_SAFE' +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^(<|lib)' + Priority: 0 +## New: XXX whats it mean? +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentGotoLabels: false +IndentPPDirectives: None +IndentWidth: 8 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +## Linux: MaxEmptyLinesToKeep: 1 +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 8 +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true + +## Lowest Penalty Value wins. Values are used by clang-format to influence +## the brak decisions, it's a bit of voodoo magic though. +## Originally from linux which was "Taken from git's rules" +PenaltyBreakAssignment: 30 +PenaltyBreakComment: 10 +PenaltyBreakFirstLessLess: 0 +# Don't break a string into multi-string-fragments +PenaltyBreakString: 1000 +# Allow going past the ColumnLimit to keep function arguments aligned +# with the open parenthesis. +PenaltyBreakBeforeFirstCallParameter: 1000 +# Try and stay under ColumnLimit, but not at the cost of incomprehensible code. +PenaltyExcessCharacter: 30 +PenaltyReturnTypeOnItsOwnLine: 60 + +PointerAlignment: Right +ReflowComments: false +SortIncludes: false +SortUsingDeclarations: false +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: false +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp03 +TabWidth: 8 +UseTab: Always +... diff --git a/.github/workflows/freeze.yml b/.github/workflows/freeze.yml index f3506d0061..a780298a42 100644 --- a/.github/workflows/freeze.yml +++ b/.github/workflows/freeze.yml @@ -1,4 +1,4 @@ -name: Warn before merging if a "freeze" label exists +name: Warn before merging if a "freeze" or "do not merge" label exists on: pull_request_target: @@ -6,12 +6,12 @@ on: jobs: freeze_warning: - if: ${{ contains(github.event.*.labels.*.name, 'freeze') }} - name: Warn before merging if a "freeze" label exists + if: ${{ contains(github.event.*.labels.*.name, 'freeze') || contains(github.event.*.labels.*.name, 'do not merge') }} + name: Warn before merging if a "freeze" or "do not merge" label exists runs-on: ubuntu-latest steps: - name: Check for "freeze" label run: | - echo "Pull request is labeled as 'freeze'" + echo "Pull request is labeled as 'freeze' or 'do not merge'" echo "This workflow fails so that the pull request cannot be merged." exit 1 diff --git a/alpine/APKBUILD.in b/alpine/APKBUILD.in index fd3c02f47e..9a29ff3a96 100644 --- a/alpine/APKBUILD.in +++ b/alpine/APKBUILD.in @@ -13,13 +13,13 @@ makedepends="ncurses-dev net-snmp-dev gawk texinfo perl expat fakeroot flex fortify-headers gdbm git gmp json-c-dev kmod lddtree libacl libatomic libattr libblkid libburn libbz2 libc-dev libcap-dev libcurl libedit libffi libgcc libgomp libisoburn libisofs - libltdl libressl libssh2 libstdc++ libtool libuuid + libltdl openssl libssh2 libstdc++ libtool libuuid linux-headers lzip lzo m4 make mkinitfs mpc1 mpfr4 mtools musl-dev ncurses-libs ncurses-terminfo ncurses-terminfo-base patch pax-utils pcre2 perl pkgconf python3 python3-dev readline readline-dev sqlite-libs pcre2-dev squashfs-tools sudo tar texinfo xorriso xz-libs py-pip rtrlib rtrlib-dev - py3-sphinx elfutils elfutils-dev libyang-dev protobuf-c-compiler protobuf-c-dev - lua5.3-dev lua5.3" + py3-sphinx elfutils elfutils-dev protobuf-c-compiler protobuf-c-dev + lua5.3-dev lua5.3 gzip" checkdepends="pytest py-setuptools" install="$pkgname.pre-install $pkgname.pre-deinstall $pkgname.post-deinstall" subpackages="$pkgname-dev $pkgname-doc $pkgname-dbg" diff --git a/babeld/babel_interface.c b/babeld/babel_interface.c index ceff472c2a..c4349b509e 100644 --- a/babeld/babel_interface.c +++ b/babeld/babel_interface.c @@ -695,6 +695,11 @@ interface_reset(struct interface *ifp) babel_ifp->cost, babel_ifp->ipv4 ? ", IPv4" : ""); + if (babel_ifp->ipv4 != NULL){ + free(babel_ifp->ipv4); + babel_ifp->ipv4 = NULL; + } + return 1; } @@ -734,12 +739,11 @@ int is_interface_ll_address(struct interface *ifp, const unsigned char *address) { struct connected *connected; - struct listnode *node; if(!if_up(ifp)) return 0; - FOR_ALL_INTERFACES_ADDRESSES(ifp, connected, node) { + frr_each (if_connected, ifp->connected, connected) { if (connected->address->family == AF_INET6 && memcmp(&connected->address->u.prefix6, address, IPV6_MAX_BYTELEN) @@ -1345,5 +1349,9 @@ babel_interface_allocate (void) static void babel_interface_free (babel_interface_nfo *babel_ifp) { + if (babel_ifp->ipv4){ + free(babel_ifp->ipv4); + babel_ifp->ipv4 = NULL; + } XFREE(MTYPE_BABEL_IF, babel_ifp); } diff --git a/babeld/babel_interface.h b/babeld/babel_interface.h index 12fa6e2bad..a585e23afc 100644 --- a/babeld/babel_interface.h +++ b/babeld/babel_interface.h @@ -82,7 +82,6 @@ static inline int if_up(struct interface *ifp) { return (if_is_operative(ifp) && - ifp->connected != NULL && CHECK_FLAG(babel_get_if_nfo(ifp)->flags, BABEL_IF_IS_UP)); } diff --git a/babeld/babel_main.c b/babeld/babel_main.c index b6126d5b7d..7122d6953b 100644 --- a/babeld/babel_main.c +++ b/babeld/babel_main.c @@ -5,6 +5,8 @@ Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek /* include zebra library */ #include +#include + #include "getopt.h" #include "if.h" #include "log.h" @@ -182,8 +184,10 @@ main(int argc, char **argv) change_smoothing_half_life(BABEL_DEFAULT_SMOOTHING_HALF_LIFE); /* init some quagga's dependencies, and babeld's commands */ - if_zapi_callbacks(babel_ifp_create, babel_ifp_up, - babel_ifp_down, babel_ifp_destroy); + hook_register_prio(if_real, 0, babel_ifp_create); + hook_register_prio(if_up, 0, babel_ifp_up); + hook_register_prio(if_down, 0, babel_ifp_down); + hook_register_prio(if_unreal, 0, babel_ifp_destroy); babeld_quagga_init(); /* init zebra client's structure and it's commands */ /* this replace kernel_setup && kernel_setup_socket */ @@ -306,6 +310,8 @@ babel_exit_properly(void) babel_save_state_file(); debugf(BABEL_DEBUG_COMMON, "Remove pid file."); debugf(BABEL_DEBUG_COMMON, "Done."); + + vrf_terminate(); frr_fini(); exit(0); diff --git a/babeld/babeld.c b/babeld/babeld.c index f4c932971e..41fac62511 100644 --- a/babeld/babeld.c +++ b/babeld/babeld.c @@ -108,14 +108,14 @@ babel_config_write (struct vty *vty) /* list redistributed protocols */ for (afi = AFI_IP; afi <= AFI_IP6; afi++) { for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { - if (i != zclient->redist_default && - vrf_bitmap_check (zclient->redist[afi][i], VRF_DEFAULT)) { - vty_out (vty, " redistribute %s %s\n", - (afi == AFI_IP) ? "ipv4" : "ipv6", - zebra_route_string(i)); - lines++; - } - } + if (i != zclient->redist_default && + vrf_bitmap_check(&zclient->redist[afi][i], VRF_DEFAULT)) { + vty_out(vty, " redistribute %s %s\n", + (afi == AFI_IP) ? "ipv4" : "ipv6", + zebra_route_string(i)); + lines++; + } + } } lines += config_write_distribute (vty, babel_routing_process->distribute_ctx); @@ -242,7 +242,7 @@ babel_get_myid(void) /* We failed to get a global EUI64 from the interfaces we were given. Let's try to find an interface with a MAC address. */ for(i = 1; i < 256; i++) { - char buf[INTERFACE_NAMSIZ], *ifname; + char buf[IFNAMSIZ], *ifname; unsigned char eui[8]; ifname = if_indextoname(i, buf); if(ifname == NULL) diff --git a/babeld/kernel.c b/babeld/kernel.c index 4fe5bcfea6..aed6dc9c4f 100644 --- a/babeld/kernel.c +++ b/babeld/kernel.c @@ -11,6 +11,7 @@ Copyright 2011, 2012 by Matthieu Boutier and Juliusz Chroboczek #include #include #include +#include #include "babeld.h" diff --git a/babeld/message.c b/babeld/message.c index d4ddebff08..f8549329c6 100644 --- a/babeld/message.c +++ b/babeld/message.c @@ -556,7 +556,7 @@ parse_packet(const unsigned char *from, struct interface *ifp, int rc; rc = network_address(message[2], message + 4, len - 2, nh); - if(rc < 0) { + if(rc <= 0) { have_v4_nh = 0; have_v6_nh = 0; goto fail; @@ -731,7 +731,7 @@ parse_packet(const unsigned char *from, struct interface *ifp, DO_NTOHS(seqno, message + 4); rc = network_prefix(message[2], message[3], 0, message + 16, NULL, len - 14, prefix); - if(rc < 0) goto fail; + if(rc <= 0) goto fail; plen = message[3] + (message[2] == 1 ? 96 : 0); debugf(BABEL_DEBUG_COMMON,"Received request (%d) for %s from %s on %s (%s, %d).", message[6], diff --git a/bfdd/bfd.h b/bfdd/bfd.h index 5451e66c23..26bd20b5d7 100644 --- a/bfdd/bfd.h +++ b/bfdd/bfd.h @@ -32,6 +32,11 @@ DECLARE_MGROUP(BFDD); DECLARE_MTYPE(BFDD_CONTROL); DECLARE_MTYPE(BFDD_NOTIFICATION); +/* bfd Authentication Type. */ +#define BFD_AUTH_NULL 0 +#define BFD_AUTH_SIMPLE 1 +#define BFD_AUTH_CRYPTOGRAPHIC 2 + struct bfd_timers { uint32_t desired_min_tx; uint32_t required_min_rx; @@ -60,6 +65,15 @@ struct bfd_pkt { struct bfd_timers timers; }; +/* + * Format of authentification. + */ +struct bfd_auth { + uint8_t type; + uint8_t length; +}; + + /* * Format of Echo packet. */ @@ -79,7 +93,7 @@ struct bfd_echo_pkt { /* Macros for manipulating control packets */ -#define BFD_VERMASK 0x03 +#define BFD_VERMASK 0x07 #define BFD_DIAGMASK 0x1F #define BFD_GETVER(diag) ((diag >> 5) & BFD_VERMASK) #define BFD_SETVER(diag, val) ((diag) |= (val & BFD_VERMASK) << 5) @@ -179,7 +193,7 @@ struct bfd_key { uint16_t mhop; struct in6_addr peer; struct in6_addr local; - char ifname[INTERFACE_NAMSIZ]; + char ifname[IFNAMSIZ]; char vrfname[VRF_NAMSIZ]; } __attribute__((packed)); @@ -768,6 +782,7 @@ void bfdd_cli_init(void); */ void bfdd_zclient_init(struct zebra_privs_t *bfdd_priv); void bfdd_zclient_stop(void); +void bfdd_zclient_terminate(void); void bfdd_zclient_unregister(vrf_id_t vrf_id); void bfdd_zclient_register(vrf_id_t vrf_id); void bfdd_sessions_enable_vrf(struct vrf *vrf); diff --git a/bfdd/bfd_packet.c b/bfdd/bfd_packet.c index ea7a1038ae..fec195c77e 100644 --- a/bfdd/bfd_packet.c +++ b/bfdd/bfd_packet.c @@ -12,6 +12,11 @@ */ #include +#include + +#ifdef GNU_LINUX +#include +#endif #ifdef BFD_LINUX #include @@ -768,6 +773,37 @@ static void cp_debug(bool mhop, struct sockaddr_any *peer, mhop ? "yes" : "no", peerstr, localstr, portstr, vrfstr); } +static bool bfd_check_auth(const struct bfd_session *bfd, + const struct bfd_pkt *cp) +{ + if (CHECK_FLAG(cp->flags, BFD_ABIT)) { + /* RFC5880 4.1: Authentication Section is present. */ + struct bfd_auth *auth = (struct bfd_auth *)(cp + 1); + uint16_t pkt_auth_type = ntohs(auth->type); + + if (cp->len < BFD_PKT_LEN + sizeof(struct bfd_auth)) + return false; + + if (cp->len < BFD_PKT_LEN + auth->length) + return false; + + switch (pkt_auth_type) { + case BFD_AUTH_NULL: + return false; + case BFD_AUTH_SIMPLE: + /* RFC5880 6.7: To be finshed. */ + return false; + case BFD_AUTH_CRYPTOGRAPHIC: + /* RFC5880 6.7: To be finshed. */ + return false; + default: + /* RFC5880 6.7: To be finshed. */ + return false; + } + } + return true; +} + void bfd_recv_cb(struct event *t) { int sd = EVENT_FD(t); @@ -932,6 +968,13 @@ void bfd_recv_cb(struct event *t) bfd->discrs.remote_discr = ntohl(cp->discrs.my_discr); + /* Check authentication. */ + if (!bfd_check_auth(bfd, cp)) { + cp_debug(is_mhop, &peer, &local, ifindex, vrfid, + "Authentication failed"); + return; + } + /* Save remote diagnostics before state switch. */ bfd->remote_diag = cp->diag & BFD_DIAGMASK; @@ -1704,9 +1747,10 @@ void bfd_peer_mac_set(int sd, struct bfd_session *bfd, strlcpy(arpreq_.arp_dev, ifp->name, sizeof(arpreq_.arp_dev)); if (ioctl(sd, SIOCGARP, &arpreq_) < 0) { - zlog_warn( - "BFD: getting peer's mac on %s failed error %s", - ifp->name, strerror(errno)); + if (bglobal.debug_network) + zlog_debug( + "BFD: getting peer's mac on %s failed error %s", + ifp->name, strerror(errno)); UNSET_FLAG(bfd->flags, BFD_SESS_FLAG_MAC_SET); memset(bfd->peer_hw_addr, 0, sizeof(bfd->peer_hw_addr)); diff --git a/bfdd/bfdd.c b/bfdd/bfdd.c index 95066b97ce..71055c32ed 100644 --- a/bfdd/bfdd.c +++ b/bfdd/bfdd.c @@ -75,6 +75,8 @@ static void sigterm_handler(void) bfd_vrf_terminate(); + bfdd_zclient_terminate(); + /* Terminate and free() FRR related memory. */ frr_fini(); diff --git a/bfdd/bfdd_cli.c b/bfdd/bfdd_cli.c index 44439c6756..75034d220c 100644 --- a/bfdd/bfdd_cli.c +++ b/bfdd/bfdd_cli.c @@ -219,24 +219,24 @@ static void _bfd_cli_show_peer(struct vty *vty, const struct lyd_node *dnode, bool show_defaults __attribute__((__unused__)), bool mhop) { - const char *vrf = yang_dnode_get_string(dnode, "./vrf"); + const char *vrf = yang_dnode_get_string(dnode, "vrf"); vty_out(vty, " peer %s", - yang_dnode_get_string(dnode, "./dest-addr")); + yang_dnode_get_string(dnode, "dest-addr")); if (mhop) vty_out(vty, " multihop"); - if (yang_dnode_exists(dnode, "./source-addr")) + if (yang_dnode_exists(dnode, "source-addr")) vty_out(vty, " local-address %s", - yang_dnode_get_string(dnode, "./source-addr")); + yang_dnode_get_string(dnode, "source-addr")); if (strcmp(vrf, VRF_DEFAULT_NAME)) vty_out(vty, " vrf %s", vrf); if (!mhop) { const char *ifname = - yang_dnode_get_string(dnode, "./interface"); + yang_dnode_get_string(dnode, "interface"); if (strcmp(ifname, "*")) vty_out(vty, " interface %s", ifname); } @@ -567,7 +567,7 @@ DEFPY_YANG(no_bfd_profile, no_bfd_profile_cmd, void bfd_cli_show_profile(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - vty_out(vty, " profile %s\n", yang_dnode_get_string(dnode, "./name")); + vty_out(vty, " profile %s\n", yang_dnode_get_string(dnode, "name")); } ALIAS_YANG(bfd_peer_mult, bfd_profile_mult_cmd, diff --git a/bfdd/bfdd_nb.c b/bfdd/bfdd_nb.c index 7135c50763..114fbc2bdd 100644 --- a/bfdd/bfdd_nb.c +++ b/bfdd/bfdd_nb.c @@ -74,7 +74,6 @@ const struct frr_yang_module_info frr_bfdd_info = { .xpath = "/frr-bfdd:bfdd/bfd/profile/minimum-ttl", .cbs = { .modify = bfdd_bfd_profile_minimum_ttl_modify, - .destroy = bfdd_bfd_profile_minimum_ttl_destroy, .cli_show = bfd_cli_show_minimum_ttl, } }, @@ -361,7 +360,6 @@ const struct frr_yang_module_info frr_bfdd_info = { .xpath = "/frr-bfdd:bfdd/bfd/sessions/multi-hop/minimum-ttl", .cbs = { .modify = bfdd_bfd_sessions_multi_hop_minimum_ttl_modify, - .destroy = bfdd_bfd_sessions_multi_hop_minimum_ttl_destroy, .cli_show = bfd_cli_show_minimum_ttl, } }, diff --git a/bfdd/bfdd_nb.h b/bfdd/bfdd_nb.h index 7a0e724d28..b5b00b57e4 100644 --- a/bfdd/bfdd_nb.h +++ b/bfdd/bfdd_nb.h @@ -25,7 +25,6 @@ int bfdd_bfd_profile_required_receive_interval_modify( int bfdd_bfd_profile_administrative_down_modify(struct nb_cb_modify_args *args); int bfdd_bfd_profile_passive_mode_modify(struct nb_cb_modify_args *args); int bfdd_bfd_profile_minimum_ttl_modify(struct nb_cb_modify_args *args); -int bfdd_bfd_profile_minimum_ttl_destroy(struct nb_cb_destroy_args *args); int bfdd_bfd_profile_echo_mode_modify(struct nb_cb_modify_args *args); int bfdd_bfd_profile_desired_echo_transmission_interval_modify( struct nb_cb_modify_args *args); @@ -128,8 +127,6 @@ int bfdd_bfd_sessions_multi_hop_administrative_down_modify( struct nb_cb_modify_args *args); int bfdd_bfd_sessions_multi_hop_minimum_ttl_modify( struct nb_cb_modify_args *args); -int bfdd_bfd_sessions_multi_hop_minimum_ttl_destroy( - struct nb_cb_destroy_args *args); struct yang_data * bfdd_bfd_sessions_multi_hop_stats_local_discriminator_get_elem( struct nb_cb_get_elem_args *args); diff --git a/bfdd/bfdd_nb_config.c b/bfdd/bfdd_nb_config.c index e4e97404d8..48fbe7139c 100644 --- a/bfdd/bfdd_nb_config.c +++ b/bfdd/bfdd_nb_config.c @@ -24,17 +24,17 @@ static void bfd_session_get_key(bool mhop, const struct lyd_node *dnode, struct sockaddr_any psa, lsa; /* Required destination parameter. */ - strtosa(yang_dnode_get_string(dnode, "./dest-addr"), &psa); + strtosa(yang_dnode_get_string(dnode, "dest-addr"), &psa); /* Get optional source address. */ memset(&lsa, 0, sizeof(lsa)); - if (yang_dnode_exists(dnode, "./source-addr")) - strtosa(yang_dnode_get_string(dnode, "./source-addr"), &lsa); + if (yang_dnode_exists(dnode, "source-addr")) + strtosa(yang_dnode_get_string(dnode, "source-addr"), &lsa); - vrfname = yang_dnode_get_string(dnode, "./vrf"); + vrfname = yang_dnode_get_string(dnode, "vrf"); if (!mhop) { - ifname = yang_dnode_get_string(dnode, "./interface"); + ifname = yang_dnode_get_string(dnode, "interface"); if (strcmp(ifname, "*") == 0) ifname = NULL; } @@ -53,7 +53,7 @@ static int session_iter_cb(const struct lyd_node *dnode, void *arg) struct session_iter *iter = arg; const char *ifname; - ifname = yang_dnode_get_string(dnode, "./interface"); + ifname = yang_dnode_get_string(dnode, "interface"); if (strmatch(ifname, "*")) iter->wildcard = true; @@ -76,7 +76,7 @@ static int bfd_session_create(struct nb_cb_create_args *args, bool mhop) switch (args->event) { case NB_EV_VALIDATE: - yang_dnode_get_prefix(&p, args->dnode, "./dest-addr"); + yang_dnode_get_prefix(&p, args->dnode, "dest-addr"); if (mhop) { /* @@ -97,7 +97,7 @@ static int bfd_session_create(struct nb_cb_create_args *args, bool mhop) * require interface name, otherwise we can't figure * which interface to use to send the packets. */ - ifname = yang_dnode_get_string(args->dnode, "./interface"); + ifname = yang_dnode_get_string(args->dnode, "interface"); if (p.family == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&p.u.prefix6) && strcmp(ifname, "*") == 0) { @@ -112,8 +112,8 @@ static int bfd_session_create(struct nb_cb_create_args *args, bool mhop) sess_dnode = yang_dnode_get_parent(args->dnode, "sessions"); - dest = yang_dnode_get_string(args->dnode, "./dest-addr"); - vrfname = yang_dnode_get_string(args->dnode, "./vrf"); + dest = yang_dnode_get_string(args->dnode, "dest-addr"); + vrfname = yang_dnode_get_string(args->dnode, "vrf"); yang_dnode_iterate(session_iter_cb, &iter, sess_dnode, "./single-hop[dest-addr='%s'][vrf='%s']", @@ -275,7 +275,7 @@ int bfdd_bfd_profile_create(struct nb_cb_create_args *args) if (args->event != NB_EV_APPLY) return NB_OK; - name = yang_dnode_get_string(args->dnode, "./name"); + name = yang_dnode_get_string(args->dnode, "name"); bp = bfd_profile_new(name); nb_running_set_entry(args->dnode, bp); @@ -423,20 +423,6 @@ int bfdd_bfd_profile_minimum_ttl_modify(struct nb_cb_modify_args *args) return NB_OK; } -int bfdd_bfd_profile_minimum_ttl_destroy(struct nb_cb_destroy_args *args) -{ - struct bfd_profile *bp; - - if (args->event != NB_EV_APPLY) - return NB_OK; - - bp = nb_running_get_entry(args->dnode, NULL, true); - bp->minimum_ttl = BFD_DEF_MHOP_TTL; - bfd_profile_update(bp); - - return NB_OK; -} - /* * XPath: /frr-bfdd:bfdd/bfd/profile/echo-mode */ @@ -859,27 +845,3 @@ int bfdd_bfd_sessions_multi_hop_minimum_ttl_modify( return NB_OK; } - -int bfdd_bfd_sessions_multi_hop_minimum_ttl_destroy( - struct nb_cb_destroy_args *args) -{ - struct bfd_session *bs; - - switch (args->event) { - case NB_EV_VALIDATE: - case NB_EV_PREPARE: - return NB_OK; - - case NB_EV_APPLY: - break; - - case NB_EV_ABORT: - return NB_OK; - } - - bs = nb_running_get_entry(args->dnode, NULL, true); - bs->peer_profile.minimum_ttl = BFD_DEF_MHOP_TTL; - bfd_session_apply(bs); - - return NB_OK; -} diff --git a/bfdd/bfdd_vty.c b/bfdd/bfdd_vty.c index 15444e4e9d..496d5019b5 100644 --- a/bfdd/bfdd_vty.c +++ b/bfdd/bfdd_vty.c @@ -213,6 +213,8 @@ static struct json_object *__display_peer_json(struct bfd_session *bs) uint32_t avg = 0; uint32_t max = 0; + if (bs->key.ifname[0]) + json_object_string_add(jo, "interface", bs->key.ifname); json_object_int_add(jo, "id", bs->discrs.my_discr); json_object_int_add(jo, "remote-id", bs->discrs.remote_discr); json_object_boolean_add(jo, "passive-mode", @@ -246,6 +248,10 @@ static struct json_object *__display_peer_json(struct bfd_session *bs) json_object_string_add(jo, "diagnostic", diag2str(bs->local_diag)); json_object_string_add(jo, "remote-diagnostic", diag2str(bs->remote_diag)); + if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_CONFIG)) + json_object_string_add(jo, "type", "configured"); + else + json_object_string_add(jo, "type", "dynamic"); json_object_int_add(jo, "receive-interval", bs->timers.required_min_rx / 1000); diff --git a/bfdd/control.c b/bfdd/control.c index f435358f33..6ff86f2913 100644 --- a/bfdd/control.c +++ b/bfdd/control.c @@ -12,6 +12,9 @@ #include +#include +#include + #include #include "bfd.h" diff --git a/bfdd/ptm_adapter.c b/bfdd/ptm_adapter.c index 490bc30d74..b5ab2ef1d0 100644 --- a/bfdd/ptm_adapter.c +++ b/bfdd/ptm_adapter.c @@ -756,20 +756,6 @@ static int bfd_ifp_destroy(struct interface *ifp) return 0; } -static int bfdd_interface_vrf_update(ZAPI_CALLBACK_ARGS) -{ - struct interface *ifp; - vrf_id_t nvrfid; - - ifp = zebra_interface_vrf_update_read(zclient->ibuf, vrf_id, &nvrfid); - if (ifp == NULL) - return 0; - - if_update_to_new_vrf(ifp, nvrfid); - - return 0; -} - static void bfdd_sessions_enable_address(struct connected *ifc) { struct bfd_session_observer *bso; @@ -833,9 +819,6 @@ static zclient_handler *const bfd_handlers[] = { */ [ZEBRA_BFD_DEST_REPLAY] = bfdd_replay, - /* Learn about interface VRF. */ - [ZEBRA_INTERFACE_VRF_UPDATE] = bfdd_interface_vrf_update, - /* Learn about new addresses being registered. */ [ZEBRA_INTERFACE_ADDRESS_ADD] = bfdd_interface_address_update, [ZEBRA_INTERFACE_ADDRESS_DELETE] = bfdd_interface_address_update, @@ -843,7 +826,8 @@ static zclient_handler *const bfd_handlers[] = { void bfdd_zclient_init(struct zebra_privs_t *bfdd_priv) { - if_zapi_callbacks(bfd_ifp_create, NULL, NULL, bfd_ifp_destroy); + hook_register_prio(if_real, 0, bfd_ifp_create); + hook_register_prio(if_unreal, 0, bfd_ifp_destroy); zclient = zclient_new(master, &zclient_options_default, bfd_handlers, array_size(bfd_handlers)); assert(zclient != NULL); @@ -875,6 +859,11 @@ void bfdd_zclient_stop(void) pc_free_all(); } +void bfdd_zclient_terminate(void) +{ + zclient_free(zclient); +} + /* * Client handling. diff --git a/bgpd/bgp_addpath.c b/bgpd/bgp_addpath.c index 7f746541ff..f391c13847 100644 --- a/bgpd/bgp_addpath.c +++ b/bgpd/bgp_addpath.c @@ -10,6 +10,8 @@ #include "bgp_addpath.h" #include "bgp_route.h" +#include "bgp_open.h" +#include "bgp_packet.h" static const struct bgp_addpath_strategy_names strat_names[BGP_ADDPATH_MAX] = { { @@ -25,7 +27,14 @@ static const struct bgp_addpath_strategy_names strat_names[BGP_ADDPATH_MAX] = { .human_description = "Advertise bestpath per AS via addpath", .type_json_name = "addpathTxBestpathPerAS", .id_json_name = "addpathTxIdBestPerAS" - } + }, + { + .config_name = "addpath-tx-best-selected", + .human_name = "Best-Selected", + .human_description = "Advertise best N selected paths via addpath", + .type_json_name = "addpathTxBestSelectedPaths", + .id_json_name = "addpathTxIdBestSelected" + }, }; static const struct bgp_addpath_strategy_names unknown_names = { @@ -161,6 +170,8 @@ bool bgp_addpath_tx_path(enum bgp_addpath_strat strat, struct bgp_path_info *pi) return true; else return false; + case BGP_ADDPATH_BEST_SELECTED: + return true; case BGP_ADDPATH_MAX: return false; } @@ -350,23 +361,52 @@ void bgp_addpath_type_changed(struct bgp *bgp) } } +int bgp_addpath_capability_action(enum bgp_addpath_strat addpath_type, + uint8_t paths) +{ + int action = CAPABILITY_ACTION_UNSET; + + switch (addpath_type) { + case BGP_ADDPATH_ALL: + case BGP_ADDPATH_BEST_PER_AS: + action = CAPABILITY_ACTION_SET; + break; + case BGP_ADDPATH_BEST_SELECTED: + if (paths) + action = CAPABILITY_ACTION_SET; + else + action = CAPABILITY_ACTION_UNSET; + break; + case BGP_ADDPATH_NONE: + case BGP_ADDPATH_MAX: + action = CAPABILITY_ACTION_UNSET; + break; + } + + return action; +} + /* * Change the addpath type assigned to a peer, or peer group. In addition to * adjusting the counts, peer sessions will be reset as needed to make the * change take effect. */ void bgp_addpath_set_peer_type(struct peer *peer, afi_t afi, safi_t safi, - enum bgp_addpath_strat addpath_type) + enum bgp_addpath_strat addpath_type, + uint8_t paths) { struct bgp *bgp = peer->bgp; enum bgp_addpath_strat old_type; struct listnode *node, *nnode; struct peer *tmp_peer; struct peer_group *group; + int action = bgp_addpath_capability_action(addpath_type, paths); if (safi == SAFI_LABELED_UNICAST) safi = SAFI_UNICAST; + peer->addpath_best_selected[afi][safi] = paths; + old_type = peer->addpath_type[afi][safi]; if (addpath_type == old_type) return; @@ -411,17 +451,19 @@ void bgp_addpath_set_peer_type(struct peer *peer, afi_t afi, safi_t safi, tmp_peer)) { if (tmp_peer->addpath_type[afi][safi] == old_type) { - bgp_addpath_set_peer_type(tmp_peer, - afi, - safi, - addpath_type); + bgp_addpath_set_peer_type( + tmp_peer, afi, safi, + addpath_type, paths); } } } } else { - peer_change_action(peer, afi, safi, peer_change_reset); + if (!CHECK_FLAG(peer->cap, PEER_CAP_DYNAMIC_RCV) && + !CHECK_FLAG(peer->cap, PEER_CAP_DYNAMIC_ADV)) + peer_change_action(peer, afi, safi, peer_change_reset); } + bgp_capability_send(peer, afi, safi, CAPABILITY_CODE_ADDPATH, action); } /* diff --git a/bgpd/bgp_addpath.h b/bgpd/bgp_addpath.h index 909a9710c4..d562000e30 100644 --- a/bgpd/bgp_addpath.h +++ b/bgpd/bgp_addpath.h @@ -15,6 +15,12 @@ #include "bgpd/bgp_table.h" #include "lib/json.h" +struct bgp_addpath_capability { + uint16_t afi; + uint8_t safi; + uint8_t flags; +}; + #define BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE 1 void bgp_addpath_init_bgp_data(struct bgp_addpath_bgp_data *d); @@ -50,10 +56,13 @@ bool bgp_addpath_tx_path(enum bgp_addpath_strat strat, * Change the type of addpath used for a peer. */ void bgp_addpath_set_peer_type(struct peer *peer, afi_t afi, safi_t safi, - enum bgp_addpath_strat addpath_type); + enum bgp_addpath_strat addpath_type, + uint8_t paths); void bgp_addpath_update_ids(struct bgp *bgp, struct bgp_dest *dest, afi_t afi, safi_t safi); void bgp_addpath_type_changed(struct bgp *bgp); +extern int bgp_addpath_capability_action(enum bgp_addpath_strat addpath_type, + uint8_t paths); #endif diff --git a/bgpd/bgp_addpath_types.h b/bgpd/bgp_addpath_types.h index 3de9546a6d..8e32b0444a 100644 --- a/bgpd/bgp_addpath_types.h +++ b/bgpd/bgp_addpath_types.h @@ -12,6 +12,7 @@ enum bgp_addpath_strat { BGP_ADDPATH_ALL = 0, BGP_ADDPATH_BEST_PER_AS, + BGP_ADDPATH_BEST_SELECTED, BGP_ADDPATH_MAX, BGP_ADDPATH_NONE, }; diff --git a/bgpd/bgp_advertise.c b/bgpd/bgp_advertise.c index 9686b08a98..2ca3ffaa1a 100644 --- a/bgpd/bgp_advertise.c +++ b/bgpd/bgp_advertise.c @@ -36,6 +36,8 @@ struct bgp_advertise_attr *bgp_advertise_attr_new(void) void bgp_advertise_attr_free(struct bgp_advertise_attr *baa) { + bgp_advertise_attr_fifo_fini(&baa->fifo); + XFREE(MTYPE_BGP_ADVERTISE_ATTR, baa); } @@ -46,6 +48,9 @@ static void *bgp_advertise_attr_hash_alloc(void *p) baa = bgp_advertise_attr_new(); baa->attr = ref->attr; + + bgp_advertise_attr_fifo_init(&baa->fifo); + return baa; } @@ -83,21 +88,13 @@ void bgp_advertise_free(struct bgp_advertise *adv) void bgp_advertise_add(struct bgp_advertise_attr *baa, struct bgp_advertise *adv) { - adv->next = baa->adv; - if (baa->adv) - baa->adv->prev = adv; - baa->adv = adv; + bgp_advertise_attr_fifo_add_tail(&baa->fifo, adv); } void bgp_advertise_delete(struct bgp_advertise_attr *baa, struct bgp_advertise *adv) { - if (adv->next) - adv->next->prev = adv->prev; - if (adv->prev) - adv->prev->next = adv->next; - else - baa->adv = adv->next; + bgp_advertise_attr_fifo_del(&baa->fifo, adv); } struct bgp_advertise_attr *bgp_advertise_attr_intern(struct hash *hash, @@ -188,22 +185,22 @@ void bgp_adj_in_set(struct bgp_dest *dest, struct peer *peer, struct attr *attr, bgp_dest_lock_node(dest); } -void bgp_adj_in_remove(struct bgp_dest *dest, struct bgp_adj_in *bai) +void bgp_adj_in_remove(struct bgp_dest **dest, struct bgp_adj_in *bai) { bgp_attr_unintern(&bai->attr); - BGP_ADJ_IN_DEL(dest, bai); - bgp_dest_unlock_node(dest); + BGP_ADJ_IN_DEL(*dest, bai); + *dest = bgp_dest_unlock_node(*dest); peer_unlock(bai->peer); /* adj_in peer reference */ XFREE(MTYPE_BGP_ADJ_IN, bai); } -bool bgp_adj_in_unset(struct bgp_dest *dest, struct peer *peer, +bool bgp_adj_in_unset(struct bgp_dest **dest, struct peer *peer, uint32_t addpath_id) { struct bgp_adj_in *adj; struct bgp_adj_in *adj_next; - adj = dest->adj_in; + adj = (*dest)->adj_in; if (!adj) return false; @@ -215,33 +212,9 @@ bool bgp_adj_in_unset(struct bgp_dest *dest, struct peer *peer, bgp_adj_in_remove(dest, adj); adj = adj_next; - } - return true; -} - -void bgp_sync_init(struct peer *peer) -{ - afi_t afi; - safi_t safi; - struct bgp_synchronize *sync; - - FOREACH_AFI_SAFI (afi, safi) { - sync = XCALLOC(MTYPE_BGP_SYNCHRONISE, - sizeof(struct bgp_synchronize)); - bgp_adv_fifo_init(&sync->update); - bgp_adv_fifo_init(&sync->withdraw); - bgp_adv_fifo_init(&sync->withdraw_low); - peer->sync[afi][safi] = sync; + assert(*dest); } -} - -void bgp_sync_delete(struct peer *peer) -{ - afi_t afi; - safi_t safi; - FOREACH_AFI_SAFI (afi, safi) { - XFREE(MTYPE_BGP_SYNCHRONISE, peer->sync[afi][safi]); - } + return true; } diff --git a/bgpd/bgp_advertise.h b/bgpd/bgp_advertise.h index c5e2a5f216..7c3b23ab54 100644 --- a/bgpd/bgp_advertise.h +++ b/bgpd/bgp_advertise.h @@ -11,26 +11,19 @@ PREDECL_DLIST(bgp_adv_fifo); struct update_subgroup; +struct bgp_advertise; -/* BGP advertise attribute. */ -struct bgp_advertise_attr { - /* Head of advertisement pointer. */ - struct bgp_advertise *adv; +PREDECL_DLIST(bgp_advertise_attr_fifo); - /* Reference counter. */ - unsigned long refcnt; - - /* Attribute pointer to be announced. */ - struct attr *attr; -}; +struct bgp_advertise_attr; +/* BGP advertise attribute. */ struct bgp_advertise { /* FIFO for advertisement. */ struct bgp_adv_fifo_item fifo; - /* Link list for same attribute advertise. */ - struct bgp_advertise *next; - struct bgp_advertise *prev; + /* FIFO for this item in the bgp_advertise_attr fifo */ + struct bgp_advertise_attr_fifo_item item; /* Prefix information. */ struct bgp_dest *dest; @@ -45,8 +38,21 @@ struct bgp_advertise { struct bgp_path_info *pathi; }; +DECLARE_DLIST(bgp_advertise_attr_fifo, struct bgp_advertise, item); DECLARE_DLIST(bgp_adv_fifo, struct bgp_advertise, fifo); +/* BGP advertise attribute. */ +struct bgp_advertise_attr { + /* Head of advertisement pointer. */ + struct bgp_advertise_attr_fifo_head fifo; + + /* Reference counter. */ + unsigned long refcnt; + + /* Attribute pointer to be announced. */ + struct attr *attr; +}; + /* BGP adjacency out. */ struct bgp_adj_out { /* RB Tree of adjacency entries */ @@ -100,7 +106,6 @@ struct bgp_adj_in { struct bgp_synchronize { struct bgp_adv_fifo_head update; struct bgp_adv_fifo_head withdraw; - struct bgp_adv_fifo_head withdraw_low; }; /* BGP adjacency linked list. */ @@ -131,12 +136,10 @@ extern bool bgp_adj_out_lookup(struct peer *peer, struct bgp_dest *dest, uint32_t addpath_tx_id); extern void bgp_adj_in_set(struct bgp_dest *dest, struct peer *peer, struct attr *attr, uint32_t addpath_id); -extern bool bgp_adj_in_unset(struct bgp_dest *dest, struct peer *peer, +extern bool bgp_adj_in_unset(struct bgp_dest **dest, struct peer *peer, uint32_t addpath_id); -extern void bgp_adj_in_remove(struct bgp_dest *dest, struct bgp_adj_in *bai); +extern void bgp_adj_in_remove(struct bgp_dest **dest, struct bgp_adj_in *bai); -extern void bgp_sync_init(struct peer *peer); -extern void bgp_sync_delete(struct peer *peer); extern unsigned int bgp_advertise_attr_hash_key(const void *p); extern bool bgp_advertise_attr_hash_cmp(const void *p1, const void *p2); extern void bgp_advertise_add(struct bgp_advertise_attr *baa, diff --git a/bgpd/bgp_aspath.c b/bgpd/bgp_aspath.c index 2c0de43c9b..bc7e8939b4 100644 --- a/bgpd/bgp_aspath.c +++ b/bgpd/bgp_aspath.c @@ -21,6 +21,7 @@ #include "bgpd/bgp_debug.h" #include "bgpd/bgp_attr.h" #include "bgpd/bgp_errors.h" +#include "bgpd/bgp_filter.h" /* Attr. Flags and Attr. Type Code. */ #define AS_HEADER_SIZE 2 @@ -1015,8 +1016,6 @@ static struct assegment *aspath_aggregate_as_set_add(struct aspath *aspath, seg = seg->next; seg->next = asset; } - asset->type = AS_SET; - asset->length = 1; asset->as[0] = as; } else { /* Check this AS value already exists or not. */ @@ -1230,6 +1229,46 @@ bool aspath_private_as_check(struct aspath *aspath) return true; } +/* Replace all ASN instances of the regex rule with our own ASN */ +struct aspath *aspath_replace_regex_asn(struct aspath *aspath, + struct as_list *acl_list, as_t our_asn) +{ + struct aspath *new; + struct assegment *cur_seg; + struct as_list *cur_as_list; + struct as_filter *cur_as_filter; + char str_buf[ASPATH_STR_DEFAULT_LEN]; + uint32_t i; + + new = aspath_dup(aspath); + cur_seg = new->segments; + + while (cur_seg) { + cur_as_list = acl_list; + while (cur_as_list) { + cur_as_filter = cur_as_list->head; + while (cur_as_filter) { + for (i = 0; i < cur_seg->length; i++) { + snprintfrr(str_buf, + ASPATH_STR_DEFAULT_LEN, + ASN_FORMAT(new->asnotation), + &cur_seg->as[i]); + if (!regexec(cur_as_filter->reg, + str_buf, 0, NULL, 0)) + cur_seg->as[i] = our_asn; + } + cur_as_filter = cur_as_filter->next; + } + cur_as_list = cur_as_list->next; + } + cur_seg = cur_seg->next; + } + + aspath_str_update(new, false); + return new; +} + + /* Replace all instances of the target ASN with our own ASN */ struct aspath *aspath_replace_specific_asn(struct aspath *aspath, as_t target_asn, as_t our_asn) @@ -1368,7 +1407,8 @@ struct aspath *aspath_remove_private_asns(struct aspath *aspath, as_t peer_asn) last_new_seg = new_seg; seg = seg->next; } - + if (!aspath->refcnt) + aspath_free(aspath); aspath_str_update(new, false); return new; } @@ -1598,6 +1638,111 @@ struct aspath *aspath_filter_exclude(struct aspath *source, return newpath; } +struct aspath *aspath_filter_exclude_all(struct aspath *source) +{ + struct aspath *newpath; + + newpath = aspath_new(source->asnotation); + + aspath_str_update(newpath, false); + /* We are happy returning even an empty AS_PATH, because the + * administrator + * might expect this very behaviour. There's a mean to avoid this, if + * necessary, + * by having a match rule against certain AS_PATH regexps in the + * route-map index. + */ + aspath_free(source); + return newpath; +} + +struct aspath *aspath_filter_exclude_acl(struct aspath *source, + struct as_list *acl_list) +{ + struct assegment *cur_seg, *new_seg, *prev_seg, *next_seg; + struct as_list *cur_as_list; + struct as_filter *cur_as_filter; + char str_buf[ASPATH_STR_DEFAULT_LEN]; + uint32_t nb_as_del; + uint32_t i, j; + + cur_seg = source->segments; + prev_seg = NULL; + /* segments from source aspath */ + while (cur_seg) { + next_seg = cur_seg->next; + cur_as_list = acl_list; + nb_as_del = 0; + /* aspath filter list from acl_list */ + while (cur_as_list) { + cur_as_filter = cur_as_list->head; + while (cur_as_filter) { + for (i = 0; i < cur_seg->length; i++) { + if (cur_seg->as[i] == 0) + continue; + + snprintfrr(str_buf, + ASPATH_STR_DEFAULT_LEN, + ASN_FORMAT(source->asnotation), + &cur_seg->as[i]); + if (!regexec(cur_as_filter->reg, + str_buf, 0, NULL, 0)) { + cur_seg->as[i] = 0; + nb_as_del++; + } + } + + cur_as_filter = cur_as_filter->next; + } + + cur_as_list = cur_as_list->next; + } + /* full segment is excluded remove it */ + if (nb_as_del == cur_seg->length) { + if (cur_seg == source->segments) + /* first segment */ + source->segments = cur_seg->next; + else if (prev_seg) + prev_seg->next = cur_seg->next; + assegment_free(cur_seg); + } + /* change in segment size -> new allocation and replace segment*/ + else if (nb_as_del) { + new_seg = assegment_new(cur_seg->type, + cur_seg->length - nb_as_del); + j = 0; + for (i = 0; i < cur_seg->length; i++) { + if (cur_seg->as[i] == 0) + continue; + new_seg->as[j] = cur_seg->as[i]; + j++; + } + new_seg->next = next_seg; + if (cur_seg == source->segments) + /* first segment */ + source->segments = new_seg; + else if (prev_seg) + prev_seg->next = new_seg; + assegment_free(cur_seg); + prev_seg = new_seg; + } else + prev_seg = cur_seg; + cur_seg = next_seg; + } + + + aspath_str_update(source, false); + /* We are happy returning even an empty AS_PATH, because the + * administrator + * might expect this very behaviour. There's a mean to avoid this, if + * necessary, + * by having a match rule against certain AS_PATH regexps in the + * route-map index. + */ + return source; +} + + /* Add specified AS to the leftmost of aspath. */ static struct aspath *aspath_add_asns(struct aspath *aspath, as_t asno, uint8_t type, unsigned num) @@ -1748,7 +1893,7 @@ struct aspath *aspath_reconcile_as4(struct aspath *aspath, "[AS4] AS4PATHmangle: AS_CONFED_SEQUENCE falls across 2/4 ASN boundary somewhere, broken.."); hops = seg->length; } - /* fallthru */ + fallthrough; case AS_SEQUENCE: cpasns = MIN(seg->length, hops); hops -= seg->length; diff --git a/bgpd/bgp_aspath.h b/bgpd/bgp_aspath.h index 18af375c13..ebfc7d087d 100644 --- a/bgpd/bgp_aspath.h +++ b/bgpd/bgp_aspath.h @@ -8,6 +8,7 @@ #include "lib/json.h" #include "bgpd/bgp_route.h" +#include "bgpd/bgp_filter.h" /* AS path segment type. */ #define AS_SET 1 @@ -76,6 +77,9 @@ extern struct aspath *aspath_aggregate(struct aspath *as1, struct aspath *as2); extern struct aspath *aspath_prepend(struct aspath *as1, struct aspath *as2); extern struct aspath *aspath_filter_exclude(struct aspath *source, struct aspath *exclude_list); +extern struct aspath *aspath_filter_exclude_all(struct aspath *source); +extern struct aspath *aspath_filter_exclude_acl(struct aspath *source, + struct as_list *acl_list); extern struct aspath *aspath_add_seq_n(struct aspath *aspath, as_t asno, unsigned num); extern struct aspath *aspath_add_seq(struct aspath *aspath, as_t asno); @@ -103,6 +107,9 @@ extern unsigned int aspath_get_last_as(struct aspath *aspath); extern int aspath_loop_check(struct aspath *aspath, as_t asno); extern int aspath_loop_check_confed(struct aspath *aspath, as_t asno); extern bool aspath_private_as_check(struct aspath *aspath); +extern struct aspath *aspath_replace_regex_asn(struct aspath *aspath, + struct as_list *acl_list, + as_t our_asn); extern struct aspath *aspath_replace_specific_asn(struct aspath *aspath, as_t target_asn, as_t our_asn); diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index ec9f12d61a..75aa2ac7cc 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -167,6 +167,9 @@ static struct cluster_list *cluster_intern(struct cluster_list *cluster) static void cluster_unintern(struct cluster_list **cluster) { + if (!*cluster) + return; + if ((*cluster)->refcnt) (*cluster)->refcnt--; @@ -330,6 +333,10 @@ static void encap_unintern(struct bgp_attr_encap_subtlv **encapp, encap_subtlv_type type) { struct bgp_attr_encap_subtlv *encap = *encapp; + + if (!*encapp) + return; + if (encap->refcnt) encap->refcnt--; @@ -418,6 +425,9 @@ static struct transit *transit_intern(struct transit *transit) static void transit_unintern(struct transit **transit) { + if (!*transit) + return; + if ((*transit)->refcnt) (*transit)->refcnt--; @@ -492,6 +502,7 @@ static bool bgp_attr_aigp_valid(uint8_t *pnt, int length) uint8_t *data = pnt; uint8_t tlv_type; uint16_t tlv_length; + uint8_t *end = data + length; if (length < 3) { zlog_err("Bad AIGP attribute length (MUST be minimum 3): %u", @@ -500,7 +511,13 @@ static bool bgp_attr_aigp_valid(uint8_t *pnt, int length) } while (length) { + size_t data_len = end - data; + tlv_type = *data; + + if (data_len - 1 < 2) + return false; + ptr_get_be16(data + 1, &tlv_length); (void)data; @@ -558,6 +575,9 @@ static void srv6_l3vpn_unintern(struct bgp_attr_srv6_l3vpn **l3vpnp) { struct bgp_attr_srv6_l3vpn *l3vpn = *l3vpnp; + if (!*l3vpnp) + return; + if (l3vpn->refcnt) l3vpn->refcnt--; @@ -593,6 +613,9 @@ static void srv6_vpn_unintern(struct bgp_attr_srv6_vpn **vpnp) { struct bgp_attr_srv6_vpn *vpn = *vpnp; + if (!*vpnp) + return; + if (vpn->refcnt) vpn->refcnt--; @@ -1183,6 +1206,7 @@ void bgp_attr_unintern_sub(struct attr *attr) struct cluster_list *cluster; struct lcommunity *lcomm = NULL; struct community *comm = NULL; + struct transit *transit; /* aspath refcount shoud be decrement. */ aspath_unintern(&attr->aspath); @@ -1205,37 +1229,25 @@ void bgp_attr_unintern_sub(struct attr *attr) bgp_attr_set_lcommunity(attr, NULL); cluster = bgp_attr_get_cluster(attr); - if (cluster) { - cluster_unintern(&cluster); - bgp_attr_set_cluster(attr, cluster); - } - UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)); + cluster_unintern(&cluster); + bgp_attr_set_cluster(attr, NULL); - struct transit *transit = bgp_attr_get_transit(attr); + transit = bgp_attr_get_transit(attr); + transit_unintern(&transit); + bgp_attr_set_transit(attr, NULL); - if (transit) { - transit_unintern(&transit); - bgp_attr_set_transit(attr, transit); - } - - if (attr->encap_subtlvs) - encap_unintern(&attr->encap_subtlvs, ENCAP_SUBTLV_TYPE); + encap_unintern(&attr->encap_subtlvs, ENCAP_SUBTLV_TYPE); #ifdef ENABLE_BGP_VNC struct bgp_attr_encap_subtlv *vnc_subtlvs = bgp_attr_get_vnc_subtlvs(attr); - if (vnc_subtlvs) { - encap_unintern(&vnc_subtlvs, VNC_SUBTLV_TYPE); - bgp_attr_set_vnc_subtlvs(attr, vnc_subtlvs); - } + encap_unintern(&vnc_subtlvs, VNC_SUBTLV_TYPE); + bgp_attr_set_vnc_subtlvs(attr, NULL); #endif - if (attr->srv6_l3vpn) - srv6_l3vpn_unintern(&attr->srv6_l3vpn); - - if (attr->srv6_vpn) - srv6_vpn_unintern(&attr->srv6_vpn); + srv6_l3vpn_unintern(&attr->srv6_l3vpn); + srv6_vpn_unintern(&attr->srv6_vpn); } /* Free bgp attribute and aspath. */ @@ -1356,7 +1368,8 @@ bgp_attr_malformed(struct bgp_attr_parser_args *args, uint8_t subcode, /* Only relax error handling for eBGP peers */ if (peer->sort != BGP_PEER_EBGP) { - bgp_notify_send_with_data(peer, BGP_NOTIFY_UPDATE_ERR, subcode, + bgp_notify_send_with_data(peer->connection, + BGP_NOTIFY_UPDATE_ERR, subcode, notify_datap, length); return BGP_ATTR_PARSE_ERROR; } @@ -1384,6 +1397,7 @@ bgp_attr_malformed(struct bgp_attr_parser_args *args, uint8_t subcode, */ case BGP_ATTR_ORIGIN: case BGP_ATTR_AS_PATH: + case BGP_ATTR_AS4_PATH: case BGP_ATTR_NEXT_HOP: case BGP_ATTR_MULTI_EXIT_DISC: case BGP_ATTR_LOCAL_PREF: @@ -1393,11 +1407,14 @@ bgp_attr_malformed(struct bgp_attr_parser_args *args, uint8_t subcode, case BGP_ATTR_LARGE_COMMUNITIES: case BGP_ATTR_ORIGINATOR_ID: case BGP_ATTR_CLUSTER_LIST: + case BGP_ATTR_PMSI_TUNNEL: + case BGP_ATTR_ENCAP: case BGP_ATTR_OTC: return BGP_ATTR_PARSE_WITHDRAW; case BGP_ATTR_MP_REACH_NLRI: case BGP_ATTR_MP_UNREACH_NLRI: - bgp_notify_send_with_data(peer, BGP_NOTIFY_UPDATE_ERR, subcode, + bgp_notify_send_with_data(peer->connection, + BGP_NOTIFY_UPDATE_ERR, subcode, notify_datap, length); return BGP_ATTR_PARSE_ERROR; } @@ -1753,7 +1770,8 @@ enum bgp_attr_parse_ret bgp_attr_nexthop_valid(struct peer *peer, data[1] = BGP_ATTR_NEXT_HOP; data[2] = BGP_ATTR_NHLEN_IPV4; memcpy(&data[3], &attr->nexthop.s_addr, BGP_ATTR_NHLEN_IPV4); - bgp_notify_send_with_data(peer, BGP_NOTIFY_UPDATE_ERR, + bgp_notify_send_with_data(peer->connection, + BGP_NOTIFY_UPDATE_ERR, BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP, data, 7); return BGP_ATTR_PARSE_ERROR; @@ -1821,7 +1839,9 @@ bgp_attr_local_pref(struct bgp_attr_parser_args *args) * UPDATE message SHALL be handled using the approach of "treat-as- * withdraw". */ - if (peer->sort == BGP_PEER_IBGP && length != 4) { + if ((peer->sort == BGP_PEER_IBGP || + peer->sub_sort == BGP_PEER_EBGP_OAD) && + length != 4) { flog_err(EC_BGP_ATTR_LEN, "LOCAL_PREF attribute length isn't 4 [%u]", length); return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, @@ -1831,7 +1851,7 @@ bgp_attr_local_pref(struct bgp_attr_parser_args *args) /* If it is contained in an UPDATE message that is received from an external peer, then this attribute MUST be ignored by the receiving speaker. */ - if (peer->sort == BGP_PEER_EBGP) { + if (peer->sort == BGP_PEER_EBGP && peer->sub_sort != BGP_PEER_EBGP_OAD) { STREAM_FORWARD_GETP(peer->curr, length); return BGP_ATTR_PARSE_PROCEED; } @@ -2138,6 +2158,15 @@ bgp_attr_originator_id(struct bgp_attr_parser_args *args) struct attr *const attr = args->attr; const bgp_size_t length = args->length; + /* if the ORIGINATOR_ID attribute is received from an external + * neighbor, it SHALL be discarded using the approach of "attribute + * discard". + */ + if (peer->sort == BGP_PEER_EBGP) { + stream_forward_getp(peer->curr, length); + return BGP_ATTR_PARSE_PROCEED; + } + /* if received from an internal neighbor, it SHALL be considered * malformed if its length is not equal to 4. If malformed, the * UPDATE message SHALL be handled using the approach of "treat-as- @@ -2174,6 +2203,15 @@ bgp_attr_cluster_list(struct bgp_attr_parser_args *args) struct attr *const attr = args->attr; const bgp_size_t length = args->length; + /* if the CLUSTER_LIST attribute is received from an external + * neighbor, it SHALL be discarded using the approach of "attribute + * discard". + */ + if (peer->sort == BGP_PEER_EBGP) { + stream_forward_getp(peer->curr, length); + return BGP_ATTR_PARSE_PROCEED; + } + /* if received from an internal neighbor, it SHALL be considered * malformed if its length is not a non-zero multiple of 4. If * malformed, the UPDATE message SHALL be handled using the approach @@ -2196,8 +2234,6 @@ bgp_attr_cluster_list(struct bgp_attr_parser_args *args) /* XXX: Fix cluster_parse to use stream API and then remove this */ stream_forward_getp(peer->curr, length); - attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST); - return BGP_ATTR_PARSE_PROCEED; cluster_list_ignore: @@ -2206,6 +2242,16 @@ bgp_attr_cluster_list(struct bgp_attr_parser_args *args) return bgp_attr_ignore(peer, args->type); } +/* get locally configure or received srte-color value*/ +uint32_t bgp_attr_get_color(struct attr *attr) +{ + if (attr->srte_color) + return attr->srte_color; + if (attr->ecommunity) + return ecommunity_select_color(attr->ecommunity); + return 0; +} + /* Multiprotocol reachability information parse. */ int bgp_mp_reach_parse(struct bgp_attr_parser_args *args, struct bgp_nlri *mp_update) @@ -2277,11 +2323,8 @@ int bgp_mp_reach_parse(struct bgp_attr_parser_args *args, /* * NOTE: intentional fall through * - for consistency in rx processing - * - * The following comment is to signal GCC this intention - * and suppress the warning */ - /* FALLTHRU */ + fallthrough; case BGP_ATTR_NHLEN_IPV4: stream_get(&attr->mp_nexthop_global_in, s, IPV4_MAX_BYTELEN); /* Probably needed for RFC 2283 */ @@ -2378,7 +2421,7 @@ int bgp_mp_reach_parse(struct bgp_attr_parser_args *args, mp_update->afi = afi; mp_update->safi = safi; - return BGP_ATTR_PARSE_EOR; + return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_MAL_ATTR, 0); } mp_update->afi = afi; @@ -2597,26 +2640,21 @@ bgp_attr_ipv6_ext_communities(struct bgp_attr_parser_args *args) } /* Parse Tunnel Encap attribute in an UPDATE */ -static int bgp_attr_encap(uint8_t type, struct peer *peer, /* IN */ - bgp_size_t length, /* IN: attr's length field */ - struct attr *attr, /* IN: caller already allocated */ - uint8_t flag, /* IN: attr's flags field */ - uint8_t *startp) +static int bgp_attr_encap(struct bgp_attr_parser_args *args) { - bgp_size_t total; uint16_t tunneltype = 0; - - total = length + (CHECK_FLAG(flag, BGP_ATTR_FLAG_EXTLEN) ? 4 : 3); + struct peer *const peer = args->peer; + struct attr *const attr = args->attr; + bgp_size_t length = args->length; + uint8_t type = args->type; + uint8_t flag = args->flags; if (!CHECK_FLAG(flag, BGP_ATTR_FLAG_TRANS) || !CHECK_FLAG(flag, BGP_ATTR_FLAG_OPTIONAL)) { - zlog_info( - "Tunnel Encap attribute flag isn't optional and transitive %d", - flag); - bgp_notify_send_with_data(peer, BGP_NOTIFY_UPDATE_ERR, - BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR, - startp, total); - return -1; + zlog_err("Tunnel Encap attribute flag isn't optional and transitive %d", + flag); + return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, + args->total); } if (BGP_ATTR_ENCAP == type) { @@ -2624,12 +2662,11 @@ static int bgp_attr_encap(uint8_t type, struct peer *peer, /* IN */ uint16_t tlv_length; if (length < 4) { - zlog_info( + zlog_err( "Tunnel Encap attribute not long enough to contain outer T,L"); - bgp_notify_send_with_data( - peer, BGP_NOTIFY_UPDATE_ERR, - BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, startp, total); - return -1; + return bgp_attr_malformed(args, + BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, + args->total); } tunneltype = stream_getw(BGP_INPUT(peer)); tlv_length = stream_getw(BGP_INPUT(peer)); @@ -2648,7 +2685,9 @@ static int bgp_attr_encap(uint8_t type, struct peer *peer, /* IN */ if (BGP_ATTR_ENCAP == type) { subtype = stream_getc(BGP_INPUT(peer)); - sublength = stream_getc(BGP_INPUT(peer)); + sublength = (subtype < 128) + ? stream_getc(BGP_INPUT(peer)) + : stream_getw(BGP_INPUT(peer)); length -= 2; #ifdef ENABLE_BGP_VNC } else { @@ -2659,13 +2698,11 @@ static int bgp_attr_encap(uint8_t type, struct peer *peer, /* IN */ } if (sublength > length) { - zlog_info( - "Tunnel Encap attribute sub-tlv length %d exceeds remaining length %d", - sublength, length); - bgp_notify_send_with_data( - peer, BGP_NOTIFY_UPDATE_ERR, - BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, startp, total); - return -1; + zlog_err("Tunnel Encap attribute sub-tlv length %d exceeds remaining length %d", + sublength, length); + return bgp_attr_malformed(args, + BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, + args->total); } /* alloc and copy sub-tlv */ @@ -2713,13 +2750,10 @@ static int bgp_attr_encap(uint8_t type, struct peer *peer, /* IN */ if (length) { /* spurious leftover data */ - zlog_info( - "Tunnel Encap attribute length is bad: %d leftover octets", - length); - bgp_notify_send_with_data(peer, BGP_NOTIFY_UPDATE_ERR, - BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, - startp, total); - return -1; + zlog_err("Tunnel Encap attribute length is bad: %d leftover octets", + length); + return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, + args->total); } return 0; @@ -3232,7 +3266,8 @@ static enum bgp_attr_parse_ret bgp_attr_aigp(struct bgp_attr_parser_args *args) * the default value of AIGP_SESSION SHOULD be "enabled". */ if (peer->sort == BGP_PEER_EBGP && - !CHECK_FLAG(peer->flags, PEER_FLAG_AIGP)) { + (!CHECK_FLAG(peer->flags, PEER_FLAG_AIGP) || + peer->sub_sort != BGP_PEER_EBGP_OAD)) { zlog_warn( "%pBP received AIGP attribute, but eBGP peer do not support it", peer); @@ -3350,23 +3385,19 @@ bgp_attr_unknown(struct bgp_attr_parser_args *args) } /* Well-known attribute check. */ -static int bgp_attr_check(struct peer *peer, struct attr *attr) +static int bgp_attr_check(struct peer *peer, struct attr *attr, + bgp_size_t length) { uint8_t type = 0; /* BGP Graceful-Restart End-of-RIB for IPv4 unicast is signaled as an - * empty UPDATE. */ - if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV) && !attr->flag) - return BGP_ATTR_PARSE_PROCEED; - - /* "An UPDATE message that contains the MP_UNREACH_NLRI is not required - to carry any other path attributes.", though if MP_REACH_NLRI or NLRI - are present, it should. Check for any other attribute being present - instead. + * empty UPDATE. Treat-as-withdraw, otherwise if we just ignore it, + * we will pass it to be processed as a normal UPDATE without mandatory + * attributes, that could lead to harmful behavior. */ - if ((!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI)) && - CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_UNREACH_NLRI)))) - return BGP_ATTR_PARSE_PROCEED; + if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV) && !attr->flag && + !length) + return BGP_ATTR_PARSE_WITHDRAW; if (!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN))) type = BGP_ATTR_ORIGIN; @@ -3386,6 +3417,16 @@ static int bgp_attr_check(struct peer *peer, struct attr *attr) && !CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))) type = BGP_ATTR_LOCAL_PREF; + /* An UPDATE message that contains the MP_UNREACH_NLRI is not required + * to carry any other path attributes. Though if MP_REACH_NLRI or NLRI + * are present, it should. Check for any other attribute being present + * instead. + */ + if (!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_REACH_NLRI)) && + CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MP_UNREACH_NLRI))) + return type ? BGP_ATTR_PARSE_MISSING_MANDATORY + : BGP_ATTR_PARSE_PROCEED; + /* If any of the well-known mandatory attributes are not present * in an UPDATE message, then "treat-as-withdraw" MUST be used. */ @@ -3408,7 +3449,7 @@ enum bgp_attr_parse_ret bgp_attr_parse(struct peer *peer, struct attr *attr, enum bgp_attr_parse_ret ret; uint8_t flag = 0; uint8_t type = 0; - bgp_size_t length; + bgp_size_t length = 0; uint8_t *startp, *endp; uint8_t *attr_endp; uint8_t seen[BGP_ATTR_BITMAP_SIZE]; @@ -3428,8 +3469,24 @@ enum bgp_attr_parse_ret bgp_attr_parse(struct peer *peer, struct attr *attr, /* Get attributes to the end of attribute length. */ while (BGP_INPUT_PNT(peer) < endp) { + startp = BGP_INPUT_PNT(peer); + + /* Fewer than three octets remain (or fewer than four + * octets, if the Attribute Flags field has the Extended + * Length bit set) when beginning to parse the attribute. + * That is, this case exists if there remains unconsumed + * data in the path attributes but yet insufficient data + * to encode a single minimum-sized path attribute. + * + * An error condition exists and the "treat-as-withdraw" + * approach MUST be used (unless some other, more severe + * error is encountered dictating a stronger approach), + * and the Total Attribute Length MUST be relied upon to + * enable the beginning of the NLRI field to be located. + */ + /* Check remaining length check.*/ - if (endp - BGP_INPUT_PNT(peer) < BGP_ATTR_MIN_LEN) { + if ((endp - startp) < BGP_ATTR_MIN_LEN) { /* XXX warning: long int format, int arg (arg 5) */ flog_warn( EC_BGP_ATTRIBUTE_TOO_SMALL, @@ -3438,17 +3495,23 @@ enum bgp_attr_parse_ret bgp_attr_parse(struct peer *peer, struct attr *attr, (unsigned long)(endp - stream_pnt(BGP_INPUT(peer)))); - bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR, - BGP_NOTIFY_UPDATE_ATTR_LENG_ERR); - ret = BGP_ATTR_PARSE_ERROR; + if (peer->sort != BGP_PEER_EBGP) { + bgp_notify_send(peer->connection, + BGP_NOTIFY_UPDATE_ERR, + BGP_NOTIFY_UPDATE_ATTR_LENG_ERR); + ret = BGP_ATTR_PARSE_ERROR; + } else { + ret = BGP_ATTR_PARSE_WITHDRAW; + } + goto done; } - /* Fetch attribute flag and type. */ - startp = BGP_INPUT_PNT(peer); - /* "The lower-order four bits of the Attribute Flags octet are - unused. They MUST be zero when sent and MUST be ignored when - received." */ + /* Fetch attribute flag and type. + * The lower-order four bits of the Attribute Flags octet are + * unused. They MUST be zero when sent and MUST be ignored when + * received. + */ flag = 0xF0 & stream_getc(BGP_INPUT(peer)); type = stream_getc(BGP_INPUT(peer)); @@ -3462,9 +3525,15 @@ enum bgp_attr_parse_ret bgp_attr_parse(struct peer *peer, struct attr *attr, (unsigned long)(endp - stream_pnt(BGP_INPUT(peer)))); - bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR, - BGP_NOTIFY_UPDATE_ATTR_LENG_ERR); - ret = BGP_ATTR_PARSE_ERROR; + if (peer->sort != BGP_PEER_EBGP) { + bgp_notify_send(peer->connection, + BGP_NOTIFY_UPDATE_ERR, + BGP_NOTIFY_UPDATE_ATTR_LENG_ERR); + ret = BGP_ATTR_PARSE_ERROR; + } else { + ret = BGP_ATTR_PARSE_WITHDRAW; + } + goto done; } @@ -3474,27 +3543,6 @@ enum bgp_attr_parse_ret bgp_attr_parse(struct peer *peer, struct attr *attr, else length = stream_getc(BGP_INPUT(peer)); - /* If any attribute appears more than once in the UPDATE - message, then the Error Subcode is set to Malformed Attribute - List. */ - - if (CHECK_BITMAP(seen, type)) { - flog_warn( - EC_BGP_ATTRIBUTE_REPEATED, - "%s: error BGP attribute type %d appears twice in a message", - peer->host, type); - - bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR, - BGP_NOTIFY_UPDATE_MAL_ATTR); - ret = BGP_ATTR_PARSE_ERROR; - goto done; - } - - /* Set type to bitmap to check duplicate attribute. `type' is - unsigned char so it never overflow bitmap range. */ - - SET_BITMAP(seen, type); - /* Overflow check. */ attr_endp = BGP_INPUT_PNT(peer) + length; @@ -3504,50 +3552,108 @@ enum bgp_attr_parse_ret bgp_attr_parse(struct peer *peer, struct attr *attr, "%s: BGP type %d length %d is too large, attribute total length is %d. attr_endp is %p. endp is %p", peer->host, type, length, size, attr_endp, endp); - /* - * RFC 4271 6.3 - * If any recognized attribute has an Attribute - * Length that conflicts with the expected length - * (based on the attribute type code), then the - * Error Subcode MUST be set to Attribute Length - * Error. The Data field MUST contain the erroneous - * attribute (type, length, and value). - * ---------- - * We do not currently have a good way to determine the - * length of the attribute independent of the length - * received in the message. Instead we send the - * minimum between the amount of data we have and the - * amount specified by the attribute length field. - * - * Instead of directly passing in the packet buffer and - * offset we use the stream_get* functions to read into - * a stack buffer, since they perform bounds checking - * and we are working with untrusted data. - */ - unsigned char ndata[peer->max_packet_size]; - memset(ndata, 0x00, sizeof(ndata)); - size_t lfl = - CHECK_FLAG(flag, BGP_ATTR_FLAG_EXTLEN) ? 2 : 1; - /* Rewind to end of flag field */ - stream_rewind_getp(BGP_INPUT(peer), (1 + lfl)); - /* Type */ - stream_get(&ndata[0], BGP_INPUT(peer), 1); - /* Length */ - stream_get(&ndata[1], BGP_INPUT(peer), lfl); - /* Value */ - size_t atl = attr_endp - startp; - size_t ndl = MIN(atl, STREAM_READABLE(BGP_INPUT(peer))); - stream_get(&ndata[lfl + 1], BGP_INPUT(peer), ndl); - - bgp_notify_send_with_data( - peer, BGP_NOTIFY_UPDATE_ERR, - BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, ndata, - ndl + lfl + 1); - ret = BGP_ATTR_PARSE_ERROR; - goto done; + /* Only relax error handling for eBGP peers */ + if (peer->sort != BGP_PEER_EBGP) { + /* + * RFC 4271 6.3 + * If any recognized attribute has an Attribute + * Length that conflicts with the expected length + * (based on the attribute type code), then the + * Error Subcode MUST be set to Attribute Length + * Error. The Data field MUST contain the erroneous + * attribute (type, length, and value). + * ---------- + * We do not currently have a good way to determine the + * length of the attribute independent of the length + * received in the message. Instead we send the + * minimum between the amount of data we have and the + * amount specified by the attribute length field. + * + * Instead of directly passing in the packet buffer and + * offset we use the stream_get* functions to read into + * a stack buffer, since they perform bounds checking + * and we are working with untrusted data. + */ + unsigned char ndata[peer->max_packet_size]; + + memset(ndata, 0x00, sizeof(ndata)); + size_t lfl = + CHECK_FLAG(flag, BGP_ATTR_FLAG_EXTLEN) ? 2 : 1; + /* Rewind to end of flag field */ + stream_rewind_getp(BGP_INPUT(peer), (1 + lfl)); + /* Type */ + stream_get(&ndata[0], BGP_INPUT(peer), 1); + /* Length */ + stream_get(&ndata[1], BGP_INPUT(peer), lfl); + /* Value */ + size_t atl = attr_endp - startp; + size_t ndl = MIN(atl, STREAM_READABLE(BGP_INPUT(peer))); + + stream_get(&ndata[lfl + 1], BGP_INPUT(peer), ndl); + + bgp_notify_send_with_data(peer->connection, + BGP_NOTIFY_UPDATE_ERR, + BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, + ndata, ndl + lfl + 1); + + ret = BGP_ATTR_PARSE_ERROR; + goto done; + } else { + /* Handling as per RFC7606 section 4, treat-as-withdraw approach + * must be followed when the total attribute length is in conflict + * with the enclosed path attribute length. + */ + flog_warn( + EC_BGP_ATTRIBUTE_PARSE_WITHDRAW, + "%s: Attribute %s, parse error - treating as withdrawal", + peer->host, lookup_msg(attr_str, type, NULL)); + ret = BGP_ATTR_PARSE_WITHDRAW; + stream_forward_getp(BGP_INPUT(peer), endp - BGP_INPUT_PNT(peer)); + goto done; + } + } + + /* If attribute appears more than once in the UPDATE message, + * for MP_REACH_NLRI & MP_UNREACH_NLRI attributes + * the Error Subcode is set to Malformed Attribute List. + * For all other attributes, all the occurances of the attribute + * other than the first occurence is discarded. (RFC7606 3g) + */ + + if (CHECK_BITMAP(seen, type)) { + /* Only relax error handling for eBGP peers */ + if (peer->sort != BGP_PEER_EBGP || + type == BGP_ATTR_MP_REACH_NLRI || type == BGP_ATTR_MP_UNREACH_NLRI) { + flog_warn( + EC_BGP_ATTRIBUTE_REPEATED, + "%s: error BGP attribute type %d appears twice in a message", + peer->host, type); + + bgp_notify_send(peer->connection, + BGP_NOTIFY_UPDATE_ERR, + BGP_NOTIFY_UPDATE_MAL_ATTR); + ret = BGP_ATTR_PARSE_ERROR; + goto done; + } else { + flog_warn( + EC_BGP_ATTRIBUTE_REPEATED, + "%s: error BGP attribute type %d appears twice in a message - discard attribute", + peer->host, type); + /* Adjust the stream getp to the end of the attribute, in case we + * haven't read all the attributes. + */ + stream_set_getp(BGP_INPUT(peer), + (startp - STREAM_DATA(BGP_INPUT(peer))) + (attr_endp - startp)); + continue; + } } + /* Set type to bitmap to check duplicate attribute. `type' is + unsigned char so it never overflow bitmap range. */ + + SET_BITMAP(seen, type); + struct bgp_attr_parser_args attr_args = { .peer = peer, .length = length, @@ -3570,6 +3676,7 @@ enum bgp_attr_parse_ret bgp_attr_parse(struct peer *peer, struct attr *attr, attr_args.total); if (ret == BGP_ATTR_PARSE_PROCEED) continue; + stream_forward_getp(BGP_INPUT(peer), endp - BGP_INPUT_PNT(peer)); goto done; } @@ -3629,8 +3736,7 @@ enum bgp_attr_parse_ret bgp_attr_parse(struct peer *peer, struct attr *attr, case BGP_ATTR_VNC: #endif case BGP_ATTR_ENCAP: - ret = bgp_attr_encap(type, peer, length, attr, flag, - startp); + ret = bgp_attr_encap(&attr_args); break; case BGP_ATTR_PREFIX_SID: ret = bgp_attr_prefix_sid(&attr_args); @@ -3653,16 +3759,12 @@ enum bgp_attr_parse_ret bgp_attr_parse(struct peer *peer, struct attr *attr, } if (ret == BGP_ATTR_PARSE_ERROR_NOTIFYPLS) { - bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR, + bgp_notify_send(peer->connection, BGP_NOTIFY_UPDATE_ERR, BGP_NOTIFY_UPDATE_MAL_ATTR); ret = BGP_ATTR_PARSE_ERROR; goto done; } - if (ret == BGP_ATTR_PARSE_EOR) { - goto done; - } - if (ret == BGP_ATTR_PARSE_ERROR) { flog_warn(EC_BGP_ATTRIBUTE_PARSE_ERROR, "%s: Attribute %s, parse error", peer->host, @@ -3674,6 +3776,7 @@ enum bgp_attr_parse_ret bgp_attr_parse(struct peer *peer, struct attr *attr, EC_BGP_ATTRIBUTE_PARSE_WITHDRAW, "%s: Attribute %s, parse error - treating as withdrawal", peer->host, lookup_msg(attr_str, type, NULL)); + stream_forward_getp(BGP_INPUT(peer), endp - BGP_INPUT_PNT(peer)); goto done; } @@ -3682,7 +3785,7 @@ enum bgp_attr_parse_ret bgp_attr_parse(struct peer *peer, struct attr *attr, flog_warn(EC_BGP_ATTRIBUTE_FETCH_ERROR, "%s: BGP attribute %s, fetch error", peer->host, lookup_msg(attr_str, type, NULL)); - bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR, + bgp_notify_send(peer->connection, BGP_NOTIFY_UPDATE_ERR, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR); ret = BGP_ATTR_PARSE_ERROR; goto done; @@ -3705,7 +3808,7 @@ enum bgp_attr_parse_ret bgp_attr_parse(struct peer *peer, struct attr *attr, flog_warn(EC_BGP_ATTRIBUTES_MISMATCH, "%s: BGP attribute %s, length mismatch", peer->host, lookup_msg(attr_str, type, NULL)); - bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR, + bgp_notify_send(peer->connection, BGP_NOTIFY_UPDATE_ERR, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR); ret = BGP_ATTR_PARSE_ERROR; @@ -3734,7 +3837,7 @@ enum bgp_attr_parse_ret bgp_attr_parse(struct peer *peer, struct attr *attr, } /* Check all mandatory well-known attributes are present */ - ret = bgp_attr_check(peer, attr); + ret = bgp_attr_check(peer, attr, length); if (ret < 0) goto done; @@ -3757,7 +3860,7 @@ enum bgp_attr_parse_ret bgp_attr_parse(struct peer *peer, struct attr *attr, if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH)) && bgp_attr_munge_as4_attrs(peer, attr, as4_path, as4_aggregator, &as4_aggregator_addr)) { - bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR, + bgp_notify_send(peer->connection, BGP_NOTIFY_UPDATE_ERR, BGP_NOTIFY_UPDATE_MAL_ATTR); ret = BGP_ATTR_PARSE_ERROR; goto done; @@ -3790,7 +3893,13 @@ enum bgp_attr_parse_ret bgp_attr_parse(struct peer *peer, struct attr *attr, aspath_unintern(&as4_path); transit = bgp_attr_get_transit(attr); - if (ret != BGP_ATTR_PARSE_ERROR) { + /* If we received an UPDATE with mandatory attributes, then + * the unrecognized transitive optional attribute of that + * path MUST be passed. Otherwise, it's an error, and from + * security perspective it might be very harmful if we continue + * here with the unrecognized attributes. + */ + if (ret == BGP_ATTR_PARSE_PROCEED) { /* Finally intern unknown attribute. */ if (transit) bgp_attr_set_transit(attr, transit_intern(transit)); @@ -4383,7 +4492,8 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer, } /* Local preference. */ - if (peer->sort == BGP_PEER_IBGP || peer->sort == BGP_PEER_CONFED) { + if (peer->sort == BGP_PEER_IBGP || peer->sort == BGP_PEER_CONFED || + peer->sub_sort == BGP_PEER_EBGP_OAD) { stream_putc(s, BGP_ATTR_FLAG_TRANS); stream_putc(s, BGP_ATTR_LOCAL_PREF); stream_putc(s, 4); @@ -4749,6 +4859,7 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer, /* AIGP */ if (bpi && attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AIGP) && (CHECK_FLAG(peer->flags, PEER_FLAG_AIGP) || + peer->sub_sort == BGP_PEER_EBGP_OAD || peer->sort != BGP_PEER_EBGP)) { /* At the moment only AIGP Metric TLV exists for AIGP * attribute. If more comes in, do not forget to update @@ -5050,7 +5161,7 @@ void bgp_path_attribute_discard_vty(struct vty *vty, struct peer *peer, * then flush all. */ if (!discard_attrs) { - for (i = 0; i < BGP_ATTR_MAX; i++) + for (i = 1; i <= BGP_ATTR_MAX; i++) peer->discard_attrs[i] = false; goto discard_soft_clear; } @@ -5059,7 +5170,7 @@ void bgp_path_attribute_discard_vty(struct vty *vty, struct peer *peer, frrstr_split(discard_attrs, " ", &attributes, &num_attributes); if (set) - for (i = 0; i < BGP_ATTR_MAX; i++) + for (i = 1; i <= BGP_ATTR_MAX; i++) peer->discard_attrs[i] = false; for (i = 0; i < num_attributes; i++) { @@ -5119,7 +5230,7 @@ void bgp_path_attribute_withdraw_vty(struct vty *vty, struct peer *peer, * then flush all. */ if (!withdraw_attrs) { - for (i = 0; i < BGP_ATTR_MAX; i++) + for (i = 1; i <= BGP_ATTR_MAX; i++) peer->withdraw_attrs[i] = false; goto withdraw_soft_clear; } @@ -5128,7 +5239,7 @@ void bgp_path_attribute_withdraw_vty(struct vty *vty, struct peer *peer, frrstr_split(withdraw_attrs, " ", &attributes, &num_attributes); if (set) - for (i = 0; i < BGP_ATTR_MAX; i++) + for (i = 1; i <= BGP_ATTR_MAX; i++) peer->withdraw_attrs[i] = false; for (i = 0; i < num_attributes; i++) { @@ -5189,3 +5300,18 @@ enum bgp_attr_parse_ret bgp_attr_ignore(struct peer *peer, uint8_t type) return withdraw ? BGP_ATTR_PARSE_WITHDRAW : BGP_ATTR_PARSE_PROCEED; } + +bool route_matches_soo(struct bgp_path_info *pi, struct ecommunity *soo) +{ + struct attr *attr = pi->attr; + struct ecommunity *ecom; + + if (!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))) + return false; + + ecom = attr->ecommunity; + if (!ecom || !ecom->size) + return false; + + return soo_in_ecom(ecom, soo); +} diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h index 1c7e88a4f9..d30155e6db 100644 --- a/bgpd/bgp_attr.h +++ b/bgpd/bgp_attr.h @@ -364,7 +364,7 @@ enum bgp_attr_parse_ret { /* only used internally, send notify + convert to BGP_ATTR_PARSE_ERROR */ BGP_ATTR_PARSE_ERROR_NOTIFYPLS = -3, - BGP_ATTR_PARSE_EOR = -4, + BGP_ATTR_PARSE_MISSING_MANDATORY = -4, }; struct bpacket_attr_vec_arr; @@ -466,6 +466,8 @@ extern void bgp_packet_mpunreach_end(struct stream *s, size_t attrlen_pnt); extern enum bgp_attr_parse_ret bgp_attr_nexthop_valid(struct peer *peer, struct attr *attr); +extern uint32_t bgp_attr_get_color(struct attr *attr); + static inline bool bgp_rmap_nhop_changed(uint32_t out_rmap_flags, uint32_t in_rmap_flags) { @@ -592,7 +594,7 @@ static inline void bgp_attr_set_aigp_metric(struct attr *attr, uint64_t aigp) attr->aigp_metric = aigp; if (aigp) - attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_AIGP); + SET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AIGP)); } static inline struct cluster_list *bgp_attr_get_cluster(const struct attr *attr) @@ -604,6 +606,11 @@ static inline void bgp_attr_set_cluster(struct attr *attr, struct cluster_list *cl) { attr->cluster1 = cl; + + if (cl) + SET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)); + else + UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)); } static inline const struct bgp_route_evpn * @@ -637,4 +644,6 @@ bgp_attr_set_vnc_subtlvs(struct attr *attr, #endif } +extern bool route_matches_soo(struct bgp_path_info *pi, struct ecommunity *soo); + #endif /* _QUAGGA_BGP_ATTR_H */ diff --git a/bgpd/bgp_bfd.c b/bgpd/bgp_bfd.c index d1ddfd0460..85d4035a17 100644 --- a/bgpd/bgp_bfd.c +++ b/bgpd/bgp_bfd.c @@ -56,18 +56,18 @@ static void bfd_session_status_update(struct bfd_session_params *bsp, peer->last_reset = PEER_DOWN_BFD_DOWN; /* rfc9384 */ - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_BFD_DOWN); - BGP_EVENT_ADD(peer, BGP_Stop); + BGP_EVENT_ADD(peer->connection, BGP_Stop); } - if (bss->state == BSS_UP && bss->previous_state != BSS_UP - && !peer_established(peer)) { + if (bss->state == BSS_UP && bss->previous_state != BSS_UP && + !peer_established(peer->connection)) { if (!BGP_PEER_START_SUPPRESSED(peer)) { - bgp_fsm_nht_update(peer, true); - BGP_EVENT_ADD(peer, BGP_Start); + bgp_fsm_nht_update(peer->connection, peer, true); + BGP_EVENT_ADD(peer->connection, BGP_Start); } } } @@ -163,36 +163,35 @@ void bgp_peer_bfd_update_source(struct peer *p) /* Update peer's source/destination addresses. */ bfd_sess_addresses(session, &family, &src.v6, &dst.v6); if (family == AF_INET) { - if ((source && source->sin.sin_addr.s_addr != src.v4.s_addr) - || p->su.sin.sin_addr.s_addr != dst.v4.s_addr) { + if ((source && source->sin.sin_addr.s_addr != src.v4.s_addr) || + p->connection->su.sin.sin_addr.s_addr != dst.v4.s_addr) { if (BGP_DEBUG(bfd, BFD_LIB)) - zlog_debug( - "%s: address [%pI4->%pI4] to [%pI4->%pI4]", - __func__, &src.v4, &dst.v4, - source ? &source->sin.sin_addr - : &src.v4, - &p->su.sin.sin_addr); - - bfd_sess_set_ipv4_addrs( - session, source ? &source->sin.sin_addr : NULL, - &p->su.sin.sin_addr); + zlog_debug("%s: address [%pI4->%pI4] to [%pI4->%pI4]", + __func__, &src.v4, &dst.v4, + source ? &source->sin.sin_addr + : &src.v4, + &p->connection->su.sin.sin_addr); + + bfd_sess_set_ipv4_addrs(session, + source ? &source->sin.sin_addr + : NULL, + &p->connection->su.sin.sin_addr); changed = true; } } else { - if ((source && memcmp(&source->sin6, &src.v6, sizeof(src.v6))) - || memcmp(&p->su.sin6, &dst.v6, sizeof(dst.v6))) { + if ((source && memcmp(&source->sin6, &src.v6, sizeof(src.v6))) || + memcmp(&p->connection->su.sin6, &dst.v6, sizeof(dst.v6))) { if (BGP_DEBUG(bfd, BFD_LIB)) - zlog_debug( - "%s: address [%pI6->%pI6] to [%pI6->%pI6]", - __func__, &src.v6, &dst.v6, - source ? &source->sin6.sin6_addr - : &src.v6, - &p->su.sin6.sin6_addr); + zlog_debug("%s: address [%pI6->%pI6] to [%pI6->%pI6]", + __func__, &src.v6, &dst.v6, + source ? &source->sin6.sin6_addr + : &src.v6, + &p->connection->su.sin6.sin6_addr); bfd_sess_set_ipv6_addrs(session, source ? &source->sin6.sin6_addr : NULL, - &p->su.sin6.sin6_addr); + &p->connection->su.sin6.sin6_addr); changed = true; } } @@ -284,16 +283,17 @@ void bgp_peer_configure_bfd(struct peer *p, bool manual) bgp_peer_bfd_reset(p); /* Configure session with basic BGP peer data. */ - if (p->su.sa.sa_family == AF_INET) + if (p->connection->su.sa.sa_family == AF_INET) bfd_sess_set_ipv4_addrs(p->bfd_config->session, p->su_local ? &p->su_local->sin.sin_addr : NULL, - &p->su.sin.sin_addr); + &p->connection->su.sin.sin_addr); else - bfd_sess_set_ipv6_addrs( - p->bfd_config->session, - p->su_local ? &p->su_local->sin6.sin6_addr : NULL, - &p->su.sin6.sin6_addr); + bfd_sess_set_ipv6_addrs(p->bfd_config->session, + p->su_local + ? &p->su_local->sin6.sin6_addr + : NULL, + &p->connection->su.sin6.sin6_addr); bfd_sess_set_vrf(p->bfd_config->session, p->bgp->vrf_id); bfd_sess_set_hop_count(p->bfd_config->session, @@ -321,7 +321,7 @@ static void bgp_peer_remove_bfd(struct peer *p) } if (p->bfd_config) - bfd_sess_free(&p->bfd_config->session); + bfd_sess_free(&p->bfd_config->session); XFREE(MTYPE_BFD_CONFIG, p->bfd_config); } diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c index baf164679c..6a55432e14 100644 --- a/bgpd/bgp_bmp.c +++ b/bgpd/bgp_bmp.c @@ -240,60 +240,115 @@ static void bmp_free(struct bmp *bmp) XFREE(MTYPE_BMP_CONN, bmp); } +#define BMP_PEER_TYPE_GLOBAL_INSTANCE 0 +#define BMP_PEER_TYPE_RD_INSTANCE 1 +#define BMP_PEER_TYPE_LOCAL_INSTANCE 2 +#define BMP_PEER_TYPE_LOC_RIB_INSTANCE 3 + +static inline int bmp_get_peer_distinguisher(struct bmp *bmp, afi_t afi, + uint8_t peer_type, + uint64_t *result_ref) +{ + + /* remove this check when the other peer types get correct peer dist. + *(RFC7854) impl. + * for now, always return no error and 0 peer distinguisher as before + */ + if (peer_type != BMP_PEER_TYPE_LOC_RIB_INSTANCE) + return (*result_ref = 0); + + /* sending vrf_id or rd could be turned into an option at some point */ + struct bgp *bgp = bmp->targets->bgp; + + /* vrf default => ok, distinguisher 0 */ + if (bgp->inst_type == VRF_DEFAULT) + return (*result_ref = 0); + + /* use RD if set in VRF config for this AFI */ + struct prefix_rd *prd = &bgp->vpn_policy[afi].tovpn_rd; + + if (CHECK_FLAG(bgp->vpn_policy[afi].flags, + BGP_VPN_POLICY_TOVPN_RD_SET)) { + memcpy(result_ref, prd->val, sizeof(prd->val)); + return 0; + } + + /* VRF has no id => error => message should be skipped */ + if (bgp->vrf_id == VRF_UNKNOWN) + return 1; + + /* use VRF id converted to ::vrf_id 64bits format */ + *result_ref = ((uint64_t)htonl(bgp->vrf_id)) << 32; + return 0; +} + static void bmp_common_hdr(struct stream *s, uint8_t ver, uint8_t type) { stream_putc(s, ver); - stream_putl(s, 0); //dummy message length. will be set later. + stream_putl(s, 0); /* dummy message length. will be set later. */ stream_putc(s, type); } -static void bmp_per_peer_hdr(struct stream *s, struct peer *peer, - uint8_t flags, const struct timeval *tv) +static void bmp_per_peer_hdr(struct stream *s, struct bgp *bgp, + struct peer *peer, uint8_t flags, + uint8_t peer_type_flag, + uint64_t peer_distinguisher, + const struct timeval *tv) { - char peer_distinguisher[8]; - -#define BMP_PEER_TYPE_GLOBAL_INSTANCE 0 -#define BMP_PEER_TYPE_RD_INSTANCE 1 -#define BMP_PEER_TYPE_LOCAL_INSTANCE 2 - #define BMP_PEER_FLAG_V (1 << 7) #define BMP_PEER_FLAG_L (1 << 6) #define BMP_PEER_FLAG_A (1 << 5) + bool is_locrib = peer_type_flag == BMP_PEER_TYPE_LOC_RIB_INSTANCE; + /* Peer Type */ - stream_putc(s, BMP_PEER_TYPE_GLOBAL_INSTANCE); + stream_putc(s, peer_type_flag); /* Peer Flags */ - if (peer->su.sa.sa_family == AF_INET6) + if (!is_locrib && peer->connection->su.sa.sa_family == AF_INET6) SET_FLAG(flags, BMP_PEER_FLAG_V); else UNSET_FLAG(flags, BMP_PEER_FLAG_V); stream_putc(s, flags); /* Peer Distinguisher */ - memset (&peer_distinguisher[0], 0, 8); - stream_put(s, &peer_distinguisher[0], 8); + stream_put(s, (uint8_t *)&peer_distinguisher, 8); /* Peer Address */ - if (peer->su.sa.sa_family == AF_INET6) - stream_put(s, &peer->su.sin6.sin6_addr, 16); - else if (peer->su.sa.sa_family == AF_INET) { + /* Set to 0 if it's a LOC-RIB INSTANCE (RFC 9069) or if it's not an + * IPv4/6 address + */ + if (is_locrib || (peer->connection->su.sa.sa_family != AF_INET6 && + peer->connection->su.sa.sa_family != AF_INET)) { stream_putl(s, 0); stream_putl(s, 0); stream_putl(s, 0); - stream_put_in_addr(s, &peer->su.sin.sin_addr); - } else { stream_putl(s, 0); + } else if (peer->connection->su.sa.sa_family == AF_INET6) + stream_put(s, &peer->connection->su.sin6.sin6_addr, IPV6_MAX_BYTELEN); + else if (peer->connection->su.sa.sa_family == AF_INET) { stream_putl(s, 0); stream_putl(s, 0); stream_putl(s, 0); + stream_put_in_addr(s, &peer->connection->su.sin.sin_addr); } /* Peer AS */ - stream_putl(s, peer->as); + /* set peer ASN but for LOC-RIB INSTANCE (RFC 9069) put the local bgp + * ASN + */ + as_t asn = !is_locrib ? peer->as : bgp->as; + + stream_putl(s, asn); /* Peer BGP ID */ - stream_put_in_addr(s, &peer->remote_id); + /* set router-id but for LOC-RIB INSTANCE (RFC 9069) put the instance + * router-id + */ + struct in_addr *bgp_id = + !is_locrib ? &peer->remote_id : &bgp->router_id; + + stream_put_in_addr(s, bgp_id); /* Timestamp */ if (tv) { @@ -314,11 +369,26 @@ static void bmp_put_info_tlv(struct stream *s, uint16_t type, stream_put(s, string, len); } +static void __attribute__((unused)) +bmp_put_vrftablename_info_tlv(struct stream *s, struct bmp *bmp) +{ + +#define BMP_INFO_TYPE_VRFTABLENAME 3 + const char *vrftablename = "global"; + if (bmp->targets->bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT) { + struct vrf *vrf = vrf_lookup_by_id(bmp->targets->bgp->vrf_id); + + vrftablename = vrf ? vrf->name : NULL; + } + if (vrftablename != NULL) + bmp_put_info_tlv(s, BMP_INFO_TYPE_VRFTABLENAME, vrftablename); +} + static int bmp_send_initiation(struct bmp *bmp) { int len; - struct stream *s; - s = stream_new(BGP_MAX_PACKET_SIZE); + struct stream *s = stream_new(BGP_MAX_PACKET_SIZE); + bmp_common_hdr(s, BMP_VERSION_3, BMP_TYPE_INITIATION); #define BMP_INFO_TYPE_SYSDESCR 1 @@ -328,7 +398,7 @@ static int bmp_send_initiation(struct bmp *bmp) bmp_put_info_tlv(s, BMP_INFO_TYPE_SYSNAME, cmd_hostname_get()); len = stream_get_endp(s); - stream_putl_at(s, BMP_LENGTH_POS, len); //message length is set. + stream_putl_at(s, BMP_LENGTH_POS, len); /* message length is set. */ pullwr_write_stream(bmp->pullwr, s); stream_free(s); @@ -370,12 +440,14 @@ static struct stream *bmp_peerstate(struct peer *peer, bool down) #define BGP_BMP_MAX_PACKET_SIZE 1024 s = stream_new(BGP_MAX_PACKET_SIZE); - if (peer_established(peer) && !down) { + if (peer_established(peer->connection) && !down) { struct bmp_bgp_peer *bbpeer; bmp_common_hdr(s, BMP_VERSION_3, BMP_TYPE_PEER_UP_NOTIFICATION); - bmp_per_peer_hdr(s, peer, 0, &uptime_real); + bmp_per_peer_hdr(s, peer->bgp, peer, 0, + BMP_PEER_TYPE_GLOBAL_INSTANCE, 0, + &uptime_real); /* Local Address (16 bytes) */ if (peer->su_local->sa.sa_family == AF_INET6) @@ -428,7 +500,9 @@ static struct stream *bmp_peerstate(struct peer *peer, bool down) bmp_common_hdr(s, BMP_VERSION_3, BMP_TYPE_PEER_DOWN_NOTIFICATION); - bmp_per_peer_hdr(s, peer, 0, &uptime_real); + bmp_per_peer_hdr(s, peer->bgp, peer, 0, + BMP_PEER_TYPE_GLOBAL_INSTANCE, 0, + &uptime_real); type_pos = stream_get_endp(s); stream_putc(s, 0); /* placeholder for down reason */ @@ -460,7 +534,7 @@ static struct stream *bmp_peerstate(struct peer *peer, bool down) } len = stream_get_endp(s); - stream_putl_at(s, BMP_LENGTH_POS, len); //message length is set. + stream_putl_at(s, BMP_LENGTH_POS, len); /* message length is set. */ return s; } @@ -618,7 +692,8 @@ static void bmp_wrmirror_lost(struct bmp *bmp, struct pullwr *pullwr) s = stream_new(BGP_MAX_PACKET_SIZE); bmp_common_hdr(s, BMP_VERSION_3, BMP_TYPE_ROUTE_MIRRORING); - bmp_per_peer_hdr(s, bmp->targets->bgp->peer_self, 0, &tv); + bmp_per_peer_hdr(s, bmp->targets->bgp, bmp->targets->bgp->peer_self, 0, + BMP_PEER_TYPE_GLOBAL_INSTANCE, 0, &tv); stream_putw(s, BMP_MIRROR_TLV_TYPE_INFO); stream_putw(s, 2); @@ -656,7 +731,8 @@ static bool bmp_wrmirror(struct bmp *bmp, struct pullwr *pullwr) s = stream_new(BGP_MAX_PACKET_SIZE); bmp_common_hdr(s, BMP_VERSION_3, BMP_TYPE_ROUTE_MIRRORING); - bmp_per_peer_hdr(s, peer, 0, &bmq->tv); + bmp_per_peer_hdr(s, bmp->targets->bgp, peer, 0, + BMP_PEER_TYPE_GLOBAL_INSTANCE, 0, &bmq->tv); /* BMP Mirror TLV. */ stream_putw(s, BMP_MIRROR_TLV_TYPE_BGP_MESSAGE); @@ -703,7 +779,7 @@ static int bmp_peer_status_changed(struct peer *peer) if (!bmpbgp) return 0; - if (peer->status == Deleted) { + if (peer->connection->status == Deleted) { bbpeer = bmp_bgp_peer_find(peer->qobj_node.nid); if (bbpeer) { XFREE(MTYPE_BMP_OPEN, bbpeer->open_rx); @@ -715,10 +791,12 @@ static int bmp_peer_status_changed(struct peer *peer) } /* Check if this peer just went to Established */ - if ((peer->ostatus != OpenConfirm) || !(peer_established(peer))) + if ((peer->connection->ostatus != OpenConfirm) || + !(peer_established(peer->connection))) return 0; - if (peer->doppelganger && (peer->doppelganger->status != Deleted)) { + if (peer->doppelganger && + (peer->doppelganger->connection->status != Deleted)) { bbpeer = bmp_bgp_peer_get(peer); bbdopp = bmp_bgp_peer_find(peer->doppelganger->qobj_node.nid); if (bbdopp) { @@ -761,7 +839,8 @@ static int bmp_peer_backward(struct peer *peer) return 0; } -static void bmp_eor(struct bmp *bmp, afi_t afi, safi_t safi, uint8_t flags) +static void bmp_eor(struct bmp *bmp, afi_t afi, safi_t safi, uint8_t flags, + uint8_t peer_type_flag) { struct peer *peer; struct listnode *node; @@ -769,7 +848,7 @@ static void bmp_eor(struct bmp *bmp, afi_t afi, safi_t safi, uint8_t flags) iana_afi_t pkt_afi = IANA_AFI_IPV4; iana_safi_t pkt_safi = IANA_SAFI_UNICAST; - frrtrace(3, frr_bgp, bmp_eor, afi, safi, flags); + frrtrace(4, frr_bgp, bmp_eor, afi, safi, flags, peer_type_flag); s = stream_new(BGP_MAX_PACKET_SIZE); @@ -801,11 +880,22 @@ static void bmp_eor(struct bmp *bmp, afi_t afi, safi_t safi, uint8_t flags) if (!peer->afc_nego[afi][safi]) continue; + uint64_t peer_distinguisher = 0; + /* skip this message if peer distinguisher is not available */ + if (bmp_get_peer_distinguisher(bmp, afi, peer_type_flag, + &peer_distinguisher)) { + zlog_warn( + "skipping bmp message for reason: can't get peer distinguisher"); + continue; + } + s2 = stream_new(BGP_MAX_PACKET_SIZE); bmp_common_hdr(s2, BMP_VERSION_3, BMP_TYPE_ROUTE_MONITORING); - bmp_per_peer_hdr(s2, peer, flags, NULL); + + bmp_per_peer_hdr(s2, bmp->targets->bgp, peer, flags, + peer_type_flag, peer_distinguisher, NULL); stream_putl_at(s2, BMP_LENGTH_POS, stream_get_endp(s) + stream_get_endp(s2)); @@ -910,14 +1000,23 @@ static struct stream *bmp_withdraw(const struct prefix *p, } static void bmp_monitor(struct bmp *bmp, struct peer *peer, uint8_t flags, - const struct prefix *p, struct prefix_rd *prd, - struct attr *attr, afi_t afi, safi_t safi, - time_t uptime) + uint8_t peer_type_flag, const struct prefix *p, + struct prefix_rd *prd, struct attr *attr, afi_t afi, + safi_t safi, time_t uptime) { struct stream *hdr, *msg; struct timeval tv = { .tv_sec = uptime, .tv_usec = 0 }; struct timeval uptime_real; + uint64_t peer_distinguisher = 0; + /* skip this message if peer distinguisher is not available */ + if (bmp_get_peer_distinguisher(bmp, afi, peer_type_flag, + &peer_distinguisher)) { + zlog_warn( + "skipping bmp message for reason: can't get peer distinguisher"); + return; + } + monotime_to_realtime(&tv, &uptime_real); if (attr) msg = bmp_update(p, prd, peer, attr, afi, safi); @@ -926,7 +1025,9 @@ static void bmp_monitor(struct bmp *bmp, struct peer *peer, uint8_t flags, hdr = stream_new(BGP_MAX_PACKET_SIZE); bmp_common_hdr(hdr, BMP_VERSION_3, BMP_TYPE_ROUTE_MONITORING); - bmp_per_peer_hdr(hdr, peer, flags, &uptime_real); + bmp_per_peer_hdr(hdr, bmp->targets->bgp, peer, flags, peer_type_flag, + peer_distinguisher, + uptime == (time_t)(-1L) ? NULL : &uptime_real); stream_putl_at(hdr, BMP_LENGTH_POS, stream_get_endp(hdr) + stream_get_endp(msg)); @@ -1037,8 +1138,13 @@ static bool bmp_wrsync(struct bmp *bmp, struct pullwr *pullwr) zlog_info("bmp[%s] %s %s table completed (EoR)", bmp->remote, afi2str(afi), safi2str(safi)); - bmp_eor(bmp, afi, safi, BMP_PEER_FLAG_L); - bmp_eor(bmp, afi, safi, 0); + + bmp_eor(bmp, afi, safi, BMP_PEER_FLAG_L, + BMP_PEER_TYPE_GLOBAL_INSTANCE); + bmp_eor(bmp, afi, safi, 0, + BMP_PEER_TYPE_GLOBAL_INSTANCE); + bmp_eor(bmp, afi, safi, 0, + BMP_PEER_TYPE_LOC_RIB_INSTANCE); bmp->afistate[afi][safi] = BMP_AFI_LIVE; bmp->syncafi = AFI_MAX; @@ -1049,10 +1155,16 @@ static bool bmp_wrsync(struct bmp *bmp, struct pullwr *pullwr) prefix_copy(&bmp->syncpos, bgp_dest_get_prefix(bn)); } - if (bmp->targets->afimon[afi][safi] & BMP_MON_POSTPOLICY) { + if (CHECK_FLAG(bmp->targets->afimon[afi][safi], + BMP_MON_POSTPOLICY) || + CHECK_FLAG(bmp->targets->afimon[afi][safi], + BMP_MON_LOC_RIB)) { for (bpiter = bgp_dest_get_bgp_path_info(bn); bpiter; bpiter = bpiter->next) { - if (!CHECK_FLAG(bpiter->flags, BGP_PATH_VALID)) + if (!CHECK_FLAG(bpiter->flags, + BGP_PATH_VALID) && + !CHECK_FLAG(bpiter->flags, + BGP_PATH_SELECTED)) continue; if (bpiter->peer->qobj_node.nid <= bmp->syncpeerid) @@ -1063,7 +1175,8 @@ static bool bmp_wrsync(struct bmp *bmp, struct pullwr *pullwr) bpi = bpiter; } } - if (bmp->targets->afimon[afi][safi] & BMP_MON_PREPOLICY) { + if (CHECK_FLAG(bmp->targets->afimon[afi][safi], + BMP_MON_PREPOLICY)) { for (adjiter = bn->adj_in; adjiter; adjiter = adjiter->next) { if (adjiter->peer->qobj_node.nid @@ -1101,12 +1214,23 @@ static bool bmp_wrsync(struct bmp *bmp, struct pullwr *pullwr) (safi == SAFI_MPLS_VPN)) prd = (struct prefix_rd *)bgp_dest_get_prefix(bmp->syncrdpos); - if (bpi) - bmp_monitor(bmp, bpi->peer, BMP_PEER_FLAG_L, bn_p, prd, - bpi->attr, afi, safi, bpi->uptime); + if (bpi && CHECK_FLAG(bpi->flags, BGP_PATH_SELECTED) && + CHECK_FLAG(bmp->targets->afimon[afi][safi], BMP_MON_LOC_RIB)) { + bmp_monitor(bmp, bpi->peer, 0, BMP_PEER_TYPE_LOC_RIB_INSTANCE, + bn_p, prd, bpi->attr, afi, safi, + bpi && bpi->extra ? bpi->extra->bgp_rib_uptime + : (time_t)(-1L)); + } + + if (bpi && CHECK_FLAG(bpi->flags, BGP_PATH_VALID) && + CHECK_FLAG(bmp->targets->afimon[afi][safi], BMP_MON_POSTPOLICY)) + bmp_monitor(bmp, bpi->peer, BMP_PEER_FLAG_L, + BMP_PEER_TYPE_GLOBAL_INSTANCE, bn_p, prd, bpi->attr, + afi, safi, bpi->uptime); + if (adjin) - bmp_monitor(bmp, adjin->peer, 0, bn_p, prd, adjin->attr, afi, - safi, adjin->uptime); + bmp_monitor(bmp, adjin->peer, 0, BMP_PEER_TYPE_GLOBAL_INSTANCE, + bn_p, prd, adjin->attr, afi, safi, adjin->uptime); if (bn) bgp_dest_unlock_node(bn); @@ -1114,24 +1238,124 @@ static bool bmp_wrsync(struct bmp *bmp, struct pullwr *pullwr) return true; } -static struct bmp_queue_entry *bmp_pull(struct bmp *bmp) +static struct bmp_queue_entry * +bmp_pull_from_queue(struct bmp_qlist_head *list, struct bmp_qhash_head *hash, + struct bmp_queue_entry **queuepos_ptr) { struct bmp_queue_entry *bqe; - bqe = bmp->queuepos; + bqe = *queuepos_ptr; if (!bqe) return NULL; - bmp->queuepos = bmp_qlist_next(&bmp->targets->updlist, bqe); + *queuepos_ptr = bmp_qlist_next(list, bqe); bqe->refcount--; if (!bqe->refcount) { - bmp_qhash_del(&bmp->targets->updhash, bqe); - bmp_qlist_del(&bmp->targets->updlist, bqe); + bmp_qhash_del(hash, bqe); + bmp_qlist_del(list, bqe); } return bqe; } +static inline struct bmp_queue_entry *bmp_pull(struct bmp *bmp) +{ + return bmp_pull_from_queue(&bmp->targets->updlist, + &bmp->targets->updhash, &bmp->queuepos); +} + +static inline struct bmp_queue_entry *bmp_pull_locrib(struct bmp *bmp) +{ + return bmp_pull_from_queue(&bmp->targets->locupdlist, + &bmp->targets->locupdhash, + &bmp->locrib_queuepos); +} + +/* TODO BMP_MON_LOCRIB find a way to merge properly this function with + * bmp_wrqueue or abstract it if possible + */ +static bool bmp_wrqueue_locrib(struct bmp *bmp, struct pullwr *pullwr) +{ + + struct bmp_queue_entry *bqe; + struct peer *peer; + struct bgp_dest *bn = NULL; + bool written = false; + + bqe = bmp_pull_locrib(bmp); + if (!bqe) + return false; + + afi_t afi = bqe->afi; + safi_t safi = bqe->safi; + + if (!CHECK_FLAG(bmp->targets->afimon[afi][safi], BMP_MON_LOC_RIB)) + goto out; + + switch (bmp->afistate[afi][safi]) { + case BMP_AFI_INACTIVE: + case BMP_AFI_NEEDSYNC: + goto out; + case BMP_AFI_SYNC: + if (prefix_cmp(&bqe->p, &bmp->syncpos) <= 0) + /* currently syncing but have already passed this + * prefix => send it. + */ + break; + + /* currently syncing & haven't reached this prefix yet + * => it'll be sent as part of the table sync, no need here + */ + goto out; + case BMP_AFI_LIVE: + break; + } + + peer = QOBJ_GET_TYPESAFE(bqe->peerid, peer); + if (!peer) { + /* skipping queued item for deleted peer + */ + goto out; + } + if (peer != bmp->targets->bgp->peer_self && !peer_established(peer->connection)) { + /* peer is neither self, nor established + */ + goto out; + } + + bool is_vpn = (bqe->afi == AFI_L2VPN && bqe->safi == SAFI_EVPN) || + (bqe->safi == SAFI_MPLS_VPN); + + struct prefix_rd *prd = is_vpn ? &bqe->rd : NULL; + + bn = bgp_safi_node_lookup(bmp->targets->bgp->rib[afi][safi], safi, + &bqe->p, prd); + + struct bgp_path_info *bpi; + + for (bpi = bgp_dest_get_bgp_path_info(bn); bpi; bpi = bpi->next) { + if (!CHECK_FLAG(bpi->flags, BGP_PATH_SELECTED)) + continue; + if (bpi->peer == peer) + break; + } + + bmp_monitor(bmp, peer, 0, BMP_PEER_TYPE_LOC_RIB_INSTANCE, &bqe->p, prd, + bpi ? bpi->attr : NULL, afi, safi, + bpi && bpi->extra ? bpi->extra->bgp_rib_uptime + : (time_t)(-1L)); + written = true; + +out: + if (!bqe->refcount) + XFREE(MTYPE_BMP_QUEUE, bqe); + + if (bn) + bgp_dest_unlock_node(bn); + + return written; +} + static bool bmp_wrqueue(struct bmp *bmp, struct pullwr *pullwr) { struct bmp_queue_entry *bqe; @@ -1168,7 +1392,7 @@ static bool bmp_wrqueue(struct bmp *bmp, struct pullwr *pullwr) zlog_info("bmp: skipping queued item for deleted peer"); goto out; } - if (!peer_established(peer)) + if (!peer_established(peer->connection)) goto out; bool is_vpn = (bqe->afi == AFI_L2VPN && bqe->safi == SAFI_EVPN) || @@ -1178,11 +1402,10 @@ static bool bmp_wrqueue(struct bmp *bmp, struct pullwr *pullwr) bn = bgp_safi_node_lookup(bmp->targets->bgp->rib[afi][safi], safi, &bqe->p, prd); - - if (bmp->targets->afimon[afi][safi] & BMP_MON_POSTPOLICY) { + if (CHECK_FLAG(bmp->targets->afimon[afi][safi], BMP_MON_POSTPOLICY)) { struct bgp_path_info *bpi; - for (bpi = bn ? bgp_dest_get_bgp_path_info(bn) : NULL; bpi; + for (bpi = bgp_dest_get_bgp_path_info(bn); bpi; bpi = bpi->next) { if (!CHECK_FLAG(bpi->flags, BGP_PATH_VALID)) continue; @@ -1190,13 +1413,14 @@ static bool bmp_wrqueue(struct bmp *bmp, struct pullwr *pullwr) break; } - bmp_monitor(bmp, peer, BMP_PEER_FLAG_L, &bqe->p, prd, + bmp_monitor(bmp, peer, BMP_PEER_FLAG_L, + BMP_PEER_TYPE_GLOBAL_INSTANCE, &bqe->p, prd, bpi ? bpi->attr : NULL, afi, safi, bpi ? bpi->uptime : monotime(NULL)); written = true; } - if (bmp->targets->afimon[afi][safi] & BMP_MON_PREPOLICY) { + if (CHECK_FLAG(bmp->targets->afimon[afi][safi], BMP_MON_PREPOLICY)) { struct bgp_adj_in *adjin; for (adjin = bn ? bn->adj_in : NULL; adjin; @@ -1204,8 +1428,8 @@ static bool bmp_wrqueue(struct bmp *bmp, struct pullwr *pullwr) if (adjin->peer == peer) break; } - bmp_monitor(bmp, peer, 0, &bqe->p, prd, - adjin ? adjin->attr : NULL, afi, safi, + bmp_monitor(bmp, peer, 0, BMP_PEER_TYPE_GLOBAL_INSTANCE, + &bqe->p, prd, adjin ? adjin->attr : NULL, afi, safi, adjin ? adjin->uptime : monotime(NULL)); written = true; } @@ -1233,6 +1457,8 @@ static void bmp_wrfill(struct bmp *bmp, struct pullwr *pullwr) break; if (bmp_wrqueue(bmp, pullwr)) break; + if (bmp_wrqueue_locrib(bmp, pullwr)) + break; if (bmp_wrsync(bmp, pullwr)) break; break; @@ -1251,16 +1477,17 @@ static void bmp_wrerr(struct bmp *bmp, struct pullwr *pullwr, bool eof) bmp_free(bmp); } -static void bmp_process_one(struct bmp_targets *bt, struct bgp *bgp, afi_t afi, - safi_t safi, struct bgp_dest *bn, struct peer *peer) +static struct bmp_queue_entry * +bmp_process_one(struct bmp_targets *bt, struct bmp_qhash_head *updhash, + struct bmp_qlist_head *updlist, struct bgp *bgp, afi_t afi, + safi_t safi, struct bgp_dest *bn, struct peer *peer) { - struct bmp *bmp; struct bmp_queue_entry *bqe, bqeref; size_t refcount; refcount = bmp_session_count(&bt->sessions); if (refcount == 0) - return; + return NULL; memset(&bqeref, 0, sizeof(bqeref)); prefix_copy(&bqeref.p, bgp_dest_get_prefix(bn)); @@ -1273,26 +1500,28 @@ static void bmp_process_one(struct bmp_targets *bt, struct bgp *bgp, afi_t afi, prefix_copy(&bqeref.rd, (struct prefix_rd *)bgp_dest_get_prefix(bn->pdest)); - bqe = bmp_qhash_find(&bt->updhash, &bqeref); + bqe = bmp_qhash_find(updhash, &bqeref); if (bqe) { if (bqe->refcount >= refcount) /* nothing to do here */ - return; + return NULL; - bmp_qlist_del(&bt->updlist, bqe); + bmp_qlist_del(updlist, bqe); } else { bqe = XMALLOC(MTYPE_BMP_QUEUE, sizeof(*bqe)); memcpy(bqe, &bqeref, sizeof(*bqe)); - bmp_qhash_add(&bt->updhash, bqe); + bmp_qhash_add(updhash, bqe); } bqe->refcount = refcount; - bmp_qlist_add_tail(&bt->updlist, bqe); + bmp_qlist_add_tail(updlist, bqe); + + return bqe; - frr_each (bmp_session, &bt->sessions, bmp) - if (!bmp->queuepos) - bmp->queuepos = bqe; + /* need to update correct queue pos for all sessions of the target after + * a call to this function + */ } static int bmp_process(struct bgp *bgp, afi_t afi, safi_t safi, @@ -1305,7 +1534,7 @@ static int bmp_process(struct bgp *bgp, afi_t afi, safi_t safi, if (frrtrace_enabled(frr_bgp, bmp_process)) { char pfxprint[PREFIX2STR_BUFFER]; - prefix2str(&bn->p, pfxprint, sizeof(pfxprint)); + prefix2str(&bn->rn->p, pfxprint, sizeof(pfxprint)); frrtrace(5, frr_bgp, bmp_process, peer, pfxprint, afi, safi, withdraw); } @@ -1314,12 +1543,26 @@ static int bmp_process(struct bgp *bgp, afi_t afi, safi_t safi, return 0; frr_each(bmp_targets, &bmpbgp->targets, bt) { - if (!bt->afimon[afi][safi]) + /* check if any monitoring is enabled (ignoring loc-rib since it + * uses another hook & queue + */ + if (!CHECK_FLAG(bt->afimon[afi][safi], ~BMP_MON_LOC_RIB)) continue; - bmp_process_one(bt, bgp, afi, safi, bn, peer); + struct bmp_queue_entry *last_item = + bmp_process_one(bt, &bt->updhash, &bt->updlist, bgp, + afi, safi, bn, peer); + + /* if bmp_process_one returns NULL + * we don't have anything to do next + */ + if (!last_item) + continue; frr_each(bmp_session, &bt->sessions, bmp) { + if (!bmp->queuepos) + bmp->queuepos = last_item; + pullwr_bump(bmp->pullwr); } } @@ -1353,12 +1596,13 @@ static void bmp_stats(struct event *thread) for (ALL_LIST_ELEMENTS_RO(bt->bgp->peer, node, peer)) { size_t count = 0, count_pos, len; - if (!peer_established(peer)) + if (!peer_established(peer->connection)) continue; s = stream_new(BGP_MAX_PACKET_SIZE); bmp_common_hdr(s, BMP_VERSION_3, BMP_TYPE_STATISTICS_REPORT); - bmp_per_peer_hdr(s, peer, 0, &tv); + bmp_per_peer_hdr(s, bt->bgp, peer, 0, + BMP_PEER_TYPE_GLOBAL_INSTANCE, 0, &tv); count_pos = stream_get_endp(s); stream_putl(s, 0); @@ -1528,6 +1772,9 @@ static void bmp_close(struct bmp *bmp) while ((bqe = bmp_pull(bmp))) if (!bqe->refcount) XFREE(MTYPE_BMP_QUEUE, bqe); + while ((bqe = bmp_pull_locrib(bmp))) + if (!bqe->refcount) + XFREE(MTYPE_BMP_QUEUE, bqe); EVENT_OFF(bmp->t_read); pullwr_del(bmp->pullwr); @@ -1631,6 +1878,8 @@ static struct bmp_targets *bmp_targets_get(struct bgp *bgp, const char *name) bmp_session_init(&bt->sessions); bmp_qhash_init(&bt->updhash); bmp_qlist_init(&bt->updlist); + bmp_qhash_init(&bt->locupdhash); + bmp_qlist_init(&bt->locupdlist); bmp_actives_init(&bt->actives); bmp_listeners_init(&bt->listeners); @@ -1661,6 +1910,8 @@ static void bmp_targets_put(struct bmp_targets *bt) bmp_actives_fini(&bt->actives); bmp_qhash_fini(&bt->updhash); bmp_qlist_fini(&bt->updlist); + bmp_qhash_fini(&bt->locupdhash); + bmp_qlist_fini(&bt->locupdlist); XFREE(MTYPE_BMP_ACLNAME, bt->acl_name); XFREE(MTYPE_BMP_ACLNAME, bt->acl6_name); @@ -2204,21 +2455,17 @@ DEFPY(bmp_stats_cfg, return CMD_SUCCESS; } -DEFPY(bmp_monitor_cfg, - bmp_monitor_cmd, - "[no] bmp monitor $policy", - NO_STR - BMP_STR - "Send BMP route monitoring messages\n" - BGP_AF_STR - BGP_AF_STR - BGP_AF_STR - BGP_AF_STR - BGP_AF_STR - BGP_AF_STR - BGP_AF_STR +#define BMP_POLICY_IS_LOCRIB(str) ((str)[0] == 'l') /* __l__oc-rib */ +#define BMP_POLICY_IS_PRE(str) ((str)[1] == 'r') /* p__r__e-policy */ + +DEFPY(bmp_monitor_cfg, bmp_monitor_cmd, + "[no] bmp monitor $policy", + NO_STR BMP_STR + "Send BMP route monitoring messages\n" BGP_AF_STR BGP_AF_STR BGP_AF_STR + BGP_AF_STR BGP_AF_STR BGP_AF_STR BGP_AF_STR "Send state before policy and filter processing\n" - "Send state with policy and filters applied\n") + "Send state with policy and filters applied\n" + "Send state after decision process is applied\n") { int index = 0; uint8_t flag, prev; @@ -2231,7 +2478,9 @@ DEFPY(bmp_monitor_cfg, argv_find_and_parse_afi(argv, argc, &index, &afi); argv_find_and_parse_safi(argv, argc, &index, &safi); - if (policy[1] == 'r') + if (BMP_POLICY_IS_LOCRIB(policy)) + flag = BMP_MON_LOC_RIB; + else if (BMP_POLICY_IS_PRE(policy)) flag = BMP_MON_PREPOLICY; else flag = BMP_MON_POSTPOLICY; @@ -2362,23 +2611,31 @@ DEFPY(show_bmp, safi_t safi; FOREACH_AFI_SAFI (afi, safi) { - const char *str = NULL; - - switch (bt->afimon[afi][safi]) { - case BMP_MON_PREPOLICY: - str = "pre-policy"; - break; - case BMP_MON_POSTPOLICY: - str = "post-policy"; - break; - case BMP_MON_PREPOLICY | BMP_MON_POSTPOLICY: - str = "pre-policy and post-policy"; - break; - } - if (!str) + + uint8_t afimon_flag = bt->afimon[afi][safi]; + + if (!afimon_flag) continue; - vty_out(vty, " Route Monitoring %s %s %s\n", - afi2str(afi), safi2str(safi), str); + + const char *pre_str = + CHECK_FLAG(afimon_flag, + BMP_MON_PREPOLICY) + ? "pre-policy " + : ""; + const char *post_str = + CHECK_FLAG(afimon_flag, + BMP_MON_POSTPOLICY) + ? "post-policy " + : ""; + const char *locrib_str = + CHECK_FLAG(afimon_flag, BMP_MON_LOC_RIB) + ? "loc-rib" + : ""; + + vty_out(vty, + " Route Monitoring %s %s %s%s%s\n", + afi2str(afi), safi2str(safi), pre_str, + post_str, locrib_str); } vty_out(vty, " Listeners:\n"); @@ -2498,13 +2755,18 @@ static int bmp_config_write(struct bgp *bgp, struct vty *vty) vty_out(vty, " bmp mirror\n"); FOREACH_AFI_SAFI (afi, safi) { - if (bt->afimon[afi][safi] & BMP_MON_PREPOLICY) + if (CHECK_FLAG(bt->afimon[afi][safi], + BMP_MON_PREPOLICY)) vty_out(vty, " bmp monitor %s %s pre-policy\n", afi2str_lower(afi), safi2str(safi)); - if (bt->afimon[afi][safi] & BMP_MON_POSTPOLICY) + if (CHECK_FLAG(bt->afimon[afi][safi], + BMP_MON_POSTPOLICY)) vty_out(vty, " bmp monitor %s %s post-policy\n", afi2str_lower(afi), safi2str(safi)); + if (CHECK_FLAG(bt->afimon[afi][safi], BMP_MON_LOC_RIB)) + vty_out(vty, " bmp monitor %s %s loc-rib\n", + afi2str(afi), safi2str(safi)); } frr_each (bmp_listeners, &bt->listeners, bl) vty_out(vty, " \n bmp listener %pSU port %d\n", @@ -2553,6 +2815,82 @@ static int bgp_bmp_init(struct event_loop *tm) return 0; } +static int bmp_route_update(struct bgp *bgp, afi_t afi, safi_t safi, + struct bgp_dest *bn, + struct bgp_path_info *old_route, + struct bgp_path_info *new_route) +{ + bool is_locribmon_enabled = false; + bool is_withdraw = old_route && !new_route; + struct bgp_path_info *updated_route = + is_withdraw ? old_route : new_route; + + + /* this should never happen */ + if (!updated_route) { + zlog_warn("%s: no updated route found!", __func__); + return 0; + } + + struct bmp_bgp *bmpbgp = bmp_bgp_get(bgp); + struct peer *peer = updated_route->peer; + struct bmp_targets *bt; + struct bmp *bmp; + + frr_each (bmp_targets, &bmpbgp->targets, bt) { + if (CHECK_FLAG(bt->afimon[afi][safi], BMP_MON_LOC_RIB)) { + is_locribmon_enabled = true; + break; + } + } + + if (!is_locribmon_enabled) + return 0; + + /* route is not installed in locrib anymore and rib uptime was saved */ + if (old_route && old_route->extra) + bgp_path_info_extra_get(old_route)->bgp_rib_uptime = + (time_t)(-1L); + + /* route is installed in locrib from now on so + * save rib uptime in bgp_path_info_extra + */ + if (new_route) + bgp_path_info_extra_get(new_route)->bgp_rib_uptime = + monotime(NULL); + + frr_each (bmp_targets, &bmpbgp->targets, bt) { + if (CHECK_FLAG(bt->afimon[afi][safi], BMP_MON_LOC_RIB)) { + + struct bmp_queue_entry *last_item = bmp_process_one( + bt, &bt->locupdhash, &bt->locupdlist, bgp, afi, + safi, bn, peer); + + /* if bmp_process_one returns NULL + * we don't have anything to do next + */ + if (!last_item) + continue; + + frr_each (bmp_session, &bt->sessions, bmp) { + if (!bmp->locrib_queuepos) + bmp->locrib_queuepos = last_item; + + pullwr_bump(bmp->pullwr); + }; + } + }; + + return 0; +} + +static int bgp_bmp_early_fini(void) +{ + resolver_terminate(); + + return 0; +} + static int bgp_bmp_module_init(void) { hook_register(bgp_packet_dump, bmp_mirror_packet); @@ -2563,6 +2901,8 @@ static int bgp_bmp_module_init(void) hook_register(bgp_inst_config_write, bmp_config_write); hook_register(bgp_inst_delete, bmp_bgp_del); hook_register(frr_late_init, bgp_bmp_init); + hook_register(bgp_route_update, bmp_route_update); + hook_register(frr_early_fini, bgp_bmp_early_fini); return 0; } diff --git a/bgpd/bgp_bmp.h b/bgpd/bgp_bmp.h index ab7463fadc..dadd99eb6d 100644 --- a/bgpd/bgp_bmp.h +++ b/bgpd/bgp_bmp.h @@ -124,6 +124,7 @@ struct bmp { * ahead we need to make sure that refcount is decremented. Also, on * disconnects we need to walk the queue and drop our reference. */ + struct bmp_queue_entry *locrib_queuepos; struct bmp_queue_entry *queuepos; struct bmp_mirrorq *mirrorpos; bool mirror_lost; @@ -215,12 +216,14 @@ struct bmp_targets { int stat_msec; /* only supporting: - * - IPv4 / unicast & multicast - * - IPv6 / unicast & multicast + * - IPv4 / unicast & multicast & VPN + * - IPv6 / unicast & multicast & VPN * - L2VPN / EVPN */ #define BMP_MON_PREPOLICY (1 << 0) #define BMP_MON_POSTPOLICY (1 << 1) +#define BMP_MON_LOC_RIB (1 << 2) + uint8_t afimon[AFI_MAX][SAFI_MAX]; bool mirror; @@ -232,6 +235,9 @@ struct bmp_targets { struct bmp_qhash_head updhash; struct bmp_qlist_head updlist; + struct bmp_qhash_head locupdhash; + struct bmp_qlist_head locupdlist; + uint64_t cnt_accept, cnt_aclrefused; QOBJ_FIELDS; diff --git a/bgpd/bgp_btoa.c b/bgpd/bgp_btoa.c index fc3363b098..1d5034efd2 100644 --- a/bgpd/bgp_btoa.c +++ b/bgpd/bgp_btoa.c @@ -4,6 +4,7 @@ */ #include +#include #include "zebra.h" #include "stream.h" @@ -120,6 +121,7 @@ int main(int argc, char **argv) struct in_addr dip; uint16_t viewno, seq_num; struct prefix_ipv4 p; + char tbuf[32]; s = stream_new(10000); @@ -155,7 +157,7 @@ int main(int argc, char **argv) subtype = stream_getw(s); len = stream_getl(s); - printf("TIME: %s", ctime(&now)); + printf("TIME: %s", ctime_r(&now, tbuf)); /* printf ("TYPE: %d/%d\n", type, subtype); */ @@ -239,7 +241,8 @@ int main(int argc, char **argv) source_as = stream_getw(s); printf("FROM: %pI4 AS%d\n", &peer, source_as); - printf("ORIGINATED: %s", ctime(&originated)); + printf("ORIGINATED: %s", ctime_r(&originated, + tbuf)); attrlen = stream_getw(s); printf("ATTRLEN: %d\n", attrlen); diff --git a/bgpd/bgp_clist.c b/bgpd/bgp_clist.c index 1d2ba3bf58..8336d6f311 100644 --- a/bgpd/bgp_clist.c +++ b/bgpd/bgp_clist.c @@ -128,6 +128,7 @@ static void community_entry_free(struct community_entry *entry) XFREE(MTYPE_COMMUNITY_LIST_CONFIG, entry->config); if (entry->reg) bgp_regex_free(entry->reg); + break; default: break; } @@ -449,13 +450,6 @@ static char *community_str_get(struct community *com, int i) comval = ntohl(comval); switch (comval) { -#if CONFDATE > 20230801 -CPP_NOTICE("Deprecate COMMUNITY_INTERNET BGP community") -#endif - case COMMUNITY_INTERNET: - str = XSTRDUP(MTYPE_COMMUNITY_STR, "internet"); - zlog_warn("`internet` community is deprecated"); - break; case COMMUNITY_GSHUT: str = XSTRDUP(MTYPE_COMMUNITY_STR, "graceful-shutdown"); break; @@ -659,13 +653,7 @@ bool community_list_match(struct community *com, struct community_list *list) struct community_entry *entry; for (entry = list->head; entry; entry = entry->next) { - if (entry->any) - return entry->direct == COMMUNITY_PERMIT; - if (entry->style == COMMUNITY_LIST_STANDARD) { - if (community_include(entry->u.com, COMMUNITY_INTERNET)) - return entry->direct == COMMUNITY_PERMIT; - if (community_match(com, entry->u.com)) return entry->direct == COMMUNITY_PERMIT; } else if (entry->style == COMMUNITY_LIST_EXPANDED) { @@ -681,9 +669,6 @@ bool lcommunity_list_match(struct lcommunity *lcom, struct community_list *list) struct community_entry *entry; for (entry = list->head; entry; entry = entry->next) { - if (entry->any) - return entry->direct == COMMUNITY_PERMIT; - if (entry->style == LARGE_COMMUNITY_LIST_STANDARD) { if (lcommunity_match(lcom, entry->u.lcom)) return entry->direct == COMMUNITY_PERMIT; @@ -705,9 +690,6 @@ bool lcommunity_list_exact_match(struct lcommunity *lcom, struct community_entry *entry; for (entry = list->head; entry; entry = entry->next) { - if (entry->any) - return entry->direct == COMMUNITY_PERMIT; - if (entry->style == LARGE_COMMUNITY_LIST_STANDARD) { if (lcommunity_cmp(lcom, entry->u.lcom)) return entry->direct == COMMUNITY_PERMIT; @@ -724,9 +706,6 @@ bool ecommunity_list_match(struct ecommunity *ecom, struct community_list *list) struct community_entry *entry; for (entry = list->head; entry; entry = entry->next) { - if (entry->any) - return entry->direct == COMMUNITY_PERMIT; - if (entry->style == EXTCOMMUNITY_LIST_STANDARD) { if (ecommunity_match(ecom, entry->u.ecom)) return entry->direct == COMMUNITY_PERMIT; @@ -746,13 +725,7 @@ bool community_list_exact_match(struct community *com, struct community_entry *entry; for (entry = list->head; entry; entry = entry->next) { - if (entry->any) - return entry->direct == COMMUNITY_PERMIT; - if (entry->style == COMMUNITY_LIST_STANDARD) { - if (community_include(entry->u.com, COMMUNITY_INTERNET)) - return entry->direct == COMMUNITY_PERMIT; - if (community_cmp(com, entry->u.com)) return entry->direct == COMMUNITY_PERMIT; } else if (entry->style == COMMUNITY_LIST_EXPANDED) { @@ -763,6 +736,27 @@ bool community_list_exact_match(struct community *com, return false; } +bool community_list_any_match(struct community *com, struct community_list *list) +{ + struct community_entry *entry; + uint32_t val; + int i; + + for (i = 0; i < com->size; i++) { + val = community_val_get(com, i); + + for (entry = list->head; entry; entry = entry->next) { + if (entry->style == COMMUNITY_LIST_STANDARD && + community_include(entry->u.com, val)) + return entry->direct == COMMUNITY_PERMIT; + if ((entry->style == COMMUNITY_LIST_EXPANDED) && + community_regexp_include(entry->reg, com, i)) + return entry->direct == COMMUNITY_PERMIT; + } + } + return false; +} + /* Delete all permitted communities in the list from com. */ struct community *community_list_match_delete(struct community *com, struct community_list *list) @@ -781,28 +775,15 @@ struct community *community_list_match_delete(struct community *com, val = community_val_get(com, i); for (entry = list->head; entry; entry = entry->next) { - if (entry->any) { - if (entry->direct == COMMUNITY_PERMIT) { - com_index_to_delete[delete_index] = i; - delete_index++; - } - break; - } - - else if ((entry->style == COMMUNITY_LIST_STANDARD) - && (community_include(entry->u.com, - COMMUNITY_INTERNET) - || community_include(entry->u.com, val))) { + if ((entry->style == COMMUNITY_LIST_STANDARD) && + community_include(entry->u.com, val)) { if (entry->direct == COMMUNITY_PERMIT) { com_index_to_delete[delete_index] = i; delete_index++; } break; - } - - else if ((entry->style == COMMUNITY_LIST_EXPANDED) - && community_regexp_include(entry->reg, com, - i)) { + } else if ((entry->style == COMMUNITY_LIST_EXPANDED) && + community_regexp_include(entry->reg, com, i)) { if (entry->direct == COMMUNITY_PERMIT) { com_index_to_delete[delete_index] = i; delete_index++; @@ -836,12 +817,6 @@ static bool community_list_dup_check(struct community_list *list, if (entry->direct != new->direct) continue; - if (entry->any != new->any) - continue; - - if (entry->any) - return true; - switch (entry->style) { case COMMUNITY_LIST_STANDARD: if (community_cmp(entry->u.com, new->u.com)) @@ -899,20 +874,17 @@ int community_list_set(struct community_list_handler *ch, const char *name, } } - if (str) { - if (style == COMMUNITY_LIST_STANDARD) - com = community_str2com(str); - else - regex = bgp_regcomp(str); + if (style == COMMUNITY_LIST_STANDARD) + com = community_str2com(str); + else + regex = bgp_regcomp(str); - if (!com && !regex) - return COMMUNITY_LIST_ERR_MALFORMED_VAL; - } + if (!com && !regex) + return COMMUNITY_LIST_ERR_MALFORMED_VAL; entry = community_entry_new(); entry->direct = direct; entry->style = style; - entry->any = (str ? false : true); entry->u.com = com; entry->reg = regex; entry->seq = seqnum; @@ -972,6 +944,28 @@ int community_list_unset(struct community_list_handler *ch, const char *name, return 0; } +bool lcommunity_list_any_match(struct lcommunity *lcom, + struct community_list *list) +{ + struct community_entry *entry; + uint8_t *ptr; + int i; + + for (i = 0; i < lcom->size; i++) { + ptr = lcom->val + (i * LCOMMUNITY_SIZE); + + for (entry = list->head; entry; entry = entry->next) { + if ((entry->style == LARGE_COMMUNITY_LIST_STANDARD) && + lcommunity_include(entry->u.lcom, ptr)) + return entry->direct == COMMUNITY_PERMIT; + if ((entry->style == LARGE_COMMUNITY_LIST_EXPANDED) && + lcommunity_regexp_include(entry->reg, lcom, i)) + return entry->direct == COMMUNITY_PERMIT; + } + } + return false; +} + /* Delete all permitted large communities in the list from com. */ struct lcommunity *lcommunity_list_match_delete(struct lcommunity *lcom, struct community_list *list) @@ -989,7 +983,8 @@ struct lcommunity *lcommunity_list_match_delete(struct lcommunity *lcom, for (i = 0; i < lcom->size; i++) { ptr = lcom->val + (i * LCOMMUNITY_SIZE); for (entry = list->head; entry; entry = entry->next) { - if (entry->any) { + if ((entry->style == LARGE_COMMUNITY_LIST_STANDARD) && + lcommunity_include(entry->u.lcom, ptr)) { if (entry->direct == COMMUNITY_PERMIT) { com_index_to_delete[delete_index] = i; delete_index++; @@ -997,18 +992,47 @@ struct lcommunity *lcommunity_list_match_delete(struct lcommunity *lcom, break; } - else if ((entry->style == LARGE_COMMUNITY_LIST_STANDARD) - && lcommunity_include(entry->u.lcom, ptr)) { + else if ((entry->style == + LARGE_COMMUNITY_LIST_EXPANDED) && + lcommunity_regexp_include(entry->reg, lcom, + i)) { if (entry->direct == COMMUNITY_PERMIT) { com_index_to_delete[delete_index] = i; delete_index++; } break; } + } + } - else if ((entry->style == LARGE_COMMUNITY_LIST_EXPANDED) - && lcommunity_regexp_include(entry->reg, lcom, - i)) { + /* Delete all of the communities we flagged for deletion */ + for (i = delete_index - 1; i >= 0; i--) { + ptr = lcom->val + (com_index_to_delete[i] * LCOMMUNITY_SIZE); + lcommunity_del_val(lcom, ptr); + } + + return lcom; +} + +/* Delete all permitted extended communities in the list from ecom.*/ +struct ecommunity *ecommunity_list_match_delete(struct ecommunity *ecom, + struct community_list *list) +{ + struct community_entry *entry; + uint32_t com_index_to_delete[ecom->size]; + uint8_t *ptr; + uint32_t delete_index = 0; + uint32_t i; + struct ecommunity local_ecom = {.size = 1}; + struct ecommunity_val local_eval = {0}; + + for (i = 0; i < ecom->size; i++) { + local_ecom.val = ecom->val + (i * ECOMMUNITY_SIZE); + for (entry = list->head; entry; entry = entry->next) { + if (((entry->style == EXTCOMMUNITY_LIST_STANDARD) && + ecommunity_include(entry->u.ecom, &local_ecom)) || + ((entry->style == EXTCOMMUNITY_LIST_EXPANDED) && + ecommunity_regexp_match(ecom, entry->reg))) { if (entry->direct == COMMUNITY_PERMIT) { com_index_to_delete[delete_index] = i; delete_index++; @@ -1018,13 +1042,14 @@ struct lcommunity *lcommunity_list_match_delete(struct lcommunity *lcom, } } - /* Delete all of the communities we flagged for deletion */ - for (i = delete_index - 1; i >= 0; i--) { - ptr = lcom->val + (com_index_to_delete[i] * LCOMMUNITY_SIZE); - lcommunity_del_val(lcom, ptr); + /* Delete all of the extended communities we flagged for deletion */ + for (i = delete_index; i > 0; i--) { + ptr = ecom->val + (com_index_to_delete[i-1] * ECOMMUNITY_SIZE); + memcpy(&local_eval.val, ptr, sizeof(local_eval.val)); + ecommunity_del_val(ecom, &local_eval); } - return lcom; + return ecom; } /* Helper to check if every octet do not exceed UINT_MAX */ @@ -1127,7 +1152,6 @@ int lcommunity_list_set(struct community_list_handler *ch, const char *name, entry = community_entry_new(); entry->direct = direct; entry->style = style; - entry->any = (str ? false : true); entry->u.lcom = lcom; entry->reg = regex; entry->seq = seqnum; @@ -1248,7 +1272,6 @@ int extcommunity_list_set(struct community_list_handler *ch, const char *name, entry = community_entry_new(); entry->direct = direct; entry->style = style; - entry->any = false; if (ecom) entry->config = ecommunity_ecom2str( ecom, ECOMMUNITY_FORMAT_COMMUNITY_LIST, 0); diff --git a/bgpd/bgp_clist.h b/bgpd/bgp_clist.h index 7a9b28038c..a435b92ce1 100644 --- a/bgpd/bgp_clist.h +++ b/bgpd/bgp_clist.h @@ -65,9 +65,6 @@ struct community_entry { /* Standard or expanded. */ uint8_t style; - /* Any match. */ - bool any; - /* Sequence number. */ int64_t seq; @@ -161,11 +158,18 @@ extern bool community_list_exact_match(struct community *com, struct community_list *list); extern bool lcommunity_list_exact_match(struct lcommunity *lcom, struct community_list *list); +extern bool community_list_any_match(struct community *com, + struct community_list *list); extern struct community * community_list_match_delete(struct community *com, struct community_list *list); +extern bool lcommunity_list_any_match(struct lcommunity *lcom, + struct community_list *list); extern struct lcommunity * lcommunity_list_match_delete(struct lcommunity *lcom, struct community_list *list); +extern struct ecommunity * +ecommunity_list_match_delete(struct ecommunity *ecom, + struct community_list *list); static inline uint32_t bgp_clist_hash_key(char *name) { diff --git a/bgpd/bgp_community.c b/bgpd/bgp_community.c index f56bfc8bdc..8e4c430555 100644 --- a/bgpd/bgp_community.c +++ b/bgpd/bgp_community.c @@ -228,13 +228,6 @@ static void set_community_string(struct community *com, bool make_json, comval = ntohl(comval); switch (comval) { -#if CONFDATE > 20230801 -CPP_NOTICE("Deprecate COMMUNITY_INTERNET BGP community") -#endif - case COMMUNITY_INTERNET: - len += strlen(" internet"); - zlog_warn("`internet` community is deprecated"); - break; case COMMUNITY_GSHUT: len += strlen(" graceful-shutdown"); break; @@ -298,19 +291,6 @@ CPP_NOTICE("Deprecate COMMUNITY_INTERNET BGP community") strlcat(str, " ", len); switch (comval) { -#if CONFDATE > 20230801 -CPP_NOTICE("Deprecate COMMUNITY_INTERNET BGP community") -#endif - case COMMUNITY_INTERNET: - strlcat(str, "internet", len); - if (make_json) { - json_string = - json_object_new_string("internet"); - json_object_array_add(json_community_list, - json_string); - } - zlog_warn("`internet` community is deprecated"); - break; case COMMUNITY_GSHUT: strlcat(str, "graceful-shutdown", len); if (make_json) { @@ -680,16 +660,6 @@ community_gettoken(const char *buf, enum community_token *token, uint32_t *val) /* Well known community string check. */ if (isalpha((unsigned char)*p)) { -#if CONFDATE > 20230801 -CPP_NOTICE("Deprecate COMMUNITY_INTERNET BGP community") -#endif - if (strncmp(p, "internet", strlen("internet")) == 0) { - *val = COMMUNITY_INTERNET; - *token = community_token_no_export; - p += strlen("internet"); - zlog_warn("`internet` community is deprecated"); - return p; - } if (strncmp(p, "graceful-shutdown", strlen("graceful-shutdown")) == 0) { *val = COMMUNITY_GSHUT; diff --git a/bgpd/bgp_community.h b/bgpd/bgp_community.h index e7af362ea8..7c7e7af4d2 100644 --- a/bgpd/bgp_community.h +++ b/bgpd/bgp_community.h @@ -30,10 +30,6 @@ struct community { }; /* Well-known communities value. */ -#if CONFDATE > 20230801 -CPP_NOTICE("Deprecate COMMUNITY_INTERNET BGP community") -#endif -#define COMMUNITY_INTERNET 0x0 #define COMMUNITY_GSHUT 0xFFFF0000 #define COMMUNITY_ACCEPT_OWN 0xFFFF0001 #define COMMUNITY_ROUTE_FILTER_TRANSLATED_v4 0xFFFF0002 diff --git a/bgpd/bgp_conditional_adv.c b/bgpd/bgp_conditional_adv.c index 53652f7dce..6ed0dd797b 100644 --- a/bgpd/bgp_conditional_adv.c +++ b/bgpd/bgp_conditional_adv.c @@ -90,6 +90,7 @@ static void bgp_conditional_adv_routes(struct peer *peer, afi_t afi, addpath_capable = bgp_addpath_encode_tx(peer, afi, safi); + SET_FLAG(subgrp->sflags, SUBGRP_STATUS_FORCE_UPDATES); for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) { dest_p = bgp_dest_get_prefix(dest); assert(dest_p); @@ -140,8 +141,9 @@ static void bgp_conditional_adv_routes(struct peer *peer, afi_t afi, bgp_addpath_id_for_peer( peer, afi, safi, &pi->tx_addpath)); + + bgp_attr_flush(&advmap_attr); } - bgp_attr_flush(&advmap_attr); } } UNSET_FLAG(subgrp->sflags, SUBGRP_STATUS_TABLE_REPARSING); @@ -194,7 +196,7 @@ static void bgp_conditional_adv_timer(struct event *t) if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE)) continue; - if (!peer_established(peer)) + if (!peer_established(peer->connection)) continue; FOREACH_AFI_SAFI (afi, safi) { diff --git a/bgpd/bgp_damp.c b/bgpd/bgp_damp.c index a6d0e74dc0..80425ebe7a 100644 --- a/bgpd/bgp_damp.c +++ b/bgpd/bgp_damp.c @@ -558,7 +558,7 @@ void bgp_damp_info_vty(struct vty *vty, struct bgp_path_info *path, afi_t afi, { struct bgp_damp_info *bdi; time_t t_now, t_diff; - char timebuf[BGP_UPTIME_LEN]; + char timebuf[BGP_UPTIME_LEN] = {}; int penalty; struct bgp_damp_config *bdc = &damp[afi][safi]; @@ -570,7 +570,9 @@ void bgp_damp_info_vty(struct vty *vty, struct bgp_path_info *path, afi_t afi, /* If dampening is not enabled or there is no dampening information, return immediately. */ - if (!bdc || !bdi) + if (!CHECK_FLAG(path->peer->bgp->af_flags[afi][safi], + BGP_CONFIG_DAMPENING) || + !bdi) return; /* Calculate new penalty. */ @@ -624,7 +626,9 @@ const char *bgp_damp_reuse_time_vty(struct vty *vty, struct bgp_path_info *path, /* If dampening is not enabled or there is no dampening information, return immediately. */ - if (!bdc || !bdi) + if (!CHECK_FLAG(path->peer->bgp->af_flags[afi][safi], + BGP_CONFIG_DAMPENING) || + !bdi) return NULL; /* Calculate new penalty. */ diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c index 782245e512..bd5d94908e 100644 --- a/bgpd/bgp_debug.c +++ b/bgpd/bgp_debug.c @@ -216,6 +216,7 @@ static void bgp_debug_list_free(struct list *list) listnode_delete(list, filter); prefix_free(&filter->p); XFREE(MTYPE_BGP_DEBUG_STR, filter->host); + XFREE(MTYPE_BGP_DEBUG_STR, filter->plist_name); XFREE(MTYPE_BGP_DEBUG_FILTER, filter); } } @@ -233,15 +234,21 @@ static void bgp_debug_list_print(struct vty *vty, const char *desc, vty_out(vty, "%s", desc); if (list && !list_isempty(list)) { - vty_out(vty, " for"); + vty_out(vty, " for:\n"); for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) { if (filter->host) - vty_out(vty, " %s", filter->host); + vty_out(vty, " %s", filter->host); + + if (filter->plist_name) + vty_out(vty, " with prefix-list %s", + filter->plist_name); if (filter->p && filter->p->family == AF_EVPN) bgp_debug_print_evpn_prefix(vty, "", filter->p); else if (filter->p) vty_out(vty, " %pFX", filter->p); + + vty_out(vty, "\n"); } } @@ -261,7 +268,11 @@ static int bgp_debug_list_conf_print(struct vty *vty, const char *desc, if (list && !list_isempty(list)) { for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) { - if (filter->host) { + if (filter->host && filter->plist_name) { + vty_out(vty, "%s %s prefix-list %s\n", desc, + filter->host, filter->plist_name); + write++; + } else if (filter->host) { vty_out(vty, "%s %s\n", desc, filter->host); write++; } @@ -286,7 +297,8 @@ static int bgp_debug_list_conf_print(struct vty *vty, const char *desc, } static void bgp_debug_list_add_entry(struct list *list, const char *host, - const struct prefix *p) + const struct prefix *p, + const char *plist_name) { struct bgp_debug_filter *filter; @@ -295,13 +307,27 @@ static void bgp_debug_list_add_entry(struct list *list, const char *host, if (host) { filter->host = XSTRDUP(MTYPE_BGP_DEBUG_STR, host); + filter->plist_name = NULL; + filter->plist_v4 = NULL; + filter->plist_v6 = NULL; filter->p = NULL; } else if (p) { filter->host = NULL; + filter->plist_name = NULL; + filter->plist_v4 = NULL; + filter->plist_v6 = NULL; filter->p = prefix_new(); prefix_copy(filter->p, p); } + if (plist_name) { + filter->plist_name = XSTRDUP(MTYPE_BGP_DEBUG_STR, plist_name); + filter->plist_v4 = prefix_list_lookup(AFI_IP, + filter->plist_name); + filter->plist_v6 = prefix_list_lookup(AFI_IP6, + filter->plist_name); + } + listnode_add(list, filter); } @@ -315,6 +341,7 @@ static bool bgp_debug_list_remove_entry(struct list *list, const char *host, if (host && strcmp(filter->host, host) == 0) { listnode_delete(list, filter); XFREE(MTYPE_BGP_DEBUG_STR, filter->host); + XFREE(MTYPE_BGP_DEBUG_STR, filter->plist_name); XFREE(MTYPE_BGP_DEBUG_FILTER, filter); return true; } else if (p && filter->p->prefixlen == p->prefixlen @@ -330,16 +357,20 @@ static bool bgp_debug_list_remove_entry(struct list *list, const char *host, } static bool bgp_debug_list_has_entry(struct list *list, const char *host, - const struct prefix *p) + const struct prefix *p, + const char *plist_name) { struct bgp_debug_filter *filter; struct listnode *node, *nnode; for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) { - if (host) { - if (strcmp(filter->host, host) == 0) { + if (host && plist_name) { + if (strmatch(filter->host, host) && filter->plist_name && + strmatch(filter->plist_name, plist_name)) + return true; + } else if (host) { + if (strmatch(filter->host, host)) return true; - } } else if (p) { if (filter->p->prefixlen == p->prefixlen && prefix_match(filter->p, p)) { @@ -353,7 +384,7 @@ static bool bgp_debug_list_has_entry(struct list *list, const char *host, bool bgp_debug_peer_updout_enabled(char *host) { - return (bgp_debug_list_has_entry(bgp_debug_update_out_peers, host, + return (bgp_debug_list_has_entry(bgp_debug_update_out_peers, host, NULL, NULL)); } @@ -498,12 +529,13 @@ const char *bgp_notify_subcode_str(char code, char subcode) const char *bgp_notify_admin_message(char *buf, size_t bufsz, uint8_t *data, size_t datalen) { + memset(buf, 0, bufsz); if (!data || datalen < 1) - return NULL; + return buf; uint8_t len = data[0]; if (!len || len > datalen - 1) - return NULL; + return buf; return zlog_sanitize(buf, bufsz, data + 1, len); } @@ -779,14 +811,15 @@ DEFUN (debug_bgp_neighbor_events_peer, bgp_debug_neighbor_events_peers = list_new(); if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers, host, - NULL)) { + NULL, NULL)) { vty_out(vty, "BGP neighbor-events debugging is already enabled for %s\n", host); return CMD_SUCCESS; } - bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers, host, NULL); + bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers, host, NULL, + NULL); if (vty->node == CONFIG_NODE) DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS); @@ -926,14 +959,15 @@ DEFUN (debug_bgp_keepalive_peer, if (!bgp_debug_keepalive_peers) bgp_debug_keepalive_peers = list_new(); - if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers, host, NULL)) { + if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers, host, NULL, + NULL)) { vty_out(vty, "BGP keepalive debugging is already enabled for %s\n", host); return CMD_SUCCESS; } - bgp_debug_list_add_entry(bgp_debug_keepalive_peers, host, NULL); + bgp_debug_list_add_entry(bgp_debug_keepalive_peers, host, NULL, NULL); if (vty->node == CONFIG_NODE) DEBUG_ON(keepalive, KEEPALIVE); @@ -1014,15 +1048,16 @@ DEFPY (debug_bgp_bestpath_prefix, if (!bgp_debug_bestpath_prefixes) bgp_debug_bestpath_prefixes = list_new(); - if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes, NULL, - prefix)) { + if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes, NULL, prefix, + NULL)) { vty_out(vty, "BGP bestpath debugging is already enabled for %s\n", prefix_str); return CMD_SUCCESS; } - bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes, NULL, prefix); + bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes, NULL, prefix, + NULL); if (vty->node == CONFIG_NODE) { DEBUG_ON(bestpath, BESTPATH); @@ -1115,6 +1150,31 @@ DEFUN (debug_bgp_update, return CMD_SUCCESS; } +DEFPY (debug_bgp_update_detail, + debug_bgp_update_detail_cmd, + "[no] debug bgp updates detail", + NO_STR + DEBUG_STR + BGP_STR + "BGP updates\n" + "Show detailed information about updates\n") +{ + if (vty->node == CONFIG_NODE) { + if (no) + DEBUG_OFF(update, UPDATE_DETAIL); + else + DEBUG_ON(update, UPDATE_DETAIL); + } else { + if (no) + TERM_DEBUG_OFF(update, UPDATE_DETAIL); + else + TERM_DEBUG_ON(update, UPDATE_DETAIL); + vty_out(vty, "BGP updates detail debugging is on\n"); + } + + return CMD_SUCCESS; +} + DEFUN (debug_bgp_update_direct, debug_bgp_update_direct_cmd, "debug bgp updates ", @@ -1149,9 +1209,9 @@ DEFUN (debug_bgp_update_direct, return CMD_SUCCESS; } -DEFUN (debug_bgp_update_direct_peer, +DEFPY (debug_bgp_update_direct_peer, debug_bgp_update_direct_peer_cmd, - "debug bgp updates ", + "debug bgp updates [prefix-list PREFIXLIST_NAME$plist]", DEBUG_STR BGP_STR "BGP updates\n" @@ -1159,7 +1219,9 @@ DEFUN (debug_bgp_update_direct_peer, "Outbound updates\n" "BGP neighbor IP address to debug\n" "BGP IPv6 neighbor to debug\n" - "BGP neighbor on interface to debug\n") + "BGP neighbor on interface to debug\n" + "Use prefix-list to filter prefixes to debug\n" + "Name of prefix-list\n") { int idx_in_out = 3; int idx_peer = 4; @@ -1179,7 +1241,7 @@ DEFUN (debug_bgp_update_direct_peer, if (inbound) { if (bgp_debug_list_has_entry(bgp_debug_update_in_peers, host, - NULL)) { + NULL, plist)) { vty_out(vty, "BGP inbound update debugging is already enabled for %s\n", host); @@ -1189,7 +1251,7 @@ DEFUN (debug_bgp_update_direct_peer, else { if (bgp_debug_list_has_entry(bgp_debug_update_out_peers, host, - NULL)) { + NULL, plist)) { vty_out(vty, "BGP outbound update debugging is already enabled for %s\n", host); @@ -1198,14 +1260,15 @@ DEFUN (debug_bgp_update_direct_peer, } if (inbound) - bgp_debug_list_add_entry(bgp_debug_update_in_peers, host, NULL); + bgp_debug_list_add_entry(bgp_debug_update_in_peers, host, NULL, + plist); else { struct peer *peer; struct peer_af *paf; int afidx; - bgp_debug_list_add_entry(bgp_debug_update_out_peers, host, - NULL); + bgp_debug_list_add_entry(bgp_debug_update_out_peers, host, NULL, + plist); peer = bgp_find_peer(vty, host); if (peer) { @@ -1282,7 +1345,7 @@ DEFUN (no_debug_bgp_update_direct, DEFUN (no_debug_bgp_update_direct_peer, no_debug_bgp_update_direct_peer_cmd, - "no debug bgp updates ", + "no debug bgp updates [prefix-list PREFIXLIST_NAME]", NO_STR DEBUG_STR BGP_STR @@ -1291,7 +1354,9 @@ DEFUN (no_debug_bgp_update_direct_peer, "Outbound updates\n" "BGP neighbor IP address to debug\n" "BGP IPv6 neighbor to debug\n" - "BGP neighbor on interface to debug\n") + "BGP neighbor on interface to debug\n" + "Use prefix-list to filter prefixes to debug\n" + "Name of prefix-list\n") { int idx_in_out = 4; int idx_peer = 5; @@ -1413,15 +1478,15 @@ DEFPY (debug_bgp_update_prefix_afi_safi, if (!bgp_debug_update_prefixes) bgp_debug_update_prefixes = list_new(); - if (bgp_debug_list_has_entry(bgp_debug_update_prefixes, NULL, - &argv_p)) { + if (bgp_debug_list_has_entry(bgp_debug_update_prefixes, NULL, &argv_p, + NULL)) { vty_out(vty, "BGP updates debugging is already enabled for %pFX\n", &argv_p); return CMD_SUCCESS; } - bgp_debug_list_add_entry(bgp_debug_update_prefixes, NULL, &argv_p); + bgp_debug_list_add_entry(bgp_debug_update_prefixes, NULL, &argv_p, NULL); if (vty->node == CONFIG_NODE) { DEBUG_ON(update, UPDATE_PREFIX); @@ -1509,14 +1574,15 @@ DEFPY (debug_bgp_update_prefix, if (!bgp_debug_update_prefixes) bgp_debug_update_prefixes = list_new(); - if (bgp_debug_list_has_entry(bgp_debug_update_prefixes, NULL, prefix)) { + if (bgp_debug_list_has_entry(bgp_debug_update_prefixes, NULL, prefix, + NULL)) { vty_out(vty, "BGP updates debugging is already enabled for %s\n", prefix_str); return CMD_SUCCESS; } - bgp_debug_list_add_entry(bgp_debug_update_prefixes, NULL, prefix); + bgp_debug_list_add_entry(bgp_debug_update_prefixes, NULL, prefix, NULL); if (vty->node == CONFIG_NODE) { DEBUG_ON(update, UPDATE_PREFIX); @@ -1646,13 +1712,14 @@ DEFPY (debug_bgp_zebra_prefix, if (!bgp_debug_zebra_prefixes) bgp_debug_zebra_prefixes = list_new(); - if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes, NULL, prefix)) { + if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes, NULL, prefix, + NULL)) { vty_out(vty, "BGP zebra debugging is already enabled for %s\n", prefix_str); return CMD_SUCCESS; } - bgp_debug_list_add_entry(bgp_debug_zebra_prefixes, NULL, prefix); + bgp_debug_list_add_entry(bgp_debug_zebra_prefixes, NULL, prefix, NULL); if (vty->node == CONFIG_NODE) DEBUG_ON(zebra, ZEBRA); @@ -2264,6 +2331,11 @@ static int bgp_config_write_debug(struct vty *vty) bgp_debug_update_out_peers); } + if (CONF_BGP_DEBUG(update, UPDATE_DETAIL)) { + vty_out(vty, "debug bgp updates detail\n"); + write++; + } + if (CONF_BGP_DEBUG(zebra, ZEBRA)) { if (!bgp_debug_zebra_prefixes || list_isempty(bgp_debug_zebra_prefixes)) { @@ -2369,6 +2441,8 @@ void bgp_debug_init(void) install_element(CONFIG_NODE, &debug_bgp_keepalive_cmd); install_element(ENABLE_NODE, &debug_bgp_update_cmd); install_element(CONFIG_NODE, &debug_bgp_update_cmd); + install_element(ENABLE_NODE, &debug_bgp_update_detail_cmd); + install_element(CONFIG_NODE, &debug_bgp_update_detail_cmd); install_element(ENABLE_NODE, &debug_bgp_zebra_cmd); install_element(CONFIG_NODE, &debug_bgp_zebra_cmd); install_element(ENABLE_NODE, &debug_bgp_update_groups_cmd); @@ -2509,7 +2583,8 @@ static int bgp_debug_per_prefix(const struct prefix *p, /* Return true if this peer is on the per_peer_list of peers to debug * for BGP_DEBUG_TYPE */ -static bool bgp_debug_per_peer(char *host, unsigned long term_bgp_debug_type, +static bool bgp_debug_per_peer(char *host, const struct prefix *p, + unsigned long term_bgp_debug_type, unsigned int BGP_DEBUG_TYPE, struct list *per_peer_list) { @@ -2521,17 +2596,28 @@ static bool bgp_debug_per_peer(char *host, unsigned long term_bgp_debug_type, if (!per_peer_list || list_isempty(per_peer_list)) return true; - else { - if (!host) - return false; + if (!host) + return false; - for (ALL_LIST_ELEMENTS(per_peer_list, node, nnode, - filter)) - if (strcmp(filter->host, host) == 0) - return true; + for (ALL_LIST_ELEMENTS(per_peer_list, node, nnode, filter)) + if (strmatch(filter->host, host) && + filter->plist_name && p) { + struct prefix_list *plist; + afi_t afi = family2afi(p->family); - return false; - } + plist = (afi == AFI_IP) ? filter->plist_v4 + : filter->plist_v6; + + if (!plist) + continue; + + return prefix_list_apply(plist, p) == + PREFIX_PERMIT; + } else if (strmatch(filter->host, host)) { + return true; + } + + return false; } return false; @@ -2544,7 +2630,7 @@ bool bgp_debug_neighbor_events(const struct peer *peer) if (peer) host = peer->host; - return bgp_debug_per_peer(host, term_bgp_debug_neighbor_events, + return bgp_debug_per_peer(host, NULL, term_bgp_debug_neighbor_events, BGP_DEBUG_NEIGHBOR_EVENTS, bgp_debug_neighbor_events_peers); } @@ -2556,7 +2642,7 @@ bool bgp_debug_keepalive(const struct peer *peer) if (peer) host = peer->host; - return bgp_debug_per_peer(host, term_bgp_debug_keepalive, + return bgp_debug_per_peer(host, NULL, term_bgp_debug_keepalive, BGP_DEBUG_KEEPALIVE, bgp_debug_keepalive_peers); } @@ -2570,7 +2656,7 @@ bool bgp_debug_update(const struct peer *peer, const struct prefix *p, host = peer->host; if (inbound) { - if (bgp_debug_per_peer(host, term_bgp_debug_update, + if (bgp_debug_per_peer(host, p, term_bgp_debug_update, BGP_DEBUG_UPDATE_IN, bgp_debug_update_in_peers)) return true; @@ -2578,7 +2664,7 @@ bool bgp_debug_update(const struct peer *peer, const struct prefix *p, /* outbound */ else { - if (bgp_debug_per_peer(host, term_bgp_debug_update, + if (bgp_debug_per_peer(host, p, term_bgp_debug_update, BGP_DEBUG_UPDATE_OUT, bgp_debug_update_out_peers)) return true; diff --git a/bgpd/bgp_debug.h b/bgpd/bgp_debug.h index 118325e0a3..bb4ddea81e 100644 --- a/bgpd/bgp_debug.h +++ b/bgpd/bgp_debug.h @@ -96,6 +96,9 @@ extern struct list *bgp_debug_zebra_prefixes; struct bgp_debug_filter { char *host; + char *plist_name; + struct prefix_list *plist_v4; + struct prefix_list *plist_v6; struct prefix *p; }; @@ -109,6 +112,7 @@ struct bgp_debug_filter { #define BGP_DEBUG_UPDATE_IN 0x01 #define BGP_DEBUG_UPDATE_OUT 0x02 #define BGP_DEBUG_UPDATE_PREFIX 0x04 +#define BGP_DEBUG_UPDATE_DETAIL 0x08 #define BGP_DEBUG_ZEBRA 0x01 #define BGP_DEBUG_ALLOW_MARTIANS 0x01 #define BGP_DEBUG_NHT 0x01 @@ -124,9 +128,6 @@ struct bgp_debug_filter { #define BGP_DEBUG_EVPN_MH_ES 0x01 #define BGP_DEBUG_EVPN_MH_RT 0x02 -#define BGP_DEBUG_PACKET_SEND 0x01 -#define BGP_DEBUG_PACKET_SEND_DETAIL 0x02 - #define BGP_DEBUG_GRACEFUL_RESTART 0x01 #define BGP_DEBUG_BFD_LIB 0x01 diff --git a/bgpd/bgp_dump.c b/bgpd/bgp_dump.c index fe77e7e250..53b5212482 100644 --- a/bgpd/bgp_dump.c +++ b/bgpd/bgp_dump.c @@ -4,6 +4,7 @@ */ #include +#include #include "log.h" #include "stream.h" @@ -246,14 +247,15 @@ static void bgp_dump_routes_index_table(struct bgp *bgp) /* Walk down all peers */ for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) { + int family = sockunion_family(&peer->connection->su); /* Peer's type */ - if (sockunion_family(&peer->su) == AF_INET) { + if (family == AF_INET) { stream_putc( obuf, TABLE_DUMP_V2_PEER_INDEX_TABLE_AS4 + TABLE_DUMP_V2_PEER_INDEX_TABLE_IP); - } else if (sockunion_family(&peer->su) == AF_INET6) { + } else if (family == AF_INET6) { stream_putc( obuf, TABLE_DUMP_V2_PEER_INDEX_TABLE_AS4 @@ -264,10 +266,13 @@ static void bgp_dump_routes_index_table(struct bgp *bgp) stream_put_in_addr(obuf, &peer->remote_id); /* Peer's IP address */ - if (sockunion_family(&peer->su) == AF_INET) { - stream_put_in_addr(obuf, &peer->su.sin.sin_addr); - } else if (sockunion_family(&peer->su) == AF_INET6) { - stream_write(obuf, (uint8_t *)&peer->su.sin6.sin6_addr, + if (family == AF_INET) { + stream_put_in_addr(obuf, + &peer->connection->su.sin.sin_addr); + } else if (family == AF_INET6) { + stream_write(obuf, + (uint8_t *)&peer->connection->su.sin6 + .sin6_addr, IPV6_MAX_BYTELEN); } @@ -468,24 +473,26 @@ static void bgp_dump_common(struct stream *obuf, struct peer *peer, stream_putw(obuf, peer->local_as); } - if (peer->su.sa.sa_family == AF_INET) { + if (peer->connection->su.sa.sa_family == AF_INET) { stream_putw(obuf, peer->ifp ? peer->ifp->ifindex : 0); stream_putw(obuf, AFI_IP); - stream_put(obuf, &peer->su.sin.sin_addr, IPV4_MAX_BYTELEN); + stream_put(obuf, &peer->connection->su.sin.sin_addr, + IPV4_MAX_BYTELEN); if (peer->su_local) stream_put(obuf, &peer->su_local->sin.sin_addr, IPV4_MAX_BYTELEN); else stream_put(obuf, empty, IPV4_MAX_BYTELEN); - } else if (peer->su.sa.sa_family == AF_INET6) { + } else if (peer->connection->su.sa.sa_family == AF_INET6) { /* Interface Index and Address family. */ stream_putw(obuf, peer->ifp ? peer->ifp->ifindex : 0); stream_putw(obuf, AFI_IP6); /* Source IP Address and Destination IP Address. */ - stream_put(obuf, &peer->su.sin6.sin6_addr, IPV6_MAX_BYTELEN); + stream_put(obuf, &peer->connection->su.sin6.sin6_addr, + IPV6_MAX_BYTELEN); if (peer->su_local) stream_put(obuf, &peer->su_local->sin6.sin6_addr, @@ -512,8 +519,8 @@ int bgp_dump_state(struct peer *peer) bgp_dump_all.type); bgp_dump_common(obuf, peer, 1); /* force this in as4speak*/ - stream_putw(obuf, peer->ostatus); - stream_putw(obuf, peer->status); + stream_putw(obuf, peer->connection->ostatus); + stream_putw(obuf, peer->connection->status); /* Set length. */ bgp_dump_set_size(obuf, MSG_PROTOCOL_BGP4MP); @@ -532,10 +539,10 @@ static void bgp_dump_packet_func(struct bgp_dump *bgp_dump, struct peer *peer, /* If dump file pointer is disabled return immediately. */ if (bgp_dump->fp == NULL) return; - if (peer->su.sa.sa_family == AF_INET) { + if (peer->connection->su.sa.sa_family == AF_INET) { addpath_capable = bgp_addpath_encode_rx(peer, AFI_IP, SAFI_UNICAST); - } else if (peer->su.sa.sa_family == AF_INET6) { + } else if (peer->connection->su.sa.sa_family == AF_INET6) { addpath_capable = bgp_addpath_encode_rx(peer, AFI_IP6, SAFI_UNICAST); } diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c index a555930137..a8ae177d03 100644 --- a/bgpd/bgp_ecommunity.c +++ b/bgpd/bgp_ecommunity.c @@ -355,6 +355,22 @@ bool ecommunity_cmp(const void *arg1, const void *arg2) ecom1->unit_size) == 0); } +static void ecommunity_color_str(char *buf, size_t bufsz, uint8_t *ptr) +{ + /* + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | 0x03 | Sub-Type(0x0b) | Flags | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Color Value | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + uint32_t colorid; + + memcpy(&colorid, ptr + 3, 4); + colorid = ntohl(colorid); + snprintf(buf, bufsz, "Color:%d", colorid); +} + /* Initialize Extended Comminities related hash. */ void ecommunity_init(void) { @@ -373,6 +389,7 @@ enum ecommunity_token { ecommunity_token_rt, ecommunity_token_nt, ecommunity_token_soo, + ecommunity_token_color, ecommunity_token_val, ecommunity_token_rt6, ecommunity_token_val6, @@ -510,6 +527,9 @@ static int ecommunity_encode_internal(uint8_t type, uint8_t sub_type, memcpy(&eval6->val[2], ip6, sizeof(struct in6_addr)); eval6->val[18] = (val >> 8) & 0xff; eval6->val[19] = val & 0xff; + } else if (type == ECOMMUNITY_ENCODE_OPAQUE && + sub_type == ECOMMUNITY_COLOR) { + encode_color(val, eval); } else { encode_route_target_as4(as, val, eval, trans); } @@ -543,10 +563,15 @@ static const char *ecommunity_gettoken(const char *str, void *eval_ptr, struct in6_addr ip6; as_t as = 0; uint32_t val = 0; - uint8_t ecomm_type; + uint32_t val_color = 0; + uint8_t ecomm_type = 0; + uint8_t sub_type = 0; char buf[INET_ADDRSTRLEN + 1]; struct ecommunity_val *eval = (struct ecommunity_val *)eval_ptr; uint64_t tmp_as = 0; + static const char str_color[5] = "color"; + const char *ptr_color; + bool val_color_set = false; /* Skip white space. */ while (isspace((unsigned char)*p)) { @@ -558,54 +583,49 @@ static const char *ecommunity_gettoken(const char *str, void *eval_ptr, if (*p == '\0') return NULL; - /* "rt", "nt", and "soo" keyword parse. */ - if (!isdigit((unsigned char)*p)) { - /* "rt" match check. */ - if (tolower((unsigned char)*p) == 'r') { + /* "rt", "nt", "soo", and "color" keyword parse. */ + /* "rt" */ + if (tolower((unsigned char)*p) == 'r') { + p++; + if (tolower((unsigned char)*p) == 't') { p++; - if (tolower((unsigned char)*p) == 't') { - p++; - if (*p != '\0' && tolower((int)*p) == '6') - *token = ecommunity_token_rt6; - else - *token = ecommunity_token_rt; - return p; - } - if (isspace((unsigned char)*p) || *p == '\0') { + if (*p != '\0' && tolower((int)*p) == '6') + *token = ecommunity_token_rt6; + else *token = ecommunity_token_rt; - return p; - } - goto error; + return p; + } + if (isspace((unsigned char)*p) || *p == '\0') { + *token = ecommunity_token_rt; + return p; } - /* "nt" match check. */ - if (tolower((unsigned char)*p) == 'n') { + goto error; + } + + /* "nt" */ + if (tolower((unsigned char)*p) == 'n') { + p++; + if (tolower((unsigned char)*p) == 't') { p++; - if (tolower((unsigned char)*p) == 't') { - p++; - *token = ecommunity_token_nt; - return p; - } - if (isspace((unsigned char)*p) || *p == '\0') { - *token = ecommunity_token_nt; - return p; - } - goto error; + *token = ecommunity_token_nt; + return p; + } + if (isspace((unsigned char)*p) || *p == '\0') { + *token = ecommunity_token_nt; + return p; } - /* "soo" match check. */ - else if (tolower((unsigned char)*p) == 's') { + goto error; + } + + /* "soo" */ + if (tolower((unsigned char)*p) == 's') { + p++; + if (tolower((unsigned char)*p) == 'o') { p++; if (tolower((unsigned char)*p) == 'o') { p++; - if (tolower((unsigned char)*p) == 'o') { - p++; - *token = ecommunity_token_soo; - return p; - } - if (isspace((unsigned char)*p) || *p == '\0') { - *token = ecommunity_token_soo; - return p; - } - goto error; + *token = ecommunity_token_soo; + return p; } if (isspace((unsigned char)*p) || *p == '\0') { *token = ecommunity_token_soo; @@ -613,9 +633,29 @@ static const char *ecommunity_gettoken(const char *str, void *eval_ptr, } goto error; } + if (isspace((unsigned char)*p) || *p == '\0') { + *token = ecommunity_token_soo; + return p; + } goto error; } + /* "color" */ + if (tolower((unsigned char)*p) == 'c') { + ptr_color = &str_color[0]; + for (unsigned int i = 0; i < 5; i++) { + if (tolower((unsigned char)*p) != *ptr_color) + break; + + p++; + ptr_color++; + } + if (isspace((unsigned char)*p) || *p == '\0') { + *token = ecommunity_token_color; + return p; + } + goto error; + } /* What a mess, there are several possibilities: * * a) A.B.C.D:MN @@ -716,17 +756,24 @@ static const char *ecommunity_gettoken(const char *str, void *eval_ptr, } else { digit = 1; - /* We're past the IP/ASN part */ + /* We're past the IP/ASN part, + * or we have a color + */ if (separator) { val *= 10; val += (*p - '0'); + val_color_set = false; + } else { + val_color *= 10; + val_color += (*p - '0'); + val_color_set = true; } } p++; } /* Low digit part must be there. */ - if (!digit || !separator) + if (!digit && (!separator || !val_color_set)) goto error; /* Encode result into extended community. */ @@ -734,9 +781,15 @@ static const char *ecommunity_gettoken(const char *str, void *eval_ptr, ecomm_type = ECOMMUNITY_ENCODE_IP; else if (as > BGP_AS_MAX) ecomm_type = ECOMMUNITY_ENCODE_AS4; - else + else if (as > 0) ecomm_type = ECOMMUNITY_ENCODE_AS; - if (ecommunity_encode(ecomm_type, type, 1, as, ip, val, eval)) + else if (val_color) { + ecomm_type = ECOMMUNITY_ENCODE_OPAQUE; + sub_type = ECOMMUNITY_COLOR; + val = val_color; + } + + if (ecommunity_encode(ecomm_type, sub_type, 1, as, ip, val, eval)) goto error; *token = ecommunity_token_val; return p; @@ -763,6 +816,7 @@ static struct ecommunity *ecommunity_str2com_internal(const char *str, int type, case ecommunity_token_nt: case ecommunity_token_rt6: case ecommunity_token_soo: + case ecommunity_token_color: if (!keyword_included || keyword) { if (ecom) ecommunity_free(&ecom); @@ -771,15 +825,14 @@ static struct ecommunity *ecommunity_str2com_internal(const char *str, int type, keyword = 1; if (token == ecommunity_token_rt || - token == ecommunity_token_rt6) { + token == ecommunity_token_rt6) type = ECOMMUNITY_ROUTE_TARGET; - } - if (token == ecommunity_token_soo) { + if (token == ecommunity_token_soo) type = ECOMMUNITY_SITE_ORIGIN; - } - if (token == ecommunity_token_nt) { + if (token == ecommunity_token_nt) type = ECOMMUNITY_NODE_TARGET; - } + if (token == ecommunity_token_color) + type = ECOMMUNITY_COLOR; break; case ecommunity_token_val: if (keyword_included) { @@ -989,27 +1042,55 @@ static int ecommunity_lb_str(char *buf, size_t bufsz, const uint8_t *pnt, return len; } -/* Convert extended community attribute to string. - - Due to historical reason of industry standard implementation, there - are three types of format. - - route-map set extcommunity format - "rt 100:1 100:2soo 100:3" +bool ecommunity_has_route_target(struct ecommunity *ecom) +{ + uint32_t i; + uint8_t *pnt; + uint8_t type = 0; + uint8_t sub_type = 0; - extcommunity-list - "rt 100:1 rt 100:2 soo 100:3show [ip] bgp" and extcommunity-list regular expression matching - "RT:100:1 RT:100:2 SoO:100:3" + if (!ecom) + return false; + for (i = 0; i < ecom->size; i++) { + /* Retrieve value field */ + pnt = ecom->val + (i * ecom->unit_size); - For each formath please use below definition for format: + /* High-order octet is the type */ + type = *pnt++; - ECOMMUNITY_FORMAT_ROUTE_MAP - ECOMMUNITY_FORMAT_COMMUNITY_LIST - ECOMMUNITY_FORMAT_DISPLAY + if (type == ECOMMUNITY_ENCODE_AS || + type == ECOMMUNITY_ENCODE_IP || + type == ECOMMUNITY_ENCODE_AS4) { + /* Low-order octet of type. */ + sub_type = *pnt++; + if (sub_type == ECOMMUNITY_ROUTE_TARGET) + return true; + } + } + return false; +} - Filter is added to display only ECOMMUNITY_ROUTE_TARGET in some cases. - 0 value displays all -*/ +/* Convert extended community attribute to string. + * Due to historical reason of industry standard implementation, there + * are three types of format: + * + * route-map set extcommunity format: + * "rt 100:1 100:2soo 100:3" + * + * extcommunity-list: + * "rt 100:1 rt 100:2 soo 100:3" + * + * show bgp: + * "RT:100:1 RT:100:2 SoO:100:3" + * + * For each format please use below definition for format: + * ECOMMUNITY_FORMAT_ROUTE_MAP + * ECOMMUNITY_FORMAT_COMMUNITY_LIST + * ECOMMUNITY_FORMAT_DISPLAY + * + * Filter is added to display only ECOMMUNITY_ROUTE_TARGET in some cases. + * 0 value displays all. + */ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter) { uint32_t i; @@ -1086,6 +1167,9 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter) } else if (*pnt == ECOMMUNITY_EVPN_SUBTYPE_DEF_GW) { strlcpy(encbuf, "Default Gateway", sizeof(encbuf)); + } else if (*pnt == ECOMMUNITY_COLOR) { + ecommunity_color_str(encbuf, sizeof(encbuf), + pnt); } else { unk_ecom = 1; } @@ -1353,6 +1437,29 @@ bool ecommunity_match(const struct ecommunity *ecom1, return false; } +/* return last occurence of color */ +/* it will be the greatest color value */ +extern uint32_t ecommunity_select_color(const struct ecommunity *ecom) +{ + + uint32_t aux_color = 0; + uint8_t *p; + uint32_t c = 0; + + /* If the value already exists in the structure return 0. */ + + for (p = ecom->val; c < ecom->size; p += ecom->unit_size, c++) { + if (p == NULL) + break; + + if (p[0] == ECOMMUNITY_ENCODE_OPAQUE && + p[1] == ECOMMUNITY_COLOR) + ptr_get_be32((const uint8_t *)&p[4], &aux_color); + } + return aux_color; +} + + /* return first occurence of type */ extern struct ecommunity_val *ecommunity_lookup(const struct ecommunity *ecom, uint8_t type, uint8_t subtype) @@ -1502,8 +1609,8 @@ int ecommunity_fill_pbr_action(struct ecommunity_val *ecom_eval, * in the 'Network Address of Next- Hop' * field of the associated MP_REACH_NLRI. */ - struct ecommunity_ip *ip_ecom = (struct ecommunity_ip *) - ecom_eval + 2; + struct ecommunity_ip *ip_ecom = + (struct ecommunity_ip *)&ecom_eval->val[2]; api->u.zr.redirect_ip_v4 = ip_ecom->ip; } else @@ -1765,3 +1872,18 @@ struct ecommunity *ecommunity_replace_linkbw(as_t as, struct ecommunity *ecom, return new; } + +bool soo_in_ecom(struct ecommunity *ecom, struct ecommunity *soo) +{ + if (ecom && soo) { + if ((ecommunity_lookup(ecom, ECOMMUNITY_ENCODE_AS, + ECOMMUNITY_SITE_ORIGIN) || + ecommunity_lookup(ecom, ECOMMUNITY_ENCODE_AS4, + ECOMMUNITY_SITE_ORIGIN) || + ecommunity_lookup(ecom, ECOMMUNITY_ENCODE_IP, + ECOMMUNITY_SITE_ORIGIN)) && + ecommunity_include(ecom, soo)) + return true; + } + return false; +} diff --git a/bgpd/bgp_ecommunity.h b/bgpd/bgp_ecommunity.h index 94a178bbb6..f12d0dd3ee 100644 --- a/bgpd/bgp_ecommunity.h +++ b/bgpd/bgp_ecommunity.h @@ -46,6 +46,8 @@ #define ECOMMUNITY_REDIRECT_VRF 0x08 #define ECOMMUNITY_TRAFFIC_MARKING 0x09 #define ECOMMUNITY_REDIRECT_IP_NH 0x00 +#define ECOMMUNITY_COLOR 0x0b /* RFC9012 - color */ + /* from IANA: bgp-extended-communities/bgp-extended-communities.xhtml * 0x0c Flow-spec Redirect to IPv4 - draft-ietf-idr-flowspec-redirect */ @@ -290,6 +292,35 @@ static inline void encode_node_target(struct in_addr *node_id, eval->val[7] = ECOMMUNITY_NODE_TARGET_RESERVED; } +/* + * Encode BGP Color extended community + * is's a transitive opaque Extended community (RFC 9012 4.3) + * flag is set to 0 + * RFC 9012 14.10: No values have currently been registered. + * 4.3: this field MUST be set to zero by the originator + * and ignored by the receiver; + * + */ +static inline void encode_color(uint32_t color_id, struct ecommunity_val *eval) +{ + /* + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | 0x03 | Sub-Type(0x0b) | Flags | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Color Value | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + memset(eval, 0, sizeof(*eval)); + eval->val[0] = ECOMMUNITY_ENCODE_OPAQUE; + eval->val[1] = ECOMMUNITY_COLOR; + eval->val[2] = 0x00; + eval->val[3] = 0x00; + eval->val[4] = (color_id >> 24) & 0xff; + eval->val[5] = (color_id >> 16) & 0xff; + eval->val[6] = (color_id >> 8) & 0xff; + eval->val[7] = color_id & 0xff; +} + extern void ecommunity_init(void); extern void ecommunity_finish(void); extern void ecommunity_free(struct ecommunity **); @@ -310,14 +341,16 @@ extern struct ecommunity *ecommunity_str2com(const char *, int, int); extern struct ecommunity *ecommunity_str2com_ipv6(const char *str, int type, int keyword_included); extern char *ecommunity_ecom2str(struct ecommunity *, int, int); +extern bool ecommunity_has_route_target(struct ecommunity *ecom); extern void ecommunity_strfree(char **s); extern bool ecommunity_include(struct ecommunity *e1, struct ecommunity *e2); extern bool ecommunity_match(const struct ecommunity *, const struct ecommunity *); -extern char *ecommunity_str(struct ecommunity *); +extern char *ecommunity_str(struct ecommunity *ecom); extern struct ecommunity_val *ecommunity_lookup(const struct ecommunity *, uint8_t, uint8_t); +extern uint32_t ecommunity_select_color(const struct ecommunity *ecom); extern bool ecommunity_add_val(struct ecommunity *ecom, struct ecommunity_val *eval, bool unique, bool overwrite); @@ -360,6 +393,8 @@ extern struct ecommunity *ecommunity_replace_linkbw(as_t as, uint64_t cum_bw, bool disable_ieee_floating); +extern bool soo_in_ecom(struct ecommunity *ecom, struct ecommunity *soo); + static inline void ecommunity_strip_rts(struct ecommunity *ecom) { uint8_t subtype = ECOMMUNITY_ROUTE_TARGET; diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index fc8889c175..1a4364bb74 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -41,6 +41,7 @@ #include "bgpd/bgp_nht.h" #include "bgpd/bgp_trace.h" #include "bgpd/bgp_mpath.h" +#include "bgpd/bgp_packet.h" /* * Definitions and external declarations. @@ -48,6 +49,7 @@ DEFINE_QOBJ_TYPE(bgpevpn); DEFINE_QOBJ_TYPE(bgp_evpn_es); +DEFINE_MTYPE_STATIC(BGPD, BGP_EVPN_INFO, "BGP EVPN instance information"); DEFINE_MTYPE_STATIC(BGPD, VRF_ROUTE_TARGET, "L3 Route Target"); /* @@ -309,6 +311,39 @@ static int is_vni_present_in_irt_vnis(struct list *vnis, struct bgpevpn *vpn) return 0; } +/* Flag if the route is injectable into EVPN. + * This would be following category: + * Non-imported route, + * Non-EVPN imported route, + * Non Aggregate suppressed route. + */ +bool is_route_injectable_into_evpn(struct bgp_path_info *pi) +{ + struct bgp_path_info *parent_pi; + struct bgp_table *table; + struct bgp_dest *dest; + + /* do not import aggr suppressed routes */ + if (bgp_path_suppressed(pi)) + return false; + + if (pi->sub_type != BGP_ROUTE_IMPORTED || !pi->extra || + !pi->extra->vrfleak || !pi->extra->vrfleak->parent) + return true; + + parent_pi = (struct bgp_path_info *)pi->extra->vrfleak->parent; + dest = parent_pi->net; + if (!dest) + return true; + table = bgp_dest_table(dest); + if (table && + table->afi == AFI_L2VPN && + table->safi == SAFI_EVPN) + return false; + + return true; +} + /* * Compare Route Targets. */ @@ -879,7 +914,7 @@ static int bgp_zebra_send_remote_macip(struct bgp *bgp, struct bgpevpn *vpn, zclient_create_header( s, add ? ZEBRA_REMOTE_MACIP_ADD : ZEBRA_REMOTE_MACIP_DEL, bgp->vrf_id); - stream_putl(s, vpn->vni); + stream_putl(s, vpn ? vpn->vni : 0); if (mac) /* Mac Addr */ stream_put(s, &mac->octet, ETH_ALEN); @@ -925,7 +960,7 @@ static int bgp_zebra_send_remote_macip(struct bgp *bgp, struct bgpevpn *vpn, snprintf(esi_buf, sizeof(esi_buf), "-"); zlog_debug( "Tx %s MACIP, VNI %u MAC %pEA IP %pIA flags 0x%x seq %u remote VTEP %pI4 esi %s", - add ? "ADD" : "DEL", vpn->vni, + add ? "ADD" : "DEL", (vpn ? vpn->vni : 0), (mac ? mac : &p->prefix.macip_addr.mac), &p->prefix.macip_addr.ip, flags, seq, &remote_vtep_ip, esi_buf); @@ -934,7 +969,10 @@ static int bgp_zebra_send_remote_macip(struct bgp *bgp, struct bgpevpn *vpn, frrtrace(5, frr_bgp, evpn_mac_ip_zsend, add, vpn, p, remote_vtep_ip, esi); - return zclient_send_message(zclient); + if (zclient_send_message(zclient) == ZCLIENT_SEND_FAILURE) + return -1; + + return 0; } /* @@ -965,14 +1003,14 @@ static int bgp_zebra_send_remote_vtep(struct bgp *bgp, struct bgpevpn *vpn, zclient_create_header( s, add ? ZEBRA_REMOTE_VTEP_ADD : ZEBRA_REMOTE_VTEP_DEL, bgp->vrf_id); - stream_putl(s, vpn->vni); + stream_putl(s, vpn ? vpn->vni : 0); if (is_evpn_prefix_ipaddr_v4(p)) stream_put_in_addr(s, &p->prefix.imet_addr.ip.ipaddr_v4); else if (is_evpn_prefix_ipaddr_v6(p)) { flog_err( EC_BGP_VTEP_INVALID, "Bad remote IP when trying to %s remote VTEP for VNI %u", - add ? "ADD" : "DEL", vpn->vni); + add ? "ADD" : "DEL", (vpn ? vpn->vni : 0)); return -1; } stream_putl(s, flood_control); @@ -981,12 +1019,15 @@ static int bgp_zebra_send_remote_vtep(struct bgp *bgp, struct bgpevpn *vpn, if (bgp_debug_zebra(NULL)) zlog_debug("Tx %s Remote VTEP, VNI %u remote VTEP %pI4", - add ? "ADD" : "DEL", vpn->vni, + add ? "ADD" : "DEL", (vpn ? vpn->vni : 0), &p->prefix.imet_addr.ip.ipaddr_v4); frrtrace(3, frr_bgp, evpn_bum_vtep_zsend, add, vpn, p); - return zclient_send_message(zclient); + if (zclient_send_message(zclient) == ZCLIENT_SEND_FAILURE) + return -1; + + return 0; } /* @@ -1050,7 +1091,8 @@ static void build_evpn_type5_route_extcomm(struct bgp *bgp_vrf, * type-2 routes. */ static void build_evpn_route_extcomm(struct bgpevpn *vpn, struct attr *attr, - int add_l3_ecomm) + int add_l3_ecomm, + struct ecommunity *macvrf_soo) { struct ecommunity ecom_encap; struct ecommunity ecom_sticky; @@ -1147,6 +1189,11 @@ static void build_evpn_route_extcomm(struct bgpevpn *vpn, struct attr *attr, attr, ecommunity_merge(bgp_attr_get_ecommunity(attr), &ecom_na)); } + + /* Add MAC-VRF SoO, if configured */ + if (macvrf_soo) + bgp_attr_set_ecommunity( + attr, ecommunity_merge(attr->ecommunity, macvrf_soo)); } /* @@ -1624,6 +1671,9 @@ static int update_evpn_type5_route(struct bgp *bgp_vrf, struct prefix_evpn *evp, vrf_id_to_name(bgp_vrf->vrf_id), evp, &attr.rmac, &attr.nexthop); + frrtrace(4, frr_bgp, evpn_advertise_type5, bgp_vrf->vrf_id, evp, + &attr.rmac, attr.nexthop); + attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV4; if (src_afi == AFI_IP6 && @@ -1685,7 +1735,7 @@ static void bgp_evpn_get_sync_info(struct bgp *bgp, esi_t *esi, int paths_eq; struct ethaddr *tmp_mac; bool mac_cmp = false; - struct prefix_evpn *evp = (struct prefix_evpn *)&dest->p; + struct prefix_evpn *evp = (struct prefix_evpn *)&dest->rn->p; /* mac comparison is not needed for MAC-only routes */ @@ -1708,8 +1758,8 @@ static void bgp_evpn_get_sync_info(struct bgp *bgp, esi_t *esi, continue; } - if (bgp_evpn_path_info_cmp(bgp, tmp_pi, - second_best_path, &paths_eq)) + if (bgp_evpn_path_info_cmp(bgp, tmp_pi, second_best_path, + &paths_eq, false)) second_best_path = tmp_pi; } @@ -1910,7 +1960,8 @@ static int update_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn, /* Mark route as self type-2 route */ if (flags && CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_SVI_IP)) - tmp_pi->extra->af_flags = BGP_EVPN_MACIP_TYPE_SVI_IP; + tmp_pi->extra->evpn->af_flags = + BGP_EVPN_MACIP_TYPE_SVI_IP; bgp_path_info_add(dest, tmp_pi); } else { tmp_pi = local_pi; @@ -2020,10 +2071,10 @@ static void evpn_zebra_reinstall_best_route(struct bgp *bgp, * additional handling to prevent bgp from injecting and holding on to a * non-best local path. */ -static void evpn_cleanup_local_non_best_route(struct bgp *bgp, - struct bgpevpn *vpn, - struct bgp_dest *dest, - struct bgp_path_info *local_pi) +static struct bgp_dest * +evpn_cleanup_local_non_best_route(struct bgp *bgp, struct bgpevpn *vpn, + struct bgp_dest *dest, + struct bgp_path_info *local_pi) { /* local path was not picked as the winner; kick it out */ if (bgp_debug_zebra(NULL)) @@ -2031,10 +2082,11 @@ static void evpn_cleanup_local_non_best_route(struct bgp *bgp, dest); evpn_delete_old_local_route(bgp, vpn, dest, local_pi, NULL); - bgp_path_info_reap(dest, local_pi); /* tell zebra to re-add the best remote path */ evpn_zebra_reinstall_best_route(bgp, vpn, dest); + + return bgp_path_info_reap(dest, local_pi); } static inline bool bgp_evpn_route_add_l3_ecomm_ok(struct bgpevpn *vpn, @@ -2068,6 +2120,7 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn, int route_change; bool old_is_sync = false; bool mac_only = false; + struct ecommunity *macvrf_soo = NULL; memset(&attr, 0, sizeof(attr)); @@ -2125,8 +2178,11 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn, add_l3_ecomm = bgp_evpn_route_add_l3_ecomm_ok( vpn, p, (attr.es_flags & ATTR_ES_IS_LOCAL) ? &attr.esi : NULL); + if (bgp->evpn_info) + macvrf_soo = bgp->evpn_info->soo; + /* Set up extended community. */ - build_evpn_route_extcomm(vpn, &attr, add_l3_ecomm); + build_evpn_route_extcomm(vpn, &attr, add_l3_ecomm, macvrf_soo); /* First, create (or fetch) route node within the VNI. * NOTE: There is no RD here. @@ -2167,7 +2223,8 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn, } else { if (!CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)) { route_change = 0; - evpn_cleanup_local_non_best_route(bgp, vpn, dest, pi); + dest = evpn_cleanup_local_non_best_route(bgp, vpn, dest, + pi); } else { bool new_is_sync; @@ -2184,7 +2241,8 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn, } bgp_path_info_unlock(pi); - bgp_dest_unlock_node(dest); + if (dest) + bgp_dest_unlock_node(dest); /* If this is a new route or some attribute has changed, export the * route to the global table. The route will be advertised to peers @@ -2258,6 +2316,8 @@ static int delete_evpn_type5_route(struct bgp *bgp_vrf, struct prefix_evpn *evp) if (!dest) return 0; + frrtrace(2, frr_bgp, evpn_withdraw_type5, bgp_vrf->vrf_id, evp); + delete_evpn_route_entry(bgp_evpn, afi, safi, dest, &pi); if (pi) bgp_process(bgp_evpn, dest, afi, safi); @@ -2308,9 +2368,13 @@ static int delete_evpn_route(struct bgp *bgp, struct bgpevpn *vpn, */ delete_evpn_route_entry(bgp, afi, safi, dest, &pi); if (pi) { - bgp_path_info_reap(dest, pi); + dest = bgp_path_info_reap(dest, pi); + assert(dest); evpn_route_select_install(bgp, vpn, dest); } + + /* dest should still exist due to locking make coverity happy */ + assert(dest); bgp_dest_unlock_node(dest); return 0; @@ -2333,6 +2397,7 @@ void bgp_evpn_update_type2_route_entry(struct bgp *bgp, struct bgpevpn *vpn, struct prefix_evpn evp; int route_change; bool old_is_sync = false; + struct ecommunity *macvrf_soo = NULL; if (CHECK_FLAG(local_pi->flags, BGP_PATH_REMOVED)) return; @@ -2341,15 +2406,15 @@ void bgp_evpn_update_type2_route_entry(struct bgp *bgp, struct bgpevpn *vpn, * VNI table MAC-IP prefixes don't have MAC so make sure it's set from * path info here. */ - if (is_evpn_prefix_ipaddr_none((struct prefix_evpn *)&dest->p)) { + if (is_evpn_prefix_ipaddr_none((struct prefix_evpn *)&dest->rn->p)) { /* VNI MAC -> Global */ evpn_type2_prefix_global_copy( - &evp, (struct prefix_evpn *)&dest->p, NULL /* mac */, + &evp, (struct prefix_evpn *)&dest->rn->p, NULL /* mac */, evpn_type2_path_info_get_ip(local_pi)); } else { /* VNI IP -> Global */ evpn_type2_prefix_global_copy( - &evp, (struct prefix_evpn *)&dest->p, + &evp, (struct prefix_evpn *)&dest->rn->p, evpn_type2_path_info_get_mac(local_pi), NULL /* ip */); } @@ -2371,7 +2436,8 @@ void bgp_evpn_update_type2_route_entry(struct bgp *bgp, struct bgpevpn *vpn, attr.router_flag = 1; } memcpy(&attr.esi, &local_pi->attr->esi, sizeof(esi_t)); - bgp_evpn_get_rmac_nexthop(vpn, &evp, &attr, local_pi->extra->af_flags); + bgp_evpn_get_rmac_nexthop(vpn, &evp, &attr, + local_pi->extra->evpn->af_flags); vni2label(vpn->vni, &(attr.label)); /* Add L3 VNI RTs and RMAC for non IPv6 link-local if * using L3 VNI for type-2 routes also. @@ -2380,8 +2446,11 @@ void bgp_evpn_update_type2_route_entry(struct bgp *bgp, struct bgpevpn *vpn, vpn, &evp, (attr.es_flags & ATTR_ES_IS_LOCAL) ? &attr.esi : NULL); + if (bgp->evpn_info) + macvrf_soo = bgp->evpn_info->soo; + /* Set up extended community. */ - build_evpn_route_extcomm(vpn, &attr, add_l3_ecomm); + build_evpn_route_extcomm(vpn, &attr, add_l3_ecomm, macvrf_soo); seq = mac_mobility_seqnum(local_pi->attr); if (bgp_debug_zebra(NULL)) { @@ -2547,7 +2616,8 @@ static void delete_global_type2_routes(struct bgp *bgp, struct bgpevpn *vpn) } } -static void delete_vni_type2_route(struct bgp *bgp, struct bgp_dest *dest) +static struct bgp_dest *delete_vni_type2_route(struct bgp *bgp, + struct bgp_dest *dest) { struct bgp_path_info *pi; afi_t afi = AFI_L2VPN; @@ -2557,13 +2627,15 @@ static void delete_vni_type2_route(struct bgp *bgp, struct bgp_dest *dest) (const struct prefix_evpn *)bgp_dest_get_prefix(dest); if (evp->prefix.route_type != BGP_EVPN_MAC_IP_ROUTE) - return; + return dest; delete_evpn_route_entry(bgp, afi, safi, dest, &pi); /* Route entry in local table gets deleted immediately. */ if (pi) - bgp_path_info_reap(dest, pi); + dest = bgp_path_info_reap(dest, pi); + + return dest; } static void delete_vni_type2_routes(struct bgp *bgp, struct bgpevpn *vpn) @@ -2574,12 +2646,16 @@ static void delete_vni_type2_routes(struct bgp *bgp, struct bgpevpn *vpn) * routes. */ for (dest = bgp_table_top(vpn->mac_table); dest; - dest = bgp_route_next(dest)) - delete_vni_type2_route(bgp, dest); + dest = bgp_route_next(dest)) { + dest = delete_vni_type2_route(bgp, dest); + assert(dest); + } for (dest = bgp_table_top(vpn->ip_table); dest; - dest = bgp_route_next(dest)) - delete_vni_type2_route(bgp, dest); + dest = bgp_route_next(dest)) { + dest = delete_vni_type2_route(bgp, dest); + assert(dest); + } } /* @@ -2611,7 +2687,9 @@ static void delete_all_vni_routes(struct bgp *bgp, struct bgpevpn *vpn) (pi != NULL) && (nextpi = pi->next, 1); pi = nextpi) { bgp_evpn_remote_ip_hash_del(vpn, pi); bgp_path_info_delete(dest, pi); - bgp_path_info_reap(dest, pi); + dest = bgp_path_info_reap(dest, pi); + + assert(dest); } } @@ -2620,7 +2698,9 @@ static void delete_all_vni_routes(struct bgp *bgp, struct bgpevpn *vpn) for (pi = bgp_dest_get_bgp_path_info(dest); (pi != NULL) && (nextpi = pi->next, 1); pi = nextpi) { bgp_path_info_delete(dest, pi); - bgp_path_info_reap(dest, pi); + dest = bgp_path_info_reap(dest, pi); + + assert(dest); } } } @@ -2673,6 +2753,21 @@ int update_routes_for_vni(struct bgp *bgp, struct bgpevpn *vpn) return 0; } +/* Update Type-2/3 Routes for L2VNI. + * Called by hash_iterate() + */ +static void update_routes_for_vni_hash(struct hash_bucket *bucket, + struct bgp *bgp) +{ + struct bgpevpn *vpn; + + if (!bucket) + return; + + vpn = (struct bgpevpn *)bucket->data; + update_routes_for_vni(bgp, vpn); +} + /* * Delete (and withdraw) local routes for specified VNI from the global * table and per-VNI table. After this, remove all other routes from @@ -2720,43 +2815,60 @@ static int bgp_evpn_mcast_grp_change(struct bgp *bgp, struct bgpevpn *vpn, } /* - * There is a tunnel endpoint IP address change for this VNI, delete - * prior type-3 route (if needed) and update. + * If there is a tunnel endpoint IP address (VTEP-IP) change for this VNI. + - Deletes tip_hash entry for old VTEP-IP + - Adds tip_hash entry/refcount for new VTEP-IP + - Deletes prior type-3 route for L2VNI (if needed) + - Updates originator_ip * Note: Route re-advertisement happens elsewhere after other processing * other changes. */ -static void handle_tunnel_ip_change(struct bgp *bgp, struct bgpevpn *vpn, +static void handle_tunnel_ip_change(struct bgp *bgp_vrf, struct bgp *bgp_evpn, + struct bgpevpn *vpn, struct in_addr originator_ip) { struct prefix_evpn p; + struct in_addr old_vtep_ip; + + if (bgp_vrf) /* L3VNI */ + old_vtep_ip = bgp_vrf->originator_ip; + else /* L2VNI */ + old_vtep_ip = vpn->originator_ip; - if (IPV4_ADDR_SAME(&vpn->originator_ip, &originator_ip)) + /* TIP didn't change, nothing to do */ + if (IPV4_ADDR_SAME(&old_vtep_ip, &originator_ip)) return; - /* If VNI is not live, we only need to update the originator ip */ - if (!is_vni_live(vpn)) { + /* If L2VNI is not live, we only need to update the originator_ip. + * L3VNIs are updated immediately, so we can't bail out early. + */ + if (!bgp_vrf && !is_vni_live(vpn)) { vpn->originator_ip = originator_ip; return; } /* Update the tunnel-ip hash */ - bgp_tip_del(bgp, &vpn->originator_ip); - if (bgp_tip_add(bgp, &originator_ip)) + bgp_tip_del(bgp_evpn, &old_vtep_ip); + if (bgp_tip_add(bgp_evpn, &originator_ip)) /* The originator_ip was not already present in the * bgp martian next-hop table as a tunnel-ip, so we * need to go back and filter routes matching the new * martian next-hop. */ - bgp_filter_evpn_routes_upon_martian_nh_change(bgp); + bgp_filter_evpn_routes_upon_martian_change(bgp_evpn, + BGP_MARTIAN_TUN_IP); - /* Need to withdraw type-3 route as the originator IP is part - * of the key. - */ - build_evpn_type3_prefix(&p, vpn->originator_ip); - delete_evpn_route(bgp, vpn, &p); + if (!bgp_vrf) { + /* Need to withdraw type-3 route as the originator IP is part + * of the key. + */ + build_evpn_type3_prefix(&p, vpn->originator_ip); + delete_evpn_route(bgp_evpn, vpn, &p); + + vpn->originator_ip = originator_ip; + } else + bgp_vrf->originator_ip = originator_ip; - /* Update the tunnel IP and re-advertise all routes for this VNI. */ - vpn->originator_ip = originator_ip; return; } @@ -2775,7 +2887,11 @@ bgp_create_evpn_bgp_path_info(struct bgp_path_info *parent_pi, attr_new, dest); SET_FLAG(pi->flags, BGP_PATH_VALID); bgp_path_info_extra_get(pi); - pi->extra->parent = bgp_path_info_lock(parent_pi); + if (!pi->extra->vrfleak) + pi->extra->vrfleak = + XCALLOC(MTYPE_BGP_ROUTE_EXTRA_VRFLEAK, + sizeof(struct bgp_path_info_extra_vrfleak)); + pi->extra->vrfleak->parent = bgp_path_info_lock(parent_pi); bgp_dest_lock_node((struct bgp_dest *)parent_pi->net); if (parent_pi->extra) { memcpy(&pi->extra->label, &parent_pi->extra->label, @@ -2881,8 +2997,9 @@ static int install_evpn_route_entry_in_vrf(struct bgp *bgp_vrf, /* Check if route entry is already present. */ for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) - if (pi->extra - && (struct bgp_path_info *)pi->extra->parent == parent_pi) + if (pi->extra && pi->extra->vrfleak && + (struct bgp_path_info *)pi->extra->vrfleak->parent == + parent_pi) break; if (!pi) { @@ -2950,13 +3067,24 @@ static int install_evpn_route_entry_in_vrf(struct bgp *bgp_vrf, /* Process for route leaking. */ vpn_leak_from_vrf_update(bgp_get_default(), bgp_vrf, pi); - bgp_dest_unlock_node(dest); + if (bgp_debug_zebra(NULL)) { + struct ipaddr nhip = {}; - if (bgp_debug_zebra(NULL)) - zlog_debug("... %s pi dest %p (l %d) pi %p (l %d, f 0x%x)", - new_pi ? "new" : "update", dest, + if (pi->net->rn->p.family == AF_INET6) { + SET_IPADDR_V6(&nhip); + IPV6_ADDR_COPY(&nhip.ipaddr_v6, &pi->attr->mp_nexthop_global); + } else { + SET_IPADDR_V4(&nhip); + IPV4_ADDR_COPY(&nhip.ipaddr_v4, &pi->attr->nexthop); + } + zlog_debug("... %s pi %s dest %p (l %d) pi %p (l %d, f 0x%x) nh %pIA", + new_pi ? "new" : "update", + bgp_vrf->name_pretty, dest, bgp_dest_get_lock_count(dest), pi, pi->lock, - pi->flags); + pi->flags, &nhip); + } + + bgp_dest_unlock_node(dest); return ret; } @@ -2977,8 +3105,9 @@ static int install_evpn_route_entry_in_vni_common( /* Check if route entry is already present. */ for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) - if (pi->extra - && (struct bgp_path_info *)pi->extra->parent == parent_pi) + if (pi->extra && pi->extra->vrfleak && + (struct bgp_path_info *)pi->extra->vrfleak->parent == + parent_pi) break; if (!pi) { @@ -3029,7 +3158,7 @@ static int install_evpn_route_entry_in_vni_common( if (BGP_DEBUG(evpn_mh, EVPN_MH_RT)) zlog_debug("VNI %d path %pFX chg to %s es", - vpn->vni, &pi->net->p, + vpn->vni, &pi->net->rn->p, new_local_es ? "local" : "non-local"); bgp_path_info_set_flag(dest, pi, BGP_PATH_ATTR_CHANGED); @@ -3073,8 +3202,9 @@ static int uninstall_evpn_route_entry_in_vni_common( /* Find matching route entry. */ for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) - if (pi->extra && - (struct bgp_path_info *)pi->extra->parent == parent_pi) + if (pi->extra && pi->extra->vrfleak && + (struct bgp_path_info *)pi->extra->vrfleak->parent == + parent_pi) break; if (!pi) @@ -3251,8 +3381,9 @@ static int uninstall_evpn_route_entry_in_vrf(struct bgp *bgp_vrf, /* Find matching route entry. */ for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) - if (pi->extra - && (struct bgp_path_info *)pi->extra->parent == parent_pi) + if (pi->extra && pi->extra->vrfleak && + (struct bgp_path_info *)pi->extra->vrfleak->parent == + parent_pi) break; if (!pi) { @@ -3260,10 +3391,22 @@ static int uninstall_evpn_route_entry_in_vrf(struct bgp *bgp_vrf, return 0; } - if (bgp_debug_zebra(NULL)) - zlog_debug("... delete dest %p (l %d) pi %p (l %d, f 0x%x)", - dest, bgp_dest_get_lock_count(dest), pi, pi->lock, - pi->flags); + if (bgp_debug_zebra(NULL)) { + struct ipaddr nhip = {}; + + if (pi->net->rn->p.family == AF_INET6) { + SET_IPADDR_V6(&nhip); + IPV6_ADDR_COPY(&nhip.ipaddr_v6, &pi->attr->mp_nexthop_global); + } else { + SET_IPADDR_V4(&nhip); + IPV4_ADDR_COPY(&nhip.ipaddr_v4, &pi->attr->nexthop); + } + + zlog_debug("... delete pi %s dest %p (l %d) pi %p (l %d, f 0x%x) nh %pIA", + bgp_vrf->name_pretty, dest, + bgp_dest_get_lock_count(dest), pi, pi->lock, + pi->flags, &nhip); + } /* Process for route leaking. */ vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp_vrf, pi); @@ -3271,6 +3414,9 @@ static int uninstall_evpn_route_entry_in_vrf(struct bgp *bgp_vrf, bgp_aggregate_decrement(bgp_vrf, bgp_dest_get_prefix(dest), pi, afi, safi); + /* Force deletion */ + SET_FLAG(dest->flags, BGP_NODE_PROCESS_CLEAR); + /* Mark entry for deletion */ bgp_path_info_delete(dest, pi); @@ -3366,7 +3512,7 @@ static int uninstall_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn, /* * Given a route entry and a VRF, see if this route entry should be - * imported into the VRF i.e., RTs match. + * imported into the VRF i.e., RTs match + Site-of-Origin check passes. */ static int is_route_matching_for_vrf(struct bgp *bgp_vrf, struct bgp_path_info *pi) @@ -3498,6 +3644,41 @@ static int is_route_matching_for_vni(struct bgp *bgp, struct bgpevpn *vpn, return 0; } +static bool bgp_evpn_route_matches_macvrf_soo(struct bgp_path_info *pi, + const struct prefix_evpn *evp) +{ + struct bgp *bgp_evpn = bgp_get_evpn(); + struct ecommunity *macvrf_soo; + bool ret = false; + + if (!bgp_evpn || !bgp_evpn->evpn_info) + return false; + + /* We only stamp the mac-vrf soo on routes from our local L2VNI. + * No need to filter additional EVPN routes that originated outside + * the MAC-VRF/L2VNI. + */ + if (evp->prefix.route_type != BGP_EVPN_MAC_IP_ROUTE && + evp->prefix.route_type != BGP_EVPN_IMET_ROUTE) + return false; + + macvrf_soo = bgp_evpn->evpn_info->soo; + ret = route_matches_soo(pi, macvrf_soo); + + if (ret && bgp_debug_zebra(NULL)) { + char *ecom_str; + + ecom_str = ecommunity_ecom2str(macvrf_soo, + ECOMMUNITY_FORMAT_ROUTE_MAP, 0); + zlog_debug( + "import of evpn prefix %pFX skipped, local mac-vrf soo %s", + evp, ecom_str); + ecommunity_strfree(&ecom_str); + } + + return ret; +} + /* This API will scan evpn routes for checking attribute's rmac * macthes with bgp instance router mac. It avoid installing * route into bgp vrf table and remote rmac in bridge table. @@ -3583,8 +3764,9 @@ int bgp_evpn_route_entry_install_if_vrf_match(struct bgp *bgp_vrf, return 0; /* don't import hosts that are locally attached */ - if (install && bgp_evpn_skip_vrf_import_of_local_es( - bgp_vrf, evp, pi, install)) + if (install && (bgp_evpn_skip_vrf_import_of_local_es( + bgp_vrf, evp, pi, install) || + bgp_evpn_route_matches_macvrf_soo(pi, evp))) return 0; if (install) @@ -3654,8 +3836,11 @@ static int install_uninstall_routes_for_vrf(struct bgp *bgp_vrf, int install) pi = pi->next) { ret = bgp_evpn_route_entry_install_if_vrf_match( bgp_vrf, pi, install); - if (ret) + if (ret) { + bgp_dest_unlock_node(rd_dest); + bgp_dest_unlock_node(dest); return ret; + } } } } @@ -3713,30 +3898,35 @@ static int install_uninstall_routes_for_vni(struct bgp *bgp, && pi->sub_type == BGP_ROUTE_NORMAL)) continue; - if (is_route_matching_for_vni(bgp, vpn, pi)) { - if (install) - ret = install_evpn_route_entry( - bgp, vpn, evp, pi); - else - ret = uninstall_evpn_route_entry( - bgp, vpn, evp, pi); - - if (ret) { - flog_err( - EC_BGP_EVPN_FAIL, - "%u: Failed to %s EVPN %s route in VNI %u", - bgp->vrf_id, - install ? "install" - : "uninstall", - rtype == BGP_EVPN_MAC_IP_ROUTE - ? "MACIP" - : "IMET", - vpn->vni); - - bgp_dest_unlock_node(rd_dest); - bgp_dest_unlock_node(dest); - return ret; - } + if (!is_route_matching_for_vni(bgp, vpn, pi)) + continue; + + if (install) { + if (bgp_evpn_route_matches_macvrf_soo( + pi, evp)) + continue; + + ret = install_evpn_route_entry(bgp, vpn, + evp, pi); + } else + ret = uninstall_evpn_route_entry( + bgp, vpn, evp, pi); + + if (ret) { + flog_err( + EC_BGP_EVPN_FAIL, + "%u: Failed to %s EVPN %s route in VNI %u", + bgp->vrf_id, + install ? "install" + : "uninstall", + rtype == BGP_EVPN_MAC_IP_ROUTE + ? "MACIP" + : "IMET", + vpn->vni); + + bgp_dest_unlock_node(rd_dest); + bgp_dest_unlock_node(dest); + return ret; } } } @@ -3942,6 +4132,12 @@ static int bgp_evpn_install_uninstall_table(struct bgp *bgp, afi_t afi, if (!ecom || !ecom->size) return -1; + /* Filter routes carrying a Site-of-Origin that matches our + * local MAC-VRF SoO. + */ + if (import && bgp_evpn_route_matches_macvrf_soo(pi, evp)) + return 0; + /* An EVPN route belongs to a VNI or a VRF or an ESI based on the RTs * attached to the route */ for (i = 0; i < ecom->size; i++) { @@ -4057,7 +4253,7 @@ void bgp_evpn_import_type2_route(struct bgp_path_info *pi, int import) return; install_uninstall_evpn_route(bgp_evpn, AFI_L2VPN, SAFI_EVPN, - &pi->net->p, pi, import); + &pi->net->rn->p, pi, import); } /* @@ -5489,6 +5685,46 @@ void bgp_evpn_handle_rd_change(struct bgp *bgp, struct bgpevpn *vpn, update_advertise_vni_routes(bgp, vpn); } +/* "mac-vrf soo" vty handler + * Handle change to the global MAC-VRF Site-of-Origin: + * - Unimport routes with new SoO from VNI/VRF + * - Import routes with old SoO into VNI/VRF + * - Update SoO on local VNI routes + re-advertise + */ +void bgp_evpn_handle_global_macvrf_soo_change(struct bgp *bgp, + struct ecommunity *new_soo) +{ + struct ecommunity *old_soo; + + old_soo = bgp->evpn_info->soo; + + /* cleanup and bail out if old_soo == new_soo */ + if (ecommunity_match(old_soo, new_soo)) { + ecommunity_free(&new_soo); + return; + } + + /* set new_soo */ + bgp->evpn_info->soo = new_soo; + + /* Unimport routes matching the new_soo */ + bgp_filter_evpn_routes_upon_martian_change(bgp, BGP_MARTIAN_SOO); + + /* Reimport routes with old_soo and !new_soo. + */ + bgp_reimport_evpn_routes_upon_martian_change( + bgp, BGP_MARTIAN_SOO, (void *)old_soo, (void *)new_soo); + + /* Update locally originated routes for all L2VNIs */ + hash_iterate(bgp->vnihash, + (void (*)(struct hash_bucket *, + void *))update_routes_for_vni_hash, + bgp); + + /* clear old_soo */ + ecommunity_free(&old_soo); +} + /* * Install routes for this VNI. Invoked upon change to Import RT. */ @@ -5922,7 +6158,7 @@ void bgp_evpn_derive_auto_rd(struct bgp *bgp, struct bgpevpn *vpn) snprintfrr(buf, sizeof(buf), "%pI4:%hu", &bgp->router_id, vpn->rd_id); (void)str2prefix_rd(buf, &vpn->prd); if (vpn->prd_pretty) - XFREE(MTYPE_BGP, vpn->prd_pretty); + XFREE(MTYPE_BGP_NAME, vpn->prd_pretty); UNSET_FLAG(vpn->flags, VNI_FLAG_RD_CFGD); } @@ -6028,7 +6264,7 @@ void bgp_evpn_free(struct bgp *bgp, struct bgpevpn *vpn) hash_release(bgp->vni_svi_hash, vpn); hash_release(bgp->vnihash, vpn); if (vpn->prd_pretty) - XFREE(MTYPE_BGP, vpn->prd_pretty); + XFREE(MTYPE_BGP_NAME, vpn->prd_pretty); QOBJ_UNREG(vpn); XFREE(MTYPE_BGP_EVPN, vpn); } @@ -6056,8 +6292,12 @@ int bgp_evpn_unimport_route(struct bgp *bgp, afi_t afi, safi_t safi, return install_uninstall_evpn_route(bgp, afi, safi, p, pi, 0); } -/* filter routes which have martian next hops */ -int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp *bgp) +/* Refresh previously-discarded EVPN routes carrying "self" MAC-VRF SoO. + * Walk global EVPN rib + import remote routes with old_soo && !new_soo. + */ +void bgp_reimport_evpn_routes_upon_macvrf_soo_change(struct bgp *bgp, + struct ecommunity *old_soo, + struct ecommunity *new_soo) { afi_t afi; safi_t safi; @@ -6068,12 +6308,9 @@ int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp *bgp) afi = AFI_L2VPN; safi = SAFI_EVPN; - /* Walk entire global routing table and evaluate routes which could be - * imported into this VPN. Note that we cannot just look at the routes - * for the VNI's RD - - * remote routes applicable for this VNI could have any RD. + /* EVPN routes are a 2-level table: outer=prefix_rd, inner=prefix_evpn. + * A remote route could have any RD, so we need to walk them all. */ - /* EVPN routes are a 2-level table. */ for (rd_dest = bgp_table_top(bgp->rib[afi][safi]); rd_dest; rd_dest = bgp_route_next(rd_dest)) { table = bgp_dest_get_bgp_table_info(rd_dest); @@ -6082,21 +6319,132 @@ int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp *bgp) for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) { + const struct prefix *p; + struct prefix_evpn *evp; + + p = bgp_dest_get_prefix(dest); + evp = (struct prefix_evpn *)p; + + /* On export we only add MAC-VRF SoO to RT-2/3, so we + * can skip evaluation of other RTs. + */ + if (evp->prefix.route_type != BGP_EVPN_MAC_IP_ROUTE && + evp->prefix.route_type != BGP_EVPN_IMET_ROUTE) + continue; for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) { + bool old_soo_fnd = false; + bool new_soo_fnd = false; - /* Consider "valid" remote routes applicable for - * this VNI. */ + /* Only consider routes learned from peers */ + if (!(pi->type == ZEBRA_ROUTE_BGP && + pi->sub_type == BGP_ROUTE_NORMAL)) + continue; + + if (!CHECK_FLAG(pi->flags, BGP_PATH_VALID)) + continue; + + old_soo_fnd = route_matches_soo(pi, old_soo); + new_soo_fnd = route_matches_soo(pi, new_soo); + + if (old_soo_fnd && !new_soo_fnd) { + if (bgp_debug_update(pi->peer, p, NULL, + 1)) { + char attr_str[BUFSIZ] = {0}; + + bgp_dump_attr(pi->attr, + attr_str, BUFSIZ); + + zlog_debug( + "mac-vrf soo changed: evaluating reimport of prefix %pBD with attr %s", + dest, attr_str); + } + + bgp_evpn_import_route(bgp, afi, safi, p, + pi); + } + } + } + } +} + +/* Filter learned (!local) EVPN routes carrying "self" attributes. + * Walk the Global EVPN loc-rib unimporting martian routes from the appropriate + * L2VNIs (MAC-VRFs) / L3VNIs (IP-VRFs), and deleting them from the Global + * loc-rib when applicable (based on martian_type). + * This function is the handler for new martian entries, which is triggered by + * events occurring on the local system, + * e.g. + * - New VTEP-IP + * + bgp_zebra_process_local_vni + * + bgp_zebra_process_local_l3vni + * - New MAC-VRF Site-of-Origin + * + bgp_evpn_handle_global_macvrf_soo_change + * This will likely be extended in the future to cover these events too: + * - New Interface IP + * + bgp_interface_address_add + * - New Interface MAC + * + bgp_ifp_up + * + bgp_ifp_create + * - New RMAC + * + bgp_zebra_process_local_l3vni + */ +void bgp_filter_evpn_routes_upon_martian_change( + struct bgp *bgp, enum bgp_martian_type martian_type) +{ + afi_t afi; + safi_t safi; + struct bgp_dest *rd_dest, *dest; + struct bgp_table *table; + struct bgp_path_info *pi; + struct ecommunity *macvrf_soo; + + afi = AFI_L2VPN; + safi = SAFI_EVPN; + macvrf_soo = bgp->evpn_info->soo; + + /* EVPN routes are a 2-level table: outer=prefix_rd, inner=prefix_evpn. + * A remote route could have any RD, so we need to walk them all. + */ + for (rd_dest = bgp_table_top(bgp->rib[afi][safi]); rd_dest; + rd_dest = bgp_route_next(rd_dest)) { + table = bgp_dest_get_bgp_table_info(rd_dest); + if (!table) + continue; + + for (dest = bgp_table_top(table); dest; + dest = bgp_route_next(dest)) { + + for (pi = bgp_dest_get_bgp_path_info(dest); pi; + pi = pi->next) { + bool affected = false; + const struct prefix *p; + + /* Only consider routes learned from peers */ if (!(pi->type == ZEBRA_ROUTE_BGP && pi->sub_type == BGP_ROUTE_NORMAL)) continue; - if (bgp_nexthop_self(bgp, afi, pi->type, - pi->sub_type, pi->attr, - dest)) { - const struct prefix *p = - bgp_dest_get_prefix(dest); + p = bgp_dest_get_prefix(dest); + + switch (martian_type) { + case BGP_MARTIAN_TUN_IP: + affected = bgp_nexthop_self( + bgp, afi, pi->type, + pi->sub_type, pi->attr, dest); + break; + case BGP_MARTIAN_SOO: + affected = route_matches_soo( + pi, macvrf_soo); + break; + case BGP_MARTIAN_IF_IP: + case BGP_MARTIAN_IF_MAC: + case BGP_MARTIAN_RMAC: + break; + } + + if (affected) { if (bgp_debug_update(pi->peer, p, NULL, 1)) { char attr_str[BUFSIZ] = {0}; @@ -6106,21 +6454,116 @@ int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp *bgp) sizeof(attr_str)); zlog_debug( - "%u: prefix %pBD with attr %s - DENIED due to martian or self nexthop", + "%u: prefix %pBD with attr %s - DISCARDED due to Martian/%s", bgp->vrf_id, dest, - attr_str); + attr_str, + bgp_martian_type2str( + martian_type)); } + + bgp_evpn_unimport_route(bgp, afi, safi, p, pi); - bgp_rib_remove(dest, pi, pi->peer, afi, - safi); + /* For now, retain existing handling of + * tip_hash updates: (Self SoO routes + * are unimported from L2VNI/VRF but + * retained in global loc-rib, but Self + * IP/MAC routes are also deleted from + * global loc-rib). + * TODO: use consistent handling for all + * martian types + */ + if (martian_type == BGP_MARTIAN_TUN_IP) + bgp_rib_remove(dest, pi, + pi->peer, afi, + safi); } } } } +} - return 0; +/* Refresh previously-discarded EVPN routes carrying "self" attributes. + * This function is the handler for deleted martian entries, which is triggered + * by events occurring on the local system, + * e.g. + * - Del MAC-VRF Site-of-Origin + * + bgp_evpn_handle_global_macvrf_soo_change + * This will likely be extended in the future to cover these events too: + * - Del VTEP-IP + * + bgp_zebra_process_local_vni + * + bgp_zebra_process_local_l3vni + * - Del Interface IP + * + bgp_interface_address_delete + * - Del Interface MAC + * + bgp_ifp_down + * + bgp_ifp_destroy + * - Del RMAC + * + bgp_zebra_process_local_l3vni + */ +void bgp_reimport_evpn_routes_upon_martian_change( + struct bgp *bgp, enum bgp_martian_type martian_type, void *old_martian, + void *new_martian) +{ + struct listnode *node; + struct peer *peer; + safi_t safi; + afi_t afi; + struct ecommunity *old_soo, *new_soo; + + afi = AFI_L2VPN; + safi = SAFI_EVPN; + + /* Self-SoO routes are held in the global EVPN loc-rib, so we can + * reimport routes w/o triggering soft-reconfig/route-refresh. + */ + if (martian_type == BGP_MARTIAN_SOO) { + old_soo = (struct ecommunity *)old_martian; + new_soo = (struct ecommunity *)new_martian; + + /* If !old_soo, then we can skip the reimport because we + * wouldn't have filtered anything via the self-SoO import check + */ + if (old_martian) + bgp_reimport_evpn_routes_upon_macvrf_soo_change( + bgp, old_soo, new_soo); + + return; + } + + /* Self-TIP/IP/MAC/RMAC routes are deleted from the global EVPN + * loc-rib, so we need to re-learn the routes via soft-reconfig/ + * route-refresh. + */ + for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) { + + if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) + continue; + + if (peer->connection->status != Established) + continue; + + if (CHECK_FLAG(peer->af_flags[afi][safi], + PEER_FLAG_SOFT_RECONFIG)) { + if (bgp_debug_update(peer, NULL, NULL, 1)) + zlog_debug( + "Processing EVPN Martian/%s change on peer %s (inbound, soft-reconfig)", + bgp_martian_type2str(martian_type), + peer->host); + + bgp_soft_reconfig_in(peer, afi, safi); + } else { + if (bgp_debug_update(peer, NULL, NULL, 1)) + zlog_debug( + "Processing EVPN Martian/%s change on peer %s", + bgp_martian_type2str(martian_type), + peer->host); + bgp_route_refresh_send(peer, afi, safi, 0, + REFRESH_IMMEDIATE, 0, + BGP_ROUTE_REFRESH_NORMAL); + } + } } /* @@ -6269,10 +6712,14 @@ int bgp_evpn_local_l3vni_add(vni_t l3vni, vrf_id_t vrf_id, /* associate the vrf with l3vni and related parameters */ bgp_vrf->l3vni = l3vni; - bgp_vrf->originator_ip = originator_ip; bgp_vrf->l3vni_svi_ifindex = svi_ifindex; bgp_vrf->evpn_info->is_anycast_mac = is_anycast_mac; + /* Update tip_hash of the EVPN underlay BGP instance (bgp_evpn) + * if the VTEP-IP (originator_ip) has changed + */ + handle_tunnel_ip_change(bgp_vrf, bgp_evpn, vpn, originator_ip); + /* copy anycast MAC from VRR MAC */ memcpy(&bgp_vrf->rmac, vrr_rmac, ETH_ALEN); /* copy sys RMAC from SVI MAC */ @@ -6397,6 +6844,11 @@ int bgp_evpn_local_l3vni_del(vni_t l3vni, vrf_id_t vrf_id) /* delete/withdraw all type-5 routes */ delete_withdraw_vrf_routes(bgp_vrf); + /* Tunnel is no longer active. + * Delete VTEP-IP from EVPN underlay's tip_hash. + */ + bgp_tip_del(bgp_evpn, &bgp_vrf->originator_ip); + /* remove the l3vni from vrf instance */ bgp_vrf->l3vni = 0; @@ -6461,8 +6913,8 @@ int bgp_evpn_local_vni_del(struct bgp *bgp, vni_t vni) bgp_evpn_unlink_from_vni_svi_hash(bgp, vpn); vpn->svi_ifindex = 0; - /* - * tunnel is no longer active, del tunnel ip address from tip_hash + /* Tunnel is no longer active. + * Delete VTEP-IP from EVPN underlay's tip_hash. */ bgp_tip_del(bgp, &vpn->originator_ip); @@ -6486,6 +6938,7 @@ int bgp_evpn_local_vni_add(struct bgp *bgp, vni_t vni, { struct bgpevpn *vpn; struct prefix_evpn p; + struct bgp *bgp_evpn = bgp_get_evpn(); /* Lookup VNI. If present and no change, exit. */ vpn = bgp_evpn_lookup_vni(bgp, vni); @@ -6558,7 +7011,7 @@ int bgp_evpn_local_vni_add(struct bgp *bgp, vni_t vni, /* If tunnel endpoint IP has changed, update (and delete prior * type-3 route, if needed.) */ - handle_tunnel_ip_change(bgp, vpn, originator_ip); + handle_tunnel_ip_change(NULL, bgp, vpn, originator_ip); /* Update all routes with new endpoint IP and/or export RT * for VRFs @@ -6578,14 +7031,17 @@ int bgp_evpn_local_vni_add(struct bgp *bgp, vni_t vni, /* Mark as "live" */ SET_FLAG(vpn->flags, VNI_FLAG_LIVE); - /* tunnel is now active, add tunnel-ip to db */ + /* Tunnel is newly active. + * Add TIP to tip_hash of the EVPN underlay instance (bgp_get_evpn()). + */ if (bgp_tip_add(bgp, &originator_ip)) /* The originator_ip was not already present in the * bgp martian next-hop table as a tunnel-ip, so we * need to go back and filter routes matching the new * martian next-hop. */ - bgp_filter_evpn_routes_upon_martian_nh_change(bgp); + bgp_filter_evpn_routes_upon_martian_change(bgp_evpn, + BGP_MARTIAN_TUN_IP); /* * Create EVPN type-3 route and schedule for processing. @@ -6679,8 +7135,13 @@ void bgp_evpn_cleanup(struct bgp *bgp) list_delete(&bgp->vrf_export_rtl); list_delete(&bgp->l2vnis); + if (bgp->evpn_info) { + ecommunity_free(&bgp->evpn_info->soo); + XFREE(MTYPE_BGP_EVPN_INFO, bgp->evpn_info); + } + if (bgp->vrf_prd_pretty) - XFREE(MTYPE_BGP, bgp->vrf_prd_pretty); + XFREE(MTYPE_BGP_NAME, bgp->vrf_prd_pretty); } /* @@ -6712,6 +7173,8 @@ void bgp_evpn_init(struct bgp *bgp) bgp->vrf_export_rtl->del = evpn_vrf_rt_del; bgp->l2vnis = list_new(); bgp->l2vnis->cmp = vni_list_cmp; + bgp->evpn_info = + XCALLOC(MTYPE_BGP_EVPN_INFO, sizeof(struct bgp_evpn_info)); /* By default Duplicate Address Dection is enabled. * Max-moves (N) 5, detection time (M) 180 * default action is warning-only @@ -6875,7 +7338,7 @@ static void bgp_evpn_remote_ip_hash_add(struct bgpevpn *vpn, || !CHECK_FLAG(pi->flags, BGP_PATH_VALID)) return; - evp = (struct prefix_evpn *)&pi->net->p; + evp = (struct prefix_evpn *)&pi->net->rn->p; if (evp->family != AF_EVPN || evp->prefix.route_type != BGP_EVPN_MAC_IP_ROUTE @@ -6908,7 +7371,7 @@ static void bgp_evpn_remote_ip_hash_del(struct bgpevpn *vpn, if (!evpn_resolve_overlay_index()) return; - evp = (struct prefix_evpn *)&pi->net->p; + evp = (struct prefix_evpn *)&pi->net->rn->p; if (evp->family != AF_EVPN || evp->prefix.route_type != BGP_EVPN_MAC_IP_ROUTE @@ -6953,7 +7416,7 @@ static void show_remote_ip_entry(struct hash_bucket *bucket, void *args) ipaddr2str(&ip->addr, buf, sizeof(buf))); vty_out(vty, " Linked MAC/IP routes:\n"); for (ALL_LIST_ELEMENTS_RO(ip->macip_path_list, node, pi)) - vty_out(vty, " %pFX\n", &pi->net->p); + vty_out(vty, " %pFX\n", &pi->net->rn->p); } void bgp_evpn_show_remote_ip_hash(struct hash_bucket *bucket, void *args) diff --git a/bgpd/bgp_evpn.h b/bgpd/bgp_evpn.h index a034bfbd7e..8403897587 100644 --- a/bgpd/bgp_evpn.h +++ b/bgpd/bgp_evpn.h @@ -51,15 +51,15 @@ get_route_parent_evpn(struct bgp_path_info *ri) struct bgp_path_info *parent_ri; /* If not imported (or doesn't have a parent), bail. */ - if (ri->sub_type != BGP_ROUTE_IMPORTED || - !ri->extra || - !ri->extra->parent) + if (ri->sub_type != BGP_ROUTE_IMPORTED || !ri->extra || + !ri->extra->vrfleak || !ri->extra->vrfleak->parent) return NULL; /* Determine parent recursively */ - for (parent_ri = ri->extra->parent; - parent_ri->extra && parent_ri->extra->parent; - parent_ri = parent_ri->extra->parent) + for (parent_ri = ri->extra->vrfleak->parent; + parent_ri->extra && parent_ri->extra->vrfleak && + parent_ri->extra->vrfleak->parent; + parent_ri = parent_ri->extra->vrfleak->parent) ; return parent_ri; @@ -94,32 +94,6 @@ static inline bool is_pi_family_evpn(struct bgp_path_info *pi) return is_pi_family_matching(pi, AFI_L2VPN, SAFI_EVPN); } -/* Flag if the route is injectable into EVPN. This would be either a - * non-imported route or a non-EVPN imported route. - */ -static inline bool is_route_injectable_into_evpn(struct bgp_path_info *pi) -{ - struct bgp_path_info *parent_pi; - struct bgp_table *table; - struct bgp_dest *dest; - - if (pi->sub_type != BGP_ROUTE_IMPORTED || - !pi->extra || - !pi->extra->parent) - return true; - - parent_pi = (struct bgp_path_info *)pi->extra->parent; - dest = parent_pi->net; - if (!dest) - return true; - table = bgp_dest_table(dest); - if (table && - table->afi == AFI_L2VPN && - table->safi == SAFI_EVPN) - return false; - return true; -} - static inline bool evpn_resolve_overlay_index(void) { struct bgp *bgp = NULL; @@ -157,7 +131,16 @@ extern int bgp_evpn_import_route(struct bgp *bgp, afi_t afi, safi_t safi, extern int bgp_evpn_unimport_route(struct bgp *bgp, afi_t afi, safi_t safi, const struct prefix *p, struct bgp_path_info *ri); -extern int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp *bgp); +extern void +bgp_reimport_evpn_routes_upon_macvrf_soo_change(struct bgp *bgp, + struct ecommunity *old_soo, + struct ecommunity *new_soo); +extern void bgp_reimport_evpn_routes_upon_martian_change( + struct bgp *bgp, enum bgp_martian_type martian_type, void *old_martian, + void *new_martian); +extern void +bgp_filter_evpn_routes_upon_martian_change(struct bgp *bgp, + enum bgp_martian_type martian_type); extern int bgp_evpn_local_macip_del(struct bgp *bgp, vni_t vni, struct ethaddr *mac, struct ipaddr *ip, int state); @@ -198,5 +181,6 @@ extern mpls_label_t *bgp_evpn_path_info_labels_get_l3vni(mpls_label_t *labels, extern vni_t bgp_evpn_path_info_get_l3vni(const struct bgp_path_info *pi); extern bool bgp_evpn_mpath_has_dvni(const struct bgp *bgp_vrf, struct bgp_path_info *mpinfo); +extern bool is_route_injectable_into_evpn(struct bgp_path_info *pi); #endif /* _QUAGGA_BGP_EVPN_H */ diff --git a/bgpd/bgp_evpn_mh.c b/bgpd/bgp_evpn_mh.c index efadda17b8..d88c52d1f6 100644 --- a/bgpd/bgp_evpn_mh.c +++ b/bgpd/bgp_evpn_mh.c @@ -37,7 +37,7 @@ #include "bgpd/bgp_zebra.h" #include "bgpd/bgp_addpath.h" #include "bgpd/bgp_label.h" -#include "bgpd/bgp_nht.h" +#include "bgpd/bgp_nhg.h" #include "bgpd/bgp_mpath.h" #include "bgpd/bgp_trace.h" @@ -185,8 +185,9 @@ static int bgp_evpn_es_route_install(struct bgp *bgp, /* Check if route entry is already present. */ for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) - if (pi->extra && - (struct bgp_path_info *)pi->extra->parent == parent_pi) + if (pi->extra && pi->extra->vrfleak && + (struct bgp_path_info *)pi->extra->vrfleak->parent == + parent_pi) break; if (!pi) { @@ -198,7 +199,11 @@ static int bgp_evpn_es_route_install(struct bgp *bgp, parent_pi->peer, attr_new, dest); SET_FLAG(pi->flags, BGP_PATH_VALID); bgp_path_info_extra_get(pi); - pi->extra->parent = bgp_path_info_lock(parent_pi); + if (!pi->extra->vrfleak) + pi->extra->vrfleak = + XCALLOC(MTYPE_BGP_ROUTE_EXTRA_VRFLEAK, + sizeof(struct bgp_path_info_extra_vrfleak)); + pi->extra->vrfleak->parent = bgp_path_info_lock(parent_pi); bgp_dest_lock_node((struct bgp_dest *)parent_pi->net); bgp_path_info_add(dest, pi); } else { @@ -253,9 +258,9 @@ static int bgp_evpn_es_route_uninstall(struct bgp *bgp, struct bgp_evpn_es *es, /* Find matching route entry. */ for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) - if (pi->extra - && (struct bgp_path_info *)pi->extra->parent == - parent_pi) + if (pi->extra && pi->extra->vrfleak && + (struct bgp_path_info *)pi->extra->vrfleak->parent == + parent_pi) break; if (!pi) { @@ -318,7 +323,9 @@ static void bgp_evpn_es_route_del_all(struct bgp *bgp, struct bgp_evpn_es *es) for (pi = bgp_dest_get_bgp_path_info(dest); (pi != NULL) && (nextpi = pi->next, 1); pi = nextpi) { bgp_path_info_delete(dest, pi); - bgp_path_info_reap(dest, pi); + dest = bgp_path_info_reap(dest, pi); + + assert(dest); } } } @@ -434,6 +441,10 @@ int bgp_evpn_mh_route_update(struct bgp *bgp, struct bgp_evpn_es *es, ? "esr" : (vpn ? "ead-evi" : "ead-es"), &attr->mp_nexthop_global_in); + + frrtrace(4, frr_bgp, evpn_mh_local_ead_es_evi_route_upd, + &es->esi, (vpn ? vpn->vni : 0), evp->prefix.route_type, + attr->mp_nexthop_global_in); } /* Return back the route entry. */ @@ -484,6 +495,8 @@ static int bgp_evpn_mh_route_delete(struct bgp *bgp, struct bgp_evpn_es *es, : (vpn ? "ead-evi" : "ead-es"), &es->originator_ip); + frrtrace(4, frr_bgp, evpn_mh_local_ead_es_evi_route_del, &es->esi, + (vpn ? vpn->vni : 0), p->prefix.route_type, es->originator_ip); /* Next, locate route node in the global EVPN routing table. * Note that this table is a 2-level tree (RD-level + Prefix-level) */ @@ -508,8 +521,11 @@ static int bgp_evpn_mh_route_delete(struct bgp *bgp, struct bgp_evpn_es *es, */ delete_evpn_route_entry(bgp, afi, safi, dest, &pi); if (pi) - bgp_path_info_reap(dest, pi); + dest = bgp_path_info_reap(dest, pi); + + assert(dest); bgp_dest_unlock_node(dest); + return 0; } @@ -522,7 +538,7 @@ int delete_global_ead_evi_routes(struct bgp *bgp, struct bgpevpn *vpn) { afi_t afi; safi_t safi; - struct bgp_dest *rdrn, *rn; + struct bgp_dest *rdrn, *bd; struct bgp_table *table; struct bgp_path_info *pi; @@ -538,15 +554,15 @@ int delete_global_ead_evi_routes(struct bgp *bgp, struct bgpevpn *vpn) * Iterate over all the routes in this table and delete EAD/EVI * routes */ - for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { - struct prefix_evpn *evp = (struct prefix_evpn *)&rn->p; + for (bd = bgp_table_top(table); bd; bd = bgp_route_next(bd)) { + struct prefix_evpn *evp = (struct prefix_evpn *)&bd->rn->p; if (evp->prefix.route_type != BGP_EVPN_AD_ROUTE) continue; - delete_evpn_route_entry(bgp, afi, safi, rn, &pi); + delete_evpn_route_entry(bgp, afi, safi, bd, &pi); if (pi) - bgp_process(bgp, rn, afi, safi); + bgp_process(bgp, bd, afi, safi); } } @@ -1548,10 +1564,11 @@ bgp_evpn_path_es_info_new(struct bgp_path_info *pi, vni_t vni) e = bgp_path_info_extra_get(pi); /* If mh_info doesn't exist allocate it */ - mh_info = e->mh_info; + mh_info = e->evpn->mh_info; if (!mh_info) - e->mh_info = mh_info = XCALLOC(MTYPE_BGP_EVPN_PATH_MH_INFO, - sizeof(struct bgp_path_mh_info)); + e->evpn->mh_info = mh_info = + XCALLOC(MTYPE_BGP_EVPN_PATH_MH_INFO, + sizeof(struct bgp_path_mh_info)); /* If es_info doesn't exist allocate it */ es_info = mh_info->es_info; @@ -1577,7 +1594,7 @@ static void bgp_evpn_path_es_unlink(struct bgp_path_es_info *es_info) pi = es_info->pi; if (BGP_DEBUG(evpn_mh, EVPN_MH_RT)) zlog_debug("vni %u path %pFX unlinked from es %s", es_info->vni, - &pi->net->p, es->esi_str); + &pi->net->rn->p, es->esi_str); if (es_info->vni) list_delete_node(es->macip_evi_path_list, @@ -1604,8 +1621,8 @@ void bgp_evpn_path_es_link(struct bgp_path_info *pi, vni_t vni, esi_t *esi) struct bgp_evpn_es *es; struct bgp *bgp_evpn; - es_info = (pi->extra && pi->extra->mh_info) - ? pi->extra->mh_info->es_info + es_info = (pi->extra && pi->extra->evpn && pi->extra->evpn->mh_info) + ? pi->extra->evpn->mh_info->es_info : NULL; /* if the esi is zero just unlink the path from the old es */ if (!esi || !memcmp(esi, zero_esi, sizeof(*esi))) { @@ -1635,7 +1652,7 @@ void bgp_evpn_path_es_link(struct bgp_path_info *pi, vni_t vni, esi_t *esi) bgp_evpn_path_es_unlink(es_info); if (BGP_DEBUG(evpn_mh, EVPN_MH_RT)) - zlog_debug("vni %u path %pFX linked to es %s", vni, &pi->net->p, + zlog_debug("vni %u path %pFX linked to es %s", vni, &pi->net->rn->p, es->esi_str); /* link mac-ip path to the new destination ES */ @@ -1655,7 +1672,7 @@ static bool bgp_evpn_is_macip_path(struct bgp_path_info *pi) * skipped) as these lists are maintained for managing * host routes in the tenant VRF */ - evp = (struct prefix_evpn *)&pi->net->p; + evp = (struct prefix_evpn *)&pi->net->rn->p; return is_evpn_prefix_ipaddr_v4(evp) || is_evpn_prefix_ipaddr_v6(evp); } @@ -1691,7 +1708,7 @@ bgp_evpn_es_path_update_on_es_vrf_chg(struct bgp_evpn_es_vrf *es_vrf, if (BGP_DEBUG(evpn_mh, EVPN_MH_RT)) zlog_debug( "update path %pFX linked to es %s on vrf chg", - &pi->net->p, es->esi_str); + &pi->net->rn->p, es->esi_str); bgp_evpn_route_entry_install_if_vrf_match(es_vrf->bgp_vrf, pi, 1); } @@ -2080,7 +2097,7 @@ static void bgp_evpn_mac_update_on_es_oper_chg(struct bgp_evpn_es *es) if (BGP_DEBUG(evpn_mh, EVPN_MH_RT)) zlog_debug( "update path %d %pFX linked to es %s on oper chg", - es_info->vni, &pi->net->p, es->esi_str); + es_info->vni, &pi->net->rn->p, es->esi_str); bgp_evpn_update_type2_route_entry(bgp, vpn, pi->net, pi, __func__); @@ -2129,7 +2146,7 @@ static void bgp_evpn_mac_update_on_es_local_chg(struct bgp_evpn_es *es, if (BGP_DEBUG(evpn_mh, EVPN_MH_RT)) zlog_debug( "update path %pFX linked to es %s on chg to %s", - &pi->net->p, es->esi_str, + &pi->net->rn->p, es->esi_str, is_local ? "local" : "non-local"); attr_tmp = *pi->attr; @@ -2988,8 +3005,8 @@ static struct bgp_evpn_es_vrf *bgp_evpn_es_vrf_create(struct bgp_evpn_es *es, listnode_add(es->es_vrf_list, &es_vrf->es_listnode); /* setup the L3 NHG id for the ES */ - es_vrf->nhg_id = bgp_l3nhg_id_alloc(); - es_vrf->v6_nhg_id = bgp_l3nhg_id_alloc(); + es_vrf->nhg_id = bgp_nhg_id_alloc(); + es_vrf->v6_nhg_id = bgp_nhg_id_alloc(); if (BGP_DEBUG(evpn_mh, EVPN_MH_ES)) zlog_debug("es %s vrf %u nhg %u v6_nhg %d create", es->esi_str, @@ -3017,10 +3034,10 @@ static void bgp_evpn_es_vrf_delete(struct bgp_evpn_es_vrf *es_vrf) /* Remove the NHG resources */ bgp_evpn_l3nhg_deactivate(es_vrf); if (es_vrf->nhg_id) - bgp_l3nhg_id_free(es_vrf->nhg_id); + bgp_nhg_id_free(es_vrf->nhg_id); es_vrf->nhg_id = 0; if (es_vrf->v6_nhg_id) - bgp_l3nhg_id_free(es_vrf->v6_nhg_id); + bgp_nhg_id_free(es_vrf->v6_nhg_id); es_vrf->v6_nhg_id = 0; /* remove from the ES's VRF list */ @@ -3154,7 +3171,7 @@ bool bgp_evpn_path_es_use_nhg(struct bgp *bgp_vrf, struct bgp_path_info *pi, esi_t *esi; struct bgp_evpn_es_vrf *es_vrf = NULL; struct bgp_path_info *parent_pi; - struct bgp_node *rn; + struct bgp_dest *bd; struct prefix_evpn *evp; struct bgp_path_info *mpinfo; bool use_l3nhg = false; @@ -3163,18 +3180,18 @@ bool bgp_evpn_path_es_use_nhg(struct bgp *bgp_vrf, struct bgp_path_info *pi, *nhg_p = 0; /* we don't support NHG for routes leaked from another VRF yet */ - if (pi->extra && pi->extra->bgp_orig) + if (pi->extra && pi->extra->vrfleak && pi->extra->vrfleak->bgp_orig) return false; parent_pi = get_route_parent_evpn(pi); if (!parent_pi) return false; - rn = parent_pi->net; - if (!rn) + bd = parent_pi->net; + if (!bd) return false; - evp = (struct prefix_evpn *)&rn->p; + evp = (struct prefix_evpn *)&bd->rn->p; if (evp->prefix.route_type != BGP_EVPN_MAC_IP_ROUTE) return false; @@ -3449,6 +3466,10 @@ static void bgp_evpn_es_evi_vtep_add(struct bgp *bgp, evi_vtep->es_evi->vpn->vni, &evi_vtep->vtep_ip, ead_es ? "ead_es" : "ead_evi"); + frrtrace(4, frr_bgp, evpn_mh_es_evi_vtep_add, + &evi_vtep->es_evi->es->esi, evi_vtep->es_evi->vpn->vni, + evi_vtep->vtep_ip, ead_es); + if (ead_es) SET_FLAG(evi_vtep->flags, BGP_EVPN_EVI_VTEP_EAD_PER_ES); else @@ -3473,6 +3494,10 @@ static void bgp_evpn_es_evi_vtep_del(struct bgp *bgp, evi_vtep->es_evi->vpn->vni, &evi_vtep->vtep_ip, ead_es ? "ead_es" : "ead_evi"); + frrtrace(4, frr_bgp, evpn_mh_es_evi_vtep_del, + &evi_vtep->es_evi->es->esi, evi_vtep->es_evi->vpn->vni, + evi_vtep->vtep_ip, ead_es); + if (ead_es) UNSET_FLAG(evi_vtep->flags, BGP_EVPN_EVI_VTEP_EAD_PER_ES); else @@ -4432,13 +4457,13 @@ static void bgp_evpn_nh_zebra_update_send(struct bgp_evpn_nh *nh, bool add) stream_putw_at(s, 0, stream_get_endp(s)); - if (BGP_DEBUG(evpn_mh, EVPN_MH_ES)) { + if (BGP_DEBUG(evpn_mh, EVPN_MH_ES) || bgp_debug_zebra(NULL)) { if (add) - zlog_debug("evpn vrf %s nh %s rmac %pEA add to zebra", + zlog_debug("evpn %s nh %s rmac %pEA add to zebra", nh->bgp_vrf->name_pretty, nh->nh_str, &nh->rmac); - else if (BGP_DEBUG(evpn_mh, EVPN_MH_ES)) - zlog_debug("evpn vrf %s nh %s del to zebra", + else + zlog_debug("evpn %s nh %s del to zebra", nh->bgp_vrf->name_pretty, nh->nh_str); } @@ -4621,7 +4646,7 @@ static void bgp_evpn_nh_update_ref_pi(struct bgp_evpn_nh *nh) continue; if (BGP_DEBUG(evpn_mh, EVPN_MH_ES)) - zlog_debug("evpn vrf %s nh %s ref_pi update", + zlog_debug("evpn %s nh %s ref_pi update", nh->bgp_vrf->name_pretty, nh->nh_str); nh->ref_pi = pi; /* If we have a new pi copy rmac from it and update @@ -4670,10 +4695,11 @@ bgp_evpn_path_nh_info_new(struct bgp_path_info *pi) e = bgp_path_info_extra_get(pi); /* If mh_info doesn't exist allocate it */ - mh_info = e->mh_info; + mh_info = e->evpn->mh_info; if (!mh_info) - e->mh_info = mh_info = XCALLOC(MTYPE_BGP_EVPN_PATH_MH_INFO, - sizeof(struct bgp_path_mh_info)); + e->evpn->mh_info = mh_info = + XCALLOC(MTYPE_BGP_EVPN_PATH_MH_INFO, + sizeof(struct bgp_path_mh_info)); /* If nh_info doesn't exist allocate it */ nh_info = mh_info->nh_info; @@ -4698,11 +4724,12 @@ static void bgp_evpn_path_nh_unlink(struct bgp_path_evpn_nh_info *nh_info) pi = nh_info->pi; if (BGP_DEBUG(evpn_mh, EVPN_MH_RT)) - zlog_debug("path %s unlinked from nh %s %s", - pi->net ? prefix2str(&pi->net->p, prefix_buf, + zlog_debug("path %s unlinked from %s nh %s pathcount %u", + pi->net ? prefix2str(&pi->net->rn->p, prefix_buf, sizeof(prefix_buf)) : "", - nh->bgp_vrf->name_pretty, nh->nh_str); + nh->bgp_vrf->name_pretty, nh->nh_str, + listcount(nh->pi_list)); list_delete_node(nh->pi_list, &nh_info->nh_listnode); @@ -4733,13 +4760,13 @@ static void bgp_evpn_path_nh_link(struct bgp *bgp_vrf, struct bgp_path_info *pi) if (!bgp_vrf->evpn_nh_table) { if (BGP_DEBUG(evpn_mh, EVPN_MH_RT)) - zlog_debug("path %pFX linked to vrf %s failed", - &pi->net->p, bgp_vrf->name_pretty); + zlog_debug("path %pFX linked to %s failed", + &pi->net->rn->p, bgp_vrf->name_pretty); return; } - nh_info = (pi->extra && pi->extra->mh_info) - ? pi->extra->mh_info->nh_info + nh_info = (pi->extra && pi->extra->evpn && pi->extra->evpn->mh_info) + ? pi->extra->evpn->mh_info->nh_info : NULL; /* if NHG is not being used for this path we don't need to manage the @@ -4757,7 +4784,7 @@ static void bgp_evpn_path_nh_link(struct bgp *bgp_vrf, struct bgp_path_info *pi) /* find-create nh */ memset(&ip, 0, sizeof(ip)); - if (pi->net->p.family == AF_INET6) { + if (pi->net->rn->p.family == AF_INET6) { SET_IPADDR_V6(&ip); memcpy(&ip.ipaddr_v6, &pi->attr->mp_nexthop_global, sizeof(ip.ipaddr_v6)); @@ -4781,8 +4808,9 @@ static void bgp_evpn_path_nh_link(struct bgp *bgp_vrf, struct bgp_path_info *pi) bgp_evpn_path_nh_unlink(nh_info); if (BGP_DEBUG(evpn_mh, EVPN_MH_RT)) - zlog_debug("path %pFX linked to nh %s %s", &pi->net->p, - nh->bgp_vrf->name_pretty, nh->nh_str); + zlog_debug("path %pFX linked to %s nh %s pathcount %u", + &pi->net->rn->p, nh->bgp_vrf->name_pretty, + nh->nh_str, listcount(nh->pi_list)); /* link mac-ip path to the new nh */ nh_info->nh = nh; @@ -4796,7 +4824,7 @@ static void bgp_evpn_path_nh_link(struct bgp *bgp_vrf, struct bgp_path_info *pi) if (!nh->ref_pi) zlog_debug( "path %pFX linked to nh %s %s with no valid pi", - &pi->net->p, nh->bgp_vrf->name_pretty, + &pi->net->rn->p, nh->bgp_vrf->name_pretty, nh->nh_str); } } @@ -4805,8 +4833,8 @@ void bgp_evpn_path_nh_del(struct bgp *bgp_vrf, struct bgp_path_info *pi) { struct bgp_path_evpn_nh_info *nh_info; - nh_info = (pi->extra && pi->extra->mh_info) - ? pi->extra->mh_info->nh_info + nh_info = (pi->extra && pi->extra->evpn && pi->extra->evpn->mh_info) + ? pi->extra->evpn->mh_info->nh_info : NULL; if (!nh_info) @@ -4833,7 +4861,7 @@ static void bgp_evpn_nh_show_entry(struct bgp_evpn_nh *nh, struct vty *vty, prefix_mac2str(&nh->rmac, mac_buf, sizeof(mac_buf)); if (nh->ref_pi && nh->ref_pi->net) - prefix2str(&nh->ref_pi->net->p, prefix_buf, sizeof(prefix_buf)); + prefix2str(&nh->ref_pi->net->rn->p, prefix_buf, sizeof(prefix_buf)); else prefix_buf[0] = '\0'; if (json) { diff --git a/bgpd/bgp_evpn_private.h b/bgpd/bgp_evpn_private.h index fd8d2c118f..5af99afa34 100644 --- a/bgpd/bgp_evpn_private.h +++ b/bgpd/bgp_evpn_private.h @@ -162,6 +162,13 @@ struct bgp_evpn_info { /* EVPN enable - advertise svi macip routes */ int advertise_svi_macip; + /* MAC-VRF Site-of-Origin + * - added to all routes exported from L2VNI + * - Type-2/3 routes with matching SoO not imported into L2VNI + * - Type-2/5 routes with matching SoO not imported into L3VNI + */ + struct ecommunity *soo; + /* PIP feature knob */ bool advertise_pip; /* PIP IP (sys ip) */ @@ -574,32 +581,32 @@ evpn_type2_prefix_vni_mac_copy(struct prefix_evpn *vni_p, static inline struct ethaddr * evpn_type2_path_info_get_mac(const struct bgp_path_info *local_pi) { - assert(local_pi->extra); - return &local_pi->extra->vni_info.mac; + assert(local_pi->extra && local_pi->extra->evpn); + return &local_pi->extra->evpn->vni_info.mac; } /* Get IP of path_info prefix */ static inline struct ipaddr * evpn_type2_path_info_get_ip(const struct bgp_path_info *local_pi) { - assert(local_pi->extra); - return &local_pi->extra->vni_info.ip; + assert(local_pi->extra && local_pi->extra->evpn); + return &local_pi->extra->evpn->vni_info.ip; } /* Set MAC of path_info prefix */ static inline void evpn_type2_path_info_set_mac(struct bgp_path_info *local_pi, const struct ethaddr mac) { - assert(local_pi->extra); - local_pi->extra->vni_info.mac = mac; + assert(local_pi->extra && local_pi->extra->evpn); + local_pi->extra->evpn->vni_info.mac = mac; } /* Set IP of path_info prefix */ static inline void evpn_type2_path_info_set_ip(struct bgp_path_info *local_pi, const struct ipaddr ip) { - assert(local_pi->extra); - local_pi->extra->vni_info.ip = ip; + assert(local_pi->extra && local_pi->extra->evpn); + local_pi->extra->evpn->vni_info.ip = ip; } /* Is the IP empty for the RT's dest? */ @@ -680,6 +687,8 @@ extern void bgp_evpn_handle_autort_change(struct bgp *bgp); extern void bgp_evpn_handle_vrf_rd_change(struct bgp *bgp_vrf, int withdraw); extern void bgp_evpn_handle_rd_change(struct bgp *bgp, struct bgpevpn *vpn, int withdraw); +void bgp_evpn_handle_global_macvrf_soo_change(struct bgp *bgp, + struct ecommunity *new_soo); extern int bgp_evpn_install_routes(struct bgp *bgp, struct bgpevpn *vpn); extern int bgp_evpn_uninstall_routes(struct bgp *bgp, struct bgpevpn *vpn); extern void bgp_evpn_map_vrf_to_its_rts(struct bgp *bgp_vrf); @@ -741,7 +750,7 @@ bgp_evpn_vni_node_lookup(const struct bgpevpn *vpn, const struct prefix_evpn *p, extern void bgp_evpn_import_route_in_vrfs(struct bgp_path_info *pi, int import); extern void bgp_evpn_update_type2_route_entry(struct bgp *bgp, struct bgpevpn *vpn, - struct bgp_node *rn, + struct bgp_dest *rn, struct bgp_path_info *local_pi, const char *caller); extern int bgp_evpn_route_entry_install_if_vrf_match(struct bgp *bgp_vrf, diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index 66079cad22..846a82ba90 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -362,10 +362,11 @@ static void display_l3vni(struct vty *vty, struct bgp *bgp_vrf, char *ecom_str; struct listnode *node, *nnode; struct vrf_route_target *l3rt; + struct bgp *bgp_evpn = NULL; json_object *json_import_rtl = NULL; json_object *json_export_rtl = NULL; - char buf2[ETHER_ADDR_STRLEN]; + bgp_evpn = bgp_get_evpn(); json_import_rtl = json_export_rtl = 0; if (json) { @@ -379,19 +380,26 @@ static void display_l3vni(struct vty *vty, struct bgp *bgp_vrf, &bgp_vrf->vrf_prd); json_object_string_addf(json, "originatorIp", "%pI4", &bgp_vrf->originator_ip); + if (bgp_evpn && bgp_evpn->evpn_info) { + ecom_str = ecommunity_ecom2str( + bgp_evpn->evpn_info->soo, + ECOMMUNITY_FORMAT_ROUTE_MAP, 0); + json_object_string_add(json, "siteOfOrigin", ecom_str); + ecommunity_strfree(&ecom_str); + } json_object_string_add(json, "advertiseGatewayMacip", "n/a"); json_object_string_add(json, "advertiseSviMacIp", "n/a"); - json_object_string_add(json, "advertisePip", - bgp_vrf->evpn_info->advertise_pip ? - "Enabled" : "Disabled"); - json_object_string_addf(json, "sysIP", "%pI4", - &bgp_vrf->evpn_info->pip_ip); - json_object_string_add(json, "sysMac", - prefix_mac2str(&bgp_vrf->evpn_info->pip_rmac, - buf2, sizeof(buf2))); - json_object_string_add(json, "rmac", - prefix_mac2str(&bgp_vrf->rmac, - buf2, sizeof(buf2))); + if (bgp_vrf->evpn_info) { + json_object_string_add(json, "advertisePip", + bgp_vrf->evpn_info->advertise_pip + ? "Enabled" + : "Disabled"); + json_object_string_addf(json, "sysIP", "%pI4", + &bgp_vrf->evpn_info->pip_ip); + json_object_string_addf(json, "sysMac", "%pEA", + &bgp_vrf->evpn_info->pip_rmac); + } + json_object_string_addf(json, "rmac", "%pEA", &bgp_vrf->rmac); } else { vty_out(vty, "VNI: %d", bgp_vrf->l3vni); vty_out(vty, " (known to the kernel)"); @@ -406,18 +414,26 @@ static void display_l3vni(struct vty *vty, struct bgp *bgp_vrf, vty_out(vty, "\n"); vty_out(vty, " Originator IP: %pI4\n", &bgp_vrf->originator_ip); + if (bgp_evpn && bgp_evpn->evpn_info) { + ecom_str = ecommunity_ecom2str( + bgp_evpn->evpn_info->soo, + ECOMMUNITY_FORMAT_ROUTE_MAP, 0); + vty_out(vty, " MAC-VRF Site-of-Origin: %s\n", + ecom_str); + ecommunity_strfree(&ecom_str); + } vty_out(vty, " Advertise-gw-macip : %s\n", "n/a"); vty_out(vty, " Advertise-svi-macip : %s\n", "n/a"); - vty_out(vty, " Advertise-pip: %s\n", - bgp_vrf->evpn_info->advertise_pip ? "Yes" : "No"); - vty_out(vty, " System-IP: %pI4\n", - &bgp_vrf->evpn_info->pip_ip); - vty_out(vty, " System-MAC: %s\n", - prefix_mac2str(&bgp_vrf->evpn_info->pip_rmac, - buf2, sizeof(buf2))); - vty_out(vty, " Router-MAC: %s\n", - prefix_mac2str(&bgp_vrf->rmac, - buf2, sizeof(buf2))); + if (bgp_vrf->evpn_info) { + vty_out(vty, " Advertise-pip: %s\n", + bgp_vrf->evpn_info->advertise_pip ? "Yes" + : "No"); + vty_out(vty, " System-IP: %pI4\n", + &bgp_vrf->evpn_info->pip_ip); + vty_out(vty, " System-MAC: %pEA\n", + &bgp_vrf->evpn_info->pip_rmac); + } + vty_out(vty, " Router-MAC: %pEA\n", &bgp_vrf->rmac); } if (!json) @@ -433,7 +449,7 @@ static void display_l3vni(struct vty *vty, struct bgp *bgp_vrf, else vty_out(vty, " %s\n", ecom_str); - XFREE(MTYPE_ECOMMUNITY_STR, ecom_str); + ecommunity_strfree(&ecom_str); } if (json) @@ -451,7 +467,7 @@ static void display_l3vni(struct vty *vty, struct bgp *bgp_vrf, else vty_out(vty, " %s\n", ecom_str); - XFREE(MTYPE_ECOMMUNITY_STR, ecom_str); + ecommunity_strfree(&ecom_str); } if (json) @@ -484,6 +500,13 @@ static void display_vni(struct vty *vty, struct bgpevpn *vpn, json_object *json) &vpn->originator_ip); json_object_string_addf(json, "mcastGroup", "%pI4", &vpn->mcast_grp); + if (bgp_evpn && bgp_evpn->evpn_info) { + ecom_str = ecommunity_ecom2str( + bgp_evpn->evpn_info->soo, + ECOMMUNITY_FORMAT_ROUTE_MAP, 0); + json_object_string_add(json, "siteOfOrigin", ecom_str); + ecommunity_strfree(&ecom_str); + } /* per vni knob is enabled -- Enabled * Global knob is enabled -- Active * default -- Disabled @@ -499,6 +522,7 @@ static void display_vni(struct vty *vty, struct bgpevpn *vpn, json_object *json) json_object_string_add(json, "advertiseGatewayMacip", "Disabled"); if (!vpn->advertise_svi_macip && bgp_evpn && + bgp_evpn->evpn_info && bgp_evpn->evpn_info->advertise_svi_macip) json_object_string_add(json, "advertiseSviMacIp", "Active"); @@ -525,6 +549,14 @@ static void display_vni(struct vty *vty, struct bgpevpn *vpn, json_object *json) vty_out(vty, "\n"); vty_out(vty, " Originator IP: %pI4\n", &vpn->originator_ip); vty_out(vty, " Mcast group: %pI4\n", &vpn->mcast_grp); + if (bgp_evpn && bgp_evpn->evpn_info) { + ecom_str = ecommunity_ecom2str( + bgp_evpn->evpn_info->soo, + ECOMMUNITY_FORMAT_ROUTE_MAP, 0); + vty_out(vty, " MAC-VRF Site-of-Origin: %s\n", + ecom_str); + ecommunity_strfree(&ecom_str); + } if (!vpn->advertise_gw_macip && bgp_evpn && bgp_evpn->advertise_gw_macip) vty_out(vty, " Advertise-gw-macip : %s\n", @@ -536,6 +568,7 @@ static void display_vni(struct vty *vty, struct bgpevpn *vpn, json_object *json) vty_out(vty, " Advertise-gw-macip : %s\n", "Disabled"); if (!vpn->advertise_svi_macip && bgp_evpn && + bgp_evpn->evpn_info && bgp_evpn->evpn_info->advertise_svi_macip) vty_out(vty, " Advertise-svi-macip : %s\n", "Active"); @@ -562,7 +595,7 @@ static void display_vni(struct vty *vty, struct bgpevpn *vpn, json_object *json) else vty_out(vty, " %s\n", ecom_str); - XFREE(MTYPE_ECOMMUNITY_STR, ecom_str); + ecommunity_strfree(&ecom_str); } if (json) @@ -580,7 +613,7 @@ static void display_vni(struct vty *vty, struct bgpevpn *vpn, json_object *json) else vty_out(vty, " %s\n", ecom_str); - XFREE(MTYPE_ECOMMUNITY_STR, ecom_str); + ecommunity_strfree(&ecom_str); } if (json) @@ -681,7 +714,7 @@ static void bgp_evpn_show_routes_mac_ip_es(struct vty *vty, esi_t *esi, json_object *json, int detail, bool global_table) { - struct bgp_node *rn; + struct bgp_dest *bd; struct bgp_path_info *pi; int header = detail ? 0 : 1; uint32_t path_cnt; @@ -714,7 +747,7 @@ static void bgp_evpn_show_routes_mac_ip_es(struct vty *vty, esi_t *esi, json_object *json_path = NULL; pi = es_info->pi; - rn = pi->net; + bd = pi->net; if (!CHECK_FLAG(pi->flags, BGP_PATH_VALID)) continue; @@ -732,11 +765,11 @@ static void bgp_evpn_show_routes_mac_ip_es(struct vty *vty, esi_t *esi, if (detail) route_vty_out_detail( - vty, bgp, rn, bgp_dest_get_prefix(rn), + vty, bgp, bd, bgp_dest_get_prefix(bd), pi, AFI_L2VPN, SAFI_EVPN, RPKI_NOT_BEING_USED, json_path); else - route_vty_out(vty, &rn->p, pi, 0, SAFI_EVPN, + route_vty_out(vty, &bd->rn->p, pi, 0, SAFI_EVPN, json_path, false); if (json) @@ -981,10 +1014,13 @@ static void show_l3vni_entry(struct vty *vty, struct bgp *bgp, char *ecom_str; struct listnode *node, *nnode; struct vrf_route_target *l3rt; + struct bgp *bgp_evpn; if (!bgp->l3vni) return; + bgp_evpn = bgp_get_evpn(); + if (json) { json_vni = json_object_new_object(); json_import_rtl = json_object_new_array(); @@ -1041,7 +1077,7 @@ static void show_l3vni_entry(struct vty *vty, struct bgp *bgp, vty_out(vty, " %-25s", rt_buf); } - XFREE(MTYPE_ECOMMUNITY_STR, ecom_str); + ecommunity_strfree(&ecom_str); /* If there are multiple import RTs we break here and show only * one */ @@ -1069,12 +1105,19 @@ static void show_l3vni_entry(struct vty *vty, struct bgp *bgp, vty_out(vty, " %-25s", rt_buf); } - XFREE(MTYPE_ECOMMUNITY_STR, ecom_str); + ecommunity_strfree(&ecom_str); /* If there are multiple export RTs we break here and show only * one */ if (!json) { - vty_out(vty, "%-37s", vrf_id_to_name(bgp->vrf_id)); + if (bgp_evpn && bgp_evpn->evpn_info) { + ecom_str = ecommunity_ecom2str( + bgp_evpn->evpn_info->soo, + ECOMMUNITY_FORMAT_ROUTE_MAP, 0); + vty_out(vty, " %-25s", ecom_str); + ecommunity_strfree(&ecom_str); + } + vty_out(vty, " %-37s", vrf_id_to_name(bgp->vrf_id)); break; } } @@ -1083,11 +1126,18 @@ static void show_l3vni_entry(struct vty *vty, struct bgp *bgp, char vni_str[VNI_STR_LEN]; json_object_object_add(json_vni, "exportRTs", json_export_rtl); + if (bgp_evpn && bgp_evpn->evpn_info) { + ecom_str = ecommunity_ecom2str( + bgp_evpn->evpn_info->soo, + ECOMMUNITY_FORMAT_ROUTE_MAP, 0); + json_object_string_add(json_vni, "siteOfOrigin", + ecom_str); + ecommunity_strfree(&ecom_str); + } snprintf(vni_str, sizeof(vni_str), "%u", bgp->l3vni); json_object_object_add(json, vni_str, json_vni); - } else { + } else vty_out(vty, "\n"); - } } static void show_vni_entry(struct hash_bucket *bucket, void *args[]) @@ -1213,7 +1263,14 @@ static void show_vni_entry(struct hash_bucket *bucket, void *args[]) /* If there are multiple export RTs we break here and show only * one */ if (!json) { - vty_out(vty, "%-37s", + if (bgp_evpn && bgp_evpn->evpn_info) { + ecom_str = ecommunity_ecom2str( + bgp_evpn->evpn_info->soo, + ECOMMUNITY_FORMAT_ROUTE_MAP, 0); + vty_out(vty, " %-25s", ecom_str); + ecommunity_strfree(&ecom_str); + } + vty_out(vty, " %-37s", vrf_id_to_name(vpn->tenant_vrf_id)); break; } @@ -1223,11 +1280,18 @@ static void show_vni_entry(struct hash_bucket *bucket, void *args[]) char vni_str[VNI_STR_LEN]; json_object_object_add(json_vni, "exportRTs", json_export_rtl); + if (bgp_evpn && bgp_evpn->evpn_info) { + ecom_str = ecommunity_ecom2str( + bgp_evpn->evpn_info->soo, + ECOMMUNITY_FORMAT_ROUTE_MAP, 0); + json_object_string_add(json_vni, "siteOfOrigin", + ecom_str); + ecommunity_strfree(&ecom_str); + } snprintf(vni_str, sizeof(vni_str), "%u", vpn->vni); json_object_object_add(json, vni_str, json_vni); - } else { + } else vty_out(vty, "\n"); - } } static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd, @@ -2017,12 +2081,12 @@ DEFUN(evpnrt5_network, int idx_ethtag = 5; int idx_routermac = 13; - return bgp_static_set_safi( - AFI_L2VPN, SAFI_EVPN, vty, argv[idx_ipv4_prefixlen]->arg, - argv[idx_route_distinguisher]->arg, argv[idx_label]->arg, NULL, - BGP_EVPN_IP_PREFIX_ROUTE, argv[idx_esi]->arg, - argv[idx_gwip]->arg, argv[idx_ethtag]->arg, - argv[idx_routermac]->arg); + return bgp_static_set(vty, false, argv[idx_ipv4_prefixlen]->arg, + argv[idx_route_distinguisher]->arg, + argv[idx_label]->arg, AFI_L2VPN, SAFI_EVPN, NULL, + 0, 0, BGP_EVPN_IP_PREFIX_ROUTE, + argv[idx_esi]->arg, argv[idx_gwip]->arg, + argv[idx_ethtag]->arg, argv[idx_routermac]->arg); } /* For testing purpose, static route of EVPN RT-5. */ @@ -2049,11 +2113,12 @@ DEFUN(no_evpnrt5_network, int idx_ethtag = 6; int idx_esi = 10; int idx_gwip = 12; - return bgp_static_unset_safi( - AFI_L2VPN, SAFI_EVPN, vty, argv[idx_ipv4_prefixlen]->arg, - argv[idx_ext_community]->arg, argv[idx_label]->arg, - BGP_EVPN_IP_PREFIX_ROUTE, argv[idx_esi]->arg, - argv[idx_gwip]->arg, argv[idx_ethtag]->arg); + + return bgp_static_set(vty, true, argv[idx_ipv4_prefixlen]->arg, + argv[idx_ext_community]->arg, + argv[idx_label]->arg, AFI_L2VPN, SAFI_EVPN, NULL, + 0, 0, BGP_EVPN_IP_PREFIX_ROUTE, argv[idx_esi]->arg, + argv[idx_gwip]->arg, argv[idx_ethtag]->arg, NULL); } static void evpn_import_rt_delete_auto(struct bgp *bgp, struct bgpevpn *vpn) @@ -2228,9 +2293,12 @@ static void evpn_configure_vrf_rd(struct bgp *bgp_vrf, struct prefix_rd *rd, */ bgp_evpn_handle_vrf_rd_change(bgp_vrf, 1); + if (bgp_vrf->vrf_prd_pretty) + XFREE(MTYPE_BGP_NAME, bgp_vrf->vrf_prd_pretty); + /* update RD */ memcpy(&bgp_vrf->vrf_prd, rd, sizeof(struct prefix_rd)); - bgp_vrf->vrf_prd_pretty = XSTRDUP(MTYPE_BGP, rd_pretty); + bgp_vrf->vrf_prd_pretty = XSTRDUP(MTYPE_BGP_NAME, rd_pretty); SET_FLAG(bgp_vrf->vrf_flags, BGP_VRF_RD_CFGD); /* We have a new RD for VRF. @@ -2253,7 +2321,7 @@ static void evpn_unconfigure_vrf_rd(struct bgp *bgp_vrf) bgp_evpn_derive_auto_rd_for_vrf(bgp_vrf); UNSET_FLAG(bgp_vrf->vrf_flags, BGP_VRF_RD_CFGD); if (bgp_vrf->vrf_prd_pretty) - XFREE(MTYPE_BGP, bgp_vrf->vrf_prd_pretty); + XFREE(MTYPE_BGP_NAME, bgp_vrf->vrf_prd_pretty); /* We have a new RD for VRF. * Advertise all type-5 routes again with the new RD */ @@ -2275,7 +2343,7 @@ static void evpn_configure_rd(struct bgp *bgp, struct bgpevpn *vpn, /* update RD */ memcpy(&vpn->prd, rd, sizeof(struct prefix_rd)); - vpn->prd_pretty = XSTRDUP(MTYPE_BGP, rd_pretty); + vpn->prd_pretty = XSTRDUP(MTYPE_BGP_NAME, rd_pretty); SET_FLAG(vpn->flags, VNI_FLAG_RD_CFGD); if (is_vni_live(vpn)) @@ -2619,16 +2687,16 @@ static void evpn_show_route_vni_macip(struct vty *vty, struct bgp *bgp, */ if (is_evpn_prefix_ipaddr_none(evp)) { /* VNI MAC -> Global */ - evpn_type2_prefix_global_copy( - (struct prefix_evpn *)&tmp_p, evp, - NULL /* mac */, - evpn_type2_path_info_get_ip(pi)); + evpn_type2_prefix_global_copy(&tmp_p, evp, + NULL /* mac */, + evpn_type2_path_info_get_ip( + pi)); } else { /* VNI IP -> Global */ - evpn_type2_prefix_global_copy( - (struct prefix_evpn *)&tmp_p, evp, - evpn_type2_path_info_get_mac(pi), - NULL /* ip */); + evpn_type2_prefix_global_copy(&tmp_p, evp, + evpn_type2_path_info_get_mac( + pi), + NULL /* ip */); } route_vty_out_detail(vty, bgp, dest, (struct prefix *)&tmp_p, @@ -3276,8 +3344,9 @@ static void evpn_show_all_vnis(struct vty *vty, struct bgp *bgp, if (!json) { vty_out(vty, "Flags: * - Kernel\n"); - vty_out(vty, " %-10s %-4s %-21s %-25s %-25s %-37s\n", "VNI", - "Type", "RD", "Import RT", "Export RT", "Tenant VRF"); + vty_out(vty, " %-10s %-4s %-21s %-25s %-25s %-25s %-37s\n", + "VNI", "Type", "RD", "Import RT", "Export RT", + "MAC-VRF Site-of-Origin", "Tenant VRF"); } /* print all L2 VNIS */ @@ -3923,6 +3992,58 @@ DEFPY(bgp_evpn_advertise_svi_ip_vni, return CMD_SUCCESS; } +DEFPY(macvrf_soo_global, macvrf_soo_global_cmd, + "mac-vrf soo ASN:NN_OR_IP-ADDRESS:NN$soo", + "EVPN MAC-VRF\n" + "Site-of-Origin extended community\n" + "VPN extended community\n") +{ + struct bgp *bgp = VTY_GET_CONTEXT(bgp); + struct bgp *bgp_evpn = bgp_get_evpn(); + struct ecommunity *ecomm_soo; + + if (!bgp || !bgp_evpn || !bgp_evpn->evpn_info) + return CMD_WARNING; + + if (bgp != bgp_evpn) { + vty_out(vty, + "%% Please configure MAC-VRF SoO in the EVPN underlay: %s\n", + bgp_evpn->name_pretty); + return CMD_WARNING_CONFIG_FAILED; + } + + ecomm_soo = ecommunity_str2com(soo, ECOMMUNITY_SITE_ORIGIN, 0); + if (!ecomm_soo) { + vty_out(vty, "%% Malformed SoO extended community\n"); + return CMD_WARNING_CONFIG_FAILED; + } + ecommunity_str(ecomm_soo); + + bgp_evpn_handle_global_macvrf_soo_change(bgp_evpn, ecomm_soo); + + return CMD_SUCCESS; +} + +DEFPY(no_macvrf_soo_global, no_macvrf_soo_global_cmd, + "no mac-vrf soo [ASN:NN_OR_IP-ADDRESS:NN$soo]", + NO_STR + "EVPN MAC-VRF\n" + "Site-of-Origin extended community\n" + "VPN extended community\n") +{ + struct bgp *bgp = VTY_GET_CONTEXT(bgp); + struct bgp *bgp_evpn = bgp_get_evpn(); + + if (!bgp || !bgp_evpn || !bgp_evpn->evpn_info) + return CMD_WARNING; + + if (bgp_evpn) + bgp_evpn_handle_global_macvrf_soo_change(bgp_evpn, + NULL /* new_soo */); + + return CMD_SUCCESS; +} + DEFUN_HIDDEN (bgp_evpn_advertise_vni_subnet, bgp_evpn_advertise_vni_subnet_cmd, "advertise-subnet", @@ -6853,6 +6974,8 @@ DEFUN(bgp_evpn_ead_es_rt, bgp_evpn_ead_es_rt_cmd, if (!bgp_evpn_rt_matches_existing(bgp_mh_info->ead_es_export_rtl, ecomadd)) bgp_evpn_mh_config_ead_export_rt(bgp, ecomadd, false); + else + ecommunity_free(&ecomadd); return CMD_SUCCESS; } @@ -6890,6 +7013,7 @@ DEFUN(no_bgp_evpn_ead_es_rt, no_bgp_evpn_ead_es_rt_cmd, } bgp_evpn_mh_config_ead_export_rt(bgp, ecomdel, true); + ecommunity_free(&ecomdel); return CMD_SUCCESS; } @@ -6941,6 +7065,8 @@ DEFUN (bgp_evpn_vni_rt, /* Do nothing if we already have this import route-target */ if (!bgp_evpn_rt_matches_existing(vpn->import_rtl, ecomadd)) evpn_configure_import_rt(bgp, vpn, ecomadd); + else + ecommunity_free(&ecomadd); } /* Add/update the export route-target */ @@ -6957,6 +7083,8 @@ DEFUN (bgp_evpn_vni_rt, /* Do nothing if we already have this export route-target */ if (!bgp_evpn_rt_matches_existing(vpn->export_rtl, ecomadd)) evpn_configure_export_rt(bgp, vpn, ecomadd); + else + ecommunity_free(&ecomadd); } return CMD_SUCCESS; @@ -7064,6 +7192,7 @@ DEFUN (no_bgp_evpn_vni_rt, } } + ecommunity_free(&ecomdel); return CMD_SUCCESS; } @@ -7158,6 +7287,15 @@ void bgp_config_write_evpn_info(struct vty *vty, struct bgp *bgp, afi_t afi, if (bgp->evpn_info->advertise_svi_macip) vty_out(vty, " advertise-svi-ip\n"); + if (bgp->evpn_info->soo) { + char *ecom_str; + + ecom_str = ecommunity_ecom2str(bgp->evpn_info->soo, + ECOMMUNITY_FORMAT_ROUTE_MAP, 0); + vty_out(vty, " mac-vrf soo %s\n", ecom_str); + ecommunity_strfree(&ecom_str); + } + if (bgp->resolve_overlay_index) vty_out(vty, " enable-resolve-overlay-index\n"); @@ -7390,6 +7528,8 @@ void bgp_ethernetvpn_init(void) install_element(BGP_EVPN_NODE, &bgp_evpn_advertise_default_gw_cmd); install_element(BGP_EVPN_NODE, &no_bgp_evpn_advertise_default_gw_cmd); install_element(BGP_EVPN_NODE, &bgp_evpn_advertise_svi_ip_cmd); + install_element(BGP_EVPN_NODE, &macvrf_soo_global_cmd); + install_element(BGP_EVPN_NODE, &no_macvrf_soo_global_cmd); install_element(BGP_EVPN_NODE, &bgp_evpn_advertise_type5_cmd); install_element(BGP_EVPN_NODE, &no_bgp_evpn_advertise_type5_cmd); install_element(BGP_EVPN_NODE, &bgp_evpn_default_originate_cmd); diff --git a/bgpd/bgp_filter.c b/bgpd/bgp_filter.c index fbea6862b8..ad541b67ad 100644 --- a/bgpd/bgp_filter.c +++ b/bgpd/bgp_filter.c @@ -15,7 +15,6 @@ #include "bgpd/bgpd.h" #include "bgpd/bgp_aspath.h" #include "bgpd/bgp_regex.h" -#include "bgpd/bgp_filter.h" /* List of AS filter list. */ struct as_list_list { @@ -35,30 +34,6 @@ struct as_list_master { void (*delete_hook)(const char *); }; -/* Element of AS path filter. */ -struct as_filter { - struct as_filter *next; - struct as_filter *prev; - - enum as_filter_type type; - - regex_t *reg; - char *reg_str; - - /* Sequence number. */ - int64_t seq; -}; - -/* AS path filter list. */ -struct as_list { - char *name; - - struct as_list *next; - struct as_list *prev; - - struct as_filter *head; - struct as_filter *tail; -}; /* Calculate new sequential number. */ @@ -220,7 +195,6 @@ struct as_list *as_list_lookup(const char *name) for (aslist = as_list_master.str.head; aslist; aslist = aslist->next) if (strcmp(aslist->name, name) == 0) return aslist; - return NULL; } diff --git a/bgpd/bgp_filter.h b/bgpd/bgp_filter.h index a294ebc69e..1890fd3d96 100644 --- a/bgpd/bgp_filter.h +++ b/bgpd/bgp_filter.h @@ -10,6 +10,33 @@ enum as_filter_type { AS_FILTER_DENY, AS_FILTER_PERMIT }; + +/* Element of AS path filter. */ +struct as_filter { + struct as_filter *next; + struct as_filter *prev; + + enum as_filter_type type; + + regex_t *reg; + char *reg_str; + + /* Sequence number. */ + int64_t seq; +}; + +/* AS path filter list. */ +struct as_list { + char *name; + + struct as_list *next; + struct as_list *prev; + + struct as_filter *head; + struct as_filter *tail; +}; + + extern void bgp_filter_init(void); extern void bgp_filter_reset(void); diff --git a/bgpd/bgp_flowspec.c b/bgpd/bgp_flowspec.c index 70bdbaf035..6165bf892e 100644 --- a/bgpd/bgp_flowspec.c +++ b/bgpd/bgp_flowspec.c @@ -189,13 +189,16 @@ int bgp_nlri_parse_flowspec(struct peer *peer, struct attr *attr, zlog_info("%s", local_string); } /* Process the route. */ - if (!withdraw) + if (!withdraw) { bgp_update(peer, &p, 0, attr, afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0, 0, NULL); - else + } else { bgp_withdraw(peer, &p, 0, afi, safi, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0, NULL); + } + + XFREE(MTYPE_TMP, temp); } return BGP_NLRI_PARSE_OK; } diff --git a/bgpd/bgp_flowspec_vty.c b/bgpd/bgp_flowspec_vty.c index 7df1423e59..d4ccca84bb 100644 --- a/bgpd/bgp_flowspec_vty.c +++ b/bgpd/bgp_flowspec_vty.c @@ -355,7 +355,8 @@ void route_vty_out_flowspec(struct vty *vty, const struct prefix *p, bgp_path_info_extra_get(path); bool list_began = false; - if (extra->bgp_fs_pbr && listcount(extra->bgp_fs_pbr)) { + if (extra->flowspec && extra->flowspec->bgp_fs_pbr && + listcount(extra->flowspec->bgp_fs_pbr)) { struct listnode *node; struct bgp_pbr_match_entry *bpme; struct bgp_pbr_match *bpm; @@ -363,8 +364,8 @@ void route_vty_out_flowspec(struct vty *vty, const struct prefix *p, list_bpm = list_new(); vty_out(vty, "\tinstalled in PBR"); - for (ALL_LIST_ELEMENTS_RO(extra->bgp_fs_pbr, - node, bpme)) { + for (ALL_LIST_ELEMENTS_RO(extra->flowspec->bgp_fs_pbr, node, + bpme)) { bpm = bpme->backpointer; if (listnode_lookup(list_bpm, bpm)) continue; @@ -378,13 +379,14 @@ void route_vty_out_flowspec(struct vty *vty, const struct prefix *p, } list_delete(&list_bpm); } - if (extra->bgp_fs_iprule && listcount(extra->bgp_fs_iprule)) { + if (extra->flowspec && extra->flowspec->bgp_fs_iprule && + listcount(extra->flowspec->bgp_fs_iprule)) { struct listnode *node; struct bgp_pbr_rule *bpr; if (!list_began) vty_out(vty, "\tinstalled in PBR"); - for (ALL_LIST_ELEMENTS_RO(extra->bgp_fs_iprule, + for (ALL_LIST_ELEMENTS_RO(extra->flowspec->bgp_fs_iprule, node, bpr)) { if (!bpr->action) continue; @@ -545,7 +547,7 @@ static int bgp_fs_local_install_interface(struct bgp *bgp, return CMD_SUCCESS; pbr_if = XCALLOC(MTYPE_TMP, sizeof(struct bgp_pbr_interface)); - strlcpy(pbr_if->name, ifname, INTERFACE_NAMSIZ); + strlcpy(pbr_if->name, ifname, IFNAMSIZ); RB_INSERT(bgp_pbr_interface_head, head, pbr_if); *bgp_pbr_interface_any = false; } else { diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c index a289d3d67a..ad872aeda3 100644 --- a/bgpd/bgp_fsm.c +++ b/bgpd/bgp_fsm.c @@ -46,13 +46,6 @@ DEFINE_HOOK(peer_backward_transition, (struct peer * peer), (peer)); DEFINE_HOOK(peer_status_changed, (struct peer * peer), (peer)); -enum bgp_fsm_state_progress { - BGP_FSM_FAILURE_AND_DELETE = -2, - BGP_FSM_FAILURE = -1, - BGP_FSM_SUCCESS = 0, - BGP_FSM_SUCCESS_STATE_TRANSFER = 1, -}; - /* Definition of display strings corresponding to FSM events. This should be * kept consistent with the events defined in bgpd.h */ @@ -90,9 +83,6 @@ static void bgp_connect_timer(struct event *event); static void bgp_holdtime_timer(struct event *event); static void bgp_delayopen_timer(struct event *event); -/* BGP FSM functions. */ -static enum bgp_fsm_state_progress bgp_start(struct peer *); - /* Register peer with NHT */ int bgp_peer_reg_with_nht(struct peer *peer) { @@ -103,9 +93,11 @@ int bgp_peer_reg_with_nht(struct peer *peer) && !CHECK_FLAG(peer->bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK)) connected = 1; - return bgp_find_or_add_nexthop( - peer->bgp, peer->bgp, family2afi(peer->su.sa.sa_family), - SAFI_UNICAST, NULL, peer, connected, NULL); + return bgp_find_or_add_nexthop(peer->bgp, peer->bgp, + family2afi( + peer->connection->su.sa.sa_family), + SAFI_UNICAST, NULL, peer, connected, + NULL); } static void peer_xfer_stats(struct peer *peer_dst, struct peer *peer_src) @@ -126,17 +118,29 @@ static struct peer *peer_xfer_conn(struct peer *from_peer) struct peer *peer; afi_t afi; safi_t safi; - int fd; - enum bgp_fsm_status status, pstatus; enum bgp_fsm_events last_evt, last_maj_evt; + struct peer_connection *keeper, *going_away; assert(from_peer != NULL); + /* + * Keeper is the connection that is staying around + */ + keeper = from_peer->connection; peer = from_peer->doppelganger; if (!peer || !CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE)) return from_peer; + /* + * from_peer is pointing at the non config node and + * at this point peer is pointing at the CONFIG node + * peer ( non incoming connection ). The going_away pointer + * is the connection that is being placed on to + * the non Config node for deletion. + */ + going_away = peer->connection; + /* * Let's check that we are not going to loose known configuration * state based upon doppelganger rules. @@ -153,13 +157,13 @@ static struct peer *peer_xfer_conn(struct peer *from_peer) if (bgp_debug_neighbor_events(peer)) zlog_debug("%s: peer transfer %p fd %d -> %p fd %d)", - from_peer->host, from_peer, from_peer->fd, peer, - peer->fd); + from_peer->host, from_peer, from_peer->connection->fd, + peer, peer->connection->fd); - bgp_writes_off(peer); - bgp_reads_off(peer); - bgp_writes_off(from_peer); - bgp_reads_off(from_peer); + bgp_writes_off(going_away); + bgp_reads_off(going_away); + bgp_writes_off(keeper); + bgp_reads_off(keeper); /* * Before exchanging FD remove doppelganger from @@ -167,66 +171,29 @@ static struct peer *peer_xfer_conn(struct peer *from_peer) * fd is set to -1. If blocked on lock then keepalive * thread can access peer pointer with fd -1. */ - bgp_keepalives_off(from_peer); - - EVENT_OFF(peer->t_routeadv); - EVENT_OFF(peer->t_connect); - EVENT_OFF(peer->t_delayopen); - EVENT_OFF(peer->t_connect_check_r); - EVENT_OFF(peer->t_connect_check_w); - EVENT_OFF(from_peer->t_routeadv); - EVENT_OFF(from_peer->t_connect); - EVENT_OFF(from_peer->t_delayopen); - EVENT_OFF(from_peer->t_connect_check_r); - EVENT_OFF(from_peer->t_connect_check_w); - EVENT_OFF(from_peer->t_process_packet); + bgp_keepalives_off(keeper); + + EVENT_OFF(going_away->t_routeadv); + EVENT_OFF(going_away->t_connect); + EVENT_OFF(going_away->t_delayopen); + EVENT_OFF(going_away->t_connect_check_r); + EVENT_OFF(going_away->t_connect_check_w); + EVENT_OFF(keeper->t_routeadv); + EVENT_OFF(keeper->t_connect); + EVENT_OFF(keeper->t_delayopen); + EVENT_OFF(keeper->t_connect_check_r); + EVENT_OFF(keeper->t_connect_check_w); + EVENT_OFF(keeper->t_process_packet); /* * At this point in time, it is possible that there are packets pending * on various buffers. Those need to be transferred or dropped, * otherwise we'll get spurious failures during session establishment. */ - frr_with_mutex (&peer->io_mtx, &from_peer->io_mtx) { - fd = peer->fd; - peer->fd = from_peer->fd; - from_peer->fd = fd; - - stream_fifo_clean(peer->ibuf); - stream_fifo_clean(peer->obuf); - - /* - * this should never happen, since bgp_process_packet() is the - * only task that sets and unsets the current packet and it - * runs in our pthread. - */ - if (peer->curr) { - flog_err( - EC_BGP_PKT_PROCESS, - "[%s] Dropping pending packet on connection transfer:", - peer->host); - /* there used to be a bgp_packet_dump call here, but - * that's extremely confusing since there's no way to - * identify the packet in MRT dumps or BMP as dropped - * due to connection transfer. - */ - stream_free(peer->curr); - peer->curr = NULL; - } - - // copy each packet from old peer's output queue to new peer - while (from_peer->obuf->head) - stream_fifo_push(peer->obuf, - stream_fifo_pop(from_peer->obuf)); - - // copy each packet from old peer's input queue to new peer - while (from_peer->ibuf->head) - stream_fifo_push(peer->ibuf, - stream_fifo_pop(from_peer->ibuf)); - - ringbuf_wipe(peer->ibuf_work); - ringbuf_copy(peer->ibuf_work, from_peer->ibuf_work, - ringbuf_remain(from_peer->ibuf_work)); - } + peer->connection = keeper; + keeper->peer = peer; + from_peer->connection = going_away; + going_away->peer = from_peer; peer->as = from_peer->as; peer->v_holdtime = from_peer->v_holdtime; @@ -236,16 +203,10 @@ static struct peer *peer_xfer_conn(struct peer *from_peer) peer->v_gr_restart = from_peer->v_gr_restart; peer->cap = from_peer->cap; peer->remote_role = from_peer->remote_role; - status = peer->status; - pstatus = peer->ostatus; last_evt = peer->last_event; last_maj_evt = peer->last_major_event; - peer->status = from_peer->status; - peer->ostatus = from_peer->ostatus; peer->last_event = from_peer->last_event; peer->last_major_event = from_peer->last_major_event; - from_peer->status = status; - from_peer->ostatus = pstatus; from_peer->last_event = last_evt; from_peer->last_major_event = last_maj_evt; peer->remote_id = from_peer->remote_id; @@ -302,29 +263,27 @@ static struct peer *peer_xfer_conn(struct peer *from_peer) } if (bgp_getsockname(peer) < 0) { - flog_err( - EC_LIB_SOCKET, - "%%bgp_getsockname() failed for %s peer %s fd %d (from_peer fd %d)", - (CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER) - ? "accept" - : ""), - peer->host, peer->fd, from_peer->fd); - BGP_EVENT_ADD(peer, BGP_Stop); - BGP_EVENT_ADD(from_peer, BGP_Stop); + flog_err(EC_LIB_SOCKET, + "%%bgp_getsockname() failed for %s peer %s fd %d (from_peer fd %d)", + (CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER) + ? "accept" + : ""), + peer->host, going_away->fd, keeper->fd); + BGP_EVENT_ADD(going_away, BGP_Stop); + BGP_EVENT_ADD(keeper, BGP_Stop); return NULL; } - if (from_peer->status > Active) { + if (going_away->status > Active) { if (bgp_getsockname(from_peer) < 0) { - flog_err( - EC_LIB_SOCKET, - "%%bgp_getsockname() failed for %s from_peer %s fd %d (peer fd %d)", - - (CHECK_FLAG(from_peer->sflags, - PEER_STATUS_ACCEPT_PEER) - ? "accept" - : ""), - from_peer->host, from_peer->fd, peer->fd); - bgp_stop(from_peer); + flog_err(EC_LIB_SOCKET, + "%%bgp_getsockname() failed for %s from_peer %s fd %d (peer fd %d)", + + (CHECK_FLAG(from_peer->sflags, + PEER_STATUS_ACCEPT_PEER) + ? "accept" + : ""), + from_peer->host, going_away->fd, keeper->fd); + bgp_stop(going_away); from_peer = NULL; } } @@ -341,10 +300,10 @@ static struct peer *peer_xfer_conn(struct peer *from_peer) if (from_peer) bgp_replace_nexthop_by_peer(from_peer, peer); - bgp_reads_on(peer); - bgp_writes_on(peer); - event_add_event(bm->master, bgp_process_packet, peer, 0, - &peer->t_process_packet); + bgp_reads_on(keeper); + bgp_writes_on(keeper); + event_add_event(bm->master, bgp_process_packet, keeper, 0, + &keeper->t_process_packet); return (peer); } @@ -352,88 +311,90 @@ static struct peer *peer_xfer_conn(struct peer *from_peer) /* Hook function called after bgp event is occered. And vty's neighbor command invoke this function after making neighbor structure. */ -void bgp_timer_set(struct peer *peer) +void bgp_timer_set(struct peer_connection *connection) { afi_t afi; safi_t safi; + struct peer *peer = connection->peer; - switch (peer->status) { + switch (connection->status) { case Idle: /* First entry point of peer's finite state machine. In Idle status start timer is on unless peer is shutdown or peer is inactive. All other timer must be turned off */ if (BGP_PEER_START_SUPPRESSED(peer) || !peer_active(peer) || peer->bgp->vrf_id == VRF_UNKNOWN) { - EVENT_OFF(peer->t_start); + EVENT_OFF(connection->t_start); } else { - BGP_TIMER_ON(peer->t_start, bgp_start_timer, + BGP_TIMER_ON(connection->t_start, bgp_start_timer, peer->v_start); } - EVENT_OFF(peer->t_connect); - EVENT_OFF(peer->t_holdtime); - bgp_keepalives_off(peer); - EVENT_OFF(peer->t_routeadv); - EVENT_OFF(peer->t_delayopen); + EVENT_OFF(connection->t_connect); + EVENT_OFF(connection->t_holdtime); + bgp_keepalives_off(connection); + EVENT_OFF(connection->t_routeadv); + EVENT_OFF(connection->t_delayopen); break; case Connect: /* After start timer is expired, the peer moves to Connect status. Make sure start timer is off and connect timer is on. */ - EVENT_OFF(peer->t_start); + EVENT_OFF(connection->t_start); if (CHECK_FLAG(peer->flags, PEER_FLAG_TIMER_DELAYOPEN)) - BGP_TIMER_ON(peer->t_connect, bgp_connect_timer, + BGP_TIMER_ON(connection->t_connect, bgp_connect_timer, (peer->v_delayopen + peer->v_connect)); else - BGP_TIMER_ON(peer->t_connect, bgp_connect_timer, + BGP_TIMER_ON(connection->t_connect, bgp_connect_timer, peer->v_connect); - EVENT_OFF(peer->t_holdtime); - bgp_keepalives_off(peer); - EVENT_OFF(peer->t_routeadv); + EVENT_OFF(connection->t_holdtime); + bgp_keepalives_off(connection); + EVENT_OFF(connection->t_routeadv); break; case Active: /* Active is waiting connection from remote peer. And if connect timer is expired, change status to Connect. */ - EVENT_OFF(peer->t_start); + EVENT_OFF(connection->t_start); /* If peer is passive mode, do not set connect timer. */ if (CHECK_FLAG(peer->flags, PEER_FLAG_PASSIVE) || CHECK_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT)) { - EVENT_OFF(peer->t_connect); + EVENT_OFF(connection->t_connect); } else { if (CHECK_FLAG(peer->flags, PEER_FLAG_TIMER_DELAYOPEN)) - BGP_TIMER_ON( - peer->t_connect, bgp_connect_timer, - (peer->v_delayopen + peer->v_connect)); + BGP_TIMER_ON(connection->t_connect, + bgp_connect_timer, + (peer->v_delayopen + + peer->v_connect)); else - BGP_TIMER_ON(peer->t_connect, bgp_connect_timer, - peer->v_connect); + BGP_TIMER_ON(connection->t_connect, + bgp_connect_timer, peer->v_connect); } - EVENT_OFF(peer->t_holdtime); - bgp_keepalives_off(peer); - EVENT_OFF(peer->t_routeadv); + EVENT_OFF(connection->t_holdtime); + bgp_keepalives_off(connection); + EVENT_OFF(connection->t_routeadv); break; case OpenSent: /* OpenSent status. */ - EVENT_OFF(peer->t_start); - EVENT_OFF(peer->t_connect); + EVENT_OFF(connection->t_start); + EVENT_OFF(connection->t_connect); if (peer->v_holdtime != 0) { - BGP_TIMER_ON(peer->t_holdtime, bgp_holdtime_timer, + BGP_TIMER_ON(connection->t_holdtime, bgp_holdtime_timer, peer->v_holdtime); } else { - EVENT_OFF(peer->t_holdtime); + EVENT_OFF(connection->t_holdtime); } - bgp_keepalives_off(peer); - EVENT_OFF(peer->t_routeadv); - EVENT_OFF(peer->t_delayopen); + bgp_keepalives_off(connection); + EVENT_OFF(connection->t_routeadv); + EVENT_OFF(connection->t_delayopen); break; case OpenConfirm: /* OpenConfirm status. */ - EVENT_OFF(peer->t_start); - EVENT_OFF(peer->t_connect); + EVENT_OFF(connection->t_start); + EVENT_OFF(connection->t_connect); /* * If the negotiated Hold Time value is zero, then the Hold Time @@ -441,24 +402,24 @@ void bgp_timer_set(struct peer *peer) * Additionally if a different hold timer has been negotiated * than we must stop then start the timer again */ - EVENT_OFF(peer->t_holdtime); + EVENT_OFF(connection->t_holdtime); if (peer->v_holdtime == 0) - bgp_keepalives_off(peer); + bgp_keepalives_off(connection); else { - BGP_TIMER_ON(peer->t_holdtime, bgp_holdtime_timer, + BGP_TIMER_ON(connection->t_holdtime, bgp_holdtime_timer, peer->v_holdtime); - bgp_keepalives_on(peer); + bgp_keepalives_on(connection); } - EVENT_OFF(peer->t_routeadv); - EVENT_OFF(peer->t_delayopen); + EVENT_OFF(connection->t_routeadv); + EVENT_OFF(connection->t_delayopen); break; case Established: /* In Established status start and connect timer is turned off. */ - EVENT_OFF(peer->t_start); - EVENT_OFF(peer->t_connect); - EVENT_OFF(peer->t_delayopen); + EVENT_OFF(connection->t_start); + EVENT_OFF(connection->t_connect); + EVENT_OFF(connection->t_delayopen); /* * Same as OpenConfirm, if holdtime is zero then both holdtime @@ -466,32 +427,32 @@ void bgp_timer_set(struct peer *peer) * Additionally if a different hold timer has been negotiated * then we must stop then start the timer again */ - EVENT_OFF(peer->t_holdtime); + EVENT_OFF(connection->t_holdtime); if (peer->v_holdtime == 0) - bgp_keepalives_off(peer); + bgp_keepalives_off(connection); else { - BGP_TIMER_ON(peer->t_holdtime, bgp_holdtime_timer, + BGP_TIMER_ON(connection->t_holdtime, bgp_holdtime_timer, peer->v_holdtime); - bgp_keepalives_on(peer); + bgp_keepalives_on(connection); } break; case Deleted: - EVENT_OFF(peer->t_gr_restart); - EVENT_OFF(peer->t_gr_stale); + EVENT_OFF(peer->connection->t_gr_restart); + EVENT_OFF(peer->connection->t_gr_stale); FOREACH_AFI_SAFI (afi, safi) EVENT_OFF(peer->t_llgr_stale[afi][safi]); - EVENT_OFF(peer->t_pmax_restart); + EVENT_OFF(peer->connection->t_pmax_restart); EVENT_OFF(peer->t_refresh_stalepath); - /* fallthru */ + fallthrough; case Clearing: - EVENT_OFF(peer->t_start); - EVENT_OFF(peer->t_connect); - EVENT_OFF(peer->t_holdtime); - bgp_keepalives_off(peer); - EVENT_OFF(peer->t_routeadv); - EVENT_OFF(peer->t_delayopen); + EVENT_OFF(connection->t_start); + EVENT_OFF(connection->t_connect); + EVENT_OFF(connection->t_holdtime); + bgp_keepalives_off(connection); + EVENT_OFF(connection->t_routeadv); + EVENT_OFF(connection->t_delayopen); break; case BGP_STATUS_MAX: flog_err(EC_LIB_DEVELOPMENT, @@ -504,9 +465,8 @@ void bgp_timer_set(struct peer *peer) and process event. */ static void bgp_start_timer(struct event *thread) { - struct peer *peer; - - peer = EVENT_ARG(thread); + struct peer_connection *connection = EVENT_ARG(thread); + struct peer *peer = connection->peer; if (bgp_debug_neighbor_events(peer)) zlog_debug("%s [FSM] Timer (start timer expire).", peer->host); @@ -518,21 +478,20 @@ static void bgp_start_timer(struct event *thread) /* BGP connect retry timer. */ static void bgp_connect_timer(struct event *thread) { - struct peer *peer; - - peer = EVENT_ARG(thread); + struct peer_connection *connection = EVENT_ARG(thread); + struct peer *peer = connection->peer; /* stop the DelayOpenTimer if it is running */ - EVENT_OFF(peer->t_delayopen); + EVENT_OFF(connection->t_delayopen); - assert(!peer->t_write); - assert(!peer->t_read); + assert(!connection->t_write); + assert(!connection->t_read); if (bgp_debug_neighbor_events(peer)) zlog_debug("%s [FSM] Timer (connect timer expire)", peer->host); if (CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER)) - bgp_stop(peer); + bgp_stop(connection); else { EVENT_VAL(thread) = ConnectRetry_timer_expired; bgp_event(thread); /* bgp_event unlocks peer */ @@ -543,9 +502,8 @@ static void bgp_connect_timer(struct event *thread) static void bgp_holdtime_timer(struct event *thread) { atomic_size_t inq_count; - struct peer *peer; - - peer = EVENT_ARG(thread); + struct peer_connection *connection = EVENT_ARG(thread); + struct peer *peer = connection->peer; if (bgp_debug_neighbor_events(peer)) zlog_debug("%s [FSM] Timer (holdtime timer expire)", @@ -561,10 +519,10 @@ static void bgp_holdtime_timer(struct event *thread) * for systems where we are heavily loaded for one * reason or another. */ - inq_count = atomic_load_explicit(&peer->ibuf->count, + inq_count = atomic_load_explicit(&connection->ibuf->count, memory_order_relaxed); if (inq_count) - BGP_TIMER_ON(peer->t_holdtime, bgp_holdtime_timer, + BGP_TIMER_ON(connection->t_holdtime, bgp_holdtime_timer, peer->v_holdtime); EVENT_VAL(thread) = Hold_Timer_expired; @@ -573,18 +531,16 @@ static void bgp_holdtime_timer(struct event *thread) void bgp_routeadv_timer(struct event *thread) { - struct peer *peer; - - peer = EVENT_ARG(thread); + struct peer_connection *connection = EVENT_ARG(thread); + struct peer *peer = connection->peer; if (bgp_debug_neighbor_events(peer)) - zlog_debug("%s [FSM] Timer (routeadv timer expire)", - peer->host); + zlog_debug("%s [FSM] Timer (routeadv timer expire)", peer->host); peer->synctime = monotime(NULL); - event_add_timer_msec(bm->master, bgp_generate_updgrp_packets, peer, 0, - &peer->t_generate_updgrp_packets); + event_add_timer_msec(bm->master, bgp_generate_updgrp_packets, connection, + 0, &connection->t_generate_updgrp_packets); /* MRAI timer will be started again when FIFO is built, no need to * do it here. @@ -594,9 +550,8 @@ void bgp_routeadv_timer(struct event *thread) /* RFC 4271 DelayOpenTimer */ void bgp_delayopen_timer(struct event *thread) { - struct peer *peer; - - peer = EVENT_ARG(thread); + struct peer_connection *connection = EVENT_ARG(thread); + struct peer *peer = connection->peer; if (bgp_debug_neighbor_events(peer)) zlog_debug("%s [FSM] Timer (DelayOpentimer expire)", @@ -607,44 +562,48 @@ void bgp_delayopen_timer(struct event *thread) } /* BGP Peer Down Cause */ -const char *const peer_down_str[] = {"", - "Router ID changed", - "Remote AS changed", - "Local AS change", - "Cluster ID changed", - "Confederation identifier changed", - "Confederation peer changed", - "RR client config change", - "RS client config change", - "Update source change", - "Address family activated", - "Admin. shutdown", - "User reset", - "BGP Notification received", - "BGP Notification send", - "Peer closed the session", - "Neighbor deleted", - "Peer-group add member", - "Peer-group delete member", - "Capability changed", - "Passive config change", - "Multihop config change", - "NSF peer closed the session", - "Intf peering v6only config change", - "BFD down received", - "Interface down", - "Neighbor address lost", - "No path to specified Neighbor", - "Waiting for Peer IPv6 LLA", - "Waiting for VRF to be initialized", - "No AFI/SAFI activated for peer", - "AS Set config change", - "Waiting for peer OPEN", - "Reached received prefix count", - "Socket Error", - "Admin. shutdown (RTT)"}; - -static void bgp_graceful_restart_timer_off(struct peer *peer) +const char *const peer_down_str[] = { + "", + "Router ID changed", + "Remote AS changed", + "Local AS change", + "Cluster ID changed", + "Confederation identifier changed", + "Confederation peer changed", + "RR client config change", + "RS client config change", + "Update source change", + "Address family activated", + "Admin. shutdown", + "User reset", + "BGP Notification received", + "BGP Notification send", + "Peer closed the session", + "Neighbor deleted", + "Peer-group add member", + "Peer-group delete member", + "Capability changed", + "Passive config change", + "Multihop config change", + "NSF peer closed the session", + "Intf peering v6only config change", + "BFD down received", + "Interface down", + "Neighbor address lost", + "No path to specified Neighbor", + "Waiting for Peer IPv6 LLA", + "Waiting for VRF to be initialized", + "No AFI/SAFI activated for peer", + "AS Set config change", + "Waiting for peer OPEN", + "Reached received prefix count", + "Socket Error", + "Admin. shutdown (RTT)", + "Suppress Fib Turned On or Off", +}; + +static void bgp_graceful_restart_timer_off(struct peer_connection *connection, + struct peer *peer) { afi_t afi; safi_t safi; @@ -655,7 +614,7 @@ static void bgp_graceful_restart_timer_off(struct peer *peer) return; UNSET_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT); - EVENT_OFF(peer->t_gr_stale); + EVENT_OFF(connection->t_gr_stale); if (peer_dynamic_neighbor(peer) && !(CHECK_FLAG(peer->flags, PEER_FLAG_DELETE))) { @@ -665,7 +624,7 @@ static void bgp_graceful_restart_timer_off(struct peer *peer) peer_delete(peer); } - bgp_timer_set(peer); + bgp_timer_set(connection); } static void bgp_llgr_stale_timer_expire(struct event *thread) @@ -693,7 +652,7 @@ static void bgp_llgr_stale_timer_expire(struct event *thread) bgp_clear_stale_route(peer, afi, safi); - bgp_graceful_restart_timer_off(peer); + bgp_graceful_restart_timer_off(peer->connection, peer); } static void bgp_set_llgr_stale(struct peer *peer, afi_t afi, safi_t safi) @@ -729,7 +688,7 @@ static void bgp_set_llgr_stale(struct peer *peer, afi_t afi, safi_t safi) if (bgp_debug_neighbor_events(peer)) zlog_debug( "%pBP Long-lived set stale community (LLGR_STALE) for: %pFX", - peer, &dest->p); + peer, &dest->rn->p); attr = *pi->attr; bgp_attr_add_llgr_community(&attr); @@ -757,7 +716,7 @@ static void bgp_set_llgr_stale(struct peer *peer, afi_t afi, safi_t safi) if (bgp_debug_neighbor_events(peer)) zlog_debug( "%pBP Long-lived set stale community (LLGR_STALE) for: %pFX", - peer, &dest->p); + peer, &dest->rn->p); attr = *pi->attr; bgp_attr_add_llgr_community(&attr); @@ -772,14 +731,14 @@ static void bgp_set_llgr_stale(struct peer *peer, afi_t afi, safi_t safi) static void bgp_graceful_restart_timer_expire(struct event *thread) { - struct peer *peer, *tmp_peer; + struct peer_connection *connection = EVENT_ARG(thread); + struct peer *peer = connection->peer; + struct peer *tmp_peer; struct listnode *node, *nnode; struct peer_af *paf; afi_t afi; safi_t safi; - peer = EVENT_ARG(thread); - if (bgp_debug_neighbor_events(peer)) { zlog_debug("%pBP graceful restart timer expired", peer); zlog_debug("%pBP graceful restart stalepath timer stopped", @@ -832,17 +791,16 @@ static void bgp_graceful_restart_timer_expire(struct event *thread) } } - bgp_graceful_restart_timer_off(peer); + bgp_graceful_restart_timer_off(connection, peer); } static void bgp_graceful_stale_timer_expire(struct event *thread) { - struct peer *peer; + struct peer_connection *connection = EVENT_ARG(thread); + struct peer *peer = connection->peer; afi_t afi; safi_t safi; - peer = EVENT_ARG(thread); - if (bgp_debug_neighbor_events(peer)) zlog_debug("%pBP graceful restart stalepath timer expired", peer); @@ -970,10 +928,13 @@ void bgp_start_routeadv(struct bgp *bgp) sizeof(bgp->update_delay_peers_resume_time)); for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { - if (!peer_established(peer)) + struct peer_connection *connection = peer->connection; + + if (!peer_established(connection)) continue; - EVENT_OFF(peer->t_routeadv); - BGP_TIMER_ON(peer->t_routeadv, bgp_routeadv_timer, 0); + + EVENT_OFF(connection->t_routeadv); + BGP_TIMER_ON(connection->t_routeadv, bgp_routeadv_timer, 0); } } @@ -985,6 +946,7 @@ void bgp_adjust_routeadv(struct peer *peer) time_t nowtime = monotime(NULL); double diff; unsigned long remain; + struct peer_connection *connection = peer->connection; /* Bypass checks for special case of MRAI being 0 */ if (peer->v_routeadv == 0) { @@ -992,7 +954,7 @@ void bgp_adjust_routeadv(struct peer *peer) * different * duration and schedule write thread immediately. */ - EVENT_OFF(peer->t_routeadv); + EVENT_OFF(connection->t_routeadv); peer->synctime = monotime(NULL); /* If suppress fib pending is enabled, route is advertised to @@ -1000,7 +962,7 @@ void bgp_adjust_routeadv(struct peer *peer) * is added to update group packet generate which will allow * more routes to be sent in the update message */ - BGP_UPDATE_GROUP_TIMER_ON(&peer->t_generate_updgrp_packets, + BGP_UPDATE_GROUP_TIMER_ON(&connection->t_generate_updgrp_packets, bgp_generate_updgrp_packets); return; } @@ -1024,8 +986,8 @@ void bgp_adjust_routeadv(struct peer *peer) */ diff = difftime(nowtime, peer->last_update); if (diff > (double)peer->v_routeadv) { - EVENT_OFF(peer->t_routeadv); - BGP_TIMER_ON(peer->t_routeadv, bgp_routeadv_timer, 0); + EVENT_OFF(connection->t_routeadv); + BGP_TIMER_ON(connection->t_routeadv, bgp_routeadv_timer, 0); return; } @@ -1045,14 +1007,14 @@ void bgp_adjust_routeadv(struct peer *peer) * * (MRAI - m) < r */ - if (peer->t_routeadv) - remain = event_timer_remain_second(peer->t_routeadv); + if (connection->t_routeadv) + remain = event_timer_remain_second(connection->t_routeadv); else remain = peer->v_routeadv; diff = peer->v_routeadv - diff; if (diff <= (double)remain) { - EVENT_OFF(peer->t_routeadv); - BGP_TIMER_ON(peer->t_routeadv, bgp_routeadv_timer, diff); + EVENT_OFF(connection->t_routeadv); + BGP_TIMER_ON(connection->t_routeadv, bgp_routeadv_timer, diff); } } @@ -1160,7 +1122,7 @@ static void bgp_maxmed_onstartup_begin(struct bgp *bgp) static void bgp_maxmed_onstartup_process_status_change(struct peer *peer) { - if (peer_established(peer) && !peer->bgp->established) { + if (peer_established(peer->connection) && !peer->bgp->established) { bgp_maxmed_onstartup_begin(peer->bgp); } } @@ -1218,7 +1180,7 @@ static void bgp_update_delay_begin(struct bgp *bgp) static void bgp_update_delay_process_status_change(struct peer *peer) { - if (peer_established(peer)) { + if (peer_established(peer->connection)) { if (!peer->bgp->established++) { bgp_update_delay_begin(peer->bgp); zlog_info( @@ -1228,8 +1190,8 @@ static void bgp_update_delay_process_status_change(struct peer *peer) if (CHECK_FLAG(peer->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV)) bgp_update_restarted_peers(peer); } - if (peer->ostatus == Established - && bgp_update_delay_active(peer->bgp)) { + if (peer->connection->ostatus == Established && + bgp_update_delay_active(peer->bgp)) { /* Adjust the update-delay state to account for this flap. NOTE: Intentionally skipping adjusting implicit_eors or explicit_eors @@ -1244,17 +1206,18 @@ static void bgp_update_delay_process_status_change(struct peer *peer) /* Called after event occurred, this function change status and reset read/write and timer thread. */ -void bgp_fsm_change_status(struct peer *peer, enum bgp_fsm_status status) +void bgp_fsm_change_status(struct peer_connection *connection, + enum bgp_fsm_status status) { - struct bgp *bgp; + struct peer *peer = connection->peer; + struct bgp *bgp = peer->bgp; uint32_t peer_count; - bgp = peer->bgp; peer_count = bgp->established_peers; if (status == Established) bgp->established_peers++; - else if ((peer_established(peer)) && (status != Established)) + else if ((peer_established(connection)) && (status != Established)) bgp->established_peers--; if (bgp_debug_neighbor_events(peer)) { @@ -1301,18 +1264,19 @@ void bgp_fsm_change_status(struct peer *peer, enum bgp_fsm_status status) */ if (!work_queue_is_scheduled(peer->clear_node_queue) && status != Deleted) - BGP_EVENT_ADD(peer, Clearing_Completed); + BGP_EVENT_ADD(connection, Clearing_Completed); } /* Preserve old status and change into new status. */ - peer->ostatus = peer->status; - peer->status = status; + connection->ostatus = connection->status; + connection->status = status; /* Reset received keepalives counter on every FSM change */ peer->rtt_keepalive_rcv = 0; /* Fire backward transition hook if that's the case */ - if (peer->ostatus == Established && peer->status != Established) + if (connection->ostatus == Established && + connection->status != Established) hook_call(peer_backward_transition, peer); /* Save event that caused status change. */ @@ -1339,30 +1303,33 @@ void bgp_fsm_change_status(struct peer *peer, enum bgp_fsm_status status) bgp_update_delay_process_status_change(peer); if (bgp_debug_neighbor_events(peer)) - zlog_debug("%s fd %d went from %s to %s", peer->host, peer->fd, - lookup_msg(bgp_status_msg, peer->ostatus, NULL), - lookup_msg(bgp_status_msg, peer->status, NULL)); + zlog_debug("%s fd %d went from %s to %s", peer->host, + connection->fd, + lookup_msg(bgp_status_msg, connection->ostatus, NULL), + lookup_msg(bgp_status_msg, connection->status, NULL)); } /* Flush the event queue and ensure the peer is shut down */ -static enum bgp_fsm_state_progress bgp_clearing_completed(struct peer *peer) +static enum bgp_fsm_state_progress +bgp_clearing_completed(struct peer_connection *connection) { - enum bgp_fsm_state_progress rc = bgp_stop(peer); + enum bgp_fsm_state_progress rc = bgp_stop(connection); if (rc >= BGP_FSM_SUCCESS) - BGP_EVENT_FLUSH(peer); + event_cancel_event_ready(bm->master, connection); return rc; } /* Administrative BGP peer stop event. */ /* May be called multiple times for the same peer */ -enum bgp_fsm_state_progress bgp_stop(struct peer *peer) +enum bgp_fsm_state_progress bgp_stop(struct peer_connection *connection) { afi_t afi; safi_t safi; char orf_name[BUFSIZ]; enum bgp_fsm_state_progress ret = BGP_FSM_SUCCESS; + struct peer *peer = connection->peer; struct bgp *bgp = peer->bgp; struct graceful_restart_info *gr_info = NULL; @@ -1383,13 +1350,13 @@ enum bgp_fsm_state_progress bgp_stop(struct peer *peer) } /* Can't do this in Clearing; events are used for state transitions */ - if (peer->status != Clearing) { + if (connection->status != Clearing) { /* Delete all existing events of the peer */ - BGP_EVENT_FLUSH(peer); + event_cancel_event_ready(bm->master, connection); } /* Increment Dropped count. */ - if (peer_established(peer)) { + if (peer_established(connection)) { peer->dropped++; /* Notify BGP conditional advertisement process */ @@ -1411,8 +1378,8 @@ enum bgp_fsm_state_progress bgp_stop(struct peer *peer) } /* graceful restart */ - if (peer->t_gr_stale) { - EVENT_OFF(peer->t_gr_stale); + if (connection->t_gr_stale) { + EVENT_OFF(connection->t_gr_stale); if (bgp_debug_neighbor_events(peer)) zlog_debug( "%pBP graceful restart stalepath timer stopped", @@ -1427,10 +1394,10 @@ enum bgp_fsm_state_progress bgp_stop(struct peer *peer) "%pBP graceful restart stalepath timer started for %d sec", peer, peer->bgp->stalepath_time); } - BGP_TIMER_ON(peer->t_gr_restart, + BGP_TIMER_ON(connection->t_gr_restart, bgp_graceful_restart_timer_expire, peer->v_gr_restart); - BGP_TIMER_ON(peer->t_gr_stale, + BGP_TIMER_ON(connection->t_gr_stale, bgp_graceful_stale_timer_expire, peer->bgp->stalepath_time); } else { @@ -1499,33 +1466,31 @@ enum bgp_fsm_state_progress bgp_stop(struct peer *peer) } /* stop keepalives */ - bgp_keepalives_off(peer); + bgp_keepalives_off(connection); /* Stop read and write threads. */ - bgp_writes_off(peer); - bgp_reads_off(peer); + bgp_writes_off(connection); + bgp_reads_off(connection); - EVENT_OFF(peer->t_connect_check_r); - EVENT_OFF(peer->t_connect_check_w); + EVENT_OFF(connection->t_connect_check_r); + EVENT_OFF(connection->t_connect_check_w); /* Stop all timers. */ - EVENT_OFF(peer->t_start); - EVENT_OFF(peer->t_connect); - EVENT_OFF(peer->t_holdtime); - EVENT_OFF(peer->t_routeadv); - EVENT_OFF(peer->t_delayopen); + EVENT_OFF(connection->t_start); + EVENT_OFF(connection->t_connect); + EVENT_OFF(connection->t_holdtime); + EVENT_OFF(connection->t_routeadv); + EVENT_OFF(peer->connection->t_delayopen); /* Clear input and output buffer. */ - frr_with_mutex (&peer->io_mtx) { - if (peer->ibuf) - stream_fifo_clean(peer->ibuf); - if (peer->obuf) - stream_fifo_clean(peer->obuf); + frr_with_mutex (&connection->io_mtx) { + if (connection->ibuf) + stream_fifo_clean(connection->ibuf); + if (connection->obuf) + stream_fifo_clean(connection->obuf); - if (peer->ibuf_work) - ringbuf_wipe(peer->ibuf_work); - if (peer->obuf_work) - stream_reset(peer->obuf_work); + if (connection->ibuf_work) + ringbuf_wipe(connection->ibuf_work); if (peer->curr) { stream_free(peer->curr); @@ -1534,9 +1499,9 @@ enum bgp_fsm_state_progress bgp_stop(struct peer *peer) } /* Close of file descriptor. */ - if (peer->fd >= 0) { - close(peer->fd); - peer->fd = -1; + if (connection->fd >= 0) { + close(connection->fd); + connection->fd = -1; } /* Reset capabilities. */ @@ -1560,7 +1525,8 @@ enum bgp_fsm_state_progress bgp_stop(struct peer *peer) /* Received ORF prefix-filter */ peer->orf_plist[afi][safi] = NULL; - if ((peer->status == OpenConfirm) || (peer_established(peer))) { + if ((connection->status == OpenConfirm) || + peer_established(connection)) { /* ORF received prefix-filter pnt */ snprintf(orf_name, sizeof(orf_name), "%s.%d.%d", peer->host, afi, safi); @@ -1590,14 +1556,17 @@ enum bgp_fsm_state_progress bgp_stop(struct peer *peer) peer_delete(peer); ret = BGP_FSM_FAILURE_AND_DELETE; } else { - bgp_peer_conf_if_to_su_update(peer); + bgp_peer_conf_if_to_su_update(connection); } return ret; } /* BGP peer is stoped by the error. */ -static enum bgp_fsm_state_progress bgp_stop_with_error(struct peer *peer) +static enum bgp_fsm_state_progress +bgp_stop_with_error(struct peer_connection *connection) { + struct peer *peer = connection->peer; + /* Double start timer. */ peer->v_start *= 2; @@ -1613,16 +1582,19 @@ static enum bgp_fsm_state_progress bgp_stop_with_error(struct peer *peer) return BGP_FSM_FAILURE; } - return bgp_stop(peer); + return bgp_stop(connection); } /* something went wrong, send notify and tear down */ static enum bgp_fsm_state_progress -bgp_stop_with_notify(struct peer *peer, uint8_t code, uint8_t sub_code) +bgp_stop_with_notify(struct peer_connection *connection, uint8_t code, + uint8_t sub_code) { + struct peer *peer = connection->peer; + /* Send notify to remote peer */ - bgp_notify_send(peer, code, sub_code); + bgp_notify_send(connection, code, sub_code); if (peer_dynamic_neighbor_no_nsf(peer)) { if (bgp_debug_neighbor_events(peer)) @@ -1635,7 +1607,7 @@ bgp_stop_with_notify(struct peer *peer, uint8_t code, uint8_t sub_code) /* Clear start timer value to default. */ peer->v_start = BGP_INIT_START_TIMER; - return bgp_stop(peer); + return bgp_stop(connection); } /** @@ -1658,63 +1630,67 @@ static void bgp_connect_check(struct event *thread) int status; socklen_t slen; int ret; - struct peer *peer; + struct peer_connection *connection = EVENT_ARG(thread); + struct peer *peer = connection->peer; - peer = EVENT_ARG(thread); - assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_READS_ON)); - assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_WRITES_ON)); - assert(!peer->t_read); - assert(!peer->t_write); + assert(!CHECK_FLAG(connection->thread_flags, PEER_THREAD_READS_ON)); + assert(!CHECK_FLAG(connection->thread_flags, PEER_THREAD_WRITES_ON)); + assert(!connection->t_read); + assert(!connection->t_write); - EVENT_OFF(peer->t_connect_check_r); - EVENT_OFF(peer->t_connect_check_w); + EVENT_OFF(connection->t_connect_check_r); + EVENT_OFF(connection->t_connect_check_w); /* Check file descriptor. */ slen = sizeof(status); - ret = getsockopt(peer->fd, SOL_SOCKET, SO_ERROR, (void *)&status, + ret = getsockopt(connection->fd, SOL_SOCKET, SO_ERROR, (void *)&status, &slen); /* If getsockopt is fail, this is fatal error. */ if (ret < 0) { zlog_err("can't get sockopt for nonblocking connect: %d(%s)", errno, safe_strerror(errno)); - BGP_EVENT_ADD(peer, TCP_fatal_error); + BGP_EVENT_ADD(connection, TCP_fatal_error); return; } /* When status is 0 then TCP connection is established. */ if (status == 0) { if (CHECK_FLAG(peer->flags, PEER_FLAG_TIMER_DELAYOPEN)) - BGP_EVENT_ADD(peer, TCP_connection_open_w_delay); + BGP_EVENT_ADD(connection, + TCP_connection_open_w_delay); else - BGP_EVENT_ADD(peer, TCP_connection_open); + BGP_EVENT_ADD(connection, TCP_connection_open); return; } else { if (bgp_debug_neighbor_events(peer)) zlog_debug("%s [Event] Connect failed %d(%s)", peer->host, status, safe_strerror(status)); - BGP_EVENT_ADD(peer, TCP_connection_open_failed); + BGP_EVENT_ADD(connection, TCP_connection_open_failed); return; } } /* TCP connection open. Next we send open message to remote peer. And add read thread for reading open message. */ -static enum bgp_fsm_state_progress bgp_connect_success(struct peer *peer) +static enum bgp_fsm_state_progress +bgp_connect_success(struct peer_connection *connection) { - if (peer->fd < 0) { + struct peer *peer = connection->peer; + + if (connection->fd < 0) { flog_err(EC_BGP_CONNECT, "%s peer's fd is negative value %d", - __func__, peer->fd); - return bgp_stop(peer); + __func__, connection->fd); + return bgp_stop(connection); } if (bgp_getsockname(peer) < 0) { flog_err_sys(EC_LIB_SOCKET, "%s: bgp_getsockname(): failed for peer %s, fd %d", - __func__, peer->host, peer->fd); - bgp_notify_send(peer, BGP_NOTIFY_FSM_ERR, - bgp_fsm_error_subcode(peer->status)); - bgp_writes_on(peer); + __func__, peer->host, connection->fd); + bgp_notify_send(peer->connection, BGP_NOTIFY_FSM_ERR, + bgp_fsm_error_subcode(connection->status)); + bgp_writes_on(connection); return BGP_FSM_FAILURE; } @@ -1724,7 +1700,7 @@ static enum bgp_fsm_state_progress bgp_connect_success(struct peer *peer) */ bgp_nht_interface_events(peer); - bgp_reads_on(peer); + bgp_reads_on(connection); if (bgp_debug_neighbor_events(peer)) { if (!CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER)) @@ -1735,7 +1711,7 @@ static enum bgp_fsm_state_progress bgp_connect_success(struct peer *peer) } /* Send an open message */ - bgp_open_send(peer); + bgp_open_send(connection); return BGP_FSM_SUCCESS; } @@ -1744,21 +1720,23 @@ static enum bgp_fsm_state_progress bgp_connect_success(struct peer *peer) * set. */ static enum bgp_fsm_state_progress -bgp_connect_success_w_delayopen(struct peer *peer) +bgp_connect_success_w_delayopen(struct peer_connection *connection) { - if (peer->fd < 0) { + struct peer *peer = connection->peer; + + if (connection->fd < 0) { flog_err(EC_BGP_CONNECT, "%s: peer's fd is negative value %d", - __func__, peer->fd); - return bgp_stop(peer); + __func__, connection->fd); + return bgp_stop(connection); } if (bgp_getsockname(peer) < 0) { flog_err_sys(EC_LIB_SOCKET, "%s: bgp_getsockname(): failed for peer %s, fd %d", - __func__, peer->host, peer->fd); - bgp_notify_send(peer, BGP_NOTIFY_FSM_ERR, - bgp_fsm_error_subcode(peer->status)); - bgp_writes_on(peer); + __func__, peer->host, connection->fd); + bgp_notify_send(peer->connection, BGP_NOTIFY_FSM_ERR, + bgp_fsm_error_subcode(connection->status)); + bgp_writes_on(connection); return BGP_FSM_FAILURE; } @@ -1768,7 +1746,7 @@ bgp_connect_success_w_delayopen(struct peer *peer) */ bgp_nht_interface_events(peer); - bgp_reads_on(peer); + bgp_reads_on(connection); if (bgp_debug_neighbor_events(peer)) { if (!CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER)) @@ -1782,8 +1760,8 @@ bgp_connect_success_w_delayopen(struct peer *peer) peer->v_delayopen = peer->delayopen; /* Start the DelayOpenTimer if it is not already running */ - if (!peer->t_delayopen) - BGP_TIMER_ON(peer->t_delayopen, bgp_delayopen_timer, + if (!peer->connection->t_delayopen) + BGP_TIMER_ON(peer->connection->t_delayopen, bgp_delayopen_timer, peer->v_delayopen); if (bgp_debug_neighbor_events(peer)) @@ -1794,9 +1772,12 @@ bgp_connect_success_w_delayopen(struct peer *peer) } /* TCP connect fail */ -static enum bgp_fsm_state_progress bgp_connect_fail(struct peer *peer) +static enum bgp_fsm_state_progress +bgp_connect_fail(struct peer_connection *connection) { - if (peer_dynamic_neighbor_no_nsf(peer)) { + struct peer *peer = connection->peer; + + if (peer_dynamic_neighbor(peer)) { if (bgp_debug_neighbor_events(peer)) zlog_debug("%s (dynamic neighbor) deleted (%s)", peer->host, __func__); @@ -1810,19 +1791,20 @@ static enum bgp_fsm_state_progress bgp_connect_fail(struct peer *peer) */ bgp_nht_interface_events(peer); - return bgp_stop(peer); + return bgp_stop(connection); } /* This function is the first starting point of all BGP connection. It * try to connect to remote peer with non-blocking IO. */ -enum bgp_fsm_state_progress bgp_start(struct peer *peer) +static enum bgp_fsm_state_progress bgp_start(struct peer_connection *connection) { + struct peer *peer = connection->peer; int status; - bgp_peer_conf_if_to_su_update(peer); + bgp_peer_conf_if_to_su_update(connection); - if (peer->su.sa.sa_family == AF_UNSPEC) { + if (connection->su.sa.sa_family == AF_UNSPEC) { if (bgp_debug_neighbor_events(peer)) zlog_debug( "%s [FSM] Unable to get neighbor's IP address, waiting...", @@ -1847,32 +1829,12 @@ enum bgp_fsm_state_progress bgp_start(struct peer *peer) return BGP_FSM_FAILURE; } - /* Scrub some information that might be left over from a previous, - * session - */ - /* Connection information. */ - if (peer->su_local) { - sockunion_free(peer->su_local); - peer->su_local = NULL; - } - - if (peer->su_remote) { - sockunion_free(peer->su_remote); - peer->su_remote = NULL; - } - /* Clear remote router-id. */ peer->remote_id.s_addr = INADDR_ANY; /* Clear peer capability flag. */ peer->cap = 0; - /* If the peer is passive mode, force to move to Active mode. */ - if (CHECK_FLAG(peer->flags, PEER_FLAG_PASSIVE)) { - BGP_EVENT_ADD(peer, TCP_connection_open_failed); - return BGP_FSM_SUCCESS; - } - if (peer->bgp->vrf_id == VRF_UNKNOWN) { if (bgp_debug_neighbor_events(peer)) flog_err( @@ -1893,42 +1855,39 @@ enum bgp_fsm_state_progress bgp_start(struct peer *peer) "%s [FSM] Waiting for NHT, no path to neighbor present", peer->host); peer->last_reset = PEER_DOWN_WAITING_NHT; - BGP_EVENT_ADD(peer, TCP_connection_open_failed); + BGP_EVENT_ADD(connection, TCP_connection_open_failed); return BGP_FSM_SUCCESS; } } - assert(!peer->t_write); - assert(!peer->t_read); - assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_WRITES_ON)); - assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_READS_ON)); - status = bgp_connect(peer); + assert(!connection->t_write); + assert(!connection->t_read); + assert(!CHECK_FLAG(connection->thread_flags, PEER_THREAD_WRITES_ON)); + assert(!CHECK_FLAG(connection->thread_flags, PEER_THREAD_READS_ON)); + status = bgp_connect(connection); switch (status) { case connect_error: if (bgp_debug_neighbor_events(peer)) zlog_debug("%s [FSM] Connect error", peer->host); - BGP_EVENT_ADD(peer, TCP_connection_open_failed); + BGP_EVENT_ADD(connection, TCP_connection_open_failed); break; case connect_success: if (bgp_debug_neighbor_events(peer)) - zlog_debug( - "%s [FSM] Connect immediately success, fd %d", - peer->host, peer->fd); + zlog_debug("%s [FSM] Connect immediately success, fd %d", + peer->host, connection->fd); - BGP_EVENT_ADD(peer, TCP_connection_open); + BGP_EVENT_ADD(connection, TCP_connection_open); break; case connect_in_progress: /* To check nonblocking connect, we wait until socket is readable or writable. */ if (bgp_debug_neighbor_events(peer)) - zlog_debug( - "%s [FSM] Non blocking connect waiting result, fd %d", - peer->host, peer->fd); - if (peer->fd < 0) { - flog_err(EC_BGP_FSM, - "%s peer's fd is negative value %d", __func__, - peer->fd); + zlog_debug("%s [FSM] Non blocking connect waiting result, fd %d", + peer->host, connection->fd); + if (connection->fd < 0) { + flog_err(EC_BGP_FSM, "%s peer's fd is negative value %d", + __func__, peer->connection->fd); return BGP_FSM_FAILURE; } /* @@ -1940,21 +1899,23 @@ enum bgp_fsm_state_progress bgp_start(struct peer *peer) * bgp_connect_check() as the handler for each and cancel the * unused event in that function. */ - event_add_read(bm->master, bgp_connect_check, peer, peer->fd, - &peer->t_connect_check_r); - event_add_write(bm->master, bgp_connect_check, peer, peer->fd, - &peer->t_connect_check_w); + event_add_read(bm->master, bgp_connect_check, connection, + connection->fd, &connection->t_connect_check_r); + event_add_write(bm->master, bgp_connect_check, connection, + connection->fd, &connection->t_connect_check_w); break; } return BGP_FSM_SUCCESS; } /* Connect retry timer is expired when the peer status is Connect. */ -static enum bgp_fsm_state_progress bgp_reconnect(struct peer *peer) +static enum bgp_fsm_state_progress +bgp_reconnect(struct peer_connection *connection) { + struct peer *peer = connection->peer; enum bgp_fsm_state_progress ret; - ret = bgp_stop(peer); + ret = bgp_stop(connection); if (ret < BGP_FSM_SUCCESS) return ret; @@ -1962,14 +1923,17 @@ static enum bgp_fsm_state_progress bgp_reconnect(struct peer *peer) BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(peer->bgp, peer->bgp->peer); - return bgp_start(peer); + return bgp_start(connection); } -static enum bgp_fsm_state_progress bgp_fsm_open(struct peer *peer) +static enum bgp_fsm_state_progress +bgp_fsm_open(struct peer_connection *connection) { + struct peer *peer = connection->peer; + /* If DelayOpen is active, we may still need to send an open message */ - if ((peer->status == Connect) || (peer->status == Active)) - bgp_open_send(peer); + if ((connection->status == Connect) || (connection->status == Active)) + bgp_open_send(connection); /* Send keepalive and make keepalive timer */ bgp_keepalive_send(peer); @@ -1979,19 +1943,26 @@ static enum bgp_fsm_state_progress bgp_fsm_open(struct peer *peer) /* FSM error, unexpected event. This is error of BGP connection. So cut the peer and change to Idle status. */ -static enum bgp_fsm_state_progress bgp_fsm_event_error(struct peer *peer) +static enum bgp_fsm_state_progress +bgp_fsm_event_error(struct peer_connection *connection) { + struct peer *peer = connection->peer; + flog_err(EC_BGP_FSM, "%s [FSM] unexpected packet received in state %s", - peer->host, lookup_msg(bgp_status_msg, peer->status, NULL)); + peer->host, + lookup_msg(bgp_status_msg, connection->status, NULL)); - return bgp_stop_with_notify(peer, BGP_NOTIFY_FSM_ERR, - bgp_fsm_error_subcode(peer->status)); + return bgp_stop_with_notify(connection, BGP_NOTIFY_FSM_ERR, + bgp_fsm_error_subcode(connection->status)); } /* Hold timer expire. This is error of BGP connection. So cut the peer and change to Idle status. */ -static enum bgp_fsm_state_progress bgp_fsm_holdtime_expire(struct peer *peer) +static enum bgp_fsm_state_progress +bgp_fsm_holdtime_expire(struct peer_connection *connection) { + struct peer *peer = connection->peer; + if (bgp_debug_neighbor_events(peer)) zlog_debug("%s [FSM] Hold timer expire", peer->host); @@ -1999,26 +1970,26 @@ static enum bgp_fsm_state_progress bgp_fsm_holdtime_expire(struct peer *peer) * the Graceful Restart procedures to be performed when the BGP * speaker receives a BGP NOTIFICATION message or the Hold Time expires. */ - if (peer_established(peer) && + if (peer_established(connection) && bgp_has_graceful_restart_notification(peer)) if (CHECK_FLAG(peer->sflags, PEER_STATUS_NSF_MODE)) SET_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT); - return bgp_stop_with_notify(peer, BGP_NOTIFY_HOLD_ERR, 0); + return bgp_stop_with_notify(connection, BGP_NOTIFY_HOLD_ERR, 0); } /* RFC 4271 DelayOpenTimer_Expires event */ static enum bgp_fsm_state_progress -bgp_fsm_delayopen_timer_expire(struct peer *peer) +bgp_fsm_delayopen_timer_expire(struct peer_connection *connection) { /* Stop the DelayOpenTimer */ - EVENT_OFF(peer->t_delayopen); + EVENT_OFF(connection->t_delayopen); /* Send open message to peer */ - bgp_open_send(peer); + bgp_open_send(connection); /* Set the HoldTimer to a large value (4 minutes) */ - peer->v_holdtime = 245; + connection->peer->v_holdtime = 245; return BGP_FSM_SUCCESS; } @@ -2101,7 +2072,8 @@ static int bgp_update_gr_info(struct peer *peer, afi_t afi, safi_t safi) * Convert peer from stub to full fledged peer, set some timers, and generate * initial updates. */ -static enum bgp_fsm_state_progress bgp_establish(struct peer *peer) +static enum bgp_fsm_state_progress +bgp_establish(struct peer_connection *connection) { afi_t afi; safi_t safi; @@ -2109,6 +2081,8 @@ static enum bgp_fsm_state_progress bgp_establish(struct peer *peer) enum bgp_fsm_state_progress ret = BGP_FSM_SUCCESS; struct peer *other; int status; + struct peer *peer = connection->peer; + struct peer *orig = peer; other = peer->doppelganger; hash_release(peer->bgp->peerhash, peer); @@ -2118,8 +2092,24 @@ static enum bgp_fsm_state_progress bgp_establish(struct peer *peer) peer = peer_xfer_conn(peer); if (!peer) { flog_err(EC_BGP_CONNECT, "%%Neighbor failed in xfer_conn"); + + /* + * A failure of peer_xfer_conn but not putting the peers + * back in the hash ends up with a situation where incoming + * connections are rejected, as that the peer is not found + * when a lookup is done + */ + (void)hash_get(orig->bgp->peerhash, orig, hash_alloc_intern); + if (other) + (void)hash_get(other->bgp->peerhash, other, + hash_alloc_intern); return BGP_FSM_FAILURE; } + /* + * At this point the connections have been possibly swapped + * let's reset it. + */ + connection = peer->connection; if (other == peer) ret = BGP_FSM_SUCCESS_STATE_TRANSFER; @@ -2133,7 +2123,7 @@ static enum bgp_fsm_state_progress bgp_establish(struct peer *peer) /* Increment established count. */ peer->established++; - bgp_fsm_change_status(peer, Established); + bgp_fsm_change_status(connection, Established); /* bgp log-neighbor-changes of neighbor Up */ if (CHECK_FLAG(peer->bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)) { @@ -2224,8 +2214,8 @@ static enum bgp_fsm_state_progress bgp_establish(struct peer *peer) SET_FLAG(peer->sflags, PEER_STATUS_NSF_MODE); else { UNSET_FLAG(peer->sflags, PEER_STATUS_NSF_MODE); - if (peer->t_gr_stale) { - EVENT_OFF(peer->t_gr_stale); + if (connection->t_gr_stale) { + EVENT_OFF(connection->t_gr_stale); if (bgp_debug_neighbor_events(peer)) zlog_debug( "%pBP graceful restart stalepath timer stopped", @@ -2233,15 +2223,15 @@ static enum bgp_fsm_state_progress bgp_establish(struct peer *peer) } } - if (peer->t_gr_restart) { - EVENT_OFF(peer->t_gr_restart); + if (connection->t_gr_restart) { + EVENT_OFF(connection->t_gr_restart); if (bgp_debug_neighbor_events(peer)) zlog_debug("%pBP graceful restart timer stopped", peer); } /* Reset uptime, turn on keepalives, send current table. */ if (!peer->v_holdtime) - bgp_keepalives_on(peer); + bgp_keepalives_on(connection); peer->uptime = monotime(NULL); @@ -2265,12 +2255,6 @@ static enum bgp_fsm_state_progress bgp_establish(struct peer *peer) peer, afi, safi, ORF_TYPE_PREFIX, REFRESH_IMMEDIATE, 0, BGP_ROUTE_REFRESH_NORMAL); - else if (CHECK_FLAG(peer->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) - bgp_route_refresh_send( - peer, afi, safi, ORF_TYPE_PREFIX_OLD, - REFRESH_IMMEDIATE, 0, - BGP_ROUTE_REFRESH_NORMAL); } } @@ -2279,9 +2263,7 @@ static enum bgp_fsm_state_progress bgp_establish(struct peer *peer) if (CHECK_FLAG(peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)) if (CHECK_FLAG(peer->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_SM_RCV) - || CHECK_FLAG(peer->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_SM_OLD_RCV)) + PEER_CAP_ORF_PREFIX_SM_RCV)) SET_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH); } @@ -2295,18 +2277,21 @@ static enum bgp_fsm_state_progress bgp_establish(struct peer *peer) * of read-only mode. */ if (!bgp_update_delay_active(peer->bgp)) { - EVENT_OFF(peer->t_routeadv); - BGP_TIMER_ON(peer->t_routeadv, bgp_routeadv_timer, 0); + EVENT_OFF(peer->connection->t_routeadv); + BGP_TIMER_ON(peer->connection->t_routeadv, bgp_routeadv_timer, + 0); } - if (peer->doppelganger && (peer->doppelganger->status != Deleted)) { + if (peer->doppelganger && + (peer->doppelganger->connection->status != Deleted)) { if (bgp_debug_neighbor_events(peer)) zlog_debug( "[Event] Deleting stub connection for peer %s", peer->host); - if (peer->doppelganger->status > Active) - bgp_notify_send(peer->doppelganger, BGP_NOTIFY_CEASE, + if (peer->doppelganger->connection->status > Active) + bgp_notify_send(peer->doppelganger->connection, + BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_COLLISION_RESOLUTION); else peer_delete(peer->doppelganger); @@ -2328,65 +2313,71 @@ static enum bgp_fsm_state_progress bgp_establish(struct peer *peer) } /* Keepalive packet is received. */ -static enum bgp_fsm_state_progress bgp_fsm_keepalive(struct peer *peer) +static enum bgp_fsm_state_progress +bgp_fsm_keepalive(struct peer_connection *connection) { - EVENT_OFF(peer->t_holdtime); + EVENT_OFF(connection->t_holdtime); return BGP_FSM_SUCCESS; } /* Update packet is received. */ -static enum bgp_fsm_state_progress bgp_fsm_update(struct peer *peer) +static enum bgp_fsm_state_progress +bgp_fsm_update(struct peer_connection *connection) { - EVENT_OFF(peer->t_holdtime); + EVENT_OFF(connection->t_holdtime); return BGP_FSM_SUCCESS; } /* This is empty event. */ -static enum bgp_fsm_state_progress bgp_ignore(struct peer *peer) -{ - flog_err( - EC_BGP_FSM, - "%s [FSM] Ignoring event %s in state %s, prior events %s, %s, fd %d", - peer->host, bgp_event_str[peer->cur_event], - lookup_msg(bgp_status_msg, peer->status, NULL), - bgp_event_str[peer->last_event], - bgp_event_str[peer->last_major_event], peer->fd); +static enum bgp_fsm_state_progress bgp_ignore(struct peer_connection *connection) +{ + struct peer *peer = connection->peer; + + flog_err(EC_BGP_FSM, + "%s [FSM] Ignoring event %s in state %s, prior events %s, %s, fd %d", + peer->host, bgp_event_str[peer->cur_event], + lookup_msg(bgp_status_msg, connection->status, NULL), + bgp_event_str[peer->last_event], + bgp_event_str[peer->last_major_event], connection->fd); return BGP_FSM_SUCCESS; } /* This is to handle unexpected events.. */ -static enum bgp_fsm_state_progress bgp_fsm_exception(struct peer *peer) +static enum bgp_fsm_state_progress +bgp_fsm_exception(struct peer_connection *connection) { - flog_err( - EC_BGP_FSM, - "%s [FSM] Unexpected event %s in state %s, prior events %s, %s, fd %d", - peer->host, bgp_event_str[peer->cur_event], - lookup_msg(bgp_status_msg, peer->status, NULL), - bgp_event_str[peer->last_event], - bgp_event_str[peer->last_major_event], peer->fd); - return bgp_stop(peer); + struct peer *peer = connection->peer; + + flog_err(EC_BGP_FSM, + "%s [FSM] Unexpected event %s in state %s, prior events %s, %s, fd %d", + peer->host, bgp_event_str[peer->cur_event], + lookup_msg(bgp_status_msg, connection->status, NULL), + bgp_event_str[peer->last_event], + bgp_event_str[peer->last_major_event], connection->fd); + return bgp_stop(connection); } -void bgp_fsm_nht_update(struct peer *peer, bool has_valid_nexthops) +void bgp_fsm_nht_update(struct peer_connection *connection, struct peer *peer, + bool has_valid_nexthops) { if (!peer) return; - switch (peer->status) { + switch (connection->status) { case Idle: if (has_valid_nexthops) - BGP_EVENT_ADD(peer, BGP_Start); + BGP_EVENT_ADD(connection, BGP_Start); break; case Connect: if (!has_valid_nexthops) { - EVENT_OFF(peer->t_connect); - BGP_EVENT_ADD(peer, TCP_fatal_error); + EVENT_OFF(connection->t_connect); + BGP_EVENT_ADD(connection, TCP_fatal_error); } break; case Active: if (has_valid_nexthops) { - EVENT_OFF(peer->t_connect); - BGP_EVENT_ADD(peer, ConnectRetry_timer_expired); + EVENT_OFF(connection->t_connect); + BGP_EVENT_ADD(connection, ConnectRetry_timer_expired); } break; case OpenSent: @@ -2395,7 +2386,8 @@ void bgp_fsm_nht_update(struct peer *peer, bool has_valid_nexthops) if (!has_valid_nexthops && (peer->gtsm_hops == BGP_GTSM_HOPS_CONNECTED || peer->bgp->fast_convergence)) - BGP_EVENT_ADD(peer, TCP_fatal_error); + BGP_EVENT_ADD(connection, TCP_fatal_error); + break; case Clearing: case Deleted: case BGP_STATUS_MAX: @@ -2405,7 +2397,7 @@ void bgp_fsm_nht_update(struct peer *peer, bool has_valid_nexthops) /* Finite State Machine structure */ static const struct { - enum bgp_fsm_state_progress (*func)(struct peer *); + enum bgp_fsm_state_progress (*func)(struct peer_connection *); enum bgp_fsm_status next_state; } FSM[BGP_STATUS_MAX - 1][BGP_EVENTS_MAX - 1] = { { @@ -2573,62 +2565,63 @@ static const struct { /* Execute event process. */ void bgp_event(struct event *thread) { + struct peer_connection *connection = EVENT_ARG(thread); enum bgp_fsm_events event; - struct peer *peer; + struct peer *peer = connection->peer; - peer = EVENT_ARG(thread); event = EVENT_VAL(thread); peer_lock(peer); - bgp_event_update(peer, event); + bgp_event_update(connection, event); peer_unlock(peer); } -int bgp_event_update(struct peer *peer, enum bgp_fsm_events event) +int bgp_event_update(struct peer_connection *connection, + enum bgp_fsm_events event) { enum bgp_fsm_status next; enum bgp_fsm_state_progress ret = 0; - struct peer *other; + int fsm_result = FSM_PEER_NOOP; int passive_conn = 0; int dyn_nbr; + struct peer *peer = connection->peer; - /* default return code */ - ret = FSM_PEER_NOOP; - - other = peer->doppelganger; passive_conn = (CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER)) ? 1 : 0; dyn_nbr = peer_dynamic_neighbor(peer); /* Logging this event. */ - next = FSM[peer->status - 1][event - 1].next_state; + next = FSM[connection->status - 1][event - 1].next_state; - if (bgp_debug_neighbor_events(peer) && peer->status != next) + if (bgp_debug_neighbor_events(peer) && connection->status != next) zlog_debug("%s [FSM] %s (%s->%s), fd %d", peer->host, bgp_event_str[event], - lookup_msg(bgp_status_msg, peer->status, NULL), - lookup_msg(bgp_status_msg, next, NULL), peer->fd); + lookup_msg(bgp_status_msg, connection->status, NULL), + lookup_msg(bgp_status_msg, next, NULL), + connection->fd); peer->last_event = peer->cur_event; peer->cur_event = event; /* Call function. */ - if (FSM[peer->status - 1][event - 1].func) - ret = (*(FSM[peer->status - 1][event - 1].func))(peer); + if (FSM[connection->status - 1][event - 1].func) + ret = (*(FSM[connection->status - 1][event - 1].func))( + connection); - if (ret >= BGP_FSM_SUCCESS) { + switch (ret) { + case BGP_FSM_SUCCESS: + case BGP_FSM_SUCCESS_STATE_TRANSFER: if (ret == BGP_FSM_SUCCESS_STATE_TRANSFER && next == Established) { /* The case when doppelganger swap accurred in bgp_establish. Update the peer pointer accordingly */ - ret = FSM_PEER_TRANSFERRED; - peer = other; + fsm_result = FSM_PEER_TRANSFERRED; } /* If status is changed. */ - if (next != peer->status) { - bgp_fsm_change_status(peer, next); + if (next != connection->status) { + bgp_fsm_change_status(connection, next); /* * If we're going to ESTABLISHED then we executed a @@ -2637,14 +2630,14 @@ int bgp_event_update(struct peer *peer, enum bgp_fsm_events event) * Opting for TRANSFERRED since transfer implies * session establishment. */ - if (ret != FSM_PEER_TRANSFERRED) - ret = FSM_PEER_TRANSITIONED; + if (fsm_result != FSM_PEER_TRANSFERRED) + fsm_result = FSM_PEER_TRANSITIONED; } /* Make sure timer is set. */ - bgp_timer_set(peer); - - } else { + bgp_timer_set(connection); + break; + case BGP_FSM_FAILURE: /* * If we got a return value of -1, that means there was an * error, restart the FSM. Since bgp_stop() was called on the @@ -2654,22 +2647,27 @@ int bgp_event_update(struct peer *peer, enum bgp_fsm_events event) */ if (!dyn_nbr && !passive_conn && peer->bgp && ret != BGP_FSM_FAILURE_AND_DELETE) { - flog_err( - EC_BGP_FSM, - "%s [FSM] Failure handling event %s in state %s, prior events %s, %s, fd %d", - peer->host, bgp_event_str[peer->cur_event], - lookup_msg(bgp_status_msg, peer->status, NULL), - bgp_event_str[peer->last_event], - bgp_event_str[peer->last_major_event], - peer->fd); - bgp_stop(peer); - bgp_fsm_change_status(peer, Idle); - bgp_timer_set(peer); + flog_err(EC_BGP_FSM, + "%s [FSM] Failure handling event %s in state %s, prior events %s, %s, fd %d, last reset: %s", + peer->host, bgp_event_str[peer->cur_event], + lookup_msg(bgp_status_msg, connection->status, + NULL), + bgp_event_str[peer->last_event], + bgp_event_str[peer->last_major_event], + connection->fd, + peer_down_str[peer->last_reset]); + bgp_stop(connection); + bgp_fsm_change_status(connection, Idle); + bgp_timer_set(connection); } - ret = FSM_PEER_STOPPED; + fsm_result = FSM_PEER_STOPPED; + break; + case BGP_FSM_FAILURE_AND_DELETE: + fsm_result = FSM_PEER_STOPPED; + break; } - return ret; + return fsm_result; } /* BGP GR Code */ diff --git a/bgpd/bgp_fsm.h b/bgpd/bgp_fsm.h index e3cfd0c893..fd46b7994e 100644 --- a/bgpd/bgp_fsm.h +++ b/bgpd/bgp_fsm.h @@ -7,37 +7,38 @@ #ifndef _QUAGGA_BGP_FSM_H #define _QUAGGA_BGP_FSM_H +enum bgp_fsm_state_progress { + BGP_FSM_FAILURE_AND_DELETE = -2, + BGP_FSM_FAILURE = -1, + BGP_FSM_SUCCESS = 0, + BGP_FSM_SUCCESS_STATE_TRANSFER = 1, +}; + /* Macro for BGP read, write and timer thread. */ #define BGP_TIMER_ON(T, F, V) \ do { \ - if ((peer->status != Deleted)) \ - event_add_timer(bm->master, (F), peer, (V), &(T)); \ - } while (0) - -#define BGP_EVENT_ADD(P, E) \ - do { \ - if ((P)->status != Deleted) \ - event_add_event(bm->master, bgp_event, (P), (E), \ - NULL); \ + if ((connection->status != Deleted)) \ + event_add_timer(bm->master, (F), connection, (V), \ + &(T)); \ } while (0) -#define BGP_EVENT_FLUSH(P) \ - do { \ - assert(peer); \ - event_cancel_event_ready(bm->master, (P)); \ +#define BGP_EVENT_ADD(C, E) \ + do { \ + if ((C)->status != Deleted) \ + event_add_event(bm->master, bgp_event, (C), (E), NULL); \ } while (0) -#define BGP_UPDATE_GROUP_TIMER_ON(T, F) \ - do { \ - if (BGP_SUPPRESS_FIB_ENABLED(peer->bgp) && \ - PEER_ROUTE_ADV_DELAY(peer)) \ - event_add_timer_msec( \ - bm->master, (F), peer, \ - (BGP_DEFAULT_UPDATE_ADVERTISEMENT_TIME * \ - 1000), \ - (T)); \ - else \ - event_add_timer_msec(bm->master, (F), peer, 0, (T)); \ +#define BGP_UPDATE_GROUP_TIMER_ON(T, F) \ + do { \ + if (BGP_SUPPRESS_FIB_ENABLED(peer->bgp) && \ + PEER_ROUTE_ADV_DELAY(peer)) \ + event_add_timer_msec(bm->master, (F), connection, \ + (BGP_DEFAULT_UPDATE_ADVERTISEMENT_TIME * \ + 1000), \ + (T)); \ + else \ + event_add_timer_msec(bm->master, (F), connection, 0, \ + (T)); \ } while (0) #define BGP_MSEC_JITTER 10 @@ -105,13 +106,15 @@ /* * Update FSM for peer based on whether we have valid nexthops or not. */ -extern void bgp_fsm_nht_update(struct peer *peer, bool has_valid_nexthops); +extern void bgp_fsm_nht_update(struct peer_connection *connection, + struct peer *peer, bool has_valid_nexthops); extern void bgp_event(struct event *event); -extern int bgp_event_update(struct peer *, enum bgp_fsm_events event); -extern int bgp_stop(struct peer *peer); -extern void bgp_timer_set(struct peer *); +extern int bgp_event_update(struct peer_connection *connection, + enum bgp_fsm_events event); +extern enum bgp_fsm_state_progress bgp_stop(struct peer_connection *connection); +extern void bgp_timer_set(struct peer_connection *connection); extern void bgp_routeadv_timer(struct event *event); -extern void bgp_fsm_change_status(struct peer *peer, +extern void bgp_fsm_change_status(struct peer_connection *connection, enum bgp_fsm_status status); extern const char *const peer_down_str[]; extern void bgp_update_delay_end(struct bgp *); diff --git a/bgpd/bgp_io.c b/bgpd/bgp_io.c index 650adc1c9a..b07e69ac31 100644 --- a/bgpd/bgp_io.c +++ b/bgpd/bgp_io.c @@ -29,11 +29,11 @@ /* clang-format on */ /* forward declarations */ -static uint16_t bgp_write(struct peer *); -static uint16_t bgp_read(struct peer *peer, int *code_p); +static uint16_t bgp_write(struct peer_connection *connection); +static uint16_t bgp_read(struct peer_connection *connection, int *code_p); static void bgp_process_writes(struct event *event); static void bgp_process_reads(struct event *event); -static bool validate_header(struct peer *); +static bool validate_header(struct peer_connection *connection); /* generic i/o status codes */ #define BGP_IO_TRANS_ERR (1 << 0) /* EAGAIN or similar occurred */ @@ -42,65 +42,67 @@ static bool validate_header(struct peer *); /* Thread external API ----------------------------------------------------- */ -void bgp_writes_on(struct peer *peer) +void bgp_writes_on(struct peer_connection *connection) { struct frr_pthread *fpt = bgp_pth_io; + assert(fpt->running); - assert(peer->status != Deleted); - assert(peer->obuf); - assert(peer->ibuf); - assert(peer->ibuf_work); - assert(!peer->t_connect_check_r); - assert(!peer->t_connect_check_w); - assert(peer->fd); - - event_add_write(fpt->master, bgp_process_writes, peer, peer->fd, - &peer->t_write); - SET_FLAG(peer->thread_flags, PEER_THREAD_WRITES_ON); + assert(connection->status != Deleted); + assert(connection->obuf); + assert(connection->ibuf); + assert(connection->ibuf_work); + assert(!connection->t_connect_check_r); + assert(!connection->t_connect_check_w); + assert(connection->fd); + + event_add_write(fpt->master, bgp_process_writes, connection, + connection->fd, &connection->t_write); + SET_FLAG(connection->thread_flags, PEER_THREAD_WRITES_ON); } -void bgp_writes_off(struct peer *peer) +void bgp_writes_off(struct peer_connection *connection) { + struct peer *peer = connection->peer; struct frr_pthread *fpt = bgp_pth_io; assert(fpt->running); - event_cancel_async(fpt->master, &peer->t_write, NULL); - EVENT_OFF(peer->t_generate_updgrp_packets); + event_cancel_async(fpt->master, &connection->t_write, NULL); + EVENT_OFF(connection->t_generate_updgrp_packets); - UNSET_FLAG(peer->thread_flags, PEER_THREAD_WRITES_ON); + UNSET_FLAG(peer->connection->thread_flags, PEER_THREAD_WRITES_ON); } -void bgp_reads_on(struct peer *peer) +void bgp_reads_on(struct peer_connection *connection) { struct frr_pthread *fpt = bgp_pth_io; assert(fpt->running); - assert(peer->status != Deleted); - assert(peer->ibuf); - assert(peer->fd); - assert(peer->ibuf_work); - assert(peer->obuf); - assert(!peer->t_connect_check_r); - assert(!peer->t_connect_check_w); - assert(peer->fd); + assert(connection->status != Deleted); + assert(connection->ibuf); + assert(connection->fd); + assert(connection->ibuf_work); + assert(connection->obuf); + assert(!connection->t_connect_check_r); + assert(!connection->t_connect_check_w); + assert(connection->fd); - event_add_read(fpt->master, bgp_process_reads, peer, peer->fd, - &peer->t_read); + event_add_read(fpt->master, bgp_process_reads, connection, + connection->fd, &connection->t_read); - SET_FLAG(peer->thread_flags, PEER_THREAD_READS_ON); + SET_FLAG(connection->thread_flags, PEER_THREAD_READS_ON); } -void bgp_reads_off(struct peer *peer) +void bgp_reads_off(struct peer_connection *connection) { struct frr_pthread *fpt = bgp_pth_io; assert(fpt->running); - event_cancel_async(fpt->master, &peer->t_read, NULL); - EVENT_OFF(peer->t_process_packet); - EVENT_OFF(peer->t_process_packet_error); + event_cancel_async(fpt->master, &connection->t_read, NULL); + EVENT_OFF(connection->t_process_packet); + EVENT_OFF(connection->t_process_packet_error); - UNSET_FLAG(peer->thread_flags, PEER_THREAD_READS_ON); + UNSET_FLAG(connection->thread_flags, PEER_THREAD_READS_ON); } /* Thread internal functions ----------------------------------------------- */ @@ -111,19 +113,21 @@ void bgp_reads_off(struct peer *peer) static void bgp_process_writes(struct event *thread) { static struct peer *peer; - peer = EVENT_ARG(thread); + struct peer_connection *connection = EVENT_ARG(thread); uint16_t status; bool reschedule; bool fatal = false; - if (peer->fd < 0) + peer = connection->peer; + + if (connection->fd < 0) return; struct frr_pthread *fpt = bgp_pth_io; - frr_with_mutex (&peer->io_mtx) { - status = bgp_write(peer); - reschedule = (stream_fifo_head(peer->obuf) != NULL); + frr_with_mutex (&connection->io_mtx) { + status = bgp_write(connection); + reschedule = (stream_fifo_head(connection->obuf) != NULL); } /* no problem */ @@ -142,26 +146,26 @@ static void bgp_process_writes(struct event *thread) * sent in the update message */ if (reschedule) { - event_add_write(fpt->master, bgp_process_writes, peer, peer->fd, - &peer->t_write); + event_add_write(fpt->master, bgp_process_writes, connection, + connection->fd, &connection->t_write); } else if (!fatal) { - BGP_UPDATE_GROUP_TIMER_ON(&peer->t_generate_updgrp_packets, + BGP_UPDATE_GROUP_TIMER_ON(&connection->t_generate_updgrp_packets, bgp_generate_updgrp_packets); } } -static int read_ibuf_work(struct peer *peer) +static int read_ibuf_work(struct peer_connection *connection) { /* static buffer for transferring packets */ /* shorter alias to peer's input buffer */ - struct ringbuf *ibw = peer->ibuf_work; + struct ringbuf *ibw = connection->ibuf_work; /* packet size as given by header */ uint16_t pktsize = 0; struct stream *pkt; /* ============================================== */ - frr_with_mutex (&peer->io_mtx) { - if (peer->ibuf->count >= bm->inq_limit) + frr_with_mutex (&connection->io_mtx) { + if (connection->ibuf->count >= bm->inq_limit) return -ENOMEM; } @@ -170,7 +174,7 @@ static int read_ibuf_work(struct peer *peer) return 0; /* check that header is valid */ - if (!validate_header(peer)) + if (!validate_header(connection)) return -EBADMSG; /* header is valid; retrieve packet size */ @@ -179,7 +183,7 @@ static int read_ibuf_work(struct peer *peer) pktsize = ntohs(pktsize); /* if this fails we are seriously screwed */ - assert(pktsize <= peer->max_packet_size); + assert(pktsize <= connection->peer->max_packet_size); /* * If we have that much data, chuck it into its own @@ -195,9 +199,9 @@ static int read_ibuf_work(struct peer *peer) assert(ringbuf_get(ibw, pkt->data, pktsize) == pktsize); stream_set_endp(pkt, pktsize); - frrtrace(2, frr_bgp, packet_read, peer, pkt); - frr_with_mutex (&peer->io_mtx) { - stream_fifo_push(peer->ibuf, pkt); + frrtrace(2, frr_bgp, packet_read, connection->peer, pkt); + frr_with_mutex (&connection->io_mtx) { + stream_fifo_push(connection->ibuf, pkt); } return pktsize; @@ -208,30 +212,31 @@ static int read_ibuf_work(struct peer *peer) * or has hung up. * * We read as much data as possible, process as many packets as we can and - * place them on peer->ibuf for secondary processing by the main thread. + * place them on peer->connection.ibuf for secondary processing by the main + * thread. */ static void bgp_process_reads(struct event *thread) { /* clang-format off */ + struct peer_connection *connection = EVENT_ARG(thread); static struct peer *peer; /* peer to read from */ uint16_t status; /* bgp_read status code */ bool fatal = false; /* whether fatal error occurred */ - bool added_pkt = false; /* whether we pushed onto ->ibuf */ + bool added_pkt = false; /* whether we pushed onto ->connection.ibuf */ int code = 0; /* FSM code if error occurred */ - bool ibuf_full = false; /* Is peer fifo IN Buffer full */ static bool ibuf_full_logged; /* Have we logged full already */ int ret = 1; /* clang-format on */ - peer = EVENT_ARG(thread); + peer = connection->peer; - if (peer->fd < 0 || bm->terminating) + if (bm->terminating || connection->fd < 0) return; struct frr_pthread *fpt = bgp_pth_io; - frr_with_mutex (&peer->io_mtx) { - status = bgp_read(peer, &code); + frr_with_mutex (&connection->io_mtx) { + status = bgp_read(connection, &code); } /* error checking phase */ @@ -247,13 +252,13 @@ static void bgp_process_reads(struct event *thread) /* Handle the error in the main pthread, include the * specific state change from 'bgp_read'. */ - event_add_event(bm->master, bgp_packet_process_error, peer, - code, &peer->t_process_packet_error); + event_add_event(bm->master, bgp_packet_process_error, connection, + code, &connection->t_process_packet_error); goto done; } while (true) { - ret = read_ibuf_work(peer); + ret = read_ibuf_work(connection); if (ret <= 0) break; @@ -265,7 +270,6 @@ static void bgp_process_reads(struct event *thread) fatal = true; break; case -ENOMEM: - ibuf_full = true; if (!ibuf_full_logged) { if (bgp_debug_neighbor_events(peer)) zlog_debug( @@ -284,35 +288,33 @@ static void bgp_process_reads(struct event *thread) /* handle invalid header */ if (fatal) { /* wipe buffer just in case someone screwed up */ - ringbuf_wipe(peer->ibuf_work); + ringbuf_wipe(connection->ibuf_work); return; } - /* ringbuf should be fully drained unless ibuf is full */ - if (!ibuf_full) - assert(ringbuf_space(peer->ibuf_work) >= peer->max_packet_size); - - event_add_read(fpt->master, bgp_process_reads, peer, peer->fd, - &peer->t_read); + event_add_read(fpt->master, bgp_process_reads, connection, + connection->fd, &connection->t_read); if (added_pkt) - event_add_event(bm->master, bgp_process_packet, peer, 0, - &peer->t_process_packet); + event_add_event(bm->master, bgp_process_packet, connection, 0, + &connection->t_process_packet); } /* * Flush peer output buffer. * - * This function pops packets off of peer->obuf and writes them to peer->fd. - * The amount of packets written is equal to the minimum of peer->wpkt_quanta - * and the number of packets on the output buffer, unless an error occurs. + * This function pops packets off of peer->connection.obuf and writes them to + * peer->connection.fd. The amount of packets written is equal to the minimum of + * peer->wpkt_quanta and the number of packets on the output buffer, unless an + * error occurs. * * If write() returns an error, the appropriate FSM event is generated. * * The return value is equal to the number of packets written * (which may be zero). */ -static uint16_t bgp_write(struct peer *peer) +static uint16_t bgp_write(struct peer_connection *connection) { + struct peer *peer = connection->peer; uint8_t type; struct stream *s; int update_last_write = 0; @@ -334,7 +336,7 @@ static uint16_t bgp_write(struct peer *peer) struct stream **streams = ostreams; struct iovec iov[wpkt_quanta_old]; - s = stream_fifo_head(peer->obuf); + s = stream_fifo_head(connection->obuf); if (!s) goto done; @@ -354,11 +356,11 @@ static uint16_t bgp_write(struct peer *peer) total_written = 0; do { - num = writev(peer->fd, iov, iovsz); + num = writev(connection->fd, iov, iovsz); if (num < 0) { if (!ERRNO_IO_RETRY(errno)) { - BGP_EVENT_ADD(peer, TCP_fatal_error); + BGP_EVENT_ADD(connection, TCP_fatal_error); SET_FLAG(status, BGP_IO_FATAL_ERR); } else { SET_FLAG(status, BGP_IO_TRANS_ERR); @@ -403,7 +405,7 @@ static uint16_t bgp_write(struct peer *peer) /* Handle statistics */ for (unsigned int i = 0; i < total_written; i++) { - s = stream_fifo_pop(peer->obuf); + s = stream_fifo_pop(connection->obuf); assert(s == ostreams[i]); @@ -435,7 +437,7 @@ static uint16_t bgp_write(struct peer *peer) * Handle Graceful Restart case where the state changes * to Connect instead of Idle. */ - BGP_EVENT_ADD(peer, BGP_Stop); + BGP_EVENT_ADD(connection, BGP_Stop); goto done; case BGP_MSG_KEEPALIVE: @@ -480,31 +482,37 @@ done : { return status; } +uint8_t ibuf_scratch[BGP_EXTENDED_MESSAGE_MAX_PACKET_SIZE * BGP_READ_PACKET_MAX]; /* - * Reads a chunk of data from peer->fd into peer->ibuf_work. + * Reads a chunk of data from peer->connection.fd into + * peer->connection.ibuf_work. * * code_p * Pointer to location to store FSM event code in case of fatal error. * * @return status flag (see top-of-file) + * + * PLEASE NOTE: If we ever transform the bgp_read to be a pthread + * per peer then we need to rethink the global ibuf_scratch + * data structure above. */ -static uint16_t bgp_read(struct peer *peer, int *code_p) +static uint16_t bgp_read(struct peer_connection *connection, int *code_p) { size_t readsize; /* how many bytes we want to read */ ssize_t nbytes; /* how many bytes we actually read */ size_t ibuf_work_space; /* space we can read into the work buf */ uint16_t status = 0; - ibuf_work_space = ringbuf_space(peer->ibuf_work); + ibuf_work_space = ringbuf_space(connection->ibuf_work); if (ibuf_work_space == 0) { SET_FLAG(status, BGP_IO_WORK_FULL_ERR); return status; } - readsize = MIN(ibuf_work_space, sizeof(peer->ibuf_scratch)); + readsize = MIN(ibuf_work_space, sizeof(ibuf_scratch)); - nbytes = read(peer->fd, peer->ibuf_scratch, readsize); + nbytes = read(connection->fd, ibuf_scratch, readsize); /* EAGAIN or EWOULDBLOCK; come back later */ if (nbytes < 0 && ERRNO_IO_RETRY(errno)) { @@ -512,8 +520,8 @@ static uint16_t bgp_read(struct peer *peer, int *code_p) } else if (nbytes < 0) { /* Fatal error; tear down session */ flog_err(EC_BGP_UPDATE_RCV, - "%s [Error] bgp_read_packet error: %s", peer->host, - safe_strerror(errno)); + "%s [Error] bgp_read_packet error: %s", + connection->peer->host, safe_strerror(errno)); /* Handle the error in the main pthread. */ if (code_p) @@ -523,9 +531,9 @@ static uint16_t bgp_read(struct peer *peer, int *code_p) } else if (nbytes == 0) { /* Received EOF / TCP session closed */ - if (bgp_debug_neighbor_events(peer)) + if (bgp_debug_neighbor_events(connection->peer)) zlog_debug("%s [Event] BGP connection closed fd %d", - peer->host, peer->fd); + connection->peer->host, connection->fd); /* Handle the error in the main pthread. */ if (code_p) @@ -533,8 +541,8 @@ static uint16_t bgp_read(struct peer *peer, int *code_p) SET_FLAG(status, BGP_IO_FATAL_ERR); } else { - assert(ringbuf_put(peer->ibuf_work, peer->ibuf_scratch, nbytes) - == (size_t)nbytes); + assert(ringbuf_put(connection->ibuf_work, ibuf_scratch, + nbytes) == (size_t)nbytes); } return status; @@ -547,11 +555,12 @@ static uint16_t bgp_read(struct peer *peer, int *code_p) * Assumes that there are at least BGP_HEADER_SIZE readable bytes in the input * buffer. */ -static bool validate_header(struct peer *peer) +static bool validate_header(struct peer_connection *connection) { + struct peer *peer = connection->peer; uint16_t size; uint8_t type; - struct ringbuf *pkt = peer->ibuf_work; + struct ringbuf *pkt = connection->ibuf_work; static const uint8_t m_correct[BGP_MARKER_SIZE] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, diff --git a/bgpd/bgp_io.h b/bgpd/bgp_io.h index 4c92373c2d..8d481129e5 100644 --- a/bgpd/bgp_io.h +++ b/bgpd/bgp_io.h @@ -14,6 +14,8 @@ #include "bgpd/bgpd.h" #include "frr_pthread.h" +struct peer_connection; + /** * Start function for write thread. * @@ -33,57 +35,57 @@ extern int bgp_io_stop(void **result, struct frr_pthread *fpt); /** * Turns on packet writing for a peer. * - * After this function is called, any packets placed on peer->obuf will be - * written to peer->fd until no more packets remain. + * After this function is called, any packets placed on connection->obuf will be + * written to connection->fd until no more packets remain. * - * Additionally, it becomes unsafe to perform socket actions on peer->fd. + * Additionally, it becomes unsafe to perform socket actions on connection->fd. * * @param peer - peer to register */ -extern void bgp_writes_on(struct peer *peer); +extern void bgp_writes_on(struct peer_connection *peer); /** * Turns off packet writing for a peer. * - * After this function returns, packets placed on peer->obuf will not be - * written to peer->fd by the I/O thread. + * After this function returns, packets placed on connection->obuf will not be + * written to connection->fd by the I/O thread. * * After this function returns it becomes safe to perform socket actions on - * peer->fd. + * connection->fd. * - * @param peer - peer to deregister + * @param connection - connection to deregister * @param flush - as described */ -extern void bgp_writes_off(struct peer *peer); +extern void bgp_writes_off(struct peer_connection *connection); /** * Turns on packet reading for a peer. * - * After this function is called, any packets received on peer->fd will be read - * and copied into the FIFO queue peer->ibuf. + * After this function is called, any packets received on connection->fd + * will be read and copied into the FIFO queue connection->ibuf. * - * Additionally, it becomes unsafe to perform socket actions on peer->fd. + * Additionally, it becomes unsafe to perform socket actions on connection->fd. * - * Whenever one or more packets are placed onto peer->ibuf, a task of type + * Whenever one or more packets are placed onto connection->ibuf, a task of type * THREAD_EVENT will be placed on the main thread whose handler is * * bgp_packet.c:bgp_process_packet() * - * @param peer - peer to register + * @param connection - The connection to register */ -extern void bgp_reads_on(struct peer *peer); +extern void bgp_reads_on(struct peer_connection *connection); /** * Turns off packet reading for a peer. * - * After this function is called, any packets received on peer->fd will not be - * read by the I/O thread. + * After this function is called, any packets received on connection->fd + * will not be read by the I/O thread. * * After this function returns it becomes safe to perform socket actions on - * peer->fd. + * connection->fd. * - * @param peer - peer to deregister + * @param connection - The connection to register for */ -extern void bgp_reads_off(struct peer *peer); +extern void bgp_reads_off(struct peer_connection *connection); #endif /* _FRR_BGP_IO_H */ diff --git a/bgpd/bgp_keepalives.c b/bgpd/bgp_keepalives.c index 48bde1220d..92123c2cd9 100644 --- a/bgpd/bgp_keepalives.c +++ b/bgpd/bgp_keepalives.c @@ -229,8 +229,10 @@ void *bgp_keepalives_start(void *arg) /* --- thread external functions ------------------------------------------- */ -void bgp_keepalives_on(struct peer *peer) +void bgp_keepalives_on(struct peer_connection *connection) { + struct peer *peer = connection->peer; + if (CHECK_FLAG(peer->thread_flags, PEER_THREAD_KEEPALIVES_ON)) return; @@ -258,8 +260,10 @@ void bgp_keepalives_on(struct peer *peer) } } -void bgp_keepalives_off(struct peer *peer) +void bgp_keepalives_off(struct peer_connection *connection) { + struct peer *peer = connection->peer; + if (!CHECK_FLAG(peer->thread_flags, PEER_THREAD_KEEPALIVES_ON)) return; diff --git a/bgpd/bgp_keepalives.h b/bgpd/bgp_keepalives.h index 2b4389cac3..33e574da13 100644 --- a/bgpd/bgp_keepalives.h +++ b/bgpd/bgp_keepalives.h @@ -27,7 +27,7 @@ * If the peer is already registered for keepalives via this function, nothing * happens. */ -extern void bgp_keepalives_on(struct peer *); +extern void bgp_keepalives_on(struct peer_connection *connection); /** * Turns off keepalives for a peer. @@ -36,7 +36,7 @@ extern void bgp_keepalives_on(struct peer *); * * If the peer is already unregistered for keepalives, nothing happens. */ -extern void bgp_keepalives_off(struct peer *); +extern void bgp_keepalives_off(struct peer_connection *connection); /** * Pre-run initialization function for keepalives pthread. diff --git a/bgpd/bgp_label.c b/bgpd/bgp_label.c index 0f3faeb297..7327ab5182 100644 --- a/bgpd/bgp_label.c +++ b/bgpd/bgp_label.c @@ -132,9 +132,8 @@ static void bgp_send_fec_register_label_msg(struct bgp_dest *dest, bool reg, return; if (BGP_DEBUG(labelpool, LABELPOOL)) - zlog_debug("%s: FEC %sregister %pRN label_index=%u label=%u", - __func__, reg ? "" : "un", bgp_dest_to_rnode(dest), - label_index, label); + zlog_debug("%s: FEC %sregister %pBD label_index=%u label=%u", + __func__, reg ? "" : "un", dest, label_index, label); /* If the route node has a local_label assigned or the * path node has an MPLS SR label index allowing zebra to * derive the label, proceed with registration. */ @@ -195,11 +194,12 @@ int bgp_reg_for_label_callback(mpls_label_t new_label, void *labelid, return -1; } - bgp_dest_unlock_node(dest); + dest = bgp_dest_unlock_node(dest); + assert(dest); if (BGP_DEBUG(labelpool, LABELPOOL)) - zlog_debug("%s: FEC %pRN label=%u, allocated=%d", __func__, - bgp_dest_to_rnode(dest), new_label, allocated); + zlog_debug("%s: FEC %pBD label=%u, allocated=%d", __func__, + dest, new_label, allocated); if (!allocated) { /* @@ -470,3 +470,20 @@ int bgp_nlri_parse_label(struct peer *peer, struct attr *attr, return BGP_NLRI_PARSE_OK; } + +bool bgp_labels_same(const mpls_label_t *tbl_a, const uint32_t num_labels_a, + const mpls_label_t *tbl_b, const uint32_t num_labels_b) +{ + uint32_t i; + + if (num_labels_a != num_labels_b) + return false; + if (num_labels_a == 0) + return true; + + for (i = 0; i < num_labels_a; i++) { + if (tbl_a[i] != tbl_b[i]) + return false; + } + return true; +} diff --git a/bgpd/bgp_label.h b/bgpd/bgp_label.h index ac7fbb27fb..b54403ee89 100644 --- a/bgpd/bgp_label.h +++ b/bgpd/bgp_label.h @@ -26,6 +26,10 @@ extern mpls_label_t bgp_adv_label(struct bgp_dest *dest, extern int bgp_nlri_parse_label(struct peer *peer, struct attr *attr, struct bgp_nlri *packet); +extern bool bgp_labels_same(const mpls_label_t *tbl_a, + const uint32_t num_labels_a, + const mpls_label_t *tbl_b, + const uint32_t num_labels_b); static inline int bgp_labeled_safi(safi_t safi) { diff --git a/bgpd/bgp_labelpool.c b/bgpd/bgp_labelpool.c index faddfc995f..23e0c191dc 100644 --- a/bgpd/bgp_labelpool.c +++ b/bgpd/bgp_labelpool.c @@ -15,7 +15,6 @@ #include "linklist.h" #include "skiplist.h" #include "workqueue.h" -#include "zclient.h" #include "mpls.h" #include "bgpd/bgpd.h" @@ -32,16 +31,13 @@ #include "bgpd/bgp_labelpool_clippy.c" -/* - * Definitions and external declarations. - */ -extern struct zclient *zclient; - #if BGP_LABELPOOL_ENABLE_TESTS static void lptest_init(void); static void lptest_finish(void); #endif +static void bgp_sync_label_manager(struct event *e); + /* * Remember where pool data are kept */ @@ -223,6 +219,8 @@ void bgp_lp_finish(void) { struct lp_fifo *lf; struct work_queue_item *item, *titem; + struct listnode *node; + struct lp_chunk *chunk; #if BGP_LABELPOOL_ENABLE_TESTS lptest_finish(); @@ -236,6 +234,9 @@ void bgp_lp_finish(void) skiplist_free(lp->inuse); lp->inuse = NULL; + for (ALL_LIST_ELEMENTS_RO(lp->chunks, node, chunk)) + bgp_zebra_release_label_range(chunk->first, chunk->last); + list_delete(&lp->chunks); while ((lf = lp_fifo_pop(&lp->requests))) { @@ -448,16 +449,17 @@ void bgp_lp_get( lp_fifo_add_tail(&lp->requests, lf); if (lp_fifo_count(&lp->requests) > lp->pending_count) { - if (!zclient || zclient->sock < 0) + if (!bgp_zebra_request_label_range(MPLS_LABEL_BASE_ANY, + lp->next_chunksize, true)) return; - if (zclient_send_get_label_chunk(zclient, 0, lp->next_chunksize, - MPLS_LABEL_BASE_ANY) != - ZCLIENT_SEND_FAILURE) { - lp->pending_count += lp->next_chunksize; - if ((lp->next_chunksize << 1) <= LP_CHUNK_SIZE_MAX) - lp->next_chunksize <<= 1; - } + + lp->pending_count += lp->next_chunksize; + if ((lp->next_chunksize << 1) <= LP_CHUNK_SIZE_MAX) + lp->next_chunksize <<= 1; } + + event_add_timer(bm->master, bgp_sync_label_manager, NULL, 1, + &bm->t_bgp_sync_label_manager); } void bgp_lp_release( @@ -497,53 +499,28 @@ void bgp_lp_release( bf_release_index(chunk->allocated_map, index); chunk->nfree += 1; deallocated = true; + break; } assert(deallocated); + if (deallocated && + chunk->nfree == chunk->last - chunk->first + 1 && + lp_fifo_count(&lp->requests) == 0) { + bgp_zebra_release_label_range(chunk->first, + chunk->last); + list_delete_node(lp->chunks, node); + lp_chunk_free(chunk); + lp->next_chunksize = LP_CHUNK_SIZE_MIN; + } } } } -/* - * zebra response giving us a chunk of labels - */ -void bgp_lp_event_chunk(uint8_t keep, uint32_t first, uint32_t last) +static void bgp_sync_label_manager(struct event *e) { - struct lp_chunk *chunk; int debug = BGP_DEBUG(labelpool, LABELPOOL); struct lp_fifo *lf; - uint32_t labelcount; - - if (last < first) { - flog_err(EC_BGP_LABEL, - "%s: zebra label chunk invalid: first=%u, last=%u", - __func__, first, last); - return; - } - - chunk = XCALLOC(MTYPE_BGP_LABEL_CHUNK, sizeof(struct lp_chunk)); - - labelcount = last - first + 1; - - chunk->first = first; - chunk->last = last; - chunk->nfree = labelcount; - bf_init(chunk->allocated_map, labelcount); - - /* - * Optimize for allocation by adding the new (presumably larger) - * chunk at the head of the list so it is examined first. - */ - listnode_add_head(lp->chunks, chunk); - - lp->pending_count -= labelcount; - - if (debug) { - zlog_debug("%s: %zu pending requests", __func__, - lp_fifo_count(&lp->requests)); - } - - while (labelcount && (lf = lp_fifo_first(&lp->requests))) { + while ((lf = lp_fifo_pop(&lp->requests))) { struct lp_lcb *lcb; void *labelid = lf->lcb.labelid; @@ -552,7 +529,7 @@ void bgp_lp_event_chunk(uint8_t keep, uint32_t first, uint32_t last) if (debug) { zlog_debug("%s: labelid %p: request no longer in effect", - __func__, labelid); + __func__, labelid); } /* if this was a BGP_LU request, unlock node */ @@ -565,8 +542,8 @@ void bgp_lp_event_chunk(uint8_t keep, uint32_t first, uint32_t last) /* request already has a label */ if (debug) { zlog_debug("%s: labelid %p: request already has a label: %u=0x%x, lcb=%p", - __func__, labelid, - lcb->label, lcb->label, lcb); + __func__, labelid, lcb->label, + lcb->label, lcb); } /* if this was a BGP_LU request, unlock node */ @@ -583,19 +560,21 @@ void bgp_lp_event_chunk(uint8_t keep, uint32_t first, uint32_t last) */ if (debug) { zlog_debug("%s: out of labels, await more", - __func__); + __func__); } + + lp_fifo_add_tail(&lp->requests, lf); + event_add_timer(bm->master, bgp_sync_label_manager, + NULL, 1, &bm->t_bgp_sync_label_manager); break; } - labelcount -= 1; - /* * we filled the request from local pool. * Enqueue response work item with new label. */ struct lp_cbq_item *q = XCALLOC(MTYPE_BGP_LABEL_CBQ, - sizeof(struct lp_cbq_item)); + sizeof(struct lp_cbq_item)); q->cbfunc = lcb->cbfunc; q->type = lcb->type; @@ -605,16 +584,45 @@ void bgp_lp_event_chunk(uint8_t keep, uint32_t first, uint32_t last) if (debug) zlog_debug("%s: assigning label %u to labelid %p", - __func__, q->label, q->labelid); + __func__, q->label, q->labelid); work_queue_add(lp->callback_q, q); finishedrequest: - lp_fifo_del(&lp->requests, lf); XFREE(MTYPE_BGP_LABEL_FIFO, lf); } } +void bgp_lp_event_chunk(uint32_t first, uint32_t last) +{ + struct lp_chunk *chunk; + uint32_t labelcount; + + if (last < first) { + flog_err(EC_BGP_LABEL, + "%s: zebra label chunk invalid: first=%u, last=%u", + __func__, first, last); + return; + } + + chunk = XCALLOC(MTYPE_BGP_LABEL_CHUNK, sizeof(struct lp_chunk)); + + labelcount = last - first + 1; + + chunk->first = first; + chunk->last = last; + chunk->nfree = labelcount; + bf_init(chunk->allocated_map, labelcount); + + /* + * Optimize for allocation by adding the new (presumably larger) + * chunk at the head of the list so it is examined first. + */ + listnode_add_head(lp->chunks, chunk); + + lp->pending_count -= labelcount; +} + /* * continue using allocated labels until zebra returns */ @@ -634,7 +642,6 @@ void bgp_lp_event_zebra_up(void) unsigned int chunks_needed; void *labelid; struct lp_lcb *lcb; - int lm_init_ok; lp->reconnect_count++; /* @@ -651,25 +658,19 @@ void bgp_lp_event_zebra_up(void) } /* round up */ - chunks_needed = (labels_needed / lp->next_chunksize) + 1; + chunks_needed = (labels_needed + lp->next_chunksize - 1) / lp->next_chunksize; labels_needed = chunks_needed * lp->next_chunksize; - lm_init_ok = lm_label_manager_connect(zclient, 1) == 0; - - if (!lm_init_ok) { - zlog_err("%s: label manager connection error", __func__); - return; - } - - zclient_send_get_label_chunk(zclient, 0, labels_needed, - MPLS_LABEL_BASE_ANY); - lp->pending_count = labels_needed; - /* * Invalidate current list of chunks */ list_delete_all_node(lp->chunks); + if (labels_needed && !bgp_zebra_request_label_range(MPLS_LABEL_BASE_ANY, + labels_needed, true)) + return; + lp->pending_count += labels_needed; + /* * Invalidate any existing labels and requeue them as requests */ @@ -712,6 +713,9 @@ void bgp_lp_event_zebra_up(void) skiplist_delete_first(lp->inuse); } + + event_add_timer(bm->master, bgp_sync_label_manager, NULL, 1, + &bm->t_bgp_sync_label_manager); } DEFUN(show_bgp_labelpool_summary, show_bgp_labelpool_summary_cmd, @@ -843,6 +847,16 @@ DEFUN(show_bgp_labelpool_ledger, show_bgp_labelpool_ledger_cmd, vty_out(vty, "%-18s %u\n", "nexthop", lcb->label); break; + case LP_TYPE_BGP_L3VPN_BIND: + if (uj) { + json_object_string_add(json_elem, "prefix", + "l3vpn-bind"); + json_object_int_add(json_elem, "label", + lcb->label); + } else + vty_out(vty, "%-18s %u\n", "l3vpn-bind", + lcb->label); + break; } } if (uj) @@ -941,6 +955,15 @@ DEFUN(show_bgp_labelpool_inuse, show_bgp_labelpool_inuse_cmd, vty_out(vty, "%-18s %u\n", "nexthop", label); break; + case LP_TYPE_BGP_L3VPN_BIND: + if (uj) { + json_object_string_add(json_elem, "prefix", + "l3vpn-bind"); + json_object_int_add(json_elem, "label", label); + } else + vty_out(vty, "%-18s %u\n", "l3vpn-bind", + label); + break; } } if (uj) @@ -1020,6 +1043,13 @@ DEFUN(show_bgp_labelpool_requests, show_bgp_labelpool_requests_cmd, else vty_out(vty, "Nexthop\n"); break; + case LP_TYPE_BGP_L3VPN_BIND: + if (uj) + json_object_string_add(json_elem, "prefix", + "l3vpn-bind"); + else + vty_out(vty, "L3VPN-BIND\n"); + break; } } if (uj) @@ -1117,11 +1147,12 @@ static void show_bgp_nexthop_label_afi(struct vty *vty, afi_t afi, ifindex2ifname(iter->nh->ifindex, iter->nh->vrf_id)); tbuf = time(NULL) - (monotime(NULL) - iter->last_update); - vty_out(vty, " Last update: %s", ctime(&tbuf)); + vty_out(vty, " Last update: %s", ctime_r(&tbuf, buf)); if (!detail) continue; vty_out(vty, " Paths:\n"); - LIST_FOREACH (path, &(iter->paths), label_nh_thread) { + LIST_FOREACH (path, &(iter->paths), + mplsvpn.blnc.label_nh_thread) { dest = path->net; table = bgp_dest_table(dest); assert(dest && table); @@ -1703,7 +1734,7 @@ void bgp_label_per_nexthop_free(struct bgp_label_per_nexthop_cache *blnc) bgp_zebra_send_nexthop_label(ZEBRA_MPLS_LABELS_DELETE, blnc->label, blnc->nh->ifindex, blnc->nh->vrf_id, ZEBRA_LSP_BGP, - &blnc->nexthop); + &blnc->nexthop, 0, NULL); bgp_lp_release(LP_TYPE_NEXTHOP, blnc, blnc->label); } bgp_label_per_nexthop_cache_del(blnc->tree, blnc); diff --git a/bgpd/bgp_labelpool.h b/bgpd/bgp_labelpool.h index b33527186e..a17482d112 100644 --- a/bgpd/bgp_labelpool.h +++ b/bgpd/bgp_labelpool.h @@ -18,6 +18,7 @@ #define LP_TYPE_VRF 0x00000001 #define LP_TYPE_BGP_LU 0x00000002 #define LP_TYPE_NEXTHOP 0x00000003 +#define LP_TYPE_BGP_L3VPN_BIND 0x00000004 PREDECL_LIST(lp_fifo); @@ -37,7 +38,7 @@ extern void bgp_lp_finish(void); extern void bgp_lp_get(int type, void *labelid, int (*cbfunc)(mpls_label_t label, void *labelid, bool allocated)); extern void bgp_lp_release(int type, void *labelid, mpls_label_t label); -extern void bgp_lp_event_chunk(uint8_t keep, uint32_t first, uint32_t last); +extern void bgp_lp_event_chunk(uint32_t first, uint32_t last); extern void bgp_lp_event_zebra_down(void); extern void bgp_lp_event_zebra_up(void); extern void bgp_lp_vty_init(void); diff --git a/bgpd/bgp_mac.c b/bgpd/bgp_mac.c index 6272bdb884..e629732c78 100644 --- a/bgpd/bgp_mac.c +++ b/bgpd/bgp_mac.c @@ -219,7 +219,7 @@ static void bgp_mac_rescan_evpn_table(struct bgp *bgp, struct ethaddr *macaddr) if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) continue; - if (!peer_established(peer)) + if (!peer_established(peer->connection)) continue; if (bgp_debug_update(peer, NULL, NULL, 1)) @@ -279,15 +279,29 @@ static void bgp_mac_remove_ifp_internal(struct bgp_self_mac *bsm, char *ifname, } } +/* Add/Update entry of the 'bgp mac hash' table. + * A rescan of the EVPN tables is only needed if + * a new hash bucket is allocated. + * Learning an existing mac on a new interface (or + * having an existing mac move from one interface to + * another) does not result in changes to self mac + * state, so we shouldn't trigger a rescan. + */ void bgp_mac_add_mac_entry(struct interface *ifp) { struct bgp_self_mac lookup; struct bgp_self_mac *bsm; struct bgp_self_mac *old_bsm; char *ifname; + bool mac_added = false; memcpy(&lookup.macaddr, &ifp->hw_addr, ETH_ALEN); - bsm = hash_get(bm->self_mac_hash, &lookup, bgp_mac_hash_alloc); + bsm = hash_lookup(bm->self_mac_hash, &lookup); + if (!bsm) { + bsm = hash_get(bm->self_mac_hash, &lookup, bgp_mac_hash_alloc); + /* mac is new, rescan needs to be triggered */ + mac_added = true; + } /* * Does this happen to be a move @@ -318,7 +332,8 @@ void bgp_mac_add_mac_entry(struct interface *ifp) listnode_add(bsm->ifp_list, ifname); } - bgp_mac_rescan_all_evpn_tables(&bsm->macaddr); + if (mac_added) + bgp_mac_rescan_all_evpn_tables(&bsm->macaddr); } void bgp_mac_del_mac_entry(struct interface *ifp) diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c index 074059c146..e8d5a0307a 100644 --- a/bgpd/bgp_main.c +++ b/bgpd/bgp_main.c @@ -47,7 +47,7 @@ #include "bgpd/bgp_errors.h" #include "bgpd/bgp_script.h" #include "bgpd/bgp_evpn_mh.h" -#include "bgpd/bgp_nht.h" +#include "bgpd/bgp_nhg.h" #include "bgpd/bgp_routemap_nb.h" #include "bgpd/bgp_community_alias.h" @@ -57,15 +57,17 @@ /* bgpd options, we use GNU getopt library. */ static const struct option longopts[] = { - {"bgp_port", required_argument, NULL, 'p'}, - {"listenon", required_argument, NULL, 'l'}, - {"no_kernel", no_argument, NULL, 'n'}, - {"skip_runas", no_argument, NULL, 'S'}, - {"ecmp", required_argument, NULL, 'e'}, - {"int_num", required_argument, NULL, 'I'}, - {"no_zebra", no_argument, NULL, 'Z'}, - {"socket_size", required_argument, NULL, 's'}, - {0}}; + { "bgp_port", required_argument, NULL, 'p' }, + { "listenon", required_argument, NULL, 'l' }, + { "no_kernel", no_argument, NULL, 'n' }, + { "skip_runas", no_argument, NULL, 'S' }, + { "ecmp", required_argument, NULL, 'e' }, + { "int_num", required_argument, NULL, 'I' }, + { "no_zebra", no_argument, NULL, 'Z' }, + { "socket_size", required_argument, NULL, 's' }, + { "v6-with-v4-nexthops", no_argument, NULL, 'v' }, + { 0 } +}; /* signal definitions */ void sighup(void); @@ -197,7 +199,7 @@ static __attribute__((__noreturn__)) void bgp_exit(int status) bgp_delete(bgp_default); bgp_evpn_mh_finish(); - bgp_l3nhg_finish(); + bgp_nhg_finish(); /* reverse bgp_dump_init */ bgp_dump_finish(); @@ -387,16 +389,16 @@ int main(int argc, char **argv) addresses->cmp = (int (*)(void *, void *))strcmp; frr_preinit(&bgpd_di, argc, argv); - frr_opt_add( - "p:l:SnZe:I:s:" DEPRECATED_OPTIONS, longopts, - " -p, --bgp_port Set BGP listen port number (0 means do not listen).\n" - " -l, --listenon Listen on specified address (implies -n)\n" - " -n, --no_kernel Do not install route to kernel.\n" - " -Z, --no_zebra Do not communicate with Zebra.\n" - " -S, --skip_runas Skip capabilities checks, and changing user and group IDs.\n" - " -e, --ecmp Specify ECMP to use.\n" - " -I, --int_num Set instance number (label-manager)\n" - " -s, --socket_size Set BGP peer socket send buffer size\n"); + frr_opt_add("p:l:SnZe:I:s:" DEPRECATED_OPTIONS, longopts, + " -p, --bgp_port Set BGP listen port number (0 means do not listen).\n" + " -l, --listenon Listen on specified address (implies -n)\n" + " -n, --no_kernel Do not install route to kernel.\n" + " -Z, --no_zebra Do not communicate with Zebra.\n" + " -S, --skip_runas Skip capabilities checks, and changing user and group IDs.\n" + " -e, --ecmp Specify ECMP to use.\n" + " -I, --int_num Set instance number (label-manager)\n" + " -s, --socket_size Set BGP peer socket send buffer size\n" + " , --v6-with-v4-nexthop Allow BGP to form v6 neighbors using v4 nexthops\n"); /* Command line argument treatment. */ while (1) { @@ -458,6 +460,9 @@ int main(int argc, char **argv) case 's': buffer_size = atoi(optarg); break; + case 'v': + bm->v6_with_v4_nexthops = true; + break; default: frr_help_exit(1); } diff --git a/bgpd/bgp_memory.c b/bgpd/bgp_memory.c index d7b18de676..38aa4f1c38 100644 --- a/bgpd/bgp_memory.c +++ b/bgpd/bgp_memory.c @@ -15,8 +15,10 @@ DEFINE_MGROUP(BGPD, "bgpd"); DEFINE_MTYPE(BGPD, BGP, "BGP instance"); +DEFINE_MTYPE(BGPD, BGP_NAME, "BGP Name data"); DEFINE_MTYPE(BGPD, BGP_LISTENER, "BGP listen socket details"); DEFINE_MTYPE(BGPD, BGP_PEER, "BGP peer"); +DEFINE_MTYPE(BGPD, BGP_PEER_CONNECTION, "BGP peer connection"); DEFINE_MTYPE(BGPD, BGP_PEER_HOST, "BGP peer hostname"); DEFINE_MTYPE(BGPD, BGP_PEER_IFNAME, "BGP peer ifname"); DEFINE_MTYPE(BGPD, PEER_GROUP, "Peer group"); @@ -37,6 +39,9 @@ DEFINE_MTYPE(BGPD, BGP_TABLE, "BGP table"); DEFINE_MTYPE(BGPD, BGP_NODE, "BGP node"); DEFINE_MTYPE(BGPD, BGP_ROUTE, "BGP route"); DEFINE_MTYPE(BGPD, BGP_ROUTE_EXTRA, "BGP ancillary route info"); +DEFINE_MTYPE(BGPD, BGP_ROUTE_EXTRA_EVPN, "BGP extra info for EVPN"); +DEFINE_MTYPE(BGPD, BGP_ROUTE_EXTRA_FS, "BGP extra info for flowspec"); +DEFINE_MTYPE(BGPD, BGP_ROUTE_EXTRA_VRFLEAK, "BGP extra info for vrf leaking"); DEFINE_MTYPE(BGPD, BGP_CONN, "BGP connected"); DEFINE_MTYPE(BGPD, BGP_STATIC, "BGP static"); DEFINE_MTYPE(BGPD, BGP_ADVERTISE_ATTR, "BGP adv attr"); diff --git a/bgpd/bgp_memory.h b/bgpd/bgp_memory.h index 7b00497714..8c9524e2ad 100644 --- a/bgpd/bgp_memory.h +++ b/bgpd/bgp_memory.h @@ -11,8 +11,10 @@ DECLARE_MGROUP(BGPD); DECLARE_MTYPE(BGP); +DECLARE_MTYPE(BGP_NAME); DECLARE_MTYPE(BGP_LISTENER); DECLARE_MTYPE(BGP_PEER); +DECLARE_MTYPE(BGP_PEER_CONNECTION); DECLARE_MTYPE(BGP_PEER_HOST); DECLARE_MTYPE(BGP_PEER_IFNAME); DECLARE_MTYPE(PEER_GROUP); @@ -33,6 +35,9 @@ DECLARE_MTYPE(BGP_TABLE); DECLARE_MTYPE(BGP_NODE); DECLARE_MTYPE(BGP_ROUTE); DECLARE_MTYPE(BGP_ROUTE_EXTRA); +DECLARE_MTYPE(BGP_ROUTE_EXTRA_EVPN); +DECLARE_MTYPE(BGP_ROUTE_EXTRA_FS); +DECLARE_MTYPE(BGP_ROUTE_EXTRA_VRFLEAK); DECLARE_MTYPE(BGP_CONN); DECLARE_MTYPE(BGP_STATIC); DECLARE_MTYPE(BGP_ADVERTISE_ATTR); diff --git a/bgpd/bgp_mpath.c b/bgpd/bgp_mpath.c index e920d5753e..c773c21fb7 100644 --- a/bgpd/bgp_mpath.c +++ b/bgpd/bgp_mpath.c @@ -173,10 +173,11 @@ int bgp_path_info_nexthop_cmp(struct bgp_path_info *bpi1, * if they belong to same VRF */ if (!compare && bpi1->attr->nh_type != NEXTHOP_TYPE_BLACKHOLE) { - if (bpi1->extra && bpi1->extra->bgp_orig && bpi2->extra - && bpi2->extra->bgp_orig) { - if (bpi1->extra->bgp_orig->vrf_id - != bpi2->extra->bgp_orig->vrf_id) { + if (bpi1->extra && bpi1->extra->vrfleak && + bpi1->extra->vrfleak->bgp_orig && bpi2->extra && + bpi2->extra->vrfleak && bpi2->extra->vrfleak->bgp_orig) { + if (bpi1->extra->vrfleak->bgp_orig->vrf_id != + bpi2->extra->vrfleak->bgp_orig->vrf_id) { compare = 1; } } @@ -553,12 +554,11 @@ void bgp_path_info_mpath_update(struct bgp *bgp, struct bgp_dest *dest, } if (debug) - zlog_debug( - "%pRN(%s): starting mpath update, newbest %s num candidates %d old-mpath-count %d old-cum-bw %" PRIu64, - bgp_dest_to_rnode(dest), bgp->name_pretty, - new_best ? new_best->peer->host : "NONE", - mp_list ? listcount(mp_list) : 0, old_mpath_count, - old_cum_bw); + zlog_debug("%pBD(%s): starting mpath update, newbest %s num candidates %d old-mpath-count %d old-cum-bw %" PRIu64, + dest, bgp->name_pretty, + new_best ? new_best->peer->host : "NONE", + mp_list ? listcount(mp_list) : 0, old_mpath_count, + old_cum_bw); /* * We perform an ordered walk through both lists in parallel. @@ -589,11 +589,10 @@ void bgp_path_info_mpath_update(struct bgp *bgp, struct bgp_dest *dest, tmp_info = mp_node ? listgetdata(mp_node) : NULL; if (debug) - zlog_debug( - "%pRN(%s): comparing candidate %s with existing mpath %s", - bgp_dest_to_rnode(dest), bgp->name_pretty, - tmp_info ? tmp_info->peer->host : "NONE", - cur_mpath ? cur_mpath->peer->host : "NONE"); + zlog_debug("%pBD(%s): comparing candidate %s with existing mpath %s", + dest, bgp->name_pretty, + tmp_info ? tmp_info->peer->host : "NONE", + cur_mpath ? cur_mpath->peer->host : "NONE"); /* * If equal, the path was a multipath and is still a multipath. @@ -621,10 +620,8 @@ void bgp_path_info_mpath_update(struct bgp *bgp, struct bgp_dest *dest, bgp_path_info_path_with_addpath_rx_str( cur_mpath, path_buf, sizeof(path_buf)); - zlog_debug( - "%pRN: %s is still multipath, cur count %d", - bgp_dest_to_rnode(dest), - path_buf, mpath_count); + zlog_debug("%pBD: %s is still multipath, cur count %d", + dest, path_buf, mpath_count); } } else { mpath_changed = 1; @@ -632,12 +629,10 @@ void bgp_path_info_mpath_update(struct bgp *bgp, struct bgp_dest *dest, bgp_path_info_path_with_addpath_rx_str( cur_mpath, path_buf, sizeof(path_buf)); - zlog_debug( - "%pRN: remove mpath %s nexthop %pI4, cur count %d", - bgp_dest_to_rnode(dest), - path_buf, - &cur_mpath->attr->nexthop, - mpath_count); + zlog_debug("%pBD: remove mpath %s nexthop %pI4, cur count %d", + dest, path_buf, + &cur_mpath->attr->nexthop, + mpath_count); } } mp_node = mp_next_node; @@ -662,10 +657,10 @@ void bgp_path_info_mpath_update(struct bgp *bgp, struct bgp_dest *dest, if (debug) { bgp_path_info_path_with_addpath_rx_str( cur_mpath, path_buf, sizeof(path_buf)); - zlog_debug( - "%pRN: remove mpath %s nexthop %pI4, cur count %d", - bgp_dest_to_rnode(dest), path_buf, - &cur_mpath->attr->nexthop, mpath_count); + zlog_debug("%pBD: remove mpath %s nexthop %pI4, cur count %d", + dest, path_buf, + &cur_mpath->attr->nexthop, + mpath_count); } cur_mpath = next_mpath; } else { @@ -712,12 +707,10 @@ void bgp_path_info_mpath_update(struct bgp *bgp, struct bgp_dest *dest, bgp_path_info_path_with_addpath_rx_str( new_mpath, path_buf, sizeof(path_buf)); - zlog_debug( - "%pRN: add mpath %s nexthop %pI4, cur count %d", - bgp_dest_to_rnode(dest), - path_buf, - &new_mpath->attr->nexthop, - mpath_count); + zlog_debug("%pBD: add mpath %s nexthop %pI4, cur count %d", + dest, path_buf, + &new_mpath->attr->nexthop, + mpath_count); } } mp_node = mp_next_node; @@ -736,11 +729,10 @@ void bgp_path_info_mpath_update(struct bgp *bgp, struct bgp_dest *dest, all_paths_lb, cum_bw); if (debug) - zlog_debug( - "%pRN(%s): New mpath count (incl newbest) %d mpath-change %s all_paths_lb %d cum_bw %" PRIu64, - bgp_dest_to_rnode(dest), bgp->name_pretty, - mpath_count, mpath_changed ? "YES" : "NO", - all_paths_lb, cum_bw); + zlog_debug("%pBD(%s): New mpath count (incl newbest) %d mpath-change %s all_paths_lb %d cum_bw %" PRIu64, + dest, bgp->name_pretty, mpath_count, + mpath_changed ? "YES" : "NO", all_paths_lb, + cum_bw); if (mpath_changed || (bgp_path_info_mpath_count(new_best) != old_mpath_count)) diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index ecc84533b0..cf57d95eb0 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -39,6 +39,9 @@ #include "bgpd/rfapi/rfapi_backend.h" #endif +DEFINE_MTYPE_STATIC(BGPD, MPLSVPN_NH_LABEL_BIND_CACHE, + "BGP MPLSVPN nexthop label bind cache"); + /* * Definitions and external declarations. */ @@ -297,7 +300,7 @@ void vpn_leak_zebra_vrf_label_update(struct bgp *bgp, afi_t afi) return; } - if (vpn_leak_to_vpn_active(bgp, afi, NULL)) { + if (vpn_leak_to_vpn_active(bgp, afi, NULL, false)) { label = bgp->vpn_policy[afi].tovpn_label; } @@ -593,7 +596,12 @@ static void sid_register(struct bgp *bgp, const struct in6_addr *sid, listnode_add(bgp->srv6_functions, func); } -static void sid_unregister(struct bgp *bgp, const struct in6_addr *sid) +void srv6_function_free(struct bgp_srv6_function *func) +{ + XFREE(MTYPE_BGP_SRV6_FUNCTION, func); +} + +void sid_unregister(struct bgp *bgp, const struct in6_addr *sid) { struct listnode *node, *nnode; struct bgp_srv6_function *func; @@ -601,7 +609,7 @@ static void sid_unregister(struct bgp *bgp, const struct in6_addr *sid) for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) if (sid_same(&func->sid, sid)) { listnode_delete(bgp->srv6_functions, func); - XFREE(MTYPE_BGP_SRV6_FUNCTION, func); + srv6_function_free(func); } } @@ -952,8 +960,6 @@ void transpose_sid(struct in6_addr *sid, uint32_t label, uint8_t offset, static bool labels_same(struct bgp_path_info *bpi, mpls_label_t *label, uint32_t n) { - uint32_t i; - if (!bpi->extra) { if (!n) return true; @@ -961,14 +967,9 @@ static bool labels_same(struct bgp_path_info *bpi, mpls_label_t *label, return false; } - if (n != bpi->extra->num_labels) - return false; - - for (i = 0; i < n; ++i) { - if (label[i] != bpi->extra->label[i]) - return false; - } - return true; + return bgp_labels_same((const mpls_label_t *)bpi->extra->label, + bpi->extra->num_labels, + (const mpls_label_t *)label, n); } /* @@ -1000,41 +1001,6 @@ static void setlabels(struct bgp_path_info *bpi, extra->num_labels = num_labels; } -/* - * make encoded route SIDs match specified encoded sid set - */ -static void setsids(struct bgp_path_info *bpi, - struct in6_addr *sid, - uint32_t num_sids) -{ - uint32_t i; - struct bgp_path_info_extra *extra; - - if (num_sids) - assert(sid); - assert(num_sids <= BGP_MAX_SIDS); - - if (!num_sids) { - if (bpi->extra) - bpi->extra->num_sids = 0; - return; - } - - extra = bgp_path_info_extra_get(bpi); - for (i = 0; i < num_sids; i++) - memcpy(&extra->sid[i].sid, &sid[i], sizeof(struct in6_addr)); - extra->num_sids = num_sids; -} - -static void unsetsids(struct bgp_path_info *bpi) -{ - struct bgp_path_info_extra *extra; - - extra = bgp_path_info_extra_get(bpi); - extra->num_sids = 0; - memset(extra->sid, 0, sizeof(extra->sid)); -} - static bool leak_update_nexthop_valid(struct bgp *to_bgp, struct bgp_dest *bn, struct attr *new_attr, afi_t afi, safi_t safi, @@ -1049,8 +1015,8 @@ static bool leak_update_nexthop_valid(struct bgp *to_bgp, struct bgp_dest *bn, bpi_ultimate = bgp_get_imported_bpi_ultimate(source_bpi); - if (bpi->extra && bpi->extra->bgp_orig) - bgp_nexthop = bpi->extra->bgp_orig; + if (bpi->extra && bpi->extra->vrfleak && bpi->extra->vrfleak->bgp_orig) + bgp_nexthop = bpi->extra->vrfleak->bgp_orig; else bgp_nexthop = bgp_orig; @@ -1102,12 +1068,8 @@ leak_update(struct bgp *to_bgp, struct bgp_dest *bn, struct bgp_path_info *bpi; struct bgp_path_info *new; struct bgp_path_info_extra *extra; - uint32_t num_sids = 0; struct bgp_path_info *parent = source_bpi; - if (new_attr->srv6_l3vpn || new_attr->srv6_vpn) - num_sids = 1; - if (debug) zlog_debug( "%s: entry: leak-to=%s, p=%pBD, type=%d, sub_type=%d", @@ -1136,7 +1098,8 @@ leak_update(struct bgp *to_bgp, struct bgp_dest *bn, * match parent */ for (bpi = bgp_dest_get_bgp_path_info(bn); bpi; bpi = bpi->next) { - if (bpi->extra && bpi->extra->parent == parent) + if (bpi->extra && bpi->extra->vrfleak && + bpi->extra->vrfleak->parent == parent) break; } @@ -1204,34 +1167,6 @@ leak_update(struct bgp *to_bgp, struct bgp_dest *bn, if (!labelssame) setlabels(bpi, label, num_labels); - /* - * rewrite sid - */ - if (num_sids) { - if (new_attr->srv6_l3vpn) { - setsids(bpi, &new_attr->srv6_l3vpn->sid, - num_sids); - - extra = bgp_path_info_extra_get(bpi); - - extra->sid[0].loc_block_len = - new_attr->srv6_l3vpn->loc_block_len; - extra->sid[0].loc_node_len = - new_attr->srv6_l3vpn->loc_node_len; - extra->sid[0].func_len = - new_attr->srv6_l3vpn->func_len; - extra->sid[0].arg_len = - new_attr->srv6_l3vpn->arg_len; - extra->sid[0].transposition_len = - new_attr->srv6_l3vpn->transposition_len; - extra->sid[0].transposition_offset = - new_attr->srv6_l3vpn - ->transposition_offset; - } else if (new_attr->srv6_vpn) - setsids(bpi, &new_attr->srv6_vpn->sid, - num_sids); - } else - unsetsids(bpi); if (nexthop_self_flag) bgp_path_info_set_flag(bn, bpi, BGP_PATH_ANNC_NH_SELF); @@ -1249,12 +1184,13 @@ leak_update(struct bgp *to_bgp, struct bgp_dest *bn, /* Process change. */ bgp_aggregate_increment(to_bgp, p, bpi, afi, safi); bgp_process(to_bgp, bn, afi, safi); - bgp_dest_unlock_node(bn); if (debug) zlog_debug("%s: ->%s: %pBD Found route, changed attr", __func__, to_bgp->name_pretty, bn); + bgp_dest_unlock_node(bn); + return bpi; } @@ -1271,9 +1207,15 @@ leak_update(struct bgp *to_bgp, struct bgp_dest *bn, new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_IMPORTED, 0, to_bgp->peer_self, new_attr, bn); + bgp_path_info_extra_get(new); + if (!new->extra->vrfleak) + new->extra->vrfleak = + XCALLOC(MTYPE_BGP_ROUTE_EXTRA_VRFLEAK, + sizeof(struct bgp_path_info_extra_vrfleak)); + if (source_bpi->peer) { extra = bgp_path_info_extra_get(new); - extra->peer_orig = peer_lock(source_bpi->peer); + extra->vrfleak->peer_orig = peer_lock(source_bpi->peer); } if (nexthop_self_flag) @@ -1282,42 +1224,17 @@ leak_update(struct bgp *to_bgp, struct bgp_dest *bn, if (CHECK_FLAG(source_bpi->flags, BGP_PATH_ACCEPT_OWN)) bgp_path_info_set_flag(bn, new, BGP_PATH_ACCEPT_OWN); - bgp_path_info_extra_get(new); - - /* - * rewrite sid - */ - if (num_sids) { - if (new_attr->srv6_l3vpn) { - setsids(new, &new_attr->srv6_l3vpn->sid, num_sids); - - extra = bgp_path_info_extra_get(new); - - extra->sid[0].loc_block_len = - new_attr->srv6_l3vpn->loc_block_len; - extra->sid[0].loc_node_len = - new_attr->srv6_l3vpn->loc_node_len; - extra->sid[0].func_len = new_attr->srv6_l3vpn->func_len; - extra->sid[0].arg_len = new_attr->srv6_l3vpn->arg_len; - extra->sid[0].transposition_len = - new_attr->srv6_l3vpn->transposition_len; - extra->sid[0].transposition_offset = - new_attr->srv6_l3vpn->transposition_offset; - } else if (new_attr->srv6_vpn) - setsids(new, &new_attr->srv6_vpn->sid, num_sids); - } else - unsetsids(new); - if (num_labels) setlabels(new, label, num_labels); - new->extra->parent = bgp_path_info_lock(parent); + new->extra->vrfleak->parent = bgp_path_info_lock(parent); bgp_dest_lock_node( (struct bgp_dest *)parent->net); - if (bgp_orig) - new->extra->bgp_orig = bgp_lock(bgp_orig); + + new->extra->vrfleak->bgp_orig = bgp_lock(bgp_orig); + if (nexthop_orig) - new->extra->nexthop_orig = *nexthop_orig; + new->extra->vrfleak->nexthop_orig = *nexthop_orig; if (leak_update_nexthop_valid(to_bgp, bn, new_attr, afi, safi, source_bpi, new, bgp_orig, p, debug)) @@ -1328,13 +1245,14 @@ leak_update(struct bgp *to_bgp, struct bgp_dest *bn, bgp_aggregate_increment(to_bgp, p, new, afi, safi); bgp_path_info_add(bn, new); - bgp_dest_unlock_node(bn); bgp_process(to_bgp, bn, afi, safi); if (debug) zlog_debug("%s: ->%s: %pBD: Added new route", __func__, to_bgp->name_pretty, bn); + bgp_dest_unlock_node(bn); + return new; } @@ -1345,14 +1263,18 @@ void bgp_mplsvpn_path_nh_label_unlink(struct bgp_path_info *pi) if (!pi) return; - blnc = pi->label_nexthop_cache; + if (!CHECK_FLAG(pi->flags, BGP_PATH_MPLSVPN_LABEL_NH)) + return; + + blnc = pi->mplsvpn.blnc.label_nexthop_cache; if (!blnc) return; - LIST_REMOVE(pi, label_nh_thread); - pi->label_nexthop_cache->path_count--; - pi->label_nexthop_cache = NULL; + LIST_REMOVE(pi, mplsvpn.blnc.label_nh_thread); + pi->mplsvpn.blnc.label_nexthop_cache->path_count--; + pi->mplsvpn.blnc.label_nexthop_cache = NULL; + UNSET_FLAG(pi->flags, BGP_PATH_MPLSVPN_LABEL_NH); if (LIST_EMPTY(&(blnc->paths))) bgp_label_per_nexthop_free(blnc); @@ -1390,11 +1312,12 @@ static int bgp_mplsvpn_get_label_per_nexthop_cb(mpls_label_t label, /* update paths */ if (blnc->label != MPLS_INVALID_LABEL) - bgp_zebra_send_nexthop_label( - ZEBRA_MPLS_LABELS_ADD, blnc->label, blnc->nh->ifindex, - blnc->nh->vrf_id, ZEBRA_LSP_BGP, &blnc->nexthop); + bgp_zebra_send_nexthop_label(ZEBRA_MPLS_LABELS_ADD, blnc->label, + blnc->nh->ifindex, + blnc->nh->vrf_id, ZEBRA_LSP_BGP, + &blnc->nexthop, 0, NULL); - LIST_FOREACH (pi, &(blnc->paths), label_nh_thread) { + LIST_FOREACH (pi, &(blnc->paths), mplsvpn.blnc.label_nh_thread) { if (!pi->net) continue; table = bgp_dest_table(pi->net); @@ -1411,9 +1334,10 @@ static int bgp_mplsvpn_get_label_per_nexthop_cb(mpls_label_t label, * - else allocate a new per label nexthop cache entry and request a * label to zebra. Return MPLS_INVALID_LABEL */ -static mpls_label_t _vpn_leak_from_vrf_get_per_nexthop_label( - struct bgp_path_info *pi, struct bgp *to_bgp, struct bgp *from_bgp, - afi_t afi, safi_t safi) +static mpls_label_t +_vpn_leak_from_vrf_get_per_nexthop_label(struct bgp_path_info *pi, + struct bgp *to_bgp, + struct bgp *from_bgp, afi_t afi) { struct bgp_nexthop_cache *bnc = pi->nexthop; struct bgp_label_per_nexthop_cache *blnc; @@ -1460,20 +1384,20 @@ static mpls_label_t _vpn_leak_from_vrf_get_per_nexthop_label( bgp_mplsvpn_get_label_per_nexthop_cb); } - if (pi->label_nexthop_cache == blnc) + if (pi->mplsvpn.blnc.label_nexthop_cache == blnc) /* no change */ return blnc->label; /* Unlink from any existing nexthop cache. Free the entry if unused. */ bgp_mplsvpn_path_nh_label_unlink(pi); - if (blnc) { - /* updates NHT pi list reference */ - LIST_INSERT_HEAD(&(blnc->paths), pi, label_nh_thread); - pi->label_nexthop_cache = blnc; - pi->label_nexthop_cache->path_count++; - blnc->last_update = monotime(NULL); - } + + /* updates NHT pi list reference */ + LIST_INSERT_HEAD(&(blnc->paths), pi, mplsvpn.blnc.label_nh_thread); + pi->mplsvpn.blnc.label_nexthop_cache = blnc; + pi->mplsvpn.blnc.label_nexthop_cache->path_count++; + SET_FLAG(pi->flags, BGP_PATH_MPLSVPN_LABEL_NH); + blnc->last_update = monotime(NULL); /* then add or update the selected nexthop */ if (!blnc->nh) @@ -1485,7 +1409,7 @@ static mpls_label_t _vpn_leak_from_vrf_get_per_nexthop_label( bgp_zebra_send_nexthop_label( ZEBRA_MPLS_LABELS_REPLACE, blnc->label, bnc->nexthop->ifindex, bnc->nexthop->vrf_id, - ZEBRA_LSP_BGP, &blnc->nexthop); + ZEBRA_LSP_BGP, &blnc->nexthop, 0, NULL); } } @@ -1497,9 +1421,10 @@ static mpls_label_t _vpn_leak_from_vrf_get_per_nexthop_label( * - return the per VRF label when the per nexthop label is not supported * Otherwise, find or request a per label nexthop. */ -static mpls_label_t vpn_leak_from_vrf_get_per_nexthop_label( - afi_t afi, safi_t safi, struct bgp_path_info *pi, struct bgp *from_bgp, - struct bgp *to_bgp) +static mpls_label_t +vpn_leak_from_vrf_get_per_nexthop_label(afi_t afi, struct bgp_path_info *pi, + struct bgp *from_bgp, + struct bgp *to_bgp) { struct bgp_path_info *bpi_ultimate = bgp_get_imported_bpi_ultimate(pi); struct bgp *bgp_nexthop = NULL; @@ -1551,14 +1476,14 @@ static mpls_label_t vpn_leak_from_vrf_get_per_nexthop_label( /* Check the next-hop reachability. * Get the bgp instance where the bgp_path_info originates. */ - if (pi->extra && pi->extra->bgp_orig) - bgp_nexthop = pi->extra->bgp_orig; + if (pi->extra && pi->extra->vrfleak && pi->extra->vrfleak->bgp_orig) + bgp_nexthop = pi->extra->vrfleak->bgp_orig; else bgp_nexthop = from_bgp; nh_afi = BGP_ATTR_NH_AFI(afi, pi->attr); - nh_valid = bgp_find_or_add_nexthop(from_bgp, bgp_nexthop, nh_afi, safi, - pi, NULL, 0, NULL); + nh_valid = bgp_find_or_add_nexthop(from_bgp, bgp_nexthop, nh_afi, + SAFI_UNICAST, pi, NULL, 0, NULL); if (!nh_valid && is_bgp_static_route && !CHECK_FLAG(from_bgp->flags, BGP_FLAG_IMPORT_CHECK)) { @@ -1594,7 +1519,7 @@ static mpls_label_t vpn_leak_from_vrf_get_per_nexthop_label( } return _vpn_leak_from_vrf_get_per_nexthop_label(pi, to_bgp, from_bgp, - afi, safi); + afi); } /* cf vnc_import_bgp_add_route_mode_nvegroup() and add_vnc_route() */ @@ -1613,6 +1538,9 @@ void vpn_leak_from_vrf_update(struct bgp *to_bgp, /* to */ struct bgp_dest *bn; const char *debugmsg; int nexthop_self_flag = 0; + struct ecommunity *old_ecom; + struct ecommunity *new_ecom = NULL; + struct ecommunity *rtlist_ecom; if (debug) zlog_debug("%s: from vrf %s", __func__, from_bgp->name_pretty); @@ -1640,7 +1568,7 @@ void vpn_leak_from_vrf_update(struct bgp *to_bgp, /* to */ if (!is_route_injectable_into_vpn(path_vrf)) return; - if (!vpn_leak_to_vpn_active(from_bgp, afi, &debugmsg)) { + if (!vpn_leak_to_vpn_active(from_bgp, afi, &debugmsg, false)) { if (debug) zlog_debug("%s: %s skipping: %s", __func__, from_bgp->name, debugmsg); @@ -1650,32 +1578,6 @@ void vpn_leak_from_vrf_update(struct bgp *to_bgp, /* to */ /* shallow copy */ static_attr = *path_vrf->attr; - /* - * route map handling - */ - if (from_bgp->vpn_policy[afi].rmap[BGP_VPN_POLICY_DIR_TOVPN]) { - struct bgp_path_info info; - route_map_result_t ret; - - memset(&info, 0, sizeof(info)); - info.peer = to_bgp->peer_self; - info.attr = &static_attr; - ret = route_map_apply(from_bgp->vpn_policy[afi] - .rmap[BGP_VPN_POLICY_DIR_TOVPN], - p, &info); - if (RMAP_DENYMATCH == ret) { - bgp_attr_flush(&static_attr); /* free any added parts */ - if (debug) - zlog_debug( - "%s: vrf %s route map \"%s\" says DENY, returning", - __func__, from_bgp->name_pretty, - from_bgp->vpn_policy[afi] - .rmap[BGP_VPN_POLICY_DIR_TOVPN] - ->name); - return; - } - } - if (debug && bgp_attr_get_ecommunity(&static_attr)) { char *s = ecommunity_ecom2str( bgp_attr_get_ecommunity(&static_attr), @@ -1689,29 +1591,62 @@ void vpn_leak_from_vrf_update(struct bgp *to_bgp, /* to */ /* * Add the vpn-policy rt-list */ - struct ecommunity *old_ecom; - struct ecommunity *new_ecom; /* Export with the 'from' instance's export RTs. */ /* If doing VRF-to-VRF leaking, strip existing RTs first. */ old_ecom = bgp_attr_get_ecommunity(&static_attr); + rtlist_ecom = from_bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]; if (old_ecom) { new_ecom = ecommunity_dup(old_ecom); if (CHECK_FLAG(from_bgp->af_flags[afi][SAFI_UNICAST], BGP_CONFIG_VRF_TO_VRF_EXPORT)) ecommunity_strip_rts(new_ecom); - new_ecom = ecommunity_merge( - new_ecom, from_bgp->vpn_policy[afi] - .rtlist[BGP_VPN_POLICY_DIR_TOVPN]); + if (rtlist_ecom) + new_ecom = ecommunity_merge(new_ecom, rtlist_ecom); if (!old_ecom->refcnt) ecommunity_free(&old_ecom); + } else if (rtlist_ecom) { + new_ecom = ecommunity_dup(rtlist_ecom); } else { - new_ecom = ecommunity_dup( - from_bgp->vpn_policy[afi] - .rtlist[BGP_VPN_POLICY_DIR_TOVPN]); + new_ecom = NULL; } + bgp_attr_set_ecommunity(&static_attr, new_ecom); + /* + * route map handling + */ + if (from_bgp->vpn_policy[afi].rmap[BGP_VPN_POLICY_DIR_TOVPN]) { + struct bgp_path_info info; + route_map_result_t ret; + + memset(&info, 0, sizeof(info)); + info.peer = to_bgp->peer_self; + info.attr = &static_attr; + ret = route_map_apply(from_bgp->vpn_policy[afi] + .rmap[BGP_VPN_POLICY_DIR_TOVPN], + p, &info); + if (RMAP_DENYMATCH == ret) { + bgp_attr_flush(&static_attr); /* free any added parts */ + if (debug) + zlog_debug("%s: vrf %s route map \"%s\" says DENY, returning", + __func__, from_bgp->name_pretty, + from_bgp->vpn_policy[afi] + .rmap[BGP_VPN_POLICY_DIR_TOVPN] + ->name); + return; + } + } + + new_ecom = bgp_attr_get_ecommunity(&static_attr); + if (!ecommunity_has_route_target(new_ecom)) { + ecommunity_free(&new_ecom); + if (debug) + zlog_debug("%s: %s skipping: waiting for a valid export rt list.", + __func__, from_bgp->name_pretty); + return; + } + if (debug && bgp_attr_get_ecommunity(&static_attr)) { char *s = ecommunity_ecom2str( bgp_attr_get_ecommunity(&static_attr), @@ -1793,7 +1728,7 @@ void vpn_leak_from_vrf_update(struct bgp *to_bgp, /* to */ BGP_VPN_POLICY_TOVPN_LABEL_PER_NEXTHOP)) /* per nexthop label mode */ label_val = vpn_leak_from_vrf_get_per_nexthop_label( - afi, safi, path_vrf, from_bgp, to_bgp); + afi, path_vrf, from_bgp, to_bgp); else /* per VRF label mode */ label_val = from_bgp->vpn_policy[afi].tovpn_label; @@ -1809,6 +1744,7 @@ void vpn_leak_from_vrf_update(struct bgp *to_bgp, /* to */ zlog_debug( "%s: %s skipping: waiting for a valid per-label nexthop.", __func__, from_bgp->name_pretty); + bgp_attr_flush(&static_attr); return; } if (label_val == MPLS_LABEL_NONE) @@ -1964,26 +1900,27 @@ void vpn_leak_from_vrf_withdraw(struct bgp *to_bgp, /* to */ if (!is_route_injectable_into_vpn(path_vrf)) return; - if (!vpn_leak_to_vpn_active(from_bgp, afi, &debugmsg)) { + if (!vpn_leak_to_vpn_active(from_bgp, afi, &debugmsg, true)) { if (debug) zlog_debug("%s: skipping: %s", __func__, debugmsg); return; } - if (debug) - zlog_debug("%s: withdrawing (path_vrf=%p)", __func__, path_vrf); - - bn = bgp_afi_node_get(to_bgp->rib[afi][safi], afi, safi, p, - &(from_bgp->vpn_policy[afi].tovpn_rd)); + bn = bgp_safi_node_lookup(to_bgp->rib[afi][safi], safi, p, + &(from_bgp->vpn_policy[afi].tovpn_rd)); if (!bn) return; + if (debug) + zlog_debug("%s: withdrawing (path_vrf=%p)", __func__, path_vrf); + /* * vrf -> vpn * match original bpi imported from */ for (bpi = bgp_dest_get_bgp_path_info(bn); bpi; bpi = bpi->next) { - if (bpi->extra && bpi->extra->parent == path_vrf) { + if (bpi->extra && bpi->extra->vrfleak && + bpi->extra->vrfleak->parent == path_vrf) { break; } } @@ -2036,9 +1973,9 @@ void vpn_leak_from_vrf_withdraw_all(struct bgp *to_bgp, struct bgp *from_bgp, bpi->sub_type); if (bpi->sub_type != BGP_ROUTE_IMPORTED) continue; - if (!bpi->extra) + if (!bpi->extra || !bpi->extra->vrfleak) continue; - if ((struct bgp *)bpi->extra->bgp_orig == + if ((struct bgp *)bpi->extra->vrfleak->bgp_orig == from_bgp) { /* delete route */ if (debug) @@ -2052,7 +1989,7 @@ void vpn_leak_from_vrf_withdraw_all(struct bgp *to_bgp, struct bgp *from_bgp, bgp_path_info_delete(bn, bpi); bgp_process(to_bgp, bn, afi, safi); bgp_mplsvpn_path_nh_label_unlink( - bpi->extra->parent); + bpi->extra->vrfleak->parent); } } } @@ -2117,7 +2054,7 @@ static struct bgp *bgp_lookup_by_rd(struct bgp_path_info *bpi, return NULL; } -static bool vpn_leak_to_vrf_update_onevrf(struct bgp *to_bgp, /* to */ +static void vpn_leak_to_vrf_update_onevrf(struct bgp *to_bgp, /* to */ struct bgp *from_bgp, /* from */ struct bgp_path_info *path_vpn, struct prefix_rd *prd) @@ -2147,7 +2084,7 @@ static bool vpn_leak_to_vrf_update_onevrf(struct bgp *to_bgp, /* to */ "%s: from vpn (%s) to vrf (%s), skipping: %s", __func__, from_bgp->name_pretty, to_bgp->name_pretty, debugmsg); - return false; + return; } /* @@ -2159,8 +2096,9 @@ static bool vpn_leak_to_vrf_update_onevrf(struct bgp *to_bgp, /* to */ */ struct bgp *src_bgp = bgp_lookup_by_rd(path_vpn, prd, afi); - if (path_vpn->extra && path_vpn->extra->bgp_orig) - src_vrf = path_vpn->extra->bgp_orig; + if (path_vpn->extra && path_vpn->extra->vrfleak && + path_vpn->extra->vrfleak->bgp_orig) + src_vrf = path_vpn->extra->vrfleak->bgp_orig; else if (src_bgp) src_vrf = src_bgp; else @@ -2174,7 +2112,7 @@ static bool vpn_leak_to_vrf_update_onevrf(struct bgp *to_bgp, /* to */ zlog_debug( "from vpn (%s) to vrf (%s), skipping after no intersection of route targets", from_bgp->name_pretty, to_bgp->name_pretty); - return false; + return; } rd_buf[0] = '\0'; @@ -2191,7 +2129,7 @@ static bool vpn_leak_to_vrf_update_onevrf(struct bgp *to_bgp, /* to */ zlog_debug( "%s: skipping import, match RD (%s) of src VRF (%s) and the prefix (%pFX)", __func__, rd_buf, to_bgp->name_pretty, p); - return false; + return; } if (debug) @@ -2302,7 +2240,7 @@ static bool vpn_leak_to_vrf_update_onevrf(struct bgp *to_bgp, /* to */ to_bgp->vpn_policy[afi] .rmap[BGP_VPN_POLICY_DIR_FROMVPN] ->name); - return false; + return; } /* * if route-map changed nexthop, don't nexthop-self on output @@ -2364,17 +2302,60 @@ static bool vpn_leak_to_vrf_update_onevrf(struct bgp *to_bgp, /* to */ num_labels, src_vrf, &nexthop_orig, nexthop_self_flag, debug)) bgp_dest_unlock_node(bn); +} + +bool vpn_leak_to_vrf_no_retain_filter_check(struct bgp *from_bgp, + struct attr *attr, afi_t afi) +{ + struct ecommunity *ecom_route_target = bgp_attr_get_ecommunity(attr); + int debug = BGP_DEBUG(vpn, VPN_LEAK_TO_VRF); + struct listnode *node; + const char *debugmsg; + struct bgp *to_bgp; + + /* Loop over BGP instances */ + for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, to_bgp)) { + if (!vpn_leak_from_vpn_active(to_bgp, afi, &debugmsg)) { + if (debug) + zlog_debug( + "%s: from vpn (%s) to vrf (%s) afi %s, skipping: %s", + __func__, from_bgp->name_pretty, + to_bgp->name_pretty, afi2str(afi), + debugmsg); + continue; + } + + /* Check for intersection of route targets */ + if (!ecommunity_include( + to_bgp->vpn_policy[afi] + .rtlist[BGP_VPN_POLICY_DIR_FROMVPN], + ecom_route_target)) { + if (debug) + zlog_debug( + "%s: from vpn (%s) to vrf (%s) afi %s %s, skipping after no intersection of route targets", + __func__, from_bgp->name_pretty, + to_bgp->name_pretty, afi2str(afi), + ecommunity_str(ecom_route_target)); + continue; + } + return false; + } + + if (debug) + zlog_debug( + "%s: from vpn (%s) afi %s %s, no import - must be filtered", + __func__, from_bgp->name_pretty, afi2str(afi), + ecommunity_str(ecom_route_target)); return true; } -bool vpn_leak_to_vrf_update(struct bgp *from_bgp, +void vpn_leak_to_vrf_update(struct bgp *from_bgp, struct bgp_path_info *path_vpn, struct prefix_rd *prd) { struct listnode *mnode, *mnnode; struct bgp *bgp; - bool leak_success = false; int debug = BGP_DEBUG(vpn, VPN_LEAK_TO_VRF); @@ -2383,14 +2364,12 @@ bool vpn_leak_to_vrf_update(struct bgp *from_bgp, /* Loop over VRFs */ for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) { - - if (!path_vpn->extra - || path_vpn->extra->bgp_orig != bgp) { /* no loop */ - leak_success |= vpn_leak_to_vrf_update_onevrf( - bgp, from_bgp, path_vpn, prd); + if (!path_vpn->extra || !path_vpn->extra->vrfleak || + path_vpn->extra->vrfleak->bgp_orig != bgp) { /* no loop */ + vpn_leak_to_vrf_update_onevrf(bgp, from_bgp, path_vpn, + prd); } } - return leak_success; } void vpn_leak_to_vrf_withdraw(struct bgp_path_info *path_vpn) @@ -2459,9 +2438,9 @@ void vpn_leak_to_vrf_withdraw(struct bgp_path_info *path_vpn) for (bpi = bgp_dest_get_bgp_path_info(bn); bpi; bpi = bpi->next) { - if (bpi->extra - && (struct bgp_path_info *)bpi->extra->parent - == path_vpn) { + if (bpi->extra && bpi->extra->vrfleak && + (struct bgp_path_info *)bpi->extra->vrfleak->parent == + path_vpn) { break; } } @@ -2495,10 +2474,10 @@ void vpn_leak_to_vrf_withdraw_all(struct bgp *to_bgp, afi_t afi) for (bpi = bgp_dest_get_bgp_path_info(bn); bpi; bpi = bpi->next) { - if (bpi->extra && bpi->extra->bgp_orig != to_bgp && - bpi->extra->parent && - is_pi_family_vpn(bpi->extra->parent)) { - + if (bpi->extra && bpi->extra->vrfleak && + bpi->extra->vrfleak->bgp_orig != to_bgp && + bpi->extra->vrfleak->parent && + is_pi_family_vpn(bpi->extra->vrfleak->parent)) { /* delete route */ bgp_aggregate_decrement(to_bgp, bgp_dest_get_prefix(bn), @@ -2510,6 +2489,50 @@ void vpn_leak_to_vrf_withdraw_all(struct bgp *to_bgp, afi_t afi) } } +void vpn_leak_no_retain(struct bgp *to_bgp, struct bgp *vpn_from, afi_t afi) +{ + struct bgp_dest *pdest; + safi_t safi = SAFI_MPLS_VPN; + + assert(vpn_from); + + /* + * Walk vpn table + */ + for (pdest = bgp_table_top(vpn_from->rib[afi][safi]); pdest; + pdest = bgp_route_next(pdest)) { + struct bgp_table *table; + struct bgp_dest *bn; + struct bgp_path_info *bpi; + + /* This is the per-RD table of prefixes */ + table = bgp_dest_get_bgp_table_info(pdest); + + if (!table) + continue; + + for (bn = bgp_table_top(table); bn; bn = bgp_route_next(bn)) { + for (bpi = bgp_dest_get_bgp_path_info(bn); bpi; + bpi = bpi->next) { + if (bpi->extra && bpi->extra->vrfleak && + bpi->extra->vrfleak->bgp_orig == to_bgp) + continue; + + if (bpi->sub_type != BGP_ROUTE_NORMAL) + continue; + + if (!vpn_leak_to_vrf_no_retain_filter_check( + vpn_from, bpi->attr, afi)) + /* do not filter */ + continue; + + bgp_unlink_nexthop(bpi); + bgp_rib_remove(bn, bpi, bpi->peer, afi, safi); + } + } + } +} + void vpn_leak_to_vrf_update_all(struct bgp *to_bgp, struct bgp *vpn_from, afi_t afi) { @@ -2537,9 +2560,8 @@ void vpn_leak_to_vrf_update_all(struct bgp *to_bgp, struct bgp *vpn_from, for (bpi = bgp_dest_get_bgp_path_info(bn); bpi; bpi = bpi->next) { - - if (bpi->extra && - bpi->extra->bgp_orig == to_bgp) + if (bpi->extra && bpi->extra->vrfleak && + bpi->extra->vrfleak->bgp_orig == to_bgp) continue; vpn_leak_to_vrf_update_onevrf(to_bgp, vpn_from, @@ -2659,7 +2681,7 @@ void vpn_handle_router_id_update(struct bgp *bgp, bool withdraw, edir = BGP_VPN_POLICY_DIR_TOVPN; for (afi = 0; afi < AFI_MAX; ++afi) { - if (!vpn_leak_to_vpn_active(bgp, afi, NULL)) + if (!vpn_leak_to_vpn_active(bgp, afi, NULL, false)) continue; if (withdraw) { @@ -3008,10 +3030,11 @@ DEFUN (vpnv4_network, int idx_ipv4_prefixlen = 1; int idx_ext_community = 3; int idx_label = 5; - return bgp_static_set_safi( - AFI_IP, SAFI_MPLS_VPN, vty, argv[idx_ipv4_prefixlen]->arg, - argv[idx_ext_community]->arg, argv[idx_label]->arg, NULL, 0, - NULL, NULL, NULL, NULL); + + return bgp_static_set(vty, false, argv[idx_ipv4_prefixlen]->arg, + argv[idx_ext_community]->arg, + argv[idx_label]->arg, AFI_IP, SAFI_MPLS_VPN, NULL, + 0, 0, 0, NULL, NULL, NULL, NULL); } DEFUN (vpnv4_network_route_map, @@ -3030,11 +3053,12 @@ DEFUN (vpnv4_network_route_map, int idx_ipv4_prefixlen = 1; int idx_ext_community = 3; int idx_label = 5; - int idx_word_2 = 7; - return bgp_static_set_safi( - AFI_IP, SAFI_MPLS_VPN, vty, argv[idx_ipv4_prefixlen]->arg, - argv[idx_ext_community]->arg, argv[idx_label]->arg, - argv[idx_word_2]->arg, 0, NULL, NULL, NULL, NULL); + int idx_rmap = 7; + + return bgp_static_set(vty, false, argv[idx_ipv4_prefixlen]->arg, + argv[idx_ext_community]->arg, argv[idx_label]->arg, + AFI_IP, SAFI_MPLS_VPN, argv[idx_rmap]->arg, 0, 0, + 0, NULL, NULL, NULL, NULL); } /* For testing purpose, static route of MPLS-VPN. */ @@ -3053,10 +3077,11 @@ DEFUN (no_vpnv4_network, int idx_ipv4_prefixlen = 2; int idx_ext_community = 4; int idx_label = 6; - return bgp_static_unset_safi(AFI_IP, SAFI_MPLS_VPN, vty, - argv[idx_ipv4_prefixlen]->arg, - argv[idx_ext_community]->arg, - argv[idx_label]->arg, 0, NULL, NULL, NULL); + + return bgp_static_set(vty, true, argv[idx_ipv4_prefixlen]->arg, + argv[idx_ext_community]->arg, + argv[idx_label]->arg, AFI_IP, SAFI_MPLS_VPN, NULL, + 0, 0, 0, NULL, NULL, NULL, NULL); } DEFUN (vpnv6_network, @@ -3075,17 +3100,20 @@ DEFUN (vpnv6_network, int idx_ipv6_prefix = 1; int idx_ext_community = 3; int idx_label = 5; - int idx_word_2 = 7; + int idx_rmap = 7; + if (argc == 8) - return bgp_static_set_safi( - AFI_IP6, SAFI_MPLS_VPN, vty, argv[idx_ipv6_prefix]->arg, - argv[idx_ext_community]->arg, argv[idx_label]->arg, - argv[idx_word_2]->arg, 0, NULL, NULL, NULL, NULL); + return bgp_static_set(vty, false, argv[idx_ipv6_prefix]->arg, + argv[idx_ext_community]->arg, + argv[idx_label]->arg, AFI_IP6, + SAFI_MPLS_VPN, argv[idx_rmap]->arg, 0, 0, + 0, NULL, NULL, NULL, NULL); else - return bgp_static_set_safi( - AFI_IP6, SAFI_MPLS_VPN, vty, argv[idx_ipv6_prefix]->arg, - argv[idx_ext_community]->arg, argv[idx_label]->arg, - NULL, 0, NULL, NULL, NULL, NULL); + return bgp_static_set(vty, false, argv[idx_ipv6_prefix]->arg, + argv[idx_ext_community]->arg, + argv[idx_label]->arg, AFI_IP6, + SAFI_MPLS_VPN, NULL, 0, 0, 0, NULL, NULL, + NULL, NULL); } /* For testing purpose, static route of MPLS-VPN. */ @@ -3104,10 +3132,11 @@ DEFUN (no_vpnv6_network, int idx_ipv6_prefix = 2; int idx_ext_community = 4; int idx_label = 6; - return bgp_static_unset_safi(AFI_IP6, SAFI_MPLS_VPN, vty, - argv[idx_ipv6_prefix]->arg, - argv[idx_ext_community]->arg, - argv[idx_label]->arg, 0, NULL, NULL, NULL); + + return bgp_static_set(vty, true, argv[idx_ipv6_prefix]->arg, + argv[idx_ext_community]->arg, + argv[idx_label]->arg, AFI_IP6, SAFI_MPLS_VPN, + NULL, 0, 0, 0, NULL, NULL, NULL, NULL); } int bgp_show_mpls_vpn(struct vty *vty, afi_t afi, struct prefix_rd *prd, @@ -3130,7 +3159,7 @@ int bgp_show_mpls_vpn(struct vty *vty, afi_t afi, struct prefix_rd *prd, return CMD_WARNING; } table = bgp->rib[afi][SAFI_MPLS_VPN]; - return bgp_show_table_rd(vty, bgp, SAFI_MPLS_VPN, table, prd, type, + return bgp_show_table_rd(vty, bgp, afi, SAFI_MPLS_VPN, table, prd, type, output_arg, show_flags); } @@ -3714,6 +3743,7 @@ void vpn_leak_postchange_all(void) */ void bgp_vpn_leak_unimport(struct bgp *from_bgp) { + struct bgp *bgp_default = bgp_get_default(); struct bgp *to_bgp; const char *tmp_name; char *vname; @@ -3792,6 +3822,17 @@ void bgp_vpn_leak_unimport(struct bgp *from_bgp) } } } + + if (bgp_default && + !CHECK_FLAG(bgp_default->af_flags[afi][SAFI_MPLS_VPN], + BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL)) { + /* 'from_bgp' instance will be deleted + * so force to unset importation to update VPN labels + */ + UNSET_FLAG(from_bgp->af_flags[afi][SAFI_UNICAST], + BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT); + vpn_leak_no_retain(from_bgp, bgp_default, afi); + } } return; } @@ -3866,3 +3907,387 @@ void bgp_vpn_leak_export(struct bgp *from_bgp) } } } + +/* The nexthops values are compared to + * find in the tree the appropriate cache entry + */ +int bgp_mplsvpn_nh_label_bind_cmp( + const struct bgp_mplsvpn_nh_label_bind_cache *a, + const struct bgp_mplsvpn_nh_label_bind_cache *b) +{ + if (prefix_cmp(&a->nexthop, &b->nexthop)) + return 1; + if (a->orig_label > b->orig_label) + return 1; + if (a->orig_label < b->orig_label) + return -1; + return 0; +} + +static void bgp_mplsvpn_nh_label_bind_send_nexthop_label( + struct bgp_mplsvpn_nh_label_bind_cache *bmnc, int cmd) +{ + struct prefix pfx_nh, *p = NULL; + uint32_t num_labels = 0, lsp_num_labels; + mpls_label_t label[MPLS_MAX_LABELS]; + struct nexthop *nh; + ifindex_t ifindex = IFINDEX_INTERNAL; + vrf_id_t vrf_id = VRF_DEFAULT; + uint32_t i; + + if (bmnc->nh == NULL) + return; + nh = bmnc->nh; + switch (nh->type) { + case NEXTHOP_TYPE_IFINDEX: + p = &bmnc->nexthop; + label[num_labels] = bmnc->orig_label; + num_labels += 1; + ifindex = nh->ifindex; + vrf_id = nh->vrf_id; + break; + case NEXTHOP_TYPE_IPV4: + case NEXTHOP_TYPE_IPV4_IFINDEX: + case NEXTHOP_TYPE_IPV6: + case NEXTHOP_TYPE_IPV6_IFINDEX: + if (nh->type == NEXTHOP_TYPE_IPV4 || + nh->type == NEXTHOP_TYPE_IPV4_IFINDEX) { + pfx_nh.family = AF_INET; + pfx_nh.prefixlen = IPV4_MAX_BITLEN; + IPV4_ADDR_COPY(&pfx_nh.u.prefix4, &nh->gate.ipv4); + } else { + pfx_nh.family = AF_INET6; + pfx_nh.prefixlen = IPV6_MAX_BITLEN; + IPV6_ADDR_COPY(&pfx_nh.u.prefix6, &nh->gate.ipv6); + } + p = &pfx_nh; + if (nh->nh_label) { + if (nh->nh_label->num_labels + 1 > MPLS_MAX_LABELS) { + /* label stack overflow. no label switching will be performed + */ + flog_err(EC_BGP_LABEL, + "%s [Error] BGP label %u->%u to %pFX, forged label stack too big: %u. Abort LSP installation", + bmnc->bgp_vpn->name_pretty, + bmnc->new_label, bmnc->orig_label, + &bmnc->nexthop, + nh->nh_label->num_labels + 1); + return; + } + lsp_num_labels = nh->nh_label->num_labels; + for (i = 0; i < lsp_num_labels; i++) + label[num_labels + i] = nh->nh_label->label[i]; + num_labels = lsp_num_labels; + } + label[num_labels] = bmnc->orig_label; + num_labels += 1; + if (nh->type == NEXTHOP_TYPE_IPV4_IFINDEX || + nh->type == NEXTHOP_TYPE_IPV6_IFINDEX) { + ifindex = nh->ifindex; + vrf_id = nh->vrf_id; + } + break; + case NEXTHOP_TYPE_BLACKHOLE: + return; + } + bgp_zebra_send_nexthop_label(cmd, bmnc->new_label, ifindex, vrf_id, + ZEBRA_LSP_BGP, p, num_labels, &label[0]); +} + +void bgp_mplsvpn_nh_label_bind_free( + struct bgp_mplsvpn_nh_label_bind_cache *bmnc) +{ + if (bmnc->allocation_in_progress) { + bmnc->allocation_in_progress = false; + bgp_mplsvpn_nh_label_bind_cache_del( + &bmnc->bgp_vpn->mplsvpn_nh_label_bind, bmnc); + return; + } + if (bmnc->new_label != MPLS_INVALID_LABEL) { + bgp_mplsvpn_nh_label_bind_send_nexthop_label( + bmnc, ZEBRA_MPLS_LABELS_DELETE); + bgp_lp_release(LP_TYPE_BGP_L3VPN_BIND, bmnc, bmnc->new_label); + } + bgp_mplsvpn_nh_label_bind_cache_del( + &bmnc->bgp_vpn->mplsvpn_nh_label_bind, bmnc); + + if (bmnc->nh) + nexthop_free(bmnc->nh); + + XFREE(MTYPE_MPLSVPN_NH_LABEL_BIND_CACHE, bmnc); +} + +struct bgp_mplsvpn_nh_label_bind_cache * +bgp_mplsvpn_nh_label_bind_new(struct bgp_mplsvpn_nh_label_bind_cache_head *tree, + struct prefix *p, mpls_label_t orig_label) +{ + struct bgp_mplsvpn_nh_label_bind_cache *bmnc; + + bmnc = XCALLOC(MTYPE_MPLSVPN_NH_LABEL_BIND_CACHE, + sizeof(struct bgp_mplsvpn_nh_label_bind_cache)); + bmnc->new_label = MPLS_INVALID_LABEL; + prefix_copy(&bmnc->nexthop, p); + bmnc->orig_label = orig_label; + + LIST_INIT(&(bmnc->paths)); + bgp_mplsvpn_nh_label_bind_cache_add(tree, bmnc); + + return bmnc; +} + +struct bgp_mplsvpn_nh_label_bind_cache *bgp_mplsvpn_nh_label_bind_find( + struct bgp_mplsvpn_nh_label_bind_cache_head *tree, struct prefix *p, + mpls_label_t orig_label) +{ + struct bgp_mplsvpn_nh_label_bind_cache bmnc = {0}; + + if (!tree) + return NULL; + prefix_copy(&bmnc.nexthop, p); + bmnc.orig_label = orig_label; + + return bgp_mplsvpn_nh_label_bind_cache_find(tree, &bmnc); +} + +/* Called to check if the incoming l3vpn path entry + * has mpls label information + */ +bool bgp_mplsvpn_path_uses_valid_mpls_label(struct bgp_path_info *pi) +{ + if (pi->attr && pi->attr->srv6_l3vpn) + /* srv6 sid */ + return false; + + if (pi->attr && + CHECK_FLAG(pi->attr->flag, ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID)) && + pi->attr->label_index != BGP_INVALID_LABEL_INDEX) + /* prefix_sid attribute */ + return false; + + if (!pi->extra || !bgp_is_valid_label(&pi->extra->label[0])) + /* invalid MPLS label */ + return false; + return true; +} + +mpls_label_t bgp_mplsvpn_nh_label_bind_get_label(struct bgp_path_info *pi) +{ + mpls_label_t label; + struct bgp_mplsvpn_nh_label_bind_cache *bmnc; + + bmnc = pi->mplsvpn.bmnc.nh_label_bind_cache; + if (!bmnc || bmnc->new_label == MPLS_INVALID_LABEL) + /* allocation in progress + * or path not eligible for local label + */ + return MPLS_INVALID_LABEL; + + label = mpls_lse_encode(bmnc->new_label, 0, 0, 1); + bgp_set_valid_label(&label); + + return label; +} + +/* Called upon reception of a ZAPI Message from zebra, about + * a new available label. + */ +static int bgp_mplsvpn_nh_label_bind_get_local_label_cb(mpls_label_t label, + void *context, + bool allocated) +{ + struct bgp_mplsvpn_nh_label_bind_cache *bmnc = context; + struct bgp_table *table; + struct bgp_path_info *pi; + + if (BGP_DEBUG(labelpool, LABELPOOL)) + zlog_debug("%s: label=%u, allocated=%d, nexthop=%pFX, label %u", + __func__, label, allocated, &bmnc->nexthop, + bmnc->orig_label); + if (allocated) + /* update the entry with the new label */ + bmnc->new_label = label; + else + /* + * previously-allocated label is now invalid + * eg: zebra deallocated the labels and notifies it + */ + bmnc->new_label = MPLS_INVALID_LABEL; + + if (!bmnc->allocation_in_progress) { + bgp_mplsvpn_nh_label_bind_free(bmnc); + return 0; + } + bmnc->allocation_in_progress = false; + + if (bmnc->new_label != MPLS_INVALID_LABEL) + /* + * Create the LSP : bmnc->orig_label, + * via bmnc->prefix, interface bnc->nexthop->ifindex + */ + bgp_mplsvpn_nh_label_bind_send_nexthop_label( + bmnc, ZEBRA_MPLS_LABELS_ADD); + + LIST_FOREACH (pi, &(bmnc->paths), mplsvpn.bmnc.nh_label_bind_thread) { + /* we can advertise it */ + if (!pi->net) + continue; + table = bgp_dest_table(pi->net); + if (!table) + continue; + SET_FLAG(pi->net->flags, BGP_NODE_LABEL_CHANGED); + bgp_process(table->bgp, pi->net, table->afi, table->safi); + } + + return 0; +} + +void bgp_mplsvpn_path_nh_label_bind_unlink(struct bgp_path_info *pi) +{ + struct bgp_mplsvpn_nh_label_bind_cache *bmnc; + + if (!pi) + return; + + if (!CHECK_FLAG(pi->flags, BGP_PATH_MPLSVPN_NH_LABEL_BIND)) + return; + + bmnc = pi->mplsvpn.bmnc.nh_label_bind_cache; + + if (!bmnc) + return; + + LIST_REMOVE(pi, mplsvpn.bmnc.nh_label_bind_thread); + pi->mplsvpn.bmnc.nh_label_bind_cache->path_count--; + pi->mplsvpn.bmnc.nh_label_bind_cache = NULL; + SET_FLAG(pi->flags, BGP_PATH_MPLSVPN_NH_LABEL_BIND); + + if (LIST_EMPTY(&(bmnc->paths))) + bgp_mplsvpn_nh_label_bind_free(bmnc); +} + +void bgp_mplsvpn_nh_label_bind_register_local_label(struct bgp *bgp, + struct bgp_dest *dest, + struct bgp_path_info *pi) +{ + struct bgp_mplsvpn_nh_label_bind_cache *bmnc; + struct bgp_mplsvpn_nh_label_bind_cache_head *tree; + + tree = &bgp->mplsvpn_nh_label_bind; + bmnc = bgp_mplsvpn_nh_label_bind_find( + tree, &pi->nexthop->prefix, decode_label(&pi->extra->label[0])); + if (!bmnc) { + bmnc = bgp_mplsvpn_nh_label_bind_new( + tree, &pi->nexthop->prefix, + decode_label(&pi->extra->label[0])); + bmnc->bgp_vpn = bgp; + bmnc->allocation_in_progress = true; + bgp_lp_get(LP_TYPE_BGP_L3VPN_BIND, bmnc, + bgp_mplsvpn_nh_label_bind_get_local_label_cb); + } + + if (pi->mplsvpn.bmnc.nh_label_bind_cache == bmnc) + /* no change */ + return; + + bgp_mplsvpn_path_nh_label_bind_unlink(pi); + + /* updates NHT pi list reference */ + LIST_INSERT_HEAD(&(bmnc->paths), pi, mplsvpn.bmnc.nh_label_bind_thread); + pi->mplsvpn.bmnc.nh_label_bind_cache = bmnc; + pi->mplsvpn.bmnc.nh_label_bind_cache->path_count++; + SET_FLAG(pi->flags, BGP_PATH_MPLSVPN_NH_LABEL_BIND); + bmnc->last_update = monotime(NULL); + + /* Add or update the selected nexthop */ + if (!bmnc->nh) + bmnc->nh = nexthop_dup(pi->nexthop->nexthop, NULL); + else if (!nexthop_same(pi->nexthop->nexthop, bmnc->nh)) { + nexthop_free(bmnc->nh); + bmnc->nh = nexthop_dup(pi->nexthop->nexthop, NULL); + if (bmnc->new_label != MPLS_INVALID_LABEL) + bgp_mplsvpn_nh_label_bind_send_nexthop_label( + bmnc, ZEBRA_MPLS_LABELS_REPLACE); + } +} + +static void show_bgp_mplsvpn_nh_label_bind_internal(struct vty *vty, + struct bgp *bgp, + bool detail) +{ + struct bgp_mplsvpn_nh_label_bind_cache_head *tree; + struct bgp_mplsvpn_nh_label_bind_cache *iter; + afi_t afi; + safi_t safi; + struct bgp_dest *dest; + struct bgp_path_info *path; + struct bgp *bgp_path; + struct bgp_table *table; + time_t tbuf; + char buf[32]; + + vty_out(vty, "Current BGP mpls-vpn nexthop label bind cache, %s\n", + bgp->name_pretty); + + tree = &bgp->mplsvpn_nh_label_bind; + frr_each (bgp_mplsvpn_nh_label_bind_cache, tree, iter) { + if (iter->nexthop.family == AF_INET) + vty_out(vty, " %pI4", &iter->nexthop.u.prefix4); + else + vty_out(vty, " %pI6", &iter->nexthop.u.prefix6); + vty_out(vty, ", label %u, local label %u #paths %u\n", + iter->orig_label, iter->new_label, iter->path_count); + if (iter->nh) + vty_out(vty, " interface %s\n", + ifindex2ifname(iter->nh->ifindex, + iter->nh->vrf_id)); + tbuf = time(NULL) - (monotime(NULL) - iter->last_update); + vty_out(vty, " Last update: %s", ctime_r(&tbuf, buf)); + if (!detail) + continue; + vty_out(vty, " Paths:\n"); + LIST_FOREACH (path, &(iter->paths), + mplsvpn.bmnc.nh_label_bind_thread) { + dest = path->net; + table = bgp_dest_table(dest); + assert(dest && table); + afi = family2afi(bgp_dest_get_prefix(dest)->family); + safi = table->safi; + bgp_path = table->bgp; + + vty_out(vty, " %d/%d %pBD %s flags 0x%x\n", afi, + safi, dest, bgp_path->name_pretty, path->flags); + } + } +} + + +DEFUN(show_bgp_mplsvpn_nh_label_bind, show_bgp_mplsvpn_nh_label_bind_cmd, + "show bgp [ VIEWVRFNAME] mplsvpn-nh-label-bind [detail]", + SHOW_STR BGP_STR BGP_INSTANCE_HELP_STR + "BGP mplsvpn nexthop label binding entries\n" + "Show detailed information\n") +{ + int idx = 0; + char *vrf = NULL; + struct bgp *bgp; + bool detail = false; + + if (argv_find(argv, argc, "vrf", &idx)) { + vrf = argv[++idx]->arg; + bgp = bgp_lookup_by_name(vrf); + } else + bgp = bgp_get_default(); + + if (!bgp) + return CMD_SUCCESS; + + if (argv_find(argv, argc, "detail", &idx)) + detail = true; + + show_bgp_mplsvpn_nh_label_bind_internal(vty, bgp, detail); + return CMD_SUCCESS; +} + +void bgp_mplsvpn_nexthop_init(void) +{ + install_element(VIEW_NODE, &show_bgp_mplsvpn_nh_label_bind_cmd); +} diff --git a/bgpd/bgp_mplsvpn.h b/bgpd/bgp_mplsvpn.h index 75758edcc2..cd25899965 100644 --- a/bgpd/bgp_mplsvpn.h +++ b/bgpd/bgp_mplsvpn.h @@ -13,6 +13,7 @@ #include "bgpd/bgp_rd.h" #include "bgpd/bgp_zebra.h" #include "bgpd/bgp_vty.h" +#include "bgpd/bgp_label.h" #define MPLS_LABEL_IS_SPECIAL(label) ((label) <= MPLS_LABEL_EXTENSION) #define MPLS_LABEL_IS_NULL(label) \ @@ -56,10 +57,17 @@ extern void vpn_leak_from_vrf_update_all(struct bgp *to_bgp, extern void vpn_leak_to_vrf_withdraw_all(struct bgp *to_bgp, afi_t afi); +extern void vpn_leak_no_retain(struct bgp *to_bgp, struct bgp *vpn_from, + afi_t afi); + extern void vpn_leak_to_vrf_update_all(struct bgp *to_bgp, struct bgp *from_bgp, afi_t afi); -extern bool vpn_leak_to_vrf_update(struct bgp *from_bgp, +extern bool vpn_leak_to_vrf_no_retain_filter_check(struct bgp *from_bgp, + struct attr *attr, + afi_t afi); + +extern void vpn_leak_to_vrf_update(struct bgp *from_bgp, struct bgp_path_info *path_vpn, struct prefix_rd *prd); @@ -105,7 +113,8 @@ static inline bool is_bgp_vrf_mplsvpn(struct bgp *bgp) } static inline int vpn_leak_to_vpn_active(struct bgp *bgp_vrf, afi_t afi, - const char **pmsg) + const char **pmsg, + bool ignore_export_rt_list) { if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF && bgp_vrf->inst_type != BGP_INSTANCE_TYPE_DEFAULT) { @@ -125,8 +134,21 @@ static inline int vpn_leak_to_vpn_active(struct bgp *bgp_vrf, afi_t afi, return 0; } - /* Is there an RT list set? */ - if (!bgp_vrf->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN]) { + /* Before performing withdrawal, VPN activation is checked; however, + * when the route-map modifies the export route-target (RT) list, it + * becomes challenging to determine if VPN prefixes were previously + * present, or not. The 'ignore_export_rt_list' parameter will be + * used to force the withdraw operation by not checking the possible + * route-map changes. + * Of the 'ignore_export_rt_list' is set to false, check the following: + * - Is there an RT list set? + * - Is there a route-map that sets RT communities + */ + if (!ignore_export_rt_list && + !bgp_vrf->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_TOVPN] && + (!bgp_vrf->vpn_policy[afi].rmap[BGP_VPN_POLICY_DIR_TOVPN] || + !bgp_route_map_has_extcommunity_rt( + bgp_vrf->vpn_policy[afi].rmap[BGP_VPN_POLICY_DIR_TOVPN]))) { if (pmsg) *pmsg = "rtlist tovpn not defined"; return 0; @@ -158,6 +180,25 @@ static inline int vpn_leak_to_vpn_active(struct bgp *bgp_vrf, afi_t afi, return 0; } + /* Is there a "manual" export label that isn't allocated yet? */ + if (!CHECK_FLAG(bgp_vrf->vpn_policy[afi].flags, + BGP_VPN_POLICY_TOVPN_LABEL_AUTO) && + bgp_vrf->vpn_policy[afi].tovpn_label != BGP_PREVENT_VRF_2_VRF_LEAK && + bgp_vrf->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE && + (bgp_vrf->vpn_policy[afi].tovpn_label >= MPLS_LABEL_UNRESERVED_MIN && + !CHECK_FLAG(bgp_vrf->vpn_policy[afi].flags, + BGP_VPN_POLICY_TOVPN_LABEL_MANUAL_REG))) { + if (!bgp_zebra_request_label_range(bgp_vrf->vpn_policy[afi] + .tovpn_label, + 1, false)) { + if (pmsg) + *pmsg = "manual label could not be allocated"; + return 0; + } + SET_FLAG(bgp_vrf->vpn_policy[afi].flags, + BGP_VPN_POLICY_TOVPN_LABEL_MANUAL_REG); + } + return 1; } @@ -219,8 +260,7 @@ static inline void vpn_leak_prechange(enum vpn_policy_direction direction, vpn_leak_to_vrf_withdraw_all(bgp_vrf, afi); } if ((direction == BGP_VPN_POLICY_DIR_TOVPN) && - vpn_leak_to_vpn_active(bgp_vrf, afi, NULL)) { - + vpn_leak_to_vpn_active(bgp_vrf, afi, NULL, true)) { vpn_leak_from_vrf_withdraw_all(bgp_vpn, bgp_vrf, afi); } } @@ -238,8 +278,7 @@ static inline void vpn_leak_postchange(enum vpn_policy_direction direction, if (!CHECK_FLAG(bgp_vpn->af_flags[afi][SAFI_MPLS_VPN], BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL)) bgp_clear_soft_in(bgp_vpn, afi, SAFI_MPLS_VPN); - else - vpn_leak_to_vrf_update_all(bgp_vrf, bgp_vpn, afi); + vpn_leak_to_vrf_update_all(bgp_vrf, bgp_vpn, afi); } if (direction == BGP_VPN_POLICY_DIR_TOVPN) { @@ -291,12 +330,11 @@ static inline bool is_route_injectable_into_vpn(struct bgp_path_info *pi) struct bgp_table *table; struct bgp_dest *dest; - if (pi->sub_type != BGP_ROUTE_IMPORTED || - !pi->extra || - !pi->extra->parent) + if (pi->sub_type != BGP_ROUTE_IMPORTED || !pi->extra || + !pi->extra->vrfleak || !pi->extra->vrfleak->parent) return true; - parent_pi = (struct bgp_path_info *)pi->extra->parent; + parent_pi = (struct bgp_path_info *)pi->extra->vrfleak->parent; dest = parent_pi->net; if (!dest) return true; @@ -325,4 +363,72 @@ extern void vpn_handle_router_id_update(struct bgp *bgp, bool withdraw, extern void bgp_vpn_leak_unimport(struct bgp *from_bgp); extern void bgp_vpn_leak_export(struct bgp *from_bgp); +extern bool bgp_mplsvpn_path_uses_valid_mpls_label(struct bgp_path_info *pi); +extern int +bgp_mplsvpn_nh_label_bind_cmp(const struct bgp_mplsvpn_nh_label_bind_cache *a, + const struct bgp_mplsvpn_nh_label_bind_cache *b); +extern void bgp_mplsvpn_path_nh_label_bind_unlink(struct bgp_path_info *pi); +extern void bgp_mplsvpn_nh_label_bind_register_local_label( + struct bgp *bgp, struct bgp_dest *dest, struct bgp_path_info *pi); +mpls_label_t bgp_mplsvpn_nh_label_bind_get_label(struct bgp_path_info *pi); + +/* used to bind a local label to the (label, nexthop) values + * from an incoming BGP mplsvpn update + */ +struct bgp_mplsvpn_nh_label_bind_cache { + + /* RB-tree entry. */ + struct bgp_mplsvpn_nh_label_bind_cache_item entry; + + /* The nexthop and the vpn label are the key of the list. + * Only received BGP MPLSVPN updates may use that structure. + * orig_label is the original label received from the BGP Update. + */ + struct prefix nexthop; + mpls_label_t orig_label; + + /* resolved interface for the paths */ + struct nexthop *nh; + + /* number of mplsvpn path */ + unsigned int path_count; + + /* back pointer to bgp instance */ + struct bgp *bgp_vpn; + + /* MPLS label allocated value. + * When the next-hop is changed because of 'next-hop-self' or + * because it is an eBGP peer, the redistributed orig_label value + * is unmodified, unless the 'l3vpn-multi-domain-switching' + * is enabled: a new_label value is allocated: + * - The new_label value is sent in the advertised BGP update, + * instead of the label value. + * - An MPLS entry is set to swap with . + */ + mpls_label_t new_label; + + /* list of path_vrfs using it */ + LIST_HEAD(mplsvpn_nh_label_bind_path_lists, bgp_path_info) paths; + + time_t last_update; + + bool allocation_in_progress; +}; + +DECLARE_RBTREE_UNIQ(bgp_mplsvpn_nh_label_bind_cache, + struct bgp_mplsvpn_nh_label_bind_cache, entry, + bgp_mplsvpn_nh_label_bind_cmp); + +void bgp_mplsvpn_nh_label_bind_free( + struct bgp_mplsvpn_nh_label_bind_cache *bmnc); + +struct bgp_mplsvpn_nh_label_bind_cache * +bgp_mplsvpn_nh_label_bind_new(struct bgp_mplsvpn_nh_label_bind_cache_head *tree, + struct prefix *p, mpls_label_t orig_label); +struct bgp_mplsvpn_nh_label_bind_cache *bgp_mplsvpn_nh_label_bind_find( + struct bgp_mplsvpn_nh_label_bind_cache_head *tree, struct prefix *p, + mpls_label_t orig_label); +void bgp_mplsvpn_nexthop_init(void); +extern void sid_unregister(struct bgp *bgp, const struct in6_addr *sid); + #endif /* _QUAGGA_BGP_MPLSVPN_H */ diff --git a/bgpd/bgp_mplsvpn_snmp.c b/bgpd/bgp_mplsvpn_snmp.c index 0208a6f5a5..3344e9e0a5 100644 --- a/bgpd/bgp_mplsvpn_snmp.c +++ b/bgpd/bgp_mplsvpn_snmp.c @@ -511,8 +511,8 @@ static int bgp_init_snmp_stats(struct bgp *bgp) { if (is_bgp_vrf_mplsvpn(bgp)) { if (bgp->snmp_stats == NULL) { - bgp->snmp_stats = XCALLOC( - MTYPE_BGP, sizeof(struct bgp_snmp_stats)); + bgp->snmp_stats = XCALLOC(MTYPE_BGP_NAME, + sizeof(struct bgp_snmp_stats)); /* fix up added routes */ if (bgp->snmp_stats) { bgp->snmp_stats->routes_added = @@ -523,7 +523,7 @@ static int bgp_init_snmp_stats(struct bgp *bgp) } } else { if (bgp->snmp_stats) { - XFREE(MTYPE_BGP, bgp->snmp_stats); + XFREE(MTYPE_BGP_NAME, bgp->snmp_stats); bgp->snmp_stats = NULL; } } diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index e235a61f59..e07b18f8fd 100644 --- a/bgpd/bgp_network.c +++ b/bgpd/bgp_network.c @@ -35,7 +35,7 @@ extern struct zebra_privs_t bgpd_privs; -static char *bgp_get_bound_name(struct peer *peer); +static char *bgp_get_bound_name(struct peer_connection *connection); void bgp_dump_listener_info(struct vty *vty) { @@ -117,11 +117,13 @@ static int bgp_md5_set_connect(int socket, union sockunion *su, return ret; } -static int bgp_md5_set_password(struct peer *peer, const char *password) +static int bgp_md5_set_password(struct peer_connection *connection, + const char *password) { struct listnode *node; int ret = 0; struct bgp_listener *listener; + struct peer *peer = connection->peer; /* * Set or unset the password on the listen socket(s). Outbound @@ -130,9 +132,9 @@ static int bgp_md5_set_password(struct peer *peer, const char *password) frr_with_privs(&bgpd_privs) { for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) if (listener->su.sa.sa_family == - peer->su.sa.sa_family) { + connection->su.sa.sa_family) { uint16_t prefixlen = - peer->su.sa.sa_family == AF_INET + connection->su.sa.sa_family == AF_INET ? IPV4_MAX_BITLEN : IPV6_MAX_BITLEN; @@ -149,8 +151,8 @@ static int bgp_md5_set_password(struct peer *peer, const char *password) continue; ret = bgp_md5_set_socket(listener->fd, - &peer->su, prefixlen, - password); + &connection->su, + prefixlen, password); break; } } @@ -186,10 +188,10 @@ int bgp_md5_unset_prefix(struct bgp *bgp, struct prefix *p) return bgp_md5_set_prefix(bgp, p, NULL); } -int bgp_md5_set(struct peer *peer) +int bgp_md5_set(struct peer_connection *connection) { /* Set the password from listen socket. */ - return bgp_md5_set_password(peer, peer->password); + return bgp_md5_set_password(connection, connection->peer->password); } static void bgp_update_setsockopt_tcp_keepalive(struct bgp *bgp, int fd) @@ -211,18 +213,20 @@ static void bgp_update_setsockopt_tcp_keepalive(struct bgp *bgp, int fd) } } -int bgp_md5_unset(struct peer *peer) +int bgp_md5_unset(struct peer_connection *connection) { /* Unset the password from listen socket. */ - return bgp_md5_set_password(peer, NULL); + return bgp_md5_set_password(connection, NULL); } -int bgp_set_socket_ttl(struct peer *peer, int bgp_sock) +int bgp_set_socket_ttl(struct peer_connection *connection) { int ret = 0; + struct peer *peer = connection->peer; if (!peer->gtsm_hops) { - ret = sockopt_ttl(peer->su.sa.sa_family, bgp_sock, peer->ttl); + ret = sockopt_ttl(connection->su.sa.sa_family, connection->fd, + peer->ttl); if (ret) { flog_err( EC_LIB_SOCKET, @@ -235,7 +239,8 @@ int bgp_set_socket_ttl(struct peer *peer, int bgp_sock) with the outgoing ttl. Therefore setting both. */ - ret = sockopt_ttl(peer->su.sa.sa_family, bgp_sock, MAXTTL); + ret = sockopt_ttl(connection->su.sa.sa_family, connection->fd, + MAXTTL); if (ret) { flog_err( EC_LIB_SOCKET, @@ -243,7 +248,7 @@ int bgp_set_socket_ttl(struct peer *peer, int bgp_sock) __func__, &peer->remote_id, errno); return ret; } - ret = sockopt_minttl(peer->su.sa.sa_family, bgp_sock, + ret = sockopt_minttl(connection->su.sa.sa_family, connection->fd, MAXTTL + 1 - peer->gtsm_hops); if (ret) { flog_err( @@ -329,6 +334,53 @@ static int bgp_get_instance_for_inc_conn(int sock, struct bgp **bgp_inst) #endif } +int bgp_tcp_mss_set(struct peer *peer) +{ + struct listnode *node; + int ret = 0; + struct bgp_listener *listener; + uint32_t min_mss = 0; + struct peer *p; + + for (ALL_LIST_ELEMENTS_RO(peer->bgp->peer, node, p)) { + if (!CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) + continue; + + if (!p->tcp_mss) + continue; + + if (!min_mss) + min_mss = p->tcp_mss; + + min_mss = MIN(min_mss, p->tcp_mss); + } + + frr_with_privs(&bgpd_privs) { + for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) { + if (listener->su.sa.sa_family != + peer->connection->su.sa.sa_family) + continue; + + if (!listener->bgp) { + if (peer->bgp->vrf_id != VRF_DEFAULT) + continue; + } else if (listener->bgp != peer->bgp) + continue; + + /* Set TCP MSS per listener only if there is at least + * one peer that is in passive mode. Otherwise, TCP MSS + * is set per socket via bgp_connect(). + */ + if (CHECK_FLAG(peer->flags, PEER_FLAG_PASSIVE)) + sockopt_tcp_mss_set(listener->fd, min_mss); + + break; + } + } + + return ret; +} + static void bgp_socket_set_buffer_size(const int fd) { if (getsockopt_so_sendbuf(fd) < (int)bm->socket_buffer) @@ -344,8 +396,8 @@ static void bgp_accept(struct event *thread) int accept_sock; union sockunion su; struct bgp_listener *listener = EVENT_ARG(thread); - struct peer *peer; - struct peer *peer1; + struct peer *peer, *peer1; + struct peer_connection *connection, *connection1; char buf[SU_ADDRSTRLEN]; struct bgp *bgp = NULL; @@ -428,25 +480,24 @@ static void bgp_accept(struct event *thread) if (!peer1) { peer1 = peer_lookup_dynamic_neighbor(bgp, &su); if (peer1) { + connection1 = peer1->connection; /* Dynamic neighbor has been created, let it proceed */ - peer1->fd = bgp_sock; + connection1->fd = bgp_sock; /* Set the user configured MSS to TCP socket */ if (CHECK_FLAG(peer1->flags, PEER_FLAG_TCP_MSS)) sockopt_tcp_mss_set(bgp_sock, peer1->tcp_mss); - bgp_fsm_change_status(peer1, Active); - EVENT_OFF( - peer1->t_start); /* created in peer_create() */ + bgp_fsm_change_status(connection1, Active); + EVENT_OFF(connection1->t_start); if (peer_active(peer1)) { if (CHECK_FLAG(peer1->flags, PEER_FLAG_TIMER_DELAYOPEN)) - BGP_EVENT_ADD( - peer1, - TCP_connection_open_w_delay); + BGP_EVENT_ADD(connection1, + TCP_connection_open_w_delay); else - BGP_EVENT_ADD(peer1, + BGP_EVENT_ADD(connection1, TCP_connection_open); } @@ -465,6 +516,7 @@ static void bgp_accept(struct event *thread) return; } + connection1 = peer1->connection; if (CHECK_FLAG(peer1->flags, PEER_FLAG_SHUTDOWN) || CHECK_FLAG(peer1->bgp->flags, BGP_FLAG_SHUTDOWN)) { if (bgp_debug_neighbor_events(peer1)) @@ -482,11 +534,11 @@ static void bgp_accept(struct event *thread) * Established and then the Clearing_Completed event is generated. Also, * block incoming connection in Deleted state. */ - if (peer1->status == Clearing || peer1->status == Deleted) { + if (connection1->status == Clearing || connection1->status == Deleted) { if (bgp_debug_neighbor_events(peer1)) - zlog_debug( - "[Event] Closing incoming conn for %s (%p) state %d", - peer1->host, peer1, peer1->status); + zlog_debug("[Event] Closing incoming conn for %s (%p) state %d", + peer1->host, peer1, + peer1->connection->status); close(bgp_sock); return; } @@ -521,10 +573,9 @@ static void bgp_accept(struct event *thread) } if (bgp_debug_neighbor_events(peer1)) - zlog_debug( - "[Event] connection from %s fd %d, active peer status %d fd %d", - inet_sutop(&su, buf), bgp_sock, peer1->status, - peer1->fd); + zlog_debug("[Event] connection from %s fd %d, active peer status %d fd %d", + inet_sutop(&su, buf), bgp_sock, connection1->status, + connection1->fd); if (peer1->doppelganger) { /* We have an existing connection. Kill the existing one and run @@ -537,15 +588,11 @@ static void bgp_accept(struct event *thread) peer_delete(peer1->doppelganger); } - if (bgp_set_socket_ttl(peer1, bgp_sock) < 0) - if (bgp_debug_neighbor_events(peer1)) - zlog_debug( - "[Event] Unable to set min/max TTL on peer %s, Continuing", - peer1->host); - peer = peer_create(&su, peer1->conf_if, peer1->bgp, peer1->local_as, peer1->as, peer1->as_type, NULL, false, NULL); + connection = peer->connection; + peer_xfer_config(peer, peer1); bgp_peer_gr_flags_update(peer); @@ -563,18 +610,25 @@ static void bgp_accept(struct event *thread) peer->doppelganger = peer1; peer1->doppelganger = peer; - peer->fd = bgp_sock; + connection->fd = bgp_sock; + + if (bgp_set_socket_ttl(connection) < 0) + if (bgp_debug_neighbor_events(peer)) + zlog_debug("[Event] Unable to set min/max TTL on peer %s, Continuing", + peer->host); + frr_with_privs(&bgpd_privs) { - vrf_bind(peer->bgp->vrf_id, bgp_sock, bgp_get_bound_name(peer)); + vrf_bind(peer->bgp->vrf_id, bgp_sock, + bgp_get_bound_name(peer->connection)); } bgp_peer_reg_with_nht(peer); - bgp_fsm_change_status(peer, Active); - EVENT_OFF(peer->t_start); /* created in peer_create() */ + bgp_fsm_change_status(connection, Active); + EVENT_OFF(connection->t_start); /* created in peer_create() */ SET_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER); /* Make dummy peer until read Open packet. */ - if (peer_established(peer1) - && CHECK_FLAG(peer1->sflags, PEER_STATUS_NSF_MODE)) { + if (peer_established(connection1) && + CHECK_FLAG(peer1->sflags, PEER_STATUS_NSF_MODE)) { /* If we have an existing established connection with graceful * restart * capability announced with one or more address families, then @@ -588,14 +642,14 @@ static void bgp_accept(struct event *thread) PEER_FLAG_GRACEFUL_RESTART_HELPER)) SET_FLAG(peer1->sflags, PEER_STATUS_NSF_WAIT); - bgp_event_update(peer1, TCP_connection_closed); + bgp_event_update(connection1, TCP_connection_closed); } if (peer_active(peer)) { if (CHECK_FLAG(peer->flags, PEER_FLAG_TIMER_DELAYOPEN)) - BGP_EVENT_ADD(peer, TCP_connection_open_w_delay); + BGP_EVENT_ADD(connection, TCP_connection_open_w_delay); else - BGP_EVENT_ADD(peer, TCP_connection_open); + BGP_EVENT_ADD(connection, TCP_connection_open); } /* @@ -606,24 +660,23 @@ static void bgp_accept(struct event *thread) } /* BGP socket bind. */ -static char *bgp_get_bound_name(struct peer *peer) +static char *bgp_get_bound_name(struct peer_connection *connection) { - if (!peer) - return NULL; + struct peer *peer = connection->peer; if ((peer->bgp->vrf_id == VRF_DEFAULT) && !peer->ifname && !peer->conf_if) return NULL; - if (peer->su.sa.sa_family != AF_INET - && peer->su.sa.sa_family != AF_INET6) + if (connection->su.sa.sa_family != AF_INET && + connection->su.sa.sa_family != AF_INET6) return NULL; // unexpected /* For IPv6 peering, interface (unnumbered or link-local with interface) * takes precedence over VRF. For IPv4 peering, explicit interface or * VRF are the situations to bind. */ - if (peer->su.sa.sa_family == AF_INET6 && peer->conf_if) + if (connection->su.sa.sa_family == AF_INET6 && peer->conf_if) return peer->conf_if; if (peer->ifname) @@ -640,7 +693,6 @@ int bgp_update_address(struct interface *ifp, const union sockunion *dst, { struct prefix *p, *sel, d; struct connected *connected; - struct listnode *node; int common; if (!sockunion2hostprefix(dst, &d)) @@ -649,7 +701,7 @@ int bgp_update_address(struct interface *ifp, const union sockunion *dst, sel = NULL; common = -1; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) { + frr_each (if_connected, ifp->connected, connected) { p = connected->address; if (p->family != d.family) continue; @@ -667,11 +719,12 @@ int bgp_update_address(struct interface *ifp, const union sockunion *dst, } /* Update source selection. */ -static int bgp_update_source(struct peer *peer) +static int bgp_update_source(struct peer_connection *connection) { struct interface *ifp; union sockunion addr; int ret = 0; + struct peer *peer = connection->peer; sockunion_init(&addr); @@ -681,38 +734,41 @@ static int bgp_update_source(struct peer *peer) if (!ifp) return -1; - if (bgp_update_address(ifp, &peer->su, &addr)) + if (bgp_update_address(ifp, &connection->su, &addr)) return -1; - ret = sockunion_bind(peer->fd, &addr, 0, &addr); + ret = sockunion_bind(connection->fd, &addr, 0, &addr); } /* Source is specified with IP address. */ if (peer->update_source) - ret = sockunion_bind(peer->fd, peer->update_source, 0, + ret = sockunion_bind(connection->fd, peer->update_source, 0, peer->update_source); return ret; } /* BGP try to connect to the peer. */ -int bgp_connect(struct peer *peer) +int bgp_connect(struct peer_connection *connection) { - assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_WRITES_ON)); - assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_READS_ON)); + struct peer *peer = connection->peer; + + assert(!CHECK_FLAG(connection->thread_flags, PEER_THREAD_WRITES_ON)); + assert(!CHECK_FLAG(connection->thread_flags, PEER_THREAD_READS_ON)); ifindex_t ifindex = 0; - if (peer->conf_if && BGP_PEER_SU_UNSPEC(peer)) { + if (peer->conf_if && BGP_CONNECTION_SU_UNSPEC(connection)) { if (bgp_debug_neighbor_events(peer)) zlog_debug("Peer address not learnt: Returning from connect"); return 0; } frr_with_privs(&bgpd_privs) { - /* Make socket for the peer. */ - peer->fd = vrf_sockunion_socket(&peer->su, peer->bgp->vrf_id, - bgp_get_bound_name(peer)); + /* Make socket for the peer. */ + connection->fd = + vrf_sockunion_socket(&connection->su, peer->bgp->vrf_id, + bgp_get_bound_name(connection)); } - if (peer->fd < 0) { + if (connection->fd < 0) { peer->last_reset = PEER_DOWN_SOCKET_ERROR; if (bgp_debug_neighbor_events(peer)) zlog_debug("%s: Failure to create socket for connection to %s, error received: %s(%d)", @@ -721,18 +777,18 @@ int bgp_connect(struct peer *peer) return -1; } - set_nonblocking(peer->fd); + set_nonblocking(connection->fd); /* Set the user configured MSS to TCP socket */ if (CHECK_FLAG(peer->flags, PEER_FLAG_TCP_MSS)) - sockopt_tcp_mss_set(peer->fd, peer->tcp_mss); + sockopt_tcp_mss_set(connection->fd, peer->tcp_mss); - bgp_socket_set_buffer_size(peer->fd); + bgp_socket_set_buffer_size(connection->fd); /* Set TCP keepalive when TCP keepalive is enabled */ - bgp_update_setsockopt_tcp_keepalive(peer->bgp, peer->fd); + bgp_update_setsockopt_tcp_keepalive(peer->bgp, connection->fd); - if (bgp_set_socket_ttl(peer, peer->fd) < 0) { + if (bgp_set_socket_ttl(peer->connection) < 0) { peer->last_reset = PEER_DOWN_SOCKET_ERROR; if (bgp_debug_neighbor_events(peer)) zlog_debug("%s: Failure to set socket ttl for connection to %s, error received: %s(%d)", @@ -742,36 +798,42 @@ int bgp_connect(struct peer *peer) return -1; } - sockopt_reuseaddr(peer->fd); - sockopt_reuseport(peer->fd); + sockopt_reuseaddr(connection->fd); + sockopt_reuseport(connection->fd); #ifdef IPTOS_PREC_INTERNETCONTROL frr_with_privs(&bgpd_privs) { - if (sockunion_family(&peer->su) == AF_INET) - setsockopt_ipv4_tos(peer->fd, bm->tcp_dscp); - else if (sockunion_family(&peer->su) == AF_INET6) - setsockopt_ipv6_tclass(peer->fd, bm->tcp_dscp); + if (sockunion_family(&connection->su) == AF_INET) + setsockopt_ipv4_tos(connection->fd, bm->tcp_dscp); + else if (sockunion_family(&connection->su) == AF_INET6) + setsockopt_ipv6_tclass(connection->fd, bm->tcp_dscp); } #endif if (peer->password) { - uint16_t prefixlen = peer->su.sa.sa_family == AF_INET + uint16_t prefixlen = peer->connection->su.sa.sa_family == AF_INET ? IPV4_MAX_BITLEN : IPV6_MAX_BITLEN; - if (!BGP_PEER_SU_UNSPEC(peer)) - bgp_md5_set(peer); + if (!BGP_CONNECTION_SU_UNSPEC(connection)) + bgp_md5_set(connection); - bgp_md5_set_connect(peer->fd, &peer->su, prefixlen, + bgp_md5_set_connect(connection->fd, &connection->su, prefixlen, peer->password); } /* Update source bind. */ - if (bgp_update_source(peer) < 0) { + if (bgp_update_source(connection) < 0) { peer->last_reset = PEER_DOWN_SOCKET_ERROR; return connect_error; } + /* If the peer is passive mode, force to move to Active mode. */ + if (CHECK_FLAG(peer->flags, PEER_FLAG_PASSIVE)) { + BGP_EVENT_ADD(connection, TCP_connection_open_failed); + return BGP_FSM_SUCCESS; + } + if (peer->conf_if || peer->ifname) ifindex = ifname2ifindex(peer->conf_if ? peer->conf_if : peer->ifname, @@ -779,11 +841,11 @@ int bgp_connect(struct peer *peer) if (bgp_debug_neighbor_events(peer)) zlog_debug("%s [Event] Connect start to %s fd %d", peer->host, - peer->host, peer->fd); + peer->host, connection->fd); /* Connect to the remote peer. */ - return sockunion_connect(peer->fd, &peer->su, htons(peer->port), - ifindex); + return sockunion_connect(connection->fd, &connection->su, + htons(peer->port), ifindex); } /* After TCP connection is established. Get local address and port. */ @@ -799,10 +861,10 @@ int bgp_getsockname(struct peer *peer) peer->su_remote = NULL; } - peer->su_local = sockunion_getsockname(peer->fd); + peer->su_local = sockunion_getsockname(peer->connection->fd); if (!peer->su_local) return -1; - peer->su_remote = sockunion_getpeername(peer->fd); + peer->su_remote = sockunion_getpeername(peer->connection->fd); if (!peer->su_remote) return -1; @@ -810,8 +872,9 @@ int bgp_getsockname(struct peer *peer) &peer->nexthop, peer)) { flog_err( EC_BGP_NH_UPD, - "%s: nexthop_set failed, resetting connection - intf %s", - peer->host, + "%s: nexthop_set failed, local: %pSUp remote: %pSUp update_if: %s resetting connection - intf %s", + peer->host, peer->su_local, peer->su_remote, + peer->update_if ? peer->update_if : "(None)", peer->nexthop.ifp ? peer->nexthop.ifp->name : "(Unknown)"); return -1; diff --git a/bgpd/bgp_network.h b/bgpd/bgp_network.h index cf0b4362c5..7a0b3cc67d 100644 --- a/bgpd/bgp_network.h +++ b/bgpd/bgp_network.h @@ -21,15 +21,16 @@ extern int bgp_socket(struct bgp *bgp, unsigned short port, const char *address); extern void bgp_close_vrf_socket(struct bgp *bgp); extern void bgp_close(void); -extern int bgp_connect(struct peer *); -extern int bgp_getsockname(struct peer *); +extern int bgp_connect(struct peer_connection *connection); +extern int bgp_getsockname(struct peer *peer); extern int bgp_md5_set_prefix(struct bgp *bgp, struct prefix *p, const char *password); extern int bgp_md5_unset_prefix(struct bgp *bgp, struct prefix *p); -extern int bgp_md5_set(struct peer *); -extern int bgp_md5_unset(struct peer *); -extern int bgp_set_socket_ttl(struct peer *, int fd); +extern int bgp_md5_set(struct peer_connection *connection); +extern int bgp_md5_unset(struct peer_connection *connection); +extern int bgp_set_socket_ttl(struct peer_connection *connection); +extern int bgp_tcp_mss_set(struct peer *peer); extern int bgp_update_address(struct interface *ifp, const union sockunion *dst, union sockunion *addr); diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index c878512389..d12dc22330 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -43,9 +43,9 @@ int bgp_nexthop_cache_compare(const struct bgp_nexthop_cache *a, if (a->srte_color > b->srte_color) return 1; - if (a->ifindex < b->ifindex) + if (a->ifindex_ipv6_ll < b->ifindex_ipv6_ll) return -1; - if (a->ifindex > b->ifindex) + if (a->ifindex_ipv6_ll > b->ifindex_ipv6_ll) return 1; return prefix_cmp(&a->prefix, &b->prefix); @@ -65,7 +65,7 @@ struct bgp_nexthop_cache *bnc_new(struct bgp_nexthop_cache_head *tree, bnc = XCALLOC(MTYPE_BGP_NEXTHOP_CACHE, sizeof(struct bgp_nexthop_cache)); bnc->prefix = *prefix; - bnc->ifindex = ifindex; + bnc->ifindex_ipv6_ll = ifindex; bnc->srte_color = srte_color; bnc->tree = tree; LIST_INIT(&(bnc->paths)); @@ -105,7 +105,7 @@ struct bgp_nexthop_cache *bnc_find(struct bgp_nexthop_cache_head *tree, bnc.prefix = *prefix; bnc.srte_color = srte_color; - bnc.ifindex = ifindex; + bnc.ifindex_ipv6_ll = ifindex; return bgp_nexthop_cache_find(tree, &bnc); } @@ -121,6 +121,7 @@ static void bgp_nexthop_cache_reset(struct bgp_nexthop_cache_head *tree) struct bgp_path_info *path = LIST_FIRST(&(bnc->paths)); bgp_mplsvpn_path_nh_label_unlink(path); + bgp_mplsvpn_path_nh_label_bind_unlink(path); path_nh_map(path, bnc, false); } @@ -384,6 +385,7 @@ void bgp_connected_add(struct bgp *bgp, struct connected *ifc) struct bgp_connected_ref *bc; struct listnode *node, *nnode; struct peer *peer; + struct peer_connection *connection; addr = ifc->address; @@ -408,14 +410,14 @@ void bgp_connected_add(struct bgp *bgp, struct connected *ifc) } for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { - if (peer->conf_if - && (strcmp(peer->conf_if, ifc->ifp->name) == 0) - && !peer_established(peer) - && !CHECK_FLAG(peer->flags, - PEER_FLAG_IFPEER_V6ONLY)) { + if (peer->conf_if && + (strcmp(peer->conf_if, ifc->ifp->name) == 0) && + !peer_established(peer->connection) && + !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY)) { + connection = peer->connection; if (peer_active(peer)) - BGP_EVENT_ADD(peer, BGP_Stop); - BGP_EVENT_ADD(peer, BGP_Start); + BGP_EVENT_ADD(connection, BGP_Stop); + BGP_EVENT_ADD(connection, BGP_Start); } } } else if (addr->family == AF_INET6) { @@ -482,7 +484,9 @@ void bgp_connected_delete(struct bgp *bgp, struct connected *ifc) XFREE(MTYPE_BGP_CONN, bc); bgp_dest_set_bgp_connected_ref_info(dest, NULL); } - bgp_dest_unlock_node(dest); + + dest = bgp_dest_unlock_node(dest); + assert(dest); bgp_dest_unlock_node(dest); } @@ -593,7 +597,7 @@ bool bgp_multiaccess_check_v4(struct in_addr nexthop, struct peer *peer) p.family = AF_INET; p.prefixlen = IPV4_MAX_BITLEN; - p.u.prefix4 = peer->su.sin.sin_addr; + p.u.prefix4 = peer->connection->su.sin.sin_addr; dest2 = bgp_node_match(peer->bgp->connected_table[AFI_IP], &p); if (!dest2) { @@ -626,7 +630,7 @@ bool bgp_multiaccess_check_v6(struct in6_addr nexthop, struct peer *peer) p.family = AF_INET6; p.prefixlen = IPV6_MAX_BITLEN; - p.u.prefix6 = peer->su.sin6.sin6_addr; + p.u.prefix6 = peer->connection->su.sin6.sin6_addr; dest2 = bgp_node_match(peer->bgp->connected_table[AFI_IP6], &p); if (!dest2) { @@ -668,7 +672,7 @@ bool bgp_subgrp_multiaccess_check_v6(struct in6_addr nexthop, if (paf->peer == exclude) continue; - p.u.prefix6 = paf->peer->su.sin6.sin6_addr; + p.u.prefix6 = paf->peer->connection->su.sin6.sin6_addr; dest2 = bgp_node_match(bgp->connected_table[AFI_IP6], &p); if (dest1 == dest2) { bgp_dest_unlock_node(dest1); @@ -710,7 +714,7 @@ bool bgp_subgrp_multiaccess_check_v4(struct in_addr nexthop, if (paf->peer == exclude) continue; - p.u.prefix4 = paf->peer->su.sin.sin_addr; + p.u.prefix4 = paf->peer->connection->su.sin.sin_addr; dest2 = bgp_node_match(bgp->connected_table[AFI_IP], &p); if (dest1 == dest2) { @@ -857,8 +861,9 @@ static void bgp_show_nexthops_detail(struct vty *vty, struct bgp *bgp, json_object_string_add( json_gate, "interfaceName", ifindex2ifname( - bnc->ifindex ? bnc->ifindex - : nexthop->ifindex, + bnc->ifindex_ipv6_ll + ? bnc->ifindex_ipv6_ll + : nexthop->ifindex, bgp->vrf_id)); break; case NEXTHOP_TYPE_IPV4: @@ -869,8 +874,9 @@ static void bgp_show_nexthops_detail(struct vty *vty, struct bgp *bgp, json_object_string_add( json_gate, "interfaceName", ifindex2ifname( - bnc->ifindex ? bnc->ifindex - : nexthop->ifindex, + bnc->ifindex_ipv6_ll + ? bnc->ifindex_ipv6_ll + : nexthop->ifindex, bgp->vrf_id)); break; case NEXTHOP_TYPE_IPV4_IFINDEX: @@ -879,8 +885,9 @@ static void bgp_show_nexthops_detail(struct vty *vty, struct bgp *bgp, json_object_string_add( json_gate, "interfaceName", ifindex2ifname( - bnc->ifindex ? bnc->ifindex - : nexthop->ifindex, + bnc->ifindex_ipv6_ll + ? bnc->ifindex_ipv6_ll + : nexthop->ifindex, bgp->vrf_id)); break; case NEXTHOP_TYPE_BLACKHOLE: @@ -914,9 +921,9 @@ static void bgp_show_nexthops_detail(struct vty *vty, struct bgp *bgp, case NEXTHOP_TYPE_IPV6_IFINDEX: vty_out(vty, " gate %pI6", &nexthop->gate.ipv6); if (nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX && - bnc->ifindex) + bnc->ifindex_ipv6_ll) vty_out(vty, ", if %s\n", - ifindex2ifname(bnc->ifindex, + ifindex2ifname(bnc->ifindex_ipv6_ll, bgp->vrf_id)); else if (nexthop->ifindex) vty_out(vty, ", if %s\n", @@ -929,9 +936,9 @@ static void bgp_show_nexthops_detail(struct vty *vty, struct bgp *bgp, case NEXTHOP_TYPE_IPV4_IFINDEX: vty_out(vty, " gate %pI4", &nexthop->gate.ipv4); if (nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX && - bnc->ifindex) + bnc->ifindex_ipv6_ll) vty_out(vty, ", if %s\n", - ifindex2ifname(bnc->ifindex, + ifindex2ifname(bnc->ifindex_ipv6_ll, bgp->vrf_id)); else if (nexthop->ifindex) vty_out(vty, ", if %s\n", @@ -942,8 +949,9 @@ static void bgp_show_nexthops_detail(struct vty *vty, struct bgp *bgp, break; case NEXTHOP_TYPE_IFINDEX: vty_out(vty, " if %s\n", - ifindex2ifname(bnc->ifindex ? bnc->ifindex - : nexthop->ifindex, + ifindex2ifname(bnc->ifindex_ipv6_ll + ? bnc->ifindex_ipv6_ll + : nexthop->ifindex, bgp->vrf_id)); break; case NEXTHOP_TYPE_BLACKHOLE: @@ -964,6 +972,7 @@ static void bgp_show_nexthop(struct vty *vty, struct bgp *bgp, { char buf[PREFIX2STR_BUFFER]; time_t tbuf; + char timebuf[32]; struct peer *peer; json_object *json_last_update = NULL; json_object *json_nexthop = NULL; @@ -1062,14 +1071,14 @@ static void bgp_show_nexthop(struct vty *vty, struct bgp *bgp, json_last_update = json_object_new_object(); json_object_int_add(json_last_update, "epoch", tbuf); json_object_string_add(json_last_update, "string", - ctime(&tbuf)); + ctime_r(&tbuf, timebuf)); json_object_object_add(json_nexthop, "lastUpdate", json_last_update); } else { json_object_int_add(json_nexthop, "lastUpdate", tbuf); } } else { - vty_out(vty, " Last update: %s", ctime(&tbuf)); + vty_out(vty, " Last update: %s", ctime_r(&tbuf, timebuf)); } /* show paths dependent on nexthop, if needed. */ diff --git a/bgpd/bgp_nexthop.h b/bgpd/bgp_nexthop.h index 95e2f9165b..90e0074e35 100644 --- a/bgpd/bgp_nexthop.h +++ b/bgpd/bgp_nexthop.h @@ -26,8 +26,10 @@ PREDECL_RBTREE_UNIQ(bgp_nexthop_cache); /* BGP nexthop cache value structure. */ struct bgp_nexthop_cache { + afi_t afi; + /* The ifindex of the outgoing interface *if* it's a v6 LL */ - ifindex_t ifindex; + ifindex_t ifindex_ipv6_ll; /* RB-tree entry. */ struct bgp_nexthop_cache_item entry; @@ -104,11 +106,6 @@ struct tip_addr { int refcnt; }; -struct bgp_addrv6 { - struct in6_addr addrv6; - struct list *ifp_name_list; -}; - /* Forward declaration(s). */ struct peer; struct update_subgroup; diff --git a/bgpd/bgp_nhg.c b/bgpd/bgp_nhg.c new file mode 100644 index 0000000000..bf0ba77444 --- /dev/null +++ b/bgpd/bgp_nhg.c @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* BGP Nexthop Group Support + * Copyright (C) 2023 NVIDIA Corporation + * Copyright (C) 2023 6WIND + */ + +#include + +#include +#include +#include + + +/**************************************************************************** + * L3 NHGs are used for fast failover of nexthops in the dplane. These are + * the APIs for allocating L3 NHG ids. Management of the L3 NHG itself is + * left to the application using it. + * PS: Currently EVPN host routes is the only app using L3 NHG for fast + * failover of remote ES links. + ***************************************************************************/ +static bitfield_t bgp_nh_id_bitmap; +static uint32_t bgp_nhg_start; + +/* XXX - currently we do nothing on the callbacks */ +static void bgp_nhg_add_cb(const char *name) +{ +} + +static void bgp_nhg_modify_cb(const struct nexthop_group_cmd *nhgc) +{ +} + +static void bgp_nhg_add_nexthop_cb(const struct nexthop_group_cmd *nhgc, + const struct nexthop *nhop) +{ +} + +static void bgp_nhg_del_nexthop_cb(const struct nexthop_group_cmd *nhgc, + const struct nexthop *nhop) +{ +} + +static void bgp_nhg_del_cb(const char *name) +{ +} + +static void bgp_nhg_zebra_init(void) +{ + static bool bgp_nhg_zebra_inited; + + if (bgp_nhg_zebra_inited) + return; + + bgp_nhg_zebra_inited = true; + bgp_nhg_start = zclient_get_nhg_start(ZEBRA_ROUTE_BGP); + nexthop_group_init(bgp_nhg_add_cb, bgp_nhg_modify_cb, + bgp_nhg_add_nexthop_cb, bgp_nhg_del_nexthop_cb, + bgp_nhg_del_cb); +} + +void bgp_nhg_init(void) +{ + uint32_t id_max; + + id_max = MIN(ZEBRA_NHG_PROTO_SPACING - 1, 16 * 1024); + bf_init(bgp_nh_id_bitmap, id_max); + bf_assign_zero_index(bgp_nh_id_bitmap); + + if (BGP_DEBUG(nht, NHT) || BGP_DEBUG(evpn_mh, EVPN_MH_ES)) + zlog_debug("bgp nhg range %u - %u", bgp_nhg_start + 1, + bgp_nhg_start + id_max); +} + +void bgp_nhg_finish(void) +{ + bf_free(bgp_nh_id_bitmap); +} + +uint32_t bgp_nhg_id_alloc(void) +{ + uint32_t nhg_id = 0; + + bgp_nhg_zebra_init(); + bf_assign_index(bgp_nh_id_bitmap, nhg_id); + if (nhg_id) + nhg_id += bgp_nhg_start; + + return nhg_id; +} + +void bgp_nhg_id_free(uint32_t nhg_id) +{ + if (!nhg_id || (nhg_id <= bgp_nhg_start)) + return; + + nhg_id -= bgp_nhg_start; + + bf_release_index(bgp_nh_id_bitmap, nhg_id); +} diff --git a/bgpd/bgp_nhg.h b/bgpd/bgp_nhg.h new file mode 100644 index 0000000000..370e8ab091 --- /dev/null +++ b/bgpd/bgp_nhg.h @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* BGP Nexthop Group Support + * Copyright (C) 2023 NVIDIA Corporation + * Copyright (C) 2023 6WIND + */ + +#ifndef _BGP_NHG_H +#define _BGP_NHG_H + +#include "nexthop_group.h" + +/* APIs for setting up and allocating L3 nexthop group ids */ +extern uint32_t bgp_nhg_id_alloc(void); +extern void bgp_nhg_id_free(uint32_t nhg_id); +extern void bgp_nhg_init(void); +void bgp_nhg_finish(void); + +#endif /* _BGP_NHG_H */ diff --git a/bgpd/bgp_nht.c b/bgpd/bgp_nht.c index bda163d7a5..05fd0dc4e7 100644 --- a/bgpd/bgp_nht.c +++ b/bgpd/bgp_nht.c @@ -32,6 +32,7 @@ #include "bgpd/bgp_evpn.h" #include "bgpd/bgp_rd.h" #include "bgpd/bgp_mplsvpn.h" +#include "bgpd/bgp_ecommunity.h" extern struct zclient *zclient; @@ -55,10 +56,11 @@ static int bgp_isvalid_nexthop_for_ebgp(struct bgp_nexthop_cache *bnc, struct bgp_interface *iifp; struct peer *peer; - if (!path->extra || !path->extra->peer_orig) + if (!path->extra || !path->extra->vrfleak || + !path->extra->vrfleak->peer_orig) return false; - peer = path->extra->peer_orig; + peer = path->extra->vrfleak->peer_orig; /* only connected ebgp peers are valid */ if (peer->sort != BGP_PEER_EBGP || peer->ttl != BGP_DEFAULT_TTL || @@ -70,9 +72,10 @@ static int bgp_isvalid_nexthop_for_ebgp(struct bgp_nexthop_cache *bnc, if (nexthop->type == NEXTHOP_TYPE_IFINDEX || nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX || nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX) { - ifp = if_lookup_by_index( - bnc->ifindex ? bnc->ifindex : nexthop->ifindex, - bnc->bgp->vrf_id); + ifp = if_lookup_by_index(bnc->ifindex_ipv6_ll + ? bnc->ifindex_ipv6_ll + : nexthop->ifindex, + bnc->bgp->vrf_id); } if (!ifp) continue; @@ -91,9 +94,10 @@ static int bgp_isvalid_nexthop_for_mplsovergre(struct bgp_nexthop_cache *bnc, for (nexthop = bnc->nexthop; nexthop; nexthop = nexthop->next) { if (nexthop->type != NEXTHOP_TYPE_BLACKHOLE) { - ifp = if_lookup_by_index( - bnc->ifindex ? bnc->ifindex : nexthop->ifindex, - bnc->bgp->vrf_id); + ifp = if_lookup_by_index(bnc->ifindex_ipv6_ll + ? bnc->ifindex_ipv6_ll + : nexthop->ifindex, + bnc->bgp->vrf_id); if (ifp && (ifp->ll_type == ZEBRA_LLT_IPGRE || ifp->ll_type == ZEBRA_LLT_IP6GRE)) break; @@ -137,8 +141,8 @@ static void bgp_unlink_nexthop_check(struct bgp_nexthop_cache *bnc) if (LIST_EMPTY(&(bnc->paths)) && !bnc->nht_info) { if (BGP_DEBUG(nht, NHT)) zlog_debug("%s: freeing bnc %pFX(%d)(%u)(%s)", __func__, - &bnc->prefix, bnc->ifindex, bnc->srte_color, - bnc->bgp->name_pretty); + &bnc->prefix, bnc->ifindex_ipv6_ll, + bnc->srte_color, bnc->bgp->name_pretty); /* only unregister if this is the last nh for this prefix*/ if (!bnc_existing_for_prefix(bnc)) unregister_zebra_rnh(bnc); @@ -151,6 +155,7 @@ void bgp_unlink_nexthop(struct bgp_path_info *path) struct bgp_nexthop_cache *bnc = path->nexthop; bgp_mplsvpn_path_nh_label_unlink(path); + bgp_mplsvpn_path_nh_label_bind_unlink(path); if (!bnc) return; @@ -168,20 +173,21 @@ void bgp_replace_nexthop_by_peer(struct peer *from, struct peer *to) afi_t afi; ifindex_t ifindex = 0; - if (!sockunion2hostprefix(&from->su, &pp)) + if (!sockunion2hostprefix(&from->connection->su, &pp)) return; /* * Gather the ifindex for if up/down events to be * tagged into this fun */ - if (from->conf_if && IN6_IS_ADDR_LINKLOCAL(&from->su.sin6.sin6_addr)) - ifindex = from->su.sin6.sin6_scope_id; + if (from->conf_if && + IN6_IS_ADDR_LINKLOCAL(&from->connection->su.sin6.sin6_addr)) + ifindex = from->connection->su.sin6.sin6_scope_id; afi = family2afi(pp.family); bncp = bnc_find(&from->bgp->nexthop_cache_table[afi], &pp, 0, ifindex); - if (!sockunion2hostprefix(&to->su, &pt)) + if (!sockunion2hostprefix(&to->connection->su, &pt)) return; /* @@ -189,8 +195,9 @@ void bgp_replace_nexthop_by_peer(struct peer *from, struct peer *to) * tagged into this fun */ ifindex = 0; - if (to->conf_if && IN6_IS_ADDR_LINKLOCAL(&to->su.sin6.sin6_addr)) - ifindex = to->su.sin6.sin6_scope_id; + if (to->conf_if && + IN6_IS_ADDR_LINKLOCAL(&to->connection->su.sin6.sin6_addr)) + ifindex = to->connection->su.sin6.sin6_scope_id; bnct = bnc_find(&to->bgp->nexthop_cache_table[afi], &pt, 0, ifindex); if (bnct != bncp) @@ -215,7 +222,7 @@ bgp_find_ipv6_nexthop_matching_peer(struct peer *peer) if (BGP_DEBUG(nht, NHT)) { zlog_debug( "Found bnc: %pFX(%u)(%u)(%p) for peer: %s(%s) %p", - &bnc->prefix, bnc->ifindex, + &bnc->prefix, bnc->ifindex_ipv6_ll, bnc->srte_color, bnc, peer->host, peer->bgp->name_pretty, peer); } @@ -235,10 +242,10 @@ void bgp_unlink_nexthop_by_peer(struct peer *peer) { struct prefix p; struct bgp_nexthop_cache *bnc; - afi_t afi = family2afi(peer->su.sa.sa_family); + afi_t afi = family2afi(peer->connection->su.sa.sa_family); ifindex_t ifindex = 0; - if (!sockunion2hostprefix(&peer->su, &p)) { + if (!sockunion2hostprefix(&peer->connection->su, &p)) { /* * In scenarios where unnumbered BGP session is brought * down by shutting down the interface before unconfiguring @@ -256,8 +263,8 @@ void bgp_unlink_nexthop_by_peer(struct peer *peer) * tagged into this fun */ if (afi == AFI_IP6 && - IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr)) - ifindex = peer->su.sin6.sin6_scope_id; + IN6_IS_ADDR_LINKLOCAL(&peer->connection->su.sin6.sin6_addr)) + ifindex = peer->connection->su.sin6.sin6_scope_id; bnc = bnc_find(&peer->bgp->nexthop_cache_table[afi], &p, 0, ifindex); } @@ -311,6 +318,23 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop, if (make_prefix(afi, pi, &p) < 0) return 1; + /* + * If it's a V6 nexthop, path is learnt from a v6 LL peer, + * and if the NH prefix matches peer's LL address then + * set the ifindex to peer's interface index so that + * correct nexthop can be found in nexthop tree. + * + * NH could be set to different v6 LL address (compared to + * peer's LL) using route-map. In such a scenario, do not set + * the ifindex. + */ + if (afi == AFI_IP6 && + IN6_IS_ADDR_LINKLOCAL( + &pi->peer->connection->su.sin6.sin6_addr) && + IPV6_ADDR_SAME(&pi->peer->connection->su.sin6.sin6_addr, + &p.u.prefix6)) + ifindex = pi->peer->connection->su.sin6.sin6_scope_id; + if (!is_bgp_static_route && orig_prefix && prefix_same(&p, orig_prefix)) { if (BGP_DEBUG(nht, NHT)) { @@ -321,15 +345,18 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop, return 0; } - srte_color = pi->attr->srte_color; + if (CHECK_FLAG(pi->attr->flag, + ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR))) + srte_color = bgp_attr_get_color(pi->attr); + } else if (peer) { /* * Gather the ifindex for if up/down events to be * tagged into this fun */ if (afi == AFI_IP6 && peer->conf_if && - IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr)) { - ifindex = peer->su.sin6.sin6_scope_id; + IN6_IS_ADDR_LINKLOCAL(&peer->connection->su.sin6.sin6_addr)) { + ifindex = peer->connection->su.sin6.sin6_scope_id; if (ifindex == 0) { if (BGP_DEBUG(nht, NHT)) { zlog_debug( @@ -340,7 +367,7 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop, } } - if (!sockunion2hostprefix(&peer->su, &p)) { + if (!sockunion2hostprefix(&peer->connection->su, &p)) { if (BGP_DEBUG(nht, NHT)) { zlog_debug( "%s: Attempting to register with unknown AFI %d (not %d or %d)", @@ -359,18 +386,21 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop, bnc = bnc_find(tree, &p, srte_color, ifindex); if (!bnc) { bnc = bnc_new(tree, &p, srte_color, ifindex); + bnc->afi = afi; bnc->bgp = bgp_nexthop; if (BGP_DEBUG(nht, NHT)) zlog_debug("Allocated bnc %pFX(%d)(%u)(%s) peer %p", - &bnc->prefix, bnc->ifindex, bnc->srte_color, - bnc->bgp->name_pretty, peer); + &bnc->prefix, bnc->ifindex_ipv6_ll, + bnc->srte_color, bnc->bgp->name_pretty, + peer); } else { if (BGP_DEBUG(nht, NHT)) zlog_debug( "Found existing bnc %pFX(%d)(%s) flags 0x%x ifindex %d #paths %d peer %p", - &bnc->prefix, bnc->ifindex, - bnc->bgp->name_pretty, bnc->flags, bnc->ifindex, - bnc->path_count, bnc->nht_info); + &bnc->prefix, bnc->ifindex_ipv6_ll, + bnc->bgp->name_pretty, bnc->flags, + bnc->ifindex_ipv6_ll, bnc->path_count, + bnc->nht_info); } if (pi && is_route_parent_evpn(pi)) @@ -417,10 +447,10 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop, UNSET_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED); UNSET_FLAG(bnc->flags, BGP_NEXTHOP_VALID); } - if (peer && (bnc->ifindex != ifindex)) { + if (peer && (bnc->ifindex_ipv6_ll != ifindex)) { UNSET_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED); UNSET_FLAG(bnc->flags, BGP_NEXTHOP_VALID); - bnc->ifindex = ifindex; + bnc->ifindex_ipv6_ll = ifindex; } if (bgp_route->inst_type == BGP_INSTANCE_TYPE_VIEW) { SET_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED); @@ -467,7 +497,12 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop, pi->sub_type == BGP_ROUTE_IMPORTED && pi->extra && pi->extra->num_labels && !bnc->is_evpn_gwip_nexthop) return bgp_isvalid_nexthop_for_mpls(bnc, pi); + else if (safi == SAFI_MPLS_VPN && pi && + pi->sub_type != BGP_ROUTE_IMPORTED) + /* avoid not redistributing mpls vpn routes */ + return 1; else + /* mpls-vpn routes with BGP_ROUTE_IMPORTED subtype */ return (bgp_isvalid_nexthop(bnc)); } @@ -489,14 +524,15 @@ void bgp_delete_connected_nexthop(afi_t afi, struct peer *peer) * nodes of V6 nexthop cache to find the bnc, it is * currently not being called here. */ - if (!sockunion2hostprefix(&peer->su, &p)) + if (!sockunion2hostprefix(&peer->connection->su, &p)) return; /* * Gather the ifindex for if up/down events to be * tagged into this fun */ - if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr)) - ifindex = peer->su.sin6.sin6_scope_id; + if (afi == AFI_IP6 && + IN6_IS_ADDR_LINKLOCAL(&peer->connection->su.sin6.sin6_addr)) + ifindex = peer->connection->su.sin6.sin6_scope_id; bnc = bnc_find(&peer->bgp->nexthop_cache_table[family2afi(p.family)], &p, 0, ifindex); if (!bnc) { @@ -547,10 +583,10 @@ static void bgp_process_nexthop_update(struct bgp_nexthop_cache *bnc, char bnc_buf[BNC_FLAG_DUMP_SIZE]; zlog_debug( - "%s(%u): Rcvd NH update %pFX(%u)%u) - metric %d/%d #nhops %d/%d flags %s", + "%s(%u): Rcvd NH update %pFX(%u)(%u) - metric %d/%d #nhops %d/%d flags %s", bnc->bgp->name_pretty, bnc->bgp->vrf_id, &nhr->prefix, - bnc->ifindex, bnc->srte_color, nhr->metric, bnc->metric, - nhr->nexthop_num, bnc->nexthop_num, + bnc->ifindex_ipv6_ll, bnc->srte_color, nhr->metric, + bnc->metric, nhr->nexthop_num, bnc->nexthop_num, bgp_nexthop_dump_bnc_flags(bnc, bnc_buf, sizeof(bnc_buf))); } @@ -703,11 +739,53 @@ static void bgp_nht_ifp_table_handle(struct bgp *bgp, struct interface *ifp, bool up) { struct bgp_nexthop_cache *bnc; + struct nexthop *nhop; + uint8_t other_nh_count; + bool nhop_ll_found = false; + bool nhop_found = false; + + if (ifp->ifindex == IFINDEX_INTERNAL) { + zlog_warn("%s: The interface %s ignored", __func__, ifp->name); + return; + } frr_each (bgp_nexthop_cache, table, bnc) { - if (bnc->ifindex != ifp->ifindex) + other_nh_count = 0; + nhop_ll_found = bnc->ifindex_ipv6_ll == ifp->ifindex; + for (nhop = bnc->nexthop; nhop; nhop = nhop->next) { + if (nhop->ifindex == bnc->ifindex_ipv6_ll) + continue; + + if (nhop->ifindex != ifp->ifindex) { + other_nh_count++; + continue; + } + if (nhop->vrf_id != ifp->vrf->vrf_id) { + other_nh_count++; + continue; + } + nhop_found = true; + } + + if (!nhop_found && !nhop_ll_found) + /* The event interface does not match the nexthop cache + * entry */ continue; + if (!up && other_nh_count > 0) + /* Down event ignored in case of multiple next-hop + * interfaces. The other might interfaces might be still + * up. The cases where all interfaces are down or a bnc + * is invalid are processed by a separate zebra rnh + * messages. + */ + continue; + + if (!nhop_ll_found) { + evaluate_paths(bnc); + continue; + } + bnc->last_update = monotime(NULL); bnc->change_flags = 0; @@ -720,6 +798,7 @@ static void bgp_nht_ifp_table_handle(struct bgp *bgp, if (up) { SET_FLAG(bnc->flags, BGP_NEXTHOP_VALID); SET_FLAG(bnc->change_flags, BGP_NEXTHOP_CHANGED); + /* change nexthop number only for ll */ bnc->nexthop_num = 1; } else { UNSET_FLAG(bnc->flags, BGP_NEXTHOP_PEER_NOTIFIED); @@ -796,74 +875,67 @@ void bgp_nht_interface_events(struct peer *peer) struct prefix p; ifindex_t ifindex = 0; - if (!IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr)) + if (!IN6_IS_ADDR_LINKLOCAL(&peer->connection->su.sin6.sin6_addr)) return; - if (!sockunion2hostprefix(&peer->su, &p)) + if (!sockunion2hostprefix(&peer->connection->su, &p)) return; /* * Gather the ifindex for if up/down events to be * tagged into this fun */ - if (peer->conf_if && IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr)) - ifindex = peer->su.sin6.sin6_scope_id; + if (peer->conf_if && + IN6_IS_ADDR_LINKLOCAL(&peer->connection->su.sin6.sin6_addr)) + ifindex = peer->connection->su.sin6.sin6_scope_id; table = &bgp->nexthop_cache_table[AFI_IP6]; bnc = bnc_find(table, &p, 0, ifindex); if (!bnc) return; - if (bnc->ifindex) + if (bnc->ifindex_ipv6_ll) event_add_event(bm->master, bgp_nht_ifp_initial, bnc->bgp, - bnc->ifindex, NULL); + bnc->ifindex_ipv6_ll, NULL); } -void bgp_parse_nexthop_update(int command, vrf_id_t vrf_id) +void bgp_nexthop_update(struct vrf *vrf, struct prefix *match, + struct zapi_route *nhr) { struct bgp_nexthop_cache_head *tree = NULL; struct bgp_nexthop_cache *bnc_nhc, *bnc_import; struct bgp *bgp; - struct prefix match; - struct zapi_route nhr; afi_t afi; - bgp = bgp_lookup_by_vrf_id(vrf_id); - if (!bgp) { - flog_err( - EC_BGP_NH_UPD, - "parse nexthop update: instance not found for vrf_id %u", - vrf_id); + if (!vrf->info) { + flog_err(EC_BGP_NH_UPD, + "parse nexthop update: instance not found for vrf_id %u", + vrf->vrf_id); return; } - if (!zapi_nexthop_update_decode(zclient->ibuf, &match, &nhr)) { - zlog_err("%s[%s]: Failure to decode nexthop update", __func__, - bgp->name_pretty); - return; - } - - afi = family2afi(match.family); + bgp = (struct bgp *)vrf->info; + afi = family2afi(match->family); tree = &bgp->nexthop_cache_table[afi]; - bnc_nhc = bnc_find(tree, &match, nhr.srte_color, 0); + bnc_nhc = bnc_find(tree, match, nhr->srte_color, 0); if (!bnc_nhc) { if (BGP_DEBUG(nht, NHT)) - zlog_debug( - "parse nexthop update(%pFX(%u)(%s)): bnc info not found for nexthop cache", - &nhr.prefix, nhr.srte_color, bgp->name_pretty); + zlog_debug("parse nexthop update %pFX(%u)(%s): bnc info not found for nexthop cache", + &nhr->prefix, nhr->srte_color, + bgp->name_pretty); } else - bgp_process_nexthop_update(bnc_nhc, &nhr, false); + bgp_process_nexthop_update(bnc_nhc, nhr, false); tree = &bgp->import_check_table[afi]; - bnc_import = bnc_find(tree, &match, nhr.srte_color, 0); + bnc_import = bnc_find(tree, match, nhr->srte_color, 0); if (!bnc_import) { if (BGP_DEBUG(nht, NHT)) - zlog_debug( - "parse nexthop update(%pFX(%u)(%s)): bnc info not found for import check", - &nhr.prefix, nhr.srte_color, bgp->name_pretty); + zlog_debug("parse nexthop update %pFX(%u)(%s): bnc info not found for import check", + &nhr->prefix, nhr->srte_color, + bgp->name_pretty); } else - bgp_process_nexthop_update(bnc_import, &nhr, true); + bgp_process_nexthop_update(bnc_import, nhr, true); /* * HACK: if any BGP route is dependant on an SR-policy that doesn't @@ -876,7 +948,7 @@ void bgp_parse_nexthop_update(int command, vrf_id_t vrf_id) * which should provide a better infrastructure to solve this issue in * a more efficient and elegant way. */ - if (nhr.srte_color == 0 && bnc_nhc) { + if (nhr->srte_color == 0 && bnc_nhc) { struct bgp_nexthop_cache *bnc_iter; frr_each (bgp_nexthop_cache, &bgp->nexthop_cache_table[afi], @@ -886,7 +958,7 @@ void bgp_parse_nexthop_update(int command, vrf_id_t vrf_id) CHECK_FLAG(bnc_iter->flags, BGP_NEXTHOP_VALID)) continue; - bgp_process_nexthop_update(bnc_iter, &nhr, false); + bgp_process_nexthop_update(bnc_iter, nhr, false); } } } @@ -1074,7 +1146,7 @@ static void register_zebra_rnh(struct bgp_nexthop_cache *bnc) if (bnc->flags & BGP_NEXTHOP_REGISTERED) return; - if (bnc->ifindex) { + if (bnc->ifindex_ipv6_ll) { SET_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED); return; } @@ -1091,15 +1163,33 @@ static void register_zebra_rnh(struct bgp_nexthop_cache *bnc) */ static void unregister_zebra_rnh(struct bgp_nexthop_cache *bnc) { + struct bgp_nexthop_cache *import; + struct bgp_nexthop_cache *nexthop; + + struct bgp *bgp = bnc->bgp; + /* Check if we have already registered */ if (!CHECK_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED)) return; - if (bnc->ifindex) { + if (bnc->ifindex_ipv6_ll) { UNSET_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED); return; } + import = bnc_find(&bgp->import_check_table[bnc->afi], &bnc->prefix, 0, + 0); + nexthop = bnc_find(&bgp->nexthop_cache_table[bnc->afi], &bnc->prefix, 0, + 0); + + /* + * If this entry has both a import and a nexthop entry + * then let's not send the unregister quite as of yet + * wait until we only have 1 left + */ + if (import && nexthop) + return; + sendmsg_zebra_rnh(bnc, ZEBRA_NEXTHOP_UNREGISTER); } @@ -1128,7 +1218,7 @@ void evaluate_paths(struct bgp_nexthop_cache *bnc) zlog_debug( "NH update for %pFX(%d)(%u)(%s) - flags %s chgflags %s- evaluate paths", - &bnc->prefix, bnc->ifindex, bnc->srte_color, + &bnc->prefix, bnc->ifindex_ipv6_ll, bnc->srte_color, bnc->bgp->name_pretty, bgp_nexthop_dump_bnc_flags(bnc, bnc_buf, sizeof(bnc_buf)), @@ -1190,7 +1280,12 @@ void evaluate_paths(struct bgp_nexthop_cache *bnc) bnc_is_valid_nexthop = bgp_isvalid_nexthop_for_mpls(bnc, path) ? true : false; + } else if (safi == SAFI_MPLS_VPN && + path->sub_type != BGP_ROUTE_IMPORTED) { + /* avoid not redistributing mpls vpn routes */ + bnc_is_valid_nexthop = true; } else { + /* mpls-vpn routes with BGP_ROUTE_IMPORTED subtype */ if (bgp_update_martian_nexthop( bnc->bgp, afi, safi, path->type, path->sub_type, path->attr, dest)) { @@ -1238,9 +1333,9 @@ void evaluate_paths(struct bgp_nexthop_cache *bnc) else if (bpi_ultimate->extra) bpi_ultimate->extra->igpmetric = 0; - if (CHECK_FLAG(bnc->change_flags, BGP_NEXTHOP_METRIC_CHANGED) - || CHECK_FLAG(bnc->change_flags, BGP_NEXTHOP_CHANGED) - || path->attr->srte_color != 0) + if (CHECK_FLAG(bnc->change_flags, BGP_NEXTHOP_METRIC_CHANGED) || + CHECK_FLAG(bnc->change_flags, BGP_NEXTHOP_CHANGED) || + bgp_attr_get_color(path->attr)) SET_FLAG(path->flags, BGP_PATH_IGP_CHANGED); path_valid = CHECK_FLAG(path->flags, BGP_PATH_VALID); @@ -1329,7 +1424,8 @@ void evaluate_paths(struct bgp_nexthop_cache *bnc) __func__, peer->host, peer->bgp->name_pretty, !!valid_nexthops); - bgp_fsm_nht_update(peer, !!valid_nexthops); + bgp_fsm_nht_update(peer->connection, peer, + !!valid_nexthops); SET_FLAG(bnc->flags, BGP_NEXTHOP_PEER_NOTIFIED); } } @@ -1390,7 +1486,7 @@ void bgp_nht_reg_enhe_cap_intfs(struct peer *peer) return; bgp = peer->bgp; - if (!sockunion2hostprefix(&peer->su, &p)) { + if (!sockunion2hostprefix(&peer->connection->su, &p)) { zlog_warn("%s: Unable to convert sockunion to prefix for %s", __func__, peer->host); return; @@ -1402,8 +1498,9 @@ void bgp_nht_reg_enhe_cap_intfs(struct peer *peer) * Gather the ifindex for if up/down events to be * tagged into this fun */ - if (peer->conf_if && IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr)) - ifindex = peer->su.sin6.sin6_scope_id; + if (peer->conf_if && + IN6_IS_ADDR_LINKLOCAL(&peer->connection->su.sin6.sin6_addr)) + ifindex = peer->connection->su.sin6.sin6_scope_id; bnc = bnc_find(&bgp->nexthop_cache_table[AFI_IP6], &p, 0, ifindex); if (!bnc) @@ -1439,7 +1536,7 @@ void bgp_nht_dereg_enhe_cap_intfs(struct peer *peer) bgp = peer->bgp; - if (!sockunion2hostprefix(&peer->su, &p)) { + if (!sockunion2hostprefix(&peer->connection->su, &p)) { zlog_warn("%s: Unable to convert sockunion to prefix for %s", __func__, peer->host); return; @@ -1451,8 +1548,9 @@ void bgp_nht_dereg_enhe_cap_intfs(struct peer *peer) * Gather the ifindex for if up/down events to be * tagged into this fun */ - if (peer->conf_if && IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr)) - ifindex = peer->su.sin6.sin6_scope_id; + if (peer->conf_if && + IN6_IS_ADDR_LINKLOCAL(&peer->connection->su.sin6.sin6_addr)) + ifindex = peer->connection->su.sin6.sin6_scope_id; bnc = bnc_find(&bgp->nexthop_cache_table[AFI_IP6], &p, 0, ifindex); if (!bnc) @@ -1471,90 +1569,3 @@ void bgp_nht_dereg_enhe_cap_intfs(struct peer *peer) 0); } } - -/**************************************************************************** - * L3 NHGs are used for fast failover of nexthops in the dplane. These are - * the APIs for allocating L3 NHG ids. Management of the L3 NHG itself is - * left to the application using it. - * PS: Currently EVPN host routes is the only app using L3 NHG for fast - * failover of remote ES links. - ***************************************************************************/ -static bitfield_t bgp_nh_id_bitmap; -static uint32_t bgp_l3nhg_start; - -/* XXX - currently we do nothing on the callbacks */ -static void bgp_l3nhg_add_cb(const char *name) -{ -} - -static void bgp_l3nhg_modify_cb(const struct nexthop_group_cmd *nhgc) -{ -} - -static void bgp_l3nhg_add_nexthop_cb(const struct nexthop_group_cmd *nhgc, - const struct nexthop *nhop) -{ -} - -static void bgp_l3nhg_del_nexthop_cb(const struct nexthop_group_cmd *nhgc, - const struct nexthop *nhop) -{ -} - -static void bgp_l3nhg_del_cb(const char *name) -{ -} - -static void bgp_l3nhg_zebra_init(void) -{ - static bool bgp_l3nhg_zebra_inited; - if (bgp_l3nhg_zebra_inited) - return; - - bgp_l3nhg_zebra_inited = true; - bgp_l3nhg_start = zclient_get_nhg_start(ZEBRA_ROUTE_BGP); - nexthop_group_init(bgp_l3nhg_add_cb, bgp_l3nhg_modify_cb, - bgp_l3nhg_add_nexthop_cb, bgp_l3nhg_del_nexthop_cb, - bgp_l3nhg_del_cb); -} - - -void bgp_l3nhg_init(void) -{ - uint32_t id_max; - - id_max = MIN(ZEBRA_NHG_PROTO_SPACING - 1, 16 * 1024); - bf_init(bgp_nh_id_bitmap, id_max); - bf_assign_zero_index(bgp_nh_id_bitmap); - - if (BGP_DEBUG(nht, NHT) || BGP_DEBUG(evpn_mh, EVPN_MH_ES)) - zlog_debug("bgp l3_nhg range %u - %u", bgp_l3nhg_start + 1, - bgp_l3nhg_start + id_max); -} - -void bgp_l3nhg_finish(void) -{ - bf_free(bgp_nh_id_bitmap); -} - -uint32_t bgp_l3nhg_id_alloc(void) -{ - uint32_t nhg_id = 0; - - bgp_l3nhg_zebra_init(); - bf_assign_index(bgp_nh_id_bitmap, nhg_id); - if (nhg_id) - nhg_id += bgp_l3nhg_start; - - return nhg_id; -} - -void bgp_l3nhg_id_free(uint32_t nhg_id) -{ - if (!nhg_id || (nhg_id <= bgp_l3nhg_start)) - return; - - nhg_id -= bgp_l3nhg_start; - - bf_release_index(bgp_nh_id_bitmap, nhg_id); -} diff --git a/bgpd/bgp_nht.h b/bgpd/bgp_nht.h index 0758a0cf08..e7c6fdc281 100644 --- a/bgpd/bgp_nht.h +++ b/bgpd/bgp_nht.h @@ -7,9 +7,10 @@ #define _BGP_NHT_H /** - * bgp_parse_nexthop_update() - parse a nexthop update message from Zebra. + * bgp_nexthop_update() - process a nexthop update message from Zebra. */ -extern void bgp_parse_nexthop_update(int command, vrf_id_t vrf_id); +extern void bgp_nexthop_update(struct vrf *vrf, struct prefix *match, + struct zapi_route *nhr); /** * bgp_find_or_add_nexthop() - lookup the nexthop cache table for the bnc @@ -78,12 +79,6 @@ extern void bgp_nht_reg_enhe_cap_intfs(struct peer *peer); extern void bgp_nht_dereg_enhe_cap_intfs(struct peer *peer); extern void evaluate_paths(struct bgp_nexthop_cache *bnc); -/* APIs for setting up and allocating L3 nexthop group ids */ -extern uint32_t bgp_l3nhg_id_alloc(void); -extern void bgp_l3nhg_id_free(uint32_t nhg_id); -extern void bgp_l3nhg_init(void); -void bgp_l3nhg_finish(void); - extern void bgp_nht_ifp_up(struct interface *ifp); extern void bgp_nht_ifp_down(struct interface *ifp); diff --git a/bgpd/bgp_open.c b/bgpd/bgp_open.c index 0dd5463979..09f16bbce6 100644 --- a/bgpd/bgp_open.c +++ b/bgpd/bgp_open.c @@ -27,25 +27,23 @@ #include "bgpd/bgp_vty.h" #include "bgpd/bgp_memory.h" -static const struct message capcode_str[] = { - {CAPABILITY_CODE_MP, "MultiProtocol Extensions"}, - {CAPABILITY_CODE_REFRESH, "Route Refresh"}, - {CAPABILITY_CODE_ORF, "Cooperative Route Filtering"}, - {CAPABILITY_CODE_RESTART, "Graceful Restart"}, - {CAPABILITY_CODE_AS4, "4-octet AS number"}, - {CAPABILITY_CODE_ADDPATH, "AddPath"}, - {CAPABILITY_CODE_DYNAMIC, "Dynamic"}, - {CAPABILITY_CODE_ENHE, "Extended Next Hop Encoding"}, - {CAPABILITY_CODE_DYNAMIC_OLD, "Dynamic (Old)"}, - {CAPABILITY_CODE_REFRESH_OLD, "Route Refresh (Old)"}, - {CAPABILITY_CODE_ORF_OLD, "ORF (Old)"}, - {CAPABILITY_CODE_FQDN, "FQDN"}, - {CAPABILITY_CODE_ENHANCED_RR, "Enhanced Route Refresh"}, - {CAPABILITY_CODE_EXT_MESSAGE, "BGP Extended Message"}, - {CAPABILITY_CODE_LLGR, "Long-lived BGP Graceful Restart"}, - {CAPABILITY_CODE_ROLE, "Role"}, - {CAPABILITY_CODE_SOFT_VERSION, "Software Version"}, - {0}}; +const struct message capcode_str[] = { + { CAPABILITY_CODE_MP, "MultiProtocol Extensions" }, + { CAPABILITY_CODE_REFRESH, "Route Refresh" }, + { CAPABILITY_CODE_ORF, "Cooperative Route Filtering" }, + { CAPABILITY_CODE_RESTART, "Graceful Restart" }, + { CAPABILITY_CODE_AS4, "4-octet AS number" }, + { CAPABILITY_CODE_ADDPATH, "AddPath" }, + { CAPABILITY_CODE_DYNAMIC, "Dynamic" }, + { CAPABILITY_CODE_ENHE, "Extended Next Hop Encoding" }, + { CAPABILITY_CODE_FQDN, "FQDN" }, + { CAPABILITY_CODE_ENHANCED_RR, "Enhanced Route Refresh" }, + { CAPABILITY_CODE_EXT_MESSAGE, "BGP Extended Message" }, + { CAPABILITY_CODE_LLGR, "Long-lived BGP Graceful Restart" }, + { CAPABILITY_CODE_ROLE, "Role" }, + { CAPABILITY_CODE_SOFT_VERSION, "Software Version" }, + { 0 } +}; /* Minimum sizes for length field of each cap (so not inc. the header) */ static const size_t cap_minsizes[] = { @@ -56,10 +54,7 @@ static const size_t cap_minsizes[] = { [CAPABILITY_CODE_AS4] = CAPABILITY_CODE_AS4_LEN, [CAPABILITY_CODE_ADDPATH] = CAPABILITY_CODE_ADDPATH_LEN, [CAPABILITY_CODE_DYNAMIC] = CAPABILITY_CODE_DYNAMIC_LEN, - [CAPABILITY_CODE_DYNAMIC_OLD] = CAPABILITY_CODE_DYNAMIC_LEN, [CAPABILITY_CODE_ENHE] = CAPABILITY_CODE_ENHE_LEN, - [CAPABILITY_CODE_REFRESH_OLD] = CAPABILITY_CODE_REFRESH_LEN, - [CAPABILITY_CODE_ORF_OLD] = CAPABILITY_CODE_ORF_LEN, [CAPABILITY_CODE_FQDN] = CAPABILITY_CODE_MIN_FQDN_LEN, [CAPABILITY_CODE_ENHANCED_RR] = CAPABILITY_CODE_ENHANCED_LEN, [CAPABILITY_CODE_EXT_MESSAGE] = CAPABILITY_CODE_EXT_MESSAGE_LEN, @@ -81,10 +76,7 @@ static const size_t cap_modsizes[] = { [CAPABILITY_CODE_AS4] = 4, [CAPABILITY_CODE_ADDPATH] = 4, [CAPABILITY_CODE_DYNAMIC] = 1, - [CAPABILITY_CODE_DYNAMIC_OLD] = 1, [CAPABILITY_CODE_ENHE] = 6, - [CAPABILITY_CODE_REFRESH_OLD] = 1, - [CAPABILITY_CODE_ORF_OLD] = 1, [CAPABILITY_CODE_FQDN] = 1, [CAPABILITY_CODE_ENHANCED_RR] = 1, [CAPABILITY_CODE_EXT_MESSAGE] = 1, @@ -348,16 +340,14 @@ static void bgp_capability_orf_not_support(struct peer *peer, iana_afi_t afi, peer->host, afi, safi, type, mode); } -static const struct message orf_type_str[] = { - {ORF_TYPE_RESERVED, "Reserved"}, - {ORF_TYPE_PREFIX, "Prefixlist"}, - {ORF_TYPE_PREFIX_OLD, "Prefixlist (old)"}, - {0}}; +const struct message orf_type_str[] = { { ORF_TYPE_RESERVED, "Reserved" }, + { ORF_TYPE_PREFIX, "Prefixlist" }, + { 0 } }; -static const struct message orf_mode_str[] = {{ORF_MODE_RECEIVE, "Receive"}, - {ORF_MODE_SEND, "Send"}, - {ORF_MODE_BOTH, "Both"}, - {0}}; +const struct message orf_mode_str[] = { { ORF_MODE_RECEIVE, "Receive" }, + { ORF_MODE_SEND, "Send" }, + { ORF_MODE_BOTH, "Both" }, + { 0 } }; static int bgp_capability_orf_entry(struct peer *peer, struct capability_header *hdr) @@ -401,7 +391,7 @@ static int bgp_capability_orf_entry(struct peer *peer, zlog_info( "%s ORF Capability entry length error, Cap length %u, num %u", peer->host, hdr->length, num); - bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send(peer->connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_MALFORMED_ATTR); return -1; } @@ -440,22 +430,6 @@ static int bgp_capability_orf_entry(struct peer *peer, continue; } break; - case CAPABILITY_CODE_ORF_OLD: - switch (type) { - case ORF_TYPE_RESERVED: - if (bgp_debug_neighbor_events(peer)) - zlog_debug( - "%s Addr-family %d/%d has reserved ORF type, ignoring", - peer->host, afi, safi); - break; - case ORF_TYPE_PREFIX_OLD: - break; - default: - bgp_capability_orf_not_support( - peer, pkt_afi, pkt_safi, type, mode); - continue; - } - break; default: bgp_capability_orf_not_support(peer, pkt_afi, pkt_safi, type, mode); @@ -482,9 +456,6 @@ static int bgp_capability_orf_entry(struct peer *peer, if (hdr->code == CAPABILITY_CODE_ORF) { sm_cap = PEER_CAP_ORF_PREFIX_SM_RCV; rm_cap = PEER_CAP_ORF_PREFIX_RM_RCV; - } else if (hdr->code == CAPABILITY_CODE_ORF_OLD) { - sm_cap = PEER_CAP_ORF_PREFIX_SM_OLD_RCV; - rm_cap = PEER_CAP_ORF_PREFIX_RM_OLD_RCV; } else { bgp_capability_orf_not_support(peer, pkt_afi, pkt_safi, type, mode); @@ -604,18 +575,6 @@ static int bgp_capability_restart(struct peer *peer, static int bgp_capability_llgr(struct peer *peer, struct capability_header *caphdr) { -/* - * +--------------------------------------------------+ - * | Address Family Identifier (16 bits) | - * +--------------------------------------------------+ - * | Subsequent Address Family Identifier (8 bits) | - * +--------------------------------------------------+ - * | Flags for Address Family (8 bits) | - * +--------------------------------------------------+ - * | Long-lived Stale Time (24 bits) | - * +--------------------------------------------------+ - */ -#define BGP_CAP_LLGR_MIN_PACKET_LEN 7 struct stream *s = BGP_INPUT(peer); size_t end = stream_get_getp(s) + caphdr->length; @@ -706,7 +665,7 @@ static int bgp_capability_addpath(struct peer *peer, SET_FLAG(peer->cap, PEER_CAP_ADDPATH_RCV); /* Verify length is a multiple of 4 */ - if (hdr->length % 4) { + if (hdr->length % CAPABILITY_CODE_ADDPATH_LEN) { flog_warn( EC_BGP_CAPABILITY_INVALID_LENGTH, "Add Path: Received invalid length %d, non-multiple of 4", @@ -714,23 +673,36 @@ static int bgp_capability_addpath(struct peer *peer, return -1; } - while (stream_get_getp(s) + 4 <= end) { + while (stream_get_getp(s) + CAPABILITY_CODE_ADDPATH_LEN <= end) { afi_t afi; safi_t safi; iana_afi_t pkt_afi = stream_getw(s); iana_safi_t pkt_safi = stream_getc(s); uint8_t send_receive = stream_getc(s); + /* If any other value (other than 1-3) is received, then + * the capability SHOULD be treated as not understood + * and ignored. + */ + if (!send_receive || send_receive > 3) { + flog_warn(EC_BGP_CAPABILITY_INVALID_DATA, + "Add Path: Received invalid send/receive value %u in Add Path capability", + send_receive); + continue; + } + if (bgp_debug_neighbor_events(peer)) - zlog_debug( - "%s OPEN has %s capability for afi/safi: %s/%s%s%s", - peer->host, - lookup_msg(capcode_str, hdr->code, NULL), - iana_afi2str(pkt_afi), iana_safi2str(pkt_safi), - (send_receive & BGP_ADDPATH_RX) ? ", receive" - : "", - (send_receive & BGP_ADDPATH_TX) ? ", transmit" - : ""); + zlog_debug("%s OPEN has %s capability for afi/safi: %s/%s%s%s", + peer->host, + lookup_msg(capcode_str, hdr->code, NULL), + iana_afi2str(pkt_afi), + iana_safi2str(pkt_safi), + CHECK_FLAG(send_receive, BGP_ADDPATH_RX) + ? ", receive" + : "", + CHECK_FLAG(send_receive, BGP_ADDPATH_TX) + ? ", transmit" + : ""); /* Convert AFI, SAFI to internal values, check. */ if (bgp_map_afi_safi_iana2int(pkt_afi, pkt_safi, &afi, &safi)) { @@ -749,13 +721,19 @@ static int bgp_capability_addpath(struct peer *peer, continue; } - if (send_receive & BGP_ADDPATH_RX) + if (CHECK_FLAG(send_receive, BGP_ADDPATH_RX)) SET_FLAG(peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_RCV); + else + UNSET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ADDPATH_AF_RX_RCV); - if (send_receive & BGP_ADDPATH_TX) + if (CHECK_FLAG(send_receive, BGP_ADDPATH_TX)) SET_FLAG(peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV); + else + UNSET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ADDPATH_AF_TX_RCV); } return 0; @@ -929,8 +907,6 @@ static int bgp_capability_software_version(struct peer *peer, size_t end = stream_get_getp(s) + hdr->length; uint8_t len; - SET_FLAG(peer->cap, PEER_CAP_SOFT_VERSION_RCV); - len = stream_getc(s); if (stream_get_getp(s) + len > end) { flog_warn( @@ -940,8 +916,20 @@ static int bgp_capability_software_version(struct peer *peer, return -1; } - if (len) { + SET_FLAG(peer->cap, PEER_CAP_SOFT_VERSION_RCV); + + if (len > BGP_MAX_SOFT_VERSION) { + flog_warn(EC_BGP_CAPABILITY_INVALID_LENGTH, + "%s: Received Software Version, but the length is too big, truncating, from peer %s", + __func__, peer->host); + stream_get(str, s, BGP_MAX_SOFT_VERSION); + stream_forward_getp(s, len - BGP_MAX_SOFT_VERSION); + len = BGP_MAX_SOFT_VERSION; + } else if (len) { stream_get(str, s, len); + } + + if (len) { str[len] = '\0'; XFREE(MTYPE_BGP_SOFT_VERSION, peer->soft_version); @@ -983,7 +971,7 @@ static int bgp_capability_parse(struct peer *peer, size_t length, if (stream_get_getp(s) + 2 > end) { zlog_info("%s Capability length error (< header)", peer->host); - bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send(peer->connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_MALFORMED_ATTR); return -1; } @@ -996,7 +984,7 @@ static int bgp_capability_parse(struct peer *peer, size_t length, if (start + caphdr.length > end) { zlog_info("%s Capability length error (< length)", peer->host); - bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send(peer->connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_MALFORMED_ATTR); return -1; } @@ -1011,14 +999,11 @@ static int bgp_capability_parse(struct peer *peer, size_t length, switch (caphdr.code) { case CAPABILITY_CODE_MP: case CAPABILITY_CODE_REFRESH: - case CAPABILITY_CODE_REFRESH_OLD: case CAPABILITY_CODE_ORF: - case CAPABILITY_CODE_ORF_OLD: case CAPABILITY_CODE_RESTART: case CAPABILITY_CODE_AS4: case CAPABILITY_CODE_ADDPATH: case CAPABILITY_CODE_DYNAMIC: - case CAPABILITY_CODE_DYNAMIC_OLD: case CAPABILITY_CODE_ENHE: case CAPABILITY_CODE_FQDN: case CAPABILITY_CODE_ENHANCED_RR: @@ -1034,7 +1019,8 @@ static int bgp_capability_parse(struct peer *peer, size_t length, NULL), caphdr.length, (unsigned)cap_minsizes[caphdr.code]); - bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send(peer->connection, + BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_MALFORMED_ATTR); return -1; } @@ -1047,10 +1033,12 @@ static int bgp_capability_parse(struct peer *peer, size_t length, NULL), caphdr.length, (unsigned)cap_modsizes[caphdr.code]); - bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send(peer->connection, + BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_MALFORMED_ATTR); return -1; } + break; /* we deliberately ignore unknown codes, see below */ default: break; @@ -1076,18 +1064,14 @@ static int bgp_capability_parse(struct peer *peer, size_t length, } } break; case CAPABILITY_CODE_ENHANCED_RR: - case CAPABILITY_CODE_REFRESH: - case CAPABILITY_CODE_REFRESH_OLD: { + case CAPABILITY_CODE_REFRESH: { /* BGP refresh capability */ if (caphdr.code == CAPABILITY_CODE_ENHANCED_RR) SET_FLAG(peer->cap, PEER_CAP_ENHANCED_RR_RCV); - else if (caphdr.code == CAPABILITY_CODE_REFRESH_OLD) - SET_FLAG(peer->cap, PEER_CAP_REFRESH_OLD_RCV); else - SET_FLAG(peer->cap, PEER_CAP_REFRESH_NEW_RCV); + SET_FLAG(peer->cap, PEER_CAP_REFRESH_RCV); } break; case CAPABILITY_CODE_ORF: - case CAPABILITY_CODE_ORF_OLD: ret = bgp_capability_orf_entry(peer, &caphdr); break; case CAPABILITY_CODE_RESTART: @@ -1097,7 +1081,6 @@ static int bgp_capability_parse(struct peer *peer, size_t length, ret = bgp_capability_llgr(peer, &caphdr); break; case CAPABILITY_CODE_DYNAMIC: - case CAPABILITY_CODE_DYNAMIC_OLD: SET_FLAG(peer->cap, PEER_CAP_DYNAMIC_RCV); break; case CAPABILITY_CODE_AS4: @@ -1148,7 +1131,7 @@ static int bgp_capability_parse(struct peer *peer, size_t length, } if (ret < 0) { - bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send(peer->connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_MALFORMED_ATTR); return -1; } @@ -1196,7 +1179,7 @@ static bool bgp_role_violation(struct peer *peer) (local_role == ROLE_RS_SERVER && remote_role == ROLE_RS_CLIENT) || (local_role == ROLE_RS_CLIENT && remote_role == ROLE_RS_SERVER))) { - bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send(peer->connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_ROLE_MISMATCH); return true; } @@ -1204,7 +1187,7 @@ static bool bgp_role_violation(struct peer *peer) CHECK_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE)) { const char *err_msg = "Strict mode. Please set the role on your side."; - bgp_notify_send_with_data(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send_with_data(peer->connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_ROLE_MISMATCH, (uint8_t *)err_msg, strlen(err_msg)); return true; @@ -1332,7 +1315,7 @@ int bgp_open_option_parse(struct peer *peer, uint16_t length, */ if (STREAM_READABLE(s) < 1) { zlog_info("%s Option length error", peer->host); - bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send(peer->connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_MALFORMED_ATTR); return -1; } @@ -1345,7 +1328,8 @@ int bgp_open_option_parse(struct peer *peer, uint16_t length, if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(peer)) { if (STREAM_READABLE(s) < 2) { zlog_info("%s Option length error", peer->host); - bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send(peer->connection, + BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_MALFORMED_ATTR); return -1; } @@ -1354,7 +1338,8 @@ int bgp_open_option_parse(struct peer *peer, uint16_t length, } else { if (STREAM_READABLE(s) < 1) { zlog_info("%s Option length error", peer->host); - bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send(peer->connection, + BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_MALFORMED_ATTR); return -1; } @@ -1366,7 +1351,7 @@ int bgp_open_option_parse(struct peer *peer, uint16_t length, if (STREAM_READABLE(s) < opt_length) { zlog_info("%s Option length error (%d)", peer->host, opt_length); - bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send(peer->connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_MALFORMED_ATTR); return -1; } @@ -1385,7 +1370,7 @@ int bgp_open_option_parse(struct peer *peer, uint16_t length, mp_capability, &error); break; default: - bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send(peer->connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_UNSUP_PARAM); ret = -1; break; @@ -1404,7 +1389,8 @@ int bgp_open_option_parse(struct peer *peer, uint16_t length, if (CHECK_FLAG(peer->flags, PEER_FLAG_STRICT_CAP_MATCH)) { /* If Unsupported Capability exists. */ if (error != error_data) { - bgp_notify_send_with_data(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send_with_data(peer->connection, + BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_UNSUP_CAPBL, error_data, error - error_data); @@ -1414,7 +1400,7 @@ int bgp_open_option_parse(struct peer *peer, uint16_t length, /* Check local capability does not negotiated with remote peer. */ if (!strict_capability_same(peer)) { - bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send(peer->connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_UNSUP_CAPBL); return -1; } @@ -1453,12 +1439,14 @@ int bgp_open_option_parse(struct peer *peer, uint16_t length, peer->host); if (error != error_data) - bgp_notify_send_with_data( - peer, BGP_NOTIFY_OPEN_ERR, - BGP_NOTIFY_OPEN_UNSUP_CAPBL, error_data, - error - error_data); + bgp_notify_send_with_data(peer->connection, + BGP_NOTIFY_OPEN_ERR, + BGP_NOTIFY_OPEN_UNSUP_CAPBL, + error_data, + error - error_data); else - bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send(peer->connection, + BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_UNSUP_CAPBL); return -1; } @@ -1498,9 +1486,7 @@ static void bgp_open_capability_orf(struct stream *s, struct peer *peer, /* Address Prefix ORF */ if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_ORF_PREFIX_SM) || CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_ORF_PREFIX_RM)) { - stream_putc(s, (code == CAPABILITY_CODE_ORF - ? ORF_TYPE_PREFIX - : ORF_TYPE_PREFIX_OLD)); + stream_putc(s, ORF_TYPE_PREFIX); if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_ORF_PREFIX_SM) @@ -1733,11 +1719,11 @@ uint16_t bgp_open_capability(struct stream *s, struct peer *peer, * supporting RFC-5549 for * Link-Local peering only */ - if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE) - && peer->su.sa.sa_family == AF_INET6 - && afi == AFI_IP - && (safi == SAFI_UNICAST || safi == SAFI_MPLS_VPN - || safi == SAFI_LABELED_UNICAST)) { + if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE) && + peer->connection->su.sa.sa_family == AF_INET6 && + afi == AFI_IP && + (safi == SAFI_UNICAST || safi == SAFI_MPLS_VPN || + safi == SAFI_LABELED_UNICAST)) { /* RFC 5549 Extended Next Hop Encoding */ SET_FLAG(peer->cap, PEER_CAP_ENHE_ADV); @@ -1769,11 +1755,6 @@ uint16_t bgp_open_capability(struct stream *s, struct peer *peer, /* Route refresh. */ SET_FLAG(peer->cap, PEER_CAP_REFRESH_ADV); stream_putc(s, BGP_OPEN_OPT_CAP); - ext_opt_params ? stream_putw(s, CAPABILITY_CODE_REFRESH_LEN + 2) - : stream_putc(s, CAPABILITY_CODE_REFRESH_LEN + 2); - stream_putc(s, CAPABILITY_CODE_REFRESH_OLD); - stream_putc(s, CAPABILITY_CODE_REFRESH_LEN); - stream_putc(s, BGP_OPEN_OPT_CAP); ext_opt_params ? stream_putw(s, CAPABILITY_CODE_REFRESH_LEN + 2) : stream_putc(s, CAPABILITY_CODE_REFRESH_LEN + 2); stream_putc(s, CAPABILITY_CODE_REFRESH); @@ -1897,9 +1878,6 @@ uint16_t bgp_open_capability(struct stream *s, struct peer *peer, PEER_FLAG_ORF_PREFIX_SM) || CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_ORF_PREFIX_RM)) { - bgp_open_capability_orf(s, peer, afi, safi, - CAPABILITY_CODE_ORF_OLD, - ext_opt_params); bgp_open_capability_orf(s, peer, afi, safi, CAPABILITY_CODE_ORF, ext_opt_params); @@ -1910,12 +1888,6 @@ uint16_t bgp_open_capability(struct stream *s, struct peer *peer, if (CHECK_FLAG(peer->flags, PEER_FLAG_DYNAMIC_CAPABILITY)) { SET_FLAG(peer->cap, PEER_CAP_DYNAMIC_ADV); stream_putc(s, BGP_OPEN_OPT_CAP); - ext_opt_params - ? stream_putw(s, CAPABILITY_CODE_DYNAMIC_LEN + 2) - : stream_putc(s, CAPABILITY_CODE_DYNAMIC_LEN + 2); - stream_putc(s, CAPABILITY_CODE_DYNAMIC_OLD); - stream_putc(s, CAPABILITY_CODE_DYNAMIC_LEN); - stream_putc(s, BGP_OPEN_OPT_CAP); ext_opt_params ? stream_putw(s, CAPABILITY_CODE_DYNAMIC_LEN + 2) : stream_putc(s, CAPABILITY_CODE_DYNAMIC_LEN + 2); @@ -1976,7 +1948,8 @@ uint16_t bgp_open_capability(struct stream *s, struct peer *peer, * or disable its use, and that switch MUST be off by default. */ if (peergroup_flag_check(peer, PEER_FLAG_CAPABILITY_SOFT_VERSION) || - peer->sort == BGP_PEER_IBGP) { + CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SOFT_VERSION_CAPABILITY) || + peer->sort == BGP_PEER_IBGP || peer->sub_sort == BGP_PEER_EBGP_OAD) { SET_FLAG(peer->cap, PEER_CAP_SOFT_VERSION_ADV); stream_putc(s, BGP_OPEN_OPT_CAP); rcapp = stream_get_endp(s); diff --git a/bgpd/bgp_open.h b/bgpd/bgp_open.h index 7e3d07876d..34f4b7619e 100644 --- a/bgpd/bgp_open.h +++ b/bgpd/bgp_open.h @@ -20,18 +20,30 @@ struct capability_mp_data { }; struct graceful_restart_af { - afi_t afi; - safi_t safi; + uint16_t afi; + uint8_t safi; uint8_t flag; }; +/* + * +--------------------------------------------------+ + * | Address Family Identifier (16 bits) | + * +--------------------------------------------------+ + * | Subsequent Address Family Identifier (8 bits) | + * +--------------------------------------------------+ + * | Flags for Address Family (8 bits) | + * +--------------------------------------------------+ + * | Long-lived Stale Time (24 bits) | + * +--------------------------------------------------+ + */ +#define BGP_CAP_LLGR_MIN_PACKET_LEN 7 + /* Capability Code */ #define CAPABILITY_CODE_MP 1 /* Multiprotocol Extensions */ #define CAPABILITY_CODE_REFRESH 2 /* Route Refresh Capability */ #define CAPABILITY_CODE_ORF 3 /* Cooperative Route Filtering Capability */ #define CAPABILITY_CODE_RESTART 64 /* Graceful Restart Capability */ #define CAPABILITY_CODE_AS4 65 /* 4-octet AS number Capability */ -#define CAPABILITY_CODE_DYNAMIC_OLD 66 /* Dynamic Capability, deprecated since 2003 */ #define CAPABILITY_CODE_DYNAMIC 67 /* Dynamic Capability */ #define CAPABILITY_CODE_ADDPATH 69 /* Addpath Capability */ #define CAPABILITY_CODE_ENHANCED_RR 70 /* Enhanced Route Refresh capability */ @@ -39,8 +51,6 @@ struct graceful_restart_af { #define CAPABILITY_CODE_FQDN 73 /* Advertise hostname capability */ #define CAPABILITY_CODE_SOFT_VERSION 75 /* Software Version capability */ #define CAPABILITY_CODE_ENHE 5 /* Extended Next Hop Encoding */ -#define CAPABILITY_CODE_REFRESH_OLD 128 /* Route Refresh Capability(cisco) */ -#define CAPABILITY_CODE_ORF_OLD 130 /* Cooperative Route Filtering Capability(cisco) */ #define CAPABILITY_CODE_EXT_MESSAGE 6 /* Extended Message Support */ #define CAPABILITY_CODE_ROLE 9 /* Role Capability */ @@ -65,7 +75,6 @@ struct graceful_restart_af { /* ORF Type */ #define ORF_TYPE_RESERVED 0 #define ORF_TYPE_PREFIX 64 -#define ORF_TYPE_PREFIX_OLD 128 /* ORF Mode */ #define ORF_MODE_RECEIVE 1 @@ -98,5 +107,8 @@ extern uint16_t bgp_open_capability(struct stream *s, struct peer *peer, extern void bgp_capability_vty_out(struct vty *vty, struct peer *peer, bool use_json, json_object *json_neigh); extern as_t peek_for_as4_capability(struct peer *peer, uint16_t length); +extern const struct message capcode_str[]; +extern const struct message orf_type_str[]; +extern const struct message orf_mode_str[]; #endif /* _QUAGGA_BGP_OPEN_H */ diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index 9469a0778f..f94b64d0bd 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -24,6 +24,7 @@ #include "lib_errors.h" #include "bgpd/bgpd.h" +#include "bgpd/bgp_addpath.h" #include "bgpd/bgp_table.h" #include "bgpd/bgp_dump.h" #include "bgpd/bgp_bmp.h" @@ -105,21 +106,22 @@ void bgp_packet_set_size(struct stream *s) * Push a packet onto the beginning of the peer's output queue. * This function acquires the peer's write mutex before proceeding. */ -static void bgp_packet_add(struct peer *peer, struct stream *s) +static void bgp_packet_add(struct peer_connection *connection, + struct peer *peer, struct stream *s) { intmax_t delta; uint32_t holdtime; intmax_t sendholdtime; - frr_with_mutex (&peer->io_mtx) { + frr_with_mutex (&connection->io_mtx) { /* if the queue is empty, reset the "last OK" timestamp to * now, otherwise if we write another packet immediately * after it'll get confused */ - if (!stream_fifo_count_safe(peer->obuf)) + if (!stream_fifo_count_safe(connection->obuf)) peer->last_sendq_ok = monotime(NULL); - stream_fifo_push(peer->obuf, s); + stream_fifo_push(connection->obuf, s); delta = monotime(NULL) - peer->last_sendq_ok; @@ -146,7 +148,7 @@ static void bgp_packet_add(struct peer *peer, struct stream *s) EC_BGP_SENDQ_STUCK_PROPER, "%pBP has not made any SendQ progress for 2 holdtimes (%jds), terminating session", peer, sendholdtime); - BGP_EVENT_ADD(peer, TCP_fatal_error); + BGP_EVENT_ADD(connection, TCP_fatal_error); } else if (delta > (intmax_t)holdtime && monotime(NULL) - peer->last_sendq_warn > 5) { flog_warn( @@ -260,7 +262,7 @@ void bgp_update_restarted_peers(struct peer *peer) if (bgp_debug_neighbor_events(peer)) zlog_debug("Peer %s: Checking restarted", peer->host); - if (peer_established(peer)) { + if (peer_established(peer->connection)) { peer->update_delay_over = 1; peer->bgp->restarted_peers++; bgp_check_update_delay(peer->bgp); @@ -283,7 +285,7 @@ void bgp_update_implicit_eors(struct peer *peer) if (bgp_debug_neighbor_events(peer)) zlog_debug("Peer %s: Checking implicit EORs", peer->host); - if (peer_established(peer)) { + if (peer_established(peer->connection)) { peer->update_delay_over = 1; peer->bgp->implicit_eors++; bgp_check_update_delay(peer->bgp); @@ -391,6 +393,7 @@ static void bgp_write_proceed_actions(struct peer *peer) struct bpacket *next_pkt; struct update_subgroup *subgrp; enum bgp_af_index index; + struct peer_connection *connection = peer->connection; for (index = BGP_AF_START; index < BGP_AF_MAX; index++) { paf = peer->peer_af_array[index]; @@ -403,7 +406,7 @@ static void bgp_write_proceed_actions(struct peer *peer) next_pkt = paf->next_pkt_to_send; if (next_pkt && next_pkt->buffer) { - BGP_TIMER_ON(peer->t_generate_updgrp_packets, + BGP_TIMER_ON(connection->t_generate_updgrp_packets, bgp_generate_updgrp_packets, 0); return; } @@ -414,7 +417,7 @@ static void bgp_write_proceed_actions(struct peer *peer) if (bpacket_queue_is_full(SUBGRP_INST(subgrp), SUBGRP_PKTQ(subgrp)) || subgroup_packets_to_build(subgrp)) { - BGP_TIMER_ON(peer->t_generate_updgrp_packets, + BGP_TIMER_ON(connection->t_generate_updgrp_packets, bgp_generate_updgrp_packets, 0); return; } @@ -429,7 +432,7 @@ static void bgp_write_proceed_actions(struct peer *peer) && !CHECK_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_EOR_SEND) && safi != SAFI_MPLS_VPN) { - BGP_TIMER_ON(peer->t_generate_updgrp_packets, + BGP_TIMER_ON(connection->t_generate_updgrp_packets, bgp_generate_updgrp_packets, 0); return; } @@ -444,8 +447,8 @@ static void bgp_write_proceed_actions(struct peer *peer) */ void bgp_generate_updgrp_packets(struct event *thread) { - struct peer *peer = EVENT_ARG(thread); - + struct peer_connection *connection = EVENT_ARG(thread); + struct peer *peer = connection->peer; struct stream *s; struct peer_af *paf; struct bpacket *next_pkt; @@ -462,14 +465,14 @@ void bgp_generate_updgrp_packets(struct event *thread) * if peer is Established and updates are not on hold (as part of * update-delay processing). */ - if (!peer_established(peer)) + if (!peer_established(peer->connection)) return; if ((peer->bgp->main_peers_update_hold) || bgp_update_delay_active(peer->bgp)) return; - if (peer->t_routeadv) + if (peer->connection->t_routeadv) return; /* @@ -477,7 +480,7 @@ void bgp_generate_updgrp_packets(struct event *thread) * let's stop adding to the outq if we are * already at the limit. */ - if (peer->obuf->count >= bm->outq_limit) { + if (connection->obuf->count >= bm->outq_limit) { bgp_write_proceed_actions(peer); return; } @@ -601,14 +604,14 @@ void bgp_generate_updgrp_packets(struct event *thread) * packet with appropriate attributes from peer * and advance peer */ s = bpacket_reformat_for_peer(next_pkt, paf); - bgp_packet_add(peer, s); + bgp_packet_add(connection, peer, s); bpacket_queue_advance_peer(paf); } } while (s && (++generated < wpq) && - (peer->obuf->count <= bm->outq_limit)); + (connection->obuf->count <= bm->outq_limit)); if (generated) - bgp_writes_on(peer); + bgp_writes_on(connection); bgp_write_proceed_actions(peer); } @@ -635,20 +638,21 @@ void bgp_keepalive_send(struct peer *peer) zlog_debug("%s sending KEEPALIVE", peer->host); /* Add packet to the peer. */ - bgp_packet_add(peer, s); + bgp_packet_add(peer->connection, peer, s); - bgp_writes_on(peer); + bgp_writes_on(peer->connection); } /* * Creates a BGP Open packet and appends it to the peer's output queue. * Sets capabilities as necessary. */ -void bgp_open_send(struct peer *peer) +void bgp_open_send(struct peer_connection *connection) { struct stream *s; uint16_t send_holdtime; as_t local_as; + struct peer *peer = connection->peer; if (CHECK_FLAG(peer->flags, PEER_FLAG_TIMER)) send_holdtime = peer->holdtime; @@ -704,31 +708,32 @@ void bgp_open_send(struct peer *peer) hook_call(bgp_packet_send, peer, BGP_MSG_OPEN, stream_get_endp(s), s); /* Add packet to the peer. */ - bgp_packet_add(peer, s); + bgp_packet_add(connection, peer, s); - bgp_writes_on(peer); + bgp_writes_on(connection); } /* * Writes NOTIFICATION message directly to a peer socket without waiting for * the I/O thread. * - * There must be exactly one stream on the peer->obuf FIFO, and the data within - * this stream must match the format of a BGP NOTIFICATION message. + * There must be exactly one stream on the peer->connection->obuf FIFO, and the + * data within this stream must match the format of a BGP NOTIFICATION message. * Transmission is best-effort. * - * @requires peer->io_mtx + * @requires peer->connection->io_mtx * @param peer * @return 0 */ -static void bgp_write_notify(struct peer *peer) +static void bgp_write_notify(struct peer_connection *connection, + struct peer *peer) { int ret, val; uint8_t type; struct stream *s; /* There should be at least one packet. */ - s = stream_fifo_pop(peer->obuf); + s = stream_fifo_pop(connection->obuf); if (!s) return; @@ -739,7 +744,7 @@ static void bgp_write_notify(struct peer *peer) * socket is in nonblocking mode, if we can't deliver the NOTIFY, well, * we only care about getting a clean shutdown at this point. */ - ret = write(peer->fd, STREAM_DATA(s), stream_get_endp(s)); + ret = write(connection->fd, STREAM_DATA(s), stream_get_endp(s)); /* * only connection reset/close gets counted as TCP_fatal_error, failure @@ -747,13 +752,13 @@ static void bgp_write_notify(struct peer *peer) */ if (ret <= 0) { stream_free(s); - BGP_EVENT_ADD(peer, TCP_fatal_error); + BGP_EVENT_ADD(connection, TCP_fatal_error); return; } /* Disable Nagle, make NOTIFY packet go out right away */ val = 1; - (void)setsockopt(peer->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, + (void)setsockopt(connection->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val)); /* Retrieve BGP packet type. */ @@ -776,7 +781,7 @@ static void bgp_write_notify(struct peer *peer) * Handle Graceful Restart case where the state changes to * Connect instead of Idle */ - BGP_EVENT_ADD(peer, BGP_Stop); + BGP_EVENT_ADD(connection, BGP_Stop); stream_free(s); } @@ -902,15 +907,17 @@ bool bgp_notify_received_hard_reset(struct peer *peer, uint8_t code, * @param data Data portion * @param datalen length of data portion */ -static void bgp_notify_send_internal(struct peer *peer, uint8_t code, - uint8_t sub_code, uint8_t *data, - size_t datalen, bool use_curr) +static void bgp_notify_send_internal(struct peer_connection *connection, + uint8_t code, uint8_t sub_code, + uint8_t *data, size_t datalen, + bool use_curr) { struct stream *s; + struct peer *peer = connection->peer; bool hard_reset = bgp_notify_send_hard_reset(peer, code, sub_code); /* Lock I/O mutex to prevent other threads from pushing packets */ - frr_mutex_lock_autounlock(&peer->io_mtx); + frr_mutex_lock_autounlock(&connection->io_mtx); /* ============================================== */ /* Allocate new stream. */ @@ -943,7 +950,7 @@ static void bgp_notify_send_internal(struct peer *peer, uint8_t code, bgp_packet_set_size(s); /* wipe output buffer */ - stream_fifo_clean(peer->obuf); + stream_fifo_clean(connection->obuf); /* * If possible, store last packet for debugging purposes. This check is @@ -956,8 +963,9 @@ static void bgp_notify_send_internal(struct peer *peer, uint8_t code, if (use_curr && peer->curr) { size_t packetsize = stream_get_endp(peer->curr); assert(packetsize <= peer->max_packet_size); - memcpy(peer->last_reset_cause, peer->curr->data, packetsize); - peer->last_reset_cause_size = packetsize; + if (peer->last_reset_cause) + stream_free(peer->last_reset_cause); + peer->last_reset_cause = stream_dup(peer->curr); } /* For debug */ @@ -1027,13 +1035,13 @@ static void bgp_notify_send_internal(struct peer *peer, uint8_t code, peer->last_reset = PEER_DOWN_NOTIFY_SEND; /* Add packet to peer's output queue */ - stream_fifo_push(peer->obuf, s); + stream_fifo_push(connection->obuf, s); bgp_peer_gr_flags_update(peer); BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(peer->bgp, peer->bgp->peer); - bgp_write_notify(peer); + bgp_write_notify(connection, peer); } /* @@ -1046,18 +1054,20 @@ static void bgp_notify_send_internal(struct peer *peer, uint8_t code, * @param code BGP error code * @param sub_code BGP error subcode */ -void bgp_notify_send(struct peer *peer, uint8_t code, uint8_t sub_code) +void bgp_notify_send(struct peer_connection *connection, uint8_t code, + uint8_t sub_code) { - bgp_notify_send_internal(peer, code, sub_code, NULL, 0, true); + bgp_notify_send_internal(connection, code, sub_code, NULL, 0, true); } /* * Enqueue notification; called from the main pthread, peer object access is ok. */ -void bgp_notify_send_with_data(struct peer *peer, uint8_t code, +void bgp_notify_send_with_data(struct peer_connection *connection, uint8_t code, uint8_t sub_code, uint8_t *data, size_t datalen) { - bgp_notify_send_internal(peer, code, sub_code, data, datalen, true); + bgp_notify_send_internal(connection, code, sub_code, data, datalen, + true); } /* @@ -1068,7 +1078,8 @@ void bgp_notify_io_invalid(struct peer *peer, uint8_t code, uint8_t sub_code, uint8_t *data, size_t datalen) { /* Avoid touching the peer object */ - bgp_notify_send_internal(peer, code, sub_code, data, datalen, false); + bgp_notify_send_internal(peer->connection, code, sub_code, data, + datalen, false); } /* @@ -1080,6 +1091,7 @@ void bgp_notify_io_invalid(struct peer *peer, uint8_t code, uint8_t sub_code, * @param orf_type Outbound Route Filtering type * @param when_to_refresh Whether to refresh immediately or defer * @param remove Whether to remove ORF for specified AFI/SAFI + * @param subtype BGP enhanced route refresh optional subtypes */ void bgp_route_refresh_send(struct peer *peer, afi_t afi, safi_t safi, uint8_t orf_type, uint8_t when_to_refresh, @@ -1102,7 +1114,7 @@ void bgp_route_refresh_send(struct peer *peer, afi_t afi, safi_t safi, s = stream_new(peer->max_packet_size); /* Make BGP update packet. */ - if (CHECK_FLAG(peer->cap, PEER_CAP_REFRESH_NEW_RCV)) + if (CHECK_FLAG(peer->cap, PEER_CAP_REFRESH_RCV)) bgp_packet_set_marker(s, BGP_MSG_ROUTE_REFRESH_NEW); else bgp_packet_set_marker(s, BGP_MSG_ROUTE_REFRESH_OLD); @@ -1115,7 +1127,7 @@ void bgp_route_refresh_send(struct peer *peer, afi_t afi, safi_t safi, stream_putc(s, 0); stream_putc(s, pkt_safi); - if (orf_type == ORF_TYPE_PREFIX || orf_type == ORF_TYPE_PREFIX_OLD) + if (orf_type == ORF_TYPE_PREFIX) if (remove || filter->plist[FILTER_IN].plist) { uint16_t orf_len; unsigned long orfp; @@ -1177,9 +1189,9 @@ void bgp_route_refresh_send(struct peer *peer, afi_t afi, safi_t safi, } /* Add packet to the peer. */ - bgp_packet_add(peer, s); + bgp_packet_add(peer->connection, peer, s); - bgp_writes_on(peer); + bgp_writes_on(peer->connection); } /* @@ -1197,6 +1209,24 @@ void bgp_capability_send(struct peer *peer, afi_t afi, safi_t safi, struct stream *s; iana_afi_t pkt_afi = IANA_AFI_IPV4; iana_safi_t pkt_safi = IANA_SAFI_UNICAST; + unsigned long cap_len; + uint16_t len; + uint32_t gr_restart_time; + uint8_t addpath_afi_safi_count = 0; + bool adv_addpath_tx = false; + unsigned long number_of_orfs_p; + uint8_t number_of_orfs = 0; + const char *capability = lookup_msg(capcode_str, capability_code, + "Unknown"); + const char *hostname = cmd_hostname_get(); + const char *domainname = cmd_domainname_get(); + + if (!peer_established(peer->connection)) + return; + + if (!CHECK_FLAG(peer->cap, PEER_CAP_DYNAMIC_RCV) && + !CHECK_FLAG(peer->cap, PEER_CAP_DYNAMIC_ADV)) + return; /* Convert AFI, SAFI to values for packet. */ bgp_map_afi_safi_int2iana(afi, safi, &pkt_afi, &pkt_safi); @@ -1207,7 +1237,41 @@ void bgp_capability_send(struct peer *peer, afi_t afi, safi_t safi, bgp_packet_set_marker(s, BGP_MSG_CAPABILITY); /* Encode MP_EXT capability. */ - if (capability_code == CAPABILITY_CODE_MP) { + switch (capability_code) { + case CAPABILITY_CODE_SOFT_VERSION: + SET_FLAG(peer->cap, PEER_CAP_SOFT_VERSION_ADV); + stream_putc(s, action); + stream_putc(s, CAPABILITY_CODE_SOFT_VERSION); + cap_len = stream_get_endp(s); + stream_putc(s, 0); /* Capability Length */ + + /* The Capability Length SHOULD be no greater than 64. + * This is the limit to allow other capabilities as much + * space as they require. + */ + const char *soft_version = cmd_software_version_get(); + + len = strlen(soft_version); + if (len > BGP_MAX_SOFT_VERSION) + len = BGP_MAX_SOFT_VERSION; + + stream_putc(s, len); + stream_put(s, soft_version, len); + + /* Software Version capability Len. */ + len = stream_get_endp(s) - cap_len - 1; + stream_putc_at(s, cap_len, len); + + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%pBP sending CAPABILITY has %s %s for afi/safi: %s/%s", + peer, + action == CAPABILITY_ACTION_SET + ? "Advertising" + : "Removing", + capability, iana_afi2str(pkt_afi), + iana_safi2str(pkt_safi)); + break; + case CAPABILITY_CODE_MP: stream_putc(s, action); stream_putc(s, CAPABILITY_CODE_MP); stream_putc(s, CAPABILITY_CODE_MP_LEN); @@ -1216,27 +1280,332 @@ void bgp_capability_send(struct peer *peer, afi_t afi, safi_t safi, stream_putc(s, pkt_safi); if (bgp_debug_neighbor_events(peer)) - zlog_debug( - "%pBP sending CAPABILITY has %s MP_EXT CAP for afi/safi: %s/%s", - peer, - action == CAPABILITY_ACTION_SET ? "Advertising" - : "Removing", - iana_afi2str(pkt_afi), iana_safi2str(pkt_safi)); + zlog_debug("%pBP sending CAPABILITY has %s %s for afi/safi: %s/%s", + peer, + action == CAPABILITY_ACTION_SET + ? "Advertising" + : "Removing", + capability, iana_afi2str(pkt_afi), + iana_safi2str(pkt_safi)); + break; + case CAPABILITY_CODE_RESTART: + if (!CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART) && + !CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART_HELPER)) + return; + + SET_FLAG(peer->cap, PEER_CAP_RESTART_ADV); + stream_putc(s, action); + stream_putc(s, CAPABILITY_CODE_RESTART); + cap_len = stream_get_endp(s); + stream_putc(s, 0); + gr_restart_time = peer->bgp->restart_time; + + if (peer->bgp->t_startup) { + SET_FLAG(gr_restart_time, GRACEFUL_RESTART_R_BIT); + SET_FLAG(peer->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_ADV); + } + + if (CHECK_FLAG(peer->bgp->flags, + BGP_FLAG_GRACEFUL_NOTIFICATION)) { + SET_FLAG(gr_restart_time, GRACEFUL_RESTART_N_BIT); + SET_FLAG(peer->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_ADV); + } + + stream_putw(s, gr_restart_time); + + if (CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART)) { + FOREACH_AFI_SAFI (afi, safi) { + if (!peer->afc[afi][safi]) + continue; + + bgp_map_afi_safi_int2iana(afi, safi, &pkt_afi, + &pkt_safi); + stream_putw(s, pkt_afi); + stream_putc(s, pkt_safi); + if (CHECK_FLAG(peer->bgp->flags, + BGP_FLAG_GR_PRESERVE_FWD)) + stream_putc(s, GRACEFUL_RESTART_F_BIT); + else + stream_putc(s, 0); + } + } + + len = stream_get_endp(s) - cap_len - 1; + stream_putc_at(s, cap_len, len); + + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%pBP sending CAPABILITY has %s %s for afi/safi: %s/%s", + peer, + action == CAPABILITY_ACTION_SET + ? "Advertising" + : "Removing", + capability, iana_afi2str(pkt_afi), + iana_safi2str(pkt_safi)); + + break; + case CAPABILITY_CODE_LLGR: + if (!CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)) + return; + + SET_FLAG(peer->cap, PEER_CAP_LLGR_ADV); + + stream_putc(s, action); + stream_putc(s, CAPABILITY_CODE_LLGR); + cap_len = stream_get_endp(s); + stream_putc(s, 0); + + FOREACH_AFI_SAFI (afi, safi) { + if (!peer->afc[afi][safi]) + continue; + + bgp_map_afi_safi_int2iana(afi, safi, &pkt_afi, + &pkt_safi); + + stream_putw(s, pkt_afi); + stream_putc(s, pkt_safi); + stream_putc(s, LLGR_F_BIT); + stream_put3(s, peer->bgp->llgr_stale_time); + + SET_FLAG(peer->af_cap[afi][safi], PEER_CAP_LLGR_AF_ADV); + } + + len = stream_get_endp(s) - cap_len - 1; + stream_putc_at(s, cap_len, len); + + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%pBP sending CAPABILITY has %s %s for afi/safi: %s/%s", + peer, + action == CAPABILITY_ACTION_SET + ? "Advertising" + : "Removing", + capability, iana_afi2str(pkt_afi), + iana_safi2str(pkt_safi)); + break; + case CAPABILITY_CODE_ADDPATH: + SET_FLAG(peer->cap, PEER_CAP_ADDPATH_ADV); + + FOREACH_AFI_SAFI (afi, safi) { + if (peer->afc[afi][safi]) { + addpath_afi_safi_count++; + + /* Only advertise addpath TX if a feature that + * will use it is + * configured */ + if (peer->addpath_type[afi][safi] != + BGP_ADDPATH_NONE) + adv_addpath_tx = true; + + /* If we have enabled labeled unicast, we MUST check + * against unicast SAFI because addpath IDs are + * allocated under unicast SAFI, the same as the RIB + * is managed in unicast SAFI. + */ + if (safi == SAFI_LABELED_UNICAST) + if (peer->addpath_type[afi][SAFI_UNICAST] != + BGP_ADDPATH_NONE) + adv_addpath_tx = true; + } + } + + stream_putc(s, action); + stream_putc(s, CAPABILITY_CODE_ADDPATH); + stream_putc(s, CAPABILITY_CODE_ADDPATH_LEN * + addpath_afi_safi_count); + + FOREACH_AFI_SAFI (afi, safi) { + if (peer->afc[afi][safi]) { + bool adv_addpath_rx = + !CHECK_FLAG(peer->af_flags[afi][safi], + PEER_FLAG_DISABLE_ADDPATH_RX); + uint8_t flags = 0; + + /* Convert AFI, SAFI to values for packet. */ + bgp_map_afi_safi_int2iana(afi, safi, &pkt_afi, + &pkt_safi); + + stream_putw(s, pkt_afi); + stream_putc(s, pkt_safi); + + if (adv_addpath_rx) { + SET_FLAG(flags, BGP_ADDPATH_RX); + SET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ADDPATH_AF_RX_ADV); + } else { + UNSET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ADDPATH_AF_RX_ADV); + } + + if (adv_addpath_tx) { + SET_FLAG(flags, BGP_ADDPATH_TX); + SET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ADDPATH_AF_TX_ADV); + if (safi == SAFI_LABELED_UNICAST) + SET_FLAG(peer->af_cap[afi] + [SAFI_UNICAST], + PEER_CAP_ADDPATH_AF_TX_ADV); + } else { + UNSET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ADDPATH_AF_TX_ADV); + } + + stream_putc(s, flags); + } + } + + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%pBP sending CAPABILITY has %s %s for afi/safi: %s/%s", + peer, + action == CAPABILITY_ACTION_SET + ? "Advertising" + : "Removing", + capability, iana_afi2str(pkt_afi), + iana_safi2str(pkt_safi)); + + break; + case CAPABILITY_CODE_ORF: + /* Convert AFI, SAFI to values for packet. */ + bgp_map_afi_safi_int2iana(afi, safi, &pkt_afi, &pkt_safi); + + stream_putc(s, action); + stream_putc(s, CAPABILITY_CODE_ORF); + cap_len = stream_get_endp(s); + stream_putc(s, 0); + + stream_putw(s, pkt_afi); /* Address Family Identifier */ + stream_putc(s, 0); /* Reserved */ + stream_putc(s, + pkt_safi); /* Subsequent Address Family Identifier */ + + number_of_orfs_p = + stream_get_endp(s); /* Number of ORFs pointer */ + stream_putc(s, 0); /* Number of ORFs */ + + /* Address Prefix ORF */ + if (CHECK_FLAG(peer->af_flags[afi][safi], + PEER_FLAG_ORF_PREFIX_SM) || + CHECK_FLAG(peer->af_flags[afi][safi], + PEER_FLAG_ORF_PREFIX_RM)) { + stream_putc(s, ORF_TYPE_PREFIX); + + if (CHECK_FLAG(peer->af_flags[afi][safi], + PEER_FLAG_ORF_PREFIX_SM) && + CHECK_FLAG(peer->af_flags[afi][safi], + PEER_FLAG_ORF_PREFIX_RM)) { + SET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ORF_PREFIX_SM_ADV); + SET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ORF_PREFIX_RM_ADV); + stream_putc(s, ORF_MODE_BOTH); + } else if (CHECK_FLAG(peer->af_flags[afi][safi], + PEER_FLAG_ORF_PREFIX_SM)) { + SET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ORF_PREFIX_SM_ADV); + UNSET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ORF_PREFIX_RM_ADV); + stream_putc(s, ORF_MODE_SEND); + } else { + SET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ORF_PREFIX_RM_ADV); + UNSET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ORF_PREFIX_SM_ADV); + stream_putc(s, ORF_MODE_RECEIVE); + } + number_of_orfs++; + } else { + UNSET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ORF_PREFIX_SM_ADV); + UNSET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ORF_PREFIX_RM_ADV); + } + + /* Total Number of ORFs. */ + stream_putc_at(s, number_of_orfs_p, number_of_orfs); + + len = stream_get_endp(s) - cap_len - 1; + stream_putc_at(s, cap_len, len); + + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%pBP sending CAPABILITY has %s %s for afi/safi: %s/%s", + peer, + action == CAPABILITY_ACTION_SET + ? "Advertising" + : "Removing", + capability, iana_afi2str(pkt_afi), + iana_safi2str(pkt_safi)); + break; + case CAPABILITY_CODE_FQDN: + if (hostname) { + SET_FLAG(peer->cap, PEER_CAP_HOSTNAME_ADV); + stream_putc(s, action); + stream_putc(s, CAPABILITY_CODE_FQDN); + cap_len = stream_get_endp(s); + stream_putc(s, 0); /* Capability Length */ + + len = strlen(hostname); + if (len > BGP_MAX_HOSTNAME) + len = BGP_MAX_HOSTNAME; + + stream_putc(s, len); + stream_put(s, hostname, len); + + if (domainname) { + len = strlen(domainname); + if (len > BGP_MAX_HOSTNAME) + len = BGP_MAX_HOSTNAME; + + stream_putc(s, len); + stream_put(s, domainname, len); + } else + stream_putc(s, 0); + + len = stream_get_endp(s) - cap_len - 1; + stream_putc_at(s, cap_len, len); + + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%pBP sending CAPABILITY has %s %s for afi/safi: %s/%s", + peer, + action == CAPABILITY_ACTION_SET + ? "Advertising" + : "Removing", + capability, iana_afi2str(pkt_afi), + iana_safi2str(pkt_safi)); + } + break; + case CAPABILITY_CODE_REFRESH: + case CAPABILITY_CODE_AS4: + case CAPABILITY_CODE_DYNAMIC: + case CAPABILITY_CODE_ENHANCED_RR: + case CAPABILITY_CODE_ENHE: + case CAPABILITY_CODE_EXT_MESSAGE: + break; + case CAPABILITY_CODE_ROLE: + if (peer->local_role != ROLE_UNDEFINED) { + SET_FLAG(peer->cap, PEER_CAP_ROLE_ADV); + stream_putc(s, action); + stream_putc(s, CAPABILITY_CODE_ROLE); + stream_putc(s, CAPABILITY_CODE_ROLE_LEN); + stream_putc(s, peer->local_role); + } + break; + default: + break; } /* Set packet size. */ bgp_packet_set_size(s); /* Add packet to the peer. */ - bgp_packet_add(peer, s); + bgp_packet_add(peer->connection, peer, s); - bgp_writes_on(peer); + bgp_writes_on(peer->connection); } /* RFC1771 6.8 Connection collision detection. */ -static int bgp_collision_detect(struct peer *new, struct in_addr remote_id) +static int bgp_collision_detect(struct peer_connection *connection, + struct peer *new, struct in_addr remote_id) { struct peer *peer; + struct peer_connection *other; /* * Upon receipt of an OPEN message, the local system must examine @@ -1252,18 +1621,22 @@ static int bgp_collision_detect(struct peer *new, struct in_addr remote_id) if (peer == NULL) return 0; + other = peer->connection; + /* * Do not accept the new connection in Established or Clearing * states. Note that a peer GR is handled by closing the existing * connection upon receipt of new one. */ - if (peer_established(peer) || peer->status == Clearing) { - bgp_notify_send(new, BGP_NOTIFY_CEASE, + if (peer_established(other) || + other->status == Clearing) { + bgp_notify_send(connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_COLLISION_RESOLUTION); return -1; } - if ((peer->status != OpenConfirm) && (peer->status != OpenSent)) + if ((other->status != OpenConfirm) && + (other->status != OpenSent)) return 0; /* @@ -1290,11 +1663,11 @@ static int bgp_collision_detect(struct peer *new, struct in_addr remote_id) * and accepts BGP connection initiated by * the remote system. */ - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(other, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_COLLISION_RESOLUTION); return 1; } else { - bgp_notify_send(new, BGP_NOTIFY_CEASE, + bgp_notify_send(connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_COLLISION_RESOLUTION); return -1; } @@ -1313,11 +1686,11 @@ static int bgp_collision_detect(struct peer *new, struct in_addr remote_id) * OpenConfirm state). */ if (CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER)) { - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(other, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_COLLISION_RESOLUTION); return 1; } else { - bgp_notify_send(new, BGP_NOTIFY_CEASE, + bgp_notify_send(connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_COLLISION_RESOLUTION); return -1; } @@ -1344,7 +1717,7 @@ static int bgp_collision_detect(struct peer *new, struct in_addr remote_id) * Side effects * ------------ * - May send NOTIFY messages - * - May not modify peer->status + * - May not modify peer->connection->status * - May not call bgp_event_update() */ @@ -1360,7 +1733,8 @@ static int bgp_collision_detect(struct peer *new, struct in_addr remote_id) * @param size size of the packet * @return as in summary */ -static int bgp_open_receive(struct peer *peer, bgp_size_t size) +static int bgp_open_receive(struct peer_connection *connection, + struct peer *peer, bgp_size_t size) { int ret; uint8_t version; @@ -1399,7 +1773,7 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) EC_BGP_PKT_OPEN, "%s: stream does not have enough bytes for extended optional parameters", peer->host); - bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send(connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_MALFORMED_ATTR); return BGP_Stop; } @@ -1411,7 +1785,7 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) EC_BGP_PKT_OPEN, "%s: stream does not have enough bytes to read the extended optional parameters optlen", peer->host); - bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send(connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_MALFORMED_ATTR); return BGP_Stop; } @@ -1438,7 +1812,7 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) flog_err(EC_BGP_PKT_OPEN, "%s: stream has not enough bytes (%u)", peer->host, optlen); - bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send(connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_MALFORMED_ATTR); return BGP_Stop; } @@ -1460,7 +1834,7 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) flog_err(EC_BGP_PKT_OPEN, "%s bad OPEN, got AS4 capability, but AS4 set to 0", peer->host); - bgp_notify_send_with_data(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send_with_data(connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_BAD_PEER_AS, notify_data_remote_as4, 4); return BGP_Stop; @@ -1470,7 +1844,7 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) if (remote_as == BGP_AS_ZERO) { flog_err(EC_BGP_PKT_OPEN, "%s bad OPEN, got AS set to 0", peer->host); - bgp_notify_send(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send(connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_BAD_PEER_AS); return BGP_Stop; } @@ -1485,7 +1859,8 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) EC_BGP_PKT_OPEN, "%s [AS4] NEW speaker using AS_TRANS for AS4, not allowed", peer->host); - bgp_notify_send_with_data(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send_with_data(connection, + BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_BAD_PEER_AS, notify_data_remote_as4, 4); return BGP_Stop; @@ -1513,7 +1888,8 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) EC_BGP_PKT_OPEN, "%s bad OPEN, got AS4 capability, but remote_as %u mismatch with 16bit 'myasn' %u in open", peer->host, as4, remote_as); - bgp_notify_send_with_data(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send_with_data(connection, + BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_BAD_PEER_AS, notify_data_remote_as4, 4); return BGP_Stop; @@ -1533,7 +1909,7 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) if (bgp_debug_neighbor_events(peer)) zlog_debug("%s bad OPEN, wrong router identifier %pI4", peer->host, &remote_id); - bgp_notify_send_with_data(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send_with_data(connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_BAD_BGP_IDENT, notify_data_remote_id, 4); return BGP_Stop; @@ -1548,7 +1924,7 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) "%s bad protocol version, remote requested %d, local request %d", peer->host, version, BGP_VERSION_4); /* Data must be in network byte order here */ - bgp_notify_send_with_data(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send_with_data(connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_UNSUP_VERSION, (uint8_t *)&maxver, 2); return BGP_Stop; @@ -1560,7 +1936,7 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) zlog_debug( "%s bad OPEN, remote AS is unspecified currently", peer->host); - bgp_notify_send_with_data(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send_with_data(connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_BAD_PEER_AS, notify_data_remote_as, 2); return BGP_Stop; @@ -1570,7 +1946,8 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) zlog_debug( "%s bad OPEN, remote AS is %u, internal specified", peer->host, remote_as); - bgp_notify_send_with_data(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send_with_data(connection, + BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_BAD_PEER_AS, notify_data_remote_as, 2); return BGP_Stop; @@ -1582,7 +1959,8 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) zlog_debug( "%s bad OPEN, remote AS is %u, external specified", peer->host, remote_as); - bgp_notify_send_with_data(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send_with_data(connection, + BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_BAD_PEER_AS, notify_data_remote_as, 2); return BGP_Stop; @@ -1592,7 +1970,7 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) if (bgp_debug_neighbor_events(peer)) zlog_debug("%s bad OPEN, remote AS is %u, expected %u", peer->host, remote_as, peer->as); - bgp_notify_send_with_data(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send_with_data(connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_BAD_PEER_AS, notify_data_remote_as, 2); return BGP_Stop; @@ -1602,7 +1980,7 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) * When collision is detected and this peer is closed. * Return immediately. */ - ret = bgp_collision_detect(peer, remote_id); + ret = bgp_collision_detect(connection, peer, remote_id); if (ret < 0) return BGP_Stop; @@ -1625,7 +2003,7 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) */ if (holdtime < 3 && holdtime != 0) { - bgp_notify_send_with_data(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send_with_data(connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_UNACEP_HOLDTIME, (uint8_t *)holdtime_ptr, 2); return BGP_Stop; @@ -1635,7 +2013,7 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) * is smaller than configured minimum Hold Time. */ if (holdtime < peer->bgp->default_min_holdtime && peer->bgp->default_min_holdtime != 0) { - bgp_notify_send_with_data(peer, BGP_NOTIFY_OPEN_ERR, + bgp_notify_send_with_data(connection, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_UNACEP_HOLDTIME, (uint8_t *)holdtime_ptr, 2); return BGP_Stop; @@ -1733,14 +2111,17 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) || peer->afc_nego[AFI_IP6][SAFI_MULTICAST] || peer->afc_nego[AFI_IP6][SAFI_MPLS_VPN] || peer->afc_nego[AFI_IP6][SAFI_ENCAP]) { - if (IN6_IS_ADDR_UNSPECIFIED(&peer->nexthop.v6_global)) { -#if defined(HAVE_CUMULUS) - zlog_warn("%s: No local IPv6 address, BGP routing may not work", - peer->host); -#endif + if (IN6_IS_ADDR_UNSPECIFIED(&peer->nexthop.v6_global) && + !bm->v6_with_v4_nexthops) { + flog_err(EC_BGP_SND_FAIL, +"%s: No local IPv6 address, and zebra does not support V6 routing with v4 nexthops, BGP routing for V6 will not work", + peer->host); + bgp_notify_send(connection, BGP_NOTIFY_CEASE, + BGP_NOTIFY_SUBCODE_UNSPECIFIC); + return BGP_Stop; } } - peer->rtt = sockopt_tcp_rtt(peer->fd); + peer->rtt = sockopt_tcp_rtt(connection->fd); return Receive_OPEN_message; } @@ -1752,14 +2133,15 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) * @param size size of the packet * @return as in summary */ -static int bgp_keepalive_receive(struct peer *peer, bgp_size_t size) +static int bgp_keepalive_receive(struct peer_connection *connection, + struct peer *peer, bgp_size_t size) { if (bgp_debug_keepalive(peer)) zlog_debug("%s KEEPALIVE rcvd", peer->host); bgp_update_implicit_eors(peer); - peer->rtt = sockopt_tcp_rtt(peer->fd); + peer->rtt = sockopt_tcp_rtt(connection->fd); /* If the peer's RTT is higher than expected, shutdown * the peer automatically. @@ -1812,7 +2194,7 @@ static void bgp_refresh_stalepath_timer_expire(struct event *thread) "%pBP route-refresh (BoRR) timer expired for afi/safi: %d/%d", peer, afi, safi); - bgp_timer_set(peer); + bgp_timer_set(peer->connection); } /** @@ -1824,7 +2206,8 @@ static void bgp_refresh_stalepath_timer_expire(struct event *thread) * @param size size of the packet * @return as in summary */ -static int bgp_update_receive(struct peer *peer, bgp_size_t size) +static int bgp_update_receive(struct peer_connection *connection, + struct peer *peer, bgp_size_t size) { int ret, nlri_ret; uint8_t *end; @@ -1845,13 +2228,14 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size) struct bgp_nlri nlris[NLRI_TYPE_MAX]; /* Status must be Established. */ - if (!peer_established(peer)) { + if (!peer_established(connection)) { flog_err(EC_BGP_INVALID_STATUS, "%s [FSM] Update packet received under status %s", peer->host, - lookup_msg(bgp_status_msg, peer->status, NULL)); - bgp_notify_send(peer, BGP_NOTIFY_FSM_ERR, - bgp_fsm_error_subcode(peer->status)); + lookup_msg(bgp_status_msg, peer->connection->status, + NULL)); + bgp_notify_send(connection, BGP_NOTIFY_FSM_ERR, + bgp_fsm_error_subcode(peer->connection->status)); return BGP_Stop; } @@ -1874,7 +2258,7 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size) flog_err(EC_BGP_UPDATE_RCV, "%s [Error] Update packet error (packet length is short for unfeasible length)", peer->host); - bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR, + bgp_notify_send(connection, BGP_NOTIFY_UPDATE_ERR, BGP_NOTIFY_UPDATE_MAL_ATTR); return BGP_Stop; } @@ -1887,7 +2271,7 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size) flog_err(EC_BGP_UPDATE_RCV, "%s [Error] Update packet error (packet unfeasible length overflow %d)", peer->host, withdraw_len); - bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR, + bgp_notify_send(connection, BGP_NOTIFY_UPDATE_ERR, BGP_NOTIFY_UPDATE_MAL_ATTR); return BGP_Stop; } @@ -1907,7 +2291,7 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size) EC_BGP_UPDATE_PACKET_SHORT, "%s [Error] Packet Error (update packet is short for attribute length)", peer->host); - bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR, + bgp_notify_send(peer->connection, BGP_NOTIFY_UPDATE_ERR, BGP_NOTIFY_UPDATE_MAL_ATTR); return BGP_Stop; } @@ -1921,7 +2305,7 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size) EC_BGP_UPDATE_PACKET_LONG, "%s [Error] Packet Error (update packet attribute length overflow %d)", peer->host, attribute_len); - bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR, + bgp_notify_send(connection, BGP_NOTIFY_UPDATE_ERR, BGP_NOTIFY_UPDATE_MAL_ATTR); return BGP_Stop; } @@ -1965,7 +2349,8 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size) "%pBP rcvd UPDATE with errors in attr(s)!! Withdrawing route.", peer); - if (ret && bgp_debug_update(peer, NULL, NULL, 1)) { + if (ret && bgp_debug_update(peer, NULL, NULL, 1) && + BGP_DEBUG(update, UPDATE_DETAIL)) { zlog_debug("%pBP rcvd UPDATE w/ attr: %s", peer, peer->rcvd_attr_str); peer->rcvd_attr_printed = 1; @@ -1975,7 +2360,12 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size) /* Network Layer Reachability Information. */ update_len = end - stream_pnt(s); - if (update_len) { + /* If we received MP_UNREACH_NLRI attribute, but also NLRIs, then + * NLRIs should be handled as a new data. Though, if we received + * NLRIs without mandatory attributes, they should be ignored. + */ + if (update_len && attribute_len && + attr_parse_ret != BGP_ATTR_PARSE_MISSING_MANDATORY) { /* Set NLRI portion to structure. */ nlris[NLRI_UPDATE].afi = AFI_IP; nlris[NLRI_UPDATE].safi = SAFI_UNICAST; @@ -1995,7 +2385,7 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size) } } - if (BGP_DEBUG(update, UPDATE_IN)) + if (BGP_DEBUG(update, UPDATE_IN) && BGP_DEBUG(update, UPDATE_DETAIL)) zlog_debug("%pBP rcvd UPDATE wlen %d attrlen %d alen %d", peer, withdraw_len, attribute_len, update_len); @@ -2036,12 +2426,12 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size) && nlri_ret != BGP_NLRI_PARSE_ERROR_PREFIX_OVERFLOW) { flog_err(EC_BGP_UPDATE_RCV, "%s [Error] Error parsing NLRI", peer->host); - if (peer_established(peer)) - bgp_notify_send( - peer, BGP_NOTIFY_UPDATE_ERR, - i <= NLRI_WITHDRAW - ? BGP_NOTIFY_UPDATE_INVAL_NETWORK - : BGP_NOTIFY_UPDATE_OPT_ATTR_ERR); + if (peer_established(connection)) + bgp_notify_send(connection, + BGP_NOTIFY_UPDATE_ERR, + i <= NLRI_WITHDRAW + ? BGP_NOTIFY_UPDATE_INVAL_NETWORK + : BGP_NOTIFY_UPDATE_OPT_ATTR_ERR); bgp_attr_unintern_sub(&attr); return BGP_Stop; } @@ -2052,8 +2442,7 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size) * Non-MP IPv4/Unicast EoR is a completely empty UPDATE * and MP EoR should have only an empty MP_UNREACH */ - if ((!update_len && !withdraw_len && nlris[NLRI_MP_UPDATE].length == 0) - || (attr_parse_ret == BGP_ATTR_PARSE_EOR)) { + if (!update_len && !withdraw_len && nlris[NLRI_MP_UPDATE].length == 0) { afi_t afi = 0; safi_t safi; struct graceful_restart_info *gr_info; @@ -2074,9 +2463,6 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size) && nlris[NLRI_MP_WITHDRAW].length == 0) { afi = nlris[NLRI_MP_WITHDRAW].afi; safi = nlris[NLRI_MP_WITHDRAW].safi; - } else if (attr_parse_ret == BGP_ATTR_PARSE_EOR) { - afi = nlris[NLRI_MP_UPDATE].afi; - safi = nlris[NLRI_MP_UPDATE].safi; } if (afi && peer->afc[afi][safi]) { @@ -2149,7 +2535,8 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size) * @param size size of the packet * @return as in summary */ -static int bgp_notify_receive(struct peer *peer, bgp_size_t size) +static int bgp_notify_receive(struct peer_connection *connection, + struct peer *peer, bgp_size_t size) { struct bgp_notify outer = {}; struct bgp_notify inner = {}; @@ -2270,7 +2657,8 @@ static int bgp_notify_receive(struct peer *peer, bgp_size_t size) * @param size size of the packet * @return as in summary */ -static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) +static int bgp_route_refresh_receive(struct peer_connection *connection, + struct peer *peer, bgp_size_t size) { iana_afi_t pkt_afi; afi_t afi; @@ -2290,20 +2678,20 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) flog_err(EC_BGP_NO_CAP, "%s [Error] BGP route refresh is not enabled", peer->host); - bgp_notify_send(peer, BGP_NOTIFY_HEADER_ERR, + bgp_notify_send(connection, BGP_NOTIFY_HEADER_ERR, BGP_NOTIFY_HEADER_BAD_MESTYPE); return BGP_Stop; } /* Status must be Established. */ - if (!peer_established(peer)) { - flog_err( - EC_BGP_INVALID_STATUS, - "%s [Error] Route refresh packet received under status %s", - peer->host, - lookup_msg(bgp_status_msg, peer->status, NULL)); - bgp_notify_send(peer, BGP_NOTIFY_FSM_ERR, - bgp_fsm_error_subcode(peer->status)); + if (!peer_established(connection)) { + flog_err(EC_BGP_INVALID_STATUS, + "%s [Error] Route refresh packet received under status %s", + peer->host, + lookup_msg(bgp_status_msg, peer->connection->status, + NULL)); + bgp_notify_send(connection, BGP_NOTIFY_FSM_ERR, + bgp_fsm_error_subcode(peer->connection->status)); return BGP_Stop; } @@ -2341,9 +2729,9 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) zlog_err( "%s Enhanced Route Refresh message length error", peer->host); - bgp_notify_send( - peer, BGP_NOTIFY_ROUTE_REFRESH_ERR, - BGP_NOTIFY_ROUTE_REFRESH_INVALID_MSG_LEN); + bgp_notify_send(connection, + BGP_NOTIFY_ROUTE_REFRESH_ERR, + BGP_NOTIFY_ROUTE_REFRESH_INVALID_MSG_LEN); } /* When the BGP speaker receives a ROUTE-REFRESH message @@ -2359,7 +2747,7 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) if (msg_length < 5) { zlog_info("%s ORF route refresh length error", peer->host); - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_SUBCODE_UNSPECIFIC); return BGP_Stop; } @@ -2374,8 +2762,7 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) /* orf_len in bounds? */ if ((stream_pnt(s) + orf_len) > end) break; /* XXX: Notify instead?? */ - if (orf_type == ORF_TYPE_PREFIX - || orf_type == ORF_TYPE_PREFIX_OLD) { + if (orf_type == ORF_TYPE_PREFIX) { uint8_t *p_pnt = stream_pnt(s); uint8_t *p_end = stream_pnt(s) + orf_len; struct orf_prefix orfp; @@ -2400,7 +2787,8 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) * and 7 bytes of ORF Address-filter entry from * the stream */ - if (*p_pnt & ORF_COMMON_PART_REMOVE_ALL) { + if (p_pnt < p_end && + *p_pnt & ORF_COMMON_PART_REMOVE_ALL) { if (bgp_debug_neighbor_events(peer)) zlog_debug( "%pBP rcvd Remove-All pfxlist ORF request", @@ -2594,7 +2982,7 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) bgp_set_stale_route(peer, afi, safi); } - if (peer_established(peer)) + if (peer_established(peer->connection)) event_add_timer(bm->master, bgp_refresh_stalepath_timer_expire, paf, peer->bgp->stalepath_time, @@ -2679,6 +3067,524 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) return BGP_PACKET_NOOP; } +static void bgp_dynamic_capability_addpath(uint8_t *pnt, int action, + struct capability_header *hdr, + struct peer *peer) +{ + uint8_t *data = pnt + 3; + uint8_t *end = data + hdr->length; + size_t len = end - data; + afi_t afi; + safi_t safi; + + if (action == CAPABILITY_ACTION_SET) { + if (len % CAPABILITY_CODE_ADDPATH_LEN) { + flog_warn(EC_BGP_CAPABILITY_INVALID_LENGTH, + "Add Path: Received invalid length %zu, non-multiple of 4", + len); + return; + } + + SET_FLAG(peer->cap, PEER_CAP_ADDPATH_RCV); + + while (data + CAPABILITY_CODE_ADDPATH_LEN <= end) { + afi_t afi; + safi_t safi; + iana_afi_t pkt_afi; + iana_safi_t pkt_safi; + struct bgp_addpath_capability bac; + + memcpy(&bac, data, sizeof(bac)); + pkt_afi = ntohs(bac.afi); + pkt_safi = safi_int2iana(bac.safi); + + /* If any other value (other than 1-3) is received, + * then the capability SHOULD be treated as not + * understood and ignored. + */ + if (!bac.flags || bac.flags > 3) { + flog_warn(EC_BGP_CAPABILITY_INVALID_LENGTH, + "Add Path: Received invalid send/receive value %u in Add Path capability", + bac.flags); + goto ignore; + } + + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%s OPEN has %s capability for afi/safi: %s/%s%s%s", + peer->host, + lookup_msg(capcode_str, hdr->code, + NULL), + iana_afi2str(pkt_afi), + iana_safi2str(pkt_safi), + (bac.flags & BGP_ADDPATH_RX) + ? ", receive" + : "", + (bac.flags & BGP_ADDPATH_TX) + ? ", transmit" + : ""); + + if (bgp_map_afi_safi_iana2int(pkt_afi, pkt_safi, &afi, + &safi)) { + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%s Addr-family %s/%s(afi/safi) not supported. Ignore the Addpath Attribute for this AFI/SAFI", + peer->host, + iana_afi2str(pkt_afi), + iana_safi2str(pkt_safi)); + goto ignore; + } else if (!peer->afc[afi][safi]) { + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%s Addr-family %s/%s(afi/safi) not enabled. Ignore the AddPath capability for this AFI/SAFI", + peer->host, + iana_afi2str(pkt_afi), + iana_safi2str(pkt_safi)); + goto ignore; + } + + if (CHECK_FLAG(bac.flags, BGP_ADDPATH_RX)) + SET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ADDPATH_AF_RX_RCV); + else + UNSET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ADDPATH_AF_RX_RCV); + + if (CHECK_FLAG(bac.flags, BGP_ADDPATH_TX)) + SET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ADDPATH_AF_TX_RCV); + else + UNSET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ADDPATH_AF_TX_RCV); + +ignore: + data += CAPABILITY_CODE_ADDPATH_LEN; + } + } else { + FOREACH_AFI_SAFI (afi, safi) { + UNSET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ADDPATH_AF_RX_RCV); + UNSET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ADDPATH_AF_TX_RCV); + } + + UNSET_FLAG(peer->cap, PEER_CAP_ADDPATH_RCV); + } +} + +static void bgp_dynamic_capability_orf(uint8_t *pnt, int action, + struct capability_header *hdr, + struct peer *peer) +{ + uint8_t *data = pnt + 3; + uint8_t *end = data + hdr->length; + size_t len = end - data; + + struct capability_mp_data mpc; + uint8_t num; + iana_afi_t pkt_afi; + afi_t afi; + iana_safi_t pkt_safi; + safi_t safi; + uint8_t type; + uint8_t mode; + uint16_t sm_cap = PEER_CAP_ORF_PREFIX_SM_RCV; + uint16_t rm_cap = PEER_CAP_ORF_PREFIX_RM_RCV; + int i; + + if (data + CAPABILITY_CODE_ORF_LEN > end) { + flog_warn(EC_BGP_CAPABILITY_INVALID_LENGTH, + "ORF: Received invalid length %zu, less than %d", len, + CAPABILITY_CODE_ORF_LEN); + return; + } + + /* ORF Entry header */ + memcpy(&mpc, data, sizeof(mpc)); + data += sizeof(mpc); + num = *data++; + pkt_afi = ntohs(mpc.afi); + pkt_safi = mpc.safi; + + /* Convert AFI, SAFI to internal values, check. */ + if (bgp_map_afi_safi_iana2int(pkt_afi, pkt_safi, &afi, &safi)) { + zlog_info("%pBP Addr-family %d/%d not supported. Ignoring the ORF capability", + peer, pkt_afi, pkt_safi); + return; + } + + /* validate number field */ + if (CAPABILITY_CODE_ORF_LEN + (num * 2) > hdr->length) { + zlog_info("%pBP ORF Capability entry length error, Cap length %u, num %u", + peer, hdr->length, num); + return; + } + + if (action == CAPABILITY_ACTION_UNSET) { + UNSET_FLAG(peer->af_cap[afi][safi], sm_cap); + UNSET_FLAG(peer->af_cap[afi][safi], rm_cap); + return; + } + + for (i = 0; i < num; i++) { + if (data + 1 > end) { + flog_err(EC_BGP_CAPABILITY_INVALID_LENGTH, + "%pBP ORF Capability entry length (type) error, Cap length %u, num %u", + peer, hdr->length, num); + return; + } + type = *data++; + + if (data + 1 > end) { + flog_err(EC_BGP_CAPABILITY_INVALID_LENGTH, + "%pBP ORF Capability entry length (mode) error, Cap length %u, num %u", + peer, hdr->length, num); + return; + } + mode = *data++; + + /* ORF Mode error check */ + switch (mode) { + case ORF_MODE_BOTH: + case ORF_MODE_SEND: + case ORF_MODE_RECEIVE: + break; + default: + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%pBP Addr-family %d/%d has ORF type/mode %d/%d not supported", + peer, afi, safi, type, mode); + continue; + } + + if (!((afi == AFI_IP && safi == SAFI_UNICAST) || + (afi == AFI_IP && safi == SAFI_MULTICAST) || + (afi == AFI_IP6 && safi == SAFI_UNICAST))) { + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%pBP Addr-family %d/%d unsupported AFI/SAFI received", + peer, afi, safi); + continue; + } + + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%pBP OPEN has %s ORF capability as %s for afi/safi: %s/%s", + peer, lookup_msg(orf_type_str, type, NULL), + lookup_msg(orf_mode_str, mode, NULL), + iana_afi2str(pkt_afi), + iana_safi2str(pkt_safi)); + + switch (mode) { + case ORF_MODE_BOTH: + SET_FLAG(peer->af_cap[afi][safi], sm_cap); + SET_FLAG(peer->af_cap[afi][safi], rm_cap); + break; + case ORF_MODE_SEND: + SET_FLAG(peer->af_cap[afi][safi], sm_cap); + UNSET_FLAG(peer->af_cap[afi][safi], rm_cap); + break; + case ORF_MODE_RECEIVE: + SET_FLAG(peer->af_cap[afi][safi], rm_cap); + UNSET_FLAG(peer->af_cap[afi][safi], sm_cap); + break; + } + } +} + +static void bgp_dynamic_capability_fqdn(uint8_t *pnt, int action, + struct capability_header *hdr, + struct peer *peer) +{ + uint8_t *data = pnt + 3; + uint8_t *end = data + hdr->length; + char str[BGP_MAX_HOSTNAME + 1] = {}; + uint8_t len; + + if (action == CAPABILITY_ACTION_SET) { + /* hostname */ + if (data + 1 > end) { + zlog_err("%pBP: Received invalid FQDN capability (host name length)", + peer); + return; + } + + len = *data; + if (data + len > end) { + zlog_err("%pBP: Received invalid FQDN capability length (host name) %d", + peer, hdr->length); + return; + } + data++; + + if (len > BGP_MAX_HOSTNAME) { + memcpy(&str, data, BGP_MAX_HOSTNAME); + str[BGP_MAX_HOSTNAME] = '\0'; + } else if (len) { + memcpy(&str, data, len); + str[len] = '\0'; + } + data += len; + + if (len) { + XFREE(MTYPE_BGP_PEER_HOST, peer->hostname); + XFREE(MTYPE_BGP_PEER_HOST, peer->domainname); + + peer->hostname = XSTRDUP(MTYPE_BGP_PEER_HOST, str); + } + + if (data + 1 > end) { + zlog_err("%pBP: Received invalid FQDN capability (domain name length)", + peer); + return; + } + + /* domainname */ + len = *data; + if (data + len > end) { + zlog_err("%pBP: Received invalid FQDN capability length (domain name) %d", + peer, len); + return; + } + data++; + + if (len > BGP_MAX_HOSTNAME) { + memcpy(&str, data, BGP_MAX_HOSTNAME); + str[BGP_MAX_HOSTNAME] = '\0'; + } else if (len) { + memcpy(&str, data, len); + str[len] = '\0'; + } + /* data += len; In case new code is ever added */ + + if (len) { + XFREE(MTYPE_BGP_PEER_HOST, peer->domainname); + + peer->domainname = XSTRDUP(MTYPE_BGP_PEER_HOST, str); + } + + SET_FLAG(peer->cap, PEER_CAP_HOSTNAME_RCV); + } else { + UNSET_FLAG(peer->cap, PEER_CAP_HOSTNAME_RCV); + XFREE(MTYPE_BGP_PEER_HOST, peer->hostname); + XFREE(MTYPE_BGP_PEER_HOST, peer->domainname); + } +} + +static void bgp_dynamic_capability_llgr(uint8_t *pnt, int action, + struct capability_header *hdr, + struct peer *peer) +{ + uint8_t *data = pnt + 3; + uint8_t *end = data + hdr->length; + size_t len = end - data; + afi_t afi; + safi_t safi; + + if (action == CAPABILITY_ACTION_SET) { + if (len < BGP_CAP_LLGR_MIN_PACKET_LEN) { + zlog_err("%pBP: Received invalid Long-Lived Graceful-Restart capability length %zu", + peer, len); + return; + } + + SET_FLAG(peer->cap, PEER_CAP_LLGR_RCV); + + while (data + BGP_CAP_LLGR_MIN_PACKET_LEN <= end) { + afi_t afi; + safi_t safi; + iana_afi_t pkt_afi; + iana_safi_t pkt_safi; + struct graceful_restart_af graf; + + memcpy(&graf, data, sizeof(graf)); + pkt_afi = ntohs(graf.afi); + pkt_safi = safi_int2iana(graf.safi); + + /* Stale time is after AFI/SAFI/flags. + * It's encoded as 24 bits (= 3 bytes), so we need to + * put it into 32 bits. + */ + uint32_t stale_time; + uint8_t *stale_time_ptr = data + 4; + + stale_time = stale_time_ptr[0] << 16; + stale_time |= stale_time_ptr[1] << 8; + stale_time |= stale_time_ptr[2]; + + if (bgp_map_afi_safi_iana2int(pkt_afi, pkt_safi, &afi, + &safi)) { + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%s Addr-family %s/%s(afi/safi) not supported. Ignore the Long-lived Graceful Restart capability for this AFI/SAFI", + peer->host, + iana_afi2str(pkt_afi), + iana_safi2str(pkt_safi)); + } else if (!peer->afc[afi][safi] || + !CHECK_FLAG(peer->af_cap[afi][safi], + PEER_CAP_RESTART_AF_RCV)) { + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%s Addr-family %s/%s(afi/safi) not enabled. Ignore the Long-lived Graceful Restart capability", + peer->host, + iana_afi2str(pkt_afi), + iana_safi2str(pkt_safi)); + } else { + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%s Addr-family %s/%s(afi/safi) Long-lived Graceful Restart capability stale time %u sec", + peer->host, + iana_afi2str(pkt_afi), + iana_safi2str(pkt_safi), + stale_time); + + peer->llgr[afi][safi].flags = graf.flag; + peer->llgr[afi][safi].stale_time = + MIN(stale_time, + peer->bgp->llgr_stale_time); + SET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_LLGR_AF_RCV); + } + + data += BGP_CAP_LLGR_MIN_PACKET_LEN; + } + } else { + FOREACH_AFI_SAFI (afi, safi) { + UNSET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_LLGR_AF_RCV); + + peer->llgr[afi][safi].flags = 0; + peer->llgr[afi][safi].stale_time = + BGP_DEFAULT_LLGR_STALE_TIME; + } + + UNSET_FLAG(peer->cap, PEER_CAP_LLGR_RCV); + } +} + +static void bgp_dynamic_capability_graceful_restart(uint8_t *pnt, int action, + struct capability_header *hdr, + struct peer *peer) +{ +#define GRACEFUL_RESTART_CAPABILITY_PER_AFI_SAFI_SIZE 4 + uint16_t gr_restart_flag_time; + uint8_t *data = pnt + 3; + uint8_t *end = pnt + hdr->length; + size_t len = end - data; + afi_t afi; + safi_t safi; + + if (action == CAPABILITY_ACTION_SET) { + if (len < sizeof(gr_restart_flag_time)) { + zlog_err("%pBP: Received invalid Graceful-Restart capability length %d", + peer, hdr->length); + return; + } + + SET_FLAG(peer->cap, PEER_CAP_RESTART_RCV); + ptr_get_be16(data, &gr_restart_flag_time); + data += sizeof(gr_restart_flag_time); + + if (CHECK_FLAG(gr_restart_flag_time, GRACEFUL_RESTART_R_BIT)) + SET_FLAG(peer->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV); + else + UNSET_FLAG(peer->cap, + PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV); + + if (CHECK_FLAG(gr_restart_flag_time, GRACEFUL_RESTART_N_BIT)) + SET_FLAG(peer->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV); + else + UNSET_FLAG(peer->cap, + PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV); + + UNSET_FLAG(gr_restart_flag_time, 0xF000); + peer->v_gr_restart = gr_restart_flag_time; + + while (data + GRACEFUL_RESTART_CAPABILITY_PER_AFI_SAFI_SIZE <= + end) { + afi_t afi; + safi_t safi; + iana_afi_t pkt_afi; + iana_safi_t pkt_safi; + struct graceful_restart_af graf; + + memcpy(&graf, data, sizeof(graf)); + pkt_afi = ntohs(graf.afi); + pkt_safi = safi_int2iana(graf.safi); + + /* Convert AFI, SAFI to internal values, check. */ + if (bgp_map_afi_safi_iana2int(pkt_afi, pkt_safi, &afi, + &safi)) { + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%pBP: Addr-family %s/%s(afi/safi) not supported. Ignore the Graceful Restart capability for this AFI/SAFI", + peer, iana_afi2str(pkt_afi), + iana_safi2str(pkt_safi)); + } else if (!peer->afc[afi][safi]) { + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%pBP: Addr-family %s/%s(afi/safi) not enabled. Ignore the Graceful Restart capability", + peer, iana_afi2str(pkt_afi), + iana_safi2str(pkt_safi)); + } else { + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%pBP: Address family %s is%spreserved", + peer, + get_afi_safi_str(afi, safi, + false), + CHECK_FLAG(peer->af_cap[afi] + [safi], + PEER_CAP_RESTART_AF_PRESERVE_RCV) + ? " " + : " not "); + + SET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_RESTART_AF_RCV); + if (CHECK_FLAG(graf.flag, + GRACEFUL_RESTART_F_BIT)) + SET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_RESTART_AF_PRESERVE_RCV); + } + + data += GRACEFUL_RESTART_CAPABILITY_PER_AFI_SAFI_SIZE; + } + } else { + FOREACH_AFI_SAFI (afi, safi) { + UNSET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_RESTART_AF_RCV); + UNSET_FLAG(peer->af_cap[afi][safi], + PEER_CAP_RESTART_AF_PRESERVE_RCV); + } + + UNSET_FLAG(peer->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV); + UNSET_FLAG(peer->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV); + UNSET_FLAG(peer->cap, PEER_CAP_RESTART_RCV); + } +} + +static void bgp_dynamic_capability_software_version(uint8_t *pnt, int action, + struct capability_header *hdr, + struct peer *peer) +{ + uint8_t *data = pnt + 3; + uint8_t *end = data + hdr->length; + uint8_t len = *data; + char soft_version[BGP_MAX_SOFT_VERSION + 1] = {}; + + if (action == CAPABILITY_ACTION_SET) { + if (data + len > end) { + zlog_err("%pBP: Received invalid Software Version capability length %d", + peer, len); + return; + } + data++; + + if (len > BGP_MAX_SOFT_VERSION) + len = BGP_MAX_SOFT_VERSION; + + memcpy(&soft_version, data, len); + soft_version[len] = '\0'; + + XFREE(MTYPE_BGP_SOFT_VERSION, peer->soft_version); + peer->soft_version = XSTRDUP(MTYPE_BGP_SOFT_VERSION, + soft_version); + + SET_FLAG(peer->cap, PEER_CAP_SOFT_VERSION_RCV); + } else { + UNSET_FLAG(peer->cap, PEER_CAP_SOFT_VERSION_RCV); + XFREE(MTYPE_BGP_SOFT_VERSION, peer->soft_version); + } +} + /** * Parse BGP CAPABILITY message for peer. * @@ -2697,6 +3603,7 @@ static int bgp_capability_msg_parse(struct peer *peer, uint8_t *pnt, afi_t afi; iana_safi_t pkt_safi; safi_t safi; + const char *capability; end = pnt + length; @@ -2704,8 +3611,8 @@ static int bgp_capability_msg_parse(struct peer *peer, uint8_t *pnt, /* We need at least action, capability code and capability * length. */ if (pnt + 3 > end) { - zlog_info("%s Capability length error", peer->host); - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + zlog_err("%pBP: Capability length error", peer); + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_SUBCODE_UNSPECIFIC); return BGP_Stop; } @@ -2715,70 +3622,69 @@ static int bgp_capability_msg_parse(struct peer *peer, uint8_t *pnt, /* Action value check. */ if (action != CAPABILITY_ACTION_SET && action != CAPABILITY_ACTION_UNSET) { - zlog_info("%s Capability Action Value error %d", - peer->host, action); - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + zlog_err("%pBP: Capability Action Value error %d", peer, + action); + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_SUBCODE_UNSPECIFIC); return BGP_Stop; } if (bgp_debug_neighbor_events(peer)) - zlog_debug( - "%s CAPABILITY has action: %d, code: %u, length %u", - peer->host, action, hdr->code, hdr->length); - - if (hdr->length < sizeof(struct capability_mp_data)) { - zlog_info( - "%pBP Capability structure is not properly filled out, expected at least %zu bytes but header length specified is %d", - peer, sizeof(struct capability_mp_data), - hdr->length); - return BGP_Stop; - } + zlog_debug("%pBP: CAPABILITY has action: %d, code: %u, length %u", + peer, action, hdr->code, hdr->length); /* Capability length check. */ if ((pnt + hdr->length + 3) > end) { - zlog_info("%s Capability length error", peer->host); - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + zlog_err("%pBP: Capability length error", peer); + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_SUBCODE_UNSPECIFIC); return BGP_Stop; } - /* Fetch structure to the byte stream. */ - memcpy(&mpc, pnt + 3, sizeof(struct capability_mp_data)); - pnt += hdr->length + 3; + /* Ignore capability when override-capability is set. */ + if (CHECK_FLAG(peer->flags, PEER_FLAG_OVERRIDE_CAPABILITY)) + continue; + + capability = lookup_msg(capcode_str, hdr->code, "Unknown"); - /* We know MP Capability Code. */ - if (hdr->code == CAPABILITY_CODE_MP) { + switch (hdr->code) { + case CAPABILITY_CODE_SOFT_VERSION: + bgp_dynamic_capability_software_version(pnt, action, + hdr, peer); + break; + case CAPABILITY_CODE_MP: + if (hdr->length < sizeof(struct capability_mp_data)) { + zlog_err("%pBP: Capability (%s) structure is not properly filled out, expected at least %zu bytes but header length specified is %d", + peer, capability, + sizeof(struct capability_mp_data), + hdr->length); + return BGP_Stop; + } + + memcpy(&mpc, pnt + 3, sizeof(struct capability_mp_data)); pkt_afi = ntohs(mpc.afi); pkt_safi = mpc.safi; - /* Ignore capability when override-capability is set. */ - if (CHECK_FLAG(peer->flags, - PEER_FLAG_OVERRIDE_CAPABILITY)) - continue; - /* Convert AFI, SAFI to internal values. */ if (bgp_map_afi_safi_iana2int(pkt_afi, pkt_safi, &afi, &safi)) { if (bgp_debug_neighbor_events(peer)) - zlog_debug( - "%s Dynamic Capability MP_EXT afi/safi invalid (%s/%s)", - peer->host, - iana_afi2str(pkt_afi), - iana_safi2str(pkt_safi)); + zlog_debug("%pBP: Dynamic Capability %s afi/safi invalid (%s/%s)", + peer, capability, + iana_afi2str(pkt_afi), + iana_safi2str(pkt_safi)); continue; } /* Address family check. */ if (bgp_debug_neighbor_events(peer)) - zlog_debug( - "%s CAPABILITY has %s MP_EXT CAP for afi/safi: %s/%s", - peer->host, - action == CAPABILITY_ACTION_SET - ? "Advertising" - : "Removing", - iana_afi2str(pkt_afi), - iana_safi2str(pkt_safi)); + zlog_debug("%pBP: CAPABILITY has %s %s CAP for afi/safi: %s/%s", + peer, + action == CAPABILITY_ACTION_SET + ? "Advertising" + : "Removing", + capability, iana_afi2str(pkt_afi), + iana_safi2str(pkt_safi)); if (action == CAPABILITY_ACTION_SET) { peer->afc_recv[afi][safi] = 1; @@ -2796,12 +3702,69 @@ static int bgp_capability_msg_parse(struct peer *peer, uint8_t *pnt, else return BGP_Stop; } - } else { - flog_warn( - EC_BGP_UNRECOGNIZED_CAPABILITY, - "%s unrecognized capability code: %d - ignored", - peer->host, hdr->code); + break; + case CAPABILITY_CODE_RESTART: + if ((hdr->length - 2) % 4) { + zlog_err("%pBP: Received invalid Graceful-Restart capability length %d", + peer, hdr->length); + bgp_notify_send(peer->connection, + BGP_NOTIFY_CEASE, + BGP_NOTIFY_SUBCODE_UNSPECIFIC); + return BGP_Stop; + } + + bgp_dynamic_capability_graceful_restart(pnt, action, + hdr, peer); + break; + case CAPABILITY_CODE_LLGR: + bgp_dynamic_capability_llgr(pnt, action, hdr, peer); + break; + case CAPABILITY_CODE_ADDPATH: + bgp_dynamic_capability_addpath(pnt, action, hdr, peer); + break; + case CAPABILITY_CODE_ORF: + bgp_dynamic_capability_orf(pnt, action, hdr, peer); + break; + case CAPABILITY_CODE_FQDN: + bgp_dynamic_capability_fqdn(pnt, action, hdr, peer); + break; + case CAPABILITY_CODE_REFRESH: + case CAPABILITY_CODE_AS4: + case CAPABILITY_CODE_DYNAMIC: + case CAPABILITY_CODE_ENHANCED_RR: + case CAPABILITY_CODE_ENHE: + case CAPABILITY_CODE_EXT_MESSAGE: + break; + case CAPABILITY_CODE_ROLE: + if (hdr->length != CAPABILITY_CODE_ROLE_LEN) { + zlog_err("%pBP: Capability (%s) length error", + peer, capability); + bgp_notify_send(peer->connection, + BGP_NOTIFY_CEASE, + BGP_NOTIFY_SUBCODE_UNSPECIFIC); + return BGP_Stop; + } + + uint8_t role; + + if (action == CAPABILITY_ACTION_SET) { + SET_FLAG(peer->cap, PEER_CAP_ROLE_RCV); + memcpy(&role, pnt + 3, sizeof(role)); + + peer->remote_role = role; + } else { + UNSET_FLAG(peer->cap, PEER_CAP_ROLE_RCV); + peer->remote_role = ROLE_UNDEFINED; + } + break; + default: + flog_warn(EC_BGP_UNRECOGNIZED_CAPABILITY, + "%pBP: unrecognized capability code: %d - ignored", + peer, hdr->code); + break; } + + pnt += hdr->length + 3; } /* No FSM action necessary */ @@ -2817,7 +3780,8 @@ static int bgp_capability_msg_parse(struct peer *peer, uint8_t *pnt, * @param size size of the packet * @return as in summary */ -int bgp_capability_receive(struct peer *peer, bgp_size_t size) +int bgp_capability_receive(struct peer_connection *connection, + struct peer *peer, bgp_size_t size) { uint8_t *pnt; @@ -2832,20 +3796,19 @@ int bgp_capability_receive(struct peer *peer, bgp_size_t size) flog_err(EC_BGP_NO_CAP, "%s [Error] BGP dynamic capability is not enabled", peer->host); - bgp_notify_send(peer, BGP_NOTIFY_HEADER_ERR, + bgp_notify_send(connection, BGP_NOTIFY_HEADER_ERR, BGP_NOTIFY_HEADER_BAD_MESTYPE); return BGP_Stop; } /* Status must be Established. */ - if (!peer_established(peer)) { - flog_err( - EC_BGP_NO_CAP, - "%s [Error] Dynamic capability packet received under status %s", - peer->host, - lookup_msg(bgp_status_msg, peer->status, NULL)); - bgp_notify_send(peer, BGP_NOTIFY_FSM_ERR, - bgp_fsm_error_subcode(peer->status)); + if (!peer_established(connection)) { + flog_err(EC_BGP_NO_CAP, + "%s [Error] Dynamic capability packet received under status %s", + peer->host, + lookup_msg(bgp_status_msg, connection->status, NULL)); + bgp_notify_send(connection, BGP_NOTIFY_FSM_ERR, + bgp_fsm_error_subcode(connection->status)); return BGP_Stop; } @@ -2871,17 +3834,19 @@ void bgp_process_packet(struct event *thread) { /* Yes first of all get peer pointer. */ struct peer *peer; // peer + struct peer_connection *connection; uint32_t rpkt_quanta_old; // how many packets to read int fsm_update_result; // return code of bgp_event_update() int mprc; // message processing return code - peer = EVENT_ARG(thread); + connection = EVENT_ARG(thread); + peer = connection->peer; rpkt_quanta_old = atomic_load_explicit(&peer->bgp->rpkt_quanta, memory_order_relaxed); fsm_update_result = 0; /* Guard against scheduled events that occur after peer deletion. */ - if (peer->status == Deleted || peer->status == Clearing) + if (connection->status == Deleted || connection->status == Clearing) return; unsigned int processed = 0; @@ -2891,8 +3856,8 @@ void bgp_process_packet(struct event *thread) bgp_size_t size; char notify_data_length[2]; - frr_with_mutex (&peer->io_mtx) { - peer->curr = stream_fifo_pop(peer->ibuf); + frr_with_mutex (&connection->io_mtx) { + peer->curr = stream_fifo_pop(connection->ibuf); } if (peer->curr == NULL) // no packets to process, hmm... @@ -2918,7 +3883,7 @@ void bgp_process_packet(struct event *thread) frrtrace(2, frr_bgp, open_process, peer, size); atomic_fetch_add_explicit(&peer->open_in, 1, memory_order_relaxed); - mprc = bgp_open_receive(peer, size); + mprc = bgp_open_receive(connection, peer, size); if (mprc == BGP_Stop) flog_err( EC_BGP_PKT_OPEN, @@ -2930,7 +3895,7 @@ void bgp_process_packet(struct event *thread) atomic_fetch_add_explicit(&peer->update_in, 1, memory_order_relaxed); peer->readtime = monotime(NULL); - mprc = bgp_update_receive(peer, size); + mprc = bgp_update_receive(connection, peer, size); if (mprc == BGP_Stop) flog_err( EC_BGP_UPDATE_RCV, @@ -2941,7 +3906,7 @@ void bgp_process_packet(struct event *thread) frrtrace(2, frr_bgp, notification_process, peer, size); atomic_fetch_add_explicit(&peer->notify_in, 1, memory_order_relaxed); - mprc = bgp_notify_receive(peer, size); + mprc = bgp_notify_receive(connection, peer, size); if (mprc == BGP_Stop) flog_err( EC_BGP_NOTIFY_RCV, @@ -2953,7 +3918,7 @@ void bgp_process_packet(struct event *thread) peer->readtime = monotime(NULL); atomic_fetch_add_explicit(&peer->keepalive_in, 1, memory_order_relaxed); - mprc = bgp_keepalive_receive(peer, size); + mprc = bgp_keepalive_receive(connection, peer, size); if (mprc == BGP_Stop) flog_err( EC_BGP_KEEP_RCV, @@ -2965,7 +3930,7 @@ void bgp_process_packet(struct event *thread) frrtrace(2, frr_bgp, refresh_process, peer, size); atomic_fetch_add_explicit(&peer->refresh_in, 1, memory_order_relaxed); - mprc = bgp_route_refresh_receive(peer, size); + mprc = bgp_route_refresh_receive(connection, peer, size); if (mprc == BGP_Stop) flog_err( EC_BGP_RFSH_RCV, @@ -2976,7 +3941,7 @@ void bgp_process_packet(struct event *thread) frrtrace(2, frr_bgp, capability_process, peer, size); atomic_fetch_add_explicit(&peer->dynamic_cap_in, 1, memory_order_relaxed); - mprc = bgp_capability_receive(peer, size); + mprc = bgp_capability_receive(connection, peer, size); if (mprc == BGP_Stop) flog_err( EC_BGP_CAP_RCV, @@ -3003,7 +3968,7 @@ void bgp_process_packet(struct event *thread) /* Update FSM */ if (mprc != BGP_PACKET_NOOP) - fsm_update_result = bgp_event_update(peer, mprc); + fsm_update_result = bgp_event_update(connection, mprc); else continue; @@ -3018,12 +3983,12 @@ void bgp_process_packet(struct event *thread) if (fsm_update_result != FSM_PEER_TRANSFERRED && fsm_update_result != FSM_PEER_STOPPED) { - frr_with_mutex (&peer->io_mtx) { + frr_with_mutex (&connection->io_mtx) { // more work to do, come back later - if (peer->ibuf->count > 0) + if (connection->ibuf->count > 0) event_add_event(bm->master, bgp_process_packet, - peer, 0, - &peer->t_process_packet); + connection, 0, + &connection->t_process_packet); } } } @@ -3046,18 +4011,20 @@ void bgp_send_delayed_eor(struct bgp *bgp) */ void bgp_packet_process_error(struct event *thread) { + struct peer_connection *connection; struct peer *peer; int code; - peer = EVENT_ARG(thread); + connection = EVENT_ARG(thread); + peer = connection->peer; code = EVENT_VAL(thread); if (bgp_debug_neighbor_events(peer)) - zlog_debug("%s [Event] BGP error %d on fd %d", - peer->host, code, peer->fd); + zlog_debug("%s [Event] BGP error %d on fd %d", peer->host, code, + connection->fd); /* Closed connection or error on the socket */ - if (peer_established(peer)) { + if (peer_established(connection)) { if ((CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART) || CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART_HELPER)) @@ -3068,5 +4035,5 @@ void bgp_packet_process_error(struct event *thread) peer->last_reset = PEER_DOWN_CLOSE_SESSION; } - bgp_event_update(peer, code); + bgp_event_update(connection, code); } diff --git a/bgpd/bgp_packet.h b/bgpd/bgp_packet.h index 04bdb81849..b67acf2055 100644 --- a/bgpd/bgp_packet.h +++ b/bgpd/bgp_packet.h @@ -37,17 +37,18 @@ DECLARE_HOOK(bgp_packet_send, do { \ _s = bgp_update_packet_eor(_peer, _afi, _safi); \ if (_s) { \ - bgp_packet_add(_peer, _s); \ + bgp_packet_add(_peer->connection, _peer, _s); \ } \ } while (0) /* Packet send and receive function prototypes. */ extern void bgp_keepalive_send(struct peer *peer); -extern void bgp_open_send(struct peer *peer); -extern void bgp_notify_send(struct peer *peer, uint8_t code, uint8_t sub_code); -extern void bgp_notify_send_with_data(struct peer *peer, uint8_t code, - uint8_t sub_code, uint8_t *data, - size_t datalen); +extern void bgp_open_send(struct peer_connection *connection); +extern void bgp_notify_send(struct peer_connection *connection, uint8_t code, + uint8_t sub_code); +extern void bgp_notify_send_with_data(struct peer_connection *connection, + uint8_t code, uint8_t sub_code, + uint8_t *data, size_t datalen); void bgp_notify_io_invalid(struct peer *peer, uint8_t code, uint8_t sub_code, uint8_t *data, size_t datalen); extern void bgp_route_refresh_send(struct peer *peer, afi_t afi, safi_t safi, @@ -56,8 +57,8 @@ extern void bgp_route_refresh_send(struct peer *peer, afi_t afi, safi_t safi, extern void bgp_capability_send(struct peer *peer, afi_t afi, safi_t safi, int capabilty_code, int action); -extern int bgp_capability_receive(struct peer *peer, bgp_size_t length); - +extern int bgp_capability_receive(struct peer_connection *connection, + struct peer *peer, bgp_size_t length); extern int bgp_nlri_parse(struct peer *peer, struct attr *attr, struct bgp_nlri *nlri, bool mp_withdraw); diff --git a/bgpd/bgp_pbr.c b/bgpd/bgp_pbr.c index bc9ecff7d9..43682de413 100644 --- a/bgpd/bgp_pbr.c +++ b/bgpd/bgp_pbr.c @@ -1667,8 +1667,8 @@ static void bgp_pbr_flush_iprule(struct bgp *bgp, struct bgp_pbr_action *bpa, /* unlink path to bpme */ path = (struct bgp_path_info *)bpr->path; extra = bgp_path_info_extra_get(path); - if (extra->bgp_fs_iprule) - listnode_delete(extra->bgp_fs_iprule, bpr); + if (extra->flowspec && extra->flowspec->bgp_fs_iprule) + listnode_delete(extra->flowspec->bgp_fs_iprule, bpr); bpr->path = NULL; } } @@ -1696,8 +1696,8 @@ static void bgp_pbr_flush_entry(struct bgp *bgp, struct bgp_pbr_action *bpa, /* unlink path to bpme */ path = (struct bgp_path_info *)bpme->path; extra = bgp_path_info_extra_get(path); - if (extra->bgp_fs_pbr) - listnode_delete(extra->bgp_fs_pbr, bpme); + if (extra->flowspec && extra->flowspec->bgp_fs_pbr) + listnode_delete(extra->flowspec->bgp_fs_pbr, bpme); bpme->path = NULL; } } @@ -2342,8 +2342,8 @@ static void bgp_pbr_policyroute_add_to_zebra_unit(struct bgp *bgp, struct bgp_path_info_extra *extra = bgp_path_info_extra_get(path); - if (extra && - listnode_lookup_nocheck(extra->bgp_fs_iprule, + if (extra && extra->flowspec && + listnode_lookup_nocheck(extra->flowspec->bgp_fs_iprule, bpr)) { if (BGP_DEBUG(pbr, PBR_ERROR)) zlog_err("%s: entry %p/%p already installed in bgp pbr iprule", @@ -2501,8 +2501,8 @@ static void bgp_pbr_policyroute_add_to_zebra_unit(struct bgp *bgp, struct bgp_path_info_extra *extra = bgp_path_info_extra_get(path); - if (extra && - listnode_lookup_nocheck(extra->bgp_fs_pbr, bpme)) { + if (extra && extra->flowspec && + listnode_lookup_nocheck(extra->flowspec->bgp_fs_pbr, bpme)) { if (BGP_DEBUG(pbr, PBR_ERROR)) zlog_err( "%s: entry %p/%p already installed in bgp pbr", diff --git a/bgpd/bgp_pbr.h b/bgpd/bgp_pbr.h index ed143d9af7..cb16c4dc2e 100644 --- a/bgpd/bgp_pbr.h +++ b/bgpd/bgp_pbr.h @@ -134,7 +134,7 @@ struct bgp_pbr_entry_main { struct bgp_pbr_interface { RB_ENTRY(bgp_pbr_interface) id_entry; - char name[INTERFACE_NAMSIZ]; + char name[IFNAMSIZ]; }; RB_HEAD(bgp_pbr_interface_head, bgp_pbr_interface); diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 7b7a7ad207..e1387b0321 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -28,6 +28,8 @@ #include "lib/json.h" #include "lib_errors.h" #include "zclient.h" +#include "frrdistance.h" + #include "bgpd/bgpd.h" #include "bgpd/bgp_table.h" #include "bgpd/bgp_route.h" @@ -77,7 +79,7 @@ #include "bgpd/bgp_route_clippy.c" DEFINE_HOOK(bgp_snmp_update_stats, - (struct bgp_node *rn, struct bgp_path_info *pi, bool added), + (struct bgp_dest *rn, struct bgp_path_info *pi, bool added), (rn, pi, added)); DEFINE_HOOK(bgp_rpki_prefix_status, @@ -85,6 +87,11 @@ DEFINE_HOOK(bgp_rpki_prefix_status, const struct prefix *prefix), (peer, attr, prefix)); +DEFINE_HOOK(bgp_route_update, + (struct bgp *bgp, afi_t afi, safi_t safi, struct bgp_dest *bn, + struct bgp_path_info *old_route, struct bgp_path_info *new_route), + (bgp, afi, safi, bn, old_route, new_route)); + /* Extern from bgp_dump.c */ extern const char *bgp_origin_str[]; extern const char *bgp_origin_long_str[]; @@ -113,7 +120,7 @@ DEFINE_HOOK(bgp_process, (bgp, afi, safi, bn, peer, withdraw)); /** Test if path is suppressed. */ -static bool bgp_path_suppressed(struct bgp_path_info *pi) +bool bgp_path_suppressed(struct bgp_path_info *pi) { if (pi->extra == NULL || pi->extra->aggr_suppressors == NULL) return false; @@ -138,7 +145,9 @@ struct bgp_dest *bgp_afi_node_get(struct bgp_table *table, afi_t afi, bgp_dest_set_bgp_table_info( pdest, bgp_table_init(table->bgp, afi, safi)); else - bgp_dest_unlock_node(pdest); + pdest = bgp_dest_unlock_node(pdest); + + assert(pdest); table = bgp_dest_get_bgp_table_info(pdest); } @@ -188,8 +197,7 @@ static struct bgp_path_info_extra *bgp_path_info_extra_new(void) sizeof(struct bgp_path_info_extra)); new->label[0] = MPLS_INVALID_LABEL; new->num_labels = 0; - new->bgp_fs_pbr = NULL; - new->bgp_fs_iprule = NULL; + new->flowspec = NULL; return new; } @@ -206,8 +214,9 @@ void bgp_path_info_extra_free(struct bgp_path_info_extra **extra) e->damp_info->safi); e->damp_info = NULL; - if (e->parent) { - struct bgp_path_info *bpi = (struct bgp_path_info *)e->parent; + if (e->vrfleak && e->vrfleak->parent) { + struct bgp_path_info *bpi = + (struct bgp_path_info *)e->vrfleak->parent; if (bpi->net) { /* FIXME: since multiple e may have the same e->parent @@ -227,26 +236,34 @@ void bgp_path_info_extra_free(struct bgp_path_info_extra **extra) bpi->net = NULL; bgp_path_info_unlock(bpi); } - bgp_path_info_unlock(e->parent); - e->parent = NULL; + bgp_path_info_unlock(e->vrfleak->parent); + e->vrfleak->parent = NULL; } - if (e->bgp_orig) - bgp_unlock(e->bgp_orig); + if (e->vrfleak && e->vrfleak->bgp_orig) + bgp_unlock(e->vrfleak->bgp_orig); - if (e->peer_orig) - peer_unlock(e->peer_orig); + if (e->vrfleak && e->vrfleak->peer_orig) + peer_unlock(e->vrfleak->peer_orig); if (e->aggr_suppressors) list_delete(&e->aggr_suppressors); - if (e->mh_info) - bgp_evpn_path_mh_info_free(e->mh_info); + if (e->evpn && e->evpn->mh_info) + bgp_evpn_path_mh_info_free(e->evpn->mh_info); + + if ((*extra)->flowspec && (*extra)->flowspec->bgp_fs_iprule) + list_delete(&((*extra)->flowspec->bgp_fs_iprule)); + if ((*extra)->flowspec && (*extra)->flowspec->bgp_fs_pbr) + list_delete(&((*extra)->flowspec->bgp_fs_pbr)); + + if (e->evpn) + XFREE(MTYPE_BGP_ROUTE_EXTRA_EVPN, e->evpn); + if (e->flowspec) + XFREE(MTYPE_BGP_ROUTE_EXTRA_FS, e->flowspec); + if (e->vrfleak) + XFREE(MTYPE_BGP_ROUTE_EXTRA_VRFLEAK, e->vrfleak); - if ((*extra)->bgp_fs_iprule) - list_delete(&((*extra)->bgp_fs_iprule)); - if ((*extra)->bgp_fs_pbr) - list_delete(&((*extra)->bgp_fs_pbr)); XFREE(MTYPE_BGP_ROUTE_EXTRA, *extra); } @@ -257,6 +274,10 @@ struct bgp_path_info_extra *bgp_path_info_extra_get(struct bgp_path_info *pi) { if (!pi->extra) pi->extra = bgp_path_info_extra_new(); + if (!pi->extra->evpn && pi->net && pi->net->rn->p.family == AF_EVPN) + pi->extra->evpn = + XCALLOC(MTYPE_BGP_ROUTE_EXTRA_EVPN, + sizeof(struct bgp_path_info_extra_evpn)); return pi->extra; } @@ -298,6 +319,29 @@ struct bgp_path_info *bgp_path_info_unlock(struct bgp_path_info *path) return path; } +bool bgp_path_info_nexthop_changed(struct bgp_path_info *pi, struct peer *to, + afi_t afi) +{ + if (pi->peer->sort == BGP_PEER_IBGP && to->sort == BGP_PEER_IBGP && + !CHECK_FLAG(to->af_flags[afi][SAFI_MPLS_VPN], + PEER_FLAG_FORCE_NEXTHOP_SELF)) + /* IBGP RR with no nexthop self force configured */ + return false; + + if (to->sort == BGP_PEER_IBGP && + !CHECK_FLAG(to->af_flags[afi][SAFI_MPLS_VPN], + PEER_FLAG_NEXTHOP_SELF)) + /* IBGP RR with no nexthop self configured */ + return false; + + if (CHECK_FLAG(to->af_flags[afi][SAFI_MPLS_VPN], + PEER_FLAG_NEXTHOP_UNCHANGED)) + /* IBGP or EBGP with nexthop attribute unchanged */ + return false; + + return true; +} + /* This function sets flag BGP_NODE_SELECT_DEFER based on condition */ static int bgp_dest_set_defer_flag(struct bgp_dest *dest, bool delete) { @@ -403,7 +447,8 @@ void bgp_path_info_add_with_caller(const char *name, struct bgp_dest *dest, /* Do the actual removal of info from RIB, for use by bgp_process completion callback *only* */ -void bgp_path_info_reap(struct bgp_dest *dest, struct bgp_path_info *pi) +struct bgp_dest *bgp_path_info_reap(struct bgp_dest *dest, + struct bgp_path_info *pi) { if (pi->next) pi->next->prev = pi->prev; @@ -415,7 +460,8 @@ void bgp_path_info_reap(struct bgp_dest *dest, struct bgp_path_info *pi) bgp_path_info_mpath_dequeue(pi); bgp_path_info_unlock(pi); hook_call(bgp_snmp_update_stats, dest, pi, false); - bgp_dest_unlock_node(dest); + + return bgp_dest_unlock_node(dest); } void bgp_path_info_delete(struct bgp_dest *dest, struct bgp_path_info *pi) @@ -547,8 +593,9 @@ struct bgp_path_info *bgp_get_imported_bpi_ultimate(struct bgp_path_info *info) return info; for (bpi_ultimate = info; - bpi_ultimate->extra && bpi_ultimate->extra->parent; - bpi_ultimate = bpi_ultimate->extra->parent) + bpi_ultimate->extra && bpi_ultimate->extra->vrfleak && + bpi_ultimate->extra->vrfleak->parent; + bpi_ultimate = bpi_ultimate->extra->vrfleak->parent) ; return bpi_ultimate; @@ -556,16 +603,18 @@ struct bgp_path_info *bgp_get_imported_bpi_ultimate(struct bgp_path_info *info) /* Compare two bgp route entity. If 'new' is preferable over 'exist' return 1. */ -static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, - struct bgp_path_info *exist, int *paths_eq, - struct bgp_maxpaths_cfg *mpath_cfg, int debug, - char *pfx_buf, afi_t afi, safi_t safi, - enum bgp_path_selection_reason *reason) +int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, + struct bgp_path_info *exist, int *paths_eq, + struct bgp_maxpaths_cfg *mpath_cfg, bool debug, + char *pfx_buf, afi_t afi, safi_t safi, + enum bgp_path_selection_reason *reason) { const struct prefix *new_p; struct attr *newattr, *existattr; enum bgp_peer_sort new_sort; enum bgp_peer_sort exist_sort; + enum bgp_peer_sub_sort new_sub_sort; + enum bgp_peer_sub_sort exist_sub_sort; uint32_t new_pref; uint32_t exist_pref; uint32_t new_med; @@ -679,16 +728,6 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, * sticky flag. */ if (newattr->sticky != existattr->sticky) { - if (!debug) { - prefix2str(new_p, pfx_buf, - sizeof(*pfx_buf) - * PREFIX2STR_BUFFER); - bgp_path_info_path_with_addpath_rx_str( - new, new_buf, sizeof(new_buf)); - bgp_path_info_path_with_addpath_rx_str( - exist, exist_buf, sizeof(exist_buf)); - } - if (newattr->sticky && !existattr->sticky) { *reason = bgp_path_selection_evpn_sticky_mac; if (debug) @@ -1110,26 +1149,34 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, /* 7. Peer type check. */ new_sort = peer_new->sort; exist_sort = peer_exist->sort; + new_sub_sort = peer_new->sub_sort; + exist_sub_sort = peer_exist->sub_sort; - if (new_sort == BGP_PEER_EBGP - && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED)) { + if (new_sort == BGP_PEER_EBGP && + (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED || + exist_sub_sort == BGP_PEER_EBGP_OAD)) { *reason = bgp_path_selection_peer; if (debug) - zlog_debug( - "%s: %s wins over %s due to eBGP peer > iBGP peer", - pfx_buf, new_buf, exist_buf); + zlog_debug("%s: %s wins over %s due to eBGP peer > %s peer", + pfx_buf, new_buf, exist_buf, + (exist_sub_sort == BGP_PEER_EBGP_OAD) + ? "eBGP-OAD" + : "iBGP"); if (!CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX)) return 1; peer_sort_ret = 1; } - if (exist_sort == BGP_PEER_EBGP - && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED)) { + if (exist_sort == BGP_PEER_EBGP && + (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED || + new_sub_sort == BGP_PEER_EBGP_OAD)) { *reason = bgp_path_selection_peer; if (debug) - zlog_debug( - "%s: %s loses to %s due to iBGP peer < eBGP peer", - pfx_buf, new_buf, exist_buf); + zlog_debug("%s: %s loses to %s due to %s peer < eBGP peer", + pfx_buf, new_buf, exist_buf, + (exist_sub_sort == BGP_PEER_EBGP_OAD) + ? "eBGP-OAD" + : "iBGP"); if (!CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX)) return 0; peer_sort_ret = 0; @@ -1463,13 +1510,18 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, int bgp_evpn_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, - struct bgp_path_info *exist, int *paths_eq) + struct bgp_path_info *exist, int *paths_eq, + bool debug) { enum bgp_path_selection_reason reason; char pfx_buf[PREFIX2STR_BUFFER] = {}; - return bgp_path_info_cmp(bgp, new, exist, paths_eq, NULL, 0, pfx_buf, - AFI_L2VPN, SAFI_EVPN, &reason); + if (debug) + prefix2str(bgp_dest_get_prefix(new->net), pfx_buf, + sizeof(pfx_buf)); + + return bgp_path_info_cmp(bgp, new, exist, paths_eq, NULL, debug, + pfx_buf, AFI_L2VPN, SAFI_EVPN, &reason); } /* Compare two bgp route entity. Return -1 if new is preferred, 1 if exist @@ -1483,8 +1535,10 @@ int bgp_path_info_cmp_compatible(struct bgp *bgp, struct bgp_path_info *new, { int paths_eq; int ret; - ret = bgp_path_info_cmp(bgp, new, exist, &paths_eq, NULL, 0, pfx_buf, - afi, safi, reason); + bool debug = false; + + ret = bgp_path_info_cmp(bgp, new, exist, &paths_eq, NULL, debug, + pfx_buf, afi, safi, reason); if (paths_eq) ret = 0; @@ -1996,6 +2050,7 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, int samepeer_safe = 0; /* for synthetic mplsvpns routes */ bool nh_reset = false; uint64_t cum_bw; + mpls_label_t label; if (DISABLE_BGP_ANNOUNCE) return false; @@ -2081,7 +2136,7 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, /* If it's labeled safi, make sure the route has a valid label. */ if (safi == SAFI_LABELED_UNICAST) { - mpls_label_t label = bgp_adv_label(dest, pi, peer, afi, safi); + label = bgp_adv_label(dest, pi, peer, afi, safi); if (!bgp_is_valid_label(&label)) { if (bgp_debug_update(NULL, p, subgrp->update_group, 0)) zlog_debug("u%" PRIu64 ":s%" PRIu64 @@ -2090,6 +2145,29 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, p, &label); return false; } + } else if (safi == SAFI_MPLS_VPN && + CHECK_FLAG(pi->flags, BGP_PATH_MPLSVPN_NH_LABEL_BIND) && + pi->mplsvpn.bmnc.nh_label_bind_cache && peer && + pi->peer != peer && pi->sub_type != BGP_ROUTE_IMPORTED && + pi->sub_type != BGP_ROUTE_STATIC && + bgp_mplsvpn_path_uses_valid_mpls_label(pi) && + bgp_path_info_nexthop_changed(pi, peer, afi)) { + /* Redistributed mpls vpn route between distinct + * peers from 'pi->peer' to 'to', + * and an mpls label is used in this path, + * and there is a nh label bind entry, + * then get appropriate mpls local label + * and check its validity + */ + label = bgp_mplsvpn_nh_label_bind_get_label(pi); + if (!bgp_is_valid_label(&label)) { + if (bgp_debug_update(NULL, p, subgrp->update_group, 0)) + zlog_debug("u%" PRIu64 ":s%" PRIu64 + " %pFX is filtered - no valid label", + subgrp->update_group->id, subgrp->id, + p); + return false; + } } /* Do not send back route to sender. */ @@ -2101,9 +2179,7 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, * configured for default-originate */ if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE)) { - if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY) - return false; - else if (p->family == AF_INET6 && p->prefixlen == 0) + if ((p->family == AF_INET || p->family == AF_INET6) && p->prefixlen == 0) return false; } @@ -2134,10 +2210,8 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, } /* ORF prefix-list filter check */ - if (CHECK_FLAG(peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV) - && (CHECK_FLAG(peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV) - || CHECK_FLAG(peer->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_SM_OLD_RCV))) + if (CHECK_FLAG(peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV) && + CHECK_FLAG(peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)) if (peer->orf_plist[afi][safi]) { if (prefix_list_apply(peer->orf_plist[afi][safi], p) == PREFIX_DENY) { @@ -2220,6 +2294,9 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, else *attr = *piattr; + /* don't confuse inbound and outbound setting */ + RESET_FLAG(attr->rmap_change_flags); + /* If local-preference is not set. */ if ((peer->sort == BGP_PEER_IBGP || peer->sort == BGP_PEER_CONFED) && (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)))) { @@ -2237,8 +2314,8 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, /* Remove MED if its an EBGP peer - will get overwritten by route-maps */ - if (peer->sort == BGP_PEER_EBGP - && attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)) { + if (peer->sort == BGP_PEER_EBGP && peer->sub_sort != BGP_PEER_EBGP_OAD && + attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)) { if (from != bgp->peer_self && !transparent && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED)) @@ -2316,9 +2393,6 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, bgp_otc_egress(peer, attr)) return false; - bgp_peer_remove_private_as(bgp, afi, safi, peer, attr); - bgp_peer_as_override(bgp, afi, safi, peer, attr); - if (filter->advmap.update_type == UPDATE_TYPE_WITHDRAW && filter->advmap.aname && route_map_lookup_by_name(filter->advmap.aname)) { @@ -2355,10 +2429,6 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, /* Fill temp path_info */ prep_for_rmap_apply(&rmap_path, &dummy_rmap_path_extra, dest, pi, peer, attr); - - /* don't confuse inbound and outbound setting */ - RESET_FLAG(attr->rmap_change_flags); - /* * The route reflector is not allowed to modify the attributes * of the reflected IBGP routes unless explicitly allowed. @@ -2395,6 +2465,9 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, } } + bgp_peer_remove_private_as(bgp, afi, safi, peer, attr); + bgp_peer_as_override(bgp, afi, safi, peer, attr); + /* RFC 8212 to prevent route leaks. * This specification intends to improve this situation by requiring the * explicit configuration of both BGP Import and Export Policies for any @@ -2456,8 +2529,9 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, return false; if (bgp_in_graceful_shutdown(bgp)) { - if (peer->sort == BGP_PEER_IBGP - || peer->sort == BGP_PEER_CONFED) { + if (peer->sort == BGP_PEER_IBGP || + peer->sort == BGP_PEER_CONFED || + peer->sub_sort == BGP_PEER_EBGP_OAD) { attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF); attr->local_pref = BGP_GSHUT_LOCAL_PREF; } else { @@ -2587,8 +2661,12 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, /* If this is an iBGP, send Origin Validation State (OVS) * extended community (rfc8097). + * draft-uttaro-idr-bgp-oad states: + * For example, the Origin Validation State Extended Community, + * defined as non-transitive in [RFC8097], can be advertised to + * peers in the same OAD. */ - if (peer->sort == BGP_PEER_IBGP) { + if (peer->sort == BGP_PEER_IBGP || peer->sub_sort == BGP_PEER_EBGP_OAD) { enum rpki_states rpki_state = RPKI_NOT_BEING_USED; rpki_state = hook_call(bgp_rpki_prefix_status, peer, attr, p); @@ -2651,7 +2729,8 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest, struct bgp_path_info *pi1; struct bgp_path_info *pi2; struct bgp_path_info *nextpi = NULL; - int paths_eq, do_mpath, debug; + int paths_eq, do_mpath; + bool debug; struct list mp_list; char pfx_buf[PREFIX2STR_BUFFER] = {}; char path_buf[PATH_ADDPATH_STR_BUFFER]; @@ -2685,7 +2764,7 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest, if (pi1->peer != bgp->peer_self && !CHECK_FLAG(pi1->peer->sflags, PEER_STATUS_NSF_WAIT)) { - if (!peer_established(pi1->peer)) + if (!peer_established(pi1->peer->connection)) continue; } @@ -2697,13 +2776,12 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest, continue; if (BGP_PATH_HOLDDOWN(pi2)) continue; - if (pi2->peer != bgp->peer_self - && !CHECK_FLAG( - pi2->peer->sflags, - PEER_STATUS_NSF_WAIT)) - if (pi2->peer->status - != Established) - continue; + if (pi2->peer != bgp->peer_self && + !CHECK_FLAG(pi2->peer->sflags, + PEER_STATUS_NSF_WAIT) && + !peer_established( + pi2->peer->connection)) + continue; if (!aspath_cmp_left(pi1->attr->aspath, pi2->attr->aspath) @@ -2758,23 +2836,24 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest, /* reap REMOVED routes, if needs be * selected route must stay for a while longer though */ - if (CHECK_FLAG(pi->flags, BGP_PATH_REMOVED) - && (pi != old_select)) - bgp_path_info_reap(dest, pi); - if (debug) zlog_debug( "%s: %pBD(%s) pi from %s in holddown", __func__, dest, bgp->name_pretty, pi->peer->host); + if (CHECK_FLAG(pi->flags, BGP_PATH_REMOVED) && + (pi != old_select)) { + dest = bgp_path_info_reap(dest, pi); + assert(dest); + } + continue; } if (pi->peer && pi->peer != bgp->peer_self && !CHECK_FLAG(pi->peer->sflags, PEER_STATUS_NSF_WAIT)) - if (!peer_established(pi->peer)) { - + if (!peer_established(pi->peer->connection)) { if (debug) zlog_debug( "%s: %pBD(%s) non self peer %s not estab state", @@ -2848,7 +2927,7 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest, if (pi->peer && pi->peer != bgp->peer_self && !CHECK_FLAG(pi->peer->sflags, PEER_STATUS_NSF_WAIT)) - if (!peer_established(pi->peer)) + if (!peer_established(pi->peer->connection)) continue; if (!bgp_path_info_nexthop_cmp(pi, new_select)) { @@ -2924,7 +3003,7 @@ void subgroup_process_announce_selected(struct update_subgroup *subgrp, * is pending (BGP_NODE_FIB_INSTALL_PENDING), do not advertise the * route */ - advertise = bgp_check_advertise(bgp, dest); + advertise = bgp_check_advertise(bgp, dest, safi); if (selected) { if (subgroup_announce_check(dest, selected, subgrp, p, &attr, @@ -2933,7 +3012,7 @@ void subgroup_process_announce_selected(struct update_subgroup *subgrp, * in FIB, then it is advertised */ if (advertise) { - if (!bgp_check_withdrawal(bgp, dest)) { + if (!bgp_check_withdrawal(bgp, dest, safi)) { struct attr *adv_attr = bgp_attr_intern(&attr); @@ -3097,6 +3176,112 @@ static bool bgp_lu_need_null_label(struct bgp *bgp, return true; } +/* Right now, since we only deal with per-prefix labels, it is not + * necessary to do this upon changes to best path. Exceptions: + * - label index has changed -> recalculate resulting label + * - path_info sub_type changed -> switch to/from null label value + * - no valid label (due to removed static label binding) -> get new one + */ +static void bgp_lu_handle_label_allocation(struct bgp *bgp, + struct bgp_dest *dest, + struct bgp_path_info *new_select, + struct bgp_path_info *old_select, + afi_t afi) +{ + mpls_label_t mpls_label_null; + + if (bgp->allocate_mpls_labels[afi][SAFI_UNICAST]) { + if (new_select) { + if (!old_select || + bgp_label_index_differs(new_select, old_select) || + new_select->sub_type != old_select->sub_type || + !bgp_is_valid_label(&dest->local_label)) { + /* control label imposition for local + * routes, aggregate and redistributed + * routes + */ + mpls_label_null = MPLS_LABEL_IMPLICIT_NULL; + if (bgp_lu_need_null_label(bgp, new_select, afi, + &mpls_label_null)) { + if (CHECK_FLAG( + dest->flags, + BGP_NODE_REGISTERED_FOR_LABEL) || + CHECK_FLAG( + dest->flags, + BGP_NODE_LABEL_REQUESTED)) + bgp_unregister_for_label(dest); + dest->local_label = mpls_lse_encode( + mpls_label_null, 0, 0, 1); + bgp_set_valid_label(&dest->local_label); + } else + bgp_register_for_label(dest, + new_select); + } + } else if (CHECK_FLAG(dest->flags, + BGP_NODE_REGISTERED_FOR_LABEL) || + CHECK_FLAG(dest->flags, BGP_NODE_LABEL_REQUESTED)) { + bgp_unregister_for_label(dest); + } + } else if (CHECK_FLAG(dest->flags, BGP_NODE_REGISTERED_FOR_LABEL) || + CHECK_FLAG(dest->flags, BGP_NODE_LABEL_REQUESTED)) { + bgp_unregister_for_label(dest); + } +} + +static struct interface * +bgp_label_get_resolved_nh_iface(const struct bgp_path_info *pi) +{ + struct nexthop *nh; + + if (pi->nexthop == NULL || pi->nexthop->nexthop == NULL || + !CHECK_FLAG(pi->nexthop->flags, BGP_NEXTHOP_VALID)) + /* next-hop is not valid */ + return NULL; + + nh = pi->nexthop->nexthop; + if (nh->ifindex == IFINDEX_INTERNAL && + nh->type != NEXTHOP_TYPE_IPV4_IFINDEX && + nh->type != NEXTHOP_TYPE_IPV6_IFINDEX) + /* next-hop does not contain valid interface */ + return NULL; + + return if_lookup_by_index(nh->ifindex, nh->vrf_id); +} + +static void +bgp_mplsvpn_handle_label_allocation(struct bgp *bgp, struct bgp_dest *dest, + struct bgp_path_info *new_select, + struct bgp_path_info *old_select, afi_t afi) +{ + struct interface *ifp; + struct bgp_interface *bgp_ifp; + + if (bgp->allocate_mpls_labels[afi][SAFI_MPLS_VPN] && new_select) { + ifp = bgp_label_get_resolved_nh_iface(new_select); + if (ifp) + bgp_ifp = (struct bgp_interface *)(ifp->info); + else + bgp_ifp = NULL; + if (bgp_ifp && + CHECK_FLAG(bgp_ifp->flags, + BGP_INTERFACE_MPLS_L3VPN_SWITCHING) && + bgp_mplsvpn_path_uses_valid_mpls_label(new_select) && + new_select->sub_type != BGP_ROUTE_IMPORTED && + new_select->sub_type != BGP_ROUTE_STATIC) + bgp_mplsvpn_nh_label_bind_register_local_label( + bgp, dest, new_select); + else + bgp_mplsvpn_path_nh_label_bind_unlink(new_select); + } else { + if (new_select) + /* no mpls vpn allocation */ + bgp_mplsvpn_path_nh_label_bind_unlink(new_select); + else if (old_select) + /* unlink old selection if any */ + bgp_mplsvpn_path_nh_label_bind_unlink(old_select); + } +} + /* * old_select = The old best path * new_select = the new best path @@ -3123,7 +3308,6 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest, struct bgp_path_info *old_select; struct bgp_path_info_pair old_and_new; int debug = 0; - mpls_label_t mpls_label_null; if (CHECK_FLAG(bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS)) { if (dest) @@ -3174,49 +3358,18 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest, old_select = old_and_new.old; new_select = old_and_new.new; - /* Do we need to allocate or free labels? - * Right now, since we only deal with per-prefix labels, it is not - * necessary to do this upon changes to best path. Exceptions: - * - label index has changed -> recalculate resulting label - * - path_info sub_type changed -> switch to/from null label value - * - no valid label (due to removed static label binding) -> get new one - */ - if (bgp->allocate_mpls_labels[afi][safi]) { - if (new_select) { - if (!old_select - || bgp_label_index_differs(new_select, old_select) - || new_select->sub_type != old_select->sub_type - || !bgp_is_valid_label(&dest->local_label)) { - /* control label imposition for local routes, - * aggregate and redistributed routes - */ - mpls_label_null = MPLS_LABEL_IMPLICIT_NULL; - if (bgp_lu_need_null_label(bgp, new_select, afi, - &mpls_label_null)) { - if (CHECK_FLAG( - dest->flags, - BGP_NODE_REGISTERED_FOR_LABEL) - || CHECK_FLAG( - dest->flags, - BGP_NODE_LABEL_REQUESTED)) - bgp_unregister_for_label(dest); - dest->local_label = mpls_lse_encode( - mpls_label_null, 0, 0, 1); - bgp_set_valid_label(&dest->local_label); - } else - bgp_register_for_label(dest, - new_select); - } - } else if (CHECK_FLAG(dest->flags, - BGP_NODE_REGISTERED_FOR_LABEL) - || CHECK_FLAG(dest->flags, - BGP_NODE_LABEL_REQUESTED)) { - bgp_unregister_for_label(dest); - } - } else if (CHECK_FLAG(dest->flags, BGP_NODE_REGISTERED_FOR_LABEL) - || CHECK_FLAG(dest->flags, BGP_NODE_LABEL_REQUESTED)) { - bgp_unregister_for_label(dest); - } + if (safi == SAFI_UNICAST || safi == SAFI_LABELED_UNICAST) + /* label unicast path : + * Do we need to allocate or free labels? + */ + bgp_lu_handle_label_allocation(bgp, dest, new_select, + old_select, afi); + else if (safi == SAFI_MPLS_VPN) + /* mpls vpn path: + * Do we need to allocate or free labels? + */ + bgp_mplsvpn_handle_label_allocation(bgp, dest, new_select, + old_select, afi); if (debug) zlog_debug( @@ -3227,10 +3380,11 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest, /* If best route remains the same and this is not due to user-initiated * clear, see exactly what needs to be done. */ - if (old_select && old_select == new_select - && !CHECK_FLAG(dest->flags, BGP_NODE_USER_CLEAR) - && !CHECK_FLAG(old_select->flags, BGP_PATH_ATTR_CHANGED) - && !bgp_addpath_is_addpath_used(&bgp->tx_addpath, afi, safi)) { + if (old_select && old_select == new_select && + !CHECK_FLAG(dest->flags, BGP_NODE_USER_CLEAR) && + !CHECK_FLAG(dest->flags, BGP_NODE_PROCESS_CLEAR) && + !CHECK_FLAG(old_select->flags, BGP_PATH_ATTR_CHANGED) && + !bgp_addpath_is_addpath_used(&bgp->tx_addpath, afi, safi)) { if (bgp_zebra_has_route_changed(old_select)) { #ifdef ENABLE_BGP_VNC vnc_import_bgp_add_route(bgp, p, old_select); @@ -3284,20 +3438,23 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest, */ UNSET_FLAG(dest->flags, BGP_NODE_USER_CLEAR); + /* If the process wants to force deletion this flag will be set + */ + UNSET_FLAG(dest->flags, BGP_NODE_PROCESS_CLEAR); + /* bestpath has changed; bump version */ if (old_select || new_select) { bgp_bump_version(dest); - if (!bgp->t_rmap_def_originate_eval) { - bgp_lock(bgp); + if (!bgp->t_rmap_def_originate_eval) event_add_timer( bm->master, update_group_refresh_default_originate_route_map, - bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER, + bgp, bgp->rmap_def_originate_eval_timer, &bgp->t_rmap_def_originate_eval); - } } + /* TODO BMP insert rib update hook */ if (old_select) bgp_path_info_unset_flag(dest, old_select, BGP_PATH_SELECTED); if (new_select) { @@ -3310,6 +3467,15 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest, UNSET_FLAG(new_select->flags, BGP_PATH_LINK_BW_CHG); } + /* call bmp hook for loc-rib route update / withdraw after flags were + * set + */ + if (old_select || new_select) { + hook_call(bgp_route_update, bgp, afi, safi, dest, old_select, + new_select); + } + + #ifdef ENABLE_BGP_VNC if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) { if (old_select != new_select) { @@ -3370,11 +3536,12 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest, /* Clear any route change flags. */ bgp_zebra_clear_route_change_flags(dest); + UNSET_FLAG(dest->flags, BGP_NODE_PROCESS_SCHEDULED); + /* Reap old select bgp_path_info, if it has been removed */ if (old_select && CHECK_FLAG(old_select->flags, BGP_PATH_REMOVED)) bgp_path_info_reap(dest, old_select); - UNSET_FLAG(dest->flags, BGP_NODE_PROCESS_SCHEDULED); return; } @@ -3592,10 +3759,8 @@ void bgp_add_eoiu_mark(struct bgp *bgp) static void bgp_maximum_prefix_restart_timer(struct event *thread) { - struct peer *peer; - - peer = EVENT_ARG(thread); - peer->t_pmax_restart = NULL; + struct peer_connection *connection = EVENT_ARG(thread); + struct peer *peer = connection->peer; if (bgp_debug_neighbor_events(peer)) zlog_debug( @@ -3653,6 +3818,7 @@ bool bgp_maximum_prefix_overflow(struct peer *peer, afi_t afi, safi_t safi, ? bgp_filtered_routes_count(peer, afi, safi) + peer->pcount[afi][safi] : peer->pcount[afi][safi]; + struct peer_connection *connection = peer->connection; if (!CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) return false; @@ -3688,7 +3854,7 @@ bool bgp_maximum_prefix_overflow(struct peer *peer, afi_t afi, safi_t safi, ndata[6] = (peer->pmax[afi][safi]); SET_FLAG(peer->sflags, PEER_STATUS_PREFIX_OVERFLOW); - bgp_notify_send_with_data(peer, BGP_NOTIFY_CEASE, + bgp_notify_send_with_data(connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7); } @@ -3707,7 +3873,7 @@ bool bgp_maximum_prefix_overflow(struct peer *peer, afi_t afi, safi_t safi, "%pBP Maximum-prefix restart timer started for %d secs", peer, peer->v_pmax_restart); - BGP_TIMER_ON(peer->t_pmax_restart, + BGP_TIMER_ON(connection->t_pmax_restart, bgp_maximum_prefix_restart_timer, peer->v_pmax_restart); } @@ -4028,7 +4194,6 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, afi_t nh_afi; bool force_evpn_import = false; safi_t orig_safi = safi; - bool leak_success = true; int allowas_in = 0; if (frrtrace_enabled(frr_bgp, process_update)) { @@ -4172,6 +4337,16 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, goto filtered; } + if ((afi == AFI_IP || afi == AFI_IP6) && safi == SAFI_MPLS_VPN && + bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT && + !CHECK_FLAG(bgp->af_flags[afi][safi], + BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL) && + vpn_leak_to_vrf_no_retain_filter_check(bgp, attr, afi)) { + reason = + "no import. Filtered by no bgp retain route-target all"; + goto filtered; + } + /* If the route has Node Target Extended Communities, check * if it's allowed to be installed locally. */ @@ -4544,49 +4719,6 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, bgp_set_valid_label(&extra->label[0]); } - /* Update SRv6 SID */ - if (attr->srv6_l3vpn) { - extra = bgp_path_info_extra_get(pi); - if (sid_diff(&extra->sid[0].sid, - &attr->srv6_l3vpn->sid)) { - sid_copy(&extra->sid[0].sid, - &attr->srv6_l3vpn->sid); - extra->num_sids = 1; - - extra->sid[0].loc_block_len = 0; - extra->sid[0].loc_node_len = 0; - extra->sid[0].func_len = 0; - extra->sid[0].arg_len = 0; - extra->sid[0].transposition_len = 0; - extra->sid[0].transposition_offset = 0; - - if (attr->srv6_l3vpn->loc_block_len != 0) { - extra->sid[0].loc_block_len = - attr->srv6_l3vpn->loc_block_len; - extra->sid[0].loc_node_len = - attr->srv6_l3vpn->loc_node_len; - extra->sid[0].func_len = - attr->srv6_l3vpn->func_len; - extra->sid[0].arg_len = - attr->srv6_l3vpn->arg_len; - extra->sid[0].transposition_len = - attr->srv6_l3vpn - ->transposition_len; - extra->sid[0].transposition_offset = - attr->srv6_l3vpn - ->transposition_offset; - } - } - } else if (attr->srv6_vpn) { - extra = bgp_path_info_extra_get(pi); - if (sid_diff(&extra->sid[0].sid, - &attr->srv6_vpn->sid)) { - sid_copy(&extra->sid[0].sid, - &attr->srv6_vpn->sid); - extra->num_sids = 1; - } - } - #ifdef ENABLE_BGP_VNC if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) { @@ -4623,10 +4755,12 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, /* Nexthop reachability check - for unicast and * labeled-unicast.. */ - if (((afi == AFI_IP || afi == AFI_IP6) - && (safi == SAFI_UNICAST || safi == SAFI_LABELED_UNICAST)) - || (safi == SAFI_EVPN && - bgp_evpn_is_prefix_nht_supported(p))) { + if (((afi == AFI_IP || afi == AFI_IP6) && + (safi == SAFI_UNICAST || safi == SAFI_LABELED_UNICAST || + (safi == SAFI_MPLS_VPN && + pi->sub_type != BGP_ROUTE_IMPORTED))) || + (safi == SAFI_EVPN && + bgp_evpn_is_prefix_nht_supported(p))) { if (safi != SAFI_EVPN && peer->sort == BGP_PEER_EBGP && peer->ttl == BGP_DEFAULT_TTL && !CHECK_FLAG(peer->flags, @@ -4639,31 +4773,40 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, struct bgp *bgp_nexthop = bgp; - if (pi->extra && pi->extra->bgp_orig) - bgp_nexthop = pi->extra->bgp_orig; + if (pi->extra && pi->extra->vrfleak && + pi->extra->vrfleak->bgp_orig) + bgp_nexthop = pi->extra->vrfleak->bgp_orig; nh_afi = BGP_ATTR_NH_AFI(afi, pi->attr); if (bgp_find_or_add_nexthop(bgp, bgp_nexthop, nh_afi, safi, pi, NULL, connected, bgp_nht_param_prefix) || - CHECK_FLAG(peer->flags, PEER_FLAG_IS_RFAPI_HD)) + CHECK_FLAG(peer->flags, PEER_FLAG_IS_RFAPI_HD)) { + if (accept_own) + bgp_path_info_set_flag( + dest, pi, BGP_PATH_ACCEPT_OWN); + bgp_path_info_set_flag(dest, pi, BGP_PATH_VALID); - else { + } else { if (BGP_DEBUG(nht, NHT)) { - zlog_debug("%s(%pI4): NH unresolved", + zlog_debug("%s(%pI4): NH unresolved for existing %pFX pi %p flags 0x%x", __func__, - (in_addr_t *)&attr_new->nexthop); + (in_addr_t *)&attr_new->nexthop, + p, pi, pi->flags); } bgp_path_info_unset_flag(dest, pi, BGP_PATH_VALID); } } else { + /* case mpls-vpn routes with accept-own community + * (which have the BGP_ROUTE_IMPORTED subtype) + * case other afi/safi not supporting nexthop tracking + */ if (accept_own) bgp_path_info_set_flag(dest, pi, BGP_PATH_ACCEPT_OWN); - bgp_path_info_set_flag(dest, pi, BGP_PATH_VALID); } @@ -4696,10 +4839,23 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, * updating * the attributes for the route in the VNI(s). */ - if (safi == SAFI_EVPN && - (!same_attr || force_evpn_import) && - CHECK_FLAG(pi->flags, BGP_PATH_VALID)) - bgp_evpn_import_route(bgp, afi, safi, p, pi); + if (safi == SAFI_EVPN) { + if ((!same_attr || force_evpn_import) && + CHECK_FLAG(pi->flags, BGP_PATH_VALID)) + bgp_evpn_import_route(bgp, afi, safi, p, pi); + + /* If existing path is marked invalid then unimport the + * path from EVPN prefix. This will ensure EVPN route + * has only valid paths and path refcount maintained in + * EVPN nexthop is decremented appropriately. + */ + else if (!CHECK_FLAG(pi->flags, BGP_PATH_VALID)) { + if (BGP_DEBUG(nht, NHT)) + zlog_debug("%s unimport EVPN %pFX as pi %p is not VALID", + __func__, p, pi); + bgp_evpn_unimport_route(bgp, afi, safi, p, pi); + } + } /* Process change. */ bgp_aggregate_increment(bgp, p, pi, afi, safi); @@ -4715,7 +4871,7 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, } if ((SAFI_MPLS_VPN == safi) && (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) { - leak_success = vpn_leak_to_vrf_update(bgp, pi, prd); + vpn_leak_to_vrf_update(bgp, pi, prd); } #ifdef ENABLE_BGP_VNC @@ -4730,13 +4886,6 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, type, sub_type, NULL); } #endif - if ((safi == SAFI_MPLS_VPN) && - !CHECK_FLAG(bgp->af_flags[afi][safi], - BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL) && - !leak_success) { - bgp_unlink_nexthop(pi); - bgp_path_info_delete(dest, pi); - } return; } // End of implicit withdraw @@ -4769,33 +4918,12 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, bgp_set_valid_label(&extra->label[0]); } - /* Update SRv6 SID */ - if (safi == SAFI_MPLS_VPN) { - extra = bgp_path_info_extra_get(new); - if (attr->srv6_l3vpn) { - sid_copy(&extra->sid[0].sid, &attr->srv6_l3vpn->sid); - extra->num_sids = 1; - - extra->sid[0].loc_block_len = - attr->srv6_l3vpn->loc_block_len; - extra->sid[0].loc_node_len = - attr->srv6_l3vpn->loc_node_len; - extra->sid[0].func_len = attr->srv6_l3vpn->func_len; - extra->sid[0].arg_len = attr->srv6_l3vpn->arg_len; - extra->sid[0].transposition_len = - attr->srv6_l3vpn->transposition_len; - extra->sid[0].transposition_offset = - attr->srv6_l3vpn->transposition_offset; - } else if (attr->srv6_vpn) { - sid_copy(&extra->sid[0].sid, &attr->srv6_vpn->sid); - extra->num_sids = 1; - } - } - /* Nexthop reachability check. */ - if (((afi == AFI_IP || afi == AFI_IP6) - && (safi == SAFI_UNICAST || safi == SAFI_LABELED_UNICAST)) - || (safi == SAFI_EVPN && bgp_evpn_is_prefix_nht_supported(p))) { + if (((afi == AFI_IP || afi == AFI_IP6) && + (safi == SAFI_UNICAST || safi == SAFI_LABELED_UNICAST || + (safi == SAFI_MPLS_VPN && + new->sub_type != BGP_ROUTE_IMPORTED))) || + (safi == SAFI_EVPN && bgp_evpn_is_prefix_nht_supported(p))) { if (safi != SAFI_EVPN && peer->sort == BGP_PEER_EBGP && peer->ttl == BGP_DEFAULT_TTL && !CHECK_FLAG(peer->flags, @@ -4810,18 +4938,25 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, if (bgp_find_or_add_nexthop(bgp, bgp, nh_afi, safi, new, NULL, connected, bgp_nht_param_prefix) || - CHECK_FLAG(peer->flags, PEER_FLAG_IS_RFAPI_HD)) + CHECK_FLAG(peer->flags, PEER_FLAG_IS_RFAPI_HD)) { + if (accept_own) + bgp_path_info_set_flag(dest, new, + BGP_PATH_ACCEPT_OWN); + bgp_path_info_set_flag(dest, new, BGP_PATH_VALID); - else { + } else { if (BGP_DEBUG(nht, NHT)) zlog_debug("%s(%pI4): NH unresolved", __func__, &attr_new->nexthop); bgp_path_info_unset_flag(dest, new, BGP_PATH_VALID); } } else { + /* case mpls-vpn routes with accept-own community + * (which have the BGP_ROUTE_IMPORTED subtype) + * case other afi/safi not supporting nexthop tracking + */ if (accept_own) bgp_path_info_set_flag(dest, new, BGP_PATH_ACCEPT_OWN); - bgp_path_info_set_flag(dest, new, BGP_PATH_VALID); } @@ -4878,7 +5013,7 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, } if ((SAFI_MPLS_VPN == safi) && (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) { - leak_success = vpn_leak_to_vrf_update(bgp, new, prd); + vpn_leak_to_vrf_update(bgp, new, prd); } #ifdef ENABLE_BGP_VNC if (SAFI_MPLS_VPN == safi) { @@ -4892,13 +5027,6 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, sub_type, NULL); } #endif - if ((safi == SAFI_MPLS_VPN) && - !CHECK_FLAG(bgp->af_flags[afi][safi], - BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL) && - !leak_success) { - bgp_unlink_nexthop(new); - bgp_path_info_delete(dest, new); - } return; @@ -5001,7 +5129,8 @@ void bgp_withdraw(struct peer *peer, const struct prefix *p, */ if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG) && peer != bgp->peer_self) - if (!bgp_adj_in_unset(dest, peer, addpath_id)) { + if (!bgp_adj_in_unset(&dest, peer, addpath_id)) { + assert(dest); peer->stat_pfx_dup_withdraw++; if (bgp_debug_update(peer, p, NULL, 1)) { @@ -5018,6 +5147,7 @@ void bgp_withdraw(struct peer *peer, const struct prefix *p, } /* Lookup withdrawn route. */ + assert(dest); for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) if (pi->peer == peer && pi->type == type && pi->sub_type == sub_type @@ -5060,7 +5190,7 @@ void bgp_withdraw(struct peer *peer, const struct prefix *p, } void bgp_default_originate(struct peer *peer, afi_t afi, safi_t safi, - int withdraw) + bool withdraw) { struct update_subgroup *subgrp; subgrp = peer_subgroup(peer, afi, safi); @@ -5093,7 +5223,7 @@ static void bgp_announce_route_timer_expired(struct event *t) paf = EVENT_ARG(t); peer = paf->peer; - if (!peer_established(peer)) + if (!peer_established(peer->connection)) return; if (!peer->afc_nego[paf->afi][paf->safi]) @@ -5509,7 +5639,7 @@ static void bgp_clear_node_complete(struct work_queue *wq) struct peer *peer = wq->spec.data; /* Tickle FSM to start moving again */ - BGP_EVENT_ADD(peer, Clearing_Completed); + BGP_EVENT_ADD(peer->connection, Clearing_Completed); peer_unlock(peer); /* bgp_clear_route */ } @@ -5591,9 +5721,11 @@ static void bgp_clear_route_table(struct peer *peer, afi_t afi, safi_t safi, ain_next = ain->next; if (ain->peer == peer) - bgp_adj_in_remove(dest, ain); + bgp_adj_in_remove(&dest, ain); ain = ain_next; + + assert(dest); } for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = next) { @@ -5601,9 +5733,10 @@ static void bgp_clear_route_table(struct peer *peer, afi_t afi, safi_t safi, if (pi->peer != peer) continue; - if (force) - bgp_path_info_reap(dest, pi); - else { + if (force) { + dest = bgp_path_info_reap(dest, pi); + assert(dest); + } else { struct bgp_clear_node_queue *cnq; /* both unlocked in bgp_clear_node_queue_del */ @@ -5698,9 +5831,11 @@ void bgp_clear_adj_in(struct peer *peer, afi_t afi, safi_t safi) ain_next = ain->next; if (ain->peer == peer) - bgp_adj_in_remove(dest, ain); + bgp_adj_in_remove(&dest, ain); ain = ain_next; + + assert(dest); } } } @@ -5918,7 +6053,8 @@ static void bgp_cleanup_table(struct bgp *bgp, struct bgp_table *table, bgp_zebra_withdraw(p, pi, bgp, safi); } - bgp_path_info_reap(dest, pi); + dest = bgp_path_info_reap(dest, pi); + assert(dest); } } @@ -5947,7 +6083,9 @@ void bgp_cleanup_routes(struct bgp *bgp) bgp_cleanup_table(bgp, table, safi); bgp_table_finish(&table); bgp_dest_set_bgp_table_info(dest, NULL); - bgp_dest_unlock_node(dest); + dest = bgp_dest_unlock_node(dest); + + assert(dest); } } safi = SAFI_ENCAP; @@ -5958,7 +6096,9 @@ void bgp_cleanup_routes(struct bgp *bgp) bgp_cleanup_table(bgp, table, safi); bgp_table_finish(&table); bgp_dest_set_bgp_table_info(dest, NULL); - bgp_dest_unlock_node(dest); + dest = bgp_dest_unlock_node(dest); + + assert(dest); } } } @@ -5970,7 +6110,9 @@ void bgp_cleanup_routes(struct bgp *bgp) bgp_cleanup_table(bgp, table, SAFI_EVPN); bgp_table_finish(&table); bgp_dest_set_bgp_table_info(dest, NULL); - bgp_dest_unlock_node(dest); + dest = bgp_dest_unlock_node(dest); + + assert(dest); } } } @@ -6011,7 +6153,7 @@ int bgp_nlri_parse_ip(struct peer *peer, struct attr *attr, addpath_id = 0; addpath_capable = bgp_addpath_encode_rx(peer, afi, safi); - /* RFC4771 6.3 The NLRI field in the UPDATE message is checked for + /* RFC4271 6.3 The NLRI field in the UPDATE message is checked for syntactic validity. If the field is syntactically incorrect, then the Error Subcode is set to Invalid Network Field. */ for (; pnt < lim; pnt += psize) { @@ -6137,6 +6279,43 @@ int bgp_nlri_parse_ip(struct peer *peer, struct attr *attr, return BGP_NLRI_PARSE_OK; } +static void bgp_nexthop_reachability_check(afi_t afi, safi_t safi, + struct bgp_path_info *bpi, + const struct prefix *p, + struct bgp_dest *dest, + struct bgp *bgp) +{ + /* Nexthop reachability check. */ + if (safi == SAFI_UNICAST || safi == SAFI_LABELED_UNICAST) { + if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)) { + if (bgp_find_or_add_nexthop(bgp, bgp, afi, safi, bpi, + NULL, 0, p)) + bgp_path_info_set_flag(dest, bpi, + BGP_PATH_VALID); + else { + if (BGP_DEBUG(nht, NHT)) { + char buf1[INET6_ADDRSTRLEN]; + + inet_ntop(p->family, &p->u.prefix, buf1, + sizeof(buf1)); + zlog_debug("%s(%s): Route not in table, not advertising", + __func__, buf1); + } + bgp_path_info_unset_flag(dest, bpi, + BGP_PATH_VALID); + } + } else { + /* Delete the NHT structure if any, if we're toggling between + * enabling/disabling import check. We deregister the route + * from NHT to avoid overloading NHT and the process interaction + */ + bgp_unlink_nexthop(bpi); + + bgp_path_info_set_flag(dest, bpi, BGP_PATH_VALID); + } + } +} + static struct bgp_static *bgp_static_new(void) { return XCALLOC(MTYPE_BGP_STATIC, sizeof(struct bgp_static)); @@ -6148,7 +6327,7 @@ static void bgp_static_free(struct bgp_static *bgp_static) route_map_counter_decrement(bgp_static->rmap.map); if (bgp_static->prd_pretty) - XFREE(MTYPE_BGP, bgp_static->prd_pretty); + XFREE(MTYPE_BGP_NAME, bgp_static->prd_pretty); XFREE(MTYPE_ATTR, bgp_static->eth_s_id); XFREE(MTYPE_BGP_STATIC, bgp_static); } @@ -6165,11 +6344,18 @@ void bgp_static_update(struct bgp *bgp, const struct prefix *p, route_map_result_t ret; #ifdef ENABLE_BGP_VNC int vnc_implicit_withdraw = 0; + mpls_label_t label = 0; #endif + uint32_t num_labels = 0; assert(bgp_static); - dest = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi, p, NULL); + if ((safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP || safi == SAFI_EVPN) && + bgp_static->label != MPLS_INVALID_LABEL) + num_labels = 1; + + dest = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi, p, + &bgp_static->prd); bgp_attr_default_set(&attr, bgp, BGP_ORIGIN_IGP); @@ -6192,6 +6378,37 @@ void bgp_static_update(struct bgp *bgp, const struct prefix *p, attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID); } + if (safi == SAFI_EVPN || safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) { + if (afi == AFI_IP) { + attr.mp_nexthop_global_in = bgp_static->igpnexthop; + attr.mp_nexthop_len = IPV4_MAX_BYTELEN; + } + } + + if (afi == AFI_L2VPN) { + if (bgp_static->gatewayIp.family == AF_INET) { + SET_IPADDR_V4(&attr.evpn_overlay.gw_ip); + memcpy(&attr.evpn_overlay.gw_ip.ipaddr_v4, + &bgp_static->gatewayIp.u.prefix4, + IPV4_MAX_BYTELEN); + } else if (bgp_static->gatewayIp.family == AF_INET6) { + SET_IPADDR_V6(&attr.evpn_overlay.gw_ip); + memcpy(&attr.evpn_overlay.gw_ip.ipaddr_v6, + &bgp_static->gatewayIp.u.prefix6, + IPV6_MAX_BYTELEN); + } + memcpy(&attr.esi, bgp_static->eth_s_id, sizeof(esi_t)); + if (bgp_static->encap_tunneltype == BGP_ENCAP_TYPE_VXLAN) { + struct bgp_encap_type_vxlan bet; + memset(&bet, 0, sizeof(bet)); + bet.vnid = p->u.prefix_evpn.prefix_addr.eth_tag; + bgp_encap_type_vxlan_to_tlv(&bet, &attr); + } + if (bgp_static->router_mac) { + bgp_add_routermac_ecom(&attr, bgp_static->router_mac); + } + } + /* Apply route-map. */ if (bgp_static->rmap.name) { struct attr attr_tmp = attr; @@ -6212,7 +6429,7 @@ void bgp_static_update(struct bgp *bgp, const struct prefix *p, /* Unintern original. */ aspath_unintern(&attr.aspath); - bgp_static_withdraw(bgp, p, afi, safi); + bgp_static_withdraw(bgp, p, afi, safi, &bgp_static->prd); bgp_dest_unlock_node(dest); return; } @@ -6252,8 +6469,8 @@ void bgp_static_update(struct bgp *bgp, const struct prefix *p, else bgp_aggregate_decrement(bgp, p, pi, afi, safi); #ifdef ENABLE_BGP_VNC - if ((afi == AFI_IP || afi == AFI_IP6) - && (safi == SAFI_UNICAST)) { + if ((afi == AFI_IP || afi == AFI_IP6) && + safi == SAFI_UNICAST) { if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)) { /* * Implicit withdraw case. @@ -6271,60 +6488,41 @@ void bgp_static_update(struct bgp *bgp, const struct prefix *p, pi->attr = attr_new; pi->uptime = monotime(NULL); #ifdef ENABLE_BGP_VNC - if ((afi == AFI_IP || afi == AFI_IP6) - && (safi == SAFI_UNICAST)) { + if ((afi == AFI_IP || afi == AFI_IP6) && + safi == SAFI_UNICAST) { if (vnc_implicit_withdraw) { vnc_import_bgp_add_route(bgp, p, pi); vnc_import_bgp_exterior_add_route( bgp, p, pi); } + } else { + if (pi->extra) + label = decode_label( + &pi->extra->label[0]); } #endif - /* Nexthop reachability check. */ - if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK) - && (safi == SAFI_UNICAST - || safi == SAFI_LABELED_UNICAST)) { - - struct bgp *bgp_nexthop = bgp; - - if (pi->extra && pi->extra->bgp_orig) - bgp_nexthop = pi->extra->bgp_orig; + bgp_nexthop_reachability_check(afi, safi, pi, p, dest, + bgp); - if (bgp_find_or_add_nexthop(bgp, bgp_nexthop, - afi, safi, pi, NULL, - 0, p)) - bgp_path_info_set_flag(dest, pi, - BGP_PATH_VALID); - else { - if (BGP_DEBUG(nht, NHT)) { - char buf1[INET6_ADDRSTRLEN]; - inet_ntop(p->family, - &p->u.prefix, buf1, - sizeof(buf1)); - zlog_debug( - "%s(%s): Route not in table, not advertising", - __func__, buf1); - } - bgp_path_info_unset_flag( - dest, pi, BGP_PATH_VALID); - } - } else { - /* Delete the NHT structure if any, if we're - * toggling between - * enabling/disabling import check. We - * deregister the route - * from NHT to avoid overloading NHT and the - * process interaction - */ - bgp_unlink_nexthop(pi); - bgp_path_info_set_flag(dest, pi, - BGP_PATH_VALID); - } /* Process change. */ bgp_aggregate_increment(bgp, p, pi, afi, safi); bgp_process(bgp, dest, afi, safi); + if (SAFI_MPLS_VPN == safi && + bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) { + vpn_leak_to_vrf_update(bgp, pi, + &bgp_static->prd); + } +#ifdef ENABLE_BGP_VNC + if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP || + safi == SAFI_EVPN) + rfapiProcessUpdate(pi->peer, NULL, p, + &bgp_static->prd, pi->attr, + afi, safi, pi->type, + pi->sub_type, &label); +#endif + if (SAFI_UNICAST == safi && (bgp->inst_type == BGP_INSTANCE_TYPE_VRF || bgp->inst_type @@ -6342,313 +6540,114 @@ void bgp_static_update(struct bgp *bgp, const struct prefix *p, /* Make new BGP info. */ new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new, dest); - /* Nexthop reachability check. */ - if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK) - && (safi == SAFI_UNICAST || safi == SAFI_LABELED_UNICAST)) { - if (bgp_find_or_add_nexthop(bgp, bgp, afi, safi, new, NULL, 0, - p)) - bgp_path_info_set_flag(dest, new, BGP_PATH_VALID); - else { - if (BGP_DEBUG(nht, NHT)) { - char buf1[INET6_ADDRSTRLEN]; - - inet_ntop(p->family, &p->u.prefix, buf1, - sizeof(buf1)); - zlog_debug( - "%s(%s): Route not in table, not advertising", - __func__, buf1); - } - bgp_path_info_unset_flag(dest, new, BGP_PATH_VALID); - } - } else { - /* Delete the NHT structure if any, if we're toggling between - * enabling/disabling import check. We deregister the route - * from NHT to avoid overloading NHT and the process interaction - */ - bgp_unlink_nexthop(new); - - bgp_path_info_set_flag(dest, new, BGP_PATH_VALID); - } - - /* Aggregate address increment. */ - bgp_aggregate_increment(bgp, p, new, afi, safi); - - /* Register new BGP information. */ - bgp_path_info_add(dest, new); - - /* route_node_get lock */ - bgp_dest_unlock_node(dest); - - /* Process change. */ - bgp_process(bgp, dest, afi, safi); - - if (SAFI_UNICAST == safi - && (bgp->inst_type == BGP_INSTANCE_TYPE_VRF - || bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) { - vpn_leak_from_vrf_update(bgp_get_default(), bgp, new); - } - - /* Unintern original. */ - aspath_unintern(&attr.aspath); -} - -void bgp_static_withdraw(struct bgp *bgp, const struct prefix *p, afi_t afi, - safi_t safi) -{ - struct bgp_dest *dest; - struct bgp_path_info *pi; - - dest = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi, p, NULL); - - /* Check selected route and self inserted route. */ - for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) - if (pi->peer == bgp->peer_self && pi->type == ZEBRA_ROUTE_BGP - && pi->sub_type == BGP_ROUTE_STATIC) - break; - - /* Withdraw static BGP route from routing table. */ - if (pi) { - if (SAFI_UNICAST == safi - && (bgp->inst_type == BGP_INSTANCE_TYPE_VRF - || bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) { - vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp, pi); - } - bgp_aggregate_decrement(bgp, p, pi, afi, safi); - bgp_unlink_nexthop(pi); - bgp_path_info_delete(dest, pi); - bgp_process(bgp, dest, afi, safi); - } - - /* Unlock bgp_node_lookup. */ - bgp_dest_unlock_node(dest); -} - -/* - * Used for SAFI_MPLS_VPN and SAFI_ENCAP - */ -static void bgp_static_withdraw_safi(struct bgp *bgp, const struct prefix *p, - afi_t afi, safi_t safi, - struct prefix_rd *prd) -{ - struct bgp_dest *dest; - struct bgp_path_info *pi; - - dest = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi, p, prd); - - /* Check selected route and self inserted route. */ - for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) - if (pi->peer == bgp->peer_self && pi->type == ZEBRA_ROUTE_BGP - && pi->sub_type == BGP_ROUTE_STATIC) - break; - - /* Withdraw static BGP route from routing table. */ - if (pi) { -#ifdef ENABLE_BGP_VNC - rfapiProcessWithdraw( - pi->peer, NULL, p, prd, pi->attr, afi, safi, pi->type, - 1); /* Kill, since it is an administrative change */ -#endif - if (SAFI_MPLS_VPN == safi - && bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) { - vpn_leak_to_vrf_withdraw(pi); - } - bgp_aggregate_decrement(bgp, p, pi, afi, safi); - bgp_path_info_delete(dest, pi); - bgp_process(bgp, dest, afi, safi); - } - - /* Unlock bgp_node_lookup. */ - bgp_dest_unlock_node(dest); -} - -static void bgp_static_update_safi(struct bgp *bgp, const struct prefix *p, - struct bgp_static *bgp_static, afi_t afi, - safi_t safi) -{ - struct bgp_dest *dest; - struct bgp_path_info *new; - struct attr *attr_new; - struct attr attr = {0}; - struct bgp_path_info *pi; -#ifdef ENABLE_BGP_VNC - mpls_label_t label = 0; -#endif - uint32_t num_labels = 0; - - assert(bgp_static); - - if (bgp_static->label != MPLS_INVALID_LABEL) - num_labels = 1; - dest = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi, p, - &bgp_static->prd); - - bgp_attr_default_set(&attr, bgp, BGP_ORIGIN_IGP); - - attr.nexthop = bgp_static->igpnexthop; - attr.med = bgp_static->igpmetric; - attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC); - - if ((safi == SAFI_EVPN) || (safi == SAFI_MPLS_VPN) - || (safi == SAFI_ENCAP)) { - if (afi == AFI_IP) { - attr.mp_nexthop_global_in = bgp_static->igpnexthop; - attr.mp_nexthop_len = IPV4_MAX_BYTELEN; - } - } - if (afi == AFI_L2VPN) { - if (bgp_static->gatewayIp.family == AF_INET) { - SET_IPADDR_V4(&attr.evpn_overlay.gw_ip); - memcpy(&attr.evpn_overlay.gw_ip.ipaddr_v4, - &bgp_static->gatewayIp.u.prefix4, - IPV4_MAX_BYTELEN); - } else if (bgp_static->gatewayIp.family == AF_INET6) { - SET_IPADDR_V6(&attr.evpn_overlay.gw_ip); - memcpy(&attr.evpn_overlay.gw_ip.ipaddr_v6, - &bgp_static->gatewayIp.u.prefix6, - IPV6_MAX_BYTELEN); - } - memcpy(&attr.esi, bgp_static->eth_s_id, sizeof(esi_t)); - if (bgp_static->encap_tunneltype == BGP_ENCAP_TYPE_VXLAN) { - struct bgp_encap_type_vxlan bet; - memset(&bet, 0, sizeof(bet)); - bet.vnid = p->u.prefix_evpn.prefix_addr.eth_tag; - bgp_encap_type_vxlan_to_tlv(&bet, &attr); - } - if (bgp_static->router_mac) { - bgp_add_routermac_ecom(&attr, bgp_static->router_mac); - } - } - /* Apply route-map. */ - if (bgp_static->rmap.name) { - struct attr attr_tmp = attr; - struct bgp_path_info rmap_path; - route_map_result_t ret; - - rmap_path.peer = bgp->peer_self; - rmap_path.attr = &attr_tmp; - - SET_FLAG(bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK); - - ret = route_map_apply(bgp_static->rmap.map, p, &rmap_path); - - bgp->peer_self->rmap_type = 0; - - if (ret == RMAP_DENYMATCH) { - /* Free uninterned attribute. */ - bgp_attr_flush(&attr_tmp); - - /* Unintern original. */ - aspath_unintern(&attr.aspath); - bgp_static_withdraw_safi(bgp, p, afi, safi, - &bgp_static->prd); - bgp_dest_unlock_node(dest); - return; - } - - attr_new = bgp_attr_intern(&attr_tmp); - } else { - attr_new = bgp_attr_intern(&attr); - } - - for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) - if (pi->peer == bgp->peer_self && pi->type == ZEBRA_ROUTE_BGP - && pi->sub_type == BGP_ROUTE_STATIC) - break; - - if (pi) { - if (attrhash_cmp(pi->attr, attr_new) - && !CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)) { - bgp_dest_unlock_node(dest); - bgp_attr_unintern(&attr_new); - aspath_unintern(&attr.aspath); - return; - } else { - /* The attribute is changed. */ - bgp_path_info_set_flag(dest, pi, BGP_PATH_ATTR_CHANGED); - - /* Rewrite BGP route information. */ - if (CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)) - bgp_path_info_restore(dest, pi); - else - bgp_aggregate_decrement(bgp, p, pi, afi, safi); - bgp_attr_unintern(&pi->attr); - pi->attr = attr_new; - pi->uptime = monotime(NULL); -#ifdef ENABLE_BGP_VNC - if (pi->extra) - label = decode_label(&pi->extra->label[0]); -#endif - - /* Process change. */ - bgp_aggregate_increment(bgp, p, pi, afi, safi); - bgp_process(bgp, dest, afi, safi); - - if (SAFI_MPLS_VPN == safi - && bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) { - vpn_leak_to_vrf_update(bgp, pi, - &bgp_static->prd); - } -#ifdef ENABLE_BGP_VNC - rfapiProcessUpdate(pi->peer, NULL, p, &bgp_static->prd, - pi->attr, afi, safi, pi->type, - pi->sub_type, &label); -#endif - bgp_dest_unlock_node(dest); - aspath_unintern(&attr.aspath); - return; - } - } - - - /* Make new BGP info. */ - new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, - attr_new, dest); - SET_FLAG(new->flags, BGP_PATH_VALID); - bgp_path_info_extra_get(new); - if (num_labels) { - new->extra->label[0] = bgp_static->label; - new->extra->num_labels = num_labels; - } + + if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP || safi == SAFI_EVPN) { + SET_FLAG(new->flags, BGP_PATH_VALID); + bgp_path_info_extra_get(new); + if (num_labels) { + new->extra->label[0] = bgp_static->label; + new->extra->num_labels = num_labels; + } #ifdef ENABLE_BGP_VNC - label = decode_label(&bgp_static->label); + label = decode_label(&bgp_static->label); #endif + } + + bgp_nexthop_reachability_check(afi, safi, new, p, dest, bgp); /* Aggregate address increment. */ bgp_aggregate_increment(bgp, p, new, afi, safi); /* Register new BGP information. */ bgp_path_info_add(dest, new); + /* route_node_get lock */ bgp_dest_unlock_node(dest); /* Process change. */ bgp_process(bgp, dest, afi, safi); - if (SAFI_MPLS_VPN == safi - && bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) { + if (SAFI_UNICAST == safi && + (bgp->inst_type == BGP_INSTANCE_TYPE_VRF || + bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) { + vpn_leak_from_vrf_update(bgp_get_default(), bgp, new); + } + + if (SAFI_MPLS_VPN == safi && + bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) { vpn_leak_to_vrf_update(bgp, new, &bgp_static->prd); } #ifdef ENABLE_BGP_VNC - rfapiProcessUpdate(new->peer, NULL, p, &bgp_static->prd, new->attr, afi, - safi, new->type, new->sub_type, &label); + if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP || safi == SAFI_EVPN) + rfapiProcessUpdate(new->peer, NULL, p, &bgp_static->prd, + new->attr, afi, safi, new->type, + new->sub_type, &label); #endif /* Unintern original. */ aspath_unintern(&attr.aspath); } +void bgp_static_withdraw(struct bgp *bgp, const struct prefix *p, afi_t afi, + safi_t safi, struct prefix_rd *prd) +{ + struct bgp_dest *dest; + struct bgp_path_info *pi; + + dest = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi, p, prd); + + /* Check selected route and self inserted route. */ + for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) + if (pi->peer == bgp->peer_self && pi->type == ZEBRA_ROUTE_BGP + && pi->sub_type == BGP_ROUTE_STATIC) + break; + + /* Withdraw static BGP route from routing table. */ + if (pi) { +#ifdef ENABLE_BGP_VNC + if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) + rfapiProcessWithdraw(pi->peer, NULL, p, prd, pi->attr, + afi, safi, pi->type, + 1); /* Kill, since it is an administrative change */ +#endif + if (SAFI_UNICAST == safi && + (bgp->inst_type == BGP_INSTANCE_TYPE_VRF || + bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) { + vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp, pi); + } + if (SAFI_MPLS_VPN == safi + && bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) { + vpn_leak_to_vrf_withdraw(pi); + } + bgp_aggregate_decrement(bgp, p, pi, afi, safi); + bgp_unlink_nexthop(pi); + bgp_path_info_delete(dest, pi); + bgp_process(bgp, dest, afi, safi); + } + + /* Unlock bgp_node_lookup. */ + bgp_dest_unlock_node(dest); +} + /* Configure static BGP network. When user don't run zebra, static route should be installed as valid. */ -static int bgp_static_set(struct vty *vty, const char *negate, - const char *ip_str, afi_t afi, safi_t safi, - const char *rmap, int backdoor, uint32_t label_index) +int bgp_static_set(struct vty *vty, bool negate, const char *ip_str, + const char *rd_str, const char *label_str, afi_t afi, + safi_t safi, const char *rmap, int backdoor, + uint32_t label_index, int evpn_type, const char *esi, + const char *gwip, const char *ethtag, const char *routermac) { VTY_DECLVAR_CONTEXT(bgp, bgp); int ret; struct prefix p; struct bgp_static *bgp_static; + struct prefix_rd prd = {}; + struct bgp_dest *pdest; struct bgp_dest *dest; + struct bgp_table *table; uint8_t need_update = 0; + mpls_label_t label = MPLS_INVALID_LABEL; + struct prefix gw_ip; /* Convert IP prefix string to struct prefix. */ ret = str2prefix(ip_str, &p); @@ -6663,8 +6662,69 @@ static int bgp_static_set(struct vty *vty, const char *negate, apply_mask(&p); - if (negate) { + if (afi == AFI_L2VPN && + (bgp_build_evpn_prefix(evpn_type, ethtag != NULL ? atol(ethtag) : 0, + &p))) { + vty_out(vty, "%% L2VPN prefix could not be forged\n"); + return CMD_WARNING_CONFIG_FAILED; + } + + if (safi == SAFI_MPLS_VPN || safi == SAFI_EVPN) { + ret = str2prefix_rd(rd_str, &prd); + if (!ret) { + vty_out(vty, "%% Malformed rd\n"); + return CMD_WARNING_CONFIG_FAILED; + } + + if (label_str) { + unsigned long label_val; + + label_val = strtoul(label_str, NULL, 10); + encode_label(label_val, &label); + } + } + + if (safi == SAFI_EVPN) { + if (esi && str2esi(esi, NULL) == 0) { + vty_out(vty, "%% Malformed ESI\n"); + return CMD_WARNING_CONFIG_FAILED; + } + if (routermac && prefix_str2mac(routermac, NULL) == 0) { + vty_out(vty, "%% Malformed Router MAC\n"); + return CMD_WARNING_CONFIG_FAILED; + } + if (gwip) { + memset(&gw_ip, 0, sizeof(gw_ip)); + ret = str2prefix(gwip, &gw_ip); + if (!ret) { + vty_out(vty, "%% Malformed GatewayIp\n"); + return CMD_WARNING_CONFIG_FAILED; + } + if ((gw_ip.family == AF_INET && + is_evpn_prefix_ipaddr_v6((struct prefix_evpn *)&p)) || + (gw_ip.family == AF_INET6 && + is_evpn_prefix_ipaddr_v4( + (struct prefix_evpn *)&p))) { + vty_out(vty, + "%% GatewayIp family differs with IP prefix\n"); + return CMD_WARNING_CONFIG_FAILED; + } + } + } + + if (safi == SAFI_MPLS_VPN || safi == SAFI_EVPN) { + pdest = bgp_node_get(bgp->route[afi][safi], + (struct prefix *)&prd); + if (!bgp_dest_has_bgp_path_info_data(pdest)) + bgp_dest_set_bgp_table_info(pdest, + bgp_table_init(bgp, afi, + safi)); + table = bgp_dest_get_bgp_table_info(pdest); + } else { + table = bgp->route[afi][safi]; + } + if (negate) { /* Set BGP static route configuration. */ dest = bgp_node_lookup(bgp->route[afi][safi], &p); @@ -6674,36 +6734,38 @@ static int bgp_static_set(struct vty *vty, const char *negate, } bgp_static = bgp_dest_get_bgp_static_info(dest); + if (bgp_static) { + if ((label_index != BGP_INVALID_LABEL_INDEX) && + (label_index != bgp_static->label_index)) { + vty_out(vty, + "%% label-index doesn't match static route\n"); + bgp_dest_unlock_node(dest); + return CMD_WARNING_CONFIG_FAILED; + } - if ((label_index != BGP_INVALID_LABEL_INDEX) - && (label_index != bgp_static->label_index)) { - vty_out(vty, - "%% label-index doesn't match static route\n"); - bgp_dest_unlock_node(dest); - return CMD_WARNING_CONFIG_FAILED; - } + if ((rmap && bgp_static->rmap.name) && + strcmp(rmap, bgp_static->rmap.name)) { + vty_out(vty, + "%% route-map name doesn't match static route\n"); + bgp_dest_unlock_node(dest); + return CMD_WARNING_CONFIG_FAILED; + } - if ((rmap && bgp_static->rmap.name) - && strcmp(rmap, bgp_static->rmap.name)) { - vty_out(vty, - "%% route-map name doesn't match static route\n"); - bgp_dest_unlock_node(dest); - return CMD_WARNING_CONFIG_FAILED; - } + /* Update BGP RIB. */ + if (!bgp_static->backdoor) + bgp_static_withdraw(bgp, &p, afi, safi, NULL); - /* Update BGP RIB. */ - if (!bgp_static->backdoor) - bgp_static_withdraw(bgp, &p, afi, safi); + /* Clear configuration. */ + bgp_static_free(bgp_static); + } - /* Clear configuration. */ - bgp_static_free(bgp_static); bgp_dest_set_bgp_static_info(dest, NULL); - bgp_dest_unlock_node(dest); + dest = bgp_dest_unlock_node(dest); + assert(dest); bgp_dest_unlock_node(dest); } else { + dest = bgp_node_get(table, &p); - /* Set BGP static route configuration. */ - dest = bgp_node_get(bgp->route[afi][safi], &p); bgp_static = bgp_dest_get_bgp_static_info(dest); if (bgp_static) { /* Configuration change. */ @@ -6749,6 +6811,8 @@ static int bgp_static_set(struct vty *vty, const char *negate, bgp_static->igpmetric = 0; bgp_static->igpnexthop.s_addr = INADDR_ANY; bgp_static->label_index = label_index; + bgp_static->label = label; + bgp_static->prd = prd; if (rmap) { XFREE(MTYPE_ROUTE_MAP_NAME, @@ -6762,12 +6826,32 @@ static int bgp_static_set(struct vty *vty, const char *negate, route_map_counter_increment( bgp_static->rmap.map); } + + if (safi == SAFI_EVPN) { + if (esi) { + bgp_static->eth_s_id = + XCALLOC(MTYPE_ATTR, + sizeof(esi_t)); + str2esi(esi, bgp_static->eth_s_id); + } + if (routermac) { + bgp_static->router_mac = + XCALLOC(MTYPE_ATTR, + ETH_ALEN + 1); + (void)prefix_str2mac(routermac, + bgp_static->router_mac); + } + if (gwip) + prefix_copy(&bgp_static->gatewayIp, + &gw_ip); + } + bgp_dest_set_bgp_static_info(dest, bgp_static); } bgp_static->valid = 1; if (need_update) - bgp_static_withdraw(bgp, &p, afi, safi); + bgp_static_withdraw(bgp, &p, afi, safi, NULL); if (!bgp_static->backdoor) bgp_static_update(bgp, &p, bgp_static, afi, safi); @@ -6801,9 +6885,9 @@ void bgp_static_add(struct bgp *bgp) bgp_static = bgp_dest_get_bgp_static_info( rm); - bgp_static_update_safi( - bgp, bgp_dest_get_prefix(rm), - bgp_static, afi, safi); + bgp_static_update(bgp, + bgp_dest_get_prefix(rm), + bgp_static, afi, safi); } } else { bgp_static_update( @@ -6844,25 +6928,28 @@ void bgp_static_delete(struct bgp *bgp) if (!bgp_static) continue; - bgp_static_withdraw_safi( - bgp, bgp_dest_get_prefix(rm), - AFI_IP, safi, - (struct prefix_rd *) - bgp_dest_get_prefix( - dest)); + bgp_static_withdraw(bgp, + bgp_dest_get_prefix( + rm), + AFI_IP, safi, + (struct prefix_rd *) + bgp_dest_get_prefix( + dest)); bgp_static_free(bgp_static); bgp_dest_set_bgp_static_info(rm, NULL); - bgp_dest_unlock_node(rm); + rm = bgp_dest_unlock_node(rm); + assert(rm); } } else { bgp_static = bgp_dest_get_bgp_static_info(dest); bgp_static_withdraw(bgp, bgp_dest_get_prefix(dest), - afi, safi); + afi, safi, NULL); bgp_static_free(bgp_static); bgp_dest_set_bgp_static_info(dest, NULL); - bgp_dest_unlock_node(dest); + dest = bgp_dest_unlock_node(dest); + assert(dest); } } } @@ -6893,9 +6980,9 @@ void bgp_static_redo_import_check(struct bgp *bgp) bgp_static = bgp_dest_get_bgp_static_info( rm); - bgp_static_update_safi( - bgp, bgp_dest_get_prefix(rm), - bgp_static, afi, safi); + bgp_static_update(bgp, + bgp_dest_get_prefix(rm), + bgp_static, afi, safi); } } else { bgp_static = bgp_dest_get_bgp_static_info(dest); @@ -6955,205 +7042,6 @@ void bgp_purge_static_redist_routes(struct bgp *bgp) bgp_purge_af_static_redist_routes(bgp, afi, safi); } -/* - * gpz 110624 - * Currently this is used to set static routes for VPN and ENCAP. - * I think it can probably be factored with bgp_static_set. - */ -int bgp_static_set_safi(afi_t afi, safi_t safi, struct vty *vty, - const char *ip_str, const char *rd_str, - const char *label_str, const char *rmap_str, - int evpn_type, const char *esi, const char *gwip, - const char *ethtag, const char *routermac) -{ - VTY_DECLVAR_CONTEXT(bgp, bgp); - int ret; - struct prefix p; - struct prefix_rd prd; - struct bgp_dest *pdest; - struct bgp_dest *dest; - struct bgp_table *table; - struct bgp_static *bgp_static; - mpls_label_t label = MPLS_INVALID_LABEL; - struct prefix gw_ip; - - /* validate ip prefix */ - ret = str2prefix(ip_str, &p); - if (!ret) { - vty_out(vty, "%% Malformed prefix\n"); - return CMD_WARNING_CONFIG_FAILED; - } - apply_mask(&p); - if ((afi == AFI_L2VPN) - && (bgp_build_evpn_prefix(evpn_type, - ethtag != NULL ? atol(ethtag) : 0, &p))) { - vty_out(vty, "%% L2VPN prefix could not be forged\n"); - return CMD_WARNING_CONFIG_FAILED; - } - - ret = str2prefix_rd(rd_str, &prd); - if (!ret) { - vty_out(vty, "%% Malformed rd\n"); - return CMD_WARNING_CONFIG_FAILED; - } - - if (label_str) { - unsigned long label_val; - label_val = strtoul(label_str, NULL, 10); - encode_label(label_val, &label); - } - - if (safi == SAFI_EVPN) { - if (esi && str2esi(esi, NULL) == 0) { - vty_out(vty, "%% Malformed ESI\n"); - return CMD_WARNING_CONFIG_FAILED; - } - if (routermac && prefix_str2mac(routermac, NULL) == 0) { - vty_out(vty, "%% Malformed Router MAC\n"); - return CMD_WARNING_CONFIG_FAILED; - } - if (gwip) { - memset(&gw_ip, 0, sizeof(gw_ip)); - ret = str2prefix(gwip, &gw_ip); - if (!ret) { - vty_out(vty, "%% Malformed GatewayIp\n"); - return CMD_WARNING_CONFIG_FAILED; - } - if ((gw_ip.family == AF_INET - && is_evpn_prefix_ipaddr_v6( - (struct prefix_evpn *)&p)) - || (gw_ip.family == AF_INET6 - && is_evpn_prefix_ipaddr_v4( - (struct prefix_evpn *)&p))) { - vty_out(vty, - "%% GatewayIp family differs with IP prefix\n"); - return CMD_WARNING_CONFIG_FAILED; - } - } - } - pdest = bgp_node_get(bgp->route[afi][safi], (struct prefix *)&prd); - if (!bgp_dest_has_bgp_path_info_data(pdest)) - bgp_dest_set_bgp_table_info(pdest, - bgp_table_init(bgp, afi, safi)); - table = bgp_dest_get_bgp_table_info(pdest); - - dest = bgp_node_get(table, &p); - - if (bgp_dest_has_bgp_path_info_data(dest)) { - vty_out(vty, "%% Same network configuration exists\n"); - bgp_dest_unlock_node(dest); - } else { - /* New configuration. */ - bgp_static = bgp_static_new(); - bgp_static->backdoor = 0; - bgp_static->valid = 0; - bgp_static->igpmetric = 0; - bgp_static->igpnexthop.s_addr = INADDR_ANY; - bgp_static->label = label; - bgp_static->prd = prd; - - bgp_static->prd_pretty = XSTRDUP(MTYPE_BGP, rd_str); - - if (rmap_str) { - XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name); - route_map_counter_decrement(bgp_static->rmap.map); - bgp_static->rmap.name = - XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str); - bgp_static->rmap.map = - route_map_lookup_by_name(rmap_str); - route_map_counter_increment(bgp_static->rmap.map); - } - - if (safi == SAFI_EVPN) { - if (esi) { - bgp_static->eth_s_id = - XCALLOC(MTYPE_ATTR, - sizeof(esi_t)); - str2esi(esi, bgp_static->eth_s_id); - } - if (routermac) { - bgp_static->router_mac = - XCALLOC(MTYPE_ATTR, ETH_ALEN + 1); - (void)prefix_str2mac(routermac, - bgp_static->router_mac); - } - if (gwip) - prefix_copy(&bgp_static->gatewayIp, &gw_ip); - } - bgp_dest_set_bgp_static_info(dest, bgp_static); - - bgp_static->valid = 1; - bgp_static_update_safi(bgp, &p, bgp_static, afi, safi); - } - - return CMD_SUCCESS; -} - -/* Configure static BGP network. */ -int bgp_static_unset_safi(afi_t afi, safi_t safi, struct vty *vty, - const char *ip_str, const char *rd_str, - const char *label_str, int evpn_type, const char *esi, - const char *gwip, const char *ethtag) -{ - VTY_DECLVAR_CONTEXT(bgp, bgp); - int ret; - struct prefix p; - struct prefix_rd prd; - struct bgp_dest *pdest; - struct bgp_dest *dest; - struct bgp_table *table; - struct bgp_static *bgp_static; - mpls_label_t label = MPLS_INVALID_LABEL; - - /* Convert IP prefix string to struct prefix. */ - ret = str2prefix(ip_str, &p); - if (!ret) { - vty_out(vty, "%% Malformed prefix\n"); - return CMD_WARNING_CONFIG_FAILED; - } - apply_mask(&p); - if ((afi == AFI_L2VPN) - && (bgp_build_evpn_prefix(evpn_type, - ethtag != NULL ? atol(ethtag) : 0, &p))) { - vty_out(vty, "%% L2VPN prefix could not be forged\n"); - return CMD_WARNING_CONFIG_FAILED; - } - ret = str2prefix_rd(rd_str, &prd); - if (!ret) { - vty_out(vty, "%% Malformed rd\n"); - return CMD_WARNING_CONFIG_FAILED; - } - - if (label_str) { - unsigned long label_val; - label_val = strtoul(label_str, NULL, 10); - encode_label(label_val, &label); - } - - pdest = bgp_node_get(bgp->route[afi][safi], (struct prefix *)&prd); - if (!bgp_dest_has_bgp_path_info_data(pdest)) - bgp_dest_set_bgp_table_info(pdest, - bgp_table_init(bgp, afi, safi)); - else - bgp_dest_unlock_node(pdest); - table = bgp_dest_get_bgp_table_info(pdest); - - dest = bgp_node_lookup(table, &p); - - if (dest) { - bgp_static_withdraw_safi(bgp, &p, afi, safi, &prd); - - bgp_static = bgp_dest_get_bgp_static_info(dest); - bgp_static_free(bgp_static); - bgp_dest_set_bgp_static_info(dest, NULL); - bgp_dest_unlock_node(dest); - bgp_dest_unlock_node(dest); - } else - vty_out(vty, "%% Can't find the route\n"); - - return CMD_SUCCESS; -} - static int bgp_table_map_set(struct vty *vty, afi_t afi, safi_t safi, const char *rmap_name) { @@ -7259,10 +7147,13 @@ DEFPY(bgp_network, } } - return bgp_static_set( - vty, no, address_str ? addr_prefix_str : prefix_str, AFI_IP, - bgp_node_safi(vty), map_name, backdoor ? 1 : 0, - label_index ? (uint32_t)label_index : BGP_INVALID_LABEL_INDEX); + return bgp_static_set(vty, no, + address_str ? addr_prefix_str : prefix_str, NULL, + NULL, AFI_IP, bgp_node_safi(vty), map_name, + backdoor ? 1 : 0, + label_index ? (uint32_t)label_index + : BGP_INVALID_LABEL_INDEX, + 0, NULL, NULL, NULL, NULL); } DEFPY(ipv6_bgp_network, @@ -7277,9 +7168,11 @@ DEFPY(ipv6_bgp_network, "Label index to associate with the prefix\n" "Label index value\n") { - return bgp_static_set( - vty, no, prefix_str, AFI_IP6, bgp_node_safi(vty), map_name, 0, - label_index ? (uint32_t)label_index : BGP_INVALID_LABEL_INDEX); + return bgp_static_set(vty, no, prefix_str, NULL, NULL, AFI_IP6, + bgp_node_safi(vty), map_name, 0, + label_index ? (uint32_t)label_index + : BGP_INVALID_LABEL_INDEX, + 0, NULL, NULL, NULL, NULL); } static struct bgp_aggregate *bgp_aggregate_new(void) @@ -7728,7 +7621,6 @@ bool bgp_aggregate_route(struct bgp *bgp, const struct prefix *p, afi_t afi, */ aggregate->count = 0; aggregate->incomplete_origin_count = 0; - aggregate->incomplete_origin_count = 0; aggregate->egp_origin_count = 0; /* ORIGIN attribute: If at least one route among routes that are @@ -7754,7 +7646,7 @@ bool bgp_aggregate_route(struct bgp *bgp, const struct prefix *p, afi_t afi, /* If suppress fib is enabled and route not installed * in FIB, skip the route */ - if (!bgp_check_advertise(bgp, dest)) + if (!bgp_check_advertise(bgp, dest, safi)) continue; match = 0; @@ -8268,7 +8160,7 @@ void bgp_aggregate_increment(struct bgp *bgp, const struct prefix *p, /* If suppress fib is enabled and route not installed * in FIB, do not update the aggregate route */ - if (!bgp_check_advertise(bgp, pi->net)) + if (!bgp_check_advertise(bgp, pi->net, safi)) return; child = bgp_node_get(table, p); @@ -8387,7 +8279,8 @@ static int bgp_aggregate_unset(struct vty *vty, const char *prefix_str, bgp_dest_set_bgp_aggregate_info(dest, NULL); bgp_free_aggregate_info(aggregate); - bgp_dest_unlock_node(dest); + dest = bgp_dest_unlock_node(dest); + assert(dest); bgp_dest_unlock_node(dest); return CMD_SUCCESS; @@ -8665,6 +8558,10 @@ void bgp_redistribute_add(struct bgp *bgp, struct prefix *p, route_map_result_t ret; struct bgp_redist *red; + if (CHECK_FLAG(bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS) || + bgp->peer_self == NULL) + return; + /* Make default attribute. */ bgp_attr_default_set(&attr, bgp, BGP_ORIGIN_INCOMPLETE); /* @@ -8905,8 +8802,10 @@ void bgp_redistribute_withdraw(struct bgp *bgp, afi_t afi, int type, if (!CHECK_FLAG(bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS)) bgp_process(bgp, dest, afi, SAFI_UNICAST); - else - bgp_path_info_reap(dest, pi); + else { + dest = bgp_path_info_reap(dest, pi); + assert(dest); + } } } } @@ -9178,26 +9077,27 @@ void route_vty_out(struct vty *vty, const struct prefix *p, * If vrf id of nexthop is different from that of prefix, * set up printable string to append */ - if (path->extra && path->extra->bgp_orig) { + if (path->extra && path->extra->vrfleak && + path->extra->vrfleak->bgp_orig) { const char *self = ""; if (nexthop_self) self = "<"; nexthop_othervrf = true; - nexthop_vrfid = path->extra->bgp_orig->vrf_id; + nexthop_vrfid = path->extra->vrfleak->bgp_orig->vrf_id; - if (path->extra->bgp_orig->vrf_id == VRF_UNKNOWN) + if (path->extra->vrfleak->bgp_orig->vrf_id == VRF_UNKNOWN) snprintf(vrf_id_str, sizeof(vrf_id_str), "@%s%s", VRFID_NONE_STR, self); else snprintf(vrf_id_str, sizeof(vrf_id_str), "@%u%s", - path->extra->bgp_orig->vrf_id, self); + path->extra->vrfleak->bgp_orig->vrf_id, self); - if (path->extra->bgp_orig->inst_type - != BGP_INSTANCE_TYPE_DEFAULT) + if (path->extra->vrfleak->bgp_orig->inst_type != + BGP_INSTANCE_TYPE_DEFAULT) - nexthop_vrfname = path->extra->bgp_orig->name; + nexthop_vrfname = path->extra->vrfleak->bgp_orig->name; } else { const char *self = ""; @@ -9507,7 +9407,7 @@ void route_vty_out(struct vty *vty, const struct prefix *p, if (json_paths) json_object_string_addf(json_path, "peerId", "%pSU", - &path->peer->su); + &path->peer->connection->su); /* Print aspath */ if (attr->aspath) { @@ -9608,14 +9508,12 @@ void route_vty_out_tmp(struct vty *vty, struct bgp_dest *dest, const struct prefix *p, struct attr *attr, safi_t safi, bool use_json, json_object *json_ar, bool wide) { - json_object *json_status = NULL; json_object *json_net = NULL; int len; char buff[BUFSIZ]; /* Route status display. */ if (use_json) { - json_status = json_object_new_object(); json_net = json_object_new_object(); } else { vty_out(vty, " *"); @@ -9682,11 +9580,6 @@ void route_vty_out_tmp(struct vty *vty, struct bgp_dest *dest, attr->aspath->str); /* Print origin */ -#if CONFDATE > 20231208 -CPP_NOTICE("Drop `bgpOriginCodes` from JSON outputs") -#endif - json_object_string_add(json_net, "bgpOriginCode", - bgp_origin_str[attr->origin]); json_object_string_add( json_net, "origin", bgp_origin_long_str[attr->origin]); @@ -9742,20 +9635,11 @@ CPP_NOTICE("Drop `bgpOriginCodes` from JSON outputs") if (use_json) { struct bgp_path_info *bpi = bgp_dest_get_bgp_path_info(dest); -#if CONFDATE > 20231208 -CPP_NOTICE("Drop `bgpStatusCodes` from JSON outputs") -#endif - json_object_boolean_true_add(json_status, "*"); - json_object_boolean_true_add(json_status, ">"); json_object_boolean_true_add(json_net, "valid"); json_object_boolean_true_add(json_net, "best"); - if (bpi && CHECK_FLAG(bpi->flags, BGP_PATH_MULTIPATH)) { - json_object_boolean_true_add(json_status, "="); + if (bpi && CHECK_FLAG(bpi->flags, BGP_PATH_MULTIPATH)) json_object_boolean_true_add(json_net, "multipath"); - } - json_object_object_add(json_net, "appliedStatusSymbols", - json_status); json_object_object_addf(json_ar, json_net, "%pFX", p); } else vty_out(vty, "\n"); @@ -9838,9 +9722,8 @@ void route_vty_out_tag(struct vty *vty, const struct prefix *p, } } - label = decode_label(&path->extra->label[0]); - - if (bgp_is_valid_label(&label)) { + if (bgp_is_valid_label(&path->extra->label[0])) { + label = decode_label(&path->extra->label[0]); if (json) { json_object_int_add(json_out, "notag", label); json_object_array_add(json, json_out); @@ -9968,7 +9851,7 @@ static void damp_route_vty_out(struct vty *vty, const struct prefix *p, { struct attr *attr = path->attr; int len; - char timebuf[BGP_UPTIME_LEN]; + char timebuf[BGP_UPTIME_LEN] = {}; json_object *json_path = NULL; if (use_json) @@ -10027,7 +9910,7 @@ static void flap_route_vty_out(struct vty *vty, const struct prefix *p, { struct attr *attr = path->attr; struct bgp_damp_info *bdi; - char timebuf[BGP_UPTIME_LEN]; + char timebuf[BGP_UPTIME_LEN] = {}; int len; json_object *json_path = NULL; @@ -10128,7 +10011,7 @@ static void route_vty_out_advertised_to(struct vty *vty, struct peer *peer, json_peer); else json_object_object_addf(json_adv_to, json_peer, "%pSU", - &peer->su); + &peer->connection->su); } else { if (*first) { vty_out(vty, "%s", header); @@ -10142,12 +10025,12 @@ static void route_vty_out_advertised_to(struct vty *vty, struct peer *peer, peer->conf_if); else vty_out(vty, " %s(%pSU)", peer->hostname, - &peer->su); + &peer->connection->su); } else { if (peer->conf_if) vty_out(vty, " %s", peer->conf_if); else - vty_out(vty, " %pSU", &peer->su); + vty_out(vty, " %pSU", &peer->connection->su); } } } @@ -10233,6 +10116,7 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn, char tag_buf[30]; struct attr *attr = path->attr; time_t tbuf; + char timebuf[32]; json_object *json_bestpath = NULL; json_object *json_cluster_list = NULL; json_object *json_cluster_list_list = NULL; @@ -10312,11 +10196,13 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn, vty_out(vty, "\n"); - if (path->extra && path->extra->parent && !json_paths) { + if (path->extra && path->extra->vrfleak && + path->extra->vrfleak->parent && !json_paths) { struct bgp_path_info *parent_ri; struct bgp_dest *dest, *pdest; - parent_ri = (struct bgp_path_info *)path->extra->parent; + parent_ri = + (struct bgp_path_info *)path->extra->vrfleak->parent; dest = parent_ri->net; if (dest && dest->pdest) { pdest = dest->pdest; @@ -10571,7 +10457,7 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn, if (json_paths) { json_object_string_addf(json_peer, "peerId", "%pSU", - &path->peer->su); + &path->peer->connection->su); json_object_string_addf(json_peer, "routerId", "%pI4", &path->peer->remote_id); @@ -10606,7 +10492,7 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn, path->peer->host); else vty_out(vty, " from %pSU", - &path->peer->su); + &path->peer->connection->su); } if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) @@ -10619,17 +10505,18 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn, /* * Note when vrfid of nexthop is different from that of prefix */ - if (path->extra && path->extra->bgp_orig) { - vrf_id_t nexthop_vrfid = path->extra->bgp_orig->vrf_id; + if (path->extra && path->extra->vrfleak && + path->extra->vrfleak->bgp_orig) { + vrf_id_t nexthop_vrfid = path->extra->vrfleak->bgp_orig->vrf_id; if (json_paths) { const char *vn; - if (path->extra->bgp_orig->inst_type - == BGP_INSTANCE_TYPE_DEFAULT) + if (path->extra->vrfleak->bgp_orig->inst_type == + BGP_INSTANCE_TYPE_DEFAULT) vn = VRF_DEFAULT_NAME; else - vn = path->extra->bgp_orig->name; + vn = path->extra->vrfleak->bgp_orig->name; json_object_string_add(json_path, "nhVrfName", vn); @@ -10801,9 +10688,17 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn, } else { if (json_paths) json_object_string_add( - json_peer, "type", "external"); + json_peer, "type", + (path->peer->sub_sort == + BGP_PEER_EBGP_OAD) + ? "external (oad)" + : "external"); else - vty_out(vty, ", external"); + vty_out(vty, ", %s", + (path->peer->sub_sort == + BGP_PEER_EBGP_OAD) + ? "external (oad)" + : "external"); } } } else if (path->sub_type == BGP_ROUTE_AGGREGATE) { @@ -11024,13 +10919,16 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn, } /* Remote SID */ - if (path->extra && path->extra->num_sids > 0 && safi != SAFI_EVPN) { + if ((path->attr->srv6_l3vpn || path->attr->srv6_vpn) && + safi != SAFI_EVPN) { + struct in6_addr *sid_tmp = + path->attr->srv6_l3vpn ? (&path->attr->srv6_l3vpn->sid) + : (&path->attr->srv6_vpn->sid); if (json_paths) json_object_string_addf(json_path, "remoteSid", "%pI6", - &path->extra->sid[0].sid); + sid_tmp); else - vty_out(vty, " Remote SID: %pI6\n", - &path->extra->sid[0].sid); + vty_out(vty, " Remote SID: %pI6\n", sid_tmp); } /* Label Index */ @@ -11120,11 +11018,11 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn, json_last_update = json_object_new_object(); json_object_int_add(json_last_update, "epoch", tbuf); json_object_string_add(json_last_update, "string", - ctime(&tbuf)); + ctime_r(&tbuf, timebuf)); json_object_object_add(json_path, "lastUpdate", json_last_update); } else - vty_out(vty, " Last update: %s", ctime(&tbuf)); + vty_out(vty, " Last update: %s", ctime_r(&tbuf, timebuf)); /* Line 10 display PMSI tunnel attribute, if present */ if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL)) { @@ -11143,10 +11041,10 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn, str, label2vni(&attr->label)); } - if (path->peer->t_gr_restart && + if (path->peer->connection->t_gr_restart && CHECK_FLAG(path->flags, BGP_PATH_STALE)) { - unsigned long gr_remaining = - event_timer_remain_second(path->peer->t_gr_restart); + unsigned long gr_remaining = event_timer_remain_second( + path->peer->connection->t_gr_restart); if (json_paths) { json_object_int_add(json_path, @@ -11222,7 +11120,7 @@ static int bgp_show_community(struct vty *vty, struct bgp *bgp, const char *comstr, int exact, afi_t afi, safi_t safi, uint16_t show_flags); -static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, +static int bgp_show_table(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, struct bgp_table *table, enum bgp_show_type type, void *output_arg, const char *rd, int is_last, unsigned long *output_cum, unsigned long *total_cum, @@ -11583,12 +11481,12 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, if (type == bgp_show_type_dampend_paths || type == bgp_show_type_damp_neighbor) damp_route_vty_out(vty, dest_p, pi, display, - AFI_IP, safi, use_json, + afi, safi, use_json, json_paths); else if (type == bgp_show_type_flap_statistics || type == bgp_show_type_flap_neighbor) flap_route_vty_out(vty, dest_p, pi, display, - AFI_IP, safi, use_json, + afi, safi, use_json, json_paths); else { if (detail_routes || detail_json) { @@ -11744,7 +11642,7 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, return CMD_SUCCESS; } -int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi, +int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, struct bgp_table *table, struct prefix_rd *prd_match, enum bgp_show_type type, void *output_arg, uint16_t show_flags) @@ -11773,7 +11671,7 @@ int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi, memcpy(&prd, dest_p, sizeof(struct prefix_rd)); prefix_rd2str(&prd, rd, sizeof(rd), bgp->asnotation); - bgp_show_table(vty, bgp, safi, itable, type, output_arg, + bgp_show_table(vty, bgp, afi, safi, itable, type, output_arg, rd, next == NULL, &output_cum, &total_cum, &json_header_depth, show_flags, RPKI_NOT_BEING_USED); @@ -11790,7 +11688,7 @@ int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi, "\nDisplayed %ld routes and %ld total paths\n", output_cum, total_cum); } else { - if (use_json && output_cum == 0) + if (use_json && output_cum == 0 && json_header_depth == 0) vty_out(vty, "{}\n"); } return CMD_SUCCESS; @@ -11823,7 +11721,7 @@ static int bgp_show(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, table = bgp->rib[afi][safi]; /* use MPLS and ENCAP specific shows until they are merged */ if (safi == SAFI_MPLS_VPN) { - return bgp_show_table_rd(vty, bgp, safi, table, NULL, type, + return bgp_show_table_rd(vty, bgp, afi, safi, table, NULL, type, output_arg, show_flags); } @@ -11836,7 +11734,7 @@ static int bgp_show(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, if (safi == SAFI_EVPN) return bgp_evpn_show_all_routes(vty, bgp, type, use_json, 0); - return bgp_show_table(vty, bgp, safi, table, type, output_arg, NULL, 1, + return bgp_show_table(vty, bgp, afi, safi, table, type, output_arg, NULL, 1, NULL, NULL, &json_header_depth, show_flags, rpki_target_state); } @@ -12160,7 +12058,7 @@ static void bgp_show_path_info(const struct prefix_rd *pfx_rd, || CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)))) route_vty_out_detail(vty, bgp, bgp_node, bgp_dest_get_prefix(bgp_node), pi, - AFI_IP, safi, rpki_curr_state, + afi, safi, rpki_curr_state, json_paths); } @@ -12292,7 +12190,9 @@ static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp, rm_p); if (type5_pfxlen == match.prefixlen) { is_exact_pfxlen_match = true; - bgp_dest_unlock_node(rm); + rm = bgp_dest_unlock_node(rm); + + assert(rm); break; } } @@ -12954,6 +12854,8 @@ DEFPY(show_ip_bgp, show_ip_bgp_cmd, rpki_target_state = RPKI_VALID; else if (argv_find(argv, argc, "invalid", &idx)) rpki_target_state = RPKI_INVALID; + else if (argv_find(argv, argc, "notfound", &idx)) + rpki_target_state = RPKI_NOTFOUND; } /* Display prefixes with matching version numbers */ @@ -13513,7 +13415,7 @@ static int bgp_table_stats_single(struct vty *vty, struct bgp *bgp, afi_t afi, memset(&ts, 0, sizeof(ts)); ts.table = bgp->rib[afi][safi]; - event_execute(bm->master, bgp_table_stats_walker, &ts, 0); + event_execute(bm->master, bgp_table_stats_walker, &ts, 0, NULL); for (i = 0; i < BGP_STATS_MAX; i++) { if ((!json && !table_stats_strs[i][TABLE_STATS_IDX_VTY]) @@ -13699,11 +13601,11 @@ static int bgp_table_stats_single(struct vty *vty, struct bgp *bgp, afi_t afi, json_bitlen = json_object_new_array(); for (i = 0; i <= bitlen; i++) { - struct json_object *ind_bit = json_object_new_object(); - if (!ts.prefix_len_count[i]) continue; + struct json_object *ind_bit = json_object_new_object(); + snprintf(temp_buf, sizeof(temp_buf), "%u", i); json_object_int_add(ind_bit, temp_buf, ts.prefix_len_count[i]); @@ -13870,7 +13772,7 @@ static int bgp_peer_counts(struct vty *vty, struct peer *peer, afi_t afi, * stats for the thread-walk (i.e. ensure this can't be blamed on * on just vty_read()). */ - event_execute(bm->master, bgp_peer_count_walker, &pcounts, 0); + event_execute(bm->master, bgp_peer_count_walker, &pcounts, 0, NULL); if (use_json) { json_object_string_add(json, "prefixCountsFor", peer->host); @@ -14058,9 +13960,7 @@ DEFUN (show_bgp_l2vpn_evpn_route_prefix, static void show_adj_route_header(struct vty *vty, struct peer *peer, struct bgp_table *table, int *header1, - int *header2, json_object *json, - json_object *json_scode, - json_object *json_ocode, bool wide, + int *header2, json_object *json, bool wide, bool detail) { uint64_t version = table ? table->version : 0; @@ -14076,10 +13976,6 @@ static void show_adj_route_header(struct vty *vty, struct peer *peer, peer->change_local_as ? peer->change_local_as : peer->local_as); - json_object_object_add(json, "bgpStatusCodes", - json_scode); - json_object_object_add(json, "bgpOriginCodes", - json_ocode); } else { vty_out(vty, "BGP table version is %" PRIu64 @@ -14116,7 +14012,6 @@ static void show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table, afi_t afi, safi_t safi, enum bgp_show_adj_route_type type, const char *rmap_name, json_object *json, json_object *json_ar, - json_object *json_scode, json_object *json_ocode, uint16_t show_flags, int *header1, int *header2, char *rd_str, const struct prefix *match, unsigned long *output_count, unsigned long *filtered_count) @@ -14211,8 +14106,7 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table, if (ret != RMAP_DENY) { show_adj_route_header(vty, peer, table, header1, - header2, json, json_scode, - json_ocode, wide, detail); + header2, json, wide, detail); if (use_json) json_net = json_object_new_object(); @@ -14249,10 +14143,6 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table, peer->change_local_as ? peer->change_local_as : peer->local_as); - json_object_object_add(json, "bgpStatusCodes", - json_scode); - json_object_object_add(json, "bgpOriginCodes", - json_ocode); json_object_string_add( json, "bgpOriginatingDefaultNetwork", (afi == AFI_IP) ? "0.0.0.0/0" : "::/0"); @@ -14292,8 +14182,8 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table, if (ain->peer != peer) continue; show_adj_route_header(vty, peer, table, header1, - header2, json, json_scode, - json_ocode, wide, detail); + header2, json, wide, + detail); if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP) @@ -14377,10 +14267,10 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table, if (paf->peer != peer || !adj->attr) continue; - show_adj_route_header( - vty, peer, table, header1, - header2, json, json_scode, - json_ocode, wide, detail); + show_adj_route_header(vty, peer, table, + header1, header2, + json, wide, + detail); const struct prefix *rn_p = bgp_dest_get_prefix(dest); @@ -14444,8 +14334,7 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table, struct bgp_path_info *pi; show_adj_route_header(vty, peer, table, header1, - header2, json, json_scode, - json_ocode, wide, detail); + header2, json, wide, detail); const struct prefix *rn_p = bgp_dest_get_prefix(dest); @@ -14488,8 +14377,6 @@ static int peer_adj_routes(struct vty *vty, struct peer *peer, afi_t afi, struct bgp *bgp; struct bgp_table *table; json_object *json = NULL; - json_object *json_scode = NULL; - json_object *json_ocode = NULL; json_object *json_ar = NULL; bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON); @@ -14518,28 +14405,6 @@ static int peer_adj_routes(struct vty *vty, struct peer *peer, afi_t afi, if (use_json) { json = json_object_new_object(); json_ar = json_object_new_object(); - json_scode = json_object_new_object(); - json_ocode = json_object_new_object(); -#if CONFDATE > 20231208 -CPP_NOTICE("Drop `bgpStatusCodes` from JSON outputs") -#endif - json_object_string_add(json_scode, "suppressed", "s"); - json_object_string_add(json_scode, "damped", "d"); - json_object_string_add(json_scode, "history", "h"); - json_object_string_add(json_scode, "valid", "*"); - json_object_string_add(json_scode, "best", ">"); - json_object_string_add(json_scode, "multipath", "="); - json_object_string_add(json_scode, "internal", "i"); - json_object_string_add(json_scode, "ribFailure", "r"); - json_object_string_add(json_scode, "stale", "S"); - json_object_string_add(json_scode, "removed", "R"); - -#if CONFDATE > 20231208 -CPP_NOTICE("Drop `bgpOriginCodes` from JSON outputs") -#endif - json_object_string_add(json_ocode, "igp", "i"); - json_object_string_add(json_ocode, "egp", "e"); - json_object_string_add(json_ocode, "incomplete", "?"); } if (!peer || !peer->afc[afi][safi]) { @@ -14550,8 +14415,6 @@ CPP_NOTICE("Drop `bgpOriginCodes` from JSON outputs") vty_out(vty, "%s\n", json_object_to_json_string(json)); json_object_free(json); json_object_free(json_ar); - json_object_free(json_scode); - json_object_free(json_ocode); } else vty_out(vty, "%% No such neighbor or address family\n"); @@ -14569,8 +14432,6 @@ CPP_NOTICE("Drop `bgpOriginCodes` from JSON outputs") vty_out(vty, "%s\n", json_object_to_json_string(json)); json_object_free(json); json_object_free(json_ar); - json_object_free(json_scode); - json_object_free(json_ocode); } else vty_out(vty, "%% Inbound soft reconfiguration not enabled\n"); @@ -14610,11 +14471,11 @@ CPP_NOTICE("Drop `bgpOriginCodes` from JSON outputs") prefix_rd2str(prd, rd_str, sizeof(rd_str), bgp->asnotation); - show_adj_route( - vty, peer, table, afi, safi, type, rmap_name, - json, json_routes, json_scode, json_ocode, - show_flags, &header1, &header2, rd_str, match, - &output_count_per_rd, &filtered_count_per_rd); + show_adj_route(vty, peer, table, afi, safi, type, + rmap_name, json, json_routes, show_flags, + &header1, &header2, rd_str, match, + &output_count_per_rd, + &filtered_count_per_rd); /* Don't include an empty RD in the output! */ if (json_routes && (output_count_per_rd > 0)) @@ -14626,9 +14487,8 @@ CPP_NOTICE("Drop `bgpOriginCodes` from JSON outputs") } } else show_adj_route(vty, peer, table, afi, safi, type, rmap_name, - json, json_ar, json_scode, json_ocode, - show_flags, &header1, &header2, rd_str, match, - &output_count, &filtered_count); + json, json_ar, show_flags, &header1, &header2, + rd_str, match, &output_count, &filtered_count); if (use_json) { if (type == bgp_show_adj_route_advertised) @@ -14640,18 +14500,12 @@ CPP_NOTICE("Drop `bgpOriginCodes` from JSON outputs") json_object_int_add(json, "filteredPrefixCounter", filtered_count); - /* - * These fields only give up ownership to `json` when `header1` - * is used (set to zero). See code in `show_adj_route` and - * `show_adj_route_header`. - */ - if (header1 == 1) { - json_object_free(json_scode); - json_object_free(json_ocode); - } - - vty_json(vty, json); - } else if (output_count > 0) { + /* + * This is an extremely expensive operation at scale + * and non-pretty reduces memory footprint significantly. + */ + vty_json_no_pretty(vty, json); + } else if (output_count > 0) { if (!match && filtered_count > 0) vty_out(vty, "\nTotal number of prefixes %ld (%ld filtered)\n", @@ -14948,8 +14802,8 @@ static int bgp_show_neighbor_route(struct vty *vty, struct peer *peer, if (safi == SAFI_LABELED_UNICAST) safi = SAFI_UNICAST; - return bgp_show(vty, peer->bgp, afi, safi, type, &peer->su, show_flags, - RPKI_NOT_BEING_USED); + return bgp_show(vty, peer->bgp, afi, safi, type, &peer->connection->su, + show_flags, RPKI_NOT_BEING_USED); } /* @@ -15189,7 +15043,8 @@ static int bgp_distance_unset(struct vty *vty, const char *distance_str, bgp_distance_free(bdistance); bgp_dest_set_bgp_path_info(dest, NULL); - bgp_dest_unlock_node(dest); + dest = bgp_dest_unlock_node(dest); + assert(dest); bgp_dest_unlock_node(dest); return CMD_SUCCESS; @@ -15224,8 +15079,8 @@ uint8_t bgp_distance_apply(const struct prefix *p, struct bgp_path_info *pinfo, /* Check source address. * Note: for aggregate route, peer can have unspec af type. */ - if (pinfo->sub_type != BGP_ROUTE_AGGREGATE - && !sockunion2hostprefix(&peer->su, &q)) + if (pinfo->sub_type != BGP_ROUTE_AGGREGATE && + !sockunion2hostprefix(&peer->connection->su, &q)) return 0; dest = bgp_node_match(bgp_distance_table[afi][safi], &q); @@ -15701,7 +15556,7 @@ static void show_bgp_peerhash_entry(struct hash_bucket *bucket, void *arg) struct vty *vty = arg; struct peer *peer = bucket->data; - vty_out(vty, "\tPeer: %s %pSU\n", peer->host, &peer->su); + vty_out(vty, "\tPeer: %s %pSU\n", peer->host, &peer->connection->su); } DEFUN (show_bgp_listeners, @@ -15728,8 +15583,8 @@ DEFUN (show_bgp_peerhash, struct bgp *bgp; for (ALL_LIST_ELEMENTS_RO(instances, node, bgp)) { - vty_out(vty, "BGP: %s\n", bgp->name); - hash_iterate(bgp->peerhash, show_bgp_peerhash_entry, + vty_out(vty, "BGP: %s\n", bgp->name_pretty); + hash_iterate(bgp->peerhash, show_bgp_peerhash_entry, vty); } diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h index 9bd9e48e22..0599e8dce1 100644 --- a/bgpd/bgp_route.h +++ b/bgpd/bgp_route.h @@ -145,6 +145,54 @@ struct bgp_sid_info { uint8_t transposition_offset; }; +/* new structure for EVPN */ +struct bgp_path_info_extra_evpn { +#define BGP_EVPN_MACIP_TYPE_SVI_IP (1 << 0) + /* af specific flags */ + uint16_t af_flags; + union { + struct ethaddr mac; /* MAC set here for VNI IP table */ + struct ipaddr ip; /* IP set here for VNI MAC table */ + } vni_info; + /* Destination Ethernet Segment links for EVPN MH */ + struct bgp_path_mh_info *mh_info; +}; + +/* new structure for flowspec*/ +struct bgp_path_info_extra_fs { + /* presence of FS pbr firewall based entry */ + struct list *bgp_fs_pbr; + /* presence of FS pbr iprule based entry */ + struct list *bgp_fs_iprule; +}; + +/* new structure for vrfleak*/ +struct bgp_path_info_extra_vrfleak { + void *parent; /* parent from global table */ + /* + * Original bgp instance for imported routes. Needed for: + * 1. Find all routes from a specific vrf for deletion + * 2. vrf context of original nexthop + * + * Store pointer to bgp instance rather than bgp->vrf_id because + * bgp->vrf_id is not always valid (or may change?). + * + * Set to NULL if route is not imported from another bgp instance. + */ + struct bgp *bgp_orig; + /* + * Original bgp session to know if the session is a + * connected EBGP session or not + */ + struct peer *peer_orig; + /* + * Nexthop in context of original bgp instance. Needed + * for label resolution of core mpls routes exported to a vrf. + * Set nexthop_orig.family to 0 if not valid. + */ + struct prefix nexthop_orig; +}; + /* Ancillary information to struct bgp_path_info, * used for uncommonly used data (aggregation, MPLS, etc.) * and lazily allocated to save memory. @@ -163,13 +211,11 @@ struct bgp_path_info_extra { mpls_label_t label[BGP_MAX_LABELS]; uint32_t num_labels; - /* af specific flags */ - uint16_t af_flags; -#define BGP_EVPN_MACIP_TYPE_SVI_IP (1 << 0) + /* timestamp of the rib installation */ + time_t bgp_rib_uptime; - /* SRv6 SID(s) for SRv6-VPN */ - struct bgp_sid_info sid[BGP_MAX_SIDS]; - uint32_t num_sids; + /*For EVPN*/ + struct bgp_path_info_extra_evpn *evpn; #ifdef ENABLE_BGP_VNC union { @@ -200,50 +246,27 @@ struct bgp_path_info_extra { } vnc; #endif - /* - * For imported routes into a VNI (or VRF) - */ - void *parent; /* parent from global table */ - union { - struct ethaddr mac; /* MAC set here for VNI IP table */ - struct ipaddr ip; /* IP set here for VNI MAC table */ - } vni_info; + /* For flowspec*/ + struct bgp_path_info_extra_fs *flowspec; - /* - * Some tunnelish parameters follow. Maybe consolidate into an - * internal tunnel structure? - */ + /* For vrf leaking*/ + struct bgp_path_info_extra_vrfleak *vrfleak; +}; - /* - * Original bgp instance for imported routes. Needed for: - * 1. Find all routes from a specific vrf for deletion - * 2. vrf context of original nexthop - * - * Store pointer to bgp instance rather than bgp->vrf_id because - * bgp->vrf_id is not always valid (or may change?). - * - * Set to NULL if route is not imported from another bgp instance. - */ - struct bgp *bgp_orig; +struct bgp_mplsvpn_label_nh { + /* For nexthop per label linked list */ + LIST_ENTRY(bgp_path_info) label_nh_thread; - /* - * Original bgp session to know if the session is a - * connected EBGP session or not - */ - struct peer *peer_orig; + /* Back pointer to the bgp label per nexthop structure */ + struct bgp_label_per_nexthop_cache *label_nexthop_cache; +}; - /* - * Nexthop in context of original bgp instance. Needed - * for label resolution of core mpls routes exported to a vrf. - * Set nexthop_orig.family to 0 if not valid. - */ - struct prefix nexthop_orig; - /* presence of FS pbr firewall based entry */ - struct list *bgp_fs_pbr; - /* presence of FS pbr iprule based entry */ - struct list *bgp_fs_iprule; - /* Destination Ethernet Segment links for EVPN MH */ - struct bgp_path_mh_info *mh_info; +struct bgp_mplsvpn_nh_label_bind { + /* For mplsvpn nexthop label bind linked list */ + LIST_ENTRY(bgp_path_info) nh_label_bind_thread; + + /* Back pointer to the bgp mplsvpn nexthop label bind structure */ + struct bgp_mplsvpn_nh_label_bind_cache *nh_label_bind_cache; }; struct bgp_path_info { @@ -298,6 +321,8 @@ struct bgp_path_info { #define BGP_PATH_ANNC_NH_SELF (1 << 14) #define BGP_PATH_LINK_BW_CHG (1 << 15) #define BGP_PATH_ACCEPT_OWN (1 << 16) +#define BGP_PATH_MPLSVPN_LABEL_NH (1 << 17) +#define BGP_PATH_MPLSVPN_NH_LABEL_BIND (1 << 18) /* BGP route type. This can be static, RIP, OSPF, BGP etc. */ uint8_t type; @@ -320,11 +345,10 @@ struct bgp_path_info { uint32_t addpath_rx_id; struct bgp_addpath_info_data tx_addpath; - /* For nexthop per label linked list */ - LIST_ENTRY(bgp_path_info) label_nh_thread; - - /* Back pointer to the bgp label per nexthop structure */ - struct bgp_label_per_nexthop_cache *label_nexthop_cache; + union { + struct bgp_mplsvpn_label_nh blnc; + struct bgp_mplsvpn_nh_label_bind bmnc; + } mplsvpn; }; /* Structure used in BGP path selection */ @@ -592,8 +616,12 @@ static inline void prep_for_rmap_apply(struct bgp_path_info *dst_pi, } } -static inline bool bgp_check_advertise(struct bgp *bgp, struct bgp_dest *dest) +static inline bool bgp_check_advertise(struct bgp *bgp, struct bgp_dest *dest, + safi_t safi) { + if (!bgp_fibupd_safi(safi)) + return true; + return (!(BGP_SUPPRESS_FIB_ENABLED(bgp) && CHECK_FLAG(dest->flags, BGP_NODE_FIB_INSTALL_PENDING) && (!bgp_option_check(BGP_OPT_NO_FIB)))); @@ -605,11 +633,12 @@ static inline bool bgp_check_advertise(struct bgp *bgp, struct bgp_dest *dest) * This function assumes that bgp_check_advertise was already returned * as good to go. */ -static inline bool bgp_check_withdrawal(struct bgp *bgp, struct bgp_dest *dest) +static inline bool bgp_check_withdrawal(struct bgp *bgp, struct bgp_dest *dest, + safi_t safi) { struct bgp_path_info *pi, *selected = NULL; - if (!BGP_SUPPRESS_FIB_ENABLED(bgp)) + if (!bgp_fibupd_safi(safi) || !BGP_SUPPRESS_FIB_ENABLED(bgp)) return false; for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) { @@ -644,10 +673,16 @@ static inline bool bgp_check_withdrawal(struct bgp *bgp, struct bgp_dest *dest) /* called before bgp_process() */ DECLARE_HOOK(bgp_process, - (struct bgp * bgp, afi_t afi, safi_t safi, struct bgp_dest *bn, + (struct bgp *bgp, afi_t afi, safi_t safi, struct bgp_dest *bn, struct peer *peer, bool withdraw), (bgp, afi, safi, bn, peer, withdraw)); +/* called when a route is updated in the rib */ +DECLARE_HOOK(bgp_route_update, + (struct bgp *bgp, afi_t afi, safi_t safi, struct bgp_dest *bn, + struct bgp_path_info *old_route, struct bgp_path_info *new_route), + (bgp, afi, safi, bn, old_route, new_route)); + /* BGP show options */ #define BGP_SHOW_OPT_JSON (1 << 0) #define BGP_SHOW_OPT_WIDE (1 << 1) @@ -672,7 +707,8 @@ extern void bgp_announce_route(struct peer *peer, afi_t afi, safi_t safi, bool force); extern void bgp_stop_announce_route_timer(struct peer_af *paf); extern void bgp_announce_route_all(struct peer *); -extern void bgp_default_originate(struct peer *, afi_t, safi_t, int); +extern void bgp_default_originate(struct peer *peer, afi_t afi, safi_t safi, + bool withdraw); extern void bgp_soft_reconfig_table_task_cancel(const struct bgp *bgp, const struct bgp_table *table, const struct peer *peer); @@ -695,11 +731,14 @@ extern struct bgp_dest *bgp_afi_node_get(struct bgp_table *table, afi_t afi, struct prefix_rd *prd); extern struct bgp_path_info *bgp_path_info_lock(struct bgp_path_info *path); extern struct bgp_path_info *bgp_path_info_unlock(struct bgp_path_info *path); +extern bool bgp_path_info_nexthop_changed(struct bgp_path_info *pi, + struct peer *to, afi_t afi); extern struct bgp_path_info * bgp_get_imported_bpi_ultimate(struct bgp_path_info *info); extern void bgp_path_info_add(struct bgp_dest *dest, struct bgp_path_info *pi); extern void bgp_path_info_extra_free(struct bgp_path_info_extra **extra); -extern void bgp_path_info_reap(struct bgp_dest *dest, struct bgp_path_info *pi); +extern struct bgp_dest *bgp_path_info_reap(struct bgp_dest *dest, + struct bgp_path_info *pi); extern void bgp_path_info_delete(struct bgp_dest *dest, struct bgp_path_info *pi); extern struct bgp_path_info_extra * @@ -732,16 +771,14 @@ extern void bgp_purge_static_redist_routes(struct bgp *bgp); extern void bgp_static_update(struct bgp *bgp, const struct prefix *p, struct bgp_static *s, afi_t afi, safi_t safi); extern void bgp_static_withdraw(struct bgp *bgp, const struct prefix *p, - afi_t afi, safi_t safi); - -extern int bgp_static_set_safi(afi_t afi, safi_t safi, struct vty *vty, - const char *, const char *, const char *, - const char *, int, const char *, const char *, - const char *, const char *); + afi_t afi, safi_t safi, struct prefix_rd *prd); -extern int bgp_static_unset_safi(afi_t afi, safi_t safi, struct vty *, - const char *, const char *, const char *, int, - const char *, const char *, const char *); +extern int bgp_static_set(struct vty *vty, bool negate, const char *ip_str, + const char *rd_str, const char *label_str, afi_t afi, + safi_t safi, const char *rmap, int backdoor, + uint32_t label_index, int evpn_type, const char *esi, + const char *gwip, const char *ethtag, + const char *routermac); /* this is primarily for MPLS-VPN */ extern void bgp_update(struct peer *peer, const struct prefix *p, @@ -860,7 +897,7 @@ extern void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_path_info *path, afi_t afi, safi_t safi, enum rpki_states, json_object *json_paths); -extern int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi, +extern int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, struct bgp_table *table, struct prefix_rd *prd, enum bgp_show_type type, void *output_arg, uint16_t show_flags); @@ -869,7 +906,8 @@ extern bool bgp_update_martian_nexthop(struct bgp *bgp, afi_t afi, safi_t safi, uint8_t type, uint8_t stype, struct attr *attr, struct bgp_dest *dest); extern int bgp_evpn_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, - struct bgp_path_info *exist, int *paths_eq); + struct bgp_path_info *exist, int *paths_eq, + bool debug); extern void bgp_aggregate_toggle_suppressed(struct bgp_aggregate *aggregate, struct bgp *bgp, const struct prefix *p, afi_t afi, @@ -877,6 +915,7 @@ extern void bgp_aggregate_toggle_suppressed(struct bgp_aggregate *aggregate, extern void subgroup_announce_reset_nhop(uint8_t family, struct attr *attr); const char * bgp_path_selection_reason2str(enum bgp_path_selection_reason reason); +extern bool bgp_path_suppressed(struct bgp_path_info *pi); extern bool bgp_addpath_encode_rx(struct peer *peer, afi_t afi, safi_t safi); extern const struct prefix_rd *bgp_rd_from_dest(const struct bgp_dest *dest, safi_t safi); @@ -886,6 +925,11 @@ extern void bgp_path_info_add_with_caller(const char *caller, struct bgp_dest *dest, struct bgp_path_info *pi); extern void bgp_aggregate_free(struct bgp_aggregate *aggregate); +extern int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, + struct bgp_path_info *exist, int *paths_eq, + struct bgp_maxpaths_cfg *mpath_cfg, bool debug, + char *pfx_buf, afi_t afi, safi_t safi, + enum bgp_path_selection_reason *reason); #define bgp_path_info_add(A, B) \ bgp_path_info_add_with_caller(__func__, (A), (B)) #define bgp_path_info_free(B) bgp_path_info_free_with_caller(__func__, (B)) diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index 7db110be93..382e8ae409 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -282,14 +282,14 @@ route_match_peer(void *rule, const struct prefix *prefix, void *object) } if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { - if (sockunion_same(su, &peer->su)) + if (sockunion_same(su, &peer->connection->su)) return RMAP_MATCH; return RMAP_NOMATCH; } else { group = peer->group; for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) { - if (sockunion_same(su, &peer->su)) + if (sockunion_same(su, &peer->connection->su)) return RMAP_MATCH; } return RMAP_NOMATCH; @@ -574,11 +574,11 @@ route_match_ip_route_source(void *rule, const struct prefix *pfx, void *object) path = object; peer = path->peer; - if (!peer || sockunion_family(&peer->su) != AF_INET) + if (!peer || sockunion_family(&peer->connection->su) != AF_INET) return RMAP_NOMATCH; p.family = AF_INET; - p.prefix = peer->su.sin.sin_addr; + p.prefix = peer->connection->su.sin.sin_addr; p.prefixlen = IPV4_MAX_BITLEN; alist = access_list_lookup(AFI_IP, (char *)rule); @@ -927,11 +927,11 @@ route_match_ip_route_source_prefix_list(void *rule, const struct prefix *prefix, path = object; peer = path->peer; - if (!peer || sockunion_family(&peer->su) != AF_INET) + if (!peer || sockunion_family(&peer->connection->su) != AF_INET) return RMAP_NOMATCH; p.family = AF_INET; - p.prefix = peer->su.sin.sin_addr; + p.prefix = peer->connection->su.sin.sin_addr; p.prefixlen = IPV4_MAX_BITLEN; plist = prefix_list_lookup(AFI_IP, (char *)rule); @@ -1313,12 +1313,13 @@ route_match_vrl_source_vrf(void *rule, const struct prefix *prefix, if (strncmp(vrf_name, "n/a", VRF_NAMSIZ) == 0) return RMAP_NOMATCH; - if (path->extra == NULL || path->extra->bgp_orig == NULL) + if (path->extra == NULL || path->extra->vrfleak == NULL || + path->extra->vrfleak->bgp_orig == NULL) return RMAP_NOMATCH; - if (strncmp(vrf_name, vrf_id_to_name(path->extra->bgp_orig->vrf_id), - VRF_NAMSIZ) - == 0) + if (strncmp(vrf_name, + vrf_id_to_name(path->extra->vrfleak->bgp_orig->vrf_id), + VRF_NAMSIZ) == 0) return RMAP_MATCH; return RMAP_NOMATCH; @@ -1527,7 +1528,8 @@ static const struct route_map_rule_cmd route_match_aspath_cmd = { struct rmap_community { char *name; uint32_t name_hash; - int exact; + bool exact; + bool any; }; /* Match function for community match. */ @@ -1550,6 +1552,12 @@ route_match_community(void *rule, const struct prefix *prefix, void *object) if (community_list_exact_match( bgp_attr_get_community(path->attr), list)) return RMAP_MATCH; + } else if (rcom->any) { + if (!bgp_attr_get_community(path->attr)) + return RMAP_OKAY; + if (community_list_any_match(bgp_attr_get_community(path->attr), + list)) + return RMAP_MATCH; } else { if (community_list_match(bgp_attr_get_community(path->attr), list)) @@ -1573,10 +1581,15 @@ static void *route_match_community_compile(const char *arg) len = p - arg; rcom->name = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, len + 1); memcpy(rcom->name, arg, len); - rcom->exact = 1; + p++; + if (*p == 'e') + rcom->exact = true; + else + rcom->any = true; } else { rcom->name = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); - rcom->exact = 0; + rcom->exact = false; + rcom->any = false; } rcom->name_hash = bgp_clist_hash_key(rcom->name); @@ -1636,6 +1649,12 @@ route_match_lcommunity(void *rule, const struct prefix *prefix, void *object) if (lcommunity_list_exact_match( bgp_attr_get_lcommunity(path->attr), list)) return RMAP_MATCH; + } else if (rcom->any) { + if (!bgp_attr_get_lcommunity(path->attr)) + return RMAP_OKAY; + if (lcommunity_list_any_match(bgp_attr_get_lcommunity(path->attr), + list)) + return RMAP_MATCH; } else { if (lcommunity_list_match(bgp_attr_get_lcommunity(path->attr), list)) @@ -1659,10 +1678,15 @@ static void *route_match_lcommunity_compile(const char *arg) len = p - arg; rcom->name = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, len + 1); memcpy(rcom->name, arg, len); - rcom->exact = 1; + p++; + if (*p == 'e') + rcom->exact = true; + else + rcom->any = true; } else { rcom->name = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); - rcom->exact = 0; + rcom->exact = false; + rcom->any = false; } rcom->name_hash = bgp_clist_hash_key(rcom->name); @@ -2300,6 +2324,42 @@ static const struct route_map_rule_cmd route_set_aspath_prepend_cmd = { }; /* `set as-path exclude ASn' */ +struct aspath_exclude { + struct aspath *aspath; + bool exclude_all; + char *exclude_aspath_acl_name; + struct as_list *exclude_aspath_acl; +}; + +static void *route_aspath_exclude_compile(const char *arg) +{ + struct aspath_exclude *ase; + const char *str = arg; + static const char asp_acl[] = "as-path-access-list"; + + ase = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct aspath_exclude)); + if (strmatch(str, "all")) + ase->exclude_all = true; + else if (!strncmp(str, asp_acl, strlen(asp_acl))) { + str += strlen(asp_acl); + while (*str == ' ') + str++; + ase->exclude_aspath_acl_name = XSTRDUP(MTYPE_TMP, str); + ase->exclude_aspath_acl = as_list_lookup(str); + } else + ase->aspath = aspath_str2aspath(str, bgp_get_asnotation(NULL)); + return ase; +} + +static void route_aspath_exclude_free(void *rule) +{ + struct aspath_exclude *ase = rule; + + aspath_free(ase->aspath); + if (ase->exclude_aspath_acl_name) + XFREE(MTYPE_TMP, ase->exclude_aspath_acl_name); + XFREE(MTYPE_ROUTE_MAP_COMPILED, ase); +} /* For ASN exclude mechanism. * Iterate over ASns requested and filter them from the given AS_PATH one by @@ -2309,26 +2369,48 @@ static const struct route_map_rule_cmd route_set_aspath_prepend_cmd = { static enum route_map_cmd_result_t route_set_aspath_exclude(void *rule, const struct prefix *dummy, void *object) { - struct aspath *new_path, *exclude_path; + struct aspath *new_path; struct bgp_path_info *path; + struct aspath_exclude *ase = rule; - exclude_path = rule; path = object; + + if (path->peer->sort != BGP_PEER_EBGP) { + zlog_warn( + "`set as-path exclude` is supported only for EBGP peers"); + return RMAP_NOOP; + } + if (path->attr->aspath->refcnt) new_path = aspath_dup(path->attr->aspath); else new_path = path->attr->aspath; - path->attr->aspath = aspath_filter_exclude(new_path, exclude_path); + + if (ase->aspath) + path->attr->aspath = + aspath_filter_exclude(new_path, ase->aspath); + else if (ase->exclude_all) + path->attr->aspath = aspath_filter_exclude_all(new_path); + + else if (ase->exclude_aspath_acl_name) { + if (!ase->exclude_aspath_acl) + ase->exclude_aspath_acl = + as_list_lookup(ase->exclude_aspath_acl_name); + if (ase->exclude_aspath_acl) + path->attr->aspath = + aspath_filter_exclude_acl(new_path, + ase->exclude_aspath_acl); + } return RMAP_OKAY; } -/* Set ASn exlude rule structure. */ +/* Set ASn exclude rule structure. */ static const struct route_map_rule_cmd route_set_aspath_exclude_cmd = { "as-path exclude", route_set_aspath_exclude, - route_aspath_compile, - route_aspath_free, + route_aspath_exclude_compile, + route_aspath_exclude_free, }; /* `set as-path replace AS-PATH` */ @@ -2348,13 +2430,84 @@ route_set_aspath_replace(void *rule, const struct prefix *dummy, void *object) struct aspath *aspath_new; const char *replace = rule; struct bgp_path_info *path = object; - as_t own_asn = path->peer->change_local_as ? path->peer->change_local_as - : path->peer->local_as; + as_t replace_asn = 0; + as_t configured_asn; + char *buf; + char src_asn[ASN_STRING_MAX_SIZE]; + char *acl_list_name = NULL; + uint32_t acl_list_name_len = 0; + char *buf_acl_name = NULL; + static const char asp_acl[] = "as-path-access-list"; + struct as_list *aspath_acl = NULL; if (path->peer->sort != BGP_PEER_EBGP) { zlog_warn( "`set as-path replace` is supported only for EBGP peers"); - return RMAP_NOOP; + goto end_ko; + } + + buf = strchr(replace, ' '); + if (!buf) { + configured_asn = path->peer->change_local_as + ? path->peer->change_local_as + : path->peer->local_as; + } else if (!strncmp(replace, asp_acl, strlen(asp_acl))) { + /* its as-path-acl-list command get the access list name */ + while (*buf == ' ') + buf++; + buf_acl_name = buf; + buf = strchr(buf_acl_name, ' '); + if (buf) + acl_list_name_len = buf - buf_acl_name; + else + acl_list_name_len = strlen(buf_acl_name); + + buf_acl_name[acl_list_name_len] = 0; + /* get the acl-list */ + aspath_acl = as_list_lookup(buf_acl_name); + if (!aspath_acl) { + zlog_warn("`set as-path replace`, invalid as-path-access-list name: %s", + buf_acl_name); + goto end_ko; + } + acl_list_name = XSTRDUP(MTYPE_TMP, buf_acl_name); + buf_acl_name[acl_list_name_len] = ' '; + + if (!buf) { + configured_asn = path->peer->change_local_as + ? path->peer->change_local_as + : path->peer->local_as; + } else { + while (*buf == ' ') + buf++; + /* get the configured asn */ + if (!asn_str2asn(buf, &configured_asn)) { + zlog_warn( + "`set as-path replace`, invalid configured AS %s", + buf); + goto end_ko; + } + } + + replace = buf; + + } else { + memcpy(src_asn, replace, (size_t)(buf - replace)); + src_asn[(size_t)(buf - replace)] = '\0'; + replace = src_asn; + buf++; + if (!asn_str2asn(buf, &configured_asn)) { + zlog_warn( + "`set as-path replace`, invalid configured AS %s", + buf); + goto end_ko; + } + } + + if (replace && !strmatch(replace, "any") && + !asn_str2asn(replace, &replace_asn)) { + zlog_warn("`set as-path replace`, invalid AS %s", replace); + goto end_ko; } if (path->attr->aspath->refcnt) @@ -2362,19 +2515,29 @@ route_set_aspath_replace(void *rule, const struct prefix *dummy, void *object) else aspath_new = path->attr->aspath; - if (strmatch(replace, "any")) { + if (aspath_acl) { + path->attr->aspath = aspath_replace_regex_asn(aspath_new, + aspath_acl, + configured_asn); + } else if (strmatch(replace, "any")) { path->attr->aspath = - aspath_replace_all_asn(aspath_new, own_asn); + aspath_replace_all_asn(aspath_new, configured_asn); } else { - as_t replace_asn = strtoul(replace, NULL, 10); - path->attr->aspath = aspath_replace_specific_asn( - aspath_new, replace_asn, own_asn); + aspath_new, replace_asn, configured_asn); } - aspath_free(aspath_new); + + if (acl_list_name) + XFREE(MTYPE_TMP, acl_list_name); return RMAP_OKAY; + +end_ko: + if (acl_list_name) + XFREE(MTYPE_TMP, acl_list_name); + return RMAP_NOOP; + } static const struct route_map_rule_cmd route_set_aspath_replace_cmd = { @@ -2772,6 +2935,83 @@ static const struct route_map_rule_cmd route_set_community_delete_cmd = { route_set_community_delete_free, }; +/* `set extcomm-list (<1-99>|<100-500>|WORD) delete' */ +static enum route_map_cmd_result_t +route_set_ecommunity_delete(void *rule, const struct prefix *prefix, + void *object) +{ + struct community_list *list; + struct ecommunity *merge; + struct ecommunity *new; + struct ecommunity *old; + struct bgp_path_info *path; + struct rmap_community *rcom = rule; + + if (!rcom) + return RMAP_OKAY; + + path = object; + list = community_list_lookup(bgp_clist, rcom->name, rcom->name_hash, + EXTCOMMUNITY_LIST_MASTER); + old = bgp_attr_get_ecommunity(path->attr); + if (list && old) { + merge = ecommunity_list_match_delete(ecommunity_dup(old), list); + new = ecommunity_uniq_sort(merge); + ecommunity_free(&merge); + + /* HACK: if the old community is not intern'd, + * we should free it here, or all reference to it may be + * lost. + * Really need to cleanup attribute caching sometime. + */ + if (old->refcnt == 0) + ecommunity_free(&old); + + if (new->size == 0) { + bgp_attr_set_ecommunity(path->attr, NULL); + ecommunity_free(&new); + } else { + bgp_attr_set_ecommunity(path->attr, new); + } + } + + return RMAP_OKAY; +} + +static void *route_set_ecommunity_delete_compile(const char *arg) +{ + struct rmap_community *rcom; + char **splits; + int num; + + frrstr_split(arg, " ", &splits, &num); + + rcom = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_community)); + rcom->name = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, splits[0]); + rcom->name_hash = bgp_clist_hash_key(rcom->name); + + for (int i = 0; i < num; i++) + XFREE(MTYPE_TMP, splits[i]); + XFREE(MTYPE_TMP, splits); + + return rcom; +} + +static void route_set_ecommunity_delete_free(void *rule) +{ + struct rmap_community *rcom = rule; + + XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom->name); + XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom); +} + +static const struct route_map_rule_cmd route_set_ecommunity_delete_cmd = { + "extended-comm-list", + route_set_ecommunity_delete, + route_set_ecommunity_delete_compile, + route_set_ecommunity_delete_free, +}; + /* `set extcommunity rt COMMUNITY' */ struct rmap_ecom_set { @@ -3055,6 +3295,44 @@ static void *route_set_ecommunity_lb_compile(const char *arg) return rels; } +static enum route_map_cmd_result_t +route_set_ecommunity_color(void *rule, const struct prefix *prefix, + void *object) +{ + struct bgp_path_info *path; + + path = object; + + route_set_ecommunity(rule, prefix, object); + + path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR); + return RMAP_OKAY; +} + +static void *route_set_ecommunity_color_compile(const char *arg) +{ + struct rmap_ecom_set *rcs; + struct ecommunity *ecom; + + ecom = ecommunity_str2com(arg, ECOMMUNITY_COLOR, 0); + if (!ecom) + return NULL; + + rcs = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(struct rmap_ecom_set)); + rcs->ecom = ecommunity_intern(ecom); + rcs->none = false; + + return rcs; +} + +static const struct route_map_rule_cmd route_set_ecommunity_color_cmd = { + "extcommunity color", + route_set_ecommunity_color, + route_set_ecommunity_color_compile, + route_set_ecommunity_free, +}; + + static void route_set_ecommunity_lb_free(void *rule) { XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); @@ -4085,7 +4363,7 @@ static void bgp_route_map_process_peer(const char *rmap_name, && (strcmp(rmap_name, filter->map[RMAP_IN].name) == 0)) { filter->map[RMAP_IN].map = map; - if (route_update && peer_established(peer)) { + if (route_update && peer_established(peer->connection)) { if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)) { if (bgp_debug_update(peer, NULL, NULL, 1)) @@ -4095,10 +4373,7 @@ static void bgp_route_map_process_peer(const char *rmap_name, safi2str(safi), peer->host); bgp_soft_reconfig_in(peer, afi, safi); - } else if (CHECK_FLAG(peer->cap, - PEER_CAP_REFRESH_OLD_RCV) - || CHECK_FLAG(peer->cap, - PEER_CAP_REFRESH_NEW_RCV)) { + } else if (CHECK_FLAG(peer->cap, PEER_CAP_REFRESH_RCV)) { if (bgp_debug_update(peer, NULL, NULL, 1)) zlog_debug( "Processing route_map %s(%s:%s) update on peer %s (inbound, route-refresh)", @@ -4468,6 +4743,24 @@ static void bgp_route_map_delete(const char *rmap_name) route_map_notify_dependencies(rmap_name, RMAP_EVENT_MATCH_DELETED); } +bool bgp_route_map_has_extcommunity_rt(const struct route_map *map) +{ + struct route_map_index *index = NULL; + struct route_map_rule *set = NULL; + + assert(map); + + for (index = map->head; index; index = index->next) { + for (set = index->set_list.head; set; set = set->next) { + if (set->cmd && set->cmd->str && + (strmatch(set->cmd->str, "extcommunity rt") || + strmatch(set->cmd->str, "extended-comm-list"))) + return true; + } + } + return false; +} + static void bgp_route_map_event(const char *rmap_name) { if (route_map_mark_updated(rmap_name) == 0) @@ -5241,15 +5534,15 @@ DEFUN_YANG(no_match_alias, no_match_alias_cmd, "no match alias [ALIAS_NAME]", return nb_cli_apply_changes(vty, NULL); } -DEFPY_YANG (match_community, - match_community_cmd, - "match community <(1-99)|(100-500)|COMMUNITY_LIST_NAME> [exact-match]", - MATCH_STR - "Match BGP community list\n" - "Community-list number (standard)\n" - "Community-list number (expanded)\n" - "Community-list name\n" - "Do exact matching of communities\n") +DEFPY_YANG( + match_community, match_community_cmd, + "match community <(1-99)|(100-500)|COMMUNITY_LIST_NAME> []", + MATCH_STR "Match BGP community list\n" + "Community-list number (standard)\n" + "Community-list number (expanded)\n" + "Community-list name\n" + "Do exact matching of communities\n" + "Do matching of any community\n") { const char *xpath = "./match-condition[condition='frr-bgp-route-map:match-community']"; @@ -5265,35 +5558,35 @@ DEFPY_YANG (match_community, xpath); nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, argv[idx_comm_list]->arg); - if (argc == 4) { - snprintf( - xpath_match, sizeof(xpath_match), - "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match", - xpath); + snprintf(xpath_match, sizeof(xpath_match), + "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match", + xpath); + if (exact) nb_cli_enqueue_change(vty, xpath_match, NB_OP_MODIFY, "true"); - } else { - snprintf( - xpath_match, sizeof(xpath_match), - "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match", - xpath); - nb_cli_enqueue_change(vty, xpath_match, NB_OP_MODIFY, - "false"); - } + else + nb_cli_enqueue_change(vty, xpath_match, NB_OP_MODIFY, "false"); + + snprintf(xpath_match, sizeof(xpath_match), + "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-any", + xpath); + if (any) + nb_cli_enqueue_change(vty, xpath_match, NB_OP_MODIFY, "true"); + else + nb_cli_enqueue_change(vty, xpath_match, NB_OP_MODIFY, "false"); return nb_cli_apply_changes(vty, NULL); } -DEFUN_YANG (no_match_community, - no_match_community_cmd, - "no match community [<(1-99)|(100-500)|COMMUNITY_LIST_NAME> [exact-match]]", - NO_STR - MATCH_STR - "Match BGP community list\n" - "Community-list number (standard)\n" - "Community-list number (expanded)\n" - "Community-list name\n" - "Do exact matching of communities\n") +DEFUN_YANG( + no_match_community, no_match_community_cmd, + "no match community [<(1-99)|(100-500)|COMMUNITY_LIST_NAME> []]", + NO_STR MATCH_STR "Match BGP community list\n" + "Community-list number (standard)\n" + "Community-list number (expanded)\n" + "Community-list name\n" + "Do exact matching of communities\n" + "Do matching of any community\n") { const char *xpath = "./match-condition[condition='frr-bgp-route-map:match-community']"; @@ -5302,15 +5595,15 @@ DEFUN_YANG (no_match_community, return nb_cli_apply_changes(vty, NULL); } -DEFPY_YANG (match_lcommunity, - match_lcommunity_cmd, - "match large-community <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> [exact-match]", - MATCH_STR - "Match BGP large community list\n" - "Large Community-list number (standard)\n" - "Large Community-list number (expanded)\n" - "Large Community-list name\n" - "Do exact matching of communities\n") +DEFPY_YANG( + match_lcommunity, match_lcommunity_cmd, + "match large-community <(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> []", + MATCH_STR "Match BGP large community list\n" + "Large Community-list number (standard)\n" + "Large Community-list number (expanded)\n" + "Large Community-list name\n" + "Do exact matching of communities\n" + "Do matching of any community\n") { const char *xpath = "./match-condition[condition='frr-bgp-route-map:match-large-community']"; @@ -5326,35 +5619,35 @@ DEFPY_YANG (match_lcommunity, xpath); nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, argv[idx_lcomm_list]->arg); - if (argc == 4) { - snprintf( - xpath_match, sizeof(xpath_match), - "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match", - xpath); + snprintf(xpath_match, sizeof(xpath_match), + "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match", + xpath); + if (exact) nb_cli_enqueue_change(vty, xpath_match, NB_OP_MODIFY, "true"); - } else { - snprintf( - xpath_match, sizeof(xpath_match), - "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match", - xpath); - nb_cli_enqueue_change(vty, xpath_match, NB_OP_MODIFY, - "false"); - } + else + nb_cli_enqueue_change(vty, xpath_match, NB_OP_MODIFY, "false"); + + snprintf(xpath_match, sizeof(xpath_match), + "%s/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-any", + xpath); + if (any) + nb_cli_enqueue_change(vty, xpath_match, NB_OP_MODIFY, "true"); + else + nb_cli_enqueue_change(vty, xpath_match, NB_OP_MODIFY, "false"); return nb_cli_apply_changes(vty, NULL); } -DEFUN_YANG (no_match_lcommunity, - no_match_lcommunity_cmd, - "no match large-community [<(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> [exact-match]]", - NO_STR - MATCH_STR - "Match BGP large community list\n" - "Large Community-list number (standard)\n" - "Large Community-list number (expanded)\n" - "Large Community-list name\n" - "Do exact matching of communities\n") +DEFUN_YANG( + no_match_lcommunity, no_match_lcommunity_cmd, + "no match large-community [<(1-99)|(100-500)|LCOMMUNITY_LIST_NAME> []]", + NO_STR MATCH_STR "Match BGP large community list\n" + "Large Community-list number (standard)\n" + "Large Community-list number (expanded)\n" + "Large Community-list name\n" + "Do exact matching of communities\n" + "Do matching of any community\n") { const char *xpath = "./match-condition[condition='frr-bgp-route-map:match-large-community']"; @@ -5407,6 +5700,51 @@ DEFUN_YANG (no_match_ecommunity, } +DEFPY_YANG (set_ecommunity_delete, + set_ecommunity_delete_cmd, + "set extended-comm-list " EXTCOMM_LIST_CMD_STR " delete", + SET_STR + "set BGP extended community list (for deletion)\n" + EXTCOMM_STD_LIST_NUM_STR + EXTCOMM_EXP_LIST_NUM_STR + EXTCOMM_LIST_NAME_STR + "Delete matching extended communities\n") +{ + const char *xpath = + "./set-action[action='frr-bgp-route-map:extended-comm-list-delete']"; + char xpath_value[XPATH_MAXLEN]; + int idx_comm_list = 2; + + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); + + snprintf(xpath_value, sizeof(xpath_value), + "%s/rmap-set-action/frr-bgp-route-map:comm-list-name", + xpath); + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, + argv[idx_comm_list]->arg); + return nb_cli_apply_changes(vty, NULL); +} + + +DEFPY_YANG (no_set_ecommunity_delete, + no_set_ecommunity_delete_cmd, + "no set extended-comm-list [" EXTCOMM_LIST_CMD_STR "] delete", + NO_STR + SET_STR + "set BGP extended community list (for deletion)\n" + EXTCOMM_STD_LIST_NUM_STR + EXTCOMM_EXP_LIST_NUM_STR + EXTCOMM_LIST_NAME_STR + "Delete matching extended communities\n") +{ + const char *xpath = + "./set-action[action='frr-bgp-route-map:extended-comm-list-delete']"; + + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); + return nb_cli_apply_changes(vty, NULL); +} + + DEFUN_YANG (match_aspath, match_aspath_cmd, "match as-path AS_PATH_FILTER_NAME", @@ -5800,41 +6138,48 @@ DEFUN_YANG (set_aspath_prepend_lastas, return nb_cli_apply_changes(vty, NULL); } -DEFPY_YANG (set_aspath_replace_asn, - set_aspath_replace_asn_cmd, - "set as-path replace $replace", - SET_STR - "Transform BGP AS_PATH attribute\n" - "Replace AS number to local AS number\n" - "Replace any AS number to local AS number\n" - "Replace a specific AS number in plain or dotted format to local AS number\n") +DEFPY_YANG(set_aspath_replace_asn, set_aspath_replace_asn_cmd, + "set as-path replace $replace [$configured_asn]", + SET_STR + "Transform BGP AS_PATH attribute\n" + "Replace AS number to local or configured AS number\n" + "Replace any AS number to local or configured AS number\n" + "Replace a specific AS number to local or configured AS number\n" + "Define the configured AS number\n") { const char *xpath = "./set-action[action='frr-bgp-route-map:as-path-replace']"; char xpath_value[XPATH_MAXLEN]; - as_t as_value; + as_t as_value, as_configured_value; + char replace_value[ASN_STRING_MAX_SIZE * 2]; if (!strmatch(replace, "any") && !asn_str2asn(replace, &as_value)) { vty_out(vty, "%% Invalid AS value %s\n", replace); return CMD_WARNING_CONFIG_FAILED; } - - nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); + if (configured_asn_str && + !asn_str2asn(configured_asn_str, &as_configured_value)) { + vty_out(vty, "%% Invalid AS configured value %s\n", + configured_asn_str); + return CMD_WARNING_CONFIG_FAILED; + } snprintf(xpath_value, sizeof(xpath_value), "%s/rmap-set-action/frr-bgp-route-map:replace-as-path", xpath); - nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, replace); + snprintf(replace_value, sizeof(replace_value), "%s%s%s", replace, + configured_asn_str ? " " : "", + configured_asn_str ? configured_asn_str : ""); + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, replace_value); return nb_cli_apply_changes(vty, NULL); } -DEFPY_YANG (no_set_aspath_replace_asn, - no_set_aspath_replace_asn_cmd, - "no set as-path replace []", - NO_STR - SET_STR - "Transform BGP AS_PATH attribute\n" - "Replace AS number to local AS number\n" - "Replace any AS number to local AS number\n" - "Replace a specific AS number in plain or dotted format to local AS number\n") +DEFPY_YANG(no_set_aspath_replace_asn, no_set_aspath_replace_asn_cmd, + "no set as-path replace [] [$configured_asn]", + NO_STR SET_STR + "Transform BGP AS_PATH attribute\n" + "Replace AS number to local or configured AS number\n" + "Replace any AS number to local or configured AS number\n" + "Replace a specific AS number to local or configured AS number\n" + "Define the configured AS number\n") { const char *xpath = "./set-action[action='frr-bgp-route-map:as-path-replace']"; @@ -5843,29 +6188,72 @@ DEFPY_YANG (no_set_aspath_replace_asn, return nb_cli_apply_changes(vty, NULL); } -DEFUN_YANG (no_set_aspath_prepend, - no_set_aspath_prepend_cmd, - "no set as-path prepend [ASNUM]", - NO_STR - SET_STR - "Transform BGP AS_PATH attribute\n" - "Prepend to the as-path\n" - AS_STR) +DEFPY_YANG( + set_aspath_replace_access_list, set_aspath_replace_access_list_cmd, + "set as-path replace as-path-access-list AS_PATH_FILTER_NAME$aspath_filter_name [$configured_asn]", + SET_STR + "Transform BGP AS-path attribute\n" + "Replace AS number to local or configured AS number\n" + "Specify an as path access list name\n" + "AS path access list name\n" + "Define the configured AS number\n") { + char *str; const char *xpath = - "./set-action[action='frr-bgp-route-map:as-path-prepend']"; + "./set-action[action='frr-bgp-route-map:as-path-replace']"; + char xpath_value[XPATH_MAXLEN]; + as_t as_configured_value; + char replace_value[ASN_STRING_MAX_SIZE * 2]; + int ret; + + if (configured_asn_str && + !asn_str2asn(configured_asn_str, &as_configured_value)) { + vty_out(vty, "%% Invalid AS configured value %s\n", + configured_asn_str); + return CMD_WARNING_CONFIG_FAILED; + } + + str = argv_concat(argv, argc, 3); + + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); + + snprintf(replace_value, sizeof(replace_value), "%s %s", aspath_filter_name, str); + + snprintf(xpath_value, sizeof(xpath_value), + "%s/rmap-set-action/frr-bgp-route-map:replace-as-path", xpath); + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, str); + + ret = nb_cli_apply_changes(vty, NULL); + XFREE(MTYPE_TMP, str); + return ret; +} + +DEFPY_YANG( + no_set_aspath_replace_access_list, no_set_aspath_replace_access_list_cmd, + "no set as-path replace as-path-access-list [AS_PATH_FILTER_NAME] [$configured_asn]", + NO_STR + SET_STR + "Transform BGP AS_PATH attribute\n" + "Replace AS number to local or configured AS number\n" + "Specify an as path access list name\n" + "AS path access list name\n" + "Define the configured AS number\n") +{ + const char *xpath = + "./set-action[action='frr-bgp-route-map:as-path-replace']"; nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); return nb_cli_apply_changes(vty, NULL); } -DEFUN_YANG (no_set_aspath_prepend_lastas, - no_set_aspath_prepend_lastas_cmd, - "no set as-path prepend last-as [(1-10)]", +DEFUN_YANG (no_set_aspath_prepend, + no_set_aspath_prepend_cmd, + "no set as-path prepend [ASNUM] [last-as [(1-10)]]", NO_STR SET_STR "Transform BGP AS_PATH attribute\n" "Prepend to the as-path\n" + AS_STR "Use the peers AS-number\n" "Number of times to insert\n") { @@ -5910,6 +6298,32 @@ DEFUN_YANG (set_aspath_exclude, return ret; } +DEFPY_YANG(set_aspath_exclude_all, set_aspath_exclude_all_cmd, + "[no$no] set as-path exclude all$all", + NO_STR SET_STR + "Transform BGP AS-path attribute\n" + "Exclude from the as-path\n" + "Exclude all AS numbers from the as-path\n") +{ + int ret; + const char *xpath = + "./set-action[action='frr-bgp-route-map:as-path-exclude']"; + char xpath_value[XPATH_MAXLEN]; + + if (no) + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); + else { + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); + snprintf(xpath_value, sizeof(xpath_value), + "%s/rmap-set-action/frr-bgp-route-map:exclude-as-path", + xpath); + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, all); + } + ret = nb_cli_apply_changes(vty, NULL); + + return ret; +} + DEFUN_YANG (no_set_aspath_exclude, no_set_aspath_exclude_cmd, "no set as-path exclude ASNUM...", @@ -5926,6 +6340,49 @@ DEFUN_YANG (no_set_aspath_exclude, return nb_cli_apply_changes(vty, NULL); } +DEFPY_YANG(set_aspath_exclude_access_list, set_aspath_exclude_access_list_cmd, + "set as-path exclude as-path-access-list AS_PATH_FILTER_NAME", + SET_STR + "Transform BGP AS-path attribute\n" + "Exclude from the as-path\n" + "Specify an as path access list name\n" + "AS path access list name\n") +{ + char *str; + const char *xpath = + "./set-action[action='frr-bgp-route-map:as-path-exclude']"; + char xpath_value[XPATH_MAXLEN]; + int ret; + + str = argv_concat(argv, argc, 3); + + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); + + snprintf(xpath_value, sizeof(xpath_value), + "%s/rmap-set-action/frr-bgp-route-map:exclude-as-path", xpath); + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, str); + + ret = nb_cli_apply_changes(vty, NULL); + XFREE(MTYPE_TMP, str); + return ret; +} + +DEFPY_YANG(no_set_aspath_exclude_access_list, no_set_aspath_exclude_access_list_cmd, + "no set as-path exclude as-path-access-list [AS_PATH_FILTER_NAME]", + NO_STR + SET_STR + "Transform BGP AS_PATH attribute\n" + "Exclude from the as-path\n" + "Specify an as path access list name\n" + "AS path access list name\n") +{ + const char *xpath = + "./set-action[action='frr-bgp-route-map:as-path-exclude']"; + + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); + return nb_cli_apply_changes(vty, NULL); +} + ALIAS_YANG (no_set_aspath_exclude, no_set_aspath_exclude_all_cmd, "no set as-path exclude", NO_STR SET_STR @@ -5972,16 +6429,6 @@ DEFUN_YANG (set_community, else first = 1; -#if CONFDATE > 20230801 -CPP_NOTICE("Deprecate COMMUNITY_INTERNET BGP community") -#endif - if (strncmp(argv[i]->arg, "internet", strlen(argv[i]->arg)) - == 0) { - buffer_putstr(b, "internet"); - vty_out(vty, "%% `internet` community is deprecated\n"); - zlog_warn("`internet` community is deprecated"); - continue; - } if (strncmp(argv[i]->arg, "local-AS", strlen(argv[i]->arg)) == 0) { buffer_putstr(b, "local-AS"); @@ -6522,6 +6969,57 @@ DEFPY_YANG (no_set_ecommunity_nt, return nb_cli_apply_changes(vty, NULL); } +DEFPY_YANG(set_ecommunity_color, set_ecommunity_color_cmd, + "set extcommunity color RTLIST...", + SET_STR + "BGP extended community attribute\n" + "Color extended community\n" + "Color ID\n") +{ + int idx_color = 3; + char *str; + int ret; + const char *xpath = + "./set-action[action='frr-bgp-route-map:set-extcommunity-color']"; + char xpath_value[XPATH_MAXLEN]; + + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); + + snprintf(xpath_value, sizeof(xpath_value), + "%s/rmap-set-action/frr-bgp-route-map:extcommunity-color", + xpath); + str = argv_concat(argv, argc, idx_color); + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, str); + ret = nb_cli_apply_changes(vty, NULL); + XFREE(MTYPE_TMP, str); + return ret; +} + +DEFPY_YANG(no_set_ecommunity_color_all, no_set_ecommunity_color_all_cmd, + "no set extcommunity color", + NO_STR SET_STR + "BGP extended community attribute\n" + "Color extended community\n") +{ + const char *xpath = + "./set-action[action='frr-bgp-route-map:set-extcommunity-color']"; + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); + return nb_cli_apply_changes(vty, NULL); +} + +DEFPY_YANG(no_set_ecommunity_color, no_set_ecommunity_color_cmd, + "no set extcommunity color RTLIST...", + NO_STR SET_STR + "BGP extended community attribute\n" + "Color extended community\n" + "Color ID\n") +{ + const char *xpath = + "./set-action[action='frr-bgp-route-map:set-extcommunity-color']"; + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); + return nb_cli_apply_changes(vty, NULL); +} + ALIAS_YANG (no_set_ecommunity_nt, no_set_ecommunity_nt_short_cmd, "no set extcommunity nt", @@ -7366,6 +7864,7 @@ void bgp_route_map_init(void) route_map_install_set(&route_set_aggregator_as_cmd); route_map_install_set(&route_set_community_cmd); route_map_install_set(&route_set_community_delete_cmd); + route_map_install_set(&route_set_ecommunity_delete_cmd); route_map_install_set(&route_set_lcommunity_cmd); route_map_install_set(&route_set_lcommunity_delete_cmd); route_map_install_set(&route_set_vpnv4_nexthop_cmd); @@ -7375,6 +7874,7 @@ void bgp_route_map_init(void) route_map_install_set(&route_set_ecommunity_nt_cmd); route_map_install_set(&route_set_ecommunity_soo_cmd); route_map_install_set(&route_set_ecommunity_lb_cmd); + route_map_install_set(&route_set_ecommunity_color_cmd); route_map_install_set(&route_set_ecommunity_none_cmd); route_map_install_set(&route_set_tag_cmd); route_map_install_set(&route_set_label_index_cmd); @@ -7436,12 +7936,16 @@ void bgp_route_map_init(void) install_element(RMAP_NODE, &set_aspath_prepend_asn_cmd); install_element(RMAP_NODE, &set_aspath_prepend_lastas_cmd); install_element(RMAP_NODE, &set_aspath_exclude_cmd); + install_element(RMAP_NODE, &set_aspath_exclude_all_cmd); + install_element(RMAP_NODE, &set_aspath_exclude_access_list_cmd); install_element(RMAP_NODE, &set_aspath_replace_asn_cmd); + install_element(RMAP_NODE, &set_aspath_replace_access_list_cmd); install_element(RMAP_NODE, &no_set_aspath_prepend_cmd); - install_element(RMAP_NODE, &no_set_aspath_prepend_lastas_cmd); install_element(RMAP_NODE, &no_set_aspath_exclude_cmd); install_element(RMAP_NODE, &no_set_aspath_exclude_all_cmd); + install_element(RMAP_NODE, &no_set_aspath_exclude_access_list_cmd); install_element(RMAP_NODE, &no_set_aspath_replace_asn_cmd); + install_element(RMAP_NODE, &no_set_aspath_replace_access_list_cmd); install_element(RMAP_NODE, &set_origin_cmd); install_element(RMAP_NODE, &no_set_origin_cmd); install_element(RMAP_NODE, &set_atomic_aggregate_cmd); @@ -7478,6 +7982,11 @@ void bgp_route_map_init(void) install_element(RMAP_NODE, &set_ecommunity_nt_cmd); install_element(RMAP_NODE, &no_set_ecommunity_nt_cmd); install_element(RMAP_NODE, &no_set_ecommunity_nt_short_cmd); + install_element(RMAP_NODE, &set_ecommunity_color_cmd); + install_element(RMAP_NODE, &no_set_ecommunity_color_cmd); + install_element(RMAP_NODE, &no_set_ecommunity_color_all_cmd); + install_element(RMAP_NODE, &set_ecommunity_delete_cmd); + install_element(RMAP_NODE, &no_set_ecommunity_delete_cmd); #ifdef KEEP_OLD_VPN_COMMANDS install_element(RMAP_NODE, &set_vpn_nexthop_cmd); install_element(RMAP_NODE, &no_set_vpn_nexthop_cmd); diff --git a/bgpd/bgp_routemap_nb.c b/bgpd/bgp_routemap_nb.c index 282ebe9116..abebfe5155 100644 --- a/bgpd/bgp_routemap_nb.c +++ b/bgpd/bgp_routemap_nb.c @@ -164,6 +164,13 @@ const struct frr_yang_module_info frr_bgp_route_map_info = { .destroy = lib_route_map_entry_match_condition_rmap_match_condition_comm_list_comm_list_name_exact_match_destroy, } }, + { + .xpath = "/frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-any", + .cbs = { + .modify = lib_route_map_entry_match_condition_rmap_match_condition_comm_list_comm_list_name_any_modify, + .destroy = lib_route_map_entry_match_condition_rmap_match_condition_comm_list_comm_list_name_any_destroy, + } + }, { .xpath = "/frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:ipv4-address", .cbs = { @@ -400,6 +407,13 @@ const struct frr_yang_module_info frr_bgp_route_map_info = { .destroy = lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_bandwidth_destroy, } }, + { + .xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:extcommunity-color", + .cbs = { + .modify = lib_route_map_entry_set_action_rmap_set_action_extcommunity_color_modify, + .destroy = lib_route_map_entry_set_action_rmap_set_action_extcommunity_color_destroy, + } + }, { .xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:extcommunity-lb/two-octet-as-specific", .cbs = { diff --git a/bgpd/bgp_routemap_nb.h b/bgpd/bgp_routemap_nb.h index 7066fdb419..28e4188026 100644 --- a/bgpd/bgp_routemap_nb.h +++ b/bgpd/bgp_routemap_nb.h @@ -65,6 +65,10 @@ int lib_route_map_entry_match_condition_rmap_match_condition_comm_list_comm_list int lib_route_map_entry_match_condition_rmap_match_condition_comm_list_comm_list_name_destroy(struct nb_cb_destroy_args *args); int lib_route_map_entry_match_condition_rmap_match_condition_comm_list_comm_list_name_exact_match_modify(struct nb_cb_modify_args *args); int lib_route_map_entry_match_condition_rmap_match_condition_comm_list_comm_list_name_exact_match_destroy(struct nb_cb_destroy_args *args); +int lib_route_map_entry_match_condition_rmap_match_condition_comm_list_comm_list_name_any_modify( + struct nb_cb_modify_args *args); +int lib_route_map_entry_match_condition_rmap_match_condition_comm_list_comm_list_name_any_destroy( + struct nb_cb_destroy_args *args); int lib_route_map_entry_match_condition_rmap_match_condition_ipv4_address_modify(struct nb_cb_modify_args *args); int lib_route_map_entry_match_condition_rmap_match_condition_ipv4_address_destroy(struct nb_cb_destroy_args *args); int lib_route_map_entry_match_condition_rmap_match_condition_ipv6_address_modify(struct nb_cb_modify_args *args); @@ -153,6 +157,10 @@ int lib_route_map_entry_set_action_rmap_set_action_evpn_gateway_ip_ipv6_modify( struct nb_cb_modify_args *args); int lib_route_map_entry_set_action_rmap_set_action_evpn_gateway_ip_ipv6_destroy( struct nb_cb_destroy_args *args); +int lib_route_map_entry_set_action_rmap_set_action_extcommunity_color_modify( + struct nb_cb_modify_args *args); +int lib_route_map_entry_set_action_rmap_set_action_extcommunity_color_destroy( + struct nb_cb_destroy_args *args); int lib_route_map_entry_set_action_rmap_set_action_l3vpn_nexthop_encapsulation_modify( struct nb_cb_modify_args *args); int lib_route_map_entry_set_action_rmap_set_action_l3vpn_nexthop_encapsulation_destroy( diff --git a/bgpd/bgp_routemap_nb_config.c b/bgpd/bgp_routemap_nb_config.c index 02564b0004..5df22b171d 100644 --- a/bgpd/bgp_routemap_nb_config.c +++ b/bgpd/bgp_routemap_nb_config.c @@ -1127,6 +1127,7 @@ lib_route_map_entry_match_condition_rmap_match_condition_comm_list_finish( struct routemap_hook_context *rhc; const char *value; bool exact_match = false; + bool any = false; char *argstr; const char *condition; route_map_event_t event; @@ -1134,18 +1135,27 @@ lib_route_map_entry_match_condition_rmap_match_condition_comm_list_finish( /* Add configuration. */ rhc = nb_running_get_entry(args->dnode, NULL, true); - value = yang_dnode_get_string(args->dnode, "./comm-list-name"); + value = yang_dnode_get_string(args->dnode, "comm-list-name"); - if (yang_dnode_exists(args->dnode, "./comm-list-name-exact-match")) + if (yang_dnode_exists(args->dnode, "comm-list-name-exact-match")) exact_match = yang_dnode_get_bool( args->dnode, "./comm-list-name-exact-match"); + if (yang_dnode_exists(args->dnode, "comm-list-name-any")) + any = yang_dnode_get_bool(args->dnode, "comm-list-name-any"); + if (exact_match) { argstr = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, strlen(value) + strlen("exact-match") + 2); snprintf(argstr, (strlen(value) + strlen("exact-match") + 2), "%s exact-match", value); + } else if (any) { + argstr = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, + strlen(value) + strlen("any") + 2); + + snprintf(argstr, (strlen(value) + strlen("any") + 2), "%s any", + value); } else argstr = (char *)value; @@ -1217,6 +1227,39 @@ lib_route_map_entry_match_condition_rmap_match_condition_comm_list_comm_list_nam } +/* + * XPath: + * /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-any + */ +int lib_route_map_entry_match_condition_rmap_match_condition_comm_list_comm_list_name_any_modify( + struct nb_cb_modify_args *args) +{ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + break; + } + + return NB_OK; +} + +int lib_route_map_entry_match_condition_rmap_match_condition_comm_list_comm_list_name_any_destroy( + struct nb_cb_destroy_args *args) +{ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + break; + case NB_EV_APPLY: + return lib_route_map_entry_match_destroy(args); + } + + return NB_OK; +} + /* * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match */ @@ -1407,7 +1450,7 @@ int lib_route_map_entry_set_action_rmap_set_action_distance_destroy( case NB_EV_ABORT: break; case NB_EV_APPLY: - return lib_route_map_entry_match_destroy(args); + return lib_route_map_entry_set_destroy(args); } return NB_OK; @@ -1461,7 +1504,7 @@ lib_route_map_entry_set_action_rmap_set_action_extcommunity_rt_destroy( case NB_EV_ABORT: break; case NB_EV_APPLY: - return lib_route_map_entry_match_destroy(args); + return lib_route_map_entry_set_destroy(args); } return NB_OK; @@ -1513,7 +1556,7 @@ int lib_route_map_entry_set_action_rmap_set_action_extcommunity_nt_destroy( case NB_EV_ABORT: break; case NB_EV_APPLY: - return lib_route_map_entry_match_destroy(args); + return lib_route_map_entry_set_destroy(args); } return NB_OK; @@ -1568,7 +1611,7 @@ lib_route_map_entry_set_action_rmap_set_action_extcommunity_soo_destroy( case NB_EV_ABORT: break; case NB_EV_APPLY: - return lib_route_map_entry_match_destroy(args); + return lib_route_map_entry_set_destroy(args); } return NB_OK; @@ -1704,7 +1747,7 @@ int lib_route_map_entry_set_action_rmap_set_action_ipv6_address_modify( || IN6_IS_ADDR_LINKLOCAL(&i6a)) return NB_ERR_VALIDATION; } - /* FALLTHROUGH */ + return NB_OK; case NB_EV_PREPARE: case NB_EV_ABORT: return NB_OK; @@ -2702,8 +2745,8 @@ void lib_route_map_entry_set_action_rmap_set_action_aggregator_finish( /* Add configuration. */ rhc = nb_running_get_entry(args->dnode, NULL, true); - asn = yang_dnode_get_string(args->dnode, "./aggregator-asn"); - addr = yang_dnode_get_string(args->dnode, "./aggregator-address"); + asn = yang_dnode_get_string(args->dnode, "aggregator-asn"); + addr = yang_dnode_get_string(args->dnode, "aggregator-address"); argstr = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, strlen(asn) + strlen(addr) + 2); @@ -2835,6 +2878,8 @@ int lib_route_map_entry_set_action_rmap_set_action_comm_list_name_modify( "../../frr-route-map:action"); if (IS_SET_COMM_LIST_DEL(action)) rhc->rhc_rule = "comm-list"; + else if (IS_SET_EXTCOMM_LIST_DEL(action)) + rhc->rhc_rule = "extended-comm-list"; else rhc->rhc_rule = "large-comm-list"; @@ -2884,7 +2929,7 @@ lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_finish( /* Add configuration. */ rhc = nb_running_get_entry(args->dnode, NULL, true); - lb_type = yang_dnode_get_enum(args->dnode, "./lb-type"); + lb_type = yang_dnode_get_enum(args->dnode, "lb-type"); /* Set destroy information. */ rhc->rhc_shook = generic_set_delete; @@ -2893,7 +2938,7 @@ lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_finish( switch (lb_type) { case EXPLICIT_BANDWIDTH: - bandwidth = yang_dnode_get_uint16(args->dnode, "./bandwidth"); + bandwidth = yang_dnode_get_uint16(args->dnode, "bandwidth"); snprintf(str, sizeof(str), "%d", bandwidth); break; case CUMULATIVE_BANDWIDTH: @@ -2903,7 +2948,7 @@ lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_finish( snprintf(str, sizeof(str), "%s", "num-multipaths"); } - if (yang_dnode_get_bool(args->dnode, "./two-octet-as-specific")) + if (yang_dnode_get_bool(args->dnode, "two-octet-as-specific")) strlcat(str, " non-transitive", sizeof(str)); ret = generic_set_add(rhc->rhc_rmi, "extcommunity bandwidth", str, @@ -2952,6 +2997,58 @@ lib_route_map_entry_set_action_rmap_set_action_extcommunity_lb_bandwidth_destroy return lib_route_map_entry_set_destroy(args); } +/* + * XPath: + * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:extcommunity-color + */ +int lib_route_map_entry_set_action_rmap_set_action_extcommunity_color_modify( + struct nb_cb_modify_args *args) +{ + struct routemap_hook_context *rhc; + const char *str; + int rv; + + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + break; + case NB_EV_APPLY: + /* Add configuration. */ + rhc = nb_running_get_entry(args->dnode, NULL, true); + str = yang_dnode_get_string(args->dnode, NULL); + + /* Set destroy information. */ + rhc->rhc_shook = generic_set_delete; + rhc->rhc_rule = "extcommunity color"; + rhc->rhc_event = RMAP_EVENT_SET_DELETED; + + rv = generic_set_add(rhc->rhc_rmi, "extcommunity color", str, + args->errmsg, args->errmsg_len); + if (rv != CMD_SUCCESS) { + rhc->rhc_shook = NULL; + return NB_ERR_INCONSISTENCY; + } + } + + return NB_OK; +} + +int lib_route_map_entry_set_action_rmap_set_action_extcommunity_color_destroy( + struct nb_cb_destroy_args *args) +{ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + break; + case NB_EV_APPLY: + return lib_route_map_entry_set_destroy(args); + } + + return NB_OK; +} + /* * XPath: * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-bgp-route-map:extcommunity-lb/two-octet-as-specific diff --git a/bgpd/bgp_rpki.c b/bgpd/bgp_rpki.c index c6e3131e02..f0b2ffdee5 100644 --- a/bgpd/bgp_rpki.c +++ b/bgpd/bgp_rpki.c @@ -520,7 +520,7 @@ static void revalidate_all_routes(void) if (!bgp->rib[afi][safi]) continue; - if (!peer_established(peer)) + if (!peer_established(peer->connection)) continue; rvp = XCALLOC(MTYPE_BGP_RPKI_REVALIDATE, diff --git a/bgpd/bgp_script.c b/bgpd/bgp_script.c index f4ab233524..b37385812e 100644 --- a/bgpd/bgp_script.c +++ b/bgpd/bgp_script.c @@ -26,15 +26,16 @@ void lua_pushpeer(lua_State *L, const struct peer *peer) lua_setfield(L, -2, "remote_id"); lua_pushinaddr(L, &peer->local_id); lua_setfield(L, -2, "local_id"); - lua_pushstring(L, lookup_msg(bgp_status_msg, peer->status, NULL)); + lua_pushstring(L, lookup_msg(bgp_status_msg, peer->connection->status, + NULL)); lua_setfield(L, -2, "state"); lua_pushstring(L, peer->desc ? peer->desc : ""); lua_setfield(L, -2, "description"); - lua_pushtimet(L, &peer->uptime); + lua_pushinteger(L, peer->uptime); lua_setfield(L, -2, "uptime"); - lua_pushtimet(L, &peer->readtime); + lua_pushinteger(L, peer->readtime); lua_setfield(L, -2, "last_readtime"); - lua_pushtimet(L, &peer->resettime); + lua_pushinteger(L, peer->resettime); lua_setfield(L, -2, "last_resettime"); lua_pushsockunion(L, peer->su_local); lua_setfield(L, -2, "local_address"); diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c index ce9442c1e0..065ea7672c 100644 --- a/bgpd/bgp_snmp.c +++ b/bgpd/bgp_snmp.c @@ -29,10 +29,93 @@ #include "bgpd/bgp_snmp_bgp4.h" #include "bgpd/bgp_snmp_bgp4v2.h" #include "bgpd/bgp_mplsvpn_snmp.h" +#include "bgpd/bgp_snmp_clippy.c" + + + +static int bgp_cli_snmp_traps_config_write(struct vty *vty); + +DEFPY(bgp_snmp_traps_rfc4273, bgp_snmp_traps_rfc4273_cmd, + "[no$no] bgp snmp traps rfc4273", + NO_STR BGP_STR + "Configure BGP SNMP\n" + "Configure SNMP traps for BGP\n" + "Configure use of rfc4273 SNMP traps for BGP\n") +{ + if (no) { + UNSET_FLAG(bm->options, BGP_OPT_TRAPS_RFC4273); + return CMD_SUCCESS; + } + SET_FLAG(bm->options, BGP_OPT_TRAPS_RFC4273); + return CMD_SUCCESS; +} + +DEFPY(bgp_snmp_traps_bgp4_mibv2, bgp_snmp_traps_bgp4_mibv2_cmd, + "[no$no] bgp snmp traps bgp4-mibv2", + NO_STR BGP_STR + "Configure BGP SNMP\n" + "Configure SNMP traps for BGP\n" + "Configure use of BGP4-MIBv2 SNMP traps for BGP\n") +{ + if (no) { + UNSET_FLAG(bm->options, BGP_OPT_TRAPS_BGP4MIBV2); + return CMD_SUCCESS; + } + SET_FLAG(bm->options, BGP_OPT_TRAPS_BGP4MIBV2); + return CMD_SUCCESS; +} + +static void bgp_snmp_traps_init(void) +{ + install_element(CONFIG_NODE, &bgp_snmp_traps_rfc4273_cmd); + install_element(CONFIG_NODE, &bgp_snmp_traps_bgp4_mibv2_cmd); + + SET_FLAG(bm->options, BGP_OPT_TRAPS_RFC4273); + /* BGP4MIBv2 traps are disabled by default */ +} + +int bgp_cli_snmp_traps_config_write(struct vty *vty) +{ + int write = 0; + + if (!CHECK_FLAG(bm->options, BGP_OPT_TRAPS_RFC4273)) { + vty_out(vty, "no bgp snmp traps rfc4273\n"); + write++; + } + if (CHECK_FLAG(bm->options, BGP_OPT_TRAPS_BGP4MIBV2)) { + vty_out(vty, "bgp snmp traps bgp4-mibv2\n"); + write++; + } + + return write; +} + +int bgpTrapEstablished(struct peer *peer) +{ + if (CHECK_FLAG(bm->options, BGP_OPT_TRAPS_RFC4273)) + bgp4TrapEstablished(peer); + + if (CHECK_FLAG(bm->options, BGP_OPT_TRAPS_BGP4MIBV2)) + bgpv2TrapEstablished(peer); + + return 0; +} + +int bgpTrapBackwardTransition(struct peer *peer) +{ + if (CHECK_FLAG(bm->options, BGP_OPT_TRAPS_RFC4273)) + bgp4TrapBackwardTransition(peer); + + if (CHECK_FLAG(bm->options, BGP_OPT_TRAPS_BGP4MIBV2)) + bgpv2TrapBackwardTransition(peer); + + return 0; +} static int bgp_snmp_init(struct event_loop *tm) { smux_init(tm); + bgp_snmp_traps_init(); bgp_snmp_bgp4_init(tm); bgp_snmp_bgp4v2_init(tm); bgp_mpls_l3vpn_module_init(); @@ -44,6 +127,8 @@ static int bgp_snmp_module_init(void) hook_register(peer_status_changed, bgpTrapEstablished); hook_register(peer_backward_transition, bgpTrapBackwardTransition); hook_register(frr_late_init, bgp_snmp_init); + hook_register(bgp_snmp_traps_config_write, + bgp_cli_snmp_traps_config_write); return 0; } diff --git a/bgpd/bgp_snmp.h b/bgpd/bgp_snmp.h index d324782ae3..12ec652f8d 100644 --- a/bgpd/bgp_snmp.h +++ b/bgpd/bgp_snmp.h @@ -15,4 +15,7 @@ #define IPADDRESS ASN_IPADDRESS #define GAUGE32 ASN_UNSIGNED +extern int bgpTrapEstablished(struct peer *peer); +extern int bgpTrapBackwardTransition(struct peer *peer); + #endif /* _FRR_BGP_SNMP_H_ */ diff --git a/bgpd/bgp_snmp_bgp4.c b/bgpd/bgp_snmp_bgp4.c index 123d33bd14..3d04dc2ece 100644 --- a/bgpd/bgp_snmp_bgp4.c +++ b/bgpd/bgp_snmp_bgp4.c @@ -83,10 +83,10 @@ static struct peer *peer_lookup_addr_ipv4(struct in_addr *src) for (ALL_LIST_ELEMENTS_RO(bm->bgp, bgpnode, bgp)) { for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) { - if (sockunion_family(&peer->su) != AF_INET) + if (sockunion_family(&peer->connection->su) != AF_INET) continue; - if (sockunion2ip(&peer->su) == src->s_addr) + if (sockunion2ip(&peer->connection->su) == src->s_addr) return peer; } } @@ -104,22 +104,22 @@ static struct peer *bgp_peer_lookup_next(struct in_addr *src) for (ALL_LIST_ELEMENTS_RO(bm->bgp, bgpnode, bgp)) { for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) { - if (sockunion_family(&peer->su) != AF_INET) + if (sockunion_family(&peer->connection->su) != AF_INET) continue; - if (ntohl(sockunion2ip(&peer->su)) <= + if (ntohl(sockunion2ip(&peer->connection->su)) <= ntohl(src->s_addr)) continue; if (!next_peer || - ntohl(sockunion2ip(&next_peer->su)) > - ntohl(sockunion2ip(&peer->su))) { + ntohl(sockunion2ip(&next_peer->connection->su)) > + ntohl(sockunion2ip(&peer->connection->su))) { next_peer = peer; } } } if (next_peer) { - src->s_addr = sockunion2ip(&next_peer->su); + src->s_addr = sockunion2ip(&next_peer->connection->su); return next_peer; } @@ -173,6 +173,7 @@ static int write_bgpPeerTable(int action, uint8_t *var_val, { struct in_addr addr; struct peer *peer; + struct peer_connection *connection; long intval; if (var_val_type != ASN_INTEGER) { @@ -190,6 +191,8 @@ static int write_bgpPeerTable(int action, uint8_t *var_val, if (!peer) return SNMP_ERR_NOSUCHNAME; + connection = peer->connection; + if (action != SNMP_MSG_INTERNAL_SET_COMMIT) return SNMP_ERR_NOERROR; @@ -202,7 +205,7 @@ static int write_bgpPeerTable(int action, uint8_t *var_val, #define BGP_PeerAdmin_start 2 /* When the peer is established, */ if (intval == BGP_PeerAdmin_stop) - BGP_EVENT_ADD(peer, BGP_Stop); + BGP_EVENT_ADD(connection, BGP_Stop); else if (intval == BGP_PeerAdmin_start) ; /* Do nothing. */ else @@ -251,7 +254,7 @@ static uint8_t *bgpPeerTable(struct variable *v, oid name[], size_t *length, case BGPPEERIDENTIFIER: return SNMP_IPADDRESS(peer->remote_id); case BGPPEERSTATE: - return SNMP_INTEGER(peer->status); + return SNMP_INTEGER(peer->connection->status); case BGPPEERADMINSTATUS: *write_method = write_bgpPeerTable; #define BGP_PeerAdmin_stop 1 @@ -398,7 +401,7 @@ static struct bgp_path_info *bgp4PathAttrLookup(struct variable *v, oid name[], /* Set OID offset for prefix. */ offset = name + v->namelen; oid2in_addr(offset, IN_ADDR_SIZE, &addr->prefix); - offset += IN_ADDR_SIZE; + offset++; /* Prefix length. */ addr->prefixlen = *offset; @@ -414,7 +417,8 @@ static struct bgp_path_info *bgp4PathAttrLookup(struct variable *v, oid name[], if (dest) { for (path = bgp_dest_get_bgp_path_info(dest); path; path = path->next) - if (sockunion_same(&path->peer->su, &su)) + if (sockunion_same(&path->peer->connection->su, + &su)) return path; bgp_dest_unlock_node(dest); @@ -464,15 +468,18 @@ static struct bgp_path_info *bgp4PathAttrLookup(struct variable *v, oid name[], for (path = bgp_dest_get_bgp_path_info(dest); path; path = path->next) { - if (path->peer->su.sin.sin_family == AF_INET && + if (path->peer->connection->su.sin.sin_family == + AF_INET && ntohl(paddr.s_addr) < - ntohl(path->peer->su.sin.sin_addr - .s_addr)) { + ntohl(path->peer->connection->su.sin + .sin_addr.s_addr)) { if (min) { - if (ntohl(path->peer->su.sin + if (ntohl(path->peer->connection + ->su.sin .sin_addr .s_addr) < - ntohl(min->peer->su.sin + ntohl(min->peer->connection + ->su.sin .sin_addr .s_addr)) min = path; @@ -490,11 +497,12 @@ static struct bgp_path_info *bgp4PathAttrLookup(struct variable *v, oid name[], offset = name + v->namelen; oid_copy_in_addr(offset, &rn_p->u.prefix4); - offset += IN_ADDR_SIZE; + offset++; *offset = rn_p->prefixlen; offset++; oid_copy_in_addr(offset, - &min->peer->su.sin.sin_addr); + &min->peer->connection->su.sin + .sin_addr); addr->prefix = rn_p->u.prefix4; addr->prefixlen = rn_p->prefixlen; @@ -532,7 +540,7 @@ static uint8_t *bgp4PathAttrTable(struct variable *v, oid name[], switch (v->magic) { case BGP4PATHATTRPEER: /* 1 */ - return SNMP_IPADDRESS(path->peer->su.sin.sin_addr); + return SNMP_IPADDRESS(path->peer->connection->su.sin.sin_addr); case BGP4PATHATTRIPADDRPREFIXLEN: /* 2 */ return SNMP_INTEGER(addr.prefixlen); case BGP4PATHATTRIPADDRPREFIX: /* 3 */ @@ -749,14 +757,16 @@ static struct variable bgp_variables[] = { {6, 1, 14}}, }; -int bgpTrapEstablished(struct peer *peer) +int bgp4TrapEstablished(struct peer *peer) { int ret; struct in_addr addr; oid index[sizeof(oid) * IN_ADDR_SIZE]; + struct peer_connection *connection = peer->connection; /* Check if this peer just went to Established */ - if ((peer->ostatus != OpenConfirm) || !(peer_established(peer))) + if ((connection->ostatus != OpenConfirm) || + !(peer_established(connection))) return 0; ret = inet_aton(peer->host, &addr); @@ -772,7 +782,7 @@ int bgpTrapEstablished(struct peer *peer) return 0; } -int bgpTrapBackwardTransition(struct peer *peer) +int bgp4TrapBackwardTransition(struct peer *peer) { int ret; struct in_addr addr; diff --git a/bgpd/bgp_snmp_bgp4.h b/bgpd/bgp_snmp_bgp4.h index ccf00d6b7c..67f7cc640b 100644 --- a/bgpd/bgp_snmp_bgp4.h +++ b/bgpd/bgp_snmp_bgp4.h @@ -69,8 +69,8 @@ #define BGP4PATHATTRBEST 13 #define BGP4PATHATTRUNKNOWN 14 -extern int bgpTrapEstablished(struct peer *peer); -extern int bgpTrapBackwardTransition(struct peer *peer); +extern int bgp4TrapEstablished(struct peer *peer); +extern int bgp4TrapBackwardTransition(struct peer *peer); extern int bgp_snmp_bgp4_init(struct event_loop *tm); #endif /* _FRR_BGP_SNMP_BGP4_H_ */ diff --git a/bgpd/bgp_snmp_bgp4v2.c b/bgpd/bgp_snmp_bgp4v2.c index 712b5d4af8..0c8ed33d43 100644 --- a/bgpd/bgp_snmp_bgp4v2.c +++ b/bgpd/bgp_snmp_bgp4v2.c @@ -32,6 +32,7 @@ SNMP_LOCAL_VARIABLES static oid bgpv2_oid[] = {BGP4V2MIB}; +static oid bgpv2_trap_oid[] = { BGP4V2MIB, 0 }; static struct in_addr bgp_empty_addr = {}; static struct peer *peer_lookup_all_vrf(struct ipaddr *addr) @@ -43,14 +44,16 @@ static struct peer *peer_lookup_all_vrf(struct ipaddr *addr) for (ALL_LIST_ELEMENTS_RO(bm->bgp, bgpnode, bgp)) { for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) { - switch (sockunion_family(&peer->su)) { + switch (sockunion_family(&peer->connection->su)) { case AF_INET: - if (IPV4_ADDR_SAME(&peer->su.sin.sin_addr, + if (IPV4_ADDR_SAME(&peer->connection->su.sin + .sin_addr, &addr->ip._v4_addr)) return peer; break; case AF_INET6: - if (IPV6_ADDR_SAME(&peer->su.sin6.sin6_addr, + if (IPV6_ADDR_SAME(&peer->connection->su.sin6 + .sin6_addr, &addr->ip._v6_addr)) return peer; break; @@ -74,38 +77,47 @@ static struct peer *peer_lookup_all_vrf_next(struct ipaddr *addr, oid *offset, for (ALL_LIST_ELEMENTS_RO(bm->bgp, bgpnode, bgp)) { for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) { - sa_family_t peer_family = sockunion_family(&peer->su); + sa_family_t peer_family = + sockunion_family(&peer->connection->su); if (peer_family != family) continue; - switch (sockunion_family(&peer->su)) { + switch (peer_family) { case AF_INET: oid2in_addr(offset, IN_ADDR_SIZE, &addr->ip._v4_addr); - if (IPV4_ADDR_CMP(&peer->su.sin.sin_addr, + if (IPV4_ADDR_CMP(&peer->connection->su.sin + .sin_addr, &addr->ip._v4_addr) < 0 || - IPV4_ADDR_SAME(&peer->su.sin.sin_addr, + IPV4_ADDR_SAME(&peer->connection->su.sin + .sin_addr, &addr->ip._v4_addr)) continue; if (!next_peer || - IPV4_ADDR_CMP(&next_peer->su.sin.sin_addr, - &peer->su.sin.sin_addr) > 0) + IPV4_ADDR_CMP(&next_peer->connection->su.sin + .sin_addr, + &peer->connection->su.sin + .sin_addr) > 0) next_peer = peer; break; case AF_INET6: oid2in6_addr(offset, &addr->ip._v6_addr); - if (IPV6_ADDR_CMP(&peer->su.sin6.sin6_addr, + if (IPV6_ADDR_CMP(&peer->connection->su.sin6 + .sin6_addr, &addr->ip._v6_addr) < 0 || - IPV6_ADDR_SAME(&peer->su.sin6.sin6_addr, + IPV6_ADDR_SAME(&peer->connection->su.sin6 + .sin6_addr, &addr->ip._v6_addr)) continue; if (!next_peer || - IPV6_ADDR_CMP(&next_peer->su.sin6.sin6_addr, - &peer->su.sin6.sin6_addr) > 0) + IPV6_ADDR_CMP(&next_peer->connection->su + .sin6.sin6_addr, + &peer->connection->su.sin6 + .sin6_addr) > 0) next_peer = peer; break; @@ -128,7 +140,7 @@ static struct peer *bgpv2PeerTable_lookup(struct variable *v, oid name[], struct peer *peer = NULL; size_t namelen = v ? v->namelen : BGP4V2_PEER_ENTRY_OFFSET; oid *offset = name + namelen; - sa_family_t family = name[namelen - 1] == 4 ? AF_INET : AF_INET6; + sa_family_t family = name[namelen - 1] == 1 ? AF_INET : AF_INET6; int afi_len = IN_ADDR_SIZE; size_t offsetlen = *length - namelen; @@ -158,13 +170,15 @@ static struct peer *bgpv2PeerTable_lookup(struct variable *v, oid name[], if (peer == NULL) return NULL; - switch (sockunion_family(&peer->su)) { + switch (sockunion_family(&peer->connection->su)) { case AF_INET: - oid_copy_in_addr(offset, &peer->su.sin.sin_addr); + oid_copy_in_addr(offset, + &peer->connection->su.sin.sin_addr); *length = afi_len + namelen; return peer; case AF_INET6: - oid_copy_in6_addr(offset, &peer->su.sin6.sin6_addr); + oid_copy_in6_addr(offset, + &peer->connection->su.sin6.sin6_addr); *length = afi_len + namelen; return peer; default: @@ -265,7 +279,7 @@ static uint8_t *bgpv2PeerTable(struct variable *v, oid name[], size_t *length, else return SNMP_INTEGER(BGP_PEER_ADMIN_STATUS_RUNNING); case BGP4V2_PEER_STATE: - return SNMP_INTEGER(peer->status); + return SNMP_INTEGER(peer->connection->status); case BGP4V2_PEER_DESCRIPTION: if (peer->desc) return SNMP_STRING(peer->desc); @@ -422,53 +436,103 @@ bgp4v2PathAttrLookup(struct variable *v, oid name[], size_t *length, struct bgp_path_info *path, *min; struct bgp_dest *dest; union sockunion su; - unsigned int len; struct ipaddr paddr = {}; size_t namelen = v ? v->namelen : BGP4V2_NLRI_ENTRY_OFFSET; - sa_family_t family = name[namelen - 1] == 4 ? AF_INET : AF_INET6; - afi_t afi = AFI_IP; - size_t afi_len = IN_ADDR_SIZE; + sa_family_t family; + sa_family_t min_family = 0; /* family of the selected min path */ + afi_t afi; + safi_t safi; + size_t afi_len; + long prefix_type = 0; + long peer_addr_type = 0; + long nrli_index = 1; + long cur_index = 0; + + /* Bgp4V2AddressFamilyIdentifierTC limited to IPv6 */ + if (name[namelen - 1] > IANA_AFI_IPV6) + return NULL; + afi = afi_iana2int(name[namelen - 1]); + afi_len = afi == AFI_IP ? IN_ADDR_SIZE : IN6_ADDR_SIZE; + assert(IS_VALID_AFI(afi)); - if (family == AF_INET6) { - afi = AFI_IP6; - afi_len = IN6_ADDR_SIZE; - } +#define BGP_NLRI_ENTRY_OFFSET namelen +#define BGP4V2_NLRI_V4_V4_OFFSET IN_ADDR_SIZE + IN_ADDR_SIZE + 5 +#define BGP4V2_NLRI_V4_V6_OFFSET IN_ADDR_SIZE + IN6_ADDR_SIZE + 5 +#define BGP4V2_NLRI_V6_V6_OFFSET IN6_ADDR_SIZE + IN6_ADDR_SIZE + 5 -#define BGP_NLRI_ENTRY_OFFSET (afi_len + 1 + afi_len) sockunion_init(&su); if (exact) { - if (*length - namelen != BGP_NLRI_ENTRY_OFFSET) + if (*length - namelen != BGP4V2_NLRI_V4_V4_OFFSET && + *length - namelen != BGP4V2_NLRI_V4_V6_OFFSET && + *length - namelen != BGP4V2_NLRI_V6_V6_OFFSET) return NULL; - /* Set OID offset for prefix */ + /* Set OID offset for prefix type */ offset = name + namelen; - if (family == AF_INET) - oid2in_addr(offset, afi_len, &addr->u.prefix4); - else + + /* Bgp4V2SubsequentAddressFamilyIdentifierTC */ + /* limited to Labeled unicast */ + if (*offset > IANA_SAFI_LABELED_UNICAST) + return NULL; + safi = safi_iana2int(*offset); + offset++; + + /* get bgp4V2NlriPrefixType */ + prefix_type = *offset; + offset++; + + /* get bgp4V2NlriPrefix */ + if (prefix_type == IANA_AFI_IPV4) { + oid2in_addr(offset, IN_ADDR_SIZE, &addr->u.prefix4); + addr->family = AF_INET; + offset += IN_ADDR_SIZE; + } else if (prefix_type == IANA_AFI_IPV6) { oid2in6_addr(offset, &addr->u.prefix6); - offset += afi_len; + addr->family = AF_INET6; + offset += IN6_ADDR_SIZE; + } - /* Prefix length */ + /* get bgp4V2NlriPrefixLen */ addr->prefixlen = *offset; - addr->family = family; + offset++; + + /* get bgp4V2PeerRemoteAddrType */ + peer_addr_type = *offset; + if (peer_addr_type == IANA_AFI_IPV4) + family = AF_INET; + else + family = AF_INET6; offset++; /* Peer address */ su.sin.sin_family = family; - if (family == AF_INET) - oid2in_addr(offset, afi_len, &su.sin.sin_addr); - else + + /* get bgp4V2PeerRemoteAddr*/ + if (family == AF_INET) { + oid2in_addr(offset, IN_ADDR_SIZE, &su.sin.sin_addr); + offset += IN_ADDR_SIZE; + } else { oid2in6_addr(offset, &su.sin6.sin6_addr); + offset += IN6_ADDR_SIZE; + } + + /* bgp4V2NlriIndex */ + nrli_index = *offset; + offset++; /* Lookup node */ - dest = bgp_node_lookup(bgp->rib[afi][SAFI_UNICAST], addr); + dest = bgp_node_lookup(bgp->rib[afi][safi], addr); if (dest) { for (path = bgp_dest_get_bgp_path_info(dest); path; path = path->next) - if (sockunion_same(&path->peer->su, &su)) - return path; + if (sockunion_same(&path->peer->connection->su, + &su)) { + cur_index++; + if (cur_index == nrli_index) + return path; + } bgp_dest_unlock_node(dest); } @@ -476,116 +540,218 @@ bgp4v2PathAttrLookup(struct variable *v, oid name[], size_t *length, return NULL; } + /* Set OID offset for prefix type */ offset = name + namelen; offsetlen = *length - namelen; - len = offsetlen; if (offsetlen == 0) { dest = bgp_table_top(bgp->rib[afi][SAFI_UNICAST]); } else { - if (len > afi_len) - len = afi_len; - if (family == AF_INET) - oid2in_addr(offset, len, &addr->u.prefix4); - else - oid2in6_addr(offset, &addr->u.prefix6); + /* bgp4V2NlriAfi is already get */ + /* it is comming from the name parameter */ + + /* get bgp4V2NlriSafi */ + /* Bgp4V2SubsequentAddressFamilyIdentifierTC */ + /* limited to Labeled unicast */ + if (*offset > IANA_SAFI_LABELED_UNICAST) + return NULL; + safi = safi_iana2int(*offset); + offset++; - offset += afi_len; - offsetlen -= afi_len; + /* get bgp4V2NlriPrefixType */ + prefix_type = *offset; + offset++; + /* get bgp4V2NlriPrefix */ + if (prefix_type == IANA_AFI_IPV4) { + oid2in_addr(offset, IN_ADDR_SIZE, &addr->u.prefix4); + addr->family = AF_INET; + offset += IN_ADDR_SIZE; + offsetlen -= IN_ADDR_SIZE; + } else if (prefix_type == IANA_AFI_IPV6) { + oid2in6_addr(offset, &addr->u.prefix6); + addr->family = AF_INET6; + offset += IN6_ADDR_SIZE; + offsetlen -= IN6_ADDR_SIZE; + } + /* get bgp4V2NlriPrefixLen */ if (offsetlen > 0) addr->prefixlen = *offset; else - addr->prefixlen = len * 8; - - addr->family = family; - - dest = bgp_node_get(bgp->rib[afi][SAFI_UNICAST], addr); + addr->prefixlen = afi_len * 8; offset++; offsetlen--; + + /* get node */ + dest = bgp_node_lookup(bgp->rib[afi][safi], addr); } - if (offsetlen > 0) { - len = offsetlen; - if (len > afi_len) - len = afi_len; + if (!dest) + return NULL; - if (family == AF_INET) - oid2in_addr(offset, len, &paddr.ip._v4_addr); + if (offsetlen > 0) { + /* get bgp4V2PeerRemoteAddrType */ + peer_addr_type = *offset; + if (peer_addr_type == IANA_AFI_IPV4) + family = AF_INET; else + family = AF_INET6; + offset++; + + if (family == AF_INET) { + oid2in_addr(offset, IN_ADDR_SIZE, &paddr.ip._v4_addr); + offset += IN_ADDR_SIZE; + } else { oid2in6_addr(offset, &paddr.ip._v6_addr); + offset += IN6_ADDR_SIZE; + } + /* get bgp4V2NlriIndex */ + nrli_index = *offset; + offset++; + } else { - if (family == AF_INET) - memset(&paddr.ip._v4_addr, 0, afi_len); + /* default case start with ipv4*/ + if (afi == AFI_IP) + family = AF_INET; else - memset(&paddr.ip._v6_addr, 0, afi_len); + family = AF_INET6; + memset(&paddr.ip, 0, sizeof(paddr.ip)); + nrli_index = 1; } - if (!dest) - return NULL; - do { min = NULL; + min_family = 0; + cur_index = 0; for (path = bgp_dest_get_bgp_path_info(dest); path; path = path->next) { sa_family_t path_family = - sockunion_family(&path->peer->su); + sockunion_family(&path->peer->connection->su); + /* the next addr must be > to the current */ + if (path_family < family) + continue; - if (path_family == AF_INET && + if (family == AF_INET && IPV4_ADDR_CMP(&paddr.ip._v4_addr, - &path->peer->su.sin.sin_addr) < 0) { - if (!min || - (min && - IPV4_ADDR_CMP( - &path->peer->su.sin.sin_addr, - &min->peer->su.sin.sin_addr) < 0)) + &path->peer->connection->su.sin + .sin_addr) > 0) + continue; + else if (family == AF_INET6 && + IPV6_ADDR_CMP(&paddr.ip._v6_addr, + &path->peer->connection->su.sin6 + .sin6_addr) > 0) + continue; + + if (family == AF_INET && + IPV4_ADDR_CMP(&paddr.ip._v4_addr, + &path->peer->connection->su.sin + .sin_addr) == 0) { + if (cur_index == nrli_index) { min = path; - } else if (path_family == AF_INET6 && - IPV6_ADDR_CMP( - &paddr.ip._v6_addr, - &path->peer->su.sin6.sin6_addr) < - 0) { - if (!min || - (min && - IPV6_ADDR_CMP( - &path->peer->su.sin6.sin6_addr, - &min->peer->su.sin6.sin6_addr) < - 0)) + min_family = family; + nrli_index++; + break; + } + cur_index++; + continue; + } else if (family == AF_INET6 && + IPV6_ADDR_CMP(&paddr.ip._v6_addr, + &path->peer->connection->su + .sin6.sin6_addr) == 0) { + if (cur_index == nrli_index) { min = path; + min_family = family; + nrli_index++; + break; + } + cur_index++; + continue; + } + + /* first valid path its the min peer addr*/ + if (!min) { + min = path; + min_family = path_family; + continue; + } + + /* consider path < min */ + if (path_family < min_family) { + min = path; + min_family = path_family; + continue; + } + + if (path_family == AF_INET + && IPV4_ADDR_CMP(&path->peer->connection->su.sin.sin_addr, + &min->peer->connection->su.sin.sin_addr) + < 0) { + min = path; + min_family = path_family; + + } else if (path_family == AF_INET6 + && IPV6_ADDR_CMP( + &path->peer->connection->su.sin6.sin6_addr, + &min->peer->connection->su.sin6.sin6_addr) + < 0) { + min = path; + min_family = path_family; } } if (min) { const struct prefix *rn_p = bgp_dest_get_prefix(dest); - *length = namelen + BGP_NLRI_ENTRY_OFFSET; - offset = name + namelen; - /* Encode prefix into OID */ - if (family == AF_INET) + /* encode bgp4V2NlriSafi*/ + *offset = SAFI_UNICAST; + offset++; + /* encode bgp4V2NlriPrefixType into index*/ + /* encode bgp4V2NlriPrefix into index */ + if (rn_p->family == AF_INET) { + *offset = IANA_AFI_IPV4; + offset++; oid_copy_in_addr(offset, &rn_p->u.prefix4); - else + offset += IN_ADDR_SIZE; + } else { + *offset = IANA_AFI_IPV6; + offset++; oid_copy_in6_addr(offset, &rn_p->u.prefix6); - - offset += afi_len; + offset += IN6_ADDR_SIZE; + } + /* encode bgp4V2NlriPrefixLen into index*/ *offset = rn_p->prefixlen; offset++; - /* Encode peer's IP into OID */ - if (family == AF_INET) { + /* Encode bgp4V2PeerRemoteAddrType */ + /* Encode bgp4V2PeerRemoteAddr */ + if (min_family == AF_INET) { + *offset = IANA_AFI_IPV4; + offset++; oid_copy_in_addr(offset, - &min->peer->su.sin.sin_addr); + &min->peer->connection->su.sin.sin_addr); + offset += IN_ADDR_SIZE; addr->u.prefix4 = rn_p->u.prefix4; } else { + *offset = IANA_AFI_IPV6; + offset++; oid_copy_in6_addr( - offset, &min->peer->su.sin6.sin6_addr); + offset, &min->peer->connection->su.sin6.sin6_addr); + offset += IN6_ADDR_SIZE; addr->u.prefix6 = rn_p->u.prefix6; } + /* Encode bgp4V2NlriIndex*/ + + *offset = nrli_index; + offset++; + + *length = offset - name; + addr->prefixlen = rn_p->prefixlen; addr->family = rn_p->family; @@ -594,10 +760,9 @@ bgp4v2PathAttrLookup(struct variable *v, oid name[], size_t *length, return min; } - if (family == AF_INET) - memset(&paddr.ip._v4_addr, 0, afi_len); - else - memset(&paddr.ip._v6_addr, 0, afi_len); + memset(&paddr.ip, 0, sizeof(paddr.ip)); + nrli_index = 1; + } while ((dest = bgp_route_next(dest))); return NULL; @@ -775,6 +940,37 @@ static uint8_t *bgp4v2PathAttrTable(struct variable *v, oid name[], return NULL; } +/* BGP V2 Traps. */ +static struct trap_object bgpv2TrapEstListv4[] = { + { 6, { 1, 2, 1, BGP4V2_PEER_STATE, 1, 1 } }, + { 6, { 1, 2, 1, BGP4V2_PEER_LOCAL_PORT, 1, 1 } }, + { 6, { 1, 2, 1, BGP4V2_PEER_REMOTE_PORT, 1, 1 } } +}; + +static struct trap_object bgpv2TrapEstListv6[] = { + { 6, { 1, 2, 1, BGP4V2_PEER_STATE, 1, 2 } }, + { 6, { 1, 2, 1, BGP4V2_PEER_LOCAL_PORT, 1, 2 } }, + { 6, { 1, 2, 1, BGP4V2_PEER_REMOTE_PORT, 1, 2 } } +}; + +static struct trap_object bgpv2TrapBackListv4[] = { + { 6, { 1, 2, 1, BGP4V2_PEER_STATE, 1, 1 } }, + { 6, { 1, 2, 1, BGP4V2_PEER_LOCAL_PORT, 1, 1 } }, + { 6, { 1, 2, 1, BGP4V2_PEER_REMOTE_PORT, 1, 1 } }, + { 6, { 1, 3, 1, BGP4V2_PEER_LAST_ERROR_CODE_RECEIVED, 1, 1 } }, + { 6, { 1, 3, 1, BGP4V2_PEER_LAST_ERROR_SUBCODE_RECEIVED, 1, 1 } }, + { 6, { 1, 3, 1, BGP4V2_PEER_LAST_ERROR_RECEIVED_TEXT, 1, 1 } } +}; + +static struct trap_object bgpv2TrapBackListv6[] = { + { 6, { 1, 2, 1, BGP4V2_PEER_STATE, 1, 2 } }, + { 6, { 1, 2, 1, BGP4V2_PEER_LOCAL_PORT, 1, 2 } }, + { 6, { 1, 2, 1, BGP4V2_PEER_REMOTE_PORT, 1, 2 } }, + { 6, { 1, 3, 1, BGP4V2_PEER_LAST_ERROR_CODE_RECEIVED, 1, 2 } }, + { 6, { 1, 3, 1, BGP4V2_PEER_LAST_ERROR_SUBCODE_RECEIVED, 1, 2 } }, + { 6, { 1, 3, 1, BGP4V2_PEER_LAST_ERROR_RECEIVED_TEXT, 1, 2 } } +}; + static struct variable bgpv2_variables[] = { /* bgp4V2PeerEntry */ {BGP4V2_PEER_INSTANCE, @@ -782,618 +978,691 @@ static struct variable bgpv2_variables[] = { RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_INSTANCE, 1, 4}}, + {1, 2, 1, BGP4V2_PEER_INSTANCE, 1, 1}}, {BGP4V2_PEER_INSTANCE, ASN_UNSIGNED, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_INSTANCE, 2, 16}}, + {1, 2, 1, BGP4V2_PEER_INSTANCE, 1, 2}}, {BGP4V2_PEER_LOCAL_ADDR_TYPE, ASN_INTEGER, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_LOCAL_ADDR_TYPE, 1, 4}}, + {1, 2, 1, BGP4V2_PEER_LOCAL_ADDR_TYPE, 1, 1}}, {BGP4V2_PEER_LOCAL_ADDR_TYPE, ASN_INTEGER, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_LOCAL_ADDR_TYPE, 2, 16}}, + {1, 2, 1, BGP4V2_PEER_LOCAL_ADDR_TYPE, 1, 2}}, {BGP4V2_PEER_LOCAL_ADDR, ASN_OCTET_STR, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_LOCAL_ADDR, 1, 4}}, + {1, 2, 1, BGP4V2_PEER_LOCAL_ADDR, 1, 1}}, {BGP4V2_PEER_LOCAL_ADDR, ASN_OCTET_STR, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_LOCAL_ADDR, 2, 16}}, + {1, 2, 1, BGP4V2_PEER_LOCAL_ADDR, 1, 2}}, {BGP4V2_PEER_REMOTE_ADDR_TYPE, ASN_INTEGER, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_REMOTE_ADDR_TYPE, 1, 4}}, + {1, 2, 1, BGP4V2_PEER_REMOTE_ADDR_TYPE, 1, 1}}, {BGP4V2_PEER_REMOTE_ADDR_TYPE, ASN_INTEGER, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_REMOTE_ADDR_TYPE, 2, 16}}, + {1, 2, 1, BGP4V2_PEER_REMOTE_ADDR_TYPE, 1, 2}}, {BGP4V2_PEER_REMOTE_ADDR, ASN_OCTET_STR, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_REMOTE_ADDR, 1, 4}}, + {1, 2, 1, BGP4V2_PEER_REMOTE_ADDR, 1, 1}}, {BGP4V2_PEER_REMOTE_ADDR, ASN_OCTET_STR, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_REMOTE_ADDR, 2, 16}}, + {1, 2, 1, BGP4V2_PEER_REMOTE_ADDR, 1, 2}}, {BGP4V2_PEER_LOCAL_PORT, ASN_UNSIGNED, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_LOCAL_PORT, 1, 4}}, + {1, 2, 1, BGP4V2_PEER_LOCAL_PORT, 1, 1}}, {BGP4V2_PEER_LOCAL_PORT, ASN_UNSIGNED, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_LOCAL_PORT, 2, 16}}, + {1, 2, 1, BGP4V2_PEER_LOCAL_PORT, 1, 2}}, {BGP4V2_PEER_LOCAL_AS, ASN_UNSIGNED, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_LOCAL_AS, 1, 4}}, + {1, 2, 1, BGP4V2_PEER_LOCAL_AS, 1, 1}}, {BGP4V2_PEER_LOCAL_AS, ASN_UNSIGNED, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_LOCAL_AS, 2, 16}}, + {1, 2, 1, BGP4V2_PEER_LOCAL_AS, 1, 2}}, {BGP4V2_PEER_LOCAL_IDENTIFIER, ASN_OCTET_STR, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_LOCAL_IDENTIFIER, 1, 4}}, + {1, 2, 1, BGP4V2_PEER_LOCAL_IDENTIFIER, 1, 1}}, {BGP4V2_PEER_LOCAL_IDENTIFIER, ASN_OCTET_STR, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_LOCAL_IDENTIFIER, 2, 16}}, + {1, 2, 1, BGP4V2_PEER_LOCAL_IDENTIFIER, 1, 2}}, {BGP4V2_PEER_REMOTE_PORT, ASN_UNSIGNED, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_REMOTE_PORT, 1, 4}}, + {1, 2, 1, BGP4V2_PEER_REMOTE_PORT, 1, 1}}, {BGP4V2_PEER_REMOTE_PORT, ASN_UNSIGNED, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_REMOTE_PORT, 2, 16}}, + {1, 2, 1, BGP4V2_PEER_REMOTE_PORT, 1, 2}}, {BGP4V2_PEER_REMOTE_AS, ASN_UNSIGNED, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_REMOTE_AS, 1, 4}}, + {1, 2, 1, BGP4V2_PEER_REMOTE_AS, 1, 1}}, {BGP4V2_PEER_REMOTE_AS, ASN_UNSIGNED, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_REMOTE_AS, 2, 16}}, + {1, 2, 1, BGP4V2_PEER_REMOTE_AS, 1, 2}}, {BGP4V2_PEER_REMOTE_IDENTIFIER, ASN_OCTET_STR, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_REMOTE_IDENTIFIER, 1, 4}}, + {1, 2, 1, BGP4V2_PEER_REMOTE_IDENTIFIER, 1, 1}}, {BGP4V2_PEER_REMOTE_IDENTIFIER, ASN_OCTET_STR, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_REMOTE_IDENTIFIER, 2, 16}}, + {1, 2, 1, BGP4V2_PEER_REMOTE_IDENTIFIER, 1, 2}}, {BGP4V2_PEER_ADMIN_STATUS, ASN_INTEGER, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_ADMIN_STATUS, 1, 4}}, + {1, 2, 1, BGP4V2_PEER_ADMIN_STATUS, 1, 1}}, {BGP4V2_PEER_ADMIN_STATUS, ASN_INTEGER, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_ADMIN_STATUS, 2, 16}}, + {1, 2, 1, BGP4V2_PEER_ADMIN_STATUS, 1, 2}}, {BGP4V2_PEER_STATE, ASN_INTEGER, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_STATE, 1, 4}}, + {1, 2, 1, BGP4V2_PEER_STATE, 1, 1}}, {BGP4V2_PEER_STATE, ASN_INTEGER, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_STATE, 2, 16}}, + {1, 2, 1, BGP4V2_PEER_STATE, 1, 2}}, {BGP4V2_PEER_DESCRIPTION, ASN_OCTET_STR, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_DESCRIPTION, 1, 4}}, + {1, 2, 1, BGP4V2_PEER_DESCRIPTION, 1, 1}}, {BGP4V2_PEER_DESCRIPTION, ASN_OCTET_STR, RONLY, bgpv2PeerTable, 6, - {1, 2, 1, BGP4V2_PEER_DESCRIPTION, 2, 16}}, + {1, 2, 1, BGP4V2_PEER_DESCRIPTION, 1, 2}}, /* bgp4V2PeerErrorsEntry */ {BGP4V2_PEER_LAST_ERROR_CODE_RECEIVED, ASN_UNSIGNED, RONLY, bgpv2PeerErrorsTable, 6, - {1, 3, 1, BGP4V2_PEER_LAST_ERROR_CODE_RECEIVED, 1, 4}}, + {1, 3, 1, BGP4V2_PEER_LAST_ERROR_CODE_RECEIVED, 1, 1}}, {BGP4V2_PEER_LAST_ERROR_CODE_RECEIVED, ASN_UNSIGNED, RONLY, bgpv2PeerErrorsTable, 6, - {1, 3, 1, BGP4V2_PEER_LAST_ERROR_CODE_RECEIVED, 2, 16}}, + {1, 3, 1, BGP4V2_PEER_LAST_ERROR_CODE_RECEIVED, 1, 2}}, {BGP4V2_PEER_LAST_ERROR_SUBCODE_RECEIVED, ASN_UNSIGNED, RONLY, bgpv2PeerErrorsTable, 6, - {1, 3, 1, BGP4V2_PEER_LAST_ERROR_SUBCODE_RECEIVED, 1, 4}}, + {1, 3, 1, BGP4V2_PEER_LAST_ERROR_SUBCODE_RECEIVED, 1, 1}}, {BGP4V2_PEER_LAST_ERROR_SUBCODE_RECEIVED, ASN_UNSIGNED, RONLY, bgpv2PeerErrorsTable, 6, - {1, 3, 1, BGP4V2_PEER_LAST_ERROR_SUBCODE_RECEIVED, 2, 16}}, + {1, 3, 1, BGP4V2_PEER_LAST_ERROR_SUBCODE_RECEIVED, 1, 2}}, {BGP4V2_PEER_LAST_ERROR_RECEIVED_TIME, - ASN_UNSIGNED, + ASN_TIMETICKS, RONLY, bgpv2PeerErrorsTable, 6, - {1, 3, 1, BGP4V2_PEER_LAST_ERROR_RECEIVED_TIME, 1, 4}}, + {1, 3, 1, BGP4V2_PEER_LAST_ERROR_RECEIVED_TIME, 1, 1}}, {BGP4V2_PEER_LAST_ERROR_RECEIVED_TIME, - ASN_UNSIGNED, + ASN_TIMETICKS, RONLY, bgpv2PeerErrorsTable, 6, - {1, 3, 1, BGP4V2_PEER_LAST_ERROR_RECEIVED_TIME, 2, 16}}, + {1, 3, 1, BGP4V2_PEER_LAST_ERROR_RECEIVED_TIME, 1, 2}}, {BGP4V2_PEER_LAST_ERROR_RECEIVED_TEXT, ASN_OCTET_STR, RONLY, bgpv2PeerErrorsTable, 6, - {1, 3, 1, BGP4V2_PEER_LAST_ERROR_RECEIVED_TEXT, 1, 4}}, + {1, 3, 1, BGP4V2_PEER_LAST_ERROR_RECEIVED_TEXT, 1, 1}}, {BGP4V2_PEER_LAST_ERROR_RECEIVED_TEXT, ASN_OCTET_STR, RONLY, bgpv2PeerErrorsTable, 6, - {1, 3, 1, BGP4V2_PEER_LAST_ERROR_RECEIVED_TEXT, 2, 16}}, + {1, 3, 1, BGP4V2_PEER_LAST_ERROR_RECEIVED_TEXT, 1, 2}}, {BGP4V2_PEER_LAST_ERROR_RECEIVED_DATA, ASN_OCTET_STR, RONLY, bgpv2PeerErrorsTable, 6, - {1, 3, 1, BGP4V2_PEER_LAST_ERROR_RECEIVED_DATA, 1, 4}}, + {1, 3, 1, BGP4V2_PEER_LAST_ERROR_RECEIVED_DATA, 1, 1}}, {BGP4V2_PEER_LAST_ERROR_RECEIVED_DATA, ASN_OCTET_STR, RONLY, bgpv2PeerErrorsTable, 6, - {1, 3, 1, BGP4V2_PEER_LAST_ERROR_RECEIVED_DATA, 2, 16}}, + {1, 3, 1, BGP4V2_PEER_LAST_ERROR_RECEIVED_DATA, 1, 2}}, {BGP4V2_PEER_LAST_ERROR_CODE_SENT, ASN_UNSIGNED, RONLY, bgpv2PeerErrorsTable, 6, - {1, 3, 1, BGP4V2_PEER_LAST_ERROR_CODE_SENT, 1, 4}}, + {1, 3, 1, BGP4V2_PEER_LAST_ERROR_CODE_SENT, 1, 1}}, {BGP4V2_PEER_LAST_ERROR_CODE_SENT, ASN_UNSIGNED, RONLY, bgpv2PeerErrorsTable, 6, - {1, 3, 1, BGP4V2_PEER_LAST_ERROR_CODE_SENT, 2, 16}}, + {1, 3, 1, BGP4V2_PEER_LAST_ERROR_CODE_SENT, 1, 2}}, {BGP4V2_PEER_LAST_ERROR_SUBCODE_SENT, ASN_UNSIGNED, RONLY, bgpv2PeerErrorsTable, 6, - {1, 3, 1, BGP4V2_PEER_LAST_ERROR_SUBCODE_SENT, 1, 4}}, + {1, 3, 1, BGP4V2_PEER_LAST_ERROR_SUBCODE_SENT, 1, 1}}, {BGP4V2_PEER_LAST_ERROR_SUBCODE_SENT, ASN_UNSIGNED, RONLY, bgpv2PeerErrorsTable, 6, - {1, 3, 1, BGP4V2_PEER_LAST_ERROR_SUBCODE_SENT, 2, 16}}, + {1, 3, 1, BGP4V2_PEER_LAST_ERROR_SUBCODE_SENT, 1, 2}}, {BGP4V2_PEER_LAST_ERROR_SENT_TIME, - ASN_UNSIGNED, + ASN_TIMETICKS, RONLY, bgpv2PeerErrorsTable, 6, - {1, 3, 1, BGP4V2_PEER_LAST_ERROR_SENT_TIME, 1, 4}}, + {1, 3, 1, BGP4V2_PEER_LAST_ERROR_SENT_TIME, 1, 1}}, {BGP4V2_PEER_LAST_ERROR_SENT_TIME, - ASN_UNSIGNED, + ASN_TIMETICKS, RONLY, bgpv2PeerErrorsTable, 6, - {1, 3, 1, BGP4V2_PEER_LAST_ERROR_SENT_TIME, 2, 16}}, + {1, 3, 1, BGP4V2_PEER_LAST_ERROR_SENT_TIME, 1, 2}}, {BGP4V2_PEER_LAST_ERROR_SENT_TEXT, ASN_OCTET_STR, RONLY, bgpv2PeerErrorsTable, 6, - {1, 3, 1, BGP4V2_PEER_LAST_ERROR_SENT_TEXT, 1, 4}}, + {1, 3, 1, BGP4V2_PEER_LAST_ERROR_SENT_TEXT, 1, 1}}, {BGP4V2_PEER_LAST_ERROR_SENT_TEXT, ASN_OCTET_STR, RONLY, bgpv2PeerErrorsTable, 6, - {1, 3, 1, BGP4V2_PEER_LAST_ERROR_SENT_TEXT, 2, 16}}, + {1, 3, 1, BGP4V2_PEER_LAST_ERROR_SENT_TEXT, 1, 2}}, {BGP4V2_PEER_LAST_ERROR_SENT_DATA, ASN_OCTET_STR, RONLY, bgpv2PeerErrorsTable, 6, - {1, 3, 1, BGP4V2_PEER_LAST_ERROR_SENT_DATA, 1, 4}}, + {1, 3, 1, BGP4V2_PEER_LAST_ERROR_SENT_DATA, 1, 1}}, {BGP4V2_PEER_LAST_ERROR_SENT_DATA, ASN_OCTET_STR, RONLY, bgpv2PeerErrorsTable, 6, - {1, 3, 1, BGP4V2_PEER_LAST_ERROR_SENT_DATA, 2, 16}}, + {1, 3, 1, BGP4V2_PEER_LAST_ERROR_SENT_DATA, 1, 2}}, /* bgp4V2PeerEventTimesEntry */ {BGP4V2_PEER_FSM_ESTABLISHED_TIME, ASN_UNSIGNED, RONLY, bgpv2PeerEventTimesTable, 6, - {1, 4, 1, BGP4V2_PEER_FSM_ESTABLISHED_TIME, 1, 4}}, + {1, 4, 1, BGP4V2_PEER_FSM_ESTABLISHED_TIME, 1, 1}}, {BGP4V2_PEER_FSM_ESTABLISHED_TIME, ASN_UNSIGNED, RONLY, bgpv2PeerEventTimesTable, 6, - {1, 4, 1, BGP4V2_PEER_FSM_ESTABLISHED_TIME, 2, 16}}, + {1, 4, 1, BGP4V2_PEER_FSM_ESTABLISHED_TIME, 1, 2}}, {BGP4V2_PEER_PEER_IN_UPDATES_ELAPSED_TIME, ASN_UNSIGNED, RONLY, bgpv2PeerEventTimesTable, 6, - {1, 4, 1, BGP4V2_PEER_PEER_IN_UPDATES_ELAPSED_TIME, 1, 4}}, + {1, 4, 1, BGP4V2_PEER_PEER_IN_UPDATES_ELAPSED_TIME, 1, 1}}, {BGP4V2_PEER_PEER_IN_UPDATES_ELAPSED_TIME, ASN_UNSIGNED, RONLY, bgpv2PeerEventTimesTable, 6, - {1, 4, 1, BGP4V2_PEER_PEER_IN_UPDATES_ELAPSED_TIME, 2, 16}}, + {1, 4, 1, BGP4V2_PEER_PEER_IN_UPDATES_ELAPSED_TIME, 1, 2}}, /* bgp4V2NlriTable */ {BGP4V2_NLRI_INDEX, ASN_UNSIGNED, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_INDEX, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_INDEX, 1, 1}}, {BGP4V2_NLRI_INDEX, ASN_UNSIGNED, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_INDEX, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_INDEX, 1, 2}}, {BGP4V2_NLRI_AFI, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_AFI, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_AFI, 1, 1}}, {BGP4V2_NLRI_AFI, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_AFI, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_AFI, 1, 2}}, {BGP4V2_NLRI_SAFI, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_SAFI, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_SAFI, 1, 1}}, {BGP4V2_NLRI_SAFI, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_SAFI, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_SAFI, 1, 2}}, {BGP4V2_NLRI_PREFIX_TYPE, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_PREFIX_TYPE, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_PREFIX_TYPE, 1, 1}}, {BGP4V2_NLRI_PREFIX_TYPE, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_PREFIX_TYPE, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_PREFIX_TYPE, 1, 2}}, {BGP4V2_NLRI_PREFIX, ASN_OCTET_STR, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_PREFIX, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_PREFIX, 1, 1}}, {BGP4V2_NLRI_PREFIX, ASN_OCTET_STR, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_PREFIX, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_PREFIX, 1, 2}}, {BGP4V2_NLRI_PREFIX_LEN, ASN_UNSIGNED, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_PREFIX_LEN, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_PREFIX_LEN, 1, 1}}, {BGP4V2_NLRI_PREFIX_LEN, ASN_UNSIGNED, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_PREFIX_LEN, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_PREFIX_LEN, 1, 2}}, {BGP4V2_NLRI_BEST, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_BEST, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_BEST, 1, 1}}, {BGP4V2_NLRI_BEST, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_BEST, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_BEST, 1, 2}}, {BGP4V2_NLRI_CALC_LOCAL_PREF, ASN_UNSIGNED, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_CALC_LOCAL_PREF, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_CALC_LOCAL_PREF, 1, 1}}, {BGP4V2_NLRI_CALC_LOCAL_PREF, ASN_UNSIGNED, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_CALC_LOCAL_PREF, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_CALC_LOCAL_PREF, 1, 2}}, {BGP4V2_NLRI_ORIGIN, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_ORIGIN, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_ORIGIN, 1, 1}}, {BGP4V2_NLRI_ORIGIN, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_ORIGIN, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_ORIGIN, 1, 2}}, {BGP4V2_NLRI_NEXT_HOP_ADDR_TYPE, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_NEXT_HOP_ADDR_TYPE, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_NEXT_HOP_ADDR_TYPE, 1, 1}}, {BGP4V2_NLRI_NEXT_HOP_ADDR_TYPE, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_NEXT_HOP_ADDR_TYPE, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_NEXT_HOP_ADDR_TYPE, 1, 2}}, {BGP4V2_NLRI_NEXT_HOP_ADDR, ASN_OCTET_STR, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_NEXT_HOP_ADDR, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_NEXT_HOP_ADDR, 1, 1}}, {BGP4V2_NLRI_NEXT_HOP_ADDR, ASN_OCTET_STR, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_NEXT_HOP_ADDR, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_NEXT_HOP_ADDR, 1, 2}}, {BGP4V2_NLRI_LINK_LOCAL_NEXT_HOP_ADDR_TYPE, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_LINK_LOCAL_NEXT_HOP_ADDR_TYPE, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_LINK_LOCAL_NEXT_HOP_ADDR_TYPE, 1, 1}}, {BGP4V2_NLRI_LINK_LOCAL_NEXT_HOP_ADDR_TYPE, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_LINK_LOCAL_NEXT_HOP_ADDR_TYPE, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_LINK_LOCAL_NEXT_HOP_ADDR_TYPE, 1, 2}}, {BGP4V2_NLRI_LINK_LOCAL_NEXT_HOP_ADDR, ASN_OCTET_STR, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_LINK_LOCAL_NEXT_HOP_ADDR, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_LINK_LOCAL_NEXT_HOP_ADDR, 1, 1}}, {BGP4V2_NLRI_LINK_LOCAL_NEXT_HOP_ADDR, ASN_OCTET_STR, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_LINK_LOCAL_NEXT_HOP_ADDR, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_LINK_LOCAL_NEXT_HOP_ADDR, 1, 2}}, {BGP4V2_NLRI_LOCAL_PREF_PRESENT, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_LOCAL_PREF_PRESENT, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_LOCAL_PREF_PRESENT, 1, 1}}, {BGP4V2_NLRI_LOCAL_PREF_PRESENT, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_LOCAL_PREF_PRESENT, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_LOCAL_PREF_PRESENT, 1, 2}}, {BGP4V2_NLRI_LOCAL_PREF, ASN_UNSIGNED, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_LOCAL_PREF, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_LOCAL_PREF, 1, 1}}, {BGP4V2_NLRI_LOCAL_PREF, ASN_UNSIGNED, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_LOCAL_PREF, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_LOCAL_PREF, 1, 2}}, {BGP4V2_NLRI_MED_PRESENT, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_MED_PRESENT, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_MED_PRESENT, 1, 1}}, {BGP4V2_NLRI_MED_PRESENT, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_MED_PRESENT, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_MED_PRESENT, 1, 2}}, {BGP4V2_NLRI_MED, ASN_UNSIGNED, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_MED, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_MED, 1, 1}}, {BGP4V2_NLRI_MED, ASN_UNSIGNED, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_MED, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_MED, 1, 2}}, {BGP4V2_NLRI_ATOMIC_AGGREGATE, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_ATOMIC_AGGREGATE, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_ATOMIC_AGGREGATE, 1, 1}}, {BGP4V2_NLRI_ATOMIC_AGGREGATE, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_ATOMIC_AGGREGATE, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_ATOMIC_AGGREGATE, 1, 2}}, {BGP4V2_NLRI_AGGREGATOR_PRESENT, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_AGGREGATOR_PRESENT, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_AGGREGATOR_PRESENT, 1, 1}}, {BGP4V2_NLRI_AGGREGATOR_PRESENT, ASN_INTEGER, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_AGGREGATOR_PRESENT, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_AGGREGATOR_PRESENT, 1, 2}}, {BGP4V2_NLRI_AGGREGATOR_AS, ASN_UNSIGNED, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_AGGREGATOR_AS, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_AGGREGATOR_AS, 1, 1}}, {BGP4V2_NLRI_AGGREGATOR_AS, ASN_UNSIGNED, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_AGGREGATOR_AS, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_AGGREGATOR_AS, 1, 2}}, {BGP4V2_NLRI_AGGREGATOR_ADDR, ASN_OCTET_STR, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_AGGREGATOR_ADDR, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_AGGREGATOR_ADDR, 1, 1}}, {BGP4V2_NLRI_AGGREGATOR_ADDR, ASN_OCTET_STR, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_AGGREGATOR_ADDR, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_AGGREGATOR_ADDR, 1, 2}}, {BGP4V2_NLRI_AS_PATH_CALC_LENGTH, ASN_UNSIGNED, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_AS_PATH_CALC_LENGTH, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_AS_PATH_CALC_LENGTH, 1, 1}}, {BGP4V2_NLRI_AS_PATH_CALC_LENGTH, ASN_UNSIGNED, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_AS_PATH_CALC_LENGTH, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_AS_PATH_CALC_LENGTH, 1, 2}}, {BGP4V2_NLRI_AS_PATH_STRING, ASN_OCTET_STR, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_AS_PATH_STRING, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_AS_PATH_STRING, 1, 1}}, {BGP4V2_NLRI_AS_PATH_STRING, ASN_OCTET_STR, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_AS_PATH_STRING, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_AS_PATH_STRING, 1, 2}}, {BGP4V2_NLRI_AS_PATH, ASN_OCTET_STR, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_AS_PATH, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_AS_PATH, 1, 1}}, {BGP4V2_NLRI_AS_PATH, ASN_OCTET_STR, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_AS_PATH, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_AS_PATH, 1, 2}}, {BGP4V2_NLRI_PATH_ATTR_UNKNOWN, ASN_OCTET_STR, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_PATH_ATTR_UNKNOWN, 1, 4}}, + {1, 9, 1, BGP4V2_NLRI_PATH_ATTR_UNKNOWN, 1, 1}}, {BGP4V2_NLRI_PATH_ATTR_UNKNOWN, ASN_OCTET_STR, RONLY, bgp4v2PathAttrTable, 6, - {1, 9, 1, BGP4V2_NLRI_PATH_ATTR_UNKNOWN, 2, 16}}, + {1, 9, 1, BGP4V2_NLRI_PATH_ATTR_UNKNOWN, 1, 2}}, }; +int bgpv2TrapEstablished(struct peer *peer) +{ + oid index[sizeof(oid) * IN6_ADDR_SIZE]; + size_t length; + + if (!CHECK_FLAG(bm->options, BGP_OPT_TRAPS_BGP4MIBV2)) + return 0; + + /* Check if this peer just went to Established */ + if ((peer->connection->ostatus != OpenConfirm) || + !(peer_established(peer->connection))) + return 0; + + switch (sockunion_family(&peer->connection->su)) { + case AF_INET: + oid_copy_in_addr(index, &peer->connection->su.sin.sin_addr); + length = IN_ADDR_SIZE; + smux_trap(bgpv2_variables, array_size(bgpv2_variables), + bgpv2_trap_oid, array_size(bgpv2_trap_oid), bgpv2_oid, + sizeof(bgpv2_oid) / sizeof(oid), index, length, + bgpv2TrapEstListv4, array_size(bgpv2TrapEstListv4), + BGP4V2ESTABLISHED); + break; + case AF_INET6: + oid_copy_in6_addr(index, &peer->connection->su.sin6.sin6_addr); + length = IN6_ADDR_SIZE; + smux_trap(bgpv2_variables, array_size(bgpv2_variables), + bgpv2_trap_oid, array_size(bgpv2_trap_oid), bgpv2_oid, + sizeof(bgpv2_oid) / sizeof(oid), index, length, + bgpv2TrapEstListv6, array_size(bgpv2TrapEstListv6), + BGP4V2ESTABLISHED); + break; + default: + break; + } + + return 0; +} + +int bgpv2TrapBackwardTransition(struct peer *peer) +{ + oid index[sizeof(oid) * IN6_ADDR_SIZE]; + size_t length; + + if (!CHECK_FLAG(bm->options, BGP_OPT_TRAPS_BGP4MIBV2)) + return 0; + + switch (sockunion_family(&peer->connection->su)) { + case AF_INET: + oid_copy_in_addr(index, &peer->connection->su.sin.sin_addr); + length = IN_ADDR_SIZE; + smux_trap(bgpv2_variables, array_size(bgpv2_variables), + bgpv2_trap_oid, array_size(bgpv2_trap_oid), bgpv2_oid, + sizeof(bgpv2_oid) / sizeof(oid), index, length, + bgpv2TrapBackListv4, array_size(bgpv2TrapBackListv4), + BGP4V2BACKWARDTRANSITION); + break; + case AF_INET6: + oid_copy_in6_addr(index, &peer->connection->su.sin6.sin6_addr); + length = IN6_ADDR_SIZE; + smux_trap(bgpv2_variables, array_size(bgpv2_variables), + bgpv2_trap_oid, array_size(bgpv2_trap_oid), bgpv2_oid, + sizeof(bgpv2_oid) / sizeof(oid), index, length, + bgpv2TrapBackListv6, array_size(bgpv2TrapBackListv6), + BGP4V2BACKWARDTRANSITION); + break; + default: + break; + } + + return 0; +} + int bgp_snmp_bgp4v2_init(struct event_loop *tm) { REGISTER_MIB("mibII/bgpv2", bgpv2_variables, variable, bgpv2_oid); diff --git a/bgpd/bgp_snmp_bgp4v2.h b/bgpd/bgp_snmp_bgp4v2.h index 7cdad586bc..ca355338a6 100644 --- a/bgpd/bgp_snmp_bgp4v2.h +++ b/bgpd/bgp_snmp_bgp4v2.h @@ -14,7 +14,16 @@ /* bgp4V2PeerEntry: * offset 1.3.6.1.3.5.1.1.2.1.x.(1|2).(4|16) = 13 + * offset 1.3.6.1.4.1.7336.3.2.1.1.2.1.x.1.(1|2) = 16 */ + + +/* bgpTraps */ +#define BGP4V2ESTABLISHED 1 +#define BGP4V2BACKWARDTRANSITION 2 + +/* bgpPeerTable */ + #define BGP4V2_PEER_ENTRY_OFFSET 13 #define BGP4V2_PEER_INSTANCE 1 #define BGP4V2_PEER_LOCAL_ADDR_TYPE 2 @@ -49,6 +58,7 @@ /* bgp4V2NlriEntry * offset 1.3.6.1.3.5.1.1.9.1.x.(1|2).(4|16) = 13 + * offset 1.3.6.1.4.1.7336.3.2.1.1.9.1.x.1.(1|2) = 16 */ #define BGP4V2_NLRI_ENTRY_OFFSET 13 #define BGP4V2_NLRI_INDEX 1 @@ -82,5 +92,7 @@ #define BGP4V2_BACKWARD_TRANSITION_NOTIFICATION 2 extern int bgp_snmp_bgp4v2_init(struct event_loop *tm); +extern int bgpv2TrapEstablished(struct peer *peer); +extern int bgpv2TrapBackwardTransition(struct peer *peer); #endif /* _FRR_BGP_SNMP_BGP4V2_H_ */ diff --git a/bgpd/bgp_table.c b/bgpd/bgp_table.c index cb658c0308..8465ada996 100644 --- a/bgpd/bgp_table.c +++ b/bgpd/bgp_table.c @@ -46,16 +46,6 @@ void bgp_table_finish(struct bgp_table **rt) } } -/* - * bgp_dest_unlock_node - */ -void bgp_dest_unlock_node(struct bgp_dest *dest) -{ - frrtrace(1, frr_bgp, bgp_dest_unlock, dest); - bgp_delete_listnode(dest); - route_unlock_node(bgp_dest_to_rnode(dest)); -} - /* * bgp_dest_lock_node */ @@ -83,44 +73,59 @@ const char *bgp_dest_get_prefix_str(struct bgp_dest *dest) } /* - * bgp_node_create + * bgp_dest_unlock_node */ -static struct route_node *bgp_node_create(route_table_delegate_t *delegate, - struct route_table *table) +inline struct bgp_dest *bgp_dest_unlock_node(struct bgp_dest *dest) { - struct bgp_node *node; - node = XCALLOC(MTYPE_BGP_NODE, sizeof(struct bgp_node)); + frrtrace(1, frr_bgp, bgp_dest_unlock, dest); + bgp_delete_listnode(dest); + struct route_node *rn = bgp_dest_to_rnode(dest); + + if (rn->lock == 1) { + struct bgp_table *rt = bgp_dest_table(dest); + if (rt->bgp) { + bgp_addpath_free_node_data(&rt->bgp->tx_addpath, + &dest->tx_addpath, rt->afi, + rt->safi); + } + XFREE(MTYPE_BGP_NODE, dest); + dest = NULL; + rn->info = NULL; + } + route_unlock_node(rn); - RB_INIT(bgp_adj_out_rb, &node->adj_out); - return bgp_dest_to_rnode(node); + return dest; } /* * bgp_node_destroy */ static void bgp_node_destroy(route_table_delegate_t *delegate, - struct route_table *table, struct route_node *node) + struct route_table *table, struct route_node *node) { - struct bgp_node *bgp_node; + struct bgp_dest *dest; struct bgp_table *rt; - bgp_node = bgp_dest_from_rnode(node); + dest = bgp_dest_from_rnode(node); rt = table->info; - - if (rt->bgp) { - bgp_addpath_free_node_data(&rt->bgp->tx_addpath, - &bgp_node->tx_addpath, - rt->afi, rt->safi); + if (dest) { + if (rt->bgp) { + bgp_addpath_free_node_data(&rt->bgp->tx_addpath, + &dest->tx_addpath, + rt->afi, rt->safi); + } + XFREE(MTYPE_BGP_NODE, dest); + node->info = NULL; } - XFREE(MTYPE_BGP_NODE, bgp_node); + XFREE(MTYPE_ROUTE_NODE, node); } /* * Function vector to customize the behavior of the route table * library for BGP route tables. */ -route_table_delegate_t bgp_table_delegate = {.create_node = bgp_node_create, - .destroy_node = bgp_node_destroy}; +route_table_delegate_t bgp_table_delegate = { .create_node = route_node_create, + .destroy_node = bgp_node_destroy }; /* * bgp_table_init @@ -151,9 +156,9 @@ struct bgp_table *bgp_table_init(struct bgp *bgp, afi_t afi, safi_t safi) } /* Delete the route node from the selection deferral route list */ -void bgp_delete_listnode(struct bgp_node *node) +void bgp_delete_listnode(struct bgp_dest *dest) { - struct route_node *rn = NULL; + const struct route_node *rn = NULL; struct bgp_table *table = NULL; struct bgp *bgp = NULL; afi_t afi; @@ -162,8 +167,8 @@ void bgp_delete_listnode(struct bgp_node *node) /* If the route to be deleted is selection pending, update the * route node in gr_info */ - if (CHECK_FLAG(node->flags, BGP_NODE_SELECT_DEFER)) { - table = bgp_dest_table(node); + if (CHECK_FLAG(dest->flags, BGP_NODE_SELECT_DEFER)) { + table = bgp_dest_table(dest); if (table) { bgp = table->bgp; @@ -172,47 +177,48 @@ void bgp_delete_listnode(struct bgp_node *node) } else return; - rn = bgp_dest_to_rnode(node); + rn = bgp_dest_to_rnode(dest); if (bgp && rn && rn->lock == 1) { /* Delete the route from the selection pending list */ bgp->gr_info[afi][safi].gr_deferred--; - UNSET_FLAG(node->flags, BGP_NODE_SELECT_DEFER); + UNSET_FLAG(dest->flags, BGP_NODE_SELECT_DEFER); } } } -struct bgp_node *bgp_table_subtree_lookup(const struct bgp_table *table, +struct bgp_dest *bgp_table_subtree_lookup(const struct bgp_table *table, const struct prefix *p) { - struct bgp_node *node = bgp_dest_from_rnode(table->route_table->top); - struct bgp_node *matched = NULL; + struct bgp_dest *dest = bgp_dest_from_rnode(table->route_table->top); + struct bgp_dest *matched = NULL; - if (node == NULL) + if (dest == NULL) return NULL; - while (node) { - const struct prefix *node_p = bgp_dest_get_prefix(node); + while (dest) { + const struct prefix *dest_p = bgp_dest_get_prefix(dest); + struct route_node *node = dest->rn; - if (node_p->prefixlen >= p->prefixlen) { - if (!prefix_match(p, node_p)) + if (dest_p->prefixlen >= p->prefixlen) { + if (!prefix_match(p, dest_p)) return NULL; - matched = node; + matched = dest; break; } - if (!prefix_match(node_p, p)) + if (!prefix_match(dest_p, p)) return NULL; - if (node_p->prefixlen == p->prefixlen) { - matched = node; + if (dest_p->prefixlen == p->prefixlen) { + matched = dest; break; } - node = bgp_dest_from_rnode(node->link[prefix_bit( - &p->u.prefix, node_p->prefixlen)]); + dest = bgp_dest_from_rnode( + node->link[prefix_bit(&p->u.prefix, dest_p->prefixlen)]); } if (!matched) diff --git a/bgpd/bgp_table.h b/bgpd/bgp_table.h index 9027af5ba3..5b4c3be212 100644 --- a/bgpd/bgp_table.h +++ b/bgpd/bgp_table.h @@ -6,10 +6,6 @@ #ifndef _QUAGGA_BGP_TABLE_H #define _QUAGGA_BGP_TABLE_H -/* XXX BEGIN TEMPORARY COMPAT */ -#define bgp_dest bgp_node -/* XXX END TEMPORARY COMPAT */ - #include "mpls.h" #include "table.h" #include "queue.h" @@ -67,16 +63,10 @@ enum bgp_path_selection_reason { bgp_path_selection_default, }; -struct bgp_node { - /* - * CAUTION - * - * These fields must be the very first fields in this structure. - * - * @see bgp_node_to_rnode - * @see bgp_node_from_rnode - */ - ROUTE_NODE_FIELDS +struct bgp_dest { + struct route_node *rn; + + void *info; struct bgp_adj_out_rb adj_out; @@ -100,6 +90,7 @@ struct bgp_node { #define BGP_NODE_FIB_INSTALLED (1 << 6) #define BGP_NODE_LABEL_REQUESTED (1 << 7) #define BGP_NODE_SOFT_RECONFIG (1 << 8) +#define BGP_NODE_PROCESS_CLEAR (1 << 9) struct bgp_addpath_node_data tx_addpath; @@ -121,7 +112,7 @@ extern struct bgp_table *bgp_table_init(struct bgp *bgp, afi_t, safi_t); extern void bgp_table_lock(struct bgp_table *); extern void bgp_table_unlock(struct bgp_table *); extern void bgp_table_finish(struct bgp_table **); -extern void bgp_dest_unlock_node(struct bgp_dest *dest); +extern struct bgp_dest *bgp_dest_unlock_node(struct bgp_dest *dest); extern struct bgp_dest *bgp_dest_lock_node(struct bgp_dest *dest); extern const char *bgp_dest_get_prefix_str(struct bgp_dest *dest); @@ -133,7 +124,7 @@ extern const char *bgp_dest_get_prefix_str(struct bgp_dest *dest); */ static inline struct bgp_dest *bgp_dest_from_rnode(struct route_node *rnode) { - return (struct bgp_dest *)rnode; + return (rnode && rnode->info) ? (struct bgp_dest *)rnode->info : NULL; } /* @@ -143,7 +134,7 @@ static inline struct bgp_dest *bgp_dest_from_rnode(struct route_node *rnode) */ static inline struct route_node *bgp_dest_to_rnode(const struct bgp_dest *dest) { - return (struct route_node *)dest; + return dest ? dest->rn : NULL; } /* @@ -165,6 +156,9 @@ static inline struct bgp_dest *bgp_dest_parent_nolock(struct bgp_dest *dest) { struct route_node *rn = bgp_dest_to_rnode(dest)->parent; + while (rn && !rn->info) + rn = rn->parent; + return bgp_dest_from_rnode(rn); } @@ -178,7 +172,17 @@ static inline struct bgp_dest *bgp_dest_parent_nolock(struct bgp_dest *dest) static inline struct bgp_dest * bgp_table_top_nolock(const struct bgp_table *const table) { - return bgp_dest_from_rnode(table->route_table->top); + struct route_node *top; + struct route_node *rn = top = table->route_table->top; + + while (rn && !rn->info) { + if (rn == top) + route_lock_node(rn); + rn = route_next(rn); + } + if (rn && rn != top) + route_unlock_node(rn); + return rn ? rn->info : NULL; } /* @@ -187,7 +191,11 @@ bgp_table_top_nolock(const struct bgp_table *const table) static inline struct bgp_dest * bgp_table_top(const struct bgp_table *const table) { - return bgp_dest_from_rnode(route_top(table->route_table)); + struct route_node *rn = route_top(table->route_table); + + while (rn && !rn->info) + rn = route_next(rn); + return rn ? rn->info : NULL; } /* @@ -195,7 +203,11 @@ bgp_table_top(const struct bgp_table *const table) */ static inline struct bgp_dest *bgp_route_next(struct bgp_dest *dest) { - return bgp_dest_from_rnode(route_next(bgp_dest_to_rnode(dest))); + struct route_node *rn = route_next(bgp_dest_to_rnode(dest)); + + while (rn && !rn->info) + rn = route_next(rn); + return bgp_dest_from_rnode(rn); } /* @@ -209,6 +221,9 @@ static inline struct bgp_dest *bgp_route_next_until(struct bgp_dest *dest, rnode = route_next_until(bgp_dest_to_rnode(dest), bgp_dest_to_rnode(limit)); + while (rnode && !rnode->info) + rnode = route_next_until(rnode, bgp_dest_to_rnode(limit)); + return bgp_dest_from_rnode(rnode); } @@ -218,7 +233,17 @@ static inline struct bgp_dest *bgp_route_next_until(struct bgp_dest *dest, static inline struct bgp_dest *bgp_node_get(struct bgp_table *const table, const struct prefix *p) { - return bgp_dest_from_rnode(route_node_get(table->route_table, p)); + struct route_node *rn = route_node_get(table->route_table, p); + + if (!rn->info) { + struct bgp_dest *dest = XCALLOC(MTYPE_BGP_NODE, + sizeof(struct bgp_dest)); + + RB_INIT(bgp_adj_out_rb, &dest->adj_out); + rn->info = dest; + dest->rn = rn; + } + return rn->info; } /* @@ -254,7 +279,11 @@ static inline unsigned long bgp_table_count(const struct bgp_table *const table) static inline struct bgp_dest *bgp_table_get_next(const struct bgp_table *table, const struct prefix *p) { - return bgp_dest_from_rnode(route_table_get_next(table->route_table, p)); + struct route_node *rn = route_table_get_next(table->route_table, p); + + while (rn && !rn->info) + rn = route_next(rn); + return bgp_dest_from_rnode(rn); } /* This would benefit from a real atomic operation... @@ -356,7 +385,7 @@ static inline void bgp_dest_set_bgp_path_info(struct bgp_dest *dest, static inline struct bgp_table * bgp_dest_get_bgp_table_info(struct bgp_dest *dest) { - return dest->info; + return dest ? dest->info : NULL; } static inline void bgp_dest_set_bgp_table_info(struct bgp_dest *dest, @@ -367,17 +396,17 @@ static inline void bgp_dest_set_bgp_table_info(struct bgp_dest *dest, static inline bool bgp_dest_has_bgp_path_info_data(struct bgp_dest *dest) { - return !!dest->info; + return dest ? !!dest->info : false; } static inline const struct prefix *bgp_dest_get_prefix(const struct bgp_dest *dest) { - return &dest->p; + return dest ? &dest->rn->p : NULL; } static inline unsigned int bgp_dest_get_lock_count(const struct bgp_dest *dest) { - return dest->lock; + return dest ? dest->rn->lock : 0; } #ifdef _FRR_ATTRIBUTE_PRINTFRR diff --git a/bgpd/bgp_trace.h b/bgpd/bgp_trace.h index 3213b29d99..a77a25e435 100644 --- a/bgpd/bgp_trace.h +++ b/bgpd/bgp_trace.h @@ -54,9 +54,9 @@ PKT_PROCESS_TRACEPOINT_INSTANCE(refresh_process) TRACEPOINT_EVENT( frr_bgp, packet_read, - TP_ARGS(struct peer *, peer, struct stream *, pkt), + TP_ARGS(struct peer_connection *, connection, struct stream *, pkt), TP_FIELDS( - ctf_string(peer, PEER_HOSTNAME(peer)) + ctf_string(peer, PEER_HOSTNAME(connection->peer)) ctf_sequence_hex(uint8_t, packet, pkt->data, size_t, STREAM_READABLE(pkt)) ) @@ -135,11 +135,12 @@ TRACEPOINT_LOGLEVEL(frr_bgp, bmp_mirror_packet, TRACE_INFO) TRACEPOINT_EVENT( frr_bgp, bmp_eor, - TP_ARGS(afi_t, afi, safi_t, safi, uint8_t, flags), + TP_ARGS(afi_t, afi, safi_t, safi, uint8_t, flags, uint8_t, peer_type_flag), TP_FIELDS( ctf_integer(afi_t, afi, afi) ctf_integer(safi_t, safi, safi) ctf_integer(uint8_t, flags, flags) + ctf_integer(uint8_t, peer_type_flag, peer_type_flag) ) ) @@ -307,7 +308,8 @@ TRACEPOINT_EVENT( struct in_addr, vtep, esi_t *, esi), TP_FIELDS( ctf_string(action, add ? "add" : "del") - ctf_integer(vni_t, vni, vpn->vni) + ctf_integer(vni_t, vni, (vpn ? vpn->vni : 0)) + ctf_integer(uint32_t, eth_tag, &pfx->prefix.macip_addr.eth_tag) ctf_array(unsigned char, mac, &pfx->prefix.macip_addr.mac, sizeof(struct ethaddr)) ctf_array(unsigned char, ip, &pfx->prefix.macip_addr.ip, @@ -325,7 +327,7 @@ TRACEPOINT_EVENT( const struct prefix_evpn *, pfx), TP_FIELDS( ctf_string(action, add ? "add" : "del") - ctf_integer(vni_t, vni, vpn->vni) + ctf_integer(vni_t, vni, (vpn ? vpn->vni : 0)) ctf_integer_network_hex(unsigned int, vtep, pfx->prefix.imet_addr.ip.ipaddr_v4.s_addr) ) @@ -434,6 +436,64 @@ TRACEPOINT_EVENT( ) TRACEPOINT_LOGLEVEL(frr_bgp, evpn_mh_local_es_evi_del_zrecv, TRACE_INFO) +TRACEPOINT_EVENT( + frr_bgp, + evpn_mh_es_evi_vtep_add, + TP_ARGS(esi_t *, esi, vni_t, vni, struct in_addr, vtep, + uint8_t, ead_es), + TP_FIELDS( + ctf_array(unsigned char, esi, esi, sizeof(esi_t)) + ctf_integer(vni_t, vni, vni) + ctf_integer_network_hex(unsigned int, vtep, vtep.s_addr) + ctf_integer(uint8_t, ead_es, ead_es) + ) +) +TRACEPOINT_LOGLEVEL(frr_bgp, evpn_mh_es_evi_vtep_add, TRACE_INFO) + +TRACEPOINT_EVENT( + frr_bgp, + evpn_mh_es_evi_vtep_del, + TP_ARGS(esi_t *, esi, vni_t, vni, struct in_addr, vtep, + uint8_t, ead_es), + TP_FIELDS( + ctf_array(unsigned char, esi, esi, sizeof(esi_t)) + ctf_integer(vni_t, vni, vni) + ctf_integer_network_hex(unsigned int, vtep, vtep.s_addr) + ctf_integer(uint8_t, ead_es, ead_es) + ) +) +TRACEPOINT_LOGLEVEL(frr_bgp, evpn_mh_es_evi_vtep_del, TRACE_INFO) + +TRACEPOINT_EVENT( + frr_bgp, + evpn_mh_local_ead_es_evi_route_upd, + TP_ARGS(esi_t *, esi, vni_t, vni, + uint8_t, route_type, + struct in_addr, vtep), + TP_FIELDS( + ctf_array(unsigned char, esi, esi, sizeof(esi_t)) + ctf_integer(vni_t, vni, vni) + ctf_integer(uint8_t, route_type, route_type) + ctf_integer_network_hex(unsigned int, vtep, vtep.s_addr) + ) +) +TRACEPOINT_LOGLEVEL(frr_bgp, evpn_mh_local_ead_es_evi_route_upd, TRACE_INFO) + +TRACEPOINT_EVENT( + frr_bgp, + evpn_mh_local_ead_es_evi_route_del, + TP_ARGS(esi_t *, esi, vni_t, vni, + uint8_t, route_type, + struct in_addr, vtep), + TP_FIELDS( + ctf_array(unsigned char, esi, esi, sizeof(esi_t)) + ctf_integer(vni_t, vni, vni) + ctf_integer(uint8_t, route_type, route_type) + ctf_integer_network_hex(unsigned int, vtep, vtep.s_addr) + ) +) +TRACEPOINT_LOGLEVEL(frr_bgp, evpn_mh_local_ead_es_evi_route_del, TRACE_INFO) + TRACEPOINT_EVENT( frr_bgp, evpn_local_vni_add_zrecv, @@ -494,6 +554,34 @@ TRACEPOINT_EVENT( ) TRACEPOINT_LOGLEVEL(frr_bgp, evpn_local_macip_del_zrecv, TRACE_INFO) +TRACEPOINT_EVENT( + frr_bgp, + evpn_advertise_type5, + TP_ARGS(vrf_id_t, vrf, const struct prefix_evpn *, pfx, + struct ethaddr *, rmac, struct in_addr, vtep), + TP_FIELDS( + ctf_integer(int, vrf_id, vrf) + ctf_array(unsigned char, ip, &pfx->prefix.prefix_addr.ip, + sizeof(struct ipaddr)) + ctf_array(unsigned char, rmac, rmac, + sizeof(struct ethaddr)) + ctf_integer_network_hex(unsigned int, vtep, vtep.s_addr) + ) +) +TRACEPOINT_LOGLEVEL(frr_bgp, evpn_advertise_type5, TRACE_INFO) + +TRACEPOINT_EVENT( + frr_bgp, + evpn_withdraw_type5, + TP_ARGS(vrf_id_t, vrf, const struct prefix_evpn *, pfx), + TP_FIELDS( + ctf_integer(int, vrf_id, vrf) + ctf_array(unsigned char, ip, &pfx->prefix.prefix_addr.ip, + sizeof(struct ipaddr)) + ) +) +TRACEPOINT_LOGLEVEL(frr_bgp, evpn_withdraw_type5, TRACE_INFO) + TRACEPOINT_EVENT( frr_bgp, evpn_local_l3vni_add_zrecv, diff --git a/bgpd/bgp_updgrp.c b/bgpd/bgp_updgrp.c index 0b1e54916a..2fc1bd63f7 100644 --- a/bgpd/bgp_updgrp.c +++ b/bgpd/bgp_updgrp.c @@ -74,7 +74,7 @@ static void sync_init(struct update_subgroup *subgrp, XCALLOC(MTYPE_BGP_SYNCHRONISE, sizeof(struct bgp_synchronize)); bgp_adv_fifo_init(&subgrp->sync->update); bgp_adv_fifo_init(&subgrp->sync->withdraw); - bgp_adv_fifo_init(&subgrp->sync->withdraw_low); + subgrp->hash = hash_create(bgp_advertise_attr_hash_key, bgp_advertise_attr_hash_cmp, "BGP SubGroup Hash"); @@ -128,6 +128,7 @@ static void conf_copy(struct peer *dst, struct peer *src, afi_t afi, dst->bgp = src->bgp; dst->sort = src->sort; + dst->sub_sort = src->sub_sort; dst->as = src->as; dst->v_routeadv = src->v_routeadv; dst->flags = src->flags; @@ -142,6 +143,8 @@ static void conf_copy(struct peer *dst, struct peer *src, afi_t afi, dst->afc_nego[afi][safi] = src->afc_nego[afi][safi]; dst->orf_plist[afi][safi] = src->orf_plist[afi][safi]; dst->addpath_type[afi][safi] = src->addpath_type[afi][safi]; + dst->addpath_best_selected[afi][safi] = + src->addpath_best_selected[afi][safi]; dst->local_as = src->local_as; dst->change_local_as = src->change_local_as; dst->shared_network = src->shared_network; @@ -277,6 +280,8 @@ static void *updgrp_hash_alloc(void *p) updgrp = XCALLOC(MTYPE_BGP_UPDGRP, sizeof(struct update_group)); memcpy(updgrp, in, sizeof(struct update_group)); updgrp->conf = XCALLOC(MTYPE_BGP_PEER, sizeof(struct peer)); + updgrp->conf->connection = XCALLOC(MTYPE_BGP_PEER_CONNECTION, + sizeof(struct peer_connection)); conf_copy(updgrp->conf, in->conf, in->afi, in->safi); return updgrp; } @@ -307,6 +312,7 @@ static void *updgrp_hash_alloc(void *p) * 16. Local-as should match, if configured. * 17. maximum-prefix-out * 18. Local-role should also match, if configured. + * 19. Add-Path best selected paths count should match as well * ) */ static unsigned int updgrp_hash_key_make(const void *p) @@ -337,9 +343,11 @@ static unsigned int updgrp_hash_key_make(const void *p) key = 0; key = jhash_1word(peer->sort, key); /* EBGP or IBGP */ + key = jhash_1word(peer->sub_sort, key); /* OAD */ key = jhash_1word((peer->flags & PEER_UPDGRP_FLAGS), key); key = jhash_1word((flags & PEER_UPDGRP_AF_FLAGS), key); key = jhash_1word((uint32_t)peer->addpath_type[afi][safi], key); + key = jhash_1word(peer->addpath_best_selected[afi][safi], key); key = jhash_1word((peer->cap & PEER_UPDGRP_CAP_FLAGS), key); key = jhash_1word((peer->af_cap[afi][safi] & PEER_UPDGRP_AF_CAP_FLAGS), key); @@ -416,8 +424,6 @@ static unsigned int updgrp_hash_key_make(const void *p) */ if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL) || CHECK_FLAG(peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV) - || CHECK_FLAG(peer->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_SM_OLD_RCV) || CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_OUT)) key = jhash_1word(jhash(peer->host, strlen(peer->host), SEED2), key); @@ -443,11 +449,10 @@ static unsigned int updgrp_hash_key_make(const void *p) * STATEMENT STAYS UP TO DATE */ if (bgp_debug_neighbor_events(peer)) { - zlog_debug( - "%pBP Update Group Hash: sort: %d UpdGrpFlags: %ju UpdGrpAFFlags: %ju", - peer, peer->sort, - (intmax_t)CHECK_FLAG(peer->flags, PEER_UPDGRP_FLAGS), - (intmax_t)CHECK_FLAG(flags, PEER_UPDGRP_AF_FLAGS)); + zlog_debug("%pBP Update Group Hash: sort: %d sub_sort: %d UpdGrpFlags: %ju UpdGrpAFFlags: %ju", + peer, peer->sort, peer->sub_sort, + (intmax_t)CHECK_FLAG(peer->flags, PEER_UPDGRP_FLAGS), + (intmax_t)CHECK_FLAG(flags, PEER_UPDGRP_AF_FLAGS)); zlog_debug( "%pBP Update Group Hash: addpath: %u UpdGrpCapFlag: %u UpdGrpCapAFFlag: %u route_adv: %u change local as: %u, as_path_loop_detection: %d", peer, (uint32_t)peer->addpath_type[afi][safi], @@ -488,15 +493,12 @@ static unsigned int updgrp_hash_key_make(const void *p) : "(NONE)", peer->shared_network && peer_afi_active_nego(peer, AFI_IP6)); - zlog_debug( - "%pBP Update Group Hash: Lonesoul: %d ORF prefix: %u ORF old: %u max prefix out: %ju", - peer, !!CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL), - CHECK_FLAG(peer->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_SM_RCV), - CHECK_FLAG(peer->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_SM_OLD_RCV), - (intmax_t)CHECK_FLAG(peer->af_flags[afi][safi], - PEER_FLAG_MAX_PREFIX_OUT)); + zlog_debug("%pBP Update Group Hash: Lonesoul: %d ORF prefix: %u max prefix out: %ju", + peer, !!CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL), + CHECK_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ORF_PREFIX_SM_RCV), + (intmax_t)CHECK_FLAG(peer->af_flags[afi][safi], + PEER_FLAG_MAX_PREFIX_OUT)); zlog_debug( "%pBP Update Group Hash: local role: %u AIGP: %d SOO: %s", peer, peer->local_role, @@ -633,11 +635,9 @@ static bool updgrp_hash_cmp(const void *p1, const void *p2) if ((afi == AFI_IP6) && (pe1->shared_network != pe2->shared_network)) return false; - if ((CHECK_FLAG(pe1->flags, PEER_FLAG_LONESOUL) - || CHECK_FLAG(pe1->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV) - || CHECK_FLAG(pe1->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_SM_OLD_RCV)) - && !sockunion_same(&pe1->su, &pe2->su)) + if ((CHECK_FLAG(pe1->flags, PEER_FLAG_LONESOUL) || + CHECK_FLAG(pe1->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)) && + !sockunion_same(&pe1->connection->su, &pe2->connection->su)) return false; return true; @@ -690,6 +690,7 @@ static int update_group_show_walkcb(struct update_group *updgrp, void *arg) json_object *json_peers = NULL; json_object *json_pkt_info = NULL; time_t epoch_tbuf, tbuf; + char timebuf[32]; if (!ctx) return CMD_SUCCESS; @@ -725,7 +726,7 @@ static int update_group_show_walkcb(struct update_group *updgrp, void *arg) json_time = json_object_new_object(); json_object_int_add(json_time, "epoch", epoch_tbuf); json_object_string_add(json_time, "epochString", - ctime(&epoch_tbuf)); + ctime_r(&epoch_tbuf, timebuf)); json_object_object_add(json_updgrp, "groupCreateTime", json_time); json_object_string_add(json_updgrp, "afi", @@ -734,7 +735,8 @@ static int update_group_show_walkcb(struct update_group *updgrp, void *arg) safi2str(updgrp->safi)); } else { vty_out(vty, "Update-group %" PRIu64 ":\n", updgrp->id); - vty_out(vty, " Created: %s", timestamp_string(updgrp->uptime)); + vty_out(vty, " Created: %s", + timestamp_string(updgrp->uptime, timebuf)); } filter = &updgrp->conf->filter[updgrp->afi][updgrp->safi]; @@ -795,7 +797,7 @@ static int update_group_show_walkcb(struct update_group *updgrp, void *arg) json_object_int_add(json_subgrp_time, "epoch", epoch_tbuf); json_object_string_add(json_subgrp_time, "epochString", - ctime(&epoch_tbuf)); + ctime_r(&epoch_tbuf, timebuf)); json_object_object_add(json_subgrp, "groupCreateTime", json_subgrp_time); } else { @@ -803,7 +805,7 @@ static int update_group_show_walkcb(struct update_group *updgrp, void *arg) vty_out(vty, " Update-subgroup %" PRIu64 ":\n", subgrp->id); vty_out(vty, " Created: %s", - timestamp_string(subgrp->uptime)); + timestamp_string(subgrp->uptime, timebuf)); } if (subgrp->split_from.update_group_id @@ -990,13 +992,18 @@ static struct update_group *update_group_find(struct peer_af *paf) struct update_group *updgrp; struct update_group tmp; struct peer tmp_conf; + struct peer_connection tmp_connection; - if (!peer_established(PAF_PEER(paf))) + if (!peer_established((PAF_PEER(paf))->connection)) return NULL; memset(&tmp, 0, sizeof(tmp)); memset(&tmp_conf, 0, sizeof(tmp_conf)); + memset(&tmp_connection, 0, sizeof(struct peer_connection)); + tmp.conf = &tmp_conf; + tmp_conf.connection = &tmp_connection; + peer2_updgrp_copy(&tmp, paf); updgrp = hash_lookup(paf->peer->bgp->update_groups[paf->afid], &tmp); @@ -1009,10 +1016,14 @@ static struct update_group *update_group_create(struct peer_af *paf) struct update_group *updgrp; struct update_group tmp; struct peer tmp_conf; + struct peer_connection tmp_connection; memset(&tmp, 0, sizeof(tmp)); memset(&tmp_conf, 0, sizeof(tmp_conf)); + memset(&tmp_connection, 0, sizeof(tmp_connection)); + tmp.conf = &tmp_conf; + tmp_conf.connection = &tmp_connection; peer2_updgrp_copy(&tmp, paf); updgrp = hash_get(paf->peer->bgp->update_groups[paf->afid], &tmp, @@ -1042,6 +1053,7 @@ static void update_group_delete(struct update_group *updgrp) XFREE(MTYPE_BGP_PEER_IFNAME, updgrp->conf->ifname); + XFREE(MTYPE_BGP_PEER_CONNECTION, updgrp->conf->connection); XFREE(MTYPE_BGP_PEER, updgrp->conf); XFREE(MTYPE_BGP_UPDGRP, updgrp); } @@ -1254,7 +1266,7 @@ static struct update_subgroup *update_subgroup_find(struct update_group *updgrp, } else version = 0; - if (!peer_established(PAF_PEER(paf))) + if (!peer_established(PAF_PEER(paf)->connection)) return NULL; UPDGRP_FOREACH_SUBGRP (updgrp, subgrp) { @@ -1687,14 +1699,14 @@ static int updgrp_policy_update_walkcb(struct update_group *updgrp, void *arg) */ UNSET_FLAG(subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE); - subgroup_default_originate(subgrp, 0); + subgroup_default_originate(subgrp, false); } else { /* * This is a explicit withdraw, since the * routemap is not present in routemap lib. need - * to pass 1 for withdraw arg. + * to pass `true` for withdraw arg. */ - subgroup_default_originate(subgrp, 1); + subgroup_default_originate(subgrp, true); } } update_subgroup_set_needs_refresh(subgrp, 0); @@ -1948,7 +1960,7 @@ void update_group_adjust_peer(struct peer_af *paf) return; peer = PAF_PEER(paf); - if (!peer_established(peer)) { + if (!peer_established(peer->connection)) { return; } @@ -2003,13 +2015,13 @@ int update_group_adjust_soloness(struct peer *peer, int set) if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { peer_lonesoul_or_not(peer, set); - if (peer_established(peer)) + if (peer_established(peer->connection)) bgp_announce_route_all(peer); } else { group = peer->group; for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) { peer_lonesoul_or_not(peer, set); - if (peer_established(peer)) + if (peer_established(peer->connection)) bgp_announce_route_all(peer); } } @@ -2090,7 +2102,7 @@ update_group_default_originate_route_map_walkcb(struct update_group *updgrp, */ UNSET_FLAG(subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE); - subgroup_default_originate(subgrp, 0); + subgroup_default_originate(subgrp, false); } } @@ -2106,7 +2118,6 @@ void update_group_refresh_default_originate_route_map(struct event *thread) update_group_walk(bgp, update_group_default_originate_route_map_walkcb, reason); EVENT_OFF(bgp->t_rmap_def_originate_eval); - bgp_unlock(bgp); } /* @@ -2203,12 +2214,15 @@ void subgroup_trigger_write(struct update_subgroup *subgrp) * the subgroup output queue into their own output queue. This action * will trigger a write job on the I/O thread. */ - SUBGRP_FOREACH_PEER (subgrp, paf) - if (peer_established(paf->peer)) - event_add_timer_msec( - bm->master, bgp_generate_updgrp_packets, - paf->peer, 0, - &paf->peer->t_generate_updgrp_packets); + SUBGRP_FOREACH_PEER (subgrp, paf) { + struct peer_connection *connection = paf->peer->connection; + + if (peer_established(connection)) + event_add_timer_msec(bm->master, + bgp_generate_updgrp_packets, + connection, 0, + &connection->t_generate_updgrp_packets); + } } int update_group_clear_update_dbg(struct update_group *updgrp, void *arg) diff --git a/bgpd/bgp_updgrp.h b/bgpd/bgp_updgrp.h index 67c384ba02..7a0d328c6a 100644 --- a/bgpd/bgp_updgrp.h +++ b/bgpd/bgp_updgrp.h @@ -55,9 +55,8 @@ #define PEER_UPDGRP_CAP_FLAGS (PEER_CAP_AS4_RCV) #define PEER_UPDGRP_AF_CAP_FLAGS \ - (PEER_CAP_ORF_PREFIX_SM_RCV | PEER_CAP_ORF_PREFIX_SM_OLD_RCV \ - | PEER_CAP_ADDPATH_AF_TX_ADV | PEER_CAP_ADDPATH_AF_RX_RCV \ - | PEER_CAP_ENHE_AF_NEGO) + (PEER_CAP_ORF_PREFIX_SM_RCV | PEER_CAP_ADDPATH_AF_TX_ADV | \ + PEER_CAP_ADDPATH_AF_RX_RCV | PEER_CAP_ENHE_AF_NEGO) enum bpacket_attr_vec_type { BGP_ATTR_VEC_NH = 0, BGP_ATTR_VEC_MAX }; @@ -429,7 +428,7 @@ extern void subgroup_announce_route(struct update_subgroup *subgrp); extern void subgroup_announce_all(struct update_subgroup *subgrp); extern void subgroup_default_originate(struct update_subgroup *subgrp, - int withdraw); + bool withdraw); extern void group_announce_route(struct bgp *bgp, afi_t afi, safi_t safi, struct bgp_dest *dest, struct bgp_path_info *pi); @@ -585,11 +584,9 @@ static inline void bgp_announce_peer(struct peer *peer) */ static inline int advertise_list_is_empty(struct update_subgroup *subgrp) { - if (bgp_adv_fifo_count(&subgrp->sync->update) - || bgp_adv_fifo_count(&subgrp->sync->withdraw) - || bgp_adv_fifo_count(&subgrp->sync->withdraw_low)) { + if (bgp_adv_fifo_count(&subgrp->sync->update) || + bgp_adv_fifo_count(&subgrp->sync->withdraw)) return 0; - } return 1; } diff --git a/bgpd/bgp_updgrp_adv.c b/bgpd/bgp_updgrp_adv.c index 33617811cf..7ecebe3020 100644 --- a/bgpd/bgp_updgrp_adv.c +++ b/bgpd/bgp_updgrp_adv.c @@ -87,6 +87,67 @@ static void adj_free(struct bgp_adj_out *adj) XFREE(MTYPE_BGP_ADJ_OUT, adj); } +static void +subgrp_announce_addpath_best_selected(struct bgp_dest *dest, + struct update_subgroup *subgrp) +{ + afi_t afi = SUBGRP_AFI(subgrp); + safi_t safi = SUBGRP_SAFI(subgrp); + struct peer *peer = SUBGRP_PEER(subgrp); + enum bgp_path_selection_reason reason; + char pfx_buf[PREFIX2STR_BUFFER] = {}; + int paths_eq = 0; + int best_path_count = 0; + struct list *list = list_new(); + struct bgp_path_info *pi = NULL; + + if (peer->addpath_type[afi][safi] == BGP_ADDPATH_BEST_SELECTED) { + while (best_path_count++ < + peer->addpath_best_selected[afi][safi]) { + struct bgp_path_info *exist = NULL; + + for (pi = bgp_dest_get_bgp_path_info(dest); pi; + pi = pi->next) { + if (listnode_lookup(list, pi)) + continue; + + if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)) + continue; + + if (bgp_path_info_cmp(peer->bgp, pi, exist, + &paths_eq, NULL, 0, + pfx_buf, afi, safi, + &reason)) + exist = pi; + } + + if (exist) + listnode_add(list, exist); + } + } + + for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) { + uint32_t id = bgp_addpath_id_for_peer(peer, afi, safi, + &pi->tx_addpath); + + if (peer->addpath_type[afi][safi] == + BGP_ADDPATH_BEST_SELECTED) { + if (listnode_lookup(list, pi)) + subgroup_process_announce_selected( + subgrp, pi, dest, afi, safi, id); + else + subgroup_process_announce_selected( + subgrp, NULL, dest, afi, safi, id); + } else { + subgroup_process_announce_selected(subgrp, pi, dest, + afi, safi, id); + } + } + + if (list) + list_delete(&list); +} + static void subgrp_withdraw_stale_addpath(struct updwalk_context *ctx, struct update_subgroup *subgrp) { @@ -125,7 +186,6 @@ static int group_announce_route_walkcb(struct update_group *updgrp, void *arg) { struct updwalk_context *ctx = arg; struct update_subgroup *subgrp; - struct bgp_path_info *pi; afi_t afi; safi_t safi; struct peer *peer; @@ -138,12 +198,10 @@ static int group_announce_route_walkcb(struct update_group *updgrp, void *arg) addpath_capable = bgp_addpath_encode_tx(peer, afi, safi); if (BGP_DEBUG(update, UPDATE_OUT)) - zlog_debug("%s: afi=%s, safi=%s, p=%pRN", __func__, - afi2str(afi), safi2str(safi), - bgp_dest_to_rnode(ctx->dest)); + zlog_debug("%s: afi=%s, safi=%s, p=%pBD", __func__, + afi2str(afi), safi2str(safi), ctx->dest); UPDGRP_FOREACH_SUBGRP (updgrp, subgrp) { - /* * Skip the subgroups that have coalesce timer running. We will * walk the entire prefix table for those subgroups when the @@ -155,19 +213,8 @@ static int group_announce_route_walkcb(struct update_group *updgrp, void *arg) if (addpath_capable) { subgrp_withdraw_stale_addpath(ctx, subgrp); - for (pi = bgp_dest_get_bgp_path_info(ctx->dest); - pi; pi = pi->next) { - /* Skip the bestpath for now */ - if (pi == ctx->pi) - continue; - - subgroup_process_announce_selected( - subgrp, pi, ctx->dest, afi, - safi, - bgp_addpath_id_for_peer( - peer, afi, safi, - &pi->tx_addpath)); - } + subgrp_announce_addpath_best_selected(ctx->dest, + subgrp); /* Process the bestpath last so the "show [ip] * bgp neighbor x.x.x.x advertised" @@ -307,6 +354,7 @@ static void subgroup_coalesce_timer(struct event *thread) { struct update_subgroup *subgrp; struct bgp *bgp; + safi_t safi; subgrp = EVENT_ARG(thread); if (bgp_debug_update(NULL, NULL, subgrp->update_group, 0)) @@ -317,7 +365,7 @@ static void subgroup_coalesce_timer(struct event *thread) subgrp->v_coalesce = 0; bgp = SUBGRP_INST(subgrp); subgroup_announce_route(subgrp); - + safi = SUBGRP_SAFI(subgrp); /* While the announce_route() may kick off the route advertisement timer * for @@ -328,14 +376,18 @@ static void subgroup_coalesce_timer(struct event *thread) * announce, this is the method currently employed to trigger the EOR. */ if (!bgp_update_delay_active(SUBGRP_INST(subgrp)) && - !(BGP_SUPPRESS_FIB_ENABLED(bgp))) { + !(bgp_fibupd_safi(safi) && BGP_SUPPRESS_FIB_ENABLED(bgp))) { + struct peer_af *paf; struct peer *peer; SUBGRP_FOREACH_PEER (subgrp, paf) { peer = PAF_PEER(paf); - EVENT_OFF(peer->t_routeadv); - BGP_TIMER_ON(peer->t_routeadv, bgp_routeadv_timer, 0); + struct peer_connection *connection = peer->connection; + + EVENT_OFF(connection->t_routeadv); + BGP_TIMER_ON(connection->t_routeadv, bgp_routeadv_timer, + 0); } } } @@ -426,7 +478,7 @@ bgp_advertise_clean_subgroup(struct update_subgroup *subgrp, bgp_advertise_delete(baa, adv); /* Fetch next advertise candidate. */ - next = baa->adv; + next = bgp_advertise_attr_fifo_first(&baa->fifo); /* Unintern BGP advertise attribute. */ bgp_advertise_attr_unintern(subgrp->hash, baa); @@ -549,7 +601,8 @@ void bgp_adj_out_set_subgroup(struct bgp_dest *dest, * the flag PEER_STATUS_ADV_DELAY which will allow * more routes to be sent in the update message */ - if (BGP_SUPPRESS_FIB_ENABLED(bgp)) { + if (bgp_fibupd_safi(safi) && + BGP_SUPPRESS_FIB_ENABLED(bgp)) { adv_peer = PAF_PEER(paf); if (!bgp_adv_fifo_count( &subgrp->sync->withdraw)) @@ -680,12 +733,16 @@ void subgroup_announce_table(struct update_subgroup *subgrp, if (safi != SAFI_MPLS_VPN && safi != SAFI_ENCAP && safi != SAFI_EVPN && CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE)) - subgroup_default_originate(subgrp, 0); + subgroup_default_originate(subgrp, false); subgrp->pscount = 0; SET_FLAG(subgrp->sflags, SUBGRP_STATUS_TABLE_REPARSING); for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) { + + if (addpath_capable) + subgrp_announce_addpath_best_selected(dest, subgrp); + for (ri = bgp_dest_get_bgp_path_info(dest); ri; ri = ri->next) { if (!bgp_check_selected(ri, peer, addpath_capable, afi, @@ -703,10 +760,12 @@ void subgroup_announce_table(struct update_subgroup *subgrp, is_default_prefix(bgp_dest_get_prefix(dest))) break; - subgroup_process_announce_selected( - subgrp, ri, dest, afi, safi_rib, - bgp_addpath_id_for_peer(peer, afi, safi_rib, - &ri->tx_addpath)); + if (CHECK_FLAG(ri->flags, BGP_PATH_SELECTED)) + subgroup_process_announce_selected( + subgrp, ri, dest, afi, safi_rib, + bgp_addpath_id_for_peer( + peer, afi, safi_rib, + &ri->tx_addpath)); } } UNSET_FLAG(subgrp->sflags, SUBGRP_STATUS_TABLE_REPARSING); @@ -766,7 +825,7 @@ void subgroup_announce_route(struct update_subgroup *subgrp) } } -void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw) +void subgroup_default_originate(struct update_subgroup *subgrp, bool withdraw) { struct bgp *bgp; struct attr attr; @@ -855,8 +914,8 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw) bgp_attr_flush(new_attr); new_attr = bgp_attr_intern( tmp_pi.attr); - bgp_attr_flush(tmp_pi.attr); } + bgp_attr_flush(tmp_pi.attr); subgroup_announce_reset_nhop( (peer_cap_enhe(peer, afi, safi) ? AF_INET6 @@ -881,7 +940,7 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw) SUBGRP_STATUS_DEFAULT_ORIGINATE))) SET_FLAG(subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE); - withdraw = 1; + withdraw = true; } } @@ -1014,7 +1073,7 @@ void group_announce_route(struct bgp *bgp, afi_t afi, safi_t safi, /* If suppress fib is enabled, the route will be advertised when * FIB status is received */ - if (!bgp_check_advertise(bgp, dest)) + if (!bgp_check_advertise(bgp, dest, safi)) return; update_group_af_walk(bgp, afi, safi, group_announce_route_walkcb, &ctx); diff --git a/bgpd/bgp_updgrp_packet.c b/bgpd/bgp_updgrp_packet.c index e04d5ae245..7502bf2ec6 100644 --- a/bgpd/bgp_updgrp_packet.c +++ b/bgpd/bgp_updgrp_packet.c @@ -789,6 +789,29 @@ struct bpacket *subgroup_update_packet(struct update_subgroup *subgrp) safi); label_pnt = &label; num_labels = 1; + } else if (safi == SAFI_MPLS_VPN && path && + CHECK_FLAG(path->flags, + BGP_PATH_MPLSVPN_NH_LABEL_BIND) && + path->mplsvpn.bmnc.nh_label_bind_cache && + path->peer && path->peer != peer && + path->sub_type != BGP_ROUTE_IMPORTED && + path->sub_type != BGP_ROUTE_STATIC && + bgp_mplsvpn_path_uses_valid_mpls_label( + path) && + bgp_path_info_nexthop_changed(path, peer, + afi)) { + /* Redistributed mpls vpn route between distinct + * peers from 'pi->peer' to 'to', + * and an mpls label is used in this path, + * and there is a nh label bind entry, + * then get appropriate mpls local label. When + * called here, 'get_label()' returns a valid + * label. + */ + label = bgp_mplsvpn_nh_label_bind_get_label( + path); + label_pnt = &label; + num_labels = 1; } else if (path && path->extra) { label_pnt = &path->extra->label[0]; num_labels = path->extra->num_labels; @@ -1057,8 +1080,7 @@ void subgroup_default_update_packet(struct update_subgroup *subgrp, safi_t safi; struct bpacket_attr_vec_arr vecarr; bool addpath_capable = false; - uint8_t default_originate_label[4] = {0x80, 0x00, 0x00}; - mpls_label_t *label = NULL; + mpls_label_t label = MPLS_LABEL_IMPLICIT_NULL; uint32_t num_labels = 0; if (DISABLE_BGP_ANNOUNCE) @@ -1074,7 +1096,11 @@ void subgroup_default_update_packet(struct update_subgroup *subgrp, addpath_capable = bgp_addpath_encode_tx(peer, afi, safi); if (safi == SAFI_LABELED_UNICAST) { - label = (mpls_label_t *)default_originate_label; + label = mpls_lse_encode((afi == AFI_IP) + ? MPLS_LABEL_IPV4_EXPLICIT_NULL + : MPLS_LABEL_IPV6_EXPLICIT_NULL, + 0, 0, 1); + bgp_set_valid_label(&label); num_labels = 1; } @@ -1119,10 +1145,12 @@ void subgroup_default_update_packet(struct update_subgroup *subgrp, /* Make place for total attribute length. */ pos = stream_get_endp(s); stream_putw(s, 0); - total_attr_len = bgp_packet_attribute( - NULL, peer, s, attr, &vecarr, &p, afi, safi, from, NULL, label, - num_labels, addpath_capable, - BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE, NULL); + total_attr_len = + bgp_packet_attribute(NULL, peer, s, attr, &vecarr, &p, afi, + safi, from, NULL, &label, num_labels, + addpath_capable, + BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE, + NULL); /* Set Total Path Attribute Length. */ stream_putw_at(s, pos, total_attr_len); diff --git a/bgpd/bgp_vpn.c b/bgpd/bgp_vpn.c index 0ed1d04d83..8fe24ebe20 100644 --- a/bgpd/bgp_vpn.c +++ b/bgpd/bgp_vpn.c @@ -30,8 +30,6 @@ int show_adj_route_vpn(struct vty *vty, struct peer *peer, int rd_header; int header = 1; json_object *json = NULL; - json_object *json_scode = NULL; - json_object *json_ocode = NULL; json_object *json_adv = NULL; json_object *json_routes = NULL; char rd_str[BUFSIZ]; @@ -47,21 +45,8 @@ int show_adj_route_vpn(struct vty *vty, struct peer *peer, } if (use_json) { - json_scode = json_object_new_object(); - json_ocode = json_object_new_object(); json = json_object_new_object(); json_adv = json_object_new_object(); - - json_object_string_add(json_scode, "suppressed", "s"); - json_object_string_add(json_scode, "damped", "d"); - json_object_string_add(json_scode, "history", "h"); - json_object_string_add(json_scode, "valid", "*"); - json_object_string_add(json_scode, "best", ">"); - json_object_string_add(json_scode, "internal", "i"); - - json_object_string_add(json_ocode, "igp", "i"); - json_object_string_add(json_ocode, "egp", "e"); - json_object_string_add(json_ocode, "incomplete", "?"); } for (dest = bgp_table_top(bgp->rib[afi][safi]); dest; @@ -117,12 +102,6 @@ int show_adj_route_vpn(struct vty *vty, struct peer *peer, json_object_int_add( json, "localAS", bgp->as); - json_object_object_add(json, - "bgpStatusCodes", - json_scode); - json_object_object_add(json, - "bgpOriginCodes", - json_ocode); } else { vty_out(vty, "BGP table version is 0, local router ID is %pI4\n", diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 7ef9db9f0d..2a91715536 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -5,6 +5,10 @@ #include +#ifdef GNU_LINUX +#include //RT_TABLE_XXX +#endif + #include "command.h" #include "lib/json.h" #include "lib/sockopt.h" @@ -118,12 +122,21 @@ FRR_CFG_DEFAULT_BOOL(BGP_HARD_ADMIN_RESET, { .val_bool = false, .match_version = "< 8.3", }, { .val_bool = true }, ); +FRR_CFG_DEFAULT_BOOL(BGP_SOFT_VERSION_CAPABILITY, + { .val_bool = true, .match_profile = "datacenter", }, + { .val_bool = false }, +); +FRR_CFG_DEFAULT_BOOL(BGP_ENFORCE_FIRST_AS, + { .val_bool = false, .match_version = "< 9.1", }, + { .val_bool = true }, +); DEFINE_HOOK(bgp_inst_config_write, (struct bgp *bgp, struct vty *vty), (bgp, vty)); DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp)); DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp)); +DEFINE_HOOK(bgp_snmp_traps_config_write, (struct vty * vty), (vty)); static struct peer_group *listen_range_exists(struct bgp *bgp, struct prefix *range, int exact); @@ -306,7 +319,7 @@ static int bgp_srv6_locator_unset(struct bgp *bgp) /* refresh functions */ for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) { listnode_delete(bgp->srv6_functions, func); - XFREE(MTYPE_BGP_SRV6_FUNCTION, func); + srv6_function_free(func); } /* refresh tovpn_sid */ @@ -586,7 +599,7 @@ int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name, int ret = bgp_get(bgp, as, name, inst_type, as_pretty, asnotation); if (ret == BGP_CREATED) { - bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME, + bgp_timers_set(NULL, *bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME, DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN); if (DFLT_BGP_IMPORT_CHECK) @@ -607,6 +620,11 @@ int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name, SET_FLAG((*bgp)->flags, BGP_FLAG_GRACEFUL_NOTIFICATION); if (DFLT_BGP_HARD_ADMIN_RESET) SET_FLAG((*bgp)->flags, BGP_FLAG_HARD_ADMIN_RESET); + if (DFLT_BGP_SOFT_VERSION_CAPABILITY) + SET_FLAG((*bgp)->flags, + BGP_FLAG_SOFT_VERSION_CAPABILITY); + if (DFLT_BGP_ENFORCE_FIRST_AS) + SET_FLAG((*bgp)->flags, BGP_FLAG_ENFORCE_FIRST_AS); ret = BGP_SUCCESS; } @@ -1584,8 +1602,9 @@ DEFUN_NOSH (router_bgp, * - update asnotation if explicitly mentioned */ if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO)) { - XFREE(MTYPE_BGP, bgp->as_pretty); - bgp->as_pretty = XSTRDUP(MTYPE_BGP, argv[idx_asn]->arg); + XFREE(MTYPE_BGP_NAME, bgp->as_pretty); + bgp->as_pretty = XSTRDUP(MTYPE_BGP_NAME, + argv[idx_asn]->arg); if (!CHECK_FLAG(bgp->config, BGP_CONFIG_ASNOTATION) && asnotation != ASNOTATION_UNDEFINED) { SET_FLAG(bgp->config, BGP_CONFIG_ASNOTATION); @@ -1994,8 +2013,8 @@ DEFUN (bgp_confederation_identifier, "bgp confederation identifier ASNUM", BGP_STR "AS confederation parameters\n" - AS_STR - "Set routing domain confederation AS\n") + "Set routing domain confederation AS\n" + AS_STR) { VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_number = 3; @@ -2017,8 +2036,8 @@ DEFUN (no_bgp_confederation_identifier, NO_STR BGP_STR "AS confederation parameters\n" - AS_STR - "Set routing domain confederation AS\n") + "Set routing domain confederation AS\n" + AS_STR) { VTY_DECLVAR_CONTEXT(bgp, bgp); bgp_confederation_id_unset(bgp); @@ -2654,7 +2673,7 @@ DEFUN (bgp_timers, return CMD_WARNING_CONFIG_FAILED; } - bgp_timers_set(bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY, + bgp_timers_set(vty, bgp, keepalive, holdtime, DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN); return CMD_SUCCESS; @@ -2670,7 +2689,7 @@ DEFUN (no_bgp_timers, "Holdtime\n") { VTY_DECLVAR_CONTEXT(bgp, bgp); - bgp_timers_set(bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME, + bgp_timers_set(vty, bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME, DFLT_BGP_CONNECT_RETRY, BGP_DEFAULT_DELAYOPEN); return CMD_SUCCESS; @@ -2820,6 +2839,23 @@ DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd, return CMD_SUCCESS; } +DEFPY(bgp_enforce_first_as, + bgp_enforce_first_as_cmd, + "[no] bgp enforce-first-as", + NO_STR + BGP_STR + "Enforce the first AS for EBGP routes\n") +{ + VTY_DECLVAR_CONTEXT(bgp, bgp); + + if (no) + UNSET_FLAG(bgp->flags, BGP_FLAG_ENFORCE_FIRST_AS); + else + SET_FLAG(bgp->flags, BGP_FLAG_ENFORCE_FIRST_AS); + + return CMD_SUCCESS; +} + DEFPY(bgp_lu_uses_explicit_null, bgp_lu_uses_explicit_null_cmd, "[no] bgp labeled-unicast $value", NO_STR BGP_STR @@ -2881,9 +2917,9 @@ DEFUN(bgp_reject_as_sets, bgp_reject_as_sets_cmd, * with aspath containing AS_SET or AS_CONFED_SET. */ for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) { + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) { peer->last_reset = PEER_DOWN_AS_SETS_REJECT; - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } } @@ -2907,9 +2943,9 @@ DEFUN(no_bgp_reject_as_sets, no_bgp_reject_as_sets_cmd, * with aspath containing AS_SET or AS_CONFED_SET. */ for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) { + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) { peer->last_reset = PEER_DOWN_AS_SETS_REJECT; - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } } @@ -3059,9 +3095,17 @@ DEFUN (bgp_graceful_restart_restart_time, VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_number = 3; uint32_t restart; + struct listnode *node, *nnode; + struct peer *peer; restart = strtoul(argv[idx_number]->arg, NULL, 10); bgp->restart_time = restart; + + for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) + bgp_capability_send(peer, AFI_IP, SAFI_UNICAST, + CAPABILITY_CODE_RESTART, + CAPABILITY_ACTION_SET); + return CMD_SUCCESS; } @@ -3112,8 +3156,16 @@ DEFUN (no_bgp_graceful_restart_restart_time, "Delay value (seconds)\n") { VTY_DECLVAR_CONTEXT(bgp, bgp); + struct listnode *node, *nnode; + struct peer *peer; bgp->restart_time = BGP_DEFAULT_RESTART_TIME; + + for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) + bgp_capability_send(peer, AFI_IP, SAFI_UNICAST, + CAPABILITY_CODE_RESTART, + CAPABILITY_ACTION_UNSET); + return CMD_SUCCESS; } @@ -3168,12 +3220,19 @@ DEFPY (bgp_graceful_restart_notification, "Indicate Graceful Restart support for BGP NOTIFICATION messages\n") { VTY_DECLVAR_CONTEXT(bgp, bgp); + struct listnode *node, *nnode; + struct peer *peer; if (no) UNSET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION); else SET_FLAG(bgp->flags, BGP_FLAG_GRACEFUL_NOTIFICATION); + for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) + bgp_capability_send(peer, AFI_IP, SAFI_UNICAST, + CAPABILITY_CODE_RESTART, + CAPABILITY_ACTION_SET); + return CMD_SUCCESS; } @@ -3589,10 +3648,16 @@ DEFUN(bgp_llgr_stalepath_time, bgp_llgr_stalepath_time_cmd, VTY_DECLVAR_CONTEXT(bgp, bgp); uint32_t llgr_stale_time; + struct listnode *node, *nnode; + struct peer *peer; llgr_stale_time = strtoul(argv[3]->arg, NULL, 10); bgp->llgr_stale_time = llgr_stale_time; + for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) + bgp_capability_send(peer, AFI_IP, SAFI_UNICAST, + CAPABILITY_CODE_LLGR, CAPABILITY_ACTION_SET); + return CMD_SUCCESS; } @@ -3604,9 +3669,16 @@ DEFUN(no_bgp_llgr_stalepath_time, no_bgp_llgr_stalepath_time_cmd, "Stale time value (seconds)\n") { VTY_DECLVAR_CONTEXT(bgp, bgp); + struct listnode *node, *nnode; + struct peer *peer; bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME; + for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) + bgp_capability_send(peer, AFI_IP, SAFI_UNICAST, + CAPABILITY_CODE_LLGR, + CAPABILITY_ACTION_UNSET); + return CMD_SUCCESS; } @@ -4197,6 +4269,24 @@ DEFUN (no_bgp_default_show_nexthop_hostname, return CMD_SUCCESS; } +DEFPY (bgp_default_software_version_capability, + bgp_default_software_version_capability_cmd, + "[no] bgp default software-version-capability", + NO_STR + BGP_STR + "Configure BGP defaults\n" + "Advertise software version capability for all neighbors\n") +{ + VTY_DECLVAR_CONTEXT(bgp, bgp); + + if (no) + UNSET_FLAG(bgp->flags, BGP_FLAG_SOFT_VERSION_CAPABILITY); + else + SET_FLAG(bgp->flags, BGP_FLAG_SOFT_VERSION_CAPABILITY); + + return CMD_SUCCESS; +} + /* "bgp network import-check" configuration. */ DEFUN (bgp_network_import_check, bgp_network_import_check_cmd, @@ -4826,9 +4916,9 @@ static int peer_conf_interface_get(struct vty *vty, const char *conf_if, peer_flag_unset(peer, PEER_FLAG_IFPEER_V6ONLY); /* v6only flag changed. Reset bgp seesion */ - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) { + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) { peer->last_reset = PEER_DOWN_V6ONLY_CHANGE; - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } else bgp_session_reset(peer); @@ -5015,7 +5105,7 @@ DEFUN (no_neighbor, peer_notify_unconfig(peer); peer_delete(peer); - if (other && other->status != Deleted) { + if (other && other->connection->status != Deleted) { peer_notify_unconfig(other); peer_delete(other); } @@ -5700,17 +5790,25 @@ DEFPY(neighbor_capability_software_version, "Advertise Software Version capability to the peer\n") { struct peer *peer; + int ret; peer = peer_and_group_lookup_vty(vty, neighbor); - if (peer && peer->conf_if) - return CMD_SUCCESS; + if (!peer) + return CMD_WARNING_CONFIG_FAILED; if (no) - return peer_flag_unset_vty(vty, neighbor, - PEER_FLAG_CAPABILITY_SOFT_VERSION); + ret = peer_flag_unset_vty(vty, neighbor, + PEER_FLAG_CAPABILITY_SOFT_VERSION); else - return peer_flag_set_vty(vty, neighbor, - PEER_FLAG_CAPABILITY_SOFT_VERSION); + ret = peer_flag_set_vty(vty, neighbor, + PEER_FLAG_CAPABILITY_SOFT_VERSION); + + bgp_capability_send(peer, AFI_IP, SAFI_UNICAST, + CAPABILITY_CODE_SOFT_VERSION, + no ? CAPABILITY_ACTION_UNSET + : CAPABILITY_ACTION_SET); + + return ret; } static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str, @@ -5762,24 +5860,37 @@ DEFUN (neighbor_capability_orf_prefix, struct peer *peer; afi_t afi = bgp_node_afi(vty); safi_t safi = bgp_node_safi(vty); + int ret; peer = peer_and_group_lookup_vty(vty, peer_str); if (!peer) return CMD_WARNING_CONFIG_FAILED; - if (strmatch(argv[idx_send_recv]->text, "send")) - return peer_af_flag_set_vty(vty, peer_str, afi, safi, - PEER_FLAG_ORF_PREFIX_SM); + if (strmatch(argv[idx_send_recv]->text, "send")) { + ret = peer_af_flag_set_vty(vty, peer_str, afi, safi, + PEER_FLAG_ORF_PREFIX_SM); + bgp_capability_send(peer, afi, safi, CAPABILITY_CODE_ORF, + CAPABILITY_ACTION_SET); + return ret; + } - if (strmatch(argv[idx_send_recv]->text, "receive")) - return peer_af_flag_set_vty(vty, peer_str, afi, safi, - PEER_FLAG_ORF_PREFIX_RM); + if (strmatch(argv[idx_send_recv]->text, "receive")) { + ret = peer_af_flag_set_vty(vty, peer_str, afi, safi, + PEER_FLAG_ORF_PREFIX_RM); + bgp_capability_send(peer, afi, safi, CAPABILITY_CODE_ORF, + CAPABILITY_ACTION_SET); + return ret; + } - if (strmatch(argv[idx_send_recv]->text, "both")) - return peer_af_flag_set_vty(vty, peer_str, afi, safi, - PEER_FLAG_ORF_PREFIX_SM) - | peer_af_flag_set_vty(vty, peer_str, afi, safi, - PEER_FLAG_ORF_PREFIX_RM); + if (strmatch(argv[idx_send_recv]->text, "both")) { + ret = peer_af_flag_set_vty(vty, peer_str, afi, safi, + PEER_FLAG_ORF_PREFIX_SM) | + peer_af_flag_set_vty(vty, peer_str, afi, safi, + PEER_FLAG_ORF_PREFIX_RM); + bgp_capability_send(peer, afi, safi, CAPABILITY_CODE_ORF, + CAPABILITY_ACTION_SET); + return ret; + } return CMD_WARNING_CONFIG_FAILED; } @@ -5814,24 +5925,37 @@ DEFUN (no_neighbor_capability_orf_prefix, struct peer *peer; afi_t afi = bgp_node_afi(vty); safi_t safi = bgp_node_safi(vty); + int ret; peer = peer_and_group_lookup_vty(vty, peer_str); if (!peer) return CMD_WARNING_CONFIG_FAILED; - if (strmatch(argv[idx_send_recv]->text, "send")) - return peer_af_flag_unset_vty(vty, peer_str, afi, safi, - PEER_FLAG_ORF_PREFIX_SM); + if (strmatch(argv[idx_send_recv]->text, "send")) { + ret = peer_af_flag_unset_vty(vty, peer_str, afi, safi, + PEER_FLAG_ORF_PREFIX_SM); + bgp_capability_send(peer, afi, safi, CAPABILITY_CODE_ORF, + CAPABILITY_ACTION_UNSET); + return ret; + } - if (strmatch(argv[idx_send_recv]->text, "receive")) - return peer_af_flag_unset_vty(vty, peer_str, afi, safi, - PEER_FLAG_ORF_PREFIX_RM); + if (strmatch(argv[idx_send_recv]->text, "receive")) { + ret = peer_af_flag_unset_vty(vty, peer_str, afi, safi, + PEER_FLAG_ORF_PREFIX_RM); + bgp_capability_send(peer, afi, safi, CAPABILITY_CODE_ORF, + CAPABILITY_ACTION_UNSET); + return ret; + } - if (strmatch(argv[idx_send_recv]->text, "both")) - return peer_af_flag_unset_vty(vty, peer_str, afi, safi, - PEER_FLAG_ORF_PREFIX_SM) - | peer_af_flag_unset_vty(vty, peer_str, afi, safi, - PEER_FLAG_ORF_PREFIX_RM); + if (strmatch(argv[idx_send_recv]->text, "both")) { + ret = peer_af_flag_unset_vty(vty, peer_str, afi, safi, + PEER_FLAG_ORF_PREFIX_SM) | + peer_af_flag_unset_vty(vty, peer_str, afi, safi, + PEER_FLAG_ORF_PREFIX_RM); + bgp_capability_send(peer, afi, safi, CAPABILITY_CODE_ORF, + CAPABILITY_ACTION_UNSET); + return ret; + } return CMD_WARNING_CONFIG_FAILED; } @@ -6749,14 +6873,9 @@ static uint8_t get_role_by_name(const char *role_str) return ROLE_UNDEFINED; } -static int peer_role_set_vty(struct vty *vty, const char *ip_str, +static int peer_role_set_vty(struct vty *vty, struct peer *peer, const char *role_str, bool strict_mode) { - struct peer *peer; - - peer = peer_and_group_lookup_vty(vty, ip_str); - if (!peer) - return CMD_WARNING_CONFIG_FAILED; uint8_t role = get_role_by_name(role_str); if (role == ROLE_UNDEFINED) @@ -6764,50 +6883,56 @@ static int peer_role_set_vty(struct vty *vty, const char *ip_str, return bgp_vty_return(vty, peer_role_set(peer, role, strict_mode)); } -static int peer_role_unset_vty(struct vty *vty, const char *ip_str) -{ - struct peer *peer; - - peer = peer_and_group_lookup_vty(vty, ip_str); - if (!peer) - return CMD_WARNING_CONFIG_FAILED; - return bgp_vty_return(vty, peer_role_unset(peer)); -} - DEFPY(neighbor_role, neighbor_role_cmd, - "neighbor local-role ", + "neighbor $neighbor local-role $role", NEIGHBOR_STR NEIGHBOR_ADDR_STR2 "Set session role\n" ROLE_STR) { - int idx_peer = 1; - int idx_role = 3; + int ret; + struct peer *peer; + + peer = peer_and_group_lookup_vty(vty, neighbor); + if (!peer) + return CMD_WARNING_CONFIG_FAILED; - return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg, - false); + ret = peer_role_set_vty(vty, peer, role, false); + + bgp_capability_send(peer, AFI_IP, SAFI_UNICAST, CAPABILITY_CODE_ROLE, + CAPABILITY_ACTION_SET); + + return ret; } DEFPY(neighbor_role_strict, neighbor_role_strict_cmd, - "neighbor local-role strict-mode", + "neighbor $neighbor local-role $role strict-mode", NEIGHBOR_STR NEIGHBOR_ADDR_STR2 "Set session role\n" ROLE_STR "Use additional restriction on peer\n") { - int idx_peer = 1; - int idx_role = 3; + int ret; + struct peer *peer; - return peer_role_set_vty(vty, argv[idx_peer]->arg, argv[idx_role]->arg, - true); + peer = peer_and_group_lookup_vty(vty, neighbor); + if (!peer) + return CMD_WARNING_CONFIG_FAILED; + + ret = peer_role_set_vty(vty, peer, role, true); + + bgp_capability_send(peer, AFI_IP, SAFI_UNICAST, CAPABILITY_CODE_ROLE, + CAPABILITY_ACTION_SET); + + return ret; } DEFPY(no_neighbor_role, no_neighbor_role_cmd, - "no neighbor local-role [strict-mode]", + "no neighbor $neighbor local-role [strict-mode]", NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2 @@ -6815,9 +6940,41 @@ DEFPY(no_neighbor_role, ROLE_STR "Use additional restriction on peer\n") { - int idx_peer = 2; + int ret; + struct peer *peer; + + peer = peer_and_group_lookup_vty(vty, neighbor); + if (!peer) + return CMD_WARNING_CONFIG_FAILED; + + ret = bgp_vty_return(vty, peer_role_unset(peer)); - return peer_role_unset_vty(vty, argv[idx_peer]->arg); + bgp_capability_send(peer, AFI_IP, SAFI_UNICAST, CAPABILITY_CODE_ROLE, + CAPABILITY_ACTION_UNSET); + + return ret; +} + +DEFPY (neighbor_oad, + neighbor_oad_cmd, + "[no$no] neighbor $neighbor oad", + NO_STR + NEIGHBOR_STR + NEIGHBOR_ADDR_STR2 + "Set peering session type to EBGP-OAD\n") +{ + struct peer *peer; + + peer = peer_and_group_lookup_vty(vty, neighbor); + if (!peer) + return CMD_WARNING_CONFIG_FAILED; + + if (no) + peer->sub_sort = 0; + else if (peer->sort == BGP_PEER_EBGP) + peer->sub_sort = BGP_PEER_EBGP_OAD; + + return CMD_SUCCESS; } /* disable-connected-check */ @@ -7563,7 +7720,7 @@ DEFUN (bgp_set_route_map_delay_timer, if (!rmap_delay_timer && bm->t_rmap_update) { EVENT_OFF(bm->t_rmap_update); event_execute(bm->master, bgp_route_map_update_timer, - NULL, 0); + NULL, 0, NULL); } return CMD_SUCCESS; } else { @@ -7959,6 +8116,26 @@ DEFPY (bgp_condadv_period, return CMD_SUCCESS; } +DEFPY (bgp_def_originate_eval, + bgp_def_originate_eval_cmd, + "[no$no] bgp default-originate timer (0-3600)$timer", + NO_STR + BGP_STR + "Control default-originate\n" + "Set period to rescan BGP table to check if default-originate condition is met\n" + "Period between BGP table scans, in seconds; default 5\n") +{ + VTY_DECLVAR_CONTEXT(bgp, bgp); + + bgp->rmap_def_originate_eval_timer = + no ? RMAP_DEFAULT_ORIGINATE_EVAL_TIMER : timer; + + if (bgp->t_rmap_def_originate_eval) + EVENT_OFF(bgp->t_rmap_def_originate_eval); + + return CMD_SUCCESS; +} + DEFPY (neighbor_advertise_map, neighbor_advertise_map_cmd, "[no$no] neighbor $neighbor advertise-map RMAP_NAME$advertise_str $exist RMAP_NAME$condition_str", @@ -8567,6 +8744,8 @@ DEFPY (neighbor_soo, ecommunity_free(&peer->soo[afi][safi]); peer->soo[afi][safi] = ecomm_soo; peer_af_flag_unset(peer, afi, safi, PEER_FLAG_SOO); + } else { + ecommunity_free(&ecomm_soo); } return bgp_vty_return(vty, @@ -8738,13 +8917,21 @@ DEFUN(neighbor_disable_addpath_rx, struct peer *peer; afi_t afi = bgp_node_afi(vty); safi_t safi = bgp_node_safi(vty); + int ret; + int action; peer = peer_and_group_lookup_vty(vty, peer_str); if (!peer) return CMD_WARNING_CONFIG_FAILED; - return peer_af_flag_set_vty(vty, peer_str, afi, safi, - PEER_FLAG_DISABLE_ADDPATH_RX); + action = bgp_addpath_capability_action(peer->addpath_type[afi][safi], 0); + + ret = peer_af_flag_set_vty(vty, peer_str, afi, safi, + PEER_FLAG_DISABLE_ADDPATH_RX); + + bgp_capability_send(peer, afi, safi, CAPABILITY_CODE_ADDPATH, action); + + return ret; } DEFUN(no_neighbor_disable_addpath_rx, @@ -8759,13 +8946,21 @@ DEFUN(no_neighbor_disable_addpath_rx, struct peer *peer; afi_t afi = bgp_node_afi(vty); safi_t safi = bgp_node_safi(vty); + int ret; + int action; peer = peer_and_group_lookup_vty(vty, peer_str); if (!peer) return CMD_WARNING_CONFIG_FAILED; - return peer_af_flag_unset_vty(vty, peer_str, afi, safi, - PEER_FLAG_DISABLE_ADDPATH_RX); + action = bgp_addpath_capability_action(peer->addpath_type[afi][safi], 0); + + ret = peer_af_flag_unset_vty(vty, peer_str, afi, safi, + PEER_FLAG_DISABLE_ADDPATH_RX); + + bgp_capability_send(peer, afi, safi, CAPABILITY_CODE_ADDPATH, action); + + return ret; } DEFUN (neighbor_addpath_tx_all_paths, @@ -8777,13 +8972,15 @@ DEFUN (neighbor_addpath_tx_all_paths, { int idx_peer = 1; struct peer *peer; + afi_t afi = bgp_node_afi(vty); + safi_t safi = bgp_node_safi(vty); peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg); if (!peer) return CMD_WARNING_CONFIG_FAILED; - bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty), - BGP_ADDPATH_ALL); + bgp_addpath_set_peer_type(peer, afi, safi, BGP_ADDPATH_ALL, 0); + return CMD_SUCCESS; } @@ -8803,20 +9000,20 @@ DEFUN (no_neighbor_addpath_tx_all_paths, { int idx_peer = 2; struct peer *peer; + afi_t afi = bgp_node_afi(vty); + safi_t safi = bgp_node_safi(vty); peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg); if (!peer) return CMD_WARNING_CONFIG_FAILED; - if (peer->addpath_type[bgp_node_afi(vty)][bgp_node_safi(vty)] - != BGP_ADDPATH_ALL) { + if (peer->addpath_type[afi][safi] != BGP_ADDPATH_ALL) { vty_out(vty, "%% Peer not currently configured to transmit all paths."); return CMD_WARNING_CONFIG_FAILED; } - bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty), - BGP_ADDPATH_NONE); + bgp_addpath_set_peer_type(peer, afi, safi, BGP_ADDPATH_NONE, 0); return CMD_SUCCESS; } @@ -8827,6 +9024,45 @@ ALIAS_HIDDEN(no_neighbor_addpath_tx_all_paths, NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2 "Use addpath to advertise all paths to a neighbor\n") +DEFPY (neighbor_addpath_tx_best_selected_paths, + neighbor_addpath_tx_best_selected_paths_cmd, + "neighbor $neighbor addpath-tx-best-selected (1-6)$paths", + NEIGHBOR_STR + NEIGHBOR_ADDR_STR2 + "Use addpath to advertise best selected paths to a neighbor\n" + "The number of best paths\n") +{ + struct peer *peer; + + peer = peer_and_group_lookup_vty(vty, neighbor); + if (!peer) + return CMD_WARNING_CONFIG_FAILED; + + bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty), + BGP_ADDPATH_BEST_SELECTED, paths); + return CMD_SUCCESS; +} + +DEFPY (no_neighbor_addpath_tx_best_selected_paths, + no_neighbor_addpath_tx_best_selected_paths_cmd, + "no neighbor $neighbor addpath-tx-best-selected [(1-6)]", + NO_STR + NEIGHBOR_STR + NEIGHBOR_ADDR_STR2 + "Use addpath to advertise best selected paths to a neighbor\n" + "The number of best paths\n") +{ + struct peer *peer; + + peer = peer_and_group_lookup_vty(vty, neighbor); + if (!peer) + return CMD_WARNING_CONFIG_FAILED; + + bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty), + BGP_ADDPATH_BEST_SELECTED, 0); + return CMD_SUCCESS; +} + DEFUN (neighbor_addpath_tx_bestpath_per_as, neighbor_addpath_tx_bestpath_per_as_cmd, "neighbor addpath-tx-bestpath-per-AS", @@ -8842,7 +9078,7 @@ DEFUN (neighbor_addpath_tx_bestpath_per_as, return CMD_WARNING_CONFIG_FAILED; bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty), - BGP_ADDPATH_BEST_PER_AS); + BGP_ADDPATH_BEST_PER_AS, 0); return CMD_SUCCESS; } @@ -8876,7 +9112,7 @@ DEFUN (no_neighbor_addpath_tx_bestpath_per_as, } bgp_addpath_set_peer_type(peer, bgp_node_afi(vty), bgp_node_safi(vty), - BGP_ADDPATH_NONE); + BGP_ADDPATH_NONE, 0); return CMD_SUCCESS; } @@ -9157,13 +9393,13 @@ DEFPY (af_rd_vpn_export, bgp_get_default(), bgp); if (yes) { - bgp->vpn_policy[afi].tovpn_rd_pretty = - XSTRDUP(MTYPE_BGP, rd_str); + bgp->vpn_policy[afi].tovpn_rd_pretty = XSTRDUP(MTYPE_BGP_NAME, + rd_str); bgp->vpn_policy[afi].tovpn_rd = prd; SET_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET); } else { - XFREE(MTYPE_BGP, bgp->vpn_policy[afi].tovpn_rd_pretty); + XFREE(MTYPE_BGP_NAME, bgp->vpn_policy[afi].tovpn_rd_pretty); UNSET_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET); } @@ -9199,6 +9435,8 @@ DEFPY(af_label_vpn_export_allocation_mode, bool old_per_nexthop, new_per_nexthop; afi = vpn_policy_getafi(vty, bgp, false); + if (afi == AFI_MAX) + return CMD_WARNING_CONFIG_FAILED; old_per_nexthop = !!CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_LABEL_PER_NEXTHOP); @@ -9251,7 +9489,7 @@ DEFPY (af_label_vpn_export, "Automatically assign a label\n") { VTY_DECLVAR_CONTEXT(bgp, bgp); - mpls_label_t label = MPLS_LABEL_NONE; + mpls_label_t label = (mpls_label_t)label_val; afi_t afi; int idx = 0; bool yes = true; @@ -9259,24 +9497,28 @@ DEFPY (af_label_vpn_export, if (argv_find(argv, argc, "no", &idx)) yes = false; - /* If "no ...", squash trailing parameter */ - if (!yes) - label_auto = NULL; - - if (yes) { - if (!label_auto) - label = label_val; /* parser should force unsigned */ - } - afi = vpn_policy_getafi(vty, bgp, false); if (afi == AFI_MAX) return CMD_WARNING_CONFIG_FAILED; - - if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags, - BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) - /* no change */ - return CMD_SUCCESS; + if (yes) { + if (label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags, + BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) + /* no change */ + return CMD_SUCCESS; + if (!label_auto && label == bgp->vpn_policy[afi].tovpn_label) + /* no change */ + return CMD_SUCCESS; + } else { + if (label_auto && !CHECK_FLAG(bgp->vpn_policy[afi].flags, + BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) + /* no match */ + return CMD_WARNING_CONFIG_FAILED; + if (!label_auto && label_val && + label != bgp->vpn_policy[afi].tovpn_label) + /* no change */ + return CMD_WARNING_CONFIG_FAILED; + } /* * pre-change: un-export vpn routes (vpn->vrf routes unaffected) @@ -9284,9 +9526,16 @@ DEFPY (af_label_vpn_export, vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi, bgp_get_default(), bgp); - if (!label_auto && CHECK_FLAG(bgp->vpn_policy[afi].flags, - BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) { + if (CHECK_FLAG(bgp->vpn_policy[afi].flags, + BGP_VPN_POLICY_TOVPN_LABEL_MANUAL_REG)) { + bgp_zebra_release_label_range(bgp->vpn_policy[afi].tovpn_label, + bgp->vpn_policy[afi].tovpn_label); + UNSET_FLAG(bgp->vpn_policy[afi].flags, + BGP_VPN_POLICY_TOVPN_LABEL_MANUAL_REG); + } else if (CHECK_FLAG(bgp->vpn_policy[afi].flags, + BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) { + /* release any previous auto label */ if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) { /* @@ -9303,16 +9552,32 @@ DEFPY (af_label_vpn_export, &bgp->vpn_policy[afi], bgp->vpn_policy[afi].tovpn_label); } - UNSET_FLAG(bgp->vpn_policy[afi].flags, - BGP_VPN_POLICY_TOVPN_LABEL_AUTO); } - bgp->vpn_policy[afi].tovpn_label = label; - if (label_auto) { - SET_FLAG(bgp->vpn_policy[afi].flags, - BGP_VPN_POLICY_TOVPN_LABEL_AUTO); - bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi], - vpn_leak_label_callback); + if (yes) { + if (label_auto) { + SET_FLAG(bgp->vpn_policy[afi].flags, + BGP_VPN_POLICY_TOVPN_LABEL_AUTO); + /* fetch a label */ + bgp->vpn_policy[afi].tovpn_label = MPLS_LABEL_NONE; + bgp_lp_get(LP_TYPE_VRF, &bgp->vpn_policy[afi], + vpn_leak_label_callback); + } else { + bgp->vpn_policy[afi].tovpn_label = label; + UNSET_FLAG(bgp->vpn_policy[afi].flags, + BGP_VPN_POLICY_TOVPN_LABEL_AUTO); + if (bgp->vpn_policy[afi].tovpn_label >= + MPLS_LABEL_UNRESERVED_MIN && + bgp_zebra_request_label_range(bgp->vpn_policy[afi] + .tovpn_label, + 1, false)) + SET_FLAG(bgp->vpn_policy[afi].flags, + BGP_VPN_POLICY_TOVPN_LABEL_MANUAL_REG); + } + } else { + UNSET_FLAG(bgp->vpn_policy[afi].flags, + BGP_VPN_POLICY_TOVPN_LABEL_AUTO); + bgp->vpn_policy[afi].tovpn_label = MPLS_LABEL_NONE; } /* post-change: re-export vpn routes */ @@ -9932,6 +10197,7 @@ DEFPY (bgp_imexport_vpn, bool yes = true; int flag; enum vpn_policy_direction dir; + struct bgp *bgp_default = bgp_get_default(); if (argv_find(argv, argc, "no", &idx)) yes = false; @@ -9967,14 +10233,18 @@ DEFPY (bgp_imexport_vpn, SET_FLAG(bgp->af_flags[afi][safi], flag); if (!previous_state) { /* trigger export current vrf */ - vpn_leak_postchange(dir, afi, bgp_get_default(), bgp); + vpn_leak_postchange(dir, afi, bgp_default, bgp); } } else { if (previous_state) { /* trigger un-export current vrf */ - vpn_leak_prechange(dir, afi, bgp_get_default(), bgp); + vpn_leak_prechange(dir, afi, bgp_default, bgp); } UNSET_FLAG(bgp->af_flags[afi][safi], flag); + if (previous_state && bgp_default && + !CHECK_FLAG(bgp_default->af_flags[afi][SAFI_MPLS_VPN], + BGP_VPNVX_RETAIN_ROUTE_TARGET_ALL)) + vpn_leak_no_retain(bgp, bgp_default, afi); } hook_call(bgp_snmp_init_stats, bgp); @@ -10358,7 +10628,7 @@ static int bgp_clear_prefix(struct vty *vty, const char *view_name, /* one clear bgp command to rule them all */ DEFUN (clear_ip_bgp_all, clear_ip_bgp_all_cmd, - "clear [ip] bgp [ VIEWVRFNAME] [ []] <*|A.B.C.D$neighbor|X:X::X:X$neighbor|WORD$neighbor|ASNUM|external|peer-group PGNAME> []|in [prefix-filter]|out|message-stats>]", + "clear [ip] bgp [ VIEWVRFNAME] [ []] <*|A.B.C.D$neighbor|X:X::X:X$neighbor|WORD$neighbor|ASNUM|external|peer-group PGNAME> []|in [prefix-filter]|out|message-stats|capabilities>]", CLEAR_STR IP_STR BGP_STR @@ -10381,7 +10651,8 @@ DEFUN (clear_ip_bgp_all, BGP_SOFT_IN_STR "Push out prefix-list ORF and do inbound soft reconfig\n" BGP_SOFT_OUT_STR - "Reset message statistics\n") + "Reset message statistics\n" + "Resend capabilities\n") { char *vrf = NULL; @@ -10438,7 +10709,7 @@ DEFUN (clear_ip_bgp_all, clr_sort = clear_external; } - /* []|in [prefix-filter]|out|message-stats>] */ + /* []|in [prefix-filter]|out|message-stats|capabilities>] */ if (argv_find(argv, argc, "soft", &idx)) { if (argv_find(argv, argc, "in", &idx) || argv_find(argv, argc, "out", &idx)) @@ -10455,6 +10726,8 @@ DEFUN (clear_ip_bgp_all, clr_type = BGP_CLEAR_SOFT_OUT; } else if (argv_find(argv, argc, "message-stats", &idx)) { clr_type = BGP_CLEAR_MESSAGE_STATS; + } else if (argv_find(argv, argc, "capabilities", &idx)) { + clr_type = BGP_CLEAR_CAPABILITIES; } else clr_type = BGP_CLEAR_SOFT_NONE; @@ -10587,7 +10860,7 @@ static inline void calc_peers_cfgd_estbd(struct bgp *bgp, int *peers_cfgd, if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE)) continue; (*peers_cfgd)++; - if (peer_established(peer)) + if (peer_established(peer->connection)) (*peers_estbd)++; } } @@ -10866,6 +11139,29 @@ DEFUN (show_bgp_memory, memstrbuf, sizeof(memstrbuf), count * sizeof(struct bgp_path_info_extra))); + count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA_EVPN); + if (count) + vty_out(vty, "%ld BGP extra info for EVPN, using %s of memory\n", + count, + mtype_memstr(memstrbuf, sizeof(memstrbuf), + count * sizeof(struct bgp_path_info_extra_evpn))); + + count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA_FS); + if (count) + vty_out(vty, + "%ld BGP extra info for flowspec, using %s of memory\n", + count, + mtype_memstr(memstrbuf, sizeof(memstrbuf), + count * sizeof(struct bgp_path_info_extra_fs))); + + count = mtype_stats_alloc(MTYPE_BGP_ROUTE_EXTRA_VRFLEAK); + if (count) + vty_out(vty, + "%ld BGP extra info for vrf leaking, using %s of memory\n", + count, + mtype_memstr(memstrbuf, sizeof(memstrbuf), + count * sizeof(struct bgp_path_info_extra_vrfleak))); + if ((count = mtype_stats_alloc(MTYPE_BGP_STATIC))) vty_out(vty, "%ld Static routes, using %s of memory\n", count, mtype_memstr(memstrbuf, sizeof(memstrbuf), @@ -11044,11 +11340,9 @@ static void bgp_show_peer_reset(struct vty * vty, struct peer *peer, msgbuf, sizeof(msgbuf), (uint8_t *)peer->notify.data, peer->notify.length); - if (msg_str) - json_object_string_add( - json_peer, - "lastShutdownDescription", - msg_str); + json_object_string_add(json_peer, + "lastShutdownDescription", + msg_str); } } @@ -11088,7 +11382,8 @@ static void bgp_show_peer_reset(struct vty * vty, struct peer *peer, static inline bool bgp_has_peer_failed(struct peer *peer, afi_t afi, safi_t safi) { - return ((!peer_established(peer)) || !peer->afc_recv[afi][safi]); + return ((!peer_established(peer->connection)) || + !peer->afc_recv[afi][safi]); } static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp, @@ -11115,7 +11410,7 @@ static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp, peer->dropped); peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN, use_json, json_peer); - if (peer_established(peer)) + if (peer_established(peer->connection)) json_object_string_add(json_peer, "lastResetDueTo", "AFI/SAFI Not Negotiated"); else @@ -11138,7 +11433,7 @@ static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp, peer->dropped, peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN, 0, NULL)); - if (peer_established(peer)) + if (peer_established(peer->connection)) vty_out(vty, " AFI/SAFI Not Negotiated\n"); else bgp_show_peer_reset(vty, peer, NULL, @@ -11364,8 +11659,9 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, : bgp->name); } else { vty_out(vty, - "BGP router identifier %pI4, local AS number %s vrf-id %d", + "BGP router identifier %pI4, local AS number %s %s vrf-id %d", &bgp->router_id, bgp->as_pretty, + bgp->name_pretty, bgp->vrf_id == VRF_UNKNOWN ? -1 : (int)bgp->vrf_id); @@ -11613,12 +11909,16 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, PEER_TOTAL_TX(peer)); atomic_size_t outq_count, inq_count; - outq_count = atomic_load_explicit( - &peer->obuf->count, - memory_order_relaxed); - inq_count = atomic_load_explicit( - &peer->ibuf->count, - memory_order_relaxed); + outq_count = + atomic_load_explicit(&peer->connection + ->obuf + ->count, + memory_order_relaxed); + inq_count = + atomic_load_explicit(&peer->connection + ->ibuf + ->count, + memory_order_relaxed); json_object_int_add( json_peer, "tableVersion", @@ -11654,7 +11954,8 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, json_object_string_add( json_peer, "state", lookup_msg(bgp_status_msg, - peer->status, NULL)); + peer->connection->status, + NULL)); else if (CHECK_FLAG( peer->sflags, PEER_STATUS_PREFIX_OVERFLOW)) @@ -11665,7 +11966,8 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, json_object_string_add( json_peer, "state", lookup_msg(bgp_status_msg, - peer->status, NULL)); + peer->connection->status, + NULL)); /* BGP peer state */ if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN) @@ -11719,10 +12021,10 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, if (peer->conf_if) json_object_string_add(json_peer, "idType", "interface"); - else if (peer->su.sa.sa_family == AF_INET) + else if (peer->connection->su.sa.sa_family == AF_INET) json_object_string_add(json_peer, "idType", "ipv4"); - else if (peer->su.sa.sa_family == AF_INET6) + else if (peer->connection->su.sa.sa_family == AF_INET6) json_object_string_add(json_peer, "idType", "ipv6"); json_object_object_add(json_peers, peer->host, @@ -11781,14 +12083,18 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, " "); atomic_size_t outq_count, inq_count; - outq_count = atomic_load_explicit( - &peer->obuf->count, - memory_order_relaxed); - inq_count = atomic_load_explicit( - &peer->ibuf->count, - memory_order_relaxed); - - vty_out(vty, "4 "); + outq_count = + atomic_load_explicit(&peer->connection + ->obuf + ->count, + memory_order_relaxed); + inq_count = + atomic_load_explicit(&peer->connection + ->ibuf + ->count, + memory_order_relaxed); + + vty_out(vty, "4"); vty_out(vty, ASN_FORMAT_SPACE(bgp->asnotation), &peer->as); if (show_wide) @@ -11809,7 +12115,7 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN, 0, NULL)); - if (peer_established(peer)) { + if (peer_established(peer->connection)) { if (peer->afc_recv[afi][safi]) { if (CHECK_FLAG( bgp->flags, @@ -11858,20 +12164,31 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, else vty_out(vty, " %12s", lookup_msg(bgp_status_msg, - peer->status, NULL)); + peer->connection + ->status, + NULL)); vty_out(vty, " %8u", 0); } /* Make sure `Desc` column is the lastest in * the output. + * If the description is not set, try + * to print the software version if the + * capability is enabled and received. */ if (peer->desc) vty_out(vty, " %s", bgp_peer_description_stripped( peer->desc, show_wide ? 64 : 20)); - else + else if (peer->soft_version) { + vty_out(vty, " %s", + bgp_peer_description_stripped( + peer->soft_version, + show_wide ? 64 : 20)); + } else { vty_out(vty, " N/A"); + } vty_out(vty, "\n"); } @@ -11961,12 +12278,10 @@ static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi, safi, true)); } else { - vty_out(vty, - "\n%s Summary (%s):\n", + vty_out(vty, "\n%s Summary:\n", get_afi_safi_str(afi, safi, - false), - bgp->name_pretty); + false)); } } bgp_show_summary(vty, bgp, afi, safi, fpeer, @@ -12254,9 +12569,9 @@ static void bgp_show_neighnor_graceful_restart_flags(struct vty *vty, bool rbit = false; bool nbit = false; - if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) - && (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) - && (peer_established(p))) { + if (CHECK_FLAG(p->cap, PEER_CAP_RESTART_ADV) && + (CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) && + (peer_established(p->connection))) { rbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV); nbit = CHECK_FLAG(p->cap, PEER_CAP_GRACEFUL_RESTART_N_BIT_RCV); } @@ -12279,9 +12594,8 @@ static void bgp_show_neighbor_graceful_restart_remote_mode(struct vty *vty, if (!json) vty_out(vty, "\n Remote GR Mode: "); - if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) - && (peer_established(peer))) { - + if (CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) && + (peer_established(peer->connection))) { if ((peer->nsf_af_count == 0) && !CHECK_FLAG(peer->cap, PEER_CAP_RESTART_RCV)) { @@ -12443,12 +12757,15 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi( if (json) { json_object_int_add(json_timer, "stalePathTimer", peer->bgp->stalepath_time); + json_object_int_add(json_timer, "llgrStaleTime", + peer->llgr[afi][safi].stale_time); - if (peer->t_gr_stale != NULL) { + if (peer->connection->t_gr_stale != NULL) { json_object_int_add(json_timer, "stalePathTimerRemaining", event_timer_remain_second( - peer->t_gr_stale)); + peer->connection + ->t_gr_stale)); } /* Display Configured Selection @@ -12478,11 +12795,11 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi( " Configured Stale Path Time(sec): %u\n", peer->bgp->stalepath_time); - if (peer->t_gr_stale != NULL) + if (peer->connection->t_gr_stale != NULL) vty_out(vty, " Stale Path Remaining(sec): %ld\n", event_timer_remain_second( - peer->t_gr_stale)); + peer->connection->t_gr_stale)); /* Display Configured Selection * Deferral only when when * Gr mode is enabled. @@ -12492,6 +12809,9 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi( " Configured Selection Deferral Time(sec): %u\n", peer->bgp->select_defer_time); + vty_out(vty, " LLGR Stale Path Time(sec): %u\n", + peer->llgr[afi][safi].stale_time); + if (peer->bgp->gr_info[afi][safi].t_select_deferral != NULL) vty_out(vty, @@ -12523,14 +12843,16 @@ static void bgp_show_neighbor_graceful_restart_time(struct vty *vty, json_object_int_add(json_timer, "configuredRestartTimer", p->bgp->restart_time); + json_object_int_add(json_timer, "configuredLlgrStaleTime", + p->bgp->llgr_stale_time); json_object_int_add(json_timer, "receivedRestartTimer", p->v_gr_restart); - if (p->t_gr_restart != NULL) - json_object_int_add( - json_timer, "restartTimerRemaining", - event_timer_remain_second(p->t_gr_restart)); + if (p->connection->t_gr_restart != NULL) + json_object_int_add(json_timer, "restartTimerRemaining", + event_timer_remain_second( + p->connection->t_gr_restart)); json_object_object_add(json, "timers", json_timer); } else { @@ -12541,12 +12863,16 @@ static void bgp_show_neighbor_graceful_restart_time(struct vty *vty, vty_out(vty, " Received Restart Time(sec): %u\n", p->v_gr_restart); - if (p->t_gr_restart != NULL) + vty_out(vty, " Configured LLGR Stale Path Time(sec): %u\n", + p->bgp->llgr_stale_time); + if (p->connection->t_gr_restart != NULL) vty_out(vty, " Restart Time Remaining(sec): %ld\n", - event_timer_remain_second(p->t_gr_restart)); - if (p->t_gr_restart != NULL) { + event_timer_remain_second( + p->connection->t_gr_restart)); + if (p->connection->t_gr_restart != NULL) { vty_out(vty, " Restart Time Remaining(sec): %ld\n", - event_timer_remain_second(p->t_gr_restart)); + event_timer_remain_second( + p->connection->t_gr_restart)); } } } @@ -12564,10 +12890,10 @@ static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p, if (p->conf_if) { if (json) json_object_string_addf(json, "neighborAddr", "%pSU", - &p->su); + &p->connection->su); else vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if, - &p->su); + &p->connection->su); } else { snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag, p->host); @@ -12593,7 +12919,6 @@ static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi, int orf_pfx_count; json_object *json_af = NULL; json_object *json_prefA = NULL; - json_object *json_prefB = NULL; json_object *json_addr = NULL; json_object *json_advmap = NULL; @@ -12636,37 +12961,13 @@ static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi, json_prefA); } - if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV) - || CHECK_FLAG(p->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_SM_OLD_RCV) - || CHECK_FLAG(p->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_RM_ADV) - || CHECK_FLAG(p->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) { - json_object_int_add(json_af, "orfOldType", - ORF_TYPE_PREFIX_OLD); - json_prefB = json_object_new_object(); - bgp_show_peer_afi_orf_cap( - vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV, - PEER_CAP_ORF_PREFIX_RM_ADV, - PEER_CAP_ORF_PREFIX_SM_OLD_RCV, - PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, - json_prefB); - json_object_object_add(json_af, "orfOldPrefixList", - json_prefB); - } - - if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV) - || CHECK_FLAG(p->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_SM_RCV) - || CHECK_FLAG(p->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_SM_OLD_RCV) - || CHECK_FLAG(p->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_RM_ADV) - || CHECK_FLAG(p->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_RM_RCV) - || CHECK_FLAG(p->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) + if (CHECK_FLAG(p->af_cap[afi][safi], + PEER_CAP_ORF_PREFIX_SM_ADV) || + CHECK_FLAG(p->af_cap[afi][safi], + PEER_CAP_ORF_PREFIX_SM_RCV) || + CHECK_FLAG(p->af_cap[afi][safi], + PEER_CAP_ORF_PREFIX_RM_ADV) || + CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_RCV)) json_object_object_add(json_addr, "afDependentCap", json_af); else @@ -12953,17 +13254,13 @@ static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi, } else { vty_out(vty, " Not part of any update group\n"); } - if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV) - || CHECK_FLAG(p->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_SM_RCV) - || CHECK_FLAG(p->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_SM_OLD_RCV) - || CHECK_FLAG(p->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_RM_ADV) - || CHECK_FLAG(p->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_RM_RCV) - || CHECK_FLAG(p->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) + if (CHECK_FLAG(p->af_cap[afi][safi], + PEER_CAP_ORF_PREFIX_SM_ADV) || + CHECK_FLAG(p->af_cap[afi][safi], + PEER_CAP_ORF_PREFIX_SM_RCV) || + CHECK_FLAG(p->af_cap[afi][safi], + PEER_CAP_ORF_PREFIX_RM_ADV) || + CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_RCV)) vty_out(vty, " AF-dependant capabilities:\n"); if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV) @@ -12982,22 +13279,6 @@ static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi, PEER_CAP_ORF_PREFIX_SM_RCV, PEER_CAP_ORF_PREFIX_RM_RCV, use_json, NULL); } - if (CHECK_FLAG(p->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV) - || CHECK_FLAG(p->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_SM_OLD_RCV) - || CHECK_FLAG(p->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_RM_ADV) - || CHECK_FLAG(p->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_RM_OLD_RCV)) { - vty_out(vty, - " Outbound Route Filter (ORF) type (%d) Prefix-list:\n", - ORF_TYPE_PREFIX_OLD); - bgp_show_peer_afi_orf_cap( - vty, p, afi, safi, PEER_CAP_ORF_PREFIX_SM_ADV, - PEER_CAP_ORF_PREFIX_RM_ADV, - PEER_CAP_ORF_PREFIX_SM_OLD_RCV, - PEER_CAP_ORF_PREFIX_RM_OLD_RCV, use_json, NULL); - } snprintf(orf_pfx_name, sizeof(orf_pfx_name), "%s.%d.%d", p->host, afi, safi); @@ -13280,19 +13561,19 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, if (!use_json) { if (p->conf_if) /* Configured interface name. */ vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if, - &p->su); + &p->connection->su); else /* Configured IP address. */ vty_out(vty, "BGP neighbor is %s%s, ", dn_flag, p->host); } if (use_json) { - if (p->conf_if && BGP_PEER_SU_UNSPEC(p)) + if (p->conf_if && BGP_CONNECTION_SU_UNSPEC(p->connection)) json_object_string_add(json_neigh, "bgpNeighborAddr", "none"); - else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p)) + else if (p->conf_if && !BGP_CONNECTION_SU_UNSPEC(p->connection)) json_object_string_addf(json_neigh, "bgpNeighborAddr", - "%pSU", &p->su); + "%pSU", &p->connection->su); asn_asn2json(json_neigh, "remoteAs", p->as, bgp->asnotation); @@ -13421,7 +13702,8 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, if (dn_flag[0]) { struct prefix prefix, *range = NULL; - if (sockunion2hostprefix(&(p->su), &prefix)) + if (sockunion2hostprefix(&p->connection->su, + &prefix)) range = peer_group_lookup_dynamic_neighbor_range( p->group, &prefix); @@ -13440,7 +13722,8 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, if (dn_flag[0]) { struct prefix prefix, *range = NULL; - if (sockunion2hostprefix(&(p->su), &prefix)) + if (sockunion2hostprefix(&p->connection->su, + &prefix)) range = peer_group_lookup_dynamic_neighbor_range( p->group, &prefix); @@ -13474,11 +13757,11 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, "nbrCommonAdmin"); /* Status. */ - json_object_string_add( - json_neigh, "bgpState", - lookup_msg(bgp_status_msg, p->status, NULL)); + json_object_string_add(json_neigh, "bgpState", + lookup_msg(bgp_status_msg, + p->connection->status, NULL)); - if (peer_established(p)) { + if (peer_established(p->connection)) { time_t uptime; uptime = monotime(NULL); @@ -13494,9 +13777,7 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, json_object_int_add(json_neigh, "bgpTimerUpEstablishedEpoch", epoch_tbuf); - } - - else if (p->status == Active) { + } else if (p->connection->status == Active) { if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE)) json_object_string_add(json_neigh, "bgpStateIs", "passive"); @@ -13556,13 +13837,10 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, } /* Configured and Synced tcp-mss value for peer */ - if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) { - sync_tcp_mss = sockopt_tcp_mss_get(p->fd); - json_object_int_add(json_neigh, "bgpTcpMssConfigured", - p->tcp_mss); - json_object_int_add(json_neigh, "bgpTcpMssSynced", - sync_tcp_mss); - } + sync_tcp_mss = sockopt_tcp_mss_get(p->connection->fd); + json_object_int_add(json_neigh, "bgpTcpMssConfigured", + p->tcp_mss); + json_object_int_add(json_neigh, "bgpTcpMssSynced", sync_tcp_mss); /* Extended Optional Parameters Length for BGP OPEN Message */ if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p)) @@ -13602,14 +13880,13 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, /* Status. */ vty_out(vty, " BGP state = %s", - lookup_msg(bgp_status_msg, p->status, NULL)); + lookup_msg(bgp_status_msg, p->connection->status, NULL)); - if (peer_established(p)) + if (peer_established(p->connection)) vty_out(vty, ", up for %8s", peer_uptime(p->uptime, timebuf, BGP_UPTIME_LEN, 0, NULL)); - - else if (p->status == Active) { + else if (p->connection->status == Active) { if (CHECK_FLAG(p->flags, PEER_FLAG_PASSIVE)) vty_out(vty, " (passive)"); else if (CHECK_FLAG(p->sflags, PEER_STATUS_NSF_WAIT)) @@ -13643,11 +13920,9 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, p->delayopen); /* Configured and synced tcp-mss value for peer */ - if (CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS)) { - sync_tcp_mss = sockopt_tcp_mss_get(p->fd); - vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss); - vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss); - } + sync_tcp_mss = sockopt_tcp_mss_get(p->connection->fd); + vty_out(vty, " Configured tcp-mss is %d", p->tcp_mss); + vty_out(vty, ", synced tcp-mss is %d\n", sync_tcp_mss); /* Extended Optional Parameters Length for BGP OPEN Message */ if (BGP_OPEN_EXT_OPT_PARAMS_CAPABLE(p)) @@ -13665,7 +13940,7 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, bgp->t_condition_check)); } /* Capability. */ - if (peer_established(p) && + if (peer_established(p->connection) && (p->cap || peer_afc_advertised(p) || peer_afc_received(p))) { if (use_json) { json_object *json_cap = NULL; @@ -13949,46 +14224,19 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, /* Route Refresh */ if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) || - CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) || - CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) { + CHECK_FLAG(p->cap, PEER_CAP_REFRESH_RCV)) { if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) && - (CHECK_FLAG(p->cap, - PEER_CAP_REFRESH_NEW_RCV) || - CHECK_FLAG(p->cap, - PEER_CAP_REFRESH_OLD_RCV))) { - if (CHECK_FLAG( - p->cap, - PEER_CAP_REFRESH_OLD_RCV) && - CHECK_FLAG( - p->cap, - PEER_CAP_REFRESH_NEW_RCV)) - json_object_string_add( - json_cap, - "routeRefresh", - "advertisedAndReceivedOldNew"); - else { - if (CHECK_FLAG( - p->cap, - PEER_CAP_REFRESH_OLD_RCV)) - json_object_string_add( - json_cap, - "routeRefresh", - "advertisedAndReceivedOld"); - else - json_object_string_add( - json_cap, - "routeRefresh", - "advertisedAndReceivedNew"); - } - } else if (CHECK_FLAG(p->cap, - PEER_CAP_REFRESH_ADV)) + CHECK_FLAG(p->cap, PEER_CAP_REFRESH_RCV)) + json_object_string_add(json_cap, + "routeRefresh", + "advertisedAndReceived"); + else if (CHECK_FLAG(p->cap, + PEER_CAP_REFRESH_ADV)) json_object_string_add(json_cap, "routeRefresh", "advertised"); else if (CHECK_FLAG(p->cap, - PEER_CAP_REFRESH_NEW_RCV) || - CHECK_FLAG(p->cap, - PEER_CAP_REFRESH_OLD_RCV)) + PEER_CAP_REFRESH_RCV)) json_object_string_add(json_cap, "routeRefresh", "received"); @@ -14390,33 +14638,16 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, /* Route Refresh */ if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) || - CHECK_FLAG(p->cap, PEER_CAP_REFRESH_NEW_RCV) || - CHECK_FLAG(p->cap, PEER_CAP_REFRESH_OLD_RCV)) { + CHECK_FLAG(p->cap, PEER_CAP_REFRESH_RCV)) { vty_out(vty, " Route refresh:"); if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV)) vty_out(vty, " advertised"); - if (CHECK_FLAG(p->cap, - PEER_CAP_REFRESH_NEW_RCV) || - CHECK_FLAG(p->cap, - PEER_CAP_REFRESH_OLD_RCV)) - vty_out(vty, " %sreceived(%s)", + if (CHECK_FLAG(p->cap, PEER_CAP_REFRESH_RCV)) + vty_out(vty, " %sreceived", CHECK_FLAG(p->cap, PEER_CAP_REFRESH_ADV) ? "and " - : "", - (CHECK_FLAG( - p->cap, - PEER_CAP_REFRESH_OLD_RCV) && - CHECK_FLAG( - p->cap, - PEER_CAP_REFRESH_NEW_RCV)) - ? "old & new" - : CHECK_FLAG( - p->cap, - PEER_CAP_REFRESH_OLD_RCV) - ? "old" - : "new"); - + : ""); vty_out(vty, "\n"); } @@ -14566,7 +14797,7 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, json_grace_send = json_object_new_object(); json_grace_recv = json_object_new_object(); - if ((peer_established(p)) && + if ((peer_established(p->connection)) && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) { FOREACH_AFI_SAFI (afi, safi) { if (CHECK_FLAG(p->af_sflags[afi][safi], @@ -14595,26 +14826,27 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, json_grace_recv); - if (p->t_gr_restart) - json_object_int_add( - json_grace, "gracefulRestartTimerMsecs", - event_timer_remain_second(p->t_gr_restart) * - 1000); + if (p->connection->t_gr_restart) + json_object_int_add(json_grace, + "gracefulRestartTimerMsecs", + event_timer_remain_second( + p->connection->t_gr_restart) * + 1000); - if (p->t_gr_stale) - json_object_int_add( - json_grace, "gracefulStalepathTimerMsecs", - event_timer_remain_second(p->t_gr_stale) * - 1000); + if (p->connection->t_gr_stale) + json_object_int_add(json_grace, + "gracefulStalepathTimerMsecs", + event_timer_remain_second( + p->connection->t_gr_stale) * + 1000); /* more gr info in new format */ BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json_grace); json_object_object_add(json_neigh, "gracefulRestartInfo", json_grace); } else { vty_out(vty, " Graceful restart information:\n"); - if ((peer_established(p)) && + if ((peer_established(p->connection)) && CHECK_FLAG(p->cap, PEER_CAP_RESTART_RCV)) { - vty_out(vty, " End-of-RIB send: "); FOREACH_AFI_SAFI (afi, safi) { if (CHECK_FLAG(p->af_sflags[afi][safi], @@ -14642,15 +14874,17 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, vty_out(vty, "\n"); } - if (p->t_gr_restart) + if (p->connection->t_gr_restart) vty_out(vty, " The remaining time of restart timer is %ld\n", - event_timer_remain_second(p->t_gr_restart)); + event_timer_remain_second( + p->connection->t_gr_restart)); - if (p->t_gr_stale) + if (p->connection->t_gr_stale) vty_out(vty, " The remaining time of stalepath timer is %ld\n", - event_timer_remain_second(p->t_gr_stale)); + event_timer_remain_second( + p->connection->t_gr_stale)); /* more gr info in new format */ BGP_SHOW_PEER_GR_CAPABILITY(vty, p, NULL); @@ -14662,9 +14896,9 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, /* Packet counts. */ atomic_size_t outq_count, inq_count; - outq_count = atomic_load_explicit(&p->obuf->count, + outq_count = atomic_load_explicit(&p->connection->obuf->count, memory_order_relaxed); - inq_count = atomic_load_explicit(&p->ibuf->count, + inq_count = atomic_load_explicit(&p->connection->ibuf->count, memory_order_relaxed); json_object_int_add(json_stat, "depthInq", @@ -14715,9 +14949,9 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, notify_out, notify_in, update_out, update_in, keepalive_out, keepalive_in, refresh_out, refresh_in, dynamic_cap_out, dynamic_cap_in; - outq_count = atomic_load_explicit(&p->obuf->count, + outq_count = atomic_load_explicit(&p->connection->obuf->count, memory_order_relaxed); - inq_count = atomic_load_explicit(&p->ibuf->count, + inq_count = atomic_load_explicit(&p->connection->ibuf->count, memory_order_relaxed); open_out = atomic_load_explicit(&p->open_out, memory_order_relaxed); @@ -14849,15 +15083,15 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, BGP_UPTIME_LEN, 0, NULL)); bgp_show_peer_reset(vty, p, NULL, false); - if (p->last_reset_cause_size) { - msg = p->last_reset_cause; + if (p->last_reset_cause) { + msg = p->last_reset_cause->data; vty_out(vty, " Message received that caused BGP to send a NOTIFICATION:\n "); - for (i = 1; i <= p->last_reset_cause_size; + for (i = 1; i <= p->last_reset_cause->size; i++) { vty_out(vty, "%02X", *msg++); - if (i != p->last_reset_cause_size) { + if (i != p->last_reset_cause->size) { if (i % 16 == 0) { vty_out(vty, "\n "); } else if (i % 4 == 0) { @@ -14878,21 +15112,22 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, vty_out(vty, " Peer had exceeded the max. no. of prefixes configured.\n"); - if (p->t_pmax_restart) { + if (p->connection->t_pmax_restart) { if (use_json) { json_object_boolean_true_add( json_neigh, "reducePrefixNumFrom"); json_object_int_add(json_neigh, "restartInTimerMsec", event_timer_remain_second( - p->t_pmax_restart) * + p->connection + ->t_pmax_restart) * 1000); } else vty_out(vty, " Reduce the no. of prefix from %s, will restart in %ld seconds\n", p->host, event_timer_remain_second( - p->t_pmax_restart)); + p->connection->t_pmax_restart)); } else { if (use_json) json_object_boolean_true_add( @@ -15029,7 +15264,7 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, if (use_json) { json_object_int_add(json_neigh, "connectRetryTimer", p->v_connect); - if (peer_established(p)) { + if (peer_established(p->connection)) { json_object_int_add(json_neigh, "estimatedRttInMsecs", p->rtt); if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN)) { @@ -15041,32 +15276,37 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, p->rtt_keepalive_rcv); } } - if (p->t_start) - json_object_int_add( - json_neigh, "nextStartTimerDueInMsecs", - event_timer_remain_second(p->t_start) * 1000); - if (p->t_connect) - json_object_int_add( - json_neigh, "nextConnectTimerDueInMsecs", - event_timer_remain_second(p->t_connect) * 1000); - if (p->t_routeadv) { + if (p->connection->t_start) + json_object_int_add(json_neigh, + "nextStartTimerDueInMsecs", + event_timer_remain_second( + p->connection->t_start) * + 1000); + if (p->connection->t_connect) + json_object_int_add(json_neigh, + "nextConnectTimerDueInMsecs", + event_timer_remain_second( + p->connection->t_connect) * + 1000); + if (p->connection->t_routeadv) { json_object_int_add(json_neigh, "mraiInterval", p->v_routeadv); - json_object_int_add( - json_neigh, "mraiTimerExpireInMsecs", - event_timer_remain_second(p->t_routeadv) * - 1000); + json_object_int_add(json_neigh, "mraiTimerExpireInMsecs", + event_timer_remain_second( + p->connection->t_routeadv) * + 1000); } if (p->password) json_object_int_add(json_neigh, "authenticationEnabled", 1); - if (p->t_read) + if (p->connection->t_read) json_object_string_add(json_neigh, "readThread", "on"); else json_object_string_add(json_neigh, "readThread", "off"); - if (CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON)) + if (CHECK_FLAG(p->connection->thread_flags, + PEER_THREAD_WRITES_ON)) json_object_string_add(json_neigh, "writeThread", "on"); else json_object_string_add(json_neigh, "writeThread", @@ -15074,7 +15314,7 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, } else { vty_out(vty, "BGP Connect Retry Timer in Seconds: %d\n", p->v_connect); - if (peer_established(p)) { + if (peer_established(p->connection)) { vty_out(vty, "Estimated round trip time: %d ms\n", p->rtt); if (CHECK_FLAG(p->flags, PEER_FLAG_RTT_SHUTDOWN)) @@ -15082,25 +15322,30 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json, "Shutdown when RTT > %dms, count > %u\n", p->rtt_expected, p->rtt_keepalive_rcv); } - if (p->t_start) + if (p->connection->t_start) vty_out(vty, "Next start timer due in %ld seconds\n", - event_timer_remain_second(p->t_start)); - if (p->t_connect) + event_timer_remain_second( + p->connection->t_start)); + if (p->connection->t_connect) vty_out(vty, "Next connect timer due in %ld seconds\n", - event_timer_remain_second(p->t_connect)); - if (p->t_routeadv) + event_timer_remain_second( + p->connection->t_connect)); + if (p->connection->t_routeadv) vty_out(vty, "MRAI (interval %u) timer expires in %ld seconds\n", p->v_routeadv, - event_timer_remain_second(p->t_routeadv)); + event_timer_remain_second( + p->connection->t_routeadv)); if (p->password) vty_out(vty, "Peer Authentication Enabled\n"); vty_out(vty, "Read thread: %s Write thread: %s FD used: %d\n", - p->t_read ? "on" : "off", - CHECK_FLAG(p->thread_flags, PEER_THREAD_WRITES_ON) + p->connection->t_read ? "on" : "off", + CHECK_FLAG(p->connection->thread_flags, + PEER_THREAD_WRITES_ON) ? "on" - : "off", p->fd); + : "off", + p->connection->fd); } if (p->notify.code == BGP_NOTIFY_OPEN_ERR @@ -15163,7 +15408,7 @@ static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp, json_neighbor); } } else { - if (sockunion_same(&peer->su, su)) { + if (sockunion_same(&peer->connection->su, su)) { found = true; bgp_show_peer_gr_status(vty, peer, json_neighbor); @@ -15233,7 +15478,7 @@ static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp, json); } } else { - if (sockunion_same(&peer->su, su)) { + if (sockunion_same(&peer->connection->su, su)) { find = 1; bgp_show_peer(vty, peer, use_json, json); @@ -15255,7 +15500,9 @@ static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp, break; } } else { - if (sockunion_same(&peer->su, su)) { + if (sockunion_same(&peer->connection + ->su, + su)) { find = 1; bgp_show_peer(vty, peer, use_json, json); @@ -16364,8 +16611,10 @@ static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group, PEER_STATUS_PREFIX_OVERFLOW)) peer_status = "Idle (PfxCt)"; else - peer_status = lookup_msg(bgp_status_msg, - peer->status, NULL); + peer_status = + lookup_msg(bgp_status_msg, + peer->connection->status, + NULL); dynamic = peer_dynamic_neighbor(peer); @@ -16655,10 +16904,11 @@ ALIAS_HIDDEN( DEFUN (bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_cmd, - "redistribute (1-65535)", + "redistribute (1-65535)", "Redistribute information from another routing protocol\n" "Open Shortest Path First (OSPFv2)\n" "Non-main Kernel Routing Table\n" + "Non-main Kernel Routing Table - Direct\n" "Instance ID/Table ID\n") { VTY_DECLVAR_CONTEXT(bgp, bgp); @@ -16671,26 +16921,46 @@ DEFUN (bgp_redistribute_ipv4_ospf, if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) protocol = ZEBRA_ROUTE_OSPF; - else - protocol = ZEBRA_ROUTE_TABLE; + else { + if (bgp->vrf_id != VRF_DEFAULT) { + vty_out(vty, + "%% Only default BGP instance can use '%s'\n", + argv[idx_ospf_table]->arg); + return CMD_WARNING_CONFIG_FAILED; + } + if (strncmp(argv[idx_ospf_table]->arg, "table-direct", + strlen("table-direct")) == 0) { + protocol = ZEBRA_ROUTE_TABLE_DIRECT; + if (instance == RT_TABLE_MAIN || + instance == RT_TABLE_LOCAL) { + vty_out(vty, + "%% 'table-direct', can not use %u routing table\n", + instance); + return CMD_WARNING_CONFIG_FAILED; + } + } else + protocol = ZEBRA_ROUTE_TABLE; + } bgp_redist_add(bgp, AFI_IP, protocol, instance); return bgp_redistribute_set(bgp, AFI_IP, protocol, instance, false); } ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf, bgp_redistribute_ipv4_ospf_hidden_cmd, - "redistribute (1-65535)", + "redistribute (1-65535)", "Redistribute information from another routing protocol\n" "Open Shortest Path First (OSPFv2)\n" "Non-main Kernel Routing Table\n" + "Non-main Kernel Routing Table - Direct\n" "Instance ID/Table ID\n") DEFUN (bgp_redistribute_ipv4_ospf_rmap, bgp_redistribute_ipv4_ospf_rmap_cmd, - "redistribute (1-65535) route-map RMAP_NAME", + "redistribute (1-65535) route-map RMAP_NAME", "Redistribute information from another routing protocol\n" "Open Shortest Path First (OSPFv2)\n" "Non-main Kernel Routing Table\n" + "Non-main Kernel Routing Table - Direct\n" "Instance ID/Table ID\n" "Route map reference\n" "Pointer to route-map entries\n") @@ -16706,12 +16976,31 @@ DEFUN (bgp_redistribute_ipv4_ospf_rmap, struct route_map *route_map = route_map_lookup_warn_noexist(vty, argv[idx_word]->arg); + instance = strtoul(argv[idx_number]->arg, NULL, 10); + if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) protocol = ZEBRA_ROUTE_OSPF; - else - protocol = ZEBRA_ROUTE_TABLE; + else { + if (bgp->vrf_id != VRF_DEFAULT) { + vty_out(vty, + "%% Only default BGP instance can use '%s'\n", + argv[idx_ospf_table]->arg); + return CMD_WARNING_CONFIG_FAILED; + } + if (strncmp(argv[idx_ospf_table]->arg, "table-direct", + strlen("table-direct")) == 0) { + protocol = ZEBRA_ROUTE_TABLE_DIRECT; + if (instance == RT_TABLE_MAIN || + instance == RT_TABLE_LOCAL) { + vty_out(vty, + "%% 'table-direct', can not use %u routing table\n", + instance); + return CMD_WARNING_CONFIG_FAILED; + } + } else + protocol = ZEBRA_ROUTE_TABLE; + } - instance = strtoul(argv[idx_number]->arg, NULL, 10); red = bgp_redist_add(bgp, AFI_IP, protocol, instance); changed = bgp_redistribute_rmap_set(red, argv[idx_word]->arg, route_map); @@ -16720,20 +17009,22 @@ DEFUN (bgp_redistribute_ipv4_ospf_rmap, ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_rmap, bgp_redistribute_ipv4_ospf_rmap_hidden_cmd, - "redistribute (1-65535) route-map RMAP_NAME", + "redistribute (1-65535) route-map RMAP_NAME", "Redistribute information from another routing protocol\n" "Open Shortest Path First (OSPFv2)\n" "Non-main Kernel Routing Table\n" + "Non-main Kernel Routing Table - Direct\n" "Instance ID/Table ID\n" "Route map reference\n" "Pointer to route-map entries\n") DEFUN (bgp_redistribute_ipv4_ospf_metric, bgp_redistribute_ipv4_ospf_metric_cmd, - "redistribute (1-65535) metric (0-4294967295)", + "redistribute (1-65535) metric (0-4294967295)", "Redistribute information from another routing protocol\n" "Open Shortest Path First (OSPFv2)\n" "Non-main Kernel Routing Table\n" + "Non-main Kernel Routing Table - Direct\n" "Instance ID/Table ID\n" "Metric for redistributed routes\n" "Default metric\n") @@ -16748,12 +17039,31 @@ DEFUN (bgp_redistribute_ipv4_ospf_metric, int protocol; bool changed; + instance = strtoul(argv[idx_number]->arg, NULL, 10); + if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) protocol = ZEBRA_ROUTE_OSPF; - else - protocol = ZEBRA_ROUTE_TABLE; + else { + if (bgp->vrf_id != VRF_DEFAULT) { + vty_out(vty, + "%% Only default BGP instance can use '%s'\n", + argv[idx_ospf_table]->arg); + return CMD_WARNING_CONFIG_FAILED; + } + if (strncmp(argv[idx_ospf_table]->arg, "table-direct", + strlen("table-direct")) == 0) { + protocol = ZEBRA_ROUTE_TABLE_DIRECT; + if (instance == RT_TABLE_MAIN || + instance == RT_TABLE_LOCAL) { + vty_out(vty, + "%% 'table-direct', can not use %u routing table\n", + instance); + return CMD_WARNING_CONFIG_FAILED; + } + } else + protocol = ZEBRA_ROUTE_TABLE; + } - instance = strtoul(argv[idx_number]->arg, NULL, 10); metric = strtoul(argv[idx_number_2]->arg, NULL, 10); red = bgp_redist_add(bgp, AFI_IP, protocol, instance); @@ -16764,20 +17074,22 @@ DEFUN (bgp_redistribute_ipv4_ospf_metric, ALIAS_HIDDEN(bgp_redistribute_ipv4_ospf_metric, bgp_redistribute_ipv4_ospf_metric_hidden_cmd, - "redistribute (1-65535) metric (0-4294967295)", + "redistribute (1-65535) metric (0-4294967295)", "Redistribute information from another routing protocol\n" "Open Shortest Path First (OSPFv2)\n" "Non-main Kernel Routing Table\n" + "Non-main Kernel Routing Table - Direct\n" "Instance ID/Table ID\n" "Metric for redistributed routes\n" "Default metric\n") DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric, bgp_redistribute_ipv4_ospf_rmap_metric_cmd, - "redistribute (1-65535) route-map RMAP_NAME metric (0-4294967295)", + "redistribute (1-65535) route-map RMAP_NAME metric (0-4294967295)", "Redistribute information from another routing protocol\n" "Open Shortest Path First (OSPFv2)\n" "Non-main Kernel Routing Table\n" + "Non-main Kernel Routing Table - Direct\n" "Instance ID/Table ID\n" "Route map reference\n" "Pointer to route-map entries\n" @@ -16797,12 +17109,31 @@ DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric, struct route_map *route_map = route_map_lookup_warn_noexist(vty, argv[idx_word]->arg); + instance = strtoul(argv[idx_number]->arg, NULL, 10); + if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) protocol = ZEBRA_ROUTE_OSPF; - else - protocol = ZEBRA_ROUTE_TABLE; + else { + if (bgp->vrf_id != VRF_DEFAULT) { + vty_out(vty, + "%% Only default BGP instance can use '%s'\n", + argv[idx_ospf_table]->arg); + return CMD_WARNING_CONFIG_FAILED; + } + if (strncmp(argv[idx_ospf_table]->arg, "table-direct", + strlen("table-direct")) == 0) { + protocol = ZEBRA_ROUTE_TABLE_DIRECT; + if (instance == RT_TABLE_MAIN || + instance == RT_TABLE_LOCAL) { + vty_out(vty, + "%% 'table-direct', can not use %u routing table\n", + instance); + return CMD_WARNING_CONFIG_FAILED; + } + } else + protocol = ZEBRA_ROUTE_TABLE; + } - instance = strtoul(argv[idx_number]->arg, NULL, 10); metric = strtoul(argv[idx_number_2]->arg, NULL, 10); red = bgp_redist_add(bgp, AFI_IP, protocol, instance); @@ -16816,10 +17147,11 @@ DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric, ALIAS_HIDDEN( bgp_redistribute_ipv4_ospf_rmap_metric, bgp_redistribute_ipv4_ospf_rmap_metric_hidden_cmd, - "redistribute (1-65535) route-map RMAP_NAME metric (0-4294967295)", + "redistribute (1-65535) route-map RMAP_NAME metric (0-4294967295)", "Redistribute information from another routing protocol\n" "Open Shortest Path First (OSPFv2)\n" "Non-main Kernel Routing Table\n" + "Non-main Kernel Routing Table - Direct\n" "Instance ID/Table ID\n" "Route map reference\n" "Pointer to route-map entries\n" @@ -16828,10 +17160,11 @@ ALIAS_HIDDEN( DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap, bgp_redistribute_ipv4_ospf_metric_rmap_cmd, - "redistribute (1-65535) metric (0-4294967295) route-map RMAP_NAME", + "redistribute (1-65535) metric (0-4294967295) route-map RMAP_NAME", "Redistribute information from another routing protocol\n" "Open Shortest Path First (OSPFv2)\n" "Non-main Kernel Routing Table\n" + "Non-main Kernel Routing Table - Direct\n" "Instance ID/Table ID\n" "Metric for redistributed routes\n" "Default metric\n" @@ -16851,10 +17184,29 @@ DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap, struct route_map *route_map = route_map_lookup_warn_noexist(vty, argv[idx_word]->arg); + instance = strtoul(argv[idx_number]->arg, NULL, 10); + if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) protocol = ZEBRA_ROUTE_OSPF; - else - protocol = ZEBRA_ROUTE_TABLE; + else { + if (bgp->vrf_id != VRF_DEFAULT) { + vty_out(vty, + "%% Only default BGP instance can use '%s'\n", + argv[idx_ospf_table]->arg); + return CMD_WARNING_CONFIG_FAILED; + } else if (strncmp(argv[idx_ospf_table]->arg, "table-direct", + strlen("table-direct")) == 0) { + protocol = ZEBRA_ROUTE_TABLE_DIRECT; + if (instance == RT_TABLE_MAIN || + instance == RT_TABLE_LOCAL) { + vty_out(vty, + "%% 'table-direct', can not use %u routing table\n", + instance); + return CMD_WARNING_CONFIG_FAILED; + } + } else + protocol = ZEBRA_ROUTE_TABLE; + } instance = strtoul(argv[idx_number]->arg, NULL, 10); metric = strtoul(argv[idx_number_2]->arg, NULL, 10); @@ -16870,10 +17222,11 @@ DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap, ALIAS_HIDDEN( bgp_redistribute_ipv4_ospf_metric_rmap, bgp_redistribute_ipv4_ospf_metric_rmap_hidden_cmd, - "redistribute (1-65535) metric (0-4294967295) route-map RMAP_NAME", + "redistribute (1-65535) metric (0-4294967295) route-map RMAP_NAME", "Redistribute information from another routing protocol\n" "Open Shortest Path First (OSPFv2)\n" "Non-main Kernel Routing Table\n" + "Non-main Kernel Routing Table - Direct\n" "Instance ID/Table ID\n" "Metric for redistributed routes\n" "Default metric\n" @@ -16882,11 +17235,12 @@ ALIAS_HIDDEN( DEFUN (no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_cmd, - "no redistribute (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]", + "no redistribute (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]", NO_STR "Redistribute information from another routing protocol\n" "Open Shortest Path First (OSPFv2)\n" "Non-main Kernel Routing Table\n" + "Non-main Kernel Routing Table - Direct\n" "Instance ID/Table ID\n" "Metric for redistributed routes\n" "Default metric\n" @@ -16899,22 +17253,43 @@ DEFUN (no_bgp_redistribute_ipv4_ospf, unsigned short instance; int protocol; + instance = strtoul(argv[idx_number]->arg, NULL, 10); + if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) protocol = ZEBRA_ROUTE_OSPF; - else - protocol = ZEBRA_ROUTE_TABLE; + else { + if (bgp->vrf_id != VRF_DEFAULT) { + vty_out(vty, + "%% Only default BGP instance can use '%s'\n", + argv[idx_ospf_table]->arg); + return CMD_WARNING_CONFIG_FAILED; + } + if (strncmp(argv[idx_ospf_table]->arg, "table-direct", + strlen("table-direct")) == 0) { + protocol = ZEBRA_ROUTE_TABLE_DIRECT; + if (instance == RT_TABLE_MAIN || + instance == RT_TABLE_LOCAL) { + vty_out(vty, + "%% 'table-direct', can not use %u routing table\n", + instance); + return CMD_WARNING_CONFIG_FAILED; + } + } else + protocol = ZEBRA_ROUTE_TABLE; + } - instance = strtoul(argv[idx_number]->arg, NULL, 10); - return bgp_redistribute_unset(bgp, AFI_IP, protocol, instance); + bgp_redistribute_unset(bgp, AFI_IP, protocol, instance); + return CMD_SUCCESS; } ALIAS_HIDDEN( no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd, - "no redistribute (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]", + "no redistribute (1-65535) [{metric (0-4294967295)|route-map RMAP_NAME}]", NO_STR "Redistribute information from another routing protocol\n" "Open Shortest Path First (OSPFv2)\n" "Non-main Kernel Routing Table\n" + "Non-main Kernel Routing Table - Direct\n" "Instance ID/Table ID\n" "Metric for redistributed routes\n" "Default metric\n" @@ -16941,7 +17316,8 @@ DEFUN (no_bgp_redistribute_ipv4, vty_out(vty, "%% Invalid route type\n"); return CMD_WARNING_CONFIG_FAILED; } - return bgp_redistribute_unset(bgp, AFI_IP, type, 0); + bgp_redistribute_unset(bgp, AFI_IP, type, 0); + return CMD_SUCCESS; } ALIAS_HIDDEN( @@ -17125,7 +17501,8 @@ DEFUN (no_bgp_redistribute_ipv6, return CMD_WARNING_CONFIG_FAILED; } - return bgp_redistribute_unset(bgp, AFI_IP6, type, 0); + bgp_redistribute_unset(bgp, AFI_IP6, type, 0); + return CMD_SUCCESS; } /* Neighbor update tcp-mss. */ @@ -17680,8 +18057,12 @@ static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp, && !(peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED && peer->ttl == MAXTTL)) { if (!peer_group_active(peer) || g_peer->ttl != peer->ttl) { - vty_out(vty, " neighbor %s ebgp-multihop %d\n", addr, - peer->ttl); + if (peer->ttl != MAXTTL) + vty_out(vty, " neighbor %s ebgp-multihop %d\n", + addr, peer->ttl); + else + vty_out(vty, " neighbor %s ebgp-multihop\n", + addr); } } @@ -17702,6 +18083,9 @@ static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp, ? " strict-mode" : ""); + if (peer->sub_sort == BGP_PEER_EBGP_OAD) + vty_out(vty, " neighbor %s oad\n", addr); + /* ttl-security hops */ if (peer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) { if (!peer_group_active(peer) @@ -17726,8 +18110,13 @@ static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp, addr); /* enforce-first-as */ - if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS)) - vty_out(vty, " neighbor %s enforce-first-as\n", addr); + if (CHECK_FLAG(bgp->flags, BGP_FLAG_ENFORCE_FIRST_AS)) { + if (!peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS)) + vty_out(vty, " no neighbor %s enforce-first-as\n", addr); + } else { + if (peergroup_flag_check(peer, PEER_FLAG_ENFORCE_FIRST_AS)) + vty_out(vty, " neighbor %s enforce-first-as\n", addr); + } /* update-source */ if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) { @@ -17915,6 +18304,13 @@ static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp, " neighbor %s addpath-tx-bestpath-per-AS\n", addr); break; + case BGP_ADDPATH_BEST_SELECTED: + if (peer->addpath_best_selected[afi][safi]) + vty_out(vty, + " neighbor %s addpath-tx-best-selected %u\n", + addr, + peer->addpath_best_selected[afi][safi]); + break; case BGP_ADDPATH_MAX: case BGP_ADDPATH_NONE: break; @@ -18253,6 +18649,8 @@ int bgp_config_write(struct vty *vty) safi_t safi; uint32_t tovpn_sid_index = 0; + hook_call(bgp_snmp_traps_config_write, vty); + if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER) vty_out(vty, "bgp route-map delay-timer %u\n", bm->rmap_update_timer); @@ -18343,6 +18741,15 @@ int bgp_config_write(struct vty *vty) ? "" : "no "); + /* bgp enforce-first-as */ + if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_ENFORCE_FIRST_AS) != + SAVE_BGP_ENFORCE_FIRST_AS) + vty_out(vty, " %sbgp enforce-first-as\n", + CHECK_FLAG(bgp->flags, + BGP_FLAG_ENFORCE_FIRST_AS) + ? "" + : "no "); + if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LU_IPV4_EXPLICIT_NULL) && !!CHECK_FLAG(bgp->flags, BGP_FLAG_LU_IPV6_EXPLICIT_NULL)) vty_out(vty, " bgp labeled-unicast explicit-null\n"); @@ -18413,6 +18820,15 @@ int bgp_config_write(struct vty *vty) ? "" : "no "); + if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SOFT_VERSION_CAPABILITY) != + SAVE_BGP_SOFT_VERSION_CAPABILITY) + vty_out(vty, + " %sbgp default software-version-capability\n", + CHECK_FLAG(bgp->flags, + BGP_FLAG_SOFT_VERSION_CAPABILITY) + ? "" + : "no "); + /* BGP default subgroup-pkt-queue-max. */ if (bgp->default_subgroup_pkt_queue_max != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX) @@ -18620,6 +19036,12 @@ int bgp_config_write(struct vty *vty) " bgp conditional-advertisement timer %u\n", bgp->condition_check_period); + /* default-originate timer configuration */ + if (bgp->rmap_def_originate_eval_timer != + RMAP_DEFAULT_ORIGINATE_EVAL_TIMER) + vty_out(vty, " bgp default-originate timer %u\n", + bgp->rmap_def_originate_eval_timer); + /* peer-group */ for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) { bgp_config_write_peer_global(vty, bgp, group->conf); @@ -18906,6 +19328,9 @@ bool bgp_config_inprocess(void) return event_is_scheduled(t_bgp_cfg); } +/* Max wait time for config to load before post-config processing */ +#define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600 + static void bgp_config_finish(struct event *t) { struct listnode *node; @@ -18915,11 +19340,17 @@ static void bgp_config_finish(struct event *t) hook_call(bgp_config_end, bgp); } +static void bgp_config_end_timeout(struct event *t) +{ + zlog_err("BGP configuration end timer expired after %d seconds.", + BGP_PRE_CONFIG_MAX_WAIT_SECONDS); + bgp_config_finish(t); +} + static void bgp_config_start(void) { -#define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600 EVENT_OFF(t_bgp_cfg); - event_add_timer(bm->master, bgp_config_finish, NULL, + event_add_timer(bm->master, bgp_config_end_timeout, NULL, BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg); } @@ -18969,6 +19400,12 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf) vty_out(vty, " mpls bgp forwarding\n"); write++; } + if (CHECK_FLAG(iifp->flags, + BGP_INTERFACE_MPLS_L3VPN_SWITCHING)) { + vty_out(vty, + " mpls bgp l3vpn-multi-domain-switching\n"); + write++; + } if_vty_config_end(vty); } @@ -19019,6 +19456,35 @@ DEFPY(mpls_bgp_forwarding, mpls_bgp_forwarding_cmd, return CMD_SUCCESS; } +DEFPY(mpls_bgp_l3vpn_multi_domain_switching, + mpls_bgp_l3vpn_multi_domain_switching_cmd, + "[no$no] mpls bgp l3vpn-multi-domain-switching", + NO_STR MPLS_STR BGP_STR + "Bind a local MPLS label to incoming L3VPN updates\n") +{ + bool check; + struct bgp_interface *iifp; + + VTY_DECLVAR_CONTEXT(interface, ifp); + iifp = ifp->info; + if (!iifp) { + vty_out(vty, "Interface %s not available\n", ifp->name); + return CMD_WARNING_CONFIG_FAILED; + } + check = CHECK_FLAG(iifp->flags, BGP_INTERFACE_MPLS_L3VPN_SWITCHING); + if (check == !no) + return CMD_SUCCESS; + if (no) + UNSET_FLAG(iifp->flags, BGP_INTERFACE_MPLS_L3VPN_SWITCHING); + else + SET_FLAG(iifp->flags, BGP_INTERFACE_MPLS_L3VPN_SWITCHING); + /* trigger a nht update on eBGP sessions */ + if (if_is_operative(ifp)) + bgp_nht_ifp_up(ifp); + + return CMD_SUCCESS; +} + DEFPY (bgp_inq_limit, bgp_inq_limit_cmd, "bgp input-queue-limit (1-4294967295)$limit", @@ -19078,6 +19544,8 @@ static void bgp_vty_if_init(void) /* "mpls bgp forwarding" commands. */ install_element(INTERFACE_NODE, &mpls_bgp_forwarding_cmd); + install_element(INTERFACE_NODE, + &mpls_bgp_l3vpn_multi_domain_switching_cmd); } void bgp_vty_init(void) @@ -19201,6 +19669,9 @@ void bgp_vty_init(void) install_element(BGP_NODE, &neighbor_role_strict_cmd); install_element(BGP_NODE, &no_neighbor_role_cmd); + /* "neighbor oad" commands. */ + install_element(BGP_NODE, &neighbor_oad_cmd); + /* "neighbor aigp" commands. */ install_element(BGP_NODE, &neighbor_aigp_cmd); @@ -19274,6 +19745,9 @@ void bgp_vty_init(void) install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd); install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd); + /* bgp enforce-first-as */ + install_element(BGP_NODE, &bgp_enforce_first_as_cmd); + /* bgp labeled-unicast explicit-null */ install_element(BGP_NODE, &bgp_lu_uses_explicit_null_cmd); @@ -19400,6 +19874,9 @@ void bgp_vty_init(void) install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd); install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd); + /* bgp default software-version-capability */ + install_element(BGP_NODE, &bgp_default_software_version_capability_cmd); + /* "bgp default subgroup-pkt-queue-max" commands. */ install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd); install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd); @@ -19917,6 +20394,40 @@ void bgp_vty_init(void) install_element(BGP_VPNV6_NODE, &neighbor_addpath_tx_all_paths_cmd); install_element(BGP_VPNV6_NODE, &no_neighbor_addpath_tx_all_paths_cmd); + /* "neighbor addpath-tx-best-selected" commands.*/ + install_element(BGP_IPV4_NODE, + &neighbor_addpath_tx_best_selected_paths_cmd); + install_element(BGP_IPV4_NODE, + &no_neighbor_addpath_tx_best_selected_paths_cmd); + install_element(BGP_IPV4M_NODE, + &neighbor_addpath_tx_best_selected_paths_cmd); + install_element(BGP_IPV4M_NODE, + &no_neighbor_addpath_tx_best_selected_paths_cmd); + install_element(BGP_IPV4L_NODE, + &neighbor_addpath_tx_best_selected_paths_cmd); + install_element(BGP_IPV4L_NODE, + &no_neighbor_addpath_tx_best_selected_paths_cmd); + install_element(BGP_IPV6_NODE, + &neighbor_addpath_tx_best_selected_paths_cmd); + install_element(BGP_IPV6_NODE, + &no_neighbor_addpath_tx_best_selected_paths_cmd); + install_element(BGP_IPV6M_NODE, + &neighbor_addpath_tx_best_selected_paths_cmd); + install_element(BGP_IPV6M_NODE, + &no_neighbor_addpath_tx_best_selected_paths_cmd); + install_element(BGP_IPV6L_NODE, + &neighbor_addpath_tx_best_selected_paths_cmd); + install_element(BGP_IPV6L_NODE, + &no_neighbor_addpath_tx_best_selected_paths_cmd); + install_element(BGP_VPNV4_NODE, + &neighbor_addpath_tx_best_selected_paths_cmd); + install_element(BGP_VPNV4_NODE, + &no_neighbor_addpath_tx_best_selected_paths_cmd); + install_element(BGP_VPNV6_NODE, + &neighbor_addpath_tx_best_selected_paths_cmd); + install_element(BGP_VPNV6_NODE, + &no_neighbor_addpath_tx_best_selected_paths_cmd); + /* "neighbor addpath-tx-bestpath-per-AS" commands.*/ install_element(BGP_NODE, &neighbor_addpath_tx_bestpath_per_as_hidden_cmd); @@ -20248,6 +20759,9 @@ void bgp_vty_init(void) install_element(BGP_VPNV4_NODE, &neighbor_advertise_map_cmd); install_element(BGP_VPNV6_NODE, &neighbor_advertise_map_cmd); + /* bgp default-originate timer */ + install_element(BGP_NODE, &bgp_def_originate_eval_cmd); + /* neighbor maximum-prefix-out commands. */ install_element(BGP_NODE, &neighbor_maximum_prefix_out_cmd); install_element(BGP_NODE, &no_neighbor_maximum_prefix_out_cmd); @@ -20663,6 +21177,7 @@ DEFUN (community_list_standard, argv_find(argv, argc, "AA:NN", &idx); char *str = argv_concat(argv, argc, idx); + assert(str); int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq, direct, style); @@ -20775,6 +21290,7 @@ DEFUN (community_list_expanded_all, argv_find(argv, argc, "AA:NN", &idx); char *str = argv_concat(argv, argc, idx); + assert(str); int ret = community_list_set(bgp_clist, cl_name_or_number, str, seq, direct, style); @@ -20859,16 +21375,13 @@ static const char *community_list_config_str(struct community_entry *entry) { const char *str; - if (entry->any) - str = ""; - else { - if (entry->style == COMMUNITY_LIST_STANDARD) - str = community_str(entry->u.com, false, false); - else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD) - str = lcommunity_str(entry->u.lcom, false, false); - else - str = entry->config; - } + if (entry->style == COMMUNITY_LIST_STANDARD) + str = community_str(entry->u.com, false, false); + else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD) + str = lcommunity_str(entry->u.lcom, false, false); + else + str = entry->config; + return str; } @@ -20891,13 +21404,8 @@ static void community_list_show(struct vty *vty, struct community_list *list) : "expanded", list->name); } - if (entry->any) - vty_out(vty, " %s\n", - community_direct_str(entry->direct)); - else - vty_out(vty, " %s %s\n", - community_direct_str(entry->direct), - community_list_config_str(entry)); + vty_out(vty, " %s %s\n", community_direct_str(entry->direct), + community_list_config_str(entry)); } } @@ -21256,13 +21764,8 @@ static void lcommunity_list_show(struct vty *vty, struct community_list *list) : "expanded", list->name); } - if (entry->any) - vty_out(vty, " %s\n", - community_direct_str(entry->direct)); - else - vty_out(vty, " %s %s\n", - community_direct_str(entry->direct), - community_list_config_str(entry)); + vty_out(vty, " %s %s\n", community_direct_str(entry->direct), + community_list_config_str(entry)); } } @@ -21558,13 +22061,8 @@ static void extcommunity_list_show(struct vty *vty, struct community_list *list) : "expanded", list->name); } - if (entry->any) - vty_out(vty, " %s\n", - community_direct_str(entry->direct)); - else - vty_out(vty, " %s %s\n", - community_direct_str(entry->direct), - community_list_config_str(entry)); + vty_out(vty, " %s %s\n", community_direct_str(entry->direct), + community_list_config_str(entry)); } } diff --git a/bgpd/bgp_vty.h b/bgpd/bgp_vty.h index 826723b92d..a105b6de3f 100644 --- a/bgpd/bgp_vty.h +++ b/bgpd/bgp_vty.h @@ -145,7 +145,7 @@ extern void bgp_config_write_wpkt_quanta(struct vty *vty, struct bgp *bgp); extern void bgp_config_write_rpkt_quanta(struct vty *vty, struct bgp *bgp); extern void bgp_config_write_listen(struct vty *vty, struct bgp *bgp); extern void bgp_config_write_coalesce_time(struct vty *vty, struct bgp *bgp); -extern int bgp_vty_return(struct vty *vty, int ret); +extern int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret); extern bool bgp_config_inprocess(void); extern struct peer *peer_and_group_lookup_vty(struct vty *vty, const char *peer_str); diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 1965cd2704..0db0ac4873 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* zebra client * Copyright (C) 1997, 98, 99 Kunihiro Ishiguro + * Copyright (c) 2023 LabN Consulting, L.L.C. */ #include @@ -23,6 +24,7 @@ #include "mpls.h" #include "vxlan.h" #include "pbr.h" +#include "frrdistance.h" #include "bgpd/bgpd.h" #include "bgpd/bgp_route.h" @@ -55,6 +57,8 @@ /* All information about zebra. */ struct zclient *zclient = NULL; +struct zclient *zclient_sync; +static bool bgp_zebra_label_manager_connect(void); /* hook to indicate vrf status change for SNMP */ DEFINE_HOOK(bgp_vrf_status_changed, (struct bgp *bgp, struct interface *ifp), @@ -69,9 +73,10 @@ static inline bool bgp_install_info_to_zebra(struct bgp *bgp) return false; if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) { - zlog_debug( - "%s: No zebra instance to talk to, not installing information", - __func__); + if (BGP_DEBUG(zebra, ZEBRA)) + zlog_debug( + "%s: No zebra instance to talk to, not installing information", + __func__); return false; } @@ -95,13 +100,6 @@ static int bgp_router_id_update(ZAPI_CALLBACK_ARGS) return 0; } -/* Nexthop update message from zebra. */ -static int bgp_read_nexthop_update(ZAPI_CALLBACK_ARGS) -{ - bgp_parse_nexthop_update(cmd, vrf_id); - return 0; -} - /* Set or clear interface on which unnumbered neighbor is configured. This * would in turn cause BGP to initiate or turn off IPv6 RAs on this * interface. @@ -137,18 +135,17 @@ static void bgp_start_interface_nbrs(struct bgp *bgp, struct interface *ifp) struct peer *peer; for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { - if (peer->conf_if && (strcmp(peer->conf_if, ifp->name) == 0) - && !peer_established(peer)) { + if (peer->conf_if && (strcmp(peer->conf_if, ifp->name) == 0) && + !peer_established(peer->connection)) { if (peer_active(peer)) - BGP_EVENT_ADD(peer, BGP_Stop); - BGP_EVENT_ADD(peer, BGP_Start); + BGP_EVENT_ADD(peer->connection, BGP_Stop); + BGP_EVENT_ADD(peer->connection, BGP_Start); } } } static void bgp_nbr_connected_add(struct bgp *bgp, struct nbr_connected *ifc) { - struct listnode *node; struct connected *connected; struct interface *ifp; struct prefix *p; @@ -157,7 +154,7 @@ static void bgp_nbr_connected_add(struct bgp *bgp, struct nbr_connected *ifc) * valid local address on the interface. */ ifp = ifc->ifp; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) { + frr_each (if_connected, ifp->connected, connected) { p = connected->address; if (p->family == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&p->u.prefix6)) @@ -180,7 +177,7 @@ static void bgp_nbr_connected_delete(struct bgp *bgp, struct nbr_connected *ifc, if (peer->conf_if && (strcmp(peer->conf_if, ifc->ifp->name) == 0)) { peer->last_reset = PEER_DOWN_NBR_ADDR_DEL; - BGP_EVENT_ADD(peer, BGP_Stop); + BGP_EVENT_ADD(peer->connection, BGP_Stop); } } /* Free neighbor also, if we're asked to. */ @@ -229,7 +226,7 @@ static int bgp_ifp_up(struct interface *ifp) if (!bgp) return 0; - for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c)) + frr_each (if_connected, ifp->connected, c) bgp_connected_add(bgp, c); for (ALL_LIST_ELEMENTS(ifp->nbr_connected, node, nnode, nc)) @@ -260,7 +257,7 @@ static int bgp_ifp_down(struct interface *ifp) if (!bgp) return 0; - for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c)) + frr_each (if_connected, ifp->connected, c) bgp_connected_delete(bgp, c); for (ALL_LIST_ELEMENTS(ifp->nbr_connected, node, nnode, nc)) @@ -276,7 +273,7 @@ static int bgp_ifp_down(struct interface *ifp) continue; if (ifp == peer->nexthop.ifp) { - BGP_EVENT_ADD(peer, BGP_Stop); + BGP_EVENT_ADD(peer->connection, BGP_Stop); peer->last_reset = PEER_DOWN_IF_DOWN; } } @@ -474,65 +471,6 @@ static int bgp_interface_nbr_address_delete(ZAPI_CALLBACK_ARGS) return 0; } -/* VRF update for an interface. */ -static int bgp_interface_vrf_update(ZAPI_CALLBACK_ARGS) -{ - struct interface *ifp; - vrf_id_t new_vrf_id; - struct connected *c; - struct nbr_connected *nc; - struct listnode *node, *nnode; - struct bgp *bgp; - struct peer *peer; - - ifp = zebra_interface_vrf_update_read(zclient->ibuf, vrf_id, - &new_vrf_id); - if (!ifp) - return 0; - - if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("Rx Intf VRF change VRF %u IF %s NewVRF %u", vrf_id, - ifp->name, new_vrf_id); - - bgp = bgp_lookup_by_vrf_id(vrf_id); - - if (bgp) { - for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c)) - bgp_connected_delete(bgp, c); - - for (ALL_LIST_ELEMENTS(ifp->nbr_connected, node, nnode, nc)) - bgp_nbr_connected_delete(bgp, nc, 1); - - /* Fast external-failover */ - if (!CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER)) { - for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { - if ((peer->ttl != BGP_DEFAULT_TTL) - && (peer->gtsm_hops - != BGP_GTSM_HOPS_CONNECTED)) - continue; - - if (ifp == peer->nexthop.ifp) - BGP_EVENT_ADD(peer, BGP_Stop); - } - } - } - - if_update_to_new_vrf(ifp, new_vrf_id); - - bgp = bgp_lookup_by_vrf_id(new_vrf_id); - if (!bgp) - return 0; - - for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c)) - bgp_connected_add(bgp, c); - - for (ALL_LIST_ELEMENTS(ifp->nbr_connected, node, nnode, nc)) - bgp_nbr_connected_add(bgp, nc); - - hook_call(bgp_vrf_status_changed, bgp, ifp); - return 0; -} - /* Zebra route add and delete treatment. */ static int zebra_read_route(ZAPI_CALLBACK_ARGS) { @@ -620,7 +558,6 @@ static int zebra_read_route(ZAPI_CALLBACK_ARGS) struct interface *if_lookup_by_ipv4(struct in_addr *addr, vrf_id_t vrf_id) { struct vrf *vrf; - struct listnode *cnode; struct interface *ifp; struct connected *connected; struct prefix_ipv4 p; @@ -635,7 +572,7 @@ struct interface *if_lookup_by_ipv4(struct in_addr *addr, vrf_id_t vrf_id) p.prefixlen = IPV4_MAX_BITLEN; FOR_ALL_INTERFACES (vrf, ifp) { - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { + frr_each (if_connected, ifp->connected, connected) { cp = connected->address; if (cp->family == AF_INET) @@ -649,7 +586,6 @@ struct interface *if_lookup_by_ipv4(struct in_addr *addr, vrf_id_t vrf_id) struct interface *if_lookup_by_ipv4_exact(struct in_addr *addr, vrf_id_t vrf_id) { struct vrf *vrf; - struct listnode *cnode; struct interface *ifp; struct connected *connected; struct prefix *cp; @@ -659,7 +595,7 @@ struct interface *if_lookup_by_ipv4_exact(struct in_addr *addr, vrf_id_t vrf_id) return NULL; FOR_ALL_INTERFACES (vrf, ifp) { - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { + frr_each (if_connected, ifp->connected, connected) { cp = connected->address; if (cp->family == AF_INET) @@ -674,7 +610,6 @@ struct interface *if_lookup_by_ipv6(struct in6_addr *addr, ifindex_t ifindex, vrf_id_t vrf_id) { struct vrf *vrf; - struct listnode *cnode; struct interface *ifp; struct connected *connected; struct prefix_ipv6 p; @@ -689,7 +624,7 @@ struct interface *if_lookup_by_ipv6(struct in6_addr *addr, ifindex_t ifindex, p.prefixlen = IPV6_MAX_BITLEN; FOR_ALL_INTERFACES (vrf, ifp) { - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { + frr_each (if_connected, ifp->connected, connected) { cp = connected->address; if (cp->family == AF_INET6) @@ -710,7 +645,6 @@ struct interface *if_lookup_by_ipv6_exact(struct in6_addr *addr, ifindex_t ifindex, vrf_id_t vrf_id) { struct vrf *vrf; - struct listnode *cnode; struct interface *ifp; struct connected *connected; struct prefix *cp; @@ -720,7 +654,7 @@ struct interface *if_lookup_by_ipv6_exact(struct in6_addr *addr, return NULL; FOR_ALL_INTERFACES (vrf, ifp) { - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { + frr_each (if_connected, ifp->connected, connected) { cp = connected->address; if (cp->family == AF_INET6) @@ -739,11 +673,10 @@ struct interface *if_lookup_by_ipv6_exact(struct in6_addr *addr, static int if_get_ipv6_global(struct interface *ifp, struct in6_addr *addr) { - struct listnode *cnode; struct connected *connected; struct prefix *cp; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { + frr_each (if_connected, ifp->connected, connected) { cp = connected->address; if (cp->family == AF_INET6) @@ -757,11 +690,10 @@ static int if_get_ipv6_global(struct interface *ifp, struct in6_addr *addr) static bool if_get_ipv6_local(struct interface *ifp, struct in6_addr *addr) { - struct listnode *cnode; struct connected *connected; struct prefix *cp; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { + frr_each (if_connected, ifp->connected, connected) { cp = connected->address; if (cp->family == AF_INET6) @@ -775,11 +707,10 @@ static bool if_get_ipv6_local(struct interface *ifp, struct in6_addr *addr) static int if_get_ipv4_address(struct interface *ifp, struct in_addr *addr) { - struct listnode *cnode; struct connected *connected; struct prefix *cp; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { + frr_each (if_connected, ifp->connected, connected) { cp = connected->address; if ((cp->family == AF_INET) && !ipv4_martian(&(cp->u.prefix4))) { @@ -1073,14 +1004,17 @@ static void bgp_zebra_tm_connect(struct event *t) ret = tm_table_manager_connect(zclient); } if (ret < 0) { - zlog_info("Error connecting to table manager!"); + zlog_err("Error connecting to table manager!"); bgp_tm_status_connected = false; } else { - if (!bgp_tm_status_connected) - zlog_debug("Connecting to table manager. Success"); + if (!bgp_tm_status_connected) { + if (BGP_DEBUG(zebra, ZEBRA)) + zlog_debug( + "Connecting to table manager. Success"); + } bgp_tm_status_connected = true; if (!bgp_tm_chunk_obtained) { - if (bgp_zebra_get_table_range(bgp_tm_chunk_size, + if (bgp_zebra_get_table_range(zclient, bgp_tm_chunk_size, &bgp_tm_min, &bgp_tm_max) >= 0) { bgp_tm_chunk_obtained = true; @@ -1120,18 +1054,18 @@ void bgp_zebra_init_tm_connect(struct bgp *bgp) bgp_tm_min = bgp_tm_max = 0; bgp_tm_chunk_size = BGP_FLOWSPEC_TABLE_CHUNK; bgp_tm_bgp = bgp; - event_add_timer(bm->master, bgp_zebra_tm_connect, zclient, delay, + event_add_timer(bm->master, bgp_zebra_tm_connect, zclient_sync, delay, &bgp_tm_thread_connect); } -int bgp_zebra_get_table_range(uint32_t chunk_size, +int bgp_zebra_get_table_range(struct zclient *zc, uint32_t chunk_size, uint32_t *start, uint32_t *end) { int ret; if (!bgp_tm_status_connected) return -1; - ret = tm_get_table_chunk(zclient, chunk_size, start, end); + ret = tm_get_table_chunk(zc, chunk_size, start, end); if (ret < 0) { flog_err(EC_BGP_TABLE_CHUNK, "BGP: Error getting table chunk %u", chunk_size); @@ -1260,145 +1194,61 @@ static bool update_ipv6nh_for_route_install(int nh_othervrf, struct bgp *nh_bgp, } static bool bgp_zebra_use_nhop_weighted(struct bgp *bgp, struct attr *attr, - uint64_t tot_bw, uint32_t *nh_weight) + uint32_t *nh_weight) { - uint32_t bw; - uint64_t tmp; - - bw = attr->link_bw; /* zero link-bandwidth and link-bandwidth not present are treated * as the same situation. */ - if (!bw) { + if (!attr->link_bw) { /* the only situations should be if we're either told * to skip or use default weight. */ if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING) return false; *nh_weight = BGP_ZEBRA_DEFAULT_NHOP_WEIGHT; - } else { - tmp = (uint64_t)bw * 100; - *nh_weight = ((uint32_t)(tmp / tot_bw)); - } + } else + *nh_weight = attr->link_bw; return true; } -void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, - struct bgp_path_info *info, struct bgp *bgp, afi_t afi, - safi_t safi) +static void bgp_zebra_announce_parse_nexthop( + struct bgp_path_info *info, const struct prefix *p, struct bgp *bgp, + struct zapi_route *api, unsigned int *valid_nh_count, afi_t afi, + safi_t safi, uint32_t *nhg_id, uint32_t *metric, route_tag_t *tag, + bool *allow_recursion) { - struct zapi_route api = { 0 }; struct zapi_nexthop *api_nh; int nh_family; - unsigned int valid_nh_count = 0; - bool allow_recursion = false; - uint8_t distance; - struct peer *peer; struct bgp_path_info *mpinfo; struct bgp *bgp_orig; - uint32_t metric; struct attr local_attr; struct bgp_path_info local_info; struct bgp_path_info *mpinfo_cp = &local_info; - route_tag_t tag; - struct bgp_sid_info *sid_info; mpls_label_t *labels; uint32_t num_labels = 0; mpls_label_t nh_label; int nh_othervrf = 0; bool nh_updated = false; bool do_wt_ecmp; - uint64_t cum_bw = 0; - uint32_t nhg_id = 0; - bool is_add; uint32_t ttl = 0; uint32_t bos = 0; uint32_t exp = 0; - /* - * BGP is installing this route and bgp has been configured - * to suppress announcements until the route has been installed - * let's set the fact that we expect this route to be installed - */ - if (BGP_SUPPRESS_FIB_ENABLED(bgp)) - SET_FLAG(dest->flags, BGP_NODE_FIB_INSTALL_PENDING); - - /* Don't try to install if we're not connected to Zebra or Zebra doesn't - * know of this instance. - */ - if (!bgp_install_info_to_zebra(bgp)) - return; - - if (bgp->main_zebra_update_hold) - return; - - if (safi == SAFI_FLOWSPEC) { - bgp_pbr_update_entry(bgp, bgp_dest_get_prefix(dest), info, afi, - safi, true); - return; - } + /* Determine if we're doing weighted ECMP or not */ + do_wt_ecmp = bgp_path_info_mpath_chkwtd(bgp, info); /* * vrf leaking support (will have only one nexthop) */ - if (info->extra && info->extra->bgp_orig) + if (info->extra && info->extra->vrfleak && + info->extra->vrfleak->bgp_orig) nh_othervrf = 1; - /* Make Zebra API structure. */ - api.vrf_id = bgp->vrf_id; - api.type = ZEBRA_ROUTE_BGP; - api.safi = safi; - api.prefix = *p; - SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP); - - peer = info->peer; - - if (info->type == ZEBRA_ROUTE_BGP - && info->sub_type == BGP_ROUTE_IMPORTED) { - - /* Obtain peer from parent */ - if (info->extra && info->extra->parent) - peer = ((struct bgp_path_info *)(info->extra->parent)) - ->peer; - } - - tag = info->attr->tag; - - if (peer->sort == BGP_PEER_IBGP || peer->sort == BGP_PEER_CONFED - || info->sub_type == BGP_ROUTE_AGGREGATE) { - SET_FLAG(api.flags, ZEBRA_FLAG_IBGP); - SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION); - } - - if ((peer->sort == BGP_PEER_EBGP && peer->ttl != BGP_DEFAULT_TTL) - || CHECK_FLAG(peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK) - || CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK)) - - allow_recursion = true; - - if (info->attr->rmap_table_id) { - SET_FLAG(api.message, ZAPI_MESSAGE_TABLEID); - api.tableid = info->attr->rmap_table_id; - } - - if (CHECK_FLAG(info->attr->flag, ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR))) - SET_FLAG(api.message, ZAPI_MESSAGE_SRTE); - - /* Metric is currently based on the best-path only */ - metric = info->attr->med; - - /* Determine if we're doing weighted ECMP or not */ - do_wt_ecmp = bgp_path_info_mpath_chkwtd(bgp, info); - if (do_wt_ecmp) - cum_bw = bgp_path_info_mpath_cumbw(info); - /* EVPN MAC-IP routes are installed with a L3 NHG id */ - if (bgp_evpn_path_es_use_nhg(bgp, info, &nhg_id)) { + if (nhg_id && bgp_evpn_path_es_use_nhg(bgp, info, nhg_id)) { mpinfo = NULL; - api.nhgid = nhg_id; - if (nhg_id) - SET_FLAG(api.message, ZAPI_MESSAGE_NHG); + zapi_route_set_nhg_id(api, nhg_id); } else { mpinfo = info; } @@ -1410,7 +1260,7 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, bool is_evpn; bool is_parent_evpn; - if (valid_nh_count >= multipath_num) + if (*valid_nh_count >= multipath_num) break; *mpinfo_cp = *mpinfo; @@ -1433,16 +1283,19 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, */ if (do_wt_ecmp) { if (!bgp_zebra_use_nhop_weighted(bgp, mpinfo->attr, - cum_bw, &nh_weight)) + &nh_weight)) continue; } - api_nh = &api.nexthops[valid_nh_count]; + if (CHECK_FLAG(info->flags, BGP_PATH_SELECTED)) + api_nh = &api->nexthops[*valid_nh_count]; + else + api_nh = &api->backup_nexthops[*valid_nh_count]; if (CHECK_FLAG(info->attr->flag, ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR))) - api_nh->srte_color = info->attr->srte_color; + api_nh->srte_color = bgp_attr_get_color(info->attr); - if (bgp_debug_zebra(&api.prefix)) { + if (bgp_debug_zebra(&api->prefix)) { if (mpinfo->extra) { zlog_debug("%s: p=%pFX, bgp_is_valid_label: %d", __func__, p, @@ -1467,8 +1320,10 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, /* metric/tag is only allowed to be * overridden on 1st nexthop */ if (mpinfo == info) { - metric = mpinfo_cp->attr->med; - tag = mpinfo_cp->attr->tag; + if (metric) + *metric = mpinfo_cp->attr->med; + if (tag) + *tag = mpinfo_cp->attr->tag; } } @@ -1509,11 +1364,11 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, /* Allow recursion if it is a multipath group with both * eBGP and iBGP paths. */ - if (!allow_recursion - && CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX) - && (mpinfo->peer->sort == BGP_PEER_IBGP - || mpinfo->peer->sort == BGP_PEER_CONFED)) - allow_recursion = true; + if (allow_recursion && !*allow_recursion && + CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX) && + (mpinfo->peer->sort == BGP_PEER_IBGP || + mpinfo->peer->sort == BGP_PEER_CONFED)) + *allow_recursion = true; if (mpinfo->extra) { labels = mpinfo->extra->label; @@ -1547,35 +1402,197 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, api_nh->weight = nh_weight; - if (mpinfo->extra && !is_evpn && - bgp_is_valid_label(&labels[0]) && - !sid_zero(&mpinfo->extra->sid[0].sid)) { - sid_info = &mpinfo->extra->sid[0]; - - memcpy(&api_nh->seg6_segs, &sid_info->sid, - sizeof(api_nh->seg6_segs)); - - if (sid_info->transposition_len != 0) { + if (((mpinfo->attr->srv6_l3vpn && + !sid_zero_ipv6(&mpinfo->attr->srv6_l3vpn->sid)) || + (mpinfo->attr->srv6_vpn && + !sid_zero_ipv6(&mpinfo->attr->srv6_vpn->sid))) && + !is_evpn && bgp_is_valid_label(&labels[0])) { + struct in6_addr *sid_tmp = + mpinfo->attr->srv6_l3vpn + ? (&mpinfo->attr->srv6_l3vpn->sid) + : (&mpinfo->attr->srv6_vpn->sid); + + memcpy(&api_nh->seg6_segs[0], sid_tmp, + sizeof(api_nh->seg6_segs[0])); + + if (mpinfo->attr->srv6_l3vpn && + mpinfo->attr->srv6_l3vpn->transposition_len != 0) { mpls_lse_decode(labels[0], &nh_label, &ttl, &exp, &bos); if (nh_label < MPLS_LABEL_UNRESERVED_MIN) { - if (bgp_debug_zebra(&api.prefix)) + if (bgp_debug_zebra(&api->prefix)) zlog_debug( "skip invalid SRv6 routes: transposition scheme is used, but label is too small"); continue; } - transpose_sid(&api_nh->seg6_segs, nh_label, - sid_info->transposition_offset, - sid_info->transposition_len); + transpose_sid(&api_nh->seg6_segs[0], nh_label, + mpinfo->attr->srv6_l3vpn + ->transposition_offset, + mpinfo->attr->srv6_l3vpn + ->transposition_len); } + api_nh->seg_num = 1; SET_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_SEG6); } - valid_nh_count++; + (*valid_nh_count)++; + } +} + +static void bgp_debug_zebra_nh(struct zapi_route *api) +{ + int i; + int nh_family; + char nh_buf[INET6_ADDRSTRLEN]; + char eth_buf[ETHER_ADDR_STRLEN + 7] = { '\0' }; + char buf1[ETHER_ADDR_STRLEN]; + char label_buf[20]; + char sid_buf[20]; + char segs_buf[256]; + struct zapi_nexthop *api_nh; + int count; + + count = api->nexthop_num; + for (i = 0; i < count; i++) { + api_nh = &api->nexthops[i]; + switch (api_nh->type) { + case NEXTHOP_TYPE_IFINDEX: + nh_buf[0] = '\0'; + break; + case NEXTHOP_TYPE_IPV4: + case NEXTHOP_TYPE_IPV4_IFINDEX: + nh_family = AF_INET; + inet_ntop(nh_family, &api_nh->gate, nh_buf, + sizeof(nh_buf)); + break; + case NEXTHOP_TYPE_IPV6: + case NEXTHOP_TYPE_IPV6_IFINDEX: + nh_family = AF_INET6; + inet_ntop(nh_family, &api_nh->gate, nh_buf, + sizeof(nh_buf)); + break; + case NEXTHOP_TYPE_BLACKHOLE: + strlcpy(nh_buf, "blackhole", sizeof(nh_buf)); + break; + default: + /* Note: add new nexthop case */ + assert(0); + break; + } + + label_buf[0] = '\0'; + eth_buf[0] = '\0'; + segs_buf[0] = '\0'; + if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_LABEL) && + !CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_EVPN)) + snprintf(label_buf, sizeof(label_buf), "label %u", + api_nh->labels[0]); + if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_SEG6) && + !CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_EVPN)) { + inet_ntop(AF_INET6, &api_nh->seg6_segs[0], sid_buf, + sizeof(sid_buf)); + snprintf(segs_buf, sizeof(segs_buf), "segs %s", sid_buf); + } + if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_EVPN) && + !is_zero_mac(&api_nh->rmac)) + snprintf(eth_buf, sizeof(eth_buf), " RMAC %s", + prefix_mac2str(&api_nh->rmac, buf1, + sizeof(buf1))); + zlog_debug(" nhop [%d]: %s if %u VRF %u wt %u %s %s %s", i + 1, + nh_buf, api_nh->ifindex, api_nh->vrf_id, + api_nh->weight, label_buf, segs_buf, eth_buf); } +} + +void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, + struct bgp_path_info *info, struct bgp *bgp, afi_t afi, + safi_t safi) +{ + struct zapi_route api = { 0 }; + unsigned int valid_nh_count = 0; + bool allow_recursion = false; + uint8_t distance; + struct peer *peer; + uint32_t metric; + route_tag_t tag; + bool is_add; + uint32_t nhg_id = 0; + uint32_t recursion_flag = 0; + + /* + * BGP is installing this route and bgp has been configured + * to suppress announcements until the route has been installed + * let's set the fact that we expect this route to be installed + */ + if (BGP_SUPPRESS_FIB_ENABLED(bgp)) + SET_FLAG(dest->flags, BGP_NODE_FIB_INSTALL_PENDING); + + /* Don't try to install if we're not connected to Zebra or Zebra doesn't + * know of this instance. + */ + if (!bgp_install_info_to_zebra(bgp)) + return; + + if (bgp->main_zebra_update_hold) + return; + + if (safi == SAFI_FLOWSPEC) { + bgp_pbr_update_entry(bgp, bgp_dest_get_prefix(dest), info, afi, + safi, true); + return; + } + + /* Make Zebra API structure. */ + api.vrf_id = bgp->vrf_id; + api.type = ZEBRA_ROUTE_BGP; + api.safi = safi; + api.prefix = *p; + SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP); + + peer = info->peer; + + if (info->type == ZEBRA_ROUTE_BGP + && info->sub_type == BGP_ROUTE_IMPORTED) { + + /* Obtain peer from parent */ + if (info->extra && info->extra->vrfleak && + info->extra->vrfleak->parent) + peer = ((struct bgp_path_info *)(info->extra->vrfleak + ->parent)) + ->peer; + } + + tag = info->attr->tag; + + if (peer->sort == BGP_PEER_IBGP || peer->sort == BGP_PEER_CONFED + || info->sub_type == BGP_ROUTE_AGGREGATE) { + SET_FLAG(api.flags, ZEBRA_FLAG_IBGP); + SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION); + } + + if ((peer->sort == BGP_PEER_EBGP && peer->ttl != BGP_DEFAULT_TTL) + || CHECK_FLAG(peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK) + || CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK)) + + allow_recursion = true; + + if (info->attr->rmap_table_id) { + SET_FLAG(api.message, ZAPI_MESSAGE_TABLEID); + api.tableid = info->attr->rmap_table_id; + } + + if (CHECK_FLAG(info->attr->flag, ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR))) + SET_FLAG(api.message, ZAPI_MESSAGE_SRTE); + + /* Metric is currently based on the best-path only */ + metric = info->attr->med; + + bgp_zebra_announce_parse_nexthop(info, p, bgp, &api, &valid_nh_count, + afi, safi, &nhg_id, &metric, &tag, + &allow_recursion); is_add = (valid_nh_count || nhg_id) ? true : false; @@ -1635,75 +1652,12 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, } if (bgp_debug_zebra(p)) { - char nh_buf[INET6_ADDRSTRLEN]; - char eth_buf[ETHER_ADDR_STRLEN + 7] = {'\0'}; - char buf1[ETHER_ADDR_STRLEN]; - char label_buf[20]; - char sid_buf[20]; - char segs_buf[256]; - int i; - zlog_debug( "Tx route %s VRF %u %pFX metric %u tag %" ROUTE_TAG_PRI " count %d nhg %d", is_add ? "add" : "delete", bgp->vrf_id, &api.prefix, api.metric, api.tag, api.nexthop_num, nhg_id); - for (i = 0; i < api.nexthop_num; i++) { - api_nh = &api.nexthops[i]; - - switch (api_nh->type) { - case NEXTHOP_TYPE_IFINDEX: - nh_buf[0] = '\0'; - break; - case NEXTHOP_TYPE_IPV4: - case NEXTHOP_TYPE_IPV4_IFINDEX: - nh_family = AF_INET; - inet_ntop(nh_family, &api_nh->gate, nh_buf, - sizeof(nh_buf)); - break; - case NEXTHOP_TYPE_IPV6: - case NEXTHOP_TYPE_IPV6_IFINDEX: - nh_family = AF_INET6; - inet_ntop(nh_family, &api_nh->gate, nh_buf, - sizeof(nh_buf)); - break; - case NEXTHOP_TYPE_BLACKHOLE: - strlcpy(nh_buf, "blackhole", sizeof(nh_buf)); - break; - default: - /* Note: add new nexthop case */ - assert(0); - break; - } - - label_buf[0] = '\0'; - eth_buf[0] = '\0'; - segs_buf[0] = '\0'; - if (CHECK_FLAG(api_nh->flags, - ZAPI_NEXTHOP_FLAG_LABEL) && - !CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_EVPN)) - snprintf(label_buf, sizeof(label_buf), - "label %u", api_nh->labels[0]); - if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_SEG6) && - !CHECK_FLAG(api_nh->flags, - ZAPI_NEXTHOP_FLAG_EVPN)) { - inet_ntop(AF_INET6, &api_nh->seg6_segs, - sid_buf, sizeof(sid_buf)); - snprintf(segs_buf, sizeof(segs_buf), "segs %s", - sid_buf); - } - if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_EVPN) && - !is_zero_mac(&api_nh->rmac)) - snprintf(eth_buf, sizeof(eth_buf), " RMAC %s", - prefix_mac2str(&api_nh->rmac, - buf1, sizeof(buf1))); - zlog_debug(" nhop [%d]: %s if %u VRF %u wt %u %s %s %s", - i + 1, nh_buf, api_nh->ifindex, - api_nh->vrf_id, api_nh->weight, - label_buf, segs_buf, eth_buf); - } - - int recursion_flag = 0; + bgp_debug_zebra_nh(&api); if (CHECK_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION)) recursion_flag = 1; @@ -1909,7 +1863,7 @@ int bgp_redistribute_set(struct bgp *bgp, afi_t afi, int type, redist_add_instance(&zclient->mi_redist[afi][type], instance); } else { - if (vrf_bitmap_check(zclient->redist[afi][type], bgp->vrf_id)) + if (vrf_bitmap_check(&zclient->redist[afi][type], bgp->vrf_id)) return CMD_WARNING; #ifdef ENABLE_BGP_VNC @@ -1919,7 +1873,7 @@ int bgp_redistribute_set(struct bgp *bgp, afi_t afi, int type, } #endif - vrf_bitmap_set(zclient->redist[afi][type], bgp->vrf_id); + vrf_bitmap_set(&zclient->redist[afi][type], bgp->vrf_id); } /* @@ -2040,9 +1994,9 @@ int bgp_redistribute_unreg(struct bgp *bgp, afi_t afi, int type, return CMD_WARNING; redist_del_instance(&zclient->mi_redist[afi][type], instance); } else { - if (!vrf_bitmap_check(zclient->redist[afi][type], bgp->vrf_id)) + if (!vrf_bitmap_check(&zclient->redist[afi][type], bgp->vrf_id)) return CMD_WARNING; - vrf_bitmap_unset(zclient->redist[afi][type], bgp->vrf_id); + vrf_bitmap_unset(&zclient->redist[afi][type], bgp->vrf_id); } if (bgp_install_info_to_zebra(bgp)) { @@ -2062,8 +2016,8 @@ int bgp_redistribute_unreg(struct bgp *bgp, afi_t afi, int type, } /* Unset redistribution. */ -int bgp_redistribute_unset(struct bgp *bgp, afi_t afi, int type, - unsigned short instance) +static void _bgp_redistribute_unset(struct bgp *bgp, afi_t afi, int type, + unsigned short instance) { struct bgp_redist *red; @@ -2080,7 +2034,7 @@ int bgp_redistribute_unset(struct bgp *bgp, afi_t afi, int type, red = bgp_redist_lookup(bgp, afi, type, instance); if (!red) - return CMD_SUCCESS; + return; bgp_redistribute_unreg(bgp, afi, type, instance); @@ -2094,8 +2048,24 @@ int bgp_redistribute_unset(struct bgp *bgp, afi_t afi, int type, red->redist_metric = 0; bgp_redist_del(bgp, afi, type, instance); +} - return CMD_SUCCESS; +void bgp_redistribute_unset(struct bgp *bgp, afi_t afi, int type, + unsigned short instance) +{ + struct listnode *node, *nnode; + struct bgp_redist *red; + + if ((type != ZEBRA_ROUTE_TABLE && type != ZEBRA_ROUTE_TABLE_DIRECT) || + instance != 0) + return _bgp_redistribute_unset(bgp, afi, type, instance); + + /* walk over instance */ + if (!bgp->redist[afi][type]) + return; + + for (ALL_LIST_ELEMENTS(bgp->redist[afi][type], node, nnode, red)) + _bgp_redistribute_unset(bgp, afi, type, red->instance); } void bgp_redistribute_redo(struct bgp *bgp) @@ -2386,7 +2356,7 @@ static int rule_notify_owner(ZAPI_CALLBACK_ARGS) enum zapi_rule_notify_owner note; struct bgp_pbr_action *bgp_pbra; struct bgp_pbr_rule *bgp_pbr = NULL; - char ifname[INTERFACE_NAMSIZ + 1]; + char ifname[IFNAMSIZ + 1]; if (!zapi_rule_notify_decode(zclient->ibuf, &seqno, &priority, &unique, ifname, ¬e)) @@ -2430,8 +2400,14 @@ static int rule_notify_owner(ZAPI_CALLBACK_ARGS) /* link bgp_info to bgp_pbr */ path = (struct bgp_path_info *)bgp_pbr->path; extra = bgp_path_info_extra_get(path); - listnode_add_force(&extra->bgp_fs_iprule, - bgp_pbr); + if (!extra->flowspec) { + extra->flowspec = + XCALLOC(MTYPE_BGP_ROUTE_EXTRA_FS, + sizeof(struct bgp_path_info_extra_fs)); + extra->flowspec->bgp_fs_iprule = NULL; + extra->flowspec->bgp_fs_pbr = NULL; + } + listnode_add_force(&extra->flowspec->bgp_fs_iprule, bgp_pbr); } if (BGP_DEBUG(zebra, ZEBRA)) zlog_debug("%s: Received RULE_INSTALLED", __func__); @@ -2533,7 +2509,14 @@ static int ipset_entry_notify_owner(ZAPI_CALLBACK_ARGS) /* link bgp_path_info to bpme */ path = (struct bgp_path_info *)bgp_pbime->path; extra = bgp_path_info_extra_get(path); - listnode_add_force(&extra->bgp_fs_pbr, bgp_pbime); + if (!extra->flowspec) { + extra->flowspec = + XCALLOC(MTYPE_BGP_ROUTE_EXTRA_FS, + sizeof(struct bgp_path_info_extra_fs)); + extra->flowspec->bgp_fs_iprule = NULL; + extra->flowspec->bgp_fs_pbr = NULL; + } + listnode_add_force(&extra->flowspec->bgp_fs_pbr, bgp_pbime); } break; case ZAPI_IPSET_ENTRY_FAIL_REMOVE: @@ -2629,7 +2612,7 @@ static int bgp_zebra_route_notify_owner(int command, struct zclient *zclient, UNSET_FLAG(dest->flags, BGP_NODE_FIB_INSTALL_PENDING); SET_FLAG(dest->flags, BGP_NODE_FIB_INSTALLED); if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("route %pRN : INSTALLED", dest); + zlog_debug("route %pBD : INSTALLED", dest); /* Find the best route */ for (pi = dest->info; pi; pi = pi->next) { /* Process aggregate route */ @@ -2642,7 +2625,7 @@ static int bgp_zebra_route_notify_owner(int command, struct zclient *zclient, group_announce_route(bgp, afi, safi, dest, new_select); else { flog_err(EC_BGP_INVALID_ROUTE, - "selected route %pRN not found", dest); + "selected route %pBD not found", dest); bgp_dest_unlock_node(dest); return -1; @@ -2655,12 +2638,12 @@ static int bgp_zebra_route_notify_owner(int command, struct zclient *zclient, */ UNSET_FLAG(dest->flags, BGP_NODE_FIB_INSTALLED); if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("route %pRN: Removed from Fib", dest); + zlog_debug("route %pBD: Removed from Fib", dest); break; case ZAPI_ROUTE_FAIL_INSTALL: new_select = NULL; if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("route: %pRN Failed to Install into Fib", + zlog_debug("route: %pBD Failed to Install into Fib", dest); UNSET_FLAG(dest->flags, BGP_NODE_FIB_INSTALL_PENDING); UNSET_FLAG(dest->flags, BGP_NODE_FIB_INSTALLED); @@ -2674,7 +2657,7 @@ static int bgp_zebra_route_notify_owner(int command, struct zclient *zclient, break; case ZAPI_ROUTE_BETTER_ADMIN_WON: if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("route: %pRN removed due to better admin won", + zlog_debug("route: %pBD removed due to better admin won", dest); new_select = NULL; UNSET_FLAG(dest->flags, BGP_NODE_FIB_INSTALL_PENDING); @@ -2689,8 +2672,7 @@ static int bgp_zebra_route_notify_owner(int command, struct zclient *zclient, /* No action required */ break; case ZAPI_ROUTE_REMOVE_FAIL: - zlog_warn("%s: Route %pRN failure to remove", - __func__, dest); + zlog_warn("%s: Route %pBD failure to remove", __func__, dest); break; } @@ -2706,17 +2688,20 @@ static void bgp_encode_pbr_rule_action(struct stream *s, struct bgp_pbr_action *pbra, struct bgp_pbr_rule *pbr) { - struct prefix pfx; uint8_t fam = AF_INET; - char ifname[INTERFACE_NAMSIZ]; + struct pbr_rule r; if (pbra->nh.type == NEXTHOP_TYPE_IPV6) fam = AF_INET6; - stream_putl(s, 0); /* seqno unused */ + + /* + * Convert to canonical form + */ + memset(&r, 0, sizeof(r)); + /* r.seq unused */ if (pbr) - stream_putl(s, pbr->priority); - else - stream_putl(s, 0); + r.priority = pbr->priority; + /* ruleno unused - priority change * ruleno permits distinguishing various FS PBR entries * - FS PBR entries based on ipset/iptables @@ -2724,49 +2709,38 @@ static void bgp_encode_pbr_rule_action(struct stream *s, * the latter may contain default routing information injected by FS */ if (pbr) - stream_putl(s, pbr->unique); + r.unique = pbr->unique; else - stream_putl(s, pbra->unique); - stream_putc(s, 0); /* ip protocol being used */ - if (pbr && pbr->flags & MATCH_IP_SRC_SET) - memcpy(&pfx, &(pbr->src), sizeof(struct prefix)); - else { - memset(&pfx, 0, sizeof(pfx)); - pfx.family = fam; - } - stream_putc(s, pfx.family); - stream_putc(s, pfx.prefixlen); - stream_put(s, &pfx.u.prefix, prefix_blen(&pfx)); + r.unique = pbra->unique; - stream_putw(s, 0); /* src port */ - - if (pbr && pbr->flags & MATCH_IP_DST_SET) - memcpy(&pfx, &(pbr->dst), sizeof(struct prefix)); - else { - memset(&pfx, 0, sizeof(pfx)); - pfx.family = fam; - } - stream_putc(s, pfx.family); - stream_putc(s, pfx.prefixlen); - stream_put(s, &pfx.u.prefix, prefix_blen(&pfx)); + r.family = fam; - stream_putw(s, 0); /* dst port */ - stream_putc(s, 0); /* dsfield */ - /* if pbr present, fwmark is not used */ - if (pbr) - stream_putl(s, 0); - else - stream_putl(s, pbra->fwmark); /* fwmark */ + /* filter */ - stream_putl(s, 0); /* queue id */ - stream_putw(s, 0); /* vlan_id */ - stream_putw(s, 0); /* vlan_flags */ - stream_putw(s, 0); /* pcp */ + if (pbr && pbr->flags & MATCH_IP_SRC_SET) { + SET_FLAG(r.filter.filter_bm, PBR_FILTER_SRC_IP); + r.filter.src_ip = pbr->src; + } else { + /* ??? */ + r.filter.src_ip.family = fam; + } + if (pbr && pbr->flags & MATCH_IP_DST_SET) { + SET_FLAG(r.filter.filter_bm, PBR_FILTER_DST_IP); + r.filter.dst_ip = pbr->dst; + } else { + /* ??? */ + r.filter.dst_ip.family = fam; + } + /* src_port, dst_port, pcp, dsfield not used */ + if (!pbr) { + SET_FLAG(r.filter.filter_bm, PBR_FILTER_FWMARK); + r.filter.fwmark = pbra->fwmark; + } - stream_putl(s, pbra->table_id); + SET_FLAG(r.action.flags, PBR_ACTION_TABLE); /* always valid */ + r.action.table = pbra->table_id; - memset(ifname, 0, sizeof(ifname)); - stream_put(s, ifname, INTERFACE_NAMSIZ); /* ifname unused */ + zapi_pbr_rule_encode(s, &r); } static void bgp_encode_pbr_ipset_match(struct stream *s, @@ -2854,9 +2828,6 @@ static void bgp_zebra_connected(struct zclient *zclient) bgp_zebra_instance_register(bgp); - /* tell label pool that zebra is connected */ - bgp_lp_event_zebra_up(); - /* TODO - What if we have peers and networks configured, do we have to * kick-start them? */ @@ -2983,12 +2954,11 @@ static int bgp_zebra_process_local_l3vni(ZAPI_CALLBACK_ARGS) is_anycast_mac = stream_getl(s); if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug( - "Rx L3-VNI ADD VRF %s VNI %u RMAC svi-mac %pEA vrr-mac %pEA filter %s svi-if %u", - vrf_id_to_name(vrf_id), l3vni, &svi_rmac, - &vrr_rmac, - filter ? "prefix-routes-only" : "none", - svi_ifindex); + zlog_debug("Rx L3VNI ADD VRF %s VNI %u Originator-IP %pI4 RMAC svi-mac %pEA vrr-mac %pEA filter %s svi-if %u", + vrf_id_to_name(vrf_id), l3vni, + &originator_ip, &svi_rmac, &vrr_rmac, + filter ? "prefix-routes-only" : "none", + svi_ifindex); frrtrace(8, frr_bgp, evpn_local_l3vni_add_zrecv, l3vni, vrf_id, &svi_rmac, &vrr_rmac, filter, originator_ip, @@ -2999,7 +2969,7 @@ static int bgp_zebra_process_local_l3vni(ZAPI_CALLBACK_ARGS) is_anycast_mac); } else { if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug("Rx L3-VNI DEL VRF %s VNI %u", + zlog_debug("Rx L3VNI DEL VRF %s VNI %u", vrf_id_to_name(vrf_id), l3vni); frrtrace(2, frr_bgp, evpn_local_l3vni_del_zrecv, l3vni, vrf_id); @@ -3161,54 +3131,6 @@ static int bgp_zebra_process_local_ip_prefix(ZAPI_CALLBACK_ARGS) return 0; } -static int bgp_zebra_process_label_chunk(ZAPI_CALLBACK_ARGS) -{ - struct stream *s = NULL; - uint8_t response_keep; - uint32_t first; - uint32_t last; - uint8_t proto; - unsigned short instance; - - s = zclient->ibuf; - STREAM_GETC(s, proto); - STREAM_GETW(s, instance); - STREAM_GETC(s, response_keep); - STREAM_GETL(s, first); - STREAM_GETL(s, last); - - if (zclient->redist_default != proto) { - flog_err(EC_BGP_LM_ERROR, "Got LM msg with wrong proto %u", - proto); - return 0; - } - if (zclient->instance != instance) { - flog_err(EC_BGP_LM_ERROR, "Got LM msg with wrong instance %u", - proto); - return 0; - } - - if (first > last || - first < MPLS_LABEL_UNRESERVED_MIN || - last > MPLS_LABEL_UNRESERVED_MAX) { - - flog_err(EC_BGP_LM_ERROR, "%s: Invalid Label chunk: %u - %u", - __func__, first, last); - return 0; - } - if (BGP_DEBUG(zebra, ZEBRA)) { - zlog_debug("Label Chunk assign: %u - %u (%u) ", - first, last, response_keep); - } - - bgp_lp_event_chunk(response_keep, first, last); - - return 0; - -stream_failure: /* for STREAM_GETX */ - return -1; -} - extern struct zebra_privs_t bgpd_privs; static int bgp_ifp_create(struct interface *ifp) @@ -3308,7 +3230,7 @@ static int bgp_zebra_process_srv6_locator_delete(ZAPI_CALLBACK_ARGS) if (prefix_match((struct prefix *)&loc.prefix, (struct prefix *)&tmp_prefi)) { listnode_delete(bgp->srv6_functions, func); - XFREE(MTYPE_BGP_SRV6_FUNCTION, func); + srv6_function_free(func); } } @@ -3410,10 +3332,8 @@ static zclient_handler *const bgp_handlers[] = { [ZEBRA_INTERFACE_ADDRESS_DELETE] = bgp_interface_address_delete, [ZEBRA_INTERFACE_NBR_ADDRESS_ADD] = bgp_interface_nbr_address_add, [ZEBRA_INTERFACE_NBR_ADDRESS_DELETE] = bgp_interface_nbr_address_delete, - [ZEBRA_INTERFACE_VRF_UPDATE] = bgp_interface_vrf_update, [ZEBRA_REDISTRIBUTE_ROUTE_ADD] = zebra_read_route, [ZEBRA_REDISTRIBUTE_ROUTE_DEL] = zebra_read_route, - [ZEBRA_NEXTHOP_UPDATE] = bgp_read_nexthop_update, [ZEBRA_FEC_UPDATE] = bgp_read_fec_update, [ZEBRA_LOCAL_ES_ADD] = bgp_zebra_process_local_es_add, [ZEBRA_LOCAL_ES_DEL] = bgp_zebra_process_local_es_del, @@ -3427,7 +3347,6 @@ static zclient_handler *const bgp_handlers[] = { [ZEBRA_L3VNI_DEL] = bgp_zebra_process_local_l3vni, [ZEBRA_IP_PREFIX_ROUTE_ADD] = bgp_zebra_process_local_ip_prefix, [ZEBRA_IP_PREFIX_ROUTE_DEL] = bgp_zebra_process_local_ip_prefix, - [ZEBRA_GET_LABEL_CHUNK] = bgp_zebra_process_label_chunk, [ZEBRA_RULE_NOTIFY_OWNER] = rule_notify_owner, [ZEBRA_IPSET_NOTIFY_OWNER] = ipset_notify_owner, [ZEBRA_IPSET_ENTRY_NOTIFY_OWNER] = ipset_entry_notify_owner, @@ -3464,19 +3383,89 @@ void bgp_if_init(void) hook_register_prio(if_del, 0, bgp_if_delete_hook); } +static void bgp_start_label_manager(struct event *start) +{ + bgp_zebra_label_manager_connect(); +} + +static bool bgp_zebra_label_manager_ready(void) +{ + return (zclient_sync->sock > 0); +} + +static bool bgp_zebra_label_manager_connect(void) +{ + /* Connect to label manager. */ + if (zclient_socket_connect(zclient_sync) < 0) { + zlog_warn("%s: failed connecting synchronous zclient!", + __func__); + return false; + } + /* make socket non-blocking */ + set_nonblocking(zclient_sync->sock); + + /* Send hello to notify zebra this is a synchronous client */ + if (zclient_send_hello(zclient_sync) == ZCLIENT_SEND_FAILURE) { + zlog_warn("%s: failed sending hello for synchronous zclient!", + __func__); + close(zclient_sync->sock); + zclient_sync->sock = -1; + return false; + } + + /* Connect to label manager */ + if (lm_label_manager_connect(zclient_sync, 0) != 0) { + zlog_warn("%s: failed connecting to label manager!", __func__); + if (zclient_sync->sock > 0) { + close(zclient_sync->sock); + zclient_sync->sock = -1; + } + return false; + } + + /* tell label pool that zebra is connected */ + bgp_lp_event_zebra_up(); + + /* tell BGP L3VPN that label manager is available */ + if (bgp_get_default()) + vpn_leak_postchange_all(); + return true; +} + +static void bgp_zebra_capabilities(struct zclient_capabilities *cap) +{ + bm->v6_with_v4_nexthops = cap->v6_with_v4_nexthop; +} + void bgp_zebra_init(struct event_loop *master, unsigned short instance) { zclient_num_connects = 0; - if_zapi_callbacks(bgp_ifp_create, bgp_ifp_up, - bgp_ifp_down, bgp_ifp_destroy); + hook_register_prio(if_real, 0, bgp_ifp_create); + hook_register_prio(if_up, 0, bgp_ifp_up); + hook_register_prio(if_down, 0, bgp_ifp_down); + hook_register_prio(if_unreal, 0, bgp_ifp_destroy); /* Set default values. */ zclient = zclient_new(master, &zclient_options_default, bgp_handlers, array_size(bgp_handlers)); zclient_init(zclient, ZEBRA_ROUTE_BGP, 0, &bgpd_privs); zclient->zebra_connected = bgp_zebra_connected; + zclient->zebra_capabilities = bgp_zebra_capabilities; + zclient->nexthop_update = bgp_nexthop_update; zclient->instance = instance; + + /* Initialize special zclient for synchronous message exchanges. */ + zclient_sync = zclient_new(master, &zclient_options_sync, NULL, 0); + zclient_sync->sock = -1; + zclient_sync->redist_default = ZEBRA_ROUTE_BGP; + zclient_sync->instance = instance; + zclient_sync->session_id = 1; + zclient_sync->privs = &bgpd_privs; + + if (!bgp_zebra_label_manager_ready()) + event_add_timer(master, bgp_start_label_manager, NULL, 1, + &bm->t_bgp_start_label_manager); } void bgp_zebra_destroy(void) @@ -3486,6 +3475,12 @@ void bgp_zebra_destroy(void) zclient_stop(zclient); zclient_free(zclient); zclient = NULL; + + if (zclient_sync == NULL) + return; + zclient_stop(zclient_sync); + zclient_free(zclient_sync); + zclient_sync = NULL; } int bgp_zebra_num_connects(void) @@ -3517,11 +3512,9 @@ void bgp_send_pbr_rule_action(struct bgp_pbr_action *pbra, zclient_create_header(s, install ? ZEBRA_RULE_ADD : ZEBRA_RULE_DELETE, VRF_DEFAULT); - stream_putl(s, 1); /* send one pbr action */ bgp_encode_pbr_rule_action(s, pbra, pbr); - stream_putw_at(s, 0, stream_get_endp(s)); if ((zclient_send_message(zclient) != ZCLIENT_SEND_FAILURE) && install) { if (!pbr) @@ -3704,38 +3697,26 @@ void bgp_zebra_announce_default(struct bgp *bgp, struct nexthop *nh, api.distance = ZEBRA_EBGP_DISTANCE_DEFAULT; SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE); + api_nh->vrf_id = nh->vrf_id; + + if (BGP_DEBUG(zebra, ZEBRA)) { + struct vrf *vrf; + + vrf = vrf_lookup_by_id(nh->vrf_id); + zlog_debug("%s: %s default route to %pNHvv(%s) table %d", + bgp->name_pretty, announce ? "adding" : "withdrawing", + nh, VRF_LOGNAME(vrf), table_id); + } + /* redirect IP */ if (afi == AFI_IP && nh->gate.ipv4.s_addr != INADDR_ANY) { - api_nh->vrf_id = nh->vrf_id; api_nh->gate.ipv4 = nh->gate.ipv4; api_nh->type = NEXTHOP_TYPE_IPV4; - - if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug( - "BGP: %s default route to %pI4 table %d (redirect IP)", - announce ? "adding" : "withdrawing", - &nh->gate.ipv4, table_id); - - zclient_route_send(announce ? ZEBRA_ROUTE_ADD - : ZEBRA_ROUTE_DELETE, - zclient, &api); - } else if (afi == AFI_IP6 && - memcmp(&nh->gate.ipv6, - &in6addr_any, sizeof(struct in6_addr))) { - api_nh->vrf_id = nh->vrf_id; + } else if (afi == AFI_IP6 && memcmp(&nh->gate.ipv6, &in6addr_any, + sizeof(struct in6_addr))) { memcpy(&api_nh->gate.ipv6, &nh->gate.ipv6, sizeof(struct in6_addr)); api_nh->type = NEXTHOP_TYPE_IPV6; - - if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug( - "BGP: %s default route to %pI6 table %d (redirect IP)", - announce ? "adding" : "withdrawing", - &nh->gate.ipv6, table_id); - - zclient_route_send(announce ? ZEBRA_ROUTE_ADD - : ZEBRA_ROUTE_DELETE, - zclient, &api); } else if (nh->vrf_id != bgp->vrf_id) { struct vrf *vrf; struct interface *ifp; @@ -3749,18 +3730,12 @@ void bgp_zebra_announce_default(struct bgp *bgp, struct nexthop *nh, ifp = if_lookup_by_name_vrf(vrf->name, vrf); if (!ifp) return; - api_nh->vrf_id = nh->vrf_id; api_nh->type = NEXTHOP_TYPE_IFINDEX; api_nh->ifindex = ifp->ifindex; - if (BGP_DEBUG(zebra, ZEBRA)) - zlog_info("BGP: %s default route to %s table %d (redirect VRF)", - announce ? "adding" : "withdrawing", - vrf->name, table_id); - zclient_route_send(announce ? ZEBRA_ROUTE_ADD - : ZEBRA_ROUTE_DELETE, - zclient, &api); - return; } + + zclient_route_send(announce ? ZEBRA_ROUTE_ADD : ZEBRA_ROUTE_DELETE, + zclient, &api); } /* Send capabilities to RIB */ @@ -3914,10 +3889,13 @@ int bgp_zebra_srv6_manager_release_locator_chunk(const char *name) void bgp_zebra_send_nexthop_label(int cmd, mpls_label_t label, ifindex_t ifindex, vrf_id_t vrf_id, - enum lsp_types_t ltype, struct prefix *p) + enum lsp_types_t ltype, struct prefix *p, + uint32_t num_labels, + mpls_label_t out_labels[]) { struct zapi_labels zl = {}; struct zapi_nexthop *znh; + int i = 0; zl.type = ltype; zl.local_label = label; @@ -3935,8 +3913,62 @@ void bgp_zebra_send_nexthop_label(int cmd, mpls_label_t label, : NEXTHOP_TYPE_IPV6_IFINDEX; znh->ifindex = ifindex; znh->vrf_id = vrf_id; - znh->label_num = 0; - + if (num_labels == 0) + znh->label_num = 0; + else { + if (num_labels > MPLS_MAX_LABELS) + znh->label_num = MPLS_MAX_LABELS; + else + znh->label_num = num_labels; + for (i = 0; i < znh->label_num; i++) + znh->labels[i] = out_labels[i]; + } /* vrf_id is DEFAULT_VRF */ zebra_send_mpls_labels(zclient, cmd, &zl); } + +bool bgp_zebra_request_label_range(uint32_t base, uint32_t chunk_size, + bool label_auto) +{ + int ret; + uint32_t start, end; + + if (!zclient_sync || !bgp_zebra_label_manager_ready()) + return false; + + ret = lm_get_label_chunk(zclient_sync, 0, base, chunk_size, &start, + &end); + if (ret < 0) { + zlog_warn("%s: error getting label range!", __func__); + return false; + } + + if (start > end || start < MPLS_LABEL_UNRESERVED_MIN || + end > MPLS_LABEL_UNRESERVED_MAX) { + flog_err(EC_BGP_LM_ERROR, "%s: Invalid Label chunk: %u - %u", + __func__, start, end); + return false; + } + + if (label_auto) + /* label automatic is serviced by the bgp label pool + * manager, which allocates label chunks in + * pre-pools, and which needs to be notified about + * new chunks availability + */ + bgp_lp_event_chunk(start, end); + + return true; +} + +void bgp_zebra_release_label_range(uint32_t start, uint32_t end) +{ + int ret; + + if (!zclient_sync || !bgp_zebra_label_manager_ready()) + return; + + ret = lm_release_label_chunk(zclient_sync, start, end); + if (ret < 0) + zlog_warn("%s: error releasing label range!", __func__); +} diff --git a/bgpd/bgp_zebra.h b/bgpd/bgp_zebra.h index 7c85d86b31..4696e4dc44 100644 --- a/bgpd/bgp_zebra.h +++ b/bgpd/bgp_zebra.h @@ -10,9 +10,10 @@ /* Macro to update bgp_original based on bpg_path_info */ #define BGP_ORIGINAL_UPDATE(_bgp_orig, _mpinfo, _bgp) \ - ((_mpinfo->extra && _mpinfo->extra->bgp_orig \ - && _mpinfo->sub_type == BGP_ROUTE_IMPORTED) \ - ? (_bgp_orig = _mpinfo->extra->bgp_orig) \ + ((_mpinfo->extra && _mpinfo->extra->vrfleak && \ + _mpinfo->extra->vrfleak->bgp_orig && \ + _mpinfo->sub_type == BGP_ROUTE_IMPORTED) \ + ? (_bgp_orig = _mpinfo->extra->vrfleak->bgp_orig) \ : (_bgp_orig = _bgp)) /* Default weight for next hop, if doing weighted ECMP. */ @@ -24,7 +25,7 @@ extern void bgp_zebra_init_tm_connect(struct bgp *bgp); extern uint32_t bgp_zebra_tm_get_id(void); extern bool bgp_zebra_tm_chunk_obtained(void); extern void bgp_zebra_destroy(void); -extern int bgp_zebra_get_table_range(uint32_t chunk_size, +extern int bgp_zebra_get_table_range(struct zclient *zc, uint32_t chunk_size, uint32_t *start, uint32_t *end); extern int bgp_if_update_all(void); extern void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, @@ -63,8 +64,8 @@ extern bool bgp_redistribute_rmap_set(struct bgp_redist *red, const char *name, struct route_map *route_map); extern bool bgp_redistribute_metric_set(struct bgp *bgp, struct bgp_redist *red, afi_t afi, int type, uint32_t metric); -extern int bgp_redistribute_unset(struct bgp *bgp, afi_t afi, int type, - unsigned short instance); +extern void bgp_redistribute_unset(struct bgp *bgp, afi_t afi, int type, + unsigned short instance); extern int bgp_redistribute_unreg(struct bgp *bgp, afi_t afi, int type, unsigned short instance); @@ -121,5 +122,9 @@ extern int bgp_zebra_srv6_manager_release_locator_chunk(const char *name); extern void bgp_zebra_send_nexthop_label(int cmd, mpls_label_t label, ifindex_t index, vrf_id_t vrfid, enum lsp_types_t ltype, - struct prefix *p); + struct prefix *p, uint32_t num_labels, + mpls_label_t out_labels[]); +extern bool bgp_zebra_request_label_range(uint32_t base, uint32_t chunk_size, + bool label_auto); +extern void bgp_zebra_release_label_range(uint32_t start, uint32_t end); #endif /* _QUAGGA_BGP_ZEBRA_H */ diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 99c6a46e7c..90ac529f8c 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -63,6 +63,7 @@ #include "bgpd/bgp_vty.h" #include "bgpd/bgp_mpath.h" #include "bgpd/bgp_nht.h" +#include "bgpd/bgp_nhg.h" #include "bgpd/bgp_updgrp.h" #include "bgpd/bgp_bfd.h" #include "bgpd/bgp_memory.h" @@ -80,7 +81,6 @@ #include "bgp_trace.h" DEFINE_MTYPE_STATIC(BGPD, PEER_TX_SHUTDOWN_MSG, "Peer shutdown message (TX)"); -DEFINE_MTYPE_STATIC(BGPD, BGP_EVPN_INFO, "BGP EVPN instance information"); DEFINE_QOBJ_TYPE(bgp_master); DEFINE_QOBJ_TYPE(bgp); DEFINE_QOBJ_TYPE(peer); @@ -135,11 +135,12 @@ static int bgp_check_main_socket(bool create, struct bgp *bgp) void bgp_session_reset(struct peer *peer) { - if (peer->doppelganger && (peer->doppelganger->status != Deleted) - && !(CHECK_FLAG(peer->doppelganger->flags, PEER_FLAG_CONFIG_NODE))) + if (peer->doppelganger && + (peer->doppelganger->connection->status != Deleted) && + !(CHECK_FLAG(peer->doppelganger->flags, PEER_FLAG_CONFIG_NODE))) peer_delete(peer->doppelganger); - BGP_EVENT_ADD(peer, BGP_Stop); + BGP_EVENT_ADD(peer->connection, BGP_Stop); } /* @@ -156,16 +157,16 @@ static void bgp_session_reset_safe(struct peer *peer, struct listnode **nnode) n = (nnode) ? *nnode : NULL; npeer = (n) ? listgetdata(n) : NULL; - if (peer->doppelganger && (peer->doppelganger->status != Deleted) - && !(CHECK_FLAG(peer->doppelganger->flags, - PEER_FLAG_CONFIG_NODE))) { + if (peer->doppelganger && + (peer->doppelganger->connection->status != Deleted) && + !(CHECK_FLAG(peer->doppelganger->flags, PEER_FLAG_CONFIG_NODE))) { if (peer->doppelganger == npeer) /* nnode and *nnode are confirmed to be non-NULL here */ *nnode = (*nnode)->next; peer_delete(peer->doppelganger); } - BGP_EVENT_ADD(peer, BGP_Stop); + BGP_EVENT_ADD(peer->connection, BGP_Stop); } /* BGP global flag manipulation. */ @@ -186,7 +187,6 @@ int bgp_option_set(int flag) int bgp_option_unset(int flag) { switch (flag) { - /* Fall through. */ case BGP_OPT_NO_ZEBRA: case BGP_OPT_NO_FIB: UNSET_FLAG(bm->options, flag); @@ -306,9 +306,9 @@ static int bgp_router_id_set(struct bgp *bgp, const struct in_addr *id, for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { IPV4_ADDR_COPY(&peer->local_id, id); - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) { + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) { peer->last_reset = PEER_DOWN_RID_CHANGE; - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } } @@ -410,6 +410,9 @@ void bgp_router_id_static_set(struct bgp *bgp, struct in_addr id) void bm_wait_for_fib_set(bool set) { bool send_msg = false; + struct bgp *bgp; + struct peer *peer; + struct listnode *next, *node; if (bm->wait_for_fib == set) return; @@ -428,12 +431,32 @@ void bm_wait_for_fib_set(bool set) if (send_msg && zclient) zebra_route_notify_send(ZEBRA_ROUTE_NOTIFY_REQUEST, zclient, set); + + /* + * If this is configed at a time when peers are already set + * FRR needs to reset the connection(s) as that some installs + * may have already happened in some shape fashion or form + * let's just start over + */ + for (ALL_LIST_ELEMENTS_RO(bm->bgp, next, bgp)) { + for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) { + if (!BGP_IS_VALID_STATE_FOR_NOTIF( + peer->connection->status)) + continue; + + peer->last_reset = PEER_DOWN_SUPPRESS_FIB_PENDING; + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, + BGP_NOTIFY_CEASE_CONFIG_CHANGE); + } + } } /* Set the suppress fib pending for the bgp configuration */ void bgp_suppress_fib_pending_set(struct bgp *bgp, bool set) { bool send_msg = false; + struct peer *peer; + struct listnode *node; if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) return; @@ -465,6 +488,21 @@ void bgp_suppress_fib_pending_set(struct bgp *bgp, bool set) zebra_route_notify_send(ZEBRA_ROUTE_NOTIFY_REQUEST, zclient, set); } + + /* + * If this is configed at a time when peers are already set + * FRR needs to reset the connection as that some installs + * may have already happened in some shape fashion or form + * let's just start over + */ + for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) { + if (!BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) + continue; + + peer->last_reset = PEER_DOWN_SUPPRESS_FIB_PENDING; + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, + BGP_NOTIFY_CEASE_CONFIG_CHANGE); + } } /* BGP's cluster-id control. */ @@ -485,9 +523,9 @@ void bgp_cluster_id_set(struct bgp *bgp, struct in_addr *cluster_id) if (peer->sort != BGP_PEER_IBGP) continue; - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) { + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) { peer->last_reset = PEER_DOWN_CLID_CHANGE; - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } } @@ -509,20 +547,31 @@ void bgp_cluster_id_unset(struct bgp *bgp) if (peer->sort != BGP_PEER_IBGP) continue; - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) { + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) { peer->last_reset = PEER_DOWN_CLID_CHANGE; - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } } } /* BGP timer configuration. */ -void bgp_timers_set(struct bgp *bgp, uint32_t keepalive, uint32_t holdtime, - uint32_t connect_retry, uint32_t delayopen) +void bgp_timers_set(struct vty *vty, struct bgp *bgp, uint32_t keepalive, + uint32_t holdtime, uint32_t connect_retry, + uint32_t delayopen) { - bgp->default_keepalive = - (keepalive < holdtime / 3 ? keepalive : holdtime / 3); + uint32_t default_keepalive = holdtime / 3; + + if (keepalive > default_keepalive) { + if (vty) + vty_out(vty, + "%% keepalive value %u is larger than 1/3 of the holdtime, setting to %u\n", + keepalive, default_keepalive); + } else { + default_keepalive = keepalive; + } + + bgp->default_keepalive = default_keepalive; bgp->default_holdtime = holdtime; bgp->default_connect_retry = connect_retry; bgp->default_delayopen = delayopen; @@ -566,8 +615,8 @@ void bgp_confederation_id_set(struct bgp *bgp, as_t as, const char *as_str) already_confed = bgp_config_check(bgp, BGP_CONFIG_CONFEDERATION); bgp->confed_id = as; if (bgp->confed_id_pretty) - XFREE(MTYPE_BGP, bgp->confed_id_pretty); - bgp->confed_id_pretty = XSTRDUP(MTYPE_BGP, as_str); + XFREE(MTYPE_BGP_NAME, bgp->confed_id_pretty); + bgp->confed_id_pretty = XSTRDUP(MTYPE_BGP_NAME, as_str); bgp_config_set(bgp, BGP_CONFIG_CONFEDERATION); /* If we were doing confederation already, this is just an external @@ -582,12 +631,12 @@ void bgp_confederation_id_set(struct bgp *bgp, as_t as, const char *as_str) if (ptype == BGP_PEER_EBGP) { peer->local_as = as; if (BGP_IS_VALID_STATE_FOR_NOTIF( - peer->status)) { + peer->connection->status)) { peer->last_reset = PEER_DOWN_CONFED_ID_CHANGE; - bgp_notify_send( - peer, BGP_NOTIFY_CEASE, - BGP_NOTIFY_CEASE_CONFIG_CHANGE); + bgp_notify_send(peer->connection, + BGP_NOTIFY_CEASE, + BGP_NOTIFY_CEASE_CONFIG_CHANGE); } else bgp_session_reset_safe(peer, &nnode); } @@ -600,12 +649,12 @@ void bgp_confederation_id_set(struct bgp *bgp, as_t as, const char *as_str) if (ptype == BGP_PEER_EBGP) peer->local_as = as; if (BGP_IS_VALID_STATE_FOR_NOTIF( - peer->status)) { + peer->connection->status)) { peer->last_reset = PEER_DOWN_CONFED_ID_CHANGE; - bgp_notify_send( - peer, BGP_NOTIFY_CEASE, - BGP_NOTIFY_CEASE_CONFIG_CHANGE); + bgp_notify_send(peer->connection, + BGP_NOTIFY_CEASE, + BGP_NOTIFY_CEASE_CONFIG_CHANGE); } else bgp_session_reset_safe(peer, &nnode); } @@ -620,16 +669,18 @@ void bgp_confederation_id_unset(struct bgp *bgp) struct listnode *node, *nnode; bgp->confed_id = 0; - XFREE(MTYPE_BGP, bgp->confed_id_pretty); + XFREE(MTYPE_BGP_NAME, bgp->confed_id_pretty); bgp_config_unset(bgp, BGP_CONFIG_CONFEDERATION); for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { /* We're looking for peers who's AS is not local */ if (peer_sort(peer) != BGP_PEER_IBGP) { peer->local_as = bgp->as; - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) { + if (BGP_IS_VALID_STATE_FOR_NOTIF( + peer->connection->status)) { peer->last_reset = PEER_DOWN_CONFED_ID_CHANGE; - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(peer->connection, + BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } @@ -672,7 +723,7 @@ void bgp_confederation_peers_add(struct bgp *bgp, as_t as, const char *as_str) bgp->confed_peers[bgp->confed_peers_cnt].as = as; bgp->confed_peers[bgp->confed_peers_cnt].as_pretty = - XSTRDUP(MTYPE_BGP, as_str); + XSTRDUP(MTYPE_BGP_NAME, as_str); bgp->confed_peers_cnt++; if (bgp_config_check(bgp, BGP_CONFIG_CONFEDERATION)) { @@ -681,12 +732,12 @@ void bgp_confederation_peers_add(struct bgp *bgp, as_t as, const char *as_str) peer->local_as = bgp->as; (void)peer_sort(peer); if (BGP_IS_VALID_STATE_FOR_NOTIF( - peer->status)) { + peer->connection->status)) { peer->last_reset = PEER_DOWN_CONFED_PEER_CHANGE; - bgp_notify_send( - peer, BGP_NOTIFY_CEASE, - BGP_NOTIFY_CEASE_CONFIG_CHANGE); + bgp_notify_send(peer->connection, + BGP_NOTIFY_CEASE, + BGP_NOTIFY_CEASE_CONFIG_CHANGE); } else bgp_session_reset_safe(peer, &nnode); } @@ -710,7 +761,7 @@ void bgp_confederation_peers_remove(struct bgp *bgp, as_t as) for (i = 0; i < bgp->confed_peers_cnt; i++) if (bgp->confed_peers[i].as == as) { - XFREE(MTYPE_BGP, bgp->confed_peers[i].as_pretty); + XFREE(MTYPE_BGP_NAME, bgp->confed_peers[i].as_pretty); for (j = i + 1; j < bgp->confed_peers_cnt; j++) { bgp->confed_peers[j - 1].as = bgp->confed_peers[j].as; @@ -738,12 +789,12 @@ void bgp_confederation_peers_remove(struct bgp *bgp, as_t as) peer->local_as = bgp->confed_id; (void)peer_sort(peer); if (BGP_IS_VALID_STATE_FOR_NOTIF( - peer->status)) { + peer->connection->status)) { peer->last_reset = PEER_DOWN_CONFED_PEER_CHANGE; - bgp_notify_send( - peer, BGP_NOTIFY_CEASE, - BGP_NOTIFY_CEASE_CONFIG_CHANGE); + bgp_notify_send(peer->connection, + BGP_NOTIFY_CEASE, + BGP_NOTIFY_CEASE_CONFIG_CHANGE); } else bgp_session_reset_safe(peer, &nnode); } @@ -934,13 +985,13 @@ int peer_cmp(struct peer *p1, struct peer *p2) } else return strcmp(p1->group->name, p2->group->name); - return sockunion_cmp(&p1->su, &p2->su); + return sockunion_cmp(&p1->connection->su, &p2->connection->su); } static unsigned int peer_hash_key_make(const void *p) { const struct peer *peer = p; - return sockunion_hash(&peer->su); + return sockunion_hash(&peer->connection->su); } static bool peer_hash_same(const void *p1, const void *p2) @@ -948,9 +999,9 @@ static bool peer_hash_same(const void *p1, const void *p2) const struct peer *peer1 = p1; const struct peer *peer2 = p2; - return (sockunion_same(&peer1->su, &peer2->su) - && CHECK_FLAG(peer1->flags, PEER_FLAG_CONFIG_NODE) - == CHECK_FLAG(peer2->flags, PEER_FLAG_CONFIG_NODE)); + return (sockunion_same(&peer1->connection->su, &peer2->connection->su) && + CHECK_FLAG(peer1->flags, PEER_FLAG_CONFIG_NODE) == + CHECK_FLAG(peer2->flags, PEER_FLAG_CONFIG_NODE)); } void peer_flag_inherit(struct peer *peer, uint64_t flag) @@ -1111,34 +1162,103 @@ enum bgp_peer_sort peer_sort_lookup(struct peer *peer) return peer->sort; } +/* + * Mutex will be freed in peer_connection_free + * this is a convenience function to reduce cut-n-paste + */ +void bgp_peer_connection_buffers_free(struct peer_connection *connection) +{ + frr_with_mutex (&connection->io_mtx) { + if (connection->ibuf) { + stream_fifo_free(connection->ibuf); + connection->ibuf = NULL; + } + + if (connection->obuf) { + stream_fifo_free(connection->obuf); + connection->obuf = NULL; + } + + if (connection->ibuf_work) { + ringbuf_del(connection->ibuf_work); + connection->ibuf_work = NULL; + } + } +} + +void bgp_peer_connection_free(struct peer_connection **connection) +{ + bgp_peer_connection_buffers_free(*connection); + pthread_mutex_destroy(&(*connection)->io_mtx); + + memset(*connection, 0, sizeof(struct peer_connection)); + XFREE(MTYPE_BGP_PEER_CONNECTION, *connection); + + connection = NULL; +} + +struct peer_connection *bgp_peer_connection_new(struct peer *peer) +{ + struct peer_connection *connection; + + connection = XCALLOC(MTYPE_BGP_PEER_CONNECTION, + sizeof(struct peer_connection)); + + connection->peer = peer; + connection->fd = -1; + + connection->ibuf = stream_fifo_new(); + connection->obuf = stream_fifo_new(); + pthread_mutex_init(&connection->io_mtx, NULL); + + /* We use a larger buffer for peer->obuf_work in the event that: + * - We RX a BGP_UPDATE where the attributes alone are just + * under BGP_EXTENDED_MESSAGE_MAX_PACKET_SIZE. + * - The user configures an outbound route-map that does many as-path + * prepends or adds many communities. At most they can have + * CMD_ARGC_MAX args in a route-map so there is a finite limit on how + * large they can make the attributes. + * + * Having a buffer with BGP_MAX_PACKET_SIZE_OVERFLOW allows us to avoid + * bounds checking for every single attribute as we construct an + * UPDATE. + */ + connection->ibuf_work = + ringbuf_new(BGP_MAX_PACKET_SIZE * BGP_READ_PACKET_MAX); + + connection->status = Idle; + connection->ostatus = Idle; + + return connection; +} + static void peer_free(struct peer *peer) { afi_t afi; safi_t safi; - assert(peer->status == Deleted); + assert(peer->connection->status == Deleted); QOBJ_UNREG(peer); /* this /ought/ to have been done already through bgp_stop earlier, * but just to be sure.. */ - bgp_timer_set(peer); - bgp_reads_off(peer); - bgp_writes_off(peer); - event_cancel_event_ready(bm->master, peer); + bgp_timer_set(peer->connection); + bgp_reads_off(peer->connection); + bgp_writes_off(peer->connection); + event_cancel_event_ready(bm->master, peer->connection); FOREACH_AFI_SAFI (afi, safi) EVENT_OFF(peer->t_revalidate_all[afi][safi]); - assert(!peer->t_write); - assert(!peer->t_read); - BGP_EVENT_FLUSH(peer); - - pthread_mutex_destroy(&peer->io_mtx); + assert(!peer->connection->t_write); + assert(!peer->connection->t_read); + event_cancel_event_ready(bm->master, peer->connection); /* Free connected nexthop, if present */ if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE) && !peer_dynamic_neighbor(peer)) - bgp_delete_connected_nexthop(family2afi(peer->su.sa.sa_family), + bgp_delete_connected_nexthop(family2afi(peer->connection->su.sa + .sa_family), peer); FOREACH_AFI_SAFI (afi, safi) { @@ -1172,8 +1292,6 @@ static void peer_free(struct peer *peer) if (peer->clear_node_queue) work_queue_free_and_null(&peer->clear_node_queue); - bgp_sync_delete(peer); - XFREE(MTYPE_PEER_CONF_IF, peer->conf_if); XFREE(MTYPE_BGP_SOFT_VERSION, peer->soft_version); @@ -1183,15 +1301,19 @@ static void peer_free(struct peer *peer) bgp_peer_remove_bfd_config(peer); FOREACH_AFI_SAFI (afi, safi) - bgp_addpath_set_peer_type(peer, afi, safi, BGP_ADDPATH_NONE); + bgp_addpath_set_peer_type(peer, afi, safi, BGP_ADDPATH_NONE, 0); if (peer->change_local_as_pretty) - XFREE(MTYPE_BGP, peer->change_local_as_pretty); + XFREE(MTYPE_BGP_NAME, peer->change_local_as_pretty); if (peer->as_pretty) - XFREE(MTYPE_BGP, peer->as_pretty); + XFREE(MTYPE_BGP_NAME, peer->as_pretty); + + bgp_peer_connection_free(&peer->connection); bgp_unlock(peer->bgp); + stream_free(peer->last_reset_cause); + memset(peer, 0, sizeof(struct peer)); XFREE(MTYPE_BGP_PEER, peer); @@ -1344,7 +1466,9 @@ static void bgp_srv6_init(struct bgp *bgp) bgp->srv6_enabled = false; memset(bgp->srv6_locator_name, 0, sizeof(bgp->srv6_locator_name)); bgp->srv6_locator_chunks = list_new(); + bgp->srv6_locator_chunks->del = srv6_locator_chunk_list_free; bgp->srv6_functions = list_new(); + bgp->srv6_functions->del = (void (*)(void *))srv6_function_free; } static void bgp_srv6_cleanup(struct bgp *bgp) @@ -1369,12 +1493,12 @@ struct peer *peer_new(struct bgp *bgp) /* Allocate new peer. */ peer = XCALLOC(MTYPE_BGP_PEER, sizeof(struct peer)); + /* Create buffers. */ + peer->connection = bgp_peer_connection_new(peer); + /* Set default value. */ - peer->fd = -1; peer->v_start = BGP_INIT_START_TIMER; peer->v_connect = bgp->default_connect_retry; - peer->status = Idle; - peer->ostatus = Idle; peer->cur_event = peer->last_event = peer->last_major_event = 0; peer->bgp = bgp_lock(bgp); peer = peer_lock(peer); /* initial reference */ @@ -1398,6 +1522,7 @@ struct peer *peer_new(struct bgp *bgp) SET_FLAG(peer->af_flags_invert[afi][safi], PEER_FLAG_SEND_LARGE_COMMUNITY); peer->addpath_type[afi][safi] = BGP_ADDPATH_NONE; + peer->addpath_best_selected[afi][safi] = 0; peer->soo[afi][safi] = NULL; } @@ -1407,35 +1532,12 @@ struct peer *peer_new(struct bgp *bgp) SET_FLAG(peer->sflags, PEER_STATUS_CAPABILITY_OPEN); + if (CHECK_FLAG(bgp->flags, BGP_FLAG_ENFORCE_FIRST_AS)) + SET_FLAG(peer->flags, PEER_FLAG_ENFORCE_FIRST_AS); + /* Initialize per peer bgp GR FSM */ bgp_peer_gr_init(peer); - /* Create buffers. */ - peer->ibuf = stream_fifo_new(); - peer->obuf = stream_fifo_new(); - pthread_mutex_init(&peer->io_mtx, NULL); - - /* We use a larger buffer for peer->obuf_work in the event that: - * - We RX a BGP_UPDATE where the attributes alone are just - * under BGP_EXTENDED_MESSAGE_MAX_PACKET_SIZE. - * - The user configures an outbound route-map that does many as-path - * prepends or adds many communities. At most they can have - * CMD_ARGC_MAX args in a route-map so there is a finite limit on how - * large they can make the attributes. - * - * Having a buffer with BGP_MAX_PACKET_SIZE_OVERFLOW allows us to avoid - * bounds checking for every single attribute as we construct an - * UPDATE. - */ - peer->obuf_work = - stream_new(BGP_MAX_PACKET_SIZE + BGP_MAX_PACKET_SIZE_OVERFLOW); - peer->ibuf_work = - ringbuf_new(BGP_MAX_PACKET_SIZE * BGP_READ_PACKET_MAX); - - peer->scratch = stream_new(BGP_MAX_PACKET_SIZE); - - bgp_sync_init(peer); - /* Get service port number. */ sp = getservbyname("bgp", "tcp"); peer->port = (sp == NULL) ? BGP_PORT_DEFAULT : ntohs(sp->s_port); @@ -1479,6 +1581,7 @@ void peer_xfer_config(struct peer *peer_dst, struct peer *peer_src) /* copy tcp_mss value */ peer_dst->tcp_mss = peer_src->tcp_mss; (void)peer_sort(peer_dst); + peer_dst->sub_sort = peer_src->sub_sort; peer_dst->rmap_type = peer_src->rmap_type; peer_dst->local_role = peer_src->local_role; @@ -1546,59 +1649,57 @@ void peer_xfer_config(struct peer *peer_dst, struct peer *peer_src) peer_dst->ttl = peer_src->ttl; } -static int bgp_peer_conf_if_to_su_update_v4(struct peer *peer, +static int bgp_peer_conf_if_to_su_update_v4(struct peer_connection *connection, struct interface *ifp) { struct connected *ifc; struct prefix p; uint32_t addr; - struct listnode *node; /* If our IPv4 address on the interface is /30 or /31, we can derive the * IPv4 address of the other end. */ - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { + frr_each (if_connected, ifp->connected, ifc) { if (ifc->address && (ifc->address->family == AF_INET)) { prefix_copy(&p, CONNECTED_PREFIX(ifc)); if (p.prefixlen == 30) { - peer->su.sa.sa_family = AF_INET; + connection->su.sa.sa_family = AF_INET; addr = ntohl(p.u.prefix4.s_addr); if (addr % 4 == 1) - peer->su.sin.sin_addr.s_addr = + connection->su.sin.sin_addr.s_addr = htonl(addr + 1); else if (addr % 4 == 2) - peer->su.sin.sin_addr.s_addr = + connection->su.sin.sin_addr.s_addr = htonl(addr - 1); #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN - peer->su.sin.sin_len = + connection->su.sin.sin_len = sizeof(struct sockaddr_in); #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */ return 1; } else if (p.prefixlen == 31) { - peer->su.sa.sa_family = AF_INET; + connection->su.sa.sa_family = AF_INET; addr = ntohl(p.u.prefix4.s_addr); if (addr % 2 == 0) - peer->su.sin.sin_addr.s_addr = + connection->su.sin.sin_addr.s_addr = htonl(addr + 1); else - peer->su.sin.sin_addr.s_addr = + connection->su.sin.sin_addr.s_addr = htonl(addr - 1); #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN - peer->su.sin.sin_len = + connection->su.sin.sin_len = sizeof(struct sockaddr_in); #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */ return 1; - } else if (bgp_debug_neighbor_events(peer)) - zlog_debug( - "%s: IPv4 interface address is not /30 or /31, v4 session not started", - peer->conf_if); + } else if (bgp_debug_neighbor_events(connection->peer)) + zlog_debug("%s: IPv4 interface address is not /30 or /31, v4 session not started", + connection->peer->conf_if); } } return 0; } -static bool bgp_peer_conf_if_to_su_update_v6(struct peer *peer, +static bool bgp_peer_conf_if_to_su_update_v6(struct peer_connection *connection, struct interface *ifp) { struct nbr_connected *ifc_nbr; @@ -1606,13 +1707,13 @@ static bool bgp_peer_conf_if_to_su_update_v6(struct peer *peer, /* Have we learnt the peer's IPv6 link-local address? */ if (ifp->nbr_connected && (ifc_nbr = listnode_head(ifp->nbr_connected))) { - peer->su.sa.sa_family = AF_INET6; - memcpy(&peer->su.sin6.sin6_addr, &ifc_nbr->address->u.prefix, - sizeof(struct in6_addr)); + connection->su.sa.sa_family = AF_INET6; + memcpy(&connection->su.sin6.sin6_addr, + &ifc_nbr->address->u.prefix, sizeof(struct in6_addr)); #ifdef SIN6_LEN - peer->su.sin6.sin6_len = sizeof(struct sockaddr_in6); + connection->su.sin6.sin6_len = sizeof(struct sockaddr_in6); #endif - peer->su.sin6.sin6_scope_id = ifp->ifindex; + connection->su.sin6.sin6_scope_id = ifp->ifindex; return true; } @@ -1624,13 +1725,14 @@ static bool bgp_peer_conf_if_to_su_update_v6(struct peer *peer, * learnt/derived peer address. If the address has changed, update the * password on the listen socket, if needed. */ -void bgp_peer_conf_if_to_su_update(struct peer *peer) +void bgp_peer_conf_if_to_su_update(struct peer_connection *connection) { struct interface *ifp; int prev_family; int peer_addr_updated = 0; struct listnode *node; union sockunion old_su; + struct peer *peer = connection->peer; /* * This function is only ever needed when FRR an interface @@ -1640,9 +1742,9 @@ void bgp_peer_conf_if_to_su_update(struct peer *peer) if (!peer->conf_if) return; - old_su = peer->su; + old_su = connection->su; - prev_family = peer->su.sa.sa_family; + prev_family = connection->su.sa.sa_family; if ((ifp = if_lookup_by_name(peer->conf_if, peer->bgp->vrf_id))) { peer->ifp = ifp; /* If BGP unnumbered is not "v6only", we first see if we can @@ -1651,7 +1753,8 @@ void bgp_peer_conf_if_to_su_update(struct peer *peer) */ if (!CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY)) peer_addr_updated = - bgp_peer_conf_if_to_su_update_v4(peer, ifp); + bgp_peer_conf_if_to_su_update_v4(connection, + ifp); /* If "v6only" or we can't derive peer's IPv4 address, see if * we've @@ -1661,7 +1764,8 @@ void bgp_peer_conf_if_to_su_update(struct peer *peer) */ if (!peer_addr_updated) peer_addr_updated = - bgp_peer_conf_if_to_su_update_v6(peer, ifp); + bgp_peer_conf_if_to_su_update_v6(connection, + ifp); } /* If we could derive the peer address, we may need to install the * password @@ -1673,20 +1777,21 @@ void bgp_peer_conf_if_to_su_update(struct peer *peer) if (peer_addr_updated) { if (CHECK_FLAG(peer->flags, PEER_FLAG_PASSWORD) && prev_family == AF_UNSPEC) - bgp_md5_set(peer); + bgp_md5_set(connection); } else { if (CHECK_FLAG(peer->flags, PEER_FLAG_PASSWORD) && prev_family != AF_UNSPEC) - bgp_md5_unset(peer); - peer->su.sa.sa_family = AF_UNSPEC; - memset(&peer->su.sin6.sin6_addr, 0, sizeof(struct in6_addr)); + bgp_md5_unset(connection); + connection->su.sa.sa_family = AF_UNSPEC; + memset(&connection->su.sin6.sin6_addr, 0, + sizeof(struct in6_addr)); } /* * If they are the same, nothing to do here, move along */ - if (!sockunion_same(&old_su, &peer->su)) { - union sockunion new_su = peer->su; + if (!sockunion_same(&old_su, &connection->su)) { + union sockunion new_su = connection->su; struct bgp *bgp = peer->bgp; /* @@ -1715,11 +1820,11 @@ void bgp_peer_conf_if_to_su_update(struct peer *peer) * scan through looking for a matching * su if needed. */ - peer->su = old_su; + connection->su = old_su; hash_release(peer->bgp->peerhash, peer); listnode_delete(peer->bgp->peer, peer); - peer->su = new_su; + connection->su = new_su; (void)hash_get(peer->bgp->peerhash, peer, hash_alloc_intern); listnode_add_sort(peer->bgp->peer, peer); @@ -1786,13 +1891,13 @@ struct peer *peer_create(union sockunion *su, const char *conf_if, if (conf_if) { peer->conf_if = XSTRDUP(MTYPE_PEER_CONF_IF, conf_if); if (su) - peer->su = *su; + peer->connection->su = *su; else - bgp_peer_conf_if_to_su_update(peer); + bgp_peer_conf_if_to_su_update(peer->connection); XFREE(MTYPE_BGP_PEER_HOST, peer->host); peer->host = XSTRDUP(MTYPE_BGP_PEER_HOST, conf_if); } else if (su) { - peer->su = *su; + peer->connection->su = *su; sockunion2str(su, buf, SU_ADDRSTRLEN); XFREE(MTYPE_BGP_PEER_HOST, peer->host); peer->host = XSTRDUP(MTYPE_BGP_PEER_HOST, buf); @@ -1801,7 +1906,7 @@ struct peer *peer_create(union sockunion *su, const char *conf_if, peer->as = remote_as; /* internal and external values do not use as_pretty */ if (as_str && asn_str2asn(as_str, NULL)) - peer->as_pretty = XSTRDUP(MTYPE_BGP, as_str); + peer->as_pretty = XSTRDUP(MTYPE_BGP_NAME, as_str); peer->as_type = as_type; peer->local_id = bgp->router_id; peer->v_holdtime = bgp->default_holdtime; @@ -1831,7 +1936,7 @@ struct peer *peer_create(union sockunion *su, const char *conf_if, active = peer_active(peer); if (!active) { - if (peer->su.sa.sa_family == AF_UNSPEC) + if (peer->connection->su.sa.sa_family == AF_UNSPEC) peer->last_reset = PEER_DOWN_NBR_ADDR; else peer->last_reset = PEER_DOWN_NOAFI_ACTIVATED; @@ -1863,7 +1968,7 @@ struct peer *peer_create(union sockunion *su, const char *conf_if, peer_flag_set(peer, PEER_FLAG_SHUTDOWN); /* Set up peer's events and timers. */ else if (!active && peer_active(peer)) - bgp_timer_set(peer); + bgp_timer_set(peer->connection); bgp_peer_gr_flags_update(peer); BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer); @@ -1912,9 +2017,9 @@ void peer_as_change(struct peer *peer, as_t as, int as_specified, /* Stop peer. */ if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) { + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) { peer->last_reset = PEER_DOWN_REMOTE_AS_CHANGE; - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } else bgp_session_reset(peer); @@ -1923,10 +2028,10 @@ void peer_as_change(struct peer *peer, as_t as, int as_specified, peer->as = as; if (as_specified == AS_SPECIFIED && as_str) { if (peer->as_pretty) - XFREE(MTYPE_BGP, peer->as_pretty); - peer->as_pretty = XSTRDUP(MTYPE_BGP, as_str); + XFREE(MTYPE_BGP_NAME, peer->as_pretty); + peer->as_pretty = XSTRDUP(MTYPE_BGP_NAME, as_str); } else if (peer->as_type == AS_UNSPECIFIED && peer->as_pretty) - XFREE(MTYPE_BGP, peer->as_pretty); + XFREE(MTYPE_BGP_NAME, peer->as_pretty); peer->as_type = as_specified; if (bgp_config_check(peer->bgp, BGP_CONFIG_CONFEDERATION) @@ -2265,9 +2370,9 @@ static int peer_activate_af(struct peer *peer, afi_t afi, safi_t safi) peer_group2peer_config_copy_af(peer->group, peer, afi, safi); if (!active && peer_active(peer)) { - bgp_timer_set(peer); + bgp_timer_set(peer->connection); } else { - if (peer_established(peer)) { + if (peer_established(peer->connection)) { if (CHECK_FLAG(peer->cap, PEER_CAP_DYNAMIC_RCV)) { peer->afc_adv[afi][safi] = 1; bgp_capability_send(peer, afi, safi, @@ -2280,13 +2385,15 @@ static int peer_activate_af(struct peer *peer, afi_t afi, safi_t safi) } } else { peer->last_reset = PEER_DOWN_AF_ACTIVATE; - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(peer->connection, + BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } } - if (peer->status == OpenSent || peer->status == OpenConfirm) { + if (peer->connection->status == OpenSent || + peer->connection->status == OpenConfirm) { peer->last_reset = PEER_DOWN_AF_ACTIVATE; - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } /* @@ -2299,11 +2406,10 @@ static int peer_activate_af(struct peer *peer, afi_t afi, safi_t safi) * activation. */ other = peer->doppelganger; - if (other - && (other->status == OpenSent - || other->status == OpenConfirm)) { + if (other && (other->connection->status == OpenSent || + other->connection->status == OpenConfirm)) { other->last_reset = PEER_DOWN_AF_ACTIVATE; - bgp_notify_send(other, BGP_NOTIFY_CEASE, + bgp_notify_send(other->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } } @@ -2319,6 +2425,7 @@ int peer_activate(struct peer *peer, afi_t afi, safi_t safi) struct listnode *node, *nnode; struct peer *tmp_peer; struct bgp *bgp; + safi_t safi_check; /* Nothing to do if we've already activated this peer */ if (peer->afc[afi][safi]) @@ -2349,16 +2456,22 @@ int peer_activate(struct peer *peer, afi_t afi, safi_t safi) } /* If this is the first peer to be activated for this - * afi/labeled-unicast recalc bestpaths to trigger label allocation */ - if (ret != BGP_ERR_PEER_SAFI_CONFLICT && safi == SAFI_LABELED_UNICAST - && !bgp->allocate_mpls_labels[afi][SAFI_UNICAST]) { + * afi/labeled-unicast or afi/mpls-vpn, recalc bestpaths to trigger + * label allocation */ + if (safi == SAFI_LABELED_UNICAST) + safi_check = SAFI_UNICAST; + else + safi_check = safi; + if (ret != BGP_ERR_PEER_SAFI_CONFLICT && + (safi == SAFI_LABELED_UNICAST || safi == SAFI_MPLS_VPN) && + !bgp->allocate_mpls_labels[afi][safi_check]) { if (BGP_DEBUG(zebra, ZEBRA)) zlog_debug( - "peer(s) are now active for labeled-unicast, allocate MPLS labels"); - - bgp->allocate_mpls_labels[afi][SAFI_UNICAST] = 1; - bgp_recalculate_afi_safi_bestpaths(bgp, afi, SAFI_UNICAST); + "peer(s) are now active for %s, allocate MPLS labels", + safi2str(safi)); + bgp->allocate_mpls_labels[afi][safi_check] = 1; + bgp_recalculate_afi_safi_bestpaths(bgp, afi, safi_check); } if (safi == SAFI_FLOWSPEC) { @@ -2391,7 +2504,7 @@ static bool non_peergroup_deactivate_af(struct peer *peer, afi_t afi, return true; } - if (peer_established(peer)) { + if (peer_established(peer->connection)) { if (CHECK_FLAG(peer->cap, PEER_CAP_DYNAMIC_RCV)) { peer->afc_adv[afi][safi] = 0; peer->afc_nego[afi][safi] = 0; @@ -2404,12 +2517,13 @@ static bool non_peergroup_deactivate_af(struct peer *peer, afi_t afi, peer->pcount[afi][safi] = 0; } else { peer->last_reset = PEER_DOWN_NEIGHBOR_DELETE; - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(peer->connection, + BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } } else { peer->last_reset = PEER_DOWN_NEIGHBOR_DELETE; - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } } @@ -2424,6 +2538,7 @@ int peer_deactivate(struct peer *peer, afi_t afi, safi_t safi) struct peer *tmp_peer; struct listnode *node, *nnode; struct bgp *bgp; + safi_t safi_check; /* Nothing to do if we've already de-activated this peer */ if (!peer->afc[afi][safi]) @@ -2445,17 +2560,22 @@ int peer_deactivate(struct peer *peer, afi_t afi, safi_t safi) bgp = peer->bgp; /* If this is the last peer to be deactivated for this - * afi/labeled-unicast recalc bestpaths to trigger label deallocation */ - if (safi == SAFI_LABELED_UNICAST - && bgp->allocate_mpls_labels[afi][SAFI_UNICAST] - && !bgp_afi_safi_peer_exists(bgp, afi, safi)) { + * afi/labeled-unicast or afi/mpls-vpn, recalc bestpaths to trigger + * label deallocation */ + if (safi == SAFI_LABELED_UNICAST) + safi_check = SAFI_UNICAST; + else + safi_check = safi; + if ((safi == SAFI_LABELED_UNICAST || safi == SAFI_MPLS_VPN) && + bgp->allocate_mpls_labels[afi][safi_check] && + !bgp_afi_safi_peer_exists(bgp, afi, safi)) { if (BGP_DEBUG(zebra, ZEBRA)) zlog_debug( - "peer(s) are no longer active for labeled-unicast, deallocate MPLS labels"); - - bgp->allocate_mpls_labels[afi][SAFI_UNICAST] = 0; - bgp_recalculate_afi_safi_bestpaths(bgp, afi, SAFI_UNICAST); + "peer(s) are no longer active for %s, deallocate MPLS labels", + safi2str(safi)); + bgp->allocate_mpls_labels[afi][safi_check] = 0; + bgp_recalculate_afi_safi_bestpaths(bgp, afi, safi_check); } return ret; } @@ -2473,13 +2593,13 @@ void peer_nsf_stop(struct peer *peer) EVENT_OFF(peer->t_llgr_stale[afi][safi]); } - if (peer->t_gr_restart) { - EVENT_OFF(peer->t_gr_restart); + if (peer->connection->t_gr_restart) { + EVENT_OFF(peer->connection->t_gr_restart); if (bgp_debug_neighbor_events(peer)) zlog_debug("%pBP graceful restart timer stopped", peer); } - if (peer->t_gr_stale) { - EVENT_OFF(peer->t_gr_stale); + if (peer->connection->t_gr_stale) { + EVENT_OFF(peer->connection->t_gr_stale); if (bgp_debug_neighbor_events(peer)) zlog_debug( "%pBP graceful restart stalepath timer stopped", @@ -2509,21 +2629,23 @@ int peer_delete(struct peer *peer) struct listnode *pn; int accept_peer; - assert(peer->status != Deleted); + assert(peer->connection->status != Deleted); bgp = peer->bgp; accept_peer = CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER); bgp_soft_reconfig_table_task_cancel(bgp, NULL, peer); - bgp_keepalives_off(peer); - bgp_reads_off(peer); - bgp_writes_off(peer); - event_cancel_event_ready(bm->master, peer); + bgp_keepalives_off(peer->connection); + bgp_reads_off(peer->connection); + bgp_writes_off(peer->connection); + event_cancel_event_ready(bm->master, peer->connection); FOREACH_AFI_SAFI (afi, safi) EVENT_OFF(peer->t_revalidate_all[afi][safi]); - assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_WRITES_ON)); - assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_READS_ON)); + assert(!CHECK_FLAG(peer->connection->thread_flags, + PEER_THREAD_WRITES_ON)); + assert(!CHECK_FLAG(peer->connection->thread_flags, + PEER_THREAD_READS_ON)); assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_KEEPALIVES_ON)); if (CHECK_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT)) @@ -2554,7 +2676,7 @@ int peer_delete(struct peer *peer) * executed after peer structure is deleted. */ peer->last_reset = PEER_DOWN_NEIGHBOR_DELETE; - bgp_stop(peer); + bgp_stop(peer->connection); UNSET_FLAG(peer->flags, PEER_FLAG_DELETE); if (peer->doppelganger) { @@ -2563,7 +2685,7 @@ int peer_delete(struct peer *peer) } UNSET_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER); - bgp_fsm_change_status(peer, Deleted); + bgp_fsm_change_status(peer->connection, Deleted); /* Remove from NHT */ if (CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE)) @@ -2572,13 +2694,14 @@ int peer_delete(struct peer *peer) /* Password configuration */ if (CHECK_FLAG(peer->flags, PEER_FLAG_PASSWORD)) { XFREE(MTYPE_PEER_PASSWORD, peer->password); - if (!accept_peer && !BGP_PEER_SU_UNSPEC(peer) - && !CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP) - && !CHECK_FLAG(peer->flags, PEER_FLAG_DYNAMIC_NEIGHBOR)) - bgp_md5_unset(peer); + if (!accept_peer && + !BGP_CONNECTION_SU_UNSPEC(peer->connection) && + !CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP) && + !CHECK_FLAG(peer->flags, PEER_FLAG_DYNAMIC_NEIGHBOR)) + bgp_md5_unset(peer->connection); } - bgp_timer_set(peer); /* stops all timers for Deleted */ + bgp_timer_set(peer->connection); /* stops all timers for Deleted */ /* Delete from all peer list. */ if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP) @@ -2595,32 +2718,6 @@ int peer_delete(struct peer *peer) peer_unlock(peer); /* bgp peer list reference */ } - /* Buffers. */ - if (peer->ibuf) { - stream_fifo_free(peer->ibuf); - peer->ibuf = NULL; - } - - if (peer->obuf) { - stream_fifo_free(peer->obuf); - peer->obuf = NULL; - } - - if (peer->ibuf_work) { - ringbuf_del(peer->ibuf_work); - peer->ibuf_work = NULL; - } - - if (peer->obuf_work) { - stream_free(peer->obuf_work); - peer->obuf_work = NULL; - } - - if (peer->scratch) { - stream_free(peer->scratch); - peer->scratch = NULL; - } - /* Local and remote addresses. */ if (peer->su_local) { sockunion_free(peer->su_local); @@ -2812,8 +2909,8 @@ static void peer_group2peer_config_copy(struct peer_group *group, PEER_STR_ATTR_INHERIT(peer, group, password, MTYPE_PEER_PASSWORD); - if (!BGP_PEER_SU_UNSPEC(peer)) - bgp_md5_set(peer); + if (!BGP_CONNECTION_SU_UNSPEC(peer->connection)) + bgp_md5_set(peer->connection); /* update-source apply */ if (!CHECK_FLAG(peer->flags_override, PEER_FLAG_UPDATE_SOURCE)) { @@ -2871,8 +2968,8 @@ int peer_group_remote_as(struct bgp *bgp, const char *group_name, as_t *as, void peer_notify_unconfig(struct peer *peer) { - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_PEER_UNCONFIG); } @@ -2886,8 +2983,8 @@ static void peer_notify_shutdown(struct peer *peer) return; } - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN); } @@ -2898,7 +2995,7 @@ void peer_group_notify_unconfig(struct peer_group *group) for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) { other = peer->doppelganger; - if (other && other->status != Deleted) { + if (other && other->connection->status != Deleted) { other->group = NULL; peer_notify_unconfig(other); } else @@ -2924,7 +3021,7 @@ int peer_group_delete(struct peer_group *group) bgp_zebra_terminate_radv(bgp, peer); peer_delete(peer); - if (other && other->status != Deleted) { + if (other && other->connection->status != Deleted) { other->group = NULL; peer_delete(other); } @@ -2973,7 +3070,7 @@ int peer_group_remote_as_delete(struct peer_group *group) peer_delete(peer); - if (other && other->status != Deleted) { + if (other && other->connection->status != Deleted) { other->group = NULL; peer_delete(other); } @@ -3039,8 +3136,8 @@ int peer_group_listen_range_del(struct peer_group *group, struct prefix *range) if (!peer_dynamic_neighbor(peer)) continue; - if (sockunion2hostprefix(&peer->su, &prefix2) - && prefix_match(prefix, &prefix2)) { + if (sockunion2hostprefix(&peer->connection->su, &prefix2) && + prefix_match(prefix, &prefix2)) { if (bgp_debug_neighbor_events(peer)) zlog_debug( "Deleting dynamic neighbor %s group %s upon delete of listen range %pFX", @@ -3093,6 +3190,7 @@ int peer_group_bind(struct bgp *bgp, union sockunion *su, struct peer *peer, peer->as_type = group->conf->as_type; peer->as = group->conf->as; peer->sort = group->conf->sort; + peer->sub_sort = group->conf->sub_sort; } ptype = peer_sort(peer); @@ -3153,9 +3251,9 @@ int peer_group_bind(struct bgp *bgp, union sockunion *su, struct peer *peer, SET_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE); - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) { + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) { peer->last_reset = PEER_DOWN_RMAP_BIND; - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } else { bgp_session_reset(peer); @@ -3194,7 +3292,7 @@ int peer_group_bind(struct bgp *bgp, union sockunion *su, struct peer *peer, /* Set up peer's events and timers. */ if (peer_active(peer)) - bgp_timer_set(peer); + bgp_timer_set(peer->connection); } return 0; @@ -3233,9 +3331,9 @@ static struct bgp *bgp_create(as_t *as, const char *name, bgp = XCALLOC(MTYPE_BGP, sizeof(struct bgp)); bgp->as = *as; if (as_pretty) - bgp->as_pretty = XSTRDUP(MTYPE_BGP, as_pretty); + bgp->as_pretty = XSTRDUP(MTYPE_BGP_NAME, as_pretty); else - bgp->as_pretty = XSTRDUP(MTYPE_BGP, asn_asn2asplain(*as)); + bgp->as_pretty = XSTRDUP(MTYPE_BGP_NAME, asn_asn2asplain(*as)); if (asnotation != ASNOTATION_UNDEFINED) { bgp->asnotation = asnotation; @@ -3330,6 +3428,7 @@ static struct bgp *bgp_create(as_t *as, const char *name, bgp_addpath_init_bgp_data(&bgp->tx_addpath); bgp->fast_convergence = false; bgp->llgr_stale_time = BGP_DEFAULT_LLGR_STALE_TIME; + bgp->rmap_def_originate_eval_timer = RMAP_DEFAULT_ORIGINATE_EVAL_TIMER; #ifdef ENABLE_BGP_VNC if (inst_type != BGP_INSTANCE_TYPE_VRF) { @@ -3360,15 +3459,17 @@ static struct bgp *bgp_create(as_t *as, const char *name, bgp_label_per_nexthop_cache_init( &bgp->mpls_labels_per_nexthop[afi]); + bgp_mplsvpn_nh_label_bind_cache_init(&bgp->mplsvpn_nh_label_bind); + if (name) - bgp->name = XSTRDUP(MTYPE_BGP, name); + bgp->name = XSTRDUP(MTYPE_BGP_NAME, name); event_add_timer(bm->master, bgp_startup_timer_expire, bgp, bgp->restart_time, &bgp->t_startup); /* printable name we can use in debug messages */ if (inst_type == BGP_INSTANCE_TYPE_DEFAULT) { - bgp->name_pretty = XSTRDUP(MTYPE_BGP, "VRF default"); + bgp->name_pretty = XSTRDUP(MTYPE_BGP_NAME, "VRF default"); } else { const char *n; int len; @@ -3380,7 +3481,7 @@ static struct bgp *bgp_create(as_t *as, const char *name, len = 4 + 1 + strlen(n) + 1; /* "view foo\0" */ - bgp->name_pretty = XCALLOC(MTYPE_BGP, len); + bgp->name_pretty = XCALLOC(MTYPE_BGP_NAME, len); snprintf(bgp->name_pretty, len, "%s %s", (bgp->inst_type == BGP_INSTANCE_TYPE_VRF) ? "VRF" @@ -3402,8 +3503,6 @@ static struct bgp *bgp_create(as_t *as, const char *name, /* assign a unique rd id for auto derivation of vrf's RD */ bf_assign_index(bm->rd_idspace, bgp->vrf_rd_id); - bgp->evpn_info = XCALLOC(MTYPE_BGP_EVPN_INFO, - sizeof(struct bgp_evpn_info)); bgp_evpn_init(bgp); bgp_evpn_vrf_es_init(bgp); bgp_pbr_init(bgp); @@ -3640,9 +3739,9 @@ static void bgp_zclient_set_redist(afi_t afi, int type, unsigned short instance, instance); } else { if (set) - vrf_bitmap_set(zclient->redist[afi][type], vrf_id); + vrf_bitmap_set(&zclient->redist[afi][type], vrf_id); else - vrf_bitmap_unset(zclient->redist[afi][type], vrf_id); + vrf_bitmap_unset(&zclient->redist[afi][type], vrf_id); } } @@ -3685,7 +3784,7 @@ void bgp_instance_up(struct bgp *bgp) /* Kick off any peers that may have been configured. */ for (ALL_LIST_ELEMENTS(bgp->peer, node, next, peer)) { if (!BGP_PEER_START_SUPPRESSED(peer)) - BGP_EVENT_ADD(peer, BGP_Start); + BGP_EVENT_ADD(peer->connection, BGP_Start); } /* Process any networks that have been configured. */ @@ -3703,16 +3802,13 @@ void bgp_instance_down(struct bgp *bgp) struct listnode *next; /* Stop timers. */ - if (bgp->t_rmap_def_originate_eval) { + if (bgp->t_rmap_def_originate_eval) EVENT_OFF(bgp->t_rmap_def_originate_eval); - bgp_unlock(bgp); /* TODO - This timer is started with a lock - - why? */ - } /* Bring down peers, so corresponding routes are purged. */ for (ALL_LIST_ELEMENTS(bgp->peer, node, next, peer)) { - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN); else bgp_session_reset(peer); @@ -3810,11 +3906,8 @@ int bgp_delete(struct bgp *bgp) vpn_leak_zebra_vrf_label_withdraw(bgp, AFI_IP6); /* Stop timers. */ - if (bgp->t_rmap_def_originate_eval) { + if (bgp->t_rmap_def_originate_eval) EVENT_OFF(bgp->t_rmap_def_originate_eval); - bgp_unlock(bgp); /* TODO - This timer is started with a lock - - why? */ - } /* Inform peers we're going down. */ for (ALL_LIST_ELEMENTS(bgp->peer, node, next, peer)) @@ -3975,8 +4068,6 @@ void bgp_free(struct bgp *bgp) bgp_evpn_cleanup(bgp); bgp_pbr_cleanup(bgp); - bgp_srv6_cleanup(bgp); - XFREE(MTYPE_BGP_EVPN_INFO, bgp->evpn_info); for (afi = AFI_IP; afi < AFI_MAX; afi++) { enum vpn_policy_direction dir; @@ -3993,15 +4084,32 @@ void bgp_free(struct bgp *bgp) if (bgp->vpn_policy[afi].rtlist[dir]) ecommunity_free(&bgp->vpn_policy[afi].rtlist[dir]); if (bgp->vpn_policy[afi].tovpn_rd_pretty) - XFREE(MTYPE_BGP, bgp->vpn_policy[afi].tovpn_rd_pretty); + XFREE(MTYPE_BGP_NAME, + bgp->vpn_policy[afi].tovpn_rd_pretty); + if (bgp->vpn_policy[afi].tovpn_sid_locator != NULL) + srv6_locator_chunk_free( + &bgp->vpn_policy[afi].tovpn_sid_locator); + if (bgp->vpn_policy[afi].tovpn_zebra_vrf_sid_last_sent != NULL) + XFREE(MTYPE_BGP_SRV6_SID, + bgp->vpn_policy[afi] + .tovpn_zebra_vrf_sid_last_sent); + if (bgp->vpn_policy[afi].tovpn_sid != NULL) { + sid_unregister(bgp, bgp->vpn_policy[afi].tovpn_sid); + XFREE(MTYPE_BGP_SRV6_SID, + bgp->vpn_policy[afi].tovpn_sid); + } } - + bgp_srv6_cleanup(bgp); bgp_confederation_id_unset(bgp); - XFREE(MTYPE_BGP, bgp->as_pretty); - XFREE(MTYPE_BGP, bgp->name); - XFREE(MTYPE_BGP, bgp->name_pretty); - XFREE(MTYPE_BGP, bgp->snmp_stats); + for (int i = 0; i < bgp->confed_peers_cnt; i++) + XFREE(MTYPE_BGP_NAME, bgp->confed_peers[i].as_pretty); + + XFREE(MTYPE_BGP_NAME, bgp->as_pretty); + XFREE(MTYPE_BGP_NAME, bgp->name); + XFREE(MTYPE_BGP_NAME, bgp->name_pretty); + XFREE(MTYPE_BGP_NAME, bgp->snmp_stats); + XFREE(MTYPE_BGP_CONFED_LIST, bgp->confed_peers); XFREE(MTYPE_BGP, bgp); } @@ -4066,8 +4174,11 @@ struct peer *peer_lookup(struct bgp *bgp, union sockunion *su) { struct peer *peer = NULL; struct peer tmp_peer; + struct peer_connection connection; + memset(&connection, 0, sizeof(struct peer_connection)); memset(&tmp_peer, 0, sizeof(struct peer)); + tmp_peer.connection = &connection; /* * We do not want to find the doppelganger peer so search for the peer @@ -4076,7 +4187,7 @@ struct peer *peer_lookup(struct bgp *bgp, union sockunion *su) */ SET_FLAG(tmp_peer.flags, PEER_FLAG_CONFIG_NODE); - tmp_peer.su = *su; + connection.su = *su; if (bgp != NULL) { peer = hash_lookup(bgp->peerhash, &tmp_peer); @@ -4275,7 +4386,7 @@ bool bgp_path_attribute_discard(struct peer *peer, char *buf, size_t size) buf[0] = '\0'; - for (unsigned int i = 0; i < BGP_ATTR_MAX; i++) { + for (unsigned int i = 1; i <= BGP_ATTR_MAX; i++) { if (peer->discard_attrs[i]) snprintf(buf + strlen(buf), size - strlen(buf), "%s%d", (strlen(buf) > 0) ? " " : "", i); @@ -4295,7 +4406,7 @@ bool bgp_path_attribute_treat_as_withdraw(struct peer *peer, char *buf, buf[0] = '\0'; - for (unsigned int i = 0; i < BGP_ATTR_MAX; i++) { + for (unsigned int i = 1; i <= BGP_ATTR_MAX; i++) { if (peer->withdraw_attrs[i]) snprintf(buf + strlen(buf), size - strlen(buf), "%s%d", (strlen(buf) > 0) ? " " : "", i); @@ -4310,7 +4421,7 @@ bool bgp_path_attribute_treat_as_withdraw(struct peer *peer, char *buf, /* If peer is configured at least one address family return 1. */ bool peer_active(struct peer *peer) { - if (BGP_PEER_SU_UNSPEC(peer)) + if (BGP_CONNECTION_SU_UNSPEC(peer->connection)) return false; if (peer->afc[AFI_IP][SAFI_UNICAST] || peer->afc[AFI_IP][SAFI_MULTICAST] || peer->afc[AFI_IP][SAFI_LABELED_UNICAST] @@ -4381,33 +4492,32 @@ void peer_change_action(struct peer *peer, afi_t afi, safi_t safi, if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) return; - if (!peer_established(peer)) + if (!peer_established(peer->connection)) return; if (type == peer_change_reset) { /* If we're resetting session, we've to delete both peer struct */ - if ((peer->doppelganger) - && (peer->doppelganger->status != Deleted) - && (!CHECK_FLAG(peer->doppelganger->flags, - PEER_FLAG_CONFIG_NODE))) + if ((peer->doppelganger) && + (peer->doppelganger->connection->status != Deleted) && + (!CHECK_FLAG(peer->doppelganger->flags, + PEER_FLAG_CONFIG_NODE))) peer_delete(peer->doppelganger); - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } else if (type == peer_change_reset_in) { - if (CHECK_FLAG(peer->cap, PEER_CAP_REFRESH_OLD_RCV) - || CHECK_FLAG(peer->cap, PEER_CAP_REFRESH_NEW_RCV)) + if (CHECK_FLAG(peer->cap, PEER_CAP_REFRESH_RCV)) bgp_route_refresh_send(peer, afi, safi, 0, 0, 0, BGP_ROUTE_REFRESH_NORMAL); else { - if ((peer->doppelganger) - && (peer->doppelganger->status != Deleted) - && (!CHECK_FLAG(peer->doppelganger->flags, - PEER_FLAG_CONFIG_NODE))) + if ((peer->doppelganger) && + (peer->doppelganger->connection->status != Deleted) && + (!CHECK_FLAG(peer->doppelganger->flags, + PEER_FLAG_CONFIG_NODE))) peer_delete(peer->doppelganger); - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } } else if (type == peer_change_reset_out) { @@ -4455,12 +4565,12 @@ static const struct peer_flag_action peer_flag_action_list[] = { {PEER_FLAG_UPDATE_SOURCE, 0, peer_change_none}, {PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE, 0, peer_change_none}, {PEER_FLAG_EXTENDED_OPT_PARAMS, 0, peer_change_reset}, - {PEER_FLAG_ROLE_STRICT_MODE, 0, peer_change_reset}, - {PEER_FLAG_ROLE, 0, peer_change_reset}, + {PEER_FLAG_ROLE_STRICT_MODE, 0, peer_change_none}, + {PEER_FLAG_ROLE, 0, peer_change_none}, {PEER_FLAG_PORT, 0, peer_change_reset}, {PEER_FLAG_AIGP, 0, peer_change_none}, {PEER_FLAG_GRACEFUL_SHUTDOWN, 0, peer_change_none}, - {PEER_FLAG_CAPABILITY_SOFT_VERSION, 0, peer_change_reset}, + {PEER_FLAG_CAPABILITY_SOFT_VERSION, 0, peer_change_none}, {0, 0, 0}}; static const struct peer_flag_action peer_af_flag_action_list[] = { @@ -4491,7 +4601,7 @@ static const struct peer_flag_action peer_af_flag_action_list[] = { {PEER_FLAG_AS_OVERRIDE, 1, peer_change_reset_out}, {PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE, 1, peer_change_reset_out}, {PEER_FLAG_WEIGHT, 0, peer_change_reset_in}, - {PEER_FLAG_DISABLE_ADDPATH_RX, 0, peer_change_reset}, + {PEER_FLAG_DISABLE_ADDPATH_RX, 0, peer_change_none}, {PEER_FLAG_SOO, 0, peer_change_reset}, {PEER_FLAG_ACCEPT_OWN, 0, peer_change_reset}, {0, 0, 0}}; @@ -4552,15 +4662,16 @@ static void peer_flag_modify_action(struct peer *peer, uint64_t flag) UNSET_FLAG(peer->sflags, PEER_STATUS_PREFIX_OVERFLOW); - if (peer->t_pmax_restart) { - EVENT_OFF(peer->t_pmax_restart); + if (peer->connection->t_pmax_restart) { + EVENT_OFF(peer->connection->t_pmax_restart); if (bgp_debug_neighbor_events(peer)) zlog_debug( "%pBP Maximum-prefix restart timer canceled", peer); } - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) { + if (BGP_IS_VALID_STATE_FOR_NOTIF( + peer->connection->status)) { char *msg = peer->tx_shutdown_message; size_t msglen; uint8_t msgbuf[BGP_ADMIN_SHUTDOWN_MSG_LEN + 1]; @@ -4577,20 +4688,21 @@ static void peer_flag_modify_action(struct peer *peer, uint64_t flag) memcpy(msgbuf + 1, msg, msglen); bgp_notify_send_with_data( - peer, BGP_NOTIFY_CEASE, + peer->connection, + BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN, msgbuf, msglen + 1); } else - bgp_notify_send( - peer, BGP_NOTIFY_CEASE, - BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN); + bgp_notify_send(peer->connection, + BGP_NOTIFY_CEASE, + BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN); } else bgp_session_reset(peer); } else { peer->v_start = BGP_INIT_START_TIMER; - BGP_EVENT_ADD(peer, BGP_Stop); + BGP_EVENT_ADD(peer->connection, BGP_Stop); } - } else if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) { + } else if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) { if (flag == PEER_FLAG_DYNAMIC_CAPABILITY) peer->last_reset = PEER_DOWN_CAPABILITY_CHANGE; else if (flag == PEER_FLAG_PASSIVE) @@ -4598,7 +4710,7 @@ static void peer_flag_modify_action(struct peer *peer, uint64_t flag) else if (flag == PEER_FLAG_DISABLE_CONNECTED_CHECK) peer->last_reset = PEER_DOWN_MULTIHOP_CHANGE; - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } else bgp_session_reset(peer); @@ -4627,7 +4739,7 @@ void bgp_shutdown_enable(struct bgp *bgp, const char *msg) continue; /* send a RFC 4486 notification message if necessary */ - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) { + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) { if (msg) { size_t datalen = strlen(msg); @@ -4637,14 +4749,14 @@ void bgp_shutdown_enable(struct bgp *bgp, const char *msg) data[0] = datalen; memcpy(data + 1, msg, datalen); - bgp_notify_send_with_data( - peer, BGP_NOTIFY_CEASE, - BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN, data, - datalen + 1); + bgp_notify_send_with_data(peer->connection, + BGP_NOTIFY_CEASE, + BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN, + data, datalen + 1); } else { - bgp_notify_send( - peer, BGP_NOTIFY_CEASE, - BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN); + bgp_notify_send(peer->connection, + BGP_NOTIFY_CEASE, + BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN); } } @@ -4652,7 +4764,7 @@ void bgp_shutdown_enable(struct bgp *bgp, const char *msg) peer->v_start = BGP_INIT_START_TIMER; /* trigger a RFC 4271 ManualStop event */ - BGP_EVENT_ADD(peer, BGP_Stop); + BGP_EVENT_ADD(peer->connection, BGP_Stop); } /* set the BGP instances shutdown flag */ @@ -4677,7 +4789,7 @@ void bgp_shutdown_disable(struct bgp *bgp) UNSET_FLAG(bgp->flags, BGP_FLAG_SHUTDOWN); for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) - bgp_timer_set(peer); + bgp_timer_set(peer->connection); } /* Change specified peer flag. */ @@ -4902,8 +5014,8 @@ static int peer_af_flag_modify(struct peer *peer, afi_t afi, safi_t safi, COND_FLAG(peer->af_flags[afi][safi], flag, set); /* Execute action when peer is established. */ - if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP) - && peer_established(peer)) { + if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP) && + peer_established(peer->connection)) { if (!set && flag == PEER_FLAG_SOFT_RECONFIG) bgp_clear_adj_in(peer, afi, safi); else { @@ -4916,6 +5028,16 @@ static int peer_af_flag_modify(struct peer *peer, afi_t afi, safi_t safi, else if (flag == PEER_FLAG_ORF_PREFIX_RM) peer->last_reset = PEER_DOWN_CAPABILITY_CHANGE; + /* We should not reset the session if + * dynamic capability is enabled and we + * are changing the ORF prefix flags. + */ + if ((CHECK_FLAG(peer->cap, PEER_CAP_DYNAMIC_RCV) && + CHECK_FLAG(peer->cap, PEER_CAP_DYNAMIC_ADV)) && + (flag == PEER_FLAG_ORF_PREFIX_RM || + flag == PEER_FLAG_ORF_PREFIX_SM)) + action.type = peer_change_none; + peer_change_action(peer, afi, safi, action.type); } } @@ -4956,7 +5078,7 @@ static int peer_af_flag_modify(struct peer *peer, afi_t afi, safi_t safi, set != member_invert); /* Execute flag action on peer-group member. */ - if (peer_established(member)) { + if (peer_established(member->connection)) { if (!set && flag == PEER_FLAG_SOFT_RECONFIG) bgp_clear_adj_in(member, afi, safi); else { @@ -4976,6 +5098,18 @@ static int peer_af_flag_modify(struct peer *peer, afi_t afi, safi_t safi, member->last_reset = PEER_DOWN_CAPABILITY_CHANGE; + /* We should not reset the session if + * dynamic capability is enabled and we + * are changing the ORF prefix flags. + */ + if ((CHECK_FLAG(peer->cap, + PEER_CAP_DYNAMIC_RCV) && + CHECK_FLAG(peer->cap, + PEER_CAP_DYNAMIC_ADV)) && + (flag == PEER_FLAG_ORF_PREFIX_RM || + flag == PEER_FLAG_ORF_PREFIX_SM)) + action.type = peer_change_none; + peer_change_action(member, afi, safi, action.type); } @@ -5049,8 +5183,10 @@ int peer_ebgp_multihop_set(struct peer *peer, int ttl) if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { if (peer->sort != BGP_PEER_IBGP) { - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + if (BGP_IS_VALID_STATE_FOR_NOTIF( + peer->connection->status)) + bgp_notify_send(peer->connection, + BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); else bgp_session_reset(peer); @@ -5067,8 +5203,10 @@ int peer_ebgp_multihop_set(struct peer *peer, int ttl) peer->ttl = group->conf->ttl; - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + if (BGP_IS_VALID_STATE_FOR_NOTIF( + peer->connection->status)) + bgp_notify_send(peer->connection, + BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); else bgp_session_reset(peer); @@ -5104,8 +5242,8 @@ int peer_ebgp_multihop_unset(struct peer *peer) peer->ttl = ttl; if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); else bgp_session_reset(peer); @@ -5121,11 +5259,12 @@ int peer_ebgp_multihop_unset(struct peer *peer) peer->ttl = BGP_DEFAULT_TTL; - if (peer->fd >= 0) { - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) - bgp_notify_send( - peer, BGP_NOTIFY_CEASE, - BGP_NOTIFY_CEASE_CONFIG_CHANGE); + if (peer->connection->fd >= 0) { + if (BGP_IS_VALID_STATE_FOR_NOTIF( + peer->connection->status)) + bgp_notify_send(peer->connection, + BGP_NOTIFY_CEASE, + BGP_NOTIFY_CEASE_CONFIG_CHANGE); else bgp_session_reset(peer); } @@ -5178,7 +5317,6 @@ int peer_role_set(struct peer *peer, uint8_t role, bool strict_mode) else UNSET_FLAG(peer->flags, PEER_FLAG_ROLE_STRICT_MODE); - bgp_session_reset(peer); } return CMD_SUCCESS; @@ -5223,7 +5361,6 @@ int peer_role_set(struct peer *peer, uint8_t role, bool strict_mode) UNSET_FLAG(member->flags, PEER_FLAG_ROLE_STRICT_MODE); } - bgp_session_reset(member); } } @@ -5279,9 +5416,9 @@ int peer_update_source_if_set(struct peer *peer, const char *ifname) /* Check if handling a regular peer. */ if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { /* Send notification or reset peer depending on state. */ - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) { + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) { peer->last_reset = PEER_DOWN_UPDATE_SOURCE_CHANGE; - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } else bgp_session_reset(peer); @@ -5317,9 +5454,9 @@ int peer_update_source_if_set(struct peer *peer, const char *ifname) member->update_source = NULL; /* Send notification or reset peer depending on state. */ - if (BGP_IS_VALID_STATE_FOR_NOTIF(member->status)) { + if (BGP_IS_VALID_STATE_FOR_NOTIF(member->connection->status)) { member->last_reset = PEER_DOWN_UPDATE_SOURCE_CHANGE; - bgp_notify_send(member, BGP_NOTIFY_CEASE, + bgp_notify_send(member->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } else bgp_session_reset(member); @@ -5350,9 +5487,9 @@ void peer_update_source_addr_set(struct peer *peer, const union sockunion *su) /* Check if handling a regular peer. */ if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { /* Send notification or reset peer depending on state. */ - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) { + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) { peer->last_reset = PEER_DOWN_UPDATE_SOURCE_CHANGE; - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } else bgp_session_reset(peer); @@ -5387,9 +5524,9 @@ void peer_update_source_addr_set(struct peer *peer, const union sockunion *su) XFREE(MTYPE_PEER_UPDATE_SOURCE, member->update_if); /* Send notification or reset peer depending on state. */ - if (BGP_IS_VALID_STATE_FOR_NOTIF(member->status)) { + if (BGP_IS_VALID_STATE_FOR_NOTIF(member->connection->status)) { member->last_reset = PEER_DOWN_UPDATE_SOURCE_CHANGE; - bgp_notify_send(member, BGP_NOTIFY_CEASE, + bgp_notify_send(member->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } else bgp_session_reset(member); @@ -5404,16 +5541,29 @@ void peer_update_source_unset(struct peer *peer) { struct peer *member; struct listnode *node, *nnode; + bool src_unchanged = false; if (!CHECK_FLAG(peer->flags, PEER_FLAG_UPDATE_SOURCE)) return; /* Inherit configuration from peer-group if peer is member. */ if (peer_group_active(peer)) { + /* Don't reset peer if the update_source we'll inherit from + * the peer-group matches the peer's existing update_source + */ + src_unchanged = + (peer->update_source && + peer->group->conf->update_source && + sockunion_cmp(peer->update_source, + peer->group->conf->update_source) == 0); + peer_flag_inherit(peer, PEER_FLAG_UPDATE_SOURCE); PEER_SU_ATTR_INHERIT(peer, peer->group, update_source); PEER_STR_ATTR_INHERIT(peer, peer->group, update_if, MTYPE_PEER_UPDATE_SOURCE); + + if (src_unchanged) + return; } else { /* Otherwise remove flag and configuration from peer. */ peer_flag_unset(peer, PEER_FLAG_UPDATE_SOURCE); @@ -5425,9 +5575,9 @@ void peer_update_source_unset(struct peer *peer) /* Check if handling a regular peer. */ if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { /* Send notification or reset peer depending on state. */ - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) { + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) { peer->last_reset = PEER_DOWN_UPDATE_SOURCE_CHANGE; - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } else bgp_session_reset(peer); @@ -5461,9 +5611,9 @@ void peer_update_source_unset(struct peer *peer) XFREE(MTYPE_PEER_UPDATE_SOURCE, member->update_if); /* Send notification or reset peer depending on state. */ - if (BGP_IS_VALID_STATE_FOR_NOTIF(member->status)) { + if (BGP_IS_VALID_STATE_FOR_NOTIF(member->connection->status)) { member->last_reset = PEER_DOWN_UPDATE_SOURCE_CHANGE; - bgp_notify_send(member, BGP_NOTIFY_CEASE, + bgp_notify_send(member->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } else bgp_session_reset(member); @@ -5489,9 +5639,14 @@ int peer_default_originate_set(struct peer *peer, afi_t afi, safi_t safi, if (rmap) { if (!peer->default_rmap[afi][safi].name || strcmp(rmap, peer->default_rmap[afi][safi].name) != 0) { - if (peer->default_rmap[afi][safi].name) + struct route_map *map = NULL; + + if (peer->default_rmap[afi][safi].name) { + map = route_map_lookup_by_name( + peer->default_rmap[afi][safi].name); XFREE(MTYPE_ROUTE_MAP_NAME, peer->default_rmap[afi][safi].name); + } /* * When there is a change in route-map policy, @@ -5504,16 +5659,21 @@ int peer_default_originate_set(struct peer *peer, afi_t afi, safi_t safi, UNSET_FLAG(subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE); - route_map_counter_decrement(peer->default_rmap[afi][safi].map); + route_map_counter_decrement(map); peer->default_rmap[afi][safi].name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap); peer->default_rmap[afi][safi].map = route_map; route_map_counter_increment(route_map); } } else if (!rmap) { - if (peer->default_rmap[afi][safi].name) + struct route_map *map = NULL; + + if (peer->default_rmap[afi][safi].name) { + map = route_map_lookup_by_name( + peer->default_rmap[afi][safi].name); XFREE(MTYPE_ROUTE_MAP_NAME, peer->default_rmap[afi][safi].name); + } /* * This is triggered in case of route-map deletion. @@ -5524,7 +5684,7 @@ int peer_default_originate_set(struct peer *peer, afi_t afi, safi_t safi, UNSET_FLAG(subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE); - route_map_counter_decrement(peer->default_rmap[afi][safi].map); + route_map_counter_decrement(map); peer->default_rmap[afi][safi].name = NULL; peer->default_rmap[afi][safi].map = NULL; } @@ -5532,9 +5692,10 @@ int peer_default_originate_set(struct peer *peer, afi_t afi, safi_t safi, /* Check if handling a regular peer. */ if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { /* Update peer route announcements. */ - if (peer_established(peer) && peer->afc_nego[afi][safi]) { + if (peer_established(peer->connection) && + peer->afc_nego[afi][safi]) { update_group_adjust_peer(peer_af_find(peer, afi, safi)); - bgp_default_originate(peer, afi, safi, 0); + bgp_default_originate(peer, afi, safi, false); bgp_announce_route(peer, afi, safi, false); } @@ -5556,11 +5717,16 @@ int peer_default_originate_set(struct peer *peer, afi_t afi, safi_t safi, SET_FLAG(member->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE); if (rmap) { - if (member->default_rmap[afi][safi].name) + struct route_map *map = NULL; + + if (member->default_rmap[afi][safi].name) { + map = route_map_lookup_by_name( + member->default_rmap[afi][safi].name); XFREE(MTYPE_ROUTE_MAP_NAME, member->default_rmap[afi][safi].name); - route_map_counter_decrement( - member->default_rmap[afi][safi].map); + } + + route_map_counter_decrement(map); member->default_rmap[afi][safi].name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap); member->default_rmap[afi][safi].map = route_map; @@ -5568,10 +5734,11 @@ int peer_default_originate_set(struct peer *peer, afi_t afi, safi_t safi, } /* Update peer route announcements. */ - if (peer_established(member) && member->afc_nego[afi][safi]) { + if (peer_established(member->connection) && + member->afc_nego[afi][safi]) { update_group_adjust_peer( peer_af_find(member, afi, safi)); - bgp_default_originate(member, afi, safi, 0); + bgp_default_originate(member, afi, safi, false); bgp_announce_route(member, afi, safi, false); } } @@ -5594,13 +5761,18 @@ int peer_default_originate_unset(struct peer *peer, afi_t afi, safi_t safi) PEER_ATTR_INHERIT(peer, peer->group, default_rmap[afi][safi].map); } else { + struct route_map *map = NULL; + /* Otherwise remove flag and configuration from peer. */ peer_af_flag_unset(peer, afi, safi, PEER_FLAG_DEFAULT_ORIGINATE); - if (peer->default_rmap[afi][safi].name) + if (peer->default_rmap[afi][safi].name) { + map = route_map_lookup_by_name( + peer->default_rmap[afi][safi].name); XFREE(MTYPE_ROUTE_MAP_NAME, peer->default_rmap[afi][safi].name); - route_map_counter_decrement(peer->default_rmap[afi][safi].map); + } + route_map_counter_decrement(map); peer->default_rmap[afi][safi].name = NULL; peer->default_rmap[afi][safi].map = NULL; } @@ -5608,9 +5780,10 @@ int peer_default_originate_unset(struct peer *peer, afi_t afi, safi_t safi) /* Check if handling a regular peer. */ if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { /* Update peer route announcements. */ - if (peer_established(peer) && peer->afc_nego[afi][safi]) { + if (peer_established(peer->connection) && + peer->afc_nego[afi][safi]) { update_group_adjust_peer(peer_af_find(peer, afi, safi)); - bgp_default_originate(peer, afi, safi, 1); + bgp_default_originate(peer, afi, safi, true); bgp_announce_route(peer, afi, safi, false); } @@ -5623,6 +5796,10 @@ int peer_default_originate_unset(struct peer *peer, afi_t afi, safi_t safi) * they are explicitly overriding peer-group configuration. */ for (ALL_LIST_ELEMENTS(peer->group->peer, node, nnode, member)) { + struct route_map *map; + + map = NULL; + /* Skip peers with overridden configuration. */ if (CHECK_FLAG(member->af_flags_override[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE)) @@ -5631,17 +5808,21 @@ int peer_default_originate_unset(struct peer *peer, afi_t afi, safi_t safi) /* Remove flag and configuration on peer-group member. */ UNSET_FLAG(member->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE); - if (member->default_rmap[afi][safi].name) + if (member->default_rmap[afi][safi].name) { + map = route_map_lookup_by_name( + member->default_rmap[afi][safi].name); XFREE(MTYPE_ROUTE_MAP_NAME, member->default_rmap[afi][safi].name); - route_map_counter_decrement(member->default_rmap[afi][safi].map); + } + route_map_counter_decrement(map); member->default_rmap[afi][safi].name = NULL; member->default_rmap[afi][safi].map = NULL; /* Update peer route announcements. */ - if (peer_established(member) && member->afc_nego[afi][safi]) { + if (peer_established(member->connection) && + member->afc_nego[afi][safi]) { update_group_adjust_peer(peer_af_find(member, afi, safi)); - bgp_default_originate(member, afi, safi, 1); + bgp_default_originate(member, afi, safi, true); bgp_announce_route(member, afi, safi, false); } } @@ -5669,6 +5850,7 @@ void peer_tcp_mss_set(struct peer *peer, uint32_t tcp_mss) { peer->tcp_mss = tcp_mss; SET_FLAG(peer->flags, PEER_FLAG_TCP_MSS); + bgp_tcp_mss_set(peer); } /* Reset the TCP-MSS value in the peer structure, @@ -5679,6 +5861,7 @@ void peer_tcp_mss_unset(struct peer *peer) { UNSET_FLAG(peer->flags, PEER_FLAG_TCP_MSS); peer->tcp_mss = 0; + bgp_tcp_mss_set(peer); } /* @@ -5691,17 +5874,16 @@ void peer_on_policy_change(struct peer *peer, afi_t afi, safi_t safi, { if (outbound) { update_group_adjust_peer(peer_af_find(peer, afi, safi)); - if (peer_established(peer)) + if (peer_established(peer->connection)) bgp_announce_route(peer, afi, safi, false); } else { - if (!peer_established(peer)) + if (!peer_established(peer->connection)) return; if (bgp_soft_reconfig_in(peer, afi, safi)) return; - if (CHECK_FLAG(peer->cap, PEER_CAP_REFRESH_OLD_RCV) || - CHECK_FLAG(peer->cap, PEER_CAP_REFRESH_NEW_RCV)) + if (CHECK_FLAG(peer->cap, PEER_CAP_REFRESH_RCV)) bgp_route_refresh_send(peer, afi, safi, 0, 0, 0, BGP_ROUTE_REFRESH_NORMAL); } @@ -5890,10 +6072,10 @@ int peer_timers_connect_set(struct peer *peer, uint32_t connect) /* Skip peer-group mechanics for regular peers. */ if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { - if (!peer_established(peer)) { + if (!peer_established(peer->connection)) { if (peer_active(peer)) - BGP_EVENT_ADD(peer, BGP_Stop); - BGP_EVENT_ADD(peer, BGP_Start); + BGP_EVENT_ADD(peer->connection, BGP_Stop); + BGP_EVENT_ADD(peer->connection, BGP_Start); } return 0; } @@ -5911,10 +6093,10 @@ int peer_timers_connect_set(struct peer *peer, uint32_t connect) member->connect = connect; member->v_connect = connect; - if (!peer_established(member)) { + if (!peer_established(member->connection)) { if (peer_active(member)) - BGP_EVENT_ADD(member, BGP_Stop); - BGP_EVENT_ADD(member, BGP_Start); + BGP_EVENT_ADD(member->connection, BGP_Stop); + BGP_EVENT_ADD(member->connection, BGP_Start); } } @@ -5944,10 +6126,10 @@ int peer_timers_connect_unset(struct peer *peer) /* Skip peer-group mechanics for regular peers. */ if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { - if (!peer_established(peer)) { + if (!peer_established(peer->connection)) { if (peer_active(peer)) - BGP_EVENT_ADD(peer, BGP_Stop); - BGP_EVENT_ADD(peer, BGP_Start); + BGP_EVENT_ADD(peer->connection, BGP_Stop); + BGP_EVENT_ADD(peer->connection, BGP_Start); } return 0; } @@ -5965,10 +6147,10 @@ int peer_timers_connect_unset(struct peer *peer) member->connect = 0; member->v_connect = peer->bgp->default_connect_retry; - if (!peer_established(member)) { + if (!peer_established(member->connection)) { if (peer_active(member)) - BGP_EVENT_ADD(member, BGP_Stop); - BGP_EVENT_ADD(member, BGP_Start); + BGP_EVENT_ADD(member->connection, BGP_Stop); + BGP_EVENT_ADD(member->connection, BGP_Start); } } @@ -5992,7 +6174,7 @@ int peer_advertise_interval_set(struct peer *peer, uint32_t routeadv) if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { /* Update peer route announcements. */ update_group_adjust_peer_afs(peer); - if (peer_established(peer)) + if (peer_established(peer->connection)) bgp_announce_route_all(peer); /* Skip peer-group mechanics for regular peers. */ @@ -6015,7 +6197,7 @@ int peer_advertise_interval_set(struct peer *peer, uint32_t routeadv) /* Update peer route announcements. */ update_group_adjust_peer_afs(member); - if (peer_established(member)) + if (peer_established(member->connection)) bgp_announce_route_all(member); } @@ -6049,7 +6231,7 @@ int peer_advertise_interval_unset(struct peer *peer) if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { /* Update peer route announcements. */ update_group_adjust_peer_afs(peer); - if (peer_established(peer)) + if (peer_established(peer->connection)) bgp_announce_route_all(peer); /* Skip peer-group mechanics for regular peers. */ @@ -6074,7 +6256,7 @@ int peer_advertise_interval_unset(struct peer *peer) /* Update peer route announcements. */ update_group_adjust_peer_afs(member); - if (peer_established(member)) + if (peer_established(member->connection)) bgp_announce_route_all(member); } @@ -6329,8 +6511,8 @@ int peer_local_as_set(struct peer *peer, as_t as, bool no_prepend, peer->change_local_as = as; if (as_str) { if (peer->change_local_as_pretty) - XFREE(MTYPE_BGP, peer->change_local_as_pretty); - peer->change_local_as_pretty = XSTRDUP(MTYPE_BGP, as_str); + XFREE(MTYPE_BGP_NAME, peer->change_local_as_pretty); + peer->change_local_as_pretty = XSTRDUP(MTYPE_BGP_NAME, as_str); } (void)peer_sort(peer); @@ -6367,8 +6549,8 @@ int peer_local_as_set(struct peer *peer, as_t as, bool no_prepend, replace_as); member->change_local_as = as; if (as_str) - member->change_local_as_pretty = - XSTRDUP(MTYPE_BGP, as_str); + member->change_local_as_pretty = XSTRDUP(MTYPE_BGP_NAME, + as_str); } return 0; @@ -6394,18 +6576,18 @@ int peer_local_as_unset(struct peer *peer) peer_flag_unset(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND); peer_flag_unset(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS); peer->change_local_as = 0; - XFREE(MTYPE_BGP, peer->change_local_as_pretty); + XFREE(MTYPE_BGP_NAME, peer->change_local_as_pretty); } /* Check if handling a regular peer. */ if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { /* Send notification or stop peer depending on state. */ - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) { + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) { peer->last_reset = PEER_DOWN_LOCAL_AS_CHANGE; - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } else - BGP_EVENT_ADD(peer, BGP_Stop); + BGP_EVENT_ADD(peer->connection, BGP_Stop); /* Skip peer-group mechanics for regular peers. */ return 0; @@ -6425,12 +6607,12 @@ int peer_local_as_unset(struct peer *peer) UNSET_FLAG(member->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND); UNSET_FLAG(member->flags, PEER_FLAG_LOCAL_AS_REPLACE_AS); member->change_local_as = 0; - XFREE(MTYPE_BGP, member->change_local_as_pretty); + XFREE(MTYPE_BGP_NAME, member->change_local_as_pretty); /* Send notification or stop peer depending on state. */ - if (BGP_IS_VALID_STATE_FOR_NOTIF(member->status)) { + if (BGP_IS_VALID_STATE_FOR_NOTIF(member->connection->status)) { member->last_reset = PEER_DOWN_LOCAL_AS_CHANGE; - bgp_notify_send(member, BGP_NOTIFY_CEASE, + bgp_notify_send(member->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); } else bgp_session_reset(member); @@ -6460,8 +6642,8 @@ int peer_password_set(struct peer *peer, const char *password) /* Check if handling a regular peer. */ if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { /* Send notification or reset peer depending on state. */ - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); else bgp_session_reset(peer); @@ -6470,10 +6652,11 @@ int peer_password_set(struct peer *peer, const char *password) * Attempt to install password on socket and skip peer-group * mechanics. */ - if (BGP_PEER_SU_UNSPEC(peer)) + if (BGP_CONNECTION_SU_UNSPEC(peer->connection)) return BGP_SUCCESS; - return (bgp_md5_set(peer) >= 0) ? BGP_SUCCESS - : BGP_ERR_TCPSIG_FAILED; + return (bgp_md5_set(peer->connection) >= 0) + ? BGP_SUCCESS + : BGP_ERR_TCPSIG_FAILED; } /* @@ -6496,14 +6679,15 @@ int peer_password_set(struct peer *peer, const char *password) member->password = XSTRDUP(MTYPE_PEER_PASSWORD, password); /* Send notification or reset peer depending on state. */ - if (BGP_IS_VALID_STATE_FOR_NOTIF(member->status)) - bgp_notify_send(member, BGP_NOTIFY_CEASE, + if (BGP_IS_VALID_STATE_FOR_NOTIF(member->connection->status)) + bgp_notify_send(member->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); else bgp_session_reset(member); /* Attempt to install password on socket. */ - if (!BGP_PEER_SU_UNSPEC(member) && bgp_md5_set(member) < 0) + if (!BGP_CONNECTION_SU_UNSPEC(member->connection) && + bgp_md5_set(member->connection) < 0) ret = BGP_ERR_TCPSIG_FAILED; } @@ -6541,15 +6725,15 @@ int peer_password_unset(struct peer *peer) /* Check if handling a regular peer. */ if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { /* Send notification or reset peer depending on state. */ - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); else bgp_session_reset(peer); /* Attempt to uninstall password on socket. */ - if (!BGP_PEER_SU_UNSPEC(peer)) - bgp_md5_unset(peer); + if (!BGP_CONNECTION_SU_UNSPEC(peer->connection)) + bgp_md5_unset(peer->connection); /* Skip peer-group mechanics for regular peers. */ return 0; } @@ -6568,15 +6752,15 @@ int peer_password_unset(struct peer *peer) XFREE(MTYPE_PEER_PASSWORD, member->password); /* Send notification or reset peer depending on state. */ - if (BGP_IS_VALID_STATE_FOR_NOTIF(member->status)) - bgp_notify_send(member, BGP_NOTIFY_CEASE, + if (BGP_IS_VALID_STATE_FOR_NOTIF(member->connection->status)) + bgp_notify_send(member->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_CONFIG_CHANGE); else bgp_session_reset(member); /* Attempt to uninstall password on socket. */ - if (!BGP_PEER_SU_UNSPEC(member)) - bgp_md5_unset(member); + if (!BGP_CONNECTION_SU_UNSPEC(member->connection)) + bgp_md5_unset(member->connection); } /* Set flag and configuration on all peer-group listen ranges */ @@ -6948,11 +7132,8 @@ static void peer_prefix_list_update(struct prefix_list *plist) */ if (CHECK_FLAG(peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_ADV) && - (CHECK_FLAG(peer->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_RM_RCV) || - CHECK_FLAG( - peer->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_RM_OLD_RCV))) + CHECK_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ORF_PREFIX_RM_RCV)) peer_clear_soft( peer, afi, safi, BGP_CLEAR_SOFT_IN_ORF_PREFIX); @@ -7173,6 +7354,7 @@ int peer_route_map_set(struct peer *peer, afi_t afi, safi_t safi, int direct, struct peer *member; struct bgp_filter *filter; struct listnode *node, *nnode; + struct route_map *map = NULL; if (direct != RMAP_IN && direct != RMAP_OUT) return BGP_ERR_INVALID_VALUE; @@ -7186,9 +7368,10 @@ int peer_route_map_set(struct peer *peer, afi_t afi, safi_t safi, int direct, if (strcmp(filter->map[direct].name, name) == 0) return 0; + map = route_map_lookup_by_name(filter->map[direct].name); XFREE(MTYPE_BGP_FILTER_NAME, filter->map[direct].name); } - route_map_counter_decrement(filter->map[direct].map); + route_map_counter_decrement(map); filter->map[direct].name = XSTRDUP(MTYPE_BGP_FILTER_NAME, name); filter->map[direct].map = route_map; route_map_counter_increment(route_map); @@ -7210,6 +7393,7 @@ int peer_route_map_set(struct peer *peer, afi_t afi, safi_t safi, int direct, * explicitly overriding peer-group configuration. */ for (ALL_LIST_ELEMENTS(peer->group->peer, node, nnode, member)) { + map = NULL; /* Skip peers with overridden configuration. */ if (CHECK_FLAG(member->filter_override[afi][safi][direct], PEER_FT_ROUTE_MAP)) @@ -7217,9 +7401,11 @@ int peer_route_map_set(struct peer *peer, afi_t afi, safi_t safi, int direct, /* Set configuration on peer-group member. */ filter = &member->filter[afi][safi]; - if (filter->map[direct].name) + if (filter->map[direct].name) { + map = route_map_lookup_by_name(filter->map[direct].name); XFREE(MTYPE_BGP_FILTER_NAME, filter->map[direct].name); - route_map_counter_decrement(filter->map[direct].map); + } + route_map_counter_decrement(map); filter->map[direct].name = XSTRDUP(MTYPE_BGP_FILTER_NAME, name); filter->map[direct].map = route_map; route_map_counter_increment(route_map); @@ -7252,11 +7438,16 @@ int peer_route_map_unset(struct peer *peer, afi_t afi, safi_t safi, int direct) PEER_ATTR_INHERIT(peer, peer->group, filter[afi][safi].map[direct].map); } else { + struct route_map *map = NULL; + /* Otherwise remove configuration from peer. */ filter = &peer->filter[afi][safi]; - if (filter->map[direct].name) + + if (filter->map[direct].name) { + map = route_map_lookup_by_name(filter->map[direct].name); XFREE(MTYPE_BGP_FILTER_NAME, filter->map[direct].name); - route_map_counter_decrement(filter->map[direct].map); + } + route_map_counter_decrement(map); filter->map[direct].name = NULL; filter->map[direct].map = NULL; } @@ -7276,6 +7467,10 @@ int peer_route_map_unset(struct peer *peer, afi_t afi, safi_t safi, int direct) * explicitly overriding peer-group configuration. */ for (ALL_LIST_ELEMENTS(peer->group->peer, node, nnode, member)) { + struct route_map *map; + + map = NULL; + /* Skip peers with overridden configuration. */ if (CHECK_FLAG(member->filter_override[afi][safi][direct], PEER_FT_ROUTE_MAP)) @@ -7283,9 +7478,11 @@ int peer_route_map_unset(struct peer *peer, afi_t afi, safi_t safi, int direct) /* Remove configuration on peer-group member. */ filter = &member->filter[afi][safi]; - if (filter->map[direct].name) + if (filter->map[direct].name) { + map = route_map_lookup_by_name(filter->map[direct].name); XFREE(MTYPE_BGP_FILTER_NAME, filter->map[direct].name); - route_map_counter_decrement(filter->map[direct].map); + } + route_map_counter_decrement(map); filter->map[direct].name = NULL; filter->map[direct].map = NULL; @@ -7330,6 +7527,10 @@ int peer_unsuppress_map_set(struct peer *peer, afi_t afi, safi_t safi, * explicitly overriding peer-group configuration. */ for (ALL_LIST_ELEMENTS(peer->group->peer, node, nnode, member)) { + struct route_map *map; + + map = NULL; + /* Skip peers with overridden configuration. */ if (CHECK_FLAG(member->filter_override[afi][safi][0], PEER_FT_UNSUPPRESS_MAP)) @@ -7337,9 +7538,11 @@ int peer_unsuppress_map_set(struct peer *peer, afi_t afi, safi_t safi, /* Set configuration on peer-group member. */ filter = &member->filter[afi][safi]; - if (filter->usmap.name) + if (filter->usmap.name) { + map = route_map_lookup_by_name(filter->usmap.name); XFREE(MTYPE_BGP_FILTER_NAME, filter->usmap.name); - route_map_counter_decrement(filter->usmap.map); + } + route_map_counter_decrement(map); filter->usmap.name = XSTRDUP(MTYPE_BGP_FILTER_NAME, name); filter->usmap.map = route_map; route_map_counter_increment(route_map); @@ -7369,11 +7572,15 @@ int peer_unsuppress_map_unset(struct peer *peer, afi_t afi, safi_t safi) PEER_ATTR_INHERIT(peer, peer->group, filter[afi][safi].usmap.map); } else { + struct route_map *map = NULL; + /* Otherwise remove configuration from peer. */ filter = &peer->filter[afi][safi]; - if (filter->usmap.name) + if (filter->usmap.name) { + map = route_map_lookup_by_name(filter->usmap.name); XFREE(MTYPE_BGP_FILTER_NAME, filter->usmap.name); - route_map_counter_decrement(filter->usmap.map); + } + route_map_counter_decrement(map); filter->usmap.name = NULL; filter->usmap.map = NULL; } @@ -7392,6 +7599,10 @@ int peer_unsuppress_map_unset(struct peer *peer, afi_t afi, safi_t safi) * explicitly overriding peer-group configuration. */ for (ALL_LIST_ELEMENTS(peer->group->peer, node, nnode, member)) { + struct route_map *map; + + map = NULL; + /* Skip peers with overridden configuration. */ if (CHECK_FLAG(member->filter_override[afi][safi][0], PEER_FT_UNSUPPRESS_MAP)) @@ -7399,9 +7610,11 @@ int peer_unsuppress_map_unset(struct peer *peer, afi_t afi, safi_t safi) /* Remove configuration on peer-group member. */ filter = &member->filter[afi][safi]; - if (filter->usmap.name) + if (filter->usmap.name) { + map = route_map_lookup_by_name(filter->usmap.name); XFREE(MTYPE_BGP_FILTER_NAME, filter->usmap.name); - route_map_counter_decrement(filter->usmap.map); + } + route_map_counter_decrement(map); filter->usmap.name = NULL; filter->usmap.map = NULL; @@ -7418,14 +7631,14 @@ static bool peer_maximum_prefix_clear_overflow(struct peer *peer) return false; UNSET_FLAG(peer->sflags, PEER_STATUS_PREFIX_OVERFLOW); - if (peer->t_pmax_restart) { - EVENT_OFF(peer->t_pmax_restart); + if (peer->connection->t_pmax_restart) { + EVENT_OFF(peer->connection->t_pmax_restart); if (bgp_debug_neighbor_events(peer)) zlog_debug( "%pBP Maximum-prefix restart timer cancelled", peer); } - BGP_EVENT_ADD(peer, BGP_Start); + BGP_EVENT_ADD(peer->connection, BGP_Start); return true; } @@ -7457,7 +7670,8 @@ int peer_maximum_prefix_set(struct peer *peer, afi_t afi, safi_t safi, /* Check if handling a regular peer. */ if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { /* Re-check if peer violates maximum-prefix. */ - if ((peer_established(peer)) && (peer->afc[afi][safi])) + if ((peer_established(peer->connection)) && + (peer->afc[afi][safi])) bgp_maximum_prefix_overflow(peer, afi, safi, 1); /* Skip peer-group mechanics for regular peers. */ @@ -7494,7 +7708,8 @@ int peer_maximum_prefix_set(struct peer *peer, afi_t afi, safi_t safi, PEER_FLAG_MAX_PREFIX_WARNING); /* Re-check if peer violates maximum-prefix. */ - if ((peer_established(member)) && (member->afc[afi][safi])) + if ((peer_established(member->connection)) && + (member->afc[afi][safi])) bgp_maximum_prefix_overflow(member, afi, safi, 1); } @@ -7565,7 +7780,7 @@ void peer_maximum_prefix_out_refresh_routes(struct peer *peer, afi_t afi, { update_group_adjust_peer(peer_af_find(peer, afi, safi)); - if (peer_established(peer)) + if (peer_established(peer->connection)) bgp_announce_route(peer, afi, safi, false); } @@ -7683,8 +7898,9 @@ int peer_ttl_security_hops_set(struct peer *peer, int gtsm_hops) struct listnode *node, *nnode; int ret; - zlog_debug("%s: set gtsm_hops to %d for %s", __func__, gtsm_hops, - peer->host); + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%s: set gtsm_hops to %d for %s", __func__, + gtsm_hops, peer->host); /* We cannot configure ttl-security hops when ebgp-multihop is already set. For non peer-groups, the check is simple. For peer-groups, @@ -7740,19 +7956,23 @@ int peer_ttl_security_hops_set(struct peer *peer, int gtsm_hops) if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { peer->gtsm_hops = gtsm_hops; - if (peer->fd >= 0) - sockopt_minttl(peer->su.sa.sa_family, peer->fd, + if (peer->connection->fd >= 0) + sockopt_minttl(peer->connection->su.sa.sa_family, + peer->connection->fd, MAXTTL + 1 - gtsm_hops); - if ((peer->status < Established) && peer->doppelganger - && (peer->doppelganger->fd >= 0)) - sockopt_minttl(peer->su.sa.sa_family, - peer->doppelganger->fd, + if ((peer->connection->status < Established) && + peer->doppelganger && + (peer->doppelganger->connection->fd >= 0)) + sockopt_minttl(peer->connection->su.sa.sa_family, + peer->doppelganger->connection->fd, MAXTTL + 1 - gtsm_hops); } else { group = peer->group; group->conf->gtsm_hops = gtsm_hops; for (ALL_LIST_ELEMENTS(group->peer, node, nnode, gpeer)) { + struct peer_connection *connection = + gpeer->connection; gpeer->gtsm_hops = group->conf->gtsm_hops; /* Change setting of existing peer @@ -7763,18 +7983,18 @@ int peer_ttl_security_hops_set(struct peer *peer, int gtsm_hops) * no session then do nothing (will get * handled by next connection) */ - if (gpeer->fd >= 0 - && gpeer->gtsm_hops - != BGP_GTSM_HOPS_DISABLED) - sockopt_minttl( - gpeer->su.sa.sa_family, - gpeer->fd, - MAXTTL + 1 - gpeer->gtsm_hops); - if ((gpeer->status < Established) - && gpeer->doppelganger - && (gpeer->doppelganger->fd >= 0)) - sockopt_minttl(gpeer->su.sa.sa_family, - gpeer->doppelganger->fd, + if (connection->fd >= 0 && + gpeer->gtsm_hops != BGP_GTSM_HOPS_DISABLED) + sockopt_minttl(connection->su.sa.sa_family, + connection->fd, + MAXTTL + 1 - + gpeer->gtsm_hops); + if ((connection->status < Established) && + gpeer->doppelganger && + (gpeer->doppelganger->connection->fd >= 0)) + sockopt_minttl(connection->su.sa.sa_family, + gpeer->doppelganger + ->connection->fd, MAXTTL + 1 - gtsm_hops); } } @@ -7789,7 +8009,9 @@ int peer_ttl_security_hops_unset(struct peer *peer) struct listnode *node, *nnode; int ret = 0; - zlog_debug("%s: set gtsm_hops to zero for %s", __func__, peer->host); + if (bgp_debug_neighbor_events(peer)) + zlog_debug("%s: set gtsm_hops to zero for %s", __func__, + peer->host); /* if a peer-group member, then reset to peer-group default rather than * 0 */ @@ -7807,14 +8029,16 @@ int peer_ttl_security_hops_unset(struct peer *peer) if (peer->sort == BGP_PEER_EBGP) ret = peer_ebgp_multihop_unset(peer); else { - if (peer->fd >= 0) - sockopt_minttl(peer->su.sa.sa_family, peer->fd, + if (peer->connection->fd >= 0) + sockopt_minttl(peer->connection->su.sa.sa_family, + peer->connection->fd, 0); + + if ((peer->connection->status < Established) && + peer->doppelganger && + (peer->doppelganger->connection->fd >= 0)) + sockopt_minttl(peer->connection->su.sa.sa_family, + peer->doppelganger->connection->fd, 0); - - if ((peer->status < Established) && peer->doppelganger - && (peer->doppelganger->fd >= 0)) - sockopt_minttl(peer->su.sa.sa_family, - peer->doppelganger->fd, 0); } } else { group = peer->group; @@ -7823,15 +8047,18 @@ int peer_ttl_security_hops_unset(struct peer *peer) if (peer->sort == BGP_PEER_EBGP) ret = peer_ebgp_multihop_unset(peer); else { - if (peer->fd >= 0) - sockopt_minttl(peer->su.sa.sa_family, - peer->fd, 0); - - if ((peer->status < Established) - && peer->doppelganger - && (peer->doppelganger->fd >= 0)) - sockopt_minttl(peer->su.sa.sa_family, - peer->doppelganger->fd, + if (peer->connection->fd >= 0) + sockopt_minttl(peer->connection->su.sa + .sa_family, + peer->connection->fd, 0); + + if ((peer->connection->status < Established) && + peer->doppelganger && + (peer->doppelganger->connection->fd >= 0)) + sockopt_minttl(peer->connection->su.sa + .sa_family, + peer->doppelganger + ->connection->fd, 0); } } @@ -7868,6 +8095,16 @@ static void peer_reset_message_stats(struct peer *peer) } } +/* Helper function to resend some BGP capabilities that are uncontrolled. + * For instance, FQDN capability, that can't be turned off, but let's say + * we changed the hostname, we need to resend it. + */ +static void peer_clear_capabilities(struct peer *peer, afi_t afi, safi_t safi) +{ + bgp_capability_send(peer, afi, safi, CAPABILITY_CODE_FQDN, + CAPABILITY_ACTION_SET); +} + /* * If peer clear is invoked in a loop for all peers on the BGP instance, * it may end up freeing the doppelganger, and if this was the next node @@ -7883,8 +8120,8 @@ int peer_clear(struct peer *peer, struct listnode **nnode) return 0; peer->v_start = BGP_INIT_START_TIMER; - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->connection->status)) + bgp_notify_send(peer->connection, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_ADMIN_RESET); else bgp_session_reset_safe(peer, nnode); @@ -7897,13 +8134,13 @@ int peer_clear_soft(struct peer *peer, afi_t afi, safi_t safi, { struct peer_af *paf; - if (!peer_established(peer)) + if (!peer_established(peer->connection)) return 0; if (!peer->afc[afi][safi]) return BGP_ERR_AF_UNCONFIGURED; - peer->rtt = sockopt_tcp_rtt(peer->fd); + peer->rtt = sockopt_tcp_rtt(peer->connection->fd); if (stype == BGP_CLEAR_SOFT_OUT || stype == BGP_CLEAR_SOFT_BOTH) { /* Clear the "neighbor x.x.x.x default-originate" flag */ @@ -7919,19 +8156,15 @@ int peer_clear_soft(struct peer *peer, afi_t afi, safi_t safi, if (stype == BGP_CLEAR_SOFT_IN_ORF_PREFIX) { if (CHECK_FLAG(peer->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_SM_ADV) - && (CHECK_FLAG(peer->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_RM_RCV) - || CHECK_FLAG(peer->af_cap[afi][safi], - PEER_CAP_ORF_PREFIX_RM_OLD_RCV))) { + PEER_CAP_ORF_PREFIX_SM_ADV) && + CHECK_FLAG(peer->af_cap[afi][safi], + PEER_CAP_ORF_PREFIX_RM_RCV)) { struct bgp_filter *filter = &peer->filter[afi][safi]; uint8_t prefix_type; if (CHECK_FLAG(peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_RCV)) prefix_type = ORF_TYPE_PREFIX; - else - prefix_type = ORF_TYPE_PREFIX_OLD; if (filter->plist[FILTER_IN].plist) { if (CHECK_FLAG(peer->af_sflags[afi][safi], @@ -7968,8 +8201,7 @@ int peer_clear_soft(struct peer *peer, afi_t afi, safi_t safi, /* If neighbor has route refresh capability, send route refresh message to the peer. */ - if (CHECK_FLAG(peer->cap, PEER_CAP_REFRESH_OLD_RCV) - || CHECK_FLAG(peer->cap, PEER_CAP_REFRESH_NEW_RCV)) + if (CHECK_FLAG(peer->cap, PEER_CAP_REFRESH_RCV)) bgp_route_refresh_send( peer, afi, safi, 0, 0, 0, BGP_ROUTE_REFRESH_NORMAL); @@ -7981,6 +8213,9 @@ int peer_clear_soft(struct peer *peer, afi_t afi, safi_t safi, if (stype == BGP_CLEAR_MESSAGE_STATS) peer_reset_message_stats(peer); + if (stype == BGP_CLEAR_CAPABILITIES) + peer_clear_capabilities(peer, afi, safi); + return 0; } @@ -8055,6 +8290,8 @@ void bgp_master_init(struct event_loop *master, const int buffer_size, bm->tcp_dscp = IPTOS_PREC_INTERNETCONTROL; bm->inq_limit = BM_DEFAULT_Q_LIMIT; bm->outq_limit = BM_DEFAULT_Q_LIMIT; + bm->t_bgp_sync_label_manager = NULL; + bm->t_bgp_start_label_manager = NULL; bgp_mac_init(); /* init the rd id space. @@ -8067,7 +8304,7 @@ void bgp_master_init(struct event_loop *master, const int buffer_size, /* mpls label dynamic allocation pool */ bgp_lp_init(bm->master, &bm->labelpool); - bgp_l3nhg_init(); + bgp_nhg_init(); bgp_evpn_mh_init(); QOBJ_REG(bm, bgp_master); } @@ -8087,10 +8324,9 @@ static void bgp_if_finish(struct bgp *bgp) return; FOR_ALL_INTERFACES (vrf, ifp) { - struct listnode *c_node, *c_nnode; struct connected *c; - for (ALL_LIST_ELEMENTS(ifp->connected, c_node, c_nnode, c)) + frr_each_safe (if_connected, ifp->connected, c) bgp_connected_delete(bgp, c); } } @@ -8189,10 +8425,11 @@ static int peer_unshut_after_cfg(struct bgp *bgp) peer->host); peer->shut_during_cfg = false; - if (peer_active(peer) && peer->status != Established) { - if (peer->status != Idle) - BGP_EVENT_ADD(peer, BGP_Stop); - BGP_EVENT_ADD(peer, BGP_Start); + if (peer_active(peer) && + peer->connection->status != Established) { + if (peer->connection->status != Idle) + BGP_EVENT_ADD(peer->connection, BGP_Stop); + BGP_EVENT_ADD(peer->connection, BGP_Start); } } @@ -8258,6 +8495,7 @@ void bgp_init(unsigned short instance) bgp_lp_vty_init(); bgp_label_per_nexthop_init(); + bgp_mplsvpn_nexthop_init(); cmd_variable_handler_register(bgp_viewvrf_var_handlers); } @@ -8290,8 +8528,10 @@ void bgp_terminate(void) peer); continue; } - if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) - bgp_notify_send(peer, BGP_NOTIFY_CEASE, + if (BGP_IS_VALID_STATE_FOR_NOTIF( + peer->connection->status)) + bgp_notify_send(peer->connection, + BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_PEER_UNCONFIG); } } @@ -8300,6 +8540,8 @@ void bgp_terminate(void) list_delete(&bm->listen_sockets); EVENT_OFF(bm->t_rmap_update); + EVENT_OFF(bm->t_bgp_sync_label_manager); + EVENT_OFF(bm->t_bgp_start_label_manager); bgp_mac_finish(); } @@ -8310,6 +8552,7 @@ struct peer *peer_lookup_in_view(struct vty *vty, struct bgp *bgp, int ret; struct peer *peer; union sockunion su; + struct peer_group *group; /* Get peer sockunion. */ ret = str2sockunion(ip_str, &su); @@ -8318,6 +8561,12 @@ struct peer *peer_lookup_in_view(struct vty *vty, struct bgp *bgp, if (!peer) { peer = peer_lookup_by_hostname(bgp, ip_str); + if (!peer) { + group = peer_group_lookup(bgp, ip_str); + if (group) + peer = listnode_head(group->peer); + } + if (!peer) { if (use_json) { json_object *json_no = NULL; @@ -8395,3 +8644,16 @@ static ssize_t printfrr_bp(struct fbuf *buf, struct printfrr_eargs *ea, return bprintfrr(buf, "%s(%s)", peer->host, peer->hostname ? peer->hostname : "Unknown"); } + +const struct message bgp_martian_type_str[] = { + {BGP_MARTIAN_IF_IP, "Self Interface IP"}, + {BGP_MARTIAN_TUN_IP, "Self Tunnel IP"}, + {BGP_MARTIAN_IF_MAC, "Self Interface MAC"}, + {BGP_MARTIAN_RMAC, "Self RMAC"}, + {BGP_MARTIAN_SOO, "Self Site-of-Origin"}, + {0}}; + +const char *bgp_martian_type2str(enum bgp_martian_type mt) +{ + return lookup_msg(bgp_martian_type_str, mt, "Unknown Martian Type"); +} diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 9cb1d51088..4c12872ee9 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -121,6 +121,8 @@ struct bgp_master { #define BGP_OPT_NO_FIB (1 << 0) #define BGP_OPT_NO_LISTEN (1 << 1) #define BGP_OPT_NO_ZEBRA (1 << 2) +#define BGP_OPT_TRAPS_RFC4273 (1 << 3) +#define BGP_OPT_TRAPS_BGP4MIBV2 (1 << 4) uint64_t updgrp_idspace; uint64_t subgrp_idspace; @@ -165,6 +167,11 @@ struct bgp_master { uint32_t inq_limit; uint32_t outq_limit; + struct event *t_bgp_sync_label_manager; + struct event *t_bgp_start_label_manager; + + bool v6_with_v4_nexthops; + QOBJ_FIELDS; }; DECLARE_QOBJ_TYPE(bgp_master); @@ -212,6 +219,8 @@ struct vpn_policy { #define BGP_VPN_POLICY_TOVPN_NEXTHOP_SET (1 << 2) #define BGP_VPN_POLICY_TOVPN_SID_AUTO (1 << 3) #define BGP_VPN_POLICY_TOVPN_LABEL_PER_NEXTHOP (1 << 4) +/* Manual label is registered with zebra label manager */ +#define BGP_VPN_POLICY_TOVPN_LABEL_MANUAL_REG (1 << 5) /* * If we are importing another vrf into us keep a list of @@ -331,6 +340,9 @@ struct as_confed { char *as_pretty; }; +struct bgp_mplsvpn_nh_label_bind_cache; +PREDECL_RBTREE_UNIQ(bgp_mplsvpn_nh_label_bind_cache); + /* BGP instance structure. */ struct bgp { /* AS number of this BGP instance. */ @@ -505,6 +517,8 @@ struct bgp { #define BGP_FLAG_LU_IPV4_EXPLICIT_NULL (1ULL << 33) /* For BGP-LU, force IPv6 local prefixes to use ipv6-explicit-null label */ #define BGP_FLAG_LU_IPV6_EXPLICIT_NULL (1ULL << 34) +#define BGP_FLAG_SOFT_VERSION_CAPABILITY (1ULL << 35) +#define BGP_FLAG_ENFORCE_FIRST_AS (1ULL << 36) /* BGP default address-families. * New peers inherit enabled afi/safis from bgp instance. @@ -578,6 +592,9 @@ struct bgp { struct bgp_label_per_nexthop_cache_head mpls_labels_per_nexthop[AFI_MAX]; + /* Tree for mplsvpn next-hop label bind cache */ + struct bgp_mplsvpn_nh_label_bind_cache_head mplsvpn_nh_label_bind; + /* Allocate hash entries to store policy routing information * The hash are used to host pbr rules somewhere. * Actually, pbr will only be used by flowspec @@ -601,6 +618,7 @@ struct bgp { /* timer to re-evaluate neighbor default-originate route-maps */ struct event *t_rmap_def_originate_eval; + uint16_t rmap_def_originate_eval_timer; #define RMAP_DEFAULT_ORIGINATE_EVAL_TIMER 5 /* BGP distance configuration. */ @@ -810,6 +828,8 @@ DECLARE_QOBJ_TYPE(bgp); struct bgp_interface { #define BGP_INTERFACE_MPLS_BGP_FORWARDING (1 << 0) +/* L3VPN multi domain switching */ +#define BGP_INTERFACE_MPLS_L3VPN_SWITCHING (1 << 1) uint32_t flags; }; @@ -817,6 +837,7 @@ DECLARE_HOOK(bgp_inst_delete, (struct bgp *bgp), (bgp)); DECLARE_HOOK(bgp_inst_config_write, (struct bgp *bgp, struct vty *vty), (bgp, vty)); +DECLARE_HOOK(bgp_snmp_traps_config_write, (struct vty *vty), (vty)); DECLARE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp)); /* Thread callback information */ @@ -956,6 +977,14 @@ enum bgp_peer_sort { BGP_PEER_CONFED, }; +/* BGP peering sub-types + * E.g.: + * EBGP-OAD - https://datatracker.ietf.org/doc/html/draft-uttaro-idr-bgp-oad + */ +enum bgp_peer_sub_sort { + BGP_PEER_EBGP_OAD = 1, +}; + /* BGP message header and packet size. */ #define BGP_MARKER_SIZE 16 #define BGP_HEADER_SIZE 19 @@ -1105,6 +1134,55 @@ struct llgr_info { uint8_t flags; }; +struct peer_connection { + struct peer *peer; + + /* Status of the peer connection. */ + enum bgp_fsm_status status; + enum bgp_fsm_status ostatus; + + int fd; + + /* Packet receive and send buffer. */ + pthread_mutex_t io_mtx; // guards ibuf, obuf + struct stream_fifo *ibuf; // packets waiting to be processed + struct stream_fifo *obuf; // packets waiting to be written + + struct ringbuf *ibuf_work; // WiP buffer used by bgp_read() only + + struct event *t_read; + struct event *t_write; + struct event *t_connect; + struct event *t_delayopen; + struct event *t_start; + struct event *t_holdtime; + + struct event *t_connect_check_r; + struct event *t_connect_check_w; + + struct event *t_gr_restart; + struct event *t_gr_stale; + + struct event *t_generate_updgrp_packets; + struct event *t_pmax_restart; + + struct event *t_routeadv; + struct event *t_process_packet; + struct event *t_process_packet_error; + + union sockunion su; +#define BGP_CONNECTION_SU_UNSPEC(connection) \ + (connection->su.sa.sa_family == AF_UNSPEC) + + /* Thread flags */ + _Atomic uint32_t thread_flags; +#define PEER_THREAD_WRITES_ON (1U << 0) +#define PEER_THREAD_READS_ON (1U << 1) +}; +extern struct peer_connection *bgp_peer_connection_new(struct peer *peer); +extern void bgp_peer_connection_free(struct peer_connection **connection); +extern void bgp_peer_connection_buffers_free(struct peer_connection *connection); + /* BGP neighbor structure. */ struct peer { /* BGP structure. */ @@ -1133,6 +1211,7 @@ struct peer { as_t local_as; enum bgp_peer_sort sort; + enum bgp_peer_sub_sort sub_sort; /* Peer's Change local AS number. */ as_t change_local_as; @@ -1145,32 +1224,11 @@ struct peer { /* Local router ID. */ struct in_addr local_id; - /* Packet receive and send buffer. */ - pthread_mutex_t io_mtx; // guards ibuf, obuf - struct stream_fifo *ibuf; // packets waiting to be processed - struct stream_fifo *obuf; // packets waiting to be written - - /* used as a block to deposit raw wire data to */ - uint8_t ibuf_scratch[BGP_EXTENDED_MESSAGE_MAX_PACKET_SIZE - * BGP_READ_PACKET_MAX]; - struct ringbuf *ibuf_work; // WiP buffer used by bgp_read() only - struct stream *obuf_work; // WiP buffer used to construct packets - struct stream *curr; // the current packet being parsed - /* We use a separate stream to encode MP_REACH_NLRI for efficient - * NLRI packing. peer->obuf_work stores all the other attributes. The - * actual packet is then constructed by concatenating the two. - */ - struct stream *scratch; - /* the doppelganger peer structure, due to dual TCP conn setup */ struct peer *doppelganger; - /* Status of the peer. */ - enum bgp_fsm_status status; - enum bgp_fsm_status ostatus; - /* FSM events, stored for debug purposes. * Note: uchar used for reduced memory usage. */ @@ -1182,7 +1240,16 @@ struct peer { uint16_t table_dump_index; /* Peer information */ - int fd; /* File descriptor */ + + /* + * We will have 2 `struct peer_connection` data structures + * connection is our attempt to talk to our peer. incoming + * is the peer attempting to talk to us. When it is + * time to consolidate between the two, we'll solidify + * into the connection variable being used. + */ + struct peer_connection *connection; + int ttl; /* TTL of TCP connection to the peer. */ int rtt; /* Estimated round-trip-time from TCP_INFO */ int rtt_expected; /* Expected round-trip-time for a peer */ @@ -1192,8 +1259,7 @@ struct peer { char *desc; /* Description of the peer. */ unsigned short port; /* Destination port for peer */ char *host; /* Printable address of the peer. */ - union sockunion su; /* Sockunion address of the peer. */ -#define BGP_PEER_SU_UNSPEC(peer) (peer->su.sa.sa_family == AF_UNSPEC) + time_t uptime; /* Last Up/Down time */ time_t readtime; /* Last read time */ time_t resettime; /* Last reset time */ @@ -1230,8 +1296,7 @@ struct peer { /* Capability flags (reset in bgp_stop) */ uint32_t cap; #define PEER_CAP_REFRESH_ADV (1U << 0) /* refresh advertised */ -#define PEER_CAP_REFRESH_OLD_RCV (1U << 1) /* refresh old received */ -#define PEER_CAP_REFRESH_NEW_RCV (1U << 2) /* refresh rfc received */ +#define PEER_CAP_REFRESH_RCV (1U << 2) /* refresh rfc received */ #define PEER_CAP_DYNAMIC_ADV (1U << 3) /* dynamic advertised */ #define PEER_CAP_DYNAMIC_RCV (1U << 4) /* dynamic received */ #define PEER_CAP_RESTART_ADV (1U << 5) /* restart advertised */ @@ -1269,8 +1334,6 @@ struct peer { #define PEER_CAP_ORF_PREFIX_RM_ADV (1U << 1) /* receive-mode advertised */ #define PEER_CAP_ORF_PREFIX_SM_RCV (1U << 2) /* send-mode received */ #define PEER_CAP_ORF_PREFIX_RM_RCV (1U << 3) /* receive-mode received */ -#define PEER_CAP_ORF_PREFIX_SM_OLD_RCV (1U << 4) /* send-mode received */ -#define PEER_CAP_ORF_PREFIX_RM_OLD_RCV (1U << 5) /* receive-mode received */ #define PEER_CAP_RESTART_AF_RCV (1U << 6) /* graceful restart afi/safi received */ #define PEER_CAP_RESTART_AF_PRESERVE_RCV (1U << 7) /* graceful restart afi/safi F-bit received */ #define PEER_CAP_ADDPATH_AF_TX_ADV (1U << 8) /* addpath tx advertised */ @@ -1518,31 +1581,14 @@ struct peer { _Atomic uint32_t v_gr_restart; /* Threads. */ - struct event *t_read; - struct event *t_write; - struct event *t_start; - struct event *t_connect_check_r; - struct event *t_connect_check_w; - struct event *t_connect; - struct event *t_holdtime; - struct event *t_routeadv; - struct event *t_delayopen; - struct event *t_pmax_restart; - struct event *t_gr_restart; - struct event *t_gr_stale; struct event *t_llgr_stale[AFI_MAX][SAFI_MAX]; struct event *t_revalidate_all[AFI_MAX][SAFI_MAX]; - struct event *t_generate_updgrp_packets; - struct event *t_process_packet; - struct event *t_process_packet_error; struct event *t_refresh_stalepath; /* Thread flags. */ _Atomic uint32_t thread_flags; -#define PEER_THREAD_WRITES_ON (1U << 0) -#define PEER_THREAD_READS_ON (1U << 1) -#define PEER_THREAD_KEEPALIVES_ON (1U << 2) -#define PEER_THREAD_SUBGRP_ADV_DELAY (1U << 3) +#define PEER_THREAD_KEEPALIVES_ON (1U << 0) +#define PEER_THREAD_SUBGRP_ADV_DELAY (1U << 1) /* workqueues */ struct work_queue *clear_node_queue; @@ -1602,8 +1648,6 @@ struct peer { uint8_t update_delay_over; /* When this is set, BGP is no more waiting for EOR */ - /* Syncronization list and time. */ - struct bgp_synchronize *sync[AFI_MAX][SAFI_MAX]; time_t synctime; /* timestamp when the last UPDATE msg was written */ _Atomic time_t last_write; @@ -1713,13 +1757,13 @@ struct peer { #define PEER_DOWN_PFX_COUNT 33U /* Reached received prefix count */ #define PEER_DOWN_SOCKET_ERROR 34U /* Some socket error happened */ #define PEER_DOWN_RTT_SHUTDOWN 35U /* Automatically shutdown due to RTT */ +#define PEER_DOWN_SUPPRESS_FIB_PENDING 36U /* Suppress fib pending changed */ /* * Remember to update peer_down_str in bgp_fsm.c when you add * a new value to the last_reset reason */ - uint16_t last_reset_cause_size; - uint8_t last_reset_cause[BGP_MAX_PACKET_SIZE]; + struct stream *last_reset_cause; /* The kind of route-map Flags.*/ uint16_t rmap_type; @@ -1781,15 +1825,18 @@ struct peer { #define BGP_ATTR_MAX 255 /* Path attributes discard */ - bool discard_attrs[BGP_ATTR_MAX]; + bool discard_attrs[BGP_ATTR_MAX + 1]; /* Path attributes treat-as-withdraw */ - bool withdraw_attrs[BGP_ATTR_MAX]; + bool withdraw_attrs[BGP_ATTR_MAX + 1]; /* BGP Software Version Capability */ #define BGP_MAX_SOFT_VERSION 64 char *soft_version; + /* Add-Path Best selected paths number to advertise */ + uint8_t addpath_best_selected[AFI_MAX][SAFI_MAX]; + QOBJ_FIELDS; }; DECLARE_QOBJ_TYPE(peer); @@ -2033,7 +2080,8 @@ enum bgp_clear_type { BGP_CLEAR_SOFT_IN, BGP_CLEAR_SOFT_BOTH, BGP_CLEAR_SOFT_IN_ORF_PREFIX, - BGP_CLEAR_MESSAGE_STATS + BGP_CLEAR_MESSAGE_STATS, + BGP_CLEAR_CAPABILITIES, }; /* Macros. */ @@ -2104,6 +2152,26 @@ enum peer_change_type { peer_change_reset_out, }; +/* Enumeration of martian ("self") entry types. + * Routes carrying fields that match a self entry are considered martians + * and should be handled accordingly, i.e. dropped or import-filtered. + * Note: + * These "martians" are separate from routes optionally allowed via + * 'bgp allow-martian-nexthop'. The optionally allowed martians are + * simply prefixes caught by ipv4_martian(), i.e. routes outside + * the non-reserved IPv4 Unicast address space. + */ +enum bgp_martian_type { + BGP_MARTIAN_IF_IP, /* bgp->address_hash */ + BGP_MARTIAN_TUN_IP, /* bgp->tip_hash */ + BGP_MARTIAN_IF_MAC, /* bgp->self_mac_hash */ + BGP_MARTIAN_RMAC, /* bgp->rmac */ + BGP_MARTIAN_SOO, /* bgp->evpn_info->macvrf_soo */ +}; + +extern const struct message bgp_martian_type_str[]; +extern const char *bgp_martian_type2str(enum bgp_martian_type mt); + extern struct bgp_master *bm; extern unsigned int multipath_num; @@ -2120,7 +2188,7 @@ extern void bgp_set_evpn(struct bgp *bgp); extern struct peer *peer_lookup(struct bgp *, union sockunion *); extern struct peer *peer_lookup_by_conf_if(struct bgp *, const char *); extern struct peer *peer_lookup_by_hostname(struct bgp *, const char *); -extern void bgp_peer_conf_if_to_su_update(struct peer *); +extern void bgp_peer_conf_if_to_su_update(struct peer_connection *connection); extern int peer_group_listen_range_del(struct peer_group *, struct prefix *); extern struct peer_group *peer_group_lookup(struct bgp *, const char *); extern struct peer_group *peer_group_get(struct bgp *, const char *); @@ -2210,8 +2278,9 @@ extern void bgp_confederation_peers_add(struct bgp *bgp, as_t as, const char *as_str); extern void bgp_confederation_peers_remove(struct bgp *bgp, as_t as); -extern void bgp_timers_set(struct bgp *, uint32_t keepalive, uint32_t holdtime, - uint32_t connect_retry, uint32_t delayopen); +extern void bgp_timers_set(struct vty *vty, struct bgp *, uint32_t keepalive, + uint32_t holdtime, uint32_t connect_retry, + uint32_t delayopen); extern void bgp_timers_unset(struct bgp *); extern void bgp_default_local_preference_set(struct bgp *bgp, @@ -2378,6 +2447,8 @@ extern enum asnotation_mode bgp_get_asnotation(struct bgp *bgp); extern void bgp_route_map_terminate(void); +extern bool bgp_route_map_has_extcommunity_rt(const struct route_map *map); + extern int peer_cmp(struct peer *p1, struct peer *p2); extern int bgp_map_afi_safi_iana2int(iana_afi_t pkt_afi, iana_safi_t pkt_safi, @@ -2543,16 +2614,17 @@ static inline int peer_group_af_configured(struct peer_group *group) return 0; } -static inline char *timestamp_string(time_t ts) +static inline char *timestamp_string(time_t ts, char *timebuf) { time_t tbuf; + tbuf = time(NULL) - (monotime(NULL) - ts); - return ctime(&tbuf); + return ctime_r(&tbuf, timebuf); } -static inline bool peer_established(struct peer *peer) +static inline bool peer_established(struct peer_connection *connection) { - return peer->status == Established; + return connection->status == Established; } static inline bool peer_dynamic_neighbor(struct peer *peer) @@ -2648,7 +2720,7 @@ DECLARE_HOOK(peer_status_changed, (struct peer *peer), (peer)); DECLARE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp)); DECLARE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp)); DECLARE_HOOK(bgp_snmp_update_stats, - (struct bgp_node *rn, struct bgp_path_info *pi, bool added), + (struct bgp_dest *rn, struct bgp_path_info *pi, bool added), (rn, pi, added)); DECLARE_HOOK(bgp_rpki_prefix_status, (struct peer * peer, struct attr *attr, @@ -2668,6 +2740,9 @@ extern bool bgp_path_attribute_discard(struct peer *peer, char *buf, size_t size); extern bool bgp_path_attribute_treat_as_withdraw(struct peer *peer, char *buf, size_t size); + +extern void srv6_function_free(struct bgp_srv6_function *func); + #ifdef _FRR_ATTRIBUTE_PRINTFRR /* clang-format off */ #pragma FRR printfrr_ext "%pBP" (struct peer *) diff --git a/bgpd/rfapi/bgp_rfapi_cfg.c b/bgpd/rfapi/bgp_rfapi_cfg.c index 5b6961d18a..676d0771cd 100644 --- a/bgpd/rfapi/bgp_rfapi_cfg.c +++ b/bgpd/rfapi/bgp_rfapi_cfg.c @@ -1720,7 +1720,8 @@ DEFUN (vnc_nve_group_export_no_routemap, switch (argv[idx]->text[0]) { case 'z': is_bgp = 0; - /* fall thru */ + idx += 2; + break; case 'b': idx += 2; break; @@ -3590,7 +3591,9 @@ DEFUN (vnc_l2_group_rt, switch (argv[1]->arg[0]) { case 'b': - do_export = 1; /* fall through */ + do_export = 1; + do_import = 1; + break; case 'i': do_import = 1; break; diff --git a/bgpd/rfapi/rfapi.c b/bgpd/rfapi/rfapi.c index 67c70431bd..a2c86d1eae 100644 --- a/bgpd/rfapi/rfapi.c +++ b/bgpd/rfapi/rfapi.c @@ -46,11 +46,6 @@ #include "bgpd/rfapi/rfapi_encap_tlv.h" #include "bgpd/rfapi/vnc_debug.h" -#ifdef HAVE_GLIBC_BACKTRACE -/* for backtrace and friends */ -#include -#endif /* HAVE_GLIBC_BACKTRACE */ - #define DEBUG_CLEANUP 0 struct ethaddr rfapi_ethaddr0 = {{0}}; @@ -1236,30 +1231,9 @@ static int rfapi_open_inner(struct rfapi_descriptor *rfd, struct bgp *bgp, * Fill in BGP peer structure */ rfd->peer = peer_new(bgp); - rfd->peer->status = Established; /* keep bgp core happy */ - bgp_sync_delete(rfd->peer); /* don't need these */ - - /* - * since this peer is not on the I/O thread, this lock is not strictly - * necessary, but serves as a reminder to those who may meddle... - */ - frr_with_mutex (&rfd->peer->io_mtx) { - // we don't need any I/O related facilities - if (rfd->peer->ibuf) - stream_fifo_free(rfd->peer->ibuf); - if (rfd->peer->obuf) - stream_fifo_free(rfd->peer->obuf); - - if (rfd->peer->ibuf_work) - ringbuf_del(rfd->peer->ibuf_work); - if (rfd->peer->obuf_work) - stream_free(rfd->peer->obuf_work); + rfd->peer->connection->status = Established; /* keep bgp core happy */ - rfd->peer->ibuf = NULL; - rfd->peer->obuf = NULL; - rfd->peer->obuf_work = NULL; - rfd->peer->ibuf_work = NULL; - } + bgp_peer_connection_buffers_free(rfd->peer->connection); { /* base code assumes have valid host pointer */ char buf[INET6_ADDRSTRLEN]; @@ -2112,24 +2086,7 @@ int rfapi_close(void *handle) vnc_zlog_debug_verbose("%s: rfd=%p", __func__, rfd); #ifdef RFAPI_WHO_IS_CALLING_ME -#ifdef HAVE_GLIBC_BACKTRACE -#define RFAPI_DEBUG_BACKTRACE_NENTRIES 5 - { - void *buf[RFAPI_DEBUG_BACKTRACE_NENTRIES]; - char **syms; - int i; - size_t size; - - size = backtrace(buf, RFAPI_DEBUG_BACKTRACE_NENTRIES); - syms = backtrace_symbols(buf, size); - for (i = 0; i < size && i < RFAPI_DEBUG_BACKTRACE_NENTRIES; - ++i) { - vnc_zlog_debug_verbose("backtrace[%2d]: %s", i, - syms[i]); - } - free(syms); - } -#endif + zlog_backtrace(LOG_INFO); #endif bgp = rfd->bgp; diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c index 27f7c88d7b..f9789adad2 100644 --- a/bgpd/rfapi/rfapi_import.c +++ b/bgpd/rfapi/rfapi_import.c @@ -44,11 +44,6 @@ #include "bgpd/rfapi/rfapi_encap_tlv.h" #include "bgpd/rfapi/vnc_debug.h" -#ifdef HAVE_GLIBC_BACKTRACE -/* for backtrace and friends */ -#include -#endif /* HAVE_GLIBC_BACKTRACE */ - #undef DEBUG_MONITOR_MOVE_SHORTER #undef DEBUG_RETURNED_NHL #undef DEBUG_ROUTE_COUNTERS @@ -77,32 +72,6 @@ struct rfapi_withdraw { int lockoffset; }; -/* - * DEBUG FUNCTION - * It's evil and fiendish. It's compiler-dependent. - * ? Might need LDFLAGS -rdynamic to produce all function names - */ -void rfapiDebugBacktrace(void) -{ -#ifdef HAVE_GLIBC_BACKTRACE -#define RFAPI_DEBUG_BACKTRACE_NENTRIES 200 - void *buf[RFAPI_DEBUG_BACKTRACE_NENTRIES]; - char **syms; - size_t i; - size_t size; - - size = backtrace(buf, RFAPI_DEBUG_BACKTRACE_NENTRIES); - syms = backtrace_symbols(buf, size); - - for (i = 0; i < size && i < RFAPI_DEBUG_BACKTRACE_NENTRIES; ++i) { - vnc_zlog_debug_verbose("backtrace[%2zu]: %s", i, syms[i]); - } - - free(syms); -#else -#endif -} - /* * DEBUG FUNCTION * Count remote routes and compare with actively-maintained values. @@ -1709,7 +1678,7 @@ struct rfapi_next_hop_entry *rfapiRouteNode2NextHopList( #ifdef DEBUG_RETURNED_NHL vnc_zlog_debug_verbose("%s: called with node pfx=%rRN", __func__, rn); - rfapiDebugBacktrace(); + zlog_backtrace(LOG_INFO); #endif rfapiQprefix2Rprefix(p, &rprefix); @@ -3729,8 +3698,9 @@ void rfapiBgpInfoFilteredImportVPN( prefix_same(&pfx_un, &un_prefix)) { /* compare */ un_match = 1; } - if (!RFAPI_LOCAL_BI(bpi) && !RFAPI_LOCAL_BI(info_new) - && sockunion_same(&bpi->peer->su, &info_new->peer->su)) { + if (!RFAPI_LOCAL_BI(bpi) && !RFAPI_LOCAL_BI(info_new) && + sockunion_same(&bpi->peer->connection->su, + &info_new->peer->connection->su)) { /* old & new are both remote, same peer */ remote_peer_match = 1; } diff --git a/bgpd/rfapi/rfapi_import.h b/bgpd/rfapi/rfapi_import.h index dd06afe7e2..1a37e1c2db 100644 --- a/bgpd/rfapi/rfapi_import.h +++ b/bgpd/rfapi/rfapi_import.h @@ -57,8 +57,6 @@ struct rfapi_import_table { extern uint8_t rfapiRfpCost(struct attr *attr); -extern void rfapiDebugBacktrace(void); - extern void rfapiCheckRouteCount(void); /* diff --git a/bgpd/rfapi/rfapi_vty.c b/bgpd/rfapi/rfapi_vty.c index 29698846c3..43625b11a6 100644 --- a/bgpd/rfapi/rfapi_vty.c +++ b/bgpd/rfapi/rfapi_vty.c @@ -420,15 +420,20 @@ void rfapi_vty_out_vncinfo(struct vty *vty, const struct prefix *p, vty_out(vty, " label=%u", decode_label(&bpi->extra->label[0])); - if (bpi->extra->num_sids) { - vty_out(vty, " sid=%pI6", &bpi->extra->sid[0].sid); - - if (bpi->extra->sid[0].loc_block_len != 0) { + if (bpi->attr->srv6_l3vpn || bpi->attr->srv6_vpn) { + struct in6_addr *sid_tmp = + bpi->attr->srv6_l3vpn + ? (&bpi->attr->srv6_l3vpn->sid) + : (&bpi->attr->srv6_vpn->sid); + vty_out(vty, " sid=%pI6", sid_tmp); + + if (bpi->attr->srv6_l3vpn && + bpi->attr->srv6_l3vpn->loc_block_len != 0) { vty_out(vty, " sid_structure=[%d,%d,%d,%d]", - bpi->extra->sid[0].loc_block_len, - bpi->extra->sid[0].loc_node_len, - bpi->extra->sid[0].func_len, - bpi->extra->sid[0].arg_len); + bpi->attr->srv6_l3vpn->loc_block_len, + bpi->attr->srv6_l3vpn->loc_node_len, + bpi->attr->srv6_l3vpn->func_len, + bpi->attr->srv6_l3vpn->arg_len); } } } @@ -4146,6 +4151,7 @@ static int rfapi_vty_show_nve_summary(struct vty *vty, case SHOW_NVE_SUMMARY_RESPONSES: rfapiRibShowResponsesSummary(vty); + break; case SHOW_NVE_SUMMARY_UNKNOWN_NVES: case SHOW_NVE_SUMMARY_MAX: diff --git a/bgpd/rfapi/vnc_zebra.c b/bgpd/rfapi/vnc_zebra.c index 4c55c2f633..82c08cabde 100644 --- a/bgpd/rfapi/vnc_zebra.c +++ b/bgpd/rfapi/vnc_zebra.c @@ -171,32 +171,11 @@ static void vnc_redistribute_add(struct prefix *p, uint32_t metric, * Same setup as in rfapi_open() */ vncHD1VR.peer = peer_new(bgp); - vncHD1VR.peer->status = + vncHD1VR.peer->connection->status = Established; /* keep bgp core happy */ - bgp_sync_delete(vncHD1VR.peer); /* don't need these */ - /* - * since this peer is not on the I/O thread, this lock - * is not strictly necessary, but serves as a reminder - * to those who may meddle... - */ - frr_with_mutex (&vncHD1VR.peer->io_mtx) { - // we don't need any I/O related facilities - if (vncHD1VR.peer->ibuf) - stream_fifo_free(vncHD1VR.peer->ibuf); - if (vncHD1VR.peer->obuf) - stream_fifo_free(vncHD1VR.peer->obuf); - - if (vncHD1VR.peer->ibuf_work) - ringbuf_del(vncHD1VR.peer->ibuf_work); - if (vncHD1VR.peer->obuf_work) - stream_free(vncHD1VR.peer->obuf_work); - - vncHD1VR.peer->ibuf = NULL; - vncHD1VR.peer->obuf = NULL; - vncHD1VR.peer->obuf_work = NULL; - vncHD1VR.peer->ibuf_work = NULL; - } + bgp_peer_connection_buffers_free( + vncHD1VR.peer->connection); /* base code assumes have valid host pointer */ vncHD1VR.peer->host = @@ -560,9 +539,9 @@ static void vnc_zebra_add_del_prefix(struct bgp *bgp, return; } - if (!vrf_bitmap_check( - zclient_vnc->redist[family2afi(p->family)][ZEBRA_ROUTE_VNC], - VRF_DEFAULT)) + if (!vrf_bitmap_check(&zclient_vnc->redist[family2afi(p->family)] + [ZEBRA_ROUTE_VNC], + VRF_DEFAULT)) return; if (!bgp->rfapi_cfg) { @@ -622,7 +601,7 @@ static void vnc_zebra_add_del_nve(struct bgp *bgp, struct rfapi_descriptor *rfd, if (zclient_vnc->sock < 0) return; - if (!vrf_bitmap_check(zclient_vnc->redist[afi][ZEBRA_ROUTE_VNC], + if (!vrf_bitmap_check(&zclient_vnc->redist[afi][ZEBRA_ROUTE_VNC], VRF_DEFAULT)) return; @@ -819,12 +798,12 @@ int vnc_redistribute_set(struct bgp *bgp, afi_t afi, int type) // bgp->redist[afi][type] = 1; /* Return if already redistribute flag is set. */ - if (vrf_bitmap_check(zclient_vnc->redist[afi][type], VRF_DEFAULT)) + if (vrf_bitmap_check(&zclient_vnc->redist[afi][type], VRF_DEFAULT)) return CMD_WARNING_CONFIG_FAILED; - vrf_bitmap_set(zclient_vnc->redist[afi][type], VRF_DEFAULT); + vrf_bitmap_set(&zclient_vnc->redist[afi][type], VRF_DEFAULT); - // vrf_bitmap_set(zclient_vnc->redist[afi][type], VRF_DEFAULT); + // vrf_bitmap_set(&zclient_vnc->redist[afi][type], VRF_DEFAULT); /* Return if zebra connection is not established. */ if (zclient_vnc->sock < 0) @@ -855,9 +834,9 @@ int vnc_redistribute_unset(struct bgp *bgp, afi_t afi, int type) bgp->rfapi_cfg->redist[afi][type] = 0; /* Return if zebra connection is disabled. */ - if (!vrf_bitmap_check(zclient_vnc->redist[afi][type], VRF_DEFAULT)) + if (!vrf_bitmap_check(&zclient_vnc->redist[afi][type], VRF_DEFAULT)) return CMD_WARNING_CONFIG_FAILED; - vrf_bitmap_unset(zclient_vnc->redist[afi][type], VRF_DEFAULT); + vrf_bitmap_unset(&zclient_vnc->redist[afi][type], VRF_DEFAULT); if (bgp->rfapi_cfg->redist[AFI_IP][type] == 0 && bgp->rfapi_cfg->redist[AFI_IP6][type] == 0 @@ -893,7 +872,7 @@ static zclient_handler *const vnc_handlers[] = { void vnc_zebra_init(struct event_loop *master) { /* Set default values. */ - zclient_vnc = zclient_new(master, &zclient_options_default, + zclient_vnc = zclient_new(master, &zclient_options_auxiliary, vnc_handlers, array_size(vnc_handlers)); zclient_init(zclient_vnc, ZEBRA_ROUTE_VNC, 0, &bgpd_privs); } diff --git a/bgpd/subdir.am b/bgpd/subdir.am index c2dd207a49..6d6fad0074 100644 --- a/bgpd/subdir.am +++ b/bgpd/subdir.am @@ -77,6 +77,7 @@ bgpd_libbgp_a_SOURCES = \ bgpd/bgp_zebra.c \ bgpd/bgpd.c \ bgpd/bgp_trace.c \ + bgpd/bgp_nhg.c \ # end if ENABLE_BGP_VNC @@ -160,6 +161,7 @@ noinst_HEADERS += \ bgpd/bgp_zebra.h \ bgpd/bgpd.h \ bgpd/bgp_trace.h \ + bgpd/bgp_nhg.h \ \ bgpd/rfapi/bgp_rfapi_cfg.h \ bgpd/rfapi/rfapi_import.h \ @@ -214,6 +216,7 @@ clippy_scan += \ bgpd/bgp_rpki.c \ bgpd/bgp_vty.c \ bgpd/bgp_nexthop.c \ + bgpd/bgp_snmp.c \ # end nodist_bgpd_bgpd_SOURCES = \ diff --git a/configure.ac b/configure.ac index 0120c517c6..174090d3a9 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ ## AC_PREREQ([2.69]) -AC_INIT([frr], [9.0-dev], [https://github.com/frrouting/frr/issues]) +AC_INIT([frr], [9.2-dev], [https://github.com/frrouting/frr/issues]) PACKAGE_URL="https://frrouting.org/" AC_SUBST([PACKAGE_URL]) PACKAGE_FULLNAME="FRRouting" @@ -365,6 +365,7 @@ AC_C_FLAG([-Wpointer-arith]) AC_C_FLAG([-Wbad-function-cast]) AC_C_FLAG([-Wwrite-strings]) AC_C_FLAG([-Wundef]) +AC_C_FLAG([-Wimplicit-fallthrough]) if test "$enable_gcc_ultra_verbose" = "yes" ; then AC_C_FLAG([-Wcast-qual]) AC_C_FLAG([-Wmissing-noreturn]) @@ -378,6 +379,7 @@ else fi AC_C_FLAG([-Wno-unused-parameter]) AC_C_FLAG([-Wno-missing-field-initializers]) +AC_C_FLAG([-Wno-microsoft-anon-tag]) AC_C_FLAG([-Wc++-compat], [], [CXX_COMPAT_CFLAGS="-Wc++-compat"]) AC_SUBST([CXX_COMPAT_CFLAGS]) @@ -721,10 +723,6 @@ AC_ARG_ENABLE([gcc_ultra_verbose], AS_HELP_STRING([--enable-gcc-ultra-verbose], [enable ultra verbose GCC warnings])) AC_ARG_ENABLE([backtrace], AS_HELP_STRING([--disable-backtrace], [disable crash backtraces (default autodetect)])) -AC_ARG_ENABLE([time-check], - AS_HELP_STRING([--disable-time-check], [disable slow thread warning messages])) -AC_ARG_ENABLE([cpu-time], - AS_HELP_STRING([--disable-cpu-time], [disable cpu usage data gathering])) AC_ARG_ENABLE([pcreposix], AS_HELP_STRING([--enable-pcreposix], [enable using PCRE Posix libs for regex functions])) AC_ARG_ENABLE([pcre2posix], @@ -737,8 +735,6 @@ AC_ARG_ENABLE([cumulus], AS_HELP_STRING([--enable-cumulus], [enable Cumulus Switch Special Extensions])) AC_ARG_ENABLE([datacenter], AS_HELP_STRING([--enable-datacenter], [enable Compilation for Data Center Extensions])) -AC_ARG_ENABLE([rr-semantics], - AS_HELP_STRING([--disable-rr-semantics], [disable the v6 Route Replace semantics])) AC_ARG_ENABLE([protobuf], AS_HELP_STRING([--enable-protobuf], [Enable experimental protobuf support])) AC_ARG_ENABLE([oldvpn_commands], @@ -812,26 +808,6 @@ fi AM_CONDITIONAL([NETLINK_DEBUG], [test "$enable_netlink_debug" != "no"]) -if test "$enable_time_check" != "no" ; then - if test "$enable_time_check" = "yes" -o "$enable_time_check" = "" ; then - AC_DEFINE([CONSUMED_TIME_CHECK], [5000000], [Consumed Time Check]) - else - AC_DEFINE_UNQUOTED([CONSUMED_TIME_CHECK], [$enable_time_check], [Consumed Time Check]) - fi -fi - -case "${enable_cpu_time}" in - "no") - AC_DEFINE([EXCLUDE_CPU_TIME], [1], [Exclude getrusage data gathering]) - ;; - "*") - ;; -esac - -if test "$enable_rr_semantics" != "no" ; then - AC_DEFINE([HAVE_V6_RR_SEMANTICS], [1], [Compile in v6 Route Replacement Semantics]) -fi - if test "$enable_datacenter" = "yes" ; then AC_DEFINE([HAVE_DATACENTER], [1], [Compile extensions for a DataCenter]) DFLT_NAME="datacenter" @@ -1205,9 +1181,6 @@ m4_define([FRR_INCLUDES], /* Required for MAXSIG */ #include #include -#ifdef __APPLE__ -# define __APPLE_USE_RFC_3542 -#endif #include #include #include @@ -1385,7 +1358,9 @@ if test "$enable_protobuf3" = "yes"; then [PROTO3=false && AC_MSG_FAILURE([protobuf3 requested but protobuf-c.h not found. Install protobuf-c.])]) fi -AC_DEFINE([HAVE_PROTOBUF], [1], [protobuf]) +if test "$enable_protobuf" != "no"; then + AC_DEFINE([HAVE_PROTOBUF], [1], [protobuf]) +fi # # End of logic for protobuf support. # @@ -1978,9 +1953,9 @@ AC_SUBST([SNMP_CFLAGS]) dnl --------------- dnl libyang dnl --------------- -PKG_CHECK_MODULES([LIBYANG], [libyang >= 2.0.0], , [ - AC_MSG_ERROR([libyang (>= 2.0.0) was not found on your system.]) -]) +PKG_CHECK_MODULES([LIBYANG], [libyang >= 2.1.128], , [ +AC_MSG_ERROR([m4_normalize([libyang >= 2.1.128 is required, and was not found on your system. +Pleaes consult doc/developer/building-libyang.rst for instructions on installing or building libyang.])])]) ac_cflags_save="$CFLAGS" CFLAGS="$CFLAGS $LIBYANG_CFLAGS" AC_CHECK_MEMBER([struct lyd_node.priv], [], [ @@ -1989,6 +1964,13 @@ AC_CHECK_MEMBER([struct lyd_node.priv], [], [ Instructions for this are included in the build documentation for your platform at http://docs.frrouting.org/projects/dev-guide/en/latest/building.html]) ]) ], [[#include ]]) + +AC_CHECK_LIB([yang],[lyd_find_xpath3],[],[AC_MSG_ERROR([m4_normalize([ +libyang missing lyd_find_xpath3])])]) +dnl -- don't add lyd_new_list3 to this list unless bug is fixed upstream +dnl -- https://github.com/CESNET/libyang/issues/2149 +AC_CHECK_FUNCS([ly_strerrcode ly_strvecode lyd_trim_xpath]) + CFLAGS="$ac_cflags_save" dnl --------------- @@ -2848,6 +2830,7 @@ EOF cat >> "${srcdir}/.ccls" < Tue, 07 Feb 2023 16:00:00 +0500 + -- Donatas Abraitis Tue, 10 Oct 2023 12:00:00 -0600 -frr (8.5-1) UNRELEASED; urgency=medium +frr (9.1-0) unstable; urgency=medium + + * New upstream release FRR 9.1 + + -- Donatas Abraitis Thu, 09 Oct 2023 12:00:00 -0600 + +frr (9.0-0) unstable; urgency=medium + + * New upstream release FRR 9.0 + + -- Jafar Al-Gharaibeh Wed, 26 Jul 2023 02:00:00 -0600 + +frr (8.5-0) unstable; urgency=medium * New upstream release FRR 8.5 - -- Donatas Abraitis Tue, 07 Feb 2023 16:00:00 +0500 + -- Jafar Al-Gharaibeh Fri, 10 Mar 2023 02:00:00 -0600 frr (8.4.2-1) unstable; urgency=medium diff --git a/debian/control b/debian/control index 9b7dcfe418..b3c14f06f3 100644 --- a/debian/control +++ b/debian/control @@ -17,14 +17,16 @@ Build-Depends: bison, libjson-c-dev | libjson0-dev, libpam0g-dev | libpam-dev, libpcre2-dev, + libprotobuf-c-dev, libpython3-dev:native, libreadline-dev, librtr-dev (>= 0.8.0~) , libsnmp-dev, libssh-dev , - libyang2-dev, + libyang2-dev (>= 2.1.80), lsb-base, pkg-config, + protobuf-c-compiler, python3:native, python3-dev:native, python3-pytest:native , diff --git a/debian/not-installed b/debian/not-installed index 1a89f35853..8999dd948b 100644 --- a/debian/not-installed +++ b/debian/not-installed @@ -1,3 +1,4 @@ usr/include usr/lib/frr/ospfclient usr/lib/frr/rfptest +usr/lib/*/frr/modules/dplane_sample_plugin.so diff --git a/doc/developer/.readthedocs.yaml b/doc/developer/.readthedocs.yaml new file mode 100644 index 0000000000..90ee5c7677 --- /dev/null +++ b/doc/developer/.readthedocs.yaml @@ -0,0 +1,18 @@ +# Required +version: 2 + +# Set the version of Python and other tools you might need +build: + os: ubuntu-22.04 + tools: + python: "3.11" + apt_packages: + - graphviz + +python: + install: + - requirements: doc/developer/requirements.txt + +# Build documentation in the docs/ directory with Sphinx +sphinx: + configuration: doc/developer/conf.py diff --git a/doc/developer/bmp.rst b/doc/developer/bmp.rst new file mode 100644 index 0000000000..1c0e4b0454 --- /dev/null +++ b/doc/developer/bmp.rst @@ -0,0 +1,49 @@ +.. _bmp: + +*** +BMP +*** + +RFC 7854 +======== +Missing features (non exhaustive): + - Per-Peer Header + + - Peer Type Flag + - Peer Distingsher + + - Peer Up + + - Reason codes (according to TODO comments in code) + +Peer Type Flag and Peer Distinguisher can be implemented easily using RFC 9069's base code. + +RFC 9069 +======== +Everything that isn't listed here is implemented and should be working. +Missing features (should be exhaustive): + +- Per-Peer Header + + - Timestamp + + - set to 0 + - value is now saved `struct bgp_path_info -> locrib_uptime` + - needs testing + +- Peer Up/Down + + - VRF/Table Name TLV + + - code for TLV exists + - need better RFC understanding + +- Peer Down Only + + - Reason code (bc not supported in RFC 7854 either) + +- Statistics Report + + - Stat Type = 8: (64-bit Gauge) Number of routes in Loc-RIB. + - Stat Type = 10: Number of routes in per-AFI/SAFI Loc-RIB. The value is + structured as: 2-byte AFI, 1-byte SAFI, followed by a 64-bit Gauge. diff --git a/doc/developer/building-docker.rst b/doc/developer/building-docker.rst index 4cf356049e..644e02bd6c 100644 --- a/doc/developer/building-docker.rst +++ b/doc/developer/building-docker.rst @@ -14,10 +14,10 @@ source-built FRR on the following base platforms: The following platform images are used to support Travis CI and can also be used to reproduce topotest failures when the docker host is Ubuntu -(tested on 18.04 and 20.04): +(tested on 20.04 and 22.04): -* Ubuntu 18.04 * Ubuntu 20.04 +* Ubuntu 22.04 The following platform images may also be built, but these simply install a binary package from an existing repository and do not perform source builds: @@ -130,57 +130,75 @@ No script, multi-arch (ex. amd64, arm64):: -Building Ubuntu 18.04 Image +Building Ubuntu 20.04 Image --------------------------- Build image (from project root directory):: - docker build -t frr-ubuntu18:latest -f docker/ubuntu18-ci/Dockerfile . + docker build -t frr-ubuntu20:latest --build-arg=UBUNTU_VERSION=20.04 -f docker/ubuntu-ci/Dockerfile . + +Running Full Topotest:: + + docker run --init -it --privileged --name frr-ubuntu20 -v /lib/modules:/lib/modules \ + frr-ubuntu20:latest bash -c 'cd ~/frr/tests/topotests ; sudo pytest -nauto --dist=loadfile' + +Extract results from the above run into `run-results` dir and analyze:: + + tests/topotests/analyze.py -C frr-ubuntu20 -Ar run-results Start the container:: - docker run -d --privileged --name frr-ubuntu18 --mount type=bind,source=/lib/modules,target=/lib/modules frr-ubuntu18:latest + docker run -d --init --privileged --name frr-ubuntu20 --mount type=bind,source=/lib/modules,target=/lib/modules frr-ubuntu20:latest Running a topotest (when the docker host is Ubuntu):: - docker exec frr-ubuntu18 bash -c 'cd ~/frr/tests/topotests/ospf-topo1 ; sudo pytest test_ospf_topo1.py' + docker exec frr-ubuntu20 bash -c 'cd ~/frr/tests/topotests/ospf_topo1 ; sudo pytest test_ospf_topo1.py' Starting an interactive bash session:: - docker exec -it frr-ubuntu18 bash + docker exec -it frr-ubuntu20 bash Stopping an removing a container:: - docker stop frr-ubuntu18 ; docker rm frr-ubuntu18 + docker stop frr-ubuntu20 ; docker rm frr-ubuntu20 Removing the built image:: - docker rmi frr-ubuntu18:latest + docker rmi frr-ubuntu20:latest -Building Ubuntu 20.04 Image +Building Ubuntu 22.04 Image --------------------------- Build image (from project root directory):: - docker build -t frr-ubuntu20:latest -f docker/ubuntu20-ci/Dockerfile . + docker build -t frr-ubuntu22:latest -f docker/ubuntu-ci/Dockerfile . + +Running Full Topotest:: + + docker run --init -it --privileged --name frr-ubuntu22 -v /lib/modules:/lib/modules \ + frr-ubuntu22:latest bash -c 'cd ~/frr/tests/topotests ; sudo pytest -nauto --dist=loadfile' + +Extract results from the above run into `run-results` dir and analyze:: + + tests/topotests/analyze.py -C frr-ubuntu22 -Ar run-results Start the container:: - docker run -d --privileged --name frr-ubuntu20 --mount type=bind,source=/lib/modules,target=/lib/modules frr-ubuntu20:latest + docker run -d --init --privileged --name frr-ubuntu22 --mount type=bind,source=/lib/modules,target=/lib/modules frr-ubuntu22:latest Running a topotest (when the docker host is Ubuntu):: - docker exec frr-ubuntu20 bash -c 'cd ~/frr/tests/topotests/ospf-topo1 ; sudo pytest test_ospf_topo1.py' + docker exec frr-ubuntu22 bash -c 'cd ~/frr/tests/topotests/ospf_topo1 ; sudo pytest test_ospf_topo1.py' Starting an interactive bash session:: - docker exec -it frr-ubuntu20 bash + docker exec -it frr-ubuntu22 bash Stopping an removing a container:: - docker stop frr-ubuntu20 ; docker rm frr-ubuntu20 + docker stop frr-ubuntu22 ; docker rm frr-ubuntu22 Removing the built image:: - docker rmi frr-ubuntu20:latest + docker rmi frr-ubuntu22:latest diff --git a/doc/developer/building-frr-for-archlinux.rst b/doc/developer/building-frr-for-archlinux.rst index 406d22d618..8b0df217a0 100644 --- a/doc/developer/building-frr-for-archlinux.rst +++ b/doc/developer/building-frr-for-archlinux.rst @@ -11,18 +11,12 @@ Installing Dependencies git autoconf automake libtool make cmake pcre readline texinfo \ pkg-config pam json-c bison flex python-pytest \ c-ares python python2-ipaddress python-sphinx \ - net-snmp perl libcap libelf libunwind + net-snmp perl libcap libelf libunwind protobuf-c .. include:: building-libunwind-note.rst .. include:: building-libyang.rst -Protobuf -^^^^^^^^ - -.. code-block:: console - - sudo pacman -S protobuf-c ZeroMQ ^^^^^^ diff --git a/doc/developer/building-frr-for-centos6.rst b/doc/developer/building-frr-for-centos6.rst index 233d089f79..fb796e491e 100644 --- a/doc/developer/building-frr-for-centos6.rst +++ b/doc/developer/building-frr-for-centos6.rst @@ -124,7 +124,7 @@ Install libyang and its dependencies: sudo yum install pcre-devel doxygen cmake git clone https://github.com/CESNET/libyang.git cd libyang - git checkout 090926a89d59a3c4000719505d563aaf6ac60f2 + git checkout v2.1.128 mkdir build ; cd build cmake -DENABLE_LYD_PRIV=ON -DCMAKE_INSTALL_PREFIX:PATH=/usr -D CMAKE_BUILD_TYPE:String="Release" .. make build-rpm diff --git a/doc/developer/building-frr-for-debian12.rst b/doc/developer/building-frr-for-debian12.rst new file mode 100644 index 0000000000..ca882eedbc --- /dev/null +++ b/doc/developer/building-frr-for-debian12.rst @@ -0,0 +1,119 @@ +Debian 12 +========= + +Install required packages +------------------------- + +Add packages: + +:: + + sudo apt-get install git autoconf automake libtool make \ + libprotobuf-c-dev protobuf-c-compiler build-essential \ + python3-dev python3-pytest python3-sphinx libjson-c-dev \ + libelf-dev libreadline-dev cmake libcap-dev bison flex \ + pkg-config texinfo gdb libgrpc-dev python3-grpc-tools + +.. include:: building-libunwind-note.rst + +.. include:: building-libyang.rst + +Get FRR, compile it and install it (from Git) +--------------------------------------------- + +**This assumes you want to build and install FRR from source and not +using any packages** + +Add frr groups and user +^^^^^^^^^^^^^^^^^^^^^^^ + +:: + + sudo addgroup --system --gid 92 frr + sudo addgroup --system --gid 85 frrvty + sudo adduser --system --ingroup frr --home /var/opt/frr/ \ + --gecos "FRR suite" --shell /bin/false frr + sudo usermod -a -G frrvty frr + +Download Source, configure and compile it +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +(You may prefer different options on configure statement. These are just +an example.) + +:: + + git clone https://github.com/frrouting/frr.git frr + cd frr + ./bootstrap.sh + ./configure \ + --localstatedir=/var/opt/frr \ + --sbindir=/usr/lib/frr \ + --sysconfdir=/etc/frr \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + make + make check + sudo make install + +For more compile options, see ``./configure --help`` + +Create empty FRR configuration files +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +:: + + sudo install -m 640 -o frr -g frr /dev/null /etc/frr/frr.conf + sudo install -m 640 -o frr -g frr tools/etc/frr/daemons /etc/frr/daemons + +Edit ``/etc/frr/daemons`` and enable the FRR daemons for the protocols you need + +Enable IP & IPv6 forwarding +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Edit ``/etc/sysctl.conf`` and uncomment the following values (ignore the +other settings) + +:: + + # Uncomment the next line to enable packet forwarding for IPv4 + net.ipv4.ip_forward=1 + + # Uncomment the next line to enable packet forwarding for IPv6 + # Enabling this option disables Stateless Address Autoconfiguration + # based on Router Advertisements for this host + net.ipv6.conf.all.forwarding=1 + +**Reboot** or use ``sysctl -p`` to apply the same config to the running +system + +Troubleshooting +--------------- + +Shared library error +^^^^^^^^^^^^^^^^^^^^ + +If you try and start any of the frrouting daemons you may see the below +error due to the frrouting shared library directory not being found: + +:: + + ./zebra: error while loading shared libraries: libfrr.so.0: cannot open + shared object file: No such file or directory + +The fix is to add the following line to /etc/ld.so.conf which will +continue to reference the library directory after the system reboots. To +load the library directory path immediately run the ldconfig command +after adding the line to the file eg: + +:: + + echo include /usr/local/lib >> /etc/ld.so.conf + ldconfig diff --git a/doc/developer/building-frr-for-freebsd14.rst b/doc/developer/building-frr-for-freebsd14.rst new file mode 100644 index 0000000000..3d1fcacf1b --- /dev/null +++ b/doc/developer/building-frr-for-freebsd14.rst @@ -0,0 +1,122 @@ +FreeBSD 14 +========== + +FreeBSD 14 restrictions: +------------------------ + +- MPLS is not supported on ``FreeBSD``. MPLS requires a Linux Kernel + (4.5 or higher). LDP can be built, but may have limited use without + MPLS +- PIM for IPv6 is not currently supported on ``FreeBSD``. + +Install required packages +------------------------- + +Add packages: (Allow the install of the package management tool if this +is first package install and asked) + +.. code-block:: shell + + pkg install autoconf automake bison c-ares git gmake json-c libtool \ + libunwind libyang2 pkgconf protobuf-c py39-pytest py39-sphinx texinfo + +.. include:: building-libunwind-note.rst + +Get FRR, compile it and install it (from Git) +--------------------------------------------- + +**This assumes you want to build and install FRR from source and not using any +packages** + +Add frr group and user +^^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: shell + + pw groupadd frr -g 101 + pw groupadd frrvty -g 102 + pw adduser frr -g 101 -u 101 -G 102 -c "FRR suite" \ + -d /usr/local/etc/frr -s /usr/sbin/nologin + + +Download Source, configure and compile it +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +(You may prefer different options on configure statement. These are just +an example) + +.. code-block:: shell + + git clone https://github.com/frrouting/frr.git frr + cd frr + ./bootstrap.sh + export MAKE=gmake LDFLAGS=-L/usr/local/lib CPPFLAGS=-I/usr/local/include + ./configure \ + --sysconfdir=/usr/local/etc/frr \ + --enable-pkgsrcrcdir=/usr/pkg/share/examples/rc.d \ + --localstatedir=/var/run/frr \ + --prefix=/usr/local \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + gmake + gmake check + sudo gmake install + +Create empty FRR configuration files +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: shell + + sudo mkdir /usr/local/etc/frr + +For integrated config file: + +.. code-block:: shell + + sudo touch /usr/local/etc/frr/frr.conf + +For individual config files: + +.. note:: Integrated config is preferred to individual config. + +.. code-block:: shell + + sudo touch /usr/local/etc/frr/babeld.conf + sudo touch /usr/local/etc/frr/bfdd.conf + sudo touch /usr/local/etc/frr/bgpd.conf + sudo touch /usr/local/etc/frr/eigrpd.conf + sudo touch /usr/local/etc/frr/isisd.conf + sudo touch /usr/local/etc/frr/ldpd.conf + sudo touch /usr/local/etc/frr/nhrpd.conf + sudo touch /usr/local/etc/frr/ospf6d.conf + sudo touch /usr/local/etc/frr/ospfd.conf + sudo touch /usr/local/etc/frr/pbrd.conf + sudo touch /usr/local/etc/frr/pimd.conf + sudo touch /usr/local/etc/frr/ripd.conf + sudo touch /usr/local/etc/frr/ripngd.conf + sudo touch /usr/local/etc/frr/staticd.conf + sudo touch /usr/local/etc/frr/zebra.conf + sudo chown -R frr:frr /usr/local/etc/frr/ + sudo touch /usr/local/etc/frr/vtysh.conf + sudo chown frr:frrvty /usr/local/etc/frr/vtysh.conf + sudo chmod 640 /usr/local/etc/frr/*.conf + +Enable IP & IPv6 forwarding +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Add the following lines to the end of ``/etc/sysctl.conf``: + +:: + + # Routing: We need to forward packets + net.inet.ip.forwarding=1 + net.inet6.ip6.forwarding=1 + +**Reboot** or use ``sysctl`` to apply the same config to the running system. diff --git a/doc/developer/building-frr-for-opensuse.rst b/doc/developer/building-frr-for-opensuse.rst index 3ff445bcd0..6e9913de48 100644 --- a/doc/developer/building-frr-for-opensuse.rst +++ b/doc/developer/building-frr-for-opensuse.rst @@ -13,11 +13,13 @@ Installing Dependencies zypper in git autoconf automake libtool make \ readline-devel texinfo net-snmp-devel groff pkgconfig libjson-c-devel\ pam-devel python3-pytest bison flex c-ares-devel python3-devel\ - python3-Sphinx perl patch libcap-devel libyang-devel \ + python3-Sphinx perl patch libcap-devel \ libelf-devel libunwind-devel protobuf-c .. include:: building-libunwind-note.rst +.. include:: building-libyang.rst + Building & Installing FRR ------------------------- diff --git a/doc/developer/building-frr-for-ubuntu1404.rst b/doc/developer/building-frr-for-ubuntu1404.rst index cc6c3c03f3..dd3f98a58e 100644 --- a/doc/developer/building-frr-for-ubuntu1404.rst +++ b/doc/developer/building-frr-for-ubuntu1404.rst @@ -14,16 +14,11 @@ Installing Dependencies git autoconf automake libtool make libreadline-dev texinfo \ pkg-config libpam0g-dev libjson-c-dev bison flex python3-pytest \ libc-ares-dev python3-dev python3-sphinx install-info build-essential \ + protobuf-c-compiler libprotobuf-c-dev \ libsnmp-dev perl libcap-dev libelf-dev .. include:: building-libyang.rst -Protobuf -^^^^^^^^ - -.. code-block:: console - - sudo apt-get install protobuf-c-compiler libprotobuf-c-dev Building & Installing FRR ------------------------- diff --git a/doc/developer/building-frr-for-ubuntu1604.rst b/doc/developer/building-frr-for-ubuntu1604.rst index e5c2389f39..f3b6aa0de9 100644 --- a/doc/developer/building-frr-for-ubuntu1604.rst +++ b/doc/developer/building-frr-for-ubuntu1604.rst @@ -19,12 +19,6 @@ Installing Dependencies .. include:: building-libyang.rst -Protobuf -^^^^^^^^ - -.. code-block:: console - - sudo apt-get install protobuf-c-compiler libprotobuf-c-dev Building & Installing FRR ------------------------- diff --git a/doc/developer/building-frr-for-ubuntu1804.rst b/doc/developer/building-frr-for-ubuntu1804.rst index fcfd94ec2c..b4880e26be 100644 --- a/doc/developer/building-frr-for-ubuntu1804.rst +++ b/doc/developer/building-frr-for-ubuntu1804.rst @@ -15,18 +15,13 @@ Installing Dependencies pkg-config libpam0g-dev libjson-c-dev bison flex \ libc-ares-dev python3-dev python3-sphinx \ install-info build-essential libsnmp-dev perl libcap-dev \ + protobuf-c-compiler libprotobuf-c-dev \ libelf-dev libunwind-dev .. include:: building-libunwind-note.rst .. include:: building-libyang.rst -Protobuf -^^^^^^^^ - -.. code-block:: console - - sudo apt-get install protobuf-c-compiler libprotobuf-c-dev ZeroMQ ^^^^^^ diff --git a/doc/developer/building-frr-for-ubuntu2004.rst b/doc/developer/building-frr-for-ubuntu2004.rst index fdfc25da9d..7c23469897 100644 --- a/doc/developer/building-frr-for-ubuntu2004.rst +++ b/doc/developer/building-frr-for-ubuntu2004.rst @@ -15,34 +15,33 @@ Installing Dependencies pkg-config libpam0g-dev libjson-c-dev bison flex \ libc-ares-dev python3-dev python3-sphinx \ install-info build-essential libsnmp-dev perl \ - libcap-dev python2 libelf-dev libunwind-dev + protobuf-c-compiler libprotobuf-c-dev \ + libcap-dev libelf-dev libunwind-dev .. include:: building-libunwind-note.rst -Note that Ubuntu 20 no longer installs python 2.x, so it must be -installed explicitly. Ensure that your system has a symlink named -``/usr/bin/python`` pointing at ``/usr/bin/python3``. +.. include:: building-libyang.rst -In addition, ``pip`` for python2 must be installed if you wish to run -the FRR topotests. That version of ``pip`` is not available from the -ubuntu apt repositories; in order to install it: +GRPC +^^^^ +If GRPC is enabled using ``--enable-grpc`` the following packages should be +installed. -.. code-block:: shell +.. code-block:: console - curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py - sudo python2 ./get-pip.py + sudo apt-get install libgrpc++-dev protobuf-compiler-grpc \ - # And verify the installation - pip2 --version -.. include:: building-libyang.rst +Config Rollbacks +^^^^^^^^^^^^^^^^ -Protobuf -^^^^^^^^ +If config rollbacks are enabled using ``--enable-config-rollbacks`` +the sqlite3 developer package also should be installed. .. code-block:: console - sudo apt-get install protobuf-c-compiler libprotobuf-c-dev + sudo apt install libsqlite3-dev + ZeroMQ ^^^^^^ diff --git a/doc/developer/building-frr-for-ubuntu2204.rst b/doc/developer/building-frr-for-ubuntu2204.rst index 6b941b3679..3ea625716d 100644 --- a/doc/developer/building-frr-for-ubuntu2204.rst +++ b/doc/developer/building-frr-for-ubuntu2204.rst @@ -15,40 +15,33 @@ Installing Dependencies pkg-config libpam0g-dev libjson-c-dev bison flex \ libc-ares-dev python3-dev python3-sphinx \ install-info build-essential libsnmp-dev perl \ - libcap-dev python2 libelf-dev libunwind-dev \ - libyang2 libyang2-dev + libcap-dev libelf-dev libunwind-dev \ + protobuf-c-compiler libprotobuf-c-dev .. include:: building-libunwind-note.rst -Note that Ubuntu >= 20 no longer installs python 2.x, so it must be -installed explicitly. Ensure that your system has a symlink named -``/usr/bin/python`` pointing at ``/usr/bin/python3``. +.. include:: building-libyang.rst -.. code-block:: shell - - sudo ln -s /usr/bin/python3 /usr/bin/python - python --version +GRPC +^^^^ +If GRPC is enabled using ``--enable-grpc`` the following packages should be +installed. -In addition, ``pip`` for python2 must be installed if you wish to run -the FRR topotests. That version of ``pip`` is not available from the -ubuntu apt repositories; in order to install it: - -.. code-block:: shell +.. code-block:: console - curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py - sudo python2 ./get-pip.py + sudo apt-get install libgrpc++-dev protobuf-compiler-grpc \ - # And verify the installation - pip2 --version +Config Rollbacks +^^^^^^^^^^^^^^^^ -Protobuf -^^^^^^^^ -This is optional +If config rollbacks are enabled using ``--enable-config-rollbacks`` +the sqlite3 developer package also should be installed. .. code-block:: console - sudo apt-get install protobuf-c-compiler libprotobuf-c-dev + sudo apt install libsqlite3-dev + ZeroMQ ^^^^^^ diff --git a/doc/developer/building-libyang.rst b/doc/developer/building-libyang.rst index c36cd34287..a46c79376c 100644 --- a/doc/developer/building-libyang.rst +++ b/doc/developer/building-libyang.rst @@ -10,11 +10,11 @@ The FRR project builds some binary ``libyang`` packages. RPM packages are at our `RPM repository `_. DEB packages are available as CI artifacts `here -`_. +`_. .. warning:: - ``libyang`` version 2.0.0 or newer is required to build FRR. + ``libyang`` version 2.1.128 or newer is required to build FRR. .. note:: @@ -39,7 +39,7 @@ DEB packages are available as CI artifacts `here git clone https://github.com/CESNET/libyang.git cd libyang - git checkout v2.0.0 + git checkout v2.1.128 mkdir build; cd build cmake -D CMAKE_INSTALL_PREFIX:PATH=/usr \ -D CMAKE_BUILD_TYPE:String="Release" .. diff --git a/doc/developer/building.rst b/doc/developer/building.rst index 2d8cc209b0..6762604f32 100644 --- a/doc/developer/building.rst +++ b/doc/developer/building.rst @@ -9,25 +9,28 @@ Building FRR static-linking building-frr-for-alpine + building-frr-for-archlinux building-frr-for-centos6 building-frr-for-centos7 building-frr-for-centos8 building-frr-for-debian8 building-frr-for-debian9 + building-frr-for-debian12 building-frr-for-fedora - building-frr-for-opensuse building-frr-for-freebsd9 building-frr-for-freebsd10 building-frr-for-freebsd11 building-frr-for-freebsd13 + building-frr-for-freebsd14 building-frr-for-netbsd6 building-frr-for-netbsd7 building-frr-for-openbsd6 + building-frr-for-opensuse building-frr-for-openwrt building-frr-for-ubuntu1404 building-frr-for-ubuntu1604 building-frr-for-ubuntu1804 building-frr-for-ubuntu2004 - building-frr-for-archlinux + building-frr-for-ubuntu2204 building-docker cross-compiling diff --git a/doc/developer/checkpatch.rst b/doc/developer/checkpatch.rst new file mode 100644 index 0000000000..d8fe007c31 --- /dev/null +++ b/doc/developer/checkpatch.rst @@ -0,0 +1,1251 @@ +.. SPDX-License-Identifier: GPL-2.0-only + +.. _checkpatch: + +========== +Checkpatch +========== + +Checkpatch (scripts/checkpatch.pl) is a perl script which checks for trivial +style violations in patches and optionally corrects them. Checkpatch can +also be run on file contexts and without the kernel tree. + +Checkpatch is not always right. Your judgement takes precedence over checkpatch +messages. If your code looks better with the violations, then its probably +best left alone. + + +Options +======= + +This section will describe the options checkpatch can be run with. + +Usage:: + + ./scripts/checkpatch.pl [OPTION]... [FILE]... + +Available options: + + - -q, --quiet + + Enable quiet mode. + + - -v, --verbose + Enable verbose mode. Additional verbose test descriptions are output + so as to provide information on why that particular message is shown. + + - --no-tree + + Run checkpatch without the kernel tree. + + - --no-signoff + + Disable the 'Signed-off-by' line check. The sign-off is a simple line at + the end of the explanation for the patch, which certifies that you wrote it + or otherwise have the right to pass it on as an open-source patch. + + Example:: + + Signed-off-by: Random J Developer + + Setting this flag effectively stops a message for a missing signed-off-by + line in a patch context. + + - --patch + + Treat FILE as a patch. This is the default option and need not be + explicitly specified. + + - --emacs + + Set output to emacs compile window format. This allows emacs users to jump + from the error in the compile window directly to the offending line in the + patch. + + - --terse + + Output only one line per report. + + - --showfile + + Show the diffed file position instead of the input file position. + + - -g, --git + + Treat FILE as a single commit or a git revision range. + + Single commit with: + + - + - ^ + - ~n + + Multiple commits with: + + - .. + - ... + - - + + - -f, --file + + Treat FILE as a regular source file. This option must be used when running + checkpatch on source files in the kernel. + + - --subjective, --strict + + Enable stricter tests in checkpatch. By default the tests emitted as CHECK + do not activate by default. Use this flag to activate the CHECK tests. + + - --list-types + + Every message emitted by checkpatch has an associated TYPE. Add this flag + to display all the types in checkpatch. + + Note that when this flag is active, checkpatch does not read the input FILE, + and no message is emitted. Only a list of types in checkpatch is output. + + - --types TYPE(,TYPE2...) + + Only display messages with the given types. + + Example:: + + ./scripts/checkpatch.pl mypatch.patch --types EMAIL_SUBJECT,BRACES + + - --ignore TYPE(,TYPE2...) + + Checkpatch will not emit messages for the specified types. + + Example:: + + ./scripts/checkpatch.pl mypatch.patch --ignore EMAIL_SUBJECT,BRACES + + - --show-types + + By default checkpatch doesn't display the type associated with the messages. + Set this flag to show the message type in the output. + + - --max-line-length=n + + Set the max line length (default 100). If a line exceeds the specified + length, a LONG_LINE message is emitted. + + + The message level is different for patch and file contexts. For patches, + a WARNING is emitted. While a milder CHECK is emitted for files. So for + file contexts, the --strict flag must also be enabled. + + - --min-conf-desc-length=n + + Set the Kconfig entry minimum description length, if shorter, warn. + + - --tab-size=n + + Set the number of spaces for tab (default 8). + + - --root=PATH + + PATH to the kernel tree root. + + This option must be specified when invoking checkpatch from outside + the kernel root. + + - --no-summary + + Suppress the per file summary. + + - --mailback + + Only produce a report in case of Warnings or Errors. Milder Checks are + excluded from this. + + - --summary-file + + Include the filename in summary. + + - --debug KEY=[0|1] + + Turn on/off debugging of KEY, where KEY is one of 'values', 'possible', + 'type', and 'attr' (default is all off). + + - --fix + + This is an EXPERIMENTAL feature. If correctable errors exists, a file + .EXPERIMENTAL-checkpatch-fixes is created which has the + automatically fixable errors corrected. + + - --fix-inplace + + EXPERIMENTAL - Similar to --fix but input file is overwritten with fixes. + + DO NOT USE this flag unless you are absolutely sure and you have a backup + in place. + + - --ignore-perl-version + + Override checking of perl version. Runtime errors maybe encountered after + enabling this flag if the perl version does not meet the minimum specified. + + - --codespell + + Use the codespell dictionary for checking spelling errors. + + - --codespellfile + + Use the specified codespell file. + Default is '/usr/share/codespell/dictionary.txt'. + + - --typedefsfile + + Read additional types from this file. + + - --color[=WHEN] + + Use colors 'always', 'never', or only when output is a terminal ('auto'). + Default is 'auto'. + + - --kconfig-prefix=WORD + + Use WORD as a prefix for Kconfig symbols (default is `CONFIG_`). + + - -h, --help, --version + + Display the help text. + +Message Levels +============== + +Messages in checkpatch are divided into three levels. The levels of messages +in checkpatch denote the severity of the error. They are: + + - ERROR + + This is the most strict level. Messages of type ERROR must be taken + seriously as they denote things that are very likely to be wrong. + + - WARNING + + This is the next stricter level. Messages of type WARNING requires a + more careful review. But it is milder than an ERROR. + + - CHECK + + This is the mildest level. These are things which may require some thought. + +Type Descriptions +================= + +This section contains a description of all the message types in checkpatch. + +.. Types in this section are also parsed by checkpatch. +.. The types are grouped into subsections based on use. + + +Allocation style +---------------- + + **ALLOC_ARRAY_ARGS** + The first argument for kcalloc or kmalloc_array should be the + number of elements. sizeof() as the first argument is generally + wrong. + + See: https://www.kernel.org/doc/html/latest/core-api/memory-allocation.html + + **ALLOC_SIZEOF_STRUCT** + The allocation style is bad. In general for family of + allocation functions using sizeof() to get memory size, + constructs like:: + + p = alloc(sizeof(struct foo), ...) + + should be:: + + p = alloc(sizeof(*p), ...) + + See: https://www.kernel.org/doc/html/latest/process/coding-style.html#allocating-memory + + **ALLOC_WITH_MULTIPLY** + Prefer kmalloc_array/kcalloc over kmalloc/kzalloc with a + sizeof multiply. + + See: https://www.kernel.org/doc/html/latest/core-api/memory-allocation.html + + +API usage +--------- + + **ARCH_DEFINES** + Architecture specific defines should be avoided wherever + possible. + + **ARCH_INCLUDE_LINUX** + Whenever asm/file.h is included and linux/file.h exists, a + conversion can be made when linux/file.h includes asm/file.h. + However this is not always the case (See signal.h). + This message type is emitted only for includes from arch/. + + **AVOID_BUG** + BUG() or BUG_ON() should be avoided totally. + Use WARN() and WARN_ON() instead, and handle the "impossible" + error condition as gracefully as possible. + + See: https://www.kernel.org/doc/html/latest/process/deprecated.html#bug-and-bug-on + + **CONSIDER_KSTRTO** + The simple_strtol(), simple_strtoll(), simple_strtoul(), and + simple_strtoull() functions explicitly ignore overflows, which + may lead to unexpected results in callers. The respective kstrtol(), + kstrtoll(), kstrtoul(), and kstrtoull() functions tend to be the + correct replacements. + + See: https://www.kernel.org/doc/html/latest/process/deprecated.html#simple-strtol-simple-strtoll-simple-strtoul-simple-strtoull + + **CONSTANT_CONVERSION** + Use of __constant_ form is discouraged for the following functions:: + + __constant_cpu_to_be[x] + __constant_cpu_to_le[x] + __constant_be[x]_to_cpu + __constant_le[x]_to_cpu + __constant_htons + __constant_ntohs + + Using any of these outside of include/uapi/ is not preferred as using the + function without __constant_ is identical when the argument is a + constant. + + In big endian systems, the macros like __constant_cpu_to_be32(x) and + cpu_to_be32(x) expand to the same expression:: + + #define __constant_cpu_to_be32(x) ((__force __be32)(__u32)(x)) + #define __cpu_to_be32(x) ((__force __be32)(__u32)(x)) + + In little endian systems, the macros __constant_cpu_to_be32(x) and + cpu_to_be32(x) expand to __constant_swab32 and __swab32. __swab32 + has a __builtin_constant_p check:: + + #define __swab32(x) \ + (__builtin_constant_p((__u32)(x)) ? \ + ___constant_swab32(x) : \ + __fswab32(x)) + + So ultimately they have a special case for constants. + Similar is the case with all of the macros in the list. Thus + using the __constant_... forms are unnecessarily verbose and + not preferred outside of include/uapi. + + See: https://lore.kernel.org/lkml/1400106425.12666.6.camel@joe-AO725/ + + **DEPRECATED_API** + Usage of a deprecated RCU API is detected. It is recommended to replace + old flavourful RCU APIs by their new vanilla-RCU counterparts. + + The full list of available RCU APIs can be viewed from the kernel docs. + + See: https://www.kernel.org/doc/html/latest/RCU/whatisRCU.html#full-list-of-rcu-apis + + **DEPRECATED_VARIABLE** + EXTRA_{A,C,CPP,LD}FLAGS are deprecated and should be replaced by the new + flags added via commit f77bf01425b1 ("kbuild: introduce ccflags-y, + asflags-y and ldflags-y"). + + The following conversion scheme maybe used:: + + EXTRA_AFLAGS -> asflags-y + EXTRA_CFLAGS -> ccflags-y + EXTRA_CPPFLAGS -> cppflags-y + EXTRA_LDFLAGS -> ldflags-y + + See: + + 1. https://lore.kernel.org/lkml/20070930191054.GA15876@uranus.ravnborg.org/ + 2. https://lore.kernel.org/lkml/1313384834-24433-12-git-send-email-lacombar@gmail.com/ + 3. https://www.kernel.org/doc/html/latest/kbuild/makefiles.html#compilation-flags + + **DEVICE_ATTR_FUNCTIONS** + The function names used in DEVICE_ATTR is unusual. + Typically, the store and show functions are used with _store and + _show, where is a named attribute variable of the device. + + Consider the following examples:: + + static DEVICE_ATTR(type, 0444, type_show, NULL); + static DEVICE_ATTR(power, 0644, power_show, power_store); + + The function names should preferably follow the above pattern. + + See: https://www.kernel.org/doc/html/latest/driver-api/driver-model/device.html#attributes + + **DEVICE_ATTR_RO** + The DEVICE_ATTR_RO(name) helper macro can be used instead of + DEVICE_ATTR(name, 0444, name_show, NULL); + + Note that the macro automatically appends _show to the named + attribute variable of the device for the show method. + + See: https://www.kernel.org/doc/html/latest/driver-api/driver-model/device.html#attributes + + **DEVICE_ATTR_RW** + The DEVICE_ATTR_RW(name) helper macro can be used instead of + DEVICE_ATTR(name, 0644, name_show, name_store); + + Note that the macro automatically appends _show and _store to the + named attribute variable of the device for the show and store methods. + + See: https://www.kernel.org/doc/html/latest/driver-api/driver-model/device.html#attributes + + **DEVICE_ATTR_WO** + The DEVICE_AATR_WO(name) helper macro can be used instead of + DEVICE_ATTR(name, 0200, NULL, name_store); + + Note that the macro automatically appends _store to the + named attribute variable of the device for the store method. + + See: https://www.kernel.org/doc/html/latest/driver-api/driver-model/device.html#attributes + + **DUPLICATED_SYSCTL_CONST** + Commit d91bff3011cf ("proc/sysctl: add shared variables for range + check") added some shared const variables to be used instead of a local + copy in each source file. + + Consider replacing the sysctl range checking value with the shared + one in include/linux/sysctl.h. The following conversion scheme may + be used:: + + &zero -> SYSCTL_ZERO + &one -> SYSCTL_ONE + &int_max -> SYSCTL_INT_MAX + + See: + + 1. https://lore.kernel.org/lkml/20190430180111.10688-1-mcroce@redhat.com/ + 2. https://lore.kernel.org/lkml/20190531131422.14970-1-mcroce@redhat.com/ + + **ENOSYS** + ENOSYS means that a nonexistent system call was called. + Earlier, it was wrongly used for things like invalid operations on + otherwise valid syscalls. This should be avoided in new code. + + See: https://lore.kernel.org/lkml/5eb299021dec23c1a48fa7d9f2c8b794e967766d.1408730669.git.luto@amacapital.net/ + + **ENOTSUPP** + ENOTSUPP is not a standard error code and should be avoided in new patches. + EOPNOTSUPP should be used instead. + + See: https://lore.kernel.org/netdev/20200510182252.GA411829@lunn.ch/ + + **EXPORT_SYMBOL** + EXPORT_SYMBOL should immediately follow the symbol to be exported. + + **IN_ATOMIC** + in_atomic() is not for driver use so any such use is reported as an ERROR. + Also in_atomic() is often used to determine if sleeping is permitted, + but it is not reliable in this use model. Therefore its use is + strongly discouraged. + + However, in_atomic() is ok for core kernel use. + + See: https://lore.kernel.org/lkml/20080320201723.b87b3732.akpm@linux-foundation.org/ + + **LOCKDEP** + The lockdep_no_validate class was added as a temporary measure to + prevent warnings on conversion of device->sem to device->mutex. + It should not be used for any other purpose. + + See: https://lore.kernel.org/lkml/1268959062.9440.467.camel@laptop/ + + **MALFORMED_INCLUDE** + The #include statement has a malformed path. This has happened + because the author has included a double slash "//" in the pathname + accidentally. + + **USE_LOCKDEP** + lockdep_assert_held() annotations should be preferred over + assertions based on spin_is_locked() + + See: https://www.kernel.org/doc/html/latest/locking/lockdep-design.html#annotations + + **UAPI_INCLUDE** + No #include statements in include/uapi should use a uapi/ path. + + **USLEEP_RANGE** + usleep_range() should be preferred over udelay(). The proper way of + using usleep_range() is mentioned in the kernel docs. + + See: https://www.kernel.org/doc/html/latest/timers/timers-howto.html#delays-information-on-the-various-kernel-delay-sleep-mechanisms + + +Comments +-------- + + **BLOCK_COMMENT_STYLE** + The comment style is incorrect. The preferred style for multi- + line comments is:: + + /* + * This is the preferred style + * for multi line comments. + */ + + The networking comment style is a bit different, with the first line + not empty like the former:: + + /* This is the preferred comment style + * for files in net/ and drivers/net/ + */ + + See: https://www.kernel.org/doc/html/latest/process/coding-style.html#commenting + + **C99_COMMENTS** + C99 style single line comments (//) should not be used. + Prefer the block comment style instead. + + See: https://www.kernel.org/doc/html/latest/process/coding-style.html#commenting + + **DATA_RACE** + Applications of data_race() should have a comment so as to document the + reasoning behind why it was deemed safe. + + See: https://lore.kernel.org/lkml/20200401101714.44781-1-elver@google.com/ + + **FSF_MAILING_ADDRESS** + Kernel maintainers reject new instances of the GPL boilerplate paragraph + directing people to write to the FSF for a copy of the GPL, since the + FSF has moved in the past and may do so again. + So do not write paragraphs about writing to the Free Software Foundation's + mailing address. + + See: https://lore.kernel.org/lkml/20131006222342.GT19510@leaf/ + + +Commit message +-------------- + + **BAD_SIGN_OFF** + The signed-off-by line does not fall in line with the standards + specified by the community. + + See: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#developer-s-certificate-of-origin-1-1 + + **BAD_STABLE_ADDRESS_STYLE** + The email format for stable is incorrect. + Some valid options for stable address are:: + + 1. stable@vger.kernel.org + 2. stable@kernel.org + + For adding version info, the following comment style should be used:: + + stable@vger.kernel.org # version info + + **COMMIT_COMMENT_SYMBOL** + Commit log lines starting with a '#' are ignored by git as + comments. To solve this problem addition of a single space + infront of the log line is enough. + + **COMMIT_MESSAGE** + The patch is missing a commit description. A brief + description of the changes made by the patch should be added. + + See: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes + + **EMAIL_SUBJECT** + Naming the tool that found the issue is not very useful in the + subject line. A good subject line summarizes the change that + the patch brings. + + See: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes + + **FROM_SIGN_OFF_MISMATCH** + The author's email does not match with that in the Signed-off-by: + line(s). This can be sometimes caused due to an improperly configured + email client. + + This message is emitted due to any of the following reasons:: + + - The email names do not match. + - The email addresses do not match. + - The email subaddresses do not match. + - The email comments do not match. + + **MISSING_SIGN_OFF** + The patch is missing a Signed-off-by line. A signed-off-by + line should be added according to Developer's certificate of + Origin. + + See: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin + + **NO_AUTHOR_SIGN_OFF** + The author of the patch has not signed off the patch. It is + required that a simple sign off line should be present at the + end of explanation of the patch to denote that the author has + written it or otherwise has the rights to pass it on as an open + source patch. + + See: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin + + **DIFF_IN_COMMIT_MSG** + Avoid having diff content in commit message. + This causes problems when one tries to apply a file containing both + the changelog and the diff because patch(1) tries to apply the diff + which it found in the changelog. + + See: https://lore.kernel.org/lkml/20150611134006.9df79a893e3636019ad2759e@linux-foundation.org/ + + **GERRIT_CHANGE_ID** + To be picked up by gerrit, the footer of the commit message might + have a Change-Id like:: + + Change-Id: Ic8aaa0728a43936cd4c6e1ed590e01ba8f0fbf5b + Signed-off-by: A. U. Thor + + The Change-Id line must be removed before submitting. + + **GIT_COMMIT_ID** + The proper way to reference a commit id is: + commit <12+ chars of sha1> ("") + + An example may be:: + + Commit e21d2170f36602ae2708 ("video: remove unnecessary + platform_set_drvdata()") removed the unnecessary + platform_set_drvdata(), but left the variable "dev" unused, + delete it. + + See: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes + + +Comparison style +---------------- + + **ASSIGN_IN_IF** + Do not use assignments in if condition. + Example:: + + if ((foo = bar(...)) < BAZ) { + + should be written as:: + + foo = bar(...); + if (foo < BAZ) { + + **BOOL_COMPARISON** + Comparisons of A to true and false are better written + as A and !A. + + See: https://lore.kernel.org/lkml/1365563834.27174.12.camel@joe-AO722/ + + **COMPARISON_TO_NULL** + Comparisons to NULL in the form (foo == NULL) or (foo != NULL) + are better written as (!foo) and (foo). + + **CONSTANT_COMPARISON** + Comparisons with a constant or upper case identifier on the left + side of the test should be avoided. + + +Indentation and Line Breaks +--------------------------- + + **CODE_INDENT** + Code indent should use tabs instead of spaces. + Outside of comments, documentation and Kconfig, + spaces are never used for indentation. + + See: https://www.kernel.org/doc/html/latest/process/coding-style.html#indentation + + **DEEP_INDENTATION** + Indentation with 6 or more tabs usually indicate overly indented + code. + + It is suggested to refactor excessive indentation of + if/else/for/do/while/switch statements. + + See: https://lore.kernel.org/lkml/1328311239.21255.24.camel@joe2Laptop/ + + **SWITCH_CASE_INDENT_LEVEL** + switch should be at the same indent as case. + Example:: + + switch (suffix) { + case 'G': + case 'g': + mem <<= 30; + break; + case 'M': + case 'm': + mem <<= 20; + break; + case 'K': + case 'k': + mem <<= 10; + fallthrough; + default: + break; + } + + See: https://www.kernel.org/doc/html/latest/process/coding-style.html#indentation + + **LONG_LINE** + The line has exceeded the specified maximum length. + To use a different maximum line length, the --max-line-length=n option + may be added while invoking checkpatch. + + Earlier, the default line length was 80 columns. Commit bdc48fa11e46 + ("checkpatch/coding-style: deprecate 80-column warning") increased the + limit to 100 columns. This is not a hard limit either and it's + preferable to stay within 80 columns whenever possible. + + See: https://www.kernel.org/doc/html/latest/process/coding-style.html#breaking-long-lines-and-strings + + **LONG_LINE_STRING** + A string starts before but extends beyond the maximum line length. + To use a different maximum line length, the --max-line-length=n option + may be added while invoking checkpatch. + + See: https://www.kernel.org/doc/html/latest/process/coding-style.html#breaking-long-lines-and-strings + + **LONG_LINE_COMMENT** + A comment starts before but extends beyond the maximum line length. + To use a different maximum line length, the --max-line-length=n option + may be added while invoking checkpatch. + + See: https://www.kernel.org/doc/html/latest/process/coding-style.html#breaking-long-lines-and-strings + + **SPLIT_STRING** + Quoted strings that appear as messages in userspace and can be + grepped, should not be split across multiple lines. + + See: https://lore.kernel.org/lkml/20120203052727.GA15035@leaf/ + + **MULTILINE_DEREFERENCE** + A single dereferencing identifier spanned on multiple lines like:: + + struct_identifier->member[index]. + member = <foo>; + + is generally hard to follow. It can easily lead to typos and so makes + the code vulnerable to bugs. + + If fixing the multiple line dereferencing leads to an 80 column + violation, then either rewrite the code in a more simple way or if the + starting part of the dereferencing identifier is the same and used at + multiple places then store it in a temporary variable, and use that + temporary variable only at all the places. For example, if there are + two dereferencing identifiers:: + + member1->member2->member3.foo1; + member1->member2->member3.foo2; + + then store the member1->member2->member3 part in a temporary variable. + It not only helps to avoid the 80 column violation but also reduces + the program size by removing the unnecessary dereferences. + + But if none of the above methods work then ignore the 80 column + violation because it is much easier to read a dereferencing identifier + on a single line. + + **TRAILING_STATEMENTS** + Trailing statements (for example after any conditional) should be + on the next line. + Statements, such as:: + + if (x == y) break; + + should be:: + + if (x == y) + break; + + +Macros, Attributes and Symbols +------------------------------ + + **ARRAY_SIZE** + The ARRAY_SIZE(foo) macro should be preferred over + sizeof(foo)/sizeof(foo[0]) for finding number of elements in an + array. + + The macro is defined in include/linux/kernel.h:: + + #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + + **AVOID_EXTERNS** + Function prototypes don't need to be declared extern in .h + files. It's assumed by the compiler and is unnecessary. + + **AVOID_L_PREFIX** + Local symbol names that are prefixed with `.L` should be avoided, + as this has special meaning for the assembler; a symbol entry will + not be emitted into the symbol table. This can prevent `objtool` + from generating correct unwind info. + + Symbols with STB_LOCAL binding may still be used, and `.L` prefixed + local symbol names are still generally usable within a function, + but `.L` prefixed local symbol names should not be used to denote + the beginning or end of code regions via + `SYM_CODE_START_LOCAL`/`SYM_CODE_END` + + **BIT_MACRO** + Defines like: 1 << <digit> could be BIT(digit). + The BIT() macro is defined via include/linux/bits.h:: + + #define BIT(nr) (1UL << (nr)) + + **CONST_READ_MOSTLY** + When a variable is tagged with the __read_mostly annotation, it is a + signal to the compiler that accesses to the variable will be mostly + reads and rarely(but NOT never) a write. + + const __read_mostly does not make any sense as const data is already + read-only. The __read_mostly annotation thus should be removed. + + **DATE_TIME** + It is generally desirable that building the same source code with + the same set of tools is reproducible, i.e. the output is always + exactly the same. + + The kernel does *not* use the ``__DATE__`` and ``__TIME__`` macros, + and enables warnings if they are used as they can lead to + non-deterministic builds. + + See: https://www.kernel.org/doc/html/latest/kbuild/reproducible-builds.html#timestamps + + **DEFINE_ARCH_HAS** + The ARCH_HAS_xyz and ARCH_HAVE_xyz patterns are wrong. + + For big conceptual features use Kconfig symbols instead. And for + smaller things where we have compatibility fallback functions but + want architectures able to override them with optimized ones, we + should either use weak functions (appropriate for some cases), or + the symbol that protects them should be the same symbol we use. + + See: https://lore.kernel.org/lkml/CA+55aFycQ9XJvEOsiM3txHL5bjUc8CeKWJNR_H+MiicaddB42Q@mail.gmail.com/ + + **DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON** + do {} while(0) macros should not have a trailing semicolon. + + **INIT_ATTRIBUTE** + Const init definitions should use __initconst instead of + __initdata. + + Similarly init definitions without const require a separate + use of const. + + **INLINE_LOCATION** + The inline keyword should sit between storage class and type. + + For example, the following segment:: + + inline static int example_function(void) + { + ... + } + + should be:: + + static inline int example_function(void) + { + ... + } + + **MISPLACED_INIT** + It is possible to use section markers on variables in a way + which gcc doesn't understand (or at least not the way the + developer intended):: + + static struct __initdata samsung_pll_clock exynos4_plls[nr_plls] = { + + does not put exynos4_plls in the .initdata section. The __initdata + marker can be virtually anywhere on the line, except right after + "struct". The preferred location is before the "=" sign if there is + one, or before the trailing ";" otherwise. + + See: https://lore.kernel.org/lkml/1377655732.3619.19.camel@joe-AO722/ + + **MULTISTATEMENT_MACRO_USE_DO_WHILE** + Macros with multiple statements should be enclosed in a + do - while block. Same should also be the case for macros + starting with `if` to avoid logic defects:: + + #define macrofun(a, b, c) \ + do { \ + if (a == 5) \ + do_this(b, c); \ + } while (0) + + See: https://www.kernel.org/doc/html/latest/process/coding-style.html#macros-enums-and-rtl + + **PREFER_FALLTHROUGH** + Use the `fallthrough;` pseudo keyword instead of + `/* fallthrough */` like comments. + + **TRAILING_SEMICOLON** + Macro definition should not end with a semicolon. The macro + invocation style should be consistent with function calls. + This can prevent any unexpected code paths:: + + #define MAC do_something; + + If this macro is used within a if else statement, like:: + + if (some_condition) + MAC; + + else + do_something; + + Then there would be a compilation error, because when the macro is + expanded there are two trailing semicolons, so the else branch gets + orphaned. + + See: https://lore.kernel.org/lkml/1399671106.2912.21.camel@joe-AO725/ + + **SINGLE_STATEMENT_DO_WHILE_MACRO** + For the multi-statement macros, it is necessary to use the do-while + loop to avoid unpredictable code paths. The do-while loop helps to + group the multiple statements into a single one so that a + function-like macro can be used as a function only. + + But for the single statement macros, it is unnecessary to use the + do-while loop. Although the code is syntactically correct but using + the do-while loop is redundant. So remove the do-while loop for single + statement macros. + + **WEAK_DECLARATION** + Using weak declarations like __attribute__((weak)) or __weak + can have unintended link defects. Avoid using them. + + +Functions and Variables +----------------------- + + **CAMELCASE** + Avoid CamelCase Identifiers. + + See: https://www.kernel.org/doc/html/latest/process/coding-style.html#naming + + **CONST_CONST** + Using `const <type> const *` is generally meant to be + written `const <type> * const`. + + **CONST_STRUCT** + Using const is generally a good idea. Checkpatch reads + a list of frequently used structs that are always or + almost always constant. + + The existing structs list can be viewed from + `scripts/const_structs.checkpatch`. + + See: https://lore.kernel.org/lkml/alpine.DEB.2.10.1608281509480.3321@hadrien/ + + **EMBEDDED_FUNCTION_NAME** + Embedded function names are less appropriate to use as + refactoring can cause function renaming. Prefer the use of + "%s", __func__ to embedded function names. + + Note that this does not work with -f (--file) checkpatch option + as it depends on patch context providing the function name. + + **FUNCTION_ARGUMENTS** + This warning is emitted due to any of the following reasons: + + 1. Arguments for the function declaration do not follow + the identifier name. Example:: + + void foo + (int bar, int baz) + + This should be corrected to:: + + void foo(int bar, int baz) + + 2. Some arguments for the function definition do not + have an identifier name. Example:: + + void foo(int) + + All arguments should have identifier names. + + **FUNCTION_WITHOUT_ARGS** + Function declarations without arguments like:: + + int foo() + + should be:: + + int foo(void) + + **GLOBAL_INITIALISERS** + Global variables should not be initialized explicitly to + 0 (or NULL, false, etc.). Your compiler (or rather your + loader, which is responsible for zeroing out the relevant + sections) automatically does it for you. + + **INITIALISED_STATIC** + Static variables should not be initialized explicitly to zero. + Your compiler (or rather your loader) automatically does + it for you. + + **MULTIPLE_ASSIGNMENTS** + Multiple assignments on a single line makes the code unnecessarily + complicated. So on a single line assign value to a single variable + only, this makes the code more readable and helps avoid typos. + + **RETURN_PARENTHESES** + return is not a function and as such doesn't need parentheses:: + + return (bar); + + can simply be:: + + return bar; + + +Permissions +----------- + + **DEVICE_ATTR_PERMS** + The permissions used in DEVICE_ATTR are unusual. + Typically only three permissions are used - 0644 (RW), 0444 (RO) + and 0200 (WO). + + See: https://www.kernel.org/doc/html/latest/filesystems/sysfs.html#attributes + + **EXECUTE_PERMISSIONS** + There is no reason for source files to be executable. The executable + bit can be removed safely. + + **EXPORTED_WORLD_WRITABLE** + Exporting world writable sysfs/debugfs files is usually a bad thing. + When done arbitrarily they can introduce serious security bugs. + In the past, some of the debugfs vulnerabilities would seemingly allow + any local user to write arbitrary values into device registers - a + situation from which little good can be expected to emerge. + + See: https://lore.kernel.org/linux-arm-kernel/cover.1296818921.git.segoon@openwall.com/ + + **NON_OCTAL_PERMISSIONS** + Permission bits should use 4 digit octal permissions (like 0700 or 0444). + Avoid using any other base like decimal. + + **SYMBOLIC_PERMS** + Permission bits in the octal form are more readable and easier to + understand than their symbolic counterparts because many command-line + tools use this notation. Experienced kernel developers have been using + these traditional Unix permission bits for decades and so they find it + easier to understand the octal notation than the symbolic macros. + For example, it is harder to read S_IWUSR|S_IRUGO than 0644, which + obscures the developer's intent rather than clarifying it. + + See: https://lore.kernel.org/lkml/CA+55aFw5v23T-zvDZp-MmD_EYxF8WbafwwB59934FV7g21uMGQ@mail.gmail.com/ + + +Spacing and Brackets +-------------------- + + **ASSIGNMENT_CONTINUATIONS** + Assignment operators should not be written at the start of a + line but should follow the operand at the previous line. + + **BRACES** + The placement of braces is stylistically incorrect. + The preferred way is to put the opening brace last on the line, + and put the closing brace first:: + + if (x is true) { + we do y + } + + This applies for all non-functional blocks. + However, there is one special case, namely functions: they have the + opening brace at the beginning of the next line, thus:: + + int function(int x) + { + body of function + } + + See: https://www.kernel.org/doc/html/latest/process/coding-style.html#placing-braces-and-spaces + + **BRACKET_SPACE** + Whitespace before opening bracket '[' is prohibited. + There are some exceptions: + + 1. With a type on the left:: + + int [] a; + + 2. At the beginning of a line for slice initialisers:: + + [0...10] = 5, + + 3. Inside a curly brace:: + + = { [0...10] = 5 } + + **CONCATENATED_STRING** + Concatenated elements should have a space in between. + Example:: + + printk(KERN_INFO"bar"); + + should be:: + + printk(KERN_INFO "bar"); + + **ELSE_AFTER_BRACE** + `else {` should follow the closing block `}` on the same line. + + See: https://www.kernel.org/doc/html/latest/process/coding-style.html#placing-braces-and-spaces + + **LINE_SPACING** + Vertical space is wasted given the limited number of lines an + editor window can display when multiple blank lines are used. + + See: https://www.kernel.org/doc/html/latest/process/coding-style.html#spaces + + **OPEN_BRACE** + The opening brace should be following the function definitions on the + next line. For any non-functional block it should be on the same line + as the last construct. + + See: https://www.kernel.org/doc/html/latest/process/coding-style.html#placing-braces-and-spaces + + **POINTER_LOCATION** + When using pointer data or a function that returns a pointer type, + the preferred use of * is adjacent to the data name or function name + and not adjacent to the type name. + Examples:: + + char *linux_banner; + unsigned long long memparse(char *ptr, char **retptr); + char *match_strdup(substring_t *s); + + See: https://www.kernel.org/doc/html/latest/process/coding-style.html#spaces + + **SPACING** + Whitespace style used in the kernel sources is described in kernel docs. + + See: https://www.kernel.org/doc/html/latest/process/coding-style.html#spaces + + **TRAILING_WHITESPACE** + Trailing whitespace should always be removed. + Some editors highlight the trailing whitespace and cause visual + distractions when editing files. + + See: https://www.kernel.org/doc/html/latest/process/coding-style.html#spaces + + **UNNECESSARY_PARENTHESES** + Parentheses are not required in the following cases: + + 1. Function pointer uses:: + + (foo->bar)(); + + could be:: + + foo->bar(); + + 2. Comparisons in if:: + + if ((foo->bar) && (foo->baz)) + if ((foo == bar)) + + could be:: + + if (foo->bar && foo->baz) + if (foo == bar) + + 3. addressof/dereference single Lvalues:: + + &(foo->bar) + *(foo->bar) + + could be:: + + &foo->bar + *foo->bar + + **WHILE_AFTER_BRACE** + while should follow the closing bracket on the same line:: + + do { + ... + } while(something); + + See: https://www.kernel.org/doc/html/latest/process/coding-style.html#placing-braces-and-spaces + + +Others +------ + + **CONFIG_DESCRIPTION** + Kconfig symbols should have a help text which fully describes + it. + + **CORRUPTED_PATCH** + The patch seems to be corrupted or lines are wrapped. + Please regenerate the patch file before sending it to the maintainer. + + **CVS_KEYWORD** + Since linux moved to git, the CVS markers are no longer used. + So, CVS style keywords ($Id$, $Revision$, $Log$) should not be + added. + + **DEFAULT_NO_BREAK** + switch default case is sometimes written as "default:;". This can + cause new cases added below default to be defective. + + A "break;" should be added after empty default statement to avoid + unwanted fallthrough. + + **DOS_LINE_ENDINGS** + For DOS-formatted patches, there are extra ^M symbols at the end of + the line. These should be removed. + + **DT_SCHEMA_BINDING_PATCH** + DT bindings moved to a json-schema based format instead of + freeform text. + + See: https://www.kernel.org/doc/html/latest/devicetree/bindings/writing-schema.html + + **DT_SPLIT_BINDING_PATCH** + Devicetree bindings should be their own patch. This is because + bindings are logically independent from a driver implementation, + they have a different maintainer (even though they often + are applied via the same tree), and it makes for a cleaner history in the + DT only tree created with git-filter-branch. + + See: https://www.kernel.org/doc/html/latest/devicetree/bindings/submitting-patches.html#i-for-patch-submitters + + **EMBEDDED_FILENAME** + Embedding the complete filename path inside the file isn't particularly + useful as often the path is moved around and becomes incorrect. + + **FILE_PATH_CHANGES** + Whenever files are added, moved, or deleted, the MAINTAINERS file + patterns can be out of sync or outdated. + + So MAINTAINERS might need updating in these cases. + + **MEMSET** + The memset use appears to be incorrect. This may be caused due to + badly ordered parameters. Please recheck the usage. + + **NOT_UNIFIED_DIFF** + The patch file does not appear to be in unified-diff format. Please + regenerate the patch file before sending it to the maintainer. + + **PRINTF_0XDECIMAL** + Prefixing 0x with decimal output is defective and should be corrected. + + **SPDX_LICENSE_TAG** + The source file is missing or has an improper SPDX identifier tag. + The Linux kernel requires the precise SPDX identifier in all source files, + and it is thoroughly documented in the kernel docs. + + See: https://www.kernel.org/doc/html/latest/process/license-rules.html + + **TYPO_SPELLING** + Some words may have been misspelled. Consider reviewing them. diff --git a/doc/developer/cli.rst b/doc/developer/cli.rst index 61b9cf6acb..59073b39ab 100644 --- a/doc/developer/cli.rst +++ b/doc/developer/cli.rst @@ -639,13 +639,14 @@ in order into ``*argv[]``. Before this happens the ``->arg`` field is set to point at the snippet of user input that matched it. For most nontrivial commands the handler function will need to determine which -of the possible matching inputs was entered. Previously this was done by looking -at the first few characters of input. This is now considered an anti-pattern and -should be avoided. Instead, the ``->type`` or ``->text`` fields for this logic. -The ``->type`` field can be used when the possible inputs differ in type. When -the possible types are the same, use the ``->text`` field. This field has the -full text of the corresponding token in the definition string and using it makes -for much more readable code. An example is helpful. +of the possible matching inputs was entered. Previously this was done by +looking at the first few characters of input. This is now considered an +anti-pattern and should be avoided. Instead, use the ``->type`` or ``->text`` +fields for this logic. The ``->type`` field can be used when the possible +inputs differ in type. When the possible types are the same, use the ``->text`` +field. This field has the full text of the corresponding token in the +definition string and using it makes for much more readable code. An example is +helpful. Command definition: @@ -654,9 +655,10 @@ Command definition: command <(1-10)|foo|BAR> In this example, the user may enter any one of: -- an integer between 1 and 10 -- "foo" -- anything at all + +* an integer between 1 and 10 +* "foo" +* anything at all If the user enters "command f", then: @@ -793,12 +795,12 @@ Adding a CLI Node To add a new CLI node, you should: -- define a new numerical node constant -- define a node structure in the relevant daemon -- call ``install_node()`` in the relevant daemon -- define and install the new node in vtysh -- define corresponding node entry commands in daemon and vtysh -- add a new entry to the ``ctx_keywords`` dictionary in ``tools/frr-reload.py`` +#. define a new numerical node constant +#. define a node structure in the relevant daemon +#. call ``install_node()`` in the relevant daemon +#. define and install the new node in vtysh +#. define corresponding node entry commands in daemon and vtysh +#. add a new entry to the ``ctx_keywords`` dictionary in ``tools/frr-reload.py`` Defining the numerical node constant ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/doc/developer/cspf.rst b/doc/developer/cspf.rst index 426553ff06..7a5a55ee31 100644 --- a/doc/developer/cspf.rst +++ b/doc/developer/cspf.rst @@ -24,59 +24,59 @@ to the cost of the cuurent path from the source up to the current node. The algorithm is as followed: -``` - cost = MAX_COST; - Priority_Queue.empty(); - Visited_Node.empty(); - Processed_Path.empty(); - src = new_path(source_address); - src.cost = 0; - dst = new_destinatio(destination_address); - dst.cost = MAX_COST; - Processed_Path.add(src); - Processed_Path.add(dst); - while (Priority_Queue.count != 0) { - current_path = Priority_Queue.pop(); - current_node = next_path.destination; - Visited_Node.add(current_node); - for (current_node.edges: edge) { - if (prune_edge(current_path, edge) - continue; - if (relax(current_path) && cost > current_path.cost) { - optim_path = current_path; - cost = current_path.cost; - } - } - } - - prune_edge(path, edge) { - // check that path + edge meet constraints e.g. - if (current_path.cost + edge.cost > constrained_cost) - return false; - else - return true; - } - - relax_edge(current_path, edge) { - next_node = edge.destination; - if (Visited_Node.get(next_node)) - return false; - next_path = Processed_Path.get(edge.destination); - if (!next_path) { - next_path = new path(edge.destination); - Processed_Path.add(next_path); - } - total_cost = current_path.cost + edge.cost; - if (total_cost < next_path.cost) { - next_path = current_path; - next_path.add_edge(edge); - next_path.cost = total_cost; - Priority_Queue.add(next_path); - } - return (next_path.destination == destination); - } - -``` +.. code-block:: c + + cost = MAX_COST; + Priority_Queue.empty(); + Visited_Node.empty(); + Processed_Path.empty(); + src = new_path(source_address); + src.cost = 0; + dst = new_destinatio(destination_address); + dst.cost = MAX_COST; + Processed_Path.add(src); + Processed_Path.add(dst); + while (Priority_Queue.count != 0) { + current_path = Priority_Queue.pop(); + current_node = next_path.destination; + Visited_Node.add(current_node); + for (current_node.edges: edge) { + if (prune_edge(current_path, edge) + continue; + if (relax(current_path) && cost > current_path.cost) { + optim_path = current_path; + cost = current_path.cost; + } + } + } + + prune_edge(path, edge) { + // check that path + edge meet constraints e.g. + if (current_path.cost + edge.cost > constrained_cost) + return false; + else + return true; + } + + relax_edge(current_path, edge) { + next_node = edge.destination; + if (Visited_Node.get(next_node)) + return false; + next_path = Processed_Path.get(edge.destination); + if (!next_path) { + next_path = new path(edge.destination); + Processed_Path.add(next_path); + } + total_cost = current_path.cost + edge.cost; + if (total_cost < next_path.cost) { + next_path = current_path; + next_path.add_edge(edge); + next_path.cost = total_cost; + Priority_Queue.add(next_path); + } + return (next_path.destination == destination); + } + Definition ---------- @@ -162,34 +162,35 @@ various metrics. Link State provides such Traffic Engineering Database. To perform a Path Computation with given constraints, proceed as follow: .. code-block:: c - struct cspf *algo; - struct ls_ted *ted; - struct in_addr src; - struct in_addr dst; - struct constraints csts; - struct c_path *path; - - // Create a new CSPF structure - algo = cspf_new(); - - // Initialize constraints - csts.cost = 100; - csts.ctype = CSPF_TE_METRIC; - csts.family = AF_INET; - csts.type = SR_TE; - csts.bw = 1000000; - csts.cos = 3; - - // Then, initialise th CSPF with source, destination and constraints - cspf_init_v4(algo, ted, src, dst, &csts); - - // Finally, got the Computed Path; - path = compute_p2p_path(ted, algo); - - if (path.status == SUCCESS) - zlog_info("Got a valid constraints path"); - else - zlog_info("Unable to compute constraints path. Got %d status", path->status); + + struct cspf *algo; + struct ls_ted *ted; + struct in_addr src; + struct in_addr dst; + struct constraints csts; + struct c_path *path; + + // Create a new CSPF structure + algo = cspf_new(); + + // Initialize constraints + csts.cost = 100; + csts.ctype = CSPF_TE_METRIC; + csts.family = AF_INET; + csts.type = SR_TE; + csts.bw = 1000000; + csts.cos = 3; + + // Then, initialise th CSPF with source, destination and constraints + cspf_init_v4(algo, ted, src, dst, &csts); + + // Finally, got the Computed Path; + path = compute_p2p_path(ted, algo); + + if (path.status == SUCCESS) + zlog_info("Got a valid constraints path"); + else + zlog_info("Unable to compute constraints path. Got %d status", path->status); If you would compute another path, you must call `cspf_init()` prior to diff --git a/doc/developer/frr-release-procedure.rst b/doc/developer/frr-release-procedure.rst index 6088b52da4..9dbc9b48d7 100644 --- a/doc/developer/frr-release-procedure.rst +++ b/doc/developer/frr-release-procedure.rst @@ -13,6 +13,13 @@ Stage 1 - Preparation Note: use ``tools/release_notes.py`` to help draft release notes changelog + .. code-block:: console + + ./tools/release_notes.py -b dev/9.1 -t frr-9.0.1 + + dev/9.1 is the branch to be renamed to stable/9.1, and frr-9.0.1 in this + example is the latest tag from which to generate the logs. + #. Checkout the existing ``dev/<version>`` branch. .. code-block:: console @@ -152,11 +159,11 @@ Stage 2 - Staging 3. Suppose we are releasing 8.5.0, then ``X.Y.Z`` is ``8.5.0``. Run this: .. code-block:: console - + cd /home/builduser/frr TAG=X.Y.Z git fetch --all - git checkout frr-<version> + git checkout frr-$TAG docker buildx build --platform linux/amd64,linux/arm64,linux/ppc64le,linux/s390x,linux/arm/v7,linux/arm/v6 -f docker/alpine/Dockerfile -t quay.io/frrouting/frr:$TAG --push . git tag docker/$TAG git push origin docker/$TAG @@ -165,7 +172,7 @@ Stage 2 - Staging create a git tag corresponding to the commit that the image was built from and upload that to Github. It's important that the git tag point to the exact codebase that was used to build the docker image, so if any - changes need to be made on top of the ``frr-<version>`` release tag, make + changes need to be made on top of the ``frr-$TAG`` release tag, make sure these changes are committed and pointed at by the ``docker/X.Y.Z`` tag. diff --git a/doc/developer/index.rst b/doc/developer/index.rst index 46fd8f612e..bd794b11a8 100644 --- a/doc/developer/index.rst +++ b/doc/developer/index.rst @@ -5,6 +5,7 @@ FRRouting Developer's Guide :maxdepth: 2 workflow + checkpatch building packaging process-architecture @@ -12,6 +13,7 @@ FRRouting Developer's Guide fuzzing tracing testing + mgmtd-dev bgpd fpm grpc @@ -21,3 +23,4 @@ FRRouting Developer's Guide path pceplib link-state + northbound/northbound diff --git a/doc/developer/mgmtd-dev.rst b/doc/developer/mgmtd-dev.rst new file mode 100644 index 0000000000..92911bf650 --- /dev/null +++ b/doc/developer/mgmtd-dev.rst @@ -0,0 +1,228 @@ +.. +.. SPDX-License-Identifier: GPL-2.0-or-later +.. +.. June 19 2023, Christian Hopps <chopps@labn.net> +.. +.. Copyright (c) 2023, LabN Consulting, L.L.C. +.. + +.. _mgmtd_dev: + +MGMTD Development +================= + +Overview +^^^^^^^^ + +``mgmtd`` (Management Daemon) is a new centralized management daemon for FRR. + +Previously, ``vtysh`` was the only centralized management service provided. +Internally ``vtysh`` connects to each daemon and sends CLI commands (both +configuration and operational state queries) over a socket connection. This +service only supports CLI which is no longer sufficient. + +An important next step was made with the addition of YANG support. A YANG +infrastructure was added through a new development called *northbound*. This +*northbound* interface added the capability of daemons to be configured and +queried using YANG models. However, this interface was per daemon and not +centralized, which is not sufficient. + +``mgmtd`` harnesses this new *northbound* interface to provide a centralized +interface for all daemons. It utilizes the daemons YANG models to interact with +each daemon. ``mgmtd`` currently provides the CLI interface for each daemon that +has been converted to it, but in the future RESTCONF and NETCONF servers can +easily be added as *front-ends* to mgmtd to support those protocols as well. + + +Converting A Daemon to MGMTD +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +A daemon must first be transitioned to the new *northbound* interface if that +has not already been done (see `this northbound conversion documentation +<https://github.com/opensourcerouting/frr/wiki/Retrofitting-Configuration-Commands>`_ +for how to do this). Once this is done a few simple steps are all that is +required move the daemon over to ``mgmtd`` control. + +Overview of Changes +------------------- + +Adding support for a *northbound* converted daemon involves very little work. It +requires enabling *frontend* (CLI and YANG) and *backend* (YANG) support. +``mgmtd`` was designed to keep this as simple as possible. + +Front-End Interface: + +1. Add YANG module file to ``mgmtd/subdir.am`` (e.g., ``yang/frr-staticd.c``) +2. Add YANG module description into array defined in ``mgmtd/mgmt_main.c`` +3. Add CLI handler file[s] to ``mgmtd/subdir.am`` (e.g., ``staticd/static_vty.c``) +4. [if needed] Exclude (#ifndef) non-configuration CLI handlers from CLI source + file (e.g., inside ``staticd/static_vty.c``) + +Back-End Interface: + +5. Add XPATHs mappings to a couple arrays to direct ``mgmtd`` at your daemon in + ``mgmtd/mgmt_be_adapter.c`` + + +Add YANG and CLI into MGMTD +--------------------------- + +As an example here is the addition made to ``mgmtd/subdir.am`` for adding +``staticd`` support. + +.. code-block:: make + + if STATICD + nodist_mgmtd_mgmtd_SOURCES += \ + yang/frr-staticd.yang.c \ + yang/frr-bfdd.yang.c \ + # end + nodist_mgmtd_libmgmt_be_nb_la_SOURCES += staticd/static_vty.c + endif + +An here is the addition to the modules array in ``mgmtd/mgmt_main.c``: + +.. code-block:: c + + static const struct frr_yang_module_info *const mgmt_yang_modules[] = { + &frr_filter_info, + ... + #ifdef HAVE_STATICD + &(struct frr_yang_module_info){.name = "frr-staticd", + .ignore_cfg_cbs = true}, + #endif + } + + +CLI Handlers +------------ + +The daemon's CLI handlers for configuration (which having been converted to +*northbound* now simply generate YANG changes) will be linked directly into +``mgmtd``. + +If the operational and debug CLI commands are kept in files separate from the +daemon's configuration CLI commands then no extra work is required. Otherwise some +CPP #ifndef's will be required. + +Currently ``mgmtd`` supports configuration CLI but not operational +state so if both types of CLI handlers are present in a single file (e.g. a +``xxx_vty.c`` or ``xxx_cli.c`` file ) then #ifndef will be used to exclude these +non-configuration CLI handlers from ``mgmtd``. The same goes for *debug* CLI +handlers. For example: + +.. code-block:: c + + DEFPY(daemon_one_config, daemon_one_config_cmd, + "daemon one [optional-arg]" + ... + { + ... + } + + #ifndef INCLUDE_MGMTD_CMDDEFS_ONLY + DEFPY(daemon_show_oepr, daemon_show_oepr_cmd, + "show daemon oper [all]" + ... + { + ... + } + #endif /* ifndef INCLUDE_MGMTD_CMDDEFS_ONLY */ + + void daemon_vty_init(void) + { + install_element(CONFIG_NODE, &daemon_one_config_cmd); + ... + + #ifndef INCLUDE_MGMTD_CMDDEFS_ONLY + install_element(ENABLE_NODE, &daemon_show_oper_cmd); + #endif /* ifndef INCLUDE_MGMTD_CMDDEFS_ONLY */ + + } + + +Add Back-End XPATH mappings +--------------------------- + +In order for ``mgmtd`` to direct configuration to your daemon you need to add +some XPATH mappings to ``mgmtd/mgmt_be_adapter.c``. These XPATHs determine which +configuration changes get sent over the *back-end* interface to your daemon. + +Below are the strings added for staticd support: + +.. code-block:: c + + static const struct mgmt_be_xpath_map_init mgmt_xpath_map_init[] = { + { + .xpath_regexp = "/frr-vrf:lib/*", + .subscr_info = + { + #if HAVE_STATICD + [MGMTD_BE_CLIENT_ID_STATICD] = + MGMT_SUBSCR_VALIDATE_CFG | + MGMT_SUBSCR_NOTIFY_CFG, + #endif + }, + }, + ... + { + .xpath_regexp = + "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/*", + .subscr_info = + { + #if HAVE_STATICD + [MGMTD_BE_CLIENT_ID_STATICD] = + MGMT_SUBSCR_VALIDATE_CFG | + MGMT_SUBSCR_NOTIFY_CFG, + #endif + }, + }, + }; + + #if HAVE_STATICD + static struct mgmt_be_client_xpath staticd_xpaths[] = { + { + .xpath = "/frr-vrf:lib/*", + .subscribed = MGMT_SUBSCR_VALIDATE_CFG | MGMT_SUBSCR_NOTIFY_CFG, + }, + ... + { + .xpath = + "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/*", + .subscribed = MGMT_SUBSCR_VALIDATE_CFG | MGMT_SUBSCR_NOTIFY_CFG, + }, + }; + #endif + + static struct mgmt_be_client_xpath_map + mgmt_client_xpaths[MGMTD_BE_CLIENT_ID_MAX] = { + #ifdef HAVE_STATICD + [MGMTD_BE_CLIENT_ID_STATICD] = {staticd_xpaths, + array_size(staticd_xpaths)}, + #endif + }; + + +MGMTD Internals +^^^^^^^^^^^^^^^ + +This section will describe the internal functioning of ``mgmtd``, for now a +couple diagrams are included to aide in source code perusal. + + +The client side of a CLI configuration change + +.. figure:: ../figures/cli-change-client.svg + :align: center + + +The server (mgmtd) side of a CLI configuration change + +.. figure:: ../figures/cli-change-mgmtd.svg + :align: center + + +The client and server sides of oper-state query + +.. figure:: ../figures/cli-oper-state.svg + :align: center diff --git a/doc/developer/northbound/advanced-topics.rst b/doc/developer/northbound/advanced-topics.rst new file mode 100644 index 0000000000..bee29a95a9 --- /dev/null +++ b/doc/developer/northbound/advanced-topics.rst @@ -0,0 +1,294 @@ +Auto-generated CLI commands +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +In order to have less code to maintain, it should be possible to write a +tool that auto-generates CLI commands based on the FRR YANG models. As a +matter of fact, there are already a number of NETCONF-based CLIs that do +exactly that (e.g. `Clixon <https://github.com/clicon/clixon>`__, +ConfD’s CLI). + +The problem however is that there isn’t an exact one-to-one mapping +between the existing CLI commands and the corresponding YANG nodes from +the native models. As an example, ripd’s +``timers basic (5-2147483647) (5-2147483647) (5-2147483647)`` command +changes three YANG leaves at the same time. In order to auto-generate +CLI commands and retain their original form, it’s necessary to add +annotations in the YANG modules to specify how the commands should look +like. Without YANG annotations, the CLI auto-generator will generate a +command for each YANG leaf, (leaf-)list and presence-container. The +ripd’s ``timers basic`` command, for instance, would become three +different commands, which would be undesirable. + + This Tail-f’s® + `document <http://info.tail-f.com/hubfs/Whitepapers/Tail-f_ConfD-CLI__Cfg_Mode_App_Note_Rev%20C.pdf>`__ + shows how to customize ConfD auto-generated CLI commands using YANG + annotations. + +The good news is that *libyang* allows users to create plugins to +implement their own YANG extensions, which can be used to implement CLI +annotations. If done properly, a CLI generator can save FRR developers +from writing and maintaining hundreds if not thousands of DEFPYs! + +CLI on a separate program +~~~~~~~~~~~~~~~~~~~~~~~~~ + +The flexible design of the northbound architecture opens the door to +move the CLI to a separate program in the long-term future. Some +advantages of doing so would be: \* Treat the CLI as just another +northbound client, instead of having CLI commands embedded in the +binaries of all FRR daemons. \* Improved robustness: bugs in CLI +commands (e.g. null-pointer dereferences) or in the CLI code itself +wouldn’t affect the FRR daemons. \* Foster innovation by allowing other +CLI programs to be implemented, possibly using higher level programming +languages. + +The problem, however, is that the northbound retrofitting process will +convert only the CLI configuration commands and EXEC commands in a first +moment. Retrofitting the “show” commands is a completely different story +and shouldn’t happen anytime soon. This should hinder progress towards +moving the CLI to a separate program. + +Proposed feature: confirmed commits +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Confirmed commits allow the user to request an automatic rollback to the +previous configuration if the commit operation is not confirmed within a +number of minutes. This is particularly useful when the user is +accessing the CLI through the network (e.g. using SSH) and any +configuration change might cause an unexpected loss of connectivity +between the user and the router (e.g. misconfiguration of a routing +protocol). By using a confirmed commit, the user can rest assured the +connectivity will be restored after the given timeout expires, avoiding +the need to access the router physically to fix the problem. + +Example of how this feature could be provided in the CLI: +``commit confirmed [minutes <1-60>]``. The ability to do confirmed +commits should also be exposed in the northbound API so that the +northbound plugins can also take advantage of it (in the case of the +Sysrepo and ConfD plugins, confirmed commits are implemented externally +in the *netopeer2-server* and *confd* daemons, respectively). + +Proposed feature: enable/disable configuration commands/sections +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Since the ``lyd_node`` data structure from *libyang* can hold private +data, it should be possible to mark configuration commands or sections +as active or inactive. This would allow CLI users to leverage this +feature to disable parts of the running configuration without actually +removing the associated commands, and then re-enable the disabled +configuration commands or sections later when necessary. Example: + +:: + + ripd(config)# show configuration running + Configuration: + [snip] + ! + router rip + default-metric 2 + distance 80 + network eth0 + network eth1 + ! + end + ripd(config)# disable router rip + ripd(config)# commit + % Configuration committed successfully (Transaction ID #7). + + ripd(config)# show configuration running + Configuration: + [snip] + ! + !router rip + !default-metric 2 + !distance 80 + !network eth0 + !network eth1 + ! + end + ripd(config)# enable router rip + ripd(config)# commit + % Configuration committed successfully (Transaction ID #8). + + ripd(config)# show configuration running + [snip] + frr defaults traditional + ! + router rip + default-metric 2 + distance 80 + network eth0 + network eth1 + ! + end + +This capability could be useful in a number of occasions, like disabling +configuration commands that are no longer necessary (e.g. ACLs) but that +might be necessary at a later point in the future. Other example is +allowing users to disable a configuration section for testing purposes, +and then re-enable it easily without needing to copy and paste any +command. + +Configuration reloads +~~~~~~~~~~~~~~~~~~~~~ + +Given the limitations of the previous northbound architecture, the FRR +daemons didn’t have the ability to reload their configuration files by +themselves. The SIGHUP handler of most daemons would only re-read the +configuration file and merge it into the running configuration. In most +cases, however, what is desired is to replace the running configuration +by the updated configuration file. The *frr-reload.py* script was +written to work around this problem and it does it well to a certain +extent. The problem with the *frr-reload.py* script is that it’s full of +special cases here and there, which makes it fragile and unreliable. +Maintaining the script is also an additional burden for FRR developers, +few of whom are familiar with its code or know when it needs to be +updated to account for a new feature. + +In the new northbound architecture, reloading the configuration file can +be easily implemented using a configuration transaction. Once the FRR +northbound retrofitting process is complete, all daemons should have the +ability to reload their configuration files upon receiving the SIGHUP +signal, or when the ``configuration load [...] replace`` command is +used. Once that point is reached, the *frr-reload.py* script will no +longer be necessary and should be removed from the FRR repository. + +Configuration changes coming from the kernel +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +This +`post <http://discuss.tail-f.com/t/who-should-not-set-configuration-once-a-system-is-up-and-running/111>`__ +from the Tail-f’s® forum describes the problem of letting systems +configure themselves behind the users back. Here are some selected +snippets from it: > Traditionally, northbound interface users are the +ones in charge of providing configuration data for systems. > > In some +systems, we see a deviation from this traditional practice; allowing +systems to configure “themselves” behind the scenes (or behind the users +back). > > While there might be a business case for such a practice, +this kind of configuration remains “dangerous” from northbound users +perspective and makes systems hard to predict and even harder to debug. +(…) > > With the advent of transactional Network configuration, this +practice can not work anymore. The fact that systems are given the right +to change configuration is a key here in breaking transactional +configuration in a Network. + +FRR is immune to some of the problems described in the aforementioned +post. Management clients can configure interfaces that don’t yet exist, +and once an interface is deleted from the kernel, its configuration is +retained in FRR. + +There are however some cases where information learned from the kernel +(e.g. using netlink) can affect the running configuration of all FRR +daemons. Examples: interface rename events, VRF rename events, interface +being moved to a different VRF, etc. In these cases, since these events +can’t be ignored, the best we can do is to send YANG notifications to +the management clients to inform about the configuration changes. The +management clients should then be prepared to handle such notifications +and react accordingly. + +Interfaces and VRFs +~~~~~~~~~~~~~~~~~~~ + +As of now zebra doesn’t have the ability to create VRFs or virtual +interfaces in the kernel. The ``vrf`` and ``interface`` commands only +create pre-provisioned VRFs and interfaces that are only activated when +the corresponding information is learned from the kernel. When +configuring FRR using an external management client, like a NETCONF +client, it might be desirable to actually create functional VRFs and +virtual interfaces (e.g. VLAN subinterfaces, bridges, etc) that are +installed in the kernel using OS-specific APIs (e.g. netlink, routing +socket, etc). Work needs to be done in this area to make this possible. + +Shared configuration objects +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +One of the existing problems in FRR is that it’s hard to ensure that all +daemons are in sync with respect to the shared configuration objects +(e.g. interfaces, VRFs, route-maps, ACLs, etc). When a route-map is +configured using *vtysh*, the same command is sent to all relevant +daemons (the daemons that implement route-maps), which ensures +synchronization among them. The problem is when a daemon starts after +the route-maps are created. In this case this daemon wouldn’t be aware +of the previously configured route-maps (unlike the other daemons), +which can lead to a lot of confusion and unexpected problems. + +With the new northbound architecture, configuration objects can be +manipulated using higher level abstractions, which opens more +possibilities to solve this decades-long problem. As an example, one +solution would be to make the FRR daemons fetch the shared configuration +objects from zebra using the ZAPI interface during initialization. The +shared configuration objects could be requested using a list of XPaths +expressions in the ``ZEBRA_HELLO`` message, which zebra would respond by +sending the shared configuration objects encoded in the JSON format. +This solution however doesn’t address the case where zebra starts or +restarts after the other FRR daemons. Other solution would be to store +the shared configuration objects in the northbound SQL database and make +all daemons fetch these objects from there. So far no work has been made +on this area as more investigation needs to be done. + +vtysh support +~~~~~~~~~~~~~ + +As explained in the [[Transactional CLI]] page, all commands introduced +by the transactional CLI are not yet available in *vtysh*. This needs to +be addressed in the short term future. Some challenges for doing that +work include: \* How to display configurations (running, candidates and +rollbacks) in a more clever way? The implementation of the +``show running-config`` command in *vtysh* is not something that should +be followed as an example. A better idea would be to fetch the desired +configuration from all daemons (encoded in JSON for example), merge them +all into a single ``lyd_node`` variable and then display the combined +configurations from this variable (the configuration merges would +transparently take care of combining the shared configuration objects). +In order to be able to manipulate the JSON configurations, *vtysh* will +need to load the YANG modules from all daemons at startup (this might +have a minimal impact on startup time). The only issue with this +approach is that the ``cli_show()`` callbacks from all daemons are +embedded in their binaries and thus not accessible externally. It might +be necessary to compile these callbacks on a separate shared library so +that they are accessible to *vtysh* too. Other than that, displaying the +combined configurations in the JSON/XML formats should be +straightforward. \* With the current design, transaction IDs are +per-daemon and not global across all FRR daemons. This means that the +same transaction ID can represent different transactions on different +daemons. Given this observation, how to implement the +``rollback configuration`` command in *vtysh*? The easy solution would +be to add a ``daemon WORD`` argument to specify the context of the +rollback, but per-daemon rollbacks would certainly be confusing and +convoluted to end users. A better idea would be to attack the root of +the problem: change configuration transactions to be global instead of +being per-daemon. This involves a bigger change in the northbound +architecture, and would have implications on how transactions are stored +in the SQL database (daemon-specific and shared configuration objects +would need to have their own tables or columns). \* Loading +configuration files in the JSON or XML formats will be tricky, as +*vtysh* will need to know which sections of the configuration should be +sent to which daemons. *vtysh* will either need to fetch the YANG +modules implemented by all daemons at runtime or obtain this information +at compile-time somehow. + +Detecting type mismatches at compile-time +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +As described in the [[Retrofitting Configuration Commands]] page, the +northbound configuration callbacks detect type mismatches at runtime +when fetching data from the the ``dnode`` parameter (which represents +the configuration node being created, modified, deleted or moved). When +a type mismatch is detected, the program aborts and displays a backtrace +showing where the problem happened. It would be desirable to detect such +type mismatches at compile-time, the earlier the problems are detected +the sooner they are fixed. + +One possible solution to this problem would be to auto-generate C +structures from the YANG models and provide a function that converts a +libyang’s ``lyd_node`` variable to a C structure containing the same +information. The northbound callbacks could then fetch configuration +data from this C structure, which would naturally lead to type +mismatches being detected at compile time. One of the challenges of +doing this would be the handling of YANG lists and leaf-lists. It would +be necessary to use dynamic data structures like hashes or rb-trees to +hold all elements of the lists and leaf-lists, and the process of +converting a ``lyd_node`` to an auto-generated C-structure could be +expensive. At this point it’s unclear if it’s worth adding more +complexity in the northbound architecture to solve this specific +problem. diff --git a/doc/developer/northbound/architecture.rst b/doc/developer/northbound/architecture.rst new file mode 100644 index 0000000000..e571971c7f --- /dev/null +++ b/doc/developer/northbound/architecture.rst @@ -0,0 +1,275 @@ +Introduction +------------ + +The goal of the new northbound API is to provide a better interface to +configure and monitor FRR programatically. The current design based on +CLI commands is no longer adequate in a world where computer networks +are becoming increasingly bigger, more diverse and more complex. Network +scripting using *expect* and screen scraping techniques is too primitive +and unreliable to be used in large-scale networks. What is proposed is +to modernize FRR to turn it into an API-first routing stack, and +reposition the CLI on top of this API. The most important change, +however, is not the API that will be provided to external users. In +fact, multiple APIs will be supported and users will have the ability to +write custom management APIs if necessary. The biggest change is the +introduction of a model-driven management architecture based on the +`YANG <https://tools.ietf.org/html/rfc7950>`__ modeling language. +Instead of writing code tied to any particular user interface +(e.g. DEFUNs), YANG allows us to write API-agnostic code (in the form of +callbacks) that can be used by any management interface. As an example, +it shouldn’t matter if a set of configuration changes is coming from a +`NETCONF <https://tools.ietf.org/html/rfc6241>`__ session or from a CLI +terminal, the same callbacks should be called to process the +configuration changes regardless of where they came from. This +model-driven design ensures feature parity across all management +interfaces supported by FRR. + +Quoting :rfc:`7950`: + + YANG is a language originally designed to model data for the NETCONF + protocol. A YANG module defines hierarchies of data that can be used for + NETCONF-based operations, including configuration, state data, RPCs, and + notifications. This allows a complete description of all data sent between a + NETCONF client and server. Although out of scope for this specification, + YANG can also be used with protocols other than NETCONF. + +While the YANG and NETCONF specifications are tightly coupled with one +another, both are independent to a certain extent and are evolving +separately. Examples of other management protocols that use YANG include +`RESTCONF <https://tools.ietf.org/html/rfc8040>`__, +`gNMI <https://github.com/openconfig/reference/tree/master/rpc/gnmi>`__ +and +`CoAP <https://www.ietf.org/archive/id/draft-vanderstok-core-comi-11.txt>`__. + +In addition to being management-protocol independent, some other +advantages of using YANG in FRR are listed below: \* Have a formal +contract between FRR and application developers (management clients). A +management client that has access to the FRR YANG models knows about all +existing configuration options available for use. This information can +be used to auto-generate user-friendly interfaces like Web-UIs, custom +CLIs and even code bindings for several different programming languages. +Using `PyangBind <https://github.com/robshakir/pyangbind>`__, for +example, it’s possible to generate Python class hierarchies from YANG +models and use these classes to instantiate objects that mirror the +structure of the YANG modules and can be serialized/deserialized using +different encoding formats. \* Support different encoding formats for +instance data. Currently only JSON and XML are supported, but +`GPB <https://developers.google.com/protocol-buffers/>`__ and +`CBOR <http://cbor.io/>`__ are other viable options in the long term. +Additional encoding formats can be implemented in the *libyang* library +for optimal performance, or externally by translating data to/from one +of the supported formats (with a performance penalty). \* Have a formal +mechanism to introduce backward-incompatible changes based on `semantic +versioning <http://www.openconfig.net/docs/semver/>`__ (not part of the +YANG standard, which allows backward-compatible module updates only). \* +Provide seamless support to the industry-standard NETCONF/RESTCONF +protocols as alternative management APIs. If FRR configuration/state +data is modeled using YANG, supporting YANG-based protocols like NETCONF +and RESTCONF is much easier. + +As important as shifting to a model-driven management paradigm, the new +northbound architecture also introduces the concept of configuration +transactions. Configuration transactions allow management clients to +commit multiple configuration changes at the same time and rest assured +that either all changes will be applied or none will (all-or-nothing). +Configuration transactions are implemented as pseudo-atomic operations +and facilitate automation by removing the burden of error recovery from +the management side. Another property of configuration transactions is +that the configuration changes are always processed in a pre-defined +order to ensure consistency. Configuration transactions that encompass +multiple network devices are called network-wide transactions and are +also supported by the new northbound architecture. When FRR is built +using the ``--enable-config-rollbacks`` option, all committed +transactions are recorded in the FRR rollback log, which can reside +either in memory (volatile) or on persistent storage. + + Network-wide Transactions is the most important leap in network + management technology since SNMP. The error recovery and sequencing + tasks are removed from the manager side. This is usually more than + half the cost in a mature system; more than the entire cost of the + managed devices. + `[source] <https://www.nanog.org/sites/default/files/tuesday_tutorial_moberg_netconf_35.pdf>`__. + +Figures 1 and 2 below illustrate the old and new northbound architecture +of FRR, respectively. As it can be seen, in the old architecture the CLI +was the only interface used to configure and monitor FRR (the SNMP +plugin was’t taken into account given the small number of implemented +MIBs). This means that the only way to automate FRR was by writing +scripts that send CLI commands and parse the text output (which usually +doesn’t have any structure) using screen scraping and regular +expressions. + +.. figure:: images/arch-before.png + :alt: diagram of northbound architecture prior to nbapi conversion + + Old northbound architecture + +The new northbound architectures, on the other hand, features a +multitude of different management APIs, all of them connected to the +northbound layer of the FRR daemons. By default, only the CLI interface +is compiled built-in in the FRR daemons. The other management interfaces +are provided as optional plugins and need to be loaded during the daemon +initialization (e.g. *zebra -M confd*). This design makes it possible to +integrate FRR with different NETCONF solutions without introducing +vendor lock-in. The [[Plugins - Writing Your Own]] page explains how to +write custom northbound plugins that can be tailored to all needs +(e.g. support custom transport protocols, different data encoding +formats, fine-grained access control, etc). + +.. figure:: images/arch-after.png + :alt: diagram of northbound architecture after nbapi conversion + + New northbound architecture + +Figure 3 shows the internal view of the FRR northbound architecture. In +this image we can see that northbound layer is an abstract entity +positioned between the northbound callbacks and the northbound clients. +The northbound layer is responsible to process the requests coming from +the northbound clients and call the appropriate callbacks to satisfy +these requests. The northbound plugins communicate with the northbound +layer through a public API, which allow users to write third-party +plugins that can be maintained separately. The northbound plugins, in +turn, have their own APIs to communicate with external management +clients. + +.. figure:: images/nb-layer.png + :alt: diagram of northbound architecture internals + + New northbound architecture - internal view + +Initially the CLI (and all of its commands) will be maintained inside +the FRR daemons. In the long term, however, the goal is to move the CLI +to a separate program just like any other management client. The +[[Advanced Topics]] page describes the motivations and challenges of +doing that. Last but not least, the *libyang* block inside the +northbound layer is the engine that makes everything possible. The +*libyang* library will be described in more detail in the following +sections. + +YANG models +----------- + +The main decision to be made when using YANG is which models to +implement. There’s a general consensus that using standard models is +preferable over using custom (native) models. The reasoning is that +applications based on standard models can be reused for all network +appliances that support those models, whereas the same doesn’t apply for +applications written based on custom models. + +That said, there are multiple standards bodies publishing YANG models +and unfortunately not all of them are converging (or at least not yet). +In the context of FRR, which is a routing stack, the two sets of YANG +models that would make sense to implement are the ones from IETF and +from the OpenConfig working group. The question that arises is: which +one of them should we commit to? Or should we try to support both +somehow, at the cost of extra development efforts? + +Another problem, from an implementation point of view, is that it’s +challenging to adapt the existing code base to match standard models. A +more reasonable solution, at least in a first moment, would be to use +YANG deviations and augmentations to do the opposite: adapt the standard +models to the existing code. In practice however this is not as simple +as it seems. There are cases where the differences are too substantial +to be worked around without restructuring the code by changing its data +structures and their relationships. As an example, the *ietf-rip* model +places per-interface RIP configuration parameters inside the +*control-plane-protocol* list (which is augmented by *ietf-rip*). This +means that it’s impossible to configure RIP interface parameters without +first configuring a RIP routing instance. The *ripd* daemon on the other +hand allows the operator to configure RIP interface parameters even if +``router rip`` is not configured. If we were to implement the *ietf-rip* +module natively, we’d need to change ripd’s CLI commands (and the +associated code) to reflect the new configuration hierarchy. + +Taking into account that FRR has a huge code base and that the +northbound retrofitting process per-se will cause a lot of impact, it +was decided to take a conservative approach and write custom YANG models +for FRR modeled after the existing CLI commands. Having YANG models that +closely mirror the CLI commands will allow the FRR developers to +retrofit the code base much more easily, without introducing +backward-incompatible changes in the CLI and reducing the likelihood of +introducing bugs. The [[Retrofitting Configuration Commands]] page +explains in detail how to convert configuration commands to the new +northbound model. + +Even though having native YANG models is not the ideal solution, it will +be already a big step forward for FRR to migrate to a model-driven +management architecture, with support for configuration transactions and +multiple management interfaces, including NETCONF and RESTCONF (through +the northbound plugins). + +The new northbound also features an experimental YANG module translator +that will allow users to translate to and from standard YANG models by +using translation tables. The [[YANG module translator]] page describes +this mechanism in more detail. At this point it’s unclear what can be +achieved through module translation and if that can be considered as a +definitive solution to support standard models or not. + +Northbound Architecture +----------------------- + +.. figure:: images/lys-node.png + :alt: diagram of libyanbg's lys_node data structure + + ``libyang's`` lys_node data structure + + +.. figure:: images/lyd-node.png + :alt: diagram of libyanbg's lyd_node data structure + + ``libyang's`` lyd_node data structure + + +.. figure:: images/ly-ctx.png + :alt: diagram of libyanbg's ly_ctx data structure + + ``libyang's`` ly_ctx data structure + + +.. figure:: images/transactions.png + :alt: diagram showing how configuration transactions work + + Configuration transactions + + +Testing +------- + +The new northbound adds the libyang library as a new mandatory +dependency for FRR. To obtain and install this library, follow the steps +below: + +.. code-block:: console + + git clone https://github.com/CESNET/libyang + cd libyang + git checkout devel + mkdir build ; cd build + cmake -DENABLE_LYD_PRIV=ON .. + make + sudo make install + + +.. note:: + + first make sure to install the libyang + `requirements <https://github.com/CESNET/libyang#build-requirements>`__. + + +FRR needs libyang from version 0.16.7 or newer, which is maintained in +the ``devel`` branch. libyang 0.15.x is maintained in the ``master`` +branch and doesn’t contain one small feature used by FRR (the +``LY_CTX_DISABLE_SEARCHDIR_CWD`` flag). FRR also makes use of the +libyang’s ``ENABLE_LYD_PRIV`` feature, which is disabled by default and +needs to be enabled at compile time. + +It’s advisable (but not required) to install sqlite3 and build FRR with +``--enable-config-rollbacks`` in order to have access to the +configuration rollback feature. + +To test the northbound, the suggested method is to use the +[[Transactional CLI]] with the *ripd* daemon and play with the new +commands. The ``debug northbound`` command can be used to see which +northbound callbacks are called in response to the ``commit`` command. +For reference, the [[Demos]] page shows a small demonstration of the +transactional CLI in action and what it’s capable of. diff --git a/doc/developer/northbound/demos.rst b/doc/developer/northbound/demos.rst new file mode 100644 index 0000000000..876bd25222 --- /dev/null +++ b/doc/developer/northbound/demos.rst @@ -0,0 +1,27 @@ +Transactional CLI +----------------- + +This short demo shows some of the capabilities of the new transactional +CLI: + +|asciicast1| + +ConfD + NETCONF + Cisco YDK +--------------------------- + +This is a very simple demo of *ripd* being configured by a python +script. The script uses NETCONF to communicate with *ripd*, which has +the ConfD plugin loaded. The most interesting part, however, is the fact +that the python script is not using handcrafted XML payloads to +configure *ripd*. Instead, the script is using python bindings generated +using Cisco’s YANG Development Kit (YDK). + +- Script used in the demo: + https://gist.github.com/rwestphal/defa9bd1ccf216ab082d4711ae402f95 + +|asciicast2| + +.. |asciicast1| image:: https://asciinema.org/a/jL0BS5HfP2kS6N1HfgsZvfZk1.png + :target: https://asciinema.org/a/jL0BS5HfP2kS6N1HfgsZvfZk1 +.. |asciicast2| image:: https://asciinema.org/a/VfMElNxsjLcdvV7484E6ChxWv.png + :target: https://asciinema.org/a/VfMElNxsjLcdvV7484E6ChxWv diff --git a/doc/developer/northbound/images/arch-after.png b/doc/developer/northbound/images/arch-after.png new file mode 100644 index 0000000000..01e6ae6364 Binary files /dev/null and b/doc/developer/northbound/images/arch-after.png differ diff --git a/doc/developer/northbound/images/arch-before.png b/doc/developer/northbound/images/arch-before.png new file mode 100644 index 0000000000..ab2bb0deb2 Binary files /dev/null and b/doc/developer/northbound/images/arch-before.png differ diff --git a/doc/developer/northbound/images/ly-ctx.png b/doc/developer/northbound/images/ly-ctx.png new file mode 100644 index 0000000000..4d4e138c73 Binary files /dev/null and b/doc/developer/northbound/images/ly-ctx.png differ diff --git a/doc/developer/northbound/images/lyd-node.png b/doc/developer/northbound/images/lyd-node.png new file mode 100644 index 0000000000..4ba2b48b71 Binary files /dev/null and b/doc/developer/northbound/images/lyd-node.png differ diff --git a/doc/developer/northbound/images/lys-node.png b/doc/developer/northbound/images/lys-node.png new file mode 100644 index 0000000000..e9e46e7f64 Binary files /dev/null and b/doc/developer/northbound/images/lys-node.png differ diff --git a/doc/developer/northbound/images/nb-layer.png b/doc/developer/northbound/images/nb-layer.png new file mode 100644 index 0000000000..4aa1fd6bff Binary files /dev/null and b/doc/developer/northbound/images/nb-layer.png differ diff --git a/doc/developer/northbound/images/transactions.png b/doc/developer/northbound/images/transactions.png new file mode 100644 index 0000000000..d18faf4478 Binary files /dev/null and b/doc/developer/northbound/images/transactions.png differ diff --git a/doc/developer/northbound/links.rst b/doc/developer/northbound/links.rst new file mode 100644 index 0000000000..e80374c57b --- /dev/null +++ b/doc/developer/northbound/links.rst @@ -0,0 +1,233 @@ +RFCs +~~~~ + +- `RFC 7950 - The YANG 1.1 Data Modeling + Language <https://tools.ietf.org/html/rfc7950>`__ +- `RFC 7951 - JSON Encoding of Data Modeled with + YANG <https://tools.ietf.org/html/rfc7951>`__ +- `RFC 8342 - Network Management Datastore Architecture + (NMDA) <https://tools.ietf.org/html/rfc8342>`__ +- `RFC 6087 - Guidelines for Authors and Reviewers of YANG Data Model + Documents <https://tools.ietf.org/html/rfc6087>`__ +- `RFC 8340 - YANG Tree + Diagrams <https://tools.ietf.org/html/rfc8340>`__ +- `RFC 6991 - Common YANG Data + Types <https://tools.ietf.org/html/rfc6991>`__ +- `RFC 6241 - Network Configuration Protocol + (NETCONF) <https://tools.ietf.org/html/rfc6241>`__ +- `RFC 8040 - RESTCONF + Protocol <https://tools.ietf.org/html/rfc8040>`__ + +YANG models +~~~~~~~~~~~ + +- Collection of several YANG models, including models from standards + organizations such as the IETF and vendor specific models: + https://github.com/YangModels/yang +- OpenConfig: https://github.com/openconfig/public + +Presentations +~~~~~~~~~~~~~ + +- FRR Advanced Northbound API (May 2018) + + - Slides: + https://www.dropbox.com/s/zhybthruwocbqaw/netdef-frr-northbound.pdf?dl=1 + +- Ok, We Got Data Models, Now What? + + - Video: https://www.youtube.com/watch?v=2oqkiZ83vAA + - Slides: + https://www.nanog.org/sites/default/files/20161017_Alvarez_Ok_We_Got_v1.pdf + +- Data Model-Driven Management: Latest Industry and Tool Developments + + - Video: https://www.youtube.com/watch?v=n_oKGJ_jgYQ + - Slides: + https://pc.nanog.org/static/published/meetings/NANOG72/1559/20180219_Claise_Data_Modeling-Driven_Management__v1.pdf + +- Network Automation And Programmability: Reality Versus The Vendor + Hype When Considering Legacy And NFV Networks + + - Video: https://www.youtube.com/watch?v=N5wbYncUS9o + - Slides: + https://www.nanog.org/sites/default/files/1_Moore_Network_Automation_And_Programmability.pdf + +- Lightning Talk: The API is the new CLI? + + - Video: https://www.youtube.com/watch?v=ngi0erGNi58 + - Slides: + https://pc.nanog.org/static/published/meetings/NANOG72/1638/20180221_Grundemann_Lightning_Talk_The_v1.pdf + +- Lightning Talk: OpenConfig - progress toward vendor-neutral network + management + + - Video: https://www.youtube.com/watch?v=10rSUbeMmT4 + - Slides: + https://pc.nanog.org/static/published/meetings/NANOG71/1535/20171004_Shaikh_Lightning_Talk_Openconfig_v1.pdf + +- Getting started with OpenConfig + + - Video: https://www.youtube.com/watch?v=L7trUNK8NJI + - Slides: + https://pc.nanog.org/static/published/meetings/NANOG71/1456/20171003_Alvarez_Getting_Started_With_v1.pdf + +- Why NETCONF and YANG + + - Video: https://www.youtube.com/watch?v=mp4h8aSTba8 + +- NETCONF and YANG Concepts + + - Video: https://www.youtube.com/watch?v=UwYYvT7DBvg + +- NETCONF Tutorial + + - Video: https://www.youtube.com/watch?v=N4vov1mI14U + +Whitepapers +~~~~~~~~~~~ + +- Automating Network and Service Configuration Using NETCONF and YANG: + http://www.tail-f.com/wordpress/wp-content/uploads/2013/02/Tail-f-Presentation-Netconf-Yang.pdf +- Creating the Programmable Network: The Business Case for NETCONF/YANG + in Network Devices: + http://www.tail-f.com/wordpress/wp-content/uploads/2013/10/HR-Tail-f-NETCONF-WP-10-08-13.pdf +- NETCONF/YANG: What’s Holding Back Adoption & How to Accelerate It: + https://www.oneaccess-net.com/images/public/wp_heavy_reading.pdf +- Achieving Automation with YANG Modeling Technologies: + https://www.cisco.com/c/dam/en/us/products/collateral/cloud-systems-management/network-services-orchestrator/idc-achieving-automation-wp.pdf + +Blog posts and podcasts +~~~~~~~~~~~~~~~~~~~~~~~ + +- OpenConfig and IETF YANG Models: Can they converge? - + http://rob.sh/post/215/ +- OpenConfig: Standardized Models For Networking - + https://packetpushers.net/openconfig-standardized-models-networking/ +- (Podcast) OpenConfig: From Basics to Implementations - + https://blog.ipspace.net/2017/02/openconfig-from-basics-to.html +- (Podcast) How Did NETCONF Start on Software Gone Wild - + https://blog.ipspace.net/2017/12/how-did-netconf-start-on-software-gone.html +- YANG Data Models in the Industry: Current State of Affairs (March + 2018) - + https://www.claise.be/2018/03/yang-data-models-in-the-industry-current-state-of-affairs-march-2018/ +- Why Data Model-driven Telemetry is the only useful Telemetry? - + https://www.claise.be/2018/02/why-data-model-driven-telemetry-is-the-only-useful-telemetry/ +- NETCONF versus RESTCONF: Capabilitity Comparisons for Data + Model-driven Management - + https://www.claise.be/2017/10/netconf-versus-restconf-capabilitity-comparisons-for-data-model-driven-management-2/ +- An Introduction to NETCONF/YANG - + https://www.fir3net.com/Networking/Protocols/an-introduction-to-netconf-yang.html +- Network Automation and the Rise of NETCONF - + https://medium.com/@k.okasha/network-automation-and-the-rise-of-netconf-e96cc33fe28 +- YANG and the Road to a Model Driven Network - + https://medium.com/@k.okasha/yang-and-road-to-a-model-driven-network-e9e52d47148d + +Software +~~~~~~~~ + +libyang +^^^^^^^ + + libyang is a YANG data modelling language parser and toolkit written + (and providing API) in C. + +- GitHub page: https://github.com/CESNET/libyang +- Documentaion: https://netopeer.liberouter.org/doc/libyang/master/ + +pyang +^^^^^ + + pyang is a YANG validator, transformator and code generator, written + in python. It can be used to validate YANG modules for correctness, + to transform YANG modules into other formats, and to generate code + from the modules. + +- GitHub page: https://github.com/mbj4668/pyang +- Documentaion: https://github.com/mbj4668/pyang/wiki/Documentation + +ncclient +^^^^^^^^ + + ncclient is a Python library that facilitates client-side scripting + and application development around the NETCONF protocol. + +- GitHub page: https://github.com/ncclient/ncclient +- Documentaion: https://ncclient.readthedocs.io/en/latest/ + +YDK +^^^ + + ydk-gen is a developer tool that can generate API’s that are modeled + in YANG. Currently, it generates language binding for Python, Go and + C++ with planned support for other language bindings in the future. + +- GitHub pages: + + - Generator: https://github.com/CiscoDevNet/ydk-gen + - Python: https://github.com/CiscoDevNet/ydk-py + + - Python samples: https://github.com/CiscoDevNet/ydk-py-samples + + - Go: https://github.com/CiscoDevNet/ydk-go + - C++: https://github.com/CiscoDevNet/ydk-cpp + +- Documentation: + + - Python: http://ydk.cisco.com/py/docs/ + - Go: http://ydk.cisco.com/go/docs/ + - C++: http://ydk.cisco.com/cpp/docs/ + +- (Blog post) Simplifying Network Programmability with Model-Driven + APIs: + https://blogs.cisco.com/sp/simplifying-network-programmability-with-model-driven-apis +- (Video introduction) Infrastructure as a Code Using YANG, OpenConfig + and YDK: https://www.youtube.com/watch?v=G1b6vJW1R5w + +pyangbind +^^^^^^^^^ + + A plugin for pyang that creates Python bindings for a YANG model. + +- GitHub page: https://github.com/robshakir/pyangbind +- Documentation: http://pynms.io/pyangbind/ + +ConfD +^^^^^ + +- Official webpage (for ConfD Basic): + http://www.tail-f.com/confd-basic/ +- Training Videos: http://www.tail-f.com/confd-training-videos/ +- Forum: http://discuss.tail-f.com/ + +Sysrepo +^^^^^^^ + + Sysrepo is an YANG-based configuration and operational state data + store for Unix/Linux applications. + +- GitHub page: https://github.com/sysrepo/sysrepo +- Official webpage: http://www.sysrepo.org/ +- Documentation: http://www.sysrepo.org/static/doc/html/ + +Netopeer2 +^^^^^^^^^ + + Netopeer2 is a set of tools implementing network configuration tools + based on the NETCONF Protocol. This is the second generation of the + toolset, originally available as the Netopeer project. Netopeer2 is + based on the new generation of the NETCONF and YANG libraries - + libyang and libnetconf2. The Netopeer server uses sysrepo as a + NETCONF datastore implementation. + +- GitHub page: https://github.com/CESNET/Netopeer2 + +Clixon +^^^^^^ + + Clixon is an automatic configuration manager where you generate + interactive CLI, NETCONF, RESTCONF and embedded databases with + transaction support from a YANG specification. + +- GitHub page: https://github.com/clicon/clixon +- Project page: http://www.clicon.org/ diff --git a/doc/developer/northbound/northbound.rst b/doc/developer/northbound/northbound.rst new file mode 100644 index 0000000000..7dddf06460 --- /dev/null +++ b/doc/developer/northbound/northbound.rst @@ -0,0 +1,21 @@ +.. _northbound: + +************** +Northbound API +************** + +.. toctree:: + :maxdepth: 2 + + architecture + transactional-cli + retrofitting-configuration-commands + operational-data-rpcs-and-notifications + plugins-sysrepo + advanced-topics + yang-tools + yang-module-translator + demos + links + ppr-basic-test-topology + ppr-mpls-basic-test-topology diff --git a/doc/developer/northbound/operational-data-rpcs-and-notifications.rst b/doc/developer/northbound/operational-data-rpcs-and-notifications.rst new file mode 100644 index 0000000000..554bc17c80 --- /dev/null +++ b/doc/developer/northbound/operational-data-rpcs-and-notifications.rst @@ -0,0 +1,565 @@ +Operational data +~~~~~~~~~~~~~~~~ + +Writing API-agnostic code for YANG-modeled operational data is +challenging. ConfD and Sysrepo, for instance, have completely different +APIs to fetch operational data. So how can we write API-agnostic +callbacks that can be used by both the ConfD and Sysrepo plugins, and +any other northbound client that might be written in the future? + +As an additional requirement, the callbacks must be designed in a way +that makes in-place XPath filtering possible. As an example, a +management client might want to retrieve only a subset of a large YANG +list (e.g. a BGP table), and for optimal performance it should be +possible to filter out the unwanted elements locally in the managed +devices instead of returning all elements and performing the filtering +on the management application. + +To meet all these requirements, the four callbacks below were introduced +in the northbound architecture: + +.. code:: c + + /* + * Operational data callback. + * + * The callback function should return the value of a specific leaf or + * inform if a typeless value (presence containers or leafs of type + * empty) exists or not. + * + * xpath + * YANG data path of the data we want to get + * + * list_entry + * pointer to list entry + * + * Returns: + * pointer to newly created yang_data structure, or NULL to indicate + * the absence of data + */ + struct yang_data *(*get_elem)(const char *xpath, void *list_entry); + + /* + * Operational data callback for YANG lists. + * + * The callback function should return the next entry in the list. The + * 'list_entry' parameter will be NULL on the first invocation. + * + * list_entry + * pointer to a list entry + * + * Returns: + * pointer to the next entry in the list, or NULL to signal that the + * end of the list was reached + */ + void *(*get_next)(void *list_entry); + + /* + * Operational data callback for YANG lists. + * + * The callback function should fill the 'keys' parameter based on the + * given list_entry. + * + * list_entry + * pointer to a list entry + * + * keys + * structure to be filled based on the attributes of the provided + * list entry + * + * Returns: + * NB_OK on success, NB_ERR otherwise + */ + int (*get_keys)(void *list_entry, struct yang_list_keys *keys); + + /* + * Operational data callback for YANG lists. + * + * The callback function should return a list entry based on the list + * keys given as a parameter. + * + * keys + * structure containing the keys of the list entry + * + * Returns: + * a pointer to the list entry if found, or NULL if not found + */ + void *(*lookup_entry)(struct yang_list_keys *keys); + +These callbacks were designed to provide maximum flexibility, and borrow +a lot of ideas from the ConfD API. Each callback does one and only one +task, they are indivisible primitives that can be combined in several +different ways to iterate over operational data. The extra flexibility +certainly has a performance cost, but it’s the price to pay if we want +to expose FRR operational data using several different management +interfaces (e.g. NETCONF via either ConfD or Sysrepo+Netopeer2). In the +future it might be possible to introduce optional callbacks that do +things like returning multiple objects at once. They would provide +enhanced performance when iterating over large lists, but their use +would be limited by the northbound plugins that can be integrated with +them. + + NOTE: using the northbound callbacks as a base, the ConfD plugin can + provide up to 100 objects between each round trip between FRR and the + *confd* daemon. Preliminary tests showed FRR taking ~7 seconds + (asynchronously, without blocking the main pthread) to return a RIP + table containing 100k routes to a NETCONF client connected to *confd* + (JSON was used as the encoding format). Work needs to be done to find + the bottlenecks and optimize this operation. + +The [[Plugins - Writing Your Own]] page explains how the northbound +plugins can fetch operational data using the aforementioned northbound +callbacks, and how in-place XPath filtering can be implemented. + +Example +^^^^^^^ + +Now let’s move to an example to show how these callbacks are implemented +in practice. The following YANG container is part of the *ietf-rip* +module and contains operational data about RIP neighbors: + +.. code:: yang + + container neighbors { + description + "Neighbor information."; + list neighbor { + key "address"; + description + "A RIP neighbor."; + leaf address { + type inet:ipv4-address; + description + "IP address that a RIP neighbor is using as its + source address."; + } + leaf last-update { + type yang:date-and-time; + description + "The time when the most recent RIP update was + received from this neighbor."; + } + leaf bad-packets-rcvd { + type yang:counter32; + description + "The number of RIP invalid packets received from + this neighbor which were subsequently discarded + for any reason (e.g. a version 0 packet, or an + unknown command type)."; + } + leaf bad-routes-rcvd { + type yang:counter32; + description + "The number of routes received from this neighbor, + in valid RIP packets, which were ignored for any + reason (e.g. unknown address family, or invalid + metric)."; + } + } + } + +We know that this is operational data because the ``neighbors`` +container is within the ``state`` container, which has the +``config false;`` property (which is applied recursively). + +As expected, the ``gen_northbound_callbacks`` tool also generates +skeleton callbacks for nodes that represent operational data: + +.. code:: c + + { + .xpath = "/frr-ripd:ripd/state/neighbors/neighbor", + .cbs.get_next = ripd_state_neighbors_neighbor_get_next, + .cbs.get_keys = ripd_state_neighbors_neighbor_get_keys, + .cbs.lookup_entry = ripd_state_neighbors_neighbor_lookup_entry, + }, + { + .xpath = "/frr-ripd:ripd/state/neighbors/neighbor/address", + .cbs.get_elem = ripd_state_neighbors_neighbor_address_get_elem, + }, + { + .xpath = "/frr-ripd:ripd/state/neighbors/neighbor/last-update", + .cbs.get_elem = ripd_state_neighbors_neighbor_last_update_get_elem, + }, + { + .xpath = "/frr-ripd:ripd/state/neighbors/neighbor/bad-packets-rcvd", + .cbs.get_elem = ripd_state_neighbors_neighbor_bad_packets_rcvd_get_elem, + }, + { + .xpath = "/frr-ripd:ripd/state/neighbors/neighbor/bad-routes-rcvd", + .cbs.get_elem = ripd_state_neighbors_neighbor_bad_routes_rcvd_get_elem, + }, + +The ``/frr-ripd:ripd/state/neighbors/neighbor`` list within the +``neighbors`` container has three different callbacks that need to be +implemented. Let’s start with the first one, the ``get_next`` callback: + +.. code:: c + + static void *ripd_state_neighbors_neighbor_get_next(void *list_entry) + { + struct listnode *node; + + if (list_entry == NULL) + node = listhead(peer_list); + else + node = listnextnode((struct listnode *)list_entry); + + return node; + } + +Given a list entry, the job of this callback is to find the next element +from the list. When the ``list_entry`` parameter is NULL, then the first +element of the list should be returned. + +*ripd* uses the ``rip_peer`` structure to represent RIP neighbors, and +the ``peer_list`` global variable (linked list) is used to store all RIP +neighbors. + +In order to be able to iterate over the list of RIP neighbors, the +callback returns a ``listnode`` variable instead of a ``rip_peer`` +variable. The ``listnextnode`` macro can then be used to find the next +element from the linked list. + +Now the second callback, ``get_keys``: + +.. code:: c + + static int ripd_state_neighbors_neighbor_get_keys(void *list_entry, + struct yang_list_keys *keys) + { + struct listnode *node = list_entry; + struct rip_peer *peer = listgetdata(node); + + keys->num = 1; + (void)inet_ntop(AF_INET, &peer->addr, keys->key[0].value, + sizeof(keys->key[0].value)); + + return NB_OK; + } + +This one is easy. First, we obtain the RIP neighbor from the +``listnode`` structure. Then, we fill the ``keys`` parameter according +to the attributes of the RIP neighbor. In this case, the ``neighbor`` +YANG list has only one key: the neighbor IP address. We then use the +``inet_ntop()`` function to transform this binary IP address into a +string (the lingua franca of the FRR northbound). + +The last callback for the ``neighbor`` YANG list is the ``lookup_entry`` +callback: + +.. code:: c + + static void * + ripd_state_neighbors_neighbor_lookup_entry(struct yang_list_keys *keys) + { + struct in_addr address; + + yang_str2ipv4(keys->key[0].value, &address); + + return rip_peer_lookup(&address); + } + +This callback is the counterpart of the ``get_keys`` callback: given an +array of list keys, the associated list entry should be returned. The +``yang_str2ipv4()`` function is used to convert the list key (an IP +address) from a string to an ``in_addr`` structure. Then the +``rip_peer_lookup()`` function is used to find the list entry. + +Finally, each YANG leaf inside the ``neighbor`` list has its associated +``get_elem`` callback: + +.. code:: c + + /* + * XPath: /frr-ripd:ripd/state/neighbors/neighbor/address + */ + static struct yang_data * + ripd_state_neighbors_neighbor_address_get_elem(const char *xpath, + void *list_entry) + { + struct rip_peer *peer = list_entry; + + return yang_data_new_ipv4(xpath, &peer->addr); + } + + /* + * XPath: /frr-ripd:ripd/state/neighbors/neighbor/last-update + */ + static struct yang_data * + ripd_state_neighbors_neighbor_last_update_get_elem(const char *xpath, + void *list_entry) + { + /* TODO: yang:date-and-time is tricky */ + return NULL; + } + + /* + * XPath: /frr-ripd:ripd/state/neighbors/neighbor/bad-packets-rcvd + */ + static struct yang_data * + ripd_state_neighbors_neighbor_bad_packets_rcvd_get_elem(const char *xpath, + void *list_entry) + { + struct rip_peer *peer = list_entry; + + return yang_data_new_uint32(xpath, peer->recv_badpackets); + } + + /* + * XPath: /frr-ripd:ripd/state/neighbors/neighbor/bad-routes-rcvd + */ + static struct yang_data * + ripd_state_neighbors_neighbor_bad_routes_rcvd_get_elem(const char *xpath, + void *list_entry) + { + struct rip_peer *peer = list_entry; + + return yang_data_new_uint32(xpath, peer->recv_badroutes); + } + +These callbacks receive the list entry as parameter and return the +corresponding data using the ``yang_data_new_*()`` wrapper functions. +Not much to explain here. + +Iterating over operational data without blocking the main pthread +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +One of the problems we have in FRR is that some “show” commands in the +CLI can take too long, potentially long enough to the point of +triggering some protocol timeouts and bringing sessions down. + +To avoid this kind of problem, northbound clients are encouraged to do +one of the following: \* Create a separate pthread for handling requests +to fetch operational data. \* Iterate over YANG lists and leaf-lists +asynchronously, returning a maximum number of elements per time instead +of returning all elements in one shot. + +In order to handle both cases correctly, the ``get_next`` callbacks need +to use locks to prevent the YANG lists from being modified while they +are being iterated over. If that is not done, the list entry returned by +this callback can become a dangling pointer when used in another +callback. + +Currently the ConfD and Sysrepo plugins run only in the main pthread. +The plan in the short-term is to introduce a separate pthread only for +handling operational data, and use the main pthread only for handling +configuration changes, RPCs and notifications. + +RPCs and Actions +~~~~~~~~~~~~~~~~ + +The FRR northbound supports YANG RPCs and Actions through the ``rpc()`` +callback, which is documented as follows in the *lib/northbound.h* file: + +.. code:: c + + /* + * RPC and action callback. + * + * Both 'input' and 'output' are lists of 'yang_data' structures. The + * callback should fetch all the input parameters from the 'input' list, + * and add output parameters to the 'output' list if necessary. + * + * xpath + * xpath of the YANG RPC or action + * + * input + * read-only list of input parameters + * + * output + * list of output parameters to be populated by the callback + * + * Returns: + * NB_OK on success, NB_ERR otherwise + */ + int (*rpc)(const char *xpath, const struct list *input, + struct list *output); + +Note that the same callback is used for both RPCs and actions, which are +essentially the same thing. In the case of YANG actions, the ``xpath`` +parameter can be consulted to find the data node associated to the +operation. + +As part of the northbound retrofitting process, it’s suggested to model +some EXEC-level commands using YANG so that their functionality is +exposed to other management interfaces other than the CLI. As an +example, if the ``clear bgp`` command is modeled using a YANG RPC, and a +corresponding ``rpc`` callback is written, then it should be possible to +clear BGP neighbors using NETCONF and RESTCONF with that RPC (the ConfD +and Sysrepo plugins have full support for YANG RPCs and actions). + +Here’s an example of a very simple RPC modeled using YANG: + +.. code:: yang + + rpc clear-rip-route { + description + "Clears RIP routes from the IP routing table and routes + redistributed into the RIP protocol."; + } + +This RPC doesn’t have any input or output parameters. Below we can see +the implementation of the corresponding ``rpc`` callback, whose skeleton +was automatically generated by the ``gen_northbound_callbacks`` tool: + +.. code:: c + + /* + * XPath: /frr-ripd:clear-rip-route + */ + static int clear_rip_route_rpc(const char *xpath, const struct list *input, + struct list *output) + { + struct route_node *rp; + struct rip_info *rinfo; + struct list *list; + struct listnode *listnode; + + /* Clear received RIP routes */ + for (rp = route_top(rip->table); rp; rp = route_next(rp)) { + list = rp->info; + if (list == NULL) + continue; + + for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) { + if (!rip_route_rte(rinfo)) + continue; + + if (CHECK_FLAG(rinfo->flags, RIP_RTF_FIB)) + rip_zebra_ipv4_delete(rp); + break; + } + + if (rinfo) { + RIP_TIMER_OFF(rinfo->t_timeout); + RIP_TIMER_OFF(rinfo->t_garbage_collect); + listnode_delete(list, rinfo); + rip_info_free(rinfo); + } + + if (list_isempty(list)) { + list_delete_and_null(&list); + rp->info = NULL; + route_unlock_node(rp); + } + } + + return NB_OK; + } + +If the ``clear-rip-route`` RPC had any input parameters, they would be +available in the ``input`` list given as a parameter to the callback. +Similarly, the ``output`` list can be used to append output parameters +generated by the RPC, if any are defined in the YANG model. + +The northbound clients (CLI and northbound plugins) have the +responsibility to create and delete the ``input`` and ``output`` lists. +However, in the cases where the RPC or action doesn’t have any input or +output parameters, the northbound client can pass NULL pointers to the +``rpc`` callback to avoid creating linked lists unnecessarily. We can +see this happening in the example below: + +.. code:: c + + /* + * XPath: /frr-ripd:clear-rip-route + */ + DEFPY (clear_ip_rip, + clear_ip_rip_cmd, + "clear ip rip", + CLEAR_STR + IP_STR + "Clear IP RIP database\n") + { + return nb_cli_rpc("/frr-ripd:clear-rip-route", NULL, NULL); + } + +``nb_cli_rpc()`` is a helper function that merely finds the appropriate +``rpc`` callback based on the XPath provided in the first argument, and +map the northbound error code from the ``rpc`` callback to a vty error +code (e.g. ``CMD_SUCCESS``, ``CMD_WARNING``). The second and third +arguments provided to the function refer to the ``input`` and ``output`` +lists. In this case, both arguments are set to NULL since the YANG RPC +in question doesn’t have any input/output parameters. + +Notifications +~~~~~~~~~~~~~ + +YANG notifations are sent using the ``nb_notification_send()`` function, +documented in the *lib/northbound.h* file as follows: + +.. code:: c + + /* + * Send a YANG notification. This is a no-op unless the 'nb_notification_send' + * hook was registered by a northbound plugin. + * + * xpath + * xpath of the YANG notification + * + * arguments + * linked list containing the arguments that should be sent. This list is + * deleted after being used. + * + * Returns: + * NB_OK on success, NB_ERR otherwise + */ + extern int nb_notification_send(const char *xpath, struct list *arguments); + +The northbound doesn’t use callbacks for notifications because +notifications are generated locally and sent to the northbound clients. +This way, whenever a notification needs to be sent, it’s possible to +call the appropriate function directly instead of finding a callback +based on the XPath of the YANG notification. + +As an example, the *ietf-rip* module contains the following +notification: + +.. code:: yang + + notification authentication-failure { + description + "This notification is sent when the system + receives a PDU with the wrong authentication + information."; + leaf interface-name { + type string; + description + "Describes the name of the RIP interface."; + } + } + +The following convenience function was implemented in *ripd* to send +*authentication-failure* YANG notifications: + +.. code:: c + + /* + * XPath: /frr-ripd:authentication-failure + */ + void ripd_notif_send_auth_failure(const char *ifname) + { + const char *xpath = "/frr-ripd:authentication-failure"; + struct list *arguments; + char xpath_arg[XPATH_MAXLEN]; + struct yang_data *data; + + arguments = yang_data_list_new(); + + snprintf(xpath_arg, sizeof(xpath_arg), "%s/interface-name", xpath); + data = yang_data_new_string(xpath_arg, ifname); + listnode_add(arguments, data); + + nb_notification_send(xpath, arguments); + } + +Now sending the *authentication-failure* YANG notification should be as +simple as calling the above function and provide the appropriate +interface name. The notification will be processed by all northbound +plugins that subscribed a callback to the ``nb_notification_send`` hook. +The ConfD and Sysrepo plugins, for instance, use this hook to relay the +notifications to the *confd*/*sysrepod* daemons, which can generate +NETCONF notifications to subscribed clients. When no northbound plugin +is loaded, ``nb_notification_send()`` doesn’t do anything and the +notifications are ignored. diff --git a/doc/developer/northbound/plugins-sysrepo.rst b/doc/developer/northbound/plugins-sysrepo.rst new file mode 100644 index 0000000000..186c3a0177 --- /dev/null +++ b/doc/developer/northbound/plugins-sysrepo.rst @@ -0,0 +1,137 @@ +Installation +------------ + +Required dependencies +^^^^^^^^^^^^^^^^^^^^^ + +:: + + # apt-get install git cmake build-essential bison flex libpcre3-dev libev-dev \ + libavl-dev libprotobuf-c-dev protobuf-c-compiler libcmocka0 \ + libcmocka-dev doxygen libssl-dev libssl-dev libssh-dev + +libyang +^^^^^^^ + +:: + + # apt-get install libyang0.16 libyang-dev + +Sysrepo +^^^^^^^ + +:: + + $ git clone https://github.com/sysrepo/sysrepo.git + $ cd sysrepo/ + $ mkdir build; cd build + $ cmake -DCMAKE_BUILD_TYPE=Release -DGEN_LANGUAGE_BINDINGS=OFF .. && make + # make install + +libnetconf2 +^^^^^^^^^^^ + +:: + + $ git clone https://github.com/CESNET/libnetconf2.git + $ cd libnetconf2/ + $ mkdir build; cd build + $ cmake .. && make + # make install + +netopeer2 +^^^^^^^^^ + +:: + + $ git clone https://github.com/CESNET/Netopeer2.git + $ cd Netopeer2 + $ cd server + $ mkdir build; cd build + $ cmake .. && make + # make install + +**Note:** If ``make install`` fails as it can’t find +``libsysrepo.so.0.7``, then run ``ldconfig`` and try again as it might +not have updated the lib search path + +FRR +^^^ + +Build and install FRR using the ``--enable-sysrepo`` configure-time +option. + +Initialization +-------------- + +Install the FRR YANG modules in the Sysrepo datastore: + +:: + + # sysrepoctl --install /usr/local/share/yang/ietf-interfaces@2018-01-09.yang + # sysrepoctl --install /usr/local/share/yang/frr-vrf.yang + # sysrepoctl --install /usr/local/share/yang/frr-interface.yang + # sysrepoctl --install /usr/local/share/yang/frr-route-types.yang + # sysrepoctl --install /usr/local/share/yang/frr-filter.yang + # sysrepoctl --install /usr/local/share/yang/frr-route-map.yang + # sysrepoctl --install /usr/local/share/yang/frr-isisd.yang + # sysrepoctl --install /usr/local/share/yang/frr-ripd.yang + # sysrepoctl --install /usr/local/share/yang/frr-ripngd.yang + # sysrepoctl -c frr-vrf --owner frr --group frr + # sysrepoctl -c frr-interface --owner frr --group frr + # sysrepoctl -c frr-route-types --owner frr --group frr + # sysrepoctl -c frr-filter --owner frr --group frr + # sysrepoctl -c frr-route-map --owner frr --group frr + # sysrepoctl -c frr-isisd --owner frr --group frr + # sysrepoctl -c frr-ripd --owner frr --group frr + # sysrepoctl -c frr-ripngd --owner frr --group frr + +Start netopeer2-server: + +:: + + # netopeer2-server -d & + +Start the FRR daemons with the sysrepo module: + +:: + + # isisd -M sysrepo --log=stdout + +Managing the configuration +-------------------------- + +The following NETCONF scripts can be used to show and edit the FRR +configuration: +https://github.com/rzalamena/ietf-hackathon-brazil-201907/tree/master/netconf-scripts + +Example: + +:: + + # ./netconf-edit.py 127.0.0.1 + # ./netconf-get-config.py 127.0.0.1 + <?xml version="1.0" encoding="UTF-8"?><data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><isis xmlns="http://frrouting.org/yang/isisd"><instance><area-tag>testnet</area-tag><is-type>level-1</is-type></instance></isis></data> + +.. + + NOTE: the ncclient library needs to be installed first: + ``apt install -y python3-ncclient`` + +The *sysrepocfg* tool can also be used to show/edit the FRR +configuration. Example: + +:: + + # sysrepocfg --format=json --import=frr-isisd.json --datastore=running frr-isisd + # sysrepocfg --format=json --export --datastore=running frr-isisd + { + "frr-isisd:isis": { + "instance": [ + { + "area-tag": "testnet", + "is-type": "level-1" + } + ] + } + } diff --git a/doc/developer/northbound/ppr-basic-test-topology.rst b/doc/developer/northbound/ppr-basic-test-topology.rst new file mode 100644 index 0000000000..a680ed7dfa --- /dev/null +++ b/doc/developer/northbound/ppr-basic-test-topology.rst @@ -0,0 +1,1632 @@ +Table of Contents +~~~~~~~~~~~~~~~~~ + +- `Software <#software>`__ +- `Topology <#topology>`__ +- `Configuration <#configuration>`__ + + - `CLI <#configuration-cli>`__ + - `YANG <#configuration-yang>`__ + +- `Verification - Control Plane <#verification-cplane>`__ +- `Verification - Forwarding Plane <#verification-fplane>`__ + +Software +~~~~~~~~ + +The FRR PPR implementation for IS-IS is available here: +https://github.com/opensourcerouting/frr/tree/isisd-ppr + +Topology +~~~~~~~~ + +In this topology we have an IS-IS network consisting of 12 routers. CE1 +and CE2 are the consumer edges, connected to R11 and R14, respectively. +Three hosts are connected to the CEs using only static routes. + +Router R11 advertises 6 PPR TLVs, which corresponds to three +bi-directional GRE tunnels: \* **6000:1::1 <-> 6000:2::1:** {R11 - R21 - +R22 - R23 - R14} (IPv6 Node Addresses only) \* **6000:1::2 <-> +6000:2::2:** {R11 - R21 - R32 - R41 - R33 - R23 - R14} (IPv6 Node and +Interface Addresses) \* **6000:1::3 <-> 6000:2::3:** {R11 - R21 - R99 - +R23 - R14} (misconfigured path) + +PBR rules are configured on R11 and R14 to route the traffic between +Host 1 and Host 3 using the first PPR tunnel. Traffic between Host 2 and +Host 3 uses the regular IS-IS shortest path. + +Additional information: \* Addresses in the 4000::/16 range refer to +interface addresses, where the last hextet corresponds to the node ID. +\* Addresses in the 5000::/16 range refer to loopback addresses, where +the last hextet corresponds to the node ID. \* Addresses in the +6000::/16 range refer to PPR-ID addresses. + +:: + + +-------+ +-------+ +-------+ + | | | | | | + | HOST1 | | HOST2 | | HOST3 | + | | | | | | + +---+---+ +---+---+ +---+---+ + | | | + |fd00:10:1::/64 | | + +-----+ +------+ fd00:20:1::/64| + | |fd00:10:2::/64 | + | | | + +-+--+--+ +---+---+ + | | | | + | CE1 | | CE2 | + | | | | + +---+---+ +---+---+ + | | + | | + |fd00:10:0::/64 fd00:20:0::/64| + | | + | | + +---+---+ +-------+ +-------+ +---+---+ + | |4000:101::/64| |4000:102::/64| |4000:103::/64| | + | R11 +-------------+ R12 +-------------+ R13 +-------------+ R14 | + | | | | | | | | + +---+---+ +--+-+--+ +--+-+--+ +---+---+ + | | | | | | + |4000:104::/64 | |4000:106::/64 | |4000:108::/64 | + +---------+ +--------+ +--------+ +--------+ +--------+ +---------+ + | |4000:105::/64 | |4000:107::/64 | |4000:109::/64 + | | | | | | + +--+-+--+ +--+-+--+ +--+-+--+ + | |4000:110::/64| |4000:111::/64| | + | R21 +-------------+ R22 +-------------+ R23 | + | | | | | | + +--+-+--+ +--+-+--+ +--+-+--+ + | | | | | | + | |4000:113::/64 | |4000:115::/64 | |4000:117::/64 + +---------+ +--------+ +--------+ +--------+ +--------+ +---------+ + |4000:112::/64 | |4000:114::/64 | |4000:116::/64 | + | | | | | | + +---+---+ +--+-+--+ +--+-+--+ +---+---+ + | |4000:118::/64| |4000:119::/64| |4000:120::/64| | + | R31 +-------------+ R32 +-------------+ R33 +-------------+ R34 | + | | | | | | | | + +-------+ +---+---+ +---+---+ +-------+ + | | + |4000:121::/64 | + +----------+----------+ + | + | + +---+---+ + | | + | R41 | + | | + +-------+ + +Configuration +~~~~~~~~~~~~~ + +PPR TLV processing needs to be enabled on all IS-IS routers using the +``ppr on`` command. The advertisements of all PPR TLVs is done by router +R11. + +CLI configuration +^^^^^^^^^^^^^^^^^ + +.. code:: yaml + + --- + + routers: + + host1: + links: + eth-ce1: + peer: [ce1, eth-host1] + frr: + zebra: + staticd: + config: | + interface eth-ce1 + ipv6 address fd00:10:1::1/64 + ! + ipv6 route ::/0 fd00:10:1::100 + + host2: + links: + eth-ce1: + peer: [ce1, eth-host2] + frr: + zebra: + staticd: + config: | + interface eth-ce1 + ipv6 address fd00:10:2::1/64 + ! + ipv6 route ::/0 fd00:10:2::100 + + host3: + links: + eth-ce2: + peer: [ce2, eth-host3] + frr: + zebra: + staticd: + config: | + interface eth-ce2 + ipv6 address fd00:20:1::1/64 + ! + ipv6 route ::/0 fd00:20:1::100 + + ce1: + links: + eth-host1: + peer: [host1, eth-ce1] + eth-host2: + peer: [host2, eth-ce1] + eth-rt11: + peer: [rt11, eth-ce1] + frr: + zebra: + staticd: + config: | + interface eth-host1 + ipv6 address fd00:10:1::100/64 + ! + interface eth-host2 + ipv6 address fd00:10:2::100/64 + ! + interface eth-rt11 + ipv6 address fd00:10:0::100/64 + ! + ipv6 route ::/0 fd00:10:0::11 + + ce2: + links: + eth-host3: + peer: [host3, eth-ce2] + eth-rt14: + peer: [rt14, eth-ce2] + frr: + zebra: + staticd: + config: | + interface eth-host3 + ipv6 address fd00:20:1::100/64 + ! + interface eth-rt14 + ipv6 address fd00:20:0::100/64 + ! + ipv6 route ::/0 fd00:20:0::14 + + rt11: + links: + lo-ppr: + eth-ce1: + peer: [ce1, eth-rt11] + eth-rt12: + peer: [rt12, eth-rt11] + eth-rt21: + peer: [rt21, eth-rt11] + shell: | + # GRE tunnel for preferred packets (PPR) + ip -6 tunnel add tun-ppr mode ip6gre remote 6000:2::1 local 6000:1::1 ttl 64 + ip link set dev tun-ppr up + # PBR rules + ip -6 rule add from fd00:10:1::/64 to fd00:20:1::/64 iif eth-ce1 lookup 10000 + ip -6 route add default dev tun-ppr table 10000 + frr: + zebra: + staticd: + isisd: + config: | + interface lo-ppr + ipv6 address 6000:1::1/128 + ipv6 address 6000:1::2/128 + ipv6 address 6000:1::3/128 + ! + interface lo + ipv6 address 5000::11/128 + ipv6 router isis 1 + ! + interface eth-ce1 + ipv6 address fd00:10:0::11/64 + ! + interface eth-rt12 + ipv6 address 4000:101::11/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt21 + ipv6 address 4000:104::11/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + ipv6 route fd00:10::/32 fd00:10:0::100 + ! + ppr group VOIP + ppr ipv6 6000:1::1/128 prefix 5000::11/128 metric 50 + pde ipv6-node 5000::14/128 + pde ipv6-node 5000::23/128 + pde ipv6-node 5000::22/128 + pde ipv6-node 5000::21/128 + pde ipv6-node 5000::11/128 + ! + ppr ipv6 6000:2::1/128 prefix 5000::14/128 metric 50 + pde ipv6-node 5000::11/128 + pde ipv6-node 5000::21/128 + pde ipv6-node 5000::22/128 + pde ipv6-node 5000::23/128 + pde ipv6-node 5000::14/128 + ! + ! + ppr group INTERFACE_PDES + ppr ipv6 6000:1::2/128 prefix 5000::11/128 + pde ipv6-node 5000::14/128 + pde ipv6-node 5000::23/128 + pde ipv6-node 5000::33/128 + pde ipv6-interface 4000:121::41/64 + pde ipv6-node 5000::32/128 + pde ipv6-interface 4000:113::21/64 + pde ipv6-node 5000::11/128 + ! + ppr ipv6 6000:2::2/128 prefix 5000::14/128 + pde ipv6-node 5000::11/128 + pde ipv6-node 5000::21/128 + pde ipv6-node 5000::32/128 + pde ipv6-interface 4000:121::41/64 + pde ipv6-node 5000::33/128 + pde ipv6-interface 4000:116::23/64 + pde ipv6-node 5000::14/128 + ! + ! + ppr group BROKEN + ppr ipv6 6000:1::3/128 prefix 5000::11/128 metric 1500 + pde ipv6-node 5000::14/128 + pde ipv6-node 5000::23/128 + ! non-existing node!!! + pde ipv6-node 5000::99/128 + pde ipv6-node 5000::21/128 + pde ipv6-node 5000::11/128 + ! + ppr ipv6 6000:2::3/128 prefix 5000::14/128 metric 1500 + pde ipv6-node 5000::11/128 + pde ipv6-node 5000::21/128 + ! non-existing node!!! + pde ipv6-node 5000::99/128 + pde ipv6-node 5000::23/128 + pde ipv6-node 5000::14/128 + ! + ! + router isis 1 + net 49.0000.0000.0000.0011.00 + is-type level-1 + topology ipv6-unicast + ppr on + ppr advertise VOIP + ppr advertise INTERFACE_PDES + ppr advertise BROKEN + ! + + rt12: + links: + eth-rt11: + peer: [rt11, eth-rt12] + eth-rt13: + peer: [rt13, eth-rt12] + eth-rt21: + peer: [rt21, eth-rt12] + eth-rt22: + peer: [rt22, eth-rt12] + frr: + zebra: + isisd: + config: | + interface lo + ipv6 address 5000::12/128 + ipv6 router isis 1 + ! + interface eth-rt11 + ipv6 address 4000:101::12/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt13 + ipv6 address 4000:102::12/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt21 + ipv6 address 4000:105::12/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt22 + ipv6 address 4000:106::12/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + router isis 1 + net 49.0000.0000.0000.0012.00 + is-type level-1 + topology ipv6-unicast + ppr on + ! + + rt13: + links: + eth-rt12: + peer: [rt12, eth-rt13] + eth-rt14: + peer: [rt14, eth-rt13] + eth-rt22: + peer: [rt22, eth-rt13] + eth-rt23: + peer: [rt23, eth-rt13] + frr: + zebra: + isisd: + config: | + interface lo + ipv6 address 5000::13/128 + ipv6 router isis 1 + ! + interface eth-rt12 + ipv6 address 4000:102::13/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt14 + ipv6 address 4000:103::13/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt22 + ipv6 address 4000:107::13/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt23 + ipv6 address 4000:108::13/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + router isis 1 + net 49.0000.0000.0000.0013.00 + is-type level-1 + topology ipv6-unicast + ppr on + ! + + rt14: + links: + lo-ppr: + eth-ce2: + peer: [ce2, eth-rt14] + eth-rt13: + peer: [rt13, eth-rt14] + eth-rt23: + peer: [rt23, eth-rt14] + shell: | + # GRE tunnel for preferred packets (PPR) + ip -6 tunnel add tun-ppr mode ip6gre remote 6000:1::1 local 6000:2::1 ttl 64 + ip link set dev tun-ppr up + # PBR rules + ip -6 rule add from fd00:20:1::/64 to fd00:10:1::/64 iif eth-ce2 lookup 10000 + ip -6 route add default dev tun-ppr table 10000 + frr: + zebra: + staticd: + isisd: + config: | + interface lo-ppr + ipv6 address 6000:2::1/128 + ipv6 address 6000:2::2/128 + ipv6 address 6000:2::3/128 + ! + interface lo + ipv6 address 5000::14/128 + ipv6 router isis 1 + ! + interface eth-ce2 + ipv6 address fd00:20:0::14/64 + ! + interface eth-rt13 + ipv6 address 4000:103::14/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt23 + ipv6 address 4000:109::14/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + ipv6 route fd00:20::/32 fd00:20:0::100 + ! + router isis 1 + net 49.0000.0000.0000.0014.00 + is-type level-1 + topology ipv6-unicast + ppr on + ! + + rt21: + links: + eth-rt11: + peer: [rt11, eth-rt21] + eth-rt12: + peer: [rt12, eth-rt21] + eth-rt22: + peer: [rt22, eth-rt21] + eth-rt31: + peer: [rt31, eth-rt21] + eth-rt32: + peer: [rt32, eth-rt21] + frr: + zebra: + isisd: + config: | + interface lo + ipv6 address 5000::21/128 + ipv6 router isis 1 + ! + interface eth-rt11 + ipv6 address 4000:104::21/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt12 + ipv6 address 4000:105::21/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt22 + ipv6 address 4000:110::21/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt31 + ipv6 address 4000:112::21/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt32 + ipv6 address 4000:113::21/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + router isis 1 + net 49.0000.0000.0000.0021.00 + is-type level-1 + topology ipv6-unicast + ppr on + ! + + rt22: + links: + eth-rt12: + peer: [rt12, eth-rt22] + eth-rt13: + peer: [rt13, eth-rt22] + eth-rt21: + peer: [rt21, eth-rt22] + eth-rt23: + peer: [rt23, eth-rt22] + eth-rt32: + peer: [rt32, eth-rt22] + eth-rt33: + peer: [rt33, eth-rt22] + frr: + zebra: + isisd: + config: | + interface lo + ipv6 address 5000::22/128 + ipv6 router isis 1 + ! + interface eth-rt12 + ipv6 address 4000:106::22/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt13 + ipv6 address 4000:107::22/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt21 + ipv6 address 4000:110::22/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt23 + ipv6 address 4000:111::22/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt32 + ipv6 address 4000:114::22/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt33 + ipv6 address 4000:115::22/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + router isis 1 + net 49.0000.0000.0000.0022.00 + is-type level-1 + topology ipv6-unicast + ppr on + ! + + rt23: + links: + eth-rt13: + peer: [rt13, eth-rt23] + eth-rt14: + peer: [rt14, eth-rt23] + eth-rt22: + peer: [rt22, eth-rt23] + eth-rt33: + peer: [rt33, eth-rt23] + eth-rt34: + peer: [rt34, eth-rt23] + frr: + zebra: + isisd: + config: | + interface lo + ipv6 address 5000::23/128 + ipv6 router isis 1 + ! + interface eth-rt13 + ipv6 address 4000:108::23/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt14 + ipv6 address 4000:109::23/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt22 + ipv6 address 4000:111::23/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt33 + ipv6 address 4000:116::23/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt34 + ipv6 address 4000:117::23/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + router isis 1 + net 49.0000.0000.0000.0023.00 + is-type level-1 + topology ipv6-unicast + ppr on + ! + + rt31: + links: + eth-rt21: + peer: [rt21, eth-rt31] + eth-rt32: + peer: [rt32, eth-rt31] + frr: + zebra: + isisd: + config: | + interface lo + ipv6 address 5000::31/128 + ipv6 router isis 1 + ! + interface eth-rt21 + ipv6 address 4000:112::31/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt32 + ipv6 address 4000:118::31/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + router isis 1 + net 49.0000.0000.0000.0031.00 + is-type level-1 + topology ipv6-unicast + ppr on + ! + + rt32: + links: + eth-rt21: + peer: [rt21, eth-rt32] + eth-rt22: + peer: [rt22, eth-rt32] + eth-rt31: + peer: [rt31, eth-rt32] + eth-rt33: + peer: [rt33, eth-rt32] + eth-sw1: + peer: [sw1, eth-rt32] + frr: + zebra: + isisd: + config: | + interface lo + ipv6 address 5000::32/128 + ipv6 router isis 1 + ! + interface eth-rt21 + ipv6 address 4000:113::32/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt22 + ipv6 address 4000:114::32/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt31 + ipv6 address 4000:118::32/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt33 + ipv6 address 4000:119::32/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-sw1 + ipv6 address 4000:121::32/64 + ipv6 router isis 1 + isis hello-multiplier 3 + ! + router isis 1 + net 49.0000.0000.0000.0032.00 + is-type level-1 + topology ipv6-unicast + ppr on + ! + + rt33: + links: + eth-rt22: + peer: [rt22, eth-rt33] + eth-rt23: + peer: [rt23, eth-rt33] + eth-rt32: + peer: [rt32, eth-rt33] + eth-rt34: + peer: [rt34, eth-rt33] + eth-sw1: + peer: [sw1, eth-rt33] + frr: + zebra: + isisd: + config: | + interface lo + ipv6 address 5000::33/128 + ipv6 router isis 1 + ! + interface eth-rt22 + ipv6 address 4000:115::33/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt23 + ipv6 address 4000:116::33/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt32 + ipv6 address 4000:119::33/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt34 + ipv6 address 4000:120::33/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-sw1 + ipv6 address 4000:121::33/64 + ipv6 router isis 1 + isis hello-multiplier 3 + ! + router isis 1 + net 49.0000.0000.0000.0033.00 + is-type level-1 + topology ipv6-unicast + ppr on + ! + + rt34: + links: + eth-rt23: + peer: [rt23, eth-rt34] + eth-rt33: + peer: [rt33, eth-rt34] + frr: + zebra: + isisd: + config: | + interface lo + ipv6 address 5000::34/128 + ipv6 router isis 1 + ! + interface eth-rt23 + ipv6 address 4000:117::34/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt33 + ipv6 address 4000:120::34/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + router isis 1 + net 49.0000.0000.0000.0034.00 + is-type level-1 + topology ipv6-unicast + ppr on + ! + + rt41: + links: + eth-sw1: + peer: [sw1, eth-rt41] + frr: + zebra: + isisd: + config: | + interface lo + ipv6 address 5000::41/128 + ipv6 router isis 1 + ! + interface eth-sw1 + ipv6 address 4000:121::41/64 + ipv6 router isis 1 + isis hello-multiplier 3 + ! + router isis 1 + net 49.0000.0000.0000.0041.00 + is-type level-1 + topology ipv6-unicast + ppr on + ! + + switches: + sw1: + links: + eth-rt32: + peer: [rt32, eth-sw1] + eth-rt33: + peer: [rt33, eth-sw1] + eth-rt41: + peer: [rt41, eth-sw1] + + frr: + base-config: | + hostname %(node) + password 1 + log file %(logdir)/%(node).log + log commands + ! + debug zebra rib + debug isis ppr + debug isis events + debug isis route-events + debug isis spf-events + debug isis lsp-gen + ! + +YANG +^^^^ + +PPR can also be configured using NETCONF, RESTCONF and gRPC based on the +following YANG models: \* +`frr-ppr.yang <https://github.com/opensourcerouting/frr/blob/isisd-ppr/yang/frr-ppr.yang>`__ +\* +`frr-isisd.yang <https://github.com/opensourcerouting/frr/blob/isisd-ppr/yang/frr-isisd.yang>`__ + +As an example, here’s R11 configuration in the XML format: + +.. code:: xml + + <lib xmlns="http://frrouting.org/yang/interface"> + <interface> + <name>lo-ppr</name> + <vrf>default</vrf> + </interface> + <interface> + <name>lo</name> + <vrf>default</vrf> + <isis xmlns="http://frrouting.org/yang/isisd"> + <area-tag>1</area-tag> + <ipv6-routing>true</ipv6-routing> + </isis> + </interface> + <interface> + <name>eth-ce1</name> + <vrf>default</vrf> + </interface> + <interface> + <name>eth-rt12</name> + <vrf>default</vrf> + <isis xmlns="http://frrouting.org/yang/isisd"> + <area-tag>1</area-tag> + <ipv6-routing>true</ipv6-routing> + <hello> + <multiplier> + <level-1>3</level-1> + <level-2>3</level-2> + </multiplier> + </hello> + <network-type>point-to-point</network-type> + </isis> + </interface> + <interface> + <name>eth-rt21</name> + <vrf>default</vrf> + <isis xmlns="http://frrouting.org/yang/isisd"> + <area-tag>1</area-tag> + <ipv6-routing>true</ipv6-routing> + <hello> + <multiplier> + <level-1>3</level-1> + <level-2>3</level-2> + </multiplier> + </hello> + <network-type>point-to-point</network-type> + </isis> + </interface> + </lib> + <ppr xmlns="http://frrouting.org/yang/ppr"> + <group> + <name>VOIP</name> + <ipv6> + <ppr-id>6000:1::1/128</ppr-id> + <ppr-prefix>5000::11/128</ppr-prefix> + <ppr-pde> + <pde-id>5000::14/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::23/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::22/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::21/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::11/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <attributes> + <ppr-metric>50</ppr-metric> + </attributes> + </ipv6> + <ipv6> + <ppr-id>6000:2::1/128</ppr-id> + <ppr-prefix>5000::14/128</ppr-prefix> + <ppr-pde> + <pde-id>5000::11/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::21/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::22/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::23/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::14/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <attributes> + <ppr-metric>50</ppr-metric> + </attributes> + </ipv6> + </group> + <group> + <name>INTERFACE_PDES</name> + <ipv6> + <ppr-id>6000:1::2/128</ppr-id> + <ppr-prefix>5000::11/128</ppr-prefix> + <ppr-pde> + <pde-id>5000::14/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::23/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::33/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>4000:121::41/64</pde-id> + <pde-id-type>ipv6-interface</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::32/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>4000:113::21/64</pde-id> + <pde-id-type>ipv6-interface</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::11/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + </ipv6> + <ipv6> + <ppr-id>6000:2::2/128</ppr-id> + <ppr-prefix>5000::14/128</ppr-prefix> + <ppr-pde> + <pde-id>5000::11/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::21/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::32/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>4000:121::41/64</pde-id> + <pde-id-type>ipv6-interface</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::33/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>4000:116::23/64</pde-id> + <pde-id-type>ipv6-interface</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::14/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + </ipv6> + </group> + <group> + <name>BROKEN</name> + <ipv6> + <ppr-id>6000:1::3/128</ppr-id> + <ppr-prefix>5000::11/128</ppr-prefix> + <ppr-pde> + <pde-id>5000::14/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::23/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::99/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::21/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::11/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <attributes> + <ppr-metric>1500</ppr-metric> + </attributes> + </ipv6> + <ipv6> + <ppr-id>6000:2::3/128</ppr-id> + <ppr-prefix>5000::14/128</ppr-prefix> + <ppr-pde> + <pde-id>5000::11/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::21/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::99/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::23/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::14/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <attributes> + <ppr-metric>1500</ppr-metric> + </attributes> + </ipv6> + </group> + </ppr> + <isis xmlns="http://frrouting.org/yang/isisd"> + <instance> + <area-tag>1</area-tag> + <area-address>49.0000.0000.0000.0011.00</area-address> + <multi-topology> + <ipv6-unicast> + </ipv6-unicast> + </multi-topology> + <ppr> + <enable>true</enable> + <ppr-advertise> + <name>VOIP</name> + </ppr-advertise> + <ppr-advertise> + <name>INTERFACE_PDES</name> + </ppr-advertise> + <ppr-advertise> + <name>BROKEN</name> + </ppr-advertise> + </ppr> + </instance> + </isis> + +Verification - Control Plane +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Verify that R11 has flooded the PPR TLVs correctly to all IS-IS routers: + +:: + + # show isis database detail 0000.0000.0011 + Area 1: + IS-IS Level-1 link-state database: + LSP ID PduLen SeqNumber Chksum Holdtime ATT/P/OL + debian.00-00 1233 0x00000009 0x7bd4 683 0/0/0 + Protocols Supported: IPv4, IPv6 + Area Address: 49.0000 + MT Router Info: ipv4-unicast + MT Router Info: ipv6-unicast + Hostname: debian + MT Reachability: 0000.0000.0012.00 (Metric: 10) ipv6-unicast + MT Reachability: 0000.0000.0021.00 (Metric: 10) ipv6-unicast + MT IPv6 Reachability: 5000::11/128 (Metric: 10) ipv6-unicast + MT IPv6 Reachability: 4000:101::/64 (Metric: 10) ipv6-unicast + MT IPv6 Reachability: 4000:104::/64 (Metric: 10) ipv6-unicast + PPR: Fragment ID: 0, MT-ID: ipv4-unicast, Algorithm: SPF, F:0 D:0 A:0 U:1 + PPR Prefix: 5000::11/128 + ID: 6000:1::3/128 (Native IPv6) + PDE: 5000::14/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::23/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::99/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::21/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::11/128 (IPv6 Node Address), L:0 N:1 E:0 + Metric: 1500 + PPR: Fragment ID: 0, MT-ID: ipv4-unicast, Algorithm: SPF, F:0 D:0 A:0 U:1 + PPR Prefix: 5000::14/128 + ID: 6000:2::3/128 (Native IPv6) + PDE: 5000::11/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::21/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::99/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::23/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::14/128 (IPv6 Node Address), L:0 N:1 E:0 + Metric: 1500 + PPR: Fragment ID: 0, MT-ID: ipv4-unicast, Algorithm: SPF, F:0 D:0 A:0 U:1 + PPR Prefix: 5000::11/128 + ID: 6000:1::2/128 (Native IPv6) + PDE: 5000::14/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::23/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::33/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 4000:121::41 (IPv6 Interface Address), L:0 N:0 E:0 + PDE: 5000::32/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 4000:113::21 (IPv6 Interface Address), L:0 N:0 E:0 + PDE: 5000::11/128 (IPv6 Node Address), L:0 N:1 E:0 + Metric: 0 + PPR: Fragment ID: 0, MT-ID: ipv4-unicast, Algorithm: SPF, F:0 D:0 A:0 U:1 + PPR Prefix: 5000::14/128 + ID: 6000:2::2/128 (Native IPv6) + PDE: 5000::11/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::21/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::32/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 4000:121::41 (IPv6 Interface Address), L:0 N:0 E:0 + PDE: 5000::33/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 4000:116::23 (IPv6 Interface Address), L:0 N:0 E:0 + PDE: 5000::14/128 (IPv6 Node Address), L:0 N:1 E:0 + Metric: 0 + PPR: Fragment ID: 0, MT-ID: ipv4-unicast, Algorithm: SPF, F:0 D:0 A:0 U:1 + PPR Prefix: 5000::11/128 + ID: 6000:1::1/128 (Native IPv6) + PDE: 5000::14/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::23/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::22/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::21/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::11/128 (IPv6 Node Address), L:0 N:1 E:0 + Metric: 50 + PPR: Fragment ID: 0, MT-ID: ipv4-unicast, Algorithm: SPF, F:0 D:0 A:0 U:1 + PPR Prefix: 5000::14/128 + ID: 6000:2::1/128 (Native IPv6) + PDE: 5000::11/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::21/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::22/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::23/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::14/128 (IPv6 Node Address), L:0 N:1 E:0 + Metric: 50 + +The PPR TLVs can also be seen using a modified version of Wireshark as +seen below: + +.. figure:: https://user-images.githubusercontent.com/931662/61582441-9551e500-ab01-11e9-8f6f-400ee3fba927.png + :alt: s2 + + s2 + +Using the ``show isis ppr`` command, verify that all routers installed +the PPR-IDs for the paths they are part of. Example: + +Router RT11 +^^^^^^^^^^^ + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + -------------------------------------------------------------------------------------------- + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Tail-End - - + 1 L1 6000:1::2/128 (Native IPv6) 5000::11/128 0 Tail-End - - + 1 L1 6000:1::3/128 (Native IPv6) 5000::11/128 1500 Tail-End - - + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Head-End Up 00:45:41 + 1 L1 6000:2::2/128 (Native IPv6) 5000::14/128 0 Head-End Up 00:45:41 + 1 L1 6000:2::3/128 (Native IPv6) 5000::14/128 1500 Head-End Up 00:45:41 + + # show ipv6 route 6000::/16 longer-prefixes isis + Codes: K - kernel route, C - connected, S - static, R - RIPng, + O - OSPFv3, I - IS-IS, B - BGP, N - NHRP, T - Table, + v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, + f - OpenFabric, + > - selected route, * - FIB route, q - queued route, r - rejected route + + I>* 6000:2::1/128 [115/50] via fe80::c2a:54ff:fe39:bff7, eth-rt21, 00:01:33 + I>* 6000:2::2/128 [115/0] via fe80::c2a:54ff:fe39:bff7, eth-rt21, 00:01:33 + I>* 6000:2::3/128 [115/1500] via fe80::c2a:54ff:fe39:bff7, eth-rt21, 00:01:33 + +Router RT12 +''''''''''' + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + ------------------------------------------------------------------------------------------ + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Off-Path - - + 1 L1 6000:1::2/128 (Native IPv6) 5000::11/128 0 Off-Path - - + 1 L1 6000:1::3/128 (Native IPv6) 5000::11/128 1500 Off-Path - - + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Off-Path - - + 1 L1 6000:2::2/128 (Native IPv6) 5000::14/128 0 Off-Path - - + 1 L1 6000:2::3/128 (Native IPv6) 5000::14/128 1500 Off-Path - - + + # show ipv6 route 6000::/16 longer-prefixes isis + +Router RT13 +''''''''''' + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + ------------------------------------------------------------------------------------------ + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Off-Path - - + 1 L1 6000:1::2/128 (Native IPv6) 5000::11/128 0 Off-Path - - + 1 L1 6000:1::3/128 (Native IPv6) 5000::11/128 1500 Off-Path - - + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Off-Path - - + 1 L1 6000:2::2/128 (Native IPv6) 5000::14/128 0 Off-Path - - + 1 L1 6000:2::3/128 (Native IPv6) 5000::14/128 1500 Off-Path - - + + # show ipv6 route 6000::/16 longer-prefixes isis + +Router RT14 +''''''''''' + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + -------------------------------------------------------------------------------------------- + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Head-End Up 00:45:45 + 1 L1 6000:1::2/128 (Native IPv6) 5000::11/128 0 Head-End Up 00:45:45 + 1 L1 6000:1::3/128 (Native IPv6) 5000::11/128 1500 Head-End Up 00:45:45 + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Tail-End - - + 1 L1 6000:2::2/128 (Native IPv6) 5000::14/128 0 Tail-End - - + 1 L1 6000:2::3/128 (Native IPv6) 5000::14/128 1500 Tail-End - - + + # show ipv6 route 6000::/16 longer-prefixes isis + Codes: K - kernel route, C - connected, S - static, R - RIPng, + O - OSPFv3, I - IS-IS, B - BGP, N - NHRP, T - Table, + v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, + f - OpenFabric, + > - selected route, * - FIB route, q - queued route, r - rejected route + + I>* 6000:1::1/128 [115/50] via fe80::58ea:78ff:fe00:92c1, eth-rt23, 00:01:36 + I>* 6000:1::2/128 [115/0] via fe80::58ea:78ff:fe00:92c1, eth-rt23, 00:01:36 + I>* 6000:1::3/128 [115/1500] via fe80::58ea:78ff:fe00:92c1, eth-rt23, 00:01:36 + +Router RT21 +''''''''''' + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + --------------------------------------------------------------------------------------------- + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Mid-Point Up 00:45:46 + 1 L1 6000:1::2/128 (Native IPv6) 5000::11/128 0 Mid-Point Up 00:45:46 + 1 L1 6000:1::3/128 (Native IPv6) 5000::11/128 1500 Mid-Point Up 00:45:46 + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Mid-Point Up 00:45:46 + 1 L1 6000:2::2/128 (Native IPv6) 5000::14/128 0 Mid-Point Up 00:45:46 + 1 L1 6000:2::3/128 (Native IPv6) 5000::14/128 1500 Mid-Point Down - + + # show isis ppr id ipv6 6000:2::3/128 detail + Area 1: + PPR-ID: 6000:2::3/128 (Native IPv6) + PPR-Prefix: 5000::14/128 + PDEs: + 5000::11/128 (IPv6 Node Address) + 5000::21/128 (IPv6 Node Address) [LOCAL] + 5000::99/128 (IPv6 Node Address) [NEXT] + 5000::23/128 (IPv6 Node Address) + 5000::14/128 (IPv6 Node Address) + Attributes: + Metric: 1500 + Position: Mid-Point + Originator: 0000.0000.0011 + Level: L1 + Algorithm: 1 + MT-ID: ipv4-unicast + Status: Down: PDE is unreachable + Last change: 00:00:37 + + # show ipv6 route 6000::/16 longer-prefixes isis + Codes: K - kernel route, C - connected, S - static, R - RIPng, + O - OSPFv3, I - IS-IS, B - BGP, N - NHRP, T - Table, + v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, + f - OpenFabric, + > - selected route, * - FIB route, q - queued route, r - rejected route + + I>* 6000:1::1/128 [115/50] via fe80::142e:79ff:feeb:cffc, eth-rt11, 00:01:38 + I>* 6000:1::2/128 [115/0] via fe80::142e:79ff:feeb:cffc, eth-rt11, 00:01:38 + I>* 6000:1::3/128 [115/1500] via fe80::142e:79ff:feeb:cffc, eth-rt11, 00:01:38 + I>* 6000:2::1/128 [115/50] via fe80::c88e:7fff:fe5f:a08d, eth-rt22, 00:01:38 + I>* 6000:2::2/128 [115/0] via fe80::8b2:9eff:fe98:f66a, eth-rt32, 00:01:38 + +Router RT22 +''''''''''' + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + --------------------------------------------------------------------------------------------- + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Mid-Point Up 00:45:47 + 1 L1 6000:1::2/128 (Native IPv6) 5000::11/128 0 Off-Path - - + 1 L1 6000:1::3/128 (Native IPv6) 5000::11/128 1500 Off-Path - - + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Mid-Point Up 00:45:47 + 1 L1 6000:2::2/128 (Native IPv6) 5000::14/128 0 Off-Path - - + 1 L1 6000:2::3/128 (Native IPv6) 5000::14/128 1500 Off-Path - - + + # show ipv6 route 6000::/16 longer-prefixes isis + Codes: K - kernel route, C - connected, S - static, R - RIPng, + O - OSPFv3, I - IS-IS, B - BGP, N - NHRP, T - Table, + v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, + f - OpenFabric, + > - selected route, * - FIB route, q - queued route, r - rejected route + + I>* 6000:1::1/128 [115/50] via fe80::2cb5:edff:fe60:29b1, eth-rt21, 00:01:38 + I>* 6000:2::1/128 [115/50] via fe80::e8d9:63ff:fea3:177b, eth-rt23, 00:01:38 + +Router RT23 +''''''''''' + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + --------------------------------------------------------------------------------------------- + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Mid-Point Up 00:45:49 + 1 L1 6000:1::2/128 (Native IPv6) 5000::11/128 0 Mid-Point Up 00:45:49 + 1 L1 6000:1::3/128 (Native IPv6) 5000::11/128 1500 Mid-Point Down - + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Mid-Point Up 00:45:49 + 1 L1 6000:2::2/128 (Native IPv6) 5000::14/128 0 Mid-Point Up 00:45:49 + 1 L1 6000:2::3/128 (Native IPv6) 5000::14/128 1500 Mid-Point Up 00:45:49 + + # show isis ppr id ipv6 6000:1::3/128 detail + Area 1: + PPR-ID: 6000:1::3/128 (Native IPv6) + PPR-Prefix: 5000::11/128 + PDEs: + 5000::14/128 (IPv6 Node Address) + 5000::23/128 (IPv6 Node Address) [LOCAL] + 5000::99/128 (IPv6 Node Address) [NEXT] + 5000::21/128 (IPv6 Node Address) + 5000::11/128 (IPv6 Node Address) + Attributes: + Metric: 1500 + Position: Mid-Point + Originator: 0000.0000.0011 + Level: L1 + Algorithm: 1 + MT-ID: ipv4-unicast + Status: Down: PDE is unreachable + Last change: 00:02:50 + + # show ipv6 route 6000::/16 longer-prefixes isis + Codes: K - kernel route, C - connected, S - static, R - RIPng, + O - OSPFv3, I - IS-IS, B - BGP, N - NHRP, T - Table, + v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, + f - OpenFabric, + > - selected route, * - FIB route, q - queued route, r - rejected route + + I>* 6000:1::1/128 [115/50] via fe80::d09f:1bff:fe31:e9c9, eth-rt22, 00:01:40 + I>* 6000:1::2/128 [115/0] via fe80::c0c3:b3ff:fe9f:b5d3, eth-rt33, 00:01:40 + I>* 6000:2::1/128 [115/50] via fe80::f40a:66ff:fefc:5c32, eth-rt14, 00:01:40 + I>* 6000:2::2/128 [115/0] via fe80::f40a:66ff:fefc:5c32, eth-rt14, 00:01:40 + I>* 6000:2::3/128 [115/1500] via fe80::f40a:66ff:fefc:5c32, eth-rt14, 00:01:40 + +Router RT31 +''''''''''' + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + ------------------------------------------------------------------------------------------ + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Off-Path - - + 1 L1 6000:1::2/128 (Native IPv6) 5000::11/128 0 Off-Path - - + 1 L1 6000:1::3/128 (Native IPv6) 5000::11/128 1500 Off-Path - - + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Off-Path - - + 1 L1 6000:2::2/128 (Native IPv6) 5000::14/128 0 Off-Path - - + 1 L1 6000:2::3/128 (Native IPv6) 5000::14/128 1500 Off-Path - - + + # show ipv6 route 6000::/16 longer-prefixes isis + +Router RT32 +''''''''''' + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + --------------------------------------------------------------------------------------------- + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Off-Path - - + 1 L1 6000:1::2/128 (Native IPv6) 5000::11/128 0 Mid-Point Up 00:45:51 + 1 L1 6000:1::3/128 (Native IPv6) 5000::11/128 1500 Off-Path - - + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Off-Path - - + 1 L1 6000:2::2/128 (Native IPv6) 5000::14/128 0 Mid-Point Up 00:45:51 + 1 L1 6000:2::3/128 (Native IPv6) 5000::14/128 1500 Off-Path - - + + # show ipv6 route 6000::/16 longer-prefixes isis + Codes: K - kernel route, C - connected, S - static, R - RIPng, + O - OSPFv3, I - IS-IS, B - BGP, N - NHRP, T - Table, + v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, + f - OpenFabric, + > - selected route, * - FIB route, q - queued route, r - rejected route + + I>* 6000:1::2/128 [115/0] via 4000:113::21, eth-rt21, 00:01:42 + I>* 6000:2::2/128 [115/0] via 4000:121::41, eth-sw1, 00:01:42 + +Router RT33 +''''''''''' + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + --------------------------------------------------------------------------------------------- + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Off-Path - - + 1 L1 6000:1::2/128 (Native IPv6) 5000::11/128 0 Mid-Point Up 00:45:52 + 1 L1 6000:1::3/128 (Native IPv6) 5000::11/128 1500 Off-Path - - + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Off-Path - - + 1 L1 6000:2::2/128 (Native IPv6) 5000::14/128 0 Mid-Point Up 00:45:52 + 1 L1 6000:2::3/128 (Native IPv6) 5000::14/128 1500 Off-Path - - + + # show ipv6 route 6000::/16 longer-prefixes isis + Codes: K - kernel route, C - connected, S - static, R - RIPng, + O - OSPFv3, I - IS-IS, B - BGP, N - NHRP, T - Table, + v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, + f - OpenFabric, + > - selected route, * - FIB route, q - queued route, r - rejected route + + I>* 6000:1::2/128 [115/0] via 4000:121::41, eth-sw1, 00:01:43 + I>* 6000:2::2/128 [115/0] via 4000:116::23, eth-rt23, 00:01:43 + +Router RT34 +''''''''''' + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + ------------------------------------------------------------------------------------------ + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Off-Path - - + 1 L1 6000:1::2/128 (Native IPv6) 5000::11/128 0 Off-Path - - + 1 L1 6000:1::3/128 (Native IPv6) 5000::11/128 1500 Off-Path - - + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Off-Path - - + 1 L1 6000:2::2/128 (Native IPv6) 5000::14/128 0 Off-Path - - + 1 L1 6000:2::3/128 (Native IPv6) 5000::14/128 1500 Off-Path - - + + # show ipv6 route 6000::/16 longer-prefixes isis + +Router RT41 +''''''''''' + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + --------------------------------------------------------------------------------------------- + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Off-Path - - + 1 L1 6000:1::2/128 (Native IPv6) 5000::11/128 0 Mid-Point Up 00:45:55 + 1 L1 6000:1::3/128 (Native IPv6) 5000::11/128 1500 Off-Path - - + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Off-Path - - + 1 L1 6000:2::2/128 (Native IPv6) 5000::14/128 0 Mid-Point Up 00:45:55 + 1 L1 6000:2::3/128 (Native IPv6) 5000::14/128 1500 Off-Path - - + + # show ipv6 route 6000::/16 longer-prefixes isis + Codes: K - kernel route, C - connected, S - static, R - RIPng, + O - OSPFv3, I - IS-IS, B - BGP, N - NHRP, T - Table, + v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, + f - OpenFabric, + > - selected route, * - FIB route, q - queued route, r - rejected route + + I>* 6000:1::2/128 [115/0] via fe80::b4b9:60ff:feee:3c73, eth-sw1, 00:01:46 + I>* 6000:2::2/128 [115/0] via fe80::bc2a:d9ff:fe65:97f2, eth-sw1, 00:01:46 + +As it can be seen by the output of ``show isis ppr id ipv6 ... detail``, +routers R21 and R23 couldn’t install the third PPR path because of an +unreachable PDE (configuration error). + +Verification - Forwarding Plane +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +On Router R11, use the ``traceroute`` tool to ensure that the PPR paths +were installed correctly in the network: + +:: + + root@rt11:~# traceroute 6000:2::1 + traceroute to 6000:2::1 (6000:2::1), 30 hops max, 80 byte packets + 1 4000:104::21 (4000:104::21) 0.612 ms 0.221 ms 0.241 ms + 2 4000:110::22 (4000:110::22) 0.257 ms 0.113 ms 0.105 ms + 3 4000:111::23 (4000:111::23) 0.257 ms 0.151 ms 0.098 ms + 4 6000:2::1 (6000:2::1) 0.346 ms 0.139 ms 0.100 ms + root@rt11:~# + root@rt11:~# traceroute 6000:2::2 + traceroute to 6000:2::2 (6000:2::2), 30 hops max, 80 byte packets + 1 4000:104::21 (4000:104::21) 4.383 ms 4.148 ms 0.044 ms + 2 4000:113::32 (4000:113::32) 0.272 ms 0.065 ms 0.064 ms + 3 4000:121::41 (4000:121::41) 0.263 ms 0.101 ms 0.086 ms + 4 4000:115::33 (4000:115::33) 0.351 ms 4000:119::33 (4000:119::33) 0.249 ms 4000:115::33 (4000:115::33) 0.153 ms + 5 4000:111::23 (4000:111::23) 0.232 ms 0.293 ms 0.131 ms + 6 6000:2::2 (6000:2::2) 0.184 ms 0.212 ms 0.140 ms + root@rt11:~# + root@rt11:~# traceroute 6000:2::3 + traceroute to 6000:2::3 (6000:2::3), 30 hops max, 80 byte packets + 1 4000:104::21 (4000:104::21) 1.537 ms !N 1.347 ms !N 1.075 ms !N + +The failure on the third traceroute is expected since the 6000:2::3 +PPR-ID is misconfigured. + +Now ping Host 3 from Host 1 and use tcpdump or wireshark to verify that +the ICMP packets are being tunneled using GRE and following the {R11 - +R21 - R22 - R23 - R14} path. Here’s a wireshark capture between R11 and +R21: + +.. figure:: https://user-images.githubusercontent.com/931662/61582398-d4cc0180-ab00-11e9-83a8-d219f98010b9.png + :alt: s1 + + s1 + +Using ``traceroute`` it’s also possible to see that the ICMP packets are +being tunneled through the IS-IS network: + +:: + + root@host1:~# traceroute fd00:20:1::1 -s fd00:10:1::1 + traceroute to fd00:20:1::1 (fd00:20:1::1), 30 hops max, 80 byte packets + 1 fd00:10:1::100 (fd00:10:1::100) 0.354 ms 0.092 ms 0.031 ms + 2 fd00:10::11 (fd00:10::11) 0.125 ms 0.022 ms 0.026 ms + 3 * * * + 4 * * * + 5 fd00:20:1::1 (fd00:20:1::1) 0.235 ms 0.106 ms 0.091 ms diff --git a/doc/developer/northbound/ppr-mpls-basic-test-topology.rst b/doc/developer/northbound/ppr-mpls-basic-test-topology.rst new file mode 100644 index 0000000000..cedb795da9 --- /dev/null +++ b/doc/developer/northbound/ppr-mpls-basic-test-topology.rst @@ -0,0 +1,1991 @@ +Table of Contents +~~~~~~~~~~~~~~~~~ + +- `Software <#software>`__ +- `Topology <#topology>`__ +- `Configuration <#configuration>`__ + + - `CLI <#configuration-cli>`__ + - `YANG <#configuration-yang>`__ + +- `Verification - Control Plane <#verification-cplane>`__ +- `Verification - Forwarding Plane <#verification-fplane>`__ + +Software +~~~~~~~~ + +The FRR PPR implementation for IS-IS is available here: +https://github.com/opensourcerouting/frr/tree/isisd-ppr-sr + +Topology +~~~~~~~~ + +In this topology we have an IS-IS network consisting of 12 routers. CE1 +and CE2 are the consumer edges, connected to R11 and R14, respectively. +Three hosts are connected to the CEs using only static routes. + +Router R11 advertises 6 PPR TLVs: \* **IPv6 prefixes 6000:1::1/128 and +6000:2::1/128:** {R11 - R21 - R22 - R23 - R14} (IPv6 Node Addresses). \* +**MPLS SR Prefix-SIDs 500 and 501:** {R11 - R21 - R22 - R23 - R14} (SR +Prefix-SIDs). \* **MPLS SR Prefix-SIDs 502 and 503:** {R11 - R21 - R31 - +R32 - R41 - R33 - R34 - R23 - R14} (SR Prefix-SIDs) + +PBR rules are configured on R11 and R14 to route the traffic between +Host 1 and Host 3 using the first PPR tunnel, whereas all other traffic +between CE1 and CE2 uses the second PPR tunnel. + +Additional information: \* Addresses in the 4000::/16 range refer to +interface addresses, where the last hextet corresponds to the node ID. +\* Addresses in the 5000::/16 range refer to loopback addresses, where +the last hextet corresponds to the node ID. \* Addresses in the +6000::/16 range refer to PPR-ID addresses. + +:: + + +-------+ +-------+ +-------+ + | | | | | | + | HOST1 | | HOST2 | | HOST3 | + | | | | | | + +---+---+ +---+---+ +---+---+ + | | | + |fd00:10:1::/64 | | + +-----+ +------+ fd00:20:1::/64| + | |fd00:10:2::/64 | + | | | + +-+--+--+ +---+---+ + | | | | + | CE1 | | CE2 | + | | | | + +---+---+ +---+---+ + | | + | | + |fd00:10:0::/64 fd00:20:0::/64| + | | + | | + +---+---+ +-------+ +-------+ +---+---+ + | |4000:101::/64| |4000:102::/64| |4000:103::/64| | + | R11 +-------------+ R12 +-------------+ R13 +-------------+ R14 | + | | | | | | | | + +---+---+ +--+-+--+ +--+-+--+ +---+---+ + | | | | | | + |4000:104::/64 | |4000:106::/64 | |4000:108::/64 | + +---------+ +--------+ +--------+ +--------+ +--------+ +---------+ + | |4000:105::/64 | |4000:107::/64 | |4000:109::/64 + | | | | | | + +--+-+--+ +--+-+--+ +--+-+--+ + | |4000:110::/64| |4000:111::/64| | + | R21 +-------------+ R22 +-------------+ R23 | + | | | | | | + +--+-+--+ +--+-+--+ +--+-+--+ + | | | | | | + | |4000:113::/64 | |4000:115::/64 | |4000:117::/64 + +---------+ +--------+ +--------+ +--------+ +--------+ +---------+ + |4000:112::/64 | |4000:114::/64 | |4000:116::/64 | + | | | | | | + +---+---+ +--+-+--+ +--+-+--+ +---+---+ + | |4000:118::/64| |4000:119::/64| |4000:120::/64| | + | R31 +-------------+ R32 +-------------+ R33 +-------------+ R34 | + | | | | | | | | + +-------+ +---+---+ +---+---+ +-------+ + | | + |4000:121::/64 | + +----------+----------+ + | + | + +---+---+ + | | + | R41 | + | | + +-------+ + +Configuration +~~~~~~~~~~~~~ + +PPR TLV processing needs to be enabled on all IS-IS routers using the +``ppr on`` command. The advertisements of all PPR TLVs is done by router +R11. + +CLI configuration +^^^^^^^^^^^^^^^^^ + +.. code:: yaml + + --- + + routers: + + host1: + links: + eth-ce1: + peer: [ce1, eth-host1] + frr: + zebra: + staticd: + config: | + interface eth-ce1 + ipv6 address fd00:10:1::1/64 + ! + ipv6 route ::/0 fd00:10:1::100 + + host2: + links: + eth-ce1: + peer: [ce1, eth-host2] + frr: + zebra: + staticd: + config: | + interface eth-ce1 + ipv6 address fd00:10:2::1/64 + ! + ipv6 route ::/0 fd00:10:2::100 + + host3: + links: + eth-ce2: + peer: [ce2, eth-host3] + frr: + zebra: + staticd: + config: | + interface eth-ce2 + ipv6 address fd00:20:1::1/64 + ! + ipv6 route ::/0 fd00:20:1::100 + + ce1: + links: + eth-host1: + peer: [host1, eth-ce1] + eth-host2: + peer: [host2, eth-ce1] + eth-rt11: + peer: [rt11, eth-ce1] + frr: + zebra: + staticd: + config: | + interface eth-host1 + ipv6 address fd00:10:1::100/64 + ! + interface eth-host2 + ipv6 address fd00:10:2::100/64 + ! + interface eth-rt11 + ipv6 address fd00:10:0::100/64 + ! + ipv6 route ::/0 fd00:10:0::11 label 16501 + + ce2: + links: + eth-host3: + peer: [host3, eth-ce2] + eth-rt14: + peer: [rt14, eth-ce2] + frr: + zebra: + staticd: + config: | + interface eth-host3 + ipv6 address fd00:20:1::100/64 + ! + interface eth-rt14 + ipv6 address fd00:20:0::100/64 + ! + ipv6 route ::/0 fd00:20:0::14 label 16500 + + rt11: + links: + lo: + mpls: yes + lo-ppr: + eth-ce1: + peer: [ce1, eth-rt11] + mpls: yes + eth-rt12: + peer: [rt12, eth-rt11] + mpls: yes + eth-rt21: + peer: [rt21, eth-rt11] + mpls: yes + shell: | + # GRE tunnel for preferred packets (PPR) + ip -6 tunnel add tun-ppr mode ip6gre remote 6000:2::1 local 6000:1::1 ttl 64 + ip link set dev tun-ppr up + # PBR rules + ip -6 rule add from fd00:10:1::/64 to fd00:20:1::/64 iif eth-ce1 lookup 10000 + ip -6 route add default dev tun-ppr table 10000 + frr: + zebra: + staticd: + isisd: + config: | + interface lo-ppr + ipv6 address 6000:1::1/128 + ! + interface lo + ip address 10.0.0.11/32 + ipv6 address 5000::11/128 + ipv6 router isis 1 + ! + interface eth-ce1 + ipv6 address fd00:10:0::11/64 + ! + interface eth-rt12 + ipv6 address 4000:101::11/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt21 + ipv6 address 4000:104::11/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + ipv6 route fd00:10::/32 fd00:10:0::100 + ! + ppr group PPR_IPV6 + ppr ipv6 6000:1::1/128 prefix 5000::11/128 metric 50 + pde ipv6-node 5000::14/128 + pde ipv6-node 5000::23/128 + pde ipv6-node 5000::22/128 + pde ipv6-node 5000::21/128 + pde ipv6-node 5000::11/128 + ! + ppr ipv6 6000:2::1/128 prefix 5000::14/128 metric 50 + pde ipv6-node 5000::11/128 + pde ipv6-node 5000::21/128 + pde ipv6-node 5000::22/128 + pde ipv6-node 5000::23/128 + pde ipv6-node 5000::14/128 + ! + ! + ppr group PPR_MPLS_1 + ppr mpls 500 prefix 5000::11/128 + pde prefix-sid 14 + pde prefix-sid 23 + pde prefix-sid 22 + pde prefix-sid 21 + pde prefix-sid 11 + ! + ppr mpls 501 prefix 5000::14/128 + pde prefix-sid 11 + pde prefix-sid 21 + pde prefix-sid 22 + pde prefix-sid 23 + pde prefix-sid 14 + ! + ! + ppr group PPR_MPLS_2 + ppr mpls 502 prefix 5000::11/128 + pde prefix-sid 14 + pde prefix-sid 23 + pde prefix-sid 34 + pde prefix-sid 33 + pde prefix-sid 41 + pde prefix-sid 32 + pde prefix-sid 31 + pde prefix-sid 21 + pde prefix-sid 11 + ! + ppr mpls 503 prefix 5000::14/128 + pde prefix-sid 11 + pde prefix-sid 21 + pde prefix-sid 31 + pde prefix-sid 32 + pde prefix-sid 41 + pde prefix-sid 33 + pde prefix-sid 34 + pde prefix-sid 23 + pde prefix-sid 14 + ! + ! + router isis 1 + net 49.0000.0000.0000.0011.00 + is-type level-1 + topology ipv6-unicast + segment-routing on + segment-routing prefix 5000::11/128 index 11 no-php-flag + ppr on + ppr advertise PPR_IPV6 + ppr advertise PPR_MPLS_1 + ppr advertise PPR_MPLS_2 + ! + + rt12: + links: + lo: + mpls: yes + eth-rt11: + peer: [rt11, eth-rt12] + mpls: yes + eth-rt13: + peer: [rt13, eth-rt12] + mpls: yes + eth-rt21: + peer: [rt21, eth-rt12] + mpls: yes + eth-rt22: + peer: [rt22, eth-rt12] + mpls: yes + frr: + zebra: + isisd: + config: | + interface lo + ip address 10.0.0.12/32 + ipv6 address 5000::12/128 + ipv6 router isis 1 + ! + interface eth-rt11 + ipv6 address 4000:101::12/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt13 + ipv6 address 4000:102::12/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt21 + ipv6 address 4000:105::12/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt22 + ipv6 address 4000:106::12/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + router isis 1 + net 49.0000.0000.0000.0012.00 + is-type level-1 + topology ipv6-unicast + segment-routing on + segment-routing prefix 5000::12/128 index 12 no-php-flag + ppr on + ! + + rt13: + links: + lo: + mpls: yes + eth-rt12: + peer: [rt12, eth-rt13] + mpls: yes + eth-rt14: + peer: [rt14, eth-rt13] + mpls: yes + eth-rt22: + peer: [rt22, eth-rt13] + mpls: yes + eth-rt23: + peer: [rt23, eth-rt13] + mpls: yes + frr: + zebra: + isisd: + config: | + interface lo + ip address 10.0.0.13/32 + ipv6 address 5000::13/128 + ipv6 router isis 1 + ! + interface eth-rt12 + ipv6 address 4000:102::13/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt14 + ipv6 address 4000:103::13/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt22 + ipv6 address 4000:107::13/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt23 + ipv6 address 4000:108::13/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + router isis 1 + net 49.0000.0000.0000.0013.00 + is-type level-1 + topology ipv6-unicast + segment-routing on + segment-routing prefix 5000::13/128 index 13 no-php-flag + ppr on + ! + + rt14: + links: + lo: + mpls: yes + lo-ppr: + eth-ce2: + peer: [ce2, eth-rt14] + mpls: yes + eth-rt13: + peer: [rt13, eth-rt14] + mpls: yes + eth-rt23: + peer: [rt23, eth-rt14] + mpls: yes + shell: | + # GRE tunnel for preferred packets (PPR) + ip -6 tunnel add tun-ppr mode ip6gre remote 6000:1::1 local 6000:2::1 ttl 64 + ip link set dev tun-ppr up + # PBR rules + ip -6 rule add from fd00:20:1::/64 to fd00:10:1::/64 iif eth-ce2 lookup 10000 + ip -6 route add default dev tun-ppr table 10000 + frr: + zebra: + staticd: + isisd: + config: | + interface lo-ppr + ipv6 address 6000:2::1/128 + ! + interface lo + ip address 10.0.0.14/32 + ipv6 address 5000::14/128 + ipv6 router isis 1 + ! + interface eth-ce2 + ipv6 address fd00:20:0::14/64 + ! + interface eth-rt13 + ipv6 address 4000:103::14/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt23 + ipv6 address 4000:109::14/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + ipv6 route fd00:20::/32 fd00:20:0::100 + ! + router isis 1 + net 49.0000.0000.0000.0014.00 + is-type level-1 + topology ipv6-unicast + segment-routing on + segment-routing prefix 5000::14/128 index 14 no-php-flag + ppr on + ! + + rt21: + links: + lo: + mpls: yes + eth-rt11: + peer: [rt11, eth-rt21] + mpls: yes + eth-rt12: + peer: [rt12, eth-rt21] + mpls: yes + eth-rt22: + peer: [rt22, eth-rt21] + mpls: yes + eth-rt31: + peer: [rt31, eth-rt21] + mpls: yes + eth-rt32: + peer: [rt32, eth-rt21] + mpls: yes + frr: + zebra: + isisd: + config: | + interface lo + ip address 10.0.0.21/32 + ipv6 address 5000::21/128 + ipv6 router isis 1 + ! + interface eth-rt11 + ipv6 address 4000:104::21/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt12 + ipv6 address 4000:105::21/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt22 + ipv6 address 4000:110::21/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt31 + ipv6 address 4000:112::21/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt32 + ipv6 address 4000:113::21/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + router isis 1 + net 49.0000.0000.0000.0021.00 + is-type level-1 + topology ipv6-unicast + segment-routing on + segment-routing prefix 5000::21/128 index 21 no-php-flag + ppr on + ! + + rt22: + links: + lo: + mpls: yes + eth-rt12: + peer: [rt12, eth-rt22] + mpls: yes + eth-rt13: + peer: [rt13, eth-rt22] + mpls: yes + eth-rt21: + peer: [rt21, eth-rt22] + mpls: yes + eth-rt23: + peer: [rt23, eth-rt22] + mpls: yes + eth-rt32: + peer: [rt32, eth-rt22] + mpls: yes + eth-rt33: + mpls: yes + peer: [rt33, eth-rt22] + frr: + zebra: + isisd: + config: | + interface lo + ip address 10.0.0.22/32 + ipv6 address 5000::22/128 + ipv6 router isis 1 + ! + interface eth-rt12 + ipv6 address 4000:106::22/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt13 + ipv6 address 4000:107::22/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt21 + ipv6 address 4000:110::22/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt23 + ipv6 address 4000:111::22/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt32 + ipv6 address 4000:114::22/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt33 + ipv6 address 4000:115::22/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + router isis 1 + net 49.0000.0000.0000.0022.00 + is-type level-1 + topology ipv6-unicast + segment-routing on + segment-routing prefix 5000::22/128 index 22 no-php-flag + ppr on + ! + + rt23: + links: + lo: + mpls: yes + eth-rt13: + peer: [rt13, eth-rt23] + mpls: yes + eth-rt14: + peer: [rt14, eth-rt23] + mpls: yes + eth-rt22: + peer: [rt22, eth-rt23] + mpls: yes + eth-rt33: + peer: [rt33, eth-rt23] + mpls: yes + eth-rt34: + peer: [rt34, eth-rt23] + mpls: yes + frr: + zebra: + isisd: + config: | + interface lo + ip address 10.0.0.23/32 + ipv6 address 5000::23/128 + ipv6 router isis 1 + ! + interface eth-rt13 + ipv6 address 4000:108::23/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt14 + ipv6 address 4000:109::23/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt22 + ipv6 address 4000:111::23/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt33 + ipv6 address 4000:116::23/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt34 + ipv6 address 4000:117::23/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + router isis 1 + net 49.0000.0000.0000.0023.00 + is-type level-1 + topology ipv6-unicast + segment-routing on + segment-routing global-block 20000 27999 + segment-routing prefix 5000::23/128 index 23 no-php-flag + ppr on + ! + + rt31: + links: + lo: + mpls: yes + eth-rt21: + peer: [rt21, eth-rt31] + mpls: yes + eth-rt32: + peer: [rt32, eth-rt31] + mpls: yes + frr: + zebra: + isisd: + config: | + interface lo + ip address 10.0.0.31/32 + ipv6 address 5000::31/128 + ipv6 router isis 1 + ! + interface eth-rt21 + ipv6 address 4000:112::31/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt32 + ipv6 address 4000:118::31/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + router isis 1 + net 49.0000.0000.0000.0031.00 + is-type level-1 + topology ipv6-unicast + segment-routing on + segment-routing prefix 5000::31/128 index 31 no-php-flag + ppr on + ! + + rt32: + links: + lo: + mpls: yes + eth-rt21: + peer: [rt21, eth-rt32] + mpls: yes + eth-rt22: + peer: [rt22, eth-rt32] + mpls: yes + eth-rt31: + peer: [rt31, eth-rt32] + mpls: yes + eth-rt33: + peer: [rt33, eth-rt32] + mpls: yes + eth-sw1: + peer: [sw1, eth-rt32] + mpls: yes + frr: + zebra: + isisd: + config: | + interface lo + ip address 10.0.0.32/32 + ipv6 address 5000::32/128 + ipv6 router isis 1 + ! + interface eth-rt21 + ipv6 address 4000:113::32/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt22 + ipv6 address 4000:114::32/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt31 + ipv6 address 4000:118::32/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt33 + ipv6 address 4000:119::32/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-sw1 + ipv6 address 4000:121::32/64 + ipv6 router isis 1 + isis hello-multiplier 3 + ! + router isis 1 + net 49.0000.0000.0000.0032.00 + is-type level-1 + topology ipv6-unicast + segment-routing on + segment-routing prefix 5000::32/128 index 32 no-php-flag + ppr on + ! + + rt33: + links: + lo: + mpls: yes + eth-rt22: + peer: [rt22, eth-rt33] + mpls: yes + eth-rt23: + peer: [rt23, eth-rt33] + mpls: yes + eth-rt32: + peer: [rt32, eth-rt33] + mpls: yes + eth-rt34: + peer: [rt34, eth-rt33] + mpls: yes + eth-sw1: + peer: [sw1, eth-rt33] + mpls: yes + frr: + zebra: + isisd: + config: | + interface lo + ip address 10.0.0.33/32 + ipv6 address 5000::33/128 + ipv6 router isis 1 + ! + interface eth-rt22 + ipv6 address 4000:115::33/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt23 + ipv6 address 4000:116::33/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt32 + ipv6 address 4000:119::33/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt34 + ipv6 address 4000:120::33/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-sw1 + ipv6 address 4000:121::33/64 + ipv6 router isis 1 + isis hello-multiplier 3 + ! + router isis 1 + net 49.0000.0000.0000.0033.00 + is-type level-1 + topology ipv6-unicast + segment-routing on + segment-routing prefix 5000::33/128 index 33 no-php-flag + ppr on + ! + + rt34: + links: + lo: + mpls: yes + eth-rt23: + peer: [rt23, eth-rt34] + mpls: yes + eth-rt33: + peer: [rt33, eth-rt34] + mpls: yes + frr: + zebra: + isisd: + config: | + interface lo + ip address 10.0.0.34/32 + ipv6 address 5000::34/128 + ipv6 router isis 1 + ! + interface eth-rt23 + ipv6 address 4000:117::34/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + interface eth-rt33 + ipv6 address 4000:120::34/64 + ipv6 router isis 1 + isis network point-to-point + isis hello-multiplier 3 + ! + router isis 1 + net 49.0000.0000.0000.0034.00 + is-type level-1 + topology ipv6-unicast + segment-routing on + segment-routing prefix 5000::34/128 index 34 no-php-flag + ppr on + ! + + rt41: + links: + lo: + mpls: yes + eth-sw1: + peer: [sw1, eth-rt41] + mpls: yes + frr: + zebra: + isisd: + config: | + interface lo + ip address 10.0.0.41/32 + ipv6 address 5000::41/128 + ipv6 router isis 1 + ! + interface eth-sw1 + ipv6 address 4000:121::41/64 + ipv6 router isis 1 + isis hello-multiplier 3 + ! + router isis 1 + net 49.0000.0000.0000.0041.00 + is-type level-1 + topology ipv6-unicast + segment-routing on + segment-routing prefix 5000::41/128 index 41 no-php-flag + ppr on + ! + + switches: + sw1: + links: + eth-rt32: + peer: [rt32, eth-sw1] + eth-rt33: + peer: [rt33, eth-sw1] + eth-rt41: + peer: [rt41, eth-sw1] + + frr: + #valgrind: yes + base-config: | + hostname %(node) + password 1 + log file %(logdir)/%(node).log + log commands + ! + debug zebra rib + debug isis sr-events + debug isis ppr + debug isis events + debug isis route-events + debug isis spf-events + debug isis lsp-gen + ! + +.. + + NOTE: it’s of fundamental importance to enable MPLS processing on the + loopback interfaces, otherwise the tail-end routers of the PPR-MPLS + tunnels will drop the labeled packets they receive. + +YANG +^^^^ + +PPR can also be configured using NETCONF, RESTCONF and gRPC based on the +following YANG models: \* +`frr-ppr.yang <https://github.com/opensourcerouting/frr/blob/isisd-ppr/yang/frr-ppr.yang>`__ +\* +`frr-isisd.yang <https://github.com/opensourcerouting/frr/blob/isisd-ppr/yang/frr-isisd.yang>`__ + +As an example, here’s R11 configuration in the XML format: + +.. code:: xml + + <lib xmlns="http://frrouting.org/yang/interface"> + <interface> + <name>lo-ppr</name> + <vrf>default</vrf> + </interface> + <interface> + <name>lo</name> + <vrf>default</vrf> + <isis xmlns="http://frrouting.org/yang/isisd"> + <area-tag>1</area-tag> + <ipv6-routing>true</ipv6-routing> + </isis> + </interface> + <interface> + <name>eth-ce1</name> + <vrf>default</vrf> + </interface> + <interface> + <name>eth-rt12</name> + <vrf>default</vrf> + <isis xmlns="http://frrouting.org/yang/isisd"> + <area-tag>1</area-tag> + <ipv6-routing>true</ipv6-routing> + <hello> + <multiplier> + <level-1>3</level-1> + <level-2>3</level-2> + </multiplier> + </hello> + <network-type>point-to-point</network-type> + </isis> + </interface> + <interface> + <name>eth-rt21</name> + <vrf>default</vrf> + <isis xmlns="http://frrouting.org/yang/isisd"> + <area-tag>1</area-tag> + <ipv6-routing>true</ipv6-routing> + <hello> + <multiplier> + <level-1>3</level-1> + <level-2>3</level-2> + </multiplier> + </hello> + <network-type>point-to-point</network-type> + </isis> + </interface> + </lib> + <ppr xmlns="http://frrouting.org/yang/ppr"> + <group> + <name>PPR_IPV6</name> + <ipv6> + <ppr-id>6000:1::1/128</ppr-id> + <ppr-prefix>5000::11/128</ppr-prefix> + <ppr-pde> + <pde-id>5000::14/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::23/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::22/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::21/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::11/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <attributes> + <ppr-metric>50</ppr-metric> + </attributes> + </ipv6> + <ipv6> + <ppr-id>6000:2::1/128</ppr-id> + <ppr-prefix>5000::14/128</ppr-prefix> + <ppr-pde> + <pde-id>5000::11/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::21/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::22/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::23/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>5000::14/128</pde-id> + <pde-id-type>ipv6-node</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <attributes> + <ppr-metric>50</ppr-metric> + </attributes> + </ipv6> + </group> + <group> + <name>PPR_MPLS_1</name> + <mpls> + <ppr-id>500</ppr-id> + <ppr-prefix>5000::11/128</ppr-prefix> + <ppr-pde> + <pde-id>14</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>23</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>22</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>21</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>11</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + </mpls> + <mpls> + <ppr-id>501</ppr-id> + <ppr-prefix>5000::14/128</ppr-prefix> + <ppr-pde> + <pde-id>11</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>21</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>22</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>23</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>14</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + </mpls> + </group> + <group> + <name>PPR_MPLS_2</name> + <mpls> + <ppr-id>502</ppr-id> + <ppr-prefix>5000::11/128</ppr-prefix> + <ppr-pde> + <pde-id>14</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>23</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>34</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>33</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>41</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>32</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>31</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>21</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>11</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + </mpls> + <mpls> + <ppr-id>503</ppr-id> + <ppr-prefix>5000::14/128</ppr-prefix> + <ppr-pde> + <pde-id>11</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>21</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>31</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>32</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>41</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>33</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>34</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>23</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + <ppr-pde> + <pde-id>14</pde-id> + <pde-id-type>prefix-sid</pde-id-type> + <pde-type>topological</pde-type> + </ppr-pde> + </mpls> + </group> + </ppr> + <isis xmlns="http://frrouting.org/yang/isisd"> + <instance> + <area-tag>1</area-tag> + <area-address>49.0000.0000.0000.0011.00</area-address> + <multi-topology> + <ipv6-unicast> + </ipv6-unicast> + </multi-topology> + <segment-routing> + <enabled>true</enabled> + <prefix-sid-map> + <prefix-sid> + <prefix>5000::11/128</prefix> + <sid-value>11</sid-value> + <last-hop-behavior>no-php</last-hop-behavior> + </prefix-sid> + </prefix-sid-map> + </segment-routing> + <ppr> + <enable>true</enable> + <ppr-advertise> + <name>PPR_IPV6</name> + </ppr-advertise> + <ppr-advertise> + <name>PPR_MPLS_1</name> + </ppr-advertise> + <ppr-advertise> + <name>PPR_MPLS_2</name> + </ppr-advertise> + </ppr> + </instance> + </isis> + +Verification - Control Plane +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Verify that R11 has flooded the PPR TLVs correctly to all IS-IS routers: + +:: + + # show isis database detail 0000.0000.0011 + Area 1: + IS-IS Level-1 link-state database: + LSP ID PduLen SeqNumber Chksum Holdtime ATT/P/OL + debian.00-00 * 980 0x00000003 0x3b69 894 0/0/0 + Protocols Supported: IPv4, IPv6 + Area Address: 49.0000 + MT Router Info: ipv4-unicast + MT Router Info: ipv6-unicast + Hostname: debian + TE Router ID: 10.0.0.11 + Router Capability: 10.0.0.11 , D:0, S:0 + Segment Routing: I:1 V:1, SRGB Base: 16000 Range: 8000 + Algorithm: 0: SPF 0: Strict SPF + MT Reachability: 0000.0000.0012.00 (Metric: 10) ipv6-unicast + Adjacency-SID: 16, Weight: 0, Flags: F:1 B:0, V:1, L:1, S:0, P:0 + MT Reachability: 0000.0000.0021.00 (Metric: 10) ipv6-unicast + Adjacency-SID: 17, Weight: 0, Flags: F:1 B:0, V:1, L:1, S:0, P:0 + IPv4 Interface Address: 10.0.0.11 + Extended IP Reachability: 10.0.0.11/32 (Metric: 10) + MT IPv6 Reachability: 5000::11/128 (Metric: 10) ipv6-unicast + Subtlvs: + SR Prefix-SID Index: 11, Algorithm: 0, Flags: NO-PHP + MT IPv6 Reachability: 4000:101::/64 (Metric: 10) ipv6-unicast + MT IPv6 Reachability: 4000:104::/64 (Metric: 10) ipv6-unicast + PPR: Fragment ID: 0, MT-ID: ipv4-unicast, Algorithm: SPF, F:0 D:0 A:0 U:1 + PPR Prefix: 5000::11/128 + ID: 6000:1::1/128 (Native IPv6) + PDE: 5000::14/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::23/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::22/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::21/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::11/128 (IPv6 Node Address), L:0 N:1 E:0 + Metric: 50 + PPR: Fragment ID: 0, MT-ID: ipv4-unicast, Algorithm: SPF, F:0 D:0 A:0 U:1 + PPR Prefix: 5000::14/128 + ID: 6000:2::1/128 (Native IPv6) + PDE: 5000::11/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::21/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::22/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::23/128 (IPv6 Node Address), L:0 N:0 E:0 + PDE: 5000::14/128 (IPv6 Node Address), L:0 N:1 E:0 + Metric: 50 + PPR: Fragment ID: 0, MT-ID: ipv4-unicast, Algorithm: SPF, F:0 D:0 A:0 U:1 + PPR Prefix: 5000::11/128 + ID: 500 (MPLS) + PDE: 14 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 23 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 22 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 21 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 11 (SR-MPLS Prefix SID), L:0 N:1 E:0 + PPR: Fragment ID: 0, MT-ID: ipv4-unicast, Algorithm: SPF, F:0 D:0 A:0 U:1 + PPR Prefix: 5000::14/128 + ID: 501 (MPLS) + PDE: 11 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 21 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 22 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 23 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 14 (SR-MPLS Prefix SID), L:0 N:1 E:0 + PPR: Fragment ID: 0, MT-ID: ipv4-unicast, Algorithm: SPF, F:0 D:0 A:0 U:1 + PPR Prefix: 5000::11/128 + ID: 502 (MPLS) + PDE: 14 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 23 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 34 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 33 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 41 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 32 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 31 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 21 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 11 (SR-MPLS Prefix SID), L:0 N:1 E:0 + PPR: Fragment ID: 0, MT-ID: ipv4-unicast, Algorithm: SPF, F:0 D:0 A:0 U:1 + PPR Prefix: 5000::14/128 + ID: 503 (MPLS) + PDE: 11 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 21 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 31 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 32 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 41 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 33 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 34 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 23 (SR-MPLS Prefix SID), L:0 N:0 E:0 + PDE: 14 (SR-MPLS Prefix SID), L:0 N:1 E:0 + +Using the ``show isis ppr`` command, verify that all routers installed +the PPR-IDs for the paths they are part of. Example: + +Router RT11 +^^^^^^^^^^^ + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + -------------------------------------------------------------------------------------------- + 1 L1 500 (MPLS) 5000::11/128 0 Tail-End Up 00:00:42 + 1 L1 501 (MPLS) 5000::14/128 0 Head-End Up 00:00:41 + 1 L1 502 (MPLS) 5000::11/128 0 Tail-End Up 00:00:42 + 1 L1 503 (MPLS) 5000::14/128 0 Head-End Up 00:00:41 + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Tail-End - - + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Head-End Up 00:00:41 + + # show mpls table + Inbound Label Type Nexthop Outbound Label + ----------------------------------------------------------------------- + 16 SR (IS-IS) fe80::2065:5ff:fe72:d6c5 implicit-null + 17 SR (IS-IS) fe80::345f:dfff:fea4:913d implicit-null + 16011 SR (IS-IS) lo - + 16012 SR (IS-IS) fe80::2065:5ff:fe72:d6c5 16012 + 16013 SR (IS-IS) fe80::2065:5ff:fe72:d6c5 16013 + 16014 SR (IS-IS) fe80::2065:5ff:fe72:d6c5 16014 + 16021 SR (IS-IS) fe80::345f:dfff:fea4:913d 16021 + 16022 SR (IS-IS) fe80::345f:dfff:fea4:913d 16022 + 16022 SR (IS-IS) fe80::2065:5ff:fe72:d6c5 16022 + 16023 SR (IS-IS) fe80::345f:dfff:fea4:913d 16023 + 16023 SR (IS-IS) fe80::2065:5ff:fe72:d6c5 16023 + 16031 SR (IS-IS) fe80::345f:dfff:fea4:913d 16031 + 16032 SR (IS-IS) fe80::345f:dfff:fea4:913d 16032 + 16033 SR (IS-IS) fe80::345f:dfff:fea4:913d 16033 + 16033 SR (IS-IS) fe80::2065:5ff:fe72:d6c5 16033 + 16034 SR (IS-IS) fe80::345f:dfff:fea4:913d 16034 + 16034 SR (IS-IS) fe80::2065:5ff:fe72:d6c5 16034 + 16041 SR (IS-IS) fe80::345f:dfff:fea4:913d 16041 + 16500 PPR (IS-IS) lo - + 16501 PPR (IS-IS) fe80::345f:dfff:fea4:913d 16501 + 16502 PPR (IS-IS) lo - + 16503 PPR (IS-IS) fe80::345f:dfff:fea4:913d 16503 + + # show ipv6 route 6000::/16 longer-prefixes isis + Codes: K - kernel route, C - connected, S - static, R - RIPng, + O - OSPFv3, I - IS-IS, B - BGP, N - NHRP, T - Table, + v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, + f - OpenFabric, + > - selected route, * - FIB route, q - queued route, r - rejected route + + I>* 6000:2::1/128 [115/50] via fe80::345f:dfff:fea4:913d, eth-rt21, 00:00:41 + +Router RT12 +^^^^^^^^^^^ + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + ------------------------------------------------------------------------------------------ + 1 L1 500 (MPLS) 5000::11/128 0 Off-Path - - + 1 L1 501 (MPLS) 5000::14/128 0 Off-Path - - + 1 L1 502 (MPLS) 5000::11/128 0 Off-Path - - + 1 L1 503 (MPLS) 5000::14/128 0 Off-Path - - + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Off-Path - - + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Off-Path - - + + # show mpls table + Inbound Label Type Nexthop Outbound Label + ---------------------------------------------------------------------- + 16 SR (IS-IS) fe80::60ad:96ff:fe3f:9989 implicit-null + 17 SR (IS-IS) fe80::9cd2:25ff:febc:84c4 implicit-null + 18 SR (IS-IS) fe80::941c:12ff:fe55:8a12 implicit-null + 19 SR (IS-IS) fe80::78a7:59ff:fedc:48b8 implicit-null + 16011 SR (IS-IS) fe80::60ad:96ff:fe3f:9989 16011 + 16012 SR (IS-IS) lo - + 16013 SR (IS-IS) fe80::9cd2:25ff:febc:84c4 16013 + 16014 SR (IS-IS) fe80::9cd2:25ff:febc:84c4 16014 + 16021 SR (IS-IS) fe80::941c:12ff:fe55:8a12 16021 + 16022 SR (IS-IS) fe80::78a7:59ff:fedc:48b8 16022 + 16023 SR (IS-IS) fe80::78a7:59ff:fedc:48b8 16023 + 16023 SR (IS-IS) fe80::9cd2:25ff:febc:84c4 16023 + 16031 SR (IS-IS) fe80::941c:12ff:fe55:8a12 16031 + 16032 SR (IS-IS) fe80::78a7:59ff:fedc:48b8 16032 + 16032 SR (IS-IS) fe80::941c:12ff:fe55:8a12 16032 + 16033 SR (IS-IS) fe80::78a7:59ff:fedc:48b8 16033 + 16034 SR (IS-IS) fe80::78a7:59ff:fedc:48b8 16034 + 16034 SR (IS-IS) fe80::9cd2:25ff:febc:84c4 16034 + 16041 SR (IS-IS) fe80::78a7:59ff:fedc:48b8 16041 + 16041 SR (IS-IS) fe80::941c:12ff:fe55:8a12 16041 + + # show ipv6 route 6000::/16 longer-prefixes isis + +Router RT13 +^^^^^^^^^^^ + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + ------------------------------------------------------------------------------------------ + 1 L1 500 (MPLS) 5000::11/128 0 Off-Path - - + 1 L1 501 (MPLS) 5000::14/128 0 Off-Path - - + 1 L1 502 (MPLS) 5000::11/128 0 Off-Path - - + 1 L1 503 (MPLS) 5000::14/128 0 Off-Path - - + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Off-Path - - + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Off-Path - - + + # show mpls table + Inbound Label Type Nexthop Outbound Label + ---------------------------------------------------------------------- + 16 SR (IS-IS) fe80::1c70:63ff:fe40:3a35 implicit-null + 17 SR (IS-IS) fe80::20:56ff:feff:b218 implicit-null + 18 SR (IS-IS) fe80::44c5:3fff:fe1e:f34a implicit-null + 19 SR (IS-IS) fe80::387d:34ff:fe02:87c3 implicit-null + 16011 SR (IS-IS) fe80::20:56ff:feff:b218 16011 + 16012 SR (IS-IS) fe80::20:56ff:feff:b218 16012 + 16013 SR (IS-IS) lo - + 16014 SR (IS-IS) fe80::1c70:63ff:fe40:3a35 16014 + 16021 SR (IS-IS) fe80::387d:34ff:fe02:87c3 16021 + 16021 SR (IS-IS) fe80::20:56ff:feff:b218 16021 + 16022 SR (IS-IS) fe80::387d:34ff:fe02:87c3 16022 + 16023 SR (IS-IS) fe80::44c5:3fff:fe1e:f34a 20023 + 16031 SR (IS-IS) fe80::387d:34ff:fe02:87c3 16031 + 16031 SR (IS-IS) fe80::20:56ff:feff:b218 16031 + 16032 SR (IS-IS) fe80::387d:34ff:fe02:87c3 16032 + 16033 SR (IS-IS) fe80::44c5:3fff:fe1e:f34a 20033 + 16033 SR (IS-IS) fe80::387d:34ff:fe02:87c3 16033 + 16034 SR (IS-IS) fe80::44c5:3fff:fe1e:f34a 20034 + 16041 SR (IS-IS) fe80::44c5:3fff:fe1e:f34a 20041 + 16041 SR (IS-IS) fe80::387d:34ff:fe02:87c3 16041 + + # show ipv6 route 6000::/16 longer-prefixes isis + +Router RT14 +^^^^^^^^^^^ + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + -------------------------------------------------------------------------------------------- + 1 L1 500 (MPLS) 5000::11/128 0 Head-End Up 00:00:46 + 1 L1 501 (MPLS) 5000::14/128 0 Tail-End Up 00:00:47 + 1 L1 502 (MPLS) 5000::11/128 0 Head-End Up 00:00:46 + 1 L1 503 (MPLS) 5000::14/128 0 Tail-End Up 00:00:47 + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Head-End Up 00:00:46 + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Tail-End - - + + # show mpls table + Inbound Label Type Nexthop Outbound Label + ----------------------------------------------------------------------- + 16 SR (IS-IS) fe80::bcb5:99ff:fed7:22ad implicit-null + 17 SR (IS-IS) fe80::4c7b:a1ff:fe66:6ca7 implicit-null + 16011 SR (IS-IS) fe80::bcb5:99ff:fed7:22ad 16011 + 16012 SR (IS-IS) fe80::bcb5:99ff:fed7:22ad 16012 + 16013 SR (IS-IS) fe80::bcb5:99ff:fed7:22ad 16013 + 16014 SR (IS-IS) lo - + 16021 SR (IS-IS) fe80::4c7b:a1ff:fe66:6ca7 20021 + 16021 SR (IS-IS) fe80::bcb5:99ff:fed7:22ad 16021 + 16022 SR (IS-IS) fe80::4c7b:a1ff:fe66:6ca7 20022 + 16022 SR (IS-IS) fe80::bcb5:99ff:fed7:22ad 16022 + 16023 SR (IS-IS) fe80::4c7b:a1ff:fe66:6ca7 20023 + 16031 SR (IS-IS) fe80::4c7b:a1ff:fe66:6ca7 20031 + 16031 SR (IS-IS) fe80::bcb5:99ff:fed7:22ad 16031 + 16032 SR (IS-IS) fe80::4c7b:a1ff:fe66:6ca7 20032 + 16032 SR (IS-IS) fe80::bcb5:99ff:fed7:22ad 16032 + 16033 SR (IS-IS) fe80::4c7b:a1ff:fe66:6ca7 20033 + 16034 SR (IS-IS) fe80::4c7b:a1ff:fe66:6ca7 20034 + 16041 SR (IS-IS) fe80::4c7b:a1ff:fe66:6ca7 20041 + 16500 PPR (IS-IS) fe80::4c7b:a1ff:fe66:6ca7 20500 + 16501 PPR (IS-IS) lo - + 16502 PPR (IS-IS) fe80::4c7b:a1ff:fe66:6ca7 20502 + 16503 PPR (IS-IS) lo - + + # show ipv6 route 6000::/16 longer-prefixes isis + Codes: K - kernel route, C - connected, S - static, R - RIPng, + O - OSPFv3, I - IS-IS, B - BGP, N - NHRP, T - Table, + v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, + f - OpenFabric, + > - selected route, * - FIB route, q - queued route, r - rejected route + + I>* 6000:1::1/128 [115/50] via fe80::4c7b:a1ff:fe66:6ca7, eth-rt23, 00:00:02 + +Router RT21 +^^^^^^^^^^^ + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + --------------------------------------------------------------------------------------------- + 1 L1 500 (MPLS) 5000::11/128 0 Mid-Point Up 00:00:49 + 1 L1 501 (MPLS) 5000::14/128 0 Mid-Point Up 00:00:48 + 1 L1 502 (MPLS) 5000::11/128 0 Mid-Point Up 00:00:49 + 1 L1 503 (MPLS) 5000::14/128 0 Mid-Point Up 00:00:48 + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Mid-Point Up 00:00:49 + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Mid-Point Up 00:00:48 + + # show mpls table + Inbound Label Type Nexthop Outbound Label + ----------------------------------------------------------------------- + 16 SR (IS-IS) fe80::b886:2cff:fe84:a76f implicit-null + 17 SR (IS-IS) fe80::bc7e:bbff:fe7f:ecb0 implicit-null + 18 SR (IS-IS) fe80::e877:a2ff:feb7:4438 implicit-null + 19 SR (IS-IS) fe80::a0c2:82ff:fe39:204c implicit-null + 20 SR (IS-IS) fe80::ac6a:8aff:fe14:4f36 implicit-null + 16011 SR (IS-IS) fe80::e877:a2ff:feb7:4438 16011 + 16012 SR (IS-IS) fe80::a0c2:82ff:fe39:204c 16012 + 16013 SR (IS-IS) fe80::ac6a:8aff:fe14:4f36 16013 + 16013 SR (IS-IS) fe80::a0c2:82ff:fe39:204c 16013 + 16014 SR (IS-IS) fe80::ac6a:8aff:fe14:4f36 16014 + 16014 SR (IS-IS) fe80::a0c2:82ff:fe39:204c 16014 + 16021 SR (IS-IS) lo - + 16022 SR (IS-IS) fe80::ac6a:8aff:fe14:4f36 16022 + 16023 SR (IS-IS) fe80::ac6a:8aff:fe14:4f36 16023 + 16031 SR (IS-IS) fe80::bc7e:bbff:fe7f:ecb0 16031 + 16032 SR (IS-IS) fe80::b886:2cff:fe84:a76f 16032 + 16033 SR (IS-IS) fe80::b886:2cff:fe84:a76f 16033 + 16033 SR (IS-IS) fe80::ac6a:8aff:fe14:4f36 16033 + 16034 SR (IS-IS) fe80::b886:2cff:fe84:a76f 16034 + 16034 SR (IS-IS) fe80::ac6a:8aff:fe14:4f36 16034 + 16041 SR (IS-IS) fe80::b886:2cff:fe84:a76f 16041 + 16500 PPR (IS-IS) fe80::e877:a2ff:feb7:4438 16500 + 16501 PPR (IS-IS) fe80::ac6a:8aff:fe14:4f36 16501 + 16502 PPR (IS-IS) fe80::e877:a2ff:feb7:4438 16502 + 16503 PPR (IS-IS) fe80::bc7e:bbff:fe7f:ecb0 16503 + + # show ipv6 route 6000::/16 longer-prefixes isis + Codes: K - kernel route, C - connected, S - static, R - RIPng, + O - OSPFv3, I - IS-IS, B - BGP, N - NHRP, T - Table, + v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, + f - OpenFabric, + > - selected route, * - FIB route, q - queued route, r - rejected route + + I>* 6000:1::1/128 [115/50] via fe80::e877:a2ff:feb7:4438, eth-rt11, 00:00:04 + I>* 6000:2::1/128 [115/50] via fe80::ac6a:8aff:fe14:4f36, eth-rt22, 00:00:04 + +Router RT22 +^^^^^^^^^^^ + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + --------------------------------------------------------------------------------------------- + 1 L1 500 (MPLS) 5000::11/128 0 Mid-Point Up 00:00:50 + 1 L1 501 (MPLS) 5000::14/128 0 Mid-Point Up 00:00:50 + 1 L1 502 (MPLS) 5000::11/128 0 Off-Path - - + 1 L1 503 (MPLS) 5000::14/128 0 Off-Path - - + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Mid-Point Up 00:00:50 + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Mid-Point Up 00:00:50 + + # show mpls table + Inbound Label Type Nexthop Outbound Label + ----------------------------------------------------------------------- + 16 SR (IS-IS) fe80::3432:84ff:fe9d:2e41 implicit-null + 17 SR (IS-IS) fe80::c436:63ff:feb3:4f5d implicit-null + 18 SR (IS-IS) fe80::56:41ff:fe53:a6b2 implicit-null + 19 SR (IS-IS) fe80::b423:eaff:fea1:8247 implicit-null + 20 SR (IS-IS) fe80::9c2f:11ff:fe0a:ab34 implicit-null + 21 SR (IS-IS) fe80::7402:b8ff:fee9:682e implicit-null + 16011 SR (IS-IS) fe80::b423:eaff:fea1:8247 16011 + 16011 SR (IS-IS) fe80::3432:84ff:fe9d:2e41 16011 + 16012 SR (IS-IS) fe80::3432:84ff:fe9d:2e41 16012 + 16013 SR (IS-IS) fe80::c436:63ff:feb3:4f5d 16013 + 16014 SR (IS-IS) fe80::56:41ff:fe53:a6b2 20014 + 16014 SR (IS-IS) fe80::c436:63ff:feb3:4f5d 16014 + 16021 SR (IS-IS) fe80::b423:eaff:fea1:8247 16021 + 16022 SR (IS-IS) lo - + 16023 SR (IS-IS) fe80::56:41ff:fe53:a6b2 20023 + 16031 SR (IS-IS) fe80::9c2f:11ff:fe0a:ab34 16031 + 16031 SR (IS-IS) fe80::b423:eaff:fea1:8247 16031 + 16032 SR (IS-IS) fe80::9c2f:11ff:fe0a:ab34 16032 + 16033 SR (IS-IS) fe80::7402:b8ff:fee9:682e 16033 + 16034 SR (IS-IS) fe80::7402:b8ff:fee9:682e 16034 + 16034 SR (IS-IS) fe80::56:41ff:fe53:a6b2 20034 + 16041 SR (IS-IS) fe80::7402:b8ff:fee9:682e 16041 + 16041 SR (IS-IS) fe80::9c2f:11ff:fe0a:ab34 16041 + 16500 PPR (IS-IS) fe80::b423:eaff:fea1:8247 16500 + 16501 PPR (IS-IS) fe80::56:41ff:fe53:a6b2 20501 + + # show ipv6 route 6000::/16 longer-prefixes isis + Codes: K - kernel route, C - connected, S - static, R - RIPng, + O - OSPFv3, I - IS-IS, B - BGP, N - NHRP, T - Table, + v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, + f - OpenFabric, + > - selected route, * - FIB route, q - queued route, r - rejected route + + I>* 6000:1::1/128 [115/50] via fe80::b423:eaff:fea1:8247, eth-rt21, 00:00:06 + I>* 6000:2::1/128 [115/50] via fe80::56:41ff:fe53:a6b2, eth-rt23, 00:00:06 + +Router RT23 +^^^^^^^^^^^ + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + --------------------------------------------------------------------------------------------- + 1 L1 500 (MPLS) 5000::11/128 0 Mid-Point Up 00:00:52 + 1 L1 501 (MPLS) 5000::14/128 0 Mid-Point Up 00:00:52 + 1 L1 502 (MPLS) 5000::11/128 0 Mid-Point Up 00:00:52 + 1 L1 503 (MPLS) 5000::14/128 0 Mid-Point Up 00:00:52 + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Mid-Point Up 00:00:52 + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Mid-Point Up 00:00:52 + + # show mpls table + Inbound Label Type Nexthop Outbound Label + ----------------------------------------------------------------------- + 16 SR (IS-IS) fe80::c4ca:41ff:fe2d:de8c implicit-null + 17 SR (IS-IS) fe80::a02b:1eff:fed6:97e4 implicit-null + 18 SR (IS-IS) fe80::5c15:8aff:feea:1d07 implicit-null + 19 SR (IS-IS) fe80::a42f:50ff:fe9c:af9f implicit-null + 20 SR (IS-IS) fe80::d0dc:6eff:fe71:9f19 implicit-null + 20011 SR (IS-IS) fe80::5c15:8aff:feea:1d07 16011 + 20011 SR (IS-IS) fe80::a02b:1eff:fed6:97e4 16011 + 20012 SR (IS-IS) fe80::5c15:8aff:feea:1d07 16012 + 20012 SR (IS-IS) fe80::a02b:1eff:fed6:97e4 16012 + 20013 SR (IS-IS) fe80::a02b:1eff:fed6:97e4 16013 + 20014 SR (IS-IS) fe80::c4ca:41ff:fe2d:de8c 16014 + 20021 SR (IS-IS) fe80::5c15:8aff:feea:1d07 16021 + 20022 SR (IS-IS) fe80::5c15:8aff:feea:1d07 16022 + 20023 SR (IS-IS) lo - + 20031 SR (IS-IS) fe80::a42f:50ff:fe9c:af9f 16031 + 20031 SR (IS-IS) fe80::5c15:8aff:feea:1d07 16031 + 20032 SR (IS-IS) fe80::a42f:50ff:fe9c:af9f 16032 + 20032 SR (IS-IS) fe80::5c15:8aff:feea:1d07 16032 + 20033 SR (IS-IS) fe80::a42f:50ff:fe9c:af9f 16033 + 20034 SR (IS-IS) fe80::d0dc:6eff:fe71:9f19 16034 + 20041 SR (IS-IS) fe80::a42f:50ff:fe9c:af9f 16041 + 20500 PPR (IS-IS) fe80::5c15:8aff:feea:1d07 16500 + 20501 PPR (IS-IS) fe80::c4ca:41ff:fe2d:de8c 16501 + 20502 PPR (IS-IS) fe80::d0dc:6eff:fe71:9f19 16502 + 20503 PPR (IS-IS) fe80::c4ca:41ff:fe2d:de8c 16503 + + # show ipv6 route 6000::/16 longer-prefixes isis + Codes: K - kernel route, C - connected, S - static, R - RIPng, + O - OSPFv3, I - IS-IS, B - BGP, N - NHRP, T - Table, + v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, + f - OpenFabric, + > - selected route, * - FIB route, q - queued route, r - rejected route + + I>* 6000:1::1/128 [115/50] via fe80::5c15:8aff:feea:1d07, eth-rt22, 00:00:07 + I>* 6000:2::1/128 [115/50] via fe80::c4ca:41ff:fe2d:de8c, eth-rt14, 00:00:07 + +Router RT31 +^^^^^^^^^^^ + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + --------------------------------------------------------------------------------------------- + 1 L1 500 (MPLS) 5000::11/128 0 Off-Path - - + 1 L1 501 (MPLS) 5000::14/128 0 Off-Path - - + 1 L1 502 (MPLS) 5000::11/128 0 Mid-Point Up 00:00:54 + 1 L1 503 (MPLS) 5000::14/128 0 Mid-Point Up 00:00:54 + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Off-Path - - + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Off-Path - - + + # show mpls table + Inbound Label Type Nexthop Outbound Label + ----------------------------------------------------------------------- + 16 SR (IS-IS) fe80::a067:c6ff:fe2c:3385 implicit-null + 17 SR (IS-IS) fe80::f46d:c8ff:fe8a:a341 implicit-null + 16011 SR (IS-IS) fe80::a067:c6ff:fe2c:3385 16011 + 16012 SR (IS-IS) fe80::a067:c6ff:fe2c:3385 16012 + 16013 SR (IS-IS) fe80::f46d:c8ff:fe8a:a341 16013 + 16013 SR (IS-IS) fe80::a067:c6ff:fe2c:3385 16013 + 16014 SR (IS-IS) fe80::f46d:c8ff:fe8a:a341 16014 + 16014 SR (IS-IS) fe80::a067:c6ff:fe2c:3385 16014 + 16021 SR (IS-IS) fe80::a067:c6ff:fe2c:3385 16021 + 16022 SR (IS-IS) fe80::f46d:c8ff:fe8a:a341 16022 + 16022 SR (IS-IS) fe80::a067:c6ff:fe2c:3385 16022 + 16023 SR (IS-IS) fe80::f46d:c8ff:fe8a:a341 16023 + 16023 SR (IS-IS) fe80::a067:c6ff:fe2c:3385 16023 + 16031 SR (IS-IS) lo - + 16032 SR (IS-IS) fe80::f46d:c8ff:fe8a:a341 16032 + 16033 SR (IS-IS) fe80::f46d:c8ff:fe8a:a341 16033 + 16034 SR (IS-IS) fe80::f46d:c8ff:fe8a:a341 16034 + 16041 SR (IS-IS) fe80::f46d:c8ff:fe8a:a341 16041 + 16502 PPR (IS-IS) fe80::a067:c6ff:fe2c:3385 16502 + 16503 PPR (IS-IS) fe80::f46d:c8ff:fe8a:a341 16503 + + # show ipv6 route 6000::/16 longer-prefixes isis + +Router RT32 +^^^^^^^^^^^ + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + --------------------------------------------------------------------------------------------- + 1 L1 500 (MPLS) 5000::11/128 0 Off-Path - - + 1 L1 501 (MPLS) 5000::14/128 0 Off-Path - - + 1 L1 502 (MPLS) 5000::11/128 0 Mid-Point Up 00:00:55 + 1 L1 503 (MPLS) 5000::14/128 0 Mid-Point Up 00:00:55 + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Off-Path - - + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Off-Path - - + + # show mpls table + Inbound Label Type Nexthop Outbound Label + ----------------------------------------------------------------------- + 16 SR (IS-IS) fe80::881f:d3ff:febd:9e8c implicit-null + 17 SR (IS-IS) fe80::1c7e:c3ff:fe5e:7a54 implicit-null + 18 SR (IS-IS) fe80::9863:abff:fed0:d7e implicit-null + 19 SR (IS-IS) fe80::ec65:d1ff:fe32:b508 implicit-null + 20 SR (IS-IS) fe80::a4e9:77ff:feaa:f690 implicit-null + 21 SR (IS-IS) fe80::40c4:e6ff:fe26:767f implicit-null + 16011 SR (IS-IS) fe80::881f:d3ff:febd:9e8c 16011 + 16012 SR (IS-IS) fe80::40c4:e6ff:fe26:767f 16012 + 16012 SR (IS-IS) fe80::881f:d3ff:febd:9e8c 16012 + 16013 SR (IS-IS) fe80::40c4:e6ff:fe26:767f 16013 + 16014 SR (IS-IS) fe80::1c7e:c3ff:fe5e:7a54 16014 + 16014 SR (IS-IS) fe80::ec65:d1ff:fe32:b508 16014 + 16014 SR (IS-IS) fe80::40c4:e6ff:fe26:767f 16014 + 16021 SR (IS-IS) fe80::881f:d3ff:febd:9e8c 16021 + 16022 SR (IS-IS) fe80::40c4:e6ff:fe26:767f 16022 + 16023 SR (IS-IS) fe80::1c7e:c3ff:fe5e:7a54 16023 + 16023 SR (IS-IS) fe80::ec65:d1ff:fe32:b508 16023 + 16023 SR (IS-IS) fe80::40c4:e6ff:fe26:767f 16023 + 16031 SR (IS-IS) fe80::9863:abff:fed0:d7e 16031 + 16032 SR (IS-IS) lo - + 16033 SR (IS-IS) fe80::1c7e:c3ff:fe5e:7a54 16033 + 16033 SR (IS-IS) fe80::ec65:d1ff:fe32:b508 16033 + 16034 SR (IS-IS) fe80::1c7e:c3ff:fe5e:7a54 16034 + 16034 SR (IS-IS) fe80::ec65:d1ff:fe32:b508 16034 + 16041 SR (IS-IS) fe80::a4e9:77ff:feaa:f690 16041 + 16502 PPR (IS-IS) fe80::9863:abff:fed0:d7e 16502 + 16503 PPR (IS-IS) fe80::a4e9:77ff:feaa:f690 16503 + + # show ipv6 route 6000::/16 longer-prefixes isis + +Router RT33 +^^^^^^^^^^^ + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + --------------------------------------------------------------------------------------------- + 1 L1 500 (MPLS) 5000::11/128 0 Off-Path - - + 1 L1 501 (MPLS) 5000::14/128 0 Off-Path - - + 1 L1 502 (MPLS) 5000::11/128 0 Mid-Point Up 00:00:57 + 1 L1 503 (MPLS) 5000::14/128 0 Mid-Point Up 00:00:57 + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Off-Path - - + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Off-Path - - + + # show mpls table + Inbound Label Type Nexthop Outbound Label + ----------------------------------------------------------------------- + 16 SR (IS-IS) fe80::2832:a9ff:fec3:7078 implicit-null + 17 SR (IS-IS) fe80::7806:e1ff:fe72:9b1f implicit-null + 18 SR (IS-IS) fe80::5476:31ff:fe94:c39 implicit-null + 19 SR (IS-IS) fe80::a4e9:77ff:feaa:f690 implicit-null + 20 SR (IS-IS) fe80::68c9:2ff:fe04:5eba implicit-null + 21 SR (IS-IS) fe80::d053:97ff:fee2:1711 implicit-null + 16011 SR (IS-IS) fe80::2832:a9ff:fec3:7078 16011 + 16011 SR (IS-IS) fe80::5476:31ff:fe94:c39 16011 + 16011 SR (IS-IS) fe80::d053:97ff:fee2:1711 16011 + 16012 SR (IS-IS) fe80::d053:97ff:fee2:1711 16012 + 16013 SR (IS-IS) fe80::68c9:2ff:fe04:5eba 20013 + 16013 SR (IS-IS) fe80::d053:97ff:fee2:1711 16013 + 16014 SR (IS-IS) fe80::68c9:2ff:fe04:5eba 20014 + 16021 SR (IS-IS) fe80::2832:a9ff:fec3:7078 16021 + 16021 SR (IS-IS) fe80::5476:31ff:fe94:c39 16021 + 16021 SR (IS-IS) fe80::d053:97ff:fee2:1711 16021 + 16022 SR (IS-IS) fe80::d053:97ff:fee2:1711 16022 + 16023 SR (IS-IS) fe80::68c9:2ff:fe04:5eba 20023 + 16031 SR (IS-IS) fe80::2832:a9ff:fec3:7078 16031 + 16031 SR (IS-IS) fe80::5476:31ff:fe94:c39 16031 + 16032 SR (IS-IS) fe80::2832:a9ff:fec3:7078 16032 + 16032 SR (IS-IS) fe80::5476:31ff:fe94:c39 16032 + 16033 SR (IS-IS) lo - + 16034 SR (IS-IS) fe80::7806:e1ff:fe72:9b1f 16034 + 16041 SR (IS-IS) fe80::a4e9:77ff:feaa:f690 16041 + 16502 PPR (IS-IS) fe80::a4e9:77ff:feaa:f690 16502 + 16503 PPR (IS-IS) fe80::7806:e1ff:fe72:9b1f 16503 + + # show ipv6 route 6000::/16 longer-prefixes isis + +Router RT34 +^^^^^^^^^^^ + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + --------------------------------------------------------------------------------------------- + 1 L1 500 (MPLS) 5000::11/128 0 Off-Path - - + 1 L1 501 (MPLS) 5000::14/128 0 Off-Path - - + 1 L1 502 (MPLS) 5000::11/128 0 Mid-Point Up 00:00:59 + 1 L1 503 (MPLS) 5000::14/128 0 Mid-Point Up 00:00:59 + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Off-Path - - + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Off-Path - - + + # show mpls table + Inbound Label Type Nexthop Outbound Label + ----------------------------------------------------------------------- + 16 SR (IS-IS) fe80::ac33:5dff:fe99:81ec implicit-null + 17 SR (IS-IS) fe80::f009:b9ff:fe05:e540 implicit-null + 16011 SR (IS-IS) fe80::ac33:5dff:fe99:81ec 16011 + 16011 SR (IS-IS) fe80::f009:b9ff:fe05:e540 20011 + 16012 SR (IS-IS) fe80::ac33:5dff:fe99:81ec 16012 + 16012 SR (IS-IS) fe80::f009:b9ff:fe05:e540 20012 + 16013 SR (IS-IS) fe80::f009:b9ff:fe05:e540 20013 + 16014 SR (IS-IS) fe80::f009:b9ff:fe05:e540 20014 + 16021 SR (IS-IS) fe80::ac33:5dff:fe99:81ec 16021 + 16021 SR (IS-IS) fe80::f009:b9ff:fe05:e540 20021 + 16022 SR (IS-IS) fe80::ac33:5dff:fe99:81ec 16022 + 16022 SR (IS-IS) fe80::f009:b9ff:fe05:e540 20022 + 16023 SR (IS-IS) fe80::f009:b9ff:fe05:e540 20023 + 16031 SR (IS-IS) fe80::ac33:5dff:fe99:81ec 16031 + 16032 SR (IS-IS) fe80::ac33:5dff:fe99:81ec 16032 + 16033 SR (IS-IS) fe80::ac33:5dff:fe99:81ec 16033 + 16034 SR (IS-IS) lo - + 16041 SR (IS-IS) fe80::ac33:5dff:fe99:81ec 16041 + 16502 PPR (IS-IS) fe80::ac33:5dff:fe99:81ec 16502 + 16503 PPR (IS-IS) fe80::f009:b9ff:fe05:e540 20503 + + # show ipv6 route 6000::/16 longer-prefixes isis + +Router RT41 +^^^^^^^^^^^ + +:: + + # show isis ppr + Area Level ID Prefix Metric Position Status Uptime + --------------------------------------------------------------------------------------------- + 1 L1 500 (MPLS) 5000::11/128 0 Off-Path - - + 1 L1 501 (MPLS) 5000::14/128 0 Off-Path - - + 1 L1 502 (MPLS) 5000::11/128 0 Mid-Point Up 00:01:01 + 1 L1 503 (MPLS) 5000::14/128 0 Mid-Point Up 00:01:01 + 1 L1 6000:1::1/128 (Native IPv6) 5000::11/128 50 Off-Path - - + 1 L1 6000:2::1/128 (Native IPv6) 5000::14/128 50 Off-Path - - + + # show mpls table + Inbound Label Type Nexthop Outbound Label + ----------------------------------------------------------------------- + 16 SR (IS-IS) fe80::1c7e:c3ff:fe5e:7a54 implicit-null + 17 SR (IS-IS) fe80::2832:a9ff:fec3:7078 implicit-null + 16011 SR (IS-IS) fe80::2832:a9ff:fec3:7078 16011 + 16012 SR (IS-IS) fe80::2832:a9ff:fec3:7078 16012 + 16012 SR (IS-IS) fe80::1c7e:c3ff:fe5e:7a54 16012 + 16013 SR (IS-IS) fe80::2832:a9ff:fec3:7078 16013 + 16013 SR (IS-IS) fe80::1c7e:c3ff:fe5e:7a54 16013 + 16014 SR (IS-IS) fe80::1c7e:c3ff:fe5e:7a54 16014 + 16021 SR (IS-IS) fe80::2832:a9ff:fec3:7078 16021 + 16022 SR (IS-IS) fe80::2832:a9ff:fec3:7078 16022 + 16022 SR (IS-IS) fe80::1c7e:c3ff:fe5e:7a54 16022 + 16023 SR (IS-IS) fe80::1c7e:c3ff:fe5e:7a54 16023 + 16031 SR (IS-IS) fe80::2832:a9ff:fec3:7078 16031 + 16032 SR (IS-IS) fe80::2832:a9ff:fec3:7078 16032 + 16033 SR (IS-IS) fe80::1c7e:c3ff:fe5e:7a54 16033 + 16034 SR (IS-IS) fe80::1c7e:c3ff:fe5e:7a54 16034 + 16041 SR (IS-IS) lo - + 16502 PPR (IS-IS) fe80::2832:a9ff:fec3:7078 16502 + 16503 PPR (IS-IS) fe80::1c7e:c3ff:fe5e:7a54 16503 + + # show ipv6 route 6000::/16 longer-prefixes isis + +Notice how R23 uses a different SRGB compared to the other routers in +the network. As such, this router install different labels for PPR-IDs +500 and 501 (e.g. 20500 instead of 16500 using the default SRGB). + +Verification - Forwarding Plane +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Ping Host 3 from Host2 and use tcpdump or wireshark to verify that the +ICMP packets are being tunneled using MPLS LSPs and following the {R11 - +R21 - R22 - R23 - R14} path. Here’s a wireshark capture between R11 and +R21: + +.. figure:: https://user-images.githubusercontent.com/931662/64057179-2e980080-cb70-11e9-89c3-ff43e6d66cae.png + :alt: wireshark + + wireshark + +Using ``traceroute`` it’s also possible to see that the ICMP packets are +being tunneled through the IS-IS network: + +:: + + root@host2:~# traceroute -n fd00:20:1::1 -s fd00:10:2::1 + traceroute to fd00:20:1::1 (fd00:20:1::1), 30 hops max, 80 byte packets + 1 fd00:10:2::100 1.996 ms 1.832 ms 1.725 ms + 2 * * * + 3 * * * + 4 * * * + 5 * * * + 6 * * * + 7 * * * + 8 fd00:20::100 0.154 ms 0.191 ms 0.116 ms + 9 fd00:20:1::1 0.125 ms 0.105 ms 0.104 ms diff --git a/doc/developer/northbound/retrofitting-configuration-commands.rst b/doc/developer/northbound/retrofitting-configuration-commands.rst new file mode 100644 index 0000000000..41f9902b6a --- /dev/null +++ b/doc/developer/northbound/retrofitting-configuration-commands.rst @@ -0,0 +1,1897 @@ +Retrofitting Configuration Commands +----------------------------------- + +This page explains how to convert existing CLI configuration commands to +the new northbound model. This documentation is meant to be the primary +reference for developers working on the northbound retrofitting process. +We’ll show several examples taken from the ripd northbound conversion to +illustrate some concepts described herein. + +Retrofitting process +-------------------- + +Step 1: writing a YANG module +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The first step is to write a YANG module that models faithfully the +commands that are going to be converted. As explained in the +[[Architecture]] page, the goal is to introduce the new YANG-based +Northbound API without introducing backward incompatible changes in the +CLI. The northbound retrofitting process should be completely +transparent to FRR users. + +The developer is free to choose whether to write a full YANG module or a +partial YANG module and increment it gradually. For developers who lack +experience with YANG it’s probably a better idea to model one command at +time. + +It’s recommended to reuse definitions from standard YANG models whenever +possible to facilitate the process of writing module translators using +the [[YANG module translator]]. As an example, the frr-ripd YANG module +incorporated several parts of the IETF RIP YANG module. The repositories +below contain big collections of YANG models that might be used as a +reference: \* https://github.com/YangModels/yang \* +https://github.com/openconfig/public + +When writing a YANG module, it’s highly recommended to follow the +guidelines from `RFC 6087 <https://tools.ietf.org/html/rfc6087>`__. In +general, most commands should be modeled fairly easy. Here are a few +guidelines specific to authors of FRR YANG models: \* Use +presence-containers or lists to model commands that change the CLI node +(e.g. ``router rip``, ``interface eth0``). This way, if the +presence-container or list entry is removed, all configuration options +below them are removed automatically (exactly like the CLI behaves when +a configuration object is removed using a *no* command). This +recommendation is orthogonal to the `YANG authoring guidelines for +OpenConfig +models <https://github.com/openconfig/public/blob/master/doc/openconfig_style_guide.md>`__ +where the use of presence containers is discouraged. OpenConfig YANG +models however were not designed to replicate the behavior of legacy CLI +commands. \* When using YANG lists, be careful to identify what should +be the key leaves. In the ``offset-list WORD <in|out> (0-16) IFNAME`` +command, for example, both the direction (``<in|out>``) and the +interface name should be the keys of the list. This can be only known by +analyzing the data structures used to store the commands. \* For +clarity, use non-presence containers to group leaves that are associated +to the same configuration command (as we’ll see later, this also +facilitate the process of writing ``cli_show`` callbacks). \* YANG +leaves of type *enumeration* should define explicitly the value of each +*enum* option based on the value used in the FRR source code. \* Default +values should be taken from the source code whenever they exist. + +Some commands are more difficult to model and demand the use of more +advanced YANG constructs like *choice*, *when* and *must* statements. +**One key requirement is that it should be impossible to load an invalid +JSON/XML configuration to FRR**. The YANG modules should model exactly +what the CLI accepts in the form of commands, and all restrictions +imposed by the CLI should be defined in the YANG models whenever +possible. As we’ll see later, not all constraints can be expressed using +the YANG language and sometimes we’ll need to resort to code-level +validation in the northbound callbacks. + + Tip: the :doc:`yang-tools` page details several tools and commands that + might be useful when writing a YANG module, like validating YANG + files, indenting YANG files, validating instance data, etc. + +In the example YANG snippet below, we can see the use of the *must* +statement that prevents ripd from redistributing RIP routes into itself. +Although ripd CLI doesn’t allow the operator to enter *redistribute rip* +under *router rip*, we don’t have the same protection when configuring +ripd using other northbound interfaces (e.g. NETCONF). So without this +constraint it would be possible to feed an invalid configuration to ripd +(i.e. a bug). + +.. code:: yang + + list redistribute { + key "protocol"; + description + "Redistributes routes learned from other routing protocols."; + leaf protocol { + type frr-route-types:frr-route-types-v4; + description + "Routing protocol."; + must '. != "rip"'; + } + [snip] + } + +In the example below, we use the YANG *choice* statement to ensure that +either the ``password`` leaf or the ``key-chain`` leaf is configured, +but not both. This is in accordance to the sanity checks performed by +the *ip rip authentication* commands. + +.. code:: yang + + choice authentication-data { + description + "Choose whether to use a simple password or a key-chain."; + leaf authentication-password { + type string { + length "1..16"; + } + description + "Authentication string."; + } + leaf authentication-key-chain { + type string; + description + "Key-chain name."; + } + } + +Once finished, the new YANG model should be put into the FRR *yang/* top +level directory. This will ensure it will be installed automatically by +``make install``. It’s also encouraged (but not required) to put sample +configurations under *yang/examples/* using either JSON or XML files. + +Step 2: generate skeleton northbound callbacks +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Use the *gen_northbound_callbacks* tool to generate skeleton callbacks +for the YANG module. Example: + +.. code:: sh + + $ tools/gen_northbound_callbacks frr-ripd > ripd/rip_northbound.c + +The tool will look for the given module in the ``YANG_MODELS_PATH`` +directory defined during the installation. For each schema node of the +YANG module, the tool will generate skeleton callbacks based on the +properties of the node. Example: + +.. code:: c + + /* + * XPath: /frr-ripd:ripd/instance + */ + static int ripd_instance_create(enum nb_event event, + const struct lyd_node *dnode, + union nb_resource *resource) + { + /* TODO: implement me. */ + return NB_OK; + } + + static int ripd_instance_delete(enum nb_event event, + const struct lyd_node *dnode) + { + /* TODO: implement me. */ + return NB_OK; + } + + /* + * XPath: /frr-ripd:ripd/instance/allow-ecmp + */ + static int ripd_instance_allow_ecmp_modify(enum nb_event event, + const struct lyd_node *dnode, + union nb_resource *resource) + { + /* TODO: implement me. */ + return NB_OK; + } + + [snip] + + const struct frr_yang_module_info frr_ripd_info = { + .name = "frr-ripd", + .nodes = { + { + .xpath = "/frr-ripd:ripd/instance", + .cbs.create = ripd_instance_create, + .cbs.delete = ripd_instance_delete, + }, + { + .xpath = "/frr-ripd:ripd/instance/allow-ecmp", + .cbs.modify = ripd_instance_allow_ecmp_modify, + }, + [snip] + { + .xpath = "/frr-ripd:ripd/state/routes/route", + .cbs.get_next = ripd_state_routes_route_get_next, + .cbs.get_keys = ripd_state_routes_route_get_keys, + .cbs.lookup_entry = ripd_state_routes_route_lookup_entry, + }, + { + .xpath = "/frr-ripd:ripd/state/routes/route/prefix", + .cbs.get_elem = ripd_state_routes_route_prefix_get_elem, + }, + { + .xpath = "/frr-ripd:ripd/state/routes/route/next-hop", + .cbs.get_elem = ripd_state_routes_route_next_hop_get_elem, + }, + { + .xpath = "/frr-ripd:ripd/state/routes/route/interface", + .cbs.get_elem = ripd_state_routes_route_interface_get_elem, + }, + { + .xpath = "/frr-ripd:ripd/state/routes/route/metric", + .cbs.get_elem = ripd_state_routes_route_metric_get_elem, + }, + { + .xpath = "/frr-ripd:clear-rip-route", + .cbs.rpc = clear_rip_route_rpc, + }, + [snip] + +After the C source file is generated, it’s necessary to add a copyright +header on it and indent the code using ``clang-format``. + +Step 3: update the *frr_yang_module_info* array of all relevant daemons +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +We must inform the northbound about which daemons will implement the new +YANG module. This is done by updating the ``frr_daemon_info`` structure +of these daemons, with help of the ``FRR_DAEMON_INFO`` macro. + +When a YANG module is specific to a single daemon, like the frr-ripd +module, then only the corresponding daemon should be updated. When the +YANG module is related to a subset of libfrr (e.g. route-maps), then all +FRR daemons that make use of that subset must be updated. + +Example: + +.. code:: c + + static const struct frr_yang_module_info *ripd_yang_modules[] = { + &frr_interface_info, + &frr_ripd_info, + }; + + FRR_DAEMON_INFO(ripd, RIP, .vty_port = RIP_VTY_PORT, + [snip] + .yang_modules = ripd_yang_modules, + .n_yang_modules = array_size(ripd_yang_modules), ) + +Step 4: implement the northbound configuration callbacks +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Implementing the northbound configuration callbacks consists mostly of +copying code from the corresponding CLI commands and make the required +adaptations. + +It’s recommended to convert one command or a small group of related +commands per commit. Small commits are preferred to facilitate the +review process. Both “old” and “new” command can coexist without +problems, so the retrofitting process can happen gradually over time. + +The configuration callbacks +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +These are the four main northbound configuration callbacks, as defined +in the ``lib/northbound.h`` file: + +.. code:: c + + /* + * Configuration callback. + * + * A presence container, list entry, leaf-list entry or leaf of type + * empty has been created. + * + * For presence-containers and list entries, the callback is supposed to + * initialize the default values of its children (if any) from the YANG + * models. + * + * event + * The transaction phase. Refer to the documentation comments of + * nb_event for more details. + * + * dnode + * libyang data node that is being created. + * + * resource + * Pointer to store resource(s) allocated during the NB_EV_PREPARE + * phase. The same pointer can be used during the NB_EV_ABORT and + * NB_EV_APPLY phases to either release or make use of the allocated + * resource(s). It's set to NULL when the event is NB_EV_VALIDATE. + * + * Returns: + * - NB_OK on success. + * - NB_ERR_VALIDATION when a validation error occurred. + * - NB_ERR_RESOURCE when the callback failed to allocate a resource. + * - NB_ERR_INCONSISTENCY when an inconsistency was detected. + * - NB_ERR for other errors. + */ + int (*create)(enum nb_event event, const struct lyd_node *dnode, + union nb_resource *resource); + + /* + * Configuration callback. + * + * The value of a leaf has been modified. + * + * List keys don't need to implement this callback. When a list key is + * modified, the northbound treats this as if the list was deleted and a + * new one created with the updated key value. + * + * event + * The transaction phase. Refer to the documentation comments of + * nb_event for more details. + * + * dnode + * libyang data node that is being modified + * + * resource + * Pointer to store resource(s) allocated during the NB_EV_PREPARE + * phase. The same pointer can be used during the NB_EV_ABORT and + * NB_EV_APPLY phases to either release or make use of the allocated + * resource(s). It's set to NULL when the event is NB_EV_VALIDATE. + * + * Returns: + * - NB_OK on success. + * - NB_ERR_VALIDATION when a validation error occurred. + * - NB_ERR_RESOURCE when the callback failed to allocate a resource. + * - NB_ERR_INCONSISTENCY when an inconsistency was detected. + * - NB_ERR for other errors. + */ + int (*modify)(enum nb_event event, const struct lyd_node *dnode, + union nb_resource *resource); + + /* + * Configuration callback. + * + * A presence container, list entry, leaf-list entry or optional leaf + * has been deleted. + * + * The callback is supposed to delete the entire configuration object, + * including its children when they exist. + * + * event + * The transaction phase. Refer to the documentation comments of + * nb_event for more details. + * + * dnode + * libyang data node that is being deleted. + * + * Returns: + * - NB_OK on success. + * - NB_ERR_VALIDATION when a validation error occurred. + * - NB_ERR_INCONSISTENCY when an inconsistency was detected. + * - NB_ERR for other errors. + */ + int (*delete)(enum nb_event event, const struct lyd_node *dnode); + + /* + * Configuration callback. + * + * A list entry or leaf-list entry has been moved. Only applicable when + * the "ordered-by user" statement is present. + * + * event + * The transaction phase. Refer to the documentation comments of + * nb_event for more details. + * + * dnode + * libyang data node that is being moved. + * + * Returns: + * - NB_OK on success. + * - NB_ERR_VALIDATION when a validation error occurred. + * - NB_ERR_INCONSISTENCY when an inconsistency was detected. + * - NB_ERR for other errors. + */ + int (*move)(enum nb_event event, const struct lyd_node *dnode); + +Since skeleton northbound callbacks are generated automatically by the +*gen_northbound_callbacks* tool, the developer doesn’t need to worry +about which callbacks need to be implemented. + + NOTE: once a daemon starts, it reads its YANG modules and validates + that all required northbound callbacks were implemented. If any + northbound callback is missing, an error is logged and the program + exists. + +Transaction phases +^^^^^^^^^^^^^^^^^^ + +Configuration transactions and their phases were described in detail in +the [[Architecture]] page. Here’s the definition of the ``nb_event`` +enumeration as defined in the *lib/northbound.h* file: + +.. code:: c + + /* Northbound events. */ + enum nb_event { + /* + * The configuration callback is supposed to verify that the changes are + * valid and can be applied. + */ + NB_EV_VALIDATE, + + /* + * The configuration callback is supposed to prepare all resources + * required to apply the changes. + */ + NB_EV_PREPARE, + + /* + * Transaction has failed, the configuration callback needs to release + * all resources previously allocated. + */ + NB_EV_ABORT, + + /* + * The configuration changes need to be applied. The changes can't be + * rejected at this point (errors are logged and ignored). + */ + NB_EV_APPLY, + }; + +When converting a CLI command, we must identify all error-prone +operations and perform them in the ``NB_EV_PREPARE`` phase of the +northbound callbacks. When the operation in question involves the +allocation of a specific resource (e.g. file descriptors), we can store +the allocated resource in the ``resource`` variable given to the +callback. This way the allocated resource can be obtained in the other +phases of the transaction using the same parameter. + +Here’s the ``create`` northbound callback associated to the +``router rip`` command: + +.. code:: c + + /* + * XPath: /frr-ripd:ripd/instance + */ + static int ripd_instance_create(enum nb_event event, + const struct lyd_node *dnode, + union nb_resource *resource) + { + int socket; + + switch (event) { + case NB_EV_VALIDATE: + break; + case NB_EV_PREPARE: + socket = rip_create_socket(); + if (socket < 0) + return NB_ERR_RESOURCE; + resource->fd = socket; + break; + case NB_EV_ABORT: + socket = resource->fd; + close(socket); + break; + case NB_EV_APPLY: + socket = resource->fd; + rip_create(socket); + break; + } + + return NB_OK; + } + +Note that the socket creation is an error-prone operation since it +depends on the underlying operating system, so the socket must be +created during the ``NB_EV_PREPARE`` phase and stored in +``resource->fd``. This socket is then either closed or used depending on +the outcome of the preparation phase of the whole transaction. + +During the ``NB_EV_VALIDATE`` phase, the northbound callbacks must +validate if the intended changes are valid. As an example, FRR doesn’t +allow the operator to deconfigure active interfaces: + +.. code:: c + + static int lib_interface_delete(enum nb_event event, + const struct lyd_node *dnode) + { + struct interface *ifp; + + ifp = yang_dnode_get_entry(dnode); + + switch (event) { + case NB_EV_VALIDATE: + if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) { + zlog_warn("%s: only inactive interfaces can be deleted", + __func__); + return NB_ERR_VALIDATION; + } + break; + case NB_EV_PREPARE: + case NB_EV_ABORT: + break; + case NB_EV_APPLY: + if_delete(ifp); + break; + } + + return NB_OK; + } + +Note however that it’s preferred to use YANG to model the validation +constraints whenever possible. Code-level validations should be used +only to validate constraints that can’t be modeled using the YANG +language. + +Most callbacks don’t need to perform any validations nor perform any +error-prone operations, so in these cases we can use the following +pattern to return early if ``event`` is different than ``NB_EV_APPLY``: + +.. code:: c + + /* + * XPath: /frr-ripd:ripd/instance/distance/default + */ + static int ripd_instance_distance_default_modify(enum nb_event event, + const struct lyd_node *dnode, + union nb_resource *resource) + { + if (event != NB_EV_APPLY) + return NB_OK; + + rip->distance = yang_dnode_get_uint8(dnode, NULL); + + return NB_OK; + } + +During development it’s recommend to use the *debug northbound* command +to debug configuration transactions and see what callbacks are being +called. Example: + +:: + + ripd# conf t + ripd(config)# debug northbound + ripd(config)# router rip + ripd(config-router)# allow-ecmp + ripd(config-router)# network eth0 + ripd(config-router)# redistribute ospf metric 2 + ripd(config-router)# commit + % Configuration committed successfully. + + ripd(config-router)# + +Now the ripd log: + +:: + + 2018/09/23 12:43:59 RIP: northbound callback: event [validate] op [create] xpath [/frr-ripd:ripd/instance] value [(none)] + 2018/09/23 12:43:59 RIP: northbound callback: event [validate] op [modify] xpath [/frr-ripd:ripd/instance/allow-ecmp] value [true] + 2018/09/23 12:43:59 RIP: northbound callback: event [validate] op [create] xpath [/frr-ripd:ripd/instance/interface[.='eth0']] value [eth0] + 2018/09/23 12:43:59 RIP: northbound callback: event [validate] op [create] xpath [/frr-ripd:ripd/instance/redistribute[protocol='ospf']] value [(none)] + 2018/09/23 12:43:59 RIP: northbound callback: event [validate] op [modify] xpath [/frr-ripd:ripd/instance/redistribute[protocol='ospf']/metric] value [2] + 2018/09/23 12:43:59 RIP: northbound callback: event [prepare] op [create] xpath [/frr-ripd:ripd/instance] value [(none)] + 2018/09/23 12:43:59 RIP: northbound callback: event [prepare] op [modify] xpath [/frr-ripd:ripd/instance/allow-ecmp] value [true] + 2018/09/23 12:43:59 RIP: northbound callback: event [prepare] op [create] xpath [/frr-ripd:ripd/instance/interface[.='eth0']] value [eth0] + 2018/09/23 12:43:59 RIP: northbound callback: event [prepare] op [create] xpath [/frr-ripd:ripd/instance/redistribute[protocol='ospf']] value [(none)] + 2018/09/23 12:43:59 RIP: northbound callback: event [prepare] op [modify] xpath [/frr-ripd:ripd/instance/redistribute[protocol='ospf']/metric] value [2] + 2018/09/23 12:43:59 RIP: northbound callback: event [apply] op [create] xpath [/frr-ripd:ripd/instance] value [(none)] + 2018/09/23 12:43:59 RIP: northbound callback: event [apply] op [modify] xpath [/frr-ripd:ripd/instance/allow-ecmp] value [true] + 2018/09/23 12:43:59 RIP: northbound callback: event [apply] op [create] xpath [/frr-ripd:ripd/instance/interface[.='eth0']] value [eth0] + 2018/09/23 12:43:59 RIP: northbound callback: event [apply] op [create] xpath [/frr-ripd:ripd/instance/redistribute[protocol='ospf']] value [(none)] + 2018/09/23 12:43:59 RIP: northbound callback: event [apply] op [modify] xpath [/frr-ripd:ripd/instance/redistribute[protocol='ospf']/metric] value [2] + 2018/09/23 12:43:59 RIP: northbound callback: event [apply] op [apply_finish] xpath [/frr-ripd:ripd/instance/redistribute[protocol='ospf']] value [(null)] + +Getting the data +^^^^^^^^^^^^^^^^ + +One parameter that is common to all northbound configuration callbacks +is the ``dnode`` parameter. This is a libyang data node structure that +contains information relative to the configuration change that is being +performed. For ``create`` callbacks, it contains the configuration node +that is being added. For ``delete`` callbacks, it contains the +configuration node that is being deleted. For ``modify`` callbacks, it +contains the configuration node that is being modified. + +In order to get the actual data value out of the ``dnode`` variable, we +need to use the ``yang_dnode_get_*()`` wrappers documented in +*lib/yang_wrappers.h*. + +The advantage of passing a ``dnode`` structure to the northbound +callbacks is that the whole candidate being committed is made available, +so the callbacks can obtain values from other portions of the +configuration if necessary. This can be done by providing an xpath +expression to the second parameter of the ``yang_dnode_get_*()`` +wrappers to specify the element we want to get. The example below shows +a callback that gets the values of two leaves that are part of the same +list entry: + +.. code:: c + + static int + ripd_instance_redistribute_metric_modify(enum nb_event event, + const struct lyd_node *dnode, + union nb_resource *resource) + { + int type; + uint8_t metric; + + if (event != NB_EV_APPLY) + return NB_OK; + + type = yang_dnode_get_enum(dnode, "../protocol"); + metric = yang_dnode_get_uint8(dnode, NULL); + + rip->route_map[type].metric_config = true; + rip->route_map[type].metric = metric; + rip_redistribute_conf_update(type); + + return NB_OK; + } + +.. + + NOTE: if the wrong ``yang_dnode_get_*()`` wrapper is used, the code + will log an error and abort. An example would be using + ``yang_dnode_get_enum()`` to get the value of a boolean data node. + +No need to check if the configuration value has changed +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +A common pattern in CLI commands is this: + +.. code:: c + + DEFUN (...) + { + [snip] + if (new_value == old_value) + return CMD_SUCCESS; + [snip] + } + +Several commands need to check if the new value entered by the user is +the same as the one currently configured. Then, if yes, ignore the +command since nothing was changed. + +The northbound callbacks on the other hand don’t need to perform this +check since they act on effective configuration changes. Using the CLI +as an example, if the operator enters the same command multiple times, +the northbound layer will detect that nothing has changed in the +configuration and will avoid calling the northbound callbacks +unnecessarily. + +In some cases, however, it might be desirable to check for +inconsistencies and notify the northbound when that happens: + +.. code:: c + + /* + * XPath: /frr-ripd:ripd/instance/interface + */ + static int ripd_instance_interface_create(enum nb_event event, + const struct lyd_node *dnode, + union nb_resource *resource) + { + const char *ifname; + + if (event != NB_EV_APPLY) + return NB_OK; + + ifname = yang_dnode_get_string(dnode, NULL); + + return rip_enable_if_add(ifname); + } + +.. code:: c + + /* Add interface to rip_enable_if. */ + int rip_enable_if_add(const char *ifname) + { + int ret; + + ret = rip_enable_if_lookup(ifname); + if (ret >= 0) + return NB_ERR_INCONSISTENCY; + + vector_set(rip_enable_interface, + XSTRDUP(MTYPE_RIP_INTERFACE_STRING, ifname)); + + rip_enable_apply_all(); /* TODOVJ */ + + return NB_OK; + } + +In the example above, the ``rip_enable_if_add()`` function should never +return ``NB_ERR_INCONSISTENCY`` in normal conditions. This is because +the northbound layer guarantees that the same interface will never be +added more than once (except when it’s removed and re-added again). But +to be on the safe side it’s probably wise to check for internal +inconsistencies to ensure everything is working as expected. + +Default values +^^^^^^^^^^^^^^ + +Whenever creating a new presence-container or list entry, it’s usually +necessary to initialize certain variables to their default values. FRR +most of the time uses special constants for that purpose +(e.g. ``RIP_DEFAULT_METRIC_DEFAULT``, ``DFLT_BGP_HOLDTIME``, etc). Now +that we have YANG models, we want to fetch the default values from these +models instead. This will allow us to changes default values smoothly +without needing to touch the code. Better yet, it will allow users to +create YANG deviations to define custom default values easily. + +To fetch default values from the loaded YANG models, use the +``yang_get_default_*()`` wrapper functions +(e.g. ``yang_get_default_bool()``) documented in *lib/yang_wrappers.h*. + +Example: + +.. code:: c + + int rip_create(int socket) + { + rip = XCALLOC(MTYPE_RIP, sizeof(struct rip)); + + /* Set initial values. */ + rip->ecmp = yang_get_default_bool("%s/allow-ecmp", RIP_INSTANCE); + rip->default_metric = + yang_get_default_uint8("%s/default-metric", RIP_INSTANCE); + [snip] + } + +Configuration options are edited individually +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Several CLI commands edit multiple configuration options at the same +time. Some examples taken from ripd: \* +``timers basic (5-2147483647) (5-2147483647) (5-2147483647)`` - +*/frr-ripd:ripd/instance/timers/flush-interval* - +*/frr-ripd:ripd/instance/timers/holddown-interval* - +*/frr-ripd:ripd/instance/timers/update-interval* \* +``distance (1-255) A.B.C.D/M [WORD]`` - +*/frr-ripd:ripd/instance/distance/source/prefix* - +*/frr-ripd:ripd/instance/distance/source/distance* - +*/frr-ripd:ripd/instance/distance/source/access-list* + +In the new northbound model, there’s one or more separate callbacks for +each configuration option. This usually has implications when converting +code from CLI commands to the northbound commands. An example of this is +the following commit from ripd: +`7cf2f2eaf <https://github.com/opensourcerouting/frr/commit/7cf2f2eaf43ef5df294625d1ab4c708db8293510>`__. +The ``rip_distance_set()`` and ``rip_distance_unset()`` functions were +torn apart and their code split into a few different callbacks. + +For lists and presence-containers, it’s possible to use the +``yang_dnode_set_entry()`` function to attach user data to a libyang +data node, and then retrieve this value in the other callbacks (for the +same node or any of its children) using the ``yang_dnode_get_entry()`` +function. Example: + +.. code:: c + + static int ripd_instance_distance_source_create(enum nb_event event, + const struct lyd_node *dnode, + union nb_resource *resource) + { + struct prefix_ipv4 prefix; + struct route_node *rn; + + if (event != NB_EV_APPLY) + return NB_OK; + + yang_dnode_get_ipv4p(&prefix, dnode, "./prefix"); + + /* Get RIP distance node. */ + rn = route_node_get(rip_distance_table, (struct prefix *)&prefix); + rn->info = rip_distance_new(); + yang_dnode_set_entry(dnode, rn); + + return NB_OK; + } + +.. code:: c + + static int + ripd_instance_distance_source_distance_modify(enum nb_event event, + const struct lyd_node *dnode, + union nb_resource *resource) + { + struct route_node *rn; + uint8_t distance; + struct rip_distance *rdistance; + + if (event != NB_EV_APPLY) + return NB_OK; + + /* Set distance value. */ + rn = yang_dnode_get_entry(dnode); + distance = yang_dnode_get_uint8(dnode, NULL); + rdistance = rn->info; + rdistance->distance = distance; + + return NB_OK; + } + +Commands that edit multiple configuration options at the same time can +also use the ``apply_finish`` optional callback, documented as follows +in the *lib/northbound.h* file: + +.. code:: c + + /* + * Optional configuration callback for YANG lists and containers. + * + * The 'apply_finish' callbacks are called after all other callbacks + * during the apply phase (NB_EV_APPLY). These callbacks are called only + * under one of the following two cases: + * * The container or a list entry has been created; + * * Any change is made within the descendants of the list entry or + * container (e.g. a child leaf was modified, created or deleted). + * + * This callback is useful in the cases where a single event should be + * triggered regardless if the container or list entry was changed once + * or multiple times. + * + * dnode + * libyang data node from the YANG list or container. + */ + void (*apply_finish)(const struct lyd_node *dnode); + +Here’s an example of how this callback can be used: + +.. code:: c + + /* + * XPath: /frr-ripd:ripd/instance/timers/ + */ + static void ripd_instance_timers_apply_finish(const struct lyd_node *dnode) + { + /* Reset update timer thread. */ + rip_event(RIP_UPDATE_EVENT, 0); + } + +.. code:: c + + { + .xpath = "/frr-ripd:ripd/instance/timers", + .cbs.apply_finish = ripd_instance_timers_apply_finish, + .cbs.cli_show = cli_show_rip_timers, + }, + { + .xpath = "/frr-ripd:ripd/instance/timers/flush-interval", + .cbs.modify = ripd_instance_timers_flush_interval_modify, + }, + { + .xpath = "/frr-ripd:ripd/instance/timers/holddown-interval", + .cbs.modify = ripd_instance_timers_holddown_interval_modify, + }, + { + .xpath = "/frr-ripd:ripd/instance/timers/update-interval", + .cbs.modify = ripd_instance_timers_update_interval_modify, + }, + +In this example, we want to call the ``rip_event()`` function only once +regardless if all RIP timers were modified or only one of them. Without +the ``apply_finish`` callback we’d need to call ``rip_event()`` in the +``modify`` callback of each timer (a YANG leaf), resulting in redundant +call to the ``rip_event()`` function if multiple timers are changed at +once. + +Bonus: libyang user types +^^^^^^^^^^^^^^^^^^^^^^^^^ + +When writing YANG modules, it’s advisable to create derived types for +data types that are used on multiple places (e.g. MAC addresses, IS-IS +networks, etc). Here’s how `RFC +7950 <https://tools.ietf.org/html/rfc7950#page-25>`__ defines derived +types: > YANG can define derived types from base types using the +“typedef” > statement. A base type can be either a built-in type or a +derived > type, allowing a hierarchy of derived types. > > A derived +type can be used as the argument for the “type” statement. > > YANG +Example: > > typedef percent { > type uint8 { > range “0 .. 100”; > } > +} > > leaf completed { > type percent; > } + +Derived types are essentially built-in types with imposed restrictions. +As an example, the ``ipv4-address`` derived type from IETF is defined +using the ``string`` built-in type with a ``pattern`` constraint (a +regular expression): + +:: + + typedef ipv4-address { + type string { + pattern + '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}' + + '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])' + + '(%[\p{N}\p{L}]+)?'; + } + description + "The ipv4-address type represents an IPv4 address in + dotted-quad notation. The IPv4 address may include a zone + index, separated by a % sign. + + The zone index is used to disambiguate identical address + values. For link-local addresses, the zone index will + typically be the interface index number or the name of an + interface. If the zone index is not present, the default + zone of the device will be used. + + The canonical format for the zone index is the numerical + format"; + } + +Sometimes, however, it’s desirable to have a binary representation of +the derived type that is different from the associated built-in type. +Taking the ``ipv4-address`` example above, it would be more convenient +to manipulate this YANG type using ``in_addr`` structures instead of +strings. libyang allow us to do that using the user types plugin: +https://netopeer.liberouter.org/doc/libyang/master/howtoschemaplugins.html#usertypes + +Here’s how the the ``ipv4-address`` derived type is implemented in FRR +(*yang/libyang_plugins/frr_user_types.c*): + +.. code:: c + + static int ipv4_address_store_clb(const char *type_name, const char *value_str, + lyd_val *value, char **err_msg) + { + value->ptr = malloc(sizeof(struct in_addr)); + if (!value->ptr) + return 1; + + if (inet_pton(AF_INET, value_str, value->ptr) != 1) { + free(value->ptr); + return 1; + } + + return 0; + } + +.. code:: c + + struct lytype_plugin_list frr_user_types[] = { + {"ietf-inet-types", "2013-07-15", "ipv4-address", + ipv4_address_store_clb, free}, + {"ietf-inet-types", "2013-07-15", "ipv4-address-no-zone", + ipv4_address_store_clb, free}, + [snip] + {NULL, NULL, NULL, NULL, NULL} /* terminating item */ + }; + +Now, in addition to the string representation of the data value, libyang +will also store the data in the binary format we specified (an +``in_addr`` structure). + +Whenever a new derived type is implemented in FRR, it’s also recommended +to write new wrappers in the *lib/yang_wrappers.c* file +(e.g. ``yang_dnode_get_ipv4()``, ``yang_get_default_ipv4()``, etc). + +Step 5: rewrite the CLI commands as dumb wrappers around the northbound callbacks +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Once the northbound callbacks are implemented, we need to rewrite the +associated CLI commands on top of the northbound layer. This is the +easiest part of the retrofitting process. + +For protocol daemons, it’s recommended to put all CLI commands on a +separate C file (e.g. *ripd/rip_cli.c*). This helps to keep the code +more clean by separating the main protocol code from the user interface. +It should also help when moving the CLI to a separate program in the +future. + +For libfrr commands, it’s not possible to centralize all commands in a +single file because the *extract.pl* script from *vtysh* treats commands +differently depending on the file in which they are defined (e.g. DEFUNs +from *lib/routemap.c* are installed using the ``VTYSH_RMAP`` constant, +which identifies the daemons that support route-maps). In this case, the +CLI commands should be rewritten but maintained in the same file. + +Since all CLI configuration commands from FRR will need to be rewritten, +this is an excellent opportunity to rework this part of the code to make +the commands easier to maintain and extend. These are the three main +recommendations: 1. Always use DEFPY instead of DEFUN to improve code +readability. 2. Always try to join multiple DEFUNs into a single DEFPY +whenever possible. As an example, there’s no need to have both +``distance (1-255) A.B.C.D/M`` and ``distance (1-255) A.B.C.D/M WORD`` +when a single ``distance (1-255) A.B.C.D/M [WORD]`` would suffice. 3. +When necessary, create a separate DEFPY for ``no`` commands so that part +of the configuration command can be made optional for convenience. +Example: +``no timers basic [(5-2147483647) (5-2147483647) (5-2147483647)]``. In +this example, everything after ``no timers basic`` is ignored by FRR, so +it makes sense to accept ``no timers basic`` as a valid command. But it +also makes sense to accept all parameters +(``no timers basic (5-2147483647) (5-2147483647) (5-2147483647)``) to +make it easier to remove the command just by prefixing a “no” to it. + +To rewrite a CLI command as a dumb wrapper around the northbound +callbacks, use the ``nb_cli_cfg_change()`` function. This function +accepts as a parameter an array of ``cli_config_change`` structures that +specify the changes that need to performed on the candidate +configuration. Here’s the declaration of this structure (taken from the +*lib/northbound_cli.h* file): + +.. code:: c + + struct cli_config_change { + /* + * XPath (absolute or relative) of the configuration option being + * edited. + */ + char xpath[XPATH_MAXLEN]; + + /* + * Operation to apply (either NB_OP_CREATE, NB_OP_MODIFY or + * NB_OP_DESTROY). + */ + enum nb_operation operation; + + /* + * New value of the configuration option. Should be NULL for typeless + * YANG data (e.g. presence-containers). For convenience, NULL can also + * be used to restore a leaf to its default value. + */ + const char *value; + }; + +The ``nb_cli_cfg_change()`` function positions the CLI command on top on +top of the northbound layer. Instead of changing the running +configuration directly, this function changes the candidate +configuration instead, as described in the [[Transactional CLI]] page. +When the transactional CLI is not in use (i.e. the default mode), then +``nb_cli_cfg_change()`` performs an implicit ``commit`` operation after +changing the candidate configuration. + + NOTE: the ``nb_cli_cfg_change()`` function clones the candidate + configuration before actually editing it. This way, if any error + happens during the editing, the original candidate is restored to + avoid inconsistencies. Either all changes from the configuration + command are performed successfully or none are. It’s like a + mini-transaction but happening on the candidate configuration (thus + the northbound callbacks are not involved). + +Other important details to keep in mind while rewriting the CLI +commands: \* ``nb_cli_cfg_change()`` returns CLI errors codes +(e.g. ``CMD_SUCCESS``, ``CMD_WARNING``), so the return value of this +function can be used as the return value of CLI commands. \* Calls to +``VTY_PUSH_CONTEXT`` and ``VTY_PUSH_CONTEXT_SUB`` should be converted to +calls to ``VTY_PUSH_XPATH``. Similarly, the following macros aren’t +necessary anymore and can be removed: ``VTY_DECLVAR_CONTEXT``, +``VTY_DECLVAR_CONTEXT_SUB``, ``VTY_GET_CONTEXT`` and +``VTY_CHECK_CONTEXT``. The ``nb_cli_cfg_change()`` functions uses the +``VTY_CHECK_XPATH`` macro to check if the data node being edited still +exists before doing anything else. + +The examples below provide additional details about how the conversion +should be done. + +Example 1 +^^^^^^^^^ + +In this first example, the *router rip* command becomes a dumb wrapper +around the ``ripd_instance_create()`` callback. Note that we don’t need +to check if the ``/frr-ripd:ripd/instance`` data path already exists +before trying to create it. The northbound will detect when this +presence-container already exists and do nothing. The +``VTY_PUSH_XPATH()`` macro is used to change the vty node and set the +context for other commands under *router rip*. + +.. code:: c + + DEFPY_NOSH (router_rip, + router_rip_cmd, + "router rip", + "Enable a routing process\n" + "Routing Information Protocol (RIP)\n") + { + int ret; + + struct cli_config_change changes[] = { + { + .xpath = "/frr-ripd:ripd/instance", + .operation = NB_OP_CREATE, + .value = NULL, + }, + }; + + ret = nb_cli_cfg_change(vty, NULL, changes, array_size(changes)); + if (ret == CMD_SUCCESS) + VTY_PUSH_XPATH(RIP_NODE, changes[0].xpath); + + return ret; + } + +Example 2 +^^^^^^^^^ + +Here we can see the use of relative xpaths (starting with ``./``), which +are more convenient that absolute xpaths (which would be +``/frr-ripd:ripd/instance/default-metric`` in this example). This is +possible because the use of ``VTY_PUSH_XPATH()`` in the *router rip* +command set the vty base xpath to ``/frr-ripd:ripd/instance``. + +.. code:: c + + DEFPY (rip_default_metric, + rip_default_metric_cmd, + "default-metric (1-16)", + "Set a metric of redistribute routes\n" + "Default metric\n") + { + struct cli_config_change changes[] = { + { + .xpath = "./default-metric", + .operation = NB_OP_MODIFY, + .value = default_metric_str, + }, + }; + + return nb_cli_cfg_change(vty, NULL, changes, array_size(changes)); + } + +In the command below we the ``value`` to NULL to indicate that we want +to set this leaf to its default value. This is better than hardcoding +the default value because the default might change in the future. Also, +users might define custom defaults by using YANG deviations, so it’s +better to write code that works correctly regardless of the default +values defined in the YANG models. + +.. code:: c + + DEFPY (no_rip_default_metric, + no_rip_default_metric_cmd, + "no default-metric [(1-16)]", + NO_STR + "Set a metric of redistribute routes\n" + "Default metric\n") + { + struct cli_config_change changes[] = { + { + .xpath = "./default-metric", + .operation = NB_OP_MODIFY, + .value = NULL, + }, + }; + + return nb_cli_cfg_change(vty, NULL, changes, array_size(changes)); + } + +Example 3 +^^^^^^^^^ + +This example shows how one command can change multiple leaves at the +same time. + +.. code:: c + + DEFPY (rip_timers, + rip_timers_cmd, + "timers basic (5-2147483647)$update (5-2147483647)$timeout (5-2147483647)$garbage", + "Adjust routing timers\n" + "Basic routing protocol update timers\n" + "Routing table update timer value in second. Default is 30.\n" + "Routing information timeout timer. Default is 180.\n" + "Garbage collection timer. Default is 120.\n") + { + struct cli_config_change changes[] = { + { + .xpath = "./timers/update-interval", + .operation = NB_OP_MODIFY, + .value = update_str, + }, + { + .xpath = "./timers/holddown-interval", + .operation = NB_OP_MODIFY, + .value = timeout_str, + }, + { + .xpath = "./timers/flush-interval", + .operation = NB_OP_MODIFY, + .value = garbage_str, + }, + }; + + return nb_cli_cfg_change(vty, NULL, changes, array_size(changes)); + } + +Example 4 +^^^^^^^^^ + +This example shows how to create a list entry: + +.. code:: c + + DEFPY (rip_distance_source, + rip_distance_source_cmd, + "distance (1-255) A.B.C.D/M$prefix [WORD$acl]", + "Administrative distance\n" + "Distance value\n" + "IP source prefix\n" + "Access list name\n") + { + char xpath_list[XPATH_MAXLEN]; + struct cli_config_change changes[] = { + { + .xpath = ".", + .operation = NB_OP_CREATE, + }, + { + .xpath = "./distance", + .operation = NB_OP_MODIFY, + .value = distance_str, + }, + { + .xpath = "./access-list", + .operation = acl ? NB_OP_MODIFY : NB_OP_DESTROY, + .value = acl, + }, + }; + + snprintf(xpath_list, sizeof(xpath_list), "./distance/source[prefix='%s']", + prefix_str); + + return nb_cli_cfg_change(vty, xpath_list, changes, array_size(changes)); + } + +The ``xpath_list`` variable is used to hold the xpath that identifies +the list entry. The keys of the list entry should be embedded in this +xpath and don’t need to be part of the array of configuration changes. +All entries from the ``changes`` array use relative xpaths which are +based on the xpath of the list entry. + +The ``access-list`` optional leaf can be either modified or deleted +depending whether the optional *WORD* parameter is present or not. + +When deleting a list entry, all non-key leaves can be ignored: + +.. code:: c + + DEFPY (no_rip_distance_source, + no_rip_distance_source_cmd, + "no distance (1-255) A.B.C.D/M$prefix [WORD$acl]", + NO_STR + "Administrative distance\n" + "Distance value\n" + "IP source prefix\n" + "Access list name\n") + { + char xpath_list[XPATH_MAXLEN]; + struct cli_config_change changes[] = { + { + .xpath = ".", + .operation = NB_OP_DESTROY, + }, + }; + + snprintf(xpath_list, sizeof(xpath_list), "./distance/source[prefix='%s']", + prefix_str); + + return nb_cli_cfg_change(vty, xpath_list, changes, 1); + } + +Example 5 +^^^^^^^^^ + +This example shows a DEFPY statement that performs two validations +before calling ``nb_cli_cfg_change()``: + +.. code:: c + + DEFPY (ip_rip_authentication_string, + ip_rip_authentication_string_cmd, + "ip rip authentication string LINE$password", + IP_STR + "Routing Information Protocol\n" + "Authentication control\n" + "Authentication string\n" + "Authentication string\n") + { + struct cli_config_change changes[] = { + { + .xpath = "./frr-ripd:rip/authentication/password", + .operation = NB_OP_MODIFY, + .value = password, + }, + }; + + if (strlen(password) > 16) { + vty_out(vty, + "%% RIPv2 authentication string must be shorter than 16\n"); + return CMD_WARNING_CONFIG_FAILED; + } + + if (yang_dnode_exists(vty->candidate_config->dnode, "%s%s", + VTY_GET_XPATH, + "/frr-ripd:rip/authentication/key-chain")) { + vty_out(vty, "%% key-chain configuration exists\n"); + return CMD_WARNING_CONFIG_FAILED; + } + + return nb_cli_cfg_change(vty, NULL, changes, array_size(changes)); + } + +These two validations are not strictly necessary since the configuration +change is validated using libyang afterwards. The issue with the libyang +validation is that the error messages from libyang are too verbose: + +:: + + ripd# conf t + ripd(config)# interface eth0 + ripd(config-if)# ip rip authentication string XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + % Failed to edit candidate configuration. + + Value "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" does not satisfy the constraint "1..16" (range, length, or pattern). + Failed to create node "authentication-password" as a child of "rip". + YANG path: /frr-interface:lib/interface[name='eth0'][vrf='Default-IP-Routing-Table']/frr-ripd:rip/authentication-password + +On the other hand, the original error message from ripd is much cleaner: + +:: + + ripd# conf t + ripd(config)# interface eth0 + ripd(config-if)# ip rip authentication string XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + % RIPv2 authentication string must be shorter than 16 + +The second validation is a bit more complex. If we try to create the +``authentication/password`` leaf when the ``authentication/key-chain`` +leaf already exists (both are under a YANG *choice* statement), libyang +will automatically delete the ``authentication/key-chain`` and create +``authentication/password`` on its place. This is different from the +original ripd behavior where the *ip rip authentication key-chain* +command must be removed before configuring the *ip rip authentication +string* command. + +In the spirit of not introducing any backward-incompatible changes in +the CLI, converted commands should retain some of their validation +checks to preserve their original behavior. + +Step 6: implement the ``cli_show`` callbacks +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The traditional method used by FRR to display the running configuration +consists of looping through all CLI nodes all call their ``func`` +callbacks one by one, which in turn read the configuration from internal +variables and dump them to the terminal in the form of CLI commands. + +The problem with this approach is twofold. First, since the callbacks +read the configuration from internal variables, they can’t display +anything other than the running configuration. Second, they don’t have +the ability to display default values when requested by the user +(e.g. *show configuration candidate with-defaults*). + +The new northbound architecture solves these problems by introducing a +new callback: ``cli_show``. Here’s the signature of this function (taken +from the *lib/northbound.h* file): + +.. code:: c + + /* + * Optional callback to show the CLI command associated to the given + * YANG data node. + * + * vty + * the vty terminal to dump the configuration to + * + * dnode + * libyang data node that should be shown in the form of a CLI + * command + * + * show_defaults + * specify whether to display default configuration values or not. + * This parameter can be ignored most of the time since the + * northbound doesn't call this callback for default leaves or + * non-presence containers that contain only default child nodes. + * The exception are commands associated to multiple configuration + * options, in which case it might be desirable to hide one or more + * parts of the command when this parameter is set to false. + */ + void (*cli_show)(struct vty *vty, struct lyd_node *dnode, + bool show_defaults); + +One of the main differences to the old CLI ``func`` callbacks is that +the ``cli_show`` callbacks are associated to YANG data paths and not to +CLI nodes. This means we can define one separate callback for each CLI +command, making the code more modular and easier to maintain (among +other advantages that will be more clear later). For enhanced code +readability, it’s recommended to position the ``cli_show`` callbacks +immediately after their associated command definitions (DEFPYs). + +The ``cli_show`` callbacks are used by the ``nb_cli_show_config_cmds()`` +function to display configurations stored inside ``nb_config`` +structures. The configuration being displayed can be anything from the +running configuration (*show configuration running*), a candidate +configuration (*show configuration candidate*) or a rollback +configuration (*show configuration transaction (1-4294967296)*). The +``nb_cli_show_config_cmds()`` function works by iterating over all data +nodes from the given configuration and calling the ``cli_show`` callback +for the nodes where it’s defined. If a list has dozens of entries, the +``cli_show`` callback associated to this list will be called multiple +times with the ``dnode`` parameter pointing to different list entries on +each iteration. + +For backward compatibility with the *show running-config* command, we +can’t get rid of the CLI ``func`` callbacks at this point in time. +However, we can make the CLI ``func`` callbacks call the corresponding +``cli_show`` callbacks to avoid code duplication. The +``nb_cli_show_dnode_cmds()`` function can be used for that purpose. Once +the CLI retrofitting process finishes for all FRR daemons, we can remove +the legacy CLI ``func`` callbacks and turn *show running-config* into a +shorthand for *show configuration running*. + +Regarding displaying configuration with default values, this is +something that is taken care of by the ``nb_cli_show_config_cmds()`` +function itself. When the *show configuration* command is used without +the *with-defaults* option, ``nb_cli_show_config_cmds()`` will skip +calling ``cli_show`` callbacks for data nodes that contain only default +values (e.g. default leaves or non-presence containers that contain only +default child nodes). There are however some exceptional cases where the +implementer of the ``cli_show`` callback should take into consideration +if default values should be displayed or not. This and other concepts +will be explained in more detail in the examples below. + +.. _example-1-1: + +Example 1 +^^^^^^^^^ + +Command: ``default-metric (1-16)`` + +YANG representation: + +.. code:: yang + + leaf default-metric { + type uint8 { + range "1..16"; + } + default "1"; + description + "Default metric of redistributed routes."; + } + +Placement of the ``cli_show`` callback: + +.. code:: diff + + { + .xpath = "/frr-ripd:ripd/instance/default-metric", + .cbs.modify = ripd_instance_default_metric_modify, + + .cbs.cli_show = cli_show_rip_default_metric, + }, + +Implementation of the ``cli_show`` callback: + +.. code:: c + + void cli_show_rip_default_metric(struct vty *vty, struct lyd_node *dnode, + bool show_defaults) + { + vty_out(vty, " default-metric %s\n", + yang_dnode_get_string(dnode, NULL)); + } + +In this first example, the *default-metric* command was modeled using a +YANG leaf, and we added a new ``cli_show`` callback attached to the YANG +path of this leaf. + +The callback makes use of the ``yang_dnode_get_string()`` function to +obtain the string value of the configuration option. The following would +also be possible: + +.. code:: c + + vty_out(vty, " default-metric %u\n", + yang_dnode_get_uint8(dnode, NULL)); + +Both options are possible because libyang stores both a binary +representation and a textual representation of all values stored in a +data node (``lyd_node``). For simplicity, it’s recommended to always use +``yang_dnode_get_string()`` in the ``cli_show`` callbacks. + +.. _example-2-1: + +Example 2 +^^^^^^^^^ + +Command: ``router rip`` + +YANG representation: + +.. code:: yang + + container instance { + presence "Present if the RIP protocol is enabled."; + description + "RIP routing instance."; + [snip] + } + +Placement of the ``cli_show`` callback: + +.. code:: diff + + { + .xpath = "/frr-ripd:ripd/instance", + .cbs.create = ripd_instance_create, + .cbs.delete = ripd_instance_delete, + + .cbs.cli_show = cli_show_router_rip, + }, + +Implementation of the ``cli_show`` callback: + +.. code:: c + + void cli_show_router_rip(struct vty *vty, struct lyd_node *dnode, + bool show_defaults) + { + vty_out(vty, "!\n"); + vty_out(vty, "router rip\n"); + } + +In this example, the ``cli_show`` callback doesn’t need to obtain any +value from the ``dnode`` parameter since presence-containers don’t hold +any data (apart from their child nodes, but they have their own +``cli_show`` callbacks). + +.. _example-3-1: + +Example 3 +^^^^^^^^^ + +Command: ``timers basic (5-2147483647) (5-2147483647) (5-2147483647)`` + +YANG representation: + +.. code:: yang + + container timers { + description + "Settings of basic timers"; + leaf flush-interval { + type uint32 { + range "5..2147483647"; + } + units "seconds"; + default "120"; + description + "Interval before a route is flushed from the routing + table."; + } + leaf holddown-interval { + type uint32 { + range "5..2147483647"; + } + units "seconds"; + default "180"; + description + "Interval before better routes are released."; + } + leaf update-interval { + type uint32 { + range "5..2147483647"; + } + units "seconds"; + default "30"; + description + "Interval at which RIP updates are sent."; + } + } + +Placement of the ``cli_show`` callback: + +.. code:: diff + + { + + .xpath = "/frr-ripd:ripd/instance/timers", + + .cbs.cli_show = cli_show_rip_timers, + + }, + + { + .xpath = "/frr-ripd:ripd/instance/timers/flush-interval", + .cbs.modify = ripd_instance_timers_flush_interval_modify, + }, + { + .xpath = "/frr-ripd:ripd/instance/timers/holddown-interval", + .cbs.modify = ripd_instance_timers_holddown_interval_modify, + }, + { + .xpath = "/frr-ripd:ripd/instance/timers/update-interval", + .cbs.modify = ripd_instance_timers_update_interval_modify, + }, + +Implementation of the ``cli_show`` callback: + +.. code:: c + + void cli_show_rip_timers(struct vty *vty, struct lyd_node *dnode, + bool show_defaults) + { + vty_out(vty, " timers basic %s %s %s\n", + yang_dnode_get_string(dnode, "./update-interval"), + yang_dnode_get_string(dnode, "./holddown-interval"), + yang_dnode_get_string(dnode, "./flush-interval")); + } + +This command is a bit different since it changes three leaves at the +same time. This means we need to have a single ``cli_show`` callback in +order to display the three leaves together in the same line. + +The new ``cli_show_rip_timers()`` callback was added attached to the +*timers* non-presence container that groups the three leaves. Without +the *timers* non-presence container we’d need to display the *timers +basic* command inside the ``cli_show_router_rip()`` callback, which +would break our requirement of having a separate ``cli_show`` callback +for each configuration command. + +.. _example-4-1: + +Example 4 +^^^^^^^^^ + +Command: +``redistribute <kernel|connected|static|ospf|isis|bgp|eigrp|nhrp|table|vnc|babel|sharp> [{metric (0-16)|route-map WORD}]`` + +YANG representation: + +.. code:: yang + + list redistribute { + key "protocol"; + description + "Redistributes routes learned from other routing protocols."; + leaf protocol { + type frr-route-types:frr-route-types-v4; + description + "Routing protocol."; + must '. != "rip"'; + } + leaf route-map { + type string { + length "1..max"; + } + description + "Applies the conditions of the specified route-map to + routes that are redistributed into the RIP routing + instance."; + } + leaf metric { + type uint8 { + range "0..16"; + } + description + "Metric used for the redistributed route. If a metric is + not specified, the metric configured with the + default-metric attribute in RIP router configuration is + used. If the default-metric attribute has not been + configured, the default metric for redistributed routes + is 0."; + } + } + +Placement of the ``cli_show`` callback: + +.. code:: diff + + { + .xpath = "/frr-ripd:ripd/instance/redistribute", + .cbs.create = ripd_instance_redistribute_create, + .cbs.delete = ripd_instance_redistribute_delete, + + .cbs.cli_show = cli_show_rip_redistribute, + }, + { + .xpath = "/frr-ripd:ripd/instance/redistribute/route-map", + .cbs.modify = ripd_instance_redistribute_route_map_modify, + .cbs.delete = ripd_instance_redistribute_route_map_delete, + }, + { + .xpath = "/frr-ripd:ripd/instance/redistribute/metric", + .cbs.modify = ripd_instance_redistribute_metric_modify, + .cbs.delete = ripd_instance_redistribute_metric_delete, + }, + +Implementation of the ``cli_show`` callback: + +.. code:: c + + void cli_show_rip_redistribute(struct vty *vty, struct lyd_node *dnode, + bool show_defaults) + { + vty_out(vty, " redistribute %s", + yang_dnode_get_string(dnode, "./protocol")); + if (yang_dnode_exists(dnode, "./metric")) + vty_out(vty, " metric %s", + yang_dnode_get_string(dnode, "./metric")); + if (yang_dnode_exists(dnode, "./route-map")) + vty_out(vty, " route-map %s", + yang_dnode_get_string(dnode, "./route-map")); + vty_out(vty, "\n"); + } + +Similar to the previous example, the *redistribute* command changes +several leaves at the same time, and we need a single callback to +display all leaves in a single line in accordance to the CLI command. In +this case, the leaves are already grouped by a YANG list so there’s no +need to add a non-presence container. The new ``cli_show`` callback was +attached to the YANG path of the list. + +It’s also worth noting the use of the ``yang_dnode_exists()`` function +to check if optional leaves exist in the configuration before displaying +them. + +.. _example-5-1: + +Example 5 +^^^^^^^^^ + +Command: +``ip rip authentication mode <md5 [auth-length <rfc|old-ripd>]|text>`` + +YANG representation: + +.. code:: yang + + container authentication-scheme { + description + "Specify the authentication scheme for the RIP interface"; + leaf mode { + type enumeration { + [snip] + } + default "none"; + description + "Specify the authentication mode."; + } + leaf md5-auth-length { + when "../mode = 'md5'"; + type enumeration { + [snip] + } + default "20"; + description + "MD5 authentication data length."; + } + } + +Placement of the ``cli_show`` callback: + +.. code:: diff + + + { + + .xpath = "/frr-interface:lib/interface/frr-ripd:rip/authentication-scheme", + + .cbs.cli_show = cli_show_ip_rip_authentication_scheme, + }, + { + .xpath = "/frr-interface:lib/interface/frr-ripd:rip/authentication-scheme/mode", + .cbs.modify = lib_interface_rip_authentication_scheme_mode_modify, + }, + { + .xpath = "/frr-interface:lib/interface/frr-ripd:rip/authentication-scheme/md5-auth-length", + .cbs.modify = lib_interface_rip_authentication_scheme_md5_auth_length_modify, + .cbs.delete = lib_interface_rip_authentication_scheme_md5_auth_length_delete, + }, + +Implementation of the ``cli_show`` callback: + +.. code:: c + + void cli_show_ip_rip_authentication_scheme(struct vty *vty, + struct lyd_node *dnode, + bool show_defaults) + { + switch (yang_dnode_get_enum(dnode, "./mode")) { + case RIP_NO_AUTH: + vty_out(vty, " no ip rip authentication mode\n"); + break; + case RIP_AUTH_SIMPLE_PASSWORD: + vty_out(vty, " ip rip authentication mode text\n"); + break; + case RIP_AUTH_MD5: + vty_out(vty, " ip rip authentication mode md5"); + if (show_defaults + || !yang_dnode_is_default(dnode, "./md5-auth-length")) { + if (yang_dnode_get_enum(dnode, "./md5-auth-length") + == RIP_AUTH_MD5_SIZE) + vty_out(vty, " auth-length rfc"); + else + vty_out(vty, " auth-length old-ripd"); + } + vty_out(vty, "\n"); + break; + } + } + +This is the most complex ``cli_show`` callback we have in ripd. Its +complexity comes from the following: \* The +``ip rip authentication mode ...`` command changes two YANG leaves at +the same time. \* Part of the command should be hidden when the +``show_defaults`` parameter is set to false. + +This is the behavior we want to implement: + +:: + + ripd(config)# interface eth0 + ripd(config-if)# ip rip authentication mode md5 + ripd(config-if)# + ripd(config-if)# show configuration candidate + Configuration: + ! + [snip] + ! + interface eth0 + ip rip authentication mode md5 + ! + end + ripd(config-if)# + ripd(config-if)# show configuration candidate with-defaults + Configuration: + ! + [snip] + ! + interface eth0 + [snip] + ip rip authentication mode md5 auth-length old-ripd + ! + end + +Note that ``auth-length old-ripd`` should be hidden unless the +configuration is shown using the *with-defaults* option. This is why the +``cli_show_ip_rip_authentication_scheme()`` callback needs to consult +the value of the *show_defaults* parameter. It’s expected that only a +very small minority of all ``cli_show`` callbacks will need to consult +the *show_defaults* parameter (there’s a chance this might be the only +case!) + +In the case of the *timers basic* command seen before, we need to +display the value of all leaves even if only one of them has a value +different from the default. Hence the ``cli_show_rip_timers()`` callback +was able to completely ignore the *show_defaults* parameter. + +Step 7: consolidation +~~~~~~~~~~~~~~~~~~~~~ + +As mentioned in the fourth step, the northbound retrofitting process can +happen gradually over time, since both “old” and “new” commands can +coexist without problems. Once all commands from a given daemon were +converted, we can proceed to the consolidation step, which consists of +the following: \* Remove the vty configuration lock, which is enabled by +default in all daemons. Now multiple users should be able to edit the +configuration concurrently, using either shared or private candidate +configurations. \* Reference commit: +`57dccdb1 <https://github.com/opensourcerouting/frr/commit/57dccdb18b799556214dcfb8943e248c0bf1f6a6>`__. +\* Stop using the qobj infrastructure to keep track of configuration +objects. This is not necessary anymore, the northbound uses a similar +mechanism to keep track of YANG data nodes in the candidate +configuration. \* Reference commit: +`4e6d63ce <https://github.com/opensourcerouting/frr/commit/4e6d63cebd988af650c1c29d0f2e5a251c8d2e7a>`__. +\* Make the daemon SIGHUP handler re-read the configuration file (and +ensure it’s not doing anything other than that). \* Reference commit: +`5e57edb4 <https://github.com/opensourcerouting/frr/commit/5e57edb4b71ff03f9a22d9ec1412c3c5167f90cf>`__. + +Final Considerations +-------------------- + +Testing +~~~~~~~ + +Converting CLI commands to the new northbound model can be a complicated +task for beginners, but the more commands one converts, the easier it +gets. It’s highly recommended to perform as much testing as possible on +the converted commands to reduce the likelihood of introducing +regressions. Tools like topotests, ANVL and the `CLI +fuzzer <https://github.com/rwestphal/frr-cli-fuzzer>`__ can be used to +catch hidden bugs that might be present. As usual, it’s also recommended +to use valgrind and static code analyzers to catch other types of +problems like memory leaks. + +Amount of work +~~~~~~~~~~~~~~ + +The output below gives a rough estimate of the total number of +configuration commands that need to be converted per daemon: + +.. code:: sh + + $ for dir in lib zebra bgpd ospfd ospf6d isisd ripd ripngd eigrpd pimd pbrd ldpd nhrpd babeld ; do echo -n "$dir: " && cd $dir && grep -ERn "DEFUN|DEFPY" * | grep -Ev "clippy|show|clear" | wc -l && cd ..; done + lib: 302 + zebra: 181 + bgpd: 569 + ospfd: 198 + ospf6d: 99 + isisd: 126 + ripd: 64 + ripngd: 44 + eigrpd: 58 + pimd: 113 + pbrd: 9 + ldpd: 46 + nhrpd: 24 + babeld: 28 + +As it can be seen, the northbound retrofitting process will demand a lot +of work from FRR developers and should take months to complete. Everyone +is welcome to collaborate! diff --git a/doc/developer/northbound/transactional-cli.rst b/doc/developer/northbound/transactional-cli.rst new file mode 100644 index 0000000000..439bb6afce --- /dev/null +++ b/doc/developer/northbound/transactional-cli.rst @@ -0,0 +1,244 @@ +Table of Contents +----------------- + +- `Introduction <#introduction>`__ +- `Configuration modes <#config-modes>`__ +- `New commands <#retrofitting-process>`__ + + - `commit check <#cmd1>`__ + - `commit <#cmd2>`__ + - `discard <#cmd3>`__ + - `configuration database max-transactions <#cmd4>`__ + - `configuration load <#cmd5>`__ + - `rollback configuration <#cmd6>`__ + - `show configuration candidate <#cmd7>`__ + - `show configuration compare <#cmd8>`__ + - `show configuration running <#cmd9>`__ + - `show configuration transaction <#cmd10>`__ + - `show yang module <#cmd11>`__ + - `show yang module-translator <#cmd12>`__ + - `update <#cmd13>`__ + - `yang module-translator load <#cmd14>`__ + - `yang module-translator unload <#cmd15>`__ + +Introduction +~~~~~~~~~~~~ + +All FRR daemons have built-in support for the CLI, which can be accessed +either through local telnet or via the vty socket (e.g. by using +*vtysh*). This will not change with the introduction of the Northbound +API. However, a new command-line option will be available for all FRR +daemons: ``--tcli``. When given, this option makes the daemon start with +a transactional CLI and configuration commands behave a bit different. +Instead of editing the running configuration, they will edit the +candidate configuration. In other words, the configuration commands +won’t be applied immediately, that has to be done on a separate step +using the new ``commit`` command. + +The transactional CLI simply leverages the new capabilities provided by +the Northbound API and exposes the concept of candidate configurations +to CLI users too. When the transactional mode is not used, the +configuration commands also edit the candidate configuration, but +there’s an implicit ``commit`` after each command. + +In order for the transactional CLI to work, all configuration commands +need to be converted to the new northbound model. Commands not converted +to the new northbound model will change the running configuration +directly since they bypass the FRR northbound layer. For this reason, +starting a daemon with the transactional CLI is not advisable unless all +of its commands have already been converted. When that’s not the case, +we can run into a situation like this: + +:: + + ospfd(config)# router ospf + ospfd(config-router)# ospf router-id 1.1.1.1 + [segfault in ospfd] + +The segfault above can happen if ``router ospf`` edits the candidate +configuration but ``ospf router-id 1.1.1.1`` edits the running +configuration. The second command tries to set +``ospf->router_id_static`` but, since the previous ``router ospf`` +command hasn’t been commited yet, the ``ospf`` global variable is set to +NULL, which leads to the crash. Besides this problem, having a set of +commands that edit the candidate configuration and others that edit the +running configuration is confusing at best. The ``--tcli`` option should +be used only by developers until the northbound retrofitting process is +complete. + +Configuration modes +~~~~~~~~~~~~~~~~~~~ + +When using the transactional CLI (``--tcli``), FRR supports three +different forms of the ``configure`` command: \* ``configure terminal``: +in this mode, a single candidate configuration is shared by all users. +This means that one user might delete a configuration object that’s +being edited by another user, in which case the CLI will detect and +report the problem. If one user issues the ``commit`` command, all +changes done by all users are committed. \* ``configure private``: users +have a private candidate configuration that is edited separately from +the other users. The ``commit`` command commits only the changes done by +the user. \* ``configure exclusive``: similar to ``configure private``, +but also locks the running configuration to prevent other users from +changing it. The configuration lock is released when the user exits the +configuration mode. + +When using ``configure terminal`` or ``configure private``, the +candidate configuration being edited might become outdated if another +user commits a different candidate configuration on another session. +TODO: show image to illustrate the problem. + +New commands +~~~~~~~~~~~~ + +The list below contains the new CLI commands introduced by Northbound +API. The commands are available when a daemon is started using the +transactional CLI (``--tcli``). Currently ``vtysh`` doesn’t support any +of these new commands. + +Please refer to the [[Demos]] page to see a demo of the transactional +CLI in action. + +-------------- + +``commit check`` +'''''''''''''''' + +Check if the candidate configuration is valid or not. + +``commit [force] [comment LINE...]`` +'''''''''''''''''''''''''''''''''''' + +Commit the changes done in the candidate configuration into the running +configuration. + +Options: \* ``force``: commit even if the candidate configuration is +outdated. It’s usually a better option to use the ``update`` command +instead. \* ``comment LINE...``: assign a comment to the configuration +transaction. This comment is displayed when viewing the recorded +transactions in the output of the ``show configuration transaction`` +command. + +``discard`` +''''''''''' + +Discard the changes done in the candidate configuration. + +``configuration database max-transactions (1-100)`` +''''''''''''''''''''''''''''''''''''''''''''''''''' + +Set the maximum number of transactions to store in the rollback log. + +``configuration load <file [<json|xml> [translate WORD]] FILENAME|transaction (1-4294967296)> [replace]`` +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +Load a new configuration into the candidate configuration. When loading +the configuration from a file, it’s assumed that the configuration will +be in the form of CLI commands by default. The ``json`` and ``xml`` +options can be used to load configurations in the JSON and XML formats, +respectively. It’s also possible to load a configuration from a previous +transaction by specifying the desired transaction ID +(``(1-4294967296)``). + +Options: \* ``translate WORD``: translate the JSON/XML configuration +file using the YANG module translator. \* ``replace``: replace the +candidate by the loaded configuration. The default is to merge the +loaded configuration into the candidate configuration. + +``rollback configuration (1-4294967296)`` +''''''''''''''''''''''''''''''''''''''''' + +Roll back the running configuration to a previous configuration +identified by its transaction ID (``(1-4294967296)``). + +``show configuration candidate [<json|xml> [translate WORD]] [<with-defaults|changes>]`` +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +Show the candidate configuration. + +Options: \* ``json``: show the configuration in the JSON format. \* +``xml``: show the configuration in the XML format. \* +``translate WORD``: translate the JSON/XML output using the YANG module +translator. \* ``with-defaults``: show default values that are hidden by +default. \* ``changes``: show only the changes done in the candidate +configuration. + +``show configuration compare <candidate|running|transaction (1-4294967296)> <candidate|running|transaction (1-4294967296)> [<json|xml> [translate WORD]]`` +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +Show the difference between two different configurations. + +Options: \* ``json``: show the configuration differences in the JSON +format. \* ``xml``: show the configuration differences in the XML +format. \* ``translate WORD``: translate the JSON/XML output using the +YANG module translator. + +``show configuration running [<json|xml> [translate WORD]] [with-defaults]`` +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +Show the running configuration. + +Options: \* ``json``: show the configuration in the JSON format. \* +``xml``: show the configuration in the XML format. \* +``translate WORD``: translate the JSON/XML output using the YANG module +translator. \* ``with-defaults``: show default values that are hidden by +default. + + NOTE: ``show configuration running`` shows only the running + configuration as known by the northbound layer. Configuration + commands not converted to the new northbound model will not be + displayed. To show the full running configuration, the legacy + ``show running-config`` command must be used. + +``show configuration transaction [(1-4294967296) [<json|xml> [translate WORD]] [changes]]`` +''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +When a transaction ID (``(1-4294967296)``) is given, show the +configuration associated to the previously committed transaction. + +When a transaction ID is not given, show all recorded transactions in +the rollback log. + +Options: \* ``json``: show the configuration in the JSON format. \* +``xml``: show the configuration in the XML format. \* +``translate WORD``: translate the JSON/XML output using the YANG module +translator. \* ``with-defaults``: show default values that are hidden by +default. \* ``changes``: show changes compared to the previous +transaction. + +``show yang module [module-translator WORD] [WORD <summary|tree|yang|yin>]`` +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +When a YANG module is not given, show all loaded YANG modules. +Otherwise, show detailed information about the given module. + +Options: \* ``module-translator WORD``: change the context to modules +loaded by the specified YANG module translator. \* ``summary``: display +summary information about the module. \* ``tree``: display module in the +tree (RFC 8340) format. \* ``yang``: display module in the YANG format. +\* ``yin``: display module in the YIN format. + +``show yang module-translator`` +''''''''''''''''''''''''''''''' + +Show all loaded YANG module translators. + +``update`` +'''''''''' + +Rebase the candidate configuration on top of the latest running +configuration. Conflicts are resolved automatically by giving preference +to the changes done in the candidate configuration. + +The candidate configuration might be outdated if the running +configuration was updated after the candidate was created. + +``yang module-translator load FILENAME`` +'''''''''''''''''''''''''''''''''''''''' + +Load a YANG module translator from the filesystem. + +``yang module-translator unload WORD`` +'''''''''''''''''''''''''''''''''''''' + +Unload a YANG module translator identified by its name. diff --git a/doc/developer/northbound/yang-module-translator.rst b/doc/developer/northbound/yang-module-translator.rst new file mode 100644 index 0000000000..aa527ce6b2 --- /dev/null +++ b/doc/developer/northbound/yang-module-translator.rst @@ -0,0 +1,629 @@ +Table of Contents +----------------- + +- `Introduction <#introduction>`__ +- `Deviation Modules <#deviation-modules>`__ +- `Translation Tables <#translation-tables>`__ +- `CLI Demonstration <#cli-demonstration>`__ +- `Implementation Details <#implementation-details>`__ + +Introduction +------------ + +One key requirement for the FRR northbound architecture is that it +should be possible to configure/monitor FRR using different sets of YANG +models. This is especially important considering that the industry +hasn’t reached a consensus to provide a single source of standard models +for network management. At this moment both the IETF and OpenConfig +models are widely implemented and are unlikely to converge, at least not +in the short term. In the ideal scenario, management applications should +be able to use either IETF or OpenConfig models to configure and monitor +FRR programatically (or even both at the same time!). + +But how can FRR support multiple sets of YANG models at the same time? +There must be only a single source of truth that models the existing +implementation accurately (the native models). Writing different code +paths or callbacks for different models would be inviable, it would lead +to a lot of duplicated code and extra maintenance overhead. + +In order to support different sets of YANG modules without introducing +the overhead of writing additional code, the solution is to create a +mechanism that dynamically translates YANG instance data between +non-native models to native models and vice-versa. Based on this idea, +an experimental YANG module translator was implemented within the FRR +northbound layer. The translator works by translating XPaths at runtime +using translation tables provided by the user. The translator itself is +modeled using YANG and users can create translators using simple JSON +files. + +A YANG module translator consists of two components: deviation modules +and translation tables. + +Deviation Modules +----------------- + +The first step when writing a YANG module translator is to create a +`deviations <https://tools.ietf.org/html/rfc7950#page-131>`__ module for +each module that is going be translated. This is necessary because in +most cases it won’t be possible to create a perfect translator that +covers the non-native models on their entirety. Some non-native modules +might contain nodes that can’t be mapped to a corresponding node in the +FRR native models. This is either because the corresponding +functionality is not implemented in FRR or because it’s modeled in a +different way that is incompatible. + +An an example, *ripd* doesn’t have BFD support yet, so we need to create +a YANG deviation to modify the *ietf-rip* module and remove the ``bfd`` +container from it: + +.. code:: yang + + deviation "/ietf-routing:routing/ietf-routing:control-plane-protocols/ietf-routing:control-plane-protocol/ietf-rip:rip/ietf-rip:interfaces/ietf-rip:interface/ietf-rip:bfd" { + deviate not-supported; + } + +In the example below, while both the *frr-ripd* and *ietf-rip* modules +support RIP authentication, they model the authentication data in +different ways, making translation not possible given the constraints of +the current module translator. A new deviation is necessary to remove +the ``authentication`` container from the *ietf-rip* module: + +.. code:: yang + + deviation "/ietf-routing:routing/ietf-routing:control-plane-protocols/ietf-routing:control-plane-protocol/ietf-rip:rip/ietf-rip:interfaces/ietf-rip:interface/ietf-rip:authentication" { + deviate not-supported; + } + +.. + + NOTE: it should be possible to translate the + ``ietf-rip:authentication`` container if the *frr-ripd* module is + modified to model the corresponding data in a compatible way. Another + option is to improve the module translator to make more complex + translations possible, instead of requiring one-to-one XPath + mappings. + +Sometimes creating a mapping between nodes from the native and +non-native models is possible, but the nodes have different properties +that need to be normalized to allow the translation. In the example +below, a YANG deviation is used to change the type and the default value +from a node from the ``ietf-rip`` module. + +.. code:: yang + + deviation "/ietf-routing:routing/ietf-routing:control-plane-protocols/ietf-routing:control-plane-protocol/ietf-rip:rip/ietf-rip:timers/ietf-rip:flush-interval" { + deviate replace { + default "120"; + } + deviate replace { + type uint32; + } + } + +The deviation modules allow the management applications to know which +parts of the custom modules (e.g. IETF/OC) can be used to configure and +monitor FRR. + +In order to facilitate the process of creating YANG deviation modules, +the *gen_yang_deviations* tool was created to automate part of the +process. This tool creates a “not-supported” deviation for all nodes +from the given non-native module. Example: + +:: + + $ tools/gen_yang_deviations ietf-rip > yang/ietf/frr-deviations-ietf-rip.yang + $ head -n 40 yang/ietf/frr-deviations-ietf-rip.yang + deviation "/ietf-rip:clear-rip-route" { + deviate not-supported; + } + + deviation "/ietf-rip:clear-rip-route/ietf-rip:input" { + deviate not-supported; + } + + deviation "/ietf-rip:clear-rip-route/ietf-rip:input/ietf-rip:rip-instance" { + deviate not-supported; + } + + deviation "/ietf-routing:routing/ietf-routing:control-plane-protocols/ietf-routing:control-plane-protocol/ietf-rip:rip" { + deviate not-supported; + } + + deviation "/ietf-routing:routing/ietf-routing:control-plane-protocols/ietf-routing:control-plane-protocol/ietf-rip:rip/ietf-rip:originate-default-route" { + deviate not-supported; + } + + deviation "/ietf-routing:routing/ietf-routing:control-plane-protocols/ietf-routing:control-plane-protocol/ietf-rip:rip/ietf-rip:originate-default-route/ietf-rip:enabled" { + deviate not-supported; + } + + deviation "/ietf-routing:routing/ietf-routing:control-plane-protocols/ietf-routing:control-plane-protocol/ietf-rip:rip/ietf-rip:originate-default-route/ietf-rip:route-policy" { + deviate not-supported; + } + + deviation "/ietf-routing:routing/ietf-routing:control-plane-protocols/ietf-routing:control-plane-protocol/ietf-rip:rip/ietf-rip:default-metric" { + deviate not-supported; + } + + deviation "/ietf-routing:routing/ietf-routing:control-plane-protocols/ietf-routing:control-plane-protocol/ietf-rip:rip/ietf-rip:distance" { + deviate not-supported; + } + + deviation "/ietf-routing:routing/ietf-routing:control-plane-protocols/ietf-routing:control-plane-protocol/ietf-rip:rip/ietf-rip:triggered-update-threshold" { + deviate not-supported; + } + +Once all existing nodes are listed in the deviation module, it’s easy to +check the deviations that need to be removed or modified. This is more +convenient than starting with a blank deviations module and listing +manually all nodes that need to be deviated. + +After removing and/or modifying the auto-generated deviations, the next +step is to write the module XPath translation table as we’ll see in the +next section. Before that, it’s possible to use the *yanglint* tool to +check how the non-native module looks like after applying the +deviations. Example: + +:: + + $ yanglint -f tree yang/ietf/ietf-rip@2018-02-03.yang yang/ietf/frr-deviations-ietf-rip.yang + module: ietf-rip + + augment /ietf-routing:routing/ietf-routing:control-plane-protocols/ietf-routing:control-plane-protocol: + +--rw rip + +--rw originate-default-route + | +--rw enabled? boolean <false> + +--rw default-metric? uint8 <1> + +--rw distance? uint8 <0> + +--rw timers + | +--rw update-interval? uint32 <30> + | +--rw holddown-interval? uint32 <180> + | +--rw flush-interval? uint32 <120> + +--rw interfaces + | +--rw interface* [interface] + | +--rw interface ietf-interfaces:interface-ref + | +--rw split-horizon? enumeration <simple> + +--ro ipv4 + +--ro neighbors + | +--ro neighbor* [ipv4-address] + | +--ro ipv4-address ietf-inet-types:ipv4-address + | +--ro last-update? ietf-yang-types:date-and-time + | +--ro bad-packets-rcvd? ietf-yang-types:counter32 + | +--ro bad-routes-rcvd? ietf-yang-types:counter32 + +--ro routes + +--ro route* [ipv4-prefix] + +--ro ipv4-prefix ietf-inet-types:ipv4-prefix + +--ro next-hop? ietf-inet-types:ipv4-address + +--ro interface? ietf-interfaces:interface-ref + +--ro metric? uint8 + + rpcs: + +---x clear-rip-route + +.. + + NOTE: the same output can be obtained using the + ``show yang module module-translator ietf ietf-rip tree`` command in + FRR once the *ietf* module translator is loaded. + +In the example above, it can be seen that the vast majority of the +*ietf-rip* nodes were removed because of the “not-supported” deviations. +When a module translator is loaded, FRR calculates the coverage of the +translator by dividing the number of YANG nodes before applying the +deviations by the number of YANG nodes after applying the deviations. +The calculated coverage is displayed in the output of the +``show yang module-translator`` command: + +:: + + ripd# show yang module-translator + Family Module Deviations Coverage (%) + ----------------------------------------------------------------------- + ietf ietf-interfaces frr-deviations-ietf-interfaces 3.92 + ietf ietf-routing frr-deviations-ietf-routing 1.56 + ietf ietf-rip frr-deviations-ietf-rip 13.60 + +As it can be seen in the output above, the *ietf* module translator +covers only ~13% of the original *ietf-rip* module. This is in part +because the *ietf-rip* module models both RIPv2 and RIPng. Also, +*ietf-rip.yang* contains several knobs that aren’t implemented in *ripd* +yet (e.g. BFD support, per-interface timers, statistics, etc). Work can +be done over time to increase the coverage to a more reasonable number. + +Translation Tables +------------------ + +Below is an example of a translator for the IETF family of models: + +.. code:: json + + { + "frr-module-translator:frr-module-translator": { + "family": "ietf", + "module": [ + { + "name": "ietf-interfaces@2018-01-09", + "deviations": "frr-deviations-ietf-interfaces", + "mappings": [ + { + "custom": "/ietf-interfaces:interfaces/interface[name='KEY1']", + "native": "/frr-interface:lib/interface[name='KEY1'][vrf='default']" + }, + { + "custom": "/ietf-interfaces:interfaces/interface[name='KEY1']/description", + "native": "/frr-interface:lib/interface[name='KEY1'][vrf='default']/description" + } + ] + }, + { + "name": "ietf-routing@2018-01-25", + "deviations": "frr-deviations-ietf-routing", + "mappings": [ + { + "custom": "/ietf-routing:routing/control-plane-protocols/control-plane-protocol[type='ietf-rip:ripv2'][name='main']", + "native": "/frr-ripd:ripd/instance" + } + ] + }, + { + "name": "ietf-rip@2018-02-03", + "deviations": "frr-deviations-ietf-rip", + "mappings": [ + { + "custom": "/ietf-routing:routing/control-plane-protocols/control-plane-protocol[type='ietf-rip:ripv2'][name='main']/ietf-rip:rip/default-metric", + "native": "/frr-ripd:ripd/instance/default-metric" + }, + { + "custom": "/ietf-routing:routing/control-plane-protocols/control-plane-protocol[type='ietf-rip:ripv2'][name='main']/ietf-rip:rip/distance", + "native": "/frr-ripd:ripd/instance/distance/default" + }, + { + "custom": "/ietf-routing:routing/control-plane-protocols/control-plane-protocol[type='ietf-rip:ripv2'][name='main']/ietf-rip:rip/originate-default-route/enabled", + "native": "/frr-ripd:ripd/instance/default-information-originate" + }, + { + "custom": "/ietf-routing:routing/control-plane-protocols/control-plane-protocol[type='ietf-rip:ripv2'][name='main']/ietf-rip:rip/timers/update-interval", + "native": "/frr-ripd:ripd/instance/timers/update-interval" + }, + { + "custom": "/ietf-routing:routing/control-plane-protocols/control-plane-protocol[type='ietf-rip:ripv2'][name='main']/ietf-rip:rip/timers/holddown-interval", + "native": "/frr-ripd:ripd/instance/timers/holddown-interval" + }, + { + "custom": "/ietf-routing:routing/control-plane-protocols/control-plane-protocol[type='ietf-rip:ripv2'][name='main']/ietf-rip:rip/timers/flush-interval", + "native": "/frr-ripd:ripd/instance/timers/flush-interval" + }, + { + "custom": "/ietf-routing:routing/control-plane-protocols/control-plane-protocol[type='ietf-rip:ripv2'][name='main']/ietf-rip:rip/interfaces/interface[interface='KEY1']", + "native": "/frr-ripd:ripd/instance/interface[.='KEY1']" + }, + { + "custom": "/ietf-routing:routing/control-plane-protocols/control-plane-protocol[type='ietf-rip:ripv2'][name='main']/ietf-rip:rip/interfaces/interface[interface='KEY1']/split-horizon", + "native": "/frr-interface:lib/interface[name='KEY1'][vrf='default']/frr-ripd:rip/split-horizon" + }, + { + "custom": "/ietf-routing:routing/control-plane-protocols/control-plane-protocol/ietf-rip:rip/ipv4/neighbors/neighbor[ipv4-address='KEY1']", + "native": "/frr-ripd:ripd/state/neighbors/neighbor[address='KEY1']" + }, + { + "custom": "/ietf-routing:routing/control-plane-protocols/control-plane-protocol/ietf-rip:rip/ipv4/neighbors/neighbor[ipv4-address='KEY1']/last-update", + "native": "/frr-ripd:ripd/state/neighbors/neighbor[address='KEY1']/last-update" + }, + { + "custom": "/ietf-routing:routing/control-plane-protocols/control-plane-protocol/ietf-rip:rip/ipv4/neighbors/neighbor[ipv4-address='KEY1']/bad-packets-rcvd", + "native": "/frr-ripd:ripd/state/neighbors/neighbor[address='KEY1']/bad-packets-rcvd" + }, + { + "custom": "/ietf-routing:routing/control-plane-protocols/control-plane-protocol/ietf-rip:rip/ipv4/neighbors/neighbor[ipv4-address='KEY1']/bad-routes-rcvd", + "native": "/frr-ripd:ripd/state/neighbors/neighbor[address='KEY1']/bad-routes-rcvd" + }, + { + "custom": "/ietf-routing:routing/control-plane-protocols/control-plane-protocol/ietf-rip:rip/ipv4/routes/route[ipv4-prefix='KEY1']", + "native": "/frr-ripd:ripd/state/routes/route[prefix='KEY1']" + }, + { + "custom": "/ietf-routing:routing/control-plane-protocols/control-plane-protocol/ietf-rip:rip/ipv4/routes/route[ipv4-prefix='KEY1']/next-hop", + "native": "/frr-ripd:ripd/state/routes/route[prefix='KEY1']/next-hop" + }, + { + "custom": "/ietf-routing:routing/control-plane-protocols/control-plane-protocol/ietf-rip:rip/ipv4/routes/route[ipv4-prefix='KEY1']/interface", + "native": "/frr-ripd:ripd/state/routes/route[prefix='KEY1']/interface" + }, + { + "custom": "/ietf-routing:routing/control-plane-protocols/control-plane-protocol/ietf-rip:rip/ipv4/routes/route[ipv4-prefix='KEY1']/metric", + "native": "/frr-ripd:ripd/state/routes/route[prefix='KEY1']/metric" + }, + { + "custom": "/ietf-rip:clear-rip-route", + "native": "/frr-ripd:clear-rip-route" + } + ] + } + ] + } + } + +The main motivation to use YANG itself to model YANG module translators +was a practical one: leverage *libyang* to validate the structure of the +user input (JSON files) instead of doing that manually in the +*lib/yang_translator.c* file (tedious and error-prone work). + +Module translators can be loaded using the following CLI command: + +:: + + ripd(config)# yang module-translator load /usr/local/share/yang/ietf/frr-ietf-translator.json + % Module translator "ietf" loaded successfully. + +Module translators can also be loaded/unloaded programatically using the +``yang_translator_load()/yang_translator_unload()`` functions within the +northbound plugins. These functions are documented in the +*lib/yang_translator.h* file. + +Each module translator must be assigned a “family” identifier +(e.g. IETF, OpenConfig), and can contain mappings for multiple +interrelated YANG modules. The mappings consist of pairs of +custom/native XPath expressions that should be equivalent, despite +belonging to different YANG modules. + +Example: + +.. code:: json + + { + "custom": "/ietf-routing:routing/control-plane-protocols/control-plane-protocol[type='ietf-rip:ripv2'][name='main']/ietf-rip:rip/default-metric", + "native": "/frr-ripd:ripd/instance/default-metric" + }, + +The nodes pointed by the custom and native XPaths must have compatible +types. In the case of the example above, both nodes point to a YANG leaf +of type ``uint8``, so the mapping is valid. + +In the example below, the “custom” XPath points to a YANG list +(typeless), and the “native” XPath points to a YANG leaf-list of +strings. In this exceptional case, the types are also considered to be +compatible. + +.. code:: json + + { + "custom": "/ietf-routing:routing/control-plane-protocols/control-plane-protocol[type='ietf-rip:ripv2'][name='main']/ietf-rip:rip/interfaces/interface[interface='KEY1']", + "native": "/frr-ripd:ripd/instance/interface[.='KEY1']" + }, + +The ``KEY1..KEY4`` values have a special meaning and are used to +preserve the list keys while performing the XPath translation. + +Once a YANG module translator is loaded and validated at a syntactic +level using *libyang*, further validations are performed to check for +missing mappings (after loading the deviation modules) and incompatible +YANG types. Example: + +:: + + ripd(config)# yang module-translator load /usr/local/share/yang/ietf/frr-ietf-translator.json + % Failed to load "/usr/local/share/yang/ietf/frr-ietf-translator.json" + + Please check the logs for more details. + +:: + + 2018/09/03 15:18:45 RIP: yang_translator_validate_cb: YANG types are incompatible (xpath: "/ietf-routing:routing/control-plane-protocols/control-plane-protocol/ietf-rip:rip/default-metric") + 2018/09/03 15:18:45 RIP: yang_translator_validate_cb: missing mapping for "/ietf-routing:routing/control-plane-protocols/control-plane-protocol/ietf-rip:rip/distance" + 2018/09/03 15:18:45 RIP: yang_translator_validate: failed to validate "ietf" module translator: 2 error(s) + +Overall, this translation mechanism based on XPath mappings is simple +and functional, but only to a certain extent. The native models need to +be reasonably similar to the models that are going be translated, +otherwise the translation is compromised and a good coverage can’t be +achieved. Other translation techniques must be investigated to address +this shortcoming and make it possible to create more powerful YANG +module translators. + +YANG module translators can be evaluated based on the following metrics: +\* Translation potential: is it possible to make complex translations, +taking several variables into account? \* Complexity: measure of how +easy or hard it is to write a module translator. \* Speed: measure of +how fast the translation can be achieved. Translation speed is of +fundamental importance, especially for operational data. \* Robustness: +can the translator be checked for inconsistencies at load time? A module +translator based on scripts wouldn’t fare well on this metric. \* +Round-trip conversions: can the translated data be translated back to +the original format without information loss? + +CLI Demonstration +----------------- + +As of now the only northbound client that supports the YANG module +translator is the FRR embedded CLI. The confd and sysrepo plugins need +to be extended to support the module translator, which might be used not +only for configuration data, but also for operational data, RPCs and +notifications. + +In this demonstration, we’ll use the CLI ``configuration load`` command +to load the following JSON configuration file specified using the IETF +data hierarchy: + +.. code:: json + + { + "ietf-interfaces:interfaces": { + "interface": [ + { + "description": "Engineering", + "name": "eth0" + } + ] + }, + "ietf-routing:routing": { + "control-plane-protocols": { + "control-plane-protocol": [ + { + "name": "main", + "type": "ietf-rip:ripv2", + "ietf-rip:rip": { + "default-metric": "2", + "distance": "80", + "interfaces": { + "interface": [ + { + "interface": "eth0", + "split-horizon": "poison-reverse" + } + ] + }, + "originate-default-route": { + "enabled": "true" + }, + "timers": { + "flush-interval": "241", + "holddown-interval": "181", + "update-interval": "31" + } + } + } + ] + } + } + } + +In order to load this configuration file, it’s necessary to load the +IETF module translator first. Then, when entering the +``configuration load`` command, the ``translate ietf`` parameters must +be given to specify that the input needs to be translated using the +previously loaded ``ietf`` module translator. Example: + +:: + + ripd(config)# configuration load file json /mnt/renato/git/frr/yang/example/ietf-rip.json + % Failed to load configuration: + + Unknown element "interfaces". + ripd(config)# + ripd(config)# yang module-translator load /usr/local/share/yang/ietf/frr-ietf-translator.json + % Module translator "ietf" loaded successfully. + + ripd(config)# + ripd(config)# configuration load file json translate ietf /mnt/renato/git/frr/yang/example/ietf-rip.json + +Now let’s check the candidate configuration to see if the configuration +file was loaded successfully: + +:: + + ripd(config)# show configuration candidate + Configuration: + ! + frr version 5.1-dev + frr defaults traditional + ! + interface eth0 + description Engineering + ip rip split-horizon poisoned-reverse + ! + router rip + default-metric 2 + distance 80 + network eth0 + default-information originate + timers basic 31 181 241 + ! + end + ripd(config)# show configuration candidate json + { + "frr-interface:lib": { + "interface": [ + { + "name": "eth0", + "vrf": "default", + "description": "Engineering", + "frr-ripd:rip": { + "split-horizon": "poison-reverse" + } + } + ] + }, + "frr-ripd:ripd": { + "instance": { + "default-metric": 2, + "distance": { + "default": 80 + }, + "interface": [ + "eth0" + ], + "default-information-originate": true, + "timers": { + "flush-interval": 241, + "holddown-interval": 181, + "update-interval": 31 + } + } + } + } + +As it can be seen, the candidate configuration is identical to the one +defined in the *ietf-rip.json* file, only the structure is different. +This means that the *ietf-rip.json* file was translated successfully. + +The ``ietf`` module translator can also be used to do the translation in +other direction: transform data from the native format to the IETF +format. This is shown below by altering the output of the +``show configuration candidate json`` command using the +``translate ietf`` parameter: + +:: + + ripd(config)# show configuration candidate json translate ietf + { + "ietf-interfaces:interfaces": { + "interface": [ + { + "name": "eth0", + "description": "Engineering" + } + ] + }, + "ietf-routing:routing": { + "control-plane-protocols": { + "control-plane-protocol": [ + { + "type": "ietf-rip:ripv2", + "name": "main", + "ietf-rip:rip": { + "interfaces": { + "interface": [ + { + "interface": "eth0", + "split-horizon": "poison-reverse" + } + ] + }, + "default-metric": 2, + "distance": 80, + "originate-default-route": { + "enabled": true + }, + "timers": { + "flush-interval": 241, + "holddown-interval": 181, + "update-interval": 31 + } + } + } + ] + } + } + } + +As expected, this output is exactly identical to the configuration +defined in the *ietf-rip.json* file. The module translator was able to +do a round-trip conversion without information loss. + +Implementation Details +---------------------- + +A different libyang context is allocated for each YANG module +translator. This is important to avoid collisions and ensure that +non-native data can’t be instantiated in the running and candidate +configurations. diff --git a/doc/developer/northbound/yang-tools.rst b/doc/developer/northbound/yang-tools.rst new file mode 100644 index 0000000000..346efcaaee --- /dev/null +++ b/doc/developer/northbound/yang-tools.rst @@ -0,0 +1,112 @@ +Yang Tools +~~~~~~~~~~ + +Here's some information about various tools for working with yang +models. + +yanglint cheat sheet +~~~~~~~~~~~~~~~~~~~~ + + libyang project includes a feature-rich tool called yanglint(1) for + validation and conversion of the schemas and YANG modeled data. The + source codes are located at /tools/lint and can be used to explore + how an application is supposed to use the libyang library. + yanglint(1) binary as well as its man page are installed together + with the library itself. + +Validate a YANG module: + +.. code:: sh + + $ yanglint -p <yang-search-path> module.yang + +Generate tree representation of a YANG module: + +.. code:: sh + + $ yanglint -p <yang-search-path> -f tree module.yang + +Validate JSON/XML instance data: + +.. code:: sh + + $ yanglint -p <yang-search-path> module.yang data.{json,xml} + +Convert JSON/XML instance data to another format: + +.. code:: sh + + $ yanglint -p <yang-search-path> -f xml module.yang data.json + $ yanglint -p <yang-search-path> -f json module.yang data.xml + +*yanglint* also features an interactive mode which is very useful when +needing to validate data from multiple modules at the same time. The +*yanglint* README provides several examples: +https://github.com/CESNET/libyang/blob/master/tools/lint/examples/README.md + +Man page (groff): +https://github.com/CESNET/libyang/blob/master/tools/lint/yanglint.1 + +pyang cheat sheet +~~~~~~~~~~~~~~~~~ + + pyang is a YANG validator, transformator and code generator, written + in python. It can be used to validate YANG modules for correctness, + to transform YANG modules into other formats, and to generate code + from the modules. + +Obtaining and installing pyang: + +.. code:: sh + + $ git clone https://github.com/mbj4668/pyang.git + $ cd pyang/ + $ sudo python setup.py install + +Validate a YANG module: + +.. code:: sh + + $ pyang --ietf -p <yang-search-path> module.yang + +Generate tree representation of a YANG module: + +.. code:: sh + + $ pyang -f tree -p <yang-search-path> module.yang + +Indent a YANG file: + +.. code:: sh + + $ pyang -p <yang-search-path> \ + --keep-comments -f yang --yang-canonical \ + module.yang -o module.yang + +Generate skeleton instance data: \* XML: + +.. code:: sh + + $ pyang -p <yang-search-path> \ + -f sample-xml-skeleton --sample-xml-skeleton-defaults \ + module.yang [augmented-module1.yang ...] -o module.xml + +- JSON: + +.. code:: sh + + $ pyang -p <yang-search-path> \ + -f jsonxsl module.yang -o module.xsl + $ xsltproc -o module.json module.xsl module.xml + +Validate XML instance data (works only with YANG 1.0): + +.. code:: sh + + $ yang2dsdl -v module.xml module.yang + +vim +~~~ + +YANG syntax highlighting for vim: +https://github.com/nathanalderson/yang.vim diff --git a/doc/developer/ospf.rst b/doc/developer/ospf.rst index a5164d552a..837a0bd185 100644 --- a/doc/developer/ospf.rst +++ b/doc/developer/ospf.rst @@ -9,4 +9,5 @@ OSPFD ospf-api ospf-sr + cspf diff --git a/doc/developer/process-architecture.rst b/doc/developer/process-architecture.rst index 33ef278c4d..85126cab30 100644 --- a/doc/developer/process-architecture.rst +++ b/doc/developer/process-architecture.rst @@ -46,7 +46,8 @@ implemented in FRR. This doc should be expanded and broken off into its own section. For now it provides basic information necessary to understand the interplay between the event system and kernel threads. -The core event system is implemented in :file:`lib/thread.[ch]`. The primary +The core event system is implemented in :file:`lib/event.c` and +:file:`lib/frrevent.h`. The primary structure is ``struct event_loop``, hereafter referred to as a ``threadmaster``. A ``threadmaster`` is a global state object, or context, that holds all the tasks currently pending execution as well as statistics on tasks @@ -57,41 +58,41 @@ execute. At initialization, a daemon will typically create one fetch each task and execute it. These tasks have various types corresponding to their general action. The types -are given by integer macros in :file:`event.h` and are: +are given by integer macros in :file:`frrevent.h` and are: -``THREAD_READ`` +``EVENT_READ`` Task which waits for a file descriptor to become ready for reading and then executes. -``THREAD_WRITE`` +``EVENT_WRITE`` Task which waits for a file descriptor to become ready for writing and then executes. -``THREAD_TIMER`` +``EVENT_TIMER`` Task which executes after a certain amount of time has passed since it was scheduled. -``THREAD_EVENT`` +``EVENT_EVENT`` Generic task that executes with high priority and carries an arbitrary integer indicating the event type to its handler. These are commonly used to implement the finite state machines typically found in routing protocols. -``THREAD_READY`` +``EVENT_READY`` Type used internally for tasks on the ready queue. -``THREAD_UNUSED`` +``EVENT_UNUSED`` Type used internally for ``struct event`` objects that aren't being used. The event system pools ``struct event`` to avoid heap allocations; this is the type they have when they're in the pool. -``THREAD_EXECUTE`` +``EVENT_EXECUTE`` Just before a task is run its type is changed to this. This is used to show - ``X`` as the type in the output of :clicmd:`show thread cpu`. + ``X`` as the type in the output of :clicmd:`show event cpu`. The programmer never has to work with these types explicitly. Each type of task is created and queued via special-purpose functions (actually macros, but irrelevant for the time being) for the specific type. For example, to add a -``THREAD_READ`` task, you would call +``EVENT_READ`` task, you would call :: @@ -113,9 +114,9 @@ sockets needed for peerings or IPC. To retrieve the next task to run the program calls ``event_fetch()``. ``event_fetch()`` internally computes which task to execute next based on -rudimentary priority logic. Events (type ``THREAD_EVENT``) execute with the +rudimentary priority logic. Events (type ``EVENT_EVENT``) execute with the highest priority, followed by expired timers and finally I/O tasks (type -``THREAD_READ`` and ``THREAD_WRITE``). When scheduling a task a function and an +``EVENT_READ`` and ``EVENT_WRITE``). When scheduling a task a function and an arbitrary argument are provided. The task returned from ``event_fetch()`` is then executed with ``event_call()``. @@ -135,23 +136,23 @@ Mapping the general names used in the figure to specific FRR functions: - ``task`` is ``struct event *`` - ``fetch`` is ``event_fetch()`` -- ``exec()`` is ``event_call`` +- ``exec()`` is ``event_call()`` - ``cancel()`` is ``event_cancel()`` - ``schedule()`` is any of the various task-specific ``event_add_*`` functions Adding tasks is done with various task-specific function-like macros. These -macros wrap underlying functions in :file:`thread.c` to provide additional +macros wrap underlying functions in :file:`event.c` to provide additional information added at compile time, such as the line number the task was scheduled from, that can be accessed at runtime for debugging, logging and informational purposes. Each task type has its own specific scheduling function -that follow the naming convention ``event_add_<type>``; see :file:`event.h` +that follow the naming convention ``event_add_<type>``; see :file:`frrevent.h` for details. There are some gotchas to keep in mind: - I/O tasks are keyed off the file descriptor associated with the I/O operation. This means that for any given file descriptor, only one of each - type of I/O task (``THREAD_READ`` and ``THREAD_WRITE``) can be scheduled. For + type of I/O task (``EVENT_READ`` and ``EVENT_WRITE``) can be scheduled. For example, scheduling two write tasks one after the other will overwrite the first task with the second, resulting in total loss of the first task and difficult bugs. @@ -209,7 +210,8 @@ Kernel Thread Wrapper The basis for the integration of pthreads and the event system is a lightweight wrapper for both systems implemented in :file:`lib/frr_pthread.[ch]`. The header provides a core datastructure, ``struct frr_pthread``, that encapsulates -structures from both POSIX threads and :file:`thread.[ch]`. In particular, this +structures from both POSIX threads and :file:`event.c`, :file:`frrevent.h`. +In particular, this datastructure has a pointer to a ``threadmaster`` that runs within the pthread. It also has fields for a name as well as start and stop functions that have signatures similar to the POSIX arguments for ``pthread_create()``. @@ -217,18 +219,18 @@ signatures similar to the POSIX arguments for ``pthread_create()``. Calling ``frr_pthread_new()`` creates and registers a new ``frr_pthread``. The returned structure has a pre-initialized ``threadmaster``, and its ``start`` and ``stop`` functions are initialized to defaults that will run a basic event -loop with the given threadmaster. Calling ``frr_pthread_run`` starts the thread +loop with the given threadmaster. Calling ``frr_pthread_run()`` starts the thread with the ``start`` function. From there, the model is the same as the regular event model. To schedule tasks on a particular pthread, simply use the regular -:file:`thread.c` functions as usual and provide the ``threadmaster`` pointed to +:file:`event.c` functions as usual and provide the ``threadmaster`` pointed to from the ``frr_pthread``. As part of implementing the wrapper, the -:file:`thread.c` functions were made thread-safe. Consequently, it is safe to +:file:`event.c` functions were made thread-safe. Consequently, it is safe to schedule events on a ``threadmaster`` belonging both to the calling thread as well as *any other pthread*. This serves as the basis for inter-thread communication and boils down to a slightly more complicated method of message passing, where the messages are the regular task events as used in the event-driven model. The only difference is thread cancellation, which requires -calling ``event_cancel_async()`` instead of ``event_cancel`` to cancel a task +calling ``event_cancel_async()`` instead of ``event_cancel()`` to cancel a task currently scheduled on a ``threadmaster`` belonging to a different pthread. This is necessary to avoid race conditions in the specific case where one pthread wants to guarantee that a task on another pthread is cancelled before @@ -236,16 +238,16 @@ proceeding. In addition, the existing commands to show statistics and other information for tasks within the event driven model have been expanded to handle multiple -pthreads; running :clicmd:`show thread cpu` will display the usual event +pthreads; running :clicmd:`show event cpu` will display the usual event breakdown, but it will do so for each pthread running in the program. For example, :ref:`bgpd` runs a dedicated I/O pthread and shows the following -output for :clicmd:`show thread cpu`: +output for :clicmd:`show event cpu`: :: - frr# show thread cpu + frr# show event cpu - Thread statistics for bgpd: + Event statistics for bgpd: Showing statistics for pthread main ------------------------------------ diff --git a/doc/developer/requirements.txt b/doc/developer/requirements.txt new file mode 100644 index 0000000000..483a4e9600 --- /dev/null +++ b/doc/developer/requirements.txt @@ -0,0 +1 @@ +sphinx_rtd_theme diff --git a/doc/developer/scripting.rst b/doc/developer/scripting.rst index 202f0036f8..7a43314490 100644 --- a/doc/developer/scripting.rst +++ b/doc/developer/scripting.rst @@ -488,12 +488,6 @@ match *exactly*. In the above example, we defined encoders/decoders for a value of ``struct prefix *``, but not ``struct prefix`` or ``const struct prefix *``. -``const`` values are a special case. We want to use them in our Lua scripts -but not modify them, so creating a decoder for them would be meaningless. -But we still need a decoder for the type of value so that the compiler will be -satisfied. -For that, use ``lua_decode_noop``: - .. code-block:: diff #define DECODE_ARGS_WITH_STATE(L, value) \ diff --git a/doc/developer/subdir.am b/doc/developer/subdir.am index b4c752a473..652ee4e1af 100644 --- a/doc/developer/subdir.am +++ b/doc/developer/subdir.am @@ -5,13 +5,15 @@ dev_RSTFILES = \ doc/developer/bgp-typecodes.rst \ doc/developer/bgpd.rst \ + doc/developer/bmp.rst \ doc/developer/building-frr-for-alpine.rst \ + doc/developer/building-frr-for-archlinux.rst \ doc/developer/building-frr-for-centos6.rst \ doc/developer/building-frr-for-centos7.rst \ doc/developer/building-frr-for-debian8.rst \ doc/developer/building-frr-for-debian9.rst \ + doc/developer/building-frr-for-debian12.rst \ doc/developer/building-frr-for-fedora.rst \ - doc/developer/building-frr-for-opensuse.rst \ doc/developer/building-frr-for-freebsd10.rst \ doc/developer/building-frr-for-freebsd11.rst \ doc/developer/building-frr-for-freebsd13.rst \ @@ -19,14 +21,17 @@ dev_RSTFILES = \ doc/developer/building-frr-for-netbsd6.rst \ doc/developer/building-frr-for-netbsd7.rst \ doc/developer/building-frr-for-openbsd6.rst \ + doc/developer/building-frr-for-opensuse.rst \ doc/developer/building-frr-for-openwrt.rst \ doc/developer/building-frr-for-ubuntu1404.rst \ doc/developer/building-frr-for-ubuntu1604.rst \ doc/developer/building-frr-for-ubuntu1804.rst \ doc/developer/building-frr-for-ubuntu2004.rst \ + doc/developer/building-frr-for-ubuntu2204.rst \ doc/developer/building-libunwind-note.rst \ doc/developer/building-libyang.rst \ doc/developer/building.rst \ + doc/developer/checkpatch.rst \ doc/developer/cli.rst \ doc/developer/conf.py \ doc/developer/cross-compiling.rst \ @@ -64,6 +69,19 @@ dev_RSTFILES = \ doc/developer/workflow.rst \ doc/developer/xrefs.rst \ doc/developer/zebra.rst \ + doc/developer/northbound/advanced-topics.rst \ + doc/developer/northbound/architecture.rst \ + doc/developer/northbound/demos.rst \ + doc/developer/northbound/links.rst \ + doc/developer/northbound/northbound.rst \ + doc/developer/northbound/operational-data-rpcs-and-notifications.rst \ + doc/developer/northbound/plugins-sysrepo.rst \ + doc/developer/northbound/ppr-basic-test-topology.rst \ + doc/developer/northbound/ppr-mpls-basic-test-topology.rst \ + doc/developer/northbound/retrofitting-configuration-commands.rst \ + doc/developer/northbound/transactional-cli.rst \ + doc/developer/northbound/yang-module-translator.rst \ + doc/developer/northbound/yang-tools.rst \ # end EXTRA_DIST += \ diff --git a/doc/developer/topotests.rst b/doc/developer/topotests.rst index 773691e698..2259c7e375 100644 --- a/doc/developer/topotests.rst +++ b/doc/developer/topotests.rst @@ -8,14 +8,12 @@ Topotests is a suite of topology tests for FRR built on top of micronet. Installation and Setup ---------------------- -Topotests run under python3. Additionally, for ExaBGP (which is used -in some of the BGP tests) an older python2 version (and the python2 -version of ``pip``) must be installed. +Topotests run under python3. Tested with Ubuntu 20.04,Ubuntu 18.04, and Debian 11. -Instructions are the same for all setups (i.e. ExaBGP is only used for -BGP tests). +Instructions are the same for all setups. However, ExaBGP is only used for +BGP tests. Tshark is only required if you enable any packet captures on test runs. @@ -39,19 +37,12 @@ Installing Topotest Requirements python3 -m pip install 'pytest-xdist>=2.3.0' python3 -m pip install 'scapy>=2.4.5' python3 -m pip install xmltodict - # Use python2 pip to install older ExaBGP - python2 -m pip install 'exabgp<4.0.0' + python3 -m pip install git+https://github.com/Exa-Networks/exabgp@0659057837cd6c6351579e9f0fa47e9fb7de7311 useradd -d /var/run/exabgp/ -s /bin/false exabgp # To enable the gRPC topotest install: python3 -m pip install grpcio grpcio-tools - # Install Socat tool to run PIMv6 tests, - # Socat code can be taken from below url, - # which has latest changes done for PIMv6, - # join and traffic: - https://github.com/opensourcerouting/socat/ - Enable Coredumps """""""""""""""" @@ -236,8 +227,8 @@ the number of the test we are interested in along with ``--errmsg`` option. ~/frr/tests/topotests# ./analyze.py -Ar run-save -T0 --errmsg bgp_multiview_topo1/test_bgp_multiview_topo1.py::test_bgp_converge: AssertionError: BGP did not converge: - IPv4 Unicast Summary (VIEW 1): - BGP router identifier 172.30.1.1, local AS number 100 vrf-id -1 + IPv4 Unicast Summary: + BGP router identifier 172.30.1.1, local AS number 100 VIEW 1 vrf-id -1 BGP table version 1 RIB entries 1, using 184 bytes of memory Peers 3, using 2169 KiB of memory @@ -272,8 +263,8 @@ select the first failed test case. > assert False, "BGP did not converge:\n%s" % bgpStatus E AssertionError: BGP did not converge: E - E IPv4 Unicast Summary (VIEW 1): - E BGP router identifier 172.30.1.1, local AS number 100 vrf-id -1 + E IPv4 Unicast Summary: + E BGP router identifier 172.30.1.1, local AS number 100 VIEW 1 vrf-id -1 [...] E Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc E 172.16.1.1 4 65001 0 0 0 0 0 never Connect 0 N/A @@ -449,7 +440,7 @@ as shown in the examples below. For each capture a window is opened displaying a live summary of the captured packets. Additionally, the entire packet stream is captured in a pcap file in -the tests log directory e.g.,:: +the tests log directory e.g.,: .. code:: console @@ -459,7 +450,7 @@ the tests log directory e.g.,:: -rw------- 1 root root 45172 Apr 19 05:30 capture-r2-r2-eth0.pcap -rw------- 1 root root 48412 Apr 19 05:30 capture-sw1.pcap ... -- + Viewing Live Daemon Logs """""""""""""""""""""""" @@ -476,10 +467,10 @@ One can live view daemon or the frr logs in separate windows using the For each capture a window is opened displaying a live summary of the captured packets. Additionally, the entire packet stream is captured in a pcap file in -the tests log directory e.g.,:: +the tests log directory e.g., -When using a unified log file `frr.log` one substitutes `frr` for the daemon -name in the ``--logd`` CLI option, e.g., +When using a unified log file ``frr.log`` one substitutes ``frr`` for the +daemon name in the ``--logd`` CLI option, e.g., .. code:: shell @@ -565,6 +556,8 @@ Here's an example of launching ``vtysh`` on routers ``rt1`` and ``rt2``. sudo -E pytest --vtysh=rt1,rt2 all-protocol-startup +.. _debug_with_gdb: + Debugging with GDB """""""""""""""""" @@ -589,6 +582,12 @@ Here's an example of launching ``zebra`` and ``bgpd`` inside ``gdb`` on router --gdb-breakpoints=nb_config_diff \ all-protocol-startup +Finally, for Emacs users, you can specify ``--gdb-use-emacs``. When specified +the first router and daemon to be launched in gdb will be launched and run with +Emacs gdb functionality by using `emacsclient --eval` commands. This provides an +IDE debugging experience for Emacs users. This functionality works best when +using password-less sudo. + Reporting Memleaks with FRR Memory Statistics """"""""""""""""""""""""""""""""""""""""""""" @@ -623,6 +622,8 @@ allocations upon exit. To enable also reporting of memory leaks to a specific location, define an environment variable ``TOPOTESTS_CHECK_MEMLEAK`` with the file prefix, i.e.: +:: + export TOPOTESTS_CHECK_MEMLEAK="/home/mydir/memleak_" For tests that support the TOPOTESTS_CHECK_MEMLEAK environment variable, this @@ -635,16 +636,26 @@ Detecting Memleaks with Valgrind """""""""""""""""""""""""""""""" Topotest can automatically launch all daemons with ``valgrind`` to check for -memleaks. This is enabled by specifying 1 or 2 CLI arguments. -``--valgrind-memleaks`` will enable general memleak detection, and -``--valgrind-extra`` enables extra functionality including generating a -suppression file. The suppression file ``tools/valgrind.supp`` is used when -memleak detection is enabled. +memleaks. This is enabled by specifying 1 to 3 CLI arguments. +``--valgrind-memleaks`` enables memleak detection. ``--valgrind-extra`` enables +extra functionality including generating a suppression file. The suppression +file ``tools/valgrind.supp`` is used when memleak detection is enabled. Finally, +``--valgrind-leak-kinds=KINDS`` can be used to modify what types of links are +reported. This corresponds to valgrind's ``--show-link-kinds`` arg. The value is +either ``all`` or a comma-separated list of types: +``definite,indirect,possible,reachable``. The default is ``definite,possible``. .. code:: shell sudo -E pytest --valgrind-memleaks all-protocol-startup +.. note:: GDB can be used in conjection with valgrind. + + When you enable ``--valgrind-memleaks`` and you also launch various daemons + under GDB (debug_with_gdb_) topotest will connect the two utilities using + ``--vgdb-error=0`` and attaching to a ``vgdb`` process. This is very + useful for debugging bugs with use of uninitialized errors, et al. + Collecting Performance Data using perf(1) """"""""""""""""""""""""""""""""""""""""" @@ -666,6 +677,28 @@ during the config_timing test. To specify different arguments for ``perf record``, one can use the ``--perf-options`` this will replace the ``-g`` used by default. +Running Daemons under RR Debug (``rr record``) +"""""""""""""""""""""""""""""""""""""""""""""" + +Topotest can automatically launch any daemon under ``rr(1)`` to collect +execution state. The daemon is run in the foreground with ``rr record``. + +The execution state will be saved in the router specific directory +(in a `rr` subdir that rr creates) under the test's run directoy. + +Here's an example of collecting ``rr`` execution state from ``mgmtd`` on router +``r1`` during the ``config_timing`` test. + +.. code:: console + + $ sudo -E pytest --rr-routers=r1 --rr-daemons=mgmtd config_timing + ... + $ find /tmp/topotests/ -name '*perf.data*' + /tmp/topotests/config_timing.test_config_timing/r1/perf.data + +To specify additional arguments for ``rr record``, one can use the +``--rr-options``. + .. _topotests_docker: Running Tests with Docker diff --git a/doc/developer/workflow.rst b/doc/developer/workflow.rst index 65befaccba..68834ed710 100644 --- a/doc/developer/workflow.rst +++ b/doc/developer/workflow.rst @@ -167,28 +167,26 @@ as early as possible, i.e. the first 2-week window. For reference, the expected release schedule according to the above is: +---------+------------+------------+------------+ -| Release | 2023-07-04 | 2023-10-31 | 2024-02-27 | +| Release | 2023-11-07 | 2024-03-05 | 2024-07-02 | +---------+------------+------------+------------+ -| RC | 2023-06-20 | 2023-10-17 | 2024-02-13 | +| RC | 2023-10-24 | 2024-02-20 | 2024-06-18 | +---------+------------+------------+------------+ -| dev/X.Y | 2023-06-06 | 2023-10-03 | 2024-01-30 | +| dev/X.Y | 2023-10-10 | 2024-02-06 | 2024-06-04 | +---------+------------+------------+------------+ -| freeze | 2023-05-23 | 2023-09-19 | 2024-01-16 | +| freeze | 2023-09-26 | 2024-01-23 | 2024-05-21 | +---------+------------+------------+------------+ Here is the hint on how to get the dates easily: .. code-block:: console - ~$ # Last freeze date was 2023-09-19 - ~$ date +%F --date='2023-09-19 +119 days' # Next freeze date - 2024-01-16 - ~$ date +%F --date='2024-01-16 +14 days' # Next dev/X.Y date - 2024-01-30 - ~$ date +%F --date='2024-01-30 +14 days' # Next RC date - 2024-02-13 - ~$ date +%F --date='2024-02-13 +14 days' # Next Release date - 2024-02-27 + ~$ # Release date is 2023-11-07 (First Tuesday each March/July/November) + ~$ date +%F --date='2023-11-07 -42 days' # Next freeze date + 2023-09-26 + ~$ date +%F --date='2023-11-07 -28 days' # Next dev/X.Y date + 2023-10-10 + ~$ date +%F --date='2023-11-07 -14 days' # Next RC date + 2023-10-24 Each release is managed by one or more volunteer release managers from the FRR community. These release managers are expected to handle the branch for a period @@ -761,6 +759,13 @@ following requirements have achieved consensus: tools can catch uninitialized value use that would otherwise be suppressed by the (incorrect) zero initialization. +- Usage of ``system()`` or other c library routines that cause signals to + possibly be ignored are not allowed. This includes the ``fork()`` and + ``execXX`` call patterns, which is actually what system() does underneath + the covers. This pattern causes the system shutdown to never work properly + as the SIGINT sent is never received. It is better to just prohibit code + that does this instead of having to debug shutdown issues again. + Other than these specific rules, coding practices from the Linux kernel as well as CERT or MISRA C guidelines may provide useful input on safe C code. However, these rules are not applied as-is; some of them expressly collide @@ -812,6 +817,7 @@ The project provides multiple tools to allow you to correctly style your code as painlessly as possible, primarily built around ``clang-format``. clang-format + In the project root there is a :file:`.clang-format` configuration file which can be used with the ``clang-format`` source formatter tool from the LLVM project. Most of the time, this is the easiest and smartest tool to @@ -868,14 +874,19 @@ clang-format https://clang.llvm.org/docs/ClangFormat.html checkpatch.sh +checkpatch.pl + + .. seealso:: :ref:`checkpatch` + In the Linux kernel source tree there is a Perl script used to check - incoming patches for style errors. FRR uses an adapted version of this - script for the same purpose. It can be found at - :file:`tools/checkpatch.sh`. This script takes a git-formatted diff or - patch file, applies it to a clean FRR tree, and inspects the result to catch - potential style errors. Running this script on your patches before - submission is highly recommended. The CI system runs this script as well and - will comment on the PR with the results if style errors are found. + incoming patches for style errors. FRR uses a shell script front end and an + adapted version of the perl script for the same purpose. These scripts can + be found at :file:`tools/checkpatch.sh` and :file:`tools/checkpatch.pl`. + This script takes a git-formatted diff or patch file, applies it to a clean + FRR tree, and inspects the result to catch potential style errors. Running + this script on your patches before submission is highly recommended. The CI + system runs this script as well and will comment on the PR with the results + if style errors are found. It is run like this:: @@ -916,6 +927,10 @@ checkpatch.sh If the script finds one or more WARNINGs it will exit with 1. If it finds one or more ERRORs it will exit with 2. + For convenience the Linux documentation for the :file:`tools/checkpatch.pl` + script has been included unmodified (i.e., it has not been updated to + reflect local changes) :doc:`here <checkpatch>` + Please remember that while FRR provides these tools for your convenience, responsibility for properly formatting your code ultimately lies on the @@ -1331,10 +1346,23 @@ frr-format plugin Using the plugin also changes the string for ``PRI[udx]64`` from the system value to ``%L[udx]`` (normally ``%ll[udx]`` or ``%l[udx]``.) -Additionally, the FRR codebase is regularly scanned with Coverity. -Unfortunately Coverity does not have the ability to handle scanning pull -requests, but after code is merged it will send an email notifying project -members with Coverity access of newly introduced defects. +Additionally, the FRR codebase is regularly scanned for static analysis +errors with Coverity and pull request changes are scanned as part of the +Continuous Integration (CI) process. Developers can scan their commits for +Coverity static analysis errors prior to submission using the +``scan-build`` command. To use this command, the ``clang-tools`` package must +be installed. For example, this can be accomplished on Ubuntu with the +``sudo apt-get install clang-tools`` command. Then, touch the files you want scanned and +invoke the ``scan-build`` command. For example:: + + cd ~/GitHub/frr + touch ospfd/ospf_flood.c ospfd/ospf_vty.c ospfd/ospf_opaque.c + cd build + scan-build make -j32 + +The results of the scan including any static analysis errors will appear inline. +Additionally, there will a directory in the /tmp containing the Coverity +reports (e.g., scan-build-2023-06-09-120100-473730-1). Executing non-installed dynamic binaries ---------------------------------------- diff --git a/doc/developer/zebra.rst b/doc/developer/zebra.rst index 5f039758a5..be2952e71a 100644 --- a/doc/developer/zebra.rst +++ b/doc/developer/zebra.rst @@ -159,229 +159,7 @@ Past Versions Zebra Protocol Commands ----------------------- -+------------------------------------+-------+ -| Command | Value | -+====================================+=======+ -| ZEBRA_INTERFACE_ADD | 0 | -+------------------------------------+-------+ -| ZEBRA_INTERFACE_DELETE | 1 | -+------------------------------------+-------+ -| ZEBRA_INTERFACE_ADDRESS_ADD | 2 | -+------------------------------------+-------+ -| ZEBRA_INTERFACE_ADDRESS_DELETE | 3 | -+------------------------------------+-------+ -| ZEBRA_INTERFACE_UP | 4 | -+------------------------------------+-------+ -| ZEBRA_INTERFACE_DOWN | 5 | -+------------------------------------+-------+ -| ZEBRA_INTERFACE_SET_MASTER | 6 | -+------------------------------------+-------+ -| ZEBRA_INTERFACE_SET_PROTODOWN | 7 | -+------------------------------------+-------+ -| ZEBRA_ROUTE_ADD | 8 | -+------------------------------------+-------+ -| ZEBRA_ROUTE_DELETE | 9 | -+------------------------------------+-------+ -| ZEBRA_ROUTE_NOTIFY_OWNER | 10 | -+------------------------------------+-------+ -| ZEBRA_REDISTRIBUTE_ADD | 11 | -+------------------------------------+-------+ -| ZEBRA_REDISTRIBUTE_DELETE | 12 | -+------------------------------------+-------+ -| ZEBRA_REDISTRIBUTE_DEFAULT_ADD | 13 | -+------------------------------------+-------+ -| ZEBRA_REDISTRIBUTE_DEFAULT_DELETE | 14 | -+------------------------------------+-------+ -| ZEBRA_ROUTER_ID_ADD | 15 | -+------------------------------------+-------+ -| ZEBRA_ROUTER_ID_DELETE | 16 | -+------------------------------------+-------+ -| ZEBRA_ROUTER_ID_UPDATE | 17 | -+------------------------------------+-------+ -| ZEBRA_HELLO | 18 | -+------------------------------------+-------+ -| ZEBRA_CAPABILITIES | 19 | -+------------------------------------+-------+ -| ZEBRA_NEXTHOP_REGISTER | 20 | -+------------------------------------+-------+ -| ZEBRA_NEXTHOP_UNREGISTER | 21 | -+------------------------------------+-------+ -| ZEBRA_NEXTHOP_UPDATE | 22 | -+------------------------------------+-------+ -| ZEBRA_INTERFACE_NBR_ADDRESS_ADD | 23 | -+------------------------------------+-------+ -| ZEBRA_INTERFACE_NBR_ADDRESS_DELETE | 24 | -+------------------------------------+-------+ -| ZEBRA_INTERFACE_BFD_DEST_UPDATE | 25 | -+------------------------------------+-------+ -| ZEBRA_IMPORT_ROUTE_REGISTER | 26 | -+------------------------------------+-------+ -| ZEBRA_IMPORT_ROUTE_UNREGISTER | 27 | -+------------------------------------+-------+ -| ZEBRA_BFD_DEST_REGISTER | 29 | -+------------------------------------+-------+ -| ZEBRA_BFD_DEST_DEREGISTER | 30 | -+------------------------------------+-------+ -| ZEBRA_BFD_DEST_UPDATE | 31 | -+------------------------------------+-------+ -| ZEBRA_BFD_DEST_REPLAY | 32 | -+------------------------------------+-------+ -| ZEBRA_REDISTRIBUTE_ROUTE_ADD | 33 | -+------------------------------------+-------+ -| ZEBRA_REDISTRIBUTE_ROUTE_DEL | 34 | -+------------------------------------+-------+ -| ZEBRA_VRF_UNREGISTER | 35 | -+------------------------------------+-------+ -| ZEBRA_VRF_ADD | 36 | -+------------------------------------+-------+ -| ZEBRA_VRF_DELETE | 37 | -+------------------------------------+-------+ -| ZEBRA_VRF_LABEL | 38 | -+------------------------------------+-------+ -| ZEBRA_INTERFACE_VRF_UPDATE | 39 | -+------------------------------------+-------+ -| ZEBRA_BFD_CLIENT_REGISTER | 40 | -+------------------------------------+-------+ -| ZEBRA_BFD_CLIENT_DEREGISTER | 41 | -+------------------------------------+-------+ -| ZEBRA_INTERFACE_ENABLE_RADV | 42 | -+------------------------------------+-------+ -| ZEBRA_INTERFACE_DISABLE_RADV | 43 | -+------------------------------------+-------+ -| ZEBRA_NEXTHOP_LOOKUP_MRIB | 44 | -+------------------------------------+-------+ -| ZEBRA_INTERFACE_LINK_PARAMS | 45 | -+------------------------------------+-------+ -| ZEBRA_MPLS_LABELS_ADD | 46 | -+------------------------------------+-------+ -| ZEBRA_MPLS_LABELS_DELETE | 47 | -+------------------------------------+-------+ -| ZEBRA_MPLS_LABELS_REPLACE | 48 | -+------------------------------------+-------+ -| ZEBRA_IPMR_ROUTE_STATS | 49 | -+------------------------------------+-------+ -| ZEBRA_LABEL_MANAGER_CONNECT | 50 | -+------------------------------------+-------+ -| ZEBRA_LABEL_MANAGER_CONNECT_ASYNC | 51 | -+------------------------------------+-------+ -| ZEBRA_GET_LABEL_CHUNK | 52 | -+------------------------------------+-------+ -| ZEBRA_RELEASE_LABEL_CHUNK | 53 | -+------------------------------------+-------+ -| ZEBRA_FEC_REGISTER | 54 | -+------------------------------------+-------+ -| ZEBRA_FEC_UNREGISTER | 55 | -+------------------------------------+-------+ -| ZEBRA_FEC_UPDATE | 56 | -+------------------------------------+-------+ -| ZEBRA_ADVERTISE_DEFAULT_GW | 57 | -+------------------------------------+-------+ -| ZEBRA_ADVERTISE_SVI_MACIP | 58 | -+------------------------------------+-------+ -| ZEBRA_ADVERTISE_SUBNET | 59 | -+------------------------------------+-------+ -| ZEBRA_ADVERTISE_ALL_VNI | 60 | -+------------------------------------+-------+ -| ZEBRA_LOCAL_ES_ADD | 61 | -+------------------------------------+-------+ -| ZEBRA_LOCAL_ES_DEL | 62 | -+------------------------------------+-------+ -| ZEBRA_VNI_ADD | 63 | -+------------------------------------+-------+ -| ZEBRA_VNI_DEL | 64 | -+------------------------------------+-------+ -| ZEBRA_L3VNI_ADD | 65 | -+------------------------------------+-------+ -| ZEBRA_L3VNI_DEL | 66 | -+------------------------------------+-------+ -| ZEBRA_REMOTE_VTEP_ADD | 67 | -+------------------------------------+-------+ -| ZEBRA_REMOTE_VTEP_DEL | 68 | -+------------------------------------+-------+ -| ZEBRA_MACIP_ADD | 69 | -+------------------------------------+-------+ -| ZEBRA_MACIP_DEL | 70 | -+------------------------------------+-------+ -| ZEBRA_IP_PREFIX_ROUTE_ADD | 71 | -+------------------------------------+-------+ -| ZEBRA_IP_PREFIX_ROUTE_DEL | 72 | -+------------------------------------+-------+ -| ZEBRA_REMOTE_MACIP_ADD | 73 | -+------------------------------------+-------+ -| ZEBRA_REMOTE_MACIP_DEL | 74 | -+------------------------------------+-------+ -| ZEBRA_DUPLICATE_ADDR_DETECTION | 75 | -+------------------------------------+-------+ -| ZEBRA_PW_ADD | 76 | -+------------------------------------+-------+ -| ZEBRA_PW_DELETE | 77 | -+------------------------------------+-------+ -| ZEBRA_PW_SET | 78 | -+------------------------------------+-------+ -| ZEBRA_PW_UNSET | 79 | -+------------------------------------+-------+ -| ZEBRA_PW_STATUS_UPDATE | 80 | -+------------------------------------+-------+ -| ZEBRA_RULE_ADD | 81 | -+------------------------------------+-------+ -| ZEBRA_RULE_DELETE | 82 | -+------------------------------------+-------+ -| ZEBRA_RULE_NOTIFY_OWNER | 83 | -+------------------------------------+-------+ -| ZEBRA_TABLE_MANAGER_CONNECT | 84 | -+------------------------------------+-------+ -| ZEBRA_GET_TABLE_CHUNK | 85 | -+------------------------------------+-------+ -| ZEBRA_RELEASE_TABLE_CHUNK | 86 | -+------------------------------------+-------+ -| ZEBRA_IPSET_CREATE | 87 | -+------------------------------------+-------+ -| ZEBRA_IPSET_DESTROY | 88 | -+------------------------------------+-------+ -| ZEBRA_IPSET_ENTRY_ADD | 89 | -+------------------------------------+-------+ -| ZEBRA_IPSET_ENTRY_DELETE | 90 | -+------------------------------------+-------+ -| ZEBRA_IPSET_NOTIFY_OWNER | 91 | -+------------------------------------+-------+ -| ZEBRA_IPSET_ENTRY_NOTIFY_OWNER | 92 | -+------------------------------------+-------+ -| ZEBRA_IPTABLE_ADD | 93 | -+------------------------------------+-------+ -| ZEBRA_IPTABLE_DELETE | 94 | -+------------------------------------+-------+ -| ZEBRA_IPTABLE_NOTIFY_OWNER | 95 | -+------------------------------------+-------+ -| ZEBRA_VXLAN_FLOOD_CONTROL | 96 | -+------------------------------------+-------+ -| ZEBRA_VXLAN_SG_ADD | 97 | -+------------------------------------+-------+ -| ZEBRA_VXLAN_SG_DEL | 98 | -+------------------------------------+-------+ -| ZEBRA_VXLAN_SG_REPLAY | 99 | -+------------------------------------+-------+ -| ZEBRA_MLAG_PROCESS_UP | 100 | -+------------------------------------+-------+ -| ZEBRA_MLAG_PROCESS_DOWN | 101 | -+------------------------------------+-------+ -| ZEBRA_MLAG_CLIENT_REGISTER | 102 | -+------------------------------------+-------+ -| ZEBRA_MLAG_CLIENT_UNREGISTER | 103 | -+------------------------------------+-------+ -| ZEBRA_MLAG_FORWARD_MSG | 104 | -+------------------------------------+-------+ -| ZEBRA_ERROR | 105 | -+------------------------------------+-------+ -| ZEBRA_CLIENT_CAPABILITIES | 106 | -+------------------------------------+-------+ -| ZEBRA_OPAQUE_MESSAGE | 107 | -+------------------------------------+-------+ -| ZEBRA_OPAQUE_REGISTER | 108 | -+------------------------------------+-------+ -| ZEBRA_OPAQUE_UNREGISTER | 109 | -+------------------------------------+-------+ -| ZEBRA_NEIGH_DISCOVER | 110 | -+------------------------------------+-------+ +The definitions of zebra protocol commands can be found at ``lib/zclient.h``. Dataplane batching ================== diff --git a/doc/figures/cli-change-client.drawio b/doc/figures/cli-change-client.drawio new file mode 100644 index 0000000000..c7a68d40e4 --- /dev/null +++ b/doc/figures/cli-change-client.drawio @@ -0,0 +1,522 @@ +<mxfile host="Electron" modified="2023-06-19T07:55:43.434Z" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/21.2.8 Chrome/112.0.5615.165 Electron/24.2.0 Safari/537.36" etag="hHcr6k13KyEFOw_PaIFY" version="21.2.8" type="device"> + <diagram name="Page-1" id="58cdce13-f638-feb5-8d6f-7d28b1aa9fa0"> + <mxGraphModel dx="2074" dy="1264" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1100" pageHeight="850" background="none" math="0" shadow="1"> + <root> + <mxCell id="0" /> + <mxCell id="1" parent="0" /> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-239" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;jumpStyle=gap;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-28" target="nUYlmBzm2YxJIW5L2hvB-238" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="265.02000000000004" y="307.47999999999996" /> + <mxPoint x="265.02000000000004" y="307.47999999999996" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-240" value="copy of vty-&gt;cfg_changes<br>to protobuf msg" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-239" vertex="1" connectable="0"> + <mxGeometry x="-0.1005" relative="1" as="geometry"> + <mxPoint x="56" y="-15" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-80" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;jumpStyle=gap;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-77" target="nUYlmBzm2YxJIW5L2hvB-78" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="120.01999999999998" y="672.48" /> + <mxPoint x="120.01999999999998" y="672.48" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-11" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;fontSize=12;startSize=8;endSize=8;strokeColor=#ff0000;labelBackgroundColor=none;endArrow=open;fontFamily=Verdana;align=left;entryX=0;entryY=0.5;entryDx=0;entryDy=0;jumpStyle=gap;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-1" target="nUYlmBzm2YxJIW5L2hvB-7" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="260" y="505" /> + <mxPoint x="260" y="505" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-34" value="N" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=12;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-11" vertex="1" connectable="0"> + <mxGeometry x="-0.3317" y="1" relative="1" as="geometry"> + <mxPoint x="60" y="-14" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-15" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;entryX=0;entryY=0.5;entryDx=0;entryDy=0;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-1" target="nUYlmBzm2YxJIW5L2hvB-13" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="170.0200000000002" y="492.47999999999996" as="sourcePoint" /> + <mxPoint x="200.0200000000002" y="567.48" as="targetPoint" /> + <Array as="points"> + <mxPoint x="190.01999999999998" y="522.48" /> + <mxPoint x="190.01999999999998" y="567.48" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-35" value="N+1" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=12;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-15" vertex="1" connectable="0"> + <mxGeometry x="-0.5391" relative="1" as="geometry"> + <mxPoint x="20" y="2" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-1" value="user cmd:<br>&nbsp;"ip route 10.0.0.0/24 null0"<br>-------------------------------<br><br>" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="60.01999999999999" y="467.47999999999996" width="120" height="75" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-3" style="edgeStyle=orthogonalEdgeStyle;html=1;labelBackgroundColor=none;endArrow=open;endSize=8;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;align=left;entryX=0;entryY=0.5;entryDx=0;entryDy=0;jumpStyle=gap;exitX=1;exitY=0.25;exitDx=0;exitDy=0;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-1" target="nUYlmBzm2YxJIW5L2hvB-5" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="260.02000000000004" y="476.97999999999996" as="sourcePoint" /> + <mxPoint x="300.02000000000004" y="367.47999999999996" as="targetPoint" /> + <Array as="points"> + <mxPoint x="280.02000000000004" y="486.47999999999996" /> + <mxPoint x="280.02000000000004" y="397.47999999999996" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-33" value="1" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=12;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-3" vertex="1" connectable="0"> + <mxGeometry x="-0.3723" y="-1" relative="1" as="geometry"> + <mxPoint x="36" y="-76" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-5" value="nb_cli_enqueue_change" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=10;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="345.02000000000004" y="377.47999999999996" width="130" height="40" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-7" value="nb_cli_enqueue_change" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=10;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="345.02000000000004" y="484.97999999999996" width="130" height="40" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-29" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;jumpStyle=gap;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-13" target="nUYlmBzm2YxJIW5L2hvB-28" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="210" y="345" /> + <mxPoint x="210" y="345" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-31" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;entryX=0;entryY=0.5;entryDx=0;entryDy=0;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-13" target="nUYlmBzm2YxJIW5L2hvB-27" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-32" value="<font style="font-size: 7px;">file or !mgmtd</font>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=7;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-31" vertex="1" connectable="0"> + <mxGeometry x="-0.3307" y="1" relative="1" as="geometry"> + <mxPoint x="11" y="-9" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-13" value="nb_cli_apply_changes" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="210.01999999999998" y="547.48" width="100" height="40" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-14" value="" style="endArrow=none;dashed=1;html=1;dashPattern=1 3;strokeWidth=4;rounded=1;labelBackgroundColor=none;strokeColor=#000000;fontFamily=Verdana;fontSize=12;fontColor=default;startSize=8;endSize=8;shape=connector;" parent="1" edge="1"> + <mxGeometry width="50" height="50" relative="1" as="geometry"> + <mxPoint x="409.62000000000006" y="467.47999999999996" as="sourcePoint" /> + <mxPoint x="409.62000000000006" y="427.47999999999996" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-17" value="" style="triangle;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=12;fontColor=default;rotation=-90;" parent="1" vertex="1"> + <mxGeometry x="575" y="355" width="20" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-18" value="" style="triangle;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=12;fontColor=default;rotation=-90;" parent="1" vertex="1"> + <mxGeometry x="575" y="385" width="20" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-19" value="" style="triangle;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=12;fontColor=default;rotation=-90;" parent="1" vertex="1"> + <mxGeometry x="575" y="475" width="20" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-20" value="" style="endArrow=none;dashed=1;html=1;dashPattern=1 3;strokeWidth=4;rounded=1;labelBackgroundColor=none;strokeColor=#000000;fontFamily=Verdana;fontSize=12;fontColor=default;startSize=8;endSize=8;shape=connector;" parent="1" edge="1"> + <mxGeometry width="50" height="50" relative="1" as="geometry"> + <mxPoint x="584.63" y="465" as="sourcePoint" /> + <mxPoint x="584.63" y="425" as="targetPoint" /> + <Array as="points"> + <mxPoint x="584.63" y="445" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-21" value="<font style="font-size: 10px;">candidate<br>ds</font>" style="shape=datastore;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=12;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="530" y="577.48" width="60" height="60" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-23" value="<font style="font-size: 10px;">candidate<br>ds</font>" style="shape=datastore;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=12;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="644.98" y="577.48" width="60" height="60" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-24" value="" style="shape=singleArrow;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=12;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="600" y="592.48" width="29.98" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-61" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;entryX=0;entryY=0.5;entryDx=0;entryDy=0;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-27" target="nUYlmBzm2YxJIW5L2hvB-59" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-27" value="nb_cli_apply_changes_internal" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="380.02000000000004" y="547.48" width="130" height="40" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-38" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;labelBackgroundColor=none;strokeColor=#C73500;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;dashed=1;dashPattern=1 4;strokeWidth=2;fillColor=#fa6800;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-238" target="nUYlmBzm2YxJIW5L2hvB-37" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="825.02" y="272.47999999999996" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-39" value="<font style="font-size: 10px;"><i>socket connection</i><br>FE client -&gt; adapter SETCFG_REQ<br><br></font>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-38" vertex="1" connectable="0"> + <mxGeometry x="-0.0889" y="2" relative="1" as="geometry"> + <mxPoint x="-27" y="22" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-255" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-28" target="nUYlmBzm2YxJIW5L2hvB-246" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="230" y="200" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-256" value="implicit_commit<br style="font-size: 10px;">(legacy CLI)" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;horizontal=0;" parent="nUYlmBzm2YxJIW5L2hvB-255" vertex="1" connectable="0"> + <mxGeometry x="-0.5348" y="-1" relative="1" as="geometry"> + <mxPoint x="-11" y="9" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-28" value="vty_mgmt_send_config_data" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="200.01999999999998" y="327.47999999999996" width="130" height="40" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-238" value="mgmt_fe_send_setcfg_req" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="420.02000000000004" y="252.48000000000002" width="130" height="40" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-30" value="<font style="font-size: 7px;">mgmtd</font>" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;fontSize=16;fontFamily=Verdana;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="235.01999999999998" y="517.48" width="50" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-36" value="" style="endArrow=none;dashed=1;html=1;dashPattern=1 3;strokeWidth=4;rounded=1;labelBackgroundColor=none;strokeColor=#000000;fontFamily=Verdana;fontSize=12;fontColor=default;startSize=8;endSize=8;shape=connector;" parent="1" edge="1"> + <mxGeometry width="50" height="50" relative="1" as="geometry"> + <mxPoint x="294.62" y="472.43" as="sourcePoint" /> + <mxPoint x="294.62" y="432.43" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-41" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=doubleBlock;endFill=1;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-37" target="nUYlmBzm2YxJIW5L2hvB-40" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-42" value="<font style="font-size: 10px;">validates input and creates TXN (CONFIG)<br><i>can happen multiple times</i><br></font>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-41" vertex="1" connectable="0"> + <mxGeometry x="0.197" y="1" relative="1" as="geometry"> + <mxPoint x="114" y="-4" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-37" value="mgmt_fe_session_handle_setcfg_req_msg" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="730.02" y="297.47999999999996" width="190" height="40" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-55" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;labelBackgroundColor=none;strokeColor=#001DBC;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;dashed=1;dashPattern=1 4;strokeWidth=2;fillColor=#0050ef;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-40" target="nUYlmBzm2YxJIW5L2hvB-44" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-56" value="<font style="font-size: 10px;">copy protobuf -&gt; txn_req.set_cfg.cfg_changes<br style="border-color: var(--border-color); font-size: 10px;"></font><span style="font-size: 10px;"><font style="font-size: 10px;">TIMER: MGMTD_TXN_PROC_SETCFG</font><br style="font-size: 10px;"></span>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-55" vertex="1" connectable="0"> + <mxGeometry x="0.2852" y="-1" relative="1" as="geometry"> + <mxPoint x="126" y="-31" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-40" value="mgmt_txn_send_set_config_req" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="752.52" y="377.47999999999996" width="145" height="40" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-60" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-44" target="nUYlmBzm2YxJIW5L2hvB-59" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="675.02" y="547.48" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-128" value="1" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=12;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-60" vertex="1" connectable="0"> + <mxGeometry x="-0.3733" y="3" relative="1" as="geometry"> + <mxPoint x="21" y="-13" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-69" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.436;entryY=0.026;entryDx=0;entryDy=0;entryPerimeter=0;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-44" target="nUYlmBzm2YxJIW5L2hvB-68" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-70" value="implicit_commit" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-69" vertex="1" connectable="0"> + <mxGeometry x="-0.1764" y="-3" relative="1" as="geometry"> + <mxPoint x="48" y="-3" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-129" value="2" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=12;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-69" vertex="1" connectable="0"> + <mxGeometry x="-0.2682" y="-1" relative="1" as="geometry"> + <mxPoint x="-4" y="-11" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-72" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=baseDash;startSize=8;endSize=8;endFill=0;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-44" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="980.02" y="517.48" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-130" value="2" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=12;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-72" vertex="1" connectable="0"> + <mxGeometry x="-0.1117" y="-3" relative="1" as="geometry"> + <mxPoint x="-29" y="-13" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-44" value="<div>mgmt_txn_process_set_cfg</div>" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="752.52" y="497.47999999999996" width="145" height="40" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-49" value="" style="shape=singleArrow;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=12;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="480.02" y="375" width="70" height="40" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-50" value="" style="shape=singleArrow;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=12;fontColor=default;rotation=-180;" parent="1" vertex="1"> + <mxGeometry x="615" y="375" width="70" height="40" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-59" value="<div>nb_candidate_edit</div>" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="542.5" y="524.98" width="105" height="40" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-64" value="struct<br>nb_cfg_change" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;fontSize=10;fontFamily=Verdana;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="535" y="315" width="100" height="40" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-68" value="<div>mgmt_txn_send_commit_config_req</div>" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffe6cc;strokeColor=#d79b00;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;" parent="1" vertex="1"> + <mxGeometry x="752.52" y="592.48" width="167.5" height="40" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-74" value="user cmd:<br>&nbsp;"ip route 10.0.1.0/24 null0"" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="60.01999999999999" y="550" width="100" height="40" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-75" value="user cmd:<br>&nbsp;"ip route 10.0.2.0/24 null0"" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="70.01999999999998" y="560" width="100" height="40" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-76" value="user cmd:<br>&nbsp;"ip route 10.0.3.0/24 null0"" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="80.01999999999998" y="570" width="100" height="40" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-77" value="user cmd:<br>"XFRR_end_configuration"<br>&nbsp;config or EOF" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;dashed=1;dashPattern=1 4;" parent="1" vertex="1"> + <mxGeometry x="60.01999999999999" y="626.98" width="120" height="40" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-90" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-78" target="nUYlmBzm2YxJIW5L2hvB-84" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-78" value="vty_mgmt_send_commit_config" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="215.01999999999998" y="631.48" width="140" height="31" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-88" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#C73500;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;dashed=1;dashPattern=1 4;strokeWidth=2;fillColor=#fa6800;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-84" target="nUYlmBzm2YxJIW5L2hvB-87" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="540" y="715" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-89" value="<i style="font-size: 10px;">socket connection<br style="font-size: 10px;"></i>FE client -&gt; adapter COMMCFG_REQ" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-88" vertex="1" connectable="0"> + <mxGeometry x="-0.0463" y="1" relative="1" as="geometry"> + <mxPoint x="-34" y="30" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-84" value="mgmt_fe_send_commitcfg_req" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="215.01999999999998" y="730" width="140" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-93" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;entryX=0.166;entryY=0.994;entryDx=0;entryDy=0;entryPerimeter=0;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-87" target="nUYlmBzm2YxJIW5L2hvB-68" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-87" value="mgmt_fe_session_handle_commit_config_req_msg<br>create txn if none yet<br>if running DS not locked, lock" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="490.00000000000006" y="700" width="220" height="90" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-95" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#001DBC;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;strokeWidth=1;fillColor=#0050ef;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-68" target="nUYlmBzm2YxJIW5L2hvB-159" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="835.02" y="632.48" as="sourcePoint" /> + <mxPoint x="883.7977777777774" y="718.48" as="targetPoint" /> + <Array as="points" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-96" value="<span style="font-size: 10px;">curr_phase == MGMTD_COMMIT_PHASE_PREPARE_CFG<br style="font-size: 10px;"></span>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-95" vertex="1" connectable="0"> + <mxGeometry x="0.2852" y="-1" relative="1" as="geometry"> + <mxPoint x="91" y="-21" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-131" value="<span style="font-size: 10px;">next_phase == MGMTD_COMMIT_PHASE_PREPARE_CFG<br style="font-size: 10px;"></span>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="1" vertex="1" connectable="0"> + <mxGeometry x="989.9977193457571" y="669.9979556509891" as="geometry"> + <mxPoint x="-46" y="1" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-159" value="TIMER:<br style="font-size: 7px;">MGMTD_TXN_PROC_COMCFG" style="ellipse;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=7;fillColor=#b1ddf0;strokeColor=#10739e;" parent="1" vertex="1"> + <mxGeometry x="800.02" y="717.26" width="120" height="80" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-241" value="<i style="border-color: var(--border-color);">does nothing more</i>:<span style="font-size: 9px;"><br>when</span><b style="font-size: 9px;"> not implicit_commit:</b><br style="font-size: 9px;">&nbsp;<font face="Courier New"><b>mgmt (set|delete)-config</b></font> CLI<br style="font-size: 9px;">(no_implicit_commit == true)<br style="font-size: 9px;">inside <font face="Courier New"><b>XFRR_{start,end}_config</b></font><br style="font-size: 9px;">(pending_allowed == true)" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=9;fillColor=#eeeeee;strokeColor=#36393d;" parent="1" vertex="1"> + <mxGeometry x="940.02" y="472.42999999999995" width="140" height="100.05" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-243" value="user cmd:<br>"XFRR_start_configuration"<br>&nbsp;config file read indicator" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;dashed=1;dashPattern=1 4;" parent="1" vertex="1"> + <mxGeometry x="60.01999999999999" y="417.47999999999996" width="120" height="35" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-257" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-245" target="nUYlmBzm2YxJIW5L2hvB-246" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="150" y="243" /> + <mxPoint x="200" y="243" /> + <mxPoint x="200" y="180" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-258" value="NO implicit commit<br style="font-size: 10px;">(vtysh -f file)" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;horizontal=0;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-257" vertex="1" connectable="0"> + <mxGeometry x="-0.8771" y="-1" relative="1" as="geometry"> + <mxPoint x="9" y="-41" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-245" value="user cmd:<br>"configure terminal"" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=default;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;strokeWidth=1;" parent="1" vertex="1"> + <mxGeometry x="60.01999999999999" y="367.47999999999996" width="120" height="35" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-248" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#C73500;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;dashed=1;strokeWidth=2;fillColor=#fa6800;startArrow=open;startFill=0;shadow=0;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-246" target="nUYlmBzm2YxJIW5L2hvB-247" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="625" y="190" as="targetPoint" /> + <Array as="points"> + <mxPoint x="585" y="193" /> + <mxPoint x="585" y="193" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-250" value="<i>socket connection<br style="font-size: 9px;"></i>FE client -&gt; adapter LOCKDS_REQ" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=9;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-248" vertex="1" connectable="0"> + <mxGeometry x="-0.0567" y="1" relative="1" as="geometry"> + <mxPoint x="5" y="-16" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-246" value="vty_mgmt_lock_cand_inline" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="380.02" y="172.48" width="120" height="35" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-247" value="LOCK CANDIDATE" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffe6cc;strokeColor=#d79b00;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;" parent="1" vertex="1"> + <mxGeometry x="680" y="175.00000000000003" width="120" height="35" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-252" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-251" target="nUYlmBzm2YxJIW5L2hvB-245" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-253" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;entryX=0;entryY=0.75;entryDx=0;entryDy=0;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;exitX=0.248;exitY=0.923;exitDx=0;exitDy=0;exitPerimeter=0;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-251" target="nUYlmBzm2YxJIW5L2hvB-243" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="90.01999999999998" y="322.47999999999996" /> + <mxPoint x="50.019999999999996" y="322.47999999999996" /> + <mxPoint x="50.019999999999996" y="443.47999999999996" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-254" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;exitX=0.088;exitY=0.793;exitDx=0;exitDy=0;exitPerimeter=0;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-251" target="nUYlmBzm2YxJIW5L2hvB-1" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="60" y="510" as="targetPoint" /> + <Array as="points"> + <mxPoint x="71" y="253" /> + <mxPoint x="40" y="253" /> + <mxPoint x="40" y="513" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-251" value="EVENT: VTYSH_READ" style="ellipse;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=7;fillColor=#b1ddf0;strokeColor=#10739e;" parent="1" vertex="1"> + <mxGeometry x="60.01999999999999" y="142.48000000000002" width="120" height="80" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-260" value="UNLOCK CANDIDATE" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffe6cc;strokeColor=#d79b00;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;" parent="1" vertex="1"> + <mxGeometry x="680" y="120.00000000000001" width="120" height="35" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-265" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-261" target="nUYlmBzm2YxJIW5L2hvB-262" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="10" y="707" /> + <mxPoint x="10" y="130" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-266" value="NO implicit commit" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;horizontal=0;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-265" vertex="1" connectable="0"> + <mxGeometry x="-0.781" y="-1" relative="1" as="geometry"> + <mxPoint x="9" y="-12" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-261" value="user cmd:<br>"end/exit"" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=default;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;strokeWidth=1;" parent="1" vertex="1"> + <mxGeometry x="60.01999999999998" y="690" width="120" height="35" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-262" value="vty_mgmt_lock_cand_inline" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="380.02" y="120" width="120" height="35" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-275" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;entryX=0;entryY=0.5;entryDx=0;entryDy=0;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-270" target="nUYlmBzm2YxJIW5L2hvB-268" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="300" y="35" /> + <mxPoint x="300" y="35" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-270" value="vty_mgmt_set_config_result_notified" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="360" y="11.25" width="180" height="35" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-263" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#C73500;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;dashed=1;strokeWidth=2;fillColor=#fa6800;startArrow=open;startFill=0;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-262" target="nUYlmBzm2YxJIW5L2hvB-260" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="500.02" y="140" as="sourcePoint" /> + <mxPoint x="680.02" y="140" as="targetPoint" /> + <Array as="points" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-264" value="<i>socket connection<br style="font-size: 9px;"></i>FE client -&gt; adapter LOCKDS_REQ" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=9;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-263" vertex="1" connectable="0"> + <mxGeometry x="-0.0567" y="1" relative="1" as="geometry"> + <mxPoint x="5" y="-16" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-272" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-267" target="nUYlmBzm2YxJIW5L2hvB-271" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="630" y="76" /> + <mxPoint x="630" y="76" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-273" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-267" target="nUYlmBzm2YxJIW5L2hvB-270" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="630" y="40" /> + <mxPoint x="630" y="40" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-267" value="EVENT: REPLY NOTIFICATIONS" style="ellipse;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=7;fillColor=#b1ddf0;strokeColor=#10739e;" parent="1" vertex="1"> + <mxGeometry x="660" y="5" width="120" height="80" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-269" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;jumpStyle=gap;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-268" target="nUYlmBzm2YxJIW5L2hvB-251" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="80" y="80" /> + <mxPoint x="80" y="80" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-268" value="<div>VTYSH</div>" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#cdeb8b;strokeColor=#36393d;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;" parent="1" vertex="1"> + <mxGeometry x="30" y="15" width="77.48" height="40" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-274" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-271" target="nUYlmBzm2YxJIW5L2hvB-268" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="330" y="76" /> + <mxPoint x="330" y="50" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-271" value="vty_mgmt_commit_config_result_notified" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="360" y="58.75" width="180" height="35" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-292" value="" style="group" parent="1" vertex="1" connectable="0"> + <mxGeometry x="950" y="710" width="140" height="130" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-284" value="" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=12;fontColor=default;" parent="nUYlmBzm2YxJIW5L2hvB-292" vertex="1"> + <mxGeometry width="140" height="130" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-278" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#C73500;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;dashed=1;dashPattern=1 4;strokeWidth=2;fillColor=#fa6800;" parent="nUYlmBzm2YxJIW5L2hvB-292" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="20" y="60" as="sourcePoint" /> + <mxPoint x="110.01999999999998" y="60" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-279" value="<i style="font-size: 10px;">socket&nbsp;</i>async" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-278" vertex="1" connectable="0"> + <mxGeometry x="-0.0463" y="1" relative="1" as="geometry"> + <mxPoint x="-8" y="-9" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-282" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#001DBC;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;dashed=1;dashPattern=1 4;strokeWidth=2;fillColor=#0050ef;" parent="nUYlmBzm2YxJIW5L2hvB-292" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="20" y="90" as="sourcePoint" /> + <mxPoint x="110" y="90" as="targetPoint" /> + <Array as="points"> + <mxPoint x="50" y="89.77000000000001" /> + <mxPoint x="50" y="89.77000000000001" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-283" value="<span style="font-size: 10px;"><font style="font-size: 10px;">timer/event&nbsp;</font>async<br style="font-size: 10px;"></span>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-282" vertex="1" connectable="0"> + <mxGeometry x="0.2852" y="-1" relative="1" as="geometry"> + <mxPoint x="-28" y="-11" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-285" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#C73500;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;dashed=1;strokeWidth=2;fillColor=#fa6800;startArrow=open;startFill=0;" parent="nUYlmBzm2YxJIW5L2hvB-292" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="20" y="35" as="sourcePoint" /> + <mxPoint x="110" y="35" as="targetPoint" /> + <Array as="points"> + <mxPoint x="20" y="35" /> + <mxPoint x="20" y="35" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-286" value="<i>socket&nbsp; sync (short-circuit)<br></i>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=9;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-285" vertex="1" connectable="0"> + <mxGeometry x="-0.0567" y="1" relative="1" as="geometry"> + <mxPoint x="5" y="-16" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-287" value="" style="endArrow=open;html=1;rounded=1;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=12;fontColor=default;startSize=8;endSize=8;shape=connector;" parent="nUYlmBzm2YxJIW5L2hvB-292" edge="1"> + <mxGeometry width="50" height="50" relative="1" as="geometry"> + <mxPoint x="20" y="120" as="sourcePoint" /> + <mxPoint x="105" y="119.19999999999999" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-288" value="function sync" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=9;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-287" vertex="1" connectable="0"> + <mxGeometry x="-0.26" y="2" relative="1" as="geometry"> + <mxPoint x="6" y="-8" as="offset" /> + </mxGeometry> + </mxCell> + </root> + </mxGraphModel> + </diagram> +</mxfile> diff --git a/doc/figures/cli-change-client.svg b/doc/figures/cli-change-client.svg new file mode 100644 index 0000000000..9194f24e67 --- /dev/null +++ b/doc/figures/cli-change-client.svg @@ -0,0 +1,3 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="1099" height="842" viewBox="-0.5 -0.5 1099 842" style="background-color: rgb(255, 255, 255);"><defs><filter id="dropShadow"><feGaussianBlur in="SourceAlpha" stdDeviation="1.7" result="blur"/><feOffset in="blur" dx="3" dy="3" result="offsetBlur"/><feFlood flood-color="#3D4574" flood-opacity="0.4" result="offsetColor"/><feComposite in="offsetColor" in2="offsetBlur" operator="in" result="offsetBlur"/><feBlend in="SourceGraphic" in2="offsetBlur"/></filter></defs><g filter="url(#dropShadow)"><path d="M 264 322.48 L 264 277.5 Q 264 267.5 274 267.5 L 416.78 267.5" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 408.9 272 L 417.9 267.5 L 408.9 263" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 253px; margin-left: 360px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;">copy of vty->cfg_changes<br />to protobuf msg</div></div></div></foreignObject><text x="360" y="256" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">copy of vty->cfg_changes...</text></switch></g><path d="M 119 661.98 L 119 664.74 Q 119 667.5 119 657.5 L 119 649.75 Q 119 642 129 642 L 211.78 642" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 203.9 646.5 L 212.9 642 L 203.9 637.5" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><path d="M 179.02 499.98 L 341.78 499.98" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 333.9 504.48 L 342.9 499.98 L 333.9 495.48" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 485px; margin-left: 295px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;">N</div></div></div></foreignObject><text x="295" y="489" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="12px" text-anchor="middle">N</text></switch></g><path d="M 179.02 517.5 L 184.01 517.5 Q 189 517.5 189 527.5 L 189 552.5 Q 189 562.5 197.89 562.49 L 206.78 562.48" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 198.91 566.99 L 207.9 562.48 L 198.9 557.99" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 527px; margin-left: 210px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;">N+1</div></div></div></foreignObject><text x="210" y="531" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="12px" text-anchor="middle">N+1</text></switch></g><rect x="59.02" y="462.48" width="120" height="75" rx="18" ry="18" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 118px; height: 1px; padding-top: 500px; margin-left: 60px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">user cmd:<br /> "ip route 10.0.0.0/24 null0"<br />-------------------------------<br /><br /></div></div></div></foreignObject><text x="119" y="502" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">user cmd:...</text></switch></g><path d="M 179.02 481.23 L 269 481.2 Q 279 481.2 279 471.2 L 279 402.5 Q 279 392.5 289 392.5 L 341.78 392.48" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 333.9 396.98 L 342.9 392.48 L 333.9 387.98" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 407px; margin-left: 296px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;">1</div></div></div></foreignObject><text x="296" y="410" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="12px" text-anchor="middle">1</text></switch></g><rect x="344.02" y="372.48" width="130" height="40" rx="9.6" ry="9.6" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 128px; height: 1px; padding-top: 392px; margin-left: 345px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">nb_cli_enqueue_change</div></div></div></foreignObject><text x="409" y="395" fill="#000000" font-family="Verdana" font-size="10px" text-anchor="middle">nb_cli_enqueue_change</text></switch></g><rect x="344.02" y="479.98" width="130" height="40" rx="9.6" ry="9.6" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 128px; height: 1px; padding-top: 500px; margin-left: 345px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">nb_cli_enqueue_change</div></div></div></foreignObject><text x="409" y="503" fill="#000000" font-family="Verdana" font-size="10px" text-anchor="middle">nb_cli_enqueue_change</text></switch></g><path d="M 259.02 542.48 L 259.02 502.98 M 259.02 496.98 M 259.02 496.98 L 259.02 484.21 M 259.02 478.21 M 259.02 478.21 L 259.02 364.72" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 263.52 372.6 L 259.02 363.6 L 254.52 372.6" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><path d="M 309.02 562.48 L 376.78 562.48" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 368.9 566.98 L 377.9 562.48 L 368.9 557.98" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 553px; margin-left: 344px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 7px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><font style="font-size: 7px;">file or !mgmtd</font></div></div></div></foreignObject><text x="344" y="555" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="7px" text-anchor="middle">file or !mgmtd</text></switch></g><rect x="209.02" y="542.48" width="100" height="40" rx="9.6" ry="9.6" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 98px; height: 1px; padding-top: 562px; margin-left: 210px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">nb_cli_apply_changes</div></div></div></foreignObject><text x="259" y="565" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">nb_cli_apply_changes</text></switch></g><path d="M 408.62 462.48 L 408.62 422.48" fill="none" stroke="#000000" stroke-width="4" stroke-miterlimit="10" stroke-dasharray="4 12" pointer-events="stroke"/><path d="M 574 350 L 594 365 L 574 380 Z" fill="rgb(255, 255, 255)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" transform="rotate(-90,584,365)" pointer-events="all"/><path d="M 574 380 L 594 395 L 574 410 Z" fill="rgb(255, 255, 255)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" transform="rotate(-90,584,395)" pointer-events="all"/><path d="M 574 470 L 594 485 L 574 500 Z" fill="rgb(255, 255, 255)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" transform="rotate(-90,584,485)" pointer-events="all"/><path d="M 583.63 460 L 583.63 450 Q 583.63 440 583.63 430 L 583.63 420" fill="none" stroke="#000000" stroke-width="4" stroke-miterlimit="10" stroke-dasharray="4 12" pointer-events="stroke"/><path d="M 529 580.48 C 529 569.81 589 569.81 589 580.48 L 589 624.48 C 589 635.15 529 635.15 529 624.48 Z" fill="rgb(255, 255, 255)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><path d="M 529 580.48 C 529 588.48 589 588.48 589 580.48 M 529 584.48 C 529 592.48 589 592.48 589 584.48 M 529 588.48 C 529 596.48 589 596.48 589 588.48" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 58px; height: 1px; padding-top: 612px; margin-left: 530px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;"><font style="font-size: 10px;">candidate<br />ds</font></div></div></div></foreignObject><text x="559" y="616" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="12px" text-anchor="middle">candidate...</text></switch></g><path d="M 643.98 580.48 C 643.98 569.81 703.98 569.81 703.98 580.48 L 703.98 624.48 C 703.98 635.15 643.98 635.15 643.98 624.48 Z" fill="rgb(255, 255, 255)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><path d="M 643.98 580.48 C 643.98 588.48 703.98 588.48 703.98 580.48 M 643.98 584.48 C 643.98 592.48 703.98 592.48 703.98 584.48 M 643.98 588.48 C 643.98 596.48 703.98 596.48 703.98 588.48" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 58px; height: 1px; padding-top: 612px; margin-left: 645px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;"><font style="font-size: 10px;">candidate<br />ds</font></div></div></div></foreignObject><text x="674" y="616" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="12px" text-anchor="middle">candidate...</text></switch></g><path d="M 599 597.98 L 622.98 597.98 L 622.98 587.48 L 628.98 602.48 L 622.98 617.48 L 622.98 606.98 L 599 606.98 Z" fill="rgb(255, 255, 255)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><path d="M 509.02 562.5 L 519.01 562.5 Q 529 562.5 529 552.5 L 529 546.25 Q 529 540 534.13 539.99 L 539.26 539.98" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 531.39 544.5 L 540.38 539.98 L 531.37 535.5" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><rect x="379.02" y="542.48" width="130" height="40" rx="9.6" ry="9.6" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 128px; height: 1px; padding-top: 562px; margin-left: 380px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">nb_cli_apply_changes_internal</div></div></div></foreignObject><text x="444" y="565" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">nb_cli_apply_changes_internal</text></switch></g><path d="M 549.02 267.5 L 814 267.5 Q 824 267.5 824.01 277.5 L 824.02 288.01" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="2 8" pointer-events="stroke"/><path d="M 819.01 280.25 L 824.02 290.24 L 829.01 280.24" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 288px; margin-left: 660px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><font style="font-size: 10px;"><i>socket connection</i><br />FE client -> adapter SETCFG_REQ<br /><br /></font></div></div></div></foreignObject><text x="660" y="291" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">socket connection...</text></switch></g><path d="M 229 322.48 L 229 205 Q 229 195 239 195 L 376.78 195" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 368.9 199.5 L 377.9 195 L 368.9 190.5" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)rotate(-90 219.5 265.98)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 266px; margin-left: 220px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;">implicit_commit<br style="font-size: 10px;" />(legacy CLI)</div></div></div></foreignObject><text x="220" y="269" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">implicit_commit...</text></switch></g><rect x="199.02" y="322.48" width="130" height="40" rx="9.6" ry="9.6" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 128px; height: 1px; padding-top: 342px; margin-left: 200px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">vty_mgmt_send_config_data</div></div></div></foreignObject><text x="264" y="345" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">vty_mgmt_send_config_data</text></switch></g><rect x="419.02" y="247.48" width="130" height="40" rx="9.6" ry="9.6" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 128px; height: 1px; padding-top: 267px; margin-left: 420px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_fe_send_setcfg_req</div></div></div></foreignObject><text x="484" y="270" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_fe_send_setcfg_req</text></switch></g><rect x="234.02" y="512.48" width="50" height="30" fill="none" stroke="none" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 527px; margin-left: 259px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 16px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><font style="font-size: 7px;">mgmtd</font></div></div></div></foreignObject><text x="259" y="532" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="16px" text-anchor="middle">mgmtd</text></switch></g><path d="M 293.62 467.43 L 293.62 427.43" fill="none" stroke="#000000" stroke-width="4" stroke-miterlimit="10" stroke-dasharray="4 12" pointer-events="stroke"/><path d="M 824.02 332.48 L 824.02 357.36" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 824.02 371.36 L 820.52 364.36 L 827.52 364.36 Z M 824.02 364.36 L 820.52 357.36 L 827.52 357.36 Z" fill="#ff0000" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 353px; margin-left: 940px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><font style="font-size: 10px;">validates input and creates TXN (CONFIG)<br /><i>can happen multiple times</i><br /></font></div></div></div></foreignObject><text x="940" y="356" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">validates input and creates TXN (CONFIG)...</text></switch></g><rect x="729.02" y="292.48" width="190" height="40" rx="9.6" ry="9.6" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 188px; height: 1px; padding-top: 312px; margin-left: 730px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_fe_session_handle_setcfg_req_msg</div></div></div></foreignObject><text x="824" y="315" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_fe_session_handle_setcfg_req_msg</text></switch></g><path d="M 824.02 412.48 L 824.02 488.01" fill="none" stroke="#001dbc" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="2 8" pointer-events="stroke"/><path d="M 819.02 480.24 L 824.02 490.24 L 829.02 480.24" fill="none" stroke="#001dbc" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 433px; margin-left: 950px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><font style="font-size: 10px;">copy protobuf -> txn_req.set_cfg.cfg_changes<br style="border-color: var(--border-color); font-size: 10px;" /></font><span style="font-size: 10px;"><font style="font-size: 10px;">TIMER: MGMTD_TXN_PROC_SETCFG</font><br style="font-size: 10px;" /></span></div></div></div></foreignObject><text x="950" y="436" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">copy protobuf -> txn_req.set_cfg.cfg_changes...</text></switch></g><rect x="751.52" y="372.48" width="145" height="40" rx="9.6" ry="9.6" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 143px; height: 1px; padding-top: 392px; margin-left: 753px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_txn_send_set_config_req</div></div></div></foreignObject><text x="824" y="395" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_txn_send_set_config_req</text></switch></g><path d="M 751.52 512.5 L 709 512.5 Q 699 512.5 699 522.5 L 699 531.25 Q 699 540 689 540 L 648.74 540" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 656.62 535.5 L 647.62 540 L 656.62 544.5" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 503px; margin-left: 731px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;">1</div></div></div></foreignObject><text x="731" y="507" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="12px" text-anchor="middle">1</text></switch></g><path d="M 824 532.48 L 824 550 Q 824 560 824.19 570 L 824.51 586.28" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 819.86 578.49 L 824.53 587.4 L 828.85 578.32" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 553px; margin-left: 870px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;">implicit_commit</div></div></div></foreignObject><text x="870" y="556" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">implicit_commit</text></switch></g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 543px; margin-left: 820px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;">2</div></div></div></foreignObject><text x="820" y="547" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="12px" text-anchor="middle">2</text></switch></g><path d="M 896.52 512.5 L 927.8 512.5 Q 937.8 512.5 947.8 512.5 L 979.02 512.48" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 979.02 517.48 L 979.02 507.48" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 503px; margin-left: 905px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;">2</div></div></div></foreignObject><text x="905" y="507" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="12px" text-anchor="middle">2</text></switch></g><rect x="751.52" y="492.48" width="145" height="40" rx="9.6" ry="9.6" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 143px; height: 1px; padding-top: 512px; margin-left: 753px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;"><div>mgmt_txn_process_set_cfg</div></div></div></div></foreignObject><text x="824" y="515" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_txn_process_set_cfg</text></switch></g><path d="M 479.02 384 L 535.02 384 L 535.02 370 L 549.02 390 L 535.02 410 L 535.02 396 L 479.02 396 Z" fill="rgb(255, 255, 255)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><path d="M 614 384 L 670 384 L 670 370 L 684 390 L 670 410 L 670 396 L 614 396 Z" fill="rgb(255, 255, 255)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" transform="rotate(-180,649,390)" pointer-events="all"/><rect x="541.5" y="519.98" width="105" height="40" rx="9.6" ry="9.6" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 103px; height: 1px; padding-top: 540px; margin-left: 543px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;"><div>nb_candidate_edit</div></div></div></div></foreignObject><text x="594" y="542" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">nb_candidate_edit</text></switch></g><rect x="534" y="310" width="100" height="40" fill="none" stroke="none" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 330px; margin-left: 584px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;">struct<br />nb_cfg_change</div></div></div></foreignObject><text x="584" y="333" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">struct...</text></switch></g><rect x="751.52" y="587.48" width="167.5" height="40" rx="9.6" ry="9.6" fill="#ffe6cc" stroke="#d79b00" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 166px; height: 1px; padding-top: 607px; margin-left: 753px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;"><div>mgmt_txn_send_commit_config_req</div></div></div></div></foreignObject><text x="835" y="610" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_txn_send_commit_config_req</text></switch></g><rect x="59.02" y="545" width="100" height="40" rx="9.6" ry="9.6" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 98px; height: 1px; padding-top: 565px; margin-left: 60px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">user cmd:<br /> "ip route 10.0.1.0/24 null0"</div></div></div></foreignObject><text x="109" y="567" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">user cmd:...</text></switch></g><rect x="69.02" y="555" width="100" height="40" rx="9.6" ry="9.6" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 98px; height: 1px; padding-top: 575px; margin-left: 70px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">user cmd:<br /> "ip route 10.0.2.0/24 null0"</div></div></div></foreignObject><text x="119" y="577" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">user cmd:...</text></switch></g><rect x="79.02" y="565" width="100" height="40" rx="9.6" ry="9.6" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 98px; height: 1px; padding-top: 585px; margin-left: 80px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">user cmd:<br /> "ip route 10.0.3.0/24 null0"</div></div></div></foreignObject><text x="129" y="587" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">user cmd:...</text></switch></g><rect x="59.02" y="621.98" width="120" height="40" rx="9.6" ry="9.6" fill="#ffffc0" stroke="#ff0000" stroke-dasharray="1 4" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 118px; height: 1px; padding-top: 642px; margin-left: 60px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">user cmd:<br />"XFRR_end_configuration"<br /> config or EOF</div></div></div></foreignObject><text x="119" y="644" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">user cmd:...</text></switch></g><path d="M 284.02 657.48 L 284.02 722.76" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 279.52 714.88 L 284.02 723.88 L 288.52 714.88" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><rect x="214.02" y="626.48" width="140" height="31" rx="7.44" ry="7.44" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 138px; height: 1px; padding-top: 642px; margin-left: 215px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">vty_mgmt_send_commit_config</div></div></div></foreignObject><text x="284" y="644" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">vty_mgmt_send_commit_config</text></switch></g><path d="M 354.02 740 L 484.53 740" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="2 8" pointer-events="stroke"/><path d="M 476.76 745 L 486.76 740 L 476.76 735" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 770px; margin-left: 385px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><i style="font-size: 10px;">socket connection<br style="font-size: 10px;" /></i>FE client -> adapter COMMCFG_REQ</div></div></div></foreignObject><text x="385" y="773" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">socket connection...</text></switch></g><rect x="214.02" y="725" width="140" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 138px; height: 1px; padding-top: 740px; margin-left: 215px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_fe_send_commitcfg_req</div></div></div></foreignObject><text x="284" y="742" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_fe_send_commitcfg_req</text></switch></g><path d="M 709 740 L 769.3 740 Q 779.3 740 779.3 730 L 779.32 629.48" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 783.82 637.36 L 779.32 628.36 L 774.82 637.36" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><rect x="489" y="695" width="220" height="90" rx="21.6" ry="21.6" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 218px; height: 1px; padding-top: 740px; margin-left: 490px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_fe_session_handle_commit_config_req_msg<br />create txn if none yet<br />if running DS not locked, lock</div></div></div></foreignObject><text x="599" y="742" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_fe_session_handle_commit_config_req_msg...</text></switch></g><path d="M 835.3 627.48 L 835.3 659.9 Q 835.3 669.9 845.3 669.9 L 852.15 669.9 Q 859 669.9 859 679.9 L 859.02 710.02" fill="none" stroke="#001dbc" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 854.52 702.14 L 859.02 711.14 L 863.52 702.14" fill="none" stroke="#001dbc" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 653px; margin-left: 950px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><span style="font-size: 10px;">curr_phase == MGMTD_COMMIT_PHASE_PREPARE_CFG<br style="font-size: 10px;" /></span></div></div></div></foreignObject><text x="950" y="656" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">curr_phase == MGMTD_COMMIT_PHASE_PREPARE_CFG </text></switch></g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 666px; margin-left: 943px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><span style="font-size: 10px;">next_phase == MGMTD_COMMIT_PHASE_PREPARE_CFG<br style="font-size: 10px;" /></span></div></div></div></foreignObject><text x="943" y="669" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">next_phase == MGMTD_COMMIT_PHASE_PREPARE_CFG </text></switch></g><ellipse cx="859.02" cy="752.26" rx="60" ry="40" fill="#b1ddf0" stroke="#10739e" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 118px; height: 1px; padding-top: 752px; margin-left: 800px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 7px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">TIMER:<br style="font-size: 7px;" />MGMTD_TXN_PROC_COMCFG</div></div></div></foreignObject><text x="859" y="754" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="7px" text-anchor="middle">TIMER:...</text></switch></g><rect x="939.02" y="467.43" width="140" height="100.05" fill="#eeeeee" stroke="#36393d" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 138px; height: 1px; padding-top: 517px; margin-left: 940px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 9px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;"><i style="border-color: var(--border-color);">does nothing more</i>:<span style="font-size: 9px;"><br />when</span><b style="font-size: 9px;"> not implicit_commit:</b><br style="font-size: 9px;" /> <font face="Courier New"><b>mgmt (set|delete)-config</b></font> CLI<br style="font-size: 9px;" />(no_implicit_commit == true)<br style="font-size: 9px;" />inside <font face="Courier New"><b>XFRR_{start,end}_config</b></font><br style="font-size: 9px;" />(pending_allowed == true)</div></div></div></foreignObject><text x="1009" y="520" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="9px" text-anchor="middle">does nothing more:...</text></switch></g><rect x="59.02" y="412.48" width="120" height="35" rx="8.4" ry="8.4" fill="#ffffc0" stroke="#ff0000" stroke-dasharray="1 4" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 118px; height: 1px; padding-top: 430px; margin-left: 60px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">user cmd:<br />"XFRR_start_configuration"<br /> config file read indicator</div></div></div></foreignObject><text x="119" y="432" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">user cmd:...</text></switch></g><path d="M 149 362.48 L 149 248 Q 149 238 159 238 L 189 238 Q 199 238 199 228 L 199 185 Q 199 175 209 175 L 376.78 175" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 368.9 179.5 L 377.9 175 L 368.9 170.5" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)rotate(-90 159.5 294.98)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 295px; margin-left: 160px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;">NO implicit commit<br style="font-size: 10px;" />(vtysh -f file)</div></div></div></foreignObject><text x="160" y="298" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">NO implicit commit...</text></switch></g><rect x="59.02" y="362.48" width="120" height="35" rx="8.4" ry="8.4" fill="#ffffc0" stroke="rgb(0, 0, 0)" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 118px; height: 1px; padding-top: 380px; margin-left: 60px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">user cmd:<br />"configure terminal"</div></div></div></foreignObject><text x="119" y="382" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">user cmd:...</text></switch></g><path d="M 503.49 188 L 574 188 Q 584 188 594 188 L 674.53 188" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="6 6" pointer-events="stroke"/><path d="M 511.26 183 L 501.26 188 L 511.26 193" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><path d="M 666.76 193 L 676.76 188 L 666.76 183" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 172px; margin-left: 590px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 9px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><i>socket connection<br style="font-size: 9px;" /></i>FE client -> adapter LOCKDS_REQ</div></div></div></foreignObject><text x="590" y="174" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="9px" text-anchor="middle">socket connection...</text></switch></g><rect x="379.02" y="167.48" width="120" height="35" rx="8.4" ry="8.4" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 118px; height: 1px; padding-top: 185px; margin-left: 380px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">vty_mgmt_lock_cand_inline</div></div></div></foreignObject><text x="439" y="187" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">vty_mgmt_lock_cand_inline</text></switch></g><rect x="679" y="170" width="120" height="35" rx="8.4" ry="8.4" fill="#ffe6cc" stroke="#d79b00" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 118px; height: 1px; padding-top: 188px; margin-left: 680px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">LOCK CANDIDATE</div></div></div></foreignObject><text x="739" y="190" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">LOCK CANDIDATE</text></switch></g><path d="M 119.02 217.48 L 119.02 360.24" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 114.52 352.36 L 119.02 361.36 L 123.52 352.36" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><path d="M 88.78 211.32 L 88.8 307.5 Q 88.8 317.5 78.8 317.5 L 59 317.5 Q 49 317.5 49 327.5 L 49 428.7 Q 49 438.7 52.89 438.71 L 56.78 438.72" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 48.89 443.2 L 57.9 438.73 L 48.92 434.2" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><path d="M 69.58 200.92 L 69.6 238 Q 69.6 248 59.6 248 L 49 248 Q 39 248 39 258 L 39 498 Q 39 508 47.89 508 L 56.78 508" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 48.9 512.5 L 57.9 508 L 48.9 503.5" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><ellipse cx="119.02" cy="177.48" rx="60" ry="40" fill="#b1ddf0" stroke="#10739e" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 118px; height: 1px; padding-top: 177px; margin-left: 60px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 7px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">EVENT: VTYSH_READ</div></div></div></foreignObject><text x="119" y="180" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="7px" text-anchor="middle">EVENT: VTYSH_READ</text></switch></g><rect x="679" y="115" width="120" height="35" rx="8.4" ry="8.4" fill="#ffe6cc" stroke="#d79b00" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 118px; height: 1px; padding-top: 133px; margin-left: 680px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">UNLOCK CANDIDATE</div></div></div></foreignObject><text x="739" y="135" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">UNLOCK CANDIDATE</text></switch></g><path d="M 59.02 702.5 L 19 702.5 Q 9 702.5 9 692.5 L 9 135 Q 9 125 19 125 L 376.78 125" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 368.9 129.5 L 377.9 125 L 368.9 120.5" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)rotate(-90 19.5 631.02)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 631px; margin-left: 20px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;">NO implicit commit</div></div></div></foreignObject><text x="20" y="634" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">NO implicit commit</text></switch></g><rect x="59.02" y="685" width="120" height="35" rx="8.4" ry="8.4" fill="#ffffc0" stroke="rgb(0, 0, 0)" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 118px; height: 1px; padding-top: 703px; margin-left: 60px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">user cmd:<br />"end/exit"</div></div></div></foreignObject><text x="119" y="705" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">user cmd:...</text></switch></g><rect x="379.02" y="115" width="120" height="35" rx="8.4" ry="8.4" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 118px; height: 1px; padding-top: 133px; margin-left: 380px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">vty_mgmt_lock_cand_inline</div></div></div></foreignObject><text x="439" y="135" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">vty_mgmt_lock_cand_inline</text></switch></g><path d="M 359 30 L 309 30 Q 299 30 289 30 L 31.24 30" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 39.12 25.5 L 30.12 30 L 39.12 34.5" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><rect x="359" y="6.25" width="180" height="35" rx="8.4" ry="8.4" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 178px; height: 1px; padding-top: 24px; margin-left: 360px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">vty_mgmt_set_config_result_notified</div></div></div></foreignObject><text x="449" y="26" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">vty_mgmt_set_config_result_notified</text></switch></g><path d="M 503.49 132.5 L 674.53 132.5" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="6 6" pointer-events="stroke"/><path d="M 511.26 127.5 L 501.26 132.5 L 511.26 137.5" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><path d="M 666.76 137.5 L 676.76 132.5 L 666.76 127.5" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 116px; margin-left: 590px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 9px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><i>socket connection<br style="font-size: 9px;" /></i>FE client -> adapter LOCKDS_REQ</div></div></div></foreignObject><text x="590" y="119" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="9px" text-anchor="middle">socket connection...</text></switch></g><path d="M 681.08 71 L 639 71 Q 629 71 619 71 L 541.24 71" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 549.12 66.5 L 540.12 71 L 549.12 75.5" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><path d="M 659.47 35 L 639 35 Q 629 35 619 35 L 541.24 35" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 549.12 30.5 L 540.12 35 L 549.12 39.5" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><ellipse cx="719" cy="40" rx="60" ry="40" fill="#b1ddf0" stroke="#10739e" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 118px; height: 1px; padding-top: 40px; margin-left: 660px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 7px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">EVENT: REPLY NOTIFICATIONS</div></div></div></foreignObject><text x="719" y="42" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="7px" text-anchor="middle">EVENT: REPLY NOTIFICATIONS</text></switch></g><path d="M 79 50 L 79 122 M 79 128 M 79 128 L 79 145.44" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 74.5 137.56 L 79 146.56 L 83.5 137.56" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><rect x="29" y="10" width="77.48" height="40" rx="9.6" ry="9.6" fill="#cdeb8b" stroke="#36393d" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 75px; height: 1px; padding-top: 30px; margin-left: 30px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;"><div>VTYSH</div></div></div></div></foreignObject><text x="68" y="32" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">VTYSH</text></switch></g><path d="M 359 71.3 L 339 71.3 Q 329 71.3 329 61.3 L 329 53.15 Q 329 45 319 45 L 108.72 45" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 116.6 40.5 L 107.6 45 L 116.6 49.5" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><rect x="359" y="53.75" width="180" height="35" rx="8.4" ry="8.4" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 178px; height: 1px; padding-top: 71px; margin-left: 360px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">vty_mgmt_commit_config_result_notified</div></div></div></foreignObject><text x="449" y="74" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">vty_mgmt_commit_config_result_notified</text></switch></g><rect x="949" y="705" width="140" height="130" fill="rgb(255, 255, 255)" stroke="rgb(0, 0, 0)" pointer-events="none"/><path d="M 969 765 L 1054.55 765" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="2 8" pointer-events="none"/><path d="M 1046.78 770 L 1056.78 765 L 1046.78 760" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" pointer-events="none"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 756px; margin-left: 1005px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: none; white-space: nowrap;"><i style="font-size: 10px;">socket </i>async</div></div></div></foreignObject><text x="1005" y="759" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">socket async</text></switch></g><path d="M 969 795 L 989 795 Q 999 795 1009 795 L 1054.53 795" fill="none" stroke="#001dbc" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="2 8" pointer-events="none"/><path d="M 1046.76 800 L 1056.76 795 L 1046.76 790" fill="none" stroke="#001dbc" stroke-width="2" stroke-miterlimit="10" pointer-events="none"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 786px; margin-left: 1000px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: none; white-space: nowrap;"><span style="font-size: 10px;"><font style="font-size: 10px;">timer/event </font>async<br style="font-size: 10px;" /></span></div></div></div></foreignObject><text x="1000" y="789" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">timer/event async </text></switch></g><path d="M 973.47 740 L 1054.53 740" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="6 6" pointer-events="none"/><path d="M 981.24 735 L 971.24 740 L 981.24 745" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" pointer-events="none"/><path d="M 1046.76 745 L 1056.76 740 L 1046.76 735" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" pointer-events="none"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 724px; margin-left: 1017px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 9px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: none; white-space: nowrap;"><i>socket  sync (short-circuit)<br /></i></div></div></div></foreignObject><text x="1017" y="726" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="9px" text-anchor="middle">socket  sync (short-circuit) </text></switch></g><path d="M 969 825 L 1051.76 824.22" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="none"/><path d="M 1043.92 828.8 L 1052.88 824.21 L 1043.84 819.8" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="none"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 815px; margin-left: 1006px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 9px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: none; white-space: nowrap;">function sync</div></div></div></foreignObject><text x="1006" y="818" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="9px" text-anchor="middle">function sync</text></switch></g></g><switch><g requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"/><a transform="translate(0,-5)" xlink:href="https://www.drawio.com/doc/faq/svg-export-text-problems" target="_blank"><text text-anchor="middle" font-size="10px" x="50%" y="100%">Text is not SVG - cannot display</text></a></switch></svg> \ No newline at end of file diff --git a/doc/figures/cli-change-mgmtd.drawio b/doc/figures/cli-change-mgmtd.drawio new file mode 100644 index 0000000000..e8beade742 --- /dev/null +++ b/doc/figures/cli-change-mgmtd.drawio @@ -0,0 +1,421 @@ +<mxfile host="Electron" modified="2023-06-19T08:43:10.542Z" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/21.4.0 Chrome/112.0.5615.204 Electron/24.5.1 Safari/537.36" etag="nT5OZWDjYXR5quOjpvZj" version="21.4.0" type="device"> + <diagram name="Page-1" id="58cdce13-f638-feb5-8d6f-7d28b1aa9fa0"> + <mxGraphModel dx="974" dy="1264" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1100" pageHeight="850" background="none" math="0" shadow="1"> + <root> + <mxCell id="0" /> + <mxCell id="1" parent="0" /> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-158" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#001DBC;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;strokeWidth=1;fillColor=#0050ef;jumpStyle=gap;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-65" target="nUYlmBzm2YxJIW5L2hvB-157" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-150" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;startArrow=none;startFill=0;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-65" target="nUYlmBzm2YxJIW5L2hvB-148" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="1350" y="320" /> + <mxPoint x="1350" y="320" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-65" value="mgmt_txn_prepare_cfg" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=default;align=center;" parent="1" vertex="1"> + <mxGeometry x="1280" y="279.78000000000003" width="145" height="20.44" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-160" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;dashed=1;dashPattern=1 4;strokeWidth=2;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-217" target="nUYlmBzm2YxJIW5L2hvB-161" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="1920" y="380" as="targetPoint" /> + <Array as="points"> + <mxPoint x="1607" y="590" /> + <mxPoint x="1840" y="590" /> + <mxPoint x="1840" y="660" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-174" value="MESSAGE_TXN_REQ create" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-160" vertex="1" connectable="0"> + <mxGeometry x="-0.5683" relative="1" as="geometry"> + <mxPoint x="-17" y="-10" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-218" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-66" target="nUYlmBzm2YxJIW5L2hvB-217" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="1490" y="590" /> + <mxPoint x="1490" y="590" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-66" value="mgmt_txn_send_be_txn_create" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=default;align=center;" parent="1" vertex="1"> + <mxGeometry x="1280" y="580" width="145" height="20" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-217" value="mgmt_be_send_txn_req" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=default;align=center;" parent="1" vertex="1"> + <mxGeometry x="1505" y="581" width="145" height="20" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-203" value="does nothing cfg_data replys will cause next transition " style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#eeeeee;strokeColor=#36393d;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="1240" y="640" width="180" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-214" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-67" target="nUYlmBzm2YxJIW5L2hvB-213" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-216" value="next_phase =  PHASE_TXN_DELETE" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-214" vertex="1" connectable="0"> + <mxGeometry x="-0.2492" y="-1" relative="1" as="geometry"> + <mxPoint x="10" y="19" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-67" value="mgmt_txn_send_be_cfg_apply" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=default;align=center;" parent="1" vertex="1"> + <mxGeometry x="1200" y="709.9999999999999" width="145" height="20" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-213" value="mgmt_be_send_cfgapply_req" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=default;align=center;" parent="1" vertex="1"> + <mxGeometry x="1440" y="709.9999999999999" width="145" height="20" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-111" value="mgmt_txn_send_commit_cfg_reply" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=default;align=center;" parent="1" vertex="1"> + <mxGeometry x="1161.25" y="769.9999999999999" width="145" height="20" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-140" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-94" target="nUYlmBzm2YxJIW5L2hvB-66" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="1270" y="590" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-145" value="PHASE_TXN_CREATE" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-140" vertex="1" connectable="0"> + <mxGeometry x="0.2148" y="-2" relative="1" as="geometry"> + <mxPoint x="49" y="112" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-141" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-94" target="nUYlmBzm2YxJIW5L2hvB-65" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="1300" y="260" /> + <mxPoint x="1353" y="260" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-144" value="PHASE_PREPARE_CFG" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-141" vertex="1" connectable="0"> + <mxGeometry x="-0.1955" y="3" relative="1" as="geometry"> + <mxPoint x="13" y="-7" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-142" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-94" target="nUYlmBzm2YxJIW5L2hvB-67" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="1210" y="340" /> + <mxPoint x="1210" y="340" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-146" value="PHASE_CFG_APPLY" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-142" vertex="1" connectable="0"> + <mxGeometry x="0.6696" y="2" relative="1" as="geometry"> + <mxPoint x="48" y="68" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-143" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-94" target="nUYlmBzm2YxJIW5L2hvB-111" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="1180" y="380" /> + <mxPoint x="1180" y="380" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-147" value="PHASE_TXN_DELETE" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-143" vertex="1" connectable="0"> + <mxGeometry x="0.7799" y="3" relative="1" as="geometry"> + <mxPoint x="51" y="48" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-204" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-94" target="nUYlmBzm2YxJIW5L2hvB-203" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="1250" y="340" /> + <mxPoint x="1250" y="340" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-205" value="PHASE_SEND_CFG" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-204" vertex="1" connectable="0"> + <mxGeometry x="0.857" y="3" relative="1" as="geometry"> + <mxPoint x="37" y="18" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-94" value="mgmt_txn_process_commit_cfg" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="1150" y="170" width="167.5" height="70" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-97" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#001DBC;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;strokeWidth=1;fillColor=#0050ef;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-65" target="nUYlmBzm2YxJIW5L2hvB-138" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="1360" y="281" as="sourcePoint" /> + <mxPoint x="1318" y="225" as="targetPoint" /> + <Array as="points"> + <mxPoint x="1580" y="290" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-113" value="curr_phase = PHASE_TXN_CREATE" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-97" vertex="1" connectable="0"> + <mxGeometry x="0.2534" y="-1" relative="1" as="geometry"> + <mxPoint x="-101" y="35" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-119" value="mgmt_txn_send_commit_config_req" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#ffe6cc;strokeColor=#d79b00;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="1150" y="50" width="167.5" height="40" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-122" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#001DBC;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;strokeWidth=1;fillColor=#0050ef;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-119" target="nUYlmBzm2YxJIW5L2hvB-138" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="826" y="435" as="sourcePoint" /> + <mxPoint x="824" y="521" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-123" value="curr_phase == MGMTD_COMMIT_PHASE_PREPARE_CFG " style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-122" vertex="1" connectable="0"> + <mxGeometry x="0.2852" y="-1" relative="1" as="geometry"> + <mxPoint x="-23" y="-21" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-132" value="next_phase == MGMTD_COMMIT_PHASE_PREPARE_CFG " style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="1" vertex="1" connectable="0"> + <mxGeometry x="1425" y="89.99851851851847" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-139" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-138" target="nUYlmBzm2YxJIW5L2hvB-94" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="1540" y="190" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-138" value="TIMER: MGMTD_TXN_PROC_COMCFG" style="ellipse;whiteSpace=wrap;fontFamily=Verdana;fontSize=8;fillColor=#b1ddf0;strokeColor=#10739e;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="1520" y="30" width="120" height="80" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-156" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;startArrow=none;startFill=0;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-65" target="nUYlmBzm2YxJIW5L2hvB-154" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="1353" y="310" /> + <mxPoint x="1513" y="310" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-148" value="GET nb_config_change's nb_config_diff(cand, run) or  txn->commit_cfg_req->req.commit_cfg.cfg_chgs " style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#e1d5e7;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;strokeColor=#9673a6;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="1280" y="330" width="145" height="50" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-154" value="mgmt_txn_create_config_batches" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#e1d5e7;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;strokeColor=#9673a6;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="1440" y="330" width="145" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-157" value="TIMER: MGMTD_TXN_ COMMITCFG_TIMEOUT" style="ellipse;whiteSpace=wrap;fontFamily=Verdana;fontSize=8;fillColor=#b1ddf0;strokeColor=#10739e;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="1590" y="190" width="90" height="60" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-176" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=doubleBlock;startSize=8;endSize=8;dashed=1;dashPattern=1 4;strokeWidth=2;endFill=1;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-161" target="nUYlmBzm2YxJIW5L2hvB-175" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="1970" y="90" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-177" value="MESSAGE_CFG_DATA_REPLY" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;horizontal=0;" parent="nUYlmBzm2YxJIW5L2hvB-176" vertex="1" connectable="0"> + <mxGeometry x="0.177" relative="1" as="geometry"> + <mxPoint x="-10" y="255" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-224" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;dashed=1;dashPattern=1 4;strokeWidth=2;endFill=0;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-161" target="nUYlmBzm2YxJIW5L2hvB-223" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="1890" y="460" as="targetPoint" /> + <Array as="points"> + <mxPoint x="1940" y="305" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-225" value="MESSAGE_CFG_APPLY_REPLY;" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;horizontal=0;" parent="nUYlmBzm2YxJIW5L2hvB-224" vertex="1" connectable="0"> + <mxGeometry x="-0.0859" y="3" relative="1" as="geometry"> + <mxPoint x="-7" y="64" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-161" value="Backend Client" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#cdeb8b;strokeColor=#36393d;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="1935" y="610" width="205" height="120" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-169" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-163" target="nUYlmBzm2YxJIW5L2hvB-168" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-163" value="mgmt_txn_notify_be_txn_reply" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="2020" y="465" width="167.5" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-192" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=doubleBlock;startSize=8;endSize=8;endFill=1;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-168" target="nUYlmBzm2YxJIW5L2hvB-171" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-168" value="mgmt_txn_send_be_cfg_data" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="2020" y="415" width="167.5" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-188" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-171" target="nUYlmBzm2YxJIW5L2hvB-187" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-189" value="batch: PHASE_TXN_REQ -> PHASE_SEND_CFG" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-188" vertex="1" connectable="0"> + <mxGeometry x="-0.176" relative="1" as="geometry"> + <mxPoint x="-9" y="-55" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-171" value="mgmt_be_send_cfgdata_req" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="2025" y="310" width="157.5" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-200" value="txn: PHASE_TXN_REQ -> PHASE_SEND_CFG" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-187" target="nUYlmBzm2YxJIW5L2hvB-199" edge="1"> + <mxGeometry x="1" y="80" relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="2095" y="240" /> + <mxPoint x="2095" y="240" /> + </Array> + <mxPoint x="75" y="-80" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-187" value="mgmt_move_txn_cfg_batch_to_next" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="2025" y="255" width="157.5" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-201" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#001DBC;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;strokeWidth=1;fillColor=#0050ef;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-199" target="nUYlmBzm2YxJIW5L2hvB-138" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="2095" y="30" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-202" value="curr_phase = PHASE_SEND_CFG" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-201" vertex="1" connectable="0"> + <mxGeometry x="0.4129" y="-3" relative="1" as="geometry"> + <mxPoint x="121" y="-7" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-199" value="mgmt_try_move_commit_to_next_phase if all backend clients have all been sent their batches move to next phase and post EVENT/TIMER" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="2002.5" y="160" width="185" height="60" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-172" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=doubleBlock;startSize=8;endSize=8;dashed=1;dashPattern=1 4;strokeWidth=2;endFill=1;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-171" target="nUYlmBzm2YxJIW5L2hvB-161" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="1957.5" y="175" as="sourcePoint" /> + <Array as="points"> + <mxPoint x="2000" y="325" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-173" value="MESSAGE_CFG_DATA_REQ" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;horizontal=0;" parent="nUYlmBzm2YxJIW5L2hvB-172" vertex="1" connectable="0"> + <mxGeometry x="-0.1783" y="-1" relative="1" as="geometry"> + <mxPoint x="-9" y="-30" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-195" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-175" target="nUYlmBzm2YxJIW5L2hvB-179" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-197" value="batch: PHASE_SEND_CFG -> PHASE_APPLY_CFG" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-195" vertex="1" connectable="0"> + <mxGeometry x="0.463" y="-1" relative="1" as="geometry"> + <mxPoint x="1" y="-9" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-175" value="mgmt_txn_notify_be_cfgdata_reply" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="1770" y="75" width="167.5" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-210" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-179" target="nUYlmBzm2YxJIW5L2hvB-180" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-179" value="mgmt_move_txn_cfg_batch_to_next" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="1770" y="160" width="167.5" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-181" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#001DBC;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;strokeWidth=1;fillColor=#0050ef;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-180" target="nUYlmBzm2YxJIW5L2hvB-138" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="1770" y="30" as="targetPoint" /> + <Array as="points"> + <mxPoint x="1720" y="235" /> + <mxPoint x="1720" y="50" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-182" value="curr_phase = PHASE_APPLY_CFG" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-181" vertex="1" connectable="0"> + <mxGeometry x="-0.4275" relative="1" as="geometry"> + <mxPoint x="50" y="72" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-180" value="mgmt_try_move_commit_to_next_phase" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="1763.75" y="220" width="180" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-164" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;dashed=1;dashPattern=1 4;strokeWidth=2;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-161" target="nUYlmBzm2YxJIW5L2hvB-163" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="2120" y="510" as="targetPoint" /> + <mxPoint x="2104" y="610" as="sourcePoint" /> + <Array as="points"> + <mxPoint x="2104" y="580" /> + <mxPoint x="2104" y="580" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-167" value="MESSAGE_TXN_REPLY" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;horizontal=0;" parent="nUYlmBzm2YxJIW5L2hvB-164" vertex="1" connectable="0"> + <mxGeometry x="-0.5021" y="1" relative="1" as="geometry"> + <mxPoint x="-13" y="-25" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-183" value="curr_phase = PHASE_TXN_CREATE" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="1" vertex="1" connectable="0"> + <mxGeometry x="1470" y="569.9974074074072" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-184" value="next_phase = PHASE_SEND_CFG" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="1" vertex="1" connectable="0"> + <mxGeometry x="1459.9985714285715" y="609.998574414664" as="geometry"> + <mxPoint x="5" y="-3" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-186" value="For each of the batches of cfgdata send msg and move" style="verticalLabelPosition=middle;verticalAlign=middle;strokeWidth=2;shape=mxgraph.lean_mapping.physical_pull;pointerEvents=1;fontFamily=Verdana;fontSize=8;fontColor=default;labelPosition=right;align=left;horizontal=1;" parent="1" vertex="1"> + <mxGeometry x="2025" y="370" width="30" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-191" value="For each of the  batches of cfgdata" style="verticalLabelPosition=middle;verticalAlign=middle;strokeWidth=2;shape=mxgraph.lean_mapping.physical_pull;pointerEvents=1;fontFamily=Verdana;fontSize=8;fontColor=default;labelPosition=right;align=left;horizontal=1;" parent="1" vertex="1"> + <mxGeometry x="1935" y="55" width="30" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-211" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;dashed=1;dashPattern=1 4;strokeWidth=2;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-213" target="nUYlmBzm2YxJIW5L2hvB-161" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="1945" y="670" as="targetPoint" /> + <mxPoint x="1435" y="600" as="sourcePoint" /> + <Array as="points"> + <mxPoint x="1850" y="720" /> + <mxPoint x="1850" y="670" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-212" value="MESSAGE_CFG_APPLY" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-211" vertex="1" connectable="0"> + <mxGeometry x="-0.5683" relative="1" as="geometry"> + <mxPoint x="-31" y="-10" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-219" value="batch: comm_phase = PHASE_TXN_CREATE" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="1" vertex="1" connectable="0"> + <mxGeometry x="1470" y="539.9974074074072" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-220" value="batch: comm_phase = PHASE_APPLY_CFG" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="1" vertex="1" connectable="0"> + <mxGeometry x="1390" y="699.9974074074072" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-228" value="batch: PHASE_APPLY_CFG -> PHASE_TXN_DELETE" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-223" target="nUYlmBzm2YxJIW5L2hvB-227" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-223" value="mgmt_txn_notify_be_cfg_apply_reply for each batch id in reply" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="1750" y="290" width="167.5" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-226" value="mgmt_txn_send_be_txn_delete" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="1750" y="420" width="167.5" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-229" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-227" target="nUYlmBzm2YxJIW5L2hvB-226" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-233" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-227" target="nUYlmBzm2YxJIW5L2hvB-232" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="1730" y="375" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-227" value="mgmt_move_txn_cfg_batch_to_next" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="1750" y="360" width="167.5" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-230" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#ff0000;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;dashed=1;dashPattern=1 4;strokeWidth=2;entryX=-0.012;entryY=0.122;entryDx=0;entryDy=0;entryPerimeter=0;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-226" target="nUYlmBzm2YxJIW5L2hvB-161" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="2055" y="699.96" as="targetPoint" /> + <mxPoint x="1700" y="470" as="sourcePoint" /> + <Array as="points"> + <mxPoint x="1870" y="625" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-231" value="MESSAGE_TXN_REQ delete" style="edgeLabel;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;horizontal=0;" parent="nUYlmBzm2YxJIW5L2hvB-230" vertex="1" connectable="0"> + <mxGeometry x="-0.5683" relative="1" as="geometry"> + <mxPoint x="-10" y="9" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-234" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;labelBackgroundColor=none;strokeColor=#001DBC;fontFamily=Verdana;fontSize=8;fontColor=default;endArrow=open;startSize=8;endSize=8;strokeWidth=1;fillColor=#0050ef;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-232" target="nUYlmBzm2YxJIW5L2hvB-138" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="1690" y="70" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-232" value="mgmt_try_move_commit_to_next_phase" style="rounded=1;whiteSpace=wrap;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="1560" y="420" width="180" height="30" as="geometry" /> + </mxCell> + </root> + </mxGraphModel> + </diagram> +</mxfile> diff --git a/doc/figures/cli-change-mgmtd.svg b/doc/figures/cli-change-mgmtd.svg new file mode 100644 index 0000000000..279f74a726 --- /dev/null +++ b/doc/figures/cli-change-mgmtd.svg @@ -0,0 +1,3 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="1048" height="781" viewBox="-0.5 -0.5 1048 781" style="background-color: rgb(255, 255, 255);"><defs><filter id="dropShadow"><feGaussianBlur in="SourceAlpha" stdDeviation="1.7" result="blur"/><feOffset in="blur" dx="3" dy="3" result="offsetBlur"/><feFlood flood-color="#3D4574" flood-opacity="0.4" result="offsetColor"/><feComposite in="offsetColor" in2="offsetBlur" operator="in" result="offsetBlur"/><feBlend in="SourceGraphic" in2="offsetBlur"/></filter></defs><g filter="url(#dropShadow)"><path d="M 275 274 L 475 274 Q 485 274 485 264 L 485 236.24" fill="none" stroke="#001dbc" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 489.5 244.12 L 485 235.12 L 480.5 244.12" fill="none" stroke="#001dbc" stroke-miterlimit="10" pointer-events="all"/><path d="M 200 284.22 L 200 294.11 Q 200 304 200 307.88 L 200 311.76" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 195.5 303.88 L 200 312.88 L 204.5 303.88" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><rect x="130" y="263.78" width="145" height="20.44" rx="4.91" ry="4.91" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 143px; height: 1px; padding-top: 274px; margin-left: 131px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_txn_prepare_cfg</div></div></div></foreignObject><text x="203" y="276" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_txn_prepare_cfg</text></switch></g><path d="M 500 574 L 680 574 Q 690 574 690 584 L 690 634 Q 690 644 700 644 L 780.53 644" fill="none" stroke="#ff0000" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="2 8" pointer-events="stroke"/><path d="M 772.76 649 L 782.76 644 L 772.76 639" fill="none" stroke="#ff0000" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="560" y="562">MESSAGE_TXN_REQ</text><text x="560" y="572">create</text></g><path d="M 275 574 L 330 574 Q 340 574 346.38 574 L 352.76 574" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 344.88 578.5 L 353.88 574 L 344.88 569.5" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><rect x="130" y="564" width="145" height="20" rx="4.8" ry="4.8" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 143px; height: 1px; padding-top: 574px; margin-left: 131px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_txn_send_be_txn_create</div></div></div></foreignObject><text x="203" y="576" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_txn_send_be_txn_create</text></switch></g><rect x="355" y="565" width="145" height="20" rx="4.8" ry="4.8" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 143px; height: 1px; padding-top: 575px; margin-left: 356px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_be_send_txn_req</div></div></div></foreignObject><text x="428" y="577" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_be_send_txn_req</text></switch></g><rect x="90" y="624" width="180" height="30" rx="7.2" ry="7.2" fill="#eeeeee" stroke="#36393d" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 178px; height: 1px; padding-top: 639px; margin-left: 91px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">does nothing<br />cfg_data replys will cause next transition<div><br /></div></div></div></div></foreignObject><text x="180" y="641" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">does nothing...</text></switch></g><path d="M 195 704 L 287.76 704" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 279.88 708.5 L 288.88 704 L 279.88 699.5" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="241" y="722">next_phase =</text><text x="241" y="732"> PHASE_TXN_DELETE</text></g><rect x="50" y="694" width="145" height="20" rx="4.8" ry="4.8" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 143px; height: 1px; padding-top: 704px; margin-left: 51px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_txn_send_be_cfg_apply</div></div></div></foreignObject><text x="123" y="706" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_txn_send_be_cfg_apply</text></switch></g><rect x="290" y="694" width="145" height="20" rx="4.8" ry="4.8" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 143px; height: 1px; padding-top: 704px; margin-left: 291px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_be_send_cfgapply_req</div></div></div></foreignObject><text x="363" y="706" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_be_send_cfgapply_req</text></switch></g><rect x="11.25" y="754" width="145" height="20" rx="4.8" ry="4.8" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 143px; height: 1px; padding-top: 764px; margin-left: 12px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_txn_send_commit_cfg_reply</div></div></div></foreignObject><text x="84" y="766" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_txn_send_commit_cfg_reply</text></switch></g><path d="M 120 224 L 120 564 Q 120 574 123.88 574 L 127.76 574" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 119.88 578.5 L 128.88 574 L 119.88 569.5" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="167" y="558">PHASE_TXN_CREATE</text></g><path d="M 150 224 L 150 234 Q 150 244 160 244 L 193 244 Q 203 244 203 252.77 L 203 261.54" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 198.5 253.66 L 203 262.66 L 207.5 253.66" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="180" y="237">PHASE_PREPARE_CFG</text></g><path d="M 60 224 L 60 314 Q 60 324 60 334 L 60 691.76" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 55.5 683.88 L 60 692.88 L 64.5 683.88" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="110" y="687">PHASE_CFG_APPLY</text></g><path d="M 30 224 L 30 354 Q 30 364 30 374 L 30 751.76" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 25.5 743.88 L 30 752.88 L 34.5 743.88" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="84" y="747">PHASE_TXN_DELETE</text></g><path d="M 100 224 L 100 314 Q 100 324 100 334 L 100 621.76" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 95.5 613.88 L 100 622.88 L 104.5 613.88" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="140" y="616">PHASE_SEND_CFG</text></g><rect x="0" y="154" width="167.5" height="70" rx="16.8" ry="16.8" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 166px; height: 1px; padding-top: 189px; margin-left: 1px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_txn_process_commit_cfg</div></div></div></foreignObject><text x="84" y="191" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_txn_process_commit_cfg</text></switch></g><path d="M 275 274 L 420 274 Q 430 274 430 264 L 430 96.24" fill="none" stroke="#001dbc" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 434.5 104.12 L 430 95.12 L 425.5 104.12" fill="none" stroke="#001dbc" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="330" y="252">curr_phase =</text><text x="330" y="262">PHASE_TXN_CREATE</text></g><rect x="0" y="34" width="167.5" height="40" rx="9.6" ry="9.6" fill="#ffe6cc" stroke="#d79b00" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 166px; height: 1px; padding-top: 54px; margin-left: 1px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_txn_send_commit_config_req</div></div></div></foreignObject><text x="84" y="56" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_txn_send_commit_config_req</text></switch></g><path d="M 167.5 54 L 367.76 54" fill="none" stroke="#001dbc" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 359.88 58.5 L 368.88 54 L 359.88 49.5" fill="none" stroke="#001dbc" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="274.5" y="27">curr_phase ==</text><text x="274.5" y="37">MGMTD_COMMIT_PHASE_PREPARE_CFG</text></g><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="275" y="67">next_phase ==</text><text x="275" y="77">MGMTD_COMMIT_PHASE_PREPARE_CFG</text></g><path d="M 390 83.81 L 390 164 Q 390 174 380 174 L 169.74 174" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 177.62 169.5 L 168.62 174 L 177.62 178.5" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><ellipse cx="430" cy="54" rx="60" ry="40" fill="#b1ddf0" stroke="#10739e" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 118px; height: 1px; padding-top: 54px; margin-left: 371px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">TIMER:<br />MGMTD_TXN_PROC_COMCFG</div></div></div></foreignObject><text x="430" y="56" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">TIMER:...</text></switch></g><path d="M 202.5 284.22 L 202.5 289.11 Q 202.5 294 212.5 294 L 353 294 Q 363 294 363 302.88 L 363 311.76" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 358.5 303.88 L 363 312.88 L 367.5 303.88" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><rect x="130" y="314" width="145" height="50" rx="12" ry="12" fill="#e1d5e7" stroke="#9673a6" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 143px; height: 1px; padding-top: 339px; margin-left: 131px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">GET nb_config_change's<br />nb_config_diff(cand, run)<br />or <br />txn->commit_cfg_req->req.commit_cfg.cfg_chgs<div><br /></div></div></div></div></foreignObject><text x="203" y="341" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">GET nb_config_change's...</text></switch></g><rect x="290" y="314" width="145" height="30" rx="7.2" ry="7.2" fill="#e1d5e7" stroke="#9673a6" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 143px; height: 1px; padding-top: 329px; margin-left: 291px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_txn_create_config_batches</div></div></div></foreignObject><text x="363" y="331" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_txn_create_config_batches</text></switch></g><ellipse cx="485" cy="204" rx="45" ry="30" fill="#b1ddf0" stroke="#10739e" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 88px; height: 1px; padding-top: 204px; margin-left: 441px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">TIMER:<br />MGMTD_TXN_<br />COMMITCFG_TIMEOUT</div></div></div></foreignObject><text x="485" y="206" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">TIMER:...</text></switch></g><path d="M 820 594 L 820 84 Q 820 74 814.87 74 L 809.74 74" fill="none" stroke="#ff0000" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="2 8" pointer-events="stroke"/><path d="M 789.74 74 L 799.74 69 L 799.74 79 Z M 799.74 74 L 809.74 69 L 809.74 79 Z" fill="#ff0000" stroke="#ff0000" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px" transform="rotate(-90,810.5,523.5)"><text x="810" y="526">MESSAGE_CFG_DATA_REPLY</text></g><path d="M 790 594 L 790 299 Q 790 289 780.99 289 L 771.97 289" fill="none" stroke="#ff0000" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="2 8" pointer-events="stroke"/><path d="M 779.74 284 L 769.74 289 L 779.74 294" fill="none" stroke="#ff0000" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px" transform="rotate(-90,780.5,507.5)"><text x="780" y="510">MESSAGE_CFG_APPLY_REPLY;</text></g><rect x="785" y="594" width="205" height="120" rx="28.8" ry="28.8" fill="#cdeb8b" stroke="#36393d" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 203px; height: 1px; padding-top: 654px; margin-left: 786px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">Backend Client</div></div></div></foreignObject><text x="888" y="656" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">Backend Client</text></switch></g><path d="M 953.8 449 L 953.8 439 Q 953.8 429 953.8 439 L 953.8 444 Q 953.8 449 953.8 440.12 L 953.8 431.24" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 958.3 439.12 L 953.8 430.12 L 949.3 439.12" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><rect x="870" y="449" width="167.5" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 166px; height: 1px; padding-top: 464px; margin-left: 871px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_txn_notify_be_txn_reply</div></div></div></foreignObject><text x="954" y="466" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_txn_notify_be_txn_reply</text></switch></g><path d="M 953.75 399 L 953.75 343.12" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 953.75 325.12 L 958.25 334.12 L 949.25 334.12 Z M 953.75 334.12 L 958.25 343.12 L 949.25 343.12 Z" fill="#ff0000" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><rect x="870" y="399" width="167.5" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 166px; height: 1px; padding-top: 414px; margin-left: 871px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_txn_send_be_cfg_data</div></div></div></foreignObject><text x="954" y="416" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_txn_send_be_cfg_data</text></switch></g><path d="M 953.8 294 L 953.8 284 Q 953.8 274 953.8 281.5 L 953.8 285.25 Q 953.8 289 953.8 280.12 L 953.8 271.24" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 958.3 279.12 L 953.8 270.12 L 949.3 279.12" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="944.8" y="225">batch: PHASE_TXN_REQ -> PHASE_SEND_CFG</text></g><rect x="875" y="294" width="157.5" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 156px; height: 1px; padding-top: 309px; margin-left: 876px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_be_send_cfgdata_req</div></div></div></foreignObject><text x="954" y="311" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_be_send_cfgdata_req</text></switch></g><path d="M 945 239 L 945 231.5 Q 945 224 945 215.12 L 945 206.24" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 949.5 214.12 L 945 205.12 L 940.5 214.12" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="939.5" y="126.5">txn: PHASE_TXN_REQ -> PHASE_SEND_CFG</text></g><rect x="875" y="239" width="157.5" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 156px; height: 1px; padding-top: 254px; margin-left: 876px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_move_txn_cfg_batch_to_next</div></div></div></foreignObject><text x="954" y="256" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_move_txn_cfg_batch_to_next</text></switch></g><path d="M 945 144 L 945 24 Q 945 14 935 14 L 432.24 14" fill="none" stroke="#001dbc" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 440.12 9.5 L 431.12 14 L 440.12 18.5" fill="none" stroke="#001dbc" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="740" y="7">curr_phase = PHASE_SEND_CFG</text></g><rect x="852.5" y="144" width="185" height="60" rx="14.4" ry="14.4" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 183px; height: 1px; padding-top: 174px; margin-left: 854px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_try_move_commit_to_next_phase<br />if all backend clients<br />have all been sent their batches<br />move to next phase and post EVENT/TIMER</div></div></div></foreignObject><text x="945" y="176" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_try_move_commit_to_next_phase...</text></switch></g><path d="M 875 309 L 860 309 Q 850 309 850 319 L 850 571.76" fill="none" stroke="#ff0000" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="2 8" pointer-events="stroke"/><path d="M 850 591.76 L 845 581.76 L 855 581.76 Z M 850 581.76 L 845 571.76 L 855 571.76 Z" fill="#ff0000" stroke="#ff0000" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px" transform="rotate(-90,840.5,380.5)"><text x="840" y="383">MESSAGE_CFG_DATA_REQ</text></g><path d="M 703.75 89 L 703.75 141.76" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 699.25 133.88 L 703.75 142.88 L 708.25 133.88" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="703.75" y="123">batch: PHASE_SEND_CFG -> PHASE_APPLY_CFG</text></g><rect x="620" y="59" width="167.5" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 166px; height: 1px; padding-top: 74px; margin-left: 621px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_txn_notify_be_cfgdata_reply</div></div></div></foreignObject><text x="704" y="76" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_txn_notify_be_cfgdata_reply</text></switch></g><path d="M 703.8 174 L 703.8 184 Q 703.8 194 703.8 197.88 L 703.8 201.76" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 699.3 193.88 L 703.8 202.88 L 708.3 193.88" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><rect x="620" y="144" width="167.5" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 166px; height: 1px; padding-top: 159px; margin-left: 621px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_move_txn_cfg_batch_to_next</div></div></div></foreignObject><text x="704" y="161" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_move_txn_cfg_batch_to_next</text></switch></g><path d="M 613.75 219 L 580 219 Q 570 219 570 209 L 570 44 Q 570 34 560 34 L 484.2 34" fill="none" stroke="#001dbc" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 492.08 29.5 L 483.08 34 L 492.08 38.5" fill="none" stroke="#001dbc" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="620" y="246.75">curr_phase = PHASE_APPLY_CFG</text></g><rect x="613.75" y="204" width="180" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 178px; height: 1px; padding-top: 219px; margin-left: 615px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_try_move_commit_to_next_phase</div></div></div></foreignObject><text x="704" y="221" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_try_move_commit_to_next_phase</text></switch></g><path d="M 954 594 L 954 574 Q 954 564 954 554 L 954 483.47" fill="none" stroke="#ff0000" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="2 8" pointer-events="stroke"/><path d="M 959 491.24 L 954 481.24 L 949 491.24" fill="none" stroke="#ff0000" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px" transform="rotate(-90,940.5,539.5)"><text x="940" y="542">MESSAGE_TXN_REPLY</text></g><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="320" y="552">curr_phase =</text><text x="320" y="562">PHASE_TXN_CREATE</text></g><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="315" y="589">next_phase =</text><text x="315" y="599">PHASE_SEND_CFG</text></g><path d="M 896.96 356.21 C 891.58 352.95 884.78 353.59 880.07 357.81 C 875.37 362.03 873.83 368.87 876.25 374.79 C 878.67 380.7 884.51 384.35 890.73 383.85 C 896.96 383.35 902.17 378.8 903.66 372.57" fill="none" stroke="rgb(0, 0, 0)" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><path d="M 902.21 372.57 L 904.38 368.85 L 905 373.31 Z" fill="rgb(255, 255, 255)" stroke="rgb(0, 0, 0)" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px"><text x="906.5" y="361.5">For each of the</text><text x="906.5" y="371.5">batches of cfgdata</text><text x="906.5" y="381.5">send msg and move</text></g><path d="M 806.96 41.21 C 801.58 37.95 794.78 38.59 790.07 42.81 C 785.37 47.03 783.83 53.87 786.25 59.79 C 788.67 65.7 794.51 69.35 800.73 68.85 C 806.96 68.35 812.17 63.8 813.66 57.57" fill="none" stroke="rgb(0, 0, 0)" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><path d="M 812.21 57.57 L 814.38 53.85 L 815 58.31 Z" fill="rgb(255, 255, 255)" stroke="rgb(0, 0, 0)" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px"><text x="816.5" y="51.5">For each of the</text><text x="816.5" y="61.5"> batches of cfgdata</text></g><path d="M 435 704 L 690 704 Q 700 704 700 694 L 700 664 Q 700 654 710 654 L 780.53 654" fill="none" stroke="#ff0000" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="2 8" pointer-events="stroke"/><path d="M 772.76 659 L 782.76 654 L 772.76 649" fill="none" stroke="#ff0000" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="490" y="697">MESSAGE_CFG_APPLY</text></g><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="320" y="522">batch: comm_phase =</text><text x="320" y="532">PHASE_TXN_CREATE</text></g><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="240" y="682">batch: comm_phase =</text><text x="240" y="692">PHASE_APPLY_CFG</text></g><path d="M 683.75 304 L 683.75 341.76" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 679.25 333.88 L 683.75 342.88 L 688.25 333.88" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px"><text x="683.25" y="326.5">batch: PHASE_APPLY_CFG -> PHASE_TXN_DELETE</text></g><rect x="600" y="274" width="167.5" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 166px; height: 1px; padding-top: 289px; margin-left: 601px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_txn_notify_be_cfg_apply_reply<br />for each batch id in reply</div></div></div></foreignObject><text x="684" y="291" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_txn_notify_be_cfg_apply_reply...</text></switch></g><rect x="600" y="404" width="167.5" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 166px; height: 1px; padding-top: 419px; margin-left: 601px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_txn_send_be_txn_delete</div></div></div></foreignObject><text x="684" y="421" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_txn_send_be_txn_delete</text></switch></g><path d="M 683.8 374 L 683.8 384 Q 683.8 394 683.8 389 L 683.8 386.5 Q 683.8 384 683.8 392.88 L 683.8 401.76" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 679.3 393.88 L 683.8 402.88 L 688.3 393.88" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><path d="M 600 359 L 590 359 Q 580 359 580 369 L 580 401.76" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 575.5 393.88 L 580 402.88 L 584.5 393.88" fill="none" stroke="#ff0000" stroke-miterlimit="10" pointer-events="all"/><rect x="600" y="344" width="167.5" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 166px; height: 1px; padding-top: 359px; margin-left: 601px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_move_txn_cfg_batch_to_next</div></div></div></foreignObject><text x="684" y="361" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_move_txn_cfg_batch_to_next</text></switch></g><path d="M 720 434 L 720 598.6 Q 720 608.6 730 608.61 L 778.07 608.64" fill="none" stroke="#ff0000" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="2 8" pointer-events="stroke"/><path d="M 770.3 613.63 L 780.3 608.64 L 770.31 603.63" fill="none" stroke="#ff0000" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g fill="rgb(0, 0, 0)" font-family="Verdana" text-anchor="middle" font-size="8px" transform="rotate(-90,710.5,493.5)"><text x="710" y="491">MESSAGE_TXN_REQ</text><text x="710" y="501">delete</text></g><path d="M 540 404 L 540 64 Q 540 54 530 54 L 492.24 54" fill="none" stroke="#001dbc" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 500.12 49.5 L 491.12 54 L 500.12 58.5" fill="none" stroke="#001dbc" stroke-miterlimit="10" pointer-events="all"/><rect x="410" y="404" width="180" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 178px; height: 1px; padding-top: 419px; margin-left: 411px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_try_move_commit_to_next_phase</div></div></div></foreignObject><text x="500" y="421" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_try_move_commit_to_next_phase</text></switch></g></g><switch><g requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"/><a transform="translate(0,-5)" xlink:href="https://www.drawio.com/doc/faq/svg-export-text-problems" target="_blank"><text text-anchor="middle" font-size="10px" x="50%" y="100%">Text is not SVG - cannot display</text></a></switch></svg> \ No newline at end of file diff --git a/doc/figures/cli-oper-state.drawio b/doc/figures/cli-oper-state.drawio new file mode 100644 index 0000000000..4b86b58f7c --- /dev/null +++ b/doc/figures/cli-oper-state.drawio @@ -0,0 +1,377 @@ +<mxfile host="Electron" modified="2024-01-04T05:29:53.817Z" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/22.1.16 Chrome/120.0.6099.109 Electron/28.1.0 Safari/537.36" etag="qF0825mlH7rzndmYEIdj" version="22.1.16" type="device"> + <diagram name="Page-1" id="58cdce13-f638-feb5-8d6f-7d28b1aa9fa0"> + <mxGraphModel dx="1398" dy="842" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1100" pageHeight="850" background="none" math="0" shadow="1"> + <root> + <mxCell id="0" /> + <mxCell id="1" parent="0" /> + <mxCell id="kVfNefTpehhSeJQHV--9-92" value="<div style="font-size: 12px;">Frontend CLI (mgmtd)</div>" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#dae8fc;strokeColor=#6c8ebf;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=12;align=center;verticalAlign=top;fontStyle=1" parent="1" vertex="1"> + <mxGeometry x="10" y="61.42000000000001" width="425" height="312.17" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-30" value="<div style="font-size: 12px;">MGMTD</div>" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#dae8fc;strokeColor=#6c8ebf;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=12;align=center;verticalAlign=top;fontStyle=1" parent="1" vertex="1"> + <mxGeometry x="50" y="400" width="730" height="410" as="geometry" /> + </mxCell> + <mxCell id="lldLKuc6OoWEgdetZcLS-6" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="lldLKuc6OoWEgdetZcLS-3" target="lldLKuc6OoWEgdetZcLS-4" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="115" y="645" /> + <mxPoint x="115" y="645" /> + </Array> + <mxPoint x="385.0031707317075" y="605" as="sourcePoint" /> + <mxPoint x="385.93" y="695" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="lldLKuc6OoWEgdetZcLS-10" value="xpath" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];labelBackgroundColor=none;fontSize=8;" parent="lldLKuc6OoWEgdetZcLS-6" vertex="1" connectable="0"> + <mxGeometry x="0.062" y="2" relative="1" as="geometry"> + <mxPoint x="-22" y="4" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-4" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=classic;endFill=1;startArrow=classic;startFill=1;" parent="1" source="lldLKuc6OoWEgdetZcLS-3" target="kVfNefTpehhSeJQHV--9-3" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="215" y="695" /> + <mxPoint x="215" y="695" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-6" value="txn" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;labelBackgroundColor=none;" parent="kVfNefTpehhSeJQHV--9-4" vertex="1" connectable="0"> + <mxGeometry x="-0.1676" y="-2" relative="1" as="geometry"> + <mxPoint x="12" y="-26" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-8" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;fontFamily=Helvetica;fontSize=8;fontColor=default;" parent="1" source="lldLKuc6OoWEgdetZcLS-3" target="kVfNefTpehhSeJQHV--9-7" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="255" y="595" /> + <mxPoint x="255" y="742" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-10" value="clients (bitmask)" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Helvetica;fontColor=default;labelBackgroundColor=none;" parent="kVfNefTpehhSeJQHV--9-8" vertex="1" connectable="0"> + <mxGeometry x="-0.1299" y="1" relative="1" as="geometry"> + <mxPoint x="29" y="58" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="lldLKuc6OoWEgdetZcLS-3" value="fe_adapter_handle_get_tree" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=#000000;" parent="1" vertex="1"> + <mxGeometry x="75" y="575" width="160" height="30" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-73" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;fontFamily=Helvetica;fontSize=8;fontColor=default;endArrow=doubleBlock;endFill=1;" parent="1" source="kVfNefTpehhSeJQHV--9-46" target="kVfNefTpehhSeJQHV--9-72" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="530.037037037037" y="571" as="sourcePoint" /> + </mxGeometry> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-77" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;fontFamily=Helvetica;fontSize=8;fontColor=default;" parent="1" source="kVfNefTpehhSeJQHV--9-72" target="kVfNefTpehhSeJQHV--9-76" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-72" value="be_adapter_handle_get_tree<br>mgmt_txn_notify_tree_data_reply<br>------------------------------------<br>merge tree data<br>when all clients respond or timeout" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=#000000;" parent="1" vertex="1"> + <mxGeometry x="550" y="530" width="160" height="60" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-19" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;fontFamily=Helvetica;fontSize=8;fontColor=default;endArrow=doubleBlock;endFill=1;" parent="1" source="kVfNefTpehhSeJQHV--9-7" target="kVfNefTpehhSeJQHV--9-11" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-7" value="mgmt_txn_send_get_tree_oper" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=#000000;" parent="1" vertex="1"> + <mxGeometry x="320" y="725" width="160" height="30" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-11" value="mgmt_be_send_native" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=#000000;" parent="1" vertex="1"> + <mxGeometry x="565" y="725" width="130" height="30" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-83" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;fontFamily=Verdana;fontSize=12;fontColor=default;labelBackgroundColor=none;endArrow=open;strokeColor=#C73500;startSize=8;endSize=8;dashed=1;dashPattern=1 4;strokeWidth=2;fillColor=#fa6800;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" parent="1" source="kVfNefTpehhSeJQHV--9-76" target="kVfNefTpehhSeJQHV--9-82" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="320" y="543.75" as="sourcePoint" /> + <mxPoint x="300.03703703703695" y="326.25" as="targetPoint" /> + <Array as="points" /> + </mxGeometry> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-84" value="<i style="border-color: var(--border-color); font-family: Verdana; font-size: 10px;">socket connection<br style="border-color: var(--border-color);"></i><font style="font-size: 10px;">FE adapter -&gt; FE client<br style="border-color: var(--border-color); font-family: Verdana;"></font><span style="font-family: Verdana; font-size: 10px;">MGMT_MSG_CODE_TREE_DATA</span><br style="border-color: var(--border-color); font-family: Verdana; font-size: 10px;"><i style="border-color: var(--border-color); font-family: Verdana; font-size: 10px;">struct mgmt_msg_tree_data</i>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Helvetica;fontColor=default;labelBackgroundColor=none;" parent="kVfNefTpehhSeJQHV--9-83" vertex="1" connectable="0"> + <mxGeometry x="0.5" relative="1" as="geometry"> + <mxPoint x="80" y="84" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-76" value="txn_get_tree_data_done<br>fe_adapter_send_tree_data" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=#000000;" parent="1" vertex="1"> + <mxGeometry x="320" y="545" width="160" height="30" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-88" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;fontFamily=Helvetica;fontSize=8;fontColor=default;" parent="1" source="kVfNefTpehhSeJQHV--9-85" target="kVfNefTpehhSeJQHV--9-86" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-85" value="session-&gt;get_tree_notify" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=#000000;" parent="1" vertex="1"> + <mxGeometry x="235" y="256.79999999999995" width="160" height="30" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-90" value="vty_mgmt_resume_response" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=#000000;" parent="1" vertex="1"> + <mxGeometry x="235" y="118.92000000000002" width="160" height="30" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-91" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;fontFamily=Helvetica;fontSize=8;fontColor=default;" parent="1" source="kVfNefTpehhSeJQHV--9-86" target="kVfNefTpehhSeJQHV--9-90" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-86" value="<b>vty_mgmt_get_tree_result_notified<br></b>displays result<br>" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=#000000;" parent="1" vertex="1"> + <mxGeometry x="225" y="174.03" width="180" height="64.93" as="geometry" /> + </mxCell> + <mxCell id="lldLKuc6OoWEgdetZcLS-9" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="lldLKuc6OoWEgdetZcLS-4" target="lldLKuc6OoWEgdetZcLS-3" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="445" y="392.21000000000004" as="sourcePoint" /> + <mxPoint x="445" y="485" as="targetPoint" /> + <Array as="points"> + <mxPoint x="145" y="645" /> + <mxPoint x="145" y="645" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="lldLKuc6OoWEgdetZcLS-11" value="clients (bitmask)" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;fontFamily=Helvetica;fontColor=default;labelBackgroundColor=none;" parent="lldLKuc6OoWEgdetZcLS-9" vertex="1" connectable="0"> + <mxGeometry x="-0.1435" y="-1" relative="1" as="geometry"> + <mxPoint x="29" y="-9" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="lldLKuc6OoWEgdetZcLS-4" value="mgmt_be_interested_clients" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=#000000;" parent="1" vertex="1"> + <mxGeometry x="75" y="665" width="120" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-90" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=default;strokeColor=default;fontFamily=Helvetica;fontSize=11;fontColor=default;endArrow=classic;startSize=8;endSize=8;entryX=0.5;entryY=0;entryDx=0;entryDy=0;endFill=1;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-78" target="nUYlmBzm2YxJIW5L2hvB-84" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-78" value="vty_mgmt_send_get_tree_req" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="45.01999999999998" y="255.79999999999998" width="140" height="31" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-88" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#C73500;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;dashed=1;dashPattern=1 4;strokeWidth=2;fillColor=#fa6800;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-84" target="nUYlmBzm2YxJIW5L2hvB-87" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="540" y="715" as="targetPoint" /> + <Array as="points"> + <mxPoint x="115" y="470" /> + <mxPoint x="115" y="470" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-89" value="<i style="font-size: 10px;">socket connection<br style="font-size: 10px;"></i>FE client -&gt; FE adapter<br>MGMT_MSG_CODE_GET_TREE<br><i>struct mgmt_msg_get_tree</i>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-88" vertex="1" connectable="0"> + <mxGeometry x="-0.0463" y="1" relative="1" as="geometry"> + <mxPoint x="89" y="34" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-84" value="mgmt_fe_send_get_tree_req" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;" parent="1" vertex="1"> + <mxGeometry x="45.01999999999998" y="320.79999999999995" width="140" height="30" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-93" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=default;strokeColor=default;fontFamily=Helvetica;fontSize=11;fontColor=default;endArrow=classic;startSize=8;endSize=8;endFill=1;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-87" target="lldLKuc6OoWEgdetZcLS-3" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="532.8049999999998" y="542.2400000000002" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="lldLKuc6OoWEgdetZcLS-5" value="xpath" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-93" vertex="1" connectable="0"> + <mxGeometry x="-0.2901" y="1" relative="1" as="geometry"> + <mxPoint x="-21" y="15" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-87" value="fe_adapter_handle_native_msg" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#b1ddf0;strokeColor=#10739e;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=7;fontColor=default;align=center;" parent="1" vertex="1"> + <mxGeometry x="75" y="487.5" width="160" height="35" as="geometry" /> + </mxCell> + <mxCell id="lldLKuc6OoWEgdetZcLS-2" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=default;endArrow=classic;fontSize=11;fontFamily=Helvetica;strokeColor=default;startSize=8;endSize=8;endFill=1;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-245" target="nUYlmBzm2YxJIW5L2hvB-78" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-245" value=""show mgmt get-data-tree WORD$path [json|xml]"" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=default;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;fontColor=#000000;align=center;strokeWidth=1;" parent="1" vertex="1"> + <mxGeometry x="55.01999999999999" y="198.27999999999997" width="120" height="35" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-252" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=default;strokeColor=default;fontFamily=Helvetica;fontSize=11;fontColor=default;endArrow=classic;startSize=8;endSize=8;endFill=1;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-251" target="nUYlmBzm2YxJIW5L2hvB-245" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-251" value="EVENT: VTYSH_READ" style="ellipse;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=7;fillColor=#b1ddf0;strokeColor=#10739e;" parent="1" vertex="1"> + <mxGeometry x="55.01999999999999" y="93.92000000000004" width="120" height="80" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-275" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=default;strokeColor=default;fontFamily=Helvetica;fontSize=11;fontColor=default;endArrow=classic;startSize=8;endSize=8;endFill=1;" parent="1" source="kVfNefTpehhSeJQHV--9-90" target="nUYlmBzm2YxJIW5L2hvB-268" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="320" y="30" /> + </Array> + <mxPoint x="320.03703703703695" y="134.71000000000004" as="sourcePoint" /> + <mxPoint x="158.76" y="20" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-269" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=default;strokeColor=default;fontFamily=Helvetica;fontSize=11;fontColor=default;endArrow=classic;startSize=8;endSize=8;jumpStyle=gap;endFill=1;" parent="1" source="nUYlmBzm2YxJIW5L2hvB-268" target="nUYlmBzm2YxJIW5L2hvB-251" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="120" y="95" /> + <mxPoint x="120" y="95" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-268" value="<div>VTYSH</div>" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#cdeb8b;strokeColor=#36393d;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;" parent="1" vertex="1"> + <mxGeometry x="81.28" y="10" width="77.48" height="40" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-3" value="mgmt_create_txn" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=#000000;" parent="1" vertex="1"> + <mxGeometry x="115" y="725" width="120" height="30" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-12" value="mgmt_txn_req_alloc" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=#000000;" parent="1" vertex="1"> + <mxGeometry x="340" y="647.83" width="120" height="30" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-13" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;endArrow=classic;endFill=1;startArrow=classic;startFill=1;" parent="1" source="kVfNefTpehhSeJQHV--9-12" target="kVfNefTpehhSeJQHV--9-7" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="374.78" y="645" as="sourcePoint" /> + <mxPoint x="374.78" y="755" as="targetPoint" /> + <Array as="points" /> + </mxGeometry> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-14" value="txn_req<br>MGMTD_TXN_PROC_GETTREE" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=8;labelBackgroundColor=none;" parent="kVfNefTpehhSeJQHV--9-13" vertex="1" connectable="0"> + <mxGeometry x="-0.1676" y="-2" relative="1" as="geometry"> + <mxPoint x="37" y="-2" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-18" value="<div style="text-align: center;"><span style="background-color: initial;">for each of the clients</span></div><div style="text-align: center;"><span style="background-color: initial;">in bitmask</span></div>" style="verticalLabelPosition=middle;html=1;verticalAlign=middle;strokeWidth=2;shape=mxgraph.lean_mapping.physical_pull;pointerEvents=1;fontFamily=Verdana;fontSize=10;fontColor=default;labelPosition=right;align=left;horizontal=1;" parent="1" vertex="1"> + <mxGeometry x="525" y="687.83" width="30" height="30" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-41" value="be_client_send_native_msg" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=#000000;" parent="1" vertex="1"> + <mxGeometry x="660" y="186.42000000000002" width="130" height="25" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-46" value="be_adapter_handle_native_msg" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#b1ddf0;strokeColor=#10739e;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=7;fontColor=default;align=center;" parent="1" vertex="1"> + <mxGeometry x="550" y="437.83" width="160" height="35" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-50" value="<i style="font-size: 10px;">socket connection<br style="font-size: 10px;"></i>BE client -&gt; BE adapter<br>MGMT_MSG_CODE_TREE_DATA<br><i>struct mgmt_msg_tree_data</i>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="1" vertex="1" connectable="0"> + <mxGeometry x="529.997037037037" y="360.00370370370393" as="geometry"> + <mxPoint x="21" y="1" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-59" value="be_client_send_native_msg" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=#000000;" parent="1" vertex="1"> + <mxGeometry x="670" y="196.42000000000002" width="130" height="25" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-60" value="<div style="font-size: 12px;">Backend Client (ospfd, staticd, ...)</div>" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#E6FFCC;strokeColor=#36393d;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=12;align=center;verticalAlign=top;fontStyle=1" parent="1" vertex="1"> + <mxGeometry x="480" y="102.02000000000001" width="380" height="207.57" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-61" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;fontFamily=Helvetica;fontSize=8;fontColor=default;startArrow=classic;startFill=1;" parent="1" source="kVfNefTpehhSeJQHV--9-64" target="kVfNefTpehhSeJQHV--9-65" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="720" y="186.2" /> + <mxPoint x="720" y="186.2" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-62" value="<span style="font-style: normal;">(1) build oper state tree<br></span>struct mgmt_msg_tree_data" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Helvetica;fontColor=default;labelBackgroundColor=none;fontStyle=2" parent="kVfNefTpehhSeJQHV--9-61" vertex="1" connectable="0"> + <mxGeometry x="0.038" y="1" relative="1" as="geometry"> + <mxPoint x="71" y="-1" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-63" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;fontFamily=Helvetica;fontSize=8;fontColor=default;" parent="1" source="kVfNefTpehhSeJQHV--9-64" target="kVfNefTpehhSeJQHV--9-68" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="670" y="213.63" /> + <mxPoint x="670" y="213.63" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="eMqbX30VPKpUhST_t5Pw-11" value="(2)" style="edgeLabel;html=1;align=center;verticalAlign=bottom;resizable=0;points=[];labelBackgroundColor=none;" vertex="1" connectable="0" parent="kVfNefTpehhSeJQHV--9-63"> + <mxGeometry x="0.1063" y="-1" relative="1" as="geometry"> + <mxPoint x="3" y="1" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-64" value="be_client_handle_get_tree" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=#000000;" parent="1" vertex="1"> + <mxGeometry x="690" y="201.2" width="140" height="25" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-65" value="nb_oper_data_iterate" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=#000000;" parent="1" vertex="1"> + <mxGeometry x="690" y="131.13" width="110" height="25" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-66" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;fontFamily=Helvetica;fontSize=8;fontColor=default;" parent="1" source="kVfNefTpehhSeJQHV--9-67" target="kVfNefTpehhSeJQHV--9-64" edge="1"> + <mxGeometry relative="1" as="geometry"> + <Array as="points"> + <mxPoint x="760" y="238.63" /> + <mxPoint x="760" y="238.63" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-67" value="be_client_handle_native_msg" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#b1ddf0;strokeColor=#10739e;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=7;fontColor=default;align=center;" parent="1" vertex="1"> + <mxGeometry x="670" y="251.79999999999998" width="160" height="35" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-70" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;fontFamily=Verdana;fontSize=12;fontColor=default;labelBackgroundColor=none;endArrow=open;strokeColor=#C73500;startSize=8;endSize=8;dashed=1;dashPattern=1 4;strokeWidth=2;fillColor=#fa6800;" parent="1" source="kVfNefTpehhSeJQHV--9-68" edge="1" target="kVfNefTpehhSeJQHV--9-46"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="624.257037037037" y="257.56999999999994" as="sourcePoint" /> + <mxPoint x="624.257037037037" y="482.1700000000001" as="targetPoint" /> + <Array as="points" /> + </mxGeometry> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-68" value="be_client_send_native_msg" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#ffffc0;strokeColor=#ff0000;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=8;align=center;fontColor=#000000;" parent="1" vertex="1"> + <mxGeometry x="500" y="201.2" width="130" height="25" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-74" value="<div style="text-align: center;"><span style="background-color: initial;">for each of the</span></div>queried&nbsp;<span style="background-color: initial; text-align: center;">BE clients</span>" style="verticalLabelPosition=middle;html=1;verticalAlign=middle;strokeWidth=2;shape=mxgraph.lean_mapping.physical_pull;pointerEvents=1;fontFamily=Verdana;fontSize=10;fontColor=default;labelPosition=right;align=left;horizontal=1;" parent="1" vertex="1"> + <mxGeometry x="635" y="487.8299999999999" width="30" height="32.83" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-69" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;fontFamily=Verdana;fontSize=12;fontColor=default;labelBackgroundColor=none;endArrow=none;strokeColor=#C73500;startSize=8;endSize=8;dashed=1;dashPattern=1 4;strokeWidth=2;fillColor=#fa6800;endFill=0;startArrow=open;startFill=0;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="kVfNefTpehhSeJQHV--9-67" target="kVfNefTpehhSeJQHV--9-11" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="740.037037037037" y="312.21000000000004" as="sourcePoint" /> + <mxPoint x="570" y="775.037037037037" as="targetPoint" /> + <Array as="points"> + <mxPoint x="750" y="740" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-81" value="<i style="border-color: var(--border-color); font-family: Verdana; font-size: 10px;">socket connection<br style="border-color: var(--border-color);"></i>BE adapter -&gt; BE client<br style="border-color: var(--border-color); font-family: Verdana; font-size: 10px;"><span style="font-family: Verdana; font-size: 10px;">MGMT_MSG_CODE_GET_TREE</span><br style="border-color: var(--border-color); font-family: Verdana; font-size: 10px;"><i style="border-color: var(--border-color); font-family: Verdana; font-size: 10px;">struct mgmt_msg_get_tree</i>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="kVfNefTpehhSeJQHV--9-69" vertex="1" connectable="0"> + <mxGeometry x="-0.7023" y="-3" relative="1" as="geometry"> + <mxPoint x="93" y="-4" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-87" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;fontFamily=Helvetica;fontSize=8;fontColor=default;" parent="1" source="kVfNefTpehhSeJQHV--9-82" target="kVfNefTpehhSeJQHV--9-85" edge="1"> + <mxGeometry relative="1" as="geometry" /> + </mxCell> + <mxCell id="kVfNefTpehhSeJQHV--9-82" value="fe_client_handle_native_msg" style="rounded=1;whiteSpace=wrap;html=1;arcSize=24;fillColor=#b1ddf0;strokeColor=#10739e;shadow=0;comic=0;labelBackgroundColor=none;fontFamily=Verdana;fontSize=7;fontColor=default;align=center;" parent="1" vertex="1"> + <mxGeometry x="235" y="315.8" width="160" height="35" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-284" value="" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Verdana;fontSize=12;fontColor=default;" parent="1" vertex="1"> + <mxGeometry x="930" y="20" width="130" height="100" as="geometry" /> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-278" value="" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#C73500;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;dashed=1;dashPattern=1 4;strokeWidth=2;fillColor=#fa6800;" parent="1" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="950" y="50" as="sourcePoint" /> + <mxPoint x="1040.02" y="50" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-279" value="<i style="font-size: 10px;">socket&nbsp;</i>async" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-278" vertex="1" connectable="0"> + <mxGeometry x="-0.0463" y="1" relative="1" as="geometry"> + <mxPoint x="-8" y="-9" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-282" style="edgeStyle=orthogonalEdgeStyle;shape=connector;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;strokeColor=#001DBC;fontFamily=Verdana;fontSize=12;fontColor=default;endArrow=open;startSize=8;endSize=8;dashed=1;dashPattern=1 4;strokeWidth=2;fillColor=#0050ef;" parent="1" edge="1"> + <mxGeometry relative="1" as="geometry"> + <mxPoint x="950" y="80" as="sourcePoint" /> + <mxPoint x="1040" y="80" as="targetPoint" /> + <Array as="points"> + <mxPoint x="980" y="79.76999999999998" /> + <mxPoint x="980" y="79.76999999999998" /> + </Array> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-283" value="<span style="font-size: 10px;"><font style="font-size: 10px;">timer/event&nbsp;</font>async<br style="font-size: 10px;"></span>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-282" vertex="1" connectable="0"> + <mxGeometry x="0.2852" y="-1" relative="1" as="geometry"> + <mxPoint x="-28" y="-11" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-287" value="" style="endArrow=classic;html=1;rounded=1;labelBackgroundColor=none;strokeColor=#330000;fontFamily=Verdana;fontSize=12;fontColor=default;startSize=8;endSize=8;shape=connector;endFill=1;" parent="1" edge="1"> + <mxGeometry width="50" height="50" relative="1" as="geometry"> + <mxPoint x="950" y="110" as="sourcePoint" /> + <mxPoint x="1035" y="109.20000000000005" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="nUYlmBzm2YxJIW5L2hvB-288" value="function sync" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=9;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" parent="nUYlmBzm2YxJIW5L2hvB-287" vertex="1" connectable="0"> + <mxGeometry x="-0.26" y="2" relative="1" as="geometry"> + <mxPoint x="6" y="-8" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="eMqbX30VPKpUhST_t5Pw-6" value="" style="endArrow=none;dashed=1;html=1;strokeWidth=2;rounded=0;entryX=0.323;entryY=0.002;entryDx=0;entryDy=0;entryPerimeter=0;fillColor=#f5f5f5;strokeColor=#B3B3B3;" edge="1" parent="1"> + <mxGeometry width="50" height="50" relative="1" as="geometry"> + <mxPoint x="290" y="800" as="sourcePoint" /> + <mxPoint x="290" y="410" as="targetPoint" /> + </mxGeometry> + </mxCell> + <mxCell id="eMqbX30VPKpUhST_t5Pw-7" value="<i><font color="#999999">mgmt_fe_adapter.c</font></i>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" vertex="1" connectable="0" parent="1"> + <mxGeometry x="169.99999999999977" y="570" as="geometry"> + <mxPoint x="29" y="212" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="eMqbX30VPKpUhST_t5Pw-8" value="<i><font color="#999999">mgmt_txn.c</font></i>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" vertex="1" connectable="0" parent="1"> + <mxGeometry x="369.9999999999998" y="570" as="geometry"> + <mxPoint x="29" y="212" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="eMqbX30VPKpUhST_t5Pw-9" value="<i><font color="#999999">mgmt_be_adapter.c</font></i>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];fontSize=10;fontFamily=Verdana;fontColor=default;labelBackgroundColor=none;" vertex="1" connectable="0" parent="1"> + <mxGeometry x="604.9999999999998" y="570" as="geometry"> + <mxPoint x="29" y="212" as="offset" /> + </mxGeometry> + </mxCell> + <mxCell id="eMqbX30VPKpUhST_t5Pw-10" value="z" style="endArrow=none;dashed=1;html=1;strokeWidth=2;rounded=0;entryX=0.323;entryY=0.002;entryDx=0;entryDy=0;entryPerimeter=0;fillColor=#f5f5f5;strokeColor=#B3B3B3;" edge="1" parent="1"> + <mxGeometry width="50" height="50" relative="1" as="geometry"> + <mxPoint x="510" y="800" as="sourcePoint" /> + <mxPoint x="510" y="410" as="targetPoint" /> + </mxGeometry> + </mxCell> + </root> + </mxGraphModel> + </diagram> +</mxfile> diff --git a/doc/figures/cli-oper-state.svg b/doc/figures/cli-oper-state.svg new file mode 100644 index 0000000000..bda7d7be8e --- /dev/null +++ b/doc/figures/cli-oper-state.svg @@ -0,0 +1,3 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="1057" height="807" viewBox="-0.5 -0.5 1057 807" style="background-color: rgb(255, 255, 255);"><defs><filter id="dropShadow"><feGaussianBlur in="SourceAlpha" stdDeviation="1.7" result="blur"/><feOffset in="blur" dx="3" dy="3" result="offsetBlur"/><feFlood flood-color="#3D4574" flood-opacity="0.4" result="offsetColor"/><feComposite in="offsetColor" in2="offsetBlur" operator="in" result="offsetBlur"/><feBlend in="SourceGraphic" in2="offsetBlur"/></filter></defs><g filter="url(#dropShadow)"><rect x="0" y="51.42" width="425" height="312.17" rx="74.92" ry="74.92" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe flex-start; justify-content: unsafe center; width: 423px; height: 1px; padding-top: 58px; margin-left: 1px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; font-weight: bold; white-space: normal; overflow-wrap: normal;"><div style="font-size: 12px;">Frontend CLI (mgmtd)</div></div></div></div></foreignObject><text x="213" y="70" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="12px" text-anchor="middle" font-weight="bold">Frontend CLI (mgmtd)</text></switch></g><rect x="40" y="390" width="730" height="410" rx="98.4" ry="98.4" fill="#dae8fc" stroke="#6c8ebf" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe flex-start; justify-content: unsafe center; width: 728px; height: 1px; padding-top: 397px; margin-left: 41px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; font-weight: bold; white-space: normal; overflow-wrap: normal;"><div style="font-size: 12px;">MGMTD</div></div></div></div></foreignObject><text x="405" y="409" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="12px" text-anchor="middle" font-weight="bold">MGMTD</text></switch></g><path d="M 105 595 L 105 635 L 105 648.63" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 105 653.88 L 101.5 646.88 L 105 648.63 L 108.5 646.88 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 631px; margin-left: 85px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;">xpath</div></div></div></foreignObject><text x="85" y="633" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="8px" text-anchor="middle">xpath</text></switch></g><path d="M 205 601.37 L 205 685 L 205 708.63" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 205 596.12 L 208.5 603.12 L 205 601.37 L 201.5 603.12 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><path d="M 205 713.88 L 201.5 706.88 L 205 708.63 L 208.5 706.88 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 619px; margin-left: 215px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;">txn</div></div></div></foreignObject><text x="215" y="622" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="8px" text-anchor="middle">txn</text></switch></g><path d="M 225 585 L 245 585 L 245 732 L 303.63 732" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 308.88 732 L 301.88 735.5 L 303.63 732 L 301.88 728.5 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 724px; margin-left: 275px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;">clients (bitmask)</div></div></div></foreignObject><text x="275" y="727" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="8px" text-anchor="middle">clients (bitmask)</text></switch></g><rect x="65" y="565" width="160" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 158px; height: 1px; padding-top: 580px; margin-left: 66px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">fe_adapter_handle_get_tree</div></div></div></foreignObject><text x="145" y="582" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">fe_adapter_handle_get_tree</text></switch></g><path d="M 620 462.83 L 620 504.88" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 620 518.88 L 616.5 511.88 L 623.5 511.88 Z M 620 511.88 L 616.5 504.88 L 623.5 504.88 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><path d="M 540 550 L 476.37 550" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 471.12 550 L 478.12 546.5 L 476.37 550 L 478.12 553.5 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><rect x="540" y="520" width="160" height="60" rx="14.4" ry="14.4" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 158px; height: 1px; padding-top: 550px; margin-left: 541px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">be_adapter_handle_get_tree<br />mgmt_txn_notify_tree_data_reply<br />------------------------------------<br />merge tree data<br />when all clients respond or timeout</div></div></div></foreignObject><text x="620" y="552" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">be_adapter_handle_get_tree...</text></switch></g><path d="M 470 730 L 539.88 730" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 553.88 730 L 546.88 733.5 L 546.88 726.5 Z M 546.88 730 L 539.88 733.5 L 539.88 726.5 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><rect x="310" y="715" width="160" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 158px; height: 1px; padding-top: 730px; margin-left: 311px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_txn_send_get_tree_oper</div></div></div></foreignObject><text x="390" y="732" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_txn_send_get_tree_oper</text></switch></g><rect x="555" y="715" width="130" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 128px; height: 1px; padding-top: 730px; margin-left: 556px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_be_send_native</div></div></div></foreignObject><text x="620" y="732" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_be_send_native</text></switch></g><path d="M 390 535 L 390 447.92 Q 390 437.92 380 437.92 L 315 437.92 Q 305 437.92 305 427.92 L 305 345.27" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="2 8" pointer-events="stroke"/><path d="M 310 353.04 L 305 343.04 L 300 353.04" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 495px; margin-left: 385px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><i style="border-color: var(--border-color); font-family: Verdana; font-size: 10px;">socket connection<br style="border-color: var(--border-color);" /></i><font style="font-size: 10px;">FE adapter -> FE client<br style="border-color: var(--border-color); font-family: Verdana;" /></font><span style="font-family: Verdana; font-size: 10px;">MGMT_MSG_CODE_TREE_DATA</span><br style="border-color: var(--border-color); font-family: Verdana; font-size: 10px;" /><i style="border-color: var(--border-color); font-family: Verdana; font-size: 10px;">struct mgmt_msg_tree_data</i></div></div></div></foreignObject><text x="385" y="498" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="8px" text-anchor="middle">socket connection...</text></switch></g><rect x="310" y="535" width="160" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 158px; height: 1px; padding-top: 550px; margin-left: 311px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">txn_get_tree_data_done<br />fe_adapter_send_tree_data</div></div></div></foreignObject><text x="390" y="552" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">txn_get_tree_data_done...</text></switch></g><path d="M 305 246.8 L 305 226.77 L 305 248.92 L 305 235.33" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 305 230.08 L 308.5 237.08 L 305 235.33 L 301.5 237.08 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><rect x="225" y="246.8" width="160" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 158px; height: 1px; padding-top: 262px; margin-left: 226px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">session->get_tree_notify</div></div></div></foreignObject><text x="305" y="264" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">session->get_tree_notify</text></switch></g><rect x="225" y="108.92" width="160" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 158px; height: 1px; padding-top: 124px; margin-left: 226px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">vty_mgmt_resume_response</div></div></div></foreignObject><text x="305" y="126" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">vty_mgmt_resume_response</text></switch></g><path d="M 305 164.03 L 305 144 L 305 158.92 L 305 145.29" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 305 140.04 L 308.5 147.04 L 305 145.29 L 301.5 147.04 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><rect x="215" y="164.03" width="180" height="64.93" rx="15.58" ry="15.58" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 178px; height: 1px; padding-top: 196px; margin-left: 216px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;"><b>vty_mgmt_get_tree_result_notified<br /></b>displays result<br /></div></div></div></foreignObject><text x="305" y="199" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">vty_mgmt_get_tree_result_notified...</text></switch></g><path d="M 135 655 L 135 635 L 135 601.37" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 135 596.12 L 138.5 603.12 L 135 601.37 L 131.5 603.12 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 621px; margin-left: 165px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;">clients (bitmask)</div></div></div></foreignObject><text x="165" y="623" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="8px" text-anchor="middle">clients (bitmask)</text></switch></g><rect x="65" y="655" width="120" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 118px; height: 1px; padding-top: 670px; margin-left: 66px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_be_interested_clients</div></div></div></foreignObject><text x="125" y="672" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_be_interested_clients</text></switch></g><path d="M 105 276.8 L 105 296.77 L 105 290.77 L 105.01 302.93" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 105.02 309.68 L 100.51 300.69 L 105.01 302.93 L 109.51 300.68 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><rect x="35.02" y="245.8" width="140" height="31" rx="7.44" ry="7.44" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 138px; height: 1px; padding-top: 261px; margin-left: 36px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">vty_mgmt_send_get_tree_req</div></div></div></foreignObject><text x="105" y="264" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">vty_mgmt_send_get_tree_req</text></switch></g><path d="M 105 340.8 L 105 450 Q 105 460 105 466.51 L 105 473.03" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="2 8" pointer-events="stroke"/><path d="M 100 465.26 L 105 475.26 L 110 465.26" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 441px; margin-left: 195px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><i style="font-size: 10px;">socket connection<br style="font-size: 10px;" /></i>FE client -> FE adapter<br />MGMT_MSG_CODE_GET_TREE<br /><i>struct mgmt_msg_get_tree</i></div></div></div></foreignObject><text x="195" y="444" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">socket connection...</text></switch></g><rect x="35.02" y="310.8" width="140" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 138px; height: 1px; padding-top: 326px; margin-left: 36px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_fe_send_get_tree_req</div></div></div></foreignObject><text x="105" y="328" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_fe_send_get_tree_req</text></switch></g><path d="M 145 512.5 L 145 557.13" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 145 563.88 L 140.5 554.88 L 145 557.13 L 149.5 554.88 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 546px; margin-left: 125px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;">xpath</div></div></div></foreignObject><text x="125" y="549" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="8px" text-anchor="middle">xpath</text></switch></g><rect x="65" y="477.5" width="160" height="35" rx="8.4" ry="8.4" fill="#b1ddf0" stroke="#10739e" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 158px; height: 1px; padding-top: 495px; margin-left: 66px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 7px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">fe_adapter_handle_native_msg</div></div></div></foreignObject><text x="145" y="497" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="7px" text-anchor="middle">fe_adapter_handle_native_msg</text></switch></g><path d="M 105 223.28 L 105 243.31 L 105 225.77 L 105 237.93" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 105 244.68 L 100.5 235.68 L 105 237.93 L 109.5 235.68 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><rect x="45.02" y="188.28" width="120" height="35" rx="8.4" ry="8.4" fill="#ffffc0" stroke="rgb(0, 0, 0)" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 118px; height: 1px; padding-top: 206px; margin-left: 46px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">"show mgmt get-data-tree WORD$path [json|xml]"</div></div></div></foreignObject><text x="105" y="208" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">"show mgmt get-data-tree WORD...</text></switch></g><path d="M 105.02 163.92 L 105 183.92 L 105 168.31 L 105 180.41" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 105 187.16 L 100.5 178.16 L 105 180.41 L 109.5 178.16 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><ellipse cx="105.02" cy="123.92" rx="60" ry="40" fill="#b1ddf0" stroke="#10739e" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 118px; height: 1px; padding-top: 124px; margin-left: 46px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 7px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">EVENT: VTYSH_READ</div></div></div></foreignObject><text x="105" y="126" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="7px" text-anchor="middle">EVENT: VTYSH_READ</text></switch></g><path d="M 310 108.92 L 310 20 L 156.63 20" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 149.88 20 L 158.88 15.5 L 156.63 20 L 158.88 24.5 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><path d="M 110.02 40 L 110.02 76.19" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 110.02 82.94 L 105.52 73.94 L 110.02 76.19 L 114.52 73.94 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><rect x="71.28" y="0" width="77.48" height="40" rx="9.6" ry="9.6" fill="#cdeb8b" stroke="#36393d" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 75px; height: 1px; padding-top: 20px; margin-left: 72px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;"><div>VTYSH</div></div></div></div></foreignObject><text x="110" y="22" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="8px" text-anchor="middle">VTYSH</text></switch></g><rect x="105" y="715" width="120" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 118px; height: 1px; padding-top: 730px; margin-left: 106px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_create_txn</div></div></div></foreignObject><text x="165" y="732" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_create_txn</text></switch></g><rect x="330" y="637.83" width="120" height="30" rx="7.2" ry="7.2" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 118px; height: 1px; padding-top: 653px; margin-left: 331px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">mgmt_txn_req_alloc</div></div></div></foreignObject><text x="390" y="655" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">mgmt_txn_req_alloc</text></switch></g><path d="M 390 674.2 L 390 708.63" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 390 668.95 L 393.5 675.95 L 390 674.2 L 386.5 675.95 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><path d="M 390 713.88 L 386.5 706.88 L 390 708.63 L 393.5 706.88 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 686px; margin-left: 425px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;">txn_req<br />MGMTD_TXN_PROC_GETTREE</div></div></div></foreignObject><text x="425" y="689" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="8px" text-anchor="middle">txn_req...</text></switch></g><path d="M 536.96 680.04 C 531.58 676.78 524.78 677.42 520.07 681.64 C 515.37 685.86 513.83 692.7 516.25 698.62 C 518.67 704.53 524.51 708.18 530.73 707.68 C 536.96 707.18 542.17 702.63 543.66 696.4" fill="none" stroke="rgb(0, 0, 0)" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><path d="M 542.21 696.4 L 544.38 692.68 L 545 697.14 Z" fill="rgb(255, 255, 255)" stroke="rgb(0, 0, 0)" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe flex-start; width: 1px; height: 1px; padding-top: 693px; margin-left: 547px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: left;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><div style="text-align: center;"><span style="background-color: initial;">for each of the clients</span></div><div style="text-align: center;"><span style="background-color: initial;">in bitmask</span></div></div></div></div></foreignObject><text x="547" y="696" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px">for ea...</text></switch></g><rect x="650" y="176.42" width="130" height="25" rx="6" ry="6" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 128px; height: 1px; padding-top: 189px; margin-left: 651px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">be_client_send_native_msg</div></div></div></foreignObject><text x="715" y="191" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">be_client_send_native_msg</text></switch></g><rect x="540" y="427.83" width="160" height="35" rx="8.4" ry="8.4" fill="#b1ddf0" stroke="#10739e" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 158px; height: 1px; padding-top: 445px; margin-left: 541px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 7px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">be_adapter_handle_native_msg</div></div></div></foreignObject><text x="620" y="447" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="7px" text-anchor="middle">be_adapter_handle_native_msg</text></switch></g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 351px; margin-left: 541px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><i style="font-size: 10px;">socket connection<br style="font-size: 10px;" /></i>BE client -> BE adapter<br />MGMT_MSG_CODE_TREE_DATA<br /><i>struct mgmt_msg_tree_data</i></div></div></div></foreignObject><text x="541" y="354" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">socket connection...</text></switch></g><rect x="660" y="186.42" width="130" height="25" rx="6" ry="6" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 128px; height: 1px; padding-top: 199px; margin-left: 661px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">be_client_send_native_msg</div></div></div></foreignObject><text x="725" y="201" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">be_client_send_native_msg</text></switch></g><rect x="470" y="92.02" width="380" height="207.57" rx="49.82" ry="49.82" fill="#e6ffcc" stroke="#36393d" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe flex-start; justify-content: unsafe center; width: 378px; height: 1px; padding-top: 99px; margin-left: 471px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 12px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; font-weight: bold; white-space: normal; overflow-wrap: normal;"><div style="font-size: 12px;">Backend Client (ospfd, staticd, ...)</div></div></div></div></foreignObject><text x="660" y="111" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="12px" text-anchor="middle" font-weight="bold">Backend Client (ospfd, staticd, ...)</text></switch></g><path d="M 710 184.83 L 710 176.23 L 710 152.5" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 710 190.08 L 706.5 183.08 L 710 184.83 L 713.5 183.08 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><path d="M 710 147.25 L 713.5 154.25 L 710 152.5 L 706.5 154.25 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 168px; margin-left: 780px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; font-style: italic; white-space: nowrap;"><span style="font-style: normal;">(1) build oper state tree<br /></span>struct mgmt_msg_tree_data</div></div></div></foreignObject><text x="780" y="171" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="10px" text-anchor="middle" font-style="italic">(1) build oper state tree...</text></switch></g><path d="M 680 203.69 L 660 203.69 L 626.37 203.69" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 621.12 203.69 L 628.12 200.19 L 626.37 203.69 L 628.12 207.19 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe flex-end; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 201px; margin-left: 650px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;">(2)</div></div></div></foreignObject><text x="650" y="201" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="11px" text-anchor="middle">(2)</text></switch></g><rect x="680" y="191.2" width="140" height="25" rx="6" ry="6" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 138px; height: 1px; padding-top: 204px; margin-left: 681px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">be_client_handle_get_tree</div></div></div></foreignObject><text x="750" y="206" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">be_client_handle_get_tree</text></switch></g><rect x="680" y="121.13" width="110" height="25" rx="6" ry="6" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 108px; height: 1px; padding-top: 134px; margin-left: 681px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">nb_oper_data_iterate</div></div></div></foreignObject><text x="735" y="136" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">nb_oper_data_iterate</text></switch></g><path d="M 750 241.8 L 750 228.62 L 750 222.57" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 750 217.32 L 753.5 224.32 L 750 222.57 L 746.5 224.32 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><rect x="660" y="241.8" width="160" height="35" rx="8.4" ry="8.4" fill="#b1ddf0" stroke="#10739e" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 158px; height: 1px; padding-top: 259px; margin-left: 661px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 7px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">be_client_handle_native_msg</div></div></div></foreignObject><text x="740" y="261" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="7px" text-anchor="middle">be_client_handle_native_msg</text></switch></g><path d="M 555 216.2 L 555 312 Q 555 322 565 322 L 610 322 Q 620 322 620 332 L 620 423.36" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="2 8" pointer-events="stroke"/><path d="M 615 415.59 L 620 425.59 L 625 415.59" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><rect x="490" y="191.2" width="130" height="25" rx="6" ry="6" fill="#ffffc0" stroke="#ff0000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 128px; height: 1px; padding-top: 204px; margin-left: 491px;"><div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 8px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">be_client_send_native_msg</div></div></div></foreignObject><text x="555" y="206" fill="#000000" font-family="Verdana" font-size="8px" text-anchor="middle">be_client_send_native_msg</text></switch></g><path d="M 646.96 480.25 C 641.58 476.68 634.78 477.38 630.07 482 C 625.37 486.62 623.83 494.11 626.25 500.58 C 628.67 507.05 634.51 511.05 640.73 510.5 C 646.96 509.95 652.17 504.97 653.66 498.16" fill="none" stroke="rgb(0, 0, 0)" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><path d="M 652.21 498.16 L 654.38 494.08 L 655 498.97 Z" fill="rgb(255, 255, 255)" stroke="rgb(0, 0, 0)" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe flex-start; width: 1px; height: 1px; padding-top: 494px; margin-left: 657px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: left;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><div style="text-align: center;"><span style="background-color: initial;">for each of the</span></div>queried <span style="background-color: initial; text-align: center;">BE clients</span></div></div></div></foreignObject><text x="657" y="497" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px">for ea...</text></switch></g><path d="M 740 281.27 L 740 720 Q 740 730 730 730 L 685 730" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="2 8" pointer-events="stroke"/><path d="M 745 289.04 L 740 279.04 L 735 289.04" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 349px; margin-left: 830px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><i style="border-color: var(--border-color); font-family: Verdana; font-size: 10px;">socket connection<br style="border-color: var(--border-color);" /></i>BE adapter -> BE client<br style="border-color: var(--border-color); font-family: Verdana; font-size: 10px;" /><span style="font-family: Verdana; font-size: 10px;">MGMT_MSG_CODE_GET_TREE</span><br style="border-color: var(--border-color); font-family: Verdana; font-size: 10px;" /><i style="border-color: var(--border-color); font-family: Verdana; font-size: 10px;">struct mgmt_msg_get_tree</i></div></div></div></foreignObject><text x="830" y="352" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">socket connection...</text></switch></g><path d="M 305 305.8 L 305 285.77 L 305 296.77 L 305 283.17" fill="none" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 305 277.92 L 308.5 284.92 L 305 283.17 L 301.5 284.92 Z" fill="rgb(0, 0, 0)" stroke="rgb(0, 0, 0)" stroke-miterlimit="10" pointer-events="all"/><rect x="225" y="305.8" width="160" height="35" rx="8.4" ry="8.4" fill="#b1ddf0" stroke="#10739e" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 158px; height: 1px; padding-top: 323px; margin-left: 226px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 7px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: normal; overflow-wrap: normal;">fe_client_handle_native_msg</div></div></div></foreignObject><text x="305" y="325" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="7px" text-anchor="middle">fe_client_handle_native_msg</text></switch></g><rect x="920" y="10" width="130" height="100" fill="rgb(255, 255, 255)" stroke="rgb(0, 0, 0)" pointer-events="all"/><path d="M 940 40 L 1025.55 40" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="2 8" pointer-events="stroke"/><path d="M 1017.78 45 L 1027.78 40 L 1017.78 35" fill="none" stroke="#c73500" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 30px; margin-left: 975px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><i style="font-size: 10px;">socket </i>async</div></div></div></foreignObject><text x="975" y="33" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">socket async</text></switch></g><path d="M 940 70 L 960 70 Q 970 70 980 70 L 1025.53 70" fill="none" stroke="#001dbc" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="2 8" pointer-events="stroke"/><path d="M 1017.76 75 L 1027.76 70 L 1017.76 65" fill="none" stroke="#001dbc" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 60px; margin-left: 970px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><span style="font-size: 10px;"><font style="font-size: 10px;">timer/event </font>async<br style="font-size: 10px;" /></span></div></div></div></foreignObject><text x="970" y="63" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">timer/event async </text></switch></g><path d="M 940 100 L 1017.13 99.27" fill="none" stroke="#330000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 1023.88 99.21 L 1014.92 103.8 L 1017.13 99.27 L 1014.84 94.8 Z" fill="#330000" stroke="#330000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 90px; margin-left: 978px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 9px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;">function sync</div></div></div></foreignObject><text x="978" y="93" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="9px" text-anchor="middle">function sync</text></switch></g><path d="M 280 790 L 280 400" fill="none" stroke="#b3b3b3" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="6 6" pointer-events="stroke"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 772px; margin-left: 189px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><i><font color="#999999">mgmt_fe_adapter.c</font></i></div></div></div></foreignObject><text x="189" y="775" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">mgmt_fe_adapter.c</text></switch></g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 772px; margin-left: 389px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><i><font color="#999999">mgmt_txn.c</font></i></div></div></div></foreignObject><text x="389" y="775" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">mgmt_txn.c</text></switch></g><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 772px; margin-left: 624px;"><div data-drawio-colors="color: rgb(0, 0, 0); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 10px; font-family: Verdana; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; white-space: nowrap;"><i><font color="#999999">mgmt_be_adapter.c</font></i></div></div></div></foreignObject><text x="624" y="775" fill="rgb(0, 0, 0)" font-family="Verdana" font-size="10px" text-anchor="middle">mgmt_be_adapter.c</text></switch></g><path d="M 500 790 L 500 400" fill="none" stroke="#b3b3b3" stroke-width="2" stroke-miterlimit="10" stroke-dasharray="6 6" pointer-events="stroke"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 595px; margin-left: 500px;"><div data-drawio-colors="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); " style="box-sizing: border-box; font-size: 0px; text-align: center;"><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; background-color: rgb(255, 255, 255); white-space: nowrap;">z</div></div></div></foreignObject><text x="500" y="599" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="11px" text-anchor="middle">z</text></switch></g></g><switch><g requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"/><a transform="translate(0,-5)" xlink:href="https://www.drawio.com/doc/faq/svg-export-text-problems" target="_blank"><text text-anchor="middle" font-size="10px" x="50%" y="100%">Text is not SVG - cannot display</text></a></switch></svg> \ No newline at end of file diff --git a/doc/manpages/frr-zebra.rst b/doc/manpages/frr-zebra.rst index 722b011ecd..6cc46b806d 100644 --- a/doc/manpages/frr-zebra.rst +++ b/doc/manpages/frr-zebra.rst @@ -45,6 +45,11 @@ ROUTES When the program terminates, do not flush routes installed by zebra from the kernel. +.. option:: -R, --routing-table <tableno> + + Specify which kernel routing table *Zebra* should communicate with. + If this option is not specified the default table (RT_TABLE_MAIN) is used. + FILES ===== diff --git a/doc/requirements.txt b/doc/requirements.txt deleted file mode 100644 index debc7f1889..0000000000 --- a/doc/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -sphinx==4.0.2 diff --git a/doc/subdir.am b/doc/subdir.am index a1297a4f81..2795326d9b 100644 --- a/doc/subdir.am +++ b/doc/subdir.am @@ -99,6 +99,10 @@ EXTRA_DIST += \ doc/mpls/ospfd.conf \ doc/mpls/cli_summary.txt \ doc/mpls/opaque_lsa.txt \ + doc/figures/cli-change-client.drawio \ + doc/figures/cli-change-client.svg \ + doc/figures/cli-change-mgmtd.drawio \ + doc/figures/cli-change-mgmtd.svg \ doc/figures/cligraph.png \ doc/figures/cligraph.svg \ doc/figures/fig-normal-processing.dia \ diff --git a/doc/user/.readthedocs.yaml b/doc/user/.readthedocs.yaml new file mode 100644 index 0000000000..ba5698c1d5 --- /dev/null +++ b/doc/user/.readthedocs.yaml @@ -0,0 +1,15 @@ +# Required +version: 2 + +# Set the version of Python and other tools you might need +build: + os: ubuntu-22.04 + tools: + python: "3.11" + +python: + install: + - requirements: doc/user/requirements.txt +# Build documentation in the docs/ directory with Sphinx +sphinx: + configuration: doc/user/conf.py diff --git a/doc/user/basic.rst b/doc/user/basic.rst index 337cfff937..24978b2f79 100644 --- a/doc/user/basic.rst +++ b/doc/user/basic.rst @@ -92,9 +92,6 @@ Basic Config Commands of some routine in FRR mistakenly blocking/hogging the processing loop and should be reported as a FRR bug. - The default limit is 5 seconds (i.e. 5000), but this can be changed by the - deprecated ``--enable-time-check=...`` compile-time option. - This command has no effect if :clicmd:`service cputime-stats` is disabled. .. clicmd:: service walltime-warning (1-4294967295) @@ -106,9 +103,6 @@ Basic Config Commands provide an immediate sign that FRR is not operating correctly due to externally caused starvation.) - The default limit is 5 seconds as above, including the same deprecated - ``--enable-time-check=...`` compile-time option. - .. clicmd:: log trap LEVEL These commands are deprecated and are present only for historical @@ -679,21 +673,20 @@ Terminal Mode Commands .. _common-show-commands: -.. clicmd:: show thread cpu [r|w|t|e|x] +.. clicmd:: show event cpu [r|w|t|e|x] This command displays system run statistics for all the different event types. If no options is specified all different run types are displayed together. Additionally you can ask to look at (r)ead, (w)rite, (t)imer, - (e)vent and e(x)ecute thread event types. If you have compiled with - disable-cpu-time then this command will not show up. + (e)vent and e(x)ecute thread event types. -.. clicmd:: show thread poll +.. clicmd:: show event poll This command displays FRR's poll data. It allows a glimpse into how we are setting each individual fd for the poll command at that point in time. -.. clicmd:: show thread timers +.. clicmd:: show event timers This command displays FRR's timer data for timers that will pop in the future. diff --git a/doc/user/bfd.rst b/doc/user/bfd.rst index 776726f193..6c57822510 100644 --- a/doc/user/bfd.rst +++ b/doc/user/bfd.rst @@ -225,12 +225,6 @@ BFD peers and profiles share the same BFD session configuration commands. BFD Peer Specific Commands -------------------------- -.. clicmd:: label WORD - - Labels a peer with the provided word. This word can be referenced - later on other daemons to refer to a specific peer. - - .. clicmd:: profile BFDPROF Configure peer to use the profile configurations. @@ -443,7 +437,6 @@ Here is an example of BFD configuration: bfd peer 192.168.0.1 - label home-peer no shutdown ! ! @@ -457,7 +450,7 @@ Here is an example of BFD configuration: ! Peers can be identified by its address (use ``multihop`` when you need -to specify a multi hop peer) or can be specified manually by a label. +to specify a multi hop peer). Here are the available peer configurations: @@ -500,7 +493,6 @@ Here are the available peer configurations: ! configure a peer with every option possible peer 192.168.0.4 - label peer-label detect-multiplier 50 receive-interval 60000 transmit-interval 3000 @@ -548,7 +540,6 @@ You can inspect the current BFD peer status with the following commands: Echo receive interval: 50ms peer 192.168.1.1 - label: router3-peer ID: 2 Remote ID: 2 Status: up @@ -571,7 +562,6 @@ You can inspect the current BFD peer status with the following commands: frr# show bfd peer 192.168.1.1 BFD Peer: peer 192.168.1.1 - label: router3-peer ID: 2 Remote ID: 2 Status: up diff --git a/doc/user/bgp.rst b/doc/user/bgp.rst index f045ca239e..050141203b 100644 --- a/doc/user/bgp.rst +++ b/doc/user/bgp.rst @@ -86,6 +86,15 @@ be specified (:ref:`common-invocation-options`). be done to see if this is helping or not at the scale you are running at. +.. option:: --v6-with-v4-nexthops + + Allow BGP to peer in the V6 afi, when the interface only has v4 addresses. + This allows bgp to install the v6 routes with a v6 nexthop that has the + v4 address encoded in the nexthop. Zebra's equivalent option currently + overrides the bgp setting. This setting is only really usable when + the operator has turned off communication to zebra and is running bgpd + as a complete standalone process. + LABEL MANAGER ------------- @@ -452,10 +461,19 @@ Administrative Distance Metrics Sets the administrative distance for a particular route. + If the system has a static route configured from the kernel, it has a + distance of 0. In some cases, it might be useful to override the route + from the FRR. E.g.: Kernel has a statically configured default route, + and you received another default route from the BGP and want to install + it to be preferred over the static route. In such a case, you MUST set + a higher distance from the kernel. + + .. seealso:: :ref:`administrative-distance` + .. _bgp-requires-policy: Require policy on EBGP -------------------------------- +---------------------- .. clicmd:: bgp ebgp-requires-policy @@ -476,8 +494,8 @@ Require policy on EBGP exit1# show bgp summary - IPv4 Unicast Summary (VRF default): - BGP router identifier 10.10.10.1, local AS number 65001 vrf-id 0 + IPv4 Unicast Summary: + BGP router identifier 10.10.10.1, local AS number 65001 VRF default vrf-id 0 BGP table version 4 RIB entries 7, using 1344 bytes of memory Peers 2, using 43 KiB of memory @@ -509,6 +527,27 @@ Reject routes with AS_SET or AS_CONFED_SET types This command enables rejection of incoming and outgoing routes having AS_SET or AS_CONFED_SET type. +Enforce first AS +---------------- + +.. clicmd:: bgp enforce-first-as + + To configure a router to deny an update received from an external BGP (eBGP) + peer that does not list its autonomous system number at the beginning of + the `AS_PATH` in the incoming update, use the ``bgp enforce-first-as`` command + in router configuration mode. + + In order to exclude an arbitrary neighbor from this enforcement, use the + command ``no neighbor NAME enforce-first-as``. And vice-versa if a global + enforcement is disabled, you can override this behavior per neighbor too. + + Default: enabled. + +.. note:: + + If you have a peering to RS (Route-Server), most likely you MUST disable the + first AS enforcement. + Suppress duplicate updates -------------------------- @@ -831,7 +870,10 @@ The following functionality is provided by graceful restart: 1. The feature allows the restarting router to indicate to the helping peer the routes it can preserve in its forwarding plane during control plane restart by sending graceful restart capability in the OPEN message sent during - session establishment. + session establishment. Graceful restart notification flag and/or restart + time can also be changed during the dynamic BGP capabilities. If using + dynamic capabilities, no session reset is required, thus it's very useful + to increase restart time before doing a software upgrade or so. 2. The feature allows helping router to advertise to all other peers the routes received from the restarting router which are preserved in the forwarding plane of the restarting router during control plane restart. @@ -1288,10 +1330,31 @@ section for the specific AF to redistribute into. Protocol availability for redistribution is determined by BGP AF; for example, you cannot redistribute OSPFv3 into ``address-family ipv4 unicast`` as OSPFv3 supports IPv6. -.. clicmd:: redistribute <babel|connected|eigrp|isis|kernel|openfabric|ospf|ospf6|rip|ripng|sharp|static|table> [metric (0-4294967295)] [route-map WORD] +.. clicmd:: redistribute <babel|connected|eigrp|isis|kernel|openfabric|ospf|ospf6|rip|ripng|sharp|static> [metric (0-4294967295)] [route-map WORD] Redistribute routes from other protocols into BGP. +.. clicmd:: redistribute <table|table-direct> (1-65535)] [metric (0-4294967295)] [route-map WORD] + + Redistribute routes from a routing table ID into BGP. There are two + techniques for redistribution: + + - Standard Table Redistribution ``table (1-65535)``: + - Routes from the specified routing table ID are imported into the + default routing table using the ``ip import-table ID`` command. + - These routes are identified by the protocol type "T[ID]" when + displayed with ``show (ip|ipv6) route``. + - The ``redistribute table ID`` command then integrates these routes + into BGP. + + - Direct Table Redistribution ``table-direct (1-65535)``: + - This method directly imports routes from the designated routing table + ID into BGP, omitting the step of adding to the default routing table. + - This method is especially relevant when the specified table ID is + checked against routing by appending the appropriate `ip rules`. + +Redistribute routes from a routing table number into BGP. + .. clicmd:: redistribute vnc-direct Redistribute VNC direct (not via zebra) routes to BGP process. @@ -1411,6 +1474,23 @@ Defining Peers peers ASN is the same as mine as specified under the :clicmd:`router bgp ASN` command the connection will be denied. +.. clicmd:: neighbor PEER oad + + Mark a peer belonging to the One Administrative Domain. + + Some networks span more than one autonomous system and require more + flexibility in the propagation of path attributes.It is worth noting that + these multi-AS networks have a common or single administrative entity. + These networks are said to belong to One Administrative Domain (OAD). + It is desirable to carry IBGP-only attributes across EBGP peerings when + the peers belong to an OAD. + + Enabling this peering sub-type will allow the propagation of non-transitive + attributes across EBGP peerings (e.g. local-preference). Make sure to + turn this peering type on for all peers in the OAD. + + Disabled by default. + .. clicmd:: bgp listen range <A.B.C.D/M|X:X::X:X/M> peer-group PGNAME Accept connections from any peers in the specified prefix. Configuration @@ -1483,6 +1563,16 @@ Configuring Peers value is carried encoded as uint32. To enable backward compatibility we need to disable IEEE floating-point encoding option per-peer. +.. clicmd:: neighbor PEER enforce-first-as + + Discard updates received from the specified (eBGP) peer if the AS_PATH + attribute does not contain the PEER's ASN as the first AS_PATH segment. + + You can enable or disable this enforcement globally too using + ``bgp enforce-first-as`` command. + + Default: enabled. + .. clicmd:: neighbor PEER extended-optional-parameters Force Extended Optional Parameters Length format to be used for OPEN messages. @@ -1669,6 +1759,10 @@ Configuring Peers Configure BGP to send best known paths to neighbor in order to preserve multi path capabilities inside a network. +.. clicmd:: neighbor <A.B.C.D|X:X::X:X|WORD> addpath-tx-best-selected (1-6) + + Configure BGP to calculate and send N best known paths to the neighbor. + .. clicmd:: neighbor <A.B.C.D|X:X::X:X|WORD> disable-addpath-rx Do not accept additional paths from this neighbor. @@ -1688,6 +1782,16 @@ Configuring Peers turning on this command will allow BGP to install v4 routes with v6 nexthops if you do not have v4 configured on interfaces. +.. clicmd:: neighbor PEER capability dynamic + + Allow BGP to negotiate the Dynamic Capability with its peers. + + Dynamic Capability defines a new BGP message (CAPABILITY) that can be used + to set/unset BGP capabilities without bringing down a BGP session. + + This includes changing graceful-restart (LLGR also) timers, + enabling/disabling add-path, and other supported capabilities. + .. clicmd:: neighbor <A.B.C.D|X:X::X:X|WORD> accept-own Enable handling of self-originated VPN routes containing ``accept-own`` community. @@ -1729,6 +1833,12 @@ Configuring Peers and will not be displayed as part of a `show run`. The no form of the command turns off this ability. +.. clicmd:: bgp default-originate timer (0-3600) + + Set the period to rerun the default-originate route-map scanner process. The + default is 5 seconds. With a full routing table, it might be useful to increase + this setting to avoid scanning the whole BGP table aggressively. + .. clicmd:: bgp default ipv4-unicast This command allows the user to specify that the IPv4 Unicast address @@ -1803,6 +1913,28 @@ Configuring Peers outputs. It's easier to troubleshoot if you have a number of BGP peers and a number of routes to check. +.. clicmd:: bgp default software-version-capability + + This command enables software version capability advertisement by default + for all the neighbors. + + For ``datacenter`` profile, this is enabled by default. + + .. code-block:: frr + + IPv4 Unicast Summary: + BGP router identifier 10.0.0.6, local AS number 65001 VRF default vrf-id 0 + BGP table version 12 + RIB entries 23, using 4600 bytes of memory + Peers 3, using 2174 KiB of memory + + Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc + 10.0.0.4 4 65001 20 22 12 0 0 00:00:11 5 12 FRRouting/8.5.1 + 10.0.0.5 4 65001 21 22 12 0 0 00:00:11 5 12 FRRouting/9.0 + 192.168.67.7 4 65001 27 31 12 0 0 00:00:23 2 10 FRRouting/9.1-dev-MyOwnFRRVersion-g3c8c08dcd9 + + Total number of neighbors 3 + .. clicmd:: neighbor PEER advertisement-interval (0-600) Setup the minimum route advertisement interval(mrai) for the @@ -2095,10 +2227,31 @@ Using AS Path in Route Map Prepend the existing last AS number (the leftmost ASN) to the AS_PATH. The no form of this command removes this set operation from the route-map. -.. clicmd:: set as-path replace <any|ASN> +.. clicmd:: set as-path replace <any|ASN> [<ASN>] + + Replace a specific AS number to local AS number or a configured AS number. + ``any`` replaces each AS number in the AS-PATH with either the local AS + number or the configured AS number. + +.. clicmd:: set as-path replace as-path-access-list WORD [<ASN>] + + Replace some AS numbers from the AS_PATH of the BGP path's NLRI. Substituted + AS numbers are conformant with the regex defined in as-path access-list + WORD. Changed AS numbers are replaced either by the local AS number or the + configured AS number. + The no form of this command removes this set operation from the route-map. + +.. clicmd:: set as-path exclude all + + Remove all AS numbers from the AS_PATH of the BGP path's NLRI. The no form of + this command removes this set operation from the route-map. + +.. clicmd:: set as-path exclude as-path-access-list WORD + + Remove some AS numbers from the AS_PATH of the BGP path's NLRI. Removed AS + numbers are conformant with the regex defined in as-path access-list WORD. + The no form of this command removes this set operation from the route-map. - Replace a specific AS number to local AS number. ``any`` replaces each - AS number in the AS-PATH with the local AS number. .. _bgp-communities-attribute: @@ -2605,6 +2758,10 @@ BGP Extended Communities in Route Map This command sets Site of Origin value. +.. clicmd:: set extcomumnity color EXTCOMMUNITY + + This command sets colors values. + .. clicmd:: set extcommunity bandwidth <(1-25600) | cumulative | num-multipaths> [non-transitive] This command sets the BGP link-bandwidth extended community for the prefix @@ -2891,7 +3048,33 @@ address-family: Specifies the route-target list to be attached to a route (export) or the route-target list to match against (import) when exporting/importing between - the current unicast VRF and VPN. + the current unicast VRF and VPN. The `rt vpn export RTLIST` command is not + mandatory and can be replaced or completed by the `set extcommunity rt` + command in the route-map attached with the `route-map vpn export`. The below + configuration illustrates how the route target is selected based on the + prefixes, and not solely on vrf criterium: + + .. code-block:: frr + + access-list acl1 permit 192.0.2.0/24 + access-list acl2 permit 192.0.3.0/24 + route-map rmap permit 10 + match address acl1 + set extcommunity rt 65001:10 + ! + route-map rmap permit 20 + match address acl1 + set extcommunity rt 65001:20 + ! + router bgp 65001 vrf vrf1 + ! + address-family ipv4 unicast + rd vpn export 65001:1 + import vpn + export vpn + rt vpn import 65001:1 + route-map vpn export rmap + The RTLIST is a space-separated list of route-targets, which are BGP extended community values as described in @@ -2967,6 +3150,14 @@ by issuing the following command under the interface configuration context. This configuration will install VPN prefixes originated from an e-bgp session, and with the next-hop directly connected. +.. clicmd:: mpls bgp l3vpn-multi-domain-switching + +Redistribute labeled L3VPN routes from AS to neighboring AS (RFC-4364 option +B, or within the same AS when the iBGP peer uses ``next-hop-self`` to rewrite +the next-hop attribute). The labeled L3VPN routes received on this interface are +re-advertised with local labels and an MPLS table swap entry is set to bind +the local label to the received label. + .. _bgp-l3vpn-srv6: L3VPN SRv6 @@ -3223,6 +3414,77 @@ Example configuration: exit-address-family ! +.. _bgp-evpn-mac-vrf-site-of-origin: + +EVPN MAC-VRF Site-of-Origin +^^^^^^^^^^^^^^^^^^^^^^^^^^^ +In some EVPN deployments it is useful to associate a logical VTEP's Layer 2 +domain (MAC-VRF) with a Site-of-Origin "site" identifier. This provides a +BGP topology-independent means of marking and import-filtering EVPN routes +originated from a particular L2 domain. One situation where this is valuable +is when deploying EVPN using anycast VTEPs, i.e. Active/Active MLAG, as it +can be used to avoid ownership conflicts between the two control planes +(EVPN vs MLAG). + +Example Use Case (MLAG Anycast VTEPs): + +During normal operation, an MLAG VTEP will advertise EVPN routes for attached +hosts using a shared anycast IP as the BGP next-hop. It is expected for its +MLAG peer to drop routes originated by the MLAG Peer since they have a Martian +(self) next-hop. However, prior to the anycast IP being assigned to the local +system, the anycast BGP next-hop will not be considered a Martian (self) IP. +This results in a timing window where hosts that are locally attached to the +MLAG pair's L2 domain can be learned both as "local" (via MLAG) or "remote" +(via an EVPN route with a non-local next-hop). This can trigger erroneous MAC +Mobility events, as the host "moves" between one MLAG Peer's Unique VTEP-IP +and the shared anycast VTEP-IP, which causes unnecessary control plane and +data plane events to propagate throughout the EVPN domain. +By associating the MAC-VRF of both MLAG VTEPs with the same site identifier, +EVPN routes originated by one MLAG VTEP will ignored by its MLAG peer, ensuring +that only the MLAG control plane attempts to take ownership of local hosts. + +The EVPN MAC-VRF Site-of-Origin feature works by influencing two behaviors: + +1. All EVPN routes originating from the local MAC-VRF will have a + Site-of-Origin extended community added to the route, matching the + configured value. +2. EVPN routes will be subjected to a "self SoO" check during MAC-VRF + or IP-VRF import processing. If the EVPN route is found to carry a + Site-of-Origin extended community whose value matches the locally + configured MAC-VRF Site-of-Origin, the route will be maintained in + the global EVPN RIB ("show bgp l2vpn evpn route") but will not be + imported into the corresponding MAC-VRF ("show bgp vni") or IP-VRF + ("show bgp [vrf <vrfname>] [ipv4 | ipv6 [unicast]]"). + +The import filtering described in item (2) is constrained just to Type-2 +(MAC-IP) and Type-3 (IMET) EVPN routes. + +The EVPN MAC-VRF Site-of-Origin can be configured using a single CLI command +under ``address-family l2vpn evpn`` of the EVPN underlay BGP instance. + +.. clicmd:: [no] mac-vrf soo <site-of-origin-string> + +Example configuration: + +.. code-block:: frr + + router bgp 100 + neighbor 192.168.0.1 remote-as 101 + ! + address-family ipv4 l2vpn evpn + neighbor 192.168.0.1 activate + advertise-all-vni + mac-vrf soo 100.64.0.0:777 + exit-address-family + +This configuration ensures: + +1. EVPN routes originated from a local L2VNI will have a Site-of-Origin + extended community with the value ``100.64.0.0:777`` +2. Received EVPN routes carrying a Site-of-Origin extended community with the + value ``100.64.0.0:777`` will not be imported into a local MAC-VRF (L2VNI) + or IP-VRF (L3VNI). + .. _bgp-evpn-mh: EVPN Multihoming @@ -3641,12 +3903,20 @@ Debugging information on BGP events such as peer connection / disconnection, session establishment / teardown, and capability negotiation. -.. clicmd:: debug bgp updates +.. clicmd:: debug bgp updates [detail] Enable or disable debugging for BGP updates. This provides information on BGP UPDATE messages transmitted and received between local and remote instances. + If ``detail`` is specified, the output will include the full BGP UPDATE with + detailed information such as attribute length, withdraw length, and more. + +.. clicmd:: debug bgp updates <in|out> [<A.B.C.D|X:X::X:X|WORD> [prefix-list WORD]] + + Enable or disable debugging for BGP updates. Optionally, you can specify + a prefix-list to filter the updates for an arbitrary neighbor. + .. clicmd:: debug bgp keepalives Enable or disable debugging for BGP keepalives. This provides information on @@ -3747,6 +4017,26 @@ The following are available in the top level *enable* mode: Clear BGP message statistics for a specified peer or for all peers, optionally filtered by activated address-family and sub-address-family. +.. clicmd:: clear bgp [ipv4|ipv6] [unicast] PEER|\* capabilities + + Clear specific BGP capabilities for a specified peer or for all peers. This + includes such capabilities like FQDN capability, that can't be controlled by + any other configuration knob. + + For example, if you want to change the FQDN, you MUST reset the BGP session + in order to send a new FQDN capability to the peer. This command allows you + to resend FQDN capability without resetting the session. + + .. code-block:: frr + + hostname bgp-new.example.com + clear bgp 10.10.10.1 capabilities + +.. note:: + + Changing the hostname is possible only when connected to the specific daemon. + If you change the hostname via ``vtysh``, it won't be changed. + The following are available in the ``router bgp`` mode: .. clicmd:: write-quanta (1-64) @@ -3870,8 +4160,8 @@ structure is extended with :clicmd:`show bgp [afi] [safi]`. exit1# show ip bgp summary wide - IPv4 Unicast Summary (VRF default): - BGP router identifier 192.168.100.1, local AS number 65534 vrf-id 0 + IPv4 Unicast Summary: + BGP router identifier 192.168.100.1, local AS number 65534 VRF default vrf-id 0 BGP table version 3 RIB entries 5, using 920 bytes of memory Peers 1, using 27 KiB of memory @@ -3882,6 +4172,12 @@ structure is extended with :clicmd:`show bgp [afi] [safi]`. Total number of neighbors 1 exit1# +If PfxRcd and/or PfxSnt is shown as ``(Policy)``, that means that the EBGP +default policy is turned on, but you don't have any filters applied for +incoming/outgoing directions. + +.. seealso:: :ref:`bgp-requires-policy` + .. clicmd:: show bgp [afi] [safi] [all] [wide|json] .. clicmd:: show bgp vrfs [<VRFNAME$vrf_name>] [json] diff --git a/doc/user/bmp.rst b/doc/user/bmp.rst index 1983995c1f..0f46832059 100644 --- a/doc/user/bmp.rst +++ b/doc/user/bmp.rst @@ -36,8 +36,8 @@ The `BMP` implementation in FRR has the following properties: successfully. OPEN messages for failed sessions cannot currently be mirrored. -- **route monitoring** is available for IPv4 and IPv6 AFIs, unicast and - multicast SAFIs. Other SAFIs (VPN, Labeled-Unicast, Flowspec, etc.) are not +- **route monitoring** is available for IPv4 and IPv6 AFIs, unicast, multicast, + EVPN and VPN SAFIs. Other SAFIs (VPN, Labeled-Unicast, Flowspec, etc.) are not currently supported. - monitoring peers that have BGP **add-path** enabled on the session will @@ -146,10 +146,10 @@ associated with a particular ``bmp targets``: Send BMP Statistics (counter) messages at the specified interval (in milliseconds.) -.. clicmd:: bmp monitor AFI SAFI <pre-policy|post-policy> +.. clicmd:: bmp monitor AFI SAFI <pre-policy|post-policy|loc-rib> Perform Route Monitoring for the specified AFI and SAFI. Only IPv4 and - IPv6 are currently valid for AFI. SAFI valid values are currently + IPv6 are currently valid for AFI. SAFI valid values are currently unicast, multicast, evpn and vpn. Other AFI/SAFI combinations may be added in the future. diff --git a/doc/user/installation.rst b/doc/user/installation.rst index 8e8fb24608..24c6c223e3 100644 --- a/doc/user/installation.rst +++ b/doc/user/installation.rst @@ -351,20 +351,6 @@ options from the list below. Use libpam for PAM support in vtysh. -.. option:: --enable-time-check XXX - - This option is deprecated as it was replaced by the - :clicmd:`service cputime-stats` CLI command, which may be adjusted at - runtime rather than being a compile-time setting. See there for further - detail. - -.. option:: --disable-cpu-time - - This option is deprecated as it was replaced by the - :clicmd:`service cputime-warning NNN` CLI command, which may be adjusted at - runtime rather than being a compile-time setting. See there for further - detail. - .. option:: --enable-pcreposix Turn on the usage of PCRE Posix libs for regex functionality. diff --git a/doc/user/isisd.rst b/doc/user/isisd.rst index 570b8bd182..63c921330b 100644 --- a/doc/user/isisd.rst +++ b/doc/user/isisd.rst @@ -166,6 +166,11 @@ flavors (local LFA, Remote LFA and TI-LFA). Configure a prefix-list to select eligible PQ nodes for remote LFA backups (valid for all protected interfaces). +.. clicmd:: redistribute <ipv4 | ipv6> table (1-65535) <level-1 | level-2> [metric (0-16777215)|route-map WORD] + + Redistribute routes from a given routing table into the given ISIS + level database. + .. _isis-region: ISIS region @@ -589,6 +594,40 @@ The following command show Flex-Algo information: includes an 'algorithm (128-255)' optional argument. See :ref:`showing-isis-information` and :ref:`isis-segment-routing`. +.. _isis-srv6: + +Segment Routing over IPv6 (SRv6) +================================ + +This feature enables extensions in IS-IS to support Segment Routing over IPv6 +data plane (SRv6) as per RFC 9352. + +.. clicmd:: segment-routing srv6 + + Enable Segment Routing over IPv6 data plane (SRv6). + +.. clicmd:: locator NAME + + Specify the SRv6 locator to use for SRv6. The locator must be configured in + Zebra. Once the locator is configured, IS-IS automatically allocates prefix + SID and adjacency SIDs, creates local SID entries in the data plane, and + advertises them in the IGP domain. + +.. clicmd:: interface NAME + + Specify the dummy interface used to install SRv6 SIDs in the Linux data plane. + The interface must be created manually. By default, the interface is 'sr0'. + The interface can be created using the iproute2 utility: + + .. code-block:: bash + + ip link add sr0 type dummy + ip link set sr0 up + +.. clicmd:: show isis segment-routing srv6 node + + Show detailed information about all learned SRv6 Nodes. + Debugging ISIS ============== @@ -769,6 +808,33 @@ A Segment Routing configuration, with IPv4, IPv6, SRGB and MSD configuration. segment-routing prefix 2001:db8:1000::1/128 index 101 explicit-null ! +An SRv6 configuration: + +.. code-block:: frr + + hostname HOSTNAME + password PASSWORD + log file /var/log/isisd.log + ! + ! + interface eth0 + ipv6 router isis FOO + ip router isis FOO + isis hello-interval 5 + ! + interface eth1 + ip router isis FOO + ! + ! + router isis FOO + net 49.0001.1111.1111.1111.00 + is-type level-2-only + metric-style wide + segment-routing srv6 + locator loc1 + ! + line vty + .. _isis-vrf-config-examples: diff --git a/doc/user/mgmtd.rst b/doc/user/mgmtd.rst index 737eb57c85..42bc860b72 100644 --- a/doc/user/mgmtd.rst +++ b/doc/user/mgmtd.rst @@ -356,7 +356,7 @@ MGMT Show commands Currenlty supported values for 'candidate' and 'running' only ('operational' shall be supported in future soon). -.. clicmd:: show mgmt database-contents [candidate|operation|running] [xpath WORD] [file WORD] json|xml +.. clicmd:: show mgmt datastore-contents [candidate|operation|running] [xpath WORD] [file WORD] json|xml This command dumps the subtree pointed by the xpath in JSON or XML format. If filepath is not present then the tree will be printed on the shell. diff --git a/doc/user/ospf6d.rst b/doc/user/ospf6d.rst index 2f4c956ffd..12b368d431 100644 --- a/doc/user/ospf6d.rst +++ b/doc/user/ospf6d.rst @@ -312,10 +312,135 @@ OSPF6 interface Sets interface's Inf-Trans-Delay. Default value is 1. -.. clicmd:: ipv6 ospf6 network (broadcast|point-to-point) +.. clicmd:: ipv6 ospf6 network (broadcast|point-to-point|point-to-multipoint) Set explicitly network type for specified interface. + The only functional difference between ``point-to-point`` (PtP) and + ``point-to-multipoint`` (PtMP) mode is the packet addressing for database + flooding and updates. PtP will use multicast packets while PtMP will + unicast them. Apart from this, + :clicmd:`ipv6 ospf6 p2p-p2mp connected-prefixes <include|exclude>` has a + different default for PtP and PtMP. There are no other differences, in + particular FRR does not impose a limit of one neighbor in PtP mode. + + FRR does not support NBMA mode for IPv6 and likely never will, as NBMA is + considered deprecated for IPv6. Refer to `this IETF OSPF working group + discussion + <https://mailarchive.ietf.org/arch/msg/ospf/8GAbr4qSMMt5J7SvAcZQ1H7ARhk/>`_ + for context. + +OSPF6 point-to-point and point-to-multipoint operation +====================================================== + +OSPFv3, by default, operates in broadcast mode where it elects a DR and BDR +for each network segment. This can be changed to point-to-point (PtP) / +point-to-multipoint (PtMP) mode by configuration. The actual physical +interface characteristics do not matter for this setting, all interfaces can +be configured for all modes. However, routers must be configured for the same +mode to form adjacencies. + +The main advantages of PtP/PtMP mode are: + +- no DR/BDR election +- adjacencies can be suppressed in a pairwise manner for any two routers, e.g. + to represent the underlying topology if it isn't a true full mesh +- distinct costs can be set for each pair of routers and direction + +The main downside is less efficient flooding on networks with a large number +of OSPFv3 routers. + +.. warning:: + + All options in this section should be considered "advanced" configuration + options. Inconsistent or nonsensical combinations can easily result in a + non-functional setup. + +.. clicmd:: ipv6 ospf6 p2p-p2mp disable-multicast-hello + + Disables sending normal multicast hellos when in PtP/PtMP mode. Some + vendors do this automatically for PtMP mode while others have a separate + ``no-broadcast`` option matching this. + + If this setting is used, you must issue + :clicmd:`ipv6 ospf6 neighbor X:X::X:X poll-interval (1-65535)` for each + neighbor to send unicast hello packets. + +.. clicmd:: ipv6 ospf6 p2p-p2mp config-neighbors-only + + Only form adjacencies with neighbors that are explicitly configured with + the :clicmd:`ipv6 ospf6 neighbor X:X::X:X` command. Hellos from other + routers are ignored. + + .. warning:: + + This setting is not intended to provide any security benefit. Do not + run OSPFv3 over untrusted links without additional security measures + (e.g. IPsec.) + +.. clicmd:: ipv6 ospf6 p2p-p2mp connected-prefixes <include|exclude> + + For global/ULA prefixes configured on this interfaces, do (not) advertise + the full prefix to the area. Regardless of this setting, the router's own + address, as a /128 host route with the "LA" (Local Address) bit set, will + always be advertised. + + The default is to include connected prefixes for PtP mode and exclude them + for PtMP mode. Since these prefixes will cover other router's addresses, + these addresses can become unreachable if the link is partitioned if the + other router does not advertise the address as a /128. However, conversely, + if all routers have this flag set, the overall prefix will not be advertised + anywhere. End hosts on this link will therefore be unreachable (and + blackholing best-practices for non-existing prefixes apply.) It may be + preferable to have only one router announce the connected prefix. + + The Link LSA (which is not propagated into the area) always includes all + prefixes on the interface. This setting only affects the Router LSA that + is visible to all routers in the area. + + .. note:: + + Before interacting with this setting, consider either not configuring + any global/ULA IPv6 address on the interface, or directly configuring a + /128 if needed. OSPFv3 relies exclusively on link-local addresses to do + its signaling and there is absolutely no reason to configure global/ULA + addresses as far as OSPFv3 is concerned. + +.. clicmd:: ipv6 ospf6 neighbor X:X::X:X + + Explicitly configure a neighbor by its link-local address on this interface. + This statement has no effect other than allowing an adjacency when + :clicmd:`ipv6 ospf6 p2p-p2mp config-neighbors-only` is set. This command + does **not** cause unicast hellos to be sent. + + Only link-local addresses can be used to establish explicit neighbors. + When using this command, you should probably assign static IPv6 link-local + addresses to all routers on this link. It would technically be possible to + use the neighbor's Router ID (IPv4 address) here to ease working with + changing link-local addresses but this is not planned as a feature at the + time of writing. Global/ULA IPv6 addresses cannot be supported here due to + the way OSPFv3 works. + +.. clicmd:: ipv6 ospf6 neighbor X:X::X:X poll-interval (1-65535) + + Send unicast hellos to this neighbor at the specified interval (in seconds.) + The interval is only used while there is no adjacency with this neighbor. + As soon as an adjacency is formed, the interface's + :clicmd:`ipv6 ospf6 hello-interval HELLOINTERVAL` value is used. + (``hello-interval`` must be the same on all routers on this link.) + + :rfc:`2328` recommends a "much larger" value than ``hello-interval`` for + this setting, but this is a legacy of ATM and X.25 networks and nowadays you + should probably just use the same value as for ``hello-interval``. + +.. clicmd:: ipv6 ospf6 neighbor X:X::X:X cost (1-65535) + + Use a distinct cost for paths traversing this neighbor. The default is + to use the interface's cost value (which may be automatically calculated + based on link bandwidth.) Note that costs are directional in OSPF and the + reverse direction must be set on the other router. + + OSPF6 route-map =============== diff --git a/doc/user/ospfd.rst b/doc/user/ospfd.rst index 3430d8a282..2f88f24599 100644 --- a/doc/user/ospfd.rst +++ b/doc/user/ospfd.rst @@ -314,7 +314,7 @@ To start OSPF process you have to specify the OSPF router. This command controls the ospf instance's socket buffer sizes. The 'no' form resets one or both values to the default. - + .. clicmd:: no socket-per-interface Ordinarily, ospfd uses a socket per interface for sending @@ -599,6 +599,38 @@ Interfaces KEY is the actual message digest key, of up to 16 chars (larger strings will be truncated), and is associated with the given KEYID. +.. clicmd:: ip ospf authentication key-chain KEYCHAIN + + Specify that HMAC cryptographic authentication must be used on this interface + using a key chain. Overrides any authentication enabled on a per-area basis + (:clicmd:`area A.B.C.D authentication message-digest`). + + ``KEYCHAIN``: Specifies the name of the key chain that contains the authentication + key(s) and cryptographic algorithms to be used for OSPF authentication. The key chain + is a logical container that holds one or more authentication keys, + allowing for key rotation and management. + + Note that OSPF HMAC cryptographic authentication requires that time never go backwards + (correct time is NOT important, only that it never goes backwards), even + across resets, if ospfd is to be able to promptly reestablish adjacencies + with its neighbours after restarts/reboots. The host should have system time + be set at boot from an external or non-volatile source (e.g. battery backed + clock, NTP, etc.) or else the system clock should be periodically saved to + non-volatile storage and restored at boot if HMAC cryptographic authentication is to be + expected to work reliably. + + Example: + + .. code:: sh + + r1(config)#key chain temp + r1(config-keychain)#key 13 + r1(config-keychain-key)#key-string ospf + r1(config-keychain-key)#cryptographic-algorithm hmac-sha-256 + r1(config)#int eth0 + r1(config-if)#ip ospf authentication key-chain temp + r1(config-if)#ip ospf area 0 + .. clicmd:: ip ospf cost (1-65535) @@ -699,6 +731,15 @@ Interfaces OSPF (:ref:`redistribute-routes-to-ospf`). This is the only way to advertise non-OSPF links into stub areas. +.. clicmd:: ip ospf prefix-suppression [A.B.C.D] + + Configure OSPF to not advertise the IPv4 prefix associated with the + OSPF interface. The associated IPv4 prefix will be omitted from an OSPF + router-LSA or advertised with a host mask in an OSPF network-LSA as + specified in RFC 6860, "Hiding Transit-Only Networks in OSPF". If an + optional IPv4 address is specified, the prefix suppression will apply + to the OSPF interface associated with the specified interface address. + .. clicmd:: ip ospf area (A.B.C.D|(0-4294967295)) @@ -812,7 +853,7 @@ Graceful Restart affects the restarting router. By default 'strict-lsa-checking' is enabled" -.. clicmd:: graceful-restart helper supported-grace-time +.. clicmd:: graceful-restart helper supported-grace-time (10-1800) Supports as HELPER for configured grace period. @@ -884,10 +925,11 @@ Showing Information Show detailed information about the OSPF link-state database. -.. clicmd:: show ip ospf route [json] +.. clicmd:: show ip ospf route [detail] [json] Show the OSPF routing table, as determined by the most recent SPF - calculation. + calculation. When detail option is used, it shows more information + to the CLI like advertising router ID for each route, etc. .. clicmd:: show ip ospf [vrf <NAME|all>] border-routers [json] @@ -898,7 +940,7 @@ Showing Information .. clicmd:: show ip ospf graceful-restart helper [detail] [json] - Displays the Grcaeful Restart Helper details including helper + Displays the Graceful Restart Helper details including helper config changes. .. _opaque-lsa: @@ -912,7 +954,7 @@ Opaque LSA - *ospfd* supports Opaque LSA (:rfc:`2370`) as partial support for + *ospfd* supports Opaque LSA (:rfc:`5250`) as partial support for MPLS Traffic Engineering LSAs. The opaque-lsa capability must be enabled in the configuration. An alternate command could be "mpls-te on" (:ref:`ospf-traffic-engineering`). Note that FRR @@ -920,6 +962,18 @@ Opaque LSA extensions that are used with MPLS-TE; it does not support a complete RSVP-TE solution. +.. clicmd:: ip ospf capability opaque [A.B.C.D] + + Enable or disable OSPF LSA database exchange and flooding on an interface. + The default is that opaque capability is enabled as long as the opaque + capability is enabled with the :clicmd:`capability opaque` command at the + OSPF instance level (using the command above). Note that disabling opaque + LSA support on an interface will impact the applications using opaque LSAs + if the opaque LSAs are not received on other flooding paths by all the + OSPF routers using those applications. For example, OSPF Graceful Restart + uses opaque-link LSAs and disabling support on an interface will disable + graceful restart signaling on that interface. + .. clicmd:: show ip ospf [vrf <NAME|all>] database (opaque-link|opaque-area|opaque-external) .. clicmd:: show ip ospf [vrf <NAME|all>] database (opaque-link|opaque-area|opaque-external) LINK-STATE-ID diff --git a/doc/user/overview.rst b/doc/user/overview.rst index 33a1934628..2ef88acd7a 100644 --- a/doc/user/overview.rst +++ b/doc/user/overview.rst @@ -358,6 +358,8 @@ BGP :t:`Outbound Route Filtering Capability. E. Chen, Y. Rekhter. August 2008.` - :rfc:`5292` :t:`Address-Prefix-Based Outbound Route Filter for BGP-4. E. Chen, S. Sangli. August 2008.` +- :rfc:`5396` + :t:`Textual Representation of Autonomous System (AS) Numbers. G. Michaelson, G. Huston. December 2008.` - :rfc:`5492` :t:`Capabilities Advertisement with BGP-4. J. Scudder, R. Chandra. February 2009.` - :rfc:`5575` @@ -426,6 +428,8 @@ BGP :t:`Route Leak Prevention and Detection Using Roles in UPDATE and OPEN Messages. A. Azimov, E. Bogomazov, R. Bush, K. Patel, K. Sriram. May 2022.` - :rfc:`9384` :t:`A BGP Cease NOTIFICATION Subcode for Bidirectional Forwarding Detection (BFD). J. Haas. March 2023.` +- :rfc:`9494` + :t:`Long-Lived Graceful Restart for BGP. J. Uttaro, E. Chen, B. Decraene, J. Scudder. November 2023.` OSPF ---- diff --git a/doc/user/pathd.rst b/doc/user/pathd.rst index ec107fbe47..ba4c209a0d 100644 --- a/doc/user/pathd.rst +++ b/doc/user/pathd.rst @@ -327,7 +327,7 @@ Configuration Commands Delete or specify a bandwidth constraint for a dynamic candidate path. -.. clicmd:: metric [bound] METRIC VALUE [required] +.. clicmd:: metric [bound] METRIC VALUE [required] [computed] Delete or specify a metric constraint for a dynamic candidate path. @@ -475,6 +475,9 @@ Configuration Commands Specify the maximum SID depth in a PCC definition. +.. clicmd:: no msd [(1-32)] + + Default the maximum SID depth to 4. .. clicmd:: peer WORD [precedence (1-255)] diff --git a/doc/user/pbr.rst b/doc/user/pbr.rst index 0cdb206dd5..7a4effd3fc 100644 --- a/doc/user/pbr.rst +++ b/doc/user/pbr.rst @@ -4,10 +4,11 @@ PBR *** -:abbr:`PBR` is Policy Based Routing. This implementation supports a very simple -interface to allow admins to influence routing on their router. At this time -you can only match on destination and source prefixes for an incoming interface. -At this point in time, this implementation will only work on Linux. +:abbr:`PBR` is Policy Based Routing, which means forwarding based on +packet fields other than solely the destination IP address. +This implementation currently works only on Linux. Note that some +functionality (VLAN matching, packet mangling) is not supported by +the default Linux kernel dataplane provider. .. _starting-pbr: @@ -17,22 +18,22 @@ Starting PBR Default configuration file for *pbrd* is :file:`pbrd.conf`. The typical location of :file:`pbrd.conf` is |INSTALL_PREFIX_ETC|/pbrd.conf. -If the user is using integrated config, then :file:`pbrd.conf` need not be +If FRR is using integrated config, then :file:`pbrd.conf` need not be present and the :file:`frr.conf` is read instead. .. program:: pbrd -:abbr:`PBR` supports all the common FRR daemon start options which are +:abbr:`PBR` supports all the common FRR daemon start options, which are documented elsewhere. .. _nexthop-groups: -Nexthop Groups -============== +PBR Nexthop Groups +================== -Nexthop groups are a way to encapsulate ECMP information together. It's a -listing of ECMP nexthops used to forward packets for when a pbr-map is matched. -For detailed instructions on how to specify a nexthop group on the CLI, see +A nexthop group is a list of ECMP nexthops used to forward packets +when a pbr-map is matched. +For details on specifying a nexthop group in the CLI, see the nexthop-groups section. Showing Nexthop Group Information @@ -42,7 +43,7 @@ Showing Nexthop Group Information Display information on a PBR nexthop-group. If ``NAME`` is omitted, all nexthop groups are shown. Setting ``json`` will provide the same - information in an array of objects which obey the schema below: + information in an array of objects that adhere to the schema below: +-----------+----------------------------+---------+ | Key | Description | Type | @@ -74,118 +75,205 @@ Showing Nexthop Group Information PBR Maps ======== -PBR maps are a way to group policies that we would like to apply to individual -interfaces. These policies when applied are matched against incoming packets. -If matched the nexthop-group or nexthop is used to forward the packets to the -end destination. +PBR maps are a way to specify a set of rules that are applied to +packets received on individual interfaces. +If a received packet matches a rule, the rule's nexthop-group or +nexthop is used to forward it; any other actions +specified in the rule are also applied to the packet. .. clicmd:: pbr-map NAME seq (1-700) - Create a pbr-map with NAME and sequence number specified. This command puts - you into a new submode for pbr-map specification. To exit this mode type - exit or end as per normal conventions for leaving a sub-mode. + Create a pbr-map rule with map NAME and specified sequence number. + This command puts the CLI into a new submode for pbr-map rule specification. + To exit this submode, type ``exit`` or ``end``. .. clicmd:: match src-ip PREFIX - When a incoming packet matches the source prefix specified, take the packet - and forward according to the nexthops specified. This command accepts both - v4 and v6 prefixes. This command is used in conjunction of the - :clicmd:`match dst-ip PREFIX` command for matching. + Match the packet's source IP address. + + This command accepts both v4 and v6 prefixes. .. clicmd:: match dst-ip PREFIX - When a incoming packet matches the destination prefix specified, take the - packet and forward according to the nexthops specified. This command accepts - both v4 and v6 prefixes. This command is used in conjunction of the - :clicmd:`match src-ip PREFIX` command for matching. + Match the packet's destination IP address. + + This command accepts both v4 and v6 prefixes. .. clicmd:: match src-port (1-65535) - When a incoming packet matches the source port specified, take the - packet and forward according to the nexthops specified. + Match the packet's UDP or TCP source port. .. clicmd:: match dst-port (1-65535) - When a incoming packet matches the destination port specified, take the - packet and forward according to the nexthops specified. + Match the packet's UDP or TCP destination port. -.. clicmd:: match ip-protocol [tcp|udp] +.. clicmd:: match ip-protocol PROTOCOL - When a incoming packet matches the specified ip protocol, take the - packet and forward according to the nexthops specified. + Match the packet's IP protocol. + + Protocol names are queried from the protocols database (``/etc/protocols``; + see ``man 5 protocols`` and ``man 3 getprotobyname``). .. clicmd:: match mark (1-4294967295) - Select the mark to match. This is a linux only command and if attempted - on another platform it will be denied. This mark translates to the - underlying `ip rule .... fwmark XXXX` command. + Match the packet's meta-information mark. + The mark value is attached to the packet by the kernel/dataplane and + is platform-specific. + Currently, this field is supported only on linux and corresponds to + the underlying `ip rule .... fwmark XXXX` command. .. clicmd:: match dscp (DSCP|0-63) - Match packets according to the specified differentiated services code point - (DSCP) in the IP header; if this value matches then forward the packet - according to the nexthop(s) specified. The passed DSCP value may also be a - standard name for a differentiated service code point like cs0 or af11. + Match the packet's IP differentiated services code point (DSCP). + The specified DSCP may also be a standard name for a + differentiated service code point such as ``cs0`` or ``af11``. - You may only specify one dscp per route map sequence; to match on multiple - dscp values you will need to create several sequences, one for each value. + You may only specify one dscp per route map rule; to match on multiple + dscp values you will need to create several rules, one for each value. .. clicmd:: match ecn (0-3) - Match packets according to the specified explicit congestion notification - (ECN) field in the IP header; if this value matches then forward the packet - according to the nexthop(s) specified. + Match the packet's IP explicit congestion notification (ECN) field. + +.. clicmd:: match pcp (0-7) + + Match the packet's 802.1Q Priority Code Point. + Zero is the default (nominally, "best effort"). + The Linux kernel dataplane provider does not currently support + matching PCPs, + so this field will be ignored unless other dataplane providers are used. + +.. clicmd:: match vlan (1-4094) + + Match the packet's VLAN (802.1Q) identifier. + Note that VLAN IDs 0 and 4095 are reserved. + The Linux kernel dataplane provider does not currently support + VLAN-matching facilities, + so this field will be ignored unless other dataplane providers are used. + +.. clicmd:: match vlan (tagged|untagged|untagged-or-zero) + + Match packets according to whether or not they have a VLAN tag. + Use `untagged-or-zero` to also match packets with either no VLAN tag + or with the reserved VLAN ID of 0 (indicating an untagged frame that + includes other 802.1Q fields). + The Linux kernel dataplane provider does not currently support + VLAN-matching facilities, + so this field will be ignored unless other dataplane providers are used. + +.. clicmd:: set nexthop-group NAME + + Action: + forward the packet using nexthop-group NAME. + +.. clicmd:: set nexthop [A.B.C.D|X:X::X:XX|blackhole] [interface] [nexthop-vrf NAME] + Action: + forward the packet using the specified single nexthop. + If `blackhole`, packets will be sent to a blackhole route and dropped. + +.. clicmd:: set vrf unchanged|NAME + + Action: + If set to ``unchanged``, the rule will use the vrf table the interface + is in as its lookup. + If set to NAME, the rule will use that vrf table as its lookup. + + Not supported with NETNS VRF backend. .. clicmd:: set queue-id (1-65535) - Set the egress port queue identifier for matched packets. The Linux Kernel - provider does not currently support packet mangling, so this field will be - ignored unless another provider is used. + Action: + set the egress port queue identifier. + The Linux Kernel dataplane provider does not currently support + packet mangling, + so this field will be ignored unless another dataplane provider is used. .. clicmd:: set pcp (0-7) - Set the 802.1Q priority code point (PCP) for matched packets. A PCP of zero - is the defaul (nominally, "best effort"). The Linux Kernel provider does not - currently support packet mangling, so this field will be ignored unless - another provider is used. + Action: + set the 802.1Q priority code point (PCP). + A PCP of zero is the default (nominally, "best effort"). + The Linux Kernel dataplane provider does not currently support + packet mangling, + so this field will be ignored unless another dataplane provider is used. .. clicmd:: set vlan (1-4094) - Set the VLAN tag for matched packets. Identifiers 0 and 4095 are reserved. - The Linux Kernel provider does not currently support packet mangling, so - this field will be ignored unless another provider is used. + Action: + set the VLAN tag. Identifiers 0 and 4095 are reserved. + The Linux Kernel dataplane provider does not currently support + packet mangling, + so this field will be ignored unless another dataplane provider is used. .. clicmd:: strip vlan - Strip inner vlan tags from matched packets. The Linux Kernel provider does not currently support packet mangling, so this field will be ignored unless another provider is used. It is invalid to specify both a `strip` and `set - vlan` action. + Action: + strip inner vlan tags. + The Linux Kernel dataplane provider does not currently support + packet mangling, + so this field will be ignored unless another dataplane provider is used. + It is invalid to specify both a `strip` and `set vlan` action. -.. clicmd:: set nexthop-group NAME +.. clicmd:: set src-ip [A.B.C.D/M|X:X::X:X/M] - Use the nexthop-group NAME as the place to forward packets when the match - commands have matched a packet. + Action: + Set the source IP address of matched packets, possibly using a mask `M`. + The Linux Kernel dataplane provider does not currently support + packet mangling, + so this field will be ignored unless another dataplane provider is used. -.. clicmd:: set nexthop [A.B.C.D|X:X::X:XX] [interface] [nexthop-vrf NAME] +.. clicmd:: set dst-ip [A.B.C.D/M|X:X::X:X/M] - Use this individual nexthop as the place to forward packets when the match - commands have matched a packet. + Action: + set the destination IP address of matched packets, possibly using a mask + `M`. + The Linux Kernel dataplane provider does not currently support + packet mangling, + so this field will be ignored unless another dataplane provider is used. -.. clicmd:: set vrf unchanged|NAME +.. clicmd:: set src-port (1-65535) - If unchanged is set, the rule will use the vrf table the interface is in - as its lookup. If NAME is specified, the rule will use that vrf table as - its lookup. + Action: + set the source port of matched packets. Note that this action only makes + sense with layer 4 protocols that use ports, such as TCP, UDP, and SCTP. + The Linux Kernel dataplane provider does not currently support + packet mangling, + so this field will be ignored unless another dataplane provider is used. - Not supported with NETNS VRF backend. +.. clicmd:: set dst-port (1-65535) + + Action: + set the destination port of matched packets. Note that this action only + makes sense with layer 4 protocols that use ports, such as TCP, UDP, and + SCTP. + The Linux Kernel dataplane provider does not currently support + packet mangling, + so this field will be ignored unless another dataplane provider is used. + +.. clicmd:: set dscp DSCP + + Action: + set the differentiated services code point (DSCP) of matched packets. + The Linux Kernel dataplane provider does not currently support + this action, + so this field will be ignored unless another dataplane provider is used. + +.. clicmd:: set ecn (0-3) + + Action: + set the explicit congestion notification (ECN) of matched packets. + The Linux Kernel dataplane provider does not currently support + this action, + so this field will be ignored unless another dataplane provider is used. -.. clicmd:: show pbr map [NAME] [detail|json] +.. clicmd:: show pbr map [NAME] [detail] [json] Display pbr maps either all or by ``NAME``. If ``detail`` is set, it will - give information about the rules unique ID used internally and some extra + give information about each rule's unique internal ID and some extra debugging information about install state for the nexthop/nexthop group. Setting ``json`` will provide the same information in an array of objects - which obey the schema below: + that adher to the schema below: +----------+--------------------------------+---------+ | Key | Description | Type | @@ -197,9 +285,9 @@ end destination. | policies | Rules to match packets against | Array | +----------+--------------------------------+---------+ - Each element of the ``policies`` array is composed of a handful of objects + Each element of the ``policies`` array is composed of a set of objects representing the policies associated with this map. Each policy is - described as below (not all fields are required): + described below (not all fields are required): +-----------------+-------------------------------------------+---------+ | Key | Description | Type | @@ -227,8 +315,8 @@ end destination. | nexthopGroup | This policy's nexthop group (if relevant) | Object | +-----------------+-------------------------------------------+---------+ - Finally, the ``nexthopGroup`` object above cotains information we know - about the configured nexthop for this policy: + Finally, the ``nexthopGroup`` object above contains information FRR + knows about the configured nexthop for this policy: +---------------------+--------------------------------------+---------+ | Key | Description | Type | @@ -239,7 +327,7 @@ end destination. +---------------------+--------------------------------------+---------+ | installed | Is this nexthop group installed? | Boolean | +---------------------+--------------------------------------+---------+ - | installedInternally | Do we think this group is installed? | Integer | + | installedInternally | Does FRR think NHG is installed? | Integer | +---------------------+--------------------------------------+---------+ @@ -251,19 +339,19 @@ end destination. PBR Policy ========== -After you have specified a PBR map, in order for it to be turned on, you must -apply the PBR map to an interface. This policy application to an interface +After you have specified a PBR map, in order for it to be enabled, it must +be applied to an interface. This policy application to an interface causes the policy to be installed into the kernel. .. clicmd:: pbr-policy NAME - This command is available under interface sub-mode. This turns - on the PBR map NAME and allows it to work properly. + This command is available under interface sub-mode. + It enables the PBR map NAME on the interface. .. note:: - This will not dynamically create PBR maps on sub-interfaces (i.e. vlans) - even if one is on the master. Each must have the PBR map explicitly added - to the interface. + This command will not dynamically create PBR maps on sub-interfaces + (i.e. vlans), even if one is on the master. + Each sub-interface must have the PBR map enabled explicitly. .. clicmd:: show pbr interface [NAME] [json] @@ -285,9 +373,9 @@ causes the policy to be installed into the kernel. .. clicmd:: pbr table range (10000-4294966272) (10000-4294966272) - Set or unset the range used to assign numeric table ID's to new + Set or unset the range used to assign numeric table IDs to new nexthop-group tables. Existing tables will not be modified to fit in this - range, so it is recommended to configure this before adding nexthop groups. + range, so this range should be configured before adding nexthop groups. .. seealso:: :ref:`pbr-details` @@ -299,23 +387,23 @@ PBR Debugs .. clicmd:: debug pbr events|map|nht|zebra - Debug pbr in pbrd daemon. You specify what types of debugs to turn on. + Debug pbr in pbrd daemon. You must specify what types of debugs to turn on. .. _pbr-details: PBR Details =========== -Under the covers a PBR map is translated into two separate constructs in the +Internally, a PBR map is translated into two separate constructs in the Linux kernel. -The PBR map specified creates a `ip rule ...` that is inserted into the Linux +The PBR map creates an `ip rule ...` that is inserted into the Linux kernel that points to a table to use for forwarding once the rule matches. -The creation of a nexthop or nexthop-group is translated to a default route in a -table with the nexthops specified as the nexthops for the default route. +The creation of a nexthop or nexthop-group is translated to a +table with a default route having the specified nexthop(s). Sample configuration diff --git a/doc/user/requirements.txt b/doc/user/requirements.txt new file mode 100644 index 0000000000..483a4e9600 --- /dev/null +++ b/doc/user/requirements.txt @@ -0,0 +1 @@ +sphinx_rtd_theme diff --git a/doc/user/ripngd.rst b/doc/user/ripngd.rst index 4c9b734d88..1e78294f32 100644 --- a/doc/user/ripngd.rst +++ b/doc/user/ripngd.rst @@ -92,6 +92,53 @@ RIPng routes can be filtered by a distribute-list. `distribute-list` can be applied to both incoming and outgoing data. +.. _ripng-route-map: + +RIPng route-map +=============== + +Usage of *ripngd*'s route-map support. + +Route-map statement (:ref:`route-map`) is needed to use route-map +functionality. + +.. clicmd:: match interface WORD + + This command match to incoming interface. Notation of this match is + different from Cisco. Cisco uses a list of interfaces - NAME1 NAME2 ... + NAMEN. Ripngd allows only one name (maybe will change in the future). Next - + Cisco means interface which includes next-hop of routes (it is somewhat + similar to "ipv6 next-hop" statement). Ripngd means interface where this route + will be sent. This difference is because "next-hop" of same routes which + sends to different interfaces must be different. + +.. clicmd:: match ipv6 address WORD + +.. clicmd:: match ipv6 address prefix-list WORD + + Match if route destination is permitted by access-list/prefix-list. + +.. clicmd:: match metric (0-4294967295) + + This command match to the metric value of RIPng updates. For other protocol + compatibility metric range is shown as (0-4294967295). But for RIPng protocol + only the value range (0-16) make sense. + +.. clicmd:: set ipv6 next-hop local IPV6_ADDRESS + + Set the link-local IPv6 nexthop address. + +.. clicmd:: set metric (1-16) + + Set a metric for matched route when sending announcement. The metric value + range is very large for compatibility with other protocols. For RIPng, valid + metric values are from 1 to 16. + +.. clicmd:: set tag (1-4294967295) + + Set a tag on the matched route. + + Sample configuration ==================== diff --git a/doc/user/routemap.rst b/doc/user/routemap.rst index bd19ae88e2..18a261d940 100644 --- a/doc/user/routemap.rst +++ b/doc/user/routemap.rst @@ -185,9 +185,11 @@ Route Map Match Command Matches the specified `local-preference`. -.. clicmd:: match community COMMUNITY_LIST +.. clicmd:: match community COMMUNITY_LIST [<exact-match|any>] - Matches the specified `community_list` + Matches the specified `community_list`. ``exact-match`` specifies to + do the exact matching of the communities, while ``any`` - can match any + community specified in COMMUNITY_LIST. .. clicmd:: match peer IPV4_ADDR @@ -335,6 +337,10 @@ Route Map Set Command Set the BGP community attribute. +.. clicmd:: set extended-comm-list <EXTCOMMUNITY_LIST_NAME> delete + + Set BGP extended community list for deletion. + .. clicmd:: set ipv6 next-hop local IPV6_ADDRESS Set the BGP-4+ link local IPv6 nexthop address. diff --git a/doc/user/snmp.rst b/doc/user/snmp.rst index 0bf3565b2e..3c2d11a6a7 100644 --- a/doc/user/snmp.rst +++ b/doc/user/snmp.rst @@ -126,54 +126,121 @@ An example below is how to query SNMP for BGP: $ # Information about the peers (bgp4V2PeerTable): $ snmpwalk -c public -v2c -On -Ln localhost .1.3.6.1.3.5.1.1.2 ... - .1.3.6.1.3.5.1.1.2.1.1.1.4.192.168.10.124 = Gauge32: 0 - .1.3.6.1.3.5.1.1.2.1.1.2.16.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = Gauge32: 0 - .1.3.6.1.3.5.1.1.2.1.2.1.4.192.168.10.124 = INTEGER: 1 - .1.3.6.1.3.5.1.1.2.1.2.2.16.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = INTEGER: 2 - .1.3.6.1.3.5.1.1.2.1.3.1.4.192.168.10.124 = Hex-STRING: C0 A8 0A 11 - .1.3.6.1.3.5.1.1.2.1.3.2.16.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = Hex-STRING: 2A 02 47 80 0A BC 00 00 00 00 00 00 00 00 00 01 - .1.3.6.1.3.5.1.1.2.1.4.1.4.192.168.10.124 = INTEGER: 1 - .1.3.6.1.3.5.1.1.2.1.4.2.16.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = INTEGER: 2 - .1.3.6.1.3.5.1.1.2.1.5.1.4.192.168.10.124 = Hex-STRING: C0 A8 0A 7C - .1.3.6.1.3.5.1.1.2.1.5.2.16.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = Hex-STRING: 2A 02 47 80 0A BC 00 00 00 00 00 00 00 00 00 02 - .1.3.6.1.3.5.1.1.2.1.6.1.4.192.168.10.124 = Gauge32: 179 - .1.3.6.1.3.5.1.1.2.1.6.2.16.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = Gauge32: 179 - .1.3.6.1.3.5.1.1.2.1.7.1.4.192.168.10.124 = Gauge32: 65002 - .1.3.6.1.3.5.1.1.2.1.7.2.16.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = Gauge32: 65002 - .1.3.6.1.3.5.1.1.2.1.8.1.4.192.168.10.124 = Hex-STRING: C0 A8 0A 11 - .1.3.6.1.3.5.1.1.2.1.8.2.16.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = Hex-STRING: C0 A8 0A 11 - .1.3.6.1.3.5.1.1.2.1.9.1.4.192.168.10.124 = Gauge32: 41894 - .1.3.6.1.3.5.1.1.2.1.9.2.16.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = Gauge32: 39960 - .1.3.6.1.3.5.1.1.2.1.10.1.4.192.168.10.124 = Gauge32: 65001 - .1.3.6.1.3.5.1.1.2.1.10.2.16.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = Gauge32: 65001 - .1.3.6.1.3.5.1.1.2.1.11.1.4.192.168.10.124 = Hex-STRING: C8 C8 C8 CA - .1.3.6.1.3.5.1.1.2.1.11.2.16.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = Hex-STRING: C8 C8 C8 CA - .1.3.6.1.3.5.1.1.2.1.12.1.4.192.168.10.124 = INTEGER: 2 - .1.3.6.1.3.5.1.1.2.1.12.2.16.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = INTEGER: 2 - .1.3.6.1.3.5.1.1.2.1.13.1.4.192.168.10.124 = INTEGER: 6 - .1.3.6.1.3.5.1.1.2.1.13.2.16.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = INTEGER: 6 + .1.3.6.1.3.5.1.1.2.1.1.1.1.192.168.10.124 = Gauge32: 0 + .1.3.6.1.3.5.1.1.2.1.1.1.2.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = Gauge32: 0 + .1.3.6.1.3.5.1.1.2.1.2.1.1.192.168.10.124 = INTEGER: 1 + .1.3.6.1.3.5.1.1.2.1.2.1.2.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = INTEGER: 2 + .1.3.6.1.3.5.1.1.2.1.3.1.1.192.168.10.124 = Hex-STRING: C0 A8 0A 11 + .1.3.6.1.3.5.1.1.2.1.3.1.2.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = Hex-STRING: 2A 02 47 80 0A BC 00 00 00 00 00 00 00 00 00 01 + .1.3.6.1.3.5.1.1.2.1.4.1.1.192.168.10.124 = INTEGER: 1 + .1.3.6.1.3.5.1.1.2.1.4.1.2.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = INTEGER: 2 + .1.3.6.1.3.5.1.1.2.1.5.1.1.192.168.10.124 = Hex-STRING: C0 A8 0A 7C + .1.3.6.1.3.5.1.1.2.1.5.1.2.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = Hex-STRING: 2A 02 47 80 0A BC 00 00 00 00 00 00 00 00 00 02 + .1.3.6.1.3.5.1.1.2.1.6.1.1.192.168.10.124 = Gauge32: 179 + .1.3.6.1.3.5.1.1.2.1.6.1.2.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = Gauge32: 179 + .1.3.6.1.3.5.1.1.2.1.7.1.1.192.168.10.124 = Gauge32: 65002 + .1.3.6.1.3.5.1.1.2.1.7.1.2.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = Gauge32: 65002 + .1.3.6.1.3.5.1.1.2.1.8.1.1.192.168.10.124 = Hex-STRING: C0 A8 0A 11 + .1.3.6.1.3.5.1.1.2.1.8.1.2.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = Hex-STRING: C0 A8 0A 11 + .1.3.6.1.3.5.1.1.2.1.9.1.1.192.168.10.124 = Gauge32: 41894 + .1.3.6.1.3.5.1.1.2.1.9.1.2.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = Gauge32: 39960 + .1.3.6.1.3.5.1.1.2.1.10.1.1.192.168.10.124 = Gauge32: 65001 + .1.3.6.1.3.5.1.1.2.1.10.1.2.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = Gauge32: 65001 + .1.3.6.1.3.5.1.1.2.1.11.1.1.192.168.10.124 = Hex-STRING: C8 C8 C8 CA + .1.3.6.1.3.5.1.1.2.1.11.1.2.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = Hex-STRING: C8 C8 C8 CA + .1.3.6.1.3.5.1.1.2.1.12.1.1.192.168.10.124 = INTEGER: 2 + .1.3.6.1.3.5.1.1.2.1.12.1.2.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = INTEGER: 2 + .1.3.6.1.3.5.1.1.2.1.13.1.1.192.168.10.124 = INTEGER: 6 + .1.3.6.1.3.5.1.1.2.1.13.1.2.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = INTEGER: 6 $ # Information about the BGP table (bgp4V2NlriTable): $ snmpwalk -c public -v2c -On -Ln localhost .1.3.6.1.3.5.1.1.9 ... - .1.3.6.1.3.5.1.1.9.1.22.1.4.10.0.2.0.24.192.168.10.124 = Gauge32: 1 - .1.3.6.1.3.5.1.1.9.1.22.1.4.10.10.100.0.24.192.168.10.124 = Gauge32: 1 - .1.3.6.1.3.5.1.1.9.1.22.1.4.172.16.31.1.32.192.168.10.124 = Gauge32: 1 - .1.3.6.1.3.5.1.1.9.1.22.1.4.172.16.31.2.32.192.168.10.124 = Gauge32: 1 - .1.3.6.1.3.5.1.1.9.1.22.1.4.172.16.31.3.32.192.168.10.124 = Gauge32: 1 - .1.3.6.1.3.5.1.1.9.1.22.1.4.192.168.0.0.24.192.168.10.124 = Gauge32: 1 - .1.3.6.1.3.5.1.1.9.1.22.1.4.192.168.1.0.24.192.168.10.124 = Gauge32: 1 - .1.3.6.1.3.5.1.1.9.1.22.1.4.192.168.10.0.24.192.168.10.124 = Gauge32: 1 - .1.3.6.1.3.5.1.1.9.1.22.2.16.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.0.64.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = Gauge32: 1 - .1.3.6.1.3.5.1.1.9.1.24.1.4.10.0.2.0.24.192.168.10.124 = Hex-STRING: 02 01 FD E9 - .1.3.6.1.3.5.1.1.9.1.24.1.4.10.10.100.0.24.192.168.10.124 = Hex-STRING: 02 01 FD E9 - .1.3.6.1.3.5.1.1.9.1.24.1.4.172.16.31.1.32.192.168.10.124 = Hex-STRING: 02 01 FD E9 - .1.3.6.1.3.5.1.1.9.1.24.1.4.172.16.31.2.32.192.168.10.124 = Hex-STRING: 02 01 FD E9 - .1.3.6.1.3.5.1.1.9.1.24.1.4.172.16.31.3.32.192.168.10.124 = Hex-STRING: 02 01 FD E9 - .1.3.6.1.3.5.1.1.9.1.24.1.4.192.168.0.0.24.192.168.10.124 = Hex-STRING: 02 01 FD E9 - .1.3.6.1.3.5.1.1.9.1.24.1.4.192.168.1.0.24.192.168.10.124 = Hex-STRING: 02 01 FD E9 - .1.3.6.1.3.5.1.1.9.1.24.1.4.192.168.10.0.24.192.168.10.124 = Hex-STRING: 02 01 FD E9 - .1.3.6.1.3.5.1.1.9.1.24.2.16.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.0.64.42.2.71.128.10.188.0.0.0.0.0.0.0.0.0.2 = Hex-STRING: 02 01 FD E9 + .1.3.6.1.3.5.1.1.9.1.1.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = Gauge32: 0 + .1.3.6.1.3.5.1.1.9.1.1.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = Gauge32: 0 + .1.3.6.1.3.5.1.1.9.1.1.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Gauge32: 0 + .1.3.6.1.3.5.1.1.9.1.1.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Gauge32: 0 + .1.3.6.1.3.5.1.1.9.1.2.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = INTEGER: 1 + .1.3.6.1.3.5.1.1.9.1.2.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = INTEGER: 1 + .1.3.6.1.3.5.1.1.9.1.2.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = INTEGER: 2 + .1.3.6.1.3.5.1.1.9.1.2.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = INTEGER: 2 + .1.3.6.1.3.5.1.1.9.1.3.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = INTEGER: 1 + .1.3.6.1.3.5.1.1.9.1.3.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = INTEGER: 1 + .1.3.6.1.3.5.1.1.9.1.3.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = INTEGER: 1 + .1.3.6.1.3.5.1.1.9.1.3.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = INTEGER: 1 + .1.3.6.1.3.5.1.1.9.1.4.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = INTEGER: 1 + .1.3.6.1.3.5.1.1.9.1.4.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = INTEGER: 1 + .1.3.6.1.3.5.1.1.9.1.4.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = INTEGER: 2 + .1.3.6.1.3.5.1.1.9.1.4.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = INTEGER: 2 + .1.3.6.1.3.5.1.1.9.1.5.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = Hex-STRING: 0A 00 00 00 + .1.3.6.1.3.5.1.1.9.1.5.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = Hex-STRING: 0A 00 00 02 + .1.3.6.1.3.5.1.1.9.1.5.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Hex-STRING: 20 01 0D B8 00 00 00 00 00 00 00 00 00 00 00 01 + .1.3.6.1.3.5.1.1.9.1.5.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Hex-STRING: 20 01 0D B8 00 01 00 00 00 00 00 00 00 00 00 00 + .1.3.6.1.3.5.1.1.9.1.6.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = Gauge32: 31 + .1.3.6.1.3.5.1.1.9.1.6.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = Gauge32: 32 + .1.3.6.1.3.5.1.1.9.1.6.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Gauge32: 128 + .1.3.6.1.3.5.1.1.9.1.6.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Gauge32: 56 + .1.3.6.1.3.5.1.1.9.1.7.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = INTEGER: 1 + .1.3.6.1.3.5.1.1.9.1.7.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = INTEGER: 1 + .1.3.6.1.3.5.1.1.9.1.7.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = INTEGER: 1 + .1.3.6.1.3.5.1.1.9.1.7.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = INTEGER: 1 + .1.3.6.1.3.5.1.1.9.1.8.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = Gauge32: 0 + .1.3.6.1.3.5.1.1.9.1.8.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = Gauge32: 0 + .1.3.6.1.3.5.1.1.9.1.8.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Gauge32: 0 + .1.3.6.1.3.5.1.1.9.1.8.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Gauge32: 0 + .1.3.6.1.3.5.1.1.9.1.9.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = INTEGER: 1 + .1.3.6.1.3.5.1.1.9.1.9.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = INTEGER: 3 + .1.3.6.1.3.5.1.1.9.1.9.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = INTEGER: 1 + .1.3.6.1.3.5.1.1.9.1.9.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = INTEGER: 3 + .1.3.6.1.3.5.1.1.9.1.10.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = INTEGER: 1 + .1.3.6.1.3.5.1.1.9.1.10.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = INTEGER: 1 + .1.3.6.1.3.5.1.1.9.1.10.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = INTEGER: 4 + .1.3.6.1.3.5.1.1.9.1.10.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = INTEGER: 4 + .1.3.6.1.3.5.1.1.9.1.11.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = Hex-STRING: C0 A8 0C 01 + .1.3.6.1.3.5.1.1.9.1.11.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = Hex-STRING: C0 A8 0C 01 + .1.3.6.1.3.5.1.1.9.1.11.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Hex-STRING: FE 80 00 00 00 00 00 00 30 39 84 FF FE 9A 24 2B + .1.3.6.1.3.5.1.1.9.1.11.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Hex-STRING: FE 80 00 00 00 00 00 00 30 39 84 FF FE 9A 24 2B + .1.3.6.1.3.5.1.1.9.1.14.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = INTEGER: 0 + .1.3.6.1.3.5.1.1.9.1.14.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = INTEGER: 0 + .1.3.6.1.3.5.1.1.9.1.14.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = INTEGER: 0 + .1.3.6.1.3.5.1.1.9.1.14.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = INTEGER: 0 + .1.3.6.1.3.5.1.1.9.1.15.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = Gauge32: 0 + .1.3.6.1.3.5.1.1.9.1.15.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = Gauge32: 0 + .1.3.6.1.3.5.1.1.9.1.15.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Gauge32: 0 + .1.3.6.1.3.5.1.1.9.1.15.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Gauge32: 0 + .1.3.6.1.3.5.1.1.9.1.16.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = INTEGER: 1 + .1.3.6.1.3.5.1.1.9.1.16.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = INTEGER: 1 + .1.3.6.1.3.5.1.1.9.1.16.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = INTEGER: 1 + .1.3.6.1.3.5.1.1.9.1.16.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = INTEGER: 1 + 1.3.6.1.3.5.1.1.9.1.17.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = Gauge32: 1 + 1.3.6.1.3.5.1.1.9.1.17.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = Gauge32: 2 + 1.3.6.1.3.5.1.1.9.1.17.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Gauge32: 1 + 1.3.6.1.3.5.1.1.9.1.17.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Gauge32: 2 + 1.3.6.1.3.5.1.1.9.1.18.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = INTEGER: 0 + 1.3.6.1.3.5.1.1.9.1.18.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = INTEGER: 0 + 1.3.6.1.3.5.1.1.9.1.18.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = INTEGER: 0 + 1.3.6.1.3.5.1.1.9.1.18.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = INTEGER: 0 + 1.3.6.1.3.5.1.1.9.1.19.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = INTEGER: 0 + 1.3.6.1.3.5.1.1.9.1.19.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = INTEGER: 0 + 1.3.6.1.3.5.1.1.9.1.19.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = INTEGER: 0 + 1.3.6.1.3.5.1.1.9.1.19.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = INTEGER: 0 + 1.3.6.1.3.5.1.1.9.1.20.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = Gauge32: 0 + 1.3.6.1.3.5.1.1.9.1.20.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = Gauge32: 0 + 1.3.6.1.3.5.1.1.9.1.20.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Gauge32: 0 + 1.3.6.1.3.5.1.1.9.1.20.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Gauge32: 0 + 1.3.6.1.3.5.1.1.9.1.21.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = Hex-STRING: 00 00 00 00 + 1.3.6.1.3.5.1.1.9.1.21.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = Hex-STRING: 00 00 00 00 + 1.3.6.1.3.5.1.1.9.1.21.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Hex-STRING: 00 00 00 00 + 1.3.6.1.3.5.1.1.9.1.21.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Hex-STRING: 00 00 00 00 + 1.3.6.1.3.5.1.1.9.1.22.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = Gauge32: 1 + 1.3.6.1.3.5.1.1.9.1.22.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = Gauge32: 1 + .1.3.6.1.3.5.1.1.9.1.22.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Gauge32: 1 + .1.3.6.1.3.5.1.1.9.1.22.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Gauge32: 1 + .1.3.6.1.3.5.1.1.9.1.24.1.1.1.1.10.0.0.0.31.1.192.168.12.1.1 = Hex-STRING: 02 01 FD E9 + .1.3.6.1.3.5.1.1.9.1.24.1.1.1.1.10.0.0.2.32.1.192.168.12.1.1 = Hex-STRING: 02 01 FD E9 + .1.3.6.1.3.5.1.1.9.1.24.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Hex-STRING: 02 01 FD E9 + .1.3.6.1.3.5.1.1.9.1.24.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1.1 = Hex-STRING: 02 01 FD E9 + The AgentX protocol can be transported over a Unix socket or using TCP or UDP. It usually defaults to a Unix socket and depends on how NetSNMP was built. If diff --git a/doc/user/snmptrap.rst b/doc/user/snmptrap.rst index 7e306b743d..df534e28bd 100644 --- a/doc/user/snmptrap.rst +++ b/doc/user/snmptrap.rst @@ -4,8 +4,9 @@ Handling SNMP Traps To handle snmp traps make sure your snmp setup of frr works correctly as described in the frr documentation in :ref:`snmp-support`. -The BGP4 mib will send traps on peer up/down events. These should be visible in -your snmp logs with a message similar to: +BGP handles both :rfc:`4273` and [Draft-IETF-idr-bgp4-mibv2-11]_ MIBs. +The BGP4 MIBs will send traps on peer up/down events. These should be +visible in your snmp logs with a message similar to: :: @@ -199,3 +200,18 @@ a siren, have your display flash, etc., be creative ;). # mail the notification echo "$MAIL" | mail -s "$SUBJECT" $EMAILADDR + +.. _traps-mib-selection: + +Traps Mib Selection in BGP +-------------------------- + +Both :rfc:`4273` and [Draft-IETF-idr-bgp4-mibv2-11]_ MIBs define traps for +dealing with up/down events and state transition. The user has the +possibility to select the MIB he wants to receive traps from: + +.. clicmd:: bgp snmp traps <rfc4273|bgp4-mibv2> + +By default, only rfc4273 traps are enabled and sent. + +.. [Draft-IETF-idr-bgp4-mibv2-11] <https://tools.ietf.org/id/draft-ietf-idr-bgp4-mibv2-11.txt> diff --git a/doc/user/static.rst b/doc/user/static.rst index 6d8aca97bb..d405276573 100644 --- a/doc/user/static.rst +++ b/doc/user/static.rst @@ -164,3 +164,23 @@ network 9.9.9.9/24: .. code-block:: frr ip route 9.9.9.9/24 6.6.6.6 color 123 + +SRv6 Route Commands +==================== + +It is possible to specify a static route for ipv6 prefixes using an SRv6 +`segments` instruction. The `/` separator can be used to specify +multiple segments instructions. + +.. code-block:: frr + + ipv6 route X:X::X:X <X:X::X:X|nexthop> segments U:U::U:U/Y:Y::Y:Y/Z:Z::Z:Z + + +:: + + router(config)# ipv6 route 2005::1/64 ens3 segments 2001:db8:aaaa::7/2002::4/2002::3/2002::2 + + router# show ipv6 route + [..] + S>* 2005::/64 [1/0] is directly connected, ens3, seg6 2001:db8:aaaa::7,2002::4,2002::3,2002::2, weight 1, 00:00:06 diff --git a/doc/user/vtysh.rst b/doc/user/vtysh.rst index 1ab54f09ab..adbdf3451a 100644 --- a/doc/user/vtysh.rst +++ b/doc/user/vtysh.rst @@ -18,8 +18,9 @@ administrator with an external editor. .. warning:: - This also means the ``hostname`` and ``banner motd`` commands (which both do - have effect for vtysh) need to be manually updated in :file:`vtysh.conf`. + This also means the ``hostname``, ``domainname``, and ``banner motd`` commands + (which do have effect for vtysh) need to be manually updated + in :file:`vtysh.conf`. .. clicmd:: copy FILENAME running-config diff --git a/doc/user/zebra.rst b/doc/user/zebra.rst index d7e768b710..2b737c1a2f 100644 --- a/doc/user/zebra.rst +++ b/doc/user/zebra.rst @@ -68,6 +68,12 @@ Besides the common invocation options (:ref:`common-invocation-options`), the option and we will use Route Replace Semantics instead of delete than add. +.. option:: --routing-table <tableno> + + Specify which kernel routing table *Zebra* should communicate with. + If this option is not specified the default table (RT_TABLE_MAIN) is + used. + .. option:: --asic-offload=[notify_on_offload|notify_on_ack] The linux kernel has the ability to use asic-offload ( see switchdev @@ -87,6 +93,13 @@ Besides the common invocation options (:ref:`common-invocation-options`), the Allow zebra to modify the default receive buffer size to SIZE in bytes. Under \*BSD only the -s option is available. +.. option:: --v6-with-v4-nexthops + + Signal to zebra that v6 routes with v4 nexthops are accepted + by the underlying dataplane. This will be communicated to + the upper level daemons that can install v6 routes with v4 + nexthops. + .. _interface-commands: Configuration Addresses behaviour @@ -156,12 +169,13 @@ Standard Commands Set description for the interface. -.. clicmd:: mpls enable +.. clicmd:: mpls <enable|disable> - Enable or disable mpls kernel processing on the interface, for linux. Interfaces + Choose mpls kernel processing value on the interface, for linux. Interfaces configured with mpls will not automatically turn on if mpls kernel modules do not - happen to be loaded. This command will fail on 3.X linux kernels and does not - work on non-linux systems at all. + happen to be loaded. This command will fail on 3.X linux kernels and does not + work on non-linux systems at all. 'enable' and 'disable' will respectively turn + on and off mpls on the given interface. .. clicmd:: multicast @@ -320,11 +334,15 @@ the default route. Allow IPv4 nexthop tracking to resolve via the default route. This parameter is configured per-VRF, so the command is also available in the VRF subnode. + This is enabled by default for a traditional profile. + .. clicmd:: ipv6 nht resolve-via-default Allow IPv6 nexthop tracking to resolve via the default route. This parameter is configured per-VRF, so the command is also available in the VRF subnode. + This is enabled by default for a traditional profile. + .. clicmd:: show ip nht [vrf NAME] [A.B.C.D|X:X::X:X] [mrib] [json] Show nexthop tracking status for address resolution. If vrf is not specified @@ -356,6 +374,8 @@ outgoing interface Resolve PBR nexthop via ip neigh tracking +.. _administrative-distance: + Administrative Distance ======================= @@ -402,16 +422,34 @@ the same distances that other routing suites have chosen. +------------+-----------+ An admin distance of 255 indicates to Zebra that the route should not be -installed into the Data Plane. Additionally routes with an admin distance +installed into the Data Plane. Additionally routes with an admin distance of 255 will not be redistributed. Zebra does treat Kernel routes as special case for the purposes of Admin -Distance. Upon learning about a route that is not originated by FRR -we read the metric value as a uint32_t. The top byte of the value +Distance. Upon learning about a route that is not originated by FRR +we read the metric value as a uint32_t. The top byte of the value is interpreted as the Administrative Distance and the low three bytes -are read in as the metric. This special case is to facilitate VRF +are read in as the metric. This special case is to facilitate VRF default routes. +.. code-block:: shell + + $ # Set administrative distance to 255 for Zebra + $ ip route add 192.0.2.0/24 metric $(( 2**32 - 2**24 )) dev lo + $ vtysh -c 'show ip route 192.0.2.0/24 json' | jq '."192.0.2.0/24"[] | (.distance, .metric)' + 255 + 0 + $ # Set administrative distance to 192 for Zebra + $ ip route add 192.0.2.0/24 metric $(( 2**31 + 2**30 )) dev lo + $ vtysh -c 'show ip route 192.0.2.0/24 json' | jq '."192.0.2.0/24"[] | (.distance, .metric)' + 192 + 0 + $ # Set administrative distance to 128, and metric 100 for Zebra + $ ip route add 192.0.2.0/24 metric $(( 2**31 + 100 )) dev lo + $ vtysh -c 'show ip route 192.0.2.0/24 json' | jq '."192.0.2.0/24"[] | (.distance, .metric)' + 128 + 100 + Route Replace Semantics ======================= @@ -745,6 +783,44 @@ presence of the entry. 21 Static 10.125.0.2 IPv4 Explicit Null +MPLS label chunks +----------------- + +MPLS label chunks are handled in the zebra label manager service, +which ensures a same label value or label chunk can not be used by +multiple CP routing daemons at the same time. + +Label requests originate from CP routing daemons, and are resolved +over the default MPLS range (16-1048575). There are two kind of +requests: +- Static label requests request an exact label value or range. For +instance, segment routing label blocks requests originating from +IS-IS are part of it. +- Dynamic label requests only need a range of label values. The +'bgp l3vpn export auto' command uses such requests. + +Allocated label chunks table can be dumped using the command + +.. clicmd:: show debugging label-table + +:: + + zebra# show debugging label-table + Proto ospf: [300/350] + Proto srte: [500/500] + Proto isis: [1200/1300] + Proto ospf: [20000/21000] + Proto isis: [22000/23000] + +.. clicmd:: mpls label dynamic-block (16-1048575) (16-1048575) + + Define a range of labels where dynamic label requests will + allocate label chunks from. This command guarantees that + static label values outside that range will not conflict + with the dynamic label requests. When the dynamic-block + range is configured, static label requests that match that + range are not accepted. + .. _zebra-srv6: Segment-Routing IPv6 @@ -762,6 +838,35 @@ FRR's cli or frr.conf or zebra.conf. This section shows how to configure SRv6 on FRR. Of course SRv6 can be used as standalone, and this section also helps that case. +.. clicmd:: show segment-routing srv6 manager [json] + + This command dumps the SRv6 information configured on zebra, including + the encapsulation parameters (e.g., the IPv6 source address used for + the encapsulated packets). + + Example:: + + router# sh segment-routing srv6 manager + Parameters: + Encapsulation: + Source Address: + Configured: fc00:0:1::1 + + + To get the same information in json format, you can use the ``json`` keyword:: + + rose-srv6# sh segment-routing srv6 manager json + { + "parameters":{ + "encapsulation":{ + "sourceAddress":{ + "configured":"fc00:0:1::1" + } + } + } + } + + .. clicmd:: show segment-routing srv6 locator [json] This command dump SRv6-locator configured on zebra. SRv6-locator is used @@ -922,6 +1027,14 @@ and this section also helps that case. ! ... +.. clicmd:: encapsulation + + Configure parameters for SRv6 encapsulation. + +.. clicmd:: source-address X:X::X:X + + Configure the source address of the outer encapsulating IPv6 header. + .. _multicast-rib-commands: Multicast RIB Commands @@ -1220,6 +1333,12 @@ FPM Commands The ``no`` form uses the old known FPM behavior of including next hop information in the route (e.g. ``RTM_NEWROUTE``) messages. +.. clicmd:: fpm use-route-replace + + Use the netlink ``NLM_F_REPLACE`` flag for updating routes instead of + two different messages to update a route + (``RTM_DELROUTE`` + ``RTM_NEWROUTE``). + .. clicmd:: show fpm counters [json] Show the FPM statistics (plain text or JSON formatted). @@ -1377,8 +1496,6 @@ zebra Terminal Mode Commands .. clicmd:: show ip prefix-list [NAME] -.. clicmd:: show route-map [NAME] - .. clicmd:: show ip protocol .. clicmd:: show ip forward diff --git a/docker/alpine/Dockerfile b/docker/alpine/Dockerfile index 54621a49fd..98e8407498 100644 --- a/docker/alpine/Dockerfile +++ b/docker/alpine/Dockerfile @@ -1,7 +1,7 @@ # syntax=docker/dockerfile:1 # Create a basic stage set up to build APKs -FROM alpine:3.17 as alpine-builder +FROM alpine:3.18 as alpine-builder RUN apk add \ --update-cache \ abuild \ @@ -12,22 +12,29 @@ RUN apk add \ && echo 'builder ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers RUN adduser -D -G abuild builder && su builder -c 'abuild-keygen -a -n' -# This stage builds a dist tarball from the source -FROM alpine:3.17 as source-builder +# This stage builds an APK for libyang +FROM alpine-builder as alpine-apk-builder-libyang +RUN mkdir -p /src/libyang +COPY docker/alpine/libyang/APKBUILD /src/libyang +RUN chown -R builder /pkgs /src +USER builder +RUN cd /src/libyang \ + && abuild checksum \ + && git init \ + && abuild -r -P /pkgs/apk -RUN mkdir -p /src/alpine +# This stage builds a dist tarball from the source +FROM alpine:3.18 as source-builder +RUN mkdir -p /src/alpine /pkgs/apk COPY alpine/APKBUILD.in /src/alpine +COPY --from=alpine-apk-builder-libyang /pkgs/apk/src /pkgs/apk +RUN cd /pkgs/apk && apk add --allow-untrusted */*.apk RUN source /src/alpine/APKBUILD.in \ && apk add \ --no-cache \ --update-cache \ $makedepends \ - gzip \ - py-pip \ - rtrlib \ - protobuf-c-dev \ && pip install pytest -RUN mkdir -p /pkgs/apk COPY . /src ARG PKGVER RUN cd /src \ @@ -40,6 +47,8 @@ RUN cd /src \ # This stage builds an APK from the dist tarball FROM alpine-builder as alpine-apk-builder COPY --from=source-builder /src/frr-*.tar.gz /src/alpine/* /dist/ +COPY --from=alpine-apk-builder-libyang /pkgs/apk/src /pkgs/apk +RUN cd /pkgs/apk && apk add --allow-untrusted */*.apk RUN find /pkgs/apk -type f -name APKINDEX.tar.gz -delete RUN chown -R builder /dist /pkgs USER builder @@ -49,7 +58,7 @@ RUN cd /dist \ && abuild -r -P /pkgs/apk # This stage installs frr from the apk -FROM alpine:3.17 +FROM alpine:3.18 RUN mkdir -p /pkgs/apk COPY --from=alpine-apk-builder /pkgs/apk/ /pkgs/apk/ RUN apk add \ diff --git a/docker/alpine/libyang/APKBUILD b/docker/alpine/libyang/APKBUILD index aa792e7f0b..04e943fe48 100755 --- a/docker/alpine/libyang/APKBUILD +++ b/docker/alpine/libyang/APKBUILD @@ -1,7 +1,7 @@ # Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net> # Maintainer: Christian Franke <nobody@nowhere.ws> pkgname=libyang -pkgver=2.0.194 +pkgver=2.1.80 pkgrel=0 pkgdesc="YANG data modelling language parser and toolkit" url="https://github.com/CESNET/libyang" diff --git a/docker/centos-8/Dockerfile b/docker/centos-8/Dockerfile index 88a7d6a007..baed1fe4f3 100644 --- a/docker/centos-8/Dockerfile +++ b/docker/centos-8/Dockerfile @@ -10,8 +10,8 @@ RUN dnf install --enablerepo=powertools -y rpm-build git autoconf pcre-devel \ groff pkgconfig json-c-devel pam-devel bison flex python3-pytest \ c-ares-devel python3-devel python3-sphinx libcap-devel platform-python-devel \ protobuf-c-devel \ - https://ci1.netdef.org/artifact/LIBYANG-LIBYANGV2/shared/build-2/CentOS-8-x86_64-Packages/libyang2-2.0.0.10.g2eb910e4-1.el8.x86_64.rpm \ - https://ci1.netdef.org/artifact/LIBYANG-LIBYANGV2/shared/build-2/CentOS-8-x86_64-Packages/libyang2-devel-2.0.0.10.g2eb910e4-1.el8.x86_64.rpm \ + https://ci1.netdef.org/artifact/LIBYANG-LIBYANG2/shared/build-00181/RedHat-8-x86_64-Packages/libyang-2.1.80-1.el8.x86_64.rpm \ + https://ci1.netdef.org/artifact/LIBYANG-LIBYANG2/shared/build-00181/RedHat-8-x86_64-Packages/libyang-devel-2.1.80-1.el8.x86_64.rpm \ https://ci1.netdef.org/artifact/RPKI-RTRLIB/shared/build-00146/CentOS-7-x86_64-Packages/librtr-0.8.0-1.el7.x86_64.rpm \ https://ci1.netdef.org/artifact/RPKI-RTRLIB/shared/build-00146/CentOS-7-x86_64-Packages/librtr-devel-0.8.0-1.el7.x86_64.rpm @@ -42,7 +42,7 @@ RUN sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-* \ && sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-* RUN mkdir -p /pkgs/rpm \ - && yum install -y https://ci1.netdef.org/artifact/LIBYANG-LIBYANGV2/shared/build-2/CentOS-8-x86_64-Packages/libyang2-2.0.0.10.g2eb910e4-1.el8.x86_64.rpm \ + && yum install -y https://ci1.netdef.org/artifact/LIBYANG-LIBYANG2/shared/build-00181/RedHat-8-x86_64-Packages/libyang-2.1.80-1.el8.x86_64.rpm \ https://ci1.netdef.org/artifact/RPKI-RTRLIB/shared/build-00146/CentOS-7-x86_64-Packages/librtr-0.8.0-1.el7.x86_64.rpm COPY --from=centos-8-builder /rpmbuild/RPMS/ /pkgs/rpm/ diff --git a/docker/ubi8-minimal/Dockerfile b/docker/ubi8-minimal/Dockerfile index adb04219be..14a5cddbec 100644 --- a/docker/ubi8-minimal/Dockerfile +++ b/docker/ubi8-minimal/Dockerfile @@ -10,6 +10,7 @@ ADD docker/ubi8-minimal/almalinux.repo /etc/yum.repos.d/almalinux.repo # and later reinstall it again: https://bugzilla.redhat.com/show_bug.cgi?id=1668185 RUN rpm --quiet -e --nodeps tzdata >/dev/null 2>&1 +# Keep the list of dependencies alphabetically sorted for easier maintenance RUN microdnf --disableplugin=subscription-manager --setopt=install_weak_deps=0 install \ autoconf \ automake \ @@ -29,6 +30,7 @@ RUN microdnf --disableplugin=subscription-manager --setopt=install_weak_deps=0 i pcre-devel \ pkgconfig \ platform-python-devel \ + protobuf-c-devel \ python3-devel \ python3-pytest \ python3-sphinx \ @@ -39,11 +41,11 @@ RUN microdnf --disableplugin=subscription-manager --setopt=install_weak_deps=0 i tzdata \ && microdnf --disableplugin=subscription-manager clean all -RUN curl -sSL -o /tmp/libyang2.rpm https://ci1.netdef.org/artifact/LIBYANG-LIBYANGV2/shared/build-12/RedHat-8-x86_64-Packages/libyang2-2.0.7-1.el8.x86_64.rpm \ +RUN curl -sSL -o /tmp/libyang2.rpm https://ci1.netdef.org/artifact/LIBYANG-LIBYANG2/shared/build-181/RedHat-8-x86_64-Packages/libyang-2.1.80-1.el8.x86_64.rpm \ && rpm -i /tmp/libyang2.rpm \ && rm -f /tmp/libyang2.rpm -RUN curl -sSL -o /tmp/libyang2-devel.rpm https://ci1.netdef.org/artifact/LIBYANG-LIBYANGV2/shared/build-12/RedHat-8-x86_64-Packages/libyang2-devel-2.0.7-1.el8.x86_64.rpm \ +RUN curl -sSL -o /tmp/libyang2-devel.rpm https://ci1.netdef.org/artifact/LIBYANG-LIBYANG2/shared/build-181/RedHat-8-x86_64-Packages/libyang-devel-2.1.80-1.el8.x86_64.rpm \ && rpm -i /tmp/libyang2-devel.rpm \ && rm -f /tmp/libyang2-devel.rpm @@ -91,18 +93,20 @@ ADD docker/ubi8-minimal/almalinux.repo /etc/yum.repos.d/almalinux.repo RUN rpm --import https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux-8 +# Keep the list of dependencies alphabetically sorted for easier maintenance RUN microdnf --disableplugin=subscription-manager --setopt=install_weak_deps=0 install \ c-ares \ initscripts \ net-snmp-agent-libs \ net-snmp-libs \ openssl \ + protobuf-c \ python3 \ shadow-utils \ systemd \ && microdnf --disableplugin=subscription-manager clean all -RUN curl -sSL -o /tmp/libyang2.rpm https://ci1.netdef.org/artifact/LIBYANG-LIBYANGV2/shared/build-12/RedHat-8-x86_64-Packages/libyang2-2.0.7-1.el8.x86_64.rpm \ +RUN curl -sSL -o /tmp/libyang2.rpm https://ci1.netdef.org/artifact/LIBYANG-LIBYANG2/shared/build-181/RedHat-8-x86_64-Packages/libyang-2.1.80-1.el8.x86_64.rpm \ && rpm -i /tmp/libyang2.rpm \ && rm -f /tmp/libyang2.rpm diff --git a/docker/ubuntu-ci/Dockerfile b/docker/ubuntu-ci/Dockerfile new file mode 100644 index 0000000000..5cdbdb0f3d --- /dev/null +++ b/docker/ubuntu-ci/Dockerfile @@ -0,0 +1,132 @@ +ARG UBUNTU_VERSION=22.04 +FROM ubuntu:$UBUNTU_VERSION + +ARG DEBIAN_FRONTEND=noninteractive +ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn + +# Update and install build requirements. +RUN apt update && apt upgrade -y && \ + # Basic build requirements from documentation + apt-get install -y \ + autoconf \ + automake \ + bison \ + build-essential \ + flex \ + git \ + install-info \ + libc-ares-dev \ + libcap-dev \ + libelf-dev \ + libjson-c-dev \ + libpam0g-dev \ + libreadline-dev \ + libsnmp-dev \ + libsqlite3-dev \ + libtool \ + make \ + perl \ + pkg-config \ + python3-dev \ + python3-sphinx \ + texinfo \ + && \ + # Protobuf build requirements + apt-get install -y \ + libprotobuf-c-dev \ + protobuf-c-compiler \ + && \ + # Libyang2 extra build requirements + apt-get install -y \ + cmake \ + libpcre2-dev \ + && \ + # GRPC extra build requirements + apt-get install -y \ + libgrpc-dev \ + libgrpc++-dev \ + protobuf-compiler-grpc \ + && \ + # Runtime/triage/testing requirements + apt-get install -y \ + curl \ + gdb \ + kmod \ + iproute2 \ + iputils-ping \ + liblua5.3-dev \ + libssl-dev \ + lua5.3 \ + net-tools \ + python3 \ + python3-pip \ + snmp \ + snmp-mibs-downloader \ + snmpd \ + sudo \ + time \ + tshark \ + valgrind \ + yodl \ + && \ + download-mibs && \ + wget https://raw.githubusercontent.com/FRRouting/frr-mibs/main/iana/IANA-IPPM-METRICS-REGISTRY-MIB -O /usr/share/snmp/mibs/iana/IANA-IPPM-METRICS-REGISTRY-MIB && \ + wget https://raw.githubusercontent.com/FRRouting/frr-mibs/main/ietf/SNMPv2-PDU -O /usr/share/snmp/mibs/ietf/SNMPv2-PDU && \ + wget https://raw.githubusercontent.com/FRRouting/frr-mibs/main/ietf/IPATM-IPMC-MIB -O /usr/share/snmp/mibs/ietf/IPATM-IPMC-MIB && \ + python3 -m pip install wheel && \ + python3 -m pip install pytest && \ + python3 -m pip install pytest-sugar && \ + python3 -m pip install pytest-xdist && \ + python3 -m pip install "scapy>=2.4.2" && \ + python3 -m pip install xmltodict && \ + python3 -m pip install grpcio grpcio-tools && \ + python3 -m pip install git+https://github.com/Exa-Networks/exabgp@0659057837cd6c6351579e9f0fa47e9fb7de7311 + +RUN groupadd -r -g 92 frr && \ + groupadd -r -g 85 frrvty && \ + adduser --system --ingroup frr --home /home/frr \ + --gecos "FRR suite" --shell /bin/bash frr && \ + usermod -a -G frrvty frr && \ + useradd -d /var/run/exabgp/ -s /bin/false exabgp && \ + echo 'frr ALL = NOPASSWD: ALL' | tee /etc/sudoers.d/frr && \ + mkdir -p /home/frr && chown frr.frr /home/frr + +USER frr:frr + +# build and install libyang2 +RUN cd && pwd && ls -al && \ + git clone https://github.com/CESNET/libyang.git && \ + cd libyang && \ + git checkout v2.1.128 && \ + mkdir build; cd build && \ + cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr \ + -DCMAKE_BUILD_TYPE:String="Release" .. && \ + make -j $(nproc) && \ + sudo make install + +COPY --chown=frr:frr . /home/frr/frr/ + +RUN cd ~/frr && \ + ./bootstrap.sh && \ + ./configure \ + --prefix=/usr \ + --localstatedir=/var/run/frr \ + --sbindir=/usr/lib/frr \ + --sysconfdir=/etc/frr \ + --enable-sharpd \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-config-rollbacks \ + --enable-grpc \ + --enable-vty-group=frrvty \ + --enable-snmp=agentx \ + --enable-scripting \ + --with-pkg-extra-version=-my-manual-build && \ + make -j $(nproc) && \ + sudo make install + +RUN cd ~/frr && make check || true + +COPY docker/ubuntu-ci/docker-start /usr/sbin/docker-start +CMD ["/usr/sbin/docker-start"] diff --git a/docker/ubuntu18-ci/docker-start b/docker/ubuntu-ci/docker-start similarity index 100% rename from docker/ubuntu18-ci/docker-start rename to docker/ubuntu-ci/docker-start diff --git a/docker/ubuntu18-ci/Dockerfile b/docker/ubuntu18-ci/Dockerfile deleted file mode 100644 index dab8606739..0000000000 --- a/docker/ubuntu18-ci/Dockerfile +++ /dev/null @@ -1,73 +0,0 @@ -FROM ubuntu:18.04 - -ARG DEBIAN_FRONTEND=noninteractive -ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn -# Update Ubuntu Software repository -RUN apt update && \ - apt-get install -y \ - git autoconf automake libtool make libreadline-dev texinfo \ - pkg-config libpam0g-dev libjson-c-dev bison flex python3-pip \ - libc-ares-dev python3-dev python3-sphinx \ - install-info build-essential libsnmp-dev perl libcap-dev \ - libelf-dev libprotobuf-c-dev protobuf-c-compiler \ - sudo gdb iputils-ping time \ - python-pip net-tools iproute2 && \ - python3 -m pip install wheel && \ - python3 -m pip install pytest && \ - python3 -m pip install pytest-xdist && \ - python3 -m pip install "scapy>=2.4.2" && \ - python3 -m pip install xmltodict && \ - python2 -m pip install 'exabgp<4.0.0' - -RUN groupadd -r -g 92 frr && \ - groupadd -r -g 85 frrvty && \ - adduser --system --ingroup frr --home /home/frr \ - --gecos "FRR suite" --shell /bin/bash frr && \ - usermod -a -G frrvty frr && \ - useradd -d /var/run/exabgp/ -s /bin/false exabgp && \ - echo 'frr ALL = NOPASSWD: ALL' | tee /etc/sudoers.d/frr && \ - mkdir -p /home/frr && chown frr.frr /home/frr - -#for libyang 2 -RUN apt-get install -y cmake libpcre2-dev - -USER frr:frr - -# build and install libyang2 -RUN cd && pwd && ls -al && \ - git clone https://github.com/CESNET/libyang.git && \ - cd libyang && \ - git checkout v2.0.0 && \ - mkdir build; cd build && \ - cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr \ - -DCMAKE_BUILD_TYPE:String="Release" .. && \ - make -j $(nproc) && \ - sudo make install - -COPY --chown=frr:frr . /home/frr/frr/ - -RUN cd && ls -al && ls -al frr - -RUN cd ~/frr && \ - ./bootstrap.sh && \ - ./configure \ - --prefix=/usr \ - --localstatedir=/var/run/frr \ - --sbindir=/usr/lib/frr \ - --sysconfdir=/etc/frr \ - --enable-vtysh \ - --enable-pimd \ - --enable-sharpd \ - --enable-multipath=64 \ - --enable-user=frr \ - --enable-group=frr \ - --enable-vty-group=frrvty \ - --enable-snmp=agentx \ - --with-pkg-extra-version=-my-manual-build && \ - make -j $(nproc) && \ - sudo make install - -RUN cd ~/frr && make check || true - -COPY docker/ubuntu18-ci/docker-start /usr/sbin/docker-start -CMD ["/usr/sbin/docker-start"] diff --git a/docker/ubuntu18-ci/README.md b/docker/ubuntu18-ci/README.md deleted file mode 100644 index 4e8ab891e6..0000000000 --- a/docker/ubuntu18-ci/README.md +++ /dev/null @@ -1,44 +0,0 @@ -# Ubuntu 18.04 - -This builds an ubuntu 18.04 container for dev / test - -# Build - -``` -docker build -t frr-ubuntu18:latest -f docker/ubuntu18-ci/Dockerfile . -``` - -# Running - -``` -docker run -d --privileged --name frr-ubuntu18 --mount type=bind,source=/lib/modules,target=/lib/modules frr-ubuntu18:latest -``` - -# make check - -``` -docker exec frr-ubuntu18 bash -c 'cd ~/frr ; make check' -``` - -# interactive bash -``` -docker exec -it frr-ubuntu18 bash -``` - -# topotest -- when Host O/S is Ubuntu only - -``` -docker exec frr-ubuntu18 bash -c 'cd ~/frr/tests/topotests/ospf-topo1 ; sudo pytest test_ospf_topo1.py' -``` - -# stop & remove container - -``` -docker stop frr-ubuntu18 ; docker rm frr-ubuntu18 -``` - -# remove image - -``` -docker rmi frr-ubuntu18:latest -``` diff --git a/docker/ubuntu20-ci/Dockerfile b/docker/ubuntu20-ci/Dockerfile deleted file mode 100644 index 7e49910a72..0000000000 --- a/docker/ubuntu20-ci/Dockerfile +++ /dev/null @@ -1,78 +0,0 @@ -FROM ubuntu:20.04 - -ARG DEBIAN_FRONTEND=noninteractive -ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn -# Update Ubuntu Software repository -RUN apt update && \ - apt-get install -y \ - git autoconf automake libtool make libreadline-dev texinfo \ - pkg-config libpam0g-dev libjson-c-dev bison flex python3-pip \ - libc-ares-dev python3-dev python3-sphinx \ - install-info build-essential libsnmp-dev perl \ - libcap-dev python2 libelf-dev libprotobuf-c-dev protobuf-c-compiler \ - sudo gdb curl iputils-ping time \ - lua5.3 liblua5.3-dev \ - net-tools iproute2 && \ - curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output /tmp/get-pip.py && \ - python2 /tmp/get-pip.py && \ - rm -f /tmp/get-pip.py && \ - python3 -m pip install wheel && \ - python3 -m pip install pytest && \ - python3 -m pip install pytest-xdist && \ - python3 -m pip install "scapy>=2.4.2" && \ - python3 -m pip install xmltodict && \ - python2 -m pip install 'exabgp<4.0.0' - -RUN groupadd -r -g 92 frr && \ - groupadd -r -g 85 frrvty && \ - adduser --system --ingroup frr --home /home/frr \ - --gecos "FRR suite" --shell /bin/bash frr && \ - usermod -a -G frrvty frr && \ - useradd -d /var/run/exabgp/ -s /bin/false exabgp && \ - echo 'frr ALL = NOPASSWD: ALL' | tee /etc/sudoers.d/frr && \ - mkdir -p /home/frr && chown frr.frr /home/frr - -#for libyang 2 -RUN apt-get install -y cmake libpcre2-dev - -USER frr:frr - -# build and install libyang2 -RUN cd && pwd && ls -al && \ - git clone https://github.com/CESNET/libyang.git && \ - cd libyang && \ - git checkout v2.0.0 && \ - mkdir build; cd build && \ - cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr \ - -DCMAKE_BUILD_TYPE:String="Release" .. && \ - make -j $(nproc) && \ - sudo make install - -COPY --chown=frr:frr . /home/frr/frr/ - -RUN cd && ls -al && ls -al frr - -RUN cd ~/frr && \ - ./bootstrap.sh && \ - ./configure \ - --prefix=/usr \ - --localstatedir=/var/run/frr \ - --sbindir=/usr/lib/frr \ - --sysconfdir=/etc/frr \ - --enable-vtysh \ - --enable-pimd \ - --enable-sharpd \ - --enable-multipath=64 \ - --enable-user=frr \ - --enable-group=frr \ - --enable-vty-group=frrvty \ - --enable-snmp=agentx \ - --enable-scripting \ - --with-pkg-extra-version=-my-manual-build && \ - make -j $(nproc) && \ - sudo make install - -RUN cd ~/frr && make check || true - -COPY docker/ubuntu20-ci/docker-start /usr/sbin/docker-start -CMD ["/usr/sbin/docker-start"] diff --git a/docker/ubuntu20-ci/README.md b/docker/ubuntu20-ci/README.md index 11138c6507..6c0ff447dc 100644 --- a/docker/ubuntu20-ci/README.md +++ b/docker/ubuntu20-ci/README.md @@ -5,13 +5,25 @@ This builds an ubuntu 20.04 container for dev / test # Build ``` -docker build -t frr-ubuntu20:latest -f docker/ubuntu20-ci/Dockerfile . +docker build -t frr-ubuntu20:latest --build-arg=UBUNTU_VERSION=20.04 -f docker/ubuntu-ci/Dockerfile . +``` + +# Running Full Topotest + +``` +docker run --init -it --privileged --name frr-ubuntu20 -v /lib/modules:/lib/modules frr-ubuntu20:latest bash -c 'cd ~/frr/tests/topotests ; sudo pytest -nauto --dist=loadfile' +``` + +# Extract results from the above run into `run-results` dir and analyze + +``` +tests/topotests/analyze.py -C frr-ubuntu20 -Ar run-results ``` # Running ``` -docker run -d --privileged --name frr-ubuntu20 --mount type=bind,source=/lib/modules,target=/lib/modules frr-ubuntu20:latest +docker run -d --init --privileged --name frr-ubuntu20 --mount type=bind,source=/lib/modules,target=/lib/modules frr-ubuntu20:latest ``` # make check @@ -29,13 +41,13 @@ docker exec -it frr-ubuntu20 bash # topotest -- when Host O/S is Ubuntu only ``` -docker exec frr-ubuntu20 bash -c 'cd ~/frr/tests/topotests/ospf-topo1 ; sudo pytest test_ospf_topo1.py' +docker exec frr-ubuntu20 bash -c 'cd ~/frr/tests/topotests/ospf_topo1 ; sudo pytest test_ospf_topo1.py' ``` # stop & remove container ``` -docker stop frr-ubuntu20 ; docker rm frr-ubuntu18 +docker stop frr-ubuntu20 ; docker rm frr-ubuntu20 ``` # remove image diff --git a/docker/ubuntu20-ci/docker-start b/docker/ubuntu20-ci/docker-start deleted file mode 100755 index 9a45c722f1..0000000000 --- a/docker/ubuntu20-ci/docker-start +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -if [ $(uname -a | grep -ci Ubuntu) -ge 1 ]; then - #for topotests under ubuntu host - sudo modprobe mpls-router mpls-iptunnel - sudo /etc/init.d/openvswitch-switch start -fi -while true ; do sleep 365d ; done diff --git a/docker/ubuntu22-ci/README.md b/docker/ubuntu22-ci/README.md new file mode 100644 index 0000000000..73f4a1011b --- /dev/null +++ b/docker/ubuntu22-ci/README.md @@ -0,0 +1,57 @@ +# Ubuntu 22.04 + +This builds an ubuntu 22.04 container for dev / test + +# Build + +``` +docker build -t frr-ubuntu22:latest -f docker/ubuntu-ci/Dockerfile . +``` + +# Running Full Topotest + +``` +docker run --init -it --privileged --name frr-ubuntu22 -v /lib/modules:/lib/modules frr-ubuntu22:latest bash -c 'cd ~/frr/tests/topotests ; sudo pytest -nauto --dist=loadfile' +``` + +# Extract results from the above run into `run-results` dir and analyze + +``` +tests/topotests/analyze.py -C frr-ubuntu22 -Ar run-results +``` + +# Running + +``` +docker run -d --init --privileged --name frr-ubuntu22 --mount type=bind,source=/lib/modules,target=/lib/modules frr-ubuntu22:latest +``` + +# make check + +``` +docker exec frr-ubuntu22 bash -c 'cd ~/frr ; make check' +``` + +# interactive bash + +``` +docker exec -it frr-ubuntu22 bash +``` + +# topotest -- when Host O/S is Ubuntu only + +``` +docker exec frr-ubuntu22 bash -c 'cd ~/frr/tests/topotests/ospf_topo1 ; sudo pytest test_ospf_topo1.py' +``` + +# stop & remove container + +``` +docker stop frr-ubuntu22 ; docker rm frr-ubuntu22 +``` + +# remove image + +``` +docker rmi frr-ubuntu22:latest +``` diff --git a/eigrpd/eigrp_cli.c b/eigrpd/eigrp_cli.c index 213834afc8..b961cde871 100644 --- a/eigrpd/eigrp_cli.c +++ b/eigrpd/eigrp_cli.c @@ -69,8 +69,8 @@ DEFPY_YANG( void eigrp_cli_show_header(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - const char *asn = yang_dnode_get_string(dnode, "./asn"); - const char *vrf = yang_dnode_get_string(dnode, "./vrf"); + const char *asn = yang_dnode_get_string(dnode, "asn"); + const char *vrf = yang_dnode_get_string(dnode, "vrf"); vty_out(vty, "router eigrp %s", asn); if (strcmp(vrf, VRF_DEFAULT_NAME)) @@ -323,18 +323,18 @@ void eigrp_cli_show_metrics(struct vty *vty, const struct lyd_node *dnode, { const char *k1, *k2, *k3, *k4, *k5, *k6; - k1 = yang_dnode_exists(dnode, "./K1") ? - yang_dnode_get_string(dnode, "./K1") : "0"; - k2 = yang_dnode_exists(dnode, "./K2") ? - yang_dnode_get_string(dnode, "./K2") : "0"; - k3 = yang_dnode_exists(dnode, "./K3") ? - yang_dnode_get_string(dnode, "./K3") : "0"; - k4 = yang_dnode_exists(dnode, "./K4") ? - yang_dnode_get_string(dnode, "./K4") : "0"; - k5 = yang_dnode_exists(dnode, "./K5") ? - yang_dnode_get_string(dnode, "./K5") : "0"; - k6 = yang_dnode_exists(dnode, "./K6") ? - yang_dnode_get_string(dnode, "./K6") : "0"; + k1 = yang_dnode_exists(dnode, "K1") ? + yang_dnode_get_string(dnode, "K1") : "0"; + k2 = yang_dnode_exists(dnode, "K2") ? + yang_dnode_get_string(dnode, "K2") : "0"; + k3 = yang_dnode_exists(dnode, "K3") ? + yang_dnode_get_string(dnode, "K3") : "0"; + k4 = yang_dnode_exists(dnode, "K4") ? + yang_dnode_get_string(dnode, "K4") : "0"; + k5 = yang_dnode_exists(dnode, "K5") ? + yang_dnode_get_string(dnode, "K5") : "0"; + k6 = yang_dnode_exists(dnode, "K6") ? + yang_dnode_get_string(dnode, "K6") : "0"; vty_out(vty, " metric weights %s %s %s %s %s", k1, k2, k3, k4, k5); @@ -456,19 +456,19 @@ DEFPY_YANG( void eigrp_cli_show_redistribute(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - const char *proto = yang_dnode_get_string(dnode, "./protocol"); + const char *proto = yang_dnode_get_string(dnode, "protocol"); const char *bw, *delay, *load, *mtu, *rlbt; - bw = yang_dnode_exists(dnode, "./metrics/bandwidth") ? - yang_dnode_get_string(dnode, "./metrics/bandwidth") : NULL; - delay = yang_dnode_exists(dnode, "./metrics/delay") ? - yang_dnode_get_string(dnode, "./metrics/delay") : NULL; - rlbt = yang_dnode_exists(dnode, "./metrics/reliability") ? - yang_dnode_get_string(dnode, "./metrics/reliability") : NULL; - load = yang_dnode_exists(dnode, "./metrics/load") ? - yang_dnode_get_string(dnode, "./metrics/load") : NULL; - mtu = yang_dnode_exists(dnode, "./metrics/mtu") ? - yang_dnode_get_string(dnode, "./metrics/mtu") : NULL; + bw = yang_dnode_exists(dnode, "metrics/bandwidth") ? + yang_dnode_get_string(dnode, "metrics/bandwidth") : NULL; + delay = yang_dnode_exists(dnode, "metrics/delay") ? + yang_dnode_get_string(dnode, "metrics/delay") : NULL; + rlbt = yang_dnode_exists(dnode, "metrics/reliability") ? + yang_dnode_get_string(dnode, "metrics/reliability") : NULL; + load = yang_dnode_exists(dnode, "metrics/load") ? + yang_dnode_get_string(dnode, "metrics/load") : NULL; + mtu = yang_dnode_exists(dnode, "metrics/mtu") ? + yang_dnode_get_string(dnode, "metrics/mtu") : NULL; vty_out(vty, " redistribute %s", proto); if (bw || rlbt || delay || load || mtu) @@ -693,7 +693,7 @@ void eigrp_cli_show_summarize_address(struct vty *vty, { const struct lyd_node *instance = yang_dnode_get_parent(dnode, "instance"); - uint16_t asn = yang_dnode_get_uint16(instance, "./asn"); + uint16_t asn = yang_dnode_get_uint16(instance, "asn"); const char *summarize_address = yang_dnode_get_string(dnode, NULL); vty_out(vty, " ip summary-address eigrp %d %s\n", asn, @@ -759,7 +759,7 @@ void eigrp_cli_show_authentication(struct vty *vty, { const struct lyd_node *instance = yang_dnode_get_parent(dnode, "instance"); - uint16_t asn = yang_dnode_get_uint16(instance, "./asn"); + uint16_t asn = yang_dnode_get_uint16(instance, "asn"); const char *crypt = yang_dnode_get_string(dnode, NULL); vty_out(vty, " ip authentication mode eigrp %d %s\n", asn, crypt); @@ -819,7 +819,7 @@ void eigrp_cli_show_keychain(struct vty *vty, const struct lyd_node *dnode, { const struct lyd_node *instance = yang_dnode_get_parent(dnode, "instance"); - uint16_t asn = yang_dnode_get_uint16(instance, "./asn"); + uint16_t asn = yang_dnode_get_uint16(instance, "asn"); const char *keychain = yang_dnode_get_string(dnode, NULL); vty_out(vty, " ip authentication key-chain eigrp %d %s\n", asn, diff --git a/eigrpd/eigrp_hello.c b/eigrpd/eigrp_hello.c index 662c750e96..ee0e2451a2 100644 --- a/eigrpd/eigrp_hello.c +++ b/eigrpd/eigrp_hello.c @@ -772,7 +772,7 @@ void eigrp_hello_send(struct eigrp_interface *ei, uint8_t flags, if (ei->eigrp->t_write == NULL) { if (flags & EIGRP_HELLO_GRACEFUL_SHUTDOWN) { event_execute(master, eigrp_write, ei->eigrp, - ei->eigrp->fd); + ei->eigrp->fd, NULL); } else { event_add_write(master, eigrp_write, ei->eigrp, ei->eigrp->fd, diff --git a/eigrpd/eigrp_interface.c b/eigrpd/eigrp_interface.c index 2381977dba..fb8f47e723 100644 --- a/eigrpd/eigrp_interface.c +++ b/eigrpd/eigrp_interface.c @@ -43,8 +43,7 @@ #include "eigrpd/eigrp_types.h" #include "eigrpd/eigrp_metric.h" -DEFINE_MTYPE_STATIC(EIGRPD, EIGRP_IF, "EIGRP interface"); -DEFINE_MTYPE_STATIC(EIGRPD, EIGRP_IF_INFO, "EIGRP Interface Information"); +DEFINE_MTYPE_STATIC(EIGRPD, EIGRP_IF, "EIGRP interface"); struct eigrp_interface *eigrp_if_new(struct eigrp *eigrp, struct interface *ifp, struct prefix *p) @@ -110,7 +109,7 @@ int eigrp_if_delete_hook(struct interface *ifp) eigrp_fifo_free(ei->obuf); - XFREE(MTYPE_EIGRP_IF_INFO, ifp->info); + XFREE(MTYPE_EIGRP_IF, ifp->info); return 0; } @@ -203,8 +202,10 @@ struct list *eigrp_iflist; void eigrp_if_init(void) { - if_zapi_callbacks(eigrp_ifp_create, eigrp_ifp_up, - eigrp_ifp_down, eigrp_ifp_destroy); + hook_register_prio(if_real, 0, eigrp_ifp_create); + hook_register_prio(if_up, 0, eigrp_ifp_up); + hook_register_prio(if_down, 0, eigrp_ifp_down); + hook_register_prio(if_unreal, 0, eigrp_ifp_destroy); /* Initialize Zebra interface data structure. */ // hook_register_prio(if_add, 0, eigrp_if_new); hook_register_prio(if_del, 0, eigrp_if_delete_hook); diff --git a/eigrpd/eigrp_main.c b/eigrpd/eigrp_main.c index 6d7443b791..634bf1772e 100644 --- a/eigrpd/eigrp_main.c +++ b/eigrpd/eigrp_main.c @@ -96,6 +96,8 @@ static void sigint(void) zlog_notice("Terminating on signal"); eigrp_terminate(); + keychain_terminate(); + exit(0); } diff --git a/eigrpd/eigrp_network.c b/eigrpd/eigrp_network.c index ef567fe4ef..5ca5a18a97 100644 --- a/eigrpd/eigrp_network.c +++ b/eigrpd/eigrp_network.c @@ -233,13 +233,11 @@ static void eigrp_network_run_interface(struct eigrp *eigrp, struct prefix *p, struct interface *ifp) { struct eigrp_interface *ei; - struct listnode *cnode; struct connected *co; /* if interface prefix is match specified prefix, then create socket and join multicast group. */ - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, co)) { - + frr_each (if_connected, ifp->connected, co) { if (CHECK_FLAG(co->flags, ZEBRA_IFA_SECONDARY)) continue; diff --git a/eigrpd/eigrp_northbound.c b/eigrpd/eigrp_northbound.c index 74a4dcb858..562c292e2a 100644 --- a/eigrpd/eigrp_northbound.c +++ b/eigrpd/eigrp_northbound.c @@ -28,18 +28,18 @@ static void redistribute_get_metrics(const struct lyd_node *dnode, { memset(em, 0, sizeof(*em)); - if (yang_dnode_exists(dnode, "./bandwidth")) - em->bandwidth = yang_dnode_get_uint32(dnode, "./bandwidth"); - if (yang_dnode_exists(dnode, "./delay")) - em->delay = yang_dnode_get_uint32(dnode, "./delay"); + if (yang_dnode_exists(dnode, "bandwidth")) + em->bandwidth = yang_dnode_get_uint32(dnode, "bandwidth"); + if (yang_dnode_exists(dnode, "delay")) + em->delay = yang_dnode_get_uint32(dnode, "delay"); #if 0 /* TODO: How does MTU work? */ - if (yang_dnode_exists(dnode, "./mtu")) - em->mtu[0] = yang_dnode_get_uint32(dnode, "./mtu"); + if (yang_dnode_exists(dnode, "mtu")) + em->mtu[0] = yang_dnode_get_uint32(dnode, "mtu"); #endif - if (yang_dnode_exists(dnode, "./load")) - em->load = yang_dnode_get_uint32(dnode, "./load"); - if (yang_dnode_exists(dnode, "./reliability")) - em->reliability = yang_dnode_get_uint32(dnode, "./reliability"); + if (yang_dnode_exists(dnode, "load")) + em->load = yang_dnode_get_uint32(dnode, "load"); + if (yang_dnode_exists(dnode, "reliability")) + em->reliability = yang_dnode_get_uint32(dnode, "reliability"); } static struct eigrp_interface *eigrp_interface_lookup(const struct eigrp *eigrp, @@ -73,7 +73,7 @@ static int eigrpd_instance_create(struct nb_cb_create_args *args) /* NOTHING */ break; case NB_EV_PREPARE: - vrf = yang_dnode_get_string(args->dnode, "./vrf"); + vrf = yang_dnode_get_string(args->dnode, "vrf"); pVrf = vrf_lookup_by_name(vrf); if (pVrf) @@ -81,7 +81,7 @@ static int eigrpd_instance_create(struct nb_cb_create_args *args) else vrfid = VRF_DEFAULT; - eigrp = eigrp_get(yang_dnode_get_uint16(args->dnode, "./asn"), + eigrp = eigrp_get(yang_dnode_get_uint16(args->dnode, "asn"), vrfid); args->resource->ptr = eigrp; break; @@ -715,7 +715,7 @@ static int eigrpd_instance_redistribute_create(struct nb_cb_create_args *args) switch (args->event) { case NB_EV_VALIDATE: - proto = yang_dnode_get_enum(args->dnode, "./protocol"); + proto = yang_dnode_get_enum(args->dnode, "protocol"); vrfname = yang_dnode_get_string(args->dnode, "../vrf"); pVrf = vrf_lookup_by_name(vrfname); @@ -724,7 +724,7 @@ static int eigrpd_instance_redistribute_create(struct nb_cb_create_args *args) else vrfid = VRF_DEFAULT; - if (vrf_bitmap_check(zclient->redist[AFI_IP][proto], vrfid)) + if (vrf_bitmap_check(&zclient->redist[AFI_IP][proto], vrfid)) return NB_ERR_INCONSISTENCY; break; case NB_EV_PREPARE: @@ -733,7 +733,7 @@ static int eigrpd_instance_redistribute_create(struct nb_cb_create_args *args) break; case NB_EV_APPLY: eigrp = nb_running_get_entry(args->dnode, NULL, true); - proto = yang_dnode_get_enum(args->dnode, "./protocol"); + proto = yang_dnode_get_enum(args->dnode, "protocol"); redistribute_get_metrics(args->dnode, &metrics); eigrp_redistribute_set(eigrp, proto, metrics); break; @@ -755,7 +755,7 @@ static int eigrpd_instance_redistribute_destroy(struct nb_cb_destroy_args *args) break; case NB_EV_APPLY: eigrp = nb_running_get_entry(args->dnode, NULL, true); - proto = yang_dnode_get_enum(args->dnode, "./protocol"); + proto = yang_dnode_get_enum(args->dnode, "protocol"); eigrp_redistribute_unset(eigrp, proto); break; } @@ -1120,7 +1120,7 @@ static int lib_interface_eigrp_instance_create(struct nb_cb_create_args *args) break; } - eigrp = eigrp_get(yang_dnode_get_uint16(args->dnode, "./asn"), + eigrp = eigrp_get(yang_dnode_get_uint16(args->dnode, "asn"), ifp->vrf->vrf_id); eif = eigrp_interface_lookup(eigrp, ifp->name); if (eif == NULL) @@ -1132,7 +1132,7 @@ static int lib_interface_eigrp_instance_create(struct nb_cb_create_args *args) break; case NB_EV_APPLY: ifp = nb_running_get_entry(args->dnode, NULL, true); - eigrp = eigrp_get(yang_dnode_get_uint16(args->dnode, "./asn"), + eigrp = eigrp_get(yang_dnode_get_uint16(args->dnode, "asn"), ifp->vrf->vrf_id); eif = eigrp_interface_lookup(eigrp, ifp->name); if (eif == NULL) diff --git a/eigrpd/eigrp_update.c b/eigrpd/eigrp_update.c index 2237a611e8..74f573d9d8 100644 --- a/eigrpd/eigrp_update.c +++ b/eigrpd/eigrp_update.c @@ -842,9 +842,6 @@ static void eigrp_update_send_GR_part(struct eigrp_neighbor *nbr) eigrp_fsm_event(&fsm_msg); } - /* NULL the pointer */ - dest_addr = NULL; - /* delete processed prefix from list */ listnode_delete(prefixes, pe); @@ -916,7 +913,7 @@ void eigrp_update_send_GR_thread(struct event *thread) /* if it wasn't last chunk, schedule this thread again */ if (nbr->nbr_gr_packet_type != EIGRP_PACKET_PART_LAST) { - event_execute(master, eigrp_update_send_GR_thread, nbr, 0); + event_execute(master, eigrp_update_send_GR_thread, nbr, 0, NULL); } } @@ -982,7 +979,7 @@ void eigrp_update_send_GR(struct eigrp_neighbor *nbr, enum GR_type gr_type, /* indicate, that this is first GR Update packet chunk */ nbr->nbr_gr_packet_type = EIGRP_PACKET_PART_FIRST; /* execute packet sending in thread */ - event_execute(master, eigrp_update_send_GR_thread, nbr, 0); + event_execute(master, eigrp_update_send_GR_thread, nbr, 0, NULL); } /** diff --git a/eigrpd/eigrp_zebra.c b/eigrpd/eigrp_zebra.c index 94c2bcab71..a0eff683db 100644 --- a/eigrpd/eigrp_zebra.c +++ b/eigrpd/eigrp_zebra.c @@ -98,9 +98,7 @@ static zclient_handler *const eigrp_handlers[] = { void eigrp_zebra_init(void) { - struct zclient_options opt = {.receive_notify = false}; - - zclient = zclient_new(master, &opt, eigrp_handlers, + zclient = zclient_new(master, &zclient_options_default, eigrp_handlers, array_size(eigrp_handlers)); zclient_init(zclient, ZEBRA_ROUTE_EIGRP, 0, &eigrpd_privs); @@ -249,9 +247,9 @@ void eigrp_zebra_route_delete(struct eigrp *eigrp, struct prefix *p) static int eigrp_is_type_redistributed(int type, vrf_id_t vrf_id) { return ((DEFAULT_ROUTE_TYPE(type)) - ? vrf_bitmap_check(zclient->default_information[AFI_IP], - vrf_id) - : vrf_bitmap_check(zclient->redist[AFI_IP][type], + ? vrf_bitmap_check( + &zclient->default_information[AFI_IP], vrf_id) + : vrf_bitmap_check(&zclient->redist[AFI_IP][type], vrf_id)); } diff --git a/gdb/lib.txt b/gdb/lib.txt index 5d22321b62..435ec7eda7 100644 --- a/gdb/lib.txt +++ b/gdb/lib.txt @@ -306,8 +306,9 @@ define mq_walk end set $mg = $mg->next end +end -document mg_walk +document mq_walk Walk the memory data structures to show what is holding memory. Arguments: @@ -315,3 +316,49 @@ Arguments: sure where to start pass it mg_first, which is a global DS for all memory allocated in FRR end + +define __darr_meta + set $_ = ((struct darr_metadata *)$arg0) - 1 +end +document __darr_meta +Store a pointer to the struct darr_metadata in $_ for the given dynamic array. + +Argument: a pointer to a darr dynamic array. +Returns: pointer to the struct darr_metadata in $_. +end + +define darr_meta + __darr_meta $arg0 + p *$_ +end +document darr_meta +Print the struct darr_metadata for the given dynamic array. Store the value +in $_ as well. + +Argument: a pointer to a darr dynamic array. +Returns: pointer to the struct darr_metadata in $_. +end + +define darr_len + __darr_meta $arg0 + set $_ = $_->len + p $_ +end +document darr_len +Print the length of the given dynamic array, and store in $_. + +Argument: a pointer to a darr dynamic array. +Returns: length of the array. +end + +define darr_cap + __darr_meta $arg0 + set $_ = $_->cap + p $_ +end +document darr_len +Print the capacity of the given dynamic array, and store in $_. + +Argument: a pointer to a darr dynamic array. +Returns: capacity of the array. +end diff --git a/include/linux/seg6.h b/include/linux/seg6.h index 329163e4a0..5b572ba3db 100644 --- a/include/linux/seg6.h +++ b/include/linux/seg6.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +// SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note /* * SR-IPv6 implementation * @@ -30,7 +30,7 @@ struct ipv6_sr_hdr { __u8 flags; __u16 tag; - struct in6_addr segments[0]; + struct in6_addr segments[]; }; #define SR6_FLAG1_PROTECTED (1 << 6) diff --git a/include/linux/seg6_local.h b/include/linux/seg6_local.h index 6788b58799..401c8b0c6e 100644 --- a/include/linux/seg6_local.h +++ b/include/linux/seg6_local.h @@ -23,6 +23,7 @@ enum { SEG6_LOCAL_BPF, SEG6_LOCAL_VRFTABLE, SEG6_LOCAL_COUNTERS, + SEG6_LOCAL_FLAVORS, __SEG6_LOCAL_MAX, }; #define SEG6_LOCAL_MAX (__SEG6_LOCAL_MAX - 1) @@ -105,4 +106,27 @@ enum { #define SEG6_LOCAL_CNT_MAX (__SEG6_LOCAL_CNT_MAX - 1) +/* SRv6 End* Flavor attributes */ +enum { + SEG6_LOCAL_FLV_UNSPEC, + SEG6_LOCAL_FLV_OPERATION, + SEG6_LOCAL_FLV_LCBLOCK_BITS, + SEG6_LOCAL_FLV_LCNODE_FN_BITS, + __SEG6_LOCAL_FLV_MAX, +}; + +#define SEG6_LOCAL_FLV_MAX (__SEG6_LOCAL_FLV_MAX - 1) + +/* Designed flavor operations for SRv6 End* Behavior */ +enum { + SEG6_LOCAL_FLV_OP_UNSPEC, + SEG6_LOCAL_FLV_OP_PSP, + SEG6_LOCAL_FLV_OP_USP, + SEG6_LOCAL_FLV_OP_USD, + SEG6_LOCAL_FLV_OP_NEXT_CSID, + __SEG6_LOCAL_FLV_OP_MAX +}; + +#define SEG6_LOCAL_FLV_OP_MAX (__SEG6_LOCAL_FLV_OP_MAX - 1) + #endif diff --git a/isisd/isis_adjacency.c b/isisd/isis_adjacency.c index 30b71537e0..cba1b91fae 100644 --- a/isisd/isis_adjacency.c +++ b/isisd/isis_adjacency.c @@ -90,6 +90,7 @@ struct isis_adjacency *isis_new_adj(const uint8_t *id, const uint8_t *snpa, } } adj->adj_sids = list_new(); + adj->srv6_endx_sids = list_new(); listnode_add(circuit->area->adjacency_list, adj); return adj; @@ -160,6 +161,7 @@ void isis_delete_adj(void *arg) XFREE(MTYPE_ISIS_ADJACENCY_INFO, adj->global_ipv6_addrs); adj_mt_finish(adj); list_delete(&adj->adj_sids); + list_delete(&adj->srv6_endx_sids); listnode_delete(adj->circuit->area->adjacency_list, adj); XFREE(MTYPE_ISIS_ADJACENCY, adj); diff --git a/isisd/isis_adjacency.h b/isisd/isis_adjacency.h index c0c8e68145..b5c7dd8d73 100644 --- a/isisd/isis_adjacency.h +++ b/isisd/isis_adjacency.h @@ -74,12 +74,10 @@ struct isis_adjacency { struct nlpids nlpids; /* protocols spoken ... */ struct in_addr *ipv4_addresses; unsigned int ipv4_address_count; - struct in_addr router_address; struct in6_addr *ll_ipv6_addrs; /* Link local IPv6 neighbor address */ unsigned int ll_ipv6_count; struct in6_addr *global_ipv6_addrs; /* Global IPv6 neighbor address */ unsigned int global_ipv6_count; - struct in6_addr router_address6; uint8_t prio[ISIS_LEVELS]; /* priorityOfNeighbour for DIS */ int circuit_t; /* from hello PDU hdr */ int level; /* level (1 or 2) */ @@ -98,6 +96,8 @@ struct isis_adjacency { struct list *adj_sids; /* Segment Routing Adj-SIDs. */ uint32_t snmp_idx; struct listnode *snmp_list_node; + + struct list *srv6_endx_sids; /* SRv6 End.X SIDs. */ }; struct isis_threeway_adj; diff --git a/isisd/isis_bpf.c b/isisd/isis_bpf.c index 96d629124d..47f51a7548 100644 --- a/isisd/isis_bpf.c +++ b/isisd/isis_bpf.c @@ -8,6 +8,9 @@ */ #include <zebra.h> + +#include <fcntl.h> + #if ISIS_METHOD == ISIS_METHOD_BPF #include <net/if.h> #include <netinet/if_ether.h> diff --git a/isisd/isis_circuit.c b/isisd/isis_circuit.c index feab451233..7819b20e8f 100644 --- a/isisd/isis_circuit.c +++ b/isisd/isis_circuit.c @@ -41,6 +41,7 @@ #include "isisd/isisd.h" #include "isisd/isis_csm.h" #include "isisd/isis_events.h" +#include "isisd/isis_srv6.h" #include "isisd/isis_te.h" #include "isisd/isis_mt.h" #include "isisd/isis_errors.h" @@ -488,7 +489,6 @@ static uint8_t isis_circuit_id_gen(struct isis *isis, struct interface *ifp) void isis_circuit_if_add(struct isis_circuit *circuit, struct interface *ifp) { - struct listnode *node, *nnode; struct connected *conn; if (if_is_broadcast(ifp)) { @@ -508,20 +508,18 @@ void isis_circuit_if_add(struct isis_circuit *circuit, struct interface *ifp) circuit->circ_type = CIRCUIT_T_UNKNOWN; } - for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, conn)) + frr_each (if_connected, ifp->connected, conn) isis_circuit_add_addr(circuit, conn); - } void isis_circuit_if_del(struct isis_circuit *circuit, struct interface *ifp) { - struct listnode *node, *nnode; struct connected *conn; assert(circuit->interface == ifp); /* destroy addresses */ - for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, conn)) + frr_each_safe (if_connected, ifp->connected, conn) isis_circuit_del_addr(circuit, conn); circuit->circ_type = CIRCUIT_T_UNKNOWN; @@ -1631,6 +1629,9 @@ static int isis_ifp_up(struct interface *ifp) isis_csm_state_change(IF_UP_FROM_Z, circuit, ifp); } + /* Notify SRv6 that the interface went up */ + isis_srv6_ifp_up_notify(ifp); + return 0; } @@ -1676,6 +1677,8 @@ void isis_circuit_init(void) #else if_cmd_init_default(); #endif - if_zapi_callbacks(isis_ifp_create, isis_ifp_up, - isis_ifp_down, isis_ifp_destroy); + hook_register_prio(if_real, 0, isis_ifp_create); + hook_register_prio(if_up, 0, isis_ifp_up); + hook_register_prio(if_down, 0, isis_ifp_down); + hook_register_prio(if_unreal, 0, isis_ifp_destroy); } diff --git a/isisd/isis_cli.c b/isisd/isis_cli.c index 7c7a8d2389..bcc9456d2c 100644 --- a/isisd/isis_cli.c +++ b/isisd/isis_cli.c @@ -85,13 +85,13 @@ void cli_show_router_isis(struct vty *vty, const struct lyd_node *dnode, { const char *vrf = NULL; - vrf = yang_dnode_get_string(dnode, "./vrf"); + vrf = yang_dnode_get_string(dnode, "vrf"); vty_out(vty, "!\n"); vty_out(vty, "router isis %s", - yang_dnode_get_string(dnode, "./area-tag")); + yang_dnode_get_string(dnode, "area-tag")); if (!strmatch(vrf, VRF_DEFAULT_NAME)) - vty_out(vty, " vrf %s", yang_dnode_get_string(dnode, "./vrf")); + vty_out(vty, " vrf %s", yang_dnode_get_string(dnode, "vrf")); vty_out(vty, "\n"); } @@ -172,7 +172,7 @@ DEFPY_YANG(no_ip_router_isis, no_ip_router_isis_cmd, * If both ipv4 and ipv6 are off delete the interface isis container. */ if (strmatch(ip, "ipv6")) { - if (!yang_dnode_get_bool(dnode, "./ipv4-routing")) + if (!yang_dnode_get_bool(dnode, "ipv4-routing")) nb_cli_enqueue_change(vty, "./frr-isisd:isis", NB_OP_DESTROY, NULL); else @@ -180,7 +180,7 @@ DEFPY_YANG(no_ip_router_isis, no_ip_router_isis_cmd, "./frr-isisd:isis/ipv6-routing", NB_OP_MODIFY, "false"); } else { - if (!yang_dnode_get_bool(dnode, "./ipv6-routing")) + if (!yang_dnode_get_bool(dnode, "ipv6-routing")) nb_cli_enqueue_change(vty, "./frr-isisd:isis", NB_OP_DESTROY, NULL); else @@ -280,16 +280,16 @@ void cli_show_ip_isis_bfd_monitoring(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - if (!yang_dnode_get_bool(dnode, "./enabled")) { + if (!yang_dnode_get_bool(dnode, "enabled")) { if (show_defaults) vty_out(vty, " no isis bfd\n"); } else { vty_out(vty, " isis bfd\n"); } - if (yang_dnode_exists(dnode, "./profile")) + if (yang_dnode_exists(dnode, "profile")) vty_out(vty, " isis bfd profile %s\n", - yang_dnode_get_string(dnode, "./profile")); + yang_dnode_get_string(dnode, "profile")); } /* @@ -588,9 +588,9 @@ void cli_show_isis_area_pwd(struct vty *vty, const struct lyd_node *dnode, const char *snp; vty_out(vty, " area-password %s %s", - yang_dnode_get_string(dnode, "./password-type"), - yang_dnode_get_string(dnode, "./password")); - snp = yang_dnode_get_string(dnode, "./authenticate-snp"); + yang_dnode_get_string(dnode, "password-type"), + yang_dnode_get_string(dnode, "password")); + snp = yang_dnode_get_string(dnode, "authenticate-snp"); if (!strmatch("none", snp)) vty_out(vty, " authenticate snp %s", snp); vty_out(vty, "\n"); @@ -638,9 +638,9 @@ void cli_show_isis_domain_pwd(struct vty *vty, const struct lyd_node *dnode, const char *snp; vty_out(vty, " domain-password %s %s", - yang_dnode_get_string(dnode, "./password-type"), - yang_dnode_get_string(dnode, "./password")); - snp = yang_dnode_get_string(dnode, "./authenticate-snp"); + yang_dnode_get_string(dnode, "password-type"), + yang_dnode_get_string(dnode, "password")); + snp = yang_dnode_get_string(dnode, "authenticate-snp"); if (!strmatch("none", snp)) vty_out(vty, " authenticate snp %s", snp); vty_out(vty, "\n"); @@ -861,17 +861,17 @@ void cli_show_isis_lsp_timers(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { const char *l1_refresh = - yang_dnode_get_string(dnode, "./level-1/refresh-interval"); + yang_dnode_get_string(dnode, "level-1/refresh-interval"); const char *l2_refresh = - yang_dnode_get_string(dnode, "./level-2/refresh-interval"); + yang_dnode_get_string(dnode, "level-2/refresh-interval"); const char *l1_lifetime = - yang_dnode_get_string(dnode, "./level-1/maximum-lifetime"); + yang_dnode_get_string(dnode, "level-1/maximum-lifetime"); const char *l2_lifetime = - yang_dnode_get_string(dnode, "./level-2/maximum-lifetime"); + yang_dnode_get_string(dnode, "level-2/maximum-lifetime"); const char *l1_gen = - yang_dnode_get_string(dnode, "./level-1/generation-interval"); + yang_dnode_get_string(dnode, "level-1/generation-interval"); const char *l2_gen = - yang_dnode_get_string(dnode, "./level-2/generation-interval"); + yang_dnode_get_string(dnode, "level-2/generation-interval"); if (strmatch(l1_refresh, l2_refresh) && strmatch(l1_lifetime, l2_lifetime) && strmatch(l1_gen, l2_gen)) vty_out(vty, @@ -980,8 +980,8 @@ void cli_show_isis_spf_min_interval(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - const char *l1 = yang_dnode_get_string(dnode, "./level-1"); - const char *l2 = yang_dnode_get_string(dnode, "./level-2"); + const char *l1 = yang_dnode_get_string(dnode, "level-1"); + const char *l2 = yang_dnode_get_string(dnode, "level-2"); if (strmatch(l1, l2)) vty_out(vty, " spf-interval %s\n", l1); @@ -1051,11 +1051,11 @@ void cli_show_isis_spf_ietf_backoff(struct vty *vty, { vty_out(vty, " spf-delay-ietf init-delay %s short-delay %s long-delay %s holddown %s time-to-learn %s\n", - yang_dnode_get_string(dnode, "./init-delay"), - yang_dnode_get_string(dnode, "./short-delay"), - yang_dnode_get_string(dnode, "./long-delay"), - yang_dnode_get_string(dnode, "./hold-down"), - yang_dnode_get_string(dnode, "./time-to-learn")); + yang_dnode_get_string(dnode, "init-delay"), + yang_dnode_get_string(dnode, "short-delay"), + yang_dnode_get_string(dnode, "long-delay"), + yang_dnode_get_string(dnode, "hold-down"), + yang_dnode_get_string(dnode, "time-to-learn")); } /* @@ -1364,15 +1364,15 @@ static void vty_print_def_origin(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { vty_out(vty, " default-information originate %s %s", family, level); - if (yang_dnode_get_bool(dnode, "./always")) + if (yang_dnode_get_bool(dnode, "always")) vty_out(vty, " always"); - if (yang_dnode_exists(dnode, "./route-map")) + if (yang_dnode_exists(dnode, "route-map")) vty_out(vty, " route-map %s", - yang_dnode_get_string(dnode, "./route-map")); - if (show_defaults || !yang_dnode_is_default(dnode, "./metric")) + yang_dnode_get_string(dnode, "route-map")); + if (show_defaults || !yang_dnode_is_default(dnode, "metric")) vty_out(vty, " metric %s", - yang_dnode_get_string(dnode, "./metric")); + yang_dnode_get_string(dnode, "metric")); vty_out(vty, "\n"); } @@ -1381,7 +1381,7 @@ void cli_show_isis_def_origin_ipv4(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - const char *level = yang_dnode_get_string(dnode, "./level"); + const char *level = yang_dnode_get_string(dnode, "level"); vty_print_def_origin(vty, dnode, "ipv4", level, show_defaults); } @@ -1390,7 +1390,7 @@ void cli_show_isis_def_origin_ipv6(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - const char *level = yang_dnode_get_string(dnode, "./level"); + const char *level = yang_dnode_get_string(dnode, "level"); vty_print_def_origin(vty, dnode, "ipv6", level, show_defaults); } @@ -1430,20 +1430,99 @@ DEFPY_YANG(isis_redistribute, isis_redistribute_cmd, level); } -static void vty_print_redistribute(struct vty *vty, - const struct lyd_node *dnode, - bool show_defaults, const char *family) -{ - const char *level = yang_dnode_get_string(dnode, "./level"); - const char *protocol = yang_dnode_get_string(dnode, "./protocol"); +/* + * XPath: /frr-isisd:isis/instance/redistribute/table + */ +DEFPY_YANG(isis_redistribute_table, isis_redistribute_table_cmd, + "[no] redistribute <ipv4|ipv6>$ip table (1-65535)$table" + "<level-1|level-2>$level [{metric (0-16777215)|route-map WORD}]", + NO_STR REDIST_STR "Redistribute IPv4 routes\n" + "Redistribute IPv6 routes\n" + "Non-main Kernel Routing Table\n" + "Table Id\n" + "Redistribute into level-1\n" + "Redistribute into level-2\n" + "Metric for redistributed routes\n" + "IS-IS default metric\n" + "Route map reference\n" + "Pointer to route-map entries\n") +{ + struct isis_redist_table_present_args rtda = {}; + char xpath[XPATH_MAXLEN]; + char xpath_entry[XPATH_MAXLEN + 128]; + int rv; - vty_out(vty, " redistribute %s %s %s", family, protocol, level); - if (show_defaults || !yang_dnode_is_default(dnode, "./metric")) + rtda.rtda_table = table_str; + rtda.rtda_ip = ip; + rtda.rtda_level = level; + + if (no) { + if (!isis_redist_table_is_present(vty, &rtda)) + return CMD_WARNING_CONFIG_FAILED; + + snprintf(xpath, sizeof(xpath), "./table[table='%s']", table_str); + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); + rv = nb_cli_apply_changes(vty, + "./redistribute/%s[protocol='table'][level='%s']", + ip, level); + if (rv == CMD_SUCCESS) { + if (isis_redist_table_get_first(vty, &rtda) > 0) + return CMD_SUCCESS; + nb_cli_enqueue_change(vty, "./table", NB_OP_DESTROY, + NULL); + nb_cli_apply_changes(vty, + "./redistribute/%s[protocol='table'][level='%s']", + ip, level); + } + return CMD_SUCCESS; + } + if (isis_redist_table_is_present(vty, &rtda)) + return CMD_SUCCESS; + + snprintf(xpath, sizeof(xpath), "./table[table='%s']", table_str); + nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL); + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); + snprintf(xpath_entry, sizeof(xpath_entry), "%s/route-map", xpath); + nb_cli_enqueue_change(vty, xpath_entry, + route_map ? NB_OP_MODIFY : NB_OP_DESTROY, + route_map ? route_map : NULL); + snprintf(xpath_entry, sizeof(xpath_entry), "%s/metric", xpath); + nb_cli_enqueue_change(vty, xpath_entry, NB_OP_MODIFY, + metric_str ? metric_str : NULL); + return nb_cli_apply_changes(vty, + "./redistribute/%s[protocol='table'][level='%s']", + ip, level); +} + +static void vty_print_redistribute(struct vty *vty, const struct lyd_node *dnode, + bool show_defaults, const char *family, + bool table) +{ + const char *level; + const char *protocol = NULL; + const char *routemap = NULL; + uint16_t tableid; + + if (table) { + level = yang_dnode_get_string(dnode, "../level"); + tableid = yang_dnode_get_uint16(dnode, "table"); + vty_out(vty, " redistribute %s table %d ", family, tableid); + } else { + protocol = yang_dnode_get_string(dnode, "protocol"); + if (!table && strmatch(protocol, "table")) + return; + level = yang_dnode_get_string(dnode, "level"); + vty_out(vty, " redistribute %s %s ", family, protocol); + } + vty_out(vty, "%s", level); + if (show_defaults || !yang_dnode_is_default(dnode, "metric")) vty_out(vty, " metric %s", - yang_dnode_get_string(dnode, "./metric")); - if (yang_dnode_exists(dnode, "./route-map")) - vty_out(vty, " route-map %s", - yang_dnode_get_string(dnode, "./route-map")); + yang_dnode_get_string(dnode, "%s", "metric")); + + if (yang_dnode_exists(dnode, "route-map")) + routemap = yang_dnode_get_string(dnode, "route-map"); + if (routemap) + vty_out(vty, " route-map %s", routemap); vty_out(vty, "\n"); } @@ -1451,13 +1530,37 @@ void cli_show_isis_redistribute_ipv4(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - vty_print_redistribute(vty, dnode, show_defaults, "ipv4"); + vty_print_redistribute(vty, dnode, show_defaults, "ipv4", false); } + void cli_show_isis_redistribute_ipv6(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - vty_print_redistribute(vty, dnode, show_defaults, "ipv6"); + vty_print_redistribute(vty, dnode, show_defaults, "ipv6", false); +} + +void cli_show_isis_redistribute_ipv4_table(struct vty *vty, + const struct lyd_node *dnode, + bool show_defaults) +{ + vty_print_redistribute(vty, dnode, show_defaults, "ipv4", true); +} + +void cli_show_isis_redistribute_ipv6_table(struct vty *vty, + const struct lyd_node *dnode, + bool show_defaults) +{ + vty_print_redistribute(vty, dnode, show_defaults, "ipv6", true); +} + +int cli_cmp_isis_redistribute_table(const struct lyd_node *dnode1, + const struct lyd_node *dnode2) +{ + uint16_t table1 = yang_dnode_get_uint16(dnode1, "table"); + uint16_t table2 = yang_dnode_get_uint16(dnode2, "table"); + + return table1 - table2; } /* @@ -1516,7 +1619,7 @@ void cli_show_isis_mt_ipv4_multicast(struct vty *vty, bool show_defaults) { vty_out(vty, " topology ipv4-multicast"); - if (yang_dnode_get_bool(dnode, "./overload")) + if (yang_dnode_get_bool(dnode, "overload")) vty_out(vty, " overload"); vty_out(vty, "\n"); } @@ -1525,7 +1628,7 @@ void cli_show_isis_mt_ipv4_mgmt(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { vty_out(vty, " topology ipv4-mgmt"); - if (yang_dnode_get_bool(dnode, "./overload")) + if (yang_dnode_get_bool(dnode, "overload")) vty_out(vty, " overload"); vty_out(vty, "\n"); } @@ -1535,7 +1638,7 @@ void cli_show_isis_mt_ipv6_unicast(struct vty *vty, bool show_defaults) { vty_out(vty, " topology ipv6-unicast"); - if (yang_dnode_get_bool(dnode, "./overload")) + if (yang_dnode_get_bool(dnode, "overload")) vty_out(vty, " overload"); vty_out(vty, "\n"); } @@ -1545,7 +1648,7 @@ void cli_show_isis_mt_ipv6_multicast(struct vty *vty, bool show_defaults) { vty_out(vty, " topology ipv6-multicast"); - if (yang_dnode_get_bool(dnode, "./overload")) + if (yang_dnode_get_bool(dnode, "overload")) vty_out(vty, " overload"); vty_out(vty, "\n"); } @@ -1554,7 +1657,7 @@ void cli_show_isis_mt_ipv6_mgmt(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { vty_out(vty, " topology ipv6-mgmt"); - if (yang_dnode_get_bool(dnode, "./overload")) + if (yang_dnode_get_bool(dnode, "overload")) vty_out(vty, " overload"); vty_out(vty, "\n"); } @@ -1563,7 +1666,7 @@ void cli_show_isis_mt_ipv6_dstsrc(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { vty_out(vty, " topology ipv6-dstsrc"); - if (yang_dnode_get_bool(dnode, "./overload")) + if (yang_dnode_get_bool(dnode, "overload")) vty_out(vty, " overload"); vty_out(vty, "\n"); } @@ -1668,13 +1771,13 @@ void cli_show_isis_label_blocks(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { vty_out(vty, " segment-routing global-block %s %s", - yang_dnode_get_string(dnode, "./srgb/lower-bound"), - yang_dnode_get_string(dnode, "./srgb/upper-bound")); - if (!yang_dnode_is_default(dnode, "./srlb/lower-bound") - || !yang_dnode_is_default(dnode, "./srlb/upper-bound")) + yang_dnode_get_string(dnode, "srgb/lower-bound"), + yang_dnode_get_string(dnode, "srgb/upper-bound")); + if (!yang_dnode_is_default(dnode, "srlb/lower-bound") + || !yang_dnode_is_default(dnode, "srlb/upper-bound")) vty_out(vty, " local-block %s %s", - yang_dnode_get_string(dnode, "./srlb/lower-bound"), - yang_dnode_get_string(dnode, "./srlb/upper-bound")); + yang_dnode_get_string(dnode, "srlb/lower-bound"), + yang_dnode_get_string(dnode, "srlb/upper-bound")); vty_out(vty, "\n"); } @@ -1796,11 +1899,11 @@ void cli_show_isis_prefix_sid(struct vty *vty, const struct lyd_node *dnode, const char *sid_value; bool n_flag_clear; - prefix = yang_dnode_get_string(dnode, "./prefix"); - lh_behavior = yang_dnode_get_string(dnode, "./last-hop-behavior"); - sid_value_type = yang_dnode_get_string(dnode, "./sid-value-type"); - sid_value = yang_dnode_get_string(dnode, "./sid-value"); - n_flag_clear = yang_dnode_get_bool(dnode, "./n-flag-clear"); + prefix = yang_dnode_get_string(dnode, "prefix"); + lh_behavior = yang_dnode_get_string(dnode, "last-hop-behavior"); + sid_value_type = yang_dnode_get_string(dnode, "sid-value-type"); + sid_value = yang_dnode_get_string(dnode, "sid-value"); + n_flag_clear = yang_dnode_get_bool(dnode, "n-flag-clear"); vty_out(vty, " segment-routing prefix %s", prefix); if (strmatch(sid_value_type, "absolute")) @@ -1910,12 +2013,12 @@ void cli_show_isis_prefix_sid_algorithm(struct vty *vty, bool n_flag_clear; uint32_t algorithm; - prefix = yang_dnode_get_string(dnode, "./prefix"); - sid_value_type = yang_dnode_get_string(dnode, "./sid-value-type"); - sid_value = yang_dnode_get_string(dnode, "./sid-value"); - algorithm = yang_dnode_get_uint32(dnode, "./algo"); - lh_behavior = yang_dnode_get_string(dnode, "./last-hop-behavior"); - n_flag_clear = yang_dnode_get_bool(dnode, "./n-flag-clear"); + prefix = yang_dnode_get_string(dnode, "prefix"); + sid_value_type = yang_dnode_get_string(dnode, "sid-value-type"); + sid_value = yang_dnode_get_string(dnode, "sid-value"); + algorithm = yang_dnode_get_uint32(dnode, "algo"); + lh_behavior = yang_dnode_get_string(dnode, "last-hop-behavior"); + n_flag_clear = yang_dnode_get_bool(dnode, "n-flag-clear"); vty_out(vty, " segment-routing prefix %s", prefix); vty_out(vty, " algorithm %u", algorithm); @@ -1934,6 +2037,234 @@ void cli_show_isis_prefix_sid_algorithm(struct vty *vty, vty_out(vty, "\n"); } +/* + * XPath: /frr-isisd:isis/instance/segment-routing-srv6/locator + */ +DEFPY (isis_srv6_locator, + isis_srv6_locator_cmd, + "[no] locator NAME$loc_name", + NO_STR + "Specify SRv6 locator\n" + "Specify SRv6 locator\n") +{ + if (no) + nb_cli_enqueue_change(vty, "./locator", NB_OP_DESTROY, loc_name); + else + nb_cli_enqueue_change(vty, "./locator", NB_OP_MODIFY, loc_name); + + return nb_cli_apply_changes(vty, NULL); +} + +void cli_show_isis_srv6_locator(struct vty *vty, const struct lyd_node *dnode, + bool show_defaults) +{ + vty_out(vty, " locator %s\n", yang_dnode_get_string(dnode, NULL)); +} + +/* + * XPath: /frr-isisd:isis/instance/segment-routing-srv6/enabled + */ +DEFPY_YANG_NOSH (isis_srv6_enable, + isis_srv6_enable_cmd, + "segment-routing srv6", + SR_STR + "Enable Segment Routing over IPv6 (SRv6)\n") +{ + int ret; + char xpath[XPATH_MAXLEN + 37]; + + snprintf(xpath, sizeof(xpath), "%s/segment-routing-srv6", + VTY_CURR_XPATH); + + nb_cli_enqueue_change(vty, "./segment-routing-srv6/enabled", + NB_OP_MODIFY, "true"); + + ret = nb_cli_apply_changes(vty, NULL); + if (ret == CMD_SUCCESS) + VTY_PUSH_XPATH(ISIS_SRV6_NODE, xpath); + + return ret; +} + +DEFPY_YANG (no_isis_srv6_enable, + no_isis_srv6_enable_cmd, + "no segment-routing srv6", + NO_STR + SR_STR + "Disable Segment Routing over IPv6 (SRv6)\n") +{ + nb_cli_enqueue_change(vty, "./segment-routing-srv6", NB_OP_DESTROY, + NULL); + + return nb_cli_apply_changes(vty, NULL); +} + +void cli_show_isis_srv6_enabled(struct vty *vty, const struct lyd_node *dnode, + bool show_defaults) +{ + if (!yang_dnode_get_bool(dnode, NULL)) + vty_out(vty, " no"); + + vty_out(vty, " segment-routing srv6\n"); +} + +/* + * XPath: /frr-isisd:isis/instance/segment-routing-srv6/msd/node-msd + */ +DEFPY_YANG_NOSH (isis_srv6_node_msd, + isis_srv6_node_msd_cmd, + "[no] node-msd", + NO_STR + "Segment Routing over IPv6 (SRv6) Maximum SRv6 SID Depths\n") +{ + int ret = CMD_SUCCESS; + char xpath[XPATH_MAXLEN + 37]; + + snprintf(xpath, sizeof(xpath), "%s/msd/node-msd", VTY_CURR_XPATH); + + if (no) { + nb_cli_enqueue_change(vty, "./msd/node_msd/max-segs-left", + NB_OP_DESTROY, NULL); + nb_cli_enqueue_change(vty, "./msd/node_msd/end-pop", + NB_OP_DESTROY, NULL); + nb_cli_enqueue_change(vty, "./msd/node_msd/h-encaps", + NB_OP_DESTROY, NULL); + nb_cli_enqueue_change(vty, "./msd/node_msd/end-d", + NB_OP_DESTROY, NULL); + ret = nb_cli_apply_changes(vty, NULL); + } else + VTY_PUSH_XPATH(ISIS_SRV6_NODE_MSD_NODE, xpath); + + return ret; +} + +/* + * XPath: /frr-isisd:isis/instance/segment-routing-srv6/msd/node-msd/max-segs-left + */ +DEFPY (isis_srv6_node_msd_max_segs_left, + isis_srv6_node_msd_max_segs_left_cmd, + "[no] max-segs-left (0-255)$max_segs_left", + NO_STR + "Specify Maximum Segments Left MSD\n" + "Specify Maximum Segments Left MSD\n") +{ + if (no) + nb_cli_enqueue_change(vty, "./max-segs-left", NB_OP_DESTROY, + NULL); + else + nb_cli_enqueue_change(vty, "./max-segs-left", NB_OP_MODIFY, + max_segs_left_str); + + return nb_cli_apply_changes(vty, NULL); +} + +/* + * XPath: /frr-isisd:isis/instance/segment-routing-srv6/msd/node-msd/max-end-pop + */ +DEFPY (isis_srv6_node_msd_max_end_pop, + isis_srv6_node_msd_max_end_pop_cmd, + "[no] max-end-pop (0-255)$max_end_pop", + NO_STR + "Specify Maximum End Pop MSD\n" + "Specify Maximum End Pop MSD\n") +{ + if (no) + nb_cli_enqueue_change(vty, "./max-end-pop", NB_OP_DESTROY, NULL); + else + nb_cli_enqueue_change(vty, "./max-end-pop", NB_OP_MODIFY, + max_end_pop_str); + + return nb_cli_apply_changes(vty, NULL); +} + +/* + * XPath: /frr-isisd:isis/instance/segment-routing-srv6/msd/node-msd/max-h-encaps + */ +DEFPY (isis_srv6_node_msd_max_h_encaps, + isis_srv6_node_msd_max_h_encaps_cmd, + "[no] max-h-encaps (0-255)$max_h_encaps", + NO_STR + "Specify Maximum H.Encaps MSD\n" + "Specify Maximum H.Encaps MSD\n") +{ + if (no) + nb_cli_enqueue_change(vty, "./max-h-encaps", NB_OP_DESTROY, + NULL); + else + nb_cli_enqueue_change(vty, "./max-h-encaps", NB_OP_MODIFY, + max_h_encaps_str); + + return nb_cli_apply_changes(vty, NULL); +} + +/* + * XPath: /frr-isisd:isis/instance/segment-routing-srv6/msd/node-msd/max-end-d + */ +DEFPY (isis_srv6_node_msd_max_end_d, + isis_srv6_node_msd_max_end_d_cmd, + "[no] max-end-d (0-255)$max_end_d", + NO_STR + "Specify Maximum End D MSD\n" + "Specify Maximum End D MSD\n") +{ + if (no) + nb_cli_enqueue_change(vty, "./max-end-d", NB_OP_DESTROY, NULL); + else + nb_cli_enqueue_change(vty, "./max-end-d", NB_OP_MODIFY, + max_end_d_str); + + return nb_cli_apply_changes(vty, NULL); +} + +void cli_show_isis_srv6_node_msd(struct vty *vty, const struct lyd_node *dnode, + bool show_defaults) +{ + vty_out(vty, " node-msd\n"); + if (yang_dnode_get_uint8(dnode, "max-segs-left") != + yang_get_default_uint8("%s/msd/node-msd/max-segs-left", ISIS_SRV6)) + vty_out(vty, " max-segs-left %u\n", + yang_dnode_get_uint8(dnode, "max-segs-left")); + if (yang_dnode_get_uint8(dnode, "max-end-pop") != + yang_get_default_uint8("%s/msd/node-msd/max-end-pop", ISIS_SRV6)) + vty_out(vty, " max-end-pop %u\n", + yang_dnode_get_uint8(dnode, "max-end-pop")); + if (yang_dnode_get_uint8(dnode, "max-h-encaps") != + yang_get_default_uint8("%s/msd/node-msd/max-h-encaps", ISIS_SRV6)) + vty_out(vty, " max-h-encaps %u\n", + yang_dnode_get_uint8(dnode, "max-h-encaps")); + if (yang_dnode_get_uint8(dnode, "max-end-d") != + yang_get_default_uint8("%s/msd/node-msd/max-end-d", ISIS_SRV6)) + vty_out(vty, " max-end-d %u\n", + yang_dnode_get_uint8(dnode, "max-end-d")); +} + +/* + * XPath: /frr-isisd:isis/instance/segment-routing-srv6/interface + */ +DEFPY (isis_srv6_interface, + isis_srv6_interface_cmd, + "[no] interface WORD$interface", + NO_STR + "Interface for Segment Routing over IPv6 (SRv6)\n" + "Interface for Segment Routing over IPv6 (SRv6)\n") +{ + if (no) { + nb_cli_enqueue_change(vty, "./interface", + NB_OP_MODIFY, NULL); + } else { + nb_cli_enqueue_change(vty, "./interface", + NB_OP_MODIFY, interface); + } + + return nb_cli_apply_changes(vty, NULL); +} + +void cli_show_isis_srv6_interface(struct vty *vty, const struct lyd_node *dnode, + bool show_defaults) +{ + vty_out(vty, " interface %s\n", yang_dnode_get_string(dnode, NULL)); +} + /* * XPath: /frr-isisd:isis/instance/fast-reroute/level-{1,2}/lfa/priority-limit */ @@ -2050,8 +2381,8 @@ void cli_show_isis_frr_lfa_tiebreaker(struct vty *vty, bool show_defaults) { vty_out(vty, " fast-reroute lfa tiebreaker %s index %s %s\n", - yang_dnode_get_string(dnode, "./type"), - yang_dnode_get_string(dnode, "./index"), + yang_dnode_get_string(dnode, "type"), + yang_dnode_get_string(dnode, "index"), dnode->parent->parent->schema->name); } @@ -2223,8 +2554,8 @@ void cli_show_ip_isis_password(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { vty_out(vty, " isis password %s %s\n", - yang_dnode_get_string(dnode, "./password-type"), - yang_dnode_get_string(dnode, "./password")); + yang_dnode_get_string(dnode, "password-type"), + yang_dnode_get_string(dnode, "password")); } /* @@ -2270,8 +2601,8 @@ DEFPY_YANG(no_isis_metric, no_isis_metric_cmd, void cli_show_ip_isis_metric(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - const char *l1 = yang_dnode_get_string(dnode, "./level-1"); - const char *l2 = yang_dnode_get_string(dnode, "./level-2"); + const char *l1 = yang_dnode_get_string(dnode, "level-1"); + const char *l2 = yang_dnode_get_string(dnode, "level-2"); if (strmatch(l1, l2)) vty_out(vty, " isis metric %s\n", l1); @@ -2329,8 +2660,8 @@ void cli_show_ip_isis_hello_interval(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - const char *l1 = yang_dnode_get_string(dnode, "./level-1"); - const char *l2 = yang_dnode_get_string(dnode, "./level-2"); + const char *l1 = yang_dnode_get_string(dnode, "level-1"); + const char *l2 = yang_dnode_get_string(dnode, "level-2"); if (strmatch(l1, l2)) vty_out(vty, " isis hello-interval %s\n", l1); @@ -2387,8 +2718,8 @@ DEFPY_YANG(no_isis_hello_multiplier, no_isis_hello_multiplier_cmd, void cli_show_ip_isis_hello_multi(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - const char *l1 = yang_dnode_get_string(dnode, "./level-1"); - const char *l2 = yang_dnode_get_string(dnode, "./level-2"); + const char *l1 = yang_dnode_get_string(dnode, "level-1"); + const char *l2 = yang_dnode_get_string(dnode, "level-2"); if (strmatch(l1, l2)) vty_out(vty, " isis hello-multiplier %s\n", l1); @@ -2506,8 +2837,8 @@ void cli_show_ip_isis_csnp_interval(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - const char *l1 = yang_dnode_get_string(dnode, "./level-1"); - const char *l2 = yang_dnode_get_string(dnode, "./level-2"); + const char *l1 = yang_dnode_get_string(dnode, "level-1"); + const char *l2 = yang_dnode_get_string(dnode, "level-2"); if (strmatch(l1, l2)) vty_out(vty, " isis csnp-interval %s\n", l1); @@ -2565,8 +2896,8 @@ void cli_show_ip_isis_psnp_interval(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - const char *l1 = yang_dnode_get_string(dnode, "./level-1"); - const char *l2 = yang_dnode_get_string(dnode, "./level-2"); + const char *l1 = yang_dnode_get_string(dnode, "level-1"); + const char *l2 = yang_dnode_get_string(dnode, "level-2"); if (strmatch(l1, l2)) vty_out(vty, " isis psnp-interval %s\n", l1); @@ -2809,8 +3140,8 @@ DEFPY_YANG(no_isis_priority, no_isis_priority_cmd, void cli_show_ip_isis_priority(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - const char *l1 = yang_dnode_get_string(dnode, "./level-1"); - const char *l2 = yang_dnode_get_string(dnode, "./level-2"); + const char *l1 = yang_dnode_get_string(dnode, "level-1"); + const char *l2 = yang_dnode_get_string(dnode, "level-2"); if (strmatch(l1, l2)) vty_out(vty, " isis priority %s\n", l1); @@ -2831,8 +3162,8 @@ void cli_show_ip_isis_frr(struct vty *vty, const struct lyd_node *dnode, bool l1_link_fallback, l2_link_fallback; /* Classic LFA */ - l1_enabled = yang_dnode_get_bool(dnode, "./level-1/lfa/enable"); - l2_enabled = yang_dnode_get_bool(dnode, "./level-2/lfa/enable"); + l1_enabled = yang_dnode_get_bool(dnode, "level-1/lfa/enable"); + l2_enabled = yang_dnode_get_bool(dnode, "level-2/lfa/enable"); if (l1_enabled || l2_enabled) { if (l1_enabled == l2_enabled) { @@ -2849,8 +3180,8 @@ void cli_show_ip_isis_frr(struct vty *vty, const struct lyd_node *dnode, } /* Remote LFA */ - l1_enabled = yang_dnode_get_bool(dnode, "./level-1/remote-lfa/enable"); - l2_enabled = yang_dnode_get_bool(dnode, "./level-2/remote-lfa/enable"); + l1_enabled = yang_dnode_get_bool(dnode, "level-1/remote-lfa/enable"); + l2_enabled = yang_dnode_get_bool(dnode, "level-2/remote-lfa/enable"); if (l1_enabled || l2_enabled) { if (l1_enabled == l2_enabled) { @@ -2868,16 +3199,16 @@ void cli_show_ip_isis_frr(struct vty *vty, const struct lyd_node *dnode, } /* TI-LFA */ - l1_enabled = yang_dnode_get_bool(dnode, "./level-1/ti-lfa/enable"); - l2_enabled = yang_dnode_get_bool(dnode, "./level-2/ti-lfa/enable"); + l1_enabled = yang_dnode_get_bool(dnode, "level-1/ti-lfa/enable"); + l2_enabled = yang_dnode_get_bool(dnode, "level-2/ti-lfa/enable"); l1_node_protection = - yang_dnode_get_bool(dnode, "./level-1/ti-lfa/node-protection"); + yang_dnode_get_bool(dnode, "level-1/ti-lfa/node-protection"); l2_node_protection = - yang_dnode_get_bool(dnode, "./level-2/ti-lfa/node-protection"); + yang_dnode_get_bool(dnode, "level-2/ti-lfa/node-protection"); l1_link_fallback = - yang_dnode_get_bool(dnode, "./level-1/ti-lfa/link-fallback"); + yang_dnode_get_bool(dnode, "level-1/ti-lfa/link-fallback"); l2_link_fallback = - yang_dnode_get_bool(dnode, "./level-2/ti-lfa/link-fallback"); + yang_dnode_get_bool(dnode, "level-2/ti-lfa/link-fallback"); if (l1_enabled || l2_enabled) { @@ -3543,24 +3874,24 @@ void cli_show_isis_flex_algo(struct vty *vty, const struct lyd_node *dnode, uint32_t priority; char type_str[10]; - algorithm = yang_dnode_get_uint32(dnode, "./flex-algo"); + algorithm = yang_dnode_get_uint32(dnode, "flex-algo"); vty_out(vty, " flex-algo %u\n", algorithm); - if (yang_dnode_exists(dnode, "./advertise-definition")) + if (yang_dnode_exists(dnode, "advertise-definition")) vty_out(vty, " advertise-definition\n"); - if (yang_dnode_exists(dnode, "./dplane-sr-mpls")) + if (yang_dnode_exists(dnode, "dplane-sr-mpls")) vty_out(vty, " dataplane sr-mpls\n"); - if (yang_dnode_exists(dnode, "./dplane-srv6")) + if (yang_dnode_exists(dnode, "dplane-srv6")) vty_out(vty, " dataplane srv6\n"); - if (yang_dnode_exists(dnode, "./dplane-ip")) + if (yang_dnode_exists(dnode, "dplane-ip")) vty_out(vty, " dataplane ip\n"); - if (yang_dnode_exists(dnode, "./prefix-metric")) + if (yang_dnode_exists(dnode, "prefix-metric")) vty_out(vty, " prefix-metric\n"); - if (yang_dnode_exists(dnode, "./metric-type")) { - metric_type = yang_dnode_get_enum(dnode, "./metric-type"); + if (yang_dnode_exists(dnode, "metric-type")) { + metric_type = yang_dnode_get_enum(dnode, "metric-type"); if (metric_type != MT_IGP) { flex_algo_metric_type_print(type_str, sizeof(type_str), metric_type); @@ -3568,8 +3899,8 @@ void cli_show_isis_flex_algo(struct vty *vty, const struct lyd_node *dnode, } } - if (yang_dnode_exists(dnode, "./priority")) { - priority = yang_dnode_get_uint32(dnode, "./priority"); + if (yang_dnode_exists(dnode, "priority")) { + priority = yang_dnode_get_uint32(dnode, "priority"); if (priority != FLEX_ALGO_PRIO_DEFAULT) vty_out(vty, " priority %u\n", priority); } @@ -3681,6 +4012,7 @@ void isis_cli_init(void) install_element(ISIS_NODE, &isis_default_originate_cmd); install_element(ISIS_NODE, &isis_redistribute_cmd); + install_element(ISIS_NODE, &isis_redistribute_table_cmd); install_element(ISIS_NODE, &isis_topology_cmd); @@ -3702,6 +4034,20 @@ void isis_cli_init(void) install_element(ISIS_NODE, &isis_frr_remote_lfa_plist_cmd); install_element(ISIS_NODE, &no_isis_frr_remote_lfa_plist_cmd); + install_element(ISIS_NODE, &isis_srv6_enable_cmd); + install_element(ISIS_NODE, &no_isis_srv6_enable_cmd); + install_element(ISIS_SRV6_NODE, &isis_srv6_locator_cmd); + install_element(ISIS_SRV6_NODE, &isis_srv6_node_msd_cmd); + install_element(ISIS_SRV6_NODE, &isis_srv6_interface_cmd); + install_element(ISIS_SRV6_NODE_MSD_NODE, + &isis_srv6_node_msd_max_segs_left_cmd); + install_element(ISIS_SRV6_NODE_MSD_NODE, + &isis_srv6_node_msd_max_end_pop_cmd); + install_element(ISIS_SRV6_NODE_MSD_NODE, + &isis_srv6_node_msd_max_h_encaps_cmd); + install_element(ISIS_SRV6_NODE_MSD_NODE, + &isis_srv6_node_msd_max_end_d_cmd); + install_element(INTERFACE_NODE, &isis_passive_cmd); install_element(INTERFACE_NODE, &isis_passwd_cmd); diff --git a/isisd/isis_flex_algo.c b/isisd/isis_flex_algo.c index ef30987b8e..fbe249ab5a 100644 --- a/isisd/isis_flex_algo.c +++ b/isisd/isis_flex_algo.c @@ -127,10 +127,7 @@ _isis_flex_algo_elected(int algorithm, const struct isis_area *area, * Perform FAD comparison. First, compare the priority, and if they are * the same, compare the sys-id. */ - /* clang-format off */ - frr_each_const(lspdb, &area->lspdb[ISIS_LEVEL1 - 1], lsp) { - /* clang-format on */ - + frr_each (lspdb_const, &area->lspdb[ISIS_LEVEL1 - 1], lsp) { if (!lsp->tlvs || !lsp->tlvs->router_cap) continue; diff --git a/isisd/isis_lsp.c b/isisd/isis_lsp.c index 950d5f359c..77573cdfac 100644 --- a/isisd/isis_lsp.c +++ b/isisd/isis_lsp.c @@ -703,7 +703,7 @@ void lspid_print(uint8_t *lsp_id, char *dest, size_t dest_len, char dynhost, else if (!memcmp(isis->sysid, lsp_id, ISIS_SYS_ID_LEN) && dynhost) snprintf(id, sizeof(id), "%.14s", cmd_hostname_get()); else - snprintf(id, sizeof(id), "%pSY", lsp_id); + snprintfrr(id, sizeof(id), "%pSY", lsp_id); if (frag) snprintf(dest, dest_len, "%s.%02x-%02x", id, @@ -1210,6 +1210,62 @@ static void lsp_build(struct isis_lsp *lsp, struct isis_area *area) /* And finally MSD */ rcap->msd = srdb->config.msd; } + + /* Add SRv6 Sub-TLVs if SRv6 is enabled */ + if (area->srv6db.config.enabled) { + struct isis_srv6_db *srv6db = &area->srv6db; + + rcap->srv6_cap.is_srv6_capable = true; + + /* SRv6 flags */ + rcap->srv6_cap.flags = 0; + + /* And finally MSDs */ + rcap->srv6_msd.max_seg_left_msd = + srv6db->config.max_seg_left_msd; + rcap->srv6_msd.max_end_pop_msd = + srv6db->config.max_end_pop_msd; + rcap->srv6_msd.max_h_encaps_msd = + srv6db->config.max_h_encaps_msd; + rcap->srv6_msd.max_end_d_msd = + srv6db->config.max_end_d_msd; + } else { + rcap->srv6_cap.is_srv6_capable = false; + } + } + + /* Add SRv6 Locator TLV. */ + if (area->srv6db.config.enabled && + !list_isempty(area->srv6db.srv6_locator_chunks)) { + struct isis_srv6_locator locator = {}; + struct srv6_locator_chunk *chunk; + + /* TODO: support more than one locator */ + chunk = (struct srv6_locator_chunk *)listgetdata( + listhead(area->srv6db.srv6_locator_chunks)); + + locator.metric = 0; + locator.prefix = chunk->prefix; + locator.flags = 0; + locator.algorithm = 0; + + struct listnode *sid_node; + struct isis_srv6_sid *sid; + locator.srv6_sid = list_new(); + for (ALL_LIST_ELEMENTS_RO(area->srv6db.srv6_sids, sid_node, + sid)) { + listnode_add(locator.srv6_sid, sid); + } + + isis_tlvs_add_srv6_locator(lsp->tlvs, 0, &locator); + lsp_debug("ISIS (%s): Adding SRv6 Locator information", + area->area_tag); + + list_delete(&locator.srv6_sid); + + isis_tlvs_add_ipv6_reach(lsp->tlvs, + isis_area_ipv6_topology(area), + &chunk->prefix, 0, false, NULL); } /* IPv4 address and TE router ID TLVs. diff --git a/isisd/isis_main.c b/isisd/isis_main.c index 385cdcc350..da4c7bc00a 100644 --- a/isisd/isis_main.c +++ b/isisd/isis_main.c @@ -93,6 +93,7 @@ static __attribute__((__noreturn__)) void terminate(int i) { isis_terminate(); isis_sr_term(); + isis_srv6_term(); isis_zebra_stop(); exit(i); } @@ -170,6 +171,9 @@ static const struct frr_yang_module_info *const isisd_yang_modules[] = { /* clang-format on */ +/* Max wait time for config to load before generating LSPs */ +#define ISIS_PRE_CONFIG_MAX_WAIT_SECONDS 600 + static void isis_config_finish(struct event *t) { struct listnode *node, *inode; @@ -182,12 +186,17 @@ static void isis_config_finish(struct event *t) } } +static void isis_config_end_timeout(struct event *t) +{ + zlog_err("IS-IS configuration end timer expired after %d seconds.", + ISIS_PRE_CONFIG_MAX_WAIT_SECONDS); + isis_config_finish(t); +} + static void isis_config_start(void) { - /* Max wait time for config to load before generating lsp */ -#define ISIS_PRE_CONFIG_MAX_WAIT_SECONDS 600 EVENT_OFF(t_isis_cfg); - event_add_timer(im->master, isis_config_finish, NULL, + event_add_timer(im->master, isis_config_end_timeout, NULL, ISIS_PRE_CONFIG_MAX_WAIT_SECONDS, &t_isis_cfg); } @@ -288,6 +297,7 @@ int main(int argc, char **argv, char **envp) isis_route_map_init(); isis_mpls_te_init(); isis_sr_init(); + isis_srv6_init(); lsp_init(); mt_init(); diff --git a/isisd/isis_misc.c b/isisd/isis_misc.c index 09ffa3479a..e4ef6c8dfa 100644 --- a/isisd/isis_misc.c +++ b/isisd/isis_misc.c @@ -474,20 +474,20 @@ void log_multiline(int priority, const char *prefix, const char *format, ...) char *log_uptime(time_t uptime, char *buf, size_t nbuf) { - struct tm *tm; + struct tm tm; time_t difftime = time(NULL); difftime -= uptime; - tm = gmtime(&difftime); + gmtime_r(&difftime, &tm); if (difftime < ONE_DAY_SECOND) - snprintf(buf, nbuf, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, - tm->tm_sec); + snprintf(buf, nbuf, "%02d:%02d:%02d", tm.tm_hour, tm.tm_min, + tm.tm_sec); else if (difftime < ONE_WEEK_SECOND) - snprintf(buf, nbuf, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour, - tm->tm_min); + snprintf(buf, nbuf, "%dd%02dh%02dm", tm.tm_yday, tm.tm_hour, + tm.tm_min); else - snprintf(buf, nbuf, "%02dw%dd%02dh", tm->tm_yday / 7, - tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour); + snprintf(buf, nbuf, "%02dw%dd%02dh", tm.tm_yday / 7, + tm.tm_yday - ((tm.tm_yday / 7) * 7), tm.tm_hour); return buf; } diff --git a/isisd/isis_nb.c b/isisd/isis_nb.c index 6da8fa2d28..16cafa2ff0 100644 --- a/isisd/isis_nb.c +++ b/isisd/isis_nb.c @@ -381,6 +381,29 @@ const struct frr_yang_module_info frr_isisd_info = { }, { .xpath = "/frr-isisd:isis/instance/redistribute/ipv4/metric", + .cbs = { + .destroy = isis_instance_redistribute_ipv4_metric_destroy, + .modify = isis_instance_redistribute_ipv4_metric_modify, + }, + }, + { + .xpath = "/frr-isisd:isis/instance/redistribute/ipv4/table", + .cbs = { + .cli_show = cli_show_isis_redistribute_ipv4_table, + .cli_cmp = cli_cmp_isis_redistribute_table, + .create = isis_instance_redistribute_ipv4_table_create, + .destroy = isis_instance_redistribute_ipv4_table_destroy, + }, + }, + { + .xpath = "/frr-isisd:isis/instance/redistribute/ipv4/table/route-map", + .cbs = { + .destroy = isis_instance_redistribute_ipv4_route_map_destroy, + .modify = isis_instance_redistribute_ipv4_route_map_modify, + }, + }, + { + .xpath = "/frr-isisd:isis/instance/redistribute/ipv4/table/metric", .cbs = { .modify = isis_instance_redistribute_ipv4_metric_modify, }, @@ -403,6 +426,29 @@ const struct frr_yang_module_info frr_isisd_info = { }, { .xpath = "/frr-isisd:isis/instance/redistribute/ipv6/metric", + .cbs = { + .destroy = isis_instance_redistribute_ipv6_metric_destroy, + .modify = isis_instance_redistribute_ipv6_metric_modify, + }, + }, + { + .xpath = "/frr-isisd:isis/instance/redistribute/ipv6/table", + .cbs = { + .cli_show = cli_show_isis_redistribute_ipv6_table, + .cli_cmp = cli_cmp_isis_redistribute_table, + .create = isis_instance_redistribute_ipv6_table_create, + .destroy = isis_instance_redistribute_ipv6_table_destroy, + }, + }, + { + .xpath = "/frr-isisd:isis/instance/redistribute/ipv6/table/route-map", + .cbs = { + .destroy = isis_instance_redistribute_ipv6_route_map_destroy, + .modify = isis_instance_redistribute_ipv6_route_map_modify, + }, + }, + { + .xpath = "/frr-isisd:isis/instance/redistribute/ipv6/table/metric", .cbs = { .modify = isis_instance_redistribute_ipv6_metric_modify, }, @@ -814,6 +860,58 @@ const struct frr_yang_module_info frr_isisd_info = { .destroy = isis_instance_flex_algo_priority_destroy, }, }, + { + .xpath = "/frr-isisd:isis/instance/segment-routing-srv6/enabled", + .cbs = { + .modify = isis_instance_segment_routing_srv6_enabled_modify, + .cli_show = cli_show_isis_srv6_enabled, + }, + }, + { + .xpath = "/frr-isisd:isis/instance/segment-routing-srv6/locator", + .cbs = { + .modify = isis_instance_segment_routing_srv6_locator_modify, + .destroy = isis_instance_segment_routing_srv6_locator_destroy, + .cli_show = cli_show_isis_srv6_locator, + }, + }, + { + .xpath = "/frr-isisd:isis/instance/segment-routing-srv6/msd/node-msd/max-segs-left", + .cbs = { + .modify = isis_instance_segment_routing_srv6_msd_node_msd_max_segs_left_modify, + }, + }, + { + .xpath = "/frr-isisd:isis/instance/segment-routing-srv6/msd/node-msd/max-end-pop", + .cbs = { + .modify = isis_instance_segment_routing_srv6_msd_node_msd_max_end_pop_modify, + }, + }, + { + .xpath = "/frr-isisd:isis/instance/segment-routing-srv6/msd/node-msd/max-h-encaps", + .cbs = { + .modify = isis_instance_segment_routing_srv6_msd_node_msd_max_h_encaps_modify, + }, + }, + { + .xpath = "/frr-isisd:isis/instance/segment-routing-srv6/msd/node-msd/max-end-d", + .cbs = { + .modify = isis_instance_segment_routing_srv6_msd_node_msd_max_end_d_modify, + }, + }, + { + .xpath = "/frr-isisd:isis/instance/segment-routing-srv6/msd/node-msd", + .cbs = { + .cli_show = cli_show_isis_srv6_node_msd, + }, + }, + { + .xpath = "/frr-isisd:isis/instance/segment-routing-srv6/interface", + .cbs = { + .modify = isis_instance_segment_routing_srv6_interface_modify, + .cli_show = cli_show_isis_srv6_interface, + }, + }, { .xpath = "/frr-isisd:isis/instance/mpls/ldp-sync", .cbs = { diff --git a/isisd/isis_nb.h b/isisd/isis_nb.h index 13efa36d78..c04a006a2e 100644 --- a/isisd/isis_nb.h +++ b/isisd/isis_nb.h @@ -121,6 +121,11 @@ int isis_instance_redistribute_ipv4_route_map_destroy( struct nb_cb_destroy_args *args); int isis_instance_redistribute_ipv4_metric_modify( struct nb_cb_modify_args *args); +int isis_instance_redistribute_ipv4_metric_destroy( + struct nb_cb_destroy_args *args); +int isis_instance_redistribute_ipv4_table_create(struct nb_cb_create_args *args); +int isis_instance_redistribute_ipv4_table_destroy( + struct nb_cb_destroy_args *args); int isis_instance_redistribute_ipv6_create(struct nb_cb_create_args *args); int isis_instance_redistribute_ipv6_destroy(struct nb_cb_destroy_args *args); int isis_instance_redistribute_ipv6_route_map_modify( @@ -129,6 +134,11 @@ int isis_instance_redistribute_ipv6_route_map_destroy( struct nb_cb_destroy_args *args); int isis_instance_redistribute_ipv6_metric_modify( struct nb_cb_modify_args *args); +int isis_instance_redistribute_ipv6_metric_destroy( + struct nb_cb_destroy_args *args); +int isis_instance_redistribute_ipv6_table_create(struct nb_cb_create_args *args); +int isis_instance_redistribute_ipv6_table_destroy( + struct nb_cb_destroy_args *args); int isis_instance_multi_topology_ipv4_multicast_create( struct nb_cb_create_args *args); int isis_instance_multi_topology_ipv4_multicast_destroy( @@ -312,6 +322,30 @@ int isis_instance_flex_algo_affinity_mapping_value_modify( struct nb_cb_modify_args *args); int isis_instance_flex_algo_affinity_mapping_value_destroy( struct nb_cb_destroy_args *args); +int isis_instance_segment_routing_srv6_enabled_modify( + struct nb_cb_modify_args *args); +void cli_show_isis_srv6_enabled(struct vty *vty, const struct lyd_node *dnode, + bool show_defaults); +int isis_instance_segment_routing_srv6_locator_modify( + struct nb_cb_modify_args *args); +int isis_instance_segment_routing_srv6_locator_destroy( + struct nb_cb_destroy_args *args); +void cli_show_isis_srv6_locator(struct vty *vty, const struct lyd_node *dnode, + bool show_defaults); +int isis_instance_segment_routing_srv6_msd_node_msd_max_segs_left_modify( + struct nb_cb_modify_args *args); +int isis_instance_segment_routing_srv6_msd_node_msd_max_end_pop_modify( + struct nb_cb_modify_args *args); +int isis_instance_segment_routing_srv6_msd_node_msd_max_h_encaps_modify( + struct nb_cb_modify_args *args); +int isis_instance_segment_routing_srv6_msd_node_msd_max_end_d_modify( + struct nb_cb_modify_args *args); +void cli_show_isis_srv6_node_msd(struct vty *vty, const struct lyd_node *dnode, + bool show_defaults); +int isis_instance_segment_routing_srv6_interface_modify( + struct nb_cb_modify_args *args); +void cli_show_isis_srv6_interface(struct vty *vty, const struct lyd_node *dnode, + bool show_defaults); int isis_instance_mpls_ldp_sync_destroy(struct nb_cb_destroy_args *args); int isis_instance_mpls_ldp_sync_create(struct nb_cb_create_args *args); int isis_instance_mpls_ldp_sync_holddown_modify(struct nb_cb_modify_args *args); @@ -587,6 +621,12 @@ void cli_show_isis_redistribute_ipv6(struct vty *vty, void cli_show_isis_mt_ipv4_multicast(struct vty *vty, const struct lyd_node *dnode, bool show_defaults); +void cli_show_isis_redistribute_ipv4_table(struct vty *vty, + const struct lyd_node *dnode, + bool show_defaults); +void cli_show_isis_redistribute_ipv6_table(struct vty *vty, + const struct lyd_node *dnode, + bool show_defaults); void cli_show_isis_mt_ipv4_mgmt(struct vty *vty, const struct lyd_node *dnode, bool show_defaults); void cli_show_isis_mt_ipv6_unicast(struct vty *vty, @@ -742,6 +782,9 @@ void isis_notif_seqno_skipped(const struct isis_circuit *circuit, const uint8_t *lsp_id); void isis_notif_own_lsp_purge(const struct isis_circuit *circuit, const uint8_t *lsp_id); +/* cmp */ +int cli_cmp_isis_redistribute_table(const struct lyd_node *dnode1, + const struct lyd_node *dnode2); /* We also declare hook for every notification */ diff --git a/isisd/isis_nb_config.c b/isisd/isis_nb_config.c index 8a111b301d..5794e16a11 100644 --- a/isisd/isis_nb_config.c +++ b/isisd/isis_nb_config.c @@ -35,6 +35,7 @@ #include "isisd/isis_adjacency.h" #include "isisd/isis_spf.h" #include "isisd/isis_spf_private.h" +#include "isisd/isis_srv6.h" #include "isisd/isis_te.h" #include "isisd/isis_mt.h" #include "isisd/isis_redist.h" @@ -59,8 +60,8 @@ int isis_instance_create(struct nb_cb_create_args *args) if (args->event != NB_EV_APPLY) return NB_OK; - vrf_name = yang_dnode_get_string(args->dnode, "./vrf"); - area_tag = yang_dnode_get_string(args->dnode, "./area-tag"); + vrf_name = yang_dnode_get_string(args->dnode, "vrf"); + area_tag = yang_dnode_get_string(args->dnode, "area-tag"); area = isis_area_lookup_by_vrf(area_tag, vrf_name); if (area) @@ -649,12 +650,12 @@ int isis_instance_lsp_generation_interval_level_2_modify( */ void ietf_backoff_delay_apply_finish(struct nb_cb_apply_finish_args *args) { - long init_delay = yang_dnode_get_uint16(args->dnode, "./init-delay"); - long short_delay = yang_dnode_get_uint16(args->dnode, "./short-delay"); - long long_delay = yang_dnode_get_uint16(args->dnode, "./long-delay"); - long holddown = yang_dnode_get_uint16(args->dnode, "./hold-down"); + long init_delay = yang_dnode_get_uint16(args->dnode, "init-delay"); + long short_delay = yang_dnode_get_uint16(args->dnode, "short-delay"); + long long_delay = yang_dnode_get_uint16(args->dnode, "long-delay"); + long holddown = yang_dnode_get_uint16(args->dnode, "hold-down"); long timetolearn = - yang_dnode_get_uint16(args->dnode, "./time-to-learn"); + yang_dnode_get_uint16(args->dnode, "time-to-learn"); struct isis_area *area = nb_running_get_entry(args->dnode, NULL, true); size_t bufsiz = strlen(area->area_tag) + sizeof("IS-IS Lx"); char *buf = XCALLOC(MTYPE_TMP, bufsiz); @@ -925,11 +926,11 @@ int isis_instance_spf_prefix_priorities_medium_access_list_name_destroy( */ void area_password_apply_finish(struct nb_cb_apply_finish_args *args) { - const char *password = yang_dnode_get_string(args->dnode, "./password"); + const char *password = yang_dnode_get_string(args->dnode, "password"); struct isis_area *area = nb_running_get_entry(args->dnode, NULL, true); - int pass_type = yang_dnode_get_enum(args->dnode, "./password-type"); + int pass_type = yang_dnode_get_enum(args->dnode, "password-type"); uint8_t snp_auth = - yang_dnode_get_enum(args->dnode, "./authenticate-snp"); + yang_dnode_get_enum(args->dnode, "authenticate-snp"); switch (pass_type) { case ISIS_PASSWD_TYPE_CLEARTXT: @@ -996,11 +997,11 @@ int isis_instance_area_password_authenticate_snp_modify( */ void domain_password_apply_finish(struct nb_cb_apply_finish_args *args) { - const char *password = yang_dnode_get_string(args->dnode, "./password"); + const char *password = yang_dnode_get_string(args->dnode, "password"); struct isis_area *area = nb_running_get_entry(args->dnode, NULL, true); - int pass_type = yang_dnode_get_enum(args->dnode, "./password-type"); + int pass_type = yang_dnode_get_enum(args->dnode, "password-type"); uint8_t snp_auth = - yang_dnode_get_enum(args->dnode, "./authenticate-snp"); + yang_dnode_get_enum(args->dnode, "authenticate-snp"); switch (pass_type) { case ISIS_PASSWD_TYPE_CLEARTXT: @@ -1072,9 +1073,9 @@ void default_info_origin_apply_finish(const struct lyd_node *dnode, int family) unsigned long metric = 0; const char *routemap = NULL; struct isis_area *area = nb_running_get_entry(dnode, NULL, true); - int level = yang_dnode_get_enum(dnode, "./level"); + int level = yang_dnode_get_enum(dnode, "level"); - if (yang_dnode_get_bool(dnode, "./always")) { + if (yang_dnode_get_bool(dnode, "always")) { originate_type = DEFAULT_ORIGINATE_ALWAYS; } else if (family == AF_INET6) { zlog_warn( @@ -1082,13 +1083,13 @@ void default_info_origin_apply_finish(const struct lyd_node *dnode, int family) __func__); } - if (yang_dnode_exists(dnode, "./metric")) - metric = yang_dnode_get_uint32(dnode, "./metric"); - if (yang_dnode_exists(dnode, "./route-map")) - routemap = yang_dnode_get_string(dnode, "./route-map"); + if (yang_dnode_exists(dnode, "metric")) + metric = yang_dnode_get_uint32(dnode, "metric"); + if (yang_dnode_exists(dnode, "route-map")) + routemap = yang_dnode_get_string(dnode, "route-map"); isis_redist_set(area, level, family, DEFAULT_ROUTE, metric, routemap, - originate_type); + originate_type, 0); } void default_info_origin_ipv4_apply_finish(struct nb_cb_apply_finish_args *args) @@ -1118,8 +1119,8 @@ int isis_instance_default_information_originate_ipv4_destroy( return NB_OK; area = nb_running_get_entry(args->dnode, NULL, true); - level = yang_dnode_get_enum(args->dnode, "./level"); - isis_redist_unset(area, level, AF_INET, DEFAULT_ROUTE); + level = yang_dnode_get_enum(args->dnode, "level"); + isis_redist_unset(area, level, AF_INET, DEFAULT_ROUTE, 0); return NB_OK; } @@ -1181,8 +1182,8 @@ int isis_instance_default_information_originate_ipv6_destroy( return NB_OK; area = nb_running_get_entry(args->dnode, NULL, true); - level = yang_dnode_get_enum(args->dnode, "./level"); - isis_redist_unset(area, level, AF_INET6, DEFAULT_ROUTE); + level = yang_dnode_get_enum(args->dnode, "level"); + isis_redist_unset(area, level, AF_INET6, DEFAULT_ROUTE, 0); return NB_OK; } @@ -1235,16 +1236,16 @@ void redistribute_apply_finish(const struct lyd_node *dnode, int family) const char *routemap = NULL; struct isis_area *area; - type = yang_dnode_get_enum(dnode, "./protocol"); - level = yang_dnode_get_enum(dnode, "./level"); + type = yang_dnode_get_enum(dnode, "protocol"); + level = yang_dnode_get_enum(dnode, "level"); area = nb_running_get_entry(dnode, NULL, true); - if (yang_dnode_exists(dnode, "./metric")) - metric = yang_dnode_get_uint32(dnode, "./metric"); - if (yang_dnode_exists(dnode, "./route-map")) - routemap = yang_dnode_get_string(dnode, "./route-map"); + if (yang_dnode_exists(dnode, "metric")) + metric = yang_dnode_get_uint32(dnode, "metric"); + if (yang_dnode_exists(dnode, "route-map")) + routemap = yang_dnode_get_string(dnode, "route-map"); - isis_redist_set(area, level, family, type, metric, routemap, 0); + isis_redist_set(area, level, family, type, metric, routemap, 0, 0); } void redistribute_ipv4_apply_finish(struct nb_cb_apply_finish_args *args) @@ -1272,15 +1273,16 @@ int isis_instance_redistribute_ipv4_destroy(struct nb_cb_destroy_args *args) return NB_OK; area = nb_running_get_entry(args->dnode, NULL, true); - level = yang_dnode_get_enum(args->dnode, "./level"); - type = yang_dnode_get_enum(args->dnode, "./protocol"); - isis_redist_unset(area, level, AF_INET, type); + level = yang_dnode_get_enum(args->dnode, "level"); + type = yang_dnode_get_enum(args->dnode, "protocol"); + isis_redist_unset(area, level, AF_INET, type, 0); return NB_OK; } /* * XPath: /frr-isisd:isis/instance/redistribute/ipv4/route-map + * XPath: /frr-isisd:isis/instance/redistribute/ipv4/table/route-map */ int isis_instance_redistribute_ipv4_route_map_modify( struct nb_cb_modify_args *args) @@ -1298,6 +1300,7 @@ int isis_instance_redistribute_ipv4_route_map_destroy( /* * XPath: /frr-isisd:isis/instance/redistribute/ipv4/metric + * XPath: /frr-isisd:isis/instance/redistribute/ipv4/table/metric */ int isis_instance_redistribute_ipv4_metric_modify( struct nb_cb_modify_args *args) @@ -1306,6 +1309,58 @@ int isis_instance_redistribute_ipv4_metric_modify( return NB_OK; } +int isis_instance_redistribute_ipv4_metric_destroy(struct nb_cb_destroy_args *args) +{ + /* It's all done by redistribute_apply_finish */ + return NB_OK; +} + +/* + * XPath: /frr-isisd:isis/instance/redistribute/ipv4/table + */ +int isis_instance_redistribute_ipv4_table_create(struct nb_cb_create_args *args) +{ + uint16_t table; + int type, level; + unsigned long metric = 0; + const char *routemap = NULL; + struct isis_area *area; + + if (args->event != NB_EV_APPLY) + return NB_OK; + + type = yang_dnode_get_enum(args->dnode, "../protocol"); + level = yang_dnode_get_enum(args->dnode, "../level"); + area = nb_running_get_entry(args->dnode, "../.", true); + + if (yang_dnode_exists(args->dnode, "metric")) + metric = yang_dnode_get_uint32(args->dnode, "metric"); + if (yang_dnode_exists(args->dnode, "route-map")) + routemap = yang_dnode_get_string(args->dnode, "route-map"); + + table = yang_dnode_get_uint16(args->dnode, "table"); + isis_redist_set(area, level, AF_INET, type, metric, routemap, 0, table); + + return NB_OK; +} +int isis_instance_redistribute_ipv4_table_destroy(struct nb_cb_destroy_args *args) +{ + struct isis_area *area; + int level, type; + uint16_t table; + + if (args->event != NB_EV_APPLY) + return NB_OK; + + area = nb_running_get_entry(args->dnode, "../.", true); + level = yang_dnode_get_enum(args->dnode, "../level"); + type = yang_dnode_get_enum(args->dnode, "../protocol"); + table = yang_dnode_get_uint16(args->dnode, "table"); + isis_redist_unset(area, level, AF_INET, type, table); + + return NB_OK; +} + /* * XPath: /frr-isisd:isis/instance/redistribute/ipv6 */ @@ -1324,9 +1379,9 @@ int isis_instance_redistribute_ipv6_destroy(struct nb_cb_destroy_args *args) return NB_OK; area = nb_running_get_entry(args->dnode, NULL, true); - level = yang_dnode_get_enum(args->dnode, "./level"); - type = yang_dnode_get_enum(args->dnode, "./protocol"); - isis_redist_unset(area, level, AF_INET6, type); + level = yang_dnode_get_enum(args->dnode, "level"); + type = yang_dnode_get_enum(args->dnode, "protocol"); + isis_redist_unset(area, level, AF_INET6, type, 0); return NB_OK; } @@ -1358,6 +1413,33 @@ int isis_instance_redistribute_ipv6_metric_modify( return NB_OK; } +int isis_instance_redistribute_ipv6_metric_destroy(struct nb_cb_destroy_args *args) +{ + /* It's all done by redistribute_apply_finish */ + return NB_OK; +} + +/* + * XPath: /frr-isisd:isis/instance/redistribute/ipv6/table + */ +int isis_instance_redistribute_ipv6_table_create(struct nb_cb_create_args *args) +{ + if (args->event != NB_EV_APPLY) + return NB_OK; + + /* TODO */ + return NB_OK; +} + +int isis_instance_redistribute_ipv6_table_destroy(struct nb_cb_destroy_args *args) +{ + if (args->event != NB_EV_APPLY) + return NB_OK; + + /* TODO */ + return NB_OK; +} + /* * XPath: /frr-isisd:isis/instance/multi-topology/ipv4-multicast */ @@ -1650,8 +1732,8 @@ int isis_instance_fast_reroute_level_1_lfa_tiebreaker_create( return NB_OK; area = nb_running_get_entry(args->dnode, NULL, true); - index = yang_dnode_get_uint8(args->dnode, "./index"); - type = yang_dnode_get_enum(args->dnode, "./type"); + index = yang_dnode_get_uint8(args->dnode, "index"); + type = yang_dnode_get_enum(args->dnode, "type"); tie_b = isis_lfa_tiebreaker_add(area, ISIS_LEVEL1, index, type); nb_running_set_entry(args->dnode, tie_b); @@ -1799,8 +1881,8 @@ int isis_instance_fast_reroute_level_2_lfa_tiebreaker_create( return NB_OK; area = nb_running_get_entry(args->dnode, NULL, true); - index = yang_dnode_get_uint8(args->dnode, "./index"); - type = yang_dnode_get_enum(args->dnode, "./type"); + index = yang_dnode_get_uint8(args->dnode, "index"); + type = yang_dnode_get_enum(args->dnode, "type"); tie_b = isis_lfa_tiebreaker_add(area, ISIS_LEVEL2, index, type); nb_running_set_entry(args->dnode, tie_b); @@ -2130,10 +2212,10 @@ int isis_instance_segment_routing_label_blocks_pre_validate( uint32_t srlb_lbound; uint32_t srlb_ubound; - srgb_lbound = yang_dnode_get_uint32(args->dnode, "./srgb/lower-bound"); - srgb_ubound = yang_dnode_get_uint32(args->dnode, "./srgb/upper-bound"); - srlb_lbound = yang_dnode_get_uint32(args->dnode, "./srlb/lower-bound"); - srlb_ubound = yang_dnode_get_uint32(args->dnode, "./srlb/upper-bound"); + srgb_lbound = yang_dnode_get_uint32(args->dnode, "srgb/lower-bound"); + srgb_ubound = yang_dnode_get_uint32(args->dnode, "srgb/upper-bound"); + srlb_lbound = yang_dnode_get_uint32(args->dnode, "srlb/lower-bound"); + srlb_ubound = yang_dnode_get_uint32(args->dnode, "srlb/upper-bound"); /* Check that the block size does not exceed 65535 */ if ((srgb_ubound - srgb_lbound + 1) > 65535) { @@ -2173,8 +2255,8 @@ void isis_instance_segment_routing_srgb_apply_finish( uint32_t lower_bound, upper_bound; area = nb_running_get_entry(args->dnode, NULL, true); - lower_bound = yang_dnode_get_uint32(args->dnode, "./lower-bound"); - upper_bound = yang_dnode_get_uint32(args->dnode, "./upper-bound"); + lower_bound = yang_dnode_get_uint32(args->dnode, "lower-bound"); + upper_bound = yang_dnode_get_uint32(args->dnode, "upper-bound"); isis_sr_cfg_srgb_update(area, lower_bound, upper_bound); } @@ -2239,8 +2321,8 @@ void isis_instance_segment_routing_srlb_apply_finish( uint32_t lower_bound, upper_bound; area = nb_running_get_entry(args->dnode, NULL, true); - lower_bound = yang_dnode_get_uint32(args->dnode, "./lower-bound"); - upper_bound = yang_dnode_get_uint32(args->dnode, "./upper-bound"); + lower_bound = yang_dnode_get_uint32(args->dnode, "lower-bound"); + upper_bound = yang_dnode_get_uint32(args->dnode, "upper-bound"); isis_sr_cfg_srlb_update(area, lower_bound, upper_bound); } @@ -2346,7 +2428,7 @@ int isis_instance_segment_routing_prefix_sid_map_prefix_sid_create( return NB_OK; area = nb_running_get_entry(args->dnode, NULL, true); - yang_dnode_get_prefix(&prefix, args->dnode, "./prefix"); + yang_dnode_get_prefix(&prefix, args->dnode, "prefix"); pcfg = isis_sr_cfg_prefix_add(area, &prefix, SR_ALGORITHM_SPF); nb_running_set_entry(args->dnode, pcfg); @@ -2384,13 +2466,13 @@ int isis_instance_segment_routing_prefix_sid_map_prefix_sid_pre_validate( enum sr_sid_value_type sid_type; struct isis_prefix_sid psid = {}; - yang_dnode_get_prefix(&prefix, args->dnode, "./prefix"); + yang_dnode_get_prefix(&prefix, args->dnode, "prefix"); srgb_lbound = yang_dnode_get_uint32( args->dnode, "../../label-blocks/srgb/lower-bound"); srgb_ubound = yang_dnode_get_uint32( args->dnode, "../../label-blocks/srgb/upper-bound"); - sid = yang_dnode_get_uint32(args->dnode, "./sid-value"); - sid_type = yang_dnode_get_enum(args->dnode, "./sid-value-type"); + sid = yang_dnode_get_uint32(args->dnode, "sid-value"); + sid_type = yang_dnode_get_enum(args->dnode, "sid-value-type"); /* Check for invalid indexes/labels. */ srgb_range = srgb_ubound - srgb_lbound + 1; @@ -2554,8 +2636,8 @@ int isis_instance_segment_routing_algorithm_prefix_sid_create( return NB_OK; area = nb_running_get_entry(args->dnode, NULL, true); - yang_dnode_get_prefix(&prefix, args->dnode, "./prefix"); - algorithm = yang_dnode_get_uint32(args->dnode, "./algo"); + yang_dnode_get_prefix(&prefix, args->dnode, "prefix"); + algorithm = yang_dnode_get_uint32(args->dnode, "algo"); pcfg = isis_sr_cfg_prefix_add(area, &prefix, algorithm); pcfg->algorithm = algorithm; @@ -2594,13 +2676,13 @@ int isis_instance_segment_routing_algorithm_prefix_sid_pre_validate( enum sr_sid_value_type sid_type; struct isis_prefix_sid psid = {}; - yang_dnode_get_prefix(&prefix, args->dnode, "./prefix"); + yang_dnode_get_prefix(&prefix, args->dnode, "prefix"); srgb_lbound = yang_dnode_get_uint32( args->dnode, "../../label-blocks/srgb/lower-bound"); srgb_ubound = yang_dnode_get_uint32( args->dnode, "../../label-blocks/srgb/upper-bound"); - sid = yang_dnode_get_uint32(args->dnode, "./sid-value"); - sid_type = yang_dnode_get_enum(args->dnode, "./sid-value-type"); + sid = yang_dnode_get_uint32(args->dnode, "sid-value"); + sid_type = yang_dnode_get_enum(args->dnode, "sid-value-type"); /* Check for invalid indexes/labels. */ srgb_range = srgb_ubound - srgb_lbound + 1; @@ -2758,8 +2840,8 @@ int isis_instance_flex_algo_create(struct nb_cb_create_args *args) uint32_t priority = FLEX_ALGO_PRIO_DEFAULT; struct isis_flex_algo_alloc_arg arg; - algorithm = yang_dnode_get_uint32(args->dnode, "./flex-algo"); - advertise = yang_dnode_exists(args->dnode, "./advertise-definition"); + algorithm = yang_dnode_get_uint32(args->dnode, "flex-algo"); + advertise = yang_dnode_exists(args->dnode, "advertise-definition"); switch (args->event) { case NB_EV_APPLY: @@ -2793,7 +2875,7 @@ int isis_instance_flex_algo_destroy(struct nb_cb_destroy_args *args) struct isis_area *area; uint32_t algorithm; - algorithm = yang_dnode_get_uint32(args->dnode, "./flex-algo"); + algorithm = yang_dnode_get_uint32(args->dnode, "flex-algo"); area = nb_running_get_entry(args->dnode, NULL, true); switch (args->event) { @@ -2822,8 +2904,8 @@ int isis_instance_flex_algo_advertise_definition_modify( uint32_t algorithm; - algorithm = yang_dnode_get_uint32(args->dnode, "./../flex-algo"); - advertise = yang_dnode_exists(args->dnode, "./../advertise-definition"); + algorithm = yang_dnode_get_uint32(args->dnode, "../flex-algo"); + advertise = yang_dnode_exists(args->dnode, "../advertise-definition"); switch (args->event) { case NB_EV_APPLY: @@ -2855,7 +2937,7 @@ int isis_instance_flex_algo_advertise_definition_destroy( area = nb_running_get_entry(args->dnode, NULL, true); - algorithm = yang_dnode_get_uint32(args->dnode, "./../flex-algo"); + algorithm = yang_dnode_get_uint32(args->dnode, "../flex-algo"); switch (args->event) { case NB_EV_APPLY: @@ -3071,7 +3153,7 @@ int isis_instance_flex_algo_prefix_metric_create(struct nb_cb_create_args *args) if (!area) return NB_ERR_RESOURCE; - algorithm = yang_dnode_get_uint32(args->dnode, "./../flex-algo"); + algorithm = yang_dnode_get_uint32(args->dnode, "../flex-algo"); switch (args->event) { case NB_EV_APPLY: @@ -3106,7 +3188,7 @@ int isis_instance_flex_algo_prefix_metric_destroy( if (!area) return NB_ERR_RESOURCE; - algorithm = yang_dnode_get_uint32(args->dnode, "./../flex-algo"); + algorithm = yang_dnode_get_uint32(args->dnode, "../flex-algo"); switch (args->event) { case NB_EV_APPLY: @@ -3141,7 +3223,7 @@ static int isis_instance_flex_algo_dplane_set(struct nb_cb_create_args *args, if (!area) return NB_ERR_RESOURCE; - algorithm = yang_dnode_get_uint32(args->dnode, "./../flex-algo"); + algorithm = yang_dnode_get_uint32(args->dnode, "../flex-algo"); switch (args->event) { case NB_EV_APPLY: @@ -3183,7 +3265,7 @@ static int isis_instance_flex_algo_dplane_unset(struct nb_cb_destroy_args *args, if (!area) return NB_ERR_RESOURCE; - algorithm = yang_dnode_get_uint32(args->dnode, "./../flex-algo"); + algorithm = yang_dnode_get_uint32(args->dnode, "../flex-algo"); switch (args->event) { case NB_EV_APPLY: @@ -3266,7 +3348,7 @@ int isis_instance_flex_algo_metric_type_modify(struct nb_cb_modify_args *args) if (!area) return NB_ERR_RESOURCE; - algorithm = yang_dnode_get_uint32(args->dnode, "./../flex-algo"); + algorithm = yang_dnode_get_uint32(args->dnode, "../flex-algo"); metric_type = yang_dnode_get_enum(args->dnode, NULL); switch (args->event) { @@ -3306,7 +3388,7 @@ int isis_instance_flex_algo_priority_modify(struct nb_cb_modify_args *args) if (!area) return NB_ERR_RESOURCE; - algorithm = yang_dnode_get_uint32(args->dnode, "./../flex-algo"); + algorithm = yang_dnode_get_uint32(args->dnode, "../flex-algo"); priority = yang_dnode_get_uint32(args->dnode, NULL); switch (args->event) { @@ -3342,7 +3424,7 @@ int isis_instance_flex_algo_priority_destroy(struct nb_cb_destroy_args *args) if (!area) return NB_ERR_RESOURCE; - algorithm = yang_dnode_get_uint32(args->dnode, "./../flex-algo"); + algorithm = yang_dnode_get_uint32(args->dnode, "../flex-algo"); priority = yang_dnode_get_uint32(args->dnode, NULL); switch (args->event) { @@ -3365,6 +3447,230 @@ int isis_instance_flex_algo_priority_destroy(struct nb_cb_destroy_args *args) return NB_OK; } +/* + * XPath: /frr-isisd:isis/instance/segment-routing-srv6/enabled + */ +int isis_instance_segment_routing_srv6_enabled_modify( + struct nb_cb_modify_args *args) +{ + struct isis_area *area; + + if (args->event != NB_EV_APPLY) + return NB_OK; + + area = nb_running_get_entry(args->dnode, NULL, true); + area->srv6db.config.enabled = yang_dnode_get_bool(args->dnode, NULL); + + if (area->srv6db.config.enabled) { + if (IS_DEBUG_EVENTS) + zlog_debug( + "Segment Routing over IPv6 (SRv6): OFF -> ON"); + } else { + if (IS_DEBUG_EVENTS) + zlog_debug( + "Segment Routing over IPv6 (SRv6): ON -> OFF"); + } + + /* Regenerate LSPs to advertise SRv6 capabilities or signal that the + * node is no longer SRv6-capable. */ + lsp_regenerate_schedule(area, area->is_type, 0); + + return NB_OK; +} + +/* + * XPath: /frr-isisd:isis/instance/segment-routing-srv6/locator + */ +int isis_instance_segment_routing_srv6_locator_modify( + struct nb_cb_modify_args *args) +{ + struct isis_area *area; + const char *loc_name; + + if (args->event != NB_EV_APPLY) + return NB_OK; + + area = nb_running_get_entry(lyd_parent(lyd_parent(args->dnode)), NULL, + true); + + loc_name = yang_dnode_get_string(args->dnode, NULL); + + if (strncmp(loc_name, area->srv6db.config.srv6_locator_name, + sizeof(area->srv6db.config.srv6_locator_name)) == 0) { + snprintf(args->errmsg, args->errmsg_len, + "SRv6 locator %s is already configured", loc_name); + return NB_ERR_NO_CHANGES; + } + + /* Remove previously configured locator */ + if (strncmp(area->srv6db.config.srv6_locator_name, "", + sizeof(area->srv6db.config.srv6_locator_name)) != 0) { + sr_debug("Unsetting previously configured SRv6 locator"); + if (!isis_srv6_locator_unset(area)) { + zlog_warn("Failed to unset SRv6 locator"); + return NB_ERR; + } + } + + strlcpy(area->srv6db.config.srv6_locator_name, loc_name, + sizeof(area->srv6db.config.srv6_locator_name)); + + sr_debug("Configured SRv6 locator %s for IS-IS area %s", loc_name, + area->area_tag); + + sr_debug("Trying to get a chunk from locator %s for IS-IS area %s", + loc_name, area->area_tag); + + if (isis_zebra_srv6_manager_get_locator_chunk(loc_name) < 0) + return NB_ERR; + + return NB_OK; +} + +int isis_instance_segment_routing_srv6_locator_destroy( + struct nb_cb_destroy_args *args) +{ + struct isis_area *area; + const char *loc_name; + + if (args->event != NB_EV_APPLY) + return NB_OK; + + area = nb_running_get_entry(lyd_parent(lyd_parent(args->dnode)), NULL, + true); + + loc_name = yang_dnode_get_string(args->dnode, NULL); + + sr_debug("Trying to unset SRv6 locator %s", loc_name); + + if (strncmp(loc_name, area->srv6db.config.srv6_locator_name, + sizeof(area->srv6db.config.srv6_locator_name)) != 0) { + sr_debug("SRv6 locator %s is not configured", loc_name); + snprintf(args->errmsg, args->errmsg_len, + "SRv6 locator %s is not configured", loc_name); + return NB_ERR_NO_CHANGES; + } + + if (!isis_srv6_locator_unset(area)) { + zlog_warn("Failed to unset SRv6 locator"); + return NB_ERR; + } + + sr_debug("Deleted SRv6 locator %s for IS-IS area %s", loc_name, + area->area_tag); + + return NB_OK; +} + +/* + * XPath: /frr-isisd:isis/instance/segment-routing-srv6/msd/node-msd/max-segs-left + */ +int isis_instance_segment_routing_srv6_msd_node_msd_max_segs_left_modify( + struct nb_cb_modify_args *args) +{ + struct isis_area *area; + + if (args->event != NB_EV_APPLY) + return NB_OK; + + area = nb_running_get_entry(args->dnode, NULL, true); + area->srv6db.config.max_seg_left_msd = yang_dnode_get_uint8(args->dnode, + NULL); + + /* Update and regenerate LSP */ + lsp_regenerate_schedule(area, area->is_type, 0); + + return NB_OK; +} + +/* + * XPath: /frr-isisd:isis/instance/segment-routing-srv6/msd/node-msd/max-end-pop + */ +int isis_instance_segment_routing_srv6_msd_node_msd_max_end_pop_modify( + struct nb_cb_modify_args *args) +{ + struct isis_area *area; + + if (args->event != NB_EV_APPLY) + return NB_OK; + + area = nb_running_get_entry(args->dnode, NULL, true); + area->srv6db.config.max_end_pop_msd = yang_dnode_get_uint8(args->dnode, + NULL); + + /* Update and regenerate LSP */ + lsp_regenerate_schedule(area, area->is_type, 0); + + return NB_OK; +} + +/* + * XPath: /frr-isisd:isis/instance/segment-routing-srv6/msd/node-msd/max-h-encaps + */ +int isis_instance_segment_routing_srv6_msd_node_msd_max_h_encaps_modify( + struct nb_cb_modify_args *args) +{ + struct isis_area *area; + + if (args->event != NB_EV_APPLY) + return NB_OK; + + area = nb_running_get_entry(args->dnode, NULL, true); + area->srv6db.config.max_h_encaps_msd = yang_dnode_get_uint8(args->dnode, + NULL); + + /* Update and regenerate LSP */ + lsp_regenerate_schedule(area, area->is_type, 0); + + return NB_OK; +} + +/* + * XPath: /frr-isisd:isis/instance/segment-routing-srv6/msd/node-msd/max-end-d + */ +int isis_instance_segment_routing_srv6_msd_node_msd_max_end_d_modify( + struct nb_cb_modify_args *args) +{ + struct isis_area *area; + + if (args->event != NB_EV_APPLY) + return NB_OK; + + area = nb_running_get_entry(args->dnode, NULL, true); + area->srv6db.config.max_end_d_msd = yang_dnode_get_uint8(args->dnode, + NULL); + + /* Update and regenerate LSP */ + lsp_regenerate_schedule(area, area->is_type, 0); + + return NB_OK; +} + +/* + * XPath: /frr-isisd:isis/instance/segment-routing-srv6/interface + */ +int isis_instance_segment_routing_srv6_interface_modify( + struct nb_cb_modify_args *args) +{ + struct isis_area *area; + const char *ifname; + + if (args->event != NB_EV_APPLY) + return NB_OK; + + area = nb_running_get_entry(lyd_parent(lyd_parent(args->dnode)), NULL, + true); + + ifname = yang_dnode_get_string(args->dnode, NULL); + + sr_debug("Changing SRv6 interface for IS-IS area %s to %s", + area->area_tag, ifname); + + isis_srv6_interface_set(area, ifname); + + return NB_OK; +} + /* * XPath: /frr-isisd:isis/instance/mpls/ldp-sync */ @@ -3448,7 +3754,7 @@ int lib_interface_isis_create(struct nb_cb_create_args *args) { struct interface *ifp; struct isis_circuit *circuit = NULL; - const char *area_tag = yang_dnode_get_string(args->dnode, "./area-tag"); + const char *area_tag = yang_dnode_get_string(args->dnode, "area-tag"); switch (args->event) { case NB_EV_PREPARE: diff --git a/isisd/isis_pdu.c b/isisd/isis_pdu.c index 0cd43a7abc..6f410d342e 100644 --- a/isisd/isis_pdu.c +++ b/isisd/isis_pdu.c @@ -111,6 +111,7 @@ struct iih_info { bool v6_usable; struct isis_tlvs *tlvs; + int calculated_type; }; static int process_p2p_hello(struct iih_info *iih) @@ -151,6 +152,76 @@ static int process_p2p_hello(struct iih_info *iih) struct isis_adjacency *adj = iih->circuit->u.p2p.neighbor; /* If an adjacency exists, check it is with the source of the hello * packets */ + if (((iih->circuit->area->is_type == IS_LEVEL_1) && + ((iih->circuit->is_type_config == IS_LEVEL_1_AND_2) || + (iih->circuit->is_type_config == IS_LEVEL_1))) || + ((iih->circuit->area->is_type == IS_LEVEL_1_AND_2) && + (iih->circuit->is_type_config == IS_LEVEL_1) && + ((iih->circ_type == IS_LEVEL_1) || + (iih->circ_type == IS_LEVEL_1_AND_2))) || + ((iih->circuit->area->is_type == IS_LEVEL_1_AND_2) && + (iih->circuit->is_type_config == IS_LEVEL_1_AND_2) && + (iih->circ_type == IS_LEVEL_1))) { + if (!isis_tlvs_area_addresses_match(iih->tlvs, + iih->circuit->area + ->area_addrs)) { + if (IS_DEBUG_ADJ_PACKETS) { + zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s, cir id %u, length %u", + iih->circuit->area->area_tag, + iih->circuit->interface->name, + circuit_t2string( + iih->circuit->is_type), + iih->circuit->circuit_id, + iih->pdu_len); + } + + return ISIS_WARNING; + } + + iih->calculated_type = IS_LEVEL_1; + + } + + else if (((iih->circuit->area->is_type == IS_LEVEL_2) && + ((iih->circuit->is_type_config == IS_LEVEL_1_AND_2) || + (iih->circuit->is_type_config == IS_LEVEL_2))) || + ((iih->circuit->area->is_type == IS_LEVEL_1_AND_2) && + (iih->circuit->is_type_config == IS_LEVEL_2) && + ((iih->circ_type == IS_LEVEL_2) || + (iih->circ_type == IS_LEVEL_1_AND_2))) || + ((iih->circuit->area->is_type == IS_LEVEL_1_AND_2) && + (iih->circuit->is_type_config == IS_LEVEL_1_AND_2) && + (iih->circ_type == IS_LEVEL_2))) { + iih->calculated_type = IS_LEVEL_2; + } + + else if ((iih->circuit->area->is_type == IS_LEVEL_1_AND_2) && + (iih->circuit->is_type_config == IS_LEVEL_1_AND_2) && + (iih->circ_type == IS_LEVEL_1_AND_2)) { + iih->calculated_type = IS_LEVEL_1_AND_2; + + if (!isis_tlvs_area_addresses_match(iih->tlvs, + iih->circuit->area + ->area_addrs)) { + iih->calculated_type = IS_LEVEL_2; + } + } + + else { + if (IS_DEBUG_ADJ_PACKETS) { + if (IS_DEBUG_ADJ_PACKETS) { + zlog_debug("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s, cir id %u, length %u", + iih->circuit->area->area_tag, + iih->circuit->interface->name, + circuit_t2string( + iih->circuit->is_type), + iih->circuit->circuit_id, + iih->pdu_len); + } + } + return ISIS_WARNING; + } + if (adj) { if (memcmp(iih->sys_id, adj->sysid, ISIS_SYS_ID_LEN)) { zlog_debug( @@ -160,12 +231,13 @@ static int process_p2p_hello(struct iih_info *iih) return ISIS_OK; } } - if (!adj || adj->level != iih->circ_type) { + if (!adj || adj->level != iih->calculated_type) { if (!adj) { - adj = isis_new_adj(iih->sys_id, NULL, iih->circ_type, - iih->circuit); + adj = isis_new_adj(iih->sys_id, NULL, + iih->calculated_type, iih->circuit); + } else { - adj->level = iih->circ_type; + adj->level = iih->calculated_type; } iih->circuit->u.p2p.neighbor = adj; /* Build lsp with the new neighbor entry when a new @@ -174,7 +246,7 @@ static int process_p2p_hello(struct iih_info *iih) * when an adjacency is up. This will result in the new * adjacency entry getting added to the lsp tlv neighbor list. */ - adj->circuit_t = iih->circ_type; + adj->circuit_t = iih->calculated_type; isis_adj_state_change(&adj, ISIS_ADJ_INITIALIZING, NULL); adj->sys_type = ISIS_SYSTYPE_UNKNOWN; } @@ -205,45 +277,35 @@ static int process_p2p_hello(struct iih_info *iih) /* 8.2.5.2 a) a match was detected */ if (isis_tlvs_area_addresses_match(iih->tlvs, iih->circuit->area->area_addrs)) { - /* 8.2.5.2 a) 2) If the system is L1 - table 5 */ - if (iih->circuit->area->is_type == IS_LEVEL_1) { + /* 8.2.5.2 a) 2) If the calculated type is L1 - table 5 */ + if (iih->calculated_type == IS_LEVEL_1) { switch (iih->circ_type) { case IS_LEVEL_1: + isis_adj_process_threeway(adj, tw_adj, + iih->calculated_type); + break; case IS_LEVEL_1_AND_2: - if (adj->adj_state != ISIS_ADJ_UP - || adj->adj_usage == ISIS_ADJ_LEVEL1) { + if ((adj->adj_state != ISIS_ADJ_UP) || + (adj->adj_usage == ISIS_ADJ_LEVEL1) || + (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)) { isis_adj_process_threeway(adj, tw_adj, - ISIS_ADJ_LEVEL1); - } - break; - case IS_LEVEL_2: - if (adj->adj_state != ISIS_ADJ_UP) { - /* (7) reject - wrong system type event - */ - zlog_warn("wrongSystemType"); - return ISIS_WARNING; - } else if (adj->adj_usage == ISIS_ADJ_LEVEL1) { - /* (6) down - wrong system */ - isis_adj_state_change(&adj, - ISIS_ADJ_DOWN, - "Wrong System"); + iih->calculated_type); } break; } } - /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */ - if (iih->circuit->area->is_type == IS_LEVEL_1_AND_2) { + /* 8.2.5.2 a) 3) If the calculated type is L1L2 - table 6 */ + if (iih->calculated_type == IS_LEVEL_1_AND_2) { switch (iih->circ_type) { case IS_LEVEL_1: if (adj->adj_state != ISIS_ADJ_UP || adj->adj_usage == ISIS_ADJ_LEVEL1) { isis_adj_process_threeway(adj, tw_adj, - ISIS_ADJ_LEVEL1); - } else if ((adj->adj_usage - == ISIS_ADJ_LEVEL1AND2) - || (adj->adj_usage - == ISIS_ADJ_LEVEL2)) { + iih->calculated_type); + } else if ((adj->adj_usage == ISIS_ADJ_LEVEL2) || + (adj->adj_usage == + ISIS_ADJ_LEVEL1AND2)) { /* (8) down - wrong system */ isis_adj_state_change(&adj, ISIS_ADJ_DOWN, @@ -254,10 +316,10 @@ static int process_p2p_hello(struct iih_info *iih) if (adj->adj_state != ISIS_ADJ_UP || adj->adj_usage == ISIS_ADJ_LEVEL2) { isis_adj_process_threeway(adj, tw_adj, - ISIS_ADJ_LEVEL2); - } else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) - || (adj->adj_usage - == ISIS_ADJ_LEVEL1AND2)) { + iih->calculated_type); + } else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) || + (adj->adj_usage == + ISIS_ADJ_LEVEL1AND2)) { /* (8) down - wrong system */ isis_adj_state_change(&adj, ISIS_ADJ_DOWN, @@ -268,10 +330,9 @@ static int process_p2p_hello(struct iih_info *iih) if (adj->adj_state != ISIS_ADJ_UP || adj->adj_usage == ISIS_ADJ_LEVEL1AND2) { isis_adj_process_threeway(adj, tw_adj, - ISIS_ADJ_LEVEL1AND2); - } else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) - || (adj->adj_usage - == ISIS_ADJ_LEVEL2)) { + iih->calculated_type); + } else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) || + (adj->adj_usage == ISIS_ADJ_LEVEL2)) { /* (8) down - wrong system */ isis_adj_state_change(&adj, ISIS_ADJ_DOWN, @@ -282,44 +343,26 @@ static int process_p2p_hello(struct iih_info *iih) } /* 8.2.5.2 a) 4) If the system is L2 - table 7 */ - if (iih->circuit->area->is_type == IS_LEVEL_2) { + if (iih->calculated_type == IS_LEVEL_2) { switch (iih->circ_type) { - case IS_LEVEL_1: - if (adj->adj_state != ISIS_ADJ_UP) { - /* (5) reject - wrong system type event - */ - zlog_warn("wrongSystemType"); - return ISIS_WARNING; - } else if ((adj->adj_usage - == ISIS_ADJ_LEVEL1AND2) - || (adj->adj_usage - == ISIS_ADJ_LEVEL2)) { - /* (6) down - wrong system */ - isis_adj_state_change(&adj, - ISIS_ADJ_DOWN, - "Wrong System"); - } - break; case IS_LEVEL_1_AND_2: - case IS_LEVEL_2: - if (adj->adj_state != ISIS_ADJ_UP - || adj->adj_usage == ISIS_ADJ_LEVEL2) { + if (adj->adj_state != ISIS_ADJ_UP || + adj->adj_usage == ISIS_ADJ_LEVEL2 || + adj->adj_usage == ISIS_ADJ_LEVEL1AND2) { isis_adj_process_threeway(adj, tw_adj, - ISIS_ADJ_LEVEL2); - } else if (adj->adj_usage - == ISIS_ADJ_LEVEL1AND2) { - /* (6) down - wrong system */ - isis_adj_state_change(&adj, - ISIS_ADJ_DOWN, - "Wrong System"); + iih->calculated_type); } break; + case IS_LEVEL_2: + isis_adj_process_threeway(adj, tw_adj, + iih->calculated_type); + break; } } } /* 8.2.5.2 b) if no match was detected */ else if (listcount(iih->circuit->area->area_addrs) > 0) { - if (iih->circuit->area->is_type == IS_LEVEL_1) { + if (iih->calculated_type == IS_LEVEL_1) { /* 8.2.5.2 b) 1) is_type L1 and adj is not up */ if (adj->adj_state != ISIS_ADJ_UP) { isis_adj_state_change(&adj, ISIS_ADJ_DOWN, @@ -359,7 +402,7 @@ static int process_p2p_hello(struct iih_info *iih) if (adj->adj_state != ISIS_ADJ_UP || adj->adj_usage == ISIS_ADJ_LEVEL2) { isis_adj_process_threeway(adj, tw_adj, - ISIS_ADJ_LEVEL2); + iih->calculated_type); } else if (adj->adj_usage == ISIS_ADJ_LEVEL1) { /* (7) down - wrong system */ isis_adj_state_change(&adj, diff --git a/isisd/isis_redist.c b/isisd/isis_redist.c index 6a822f02fe..2cb08db27b 100644 --- a/isisd/isis_redist.c +++ b/isisd/isis_redist.c @@ -31,6 +31,7 @@ DEFINE_MTYPE_STATIC(ISISD, ISIS_EXT_ROUTE, "ISIS redistributed route"); DEFINE_MTYPE_STATIC(ISISD, ISIS_EXT_INFO, "ISIS redistributed route info"); DEFINE_MTYPE_STATIC(ISISD, ISIS_RMAP_NAME, "ISIS redistribute route-map name"); +DEFINE_MTYPE_STATIC(ISISD, ISIS_REDISTRIBUTE, "ISIS redistribute"); static int redist_protocol(int family) { @@ -61,12 +62,43 @@ static struct route_table *get_ext_info(struct isis *i, int family) return i->ext_info[protocol]; } -static struct isis_redist *get_redist_settings(struct isis_area *area, - int family, int type, int level) +static struct isis_redist *isis_redist_lookup(struct isis_area *area, + int family, int type, int level, + uint16_t table) { int protocol = redist_protocol(family); + struct listnode *node; + struct isis_redist *red; + + if (area->redist_settings[protocol][type][level - 1]) { + for (ALL_LIST_ELEMENTS_RO(area->redist_settings[protocol][type] + [level - 1], + node, red)) + if (red->table == table) + return red; + } + return NULL; +} + +static struct isis_redist *isis_redist_get(struct isis_area *area, int family, + int type, int level, uint16_t table) +{ + struct isis_redist *red; + int protocol; + + red = isis_redist_lookup(area, family, type, level, table); + if (red) + return red; - return &area->redist_settings[protocol][type][level - 1]; + protocol = redist_protocol(family); + if (area->redist_settings[protocol][type][level - 1] == NULL) + area->redist_settings[protocol][type][level - 1] = list_new(); + + red = XCALLOC(MTYPE_ISIS_REDISTRIBUTE, sizeof(struct isis_redist)); + red->table = table; + + listnode_add(area->redist_settings[protocol][type][level - 1], red); + return red; } struct route_table *get_ext_reach(struct isis_area *area, int family, int level) @@ -206,10 +238,57 @@ static void isis_redist_ensure_default(struct isis *isis, int family) info->metric = MAX_WIDE_PATH_METRIC; } +static int _isis_redist_table_is_present(const struct lyd_node *dnode, void *arg) +{ + struct isis_redist_table_present_args *rtda = arg; + + /* This entry is the caller, so skip it. */ + if (yang_dnode_get_uint16(dnode, "table") != + (uint16_t)atoi(rtda->rtda_table)) + return YANG_ITER_CONTINUE; + + /* found */ + rtda->rtda_found = true; + return YANG_ITER_CONTINUE; +} + +static int _isis_redist_table_get_first_cb(const struct lyd_node *dnode, + void *arg) +{ + uint16_t *table = arg; + + *table = yang_dnode_get_uint16(dnode, "table"); + return YANG_ITER_STOP; +} + +uint16_t isis_redist_table_get_first(const struct vty *vty, + struct isis_redist_table_present_args *rtda) +{ + uint16_t table = 0; + + yang_dnode_iterate(_isis_redist_table_get_first_cb, &table, + vty->candidate_config->dnode, + "%s/redistribute/%s[protocol='table'][level='%s']/table", + VTY_CURR_XPATH, rtda->rtda_ip, rtda->rtda_level); + return table; +} + +bool isis_redist_table_is_present(const struct vty *vty, + struct isis_redist_table_present_args *rtda) +{ + rtda->rtda_found = false; + yang_dnode_iterate(_isis_redist_table_is_present, rtda, + vty->candidate_config->dnode, + "%s/redistribute/%s[protocol='table'][level='%s']/table", + VTY_CURR_XPATH, rtda->rtda_ip, rtda->rtda_level); + + return rtda->rtda_found; +} + /* Handle notification about route being added */ void isis_redist_add(struct isis *isis, int type, struct prefix *p, struct prefix_ipv6 *src_p, uint8_t distance, - uint32_t metric, const route_tag_t tag) + uint32_t metric, const route_tag_t tag, uint16_t table) { int family = p->family; struct route_table *ei_table = get_ext_info(isis, family); @@ -249,8 +328,9 @@ void isis_redist_add(struct isis *isis, int type, struct prefix *p, for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) for (level = 1; level <= ISIS_LEVELS; level++) { - redist = get_redist_settings(area, family, type, level); - if (!redist->redist) + redist = isis_redist_lookup(area, family, type, level, + table); + if (!redist || !redist->redist) continue; isis_redist_update_ext_reach(area, level, redist, p, @@ -259,7 +339,7 @@ void isis_redist_add(struct isis *isis, int type, struct prefix *p, } void isis_redist_delete(struct isis *isis, int type, struct prefix *p, - struct prefix_ipv6 *src_p) + struct prefix_ipv6 *src_p, uint16_t table) { int family = p->family; struct route_table *ei_table = get_ext_info(isis, family); @@ -279,7 +359,7 @@ void isis_redist_delete(struct isis *isis, int type, struct prefix *p, * "always" setting will ignore routes with origin * DEFAULT_ROUTE. */ isis_redist_add(isis, DEFAULT_ROUTE, p, NULL, 254, - MAX_WIDE_PATH_METRIC, 0); + MAX_WIDE_PATH_METRIC, 0, table); return; } @@ -302,8 +382,9 @@ void isis_redist_delete(struct isis *isis, int type, struct prefix *p, for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) for (level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) { - redist = get_redist_settings(area, family, type, level); - if (!redist->redist) + redist = isis_redist_lookup(area, family, type, level, + table); + if (!redist || !redist->redist) continue; isis_redist_uninstall(area, level, p, src_p); @@ -329,53 +410,6 @@ static void isis_redist_routemap_set(struct isis_redist *redist, } } -static void isis_redist_update_zebra_subscriptions(struct isis *isis) -{ - struct listnode *node; - struct isis_area *area; - int type; - int level; - int protocol; - - if (isis->vrf_id == VRF_UNKNOWN) - return; - - char do_subscribe[REDIST_PROTOCOL_COUNT][ZEBRA_ROUTE_MAX + 1]; - - memset(do_subscribe, 0, sizeof(do_subscribe)); - - for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) - for (protocol = 0; protocol < REDIST_PROTOCOL_COUNT; protocol++) - for (type = 0; type < ZEBRA_ROUTE_MAX + 1; type++) - for (level = 0; level < ISIS_LEVELS; level++) - if (area->redist_settings[protocol] - [type][level] - .redist - == 1) - do_subscribe[protocol][type] = - 1; - - for (protocol = 0; protocol < REDIST_PROTOCOL_COUNT; protocol++) - for (type = 0; type < ZEBRA_ROUTE_MAX + 1; type++) { - /* This field is actually controlling transmission of - * the IS-IS - * routes to Zebra and has nothing to do with - * redistribution, - * so skip it. */ - if (type == PROTO_TYPE) - continue; - - afi_t afi = afi_for_redist_protocol(protocol); - - if (do_subscribe[protocol][type]) - isis_zebra_redistribute_set(afi, type, - isis->vrf_id); - else - isis_zebra_redistribute_unset(afi, type, - isis->vrf_id); - } -} - void isis_redist_free(struct isis *isis) { struct route_node *rn; @@ -397,11 +431,12 @@ void isis_redist_free(struct isis *isis) } void isis_redist_set(struct isis_area *area, int level, int family, int type, - uint32_t metric, const char *routemap, int originate_type) + uint32_t metric, const char *routemap, int originate_type, + uint16_t table) { int protocol = redist_protocol(family); - struct isis_redist *redist = - get_redist_settings(area, family, type, level); + struct isis_redist *redist = isis_redist_get(area, family, type, level, + table); int i; struct route_table *ei_table; struct route_node *rn; @@ -421,7 +456,8 @@ void isis_redist_set(struct isis_area *area, int level, int family, int type, } } - isis_redist_update_zebra_subscriptions(area->isis); + isis_zebra_redistribute_set(afi_for_redist_protocol(protocol), type, + area->isis->vrf_id, redist->table); if (type == DEFAULT_ROUTE && originate_type == DEFAULT_ORIGINATE_ALWAYS) isis_redist_ensure_default(area->isis, family); @@ -452,18 +488,26 @@ void isis_redist_set(struct isis_area *area, int level, int family, int type, } } -void isis_redist_unset(struct isis_area *area, int level, int family, int type) +void isis_redist_unset(struct isis_area *area, int level, int family, int type, + uint16_t table) { - struct isis_redist *redist = - get_redist_settings(area, family, type, level); + struct isis_redist *redist = isis_redist_lookup(area, family, type, + level, table); struct route_table *er_table = get_ext_reach(area, family, level); struct route_node *rn; struct isis_ext_info *info; + struct list *redist_list; + int protocol = redist_protocol(family); - if (!redist->redist) + if (!redist || !redist->redist) return; redist->redist = 0; + + redist_list = area->redist_settings[protocol][type][level - 1]; + listnode_delete(redist_list, redist); + XFREE(MTYPE_ISIS_REDISTRIBUTE, redist); + if (!er_table) { zlog_warn("%s: External reachability table uninitialized.", __func__); @@ -493,7 +537,8 @@ void isis_redist_unset(struct isis_area *area, int level, int family, int type) } lsp_regenerate_schedule(area, level, 0); - isis_redist_update_zebra_subscriptions(area->isis); + isis_zebra_redistribute_unset(afi_for_redist_protocol(protocol), type, + area->isis->vrf_id, table); } void isis_redist_area_finish(struct isis_area *area) @@ -502,16 +547,30 @@ void isis_redist_area_finish(struct isis_area *area) int protocol; int level; int type; + struct isis_redist *redist; + struct listnode *node, *nnode; + struct list *redist_list; for (protocol = 0; protocol < REDIST_PROTOCOL_COUNT; protocol++) for (level = 0; level < ISIS_LEVELS; level++) { for (type = 0; type < ZEBRA_ROUTE_MAX + 1; type++) { - struct isis_redist *redist; - - redist = &area->redist_settings[protocol][type] - [level]; - redist->redist = 0; - XFREE(MTYPE_ISIS_RMAP_NAME, redist->map_name); + redist_list = area->redist_settings[protocol] + [type][level]; + if (!redist_list) + continue; + for (ALL_LIST_ELEMENTS(redist_list, node, nnode, + redist)) { + redist->redist = 0; + XFREE(MTYPE_ISIS_RMAP_NAME, + redist->map_name); + isis_zebra_redistribute_unset( + afi_for_redist_protocol(protocol), + type, area->isis->vrf_id, + redist->table); + listnode_delete(redist_list, redist); + XFREE(MTYPE_ISIS_REDISTRIBUTE, redist); + } + list_delete(&redist_list); } if (!area->ext_reach[protocol][level]) continue; @@ -523,8 +582,6 @@ void isis_redist_area_finish(struct isis_area *area) route_table_finish(area->ext_reach[protocol][level]); area->ext_reach[protocol][level] = NULL; } - - isis_redist_update_zebra_subscriptions(area->isis); } #ifdef FABRICD @@ -581,7 +638,7 @@ DEFUN (isis_redistribute, routemap = argv[idx_metric_rmap + 1]->arg; } - isis_redist_set(area, level, family, type, metric, routemap, 0); + isis_redist_set(area, level, family, type, metric, routemap, 0, 0); return 0; } @@ -617,7 +674,7 @@ DEFUN (no_isis_redistribute, level = 2; - isis_redist_unset(area, level, family, type); + isis_redist_unset(area, level, family, type, 0); return 0; } @@ -677,7 +734,7 @@ DEFUN (isis_default_originate, } isis_redist_set(area, level, family, DEFAULT_ROUTE, metric, routemap, - originate_type); + originate_type, 0); return 0; } @@ -701,7 +758,7 @@ DEFUN (no_isis_default_originate, level = 2; - isis_redist_unset(area, level, family, DEFAULT_ROUTE); + isis_redist_unset(area, level, family, DEFAULT_ROUTE, 0); return 0; } #endif /* ifdef FABRICD */ @@ -713,7 +770,9 @@ int isis_redist_config_write(struct vty *vty, struct isis_area *area, int level; int write = 0; struct isis_redist *redist; + struct list *redist_list; const char *family_str; + struct listnode *node; if (family == AF_INET) family_str = "ipv4"; @@ -727,25 +786,36 @@ int isis_redist_config_write(struct vty *vty, struct isis_area *area, continue; for (level = 1; level <= ISIS_LEVELS; level++) { - redist = get_redist_settings(area, family, type, level); - if (!redist->redist) + redist_list = area->redist_settings[redist_protocol( + family)][type][level - 1]; + if (!redist_list) continue; - vty_out(vty, " redistribute %s %s", family_str, - zebra_route_string(type)); - if (!fabricd) - vty_out(vty, " level-%d", level); - if (redist->metric) - vty_out(vty, " metric %u", redist->metric); - if (redist->map_name) - vty_out(vty, " route-map %s", redist->map_name); - vty_out(vty, "\n"); - write++; + for (ALL_LIST_ELEMENTS_RO(redist_list, node, redist)) { + if (!redist->redist) + continue; + vty_out(vty, " redistribute %s %s", family_str, + zebra_route_string(type)); + if (type == ZEBRA_ROUTE_TABLE) + vty_out(vty, " %u", redist->table); + if (!fabricd) + vty_out(vty, " level-%d", level); + if (redist->metric) + vty_out(vty, " metric %u", + redist->metric); + if (redist->map_name) + vty_out(vty, " route-map %s", + redist->map_name); + vty_out(vty, "\n"); + write++; + } } } for (level = 1; level <= ISIS_LEVELS; level++) { - redist = - get_redist_settings(area, family, DEFAULT_ROUTE, level); + redist = isis_redist_lookup(area, family, DEFAULT_ROUTE, level, + 0); + if (!redist) + continue; if (!redist->redist) continue; vty_out(vty, " default-information originate %s", diff --git a/isisd/isis_redist.h b/isisd/isis_redist.h index ae5ec2b3b3..688f27e62d 100644 --- a/isisd/isis_redist.h +++ b/isisd/isis_redist.h @@ -26,6 +26,15 @@ struct isis_redist { uint32_t metric; char *map_name; struct route_map *map; + uint16_t table; +}; + +struct isis_redist_table_present_args { + /* from filter.h, struct acl_dup_args */ + const char *rtda_ip; + const char *rtda_level; + const char *rtda_table; + bool rtda_found; }; struct isis; @@ -40,17 +49,24 @@ struct route_table *get_ext_reach(struct isis_area *area, int family, int level); void isis_redist_add(struct isis *isis, int type, struct prefix *p, struct prefix_ipv6 *src_p, uint8_t distance, - uint32_t metric, route_tag_t tag); + uint32_t metric, route_tag_t tag, uint16_t instance); void isis_redist_delete(struct isis *isis, int type, struct prefix *p, - struct prefix_ipv6 *src_p); + struct prefix_ipv6 *src_p, uint16_t tableid); int isis_redist_config_write(struct vty *vty, struct isis_area *area, int family); void isis_redist_init(void); void isis_redist_area_finish(struct isis_area *area); void isis_redist_set(struct isis_area *area, int level, int family, int type, - uint32_t metric, const char *routemap, int originate_type); -void isis_redist_unset(struct isis_area *area, int level, int family, int type); + uint32_t metric, const char *routemap, int originate_type, + uint16_t table); +void isis_redist_unset(struct isis_area *area, int level, int family, int type, + uint16_t table); void isis_redist_free(struct isis *isis); + +bool isis_redist_table_is_present(const struct vty *vty, + struct isis_redist_table_present_args *rtda); +uint16_t isis_redist_table_get_first(const struct vty *vty, + struct isis_redist_table_present_args *rtda); #endif diff --git a/isisd/isis_route.c b/isisd/isis_route.c index be92dcc22e..b907c962be 100644 --- a/isisd/isis_route.c +++ b/isisd/isis_route.c @@ -260,24 +260,6 @@ isis_route_info_new(struct prefix *prefix, struct prefix_ipv6 *src_p, ISIS_CIRCUIT_FLAPPED_AFTER_SPF)) SET_FLAG(rinfo->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC); - /* update neighbor router address */ - switch (prefix->family) { - case AF_INET: - if (depth == 2 && prefix->prefixlen == IPV4_MAX_BITLEN) - adj->router_address = prefix->u.prefix4; - break; - case AF_INET6: - if (depth == 2 && prefix->prefixlen == IPV6_MAX_BITLEN - && (!src_p || !src_p->prefixlen)) { - adj->router_address6 = prefix->u.prefix6; - } - break; - default: - flog_err(EC_LIB_DEVELOPMENT, - "%s: unknown address family [%d]", __func__, - prefix->family); - exit(1); - } adjinfo2nexthop(prefix->family, rinfo->nexthops, adj, sr, label_stack); if (!allow_ecmp) diff --git a/isisd/isis_spf.c b/isisd/isis_spf.c index de467c8262..7a4b45a0de 100644 --- a/isisd/isis_spf.c +++ b/isisd/isis_spf.c @@ -378,6 +378,8 @@ isis_spftree_new(struct isis_area *area, struct lspdb_head *lspdb, static void _isis_spftree_del(struct isis_spftree *spftree) { + void *info, *backup_info; + hash_clean_and_free(&spftree->prefix_sids, NULL); isis_zebra_rlfa_unregister_all(spftree); isis_rlfa_list_clear(spftree); @@ -391,10 +393,12 @@ static void _isis_spftree_del(struct isis_spftree *spftree) list_delete(&spftree->sadj_list); isis_vertex_queue_free(&spftree->tents); isis_vertex_queue_free(&spftree->paths); - isis_route_table_info_free(spftree->route_table->info); - isis_route_table_info_free(spftree->route_table_backup->info); + info = spftree->route_table->info; + backup_info = spftree->route_table_backup->info; route_table_finish(spftree->route_table); route_table_finish(spftree->route_table_backup); + isis_route_table_info_free(info); + isis_route_table_info_free(backup_info); } void isis_spftree_del(struct isis_spftree *spftree) @@ -837,6 +841,7 @@ static int isis_spf_process_lsp(struct isis_spftree *spftree, struct isis_mt_router_info *mt_router_info = NULL; struct prefix_pair ip_info; bool has_valid_psid; + bool loc_is_in_ipv6_reach = false; if (isis_lfa_excise_node_check(spftree, lsp->hdr.lsp_id)) { if (IS_DEBUG_LFA) @@ -1128,6 +1133,50 @@ static int isis_spf_process_lsp(struct isis_spftree *spftree, process_N(spftree, vtype, &ip_info, dist, depth + 1, NULL, parent); } + + /* Process SRv6 Locator TLVs */ + + struct isis_item_list *srv6_locators = isis_lookup_mt_items( + &lsp->tlvs->srv6_locator, spftree->mtid); + + struct isis_srv6_locator_tlv *loc; + for (loc = srv6_locators ? (struct isis_srv6_locator_tlv *) + srv6_locators->head + : NULL; + loc; loc = loc->next) { + + if (loc->algorithm != SR_ALGORITHM_SPF) + continue; + + dist = cost + loc->metric; + vtype = VTYPE_IP6REACH_INTERNAL; + memset(&ip_info, 0, sizeof(ip_info)); + ip_info.dest.family = AF_INET6; + ip_info.dest.u.prefix6 = loc->prefix.prefix; + ip_info.dest.prefixlen = loc->prefix.prefixlen; + + /* An SRv6 Locator can be received in both a Prefix + Reachability TLV and an SRv6 Locator TLV (as per RFC + 9352 section #5). We go through the Prefix Reachability + TLVs and check if the SRv6 Locator is present in some of + them. If we find the SRv6 Locator in some Prefix + Reachbility TLV then it means that we have already + processed it before and we can skip it. */ + for (r = ipv6_reachs ? (struct isis_ipv6_reach *) + ipv6_reachs->head + : NULL; + r; r = r->next) { + if (prefix_same((struct prefix *)&r->prefix, + (struct prefix *)&loc->prefix)) + loc_is_in_ipv6_reach = true; + } + + /* SRv6 locator not present in Prefix Reachability TLV, + * let's process it */ + if (!loc_is_in_ipv6_reach) + process_N(spftree, vtype, &ip_info, dist, + depth + 1, NULL, parent); + } } end: @@ -1843,6 +1892,9 @@ void isis_run_spf(struct isis_spftree *spftree) struct timeval time_end; struct isis_mt_router_info *mt_router_info; uint16_t mtid = 0; +#ifndef FABRICD + bool flex_algo_enabled; +#endif /* ifndef FABRICD */ /* Get time that can't roll backwards. */ monotime(&time_start); @@ -1885,16 +1937,27 @@ void isis_run_spf(struct isis_spftree *spftree) * not supported by the node, it MUST stop participating in such * Flexible-Algorithm. */ - if (flex_algo_id_valid(spftree->algorithm) && - !flex_algo_get_state(spftree->area->flex_algos, - spftree->algorithm)) { - if (!CHECK_FLAG(spftree->flags, F_SPFTREE_DISABLED)) { - isis_spftree_clear(spftree); - SET_FLAG(spftree->flags, F_SPFTREE_DISABLED); + if (flex_algo_id_valid(spftree->algorithm)) { + flex_algo_enabled = isis_flex_algo_elected_supported( + spftree->algorithm, spftree->area); + if (flex_algo_enabled != + flex_algo_get_state(spftree->area->flex_algos, + spftree->algorithm)) { + /* actual state is inconsistent with local LSP */ lsp_regenerate_schedule(spftree->area, spftree->area->is_type, 0); + goto out; + } + if (!flex_algo_enabled) { + if (!CHECK_FLAG(spftree->flags, F_SPFTREE_DISABLED)) { + isis_spftree_clear(spftree); + SET_FLAG(spftree->flags, F_SPFTREE_DISABLED); + lsp_regenerate_schedule(spftree->area, + spftree->area->is_type, + 0); + } + goto out; } - goto out; } #endif /* ifndef FABRICD */ diff --git a/isisd/isis_sr.c b/isisd/isis_sr.c index f928185ffb..1d69dbbbfa 100644 --- a/isisd/isis_sr.c +++ b/isisd/isis_sr.c @@ -923,19 +923,19 @@ static int sr_adj_ip_disabled(struct isis_adjacency *adj, int family, } /** - * Activate local Prefix-SID when loopback interface goes up for IS-IS. + * Update the Node-SID flag of the configured Prefix-SID mappings in response + * to an address addition or removal event. * - * @param ifp Loopback Interface + * @param ifp Interface * * @return 0 */ -static int sr_if_new_hook(struct interface *ifp) +int sr_if_addr_update(struct interface *ifp) { struct sr_prefix_cfg *pcfgs[SR_ALGORITHM_COUNT] = {NULL}; struct isis_circuit *circuit; struct isis_area *area; struct connected *connected; - struct listnode *node; bool need_lsp_regenerate = false; /* Get corresponding circuit */ @@ -947,13 +947,7 @@ static int sr_if_new_hook(struct interface *ifp) if (!area) return 0; - /* - * Update the Node-SID flag of the configured Prefix-SID mappings if - * necessary. This needs to be done here since isisd reads the startup - * configuration before receiving interface information from zebra. - */ - FOR_ALL_INTERFACES_ADDRESSES (ifp, connected, node) { - + frr_each (if_connected, ifp->connected, connected) { for (int i = 0; i < SR_ALGORITHM_COUNT; i++) { pcfgs[i] = isis_sr_cfg_prefix_find( area, connected->address, i); @@ -1313,7 +1307,6 @@ void isis_sr_init(void) hook_register(isis_adj_state_change_hook, sr_adj_state_change); hook_register(isis_adj_ip_enabled_hook, sr_adj_ip_enabled); hook_register(isis_adj_ip_disabled_hook, sr_adj_ip_disabled); - hook_register(isis_if_new_hook, sr_if_new_hook); } /** @@ -1325,5 +1318,4 @@ void isis_sr_term(void) hook_unregister(isis_adj_state_change_hook, sr_adj_state_change); hook_unregister(isis_adj_ip_enabled_hook, sr_adj_ip_enabled); hook_unregister(isis_adj_ip_disabled_hook, sr_adj_ip_disabled); - hook_unregister(isis_if_new_hook, sr_if_new_hook); } diff --git a/isisd/isis_sr.h b/isisd/isis_sr.h index f5f0adf241..4378760299 100644 --- a/isisd/isis_sr.h +++ b/isisd/isis_sr.h @@ -222,6 +222,7 @@ extern struct sr_adjacency *isis_sr_adj_sid_find(struct isis_adjacency *adj, int family, enum sr_adj_type type); extern void isis_area_delete_backup_adj_sids(struct isis_area *area, int level); +extern int sr_if_addr_update(struct interface *ifp); extern char *sr_op2str(char *buf, size_t size, mpls_label_t label_in, mpls_label_t label_out); extern int isis_sr_start(struct isis_area *area); diff --git a/isisd/isis_srv6.c b/isisd/isis_srv6.c new file mode 100644 index 0000000000..1b0c706946 --- /dev/null +++ b/isisd/isis_srv6.c @@ -0,0 +1,862 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * This is an implementation of Segment Routing over IPv6 (SRv6) for IS-IS + * as per RFC 9352 + * https://datatracker.ietf.org/doc/html/rfc9352 + * + * Copyright (C) 2023 Carmine Scarpitta - University of Rome Tor Vergata + */ + +#include <zebra.h> + +#include "srv6.h" +#include "termtable.h" +#include "lib/lib_errors.h" + +#include "isisd/isisd.h" +#include "isisd/isis_adjacency.h" +#include "isisd/isis_misc.h" +#include "isisd/isis_route.h" +#include "isisd/isis_srv6.h" +#include "isisd/isis_zebra.h" + +/* Local variables and functions */ +DEFINE_MTYPE_STATIC(ISISD, ISIS_SRV6_SID, "ISIS SRv6 Segment ID"); +DEFINE_MTYPE_STATIC(ISISD, ISIS_SRV6_INFO, "ISIS SRv6 information"); + +/** + * Fill in SRv6 SID Structure Sub-Sub-TLV with information from an SRv6 SID. + * + * @param sid SRv6 SID configuration + * @param structure_subsubtlv SRv6 SID Structure Sub-Sub-TLV to be updated + */ +void isis_srv6_sid_structure2subsubtlv( + const struct isis_srv6_sid *sid, + struct isis_srv6_sid_structure_subsubtlv *structure_subsubtlv) +{ + /* Set Locator Block length */ + structure_subsubtlv->loc_block_len = sid->structure.loc_block_len; + + /* Set Locator Node length */ + structure_subsubtlv->loc_node_len = sid->structure.loc_node_len; + + /* Set Function length */ + structure_subsubtlv->func_len = sid->structure.func_len; + + /* Set Argument length */ + structure_subsubtlv->arg_len = sid->structure.arg_len; +} + +/** + * Fill in SRv6 End SID Sub-TLV with information from an SRv6 SID. + * + * @param sid SRv6 SID configuration + * @param sid_subtlv SRv6 End SID Sub-TLV to be updated + */ +void isis_srv6_end_sid2subtlv(const struct isis_srv6_sid *sid, + struct isis_srv6_end_sid_subtlv *sid_subtlv) +{ + /* Set SRv6 SID flags */ + sid_subtlv->flags = sid->flags; + + /* Set SRv6 SID behavior */ + sid_subtlv->behavior = sid->behavior; + + /* Set SRv6 SID value */ + sid_subtlv->sid = sid->sid; +} + +/** + * Fill in SRv6 Locator TLV with information from an SRv6 locator. + * + * @param loc SRv6 Locator configuration + * @param loc_tlv SRv6 Locator TLV to be updated + */ +void isis_srv6_locator2tlv(const struct isis_srv6_locator *loc, + struct isis_srv6_locator_tlv *loc_tlv) +{ + /* Set SRv6 Locator metric */ + loc_tlv->metric = loc->metric; + + /* Set SRv6 Locator flags */ + loc_tlv->flags = loc->flags; + + /* Set SRv6 Locator algorithm */ + loc_tlv->algorithm = loc->algorithm; + + /* Set SRv6 Locator prefix */ + loc_tlv->prefix = loc->prefix; +} + +/** + * Unset the SRv6 locator for a given IS-IS area. + * + * @param area IS-IS area + * + * @result True on success, False otherwise + */ +bool isis_srv6_locator_unset(struct isis_area *area) +{ + int ret; + struct listnode *node, *nnode; + struct srv6_locator_chunk *chunk; + struct isis_srv6_sid *sid; + struct srv6_adjacency *sra; + + if (strncmp(area->srv6db.config.srv6_locator_name, "", + sizeof(area->srv6db.config.srv6_locator_name)) == 0) { + sr_debug("SRv6 locator not set"); + return true; + } + + /* Delete SRv6 SIDs */ + for (ALL_LIST_ELEMENTS(area->srv6db.srv6_sids, node, nnode, sid)) { + sr_debug( + "Deleting SRv6 SID (locator %s, sid %pI6) from IS-IS area %s", + area->srv6db.config.srv6_locator_name, &sid->sid, + area->area_tag); + + /* Uninstall the SRv6 SID from the forwarding plane through + * Zebra */ + isis_zebra_srv6_sid_uninstall(area, sid); + + listnode_delete(area->srv6db.srv6_sids, sid); + isis_srv6_sid_free(sid); + } + + /* Uninstall all local Adjacency-SIDs. */ + for (ALL_LIST_ELEMENTS(area->srv6db.srv6_endx_sids, node, nnode, sra)) + srv6_endx_sid_del(sra); + + /* Inform Zebra that we are releasing the SRv6 locator */ + ret = isis_zebra_srv6_manager_release_locator_chunk( + area->srv6db.config.srv6_locator_name); + if (ret < 0) + return false; + + /* Delete chunks */ + for (ALL_LIST_ELEMENTS(area->srv6db.srv6_locator_chunks, node, nnode, + chunk)) { + sr_debug( + "Releasing chunk of locator %s (prefix %pFX) for IS-IS area %s", + area->srv6db.config.srv6_locator_name, &chunk->prefix, + area->area_tag); + + listnode_delete(area->srv6db.srv6_locator_chunks, chunk); + srv6_locator_chunk_free(&chunk); + } + + /* Clear locator name */ + memset(area->srv6db.config.srv6_locator_name, 0, + sizeof(area->srv6db.config.srv6_locator_name)); + + /* Regenerate LSPs to advertise that the SRv6 locator no longer exists + */ + lsp_regenerate_schedule(area, area->is_type, 0); + + return true; +} + +/** + * Set the interface used to install SRv6 SIDs into the data plane. + * + * @param area IS-IS area + */ +void isis_srv6_interface_set(struct isis_area *area, const char *ifname) +{ + struct listnode *node; + struct isis_srv6_sid *sid; + + if (!ifname) + return; + + if (!strncmp(ifname, area->srv6db.config.srv6_ifname, IF_NAMESIZE)) { + /* The interface has not changed, nothing to do */ + return; + } + + sr_debug("SRv6 interface for IS-IS area %s changed (old interface: %s, new interface: %s)", area->area_tag, area->srv6db.config.srv6_ifname, ifname); + + /* Walk through all SIDs and uninstall them from the data plane */ + for (ALL_LIST_ELEMENTS_RO(area->srv6db.srv6_sids, node, sid)) { + sr_debug("Uninstalling SID %pI6 from the data plane", &sid->sid); + isis_zebra_srv6_sid_uninstall(area, sid); + } + + strlcpy(area->srv6db.config.srv6_ifname, ifname, sizeof(area->srv6db.config.srv6_ifname)); + + if (!if_lookup_by_name(area->srv6db.config.srv6_ifname, VRF_DEFAULT)) { + sr_debug("Interface %s not yet exist in data plane, deferring SIDs installation until it's created", area->srv6db.config.srv6_ifname); + return; + } + + /* Walk through all SIDs and re-install them into the data plane with the newly configured interface */ + for (ALL_LIST_ELEMENTS_RO(area->srv6db.srv6_sids, node, sid)) { + sr_debug("Installing SID %pI6 from the data plane", &sid->sid); + isis_zebra_srv6_sid_install(area, sid); + } +} + +/** + * Encode SID function in the SRv6 SID. + * + * @param sid + * @param func + * @param offset + * @param len + */ +static void encode_sid_func(struct in6_addr *sid, uint32_t func, uint8_t offset, + uint8_t len) +{ + for (uint8_t idx = 0; idx < len; idx++) { + uint8_t tidx = offset + idx; + sid->s6_addr[tidx / 8] &= ~(0x1 << (7 - tidx % 8)); + if (func >> (len - 1 - idx) & 0x1) + sid->s6_addr[tidx / 8] |= 0x1 << (7 - tidx % 8); + } +} + +static bool sid_exist(struct isis_area *area, const struct in6_addr *sid) +{ + struct listnode *node; + struct isis_srv6_sid *s; + struct srv6_adjacency *sra; + + for (ALL_LIST_ELEMENTS_RO(area->srv6db.srv6_sids, node, s)) + if (sid_same(&s->sid, sid)) + return true; + for (ALL_LIST_ELEMENTS_RO(area->srv6db.srv6_endx_sids, node, sra)) + if (sid_same(&sra->sid, sid)) + return true; + return false; +} + +/** + * Request a SID from the SRv6 locator. + * + * @param area IS-IS area + * @param chunk SRv6 locator chunk + * @param sid_func The FUNCTION part of the SID to be allocated (a negative + * number will allocate the first available SID) + * + * @return First available SID on success or in6addr_any if the SRv6 + * locator chunk is full + */ +static struct in6_addr +srv6_locator_request_sid(struct isis_area *area, + struct srv6_locator_chunk *chunk, int sid_func) +{ + struct in6_addr sid; + uint8_t offset = 0; + uint8_t func_len = 0; + uint32_t func_max; + bool allocated = false; + + if (!area || !chunk) + return in6addr_any; + + sr_debug("ISIS-SRv6 (%s): requested new SID from locator %s", + area->area_tag, chunk->locator_name); + + /* Let's build the SID, step by step. A SID has the following structure + (defined in RFC 8986): LOCATOR:FUNCTION:ARGUMENT.*/ + + /* First, we encode the LOCATOR in the L most significant bits. */ + sid = chunk->prefix.prefix; + + /* The next part of the SID is the FUNCTION. Let's compute the length + * and the offset of the FUNCTION in the SID */ + func_len = chunk->function_bits_length; + offset = chunk->block_bits_length + chunk->node_bits_length; + + /* Then, encode the FUNCTION */ + if (sid_func >= 0) { + /* SID FUNCTION has been specified. We need to allocate a SID + * with the requested FUNCTION. */ + encode_sid_func(&sid, sid_func, offset, func_len); + if (sid_exist(area, &sid)) { + zlog_warn( + "ISIS-SRv6 (%s): the requested SID %pI6 is already used", + area->area_tag, &sid); + return sid; + } + allocated = true; + } else { + /* SID FUNCTION not specified. We need to choose a FUNCTION that + * is not already used. So let's iterate through all possible + * functions and get the first available one. */ + func_max = (1 << func_len) - 1; + for (uint32_t func = 1; func < func_max; func++) { + encode_sid_func(&sid, func, offset, func_len); + if (sid_exist(area, &sid)) + continue; + allocated = true; + break; + } + } + + if (!allocated) { + /* We ran out of available SIDs */ + zlog_warn("ISIS-SRv6 (%s): no SIDs available in locator %s", + area->area_tag, chunk->locator_name); + return in6addr_any; + } + + sr_debug("ISIS-SRv6 (%s): allocating new SID %pI6", area->area_tag, + &sid); + + return sid; +} + +/** + * Allocate an SRv6 SID from an SRv6 locator. + * + * @param area IS-IS area + * @param chunk SRv6 locator chunk + * @param behavior SRv6 Endpoint Behavior bound to the SID + * + * @result the allocated SID on success, NULL otherwise + */ +struct isis_srv6_sid * +isis_srv6_sid_alloc(struct isis_area *area, struct srv6_locator_chunk *chunk, + enum srv6_endpoint_behavior_codepoint behavior, + int sid_func) +{ + struct isis_srv6_sid *sid = NULL; + + if (!area || !chunk) + return NULL; + + sid = XCALLOC(MTYPE_ISIS_SRV6_SID, sizeof(struct isis_srv6_sid)); + + sid->sid = srv6_locator_request_sid(area, chunk, sid_func); + if (IPV6_ADDR_SAME(&sid->sid, &in6addr_any)) { + isis_srv6_sid_free(sid); + return NULL; + } + + sid->behavior = behavior; + sid->structure.loc_block_len = chunk->block_bits_length; + sid->structure.loc_node_len = chunk->node_bits_length; + sid->structure.func_len = chunk->function_bits_length; + sid->structure.arg_len = chunk->argument_bits_length; + sid->locator = chunk; + sid->area = area; + + return sid; +} + +void isis_srv6_sid_free(struct isis_srv6_sid *sid) +{ + XFREE(MTYPE_ISIS_SRV6_SID, sid); +} + +/** + * Delete all backup SRv6 End.X SIDs. + * + * @param area IS-IS area + * @param level IS-IS level + */ +void isis_area_delete_backup_srv6_endx_sids(struct isis_area *area, int level) +{ + struct srv6_adjacency *sra; + struct listnode *node, *nnode; + + for (ALL_LIST_ELEMENTS(area->srv6db.srv6_endx_sids, node, nnode, sra)) + if (sra->type == ISIS_SRV6_LAN_BACKUP && + (sra->adj->level & level)) + srv6_endx_sid_del(sra); +} + +/* --- SRv6 End.X SID management functions ------------------- */ + +/** + * Add new local End.X SID. + * + * @param adj IS-IS Adjacency + * @param backup True to initialize backup Adjacency SID + * @param nexthops List of backup nexthops (for backup End.X SIDs only) + */ +void srv6_endx_sid_add_single(struct isis_adjacency *adj, bool backup, + struct list *nexthops) +{ + struct isis_circuit *circuit = adj->circuit; + struct isis_area *area = circuit->area; + struct srv6_adjacency *sra; + struct isis_srv6_endx_sid_subtlv *adj_sid; + struct isis_srv6_lan_endx_sid_subtlv *ladj_sid; + struct in6_addr nexthop; + uint8_t flags = 0; + struct srv6_locator_chunk *chunk; + uint32_t behavior; + + if (!area || !area->srv6db.srv6_locator_chunks || + list_isempty(area->srv6db.srv6_locator_chunks)) + return; + + sr_debug("ISIS-SRv6 (%s): Add %s End.X SID", area->area_tag, + backup ? "Backup" : "Primary"); + + /* Determine nexthop IP address */ + if (!circuit->ipv6_router || !adj->ll_ipv6_count) + return; + + chunk = (struct srv6_locator_chunk *)listgetdata( + listhead(area->srv6db.srv6_locator_chunks)); + if (!chunk) + return; + + nexthop = adj->ll_ipv6_addrs[0]; + + /* Prepare SRv6 End.X as per RFC9352 section #8.1 */ + if (backup) + SET_FLAG(flags, EXT_SUBTLV_LINK_SRV6_ENDX_SID_BFLG); + + if (circuit->ext == NULL) + circuit->ext = isis_alloc_ext_subtlvs(); + + behavior = (CHECK_FLAG(chunk->flags, SRV6_LOCATOR_USID)) + ? SRV6_ENDPOINT_BEHAVIOR_END_X_NEXT_CSID + : SRV6_ENDPOINT_BEHAVIOR_END_X; + + sra = XCALLOC(MTYPE_ISIS_SRV6_INFO, sizeof(*sra)); + sra->type = backup ? ISIS_SRV6_LAN_BACKUP : ISIS_SRV6_ADJ_NORMAL; + sra->behavior = behavior; + sra->locator = chunk; + sra->structure.loc_block_len = chunk->block_bits_length; + sra->structure.loc_node_len = chunk->node_bits_length; + sra->structure.func_len = chunk->function_bits_length; + sra->structure.arg_len = chunk->argument_bits_length; + sra->nexthop = nexthop; + + sra->sid = srv6_locator_request_sid(area, chunk, -1); + if (IPV6_ADDR_SAME(&sra->sid, &in6addr_any)) { + XFREE(MTYPE_ISIS_SRV6_INFO, sra); + return; + } + + switch (circuit->circ_type) { + /* SRv6 LAN End.X SID for Broadcast interface section #8.2 */ + case CIRCUIT_T_BROADCAST: + ladj_sid = XCALLOC(MTYPE_ISIS_SUBTLV, sizeof(*ladj_sid)); + memcpy(ladj_sid->neighbor_id, adj->sysid, + sizeof(ladj_sid->neighbor_id)); + ladj_sid->flags = flags; + ladj_sid->algorithm = SR_ALGORITHM_SPF; + ladj_sid->weight = 0; + ladj_sid->behavior = sra->behavior; + ladj_sid->sid = sra->sid; + ladj_sid->subsubtlvs = isis_alloc_subsubtlvs( + ISIS_CONTEXT_SUBSUBTLV_SRV6_ENDX_SID); + ladj_sid->subsubtlvs->srv6_sid_structure = XCALLOC( + MTYPE_ISIS_SUBSUBTLV, + sizeof(*ladj_sid->subsubtlvs->srv6_sid_structure)); + ladj_sid->subsubtlvs->srv6_sid_structure->loc_block_len = + sra->structure.loc_block_len; + ladj_sid->subsubtlvs->srv6_sid_structure->loc_node_len = + sra->structure.loc_node_len; + ladj_sid->subsubtlvs->srv6_sid_structure->func_len = + sra->structure.func_len; + ladj_sid->subsubtlvs->srv6_sid_structure->arg_len = + sra->structure.arg_len; + isis_tlvs_add_srv6_lan_endx_sid(circuit->ext, ladj_sid); + sra->u.lendx_sid = ladj_sid; + break; + /* SRv6 End.X SID for Point to Point interface section #8.1 */ + case CIRCUIT_T_P2P: + adj_sid = XCALLOC(MTYPE_ISIS_SUBTLV, sizeof(*adj_sid)); + adj_sid->flags = flags; + adj_sid->algorithm = SR_ALGORITHM_SPF; + adj_sid->weight = 0; + adj_sid->behavior = sra->behavior; + adj_sid->sid = sra->sid; + adj_sid->subsubtlvs = isis_alloc_subsubtlvs( + ISIS_CONTEXT_SUBSUBTLV_SRV6_ENDX_SID); + adj_sid->subsubtlvs->srv6_sid_structure = XCALLOC( + MTYPE_ISIS_SUBSUBTLV, + sizeof(*adj_sid->subsubtlvs->srv6_sid_structure)); + adj_sid->subsubtlvs->srv6_sid_structure->loc_block_len = + sra->structure.loc_block_len; + adj_sid->subsubtlvs->srv6_sid_structure->loc_node_len = + sra->structure.loc_node_len; + adj_sid->subsubtlvs->srv6_sid_structure->func_len = + sra->structure.func_len; + adj_sid->subsubtlvs->srv6_sid_structure->arg_len = + sra->structure.arg_len; + isis_tlvs_add_srv6_endx_sid(circuit->ext, adj_sid); + sra->u.endx_sid = adj_sid; + break; + default: + flog_err(EC_LIB_DEVELOPMENT, "%s: unexpected circuit type: %u", + __func__, circuit->circ_type); + exit(1); + } + + /* Add Adjacency-SID in SRDB */ + sra->adj = adj; + listnode_add(area->srv6db.srv6_endx_sids, sra); + listnode_add(adj->srv6_endx_sids, sra); + + isis_zebra_srv6_adj_sid_install(sra); +} + +/** + * Add Primary and Backup local SRv6 End.X SID. + * + * @param adj IS-IS Adjacency + */ +void srv6_endx_sid_add(struct isis_adjacency *adj) +{ + srv6_endx_sid_add_single(adj, false, NULL); +} + +/** + * Delete local SRv6 End.X SID. + * + * @param sra SRv6 Adjacency + */ +void srv6_endx_sid_del(struct srv6_adjacency *sra) +{ + struct isis_circuit *circuit = sra->adj->circuit; + struct isis_area *area = circuit->area; + + sr_debug("ISIS-SRv6 (%s): Delete SRv6 End.X SID", area->area_tag); + + isis_zebra_srv6_adj_sid_uninstall(sra); + + /* Release dynamic SRv6 SID and remove subTLVs */ + switch (circuit->circ_type) { + case CIRCUIT_T_BROADCAST: + isis_tlvs_del_srv6_lan_endx_sid(circuit->ext, sra->u.lendx_sid); + break; + case CIRCUIT_T_P2P: + isis_tlvs_del_srv6_endx_sid(circuit->ext, sra->u.endx_sid); + break; + default: + flog_err(EC_LIB_DEVELOPMENT, "%s: unexpected circuit type: %u", + __func__, circuit->circ_type); + exit(1); + } + + if (sra->type == ISIS_SRV6_LAN_BACKUP && sra->backup_nexthops) { + sra->backup_nexthops->del = + (void (*)(void *))isis_nexthop_delete; + list_delete(&sra->backup_nexthops); + } + + /* Remove Adjacency-SID from the SRDB */ + listnode_delete(area->srv6db.srv6_endx_sids, sra); + listnode_delete(sra->adj->srv6_endx_sids, sra); + XFREE(MTYPE_ISIS_SRV6_INFO, sra); +} + +/** + * Lookup SRv6 End.X SID by type. + * + * @param adj IS-IS Adjacency + * @param type SRv6 End.X SID type + */ +struct srv6_adjacency *isis_srv6_endx_sid_find(struct isis_adjacency *adj, + enum srv6_adj_type type) +{ + struct srv6_adjacency *sra; + struct listnode *node; + + for (ALL_LIST_ELEMENTS_RO(adj->srv6_endx_sids, node, sra)) + if (sra->type == type) + return sra; + + return NULL; +} + +/** + * Remove all SRv6 End.X SIDs associated to an adjacency that is going down. + * + * @param adj IS-IS Adjacency + * + * @return 0 + */ +static int srv6_adj_state_change(struct isis_adjacency *adj) +{ + struct srv6_adjacency *sra; + struct listnode *node, *nnode; + + if (!adj->circuit->area->srv6db.config.enabled) + return 0; + + if (adj->adj_state == ISIS_ADJ_UP) + return 0; + + for (ALL_LIST_ELEMENTS(adj->srv6_endx_sids, node, nnode, sra)) + srv6_endx_sid_del(sra); + + return 0; +} + +/** + * When IS-IS Adjacency got one or more IPv6 addresses, add new + * IPv6 address to corresponding SRv6 End.X SID accordingly. + * + * @param adj IS-IS Adjacency + * @param family Inet Family (IPv4 or IPv6) + * @param global Indicate if it concerns the Local or Global IPv6 addresses + * + * @return 0 + */ +static int srv6_adj_ip_enabled(struct isis_adjacency *adj, int family, + bool global) +{ + if (!adj->circuit->area->srv6db.config.enabled || global || + family != AF_INET6) + return 0; + + srv6_endx_sid_add(adj); + + return 0; +} + +/** + * When IS-IS Adjacency doesn't have any IPv6 addresses anymore, + * delete the corresponding SRv6 End.X SID(s) accordingly. + * + * @param adj IS-IS Adjacency + * @param family Inet Family (IPv4 or IPv6) + * @param global Indicate if it concerns the Local or Global IPv6 addresses + * + * @return 0 + */ +static int srv6_adj_ip_disabled(struct isis_adjacency *adj, int family, + bool global) +{ + struct srv6_adjacency *sra; + struct listnode *node, *nnode; + + if (!adj->circuit->area->srv6db.config.enabled || global || + family != AF_INET6) + return 0; + + for (ALL_LIST_ELEMENTS(adj->srv6_endx_sids, node, nnode, sra)) + srv6_endx_sid_del(sra); + + return 0; +} + +/** + * Show Segment Routing over IPv6 (SRv6) Node. + * + * @param vty VTY output + * @param area IS-IS area + * @param level IS-IS level + */ +static void show_node(struct vty *vty, struct isis_area *area, int level) +{ + struct isis_lsp *lsp; + struct ttable *tt; + + vty_out(vty, " IS-IS %s SRv6-Nodes:\n\n", circuit_t2string(level)); + + /* Prepare table. */ + tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]); + ttable_add_row( + tt, + "System ID|Algorithm|SRH Max SL|SRH Max End Pop|SRH Max H.encaps|SRH Max End D"); + tt->style.cell.rpad = 2; + tt->style.corner = '+'; + ttable_restyle(tt); + ttable_rowseps(tt, 0, BOTTOM, true, '-'); + + frr_each (lspdb, &area->lspdb[level - 1], lsp) { + struct isis_router_cap *cap; + + if (!lsp->tlvs) + continue; + cap = lsp->tlvs->router_cap; + if (!cap) + continue; + + ttable_add_row(tt, "%pSY|%s|%u|%u|%u|%u", lsp->hdr.lsp_id, + cap->algo[0] == SR_ALGORITHM_SPF ? "SPF" + : "S-SPF", + cap->srv6_msd.max_seg_left_msd, + cap->srv6_msd.max_end_pop_msd, + cap->srv6_msd.max_h_encaps_msd, + cap->srv6_msd.max_end_d_msd); + } + + /* Dump the generated table. */ + if (tt->nrows > 1) { + char *table; + + table = ttable_dump(tt, "\n"); + vty_out(vty, "%s\n", table); + XFREE(MTYPE_TMP, table); + } + ttable_del(tt); +} + +DEFUN(show_srv6_node, show_srv6_node_cmd, + "show " PROTO_NAME " segment-routing srv6 node", + SHOW_STR + PROTO_HELP + "Segment-Routing\n" + "Segment-Routing over IPv6 (SRv6)\n" + "SRv6 node\n") +{ + struct listnode *node, *inode; + struct isis_area *area; + struct isis *isis; + + for (ALL_LIST_ELEMENTS_RO(im->isis, inode, isis)) { + for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) { + vty_out(vty, "Area %s:\n", + area->area_tag ? area->area_tag : "null"); + if (!area->srv6db.config.enabled) { + vty_out(vty, " SRv6 is disabled\n"); + continue; + } + for (int level = ISIS_LEVEL1; level <= ISIS_LEVELS; + level++) + show_node(vty, area, level); + } + } + + return CMD_SUCCESS; +} + +int isis_srv6_ifp_up_notify(struct interface *ifp) +{ + struct isis *isis = isis_lookup_by_vrfid(VRF_DEFAULT); + struct listnode *node, *node2; + struct isis_area *area; + struct isis_srv6_sid *sid; + + if (!isis) + return 0; + + /* Walk through all areas of the ISIS instance */ + for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) { + /* Skip area, if SRv6 is not enabled */ + if (!area->srv6db.config.enabled) + continue; + + /* Skip area if the interface is not the one configured for SRv6 */ + if (strncmp(area->srv6db.config.srv6_ifname, ifp->name, IF_NAMESIZE)) + continue; + + sr_debug("Interface %s went up. Installing SIDs for area %s in data plane", ifp->name, area->area_tag); + + /* Walk through all SIDs and re-install them into the data plane with the newly configured interface */ + for (ALL_LIST_ELEMENTS_RO(area->srv6db.srv6_sids, node2, sid)) { + sr_debug("Installing SID %pI6 from the data plane", &sid->sid); + isis_zebra_srv6_sid_install(area, sid); + } + } + + return 0; +} + +/** + * IS-IS SRv6 initialization for given area. + * + * @param area IS-IS area + */ +void isis_srv6_area_init(struct isis_area *area) +{ + struct isis_srv6_db *srv6db; + + if (!area) + return; + + srv6db = &area->srv6db; + + sr_debug("ISIS-SRv6 (%s): Initialize Segment Routing SRv6 DB", + area->area_tag); + + /* Initialize SRv6 Data Base */ + memset(srv6db, 0, sizeof(*srv6db)); + srv6db->srv6_endx_sids = list_new(); + + /* Pull defaults from the YANG module */ +#ifndef FABRICD + srv6db->config.enabled = yang_get_default_bool("%s/enabled", ISIS_SRV6); + srv6db->config.max_seg_left_msd = + yang_get_default_uint8("%s/msd/node-msd/max-segs-left", + ISIS_SRV6); + srv6db->config.max_end_pop_msd = + yang_get_default_uint8("%s/msd/node-msd/max-end-pop", ISIS_SRV6); + srv6db->config.max_h_encaps_msd = + yang_get_default_uint8("%s/msd/node-msd/max-h-encaps", + ISIS_SRV6); + srv6db->config.max_end_d_msd = + yang_get_default_uint8("%s/msd/node-msd/max-end-d", ISIS_SRV6); + strlcpy(srv6db->config.srv6_ifname, yang_get_default_string("%s/interface", ISIS_SRV6), sizeof(srv6db->config.srv6_ifname)); +#else + srv6db->config.enabled = false; + srv6db->config.max_seg_left_msd = ISIS_DEFAULT_SRV6_MAX_SEG_LEFT_MSD; + srv6db->config.max_end_pop_msd = ISIS_DEFAULT_SRV6_MAX_END_POP_MSD; + srv6db->config.max_h_encaps_msd = ISIS_DEFAULT_SRV6_MAX_H_ENCAPS_MSD; + srv6db->config.max_end_d_msd = ISIS_DEFAULT_SRV6_MAX_END_D_MSD; + strlcpy(srv6db->config.srv6_ifname, ISIS_DEFAULT_SRV6_IFNAME, sizeof(srv6db->config.srv6_ifname)); +#endif + + /* Initialize SRv6 Locator chunks list */ + srv6db->srv6_locator_chunks = list_new(); + + /* Initialize SRv6 SIDs list */ + srv6db->srv6_sids = list_new(); + srv6db->srv6_sids->del = (void (*)(void *))isis_srv6_sid_free; +} + +/** + * Terminate IS-IS SRv6 for the given area. + * + * @param area IS-IS area + */ +void isis_srv6_area_term(struct isis_area *area) +{ + struct isis_srv6_db *srv6db = &area->srv6db; + struct srv6_adjacency *sra; + struct listnode *node, *nnode; + struct srv6_locator_chunk *chunk; + + sr_debug("ISIS-SRv6 (%s): Terminate SRv6", area->area_tag); + + /* Uninstall all local SRv6 End.X SIDs */ + if (area->srv6db.config.enabled) + for (ALL_LIST_ELEMENTS(area->srv6db.srv6_endx_sids, node, nnode, + sra)) + srv6_endx_sid_del(sra); + + /* Free SRv6 Locator chunks list */ + for (ALL_LIST_ELEMENTS(srv6db->srv6_locator_chunks, node, nnode, chunk)) + srv6_locator_chunk_free(&chunk); + list_delete(&srv6db->srv6_locator_chunks); + + /* Free SRv6 SIDs list */ + list_delete(&srv6db->srv6_sids); + list_delete(&srv6db->srv6_endx_sids); +} + +/** + * IS-IS SRv6 global initialization. + */ +void isis_srv6_init(void) +{ + install_element(VIEW_NODE, &show_srv6_node_cmd); + + /* Register hooks. */ + hook_register(isis_adj_state_change_hook, srv6_adj_state_change); + hook_register(isis_adj_ip_enabled_hook, srv6_adj_ip_enabled); + hook_register(isis_adj_ip_disabled_hook, srv6_adj_ip_disabled); +} + +/** + * IS-IS SRv6 global terminate. + */ +void isis_srv6_term(void) +{ + /* Unregister hooks. */ + hook_unregister(isis_adj_state_change_hook, srv6_adj_state_change); + hook_unregister(isis_adj_ip_enabled_hook, srv6_adj_ip_enabled); + hook_unregister(isis_adj_ip_disabled_hook, srv6_adj_ip_disabled); +} diff --git a/isisd/isis_srv6.h b/isisd/isis_srv6.h new file mode 100644 index 0000000000..33864360c1 --- /dev/null +++ b/isisd/isis_srv6.h @@ -0,0 +1,181 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * This is an implementation of Segment Routing over IPv6 (SRv6) for IS-IS + * as per RFC 9352 + * https://datatracker.ietf.org/doc/html/rfc9352 + * + * Copyright (C) 2023 Carmine Scarpitta - University of Rome Tor Vergata + */ + +#ifndef _FRR_ISIS_SRV6_H +#define _FRR_ISIS_SRV6_H + +#include "lib/srv6.h" +#include "isisd/isis_tlvs.h" + +#define ISIS_DEFAULT_SRV6_MAX_SEG_LEFT_MSD 3 +#define ISIS_DEFAULT_SRV6_MAX_END_POP_MSD 3 +#define ISIS_DEFAULT_SRV6_MAX_H_ENCAPS_MSD 2 +#define ISIS_DEFAULT_SRV6_MAX_END_D_MSD 5 +#define ISIS_DEFAULT_SRV6_IFNAME "sr0" + +/* SRv6 SID structure */ +struct isis_srv6_sid_structure { + uint8_t loc_block_len; + uint8_t loc_node_len; + uint8_t func_len; + uint8_t arg_len; +}; + +/* SRv6 SID not bound to any adjacency */ +struct isis_srv6_sid { + struct isis_srv6_sid *next; + + /* SID flags */ + uint8_t flags; + + /* SID value */ + struct in6_addr sid; + + /* Endpoint behavior bound to the SID */ + enum srv6_endpoint_behavior_codepoint behavior; + + /* SRv6 SID structure */ + struct isis_srv6_sid_structure structure; + + /* Parent SRv6 locator */ + struct srv6_locator_chunk *locator; + + /* Backpointer to IS-IS area */ + struct isis_area *area; +}; + +/* SRv6 Locator */ +struct isis_srv6_locator { + struct isis_srv6_locator *next; + + uint32_t metric; + + uint8_t flags; +#define ISIS_SRV6_LOCATOR_FLAG_D 1 << 7 + + uint8_t algorithm; + struct prefix_ipv6 prefix; + + struct list *srv6_sid; +}; + +/* SRv6 Adjacency-SID type */ +enum srv6_adj_type { + ISIS_SRV6_ADJ_NORMAL = 0, + ISIS_SRV6_LAN_BACKUP, +}; + +/* SRv6 Adjacency. */ +struct srv6_adjacency { + /* Adjacency type */ + enum srv6_adj_type type; + + /* SID flags */ + uint8_t flags; + + /* SID value */ + struct in6_addr sid; + + /* Endpoint behavior bound to the SID */ + enum srv6_endpoint_behavior_codepoint behavior; + + /* SRv6 SID structure */ + struct isis_srv6_sid_structure structure; + + /* Parent SRv6 locator */ + struct srv6_locator_chunk *locator; + + /* Adjacency-SID nexthop information */ + struct in6_addr nexthop; + + /* End.X SID TI-LFA backup nexthops */ + struct list *backup_nexthops; + + /* SRv6 (LAN) End.X SID Sub-TLV */ + union { + struct isis_srv6_endx_sid_subtlv *endx_sid; + struct isis_srv6_lan_endx_sid_subtlv *lendx_sid; + } u; + + /* Back pointer to IS-IS adjacency. */ + struct isis_adjacency *adj; +}; + +/* Per-area IS-IS SRv6 Data Base (SRv6 DB) */ +struct isis_srv6_db { + + /* List of SRv6 Locator chunks */ + struct list *srv6_locator_chunks; + + /* List of SRv6 SIDs allocated by the IS-IS instance */ + struct list *srv6_sids; + + /* List of SRv6 End.X SIDs allocated by the IS-IS instance */ + struct list *srv6_endx_sids; + + /* Area SRv6 configuration. */ + struct { + /* Administrative status of SRv6 */ + bool enabled; + + /* Name of the SRv6 Locator */ + char srv6_locator_name[SRV6_LOCNAME_SIZE]; + + /* Maximum Segments Left Depth supported by the router */ + uint8_t max_seg_left_msd; + + /* Maximum Maximum End Pop Depth supported by the router */ + uint8_t max_end_pop_msd; + + /* Maximum H.Encaps supported by the router */ + uint8_t max_h_encaps_msd; + + /* Maximum End D MSD supported by the router */ + uint8_t max_end_d_msd; + + /* Interface used for installing SRv6 SIDs into the data plane */ + char srv6_ifname[IF_NAMESIZE]; + } config; +}; + +bool isis_srv6_locator_unset(struct isis_area *area); + +void isis_srv6_interface_set(struct isis_area *area, const char *ifname); + +struct isis_srv6_sid * +isis_srv6_sid_alloc(struct isis_area *area, struct srv6_locator_chunk *chunk, + enum srv6_endpoint_behavior_codepoint behavior, + int sid_func); +extern void isis_srv6_sid_free(struct isis_srv6_sid *sid); + +extern void isis_srv6_area_init(struct isis_area *area); +extern void isis_srv6_area_term(struct isis_area *area); + +void isis_srv6_init(void); +void isis_srv6_term(void); + +void isis_srv6_sid_structure2subsubtlv( + const struct isis_srv6_sid *sid, + struct isis_srv6_sid_structure_subsubtlv *structure_subsubtlv); +void isis_srv6_end_sid2subtlv(const struct isis_srv6_sid *sid, + struct isis_srv6_end_sid_subtlv *sid_subtlv); +void isis_srv6_locator2tlv(const struct isis_srv6_locator *loc, + struct isis_srv6_locator_tlv *loc_tlv); + +void srv6_endx_sid_add_single(struct isis_adjacency *adj, bool backup, + struct list *nexthops); +void srv6_endx_sid_add(struct isis_adjacency *adj); +void srv6_endx_sid_del(struct srv6_adjacency *sra); +struct srv6_adjacency *isis_srv6_endx_sid_find(struct isis_adjacency *adj, + enum srv6_adj_type type); +void isis_area_delete_backup_srv6_endx_sids(struct isis_area *area, int level); + +int isis_srv6_ifp_up_notify(struct interface *ifp); + +#endif /* _FRR_ISIS_SRV6_H */ diff --git a/isisd/isis_tlvs.c b/isisd/isis_tlvs.c index 4ad877ce0f..2b0a58b739 100644 --- a/isisd/isis_tlvs.c +++ b/isisd/isis_tlvs.c @@ -5,11 +5,19 @@ * Copyright (C) 2015,2017 Christian Franke * * Copyright (C) 2019 Olivier Dugeon - Orange Labs (for TE and SR) + * + * Copyright (C) 2023 Carmine Scarpitta - University of Rome Tor Vergata + * (for IS-IS Extensions to Support SRv6 as per RFC 9352) */ #include <zebra.h> #include <json-c/json_object.h> +#ifdef CRYPTO_OPENSSL +#include <openssl/evp.h> +#include <openssl/hmac.h> +#endif + #ifdef CRYPTO_INTERNAL #include "md5.h" #endif @@ -37,7 +45,7 @@ DEFINE_MTYPE_STATIC(ISISD, ISIS_TLV, "ISIS TLVs"); DEFINE_MTYPE(ISISD, ISIS_SUBTLV, "ISIS Sub-TLVs"); -DEFINE_MTYPE_STATIC(ISISD, ISIS_SUBSUBTLV, "ISIS Sub-Sub-TLVs"); +DEFINE_MTYPE(ISISD, ISIS_SUBSUBTLV, "ISIS Sub-Sub-TLVs"); DEFINE_MTYPE_STATIC(ISISD, ISIS_MT_ITEM_LIST, "ISIS MT Item Lists"); typedef int (*unpack_tlv_func)(enum isis_tlv_context context, uint8_t tlv_type, @@ -96,7 +104,8 @@ static const struct pack_order_entry pack_order[] = { PACK_ENTRY(EXTENDED_IP_REACH, ISIS_ITEMS, extended_ip_reach), PACK_ENTRY(MT_IP_REACH, ISIS_MT_ITEMS, mt_ip_reach), PACK_ENTRY(IPV6_REACH, ISIS_ITEMS, ipv6_reach), - PACK_ENTRY(MT_IPV6_REACH, ISIS_MT_ITEMS, mt_ipv6_reach) + PACK_ENTRY(MT_IPV6_REACH, ISIS_MT_ITEMS, mt_ipv6_reach), + PACK_ENTRY(SRV6_LOCATOR, ISIS_MT_ITEMS, srv6_locator) }; /* This is a forward definition. The table is actually initialized @@ -109,6 +118,18 @@ static const struct tlv_ops *const tlv_table[ISIS_CONTEXT_MAX][ISIS_TLV_MAX]; static void append_item(struct isis_item_list *dest, struct isis_item *item); static void init_item_list(struct isis_item_list *items); +static struct isis_subsubtlvs * +isis_copy_subsubtlvs(struct isis_subsubtlvs *subsubtlvs); +static void isis_format_subsubtlvs(struct isis_subsubtlvs *subsubtlvs, + struct sbuf *buf, struct json_object *json, + int indent); +static int isis_pack_subsubtlvs(struct isis_subsubtlvs *subsubtlvs, + struct stream *s); +static int unpack_tlvs(enum isis_tlv_context context, size_t avail_len, + struct stream *stream, struct sbuf *log, void *dest, + int indent, bool *unpacked_known_tlvs); +static void isis_free_subsubtlvs(struct isis_subsubtlvs *subsubtlvs); + /* For tests/isisd, TLV text requires ipv4-unicast instead of standard */ static const char *isis_mtid2str_fake(uint16_t mtid) { @@ -127,6 +148,9 @@ struct isis_ext_subtlvs *isis_alloc_ext_subtlvs(void) init_item_list(&ext->lan_sid); ext->aslas = list_new(); + init_item_list(&ext->srv6_endx_sid); + init_item_list(&ext->srv6_lan_endx_sid); + admin_group_init(&ext->ext_admin_group); return ext; @@ -158,6 +182,18 @@ void isis_del_ext_subtlvs(struct isis_ext_subtlvs *ext) admin_group_term(&ext->ext_admin_group); + /* First, free SRv6 End.X SID and SRv6 LAN End.X SID list if needed */ + for (item = ext->srv6_endx_sid.head; item; item = next_item) { + next_item = item->next; + isis_free_subsubtlvs(((struct isis_srv6_endx_sid_subtlv *)item)->subsubtlvs); + XFREE(MTYPE_ISIS_SUBTLV, item); + } + for (item = ext->srv6_lan_endx_sid.head; item; item = next_item) { + next_item = item->next; + isis_free_subsubtlvs(((struct isis_srv6_lan_endx_sid_subtlv *)item)->subsubtlvs); + XFREE(MTYPE_ISIS_SUBTLV, item); + } + XFREE(MTYPE_ISIS_SUBTLV, ext); } @@ -174,6 +210,8 @@ copy_item_ext_subtlvs(struct isis_ext_subtlvs *exts, uint16_t mtid) struct isis_lan_adj_sid *lan; struct listnode *node, *nnode; struct isis_asla_subtlvs *new_asla, *asla; + struct isis_srv6_endx_sid_subtlv *srv6_adj; + struct isis_srv6_lan_endx_sid_subtlv *srv6_lan; /* Copy the Extended IS main part */ memcpy(rv, exts, sizeof(struct isis_ext_subtlvs)); @@ -192,9 +230,16 @@ copy_item_ext_subtlvs(struct isis_ext_subtlvs *exts, uint16_t mtid) init_item_list(&rv->adj_sid); init_item_list(&rv->lan_sid); + /* Prepare SRv6 (LAN) End.X SID */ + init_item_list(&rv->srv6_endx_sid); + init_item_list(&rv->srv6_lan_endx_sid); + UNSET_SUBTLV(rv, EXT_ADJ_SID); UNSET_SUBTLV(rv, EXT_LAN_ADJ_SID); + UNSET_SUBTLV(rv, EXT_SRV6_ENDX_SID); + UNSET_SUBTLV(rv, EXT_SRV6_LAN_ENDX_SID); + /* Copy Adj SID list for IPv4 & IPv6 in function of MT ID */ for (adj = (struct isis_adj_sid *)exts->adj_sid.head; adj != NULL; adj = adj->next) { @@ -238,6 +283,50 @@ copy_item_ext_subtlvs(struct isis_ext_subtlvs *exts, uint16_t mtid) SET_SUBTLV(rv, EXT_LAN_ADJ_SID); } + /* Copy SRv6 End.X SID list for IPv4 & IPv6 in function of MT ID */ + for (srv6_adj = (struct isis_srv6_endx_sid_subtlv *) + exts->srv6_endx_sid.head; + srv6_adj != NULL; srv6_adj = srv6_adj->next) { + if ((mtid != 65535) && (mtid != ISIS_MT_DISABLE) && + ((mtid != ISIS_MT_IPV6_UNICAST))) + continue; + + struct isis_srv6_endx_sid_subtlv *new; + + new = XCALLOC(MTYPE_ISIS_SUBTLV, + sizeof(struct isis_srv6_endx_sid_subtlv)); + new->flags = srv6_adj->flags; + new->algorithm = srv6_adj->algorithm; + new->weight = srv6_adj->weight; + new->behavior = srv6_adj->behavior; + new->sid = srv6_adj->sid; + new->subsubtlvs = isis_copy_subsubtlvs(srv6_adj->subsubtlvs); + append_item(&rv->srv6_endx_sid, (struct isis_item *)new); + SET_SUBTLV(rv, EXT_SRV6_ENDX_SID); + } + /* Same for SRv6 LAN End.X SID */ + for (srv6_lan = (struct isis_srv6_lan_endx_sid_subtlv *) + exts->srv6_lan_endx_sid.head; + srv6_lan != NULL; srv6_lan = srv6_lan->next) { + if ((mtid != 65535) && (mtid != ISIS_MT_DISABLE) && + ((mtid != ISIS_MT_IPV6_UNICAST))) + continue; + + struct isis_srv6_lan_endx_sid_subtlv *new; + + new = XCALLOC(MTYPE_ISIS_SUBTLV, + sizeof(struct isis_srv6_lan_endx_sid_subtlv)); + memcpy(new->neighbor_id, srv6_lan->neighbor_id, 6); + new->flags = srv6_lan->flags; + new->algorithm = srv6_lan->algorithm; + new->weight = srv6_lan->weight; + new->behavior = srv6_lan->behavior; + new->sid = srv6_lan->sid; + new->subsubtlvs = isis_copy_subsubtlvs(srv6_lan->subsubtlvs); + append_item(&rv->srv6_lan_endx_sid, (struct isis_item *)new); + SET_SUBTLV(rv, EXT_SRV6_LAN_ENDX_SID); + } + rv->aslas = list_new(); for (ALL_LIST_ELEMENTS(exts->aslas, node, nnode, asla)) { @@ -823,6 +912,156 @@ static void format_item_ext_subtlvs(struct isis_ext_subtlvs *exts, lan->neighbor_id); } } + /* SRv6 End.X SID as per RFC9352 section #8.1 */ + if (IS_SUBTLV(exts, EXT_SRV6_ENDX_SID)) { + struct isis_srv6_endx_sid_subtlv *adj; + + if (json) { + struct json_object *arr_adj_json, *flags_json; + arr_adj_json = json_object_new_array(); + json_object_object_add(json, "srv6-endx-sid", + arr_adj_json); + for (adj = (struct isis_srv6_endx_sid_subtlv *) + exts->srv6_endx_sid.head; + adj; adj = adj->next) { + snprintfrr(cnt_buf, sizeof(cnt_buf), "%pI6", + &adj->sid); + flags_json = json_object_new_object(); + json_object_string_addf(flags_json, "sid", + "%pI6", &adj->sid); + json_object_string_add( + flags_json, "algorithm", + sr_algorithm_string(adj->algorithm)); + json_object_int_add(flags_json, "weight", + adj->weight); + json_object_string_add( + flags_json, "behavior", + seg6local_action2str(adj->behavior)); + json_object_string_add( + flags_json, "flag-b", + adj->flags & EXT_SUBTLV_LINK_SRV6_ENDX_SID_BFLG + ? "1" + : "0"); + json_object_string_add( + flags_json, "flag-s", + adj->flags & EXT_SUBTLV_LINK_SRV6_ENDX_SID_SFLG + ? "1" + : "0"); + json_object_string_add( + flags_json, "flag-p", + adj->flags & EXT_SUBTLV_LINK_SRV6_ENDX_SID_PFLG + ? "1" + : "0"); + json_object_array_add(arr_adj_json, flags_json); + if (adj->subsubtlvs) + isis_format_subsubtlvs(adj->subsubtlvs, + NULL, json, + indent + 4); + } + } else + for (adj = (struct isis_srv6_endx_sid_subtlv *) + exts->srv6_endx_sid.head; + adj; adj = adj->next) { + sbuf_push( + buf, indent, + "SRv6 End.X SID: %pI6, Algorithm: %s, Weight: %hhu, Endpoint Behavior: %s, Flags: B:%c, S:%c, P:%c\n", + &adj->sid, + sr_algorithm_string(adj->algorithm), + adj->weight, + seg6local_action2str(adj->behavior), + adj->flags & EXT_SUBTLV_LINK_SRV6_ENDX_SID_BFLG + ? '1' + : '0', + adj->flags & EXT_SUBTLV_LINK_SRV6_ENDX_SID_SFLG + ? '1' + : '0', + adj->flags & EXT_SUBTLV_LINK_SRV6_ENDX_SID_PFLG + ? '1' + : '0'); + if (adj->subsubtlvs) + isis_format_subsubtlvs(adj->subsubtlvs, + buf, NULL, + indent + 4); + } + } + /* SRv6 LAN End.X SID as per RFC9352 section #8.2 */ + if (IS_SUBTLV(exts, EXT_SRV6_LAN_ENDX_SID)) { + struct isis_srv6_lan_endx_sid_subtlv *lan; + if (json) { + struct json_object *arr_adj_json, *flags_json; + arr_adj_json = json_object_new_array(); + json_object_object_add(json, "srv6-lan-endx-sid", + arr_adj_json); + for (lan = (struct isis_srv6_lan_endx_sid_subtlv *) + exts->srv6_lan_endx_sid.head; + lan; lan = lan->next) { + snprintfrr(cnt_buf, sizeof(cnt_buf), "%pI6", + &lan->sid); + flags_json = json_object_new_object(); + json_object_string_addf(flags_json, "sid", + "%pI6", &lan->sid); + json_object_int_add(flags_json, "weight", + lan->weight); + json_object_string_add( + flags_json, "algorithm", + sr_algorithm_string(lan->algorithm)); + json_object_int_add(flags_json, "weight", + lan->weight); + json_object_string_add( + flags_json, "behavior", + seg6local_action2str(lan->behavior)); + json_object_string_add( + flags_json, "flag-b", + lan->flags & EXT_SUBTLV_LINK_SRV6_ENDX_SID_BFLG + ? "1" + : "0"); + json_object_string_add( + flags_json, "flag-s", + lan->flags & EXT_SUBTLV_LINK_SRV6_ENDX_SID_SFLG + ? "1" + : "0"); + json_object_string_add( + flags_json, "flag-p", + lan->flags & EXT_SUBTLV_LINK_SRV6_ENDX_SID_PFLG + ? "1" + : "0"); + json_object_string_addf(flags_json, + "neighbor-id", "%pSY", + lan->neighbor_id); + json_object_array_add(arr_adj_json, flags_json); + if (lan->subsubtlvs) + isis_format_subsubtlvs(lan->subsubtlvs, + NULL, json, + indent + 4); + } + } else + for (lan = (struct isis_srv6_lan_endx_sid_subtlv *) + exts->srv6_lan_endx_sid.head; + lan; lan = lan->next) { + sbuf_push( + buf, indent, + "SRv6 Lan End.X SID: %pI6, Algorithm: %s, Weight: %hhu, Endpoint Behavior: %s, Flags: B:%c, S:%c, P:%c " + "Neighbor-ID: %pSY\n", + &lan->sid, + sr_algorithm_string(lan->algorithm), + lan->weight, + seg6local_action2str(lan->behavior), + lan->flags & EXT_SUBTLV_LINK_SRV6_ENDX_SID_BFLG + ? '1' + : '0', + lan->flags & EXT_SUBTLV_LINK_SRV6_ENDX_SID_SFLG + ? '1' + : '0', + lan->flags & EXT_SUBTLV_LINK_SRV6_ENDX_SID_PFLG + ? '1' + : '0', + lan->neighbor_id); + if (lan->subsubtlvs) + isis_format_subsubtlvs(lan->subsubtlvs, + buf, NULL, + indent + 4); + } + } for (ALL_LIST_ELEMENTS_RO(exts->aslas, node, asla)) format_item_asla_subtlvs(asla, buf, indent); } @@ -1112,6 +1351,89 @@ static int pack_item_ext_subtlvs(struct isis_ext_subtlvs *exts, stream_putl(s, lan->sid); } } + /* SRv6 End.X SID as per RFC9352 section #8.1 */ + if (IS_SUBTLV(exts, EXT_SRV6_ENDX_SID)) { + struct isis_srv6_endx_sid_subtlv *adj; + size_t subtlv_len; + size_t subtlv_len_pos; + + for (adj = (struct isis_srv6_endx_sid_subtlv *) + exts->srv6_endx_sid.head; + adj; adj = adj->next) { + stream_putc(s, ISIS_SUBTLV_SRV6_ENDX_SID); + + subtlv_len_pos = stream_get_endp(s); + stream_putc(s, 0); /* length will be filled later */ + + stream_putc(s, adj->flags); + stream_putc(s, adj->algorithm); + stream_putc(s, adj->weight); + stream_putw(s, adj->behavior); + stream_put(s, &adj->sid, IPV6_MAX_BYTELEN); + + if (adj->subsubtlvs) { + /* Pack Sub-Sub-TLVs */ + if (isis_pack_subsubtlvs(adj->subsubtlvs, s)) + return 1; + } else { + /* No Sub-Sub-TLVs */ + if (STREAM_WRITEABLE(s) < 1) { + *min_len = + ISIS_SUBTLV_SRV6_ENDX_SID_SIZE; + return 1; + } + + /* Put 0 as Sub-Sub-TLV length, because we have + * no Sub-Sub-TLVs */ + stream_putc(s, 0); + } + + subtlv_len = stream_get_endp(s) - subtlv_len_pos - 1; + stream_putc_at(s, subtlv_len_pos, subtlv_len); + } + } + /* SRv6 LAN End.X SID as per RFC9352 section #8.2 */ + if (IS_SUBTLV(exts, EXT_SRV6_LAN_ENDX_SID)) { + struct isis_srv6_lan_endx_sid_subtlv *lan; + size_t subtlv_len; + size_t subtlv_len_pos; + + for (lan = (struct isis_srv6_lan_endx_sid_subtlv *) + exts->srv6_lan_endx_sid.head; + lan; lan = lan->next) { + stream_putc(s, ISIS_SUBTLV_SRV6_LAN_ENDX_SID); + + subtlv_len_pos = stream_get_endp(s); + stream_putc(s, 0); /* length will be filled later */ + + stream_put(s, lan->neighbor_id, 6); + stream_putc(s, lan->flags); + stream_putc(s, lan->algorithm); + stream_putc(s, lan->weight); + stream_putw(s, lan->behavior); + stream_put(s, &lan->sid, IPV6_MAX_BYTELEN); + + if (lan->subsubtlvs) { + /* Pack Sub-Sub-TLVs */ + if (isis_pack_subsubtlvs(lan->subsubtlvs, s)) + return 1; + } else { + /* No Sub-Sub-TLVs */ + if (STREAM_WRITEABLE(s) < 1) { + *min_len = + ISIS_SUBTLV_SRV6_LAN_ENDX_SID_SIZE; + return 1; + } + + /* Put 0 as Sub-Sub-TLV length, because we have + * no Sub-Sub-TLVs */ + stream_putc(s, 0); + } + + subtlv_len = stream_get_endp(s) - subtlv_len_pos - 1; + stream_putc_at(s, subtlv_len_pos, subtlv_len); + } + } for (ALL_LIST_ELEMENTS_RO(exts->aslas, node, asla)) { ret = pack_item_ext_subtlv_asla(asla, s, min_len); @@ -1133,7 +1455,7 @@ static int unpack_item_ext_subtlv_asla(uint16_t mtid, uint8_t subtlv_len, uint8_t uabm_flag_len; uint8_t sabm[ASLA_APP_IDENTIFIER_BIT_LENGTH] = {0}; uint8_t uabm[ASLA_APP_IDENTIFIER_BIT_LENGTH] = {0}; - uint8_t readable; + uint8_t readable = subtlv_len; uint8_t subsubtlv_type; uint8_t subsubtlv_len; size_t nb_groups; @@ -1156,15 +1478,23 @@ static int unpack_item_ext_subtlv_asla(uint16_t mtid, uint8_t subtlv_len, asla->standard_apps_length = ASLA_APPS_LENGTH_MASK & sabm_flag_len; asla->user_def_apps_length = ASLA_APPS_LENGTH_MASK & uabm_flag_len; + readable -= ISIS_SUBSUBTLV_HDR_SIZE; + if (readable < + asla->standard_apps_length + asla->user_def_apps_length) { + TLV_SIZE_MISMATCH(log, indent, "ASLA"); + return -1; + } + for (int i = 0; i < asla->standard_apps_length; i++) sabm[i] = stream_getc(s); for (int i = 0; i < asla->user_def_apps_length; i++) uabm[i] = stream_getc(s); + readable -= (asla->standard_apps_length + asla->user_def_apps_length); + asla->standard_apps = sabm[0]; asla->user_def_apps = uabm[0]; - readable = subtlv_len - 4; while (readable > 0) { if (readable < ISIS_SUBSUBTLV_HDR_SIZE) { TLV_SIZE_MISMATCH(log, indent, "ASLA Sub TLV"); @@ -1335,6 +1665,7 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, uint8_t sum = 0; uint8_t subtlv_type; uint8_t subtlv_len; + uint8_t subsubtlv_len; size_t nb_groups; uint32_t val; @@ -1673,6 +2004,92 @@ static int unpack_item_ext_subtlvs(uint16_t mtid, uint8_t len, struct stream *s, SET_SUBTLV(exts, EXT_LAN_ADJ_SID); } break; + /* SRv6 End.X SID as per RFC9352 section #8.1 */ + case ISIS_SUBTLV_SRV6_ENDX_SID: + if (subtlv_len < ISIS_SUBTLV_SRV6_ENDX_SID_SIZE) { + TLV_SIZE_MISMATCH(log, indent, + "SRv6 End.X SID"); + stream_forward_getp(s, subtlv_len); + } else { + struct isis_srv6_endx_sid_subtlv *adj; + + adj = XCALLOC( + MTYPE_ISIS_SUBTLV, + sizeof(struct + isis_srv6_endx_sid_subtlv)); + adj->flags = stream_getc(s); + adj->algorithm = stream_getc(s); + adj->weight = stream_getc(s); + adj->behavior = stream_getw(s); + stream_get(&adj->sid, s, IPV6_MAX_BYTELEN); + subsubtlv_len = stream_getc(s); + + adj->subsubtlvs = isis_alloc_subsubtlvs( + ISIS_CONTEXT_SUBSUBTLV_SRV6_ENDX_SID); + + bool unpacked_known_tlvs = false; + if (unpack_tlvs( + ISIS_CONTEXT_SUBSUBTLV_SRV6_ENDX_SID, + subsubtlv_len, s, log, + adj->subsubtlvs, indent + 4, + &unpacked_known_tlvs)) { + XFREE(MTYPE_ISIS_SUBTLV, adj); + break; + } + if (!unpacked_known_tlvs) { + isis_free_subsubtlvs(adj->subsubtlvs); + adj->subsubtlvs = NULL; + } + + append_item(&exts->srv6_endx_sid, + (struct isis_item *)adj); + SET_SUBTLV(exts, EXT_SRV6_ENDX_SID); + } + break; + /* SRv6 LAN End.X SID as per RFC9352 section #8.2 */ + case ISIS_SUBTLV_SRV6_LAN_ENDX_SID: + if (subtlv_len < ISIS_SUBTLV_SRV6_LAN_ENDX_SID_SIZE) { + TLV_SIZE_MISMATCH(log, indent, + "SRv6 LAN End.X SID"); + stream_forward_getp(s, subtlv_len); + } else { + struct isis_srv6_lan_endx_sid_subtlv *lan; + + lan = XCALLOC( + MTYPE_ISIS_SUBTLV, + sizeof(struct + isis_srv6_lan_endx_sid_subtlv)); + stream_get(&(lan->neighbor_id), s, + ISIS_SYS_ID_LEN); + lan->flags = stream_getc(s); + lan->algorithm = stream_getc(s); + lan->weight = stream_getc(s); + lan->behavior = stream_getw(s); + stream_get(&lan->sid, s, IPV6_MAX_BYTELEN); + subsubtlv_len = stream_getc(s); + + lan->subsubtlvs = isis_alloc_subsubtlvs( + ISIS_CONTEXT_SUBSUBTLV_SRV6_ENDX_SID); + + bool unpacked_known_tlvs = false; + if (unpack_tlvs( + ISIS_CONTEXT_SUBSUBTLV_SRV6_ENDX_SID, + subsubtlv_len, s, log, + lan->subsubtlvs, indent + 4, + &unpacked_known_tlvs)) { + XFREE(MTYPE_ISIS_SUBTLV, lan); + break; + } + if (!unpacked_known_tlvs) { + isis_free_subsubtlvs(lan->subsubtlvs); + lan->subsubtlvs = NULL; + } + + append_item(&exts->srv6_lan_endx_sid, + (struct isis_item *)lan); + SET_SUBTLV(exts, EXT_SRV6_LAN_ENDX_SID); + } + break; case ISIS_SUBTLV_ASLA: if (unpack_item_ext_subtlv_asla(mtid, subtlv_len, s, log, indent, @@ -1942,6 +2359,113 @@ static int unpack_subtlv_ipv6_source_prefix(enum isis_tlv_context context, return 0; } +/* Functions related to Sub-Sub-TLV 1 SRv6 SID Structure + * as per RFC 9352 section #9 */ +static struct isis_srv6_sid_structure_subsubtlv * +copy_subsubtlv_srv6_sid_structure( + struct isis_srv6_sid_structure_subsubtlv *sid_struct) +{ + if (!sid_struct) + return NULL; + + struct isis_srv6_sid_structure_subsubtlv *rv = + XCALLOC(MTYPE_ISIS_SUBSUBTLV, sizeof(*rv)); + + rv->loc_block_len = sid_struct->loc_block_len; + rv->loc_node_len = sid_struct->loc_node_len; + rv->func_len = sid_struct->func_len; + rv->arg_len = sid_struct->arg_len; + + return rv; +} + +static void format_subsubtlv_srv6_sid_structure( + struct isis_srv6_sid_structure_subsubtlv *sid_struct, struct sbuf *buf, + struct json_object *json, int indent) +{ + if (!sid_struct) + return; + + if (json) { + struct json_object *sid_struct_json; + sid_struct_json = json_object_new_object(); + json_object_object_add(json, "srv6-sid-structure", + sid_struct_json); + json_object_int_add(sid_struct_json, "loc-block-len", + sid_struct->loc_block_len); + json_object_int_add(sid_struct_json, "loc-node-len", + sid_struct->loc_node_len); + json_object_int_add(sid_struct_json, "func-len", + sid_struct->func_len); + json_object_int_add(sid_struct_json, "arg-len", + sid_struct->arg_len); + } else { + sbuf_push(buf, indent, "SRv6 SID Structure "); + sbuf_push(buf, 0, "Locator Block length: %hhu, ", + sid_struct->loc_block_len); + sbuf_push(buf, 0, "Locator Node length: %hhu, ", + sid_struct->loc_node_len); + sbuf_push(buf, 0, "Function length: %hhu, ", + sid_struct->func_len); + sbuf_push(buf, 0, "Argument length: %hhu, ", + sid_struct->arg_len); + sbuf_push(buf, 0, "\n"); + } +} + +static void free_subsubtlv_srv6_sid_structure( + struct isis_srv6_sid_structure_subsubtlv *sid_struct) +{ + XFREE(MTYPE_ISIS_SUBSUBTLV, sid_struct); +} + +static int pack_subsubtlv_srv6_sid_structure( + struct isis_srv6_sid_structure_subsubtlv *sid_struct, struct stream *s) +{ + if (!sid_struct) + return 0; + + if (STREAM_WRITEABLE(s) < 6) { + return 1; + } + + stream_putc(s, ISIS_SUBSUBTLV_SRV6_SID_STRUCTURE); + stream_putc(s, 4); + stream_putc(s, sid_struct->loc_block_len); + stream_putc(s, sid_struct->loc_node_len); + stream_putc(s, sid_struct->func_len); + stream_putc(s, sid_struct->arg_len); + + return 0; +} + +static int unpack_subsubtlv_srv6_sid_structure( + enum isis_tlv_context context, uint8_t tlv_type, uint8_t tlv_len, + struct stream *s, struct sbuf *log, void *dest, int indent) +{ + struct isis_subsubtlvs *subsubtlvs = dest; + struct isis_srv6_sid_structure_subsubtlv sid_struct = {}; + + sbuf_push(log, indent, "Unpacking SRv6 SID Structure...\n"); + if (tlv_len != 4) { + sbuf_push( + log, indent, + "Invalid SRv6 SID Structure Sub-Sub-TLV size. (Expected 4 bytes, got %hhu)\n", + tlv_len); + return 1; + } + + sid_struct.loc_block_len = stream_getc(s); + sid_struct.loc_node_len = stream_getc(s); + sid_struct.func_len = stream_getc(s); + sid_struct.arg_len = stream_getc(s); + + subsubtlvs->srv6_sid_structure = + copy_subsubtlv_srv6_sid_structure(&sid_struct); + + return 0; +} + static struct isis_item *copy_item(enum isis_tlv_context context, enum isis_tlv_type type, struct isis_item *item); @@ -1962,6 +2486,76 @@ static int pack_items_(uint16_t mtid, enum isis_tlv_context context, struct list *new_fragment_arg); #define pack_items(...) pack_items_(ISIS_MT_IPV4_UNICAST, __VA_ARGS__) +/* Functions related to Sub-Sub-TLVs in general */ + +struct isis_subsubtlvs *isis_alloc_subsubtlvs(enum isis_tlv_context context) +{ + struct isis_subsubtlvs *result; + + result = XCALLOC(MTYPE_ISIS_SUBSUBTLV, sizeof(*result)); + result->context = context; + + return result; +} + +static struct isis_subsubtlvs * +isis_copy_subsubtlvs(struct isis_subsubtlvs *subsubtlvs) +{ + if (!subsubtlvs) + return NULL; + + struct isis_subsubtlvs *rv = XCALLOC(MTYPE_ISIS_SUBSUBTLV, sizeof(*rv)); + + rv->context = subsubtlvs->context; + + rv->srv6_sid_structure = copy_subsubtlv_srv6_sid_structure( + subsubtlvs->srv6_sid_structure); + + return rv; +} + +static void isis_format_subsubtlvs(struct isis_subsubtlvs *subsubtlvs, + struct sbuf *buf, struct json_object *json, + int indent) +{ + format_subsubtlv_srv6_sid_structure(subsubtlvs->srv6_sid_structure, buf, + json, indent); +} + +static void isis_free_subsubtlvs(struct isis_subsubtlvs *subsubtlvs) +{ + if (!subsubtlvs) + return; + + free_subsubtlv_srv6_sid_structure(subsubtlvs->srv6_sid_structure); + + XFREE(MTYPE_ISIS_SUBSUBTLV, subsubtlvs); +} + +static int isis_pack_subsubtlvs(struct isis_subsubtlvs *subsubtlvs, + struct stream *s) +{ + int rv; + size_t subsubtlv_len_pos = stream_get_endp(s); + + if (STREAM_WRITEABLE(s) < 1) + return 1; + + stream_putc(s, 0); /* Put 0 as Sub-Sub-TLVs length, filled in later */ + + rv = pack_subsubtlv_srv6_sid_structure(subsubtlvs->srv6_sid_structure, + s); + if (rv) + return rv; + + size_t subsubtlv_len = stream_get_endp(s) - subsubtlv_len_pos - 1; + if (subsubtlv_len > 255) + return 1; + + stream_putc_at(s, subsubtlv_len_pos, subsubtlv_len); + return 0; +} + /* Functions related to subtlvs */ static struct isis_subtlvs *isis_alloc_subtlvs(enum isis_tlv_context context) @@ -1972,6 +2566,7 @@ static struct isis_subtlvs *isis_alloc_subtlvs(enum isis_tlv_context context) result->context = context; init_item_list(&result->prefix_sids); + init_item_list(&result->srv6_end_sids); return result; } @@ -1990,6 +2585,10 @@ static struct isis_subtlvs *copy_subtlvs(struct isis_subtlvs *subtlvs) rv->source_prefix = copy_subtlv_ipv6_source_prefix(subtlvs->source_prefix); + + copy_items(subtlvs->context, ISIS_SUBTLV_SRV6_END_SID, + &subtlvs->srv6_end_sids, &rv->srv6_end_sids); + return rv; } @@ -2000,6 +2599,9 @@ static void format_subtlvs(struct isis_subtlvs *subtlvs, struct sbuf *buf, &subtlvs->prefix_sids, buf, json, indent); format_subtlv_ipv6_source_prefix(subtlvs->source_prefix, buf, json, indent); + + format_items(subtlvs->context, ISIS_SUBTLV_SRV6_END_SID, + &subtlvs->srv6_end_sids, buf, json, indent); } static void isis_free_subtlvs(struct isis_subtlvs *subtlvs) @@ -2012,6 +2614,9 @@ static void isis_free_subtlvs(struct isis_subtlvs *subtlvs) XFREE(MTYPE_ISIS_SUBTLV, subtlvs->source_prefix); + free_items(subtlvs->context, ISIS_SUBTLV_SRV6_END_SID, + &subtlvs->srv6_end_sids); + XFREE(MTYPE_ISIS_SUBTLV, subtlvs); } @@ -2030,22 +2635,191 @@ static int pack_subtlvs(struct isis_subtlvs *subtlvs, struct stream *s) if (rv) return rv; - rv = pack_subtlv_ipv6_source_prefix(subtlvs->source_prefix, s); - if (rv) - return rv; + rv = pack_subtlv_ipv6_source_prefix(subtlvs->source_prefix, s); + if (rv) + return rv; + + rv = pack_items(subtlvs->context, ISIS_SUBTLV_SRV6_END_SID, + &subtlvs->srv6_end_sids, s, NULL, NULL, NULL, NULL); + if (rv) + return rv; + + size_t subtlv_len = stream_get_endp(s) - subtlv_len_pos - 1; + if (subtlv_len > 255) + return 1; + + stream_putc_at(s, subtlv_len_pos, subtlv_len); + return 0; +} + +static int unpack_tlvs(enum isis_tlv_context context, size_t avail_len, + struct stream *stream, struct sbuf *log, void *dest, + int indent, bool *unpacked_known_tlvs); + +/* Functions for Sub-TLV 5 SRv6 End SID as per RFC 9352 section #7.2 */ +static struct isis_item *copy_item_srv6_end_sid(struct isis_item *i) +{ + struct isis_srv6_end_sid_subtlv *sid = + (struct isis_srv6_end_sid_subtlv *)i; + struct isis_srv6_end_sid_subtlv *rv = + XCALLOC(MTYPE_ISIS_SUBTLV, sizeof(*rv)); + + rv->behavior = sid->behavior; + rv->sid = sid->sid; + rv->subsubtlvs = isis_copy_subsubtlvs(sid->subsubtlvs); + + return (struct isis_item *)rv; +} + +static void format_item_srv6_end_sid(uint16_t mtid, struct isis_item *i, + struct sbuf *buf, struct json_object *json, + int indent) +{ + struct isis_srv6_end_sid_subtlv *sid = + (struct isis_srv6_end_sid_subtlv *)i; + + if (json) { + struct json_object *sid_json; + sid_json = json_object_new_object(); + json_object_object_add(json, "srv6-end-sid", sid_json); + json_object_string_add(sid_json, "endpoint-behavior", + seg6local_action2str(sid->behavior)); + json_object_string_addf(sid_json, "sid-value", "%pI6", + &sid->sid); + if (sid->subsubtlvs) { + struct json_object *subtlvs_json; + subtlvs_json = json_object_new_object(); + json_object_object_add(sid_json, "subsubtlvs", + subtlvs_json); + isis_format_subsubtlvs(sid->subsubtlvs, NULL, + subtlvs_json, 0); + } + } else { + sbuf_push(buf, indent, "SRv6 End SID "); + sbuf_push(buf, 0, "Endpoint Behavior: %s, ", + seg6local_action2str(sid->behavior)); + sbuf_push(buf, 0, "SID value: %pI6\n", &sid->sid); + + if (sid->subsubtlvs) { + sbuf_push(buf, indent, " Sub-Sub-TLVs:\n"); + isis_format_subsubtlvs(sid->subsubtlvs, buf, NULL, + indent + 4); + } + } +} + +static void free_item_srv6_end_sid(struct isis_item *i) +{ + struct isis_srv6_end_sid_subtlv *item = + (struct isis_srv6_end_sid_subtlv *)i; + + isis_free_subsubtlvs(item->subsubtlvs); + XFREE(MTYPE_ISIS_SUBTLV, i); +} + +static int pack_item_srv6_end_sid(struct isis_item *i, struct stream *s, + size_t *min_len) +{ + struct isis_srv6_end_sid_subtlv *sid = + (struct isis_srv6_end_sid_subtlv *)i; + + if (STREAM_WRITEABLE(s) < 19) { + *min_len = 19; + return 1; + } + + stream_putc(s, sid->flags); + stream_putw(s, sid->behavior); + stream_put(s, &sid->sid, IPV6_MAX_BYTELEN); + + if (sid->subsubtlvs) { + /* Pack Sub-Sub-TLVs */ + if (isis_pack_subsubtlvs(sid->subsubtlvs, s)) + return 1; + } else { + /* No Sub-Sub-TLVs */ + if (STREAM_WRITEABLE(s) < 1) { + *min_len = 20; + return 1; + } + + /* Put 0 as Sub-Sub-TLV length, because we have no Sub-Sub-TLVs + */ + stream_putc(s, 0); + } + + return 0; +} + +static int unpack_item_srv6_end_sid(uint16_t mtid, uint8_t len, + struct stream *s, struct sbuf *log, + void *dest, int indent) +{ + struct isis_subtlvs *subtlvs = dest; + struct isis_srv6_end_sid_subtlv *sid = NULL; + size_t consume; + uint8_t subsubtlv_len; + + sbuf_push(log, indent, "Unpacking SRv6 End SID...\n"); + + consume = 19; + if (len < consume) { + sbuf_push( + log, indent, + "Not enough data left. (expected 19 or more bytes, got %hhu)\n", + len); + goto out; + } + + sid = XCALLOC(MTYPE_ISIS_SUBTLV, sizeof(*sid)); + + sid->flags = stream_getc(s); + sid->behavior = stream_getw(s); + stream_get(&sid->sid, s, IPV6_MAX_BYTELEN); + + format_item_srv6_end_sid(mtid, (struct isis_item *)sid, log, NULL, + indent + 2); + + /* Process Sub-Sub-TLVs */ + consume += 1; + if (len < consume) { + sbuf_push( + log, indent, + "Expected 1 byte of Sub-Sub-TLV len, but no more data persent.\n"); + goto out; + } + subsubtlv_len = stream_getc(s); + + consume += subsubtlv_len; + if (len < consume) { + sbuf_push(log, indent, + "Expected %hhu bytes of Sub-Sub-TLVs, but only %u bytes available.\n", + subsubtlv_len, len - ((uint8_t)consume - subsubtlv_len)); + goto out; + } - size_t subtlv_len = stream_get_endp(s) - subtlv_len_pos - 1; - if (subtlv_len > 255) - return 1; + sid->subsubtlvs = + isis_alloc_subsubtlvs(ISIS_CONTEXT_SUBSUBTLV_SRV6_END_SID); - stream_putc_at(s, subtlv_len_pos, subtlv_len); + bool unpacked_known_tlvs = false; + if (unpack_tlvs(ISIS_CONTEXT_SUBSUBTLV_SRV6_END_SID, subsubtlv_len, s, + log, sid->subsubtlvs, indent + 4, + &unpacked_known_tlvs)) { + goto out; + } + if (!unpacked_known_tlvs) { + isis_free_subsubtlvs(sid->subsubtlvs); + sid->subsubtlvs = NULL; + } + + append_item(&subtlvs->srv6_end_sids, (struct isis_item *)sid); return 0; +out: + if (sid) + free_item_srv6_end_sid((struct isis_item *)sid); + return 1; } -static int unpack_tlvs(enum isis_tlv_context context, size_t avail_len, - struct stream *stream, struct sbuf *log, void *dest, - int indent, bool *unpacked_known_tlvs); - /* Functions related to TLVs 1 Area Addresses */ static struct isis_item *copy_item_area_address(struct isis_item *i) @@ -4124,6 +4898,11 @@ static void format_tlv_router_cap(const struct isis_router_cap *router_cap, " Got an unsupported sub-TLV: Yes\n"); } #endif /* ifndef FABRICD */ + + /* SRv6 Flags as per RFC 9352 section #2 */ + if (router_cap->srv6_cap.is_srv6_capable) + sbuf_push(buf, indent, " SRv6: O:%s\n", + SUPPORTS_SRV6_OAM(&router_cap->srv6_cap) ? "1" : "0"); } static void free_tlv_router_cap(struct isis_router_cap *router_cap) @@ -4185,7 +4964,7 @@ static size_t isis_router_cap_tlv_size(const struct isis_router_cap *router_cap) #ifndef FABRICD size_t fad_sz; #endif /* ifndef FABRICD */ - int nb_algo; + int nb_algo, nb_msd; if ((router_cap->srgb.range_size != 0) && (router_cap->srgb.lower_bound != 0)) { @@ -4219,6 +4998,28 @@ static size_t isis_router_cap_tlv_size(const struct isis_router_cap *router_cap) } #endif /* ifndef FABRICD */ + if (router_cap->srv6_cap.is_srv6_capable) { + sz += ISIS_SUBTLV_TYPE_FIELD_SIZE + + ISIS_SUBTLV_LENGTH_FIELD_SIZE + + ISIS_SUBTLV_SRV6_CAPABILITIES_SIZE; + + nb_algo = isis_tlvs_sr_algo_count(router_cap); + if (nb_algo != 0) + sz += ISIS_SUBTLV_TYPE_FIELD_SIZE + + ISIS_SUBTLV_LENGTH_FIELD_SIZE + nb_algo; + + nb_msd = router_cap->srv6_msd.max_seg_left_msd + + router_cap->srv6_msd.max_end_pop_msd + + router_cap->srv6_msd.max_h_encaps_msd + + router_cap->srv6_msd.max_end_d_msd; + if (nb_msd != 0) + sz += ISIS_SUBTLV_TYPE_FIELD_SIZE + + ISIS_SUBTLV_LENGTH_FIELD_SIZE + + (ISIS_SUBTLV_NODE_MSD_TYPE_SIZE + + ISIS_SUBTLV_NODE_MSD_VALUE_SIZE) * + nb_msd; + } + return sz; } @@ -4227,6 +5028,8 @@ static int pack_tlv_router_cap(const struct isis_router_cap *router_cap, { size_t tlv_len, len_pos; uint8_t nb_algo; + size_t subtlv_len, subtlv_len_pos; + bool sr_algo_subtlv_present = false; if (!router_cap) return 0; @@ -4260,6 +5063,7 @@ static int pack_tlv_router_cap(const struct isis_router_cap *router_cap, for (int i = 0; i < SR_ALGORITHM_COUNT; i++) if (router_cap->algo[i] != SR_ALGORITHM_UNSET) stream_putc(s, router_cap->algo[i]); + sr_algo_subtlv_present = true; } /* Local Block if defined as per RFC8667 section #3.3 */ @@ -4358,6 +5162,83 @@ static int pack_tlv_router_cap(const struct isis_router_cap *router_cap, } #endif /* ifndef FABRICD */ + /* Add SRv6 capabilities if set as per RFC 9352 section #2 */ + if (router_cap->srv6_cap.is_srv6_capable) { + stream_putc(s, ISIS_SUBTLV_SRV6_CAPABILITIES); + stream_putc(s, ISIS_SUBTLV_SRV6_CAPABILITIES_SIZE); + stream_putw(s, router_cap->srv6_cap.flags); + + /* + * Then add SR Algorithm if set and if we haven't already + * added it when we processed SR-MPLS related Sub-TLVs as + * per RFC 9352 section #3 + */ + if (!sr_algo_subtlv_present) { + nb_algo = isis_tlvs_sr_algo_count(router_cap); + if (nb_algo > 0) { + stream_putc(s, ISIS_SUBTLV_ALGORITHM); + stream_putc(s, nb_algo); + for (int i = 0; i < SR_ALGORITHM_COUNT; i++) + if (router_cap->algo[i] != + SR_ALGORITHM_UNSET) + stream_putc(s, + router_cap->algo[i]); + } + } + + /* And finish with MSDs if set as per RFC 9352 section #4 */ + if (router_cap->srv6_msd.max_seg_left_msd + + router_cap->srv6_msd.max_end_pop_msd + + router_cap->srv6_msd.max_h_encaps_msd + + router_cap->srv6_msd.max_end_d_msd != + 0) { + stream_putc(s, ISIS_SUBTLV_NODE_MSD); + + subtlv_len_pos = stream_get_endp(s); + /* Put 0 as Sub-TLV length for now, real length will be + * adjusted later */ + stream_putc(s, 0); + + /* RFC 9352 section #4.1 */ + if (router_cap->srv6_msd.max_seg_left_msd != 0) { + stream_putc(s, ISIS_SUBTLV_SRV6_MAX_SL_MSD); + stream_putc( + s, + router_cap->srv6_msd.max_seg_left_msd); + } + + /* RFC 9352 section #4.2 */ + if (router_cap->srv6_msd.max_end_pop_msd != 0) { + stream_putc(s, + ISIS_SUBTLV_SRV6_MAX_END_POP_MSD); + stream_putc( + s, + router_cap->srv6_msd.max_end_pop_msd); + } + + /* RFC 9352 section #4.3 */ + if (router_cap->srv6_msd.max_h_encaps_msd != 0) { + stream_putc(s, + ISIS_SUBTLV_SRV6_MAX_H_ENCAPS_MSD); + stream_putc( + s, + router_cap->srv6_msd.max_h_encaps_msd); + } + + /* RFC 9352 section #4.4 */ + if (router_cap->srv6_msd.max_end_d_msd != 0) { + stream_putc(s, ISIS_SUBTLV_SRV6_MAX_END_D_MSD); + stream_putc(s, + router_cap->srv6_msd.max_end_d_msd); + } + + /* Adjust Node MSD Sub-TLV length which depends on MSDs + * presence */ + subtlv_len = stream_get_endp(s) - subtlv_len_pos - 1; + stream_putc_at(s, subtlv_len_pos, subtlv_len); + } + } + /* Adjust TLV length which depends on subTLVs presence */ tlv_len = stream_get_endp(s) - len_pos - 1; stream_putc_at(s, len_pos, tlv_len); @@ -4376,6 +5257,7 @@ static int unpack_tlv_router_cap(enum isis_tlv_context context, uint8_t length; uint8_t subtlv_len; uint8_t size; + int num_msd; sbuf_push(log, indent, "Unpacking Router Capability TLV...\n"); if (tlv_len < ISIS_ROUTER_CAP_SIZE) { @@ -4544,19 +5426,66 @@ static int unpack_tlv_router_cap(enum isis_tlv_context context, break; case ISIS_SUBTLV_NODE_MSD: + sbuf_push(log, indent, + "Unpacking Node MSD sub-TLV...\n"); + /* Check that MSD is correctly formated */ - if (length < MSD_TLV_SIZE) { + if (length % 2) { + sbuf_push( + log, indent, + "WARNING: Unexpected MSD sub-TLV length\n"); stream_forward_getp(s, length); break; } - msd_type = stream_getc(s); - rcap->msd = stream_getc(s); - /* Only BMI-MSD type has been defined in RFC 8491 */ - if (msd_type != MSD_TYPE_BASE_MPLS_IMPOSITION) - rcap->msd = 0; - /* Only one MSD is standardized. Skip others */ - if (length > MSD_TLV_SIZE) - stream_forward_getp(s, length - MSD_TLV_SIZE); + + /* Get the number of MSDs carried in the value field of + * the Node MSD sub-TLV. The value field consists of one + * or more pairs of a 1-octet MSD-Type and 1-octet + * MSD-Value */ + num_msd = length / 2; + + /* Unpack MSDs */ + for (int i = 0; i < num_msd; i++) { + msd_type = stream_getc(s); + + switch (msd_type) { + case MSD_TYPE_BASE_MPLS_IMPOSITION: + /* BMI-MSD type as per RFC 8491 */ + rcap->msd = stream_getc(s); + break; + case ISIS_SUBTLV_SRV6_MAX_SL_MSD: + /* SRv6 Maximum Segments Left MSD Type + * as per RFC 9352 section #4.1 */ + rcap->srv6_msd.max_seg_left_msd = + stream_getc(s); + break; + case ISIS_SUBTLV_SRV6_MAX_END_POP_MSD: + /* SRv6 Maximum End Pop MSD Type as per + * RFC 9352 section #4.2 */ + rcap->srv6_msd.max_end_pop_msd = + stream_getc(s); + break; + case ISIS_SUBTLV_SRV6_MAX_H_ENCAPS_MSD: + /* SRv6 Maximum H.Encaps MSD Type as per + * RFC 9352 section #4.3 */ + rcap->srv6_msd.max_h_encaps_msd = + stream_getc(s); + break; + case ISIS_SUBTLV_SRV6_MAX_END_D_MSD: + /* SRv6 Maximum End D MSD Type as per + * RFC 9352 section #4.4 */ + rcap->srv6_msd.max_end_d_msd = + stream_getc(s); + break; + default: + /* Unknown MSD, let's skip it */ + sbuf_push( + log, indent, + "WARNING: Skipping unknown MSD Type %hhu (1 byte)\n", + msd_type); + stream_forward_getp(s, 1); + } + } break; #ifndef FABRICD case ISIS_SUBTLV_FAD: @@ -4632,6 +5561,47 @@ static int unpack_tlv_router_cap(enum isis_tlv_context context, } break; #endif /* ifndef FABRICD */ + case ISIS_SUBTLV_SRV6_CAPABILITIES: + sbuf_push(log, indent, + "Unpacking SRv6 Capabilities sub-TLV...\n"); + /* Check that SRv6 capabilities sub-TLV is correctly + * formated */ + if (length < ISIS_SUBTLV_SRV6_CAPABILITIES_SIZE) { + sbuf_push( + log, indent, + "WARNING: Unexpected SRv6 Capabilities sub-TLV size (expected %d or more bytes, got %hhu)\n", + ISIS_SUBTLV_SRV6_CAPABILITIES_SIZE, + length); + stream_forward_getp(s, length); + break; + } + /* Only one SRv6 capabilities is supported. Skip + * subsequent one */ + if (rcap->srv6_cap.is_srv6_capable) { + sbuf_push( + log, indent, + "WARNING: SRv6 Capabilities sub-TLV present multiple times, ignoring.\n"); + stream_forward_getp(s, length); + break; + } + rcap->srv6_cap.is_srv6_capable = true; + rcap->srv6_cap.flags = stream_getw(s); + + /* The SRv6 Capabilities Sub-TLV may contain optional + * Sub-Sub-TLVs, as per RFC 9352 section #2. + * Skip any Sub-Sub-TLV contained in the SRv6 + * Capabilities Sub-TLV that is not currently supported + * by IS-IS. + */ + if (length > ISIS_SUBTLV_SRV6_CAPABILITIES_SIZE) + sbuf_push( + log, indent, + "Skipping unknown sub-TLV (%hhu bytes)\n", + length); + stream_forward_getp( + s, length - ISIS_SUBTLV_SRV6_CAPABILITIES_SIZE); + + break; default: stream_forward_getp(s, length); break; @@ -5033,6 +6003,14 @@ static int pack_items_(uint16_t mtid, enum isis_tlv_context context, stream_putw(s, mtid); } + /* The SRv6 Locator TLV (RFC 9352 section #7.1) starts with the MTID + * field */ + if (context == ISIS_CONTEXT_LSP && type == ISIS_TLV_SRV6_LOCATOR) { + if (STREAM_WRITEABLE(s) < 2) + goto too_long; + stream_putw(s, mtid); + } + if (context == ISIS_CONTEXT_LSP && type == ISIS_TLV_OLDSTYLE_REACH) { if (STREAM_WRITEABLE(s) < 1) goto too_long; @@ -5165,7 +6143,8 @@ static int unpack_tlv_with_items(enum isis_tlv_context context, tlv_start = stream_get_getp(s); tlv_pos = 0; - if (context == ISIS_CONTEXT_LSP && IS_COMPAT_MT_TLV(tlv_type)) { + if (context == ISIS_CONTEXT_LSP && + (IS_COMPAT_MT_TLV(tlv_type) || tlv_type == ISIS_TLV_SRV6_LOCATOR)) { if (tlv_len < 2) { sbuf_push(log, indent, "TLV is too short to contain MTID\n"); @@ -5317,6 +6296,207 @@ static void copy_mt_items(enum isis_tlv_context context, } } +/* Functions related to TLV 27 SRv6 Locator as per RFC 9352 section #7.1*/ +static struct isis_item *copy_item_srv6_locator(struct isis_item *i) +{ + struct isis_srv6_locator_tlv *loc = (struct isis_srv6_locator_tlv *)i; + struct isis_srv6_locator_tlv *rv = XCALLOC(MTYPE_ISIS_TLV, sizeof(*rv)); + + rv->metric = loc->metric; + rv->flags = loc->flags; + rv->algorithm = loc->algorithm; + rv->prefix = loc->prefix; + rv->subtlvs = copy_subtlvs(loc->subtlvs); + + return (struct isis_item *)rv; +} + +static void format_item_srv6_locator(uint16_t mtid, struct isis_item *i, + struct sbuf *buf, struct json_object *json, + int indent) +{ + struct isis_srv6_locator_tlv *loc = (struct isis_srv6_locator_tlv *)i; + + if (json) { + struct json_object *loc_json; + loc_json = json_object_new_object(); + json_object_object_add(json, "srv6-locator", loc_json); + json_object_int_add(loc_json, "mt-id", mtid); + json_object_string_addf(loc_json, "prefix", "%pFX", + &loc->prefix); + json_object_int_add(loc_json, "metric", loc->metric); + json_object_string_add( + loc_json, "d-flag", + CHECK_FLAG(loc->flags, ISIS_TLV_SRV6_LOCATOR_FLAG_D) + ? "yes" + : ""); + json_object_int_add(loc_json, "algorithm", loc->algorithm); + json_object_string_add(loc_json, "mt-name", + isis_mtid2str(mtid)); + if (loc->subtlvs) { + struct json_object *subtlvs_json; + subtlvs_json = json_object_new_object(); + json_object_object_add(loc_json, "subtlvs", + subtlvs_json); + format_subtlvs(loc->subtlvs, NULL, subtlvs_json, 0); + } + } else { + sbuf_push(buf, indent, "SRv6 Locator: %pFX (Metric: %u)%s", + &loc->prefix, loc->metric, + CHECK_FLAG(loc->flags, ISIS_TLV_SRV6_LOCATOR_FLAG_D) + ? " D-flag" + : ""); + sbuf_push(buf, 0, " %s\n", isis_mtid2str(mtid)); + + if (loc->subtlvs) { + sbuf_push(buf, indent, " Sub-TLVs:\n"); + format_subtlvs(loc->subtlvs, buf, NULL, indent + 4); + } + } +} + +static void free_item_srv6_locator(struct isis_item *i) +{ + struct isis_srv6_locator_tlv *item = (struct isis_srv6_locator_tlv *)i; + + isis_free_subtlvs(item->subtlvs); + XFREE(MTYPE_ISIS_TLV, item); +} + +static int pack_item_srv6_locator(struct isis_item *i, struct stream *s, + size_t *min_len) +{ + struct isis_srv6_locator_tlv *loc = (struct isis_srv6_locator_tlv *)i; + + if (STREAM_WRITEABLE(s) < 7 + (unsigned)PSIZE(loc->prefix.prefixlen)) { + *min_len = 7 + (unsigned)PSIZE(loc->prefix.prefixlen); + return 1; + } + + stream_putl(s, loc->metric); + stream_putc(s, loc->flags); + stream_putc(s, loc->algorithm); + /* Locator size */ + stream_putc(s, loc->prefix.prefixlen); + /* Locator prefix */ + stream_put(s, &loc->prefix.prefix.s6_addr, + PSIZE(loc->prefix.prefixlen)); + + if (loc->subtlvs) { + /* Pack Sub-TLVs */ + if (pack_subtlvs(loc->subtlvs, s)) + return 1; + } else { + /* No Sub-TLVs */ + if (STREAM_WRITEABLE(s) < 1) { + *min_len = 8 + (unsigned)PSIZE(loc->prefix.prefixlen); + return 1; + } + + /* Put 0 as Sub-TLV length, because we have no Sub-TLVs */ + stream_putc(s, 0); + } + + return 0; +} + +static int unpack_item_srv6_locator(uint16_t mtid, uint8_t len, + struct stream *s, struct sbuf *log, + void *dest, int indent) +{ + struct isis_tlvs *tlvs = dest; + struct isis_srv6_locator_tlv *rv = NULL; + size_t consume; + uint8_t subtlv_len; + struct isis_item_list *items; + + items = isis_get_mt_items(&tlvs->srv6_locator, mtid); + + sbuf_push(log, indent, "Unpacking SRv6 Locator...\n"); + consume = 7; + if (len < consume) { + sbuf_push( + log, indent, + "Not enough data left. (expected 7 or more bytes, got %hhu)\n", + len); + goto out; + } + + rv = XCALLOC(MTYPE_ISIS_TLV, sizeof(*rv)); + + rv->metric = stream_getl(s); + rv->flags = stream_getc(s); + rv->algorithm = stream_getc(s); + + rv->prefix.family = AF_INET6; + rv->prefix.prefixlen = stream_getc(s); + if (rv->prefix.prefixlen > IPV6_MAX_BITLEN) { + sbuf_push(log, indent, "Loc Size %u is implausible for SRv6\n", + rv->prefix.prefixlen); + goto out; + } + + consume += PSIZE(rv->prefix.prefixlen); + if (len < consume) { + sbuf_push( + log, indent, + "Expected %u bytes of prefix, but only %u bytes available.\n", + PSIZE(rv->prefix.prefixlen), len - 7); + goto out; + } + stream_get(&rv->prefix.prefix.s6_addr, s, PSIZE(rv->prefix.prefixlen)); + + struct in6_addr orig_locator = rv->prefix.prefix; + apply_mask_ipv6(&rv->prefix); + if (memcmp(&orig_locator, &rv->prefix.prefix, sizeof(orig_locator))) + sbuf_push(log, indent + 2, + "WARNING: SRv6 Locator had hostbits set.\n"); + format_item_srv6_locator(mtid, (struct isis_item *)rv, log, NULL, + indent + 2); + + consume += 1; + if (len < consume) { + sbuf_push( + log, indent, + "Expected 1 byte of subtlv len, but no more data persent.\n"); + goto out; + } + subtlv_len = stream_getc(s); + + if (subtlv_len) { + consume += subtlv_len; + if (len < consume) { + sbuf_push( + log, indent, + "Expected %hhu bytes of subtlvs, but only %u bytes available.\n", + subtlv_len, + len - 7 - PSIZE(rv->prefix.prefixlen)); + goto out; + } + + rv->subtlvs = + isis_alloc_subtlvs(ISIS_CONTEXT_SUBTLV_SRV6_LOCATOR); + + bool unpacked_known_tlvs = false; + if (unpack_tlvs(ISIS_CONTEXT_SUBTLV_SRV6_LOCATOR, subtlv_len, s, + log, rv->subtlvs, indent + 4, + &unpacked_known_tlvs)) { + goto out; + } + if (!unpacked_known_tlvs) { + isis_free_subtlvs(rv->subtlvs); + rv->subtlvs = NULL; + } + } + + append_item(items, (struct isis_item *)rv); + return 0; +out: + if (rv) + free_item_srv6_locator((struct isis_item *)rv); + return 1; +} + /* Functions related to tlvs in general */ struct isis_tlvs *isis_alloc_tlvs(void) @@ -5342,6 +6522,7 @@ struct isis_tlvs *isis_alloc_tlvs(void) RB_INIT(isis_mt_item_list, &result->mt_ip_reach); init_item_list(&result->ipv6_reach); RB_INIT(isis_mt_item_list, &result->mt_ipv6_reach); + RB_INIT(isis_mt_item_list, &result->srv6_locator); return result; } @@ -5422,6 +6603,9 @@ struct isis_tlvs *isis_copy_tlvs(struct isis_tlvs *tlvs) rv->spine_leaf = copy_tlv_spine_leaf(tlvs->spine_leaf); + copy_mt_items(ISIS_CONTEXT_LSP, ISIS_TLV_SRV6_LOCATOR, + &tlvs->srv6_locator, &rv->srv6_locator); + return rv; } @@ -5502,6 +6686,9 @@ static void format_tlvs(struct isis_tlvs *tlvs, struct sbuf *buf, struct json_ob format_tlv_threeway_adj(tlvs->threeway_adj, buf, json, indent); format_tlv_spine_leaf(tlvs->spine_leaf, buf, json, indent); + + format_mt_items(ISIS_CONTEXT_LSP, ISIS_TLV_SRV6_LOCATOR, + &tlvs->srv6_locator, buf, json, indent); } const char *isis_format_tlvs(struct isis_tlvs *tlvs, struct json_object *json) @@ -5564,6 +6751,8 @@ void isis_free_tlvs(struct isis_tlvs *tlvs) free_tlv_threeway_adj(tlvs->threeway_adj); free_tlv_router_cap(tlvs->router_cap); free_tlv_spine_leaf(tlvs->spine_leaf); + free_mt_items(ISIS_CONTEXT_LSP, ISIS_TLV_SRV6_LOCATOR, + &tlvs->srv6_locator); XFREE(MTYPE_ISIS_TLV, tlvs); } @@ -5974,6 +7163,15 @@ int isis_unpack_tlvs(size_t avail_len, struct stream *stream, #define ITEM_SUBTLV_OPS(_name_, _desc_) \ ITEM_TLV_OPS(_name_, _desc_) +#define SUBSUBTLV_OPS(_name_, _desc_) \ + static const struct tlv_ops subsubtlv_##_name_##_ops = { \ + .name = _desc_, \ + .unpack = unpack_subsubtlv_##_name_, \ + } + +#define ITEM_SUBSUBTLV_OPS(_name_, _desc_) \ + ITEM_TLV_OPS(_name_, _desc_) + ITEM_TLV_OPS(area_address, "TLV 1 Area Addresses"); ITEM_TLV_OPS(oldstyle_reach, "TLV 2 IS Reachability"); ITEM_TLV_OPS(lan_neighbor, "TLV 6 LAN Neighbors"); @@ -5999,6 +7197,10 @@ TLV_OPS(router_cap, "TLV 242 Router Capability"); ITEM_SUBTLV_OPS(prefix_sid, "Sub-TLV 3 SR Prefix-SID"); SUBTLV_OPS(ipv6_source_prefix, "Sub-TLV 22 IPv6 Source Prefix"); +ITEM_TLV_OPS(srv6_locator, "TLV 27 SRv6 Locator"); +ITEM_SUBTLV_OPS(srv6_end_sid, "Sub-TLV 5 SRv6 End SID"); +SUBSUBTLV_OPS(srv6_sid_structure, "Sub-Sub-TLV 1 SRv6 SID Structure"); + static const struct tlv_ops *const tlv_table[ISIS_CONTEXT_MAX][ISIS_TLV_MAX] = { [ISIS_CONTEXT_LSP] = { [ISIS_TLV_AREA_ADDRESSES] = &tlv_area_address_ops, @@ -6026,6 +7228,7 @@ static const struct tlv_ops *const tlv_table[ISIS_CONTEXT_MAX][ISIS_TLV_MAX] = { [ISIS_TLV_MT_IPV6_REACH] = &tlv_ipv6_reach_ops, [ISIS_TLV_THREE_WAY_ADJ] = &tlv_threeway_adj_ops, [ISIS_TLV_ROUTER_CAPABILITY] = &tlv_router_cap_ops, + [ISIS_TLV_SRV6_LOCATOR] = &tlv_srv6_locator_ops, }, [ISIS_CONTEXT_SUBTLV_NE_REACH] = {}, [ISIS_CONTEXT_SUBTLV_IP_REACH] = { @@ -6034,6 +7237,18 @@ static const struct tlv_ops *const tlv_table[ISIS_CONTEXT_MAX][ISIS_TLV_MAX] = { [ISIS_CONTEXT_SUBTLV_IPV6_REACH] = { [ISIS_SUBTLV_PREFIX_SID] = &tlv_prefix_sid_ops, [ISIS_SUBTLV_IPV6_SOURCE_PREFIX] = &subtlv_ipv6_source_prefix_ops, + }, + [ISIS_CONTEXT_SUBTLV_SRV6_LOCATOR] = { + [ISIS_SUBTLV_SRV6_END_SID] = &tlv_srv6_end_sid_ops, + }, + [ISIS_CONTEXT_SUBSUBTLV_SRV6_END_SID] = { + [ISIS_SUBSUBTLV_SRV6_SID_STRUCTURE] = &subsubtlv_srv6_sid_structure_ops, + }, + [ISIS_CONTEXT_SUBSUBTLV_SRV6_ENDX_SID] = { + [ISIS_SUBSUBTLV_SRV6_SID_STRUCTURE] = &subsubtlv_srv6_sid_structure_ops, + }, + [ISIS_CONTEXT_SUBSUBTLV_SRV6_LAN_ENDX_SID] = { + [ISIS_SUBSUBTLV_SRV6_SID_STRUCTURE] = &subsubtlv_srv6_sid_structure_ops, } }; @@ -6703,6 +7918,44 @@ void isis_tlvs_del_lan_adj_sid(struct isis_ext_subtlvs *exts, UNSET_SUBTLV(exts, EXT_LAN_ADJ_SID); } +/* Add IS-IS SRv6 End.X SID subTLVs */ +void isis_tlvs_add_srv6_endx_sid(struct isis_ext_subtlvs *exts, + struct isis_srv6_endx_sid_subtlv *adj) +{ + append_item(&exts->srv6_endx_sid, (struct isis_item *)adj); + SET_SUBTLV(exts, EXT_SRV6_ENDX_SID); +} + +/* Delete IS-IS SRv6 End.X SID subTLVs */ +void isis_tlvs_del_srv6_endx_sid(struct isis_ext_subtlvs *exts, + struct isis_srv6_endx_sid_subtlv *adj) +{ + isis_free_subsubtlvs(adj->subsubtlvs); + delete_item(&exts->srv6_endx_sid, (struct isis_item *)adj); + XFREE(MTYPE_ISIS_SUBTLV, adj); + if (exts->srv6_endx_sid.count == 0) + UNSET_SUBTLV(exts, EXT_SRV6_ENDX_SID); +} + +/* Add IS-IS SRv6 LAN End.X SID subTLVs */ +void isis_tlvs_add_srv6_lan_endx_sid(struct isis_ext_subtlvs *exts, + struct isis_srv6_lan_endx_sid_subtlv *lan) +{ + append_item(&exts->srv6_lan_endx_sid, (struct isis_item *)lan); + SET_SUBTLV(exts, EXT_SRV6_LAN_ENDX_SID); +} + +/* Delete IS-IS SRv6 LAN End.X SID subTLVs */ +void isis_tlvs_del_srv6_lan_endx_sid(struct isis_ext_subtlvs *exts, + struct isis_srv6_lan_endx_sid_subtlv *lan) +{ + isis_free_subsubtlvs(lan->subsubtlvs); + delete_item(&exts->srv6_lan_endx_sid, (struct isis_item *)lan); + XFREE(MTYPE_ISIS_SUBTLV, lan); + if (exts->srv6_lan_endx_sid.count == 0) + UNSET_SUBTLV(exts, EXT_SRV6_LAN_ENDX_SID); +} + void isis_tlvs_del_asla_flex_algo(struct isis_ext_subtlvs *ext, struct isis_asla_subtlvs *asla) { @@ -6926,3 +8179,95 @@ void isis_tlvs_set_purge_originator(struct isis_tlvs *tlvs, sizeof(tlvs->purge_originator->sender)); } } + +/* Set SRv6 SID Structure Sub-Sub-TLV parameters */ +void isis_subsubtlvs_set_srv6_sid_structure(struct isis_subsubtlvs *subsubtlvs, + struct isis_srv6_sid *sid) +{ + assert(!subsubtlvs->srv6_sid_structure); + + subsubtlvs->srv6_sid_structure = XCALLOC( + MTYPE_ISIS_SUBSUBTLV, sizeof(*subsubtlvs->srv6_sid_structure)); + + isis_srv6_sid_structure2subsubtlv(sid, subsubtlvs->srv6_sid_structure); +} + +/* Add an SRv6 End SID to the SRv6 End SID Sub-TLV */ +void isis_subtlvs_add_srv6_end_sid(struct isis_subtlvs *subtlvs, + struct isis_srv6_sid *sid) +{ + struct isis_srv6_end_sid_subtlv *sid_subtlv; + + if (!sid) + return; + + /* The SRv6 End SID Sub-TLV advertises SRv6 SIDs with Endpoint behaviors + * that do not require a particular neighbor in order to be correctly + * applied (e.g. End, End.DT6, ...). Before proceeding, let's make sure + * we are encoding one of the supported behaviors. */ + if (sid->behavior != SRV6_ENDPOINT_BEHAVIOR_END && + sid->behavior != SRV6_ENDPOINT_BEHAVIOR_END_NEXT_CSID && + sid->behavior != SRV6_ENDPOINT_BEHAVIOR_END_DT6 && + sid->behavior != SRV6_ENDPOINT_BEHAVIOR_END_DT6_USID && + sid->behavior != SRV6_ENDPOINT_BEHAVIOR_END_DT4 && + sid->behavior != SRV6_ENDPOINT_BEHAVIOR_END_DT4_USID && + sid->behavior != SRV6_ENDPOINT_BEHAVIOR_END_DT46 && + sid->behavior != SRV6_ENDPOINT_BEHAVIOR_END_DT46_USID) + return; + + /* Allocate memory for the Sub-TLV */ + sid_subtlv = XCALLOC(MTYPE_ISIS_SUBTLV, sizeof(*sid_subtlv)); + + /* Fill in the SRv6 End SID Sub-TLV according to the SRv6 SID + * configuration */ + isis_srv6_end_sid2subtlv(sid, sid_subtlv); + + /* Add the SRv6 SID Structure Sub-Sub-TLV */ + sid_subtlv->subsubtlvs = + isis_alloc_subsubtlvs(ISIS_CONTEXT_SUBSUBTLV_SRV6_END_SID); + isis_subsubtlvs_set_srv6_sid_structure(sid_subtlv->subsubtlvs, sid); + + /* Append the SRv6 End SID Sub-TLV to the Sub-TLVs list */ + append_item(&subtlvs->srv6_end_sids, (struct isis_item *)sid_subtlv); +} + +/* Add an SRv6 Locator to the SRv6 Locator TLV */ +void isis_tlvs_add_srv6_locator(struct isis_tlvs *tlvs, uint16_t mtid, + struct isis_srv6_locator *loc) +{ + bool subtlvs_present = false; + struct listnode *node; + struct isis_srv6_sid *sid; + struct isis_srv6_locator_tlv *loc_tlv = + XCALLOC(MTYPE_ISIS_TLV, sizeof(*loc_tlv)); + + /* Fill in the SRv6 Locator TLV according to the SRv6 Locator + * configuration */ + isis_srv6_locator2tlv(loc, loc_tlv); + + /* Add the SRv6 End SID Sub-TLVs */ + loc_tlv->subtlvs = isis_alloc_subtlvs(ISIS_CONTEXT_SUBTLV_SRV6_LOCATOR); + for (ALL_LIST_ELEMENTS_RO(loc->srv6_sid, node, sid)) { + if (sid->behavior == SRV6_ENDPOINT_BEHAVIOR_END || + sid->behavior == SRV6_ENDPOINT_BEHAVIOR_END_NEXT_CSID || + sid->behavior == SRV6_ENDPOINT_BEHAVIOR_END_DT6 || + sid->behavior == SRV6_ENDPOINT_BEHAVIOR_END_DT6_USID || + sid->behavior == SRV6_ENDPOINT_BEHAVIOR_END_DT4 || + sid->behavior == SRV6_ENDPOINT_BEHAVIOR_END_DT4_USID || + sid->behavior == SRV6_ENDPOINT_BEHAVIOR_END_DT46 || + sid->behavior == SRV6_ENDPOINT_BEHAVIOR_END_DT46_USID) { + isis_subtlvs_add_srv6_end_sid(loc_tlv->subtlvs, sid); + subtlvs_present = true; + } + } + + if (!subtlvs_present) { + isis_free_subtlvs(loc_tlv->subtlvs); + loc_tlv->subtlvs = NULL; + } + + /* Append the SRv6 Locator TLV to the TLVs list */ + struct isis_item_list *l; + l = isis_get_mt_items(&tlvs->srv6_locator, mtid); + append_item(l, (struct isis_item *)loc_tlv); +} diff --git a/isisd/isis_tlvs.h b/isisd/isis_tlvs.h index 03e2b2edcc..6ecd4c5f6a 100644 --- a/isisd/isis_tlvs.h +++ b/isisd/isis_tlvs.h @@ -5,6 +5,9 @@ * Copyright (C) 2015,2017 Christian Franke * Copyright (C) 2019 Olivier Dugeon - Orange Labs (for TE and SR) + * + * Copyright (C) 2023 Carmine Scarpitta - University of Rome Tor Vergata + * (for IS-IS Extensions to Support SRv6 as per RFC 9352) */ #ifndef ISIS_TLVS_H #define ISIS_TLVS_H @@ -16,10 +19,15 @@ #include "affinitymap.h" +#include "lib/srv6.h" + DECLARE_MTYPE(ISIS_SUBTLV); +DECLARE_MTYPE(ISIS_SUBSUBTLV); struct lspdb_head; struct sr_prefix_cfg; +struct isis_srv6_sid; +struct isis_srv6_locator; struct isis_area_address { struct isis_area_address *next; @@ -193,6 +201,96 @@ struct isis_router_cap_fad { }; #endif /* ifndef FABRICD */ +/* SRv6 SID Structure Sub-Sub-TLV as per RFC 9352 section #9 */ +struct isis_srv6_sid_structure_subsubtlv { + uint8_t loc_block_len; + uint8_t loc_node_len; + uint8_t func_len; + uint8_t arg_len; +}; + +/* SRv6 End SID Sub-TLV as per RFC 9352 section #7.2 */ +struct isis_srv6_end_sid_subtlv { + struct isis_srv6_end_sid_subtlv *next; + + uint8_t flags; + enum srv6_endpoint_behavior_codepoint behavior; + struct in6_addr sid; + + struct isis_subsubtlvs *subsubtlvs; +}; + +/* SRv6 End.X SID and SRv6 LAN End.X SID sub-TLVs flags */ +#define EXT_SUBTLV_LINK_SRV6_ENDX_SID_PFLG 0x20 +#define EXT_SUBTLV_LINK_SRV6_ENDX_SID_SFLG 0x40 +#define EXT_SUBTLV_LINK_SRV6_ENDX_SID_BFLG 0x80 + +/* SRv6 End.X SID Sub-TLV as per RFC 9352 section #8.1 */ +struct isis_srv6_endx_sid_subtlv { + struct isis_srv6_endx_sid_subtlv *next; + + uint8_t flags; + uint8_t algorithm; + uint8_t weight; + enum srv6_endpoint_behavior_codepoint behavior; + struct in6_addr sid; + + struct isis_subsubtlvs *subsubtlvs; +}; + +/* SRv6 End.X SID Sub-TLV as per RFC 9352 section #8.2 */ +struct isis_srv6_lan_endx_sid_subtlv { + struct isis_srv6_lan_endx_sid_subtlv *next; + + uint8_t neighbor_id[ISIS_SYS_ID_LEN]; + uint8_t flags; + uint8_t algorithm; + uint8_t weight; + enum srv6_endpoint_behavior_codepoint behavior; + struct in6_addr sid; + + struct isis_subsubtlvs *subsubtlvs; +}; + +/* RFC 9352 section 7.1 */ +struct isis_srv6_locator_tlv { + struct isis_srv6_locator_tlv *next; + + uint32_t metric; + + uint8_t flags; +#define ISIS_TLV_SRV6_LOCATOR_FLAG_D 1 << 7 + + uint8_t algorithm; + struct prefix_ipv6 prefix; + + struct isis_subtlvs *subtlvs; +}; + +#define ISIS_SRV6_LOCATOR_HDR_SIZE 22 + +/* Maximum SRv6 SID Depths (MSD) as per RFC 9352 section #4 */ +struct isis_srv6_msd { + /* RFC 9352 section #4.1 */ + uint8_t max_seg_left_msd; + /* RFC 9352 section #4.2 */ + uint8_t max_end_pop_msd; + /* RFC 9352 section #4.3 */ + uint8_t max_h_encaps_msd; + /* RFC 9352 section #4.4 */ + uint8_t max_end_d_msd; +}; + +/* SRv6 Capabilities as per RFC 9352 section #2 */ +struct isis_srv6_cap { + bool is_srv6_capable; + + uint16_t flags; +#define ISIS_SUBTLV_SRV6_FLAG_O 0x4000 +#define SUPPORTS_SRV6_OAM(srv6) \ + (CHECK_FLAG((srv6)->flags, ISIS_SUBTLV_SRV6_FLAG_O)) +}; + struct isis_router_cap { struct in_addr router_id; uint8_t flags; @@ -208,6 +306,12 @@ struct isis_router_cap { /* RFC9350 Flex-Algorithm */ struct isis_router_cap_fad *fads[SR_ALGORITHM_COUNT]; #endif /* ifndef FABRICD */ + + /* RFC 9352 section #2 */ + struct isis_srv6_cap srv6_cap; + + /* RFC 9352 section #4 */ + struct isis_srv6_msd srv6_msd; }; struct isis_item { @@ -310,6 +414,7 @@ struct isis_tlvs { struct isis_threeway_adj *threeway_adj; struct isis_router_cap *router_cap; struct isis_spine_leaf *spine_leaf; + struct isis_mt_item_list srv6_locator; }; enum isis_tlv_context { @@ -317,6 +422,10 @@ enum isis_tlv_context { ISIS_CONTEXT_SUBTLV_NE_REACH, ISIS_CONTEXT_SUBTLV_IP_REACH, ISIS_CONTEXT_SUBTLV_IPV6_REACH, + ISIS_CONTEXT_SUBTLV_SRV6_LOCATOR, + ISIS_CONTEXT_SUBSUBTLV_SRV6_END_SID, + ISIS_CONTEXT_SUBSUBTLV_SRV6_ENDX_SID, + ISIS_CONTEXT_SUBSUBTLV_SRV6_LAN_ENDX_SID, ISIS_CONTEXT_MAX, }; @@ -327,6 +436,16 @@ struct isis_subtlvs { struct prefix_ipv6 *source_prefix; /* RFC 8667 section #2.4 */ struct isis_item_list prefix_sids; + + /* RFC 9352 section #7.2 */ + struct isis_item_list srv6_end_sids; +}; + +struct isis_subsubtlvs { + enum isis_tlv_context context; + + /* RFC 9352 section #9 */ + struct isis_srv6_sid_structure_subsubtlv *srv6_sid_structure; }; enum isis_tlv_type { @@ -340,6 +459,8 @@ enum isis_tlv_type { ISIS_TLV_PURGE_ORIGINATOR = 13, ISIS_TLV_EXTENDED_REACH = 22, + ISIS_TLV_SRV6_LOCATOR = 27, + ISIS_TLV_OLDSTYLE_IP_REACH = 128, ISIS_TLV_PROTOCOLS_SUPPORTED = 129, ISIS_TLV_OLDSTYLE_IP_REACH_EXT = 130, @@ -414,6 +535,23 @@ enum isis_tlv_type { ISIS_SUBTLV_MAX = 40, + /* RFC 9352 section #2 */ + ISIS_SUBTLV_SRV6_CAPABILITIES = 25, + /* RFC 9352 section #4.1 */ + ISIS_SUBTLV_SRV6_MAX_SL_MSD = 41, + /* RFC 9352 section #4.2 */ + ISIS_SUBTLV_SRV6_MAX_END_POP_MSD = 42, + /* RFC 9352 section #4.3 */ + ISIS_SUBTLV_SRV6_MAX_H_ENCAPS_MSD = 44, + /* RFC 9352 section #4.4 */ + ISIS_SUBTLV_SRV6_MAX_END_D_MSD = 45, + + ISIS_SUBTLV_SRV6_END_SID = 5, + ISIS_SUBTLV_SRV6_ENDX_SID = 43, + ISIS_SUBTLV_SRV6_LAN_ENDX_SID = 44, + + ISIS_SUBSUBTLV_SRV6_SID_STRUCTURE = 1, + /* draft-ietf-lsr-isis-srv6-extensions */ ISIS_SUBSUBTLV_SID_STRUCTURE = 1, @@ -422,6 +560,10 @@ enum isis_tlv_type { /* subTLVs size for TE and SR */ enum ext_subtlv_size { + /* Sub-TLV Type and Length fields */ + ISIS_SUBTLV_TYPE_FIELD_SIZE = 1, + ISIS_SUBTLV_LENGTH_FIELD_SIZE = 1, + /* RFC 5307 */ ISIS_SUBTLV_LLRI_SIZE = 8, @@ -432,6 +574,8 @@ enum ext_subtlv_size { /* RFC 8491 */ ISIS_SUBTLV_NODE_MSD_SIZE = 2, + ISIS_SUBTLV_NODE_MSD_TYPE_SIZE = 1, + ISIS_SUBTLV_NODE_MSD_VALUE_SIZE = 1, /* RFC 8667 sections #2 & #3 */ ISIS_SUBTLV_SID_LABEL_SIZE = 3, @@ -454,6 +598,10 @@ enum ext_subtlv_size { ISIS_SUBTLV_MAX_SIZE = 180, + /* RFC 9352 sections #8.1 & #8.2 */ + ISIS_SUBTLV_SRV6_ENDX_SID_SIZE = 21, + ISIS_SUBTLV_SRV6_LAN_ENDX_SID_SIZE = 27, + /* draft-ietf-lsr-isis-srv6-extensions */ ISIS_SUBSUBTLV_SID_STRUCTURE_SIZE = 4, @@ -462,6 +610,9 @@ enum ext_subtlv_size { /* RFC9350 - Flex-Algorithm */ ISIS_SUBTLV_FAD_SUBSUBTLV_FLAGS_SIZE = 1, + + /* RFC 9352 section #2 */ + ISIS_SUBTLV_SRV6_CAPABILITIES_SIZE = 2, }; enum ext_subsubtlv_types { @@ -502,6 +653,8 @@ enum ext_subsubtlv_types { #define EXT_AVA_BW 0x080000 #define EXT_USE_BW 0x100000 #define EXT_EXTEND_ADM_GRP 0x200000 +#define EXT_SRV6_ENDX_SID 0x400000 +#define EXT_SRV6_LAN_ENDX_SID 0x800000 /* * This structure groups all Extended IS Reachability subTLVs. @@ -551,6 +704,10 @@ struct isis_ext_subtlvs { struct isis_item_list lan_sid; struct list *aslas; + + /* SRv6 End.X & LAN End.X SID */ + struct isis_item_list srv6_endx_sid; + struct isis_item_list srv6_lan_endx_sid; }; /* RFC 8919 */ @@ -599,6 +756,7 @@ int isis_pack_tlvs(struct isis_tlvs *tlvs, struct stream *stream, size_t len_pointer, bool pad, bool is_lsp); void isis_free_tlvs(struct isis_tlvs *tlvs); struct isis_tlvs *isis_alloc_tlvs(void); +struct isis_subsubtlvs *isis_alloc_subsubtlvs(enum isis_tlv_context context); int isis_unpack_tlvs(size_t avail_len, struct stream *stream, struct isis_tlvs **dest, const char **error_log); const char *isis_format_tlvs(struct isis_tlvs *tlvs, struct json_object *json); @@ -726,4 +884,20 @@ isis_tlvs_lookup_mt_router_info(struct isis_tlvs *tlvs, uint16_t mtid); void isis_tlvs_set_purge_originator(struct isis_tlvs *tlvs, const uint8_t *generator, const uint8_t *sender); + +void isis_subsubtlvs_set_srv6_sid_structure(struct isis_subsubtlvs *subsubtlvs, + struct isis_srv6_sid *sid); +void isis_subtlvs_add_srv6_end_sid(struct isis_subtlvs *subtlvs, + struct isis_srv6_sid *sid); +void isis_tlvs_add_srv6_locator(struct isis_tlvs *tlvs, uint16_t mtid, + struct isis_srv6_locator *loc); + +void isis_tlvs_add_srv6_endx_sid(struct isis_ext_subtlvs *exts, + struct isis_srv6_endx_sid_subtlv *adj); +void isis_tlvs_del_srv6_endx_sid(struct isis_ext_subtlvs *exts, + struct isis_srv6_endx_sid_subtlv *adj); +void isis_tlvs_add_srv6_lan_endx_sid(struct isis_ext_subtlvs *exts, + struct isis_srv6_lan_endx_sid_subtlv *lan); +void isis_tlvs_del_srv6_lan_endx_sid(struct isis_ext_subtlvs *exts, + struct isis_srv6_lan_endx_sid_subtlv *lan); #endif diff --git a/isisd/isis_zebra.c b/isisd/isis_zebra.c index 59b80c1e20..18a0c49ceb 100644 --- a/isisd/isis_zebra.c +++ b/isisd/isis_zebra.c @@ -98,6 +98,8 @@ static int isis_zebra_if_address_add(ZAPI_CALLBACK_ARGS) isis_circuit_add_addr(circuit, c); } + sr_if_addr_update(c->ifp); + return 0; } @@ -125,6 +127,8 @@ static int isis_zebra_if_address_del(ZAPI_CALLBACK_ARGS) isis_circuit_del_addr(circuit, c); } + sr_if_addr_update(c->ifp); + connected_free(&c); return 0; @@ -304,6 +308,9 @@ void isis_zebra_route_del_route(struct isis *isis, if (zclient->sock < 0) return; + if (!CHECK_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED)) + return; + memset(&api, 0, sizeof(api)); api.vrf_id = isis->vrf_id; api.type = PROTO_TYPE; @@ -498,10 +505,10 @@ static int isis_zebra_read(ZAPI_CALLBACK_ARGS) if (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD) isis_redist_add(isis, api.type, &api.prefix, &api.src_prefix, - api.distance, api.metric, api.tag); + api.distance, api.metric, api.tag, api.instance); else - isis_redist_delete(isis, api.type, &api.prefix, - &api.src_prefix); + isis_redist_delete(isis, api.type, &api.prefix, &api.src_prefix, + api.instance); return 0; } @@ -511,24 +518,26 @@ int isis_distribute_list_update(int routetype) return 0; } -void isis_zebra_redistribute_set(afi_t afi, int type, vrf_id_t vrf_id) +void isis_zebra_redistribute_set(afi_t afi, int type, vrf_id_t vrf_id, + uint16_t tableid) { if (type == DEFAULT_ROUTE) zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_ADD, zclient, afi, vrf_id); else zclient_redistribute(ZEBRA_REDISTRIBUTE_ADD, zclient, afi, type, - 0, vrf_id); + tableid, vrf_id); } -void isis_zebra_redistribute_unset(afi_t afi, int type, vrf_id_t vrf_id) +void isis_zebra_redistribute_unset(afi_t afi, int type, vrf_id_t vrf_id, + uint16_t tableid) { if (type == DEFAULT_ROUTE) zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, zclient, afi, vrf_id); else zclient_redistribute(ZEBRA_REDISTRIBUTE_DELETE, zclient, afi, - type, 0, vrf_id); + type, tableid, vrf_id); } /** @@ -772,9 +781,9 @@ static int isis_opaque_msg_handler(ZAPI_CALLBACK_ARGS) switch (info.type) { case LINK_STATE_SYNC: - STREAM_GETC(s, dst.proto); - STREAM_GETW(s, dst.instance); - STREAM_GETL(s, dst.session_id); + dst.proto = info.src_proto; + dst.instance = info.src_instance; + dst.session_id = info.src_session_id; dst.type = LINK_STATE_SYNC; ret = isis_te_sync_ted(dst); break; @@ -814,6 +823,551 @@ static int isis_zebra_client_close_notify(ZAPI_CALLBACK_ARGS) return ret; } +/** + * Send SRv6 SID to ZEBRA for installation or deletion. + * + * @param cmd ZEBRA_ROUTE_ADD or ZEBRA_ROUTE_DELETE + * @param sid SRv6 SID to install or delete + * @param prefixlen Prefix length + * @param oif Outgoing interface + * @param action SID action + * @param context SID context + */ +static void isis_zebra_send_localsid(int cmd, const struct in6_addr *sid, + uint16_t prefixlen, ifindex_t oif, + enum seg6local_action_t action, + const struct seg6local_context *context) +{ + struct prefix_ipv6 p = {}; + struct zapi_route api = {}; + struct zapi_nexthop *znh; + + if (cmd != ZEBRA_ROUTE_ADD && cmd != ZEBRA_ROUTE_DELETE) { + flog_warn(EC_LIB_DEVELOPMENT, "%s: wrong ZEBRA command", + __func__); + return; + } + + if (prefixlen > IPV6_MAX_BITLEN) { + flog_warn(EC_LIB_DEVELOPMENT, "%s: wrong prefixlen %u", + __func__, prefixlen); + return; + } + + sr_debug(" |- %s SRv6 SID %pI6 behavior %s", + cmd == ZEBRA_ROUTE_ADD ? "Add" : "Delete", sid, + seg6local_action2str(action)); + + p.family = AF_INET6; + p.prefixlen = prefixlen; + p.prefix = *sid; + + api.vrf_id = VRF_DEFAULT; + api.type = PROTO_TYPE; + api.instance = 0; + api.safi = SAFI_UNICAST; + memcpy(&api.prefix, &p, sizeof(p)); + + if (cmd == ZEBRA_ROUTE_DELETE) + return (void)zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, + &api); + + SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION); + SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP); + + znh = &api.nexthops[0]; + + memset(znh, 0, sizeof(*znh)); + + znh->type = NEXTHOP_TYPE_IFINDEX; + znh->ifindex = oif; + SET_FLAG(znh->flags, ZAPI_NEXTHOP_FLAG_SEG6LOCAL); + znh->seg6local_action = action; + memcpy(&znh->seg6local_ctx, context, sizeof(struct seg6local_context)); + + api.nexthop_num = 1; + + zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api); +} + +/** + * Install SRv6 SID in the forwarding plane through Zebra. + * + * @param area IS-IS area + * @param sid SRv6 SID + */ +void isis_zebra_srv6_sid_install(struct isis_area *area, + struct isis_srv6_sid *sid) +{ + enum seg6local_action_t action = ZEBRA_SEG6_LOCAL_ACTION_UNSPEC; + uint16_t prefixlen = IPV6_MAX_BITLEN; + struct seg6local_context ctx = {}; + struct interface *ifp; + + if (!area || !sid) + return; + + sr_debug("ISIS-SRv6 (%s): setting SRv6 SID %pI6", area->area_tag, + &sid->sid); + + switch (sid->behavior) { + case SRV6_ENDPOINT_BEHAVIOR_END: + action = ZEBRA_SEG6_LOCAL_ACTION_END; + prefixlen = IPV6_MAX_BITLEN; + break; + case SRV6_ENDPOINT_BEHAVIOR_END_NEXT_CSID: + action = ZEBRA_SEG6_LOCAL_ACTION_END; + prefixlen = sid->locator->block_bits_length + + sid->locator->node_bits_length; + SET_SRV6_FLV_OP(ctx.flv.flv_ops, + ZEBRA_SEG6_LOCAL_FLV_OP_NEXT_CSID); + ctx.flv.lcblock_len = sid->locator->block_bits_length; + ctx.flv.lcnode_func_len = sid->locator->node_bits_length; + break; + case SRV6_ENDPOINT_BEHAVIOR_END_X: + case SRV6_ENDPOINT_BEHAVIOR_END_X_NEXT_CSID: + case SRV6_ENDPOINT_BEHAVIOR_RESERVED: + case SRV6_ENDPOINT_BEHAVIOR_END_DT6: + case SRV6_ENDPOINT_BEHAVIOR_END_DT4: + case SRV6_ENDPOINT_BEHAVIOR_END_DT46: + case SRV6_ENDPOINT_BEHAVIOR_END_DT6_USID: + case SRV6_ENDPOINT_BEHAVIOR_END_DT4_USID: + case SRV6_ENDPOINT_BEHAVIOR_END_DT46_USID: + case SRV6_ENDPOINT_BEHAVIOR_OPAQUE: + default: + zlog_err( + "ISIS-SRv6 (%s): unsupported SRv6 endpoint behavior %u", + area->area_tag, sid->behavior); + return; + } + + /* Attach the SID to the SRv6 interface */ + ifp = if_lookup_by_name(area->srv6db.config.srv6_ifname, VRF_DEFAULT); + if (!ifp) { + zlog_warn( + "Failed to install SRv6 SID %pI6: %s interface not found", + &sid->sid, area->srv6db.config.srv6_ifname); + return; + } + + /* Send the SID to zebra */ + isis_zebra_send_localsid(ZEBRA_ROUTE_ADD, &sid->sid, prefixlen, + ifp->ifindex, action, &ctx); +} + +/** + * Uninstall SRv6 SID from the forwarding plane through Zebra. + * + * @param area IS-IS area + * @param sid SRv6 SID + */ +void isis_zebra_srv6_sid_uninstall(struct isis_area *area, + struct isis_srv6_sid *sid) +{ + enum seg6local_action_t action = ZEBRA_SEG6_LOCAL_ACTION_UNSPEC; + struct interface *ifp; + uint16_t prefixlen = IPV6_MAX_BITLEN; + + if (!area || !sid) + return; + + sr_debug("ISIS-SRv6 (%s): delete SID %pI6", area->area_tag, &sid->sid); + + switch (sid->behavior) { + case SRV6_ENDPOINT_BEHAVIOR_END: + prefixlen = IPV6_MAX_BITLEN; + break; + case SRV6_ENDPOINT_BEHAVIOR_END_NEXT_CSID: + prefixlen = sid->locator->block_bits_length + + sid->locator->node_bits_length; + break; + case SRV6_ENDPOINT_BEHAVIOR_RESERVED: + case SRV6_ENDPOINT_BEHAVIOR_END_X: + case SRV6_ENDPOINT_BEHAVIOR_END_DT6: + case SRV6_ENDPOINT_BEHAVIOR_END_DT4: + case SRV6_ENDPOINT_BEHAVIOR_END_DT46: + case SRV6_ENDPOINT_BEHAVIOR_END_X_NEXT_CSID: + case SRV6_ENDPOINT_BEHAVIOR_END_DT6_USID: + case SRV6_ENDPOINT_BEHAVIOR_END_DT4_USID: + case SRV6_ENDPOINT_BEHAVIOR_END_DT46_USID: + case SRV6_ENDPOINT_BEHAVIOR_OPAQUE: + default: + zlog_err( + "ISIS-SRv6 (%s): unsupported SRv6 endpoint behavior %u", + area->area_tag, sid->behavior); + return; + } + + /* The SID is attached to the SRv6 interface */ + ifp = if_lookup_by_name(area->srv6db.config.srv6_ifname, VRF_DEFAULT); + if (!ifp) { + zlog_warn("%s interface not found: nothing to uninstall", + area->srv6db.config.srv6_ifname); + return; + } + + /* Send delete request to zebra */ + isis_zebra_send_localsid(ZEBRA_ROUTE_DELETE, &sid->sid, prefixlen, + ifp->ifindex, action, NULL); +} + +void isis_zebra_srv6_adj_sid_install(struct srv6_adjacency *sra) +{ + enum seg6local_action_t action = ZEBRA_SEG6_LOCAL_ACTION_UNSPEC; + struct seg6local_context ctx = {}; + uint16_t prefixlen = IPV6_MAX_BITLEN; + struct interface *ifp; + struct isis_circuit *circuit; + struct isis_area *area; + + if (!sra) + return; + + circuit = sra->adj->circuit; + area = circuit->area; + + sr_debug("ISIS-SRv6 (%s): setting adjacency SID %pI6", area->area_tag, + &sra->sid); + + switch (sra->behavior) { + case SRV6_ENDPOINT_BEHAVIOR_END_X: + action = ZEBRA_SEG6_LOCAL_ACTION_END_X; + prefixlen = IPV6_MAX_BITLEN; + ctx.nh6 = sra->nexthop; + break; + case SRV6_ENDPOINT_BEHAVIOR_END_X_NEXT_CSID: + action = ZEBRA_SEG6_LOCAL_ACTION_END_X; + prefixlen = sra->locator->block_bits_length + + sra->locator->node_bits_length + + sra->locator->function_bits_length; + ctx.nh6 = sra->nexthop; + SET_SRV6_FLV_OP(ctx.flv.flv_ops, + ZEBRA_SEG6_LOCAL_FLV_OP_NEXT_CSID); + ctx.flv.lcblock_len = sra->locator->block_bits_length; + ctx.flv.lcnode_func_len = sra->locator->node_bits_length; + break; + case SRV6_ENDPOINT_BEHAVIOR_RESERVED: + case SRV6_ENDPOINT_BEHAVIOR_END: + case SRV6_ENDPOINT_BEHAVIOR_END_DT6: + case SRV6_ENDPOINT_BEHAVIOR_END_DT4: + case SRV6_ENDPOINT_BEHAVIOR_END_DT46: + case SRV6_ENDPOINT_BEHAVIOR_END_NEXT_CSID: + case SRV6_ENDPOINT_BEHAVIOR_END_DT6_USID: + case SRV6_ENDPOINT_BEHAVIOR_END_DT4_USID: + case SRV6_ENDPOINT_BEHAVIOR_END_DT46_USID: + case SRV6_ENDPOINT_BEHAVIOR_OPAQUE: + default: + zlog_err( + "ISIS-SRv6 (%s): unsupported SRv6 endpoint behavior %u", + area->area_tag, sra->behavior); + return; + } + + ifp = sra->adj->circuit->interface; + + isis_zebra_send_localsid(ZEBRA_ROUTE_ADD, &sra->sid, prefixlen, + ifp->ifindex, action, &ctx); +} + +void isis_zebra_srv6_adj_sid_uninstall(struct srv6_adjacency *sra) +{ + enum seg6local_action_t action = ZEBRA_SEG6_LOCAL_ACTION_UNSPEC; + struct interface *ifp; + uint16_t prefixlen = IPV6_MAX_BITLEN; + struct isis_circuit *circuit; + struct isis_area *area; + + if (!sra) + return; + + circuit = sra->adj->circuit; + area = circuit->area; + + switch (sra->behavior) { + case SRV6_ENDPOINT_BEHAVIOR_END_X: + prefixlen = IPV6_MAX_BITLEN; + break; + case SRV6_ENDPOINT_BEHAVIOR_END_X_NEXT_CSID: + prefixlen = sra->locator->block_bits_length + + sra->locator->node_bits_length + + sra->locator->function_bits_length; + break; + case SRV6_ENDPOINT_BEHAVIOR_RESERVED: + case SRV6_ENDPOINT_BEHAVIOR_END: + case SRV6_ENDPOINT_BEHAVIOR_END_DT6: + case SRV6_ENDPOINT_BEHAVIOR_END_DT4: + case SRV6_ENDPOINT_BEHAVIOR_END_DT46: + case SRV6_ENDPOINT_BEHAVIOR_END_NEXT_CSID: + case SRV6_ENDPOINT_BEHAVIOR_END_DT6_USID: + case SRV6_ENDPOINT_BEHAVIOR_END_DT4_USID: + case SRV6_ENDPOINT_BEHAVIOR_END_DT46_USID: + case SRV6_ENDPOINT_BEHAVIOR_OPAQUE: + default: + zlog_err( + "ISIS-SRv6 (%s): unsupported SRv6 endpoint behavior %u", + area->area_tag, sra->behavior); + return; + } + + ifp = sra->adj->circuit->interface; + + sr_debug("ISIS-SRv6 (%s): delete End.X SID %pI6", area->area_tag, + &sra->sid); + + isis_zebra_send_localsid(ZEBRA_ROUTE_DELETE, &sra->sid, prefixlen, + ifp->ifindex, action, NULL); +} + +/** + * Callback to process an SRv6 locator chunk received from SRv6 Manager (zebra). + * + * @result 0 on success, -1 otherwise + */ +static int isis_zebra_process_srv6_locator_chunk(ZAPI_CALLBACK_ARGS) +{ + struct isis *isis = isis_lookup_by_vrfid(VRF_DEFAULT); + struct stream *s = NULL; + struct listnode *node; + struct isis_area *area; + struct srv6_locator_chunk *c; + struct srv6_locator_chunk *chunk = srv6_locator_chunk_alloc(); + struct isis_srv6_sid *sid; + struct isis_adjacency *adj; + enum srv6_endpoint_behavior_codepoint behavior; + bool allocated = false; + + if (!isis) { + srv6_locator_chunk_free(&chunk); + return -1; + } + + /* Decode the received zebra message */ + s = zclient->ibuf; + if (zapi_srv6_locator_chunk_decode(s, chunk) < 0) { + srv6_locator_chunk_free(&chunk); + return -1; + } + + sr_debug( + "Received SRv6 locator chunk from zebra: name %s, " + "prefix %pFX, block_len %u, node_len %u, func_len %u, arg_len %u", + chunk->locator_name, &chunk->prefix, chunk->block_bits_length, + chunk->node_bits_length, chunk->function_bits_length, + chunk->argument_bits_length); + + /* Walk through all areas of the ISIS instance */ + for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) { + if (strncmp(area->srv6db.config.srv6_locator_name, + chunk->locator_name, + sizeof(area->srv6db.config.srv6_locator_name)) != 0) + continue; + + for (ALL_LIST_ELEMENTS_RO(area->srv6db.srv6_locator_chunks, + node, c)) { + if (!prefix_cmp(&c->prefix, &chunk->prefix)) { + srv6_locator_chunk_free(&chunk); + return 0; + } + } + + sr_debug( + "SRv6 locator chunk (locator %s, prefix %pFX) assigned to IS-IS area %s", + chunk->locator_name, &chunk->prefix, area->area_tag); + + /* Add the SRv6 Locator chunk to the per-area chunks list */ + listnode_add(area->srv6db.srv6_locator_chunks, chunk); + + /* Decide which behavior to use,depending on the locator type + * (i.e. uSID vs classic locator) */ + behavior = (CHECK_FLAG(chunk->flags, SRV6_LOCATOR_USID)) + ? SRV6_ENDPOINT_BEHAVIOR_END_NEXT_CSID + : SRV6_ENDPOINT_BEHAVIOR_END; + + /* Allocate new SRv6 End SID */ + sid = isis_srv6_sid_alloc(area, chunk, behavior, 0); + if (!sid) + return -1; + + /* Install the new SRv6 End SID in the forwarding plane through + * Zebra */ + isis_zebra_srv6_sid_install(area, sid); + + /* Store the SID */ + listnode_add(area->srv6db.srv6_sids, sid); + + /* Create SRv6 End.X SIDs from existing IS-IS Adjacencies */ + for (ALL_LIST_ELEMENTS_RO(area->adjacency_list, node, adj)) { + if (adj->ll_ipv6_count > 0) + srv6_endx_sid_add(adj); + } + + /* Regenerate LSPs to advertise the new locator and the SID */ + lsp_regenerate_schedule(area, area->is_type, 0); + + allocated = true; + break; + } + + if (!allocated) { + sr_debug("No IS-IS area configured for the locator %s", + chunk->locator_name); + srv6_locator_chunk_free(&chunk); + } + + return 0; +} + +/** + * Callback to process an SRv6 locator received from SRv6 Manager (zebra). + * + * @result 0 on success, -1 otherwise + */ +static int isis_zebra_process_srv6_locator_add(ZAPI_CALLBACK_ARGS) +{ + struct isis *isis = isis_lookup_by_vrfid(VRF_DEFAULT); + struct srv6_locator loc = {}; + struct listnode *node; + struct isis_area *area; + + if (!isis) + return -1; + + /* Decode the SRv6 locator */ + if (zapi_srv6_locator_decode(zclient->ibuf, &loc) < 0) + return -1; + + sr_debug( + "New SRv6 locator allocated in zebra: name %s, " + "prefix %pFX, block_len %u, node_len %u, func_len %u, arg_len %u", + loc.name, &loc.prefix, loc.block_bits_length, + loc.node_bits_length, loc.function_bits_length, + loc.argument_bits_length); + + /* Lookup on the IS-IS areas */ + for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) { + /* If SRv6 is enabled on this area and the configured locator + * corresponds to the new locator, then request a chunk from the + * locator */ + if (area->srv6db.config.enabled && + strncmp(area->srv6db.config.srv6_locator_name, loc.name, + sizeof(area->srv6db.config.srv6_locator_name)) == 0) { + sr_debug( + "Sending a request to get a chunk from the SRv6 locator %s (%pFX) " + "for IS-IS area %s", + loc.name, &loc.prefix, area->area_tag); + + if (isis_zebra_srv6_manager_get_locator_chunk( + loc.name) < 0) + return -1; + } + } + + return 0; +} + +/** + * Callback to process a notification from SRv6 Manager (zebra) of an SRv6 + * locator deleted. + * + * @result 0 on success, -1 otherwise + */ +static int isis_zebra_process_srv6_locator_delete(ZAPI_CALLBACK_ARGS) +{ + struct isis *isis = isis_lookup_by_vrfid(VRF_DEFAULT); + struct srv6_locator loc = {}; + struct isis_area *area; + struct listnode *node, *nnode; + struct srv6_locator_chunk *chunk; + struct isis_srv6_sid *sid; + struct srv6_adjacency *sra; + + if (!isis) + return -1; + + /* Decode the received zebra message */ + if (zapi_srv6_locator_decode(zclient->ibuf, &loc) < 0) + return -1; + + sr_debug( + "SRv6 locator deleted in zebra: name %s, " + "prefix %pFX, block_len %u, node_len %u, func_len %u, arg_len %u", + loc.name, &loc.prefix, loc.block_bits_length, + loc.node_bits_length, loc.function_bits_length, + loc.argument_bits_length); + + /* Walk through all areas of the ISIS instance */ + for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) { + if (strncmp(area->srv6db.config.srv6_locator_name, loc.name, + sizeof(area->srv6db.config.srv6_locator_name)) != 0) + continue; + + /* Delete SRv6 SIDs */ + for (ALL_LIST_ELEMENTS(area->srv6db.srv6_sids, node, nnode, + sid)) { + + sr_debug( + "Deleting SRv6 SID (locator %s, sid %pI6) from IS-IS area %s", + area->srv6db.config.srv6_locator_name, + &sid->sid, area->area_tag); + + /* Uninstall the SRv6 SID from the forwarding plane + * through Zebra */ + isis_zebra_srv6_sid_uninstall(area, sid); + + listnode_delete(area->srv6db.srv6_sids, sid); + isis_srv6_sid_free(sid); + } + + /* Uninstall all local Adjacency-SIDs. */ + for (ALL_LIST_ELEMENTS(area->srv6db.srv6_endx_sids, node, nnode, + sra)) + srv6_endx_sid_del(sra); + + /* Free the SRv6 locator chunks */ + for (ALL_LIST_ELEMENTS(area->srv6db.srv6_locator_chunks, node, + nnode, chunk)) { + if (prefix_match((struct prefix *)&loc.prefix, + (struct prefix *)&chunk->prefix)) { + listnode_delete( + area->srv6db.srv6_locator_chunks, + chunk); + srv6_locator_chunk_free(&chunk); + } + } + + /* Regenerate LSPs to advertise that the locator no longer + * exists */ + lsp_regenerate_schedule(area, area->is_type, 0); + } + + return 0; +} + +/** + * Request an SRv6 locator chunk to the SRv6 Manager (zebra) asynchronously. + * + * @param locator_name Name of SRv6 locator + * + * @result 0 on success, -1 otherwise + */ +int isis_zebra_srv6_manager_get_locator_chunk(const char *name) +{ + return srv6_manager_get_locator_chunk(zclient, name); +} + + +/** + * Release an SRv6 locator chunk. + * + * @param locator_name Name of SRv6 locator + * + * @result 0 on success, -1 otherwise + */ +int isis_zebra_srv6_manager_release_locator_chunk(const char *name) +{ + return srv6_manager_release_locator_chunk(zclient, name); +} + static zclient_handler *const isis_handlers[] = { [ZEBRA_ROUTER_ID_UPDATE] = isis_router_id_update_zebra, [ZEBRA_INTERFACE_ADDRESS_ADD] = isis_zebra_if_address_add, @@ -825,6 +1379,11 @@ static zclient_handler *const isis_handlers[] = { [ZEBRA_OPAQUE_MESSAGE] = isis_opaque_msg_handler, [ZEBRA_CLIENT_CLOSE_NOTIFY] = isis_zebra_client_close_notify, + + [ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK] = + isis_zebra_process_srv6_locator_chunk, + [ZEBRA_SRV6_LOCATOR_ADD] = isis_zebra_process_srv6_locator_add, + [ZEBRA_SRV6_LOCATOR_DELETE] = isis_zebra_process_srv6_locator_delete, }; void isis_zebra_init(struct event_loop *master, int instance) @@ -836,9 +1395,7 @@ void isis_zebra_init(struct event_loop *master, int instance) zclient->zebra_connected = isis_zebra_connected; /* Initialize special zclient for synchronous message exchanges. */ - struct zclient_options options = zclient_options_default; - options.synchronous = true; - zclient_sync = zclient_new(master, &options, NULL, 0); + zclient_sync = zclient_new(master, &zclient_options_sync, NULL, 0); zclient_sync->sock = -1; zclient_sync->redist_default = ZEBRA_ROUTE_ISIS; zclient_sync->instance = instance; diff --git a/isisd/isis_zebra.h b/isisd/isis_zebra.h index 045c75874a..f1684b7c25 100644 --- a/isisd/isis_zebra.h +++ b/isisd/isis_zebra.h @@ -43,8 +43,10 @@ void isis_zebra_prefix_sid_uninstall(struct isis_area *area, struct isis_sr_psid_info *psid); void isis_zebra_send_adjacency_sid(int cmd, const struct sr_adjacency *sra); int isis_distribute_list_update(int routetype); -void isis_zebra_redistribute_set(afi_t afi, int type, vrf_id_t vrf_id); -void isis_zebra_redistribute_unset(afi_t afi, int type, vrf_id_t vrf_id); +void isis_zebra_redistribute_set(afi_t afi, int type, vrf_id_t vrf_id, + uint16_t tableid); +void isis_zebra_redistribute_unset(afi_t afi, int type, vrf_id_t vrf_id, + uint16_t tableid); int isis_zebra_rlfa_register(struct isis_spftree *spftree, struct rlfa *rlfa); void isis_zebra_rlfa_unregister_all(struct isis_spftree *spftree); bool isis_zebra_label_manager_ready(void); @@ -55,4 +57,15 @@ void isis_zebra_vrf_register(struct isis *isis); void isis_zebra_vrf_deregister(struct isis *isis); int isis_zebra_ls_register(bool up); +extern void isis_zebra_srv6_sid_install(struct isis_area *area, + struct isis_srv6_sid *sid); +extern void isis_zebra_srv6_sid_uninstall(struct isis_area *area, + struct isis_srv6_sid *sid); + +void isis_zebra_srv6_adj_sid_install(struct srv6_adjacency *sra); +void isis_zebra_srv6_adj_sid_uninstall(struct srv6_adjacency *sra); + +extern int isis_zebra_srv6_manager_get_locator_chunk(const char *name); +extern int isis_zebra_srv6_manager_release_locator_chunk(const char *name); + #endif /* _ZEBRA_ISIS_ZEBRA_H */ diff --git a/isisd/isisd.c b/isisd/isisd.c index ea304ba5ef..b1064d8941 100644 --- a/isisd/isisd.c +++ b/isisd/isisd.c @@ -337,6 +337,7 @@ struct isis_area *isis_area_create(const char *area_tag, const char *vrf_name) flags_initialize(&area->flags); isis_sr_area_init(area); + isis_srv6_area_init(area); /* * Default values @@ -525,6 +526,7 @@ void isis_area_destroy(struct isis_area *area) #endif /* ifndef FABRICD */ isis_sr_area_term(area); + isis_srv6_area_term(area); isis_mpls_te_term(area); @@ -599,64 +601,66 @@ static int isis_vrf_delete(struct vrf *vrf) static void isis_set_redist_vrf_bitmaps(struct isis *isis, bool set) { - struct listnode *node; + struct listnode *node, *lnode; struct isis_area *area; int type; int level; int protocol; - - char do_subscribe[REDIST_PROTOCOL_COUNT][ZEBRA_ROUTE_MAX + 1]; - - memset(do_subscribe, 0, sizeof(do_subscribe)); + struct isis_redist *redist; for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) for (protocol = 0; protocol < REDIST_PROTOCOL_COUNT; protocol++) for (type = 0; type < ZEBRA_ROUTE_MAX + 1; type++) - for (level = 0; level < ISIS_LEVELS; level++) - if (area->redist_settings[protocol] - [type][level] - .redist - == 1) - do_subscribe[protocol][type] = - 1; - - for (protocol = 0; protocol < REDIST_PROTOCOL_COUNT; protocol++) - for (type = 0; type < ZEBRA_ROUTE_MAX + 1; type++) { - /* This field is actually controlling transmission of - * the IS-IS - * routes to Zebra and has nothing to do with - * redistribution, - * so skip it. */ - if (type == PROTO_TYPE) - continue; - - if (!do_subscribe[protocol][type]) - continue; - - afi_t afi = afi_for_redist_protocol(protocol); - - if (type == DEFAULT_ROUTE) { - if (set) - vrf_bitmap_set( - zclient->default_information - [afi], - isis->vrf_id); - else - vrf_bitmap_unset( - zclient->default_information - [afi], - isis->vrf_id); - } else { - if (set) - vrf_bitmap_set( - zclient->redist[afi][type], - isis->vrf_id); - else - vrf_bitmap_unset( - zclient->redist[afi][type], - isis->vrf_id); - } - } + for (level = 0; level < ISIS_LEVELS; level++) { + if (area->redist_settings[protocol][type] + [level] == NULL) + continue; + for (ALL_LIST_ELEMENTS_RO(area->redist_settings + [protocol] + [type] + [level], + lnode, + redist)) { + if (redist->redist == 0) + continue; + /* This field is actually + * controlling transmission of + * the IS-IS + * routes to Zebra and has + * nothing to do with + * redistribution, + * so skip it. */ + afi_t afi = + afi_for_redist_protocol( + protocol); + + if (type == DEFAULT_ROUTE) { + if (set) + vrf_bitmap_set( + &zclient->default_information + [afi], + isis->vrf_id); + else + vrf_bitmap_unset( + &zclient->default_information + [afi], + isis->vrf_id); + } else { + if (set) + vrf_bitmap_set( + &zclient->redist + [afi] + [type], + isis->vrf_id); + else + vrf_bitmap_unset( + &zclient->redist + [afi] + [type], + isis->vrf_id); + } + } + } } static int isis_vrf_enable(struct vrf *vrf) @@ -3828,6 +3832,20 @@ struct cmd_node isis_flex_algo_node = { }; #endif /* ifdnef FABRICD */ +struct cmd_node isis_srv6_node = { + .name = "isis-srv6", + .node = ISIS_SRV6_NODE, + .parent_node = ISIS_NODE, + .prompt = "%s(config-router-srv6)# ", +}; + +struct cmd_node isis_srv6_node_msd_node = { + .name = "isis-srv6-node-msd", + .node = ISIS_SRV6_NODE_MSD_NODE, + .parent_node = ISIS_SRV6_NODE, + .prompt = "%s(config-router-srv6-node-msd)# ", +}; + void isis_init(void) { /* Install IS-IS top node */ @@ -3940,5 +3958,11 @@ void isis_init(void) install_default(ISIS_FLEX_ALGO_NODE); #endif /* ifdnef FABRICD */ + install_node(&isis_srv6_node); + install_default(ISIS_SRV6_NODE); + + install_node(&isis_srv6_node_msd_node); + install_default(ISIS_SRV6_NODE_MSD_NODE); + spf_backoff_cmd_init(); } diff --git a/isisd/isisd.h b/isisd/isisd.h index f0d236b643..f5042e4ad5 100644 --- a/isisd/isisd.h +++ b/isisd/isisd.h @@ -19,6 +19,7 @@ #include "isisd/isis_pdu_counter.h" #include "isisd/isis_circuit.h" #include "isisd/isis_sr.h" +#include "isisd/isis_srv6.h" #include "isis_flags.h" #include "isis_lsp.h" #include "isis_lfa.h" @@ -208,6 +209,8 @@ struct isis_area { struct mpls_te_area *mta; /* Segment Routing information */ struct isis_sr_db srdb; + /* Segment Routing over IPv6 (SRv6) information */ + struct isis_srv6_db srv6db; int ipv6_circuits; bool purge_originator; /* SPF prefix priorities. */ @@ -230,8 +233,8 @@ struct isis_area { #endif /* ifndef FABRICD */ /* Counters */ uint32_t circuit_state_changes; - struct isis_redist redist_settings[REDIST_PROTOCOL_COUNT] - [ZEBRA_ROUTE_MAX + 1][ISIS_LEVELS]; + struct list *redist_settings[REDIST_PROTOCOL_COUNT][ZEBRA_ROUTE_MAX + 1] + [ISIS_LEVELS]; struct route_table *ext_reach[REDIST_PROTOCOL_COUNT][ISIS_LEVELS]; struct spf_backoff *spf_delay_ietf[ISIS_LEVELS]; /*Structure with IETF @@ -339,6 +342,7 @@ void config_end_lsp_generate(struct isis_area *area); /* YANG paths */ #define ISIS_INSTANCE "/frr-isisd:isis/instance" #define ISIS_SR "/frr-isisd:isis/instance/segment-routing" +#define ISIS_SRV6 "/frr-isisd:isis/instance/segment-routing-srv6" /* Master of threads. */ extern struct event_loop *master; diff --git a/isisd/subdir.am b/isisd/subdir.am index 6bd2477b19..e33cb76550 100644 --- a/isisd/subdir.am +++ b/isisd/subdir.am @@ -47,6 +47,7 @@ noinst_HEADERS += \ isisd/isis_spf_private.h \ isisd/isis_sr.h \ isisd/isis_flex_algo.h \ + isisd/isis_srv6.h \ isisd/isis_te.h \ isisd/isis_tlvs.h \ isisd/isis_tx_queue.h \ @@ -80,6 +81,7 @@ LIBISIS_SOURCES = \ isisd/isis_spf.c \ isisd/isis_sr.c \ isisd/isis_flex_algo.c \ + isisd/isis_srv6.c \ isisd/isis_te.c \ isisd/isis_tlvs.c \ isisd/isis_tx_queue.c \ @@ -96,7 +98,7 @@ ISIS_SOURCES = \ isisd/isis_pfpacket.c \ # end -ISIS_LDADD_COMMON = lib/libfrr.la $(LIBCAP) +ISIS_LDADD_COMMON = lib/libfrr.la $(LIBCAP) $(LIBYANG_LIBS) # Building isisd diff --git a/ldpd/control.c b/ldpd/control.c index 6bb5204d13..a08ce4cc1a 100644 --- a/ldpd/control.c +++ b/ldpd/control.c @@ -6,6 +6,7 @@ */ #include <zebra.h> +#include <sys/stat.h> #include <sys/un.h> #include "ldpd.h" @@ -106,8 +107,7 @@ static void control_accept(struct event *thread) */ if (errno == ENFILE || errno == EMFILE) accept_pause(); - else if (errno != EWOULDBLOCK && errno != EINTR && - errno != ECONNABORTED) + else if (errno != EWOULDBLOCK && errno != EINTR && errno != ECONNABORTED) log_warn("%s: accept", __func__); return; } @@ -192,8 +192,7 @@ static void control_dispatch_imsg(struct event *thread) c->iev.ev_read = NULL; - if (((n = imsg_read(&c->iev.ibuf)) == -1 && errno != EAGAIN) || - n == 0) { + if (((n = imsg_read(&c->iev.ibuf)) == -1 && errno != EAGAIN) || n == 0) { control_close(fd); return; } @@ -217,12 +216,10 @@ static void control_dispatch_imsg(struct event *thread) /* ignore */ break; case IMSG_CTL_SHOW_INTERFACE: - if (imsg.hdr.len == IMSG_HEADER_SIZE + - sizeof(ifidx)) { + if (imsg.hdr.len == IMSG_HEADER_SIZE + sizeof(ifidx)) { memcpy(&ifidx, imsg.data, sizeof(ifidx)); ldpe_iface_ctl(c, ifidx); - imsg_compose_event(&c->iev, IMSG_CTL_END, 0, - 0, -1, NULL, 0); + imsg_compose_event(&c->iev, IMSG_CTL_END, 0, 0, -1, NULL, 0); } break; case IMSG_CTL_SHOW_DISCOVERY: @@ -242,8 +239,7 @@ static void control_dispatch_imsg(struct event *thread) ldpe_nbr_ctl(c); break; case IMSG_CTL_CLEAR_NBR: - if (imsg.hdr.len != IMSG_HEADER_SIZE + - sizeof(struct ctl_nbr)) + if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(struct ctl_nbr)) break; nbr_clear_ctl(imsg.data); @@ -255,8 +251,7 @@ static void control_dispatch_imsg(struct event *thread) /* ignore */ break; default: - log_debug("%s: error handling imsg %d", __func__, - imsg.hdr.type); + log_debug("%s: error handling imsg %d", __func__, imsg.hdr.type); break; } imsg_free(&imsg); diff --git a/ldpd/init.c b/ldpd/init.c index 15d653b747..ef782471b8 100644 --- a/ldpd/init.c +++ b/ldpd/init.c @@ -31,13 +31,13 @@ send_init(struct nbr *nbr) if ((buf = ibuf_open(size)) == NULL) fatal(__func__); - err |= gen_ldp_hdr(buf, size); + SET_FLAG(err, gen_ldp_hdr(buf, size)); size -= LDP_HDR_SIZE; - err |= gen_msg_hdr(buf, MSG_TYPE_INIT, size); - err |= gen_init_prms_tlv(buf, nbr); - err |= gen_cap_dynamic_tlv(buf); - err |= gen_cap_twcard_tlv(buf, 1); - err |= gen_cap_unotif_tlv(buf, 1); + SET_FLAG(err, gen_msg_hdr(buf, MSG_TYPE_INIT, size)); + SET_FLAG(err, gen_init_prms_tlv(buf, nbr)); + SET_FLAG(err, gen_cap_dynamic_tlv(buf)); + SET_FLAG(err, gen_cap_twcard_tlv(buf, 1)); + SET_FLAG(err, gen_cap_unotif_tlv(buf, 1)); if (err) { ibuf_free(buf); return; @@ -121,62 +121,56 @@ recv_init(struct nbr *nbr, char *buf, uint16_t len) return (-1); case TLV_TYPE_DYNAMIC_CAP: if (tlv_len != CAP_TLV_DYNAMIC_LEN) { - session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, - msg.type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, msg.type); return (-1); } - if (caps_rcvd & F_CAP_TLV_RCVD_DYNAMIC) { - session_shutdown(nbr, S_BAD_TLV_VAL, msg.id, - msg.type); + if (CHECK_FLAG(caps_rcvd, F_CAP_TLV_RCVD_DYNAMIC)) { + session_shutdown(nbr, S_BAD_TLV_VAL, msg.id, msg.type); return (-1); } - caps_rcvd |= F_CAP_TLV_RCVD_DYNAMIC; + SET_FLAG(caps_rcvd, F_CAP_TLV_RCVD_DYNAMIC); - nbr->flags |= F_NBR_CAP_DYNAMIC; + SET_FLAG(nbr->flags, F_NBR_CAP_DYNAMIC); log_debug("%s: lsr-id %pI4 announced the Dynamic Capability Announcement capability", __func__, &nbr->id); break; case TLV_TYPE_TWCARD_CAP: if (tlv_len != CAP_TLV_TWCARD_LEN) { - session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, - msg.type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, msg.type); return (-1); } - if (caps_rcvd & F_CAP_TLV_RCVD_TWCARD) { - session_shutdown(nbr, S_BAD_TLV_VAL, msg.id, - msg.type); + if (CHECK_FLAG(caps_rcvd, F_CAP_TLV_RCVD_TWCARD)) { + session_shutdown(nbr, S_BAD_TLV_VAL, msg.id, msg.type); return (-1); } - caps_rcvd |= F_CAP_TLV_RCVD_TWCARD; + SET_FLAG(caps_rcvd, F_CAP_TLV_RCVD_TWCARD); - nbr->flags |= F_NBR_CAP_TWCARD; + SET_FLAG(nbr->flags, F_NBR_CAP_TWCARD); log_debug("%s: lsr-id %pI4 announced the Typed Wildcard FEC capability", __func__, &nbr->id); break; case TLV_TYPE_UNOTIF_CAP: if (tlv_len != CAP_TLV_UNOTIF_LEN) { - session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, - msg.type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, msg.type); return (-1); } - if (caps_rcvd & F_CAP_TLV_RCVD_UNOTIF) { - session_shutdown(nbr, S_BAD_TLV_VAL, msg.id, - msg.type); + if (CHECK_FLAG(caps_rcvd, F_CAP_TLV_RCVD_UNOTIF)) { + session_shutdown(nbr, S_BAD_TLV_VAL, msg.id, msg.type); return (-1); } - caps_rcvd |= F_CAP_TLV_RCVD_UNOTIF; + SET_FLAG(caps_rcvd, F_CAP_TLV_RCVD_UNOTIF); - nbr->flags |= F_NBR_CAP_UNOTIF; + SET_FLAG(nbr->flags, F_NBR_CAP_UNOTIF); log_debug("%s: lsr-id %pI4 announced the Unrecognized Notification capability", __func__, &nbr->id); break; default: - if (!(ntohs(tlv.type) & UNKNOWN_FLAG)) + if (!CHECK_FLAG(ntohs(tlv.type), UNKNOWN_FLAG)) send_notification_rtlvs(nbr, S_UNSSUPORTDCAP, msg.id, msg.type, tlv_type, tlv_len, buf); /* ignore unknown tlv */ @@ -217,16 +211,16 @@ send_capability(struct nbr *nbr, uint16_t capability, int enable) if ((buf = ibuf_open(size)) == NULL) fatal(__func__); - err |= gen_ldp_hdr(buf, size); + SET_FLAG(err, gen_ldp_hdr(buf, size)); size -= LDP_HDR_SIZE; - err |= gen_msg_hdr(buf, MSG_TYPE_CAPABILITY, size); + SET_FLAG(err, gen_msg_hdr(buf, MSG_TYPE_CAPABILITY, size)); switch (capability) { case TLV_TYPE_TWCARD_CAP: - err |= gen_cap_twcard_tlv(buf, enable); + SET_FLAG(err, gen_cap_twcard_tlv(buf, enable)); break; case TLV_TYPE_UNOTIF_CAP: - err |= gen_cap_unotif_tlv(buf, enable); + SET_FLAG(err, gen_cap_unotif_tlv(buf, enable)); break; case TLV_TYPE_DYNAMIC_CAP: /* @@ -235,9 +229,11 @@ send_capability(struct nbr *nbr, uint16_t capability, int enable) * Announcement Parameter in Capability messages sent to * its peers". */ - /* FALLTHROUGH */ + fatalx("send_capability: An LDP speaker MUST NOT include the Dynamic Capability Announcement Parameter"); + break; default: fatalx("send_capability: unsupported capability"); + break; } if (err) { @@ -288,52 +284,47 @@ recv_capability(struct nbr *nbr, char *buf, uint16_t len) switch (tlv_type) { case TLV_TYPE_TWCARD_CAP: if (tlv_len != CAP_TLV_TWCARD_LEN) { - session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, - msg.type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, msg.type); return (-1); } - if (caps_rcvd & F_CAP_TLV_RCVD_TWCARD) { - session_shutdown(nbr, S_BAD_TLV_VAL, msg.id, - msg.type); + if (CHECK_FLAG(caps_rcvd, F_CAP_TLV_RCVD_TWCARD)) { + session_shutdown(nbr, S_BAD_TLV_VAL, msg.id, msg.type); return (-1); } - caps_rcvd |= F_CAP_TLV_RCVD_TWCARD; + SET_FLAG(caps_rcvd, F_CAP_TLV_RCVD_TWCARD); memcpy(&reserved, buf, sizeof(reserved)); enable = reserved & STATE_BIT; if (enable) - nbr->flags |= F_NBR_CAP_TWCARD; + SET_FLAG(nbr->flags, F_NBR_CAP_TWCARD); else - nbr->flags &= ~F_NBR_CAP_TWCARD; + UNSET_FLAG(nbr->flags, F_NBR_CAP_TWCARD); log_debug("%s: lsr-id %pI4 %s the Typed Wildcard FEC capability", __func__, &nbr->id, (enable) ? "announced" : "withdrew"); break; case TLV_TYPE_UNOTIF_CAP: if (tlv_len != CAP_TLV_UNOTIF_LEN) { - session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, - msg.type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, msg.type); return (-1); } - if (caps_rcvd & F_CAP_TLV_RCVD_UNOTIF) { - session_shutdown(nbr, S_BAD_TLV_VAL, msg.id, - msg.type); + if (CHECK_FLAG(caps_rcvd, F_CAP_TLV_RCVD_UNOTIF)) { + session_shutdown(nbr, S_BAD_TLV_VAL, msg.id, msg.type); return (-1); } - caps_rcvd |= F_CAP_TLV_RCVD_UNOTIF; + SET_FLAG(caps_rcvd, F_CAP_TLV_RCVD_UNOTIF); memcpy(&reserved, buf, sizeof(reserved)); enable = reserved & STATE_BIT; if (enable) - nbr->flags |= F_NBR_CAP_UNOTIF; + SET_FLAG(nbr->flags, F_NBR_CAP_UNOTIF); else - nbr->flags &= ~F_NBR_CAP_UNOTIF; + UNSET_FLAG(nbr->flags, F_NBR_CAP_UNOTIF); log_debug("%s: lsr-id %pI4 %s the Unrecognized Notification capability", __func__, - &nbr->id, (enable) ? "announced" : - "withdrew"); + &nbr->id, (enable) ? "announced" : "withdrew"); break; case TLV_TYPE_DYNAMIC_CAP: /* @@ -344,9 +335,9 @@ recv_capability(struct nbr *nbr, char *buf, uint16_t len) * parameter and process any other Capability Parameters * in the message". */ - /* FALLTHROUGH */ + fallthrough; default: - if (!(ntohs(tlv.type) & UNKNOWN_FLAG)) + if (!CHECK_FLAG(ntohs(tlv.type), UNKNOWN_FLAG)) send_notification_rtlvs(nbr, S_UNSSUPORTDCAP, msg.id, msg.type, tlv_type, tlv_len, buf); /* ignore unknown tlv */ diff --git a/ldpd/l2vpn.c b/ldpd/l2vpn.c index 4664b1f894..ce038acdcb 100644 --- a/ldpd/l2vpn.c +++ b/ldpd/l2vpn.c @@ -161,7 +161,7 @@ l2vpn_if_update(struct l2vpn_if *lif) fec.type = MAP_TYPE_PWID; fec.fec.pwid.type = l2vpn->pw_type; fec.fec.pwid.group_id = 0; - fec.flags |= F_MAP_PW_ID; + SET_FLAG(fec.flags, F_MAP_PW_ID); fec.fec.pwid.pwid = pw->pwid; send_mac_withdrawal(nbr, &fec, lif->mac); @@ -274,17 +274,17 @@ l2vpn_pw_reset(struct l2vpn_pw *pw) pw->local_status = PW_FORWARDING; pw->remote_status = PW_NOT_FORWARDING; - if (pw->flags & F_PW_CWORD_CONF) - pw->flags |= F_PW_CWORD; + if (CHECK_FLAG(pw->flags, F_PW_CWORD_CONF)) + SET_FLAG(pw->flags, F_PW_CWORD); else - pw->flags &= ~F_PW_CWORD; + UNSET_FLAG(pw->flags, F_PW_CWORD); - if (pw->flags & F_PW_STATUSTLV_CONF) - pw->flags |= F_PW_STATUSTLV; + if (CHECK_FLAG(pw->flags, F_PW_STATUSTLV_CONF)) + SET_FLAG(pw->flags, F_PW_STATUSTLV); else - pw->flags &= ~F_PW_STATUSTLV; + UNSET_FLAG(pw->flags, F_PW_STATUSTLV); - if (pw->flags & F_PW_STATUSTLV_CONF) { + if (CHECK_FLAG(pw->flags, F_PW_STATUSTLV_CONF)) { struct fec_node *fn; struct fec fec; l2vpn_pw_fec(pw, &fec); @@ -300,8 +300,7 @@ l2vpn_pw_ok(struct l2vpn_pw *pw, struct fec_nh *fnh) { /* check for a remote label */ if (fnh->remote_label == NO_LABEL) { - log_warnx("%s: pseudowire %s: no remote label", __func__, - pw->ifname); + log_warnx("%s: pseudowire %s: no remote label", __func__, pw->ifname); pw->reason = F_PW_NO_REMOTE_LABEL; return (0); } @@ -315,10 +314,9 @@ l2vpn_pw_ok(struct l2vpn_pw *pw, struct fec_nh *fnh) } /* check pw status if applicable */ - if ((pw->flags & F_PW_STATUSTLV) && + if (CHECK_FLAG(pw->flags, F_PW_STATUSTLV) && pw->remote_status != PW_FORWARDING) { - log_warnx("%s: pseudowire %s: remote end is down", __func__, - pw->ifname); + log_warnx("%s: pseudowire %s: remote end is down", __func__, pw->ifname); pw->reason = F_PW_REMOTE_NOT_FWD; return (0); } @@ -345,34 +343,34 @@ l2vpn_pw_negotiate(struct lde_nbr *ln, struct fec_node *fn, struct map *map) /* RFC4447 - Section 6.2: control word negotiation */ if (fec_find(&ln->sent_map, &fn->fec)) { - if ((map->flags & F_MAP_PW_CWORD) && - !(pw->flags & F_PW_CWORD_CONF)) { + if (CHECK_FLAG(map->flags, F_MAP_PW_CWORD) && + !CHECK_FLAG(pw->flags, F_PW_CWORD_CONF)) { /* ignore the received label mapping */ return (1); - } else if (!(map->flags & F_MAP_PW_CWORD) && - (pw->flags & F_PW_CWORD_CONF)) { + } else if (!CHECK_FLAG(map->flags, F_MAP_PW_CWORD) && + CHECK_FLAG(pw->flags, F_PW_CWORD_CONF)) { /* append a "Wrong C-bit" status code */ st.status_code = S_WRONG_CBIT; st.msg_id = map->msg_id; st.msg_type = htons(MSG_TYPE_LABELMAPPING); lde_send_labelwithdraw(ln, fn, NULL, &st); - pw->flags &= ~F_PW_CWORD; + UNSET_FLAG(pw->flags, F_PW_CWORD); lde_send_labelmapping(ln, fn, 1); } - } else if (map->flags & F_MAP_PW_CWORD) { - if (pw->flags & F_PW_CWORD_CONF) - pw->flags |= F_PW_CWORD; + } else if (CHECK_FLAG(map->flags, F_MAP_PW_CWORD)) { + if (CHECK_FLAG(pw->flags, F_PW_CWORD_CONF)) + SET_FLAG(pw->flags, F_PW_CWORD); else /* act as if no label mapping had been received */ return (1); } else - pw->flags &= ~F_PW_CWORD; + UNSET_FLAG(pw->flags, F_PW_CWORD); /* RFC4447 - Section 5.4.3: pseudowire status negotiation */ if (fec_find(&ln->recv_map, &fn->fec) == NULL && - !(map->flags & F_MAP_PW_STATUS)) - pw->flags &= ~F_PW_STATUSTLV; + !CHECK_FLAG(map->flags, F_MAP_PW_STATUS)) + UNSET_FLAG(pw->flags, F_PW_STATUSTLV); return (0); } @@ -385,12 +383,11 @@ l2vpn_send_pw_status(struct lde_nbr *ln, uint32_t status, struct fec *fec) memset(&nm, 0, sizeof(nm)); nm.status_code = S_PW_STATUS; nm.pw_status = status; - nm.flags |= F_NOTIF_PW_STATUS; + SET_FLAG(nm.flags, F_NOTIF_PW_STATUS); lde_fec2map(fec, &nm.fec); - nm.flags |= F_NOTIF_FEC; + SET_FLAG(nm.flags, F_NOTIF_FEC); - lde_imsg_compose_ldpe(IMSG_NOTIFICATION_SEND, ln->peerid, 0, &nm, - sizeof(nm)); + lde_imsg_compose_ldpe(IMSG_NOTIFICATION_SEND, ln->peerid, 0, &nm, sizeof(nm)); } void @@ -402,14 +399,13 @@ l2vpn_send_pw_status_wcard(struct lde_nbr *ln, uint32_t status, memset(&nm, 0, sizeof(nm)); nm.status_code = S_PW_STATUS; nm.pw_status = status; - nm.flags |= F_NOTIF_PW_STATUS; + SET_FLAG(nm.flags, F_NOTIF_PW_STATUS); nm.fec.type = MAP_TYPE_PWID; nm.fec.fec.pwid.type = pw_type; nm.fec.fec.pwid.group_id = group_id; - nm.flags |= F_NOTIF_FEC; + SET_FLAG(nm.flags, F_NOTIF_FEC); - lde_imsg_compose_ldpe(IMSG_NOTIFICATION_SEND, ln->peerid, 0, &nm, - sizeof(nm)); + lde_imsg_compose_ldpe(IMSG_NOTIFICATION_SEND, ln->peerid, 0, &nm, sizeof(nm)); } void @@ -421,7 +417,7 @@ l2vpn_recv_pw_status(struct lde_nbr *ln, struct notify_msg *nm) struct l2vpn_pw *pw; if (nm->fec.type == MAP_TYPE_TYPED_WCARD || - !(nm->fec.flags & F_MAP_PW_ID)) { + !CHECK_FLAG(nm->fec.flags, F_MAP_PW_ID)) { l2vpn_recv_pw_status_wcard(ln, nm); return; } @@ -540,7 +536,7 @@ l2vpn_pw_status_update(struct zapi_pw_status *zpw) if (ln == NULL) return (0); l2vpn_pw_fec(pw, &fec); - if (pw->flags & F_PW_STATUSTLV) + if (CHECK_FLAG(pw->flags, F_PW_STATUSTLV)) l2vpn_send_pw_status(ln, local_status, &fec); else { struct fec_node *fn; @@ -611,8 +607,7 @@ l2vpn_binding_ctl(pid_t pid) pwctl.local_label = fn->local_label; pwctl.local_gid = 0; pwctl.local_ifmtu = pw->l2vpn->mtu; - pwctl.local_cword = (pw->flags & F_PW_CWORD_CONF) ? - 1 : 0; + pwctl.local_cword = CHECK_FLAG(pw->flags, F_PW_CWORD_CONF) ? 1 : 0; pwctl.reason = pw->reason; } else pwctl.local_label = NO_LABEL; @@ -624,11 +619,10 @@ l2vpn_binding_ctl(pid_t pid) if (me) { pwctl.remote_label = me->map.label; pwctl.remote_gid = me->map.fec.pwid.group_id; - if (me->map.flags & F_MAP_PW_IFMTU) + if (CHECK_FLAG(me->map.flags, F_MAP_PW_IFMTU)) pwctl.remote_ifmtu = me->map.fec.pwid.ifmtu; if (pw) - pwctl.remote_cword = (pw->flags & F_PW_CWORD) ? - 1 : 0; + pwctl.remote_cword = CHECK_FLAG(pw->flags, F_PW_CWORD) ? 1 : 0; lde_imsg_compose_ldpe(IMSG_CTL_SHOW_L2VPN_BINDING, 0, pid, &pwctl, sizeof(pwctl)); diff --git a/ldpd/lde.c b/ldpd/lde.c index 806bab6a21..ef4aecadad 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -87,7 +87,7 @@ static struct list *label_chunk_list; static struct listnode *current_label_chunk; /* Synchronous zclient to request labels */ -static struct zclient *zclient_sync; +struct zclient *zclient_sync; /* SIGINT / SIGTERM handler. */ static void @@ -2135,12 +2135,8 @@ static void zclient_sync_retry(struct event *thread) */ static void zclient_sync_init(void) { - struct zclient_options options = zclient_options_default; - - options.synchronous = true; - /* Initialize special zclient for synchronous message exchanges. */ - zclient_sync = zclient_new(master, &options, NULL, 0); + zclient_sync = zclient_new(master, &zclient_options_sync, NULL, 0); zclient_sync->sock = -1; zclient_sync->redist_default = ZEBRA_ROUTE_LDP; zclient_sync->session_id = 1; /* Distinguish from main session */ diff --git a/ldpd/ldp_debug.c b/ldpd/ldp_debug.c index d2aeaba8b3..957fb8e556 100644 --- a/ldpd/ldp_debug.c +++ b/ldpd/ldp_debug.c @@ -97,8 +97,7 @@ ldp_vty_debug(struct vty *vty, const char *negate, const char *type_str, DEBUG_ON(zebra, LDP_DEBUG_ZEBRA); } - main_imsg_compose_both(IMSG_DEBUG_UPDATE, &ldp_debug, - sizeof(ldp_debug)); + main_imsg_compose_both(IMSG_DEBUG_UPDATE, &ldp_debug, sizeof(ldp_debug)); return (CMD_SUCCESS); } @@ -119,13 +118,11 @@ ldp_vty_show_debugging(struct vty *vty) if (LDP_DEBUG(labels, LDP_DEBUG_LABELS)) vty_out (vty, " LDP labels debugging is on\n"); if (LDP_DEBUG(msg, LDP_DEBUG_MSG_RECV_ALL)) - vty_out (vty, - " LDP detailed messages debugging is on (inbound)\n"); + vty_out (vty, " LDP detailed messages debugging is on (inbound)\n"); else if (LDP_DEBUG(msg, LDP_DEBUG_MSG_RECV)) vty_out (vty," LDP messages debugging is on (inbound)\n"); if (LDP_DEBUG(msg, LDP_DEBUG_MSG_SEND_ALL)) - vty_out (vty, - " LDP detailed messages debugging is on (outbound)\n"); + vty_out (vty, " LDP detailed messages debugging is on (outbound)\n"); else if (LDP_DEBUG(msg, LDP_DEBUG_MSG_SEND)) vty_out (vty," LDP messages debugging is on (outbound)\n"); if (LDP_DEBUG(sync, LDP_DEBUG_SYNC)) diff --git a/ldpd/ldp_vty_exec.c b/ldpd/ldp_vty_exec.c index 906b5c1bf2..f3bcd1b254 100644 --- a/ldpd/ldp_vty_exec.c +++ b/ldpd/ldp_vty_exec.c @@ -1106,7 +1106,7 @@ show_lib_msg(struct vty *vty, struct imsg *imsg, struct show_params *params) if (params->lib.remote_label != NO_LABEL && params->lib.remote_label != rt->remote_label) return (0); - /* FALLTHROUGH */ + fallthrough; case IMSG_CTL_SHOW_LIB_RCVD: rt = imsg->data; diff --git a/ldpd/ldp_zebra.c b/ldpd/ldp_zebra.c index e3ace30582..df682a1347 100644 --- a/ldpd/ldp_zebra.c +++ b/ldpd/ldp_zebra.c @@ -22,8 +22,7 @@ #include "ldp_debug.h" static void ifp2kif(struct interface *, struct kif *); -static void ifc2kaddr(struct interface *, struct connected *, - struct kaddr *); +static void ifc2kaddr(struct interface *, struct connected *, struct kaddr *); static int ldp_zebra_send_mpls_labels(int, struct kroute *); static int ldp_router_id_update(ZAPI_CALLBACK_ARGS); static int ldp_interface_address_add(ZAPI_CALLBACK_ARGS); @@ -40,6 +39,7 @@ static int ldp_zebra_opaque_msg_handler(ZAPI_CALLBACK_ARGS); static void ldp_sync_zebra_init(void); static struct zclient *zclient; +extern struct zclient *zclient_sync; static bool zebra_registered = false; static void @@ -295,8 +295,7 @@ kmpw_add(struct zapi_pw *zpw) debug_zebra_out("pseudowire %s nexthop %s (add)", zpw->ifname, log_addr(zpw->af, (union ldpd_addr *)&zpw->nexthop)); - return zebra_send_pw(zclient, ZEBRA_PW_ADD, zpw) - == ZCLIENT_SEND_FAILURE; + return zebra_send_pw(zclient, ZEBRA_PW_ADD, zpw) == ZCLIENT_SEND_FAILURE; } int @@ -305,8 +304,7 @@ kmpw_del(struct zapi_pw *zpw) debug_zebra_out("pseudowire %s nexthop %s (del)", zpw->ifname, log_addr(zpw->af, (union ldpd_addr *)&zpw->nexthop)); - return zebra_send_pw(zclient, ZEBRA_PW_DELETE, zpw) - == ZCLIENT_SEND_FAILURE; + return zebra_send_pw(zclient, ZEBRA_PW_DELETE, zpw) == ZCLIENT_SEND_FAILURE; } int @@ -316,8 +314,7 @@ kmpw_set(struct zapi_pw *zpw) zpw->ifname, log_addr(zpw->af, (union ldpd_addr *)&zpw->nexthop), zpw->local_label, zpw->remote_label); - return zebra_send_pw(zclient, ZEBRA_PW_SET, zpw) - == ZCLIENT_SEND_FAILURE; + return zebra_send_pw(zclient, ZEBRA_PW_SET, zpw) == ZCLIENT_SEND_FAILURE; } int @@ -326,15 +323,13 @@ kmpw_unset(struct zapi_pw *zpw) debug_zebra_out("pseudowire %s nexthop %s (unset)", zpw->ifname, log_addr(zpw->af, (union ldpd_addr *)&zpw->nexthop)); - return zebra_send_pw(zclient, ZEBRA_PW_UNSET, zpw) - == ZCLIENT_SEND_FAILURE; + return zebra_send_pw(zclient, ZEBRA_PW_UNSET, zpw) == ZCLIENT_SEND_FAILURE; } void kif_redistribute(const char *ifname) { struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); - struct listnode *cnode; struct interface *ifp; struct connected *ifc; struct kif kif; @@ -347,7 +342,7 @@ kif_redistribute(const char *ifname) ifp2kif(ifp, &kif); main_imsg_compose_both(IMSG_IFSTATUS, &kif, sizeof(kif)); - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, ifc)) { + frr_each (if_connected, ifp->connected, ifc) { ifc2kaddr(ifp, ifc, &ka); main_imsg_compose_ldpe(IMSG_NEWADDR, 0, &ka, sizeof(ka)); } @@ -404,7 +399,6 @@ ldp_ifp_destroy(struct interface *ifp) static int ldp_interface_status_change(struct interface *ifp) { - struct listnode *node; struct connected *ifc; struct kif kif; struct kaddr ka; @@ -415,12 +409,12 @@ ldp_interface_status_change(struct interface *ifp) main_imsg_compose_both(IMSG_IFSTATUS, &kif, sizeof(kif)); if (if_is_operative(ifp)) { - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { + frr_each (if_connected, ifp->connected, ifc) { ifc2kaddr(ifp, ifc, &ka); main_imsg_compose_ldpe(IMSG_NEWADDR, 0, &ka, sizeof(ka)); } } else { - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { + frr_each (if_connected, ifp->connected, ifc) { ifc2kaddr(ifp, ifc, &ka); main_imsg_compose_ldpe(IMSG_DELADDR, 0, &ka, sizeof(ka)); } @@ -686,7 +680,10 @@ static zclient_handler *const ldp_handlers[] = { void ldp_zebra_init(struct event_loop *master) { - if_zapi_callbacks(ldp_ifp_create, ldp_ifp_up, ldp_ifp_down, ldp_ifp_destroy); + hook_register_prio(if_real, 0, ldp_ifp_create); + hook_register_prio(if_up, 0, ldp_ifp_up); + hook_register_prio(if_down, 0, ldp_ifp_down); + hook_register_prio(if_unreal, 0, ldp_ifp_destroy); /* Set default values. */ zclient = zclient_new(master, &zclient_options_default, ldp_handlers, @@ -708,4 +705,10 @@ ldp_zebra_destroy(void) zclient_stop(zclient); zclient_free(zclient); zclient = NULL; + + if (zclient_sync == NULL) + return; + zclient_stop(zclient_sync); + zclient_free(zclient_sync); + zclient_sync = NULL; } diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index 3c616d4a8c..a4d45d9c8d 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -9,6 +9,9 @@ */ #include <zebra.h> + +#include <signal.h> +#include <fcntl.h> #include <sys/wait.h> #include "ldpd.h" diff --git a/ldpd/ldpd.h b/ldpd/ldpd.h index 1fec5beafc..81c6ba3ccd 100644 --- a/ldpd/ldpd.h +++ b/ldpd/ldpd.h @@ -341,7 +341,7 @@ struct iface_ldp_sync { struct iface { RB_ENTRY(iface) entry; - char name[INTERFACE_NAMSIZ]; + char name[IFNAMSIZ]; ifindex_t ifindex; struct if_addr_head addr_list; struct in6_addr linklocal; @@ -447,7 +447,7 @@ struct ldp_entity_stats { struct l2vpn_if { RB_ENTRY(l2vpn_if) entry; struct l2vpn *l2vpn; - char ifname[INTERFACE_NAMSIZ]; + char ifname[IFNAMSIZ]; ifindex_t ifindex; int operative; uint8_t mac[ETH_ALEN]; @@ -464,7 +464,7 @@ struct l2vpn_pw { int af; union ldpd_addr addr; uint32_t pwid; - char ifname[INTERFACE_NAMSIZ]; + char ifname[IFNAMSIZ]; ifindex_t ifindex; bool enabled; uint32_t remote_group; @@ -496,7 +496,7 @@ struct l2vpn { int type; int pw_type; int mtu; - char br_ifname[INTERFACE_NAMSIZ]; + char br_ifname[IFNAMSIZ]; ifindex_t br_ifindex; struct l2vpn_if_head if_tree; struct l2vpn_pw_head pw_tree; @@ -618,7 +618,7 @@ struct kroute { }; struct kaddr { - char ifname[INTERFACE_NAMSIZ]; + char ifname[IFNAMSIZ]; ifindex_t ifindex; int af; union ldpd_addr addr; @@ -627,7 +627,7 @@ struct kaddr { }; struct kif { - char ifname[INTERFACE_NAMSIZ]; + char ifname[IFNAMSIZ]; ifindex_t ifindex; int flags; int operative; @@ -645,7 +645,7 @@ struct acl_check { /* control data structures */ struct ctl_iface { int af; - char name[INTERFACE_NAMSIZ]; + char name[IFNAMSIZ]; ifindex_t ifindex; int state; enum iface_type type; @@ -656,7 +656,7 @@ struct ctl_iface { }; struct ctl_disc_if { - char name[INTERFACE_NAMSIZ]; + char name[IFNAMSIZ]; int active_v4; int active_v6; int no_adj; @@ -672,7 +672,7 @@ struct ctl_adj { int af; struct in_addr id; enum hello_type type; - char ifname[INTERFACE_NAMSIZ]; + char ifname[IFNAMSIZ]; union ldpd_addr src_addr; uint16_t holdtime; uint16_t holdtime_remaining; @@ -712,7 +712,7 @@ struct ctl_rt { struct ctl_pw { uint16_t type; char l2vpn_name[L2VPN_NAME_LEN]; - char ifname[INTERFACE_NAMSIZ]; + char ifname[IFNAMSIZ]; uint32_t pwid; struct in_addr lsr_id; uint32_t local_label; @@ -728,7 +728,7 @@ struct ctl_pw { }; struct ctl_ldp_sync { - char name[INTERFACE_NAMSIZ]; + char name[IFNAMSIZ]; ifindex_t ifindex; bool in_sync; bool timer_running; diff --git a/ldpd/log.c b/ldpd/log.c index a9898a64f0..7c4d782dcf 100644 --- a/ldpd/log.c +++ b/ldpd/log.c @@ -35,13 +35,11 @@ vlog(int pri, const char *fmt, va_list ap) switch (ldpd_process) { case PROC_LDE_ENGINE: vsnprintfrr(buf, sizeof(buf), fmt, ap); - lde_imsg_compose_parent_sync(IMSG_LOG, pri, buf, - strlen(buf) + 1); + lde_imsg_compose_parent_sync(IMSG_LOG, pri, buf, strlen(buf) + 1); break; case PROC_LDP_ENGINE: vsnprintfrr(buf, sizeof(buf), fmt, ap); - ldpe_imsg_compose_parent_sync(IMSG_LOG, pri, buf, - strlen(buf) + 1); + ldpe_imsg_compose_parent_sync(IMSG_LOG, pri, buf, strlen(buf) + 1); break; case PROC_MAIN: vzlog(pri, fmt, ap); @@ -121,15 +119,13 @@ void fatal(const char *emsg) { if (emsg == NULL) - logit(LOG_CRIT, "fatal in %s: %s", log_procname, - strerror(errno)); + logit(LOG_CRIT, "fatal in %s: %s", log_procname, strerror(errno)); else if (errno) logit(LOG_CRIT, "fatal in %s: %s: %s", log_procname, emsg, strerror(errno)); else - logit(LOG_CRIT, "fatal in %s: %s", - log_procname, emsg); + logit(LOG_CRIT, "fatal in %s: %s", log_procname, emsg); exit(1); } diff --git a/ldpd/logmsg.c b/ldpd/logmsg.c index 4f1d950bb3..75f4293f0c 100644 --- a/ldpd/logmsg.c +++ b/ldpd/logmsg.c @@ -74,8 +74,7 @@ log_addr(int af, const union ldpd_addr *addr) switch (af) { case AF_INET: round = (round + 1) % NUM_LOGS; - if (inet_ntop(AF_INET, &addr->v4, buf[round], - sizeof(buf[round])) == NULL) + if (inet_ntop(AF_INET, &addr->v4, buf[round], sizeof(buf[round])) == NULL) return ("???"); return (buf[round]); case AF_INET6: @@ -166,8 +165,7 @@ log_hello_src(const struct hello_source *src) switch (src->type) { case HELLO_LINK: - snprintf(buf, sizeof(buf), "iface %s", - src->link.ia->iface->name); + snprintf(buf, sizeof(buf), "iface %s", src->link.ia->iface->name); break; case HELLO_TARGETED: snprintf(buf, sizeof(buf), "source %s", diff --git a/ldpd/neighbor.c b/ldpd/neighbor.c index 5209c55bb8..d40728b043 100644 --- a/ldpd/neighbor.c +++ b/ldpd/neighbor.c @@ -505,21 +505,12 @@ nbr_start_idtimer(struct nbr *nbr) { int secs; - secs = INIT_DELAY_TMR; - switch(nbr->idtimer_cnt) { - default: + if (nbr->idtimer_cnt > 2) { /* do not further increase the counter */ secs = MAX_DELAY_TMR; - break; - case 2: - secs *= 2; - /* FALLTHROUGH */ - case 1: - secs *= 2; - /* FALLTHROUGH */ - case 0: + } else { + secs = INIT_DELAY_TMR * (1 << nbr->idtimer_cnt); nbr->idtimer_cnt++; - break; } EVENT_OFF(nbr->initdelay_timer); diff --git a/ldpd/notification.c b/ldpd/notification.c index af5bb267d7..1709098d09 100644 --- a/ldpd/notification.c +++ b/ldpd/notification.c @@ -25,28 +25,28 @@ send_notification_full(struct tcp_conn *tcp, struct notify_msg *nm) /* calculate size */ size = LDP_HDR_SIZE + LDP_MSG_SIZE + STATUS_SIZE; - if (nm->flags & F_NOTIF_PW_STATUS) + if (CHECK_FLAG(nm->flags, F_NOTIF_PW_STATUS)) size += PW_STATUS_TLV_SIZE; - if (nm->flags & F_NOTIF_FEC) + if (CHECK_FLAG(nm->flags, F_NOTIF_FEC)) size += len_fec_tlv(&nm->fec); - if (nm->flags & F_NOTIF_RETURNED_TLVS) + if (CHECK_FLAG(nm->flags, F_NOTIF_RETURNED_TLVS)) size += TLV_HDR_SIZE * 2 + nm->rtlvs.length; if ((buf = ibuf_open(size)) == NULL) fatal(__func__); - err |= gen_ldp_hdr(buf, size); + SET_FLAG(err, gen_ldp_hdr(buf, size)); size -= LDP_HDR_SIZE; - err |= gen_msg_hdr(buf, MSG_TYPE_NOTIFICATION, size); - err |= gen_status_tlv(buf, nm->status_code, nm->msg_id, nm->msg_type); + SET_FLAG(err, gen_msg_hdr(buf, MSG_TYPE_NOTIFICATION, size)); + SET_FLAG(err, gen_status_tlv(buf, nm->status_code, nm->msg_id, nm->msg_type)); /* optional tlvs */ - if (nm->flags & F_NOTIF_PW_STATUS) - err |= gen_pw_status_tlv(buf, nm->pw_status); - if (nm->flags & F_NOTIF_FEC) - err |= gen_fec_tlv(buf, &nm->fec); - if (nm->flags & F_NOTIF_RETURNED_TLVS) - err |= gen_returned_tlvs(buf, nm->rtlvs.type, nm->rtlvs.length, - nm->rtlvs.data); + if (CHECK_FLAG(nm->flags, F_NOTIF_PW_STATUS)) + SET_FLAG(err, gen_pw_status_tlv(buf, nm->pw_status)); + if (CHECK_FLAG(nm->flags, F_NOTIF_FEC)) + SET_FLAG(err, gen_fec_tlv(buf, &nm->fec)); + if (CHECK_FLAG(nm->flags, F_NOTIF_RETURNED_TLVS)) + SET_FLAG(err, gen_returned_tlvs(buf, nm->rtlvs.type, nm->rtlvs.length, + nm->rtlvs.data)); if (err) { ibuf_free(buf); return; @@ -121,7 +121,7 @@ send_notification_rtlvs(struct nbr *nbr, uint32_t status_code, uint32_t msg_id, nm.rtlvs.type = tlv_type; nm.rtlvs.length = tlv_len; nm.rtlvs.data = tlv_data; - nm.flags |= F_NOTIF_RETURNED_TLVS; + SET_FLAG(nm.flags, F_NOTIF_RETURNED_TLVS); } send_notification_full(nbr->tcp, &nm); @@ -189,13 +189,12 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) break; case TLV_TYPE_PW_STATUS: if (tlv_len != 4) { - session_shutdown(nbr, S_BAD_TLV_LEN, - msg.id, msg.type); + session_shutdown(nbr, S_BAD_TLV_LEN, msg.id, msg.type); return (-1); } nm.pw_status = ntohl(*(uint32_t *)buf); - nm.flags |= F_NOTIF_PW_STATUS; + SET_FLAG(nm.flags, F_NOTIF_PW_STATUS); break; case TLV_TYPE_FEC: if ((tlen = tlv_decode_fec_elm(nbr, &msg, buf, @@ -203,12 +202,11 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) return (-1); /* allow only one fec element */ if (tlen != tlv_len) { - session_shutdown(nbr, S_BAD_TLV_VAL, - msg.id, msg.type); + session_shutdown(nbr, S_BAD_TLV_VAL, msg.id, msg.type); leconf->stats.bad_tlv_len++; return (-1); } - nm.flags |= F_NOTIF_FEC; + SET_FLAG(nm.flags, F_NOTIF_FEC); break; default: if (!(ntohs(tlv.type) & UNKNOWN_FLAG)) { @@ -226,9 +224,8 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) /* sanity checks */ switch (nm.status_code) { case S_PW_STATUS: - if (!(nm.flags & (F_NOTIF_PW_STATUS|F_NOTIF_FEC))) { - send_notification(nbr->tcp, S_MISS_MSG, - msg.id, msg.type); + if (!CHECK_FLAG(nm.flags, (F_NOTIF_PW_STATUS|F_NOTIF_FEC))) { + send_notification(nbr->tcp, S_MISS_MSG, msg.id, msg.type); return (-1); } @@ -236,20 +233,17 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) case MAP_TYPE_PWID: break; default: - send_notification(nbr->tcp, S_BAD_TLV_VAL, - msg.id, msg.type); + send_notification(nbr->tcp, S_BAD_TLV_VAL, msg.id, msg.type); return (-1); } break; case S_ENDOFLIB: - if (!(nm.flags & F_NOTIF_FEC)) { - send_notification(nbr->tcp, S_MISS_MSG, - msg.id, msg.type); + if (!CHECK_FLAG(nm.flags, F_NOTIF_FEC)) { + send_notification(nbr->tcp, S_MISS_MSG, msg.id, msg.type); return (-1); } if (nm.fec.type != MAP_TYPE_TYPED_WCARD) { - send_notification(nbr->tcp, S_BAD_TLV_VAL, - msg.id, msg.type); + send_notification(nbr->tcp, S_BAD_TLV_VAL, msg.id, msg.type); return (-1); } break; @@ -259,7 +253,7 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) log_msg_notification(0, nbr, &nm); - if (st.status_code & htonl(STATUS_FATAL)) { + if (CHECK_FLAG(st.status_code, htonl(STATUS_FATAL))) { if (nbr->state == NBR_STA_OPENSENT) nbr_start_idtimer(nbr); @@ -269,11 +263,9 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) * initialization, it SHOULD transmit a Shutdown message and * then close the transport connection". */ - if (nbr->state != NBR_STA_OPER && - nm.status_code == S_SHUTDOWN) { + if (nbr->state != NBR_STA_OPER && nm.status_code == S_SHUTDOWN) { leconf->stats.session_attempts++; - send_notification(nbr->tcp, S_SHUTDOWN, - msg.id, msg.type); + send_notification(nbr->tcp, S_SHUTDOWN, msg.id, msg.type); } leconf->stats.shutdown_rcv_notify++; @@ -287,8 +279,7 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len) switch (nm.status_code) { case S_PW_STATUS: case S_ENDOFLIB: - ldpe_imsg_compose_lde(IMSG_NOTIFICATION, nbr->peerid, 0, - &nm, sizeof(nm)); + ldpe_imsg_compose_lde(IMSG_NOTIFICATION, nbr->peerid, 0, &nm, sizeof(nm)); break; case S_NO_HELLO: leconf->stats.session_rejects_hello++; @@ -361,8 +352,8 @@ gen_returned_tlvs(struct ibuf *buf, uint16_t type, uint16_t length, tlv.length = htons(length); err = ibuf_add(buf, &rtlvs, sizeof(rtlvs)); - err |= ibuf_add(buf, &tlv, sizeof(tlv)); - err |= ibuf_add(buf, tlv_data, length); + SET_FLAG(err, ibuf_add(buf, &tlv, sizeof(tlv))); + SET_FLAG(err, ibuf_add(buf, tlv_data, length)); return (err); } @@ -378,9 +369,9 @@ log_msg_notification(int out, struct nbr *nbr, struct notify_msg *nm) debug_msg(out, "notification: lsr-id %pI4, status %s", &nbr->id, status_code_name(nm->status_code)); - if (nm->flags & F_NOTIF_FEC) + if (CHECK_FLAG(nm->flags, F_NOTIF_FEC)) debug_msg(out, "notification: fec %s", log_map(&nm->fec)); - if (nm->flags & F_NOTIF_PW_STATUS) + if (CHECK_FLAG(nm->flags, F_NOTIF_PW_STATUS)) debug_msg(out, "notification: pw-status %s", (nm->pw_status == PW_FORWARDING) ? "forwarding" : "not forwarding"); } diff --git a/ldpd/pfkey.c b/ldpd/pfkey.c index 4bea2e1904..ae771cae19 100644 --- a/ldpd/pfkey.c +++ b/ldpd/pfkey.c @@ -256,8 +256,7 @@ pfkey_read(int sd, struct sadb_msg *h) } /* XXX: Only one message can be outstanding. */ - if (hdr.sadb_msg_seq == sadb_msg_seq && - hdr.sadb_msg_pid == pid) { + if (hdr.sadb_msg_seq == sadb_msg_seq && hdr.sadb_msg_pid == pid) { if (h) *h = hdr; return (0); @@ -412,8 +411,7 @@ pfkey_establish(struct nbr *nbr, struct nbr_params *nbrp) { switch (nbr->auth.method) { case AUTH_MD5SIG: - strlcpy(nbr->auth.md5key, nbrp->auth.md5key, - sizeof(nbr->auth.md5key)); + strlcpy(nbr->auth.md5key, nbrp->auth.md5key, sizeof(nbr->auth.md5key)); return pfkey_md5sig_establish(nbr, nbrp); case AUTH_NONE: return 0; diff --git a/ldpd/socket.c b/ldpd/socket.c index ec6d8be3d5..71d5c21753 100644 --- a/ldpd/socket.c +++ b/ldpd/socket.c @@ -9,6 +9,7 @@ */ #include <zebra.h> +#include <fcntl.h> #include "ldpd.h" #include "ldpe.h" @@ -89,8 +90,7 @@ ldp_create_socket(int af, enum socket_type type) return (-1); } if (type == LDP_SOCKET_DISC) { - if (sock_set_ipv4_mcast_ttl(fd, - IP_DEFAULT_MULTICAST_TTL) == -1) { + if (sock_set_ipv4_mcast_ttl(fd, IP_DEFAULT_MULTICAST_TTL) == -1) { close(fd); return (-1); } @@ -141,7 +141,7 @@ ldp_create_socket(int af, enum socket_type type) close(fd); return (-1); } - if (!(ldpd_conf->ipv6.flags & F_LDPD_AF_NO_GTSM)) { + if (!CHECK_FLAG(ldpd_conf->ipv6.flags, F_LDPD_AF_NO_GTSM)) { /* ignore any possible error */ sock_set_ipv6_minhopcount(fd, 255); } @@ -171,8 +171,7 @@ ldp_create_socket(int af, enum socket_type type) #ifdef __OpenBSD__ opt = 1; - if (setsockopt(fd, IPPROTO_TCP, TCP_MD5SIG, &opt, - sizeof(opt)) == -1) { + if (setsockopt(fd, IPPROTO_TCP, TCP_MD5SIG, &opt, sizeof(opt)) == -1) { if (errno == ENOPROTOOPT) { /* system w/o md5sig */ log_warnx("md5sig not available, disabling"); sysdep.no_md5sig = 1; @@ -196,7 +195,7 @@ sock_set_nonblock(int fd) if ((flags = fcntl(fd, F_GETFL, 0)) == -1) fatal("fcntl F_GETFL"); - flags |= O_NONBLOCK; + SET_FLAG(flags, O_NONBLOCK); if (fcntl(fd, F_SETFL, flags) == -1) fatal("fcntl F_SETFL"); @@ -210,7 +209,7 @@ sock_set_cloexec(int fd) if ((flags = fcntl(fd, F_GETFD, 0)) == -1) fatal("fcntl F_GETFD"); - flags |= FD_CLOEXEC; + SET_FLAG(flags, FD_CLOEXEC); if (fcntl(fd, F_SETFD, flags) == -1) fatal("fcntl F_SETFD"); @@ -222,16 +221,14 @@ sock_set_recvbuf(int fd) int bsize; bsize = 65535; - while (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &bsize, - sizeof(bsize)) == -1) + while (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &bsize, sizeof(bsize)) == -1) bsize /= 2; } int sock_set_reuse(int fd, int enable) { - if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &enable, - sizeof(int)) < 0) { + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) { log_warn("%s: error setting SO_REUSEADDR", __func__); return (-1); } @@ -244,8 +241,7 @@ sock_set_bindany(int fd, int enable) { #ifdef HAVE_SO_BINDANY frr_with_privs(&ldpd_privs) { - if (setsockopt(fd, SOL_SOCKET, SO_BINDANY, &enable, - sizeof(int)) < 0) { + if (setsockopt(fd, SOL_SOCKET, SO_BINDANY, &enable, sizeof(int)) < 0) { log_warn("%s: error setting SO_BINDANY", __func__); return (-1); } @@ -259,8 +255,7 @@ sock_set_bindany(int fd, int enable) return (0); #elif defined(IP_BINDANY) frr_with_privs(&ldpd_privs) { - if (setsockopt(fd, IPPROTO_IP, IP_BINDANY, &enable, sizeof(int)) - < 0) { + if (setsockopt(fd, IPPROTO_IP, IP_BINDANY, &enable, sizeof(int)) < 0) { log_warn("%s: error setting IP_BINDANY", __func__); return (-1); } @@ -343,10 +338,8 @@ sock_set_ipv4_ucast_ttl(int fd, int ttl) int sock_set_ipv4_mcast_ttl(int fd, uint8_t ttl) { - if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, - (char *)&ttl, sizeof(ttl)) < 0) { - log_warn("%s: error setting IP_MULTICAST_TTL to %d", - __func__, ttl); + if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, (char *)&ttl, sizeof(ttl)) < 0) { + log_warn("%s: error setting IP_MULTICAST_TTL to %d", __func__, ttl); return (-1); } @@ -358,8 +351,7 @@ sock_set_ipv4_mcast_ttl(int fd, uint8_t ttl) int sock_set_ipv4_pktinfo(int fd, int enable) { - if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &enable, - sizeof(enable)) < 0) { + if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &enable, sizeof(enable)) < 0) { log_warn("%s: error setting IP_PKTINFO", __func__); return (-1); } @@ -370,8 +362,7 @@ sock_set_ipv4_pktinfo(int fd, int enable) int sock_set_ipv4_recvdstaddr(int fd, int enable) { - if (setsockopt(fd, IPPROTO_IP, IP_RECVDSTADDR, &enable, - sizeof(enable)) < 0) { + if (setsockopt(fd, IPPROTO_IP, IP_RECVDSTADDR, &enable, sizeof(enable)) < 0) { log_warn("%s: error setting IP_RECVDSTADDR", __func__); return (-1); } @@ -409,8 +400,7 @@ sock_set_ipv4_mcast_loop(int fd) int sock_set_ipv6_dscp(int fd, int dscp) { - if (setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, &dscp, - sizeof(dscp)) < 0) { + if (setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, &dscp, sizeof(dscp)) < 0) { log_warn("%s: error setting IPV6_TCLASS", __func__); return (-1); } @@ -421,8 +411,7 @@ sock_set_ipv6_dscp(int fd, int dscp) int sock_set_ipv6_pktinfo(int fd, int enable) { - if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &enable, - sizeof(enable)) < 0) { + if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &enable, sizeof(enable)) < 0) { log_warn("%s: error setting IPV6_RECVPKTINFO", __func__); return (-1); } diff --git a/lib/affinitymap_cli.c b/lib/affinitymap_cli.c index a2d5e8eccf..d417ae1951 100644 --- a/lib/affinitymap_cli.c +++ b/lib/affinitymap_cli.c @@ -93,8 +93,8 @@ void cli_show_affinity_map(struct vty *vty, const struct lyd_node *dnode, bool show_defaults __attribute__((__unused__))) { vty_out(vty, "affinity-map %s bit-position %u\n", - yang_dnode_get_string(dnode, "./name"), - yang_dnode_get_uint16(dnode, "./value")); + yang_dnode_get_string(dnode, "name"), + yang_dnode_get_uint16(dnode, "value")); } /* Initialization of affinity map vector. */ diff --git a/lib/agentx.c b/lib/agentx.c index 45f14c2703..70ee6753ff 100644 --- a/lib/agentx.c +++ b/lib/agentx.c @@ -4,12 +4,14 @@ */ #include <zebra.h> +#include <fcntl.h> #ifdef SNMP_AGENTX #include <net-snmp/net-snmp-config.h> #include <net-snmp/net-snmp-includes.h> #include <net-snmp/agent/net-snmp-agent-includes.h> #include <net-snmp/agent/snmp_vars.h> +#include <net-snmp/library/large_fd_set.h> #include "command.h" #include "smux.h" @@ -43,7 +45,7 @@ static void agentx_timeout(struct event *t) static void agentx_read(struct event *t) { - fd_set fds; + netsnmp_large_fd_set lfds; int flags, new_flags = 0; int nonblock = false; struct listnode *ln = EVENT_ARG(t); @@ -68,9 +70,9 @@ static void agentx_read(struct event *t) flog_err(EC_LIB_SYSTEM_CALL, "Failed to set snmp fd non blocking: %s(%d)", strerror(errno), errno); - FD_ZERO(&fds); - FD_SET(EVENT_FD(t), &fds); - snmp_read(&fds); + netsnmp_large_fd_set_init(&lfds, FD_SETSIZE); + netsnmp_large_fd_setfd(t->u.fd, &lfds); + snmp_read2(&lfds); /* Reset the flag */ if (!nonblock) { @@ -85,6 +87,7 @@ static void agentx_read(struct event *t) netsnmp_check_outstanding_agent_requests(); agentx_events_update(); + netsnmp_large_fd_set_cleanup(&lfds); } static void agentx_events_update(void) @@ -92,15 +95,15 @@ static void agentx_events_update(void) int maxfd = 0; int block = 1; struct timeval timeout = {.tv_sec = 0, .tv_usec = 0}; - fd_set fds; + netsnmp_large_fd_set lfds; struct listnode *ln; struct event **thr; int fd, thr_fd; event_cancel(&timeout_thr); - FD_ZERO(&fds); - snmp_select_info(&maxfd, &fds, &timeout, &block); + netsnmp_large_fd_set_init(&lfds, FD_SETSIZE); + snmp_select_info2(&maxfd, &lfds, &timeout, &block); if (!block) { event_add_timer_tv(agentx_tm, agentx_timeout, NULL, &timeout, @@ -118,7 +121,7 @@ static void agentx_events_update(void) /* caught up */ if (thr_fd == fd) { struct listnode *nextln = listnextnode(ln); - if (!FD_ISSET(fd, &fds)) { + if (!netsnmp_large_fd_is_set(fd, &lfds)) { event_cancel(thr); XFREE(MTYPE_TMP, thr); list_delete_node(events, ln); @@ -128,7 +131,7 @@ static void agentx_events_update(void) thr_fd = thr ? EVENT_FD(*thr) : -1; } /* need listener, but haven't hit one where it would be */ - else if (FD_ISSET(fd, &fds)) { + else if (netsnmp_large_fd_is_set(fd, &lfds)) { struct listnode *newln; thr = XCALLOC(MTYPE_TMP, sizeof(struct event *)); @@ -147,6 +150,7 @@ static void agentx_events_update(void) list_delete_node(events, ln); ln = nextln; } + netsnmp_large_fd_set_cleanup(&lfds); } /* AgentX node. */ diff --git a/lib/asn.h b/lib/asn.h index 81a42c658d..a7394fa52b 100644 --- a/lib/asn.h +++ b/lib/asn.h @@ -66,10 +66,10 @@ extern char *asn_asn2string(const as_t *as, char *buf, size_t len, ((mode == ASNOTATION_DOT) ? "%pASD" : \ ((mode == ASNOTATION_DOTPLUS) ? "%pASE" : \ "%pASP")) -#define ASN_FORMAT_SPACE(mode) \ - ((mode == ASNOTATION_DOT) ? "%10pASD" : \ - ((mode == ASNOTATION_DOTPLUS) ? "%10pASE" : \ - "%10pASP")) +#define ASN_FORMAT_SPACE(mode) \ + ((mode == ASNOTATION_DOT) \ + ? "%11pASD" \ + : ((mode == ASNOTATION_DOTPLUS) ? "%11pASE" : "%11pASP")) /* for test */ extern void asn_relax_as_zero(bool relax); diff --git a/lib/base64.c b/lib/base64.c index 1507b0252b..ee2e838c01 100644 --- a/lib/base64.c +++ b/lib/base64.c @@ -9,6 +9,7 @@ #endif #include "base64.h" +#include "compiler.h" static const int CHARS_PER_LINE = 72; static const char *ENCODING = @@ -41,6 +42,7 @@ int base64_encode_block(const char *plaintext_in, int length_in, char *code_out, switch (state_in->step) { while (1) { + fallthrough; case step_A: if (plainchar == plaintextend) { state_in->result = result; @@ -51,7 +53,7 @@ int base64_encode_block(const char *plaintext_in, int length_in, char *code_out, result = (fragment & 0x0fc) >> 2; *codechar++ = base64_encode_value(result); result = (fragment & 0x003) << 4; - /* fall through */ + fallthrough; case step_B: if (plainchar == plaintextend) { state_in->result = result; @@ -62,7 +64,7 @@ int base64_encode_block(const char *plaintext_in, int length_in, char *code_out, result |= (fragment & 0x0f0) >> 4; *codechar++ = base64_encode_value(result); result = (fragment & 0x00f) << 2; - /* fall through */ + fallthrough; case step_C: if (plainchar == plaintextend) { state_in->result = result; @@ -146,6 +148,7 @@ int base64_decode_block(const char *code_in, int length_in, char *plaintext_out, switch (state_in->step) { while (1) { + fallthrough; case step_a: do { if (codec == code_in+length_in) { @@ -156,7 +159,7 @@ int base64_decode_block(const char *code_in, int length_in, char *plaintext_out, fragmt = base64_decode_value(*codec++); } while (fragmt < 0); *plainc = (fragmt & 0x03f) << 2; - /* fall through */ + fallthrough; case step_b: do { if (codec == code_in+length_in) { @@ -168,7 +171,7 @@ int base64_decode_block(const char *code_in, int length_in, char *plaintext_out, } while (fragmt < 0); *plainc++ |= (fragmt & 0x030) >> 4; *plainc = (fragmt & 0x00f) << 4; - /* fall through */ + fallthrough; case step_c: do { if (codec == code_in+length_in) { @@ -180,7 +183,7 @@ int base64_decode_block(const char *code_in, int length_in, char *plaintext_out, } while (fragmt < 0); *plainc++ |= (fragmt & 0x03c) >> 2; *plainc = (fragmt & 0x003) << 6; - /* fall through */ + fallthrough; case step_d: do { if (codec == code_in+length_in) { diff --git a/lib/bfd.c b/lib/bfd.c index cc6d09a60f..2222bb9547 100644 --- a/lib/bfd.c +++ b/lib/bfd.c @@ -541,7 +541,7 @@ static void _bfd_sess_remove(struct bfd_session_params *bsp) /* Send request to remove any session. */ bsp->lastev = BSE_UNINSTALL; - event_execute(bsglobal.tm, _bfd_sess_send, bsp, 0); + event_execute(bsglobal.tm, _bfd_sess_send, bsp, 0, NULL); } void bfd_sess_free(struct bfd_session_params **bsp) @@ -894,7 +894,7 @@ int zclient_bfd_session_replay(ZAPI_CALLBACK_ARGS) /* Ask for installation. */ bsp->lastev = BSE_INSTALL; - event_execute(bsglobal.tm, _bfd_sess_send, bsp, 0); + event_execute(bsglobal.tm, _bfd_sess_send, bsp, 0, NULL); } return 0; @@ -1282,7 +1282,6 @@ static bool bfd_source_cache_update(struct bfd_source_cache *source, const struct zapi_nexthop *nh = &route->nexthops[nh_index]; const struct interface *interface; const struct connected *connected; - const struct listnode *node; interface = if_lookup_by_index(nh->ifindex, nh->vrf_id); if (interface == NULL) { @@ -1291,8 +1290,7 @@ static bool bfd_source_cache_update(struct bfd_source_cache *source, continue; } - for (ALL_LIST_ELEMENTS_RO(interface->connected, node, - connected)) { + frr_each (if_connected_const, interface->connected, connected) { if (source->address.family != connected->address->family) continue; diff --git a/lib/bitfield.h b/lib/bitfield.h index c4e2cbe4e1..cc8c311416 100644 --- a/lib/bitfield.h +++ b/lib/bitfield.h @@ -114,7 +114,8 @@ DECLARE_MTYPE(BITFIELD); (v).n += ((v).data[w] == WORD_MAX); \ if ((v).n == (v).m) { \ (v).m = (v).m + 1; \ - (v).data = realloc((v).data, (v).m * sizeof(word_t)); \ + (v).data = XREALLOC(MTYPE_BITFIELD, (v).data, \ + (v).m * sizeof(word_t)); \ } \ } while (0) @@ -188,7 +189,8 @@ bf_find_next_clear_bit_wrap(bitfield_t *v, word_t start_index, word_t max_index) * will allocate additional space. */ v->m += 1; - v->data = (word_t *)realloc(v->data, v->m * sizeof(word_t)); + v->data = (word_t *)XREALLOC(MTYPE_BITFIELD, v->data, + v->m * sizeof(word_t)); v->data[v->m - 1] = 0; return v->m * WORD_SIZE; } diff --git a/lib/buffer.h b/lib/buffer.h index 5d98c31dbc..a0b82d2121 100644 --- a/lib/buffer.h +++ b/lib/buffer.h @@ -14,21 +14,21 @@ extern "C" { /* Create a new buffer. Memory will be allocated in chunks of the given size. If the argument is 0, the library will supply a reasonable default size suitable for buffering socket I/O. */ -extern struct buffer *buffer_new(size_t); +extern struct buffer *buffer_new(size_t size); /* Free all data in the buffer. */ -extern void buffer_reset(struct buffer *); +extern void buffer_reset(struct buffer *b); /* This function first calls buffer_reset to release all buffered data. Then it frees the struct buffer itself. */ -extern void buffer_free(struct buffer *); +extern void buffer_free(struct buffer *b); /* Add the given data to the end of the buffer. */ -extern void buffer_put(struct buffer *, const void *, size_t); +extern void buffer_put(struct buffer *b, const void *p, size_t size); /* Add a single character to the end of the buffer. */ -extern void buffer_putc(struct buffer *, uint8_t); +extern void buffer_putc(struct buffer *b, uint8_t c); /* Add a NUL-terminated string to the end of the buffer. */ -extern void buffer_putstr(struct buffer *, const char *); +extern void buffer_putstr(struct buffer *b, const char *str); /* Add given data, inline-expanding \n to \r\n */ extern void buffer_put_crlf(struct buffer *b, const void *p, size_t size); @@ -36,10 +36,10 @@ extern void buffer_put_crlf(struct buffer *b, const void *p, size_t size); single NUL-terminated string allocated using XMALLOC(MTYPE_TMP). Note that this function does not alter the state of the buffer, so the data is still inside waiting to be flushed. */ -char *buffer_getstr(struct buffer *); +char *buffer_getstr(struct buffer *b); /* Returns 1 if there is no pending data in the buffer. Otherwise returns 0. */ -int buffer_empty(struct buffer *); +int buffer_empty(struct buffer *b); typedef enum { /* An I/O error occurred. The buffer should be destroyed and the @@ -59,12 +59,12 @@ typedef enum { /* Try to write this data to the file descriptor. Any data that cannot be written immediately is added to the buffer queue. */ -extern buffer_status_t buffer_write(struct buffer *, int fd, const void *, - size_t); +extern buffer_status_t buffer_write(struct buffer *b, int fd, const void *p, + size_t size); /* This function attempts to flush some (but perhaps not all) of the queued data to the given file descriptor. */ -extern buffer_status_t buffer_flush_available(struct buffer *, int fd); +extern buffer_status_t buffer_flush_available(struct buffer *b, int fd); /* The following 2 functions (buffer_flush_all and buffer_flush_window) are for use in lib/vty.c only. They should not be used elsewhere. */ @@ -72,7 +72,7 @@ extern buffer_status_t buffer_flush_available(struct buffer *, int fd); /* Call buffer_flush_available repeatedly until either all data has been flushed, or an I/O error has been encountered, or the operation would block. */ -extern buffer_status_t buffer_flush_all(struct buffer *, int fd); +extern buffer_status_t buffer_flush_all(struct buffer *b, int fd); /* Attempt to write enough data to the given fd to fill a window of the given width and height (and remove the data written from the buffer). @@ -85,7 +85,7 @@ extern buffer_status_t buffer_flush_all(struct buffer *, int fd); to return -1 (because the logic for handling the erase and more features is too complicated to retry the write later). */ -extern buffer_status_t buffer_flush_window(struct buffer *, int fd, int width, +extern buffer_status_t buffer_flush_window(struct buffer *b, int fd, int width, int height, int erase, int no_more); #ifdef __cplusplus diff --git a/lib/command.c b/lib/command.c index e92251160f..becba8452b 100644 --- a/lib/command.c +++ b/lib/command.c @@ -10,6 +10,10 @@ */ #include <zebra.h> +#include <sys/utsname.h> +#include <sys/stat.h> +#include <fcntl.h> + #include <lib/version.h> #include "command.h" @@ -477,33 +481,18 @@ static int config_write_host(struct vty *vty) } log_config_write(vty); - /* print disable always, but enable only if default is flipped - * => prep for future removal of compile-time knob - */ if (!cputime_enabled) vty_out(vty, "no service cputime-stats\n"); -#ifdef EXCLUDE_CPU_TIME - else - vty_out(vty, "service cputime-stats\n"); -#endif if (!cputime_threshold) vty_out(vty, "no service cputime-warning\n"); -#if defined(CONSUMED_TIME_CHECK) && CONSUMED_TIME_CHECK != 5000000 - else /* again, always print non-default */ -#else - else if (cputime_threshold != 5000000) -#endif + else if (cputime_threshold != CONSUMED_TIME_CHECK) vty_out(vty, "service cputime-warning %lu\n", cputime_threshold / 1000); if (!walltime_threshold) vty_out(vty, "no service walltime-warning\n"); -#if defined(CONSUMED_TIME_CHECK) && CONSUMED_TIME_CHECK != 5000000 - else /* again, always print non-default */ -#else - else if (walltime_threshold != 5000000) -#endif + else if (walltime_threshold != CONSUMED_TIME_CHECK) vty_out(vty, "service walltime-warning %lu\n", walltime_threshold / 1000); @@ -735,9 +724,13 @@ char *cmd_variable_comp2str(vector comps, unsigned short cols) char *item = vector_slot(comps, j); itemlen = strlen(item); - if (cs + itemlen + AUTOCOMP_INDENT + 3 >= bsz) - buf = XREALLOC(MTYPE_TMP, buf, (bsz *= 2)); + size_t next_sz = cs + itemlen + AUTOCOMP_INDENT + 3; + if (next_sz > bsz) { + /* Make sure the buf size is large enough */ + bsz = next_sz; + buf = XREALLOC(MTYPE_TMP, buf, bsz); + } if (lc + itemlen + 1 >= cols) { cs += snprintf(&buf[cs], bsz - cs, "\n%*s", AUTOCOMP_INDENT, ""); @@ -899,8 +892,7 @@ enum node_type node_parent(enum node_type node) } /* Execute command by argument vline vector. */ -static int cmd_execute_command_real(vector vline, enum cmd_filter_type filter, - struct vty *vty, +static int cmd_execute_command_real(vector vline, struct vty *vty, const struct cmd_element **cmd, unsigned int up_level) { @@ -1037,8 +1029,7 @@ int cmd_execute_command(vector vline, struct vty *vty, vector_set_index(shifted_vline, index - 1, vector_lookup(vline, index)); - ret = cmd_execute_command_real(shifted_vline, FILTER_RELAXED, - vty, cmd, 0); + ret = cmd_execute_command_real(shifted_vline, vty, cmd, 0); vector_free(shifted_vline); vty->node = onode; @@ -1047,7 +1038,7 @@ int cmd_execute_command(vector vline, struct vty *vty, } saved_ret = ret = - cmd_execute_command_real(vline, FILTER_RELAXED, vty, cmd, 0); + cmd_execute_command_real(vline, vty, cmd, 0); if (vtysh) return saved_ret; @@ -1065,8 +1056,7 @@ int cmd_execute_command(vector vline, struct vty *vty, if (vty->xpath_index > 0 && !cnode->no_xpath) vty->xpath_index--; - ret = cmd_execute_command_real(vline, FILTER_RELAXED, - vty, cmd, 0); + ret = cmd_execute_command_real(vline, vty, cmd, 0); if (ret == CMD_SUCCESS || ret == CMD_WARNING || ret == CMD_ERR_AMBIGUOUS || ret == CMD_ERR_INCOMPLETE || ret == CMD_NOT_MY_INSTANCE @@ -1098,7 +1088,7 @@ int cmd_execute_command(vector vline, struct vty *vty, int cmd_execute_command_strict(vector vline, struct vty *vty, const struct cmd_element **cmd) { - return cmd_execute_command_real(vline, FILTER_STRICT, vty, cmd, 0); + return cmd_execute_command_real(vline, vty, cmd, 0); } /* @@ -1270,8 +1260,7 @@ int command_config_read_one_line(struct vty *vty, && ret != CMD_ERR_AMBIGUOUS && ret != CMD_ERR_INCOMPLETE && ret != CMD_NOT_MY_INSTANCE && ret != CMD_WARNING_CONFIG_FAILED && ret != CMD_NO_LEVEL_UP) - ret = cmd_execute_command_real(vline, FILTER_STRICT, vty, cmd, - ++up_level); + ret = cmd_execute_command_real(vline, vty, cmd, ++up_level); if (ret == CMD_NO_LEVEL_UP) ret = CMD_ERR_NO_MATCH; @@ -1329,11 +1318,12 @@ int config_from_file(struct vty *vty, FILE *fp, unsigned int *line_num) /* Configuration from terminal */ DEFUN (config_terminal, config_terminal_cmd, - "configure [terminal]", + "configure [terminal [file-lock]]", "Configuration from vty interface\n" - "Configuration terminal\n") + "Configuration terminal\n" + "Configuration with locked datastores\n") { - return vty_config_enter(vty, false, false); + return vty_config_enter(vty, false, false, argc == 3); } /* Enable command */ diff --git a/lib/command.h b/lib/command.h index 39fbfa661a..b6419e6fec 100644 --- a/lib/command.h +++ b/lib/command.h @@ -82,12 +82,16 @@ enum node_type { AUTH_ENABLE_NODE, /* Authentication mode for change enable. */ ENABLE_NODE, /* Enable node. */ CONFIG_NODE, /* Config node. Default mode of config file. */ + PREFIX_NODE, /* ip prefix-list node. */ + PREFIX_IPV6_NODE, /* ipv6 prefix-list node. */ DEBUG_NODE, /* Debug node. */ VRF_DEBUG_NODE, /* Vrf Debug node. */ NORTHBOUND_DEBUG_NODE, /* Northbound Debug node. */ DEBUG_VNC_NODE, /* Debug VNC node. */ RMAP_DEBUG_NODE, /* Route-map debug node */ RESOLVER_DEBUG_NODE, /* Resolver debug node */ + MGMT_BE_DEBUG_NODE, /* mgmtd backend-client debug node */ + MGMT_FE_DEBUG_NODE, /* mgmtd frontend-client debug node */ AAA_NODE, /* AAA node. */ EXTLOG_NODE, /* RFC5424 & co. extended syslog */ KEYCHAIN_NODE, /* Key-chain node. */ @@ -131,10 +135,8 @@ enum node_type { ISIS_NODE, /* ISIS protocol mode */ ISIS_FLEX_ALGO_NODE, /* ISIS Flex Algo mode */ ACCESS_NODE, /* Access list node. */ - PREFIX_NODE, /* Prefix list node. */ ACCESS_IPV6_NODE, /* Access list node. */ ACCESS_MAC_NODE, /* MAC access list node*/ - PREFIX_IPV6_NODE, /* Prefix list node. */ AS_LIST_NODE, /* AS list node. */ COMMUNITY_LIST_NODE, /* Community list node. */ COMMUNITY_ALIAS_NODE, /* Community alias node. */ @@ -158,6 +160,7 @@ enum node_type { SRV6_NODE, /* SRv6 node */ SRV6_LOCS_NODE, /* SRv6 locators node */ SRV6_LOC_NODE, /* SRv6 locator node */ + SRV6_ENCAP_NODE, /* SRv6 encapsulation node */ VTY_NODE, /* Vty node. */ FPM_NODE, /* Dataplane FPM node. */ LINK_PARAMS_NODE, /* Link-parameters node */ @@ -172,6 +175,9 @@ enum node_type { OPENFABRIC_NODE, /* OpenFabric router configuration node */ VRRP_NODE, /* VRRP node */ BMP_NODE, /* BMP config under router bgp */ + ISIS_SRV6_NODE, /* ISIS SRv6 node */ + ISIS_SRV6_NODE_MSD_NODE, /* ISIS SRv6 Node MSDs node */ + MGMTD_NODE, /* MGMTD node. */ NODE_TYPE_MAX, /* maximum */ }; /* clang-format on */ @@ -416,6 +422,10 @@ struct cmd_node { #define COMMUNITY_AANN_STR "Community number where AA and NN are (0-65535)\n" #define COMMUNITY_VAL_STR \ "Community number in AA:NN format (where AA and NN are (0-65535)) or local-AS|no-advertise|no-export|internet|graceful-shutdown|accept-own-nexthop|accept-own|route-filter-translated-v4|route-filter-v4|route-filter-translated-v6|route-filter-v6|llgr-stale|no-llgr|blackhole|no-peer or additive\n" +#define EXTCOMM_LIST_CMD_STR "<(1-99)|(100-500)|EXTCOMMUNITY_LIST_NAME>" +#define EXTCOMM_STD_LIST_NUM_STR "Extended community-list number (standard)\n" +#define EXTCOMM_EXP_LIST_NUM_STR "Extended community-list number (expanded)\n" +#define EXTCOMM_LIST_NAME_STR "Extended community-list name\n" #define MPLS_TE_STR "MPLS-TE specific commands\n" #define LINK_PARAMS_STR "Configure interface link parameters\n" #define OSPF_RI_STR "OSPF Router Information specific commands\n" diff --git a/lib/command_match.c b/lib/command_match.c index ff3c48fc31..97e6aeb469 100644 --- a/lib/command_match.c +++ b/lib/command_match.c @@ -405,10 +405,10 @@ enum matcher_rv command_complete(struct graph *graph, vector vline, listnode_add(next, newstack); break; case partly_match: - trace_matcher("trivial_match\n"); + trace_matcher("partly_match\n"); if (exact_match_exists && !last_token) break; - /* fallthru */ + fallthrough; case exact_match: trace_matcher("exact_match\n"); if (last_token) { @@ -566,9 +566,9 @@ static int score_precedence(enum cmd_token_type type) case IPV6_PREFIX_TKN: case MAC_TKN: case MAC_PREFIX_TKN: - case ASNUM_TKN: case RANGE_TKN: return 2; + case ASNUM_TKN: case WORD_TKN: return 3; case VARIABLE_TKN: diff --git a/lib/command_match.h b/lib/command_match.h index db2a8535e0..3e7a549e1d 100644 --- a/lib/command_match.h +++ b/lib/command_match.h @@ -17,11 +17,6 @@ extern "C" { #endif -/* These definitions exist in command.c in the current engine but should be - * relocated here in the new engine - */ -enum cmd_filter_type { FILTER_RELAXED, FILTER_STRICT }; - /* matcher result value */ enum matcher_rv { MATCHER_NO_MATCH, diff --git a/lib/compiler.h b/lib/compiler.h index 29fcfbefbf..617b0c265b 100644 --- a/lib/compiler.h +++ b/lib/compiler.h @@ -33,7 +33,7 @@ extern "C" { # define _RET_NONNULL , returns_nonnull #endif #if __has_attribute(fallthrough) -# define _FALLTHROUGH __attribute__((fallthrough)); +# define fallthrough __attribute__((fallthrough)); #endif # define _CONSTRUCTOR(x) constructor(x) # define _DEPRECATED(x) deprecated(x) @@ -57,7 +57,7 @@ extern "C" { # define __has_attribute(x) 0 #endif #if __GNUC__ >= 7 -# define _FALLTHROUGH __attribute__((fallthrough)); +# define fallthrough __attribute__((fallthrough)); #endif #endif @@ -112,8 +112,8 @@ extern "C" { #ifndef _ALLOC_SIZE # define _ALLOC_SIZE(x) #endif -#ifndef _FALLTHROUGH -#define _FALLTHROUGH +#ifndef fallthrough +#define fallthrough #endif #ifndef _DEPRECATED #define _DEPRECATED(x) deprecated @@ -122,6 +122,14 @@ extern "C" { #define assume(x) #endif +#ifdef __COVERITY__ +/* __coverity_panic__() is named a bit poorly, it's essentially the same as + * __builtin_unreachable(). Used to eliminate false positives. + */ +#undef assume +#define assume(x) do { if (!(x)) __coverity_panic__(); } while (0) +#endif + /* for helper functions defined inside macros */ #define macro_inline static inline __attribute__((unused)) #define macro_pure static inline __attribute__((unused, pure)) @@ -416,10 +424,10 @@ _Static_assert(sizeof(_uint64_t) == 8 && sizeof(_int64_t) == 8, * type.) */ #ifndef __cplusplus -#define prefixtype(uname, typename, fieldname) typename *fieldname; +#define uniontype(uname, typename, fieldname) typename *fieldname; #define TRANSPARENT_UNION __attribute__((transparent_union)) #else -#define prefixtype(uname, typename, fieldname) \ +#define uniontype(uname, typename, fieldname) \ typename *fieldname; \ uname(typename *x) \ { \ diff --git a/lib/cspf.c b/lib/cspf.c index 6a0fb7f63c..c17d8e0929 100644 --- a/lib/cspf.c +++ b/lib/cspf.c @@ -331,6 +331,8 @@ void cspf_clean(struct cspf *algo) if (processed_count(&algo->processed)) { frr_each_safe (processed, &algo->processed, path) { processed_del(&algo->processed, path); + if (path == algo->pdst) + algo->pdst = NULL; cpath_del(path); } } @@ -343,6 +345,9 @@ void cspf_clean(struct cspf *algo) } } + if (algo->pdst) + cpath_del(algo->pdst); + memset(&algo->csts, 0, sizeof(struct constraints)); algo->path = NULL; algo->pdst = NULL; diff --git a/lib/darr.c b/lib/darr.c new file mode 100644 index 0000000000..f7a64fc394 --- /dev/null +++ b/lib/darr.c @@ -0,0 +1,156 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * June 23 2023, Christian Hopps <chopps@labn.net> + * + * Copyright (c) 2023, LabN Consulting, L.L.C. + * + */ +#include <zebra.h> +#include "darr.h" +#include "memory.h" + +DEFINE_MTYPE(LIB, DARR, "Dynamic Array"); +DEFINE_MTYPE(LIB, DARR_STR, "Dynamic Array String"); + +static uint _msb(uint count) +{ + uint bit = 0; + int msb = 0; + + while (count) { + if (count & 1) + msb = bit; + count >>= 1; + bit += 1; + } + return msb; +} + +static uint darr_next_count(uint count, size_t esize) +{ + uint ncount; + + if (esize > sizeof(long long) && count == 1) + /* treat like a pointer */ + ncount = 1; + else { + uint msb = _msb(count); + + ncount = 1ull << msb; + /* if the users count wasn't a pow2 make it the next pow2. */ + if (ncount != count) { + assert(ncount < count); + ncount <<= 1; + if (esize < sizeof(long long) && ncount < 8) + ncount = 8; + } + } + return ncount; +} + +static size_t darr_size(uint count, size_t esize) +{ + return count * esize + sizeof(struct darr_metadata); +} + +char *__darr_in_vsprintf(char **sp, bool concat, const char *fmt, va_list ap) +{ + size_t inlen = concat ? darr_strlen(*sp) : 0; + size_t capcount = strlen(fmt) + MIN(inlen + 64, 128); + ssize_t len; + + darr_ensure_cap(*sp, capcount); + + if (!concat) + darr_reset(*sp); + + /* code below counts on having a NUL terminated string */ + if (darr_len(*sp) == 0) + *darr_append(*sp) = 0; +again: + len = vsnprintf(darr_last(*sp), darr_avail(*sp), fmt, ap); + if (len < 0) + darr_in_strcat(*sp, fmt); + else if ((size_t)len < darr_avail(*sp)) + _darr_len(*sp) += len; + else { + darr_ensure_cap(*sp, darr_len(*sp) + (size_t)len); + goto again; + } + return *sp; +} + +char *__darr_in_sprintf(char **sp, bool concat, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + (void)__darr_in_vsprintf(sp, concat, fmt, ap); + va_end(ap); + return *sp; +} + + +void *__darr_resize(void *a, uint count, size_t esize, struct memtype *mtype) +{ + uint ncount = darr_next_count(count, esize); + size_t osz = (a == NULL) ? 0 : darr_size(darr_cap(a), esize); + size_t sz = darr_size(ncount, esize); + struct darr_metadata *dm; + + if (a) { + dm = XREALLOC(_darr_meta(a)->mtype, _darr_meta(a), sz); + if (sz > osz) + memset((char *)dm + osz, 0, sz - osz); + } else { + dm = XCALLOC(mtype, sz); + dm->mtype = mtype; + } + dm->cap = ncount; + return (void *)(dm + 1); +} + + +void *__darr_insert_n(void *a, uint at, uint count, size_t esize, bool zero, + struct memtype *mtype) +{ + struct darr_metadata *dm; + uint olen, nlen; + + if (!a) + a = __darr_resize(NULL, at + count, esize, mtype); + dm = (struct darr_metadata *)a - 1; + olen = dm->len; + + // at == 1 + // count == 100 + // olen == 2 + + /* see if the user is expanding first using `at` */ + if (at >= olen) + nlen = at + count; + else + nlen = olen + count; + + if (nlen > dm->cap) { + a = __darr_resize(a, nlen, esize, mtype); + dm = (struct darr_metadata *)a - 1; + } + +#define _a_at(i) ((char *)a + ((i)*esize)) + if (at < olen) + memmove(_a_at(at + count), _a_at(at), esize * (olen - at)); + + dm->len = nlen; + + if (zero) { + if (at >= olen) { + at -= olen; + count += olen; + } + memset(_a_at(at), 0, esize * count); + } + + return a; +#undef _a_at +} diff --git a/lib/darr.h b/lib/darr.h new file mode 100644 index 0000000000..df8ace62dd --- /dev/null +++ b/lib/darr.h @@ -0,0 +1,753 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * June 23 2023, Christian Hopps <chopps@labn.net> + * + * Copyright (c) 2023, LabN Consulting, L.L.C. + */ +#ifndef _FRR_DARR_H_ +#define _FRR_DARR_H_ + +/* + * API functions: + * ============== + * - darr_append + * - darr_append_mt + * - darr_append_n + * - darr_append_n_mt + * - darr_append_nz + * - darr_append_nz_mt + * - darr_cap + * - darr_ensure_avail + * - darr_ensure_avail_mt + * - darr_ensure_cap + * - darr_ensure_cap_mt + * - darr_ensure_i + * - darr_ensure_i_mt + * - darr_free + * - darr_insert + * - darr_insert_mt + * - darr_insertz + * - darr_insertz_mt + * - darr_insert_n + * - darr_insert_n_mt + * - darr_insert_nz + * - darr_insert_nz_mt + * - darr_last + * - darr_lasti + * - darr_len + * - darr_maxi + * - darr_pop + * - darr_push + * - darr_pushz + * - darr_remove + * - darr_remove_n + * - darr_reset + * - darr_setlen + * + * Iteration + * --------- + * - darr_foreach_i + * - darr_foreach_p + * + * String Utilities + * ---------------- + * - darr_in_strcat_tail + * - darr_in_strcatf, darr_in_vstrcatf + * - darr_in_strdup + * - darr_in_strdup_cap + * - darr_in_sprintf, darr_in_vsprintf + * - darr_set_strlen + * - darr_strdup + * - darr_strdup_cap + * - darr_strlen + * - darr_strnul + * - darr_sprintf, darr_vsprintf + */ +/* + * A few assured items + * + * - DAs will never have capacity 0 unless they are NULL pointers. + */ + +/* + * NOTE: valgrind by default enables a "length64" heuristic (among others) which + * identifies "interior-pointer" 8 bytes forward of a "start-pointer" as a + * "start-pointer". This should cause what normally would be "possibly-lost" + * errors to instead be definite for dynamic arrays. This is b/c the header is 8 bytes + */ + +#include <zebra.h> +#include <limits.h> +#include "memory.h" + +DECLARE_MTYPE(DARR); +DECLARE_MTYPE(DARR_STR); + +struct darr_metadata { + uint32_t len; + uint32_t cap; + struct memtype *mtype; +}; + +void *__darr_insert_n(void *a, uint at, uint count, size_t esize, bool zero, + struct memtype *mt); +char *__darr_in_sprintf(char **sp, bool concat, const char *fmt, ...) + PRINTFRR(3, 4); +char *__darr_in_vsprintf(char **sp, bool concat, const char *fmt, va_list ap) + PRINTFRR(3, 0); +void *__darr_resize(void *a, uint count, size_t esize, struct memtype *mt); + + +#define _darr_esize(A) sizeof((A)[0]) +#define darr_esize(A) sizeof((A)[0]) +#define _darr_len(A) _darr_meta(A)->len +#define _darr_meta(A) (((struct darr_metadata *)(A)) - 1) +#define _darr_resize_mt(A, C, MT) \ + ({ (A) = __darr_resize(A, C, _darr_esize(A), MT); }) +#define _darr_resize(A, C) _darr_resize_mt(A, C, MTYPE_DARR) + +/* Get the current capacity of the array */ +#define darr_cap(A) (((A) == NULL) ? 0 : _darr_meta(A)->cap) + +/* Get the current available expansion space */ +#define darr_avail(A) (((A) == NULL) ? 0 : (darr_cap(A) - darr_len(A))) + +/* Get the largest possible index one can `darr_ensure_i` w/o resizing */ +#define darr_maxi(A) ((int)darr_cap(A) - 1) + +/** + * darr_len() - Get the current length of the array as a unsigned int. + * darr_ilen() - Get the current length of the array as an int. + * + * Args: + * A: The dynamic array, can be NULL. + * + * Return: + * The current length of the array. + */ +#define darr_len(A) (((A) == NULL) ? 0 : _darr_meta(A)->len) +#define darr_ilen(A) (((A) == NULL) ? 0 : (ssize_t)_darr_meta(A)->len) + +/** + * darr_lasti() - Get the last element's index. + * + * Args: + * A: The dynamic array, can be NULL. + * + * Return: + * The current last element index, or -1 for none. + */ +#define darr_lasti(A) (darr_ilen(A) - 1) + +/** + * Set the current length of the array `A` to 0. + * + * Args: + * A: The dynamic array, can be NULL. + */ +#define darr_reset(A) \ + do { \ + if ((A)) \ + _darr_len(A) = 0; \ + } while (0) + +/** + * Set the current length of the array `A` to `L`. + * + * This function does *not* guarantee the memory is valid to L, + * use `darr_ensure` or `darr_ensure_cap` for that. + * + * Args: + * A: The dynamic array, can only be NULL if (L) == 0. + * L: The new length of the array. + */ +#define darr_setlen(A, L) \ + do { \ + assert((A) || !(L)); \ + if ((A)) { \ + /* have to cast to avoid compiler warning for "0" */ \ + assert((long long)darr_cap(A) >= (long long)(L)); \ + _darr_len(A) = (L); \ + } \ + } while (0) + +/** + * Set the string length of the array `S` to `L`, and NUL + * terminate the string at L. The dynamic array length will be `L` + 1. + * + * Thus after calling: + * + * darr_len(S) == L + 1 + * darr_strlen(S) == L + * S[L] == 0 + * + * This function does *not* guarantee the `L` + 1 memory is allocated to + * the array, use `darr_ensure` or `*_cap` functions for that. + * + * Args: + * S: The dynamic array, cannot be NULL. + * L: The new str length of the array, will set + * + * Return: + * A pointer to the end of S (i.e., pointing to the NUL byte). + */ +#define darr_set_strlen(S, L) \ + ({ \ + assert((S)); \ + /* have to cast to avoid compiler warning for "0" */ \ + assert((long long)darr_cap(S) >= (long long)(L)); \ + _darr_len(S) = (L) + 1; \ + *darr_last(S) = 0; \ + darr_last(S); \ + }) + +/** + * Free memory allocated for the dynamic array `A` + * + * Args: + * A: The dynamic array, can be NULL. + */ + +#define darr_free(A) \ + do { \ + if ((A)) { \ + struct darr_metadata *__meta = _darr_meta(A); \ + XFREE(__meta->mtype, __meta); \ + (A) = NULL; \ + } \ + } while (0) + +/** + * Make sure that there is room in the dynamic array `A` to add `C` elements. + * + * Available space is `darr_cap(a) - darr_len(a)`. + * + * The value `A` may be changed as a result of this call in which case any + * pointers into the previous memory block are no longer valid. The `A` value + * is guaranteed not to change if there is sufficient capacity in the array. + * + * Args: + * A: (IN/OUT) the dynamic array, can be NULL. + * S: Amount of free space to guarantee. + * + * Return: + * A pointer to the (possibly moved) array. + */ +#define darr_ensure_avail_mt(A, S, MT) \ + ({ \ + ssize_t need = (ssize_t)(S) - \ + (ssize_t)(darr_cap(A) - darr_len(A)); \ + if (need > 0) \ + _darr_resize_mt((A), darr_cap(A) + need, MT); \ + (A); \ + }) +#define darr_ensure_avail(A, S) darr_ensure_avail_mt(A, S, MTYPE_DARR) + +/** + * Make sure that there is room in the dynamic array `A` for `C` elements. + * + * The value `A` may be changed as a result of this call in which case any + * pointers into the previous memory block are no longer valid. The `A` value + * is guaranteed not to change if there is sufficient capacity in the array. + * + * The exception to the no-change rule is if @C is passed as 0, it will be + * considered 1 so that an array is always allocated if currently NULL, + * i.e., @A will never be NULL after a call to darr_ensure_cap_mt() + * + * Args: + * A: (IN/OUT) the dynamic array, can be NULL. + * C: Total capacity to guarantee. + * + * Return: + * A pointer to the (possibly moved) array. + */ +#define darr_ensure_cap_mt(A, C, MT) \ + ({ \ + /* Cast to avoid warning when C == 0 */ \ + uint _c = (C) > 0 ? (C) : 1; \ + if ((size_t)darr_cap(A) < _c) \ + _darr_resize_mt((A), _c, MT); \ + (A); \ + }) +#define darr_ensure_cap(A, C) darr_ensure_cap_mt(A, C, MTYPE_DARR) + +/** + * Return a pointer to the (I)th element of array `A`, making sure there is + * room for the element. + * + * If the array length is less than `I + 1` then the length is set to `I + 1`. + * + * The value `A` may be changed as a result of this call in which case any + * pointers into the previous memory block are no longer valid. The `A` value + * is guaranteed not to change if there is sufficient capacity in the array. + * + * Args: + * + * A: (IN/OUT) the dynamic array, can be NULL. + * I: the index to guarantee memory exists for + * + * Return: + * A pointer to the (I)th element in `A` + */ +#define darr_ensure_i_mt(A, I, MT) \ + ({ \ + assert((int)(I) >= 0 && (int)(I) <= INT_MAX); \ + int _i = (int)(I); \ + if (_i > darr_maxi(A)) \ + _darr_resize_mt((A), _i + 1, MT); \ + assert((A) != NULL); \ + if ((uint)_i + 1 > _darr_len(A)) \ + _darr_len(A) = _i + 1; \ + &(A)[_i]; \ + }) +#define darr_ensure_i(A, I) darr_ensure_i_mt(A, I, MTYPE_DARR) + +#define _darr_insert_n(A, I, N, Z, MT) \ + ({ \ + (A) = __darr_insert_n(A, I, N, _darr_esize(A), Z, MT); \ + &(A)[I]; \ + }) +/** + * Insert N uninitialized elements in the array at index `I`. + * + * Previous elements from `I` are shifted right by `N`. Array length is + * increased by `N`. + * + * The value `A` may be changed as a result of this call in which case any + * pointers into the previous memory block are no longer valid. The `A` value + * is guaranteed not to change if there is sufficient capacity in the array. + * + * The `z` variant zeros new elements. + * + * Args: + * A: The dynamic array, can be NULL. + * + * Return: + * A pointer to the first inserted element in the array. + */ +#define darr_insert_n(A, I, N) _darr_insert_n(A, I, N, false, MTYPE_DARR) +#define darr_insert_n_mt(A, I, N) _darr_insert_n(A, I, N, false, MT) +#define darr_insert_nz(A, I, N) _darr_insert_n(A, I, N, true, MTYPE_DARR) +#define darr_insert_nz_mt(A, I, N) _darr_insert_n(A, I, N, true, MT) + +/** + * Insert an uninitialized element in the array at index `I`. + * + * Previous elements from `I` are shifted right by 1. Array length is + * increased by 1. + * + * The value `A` may be changed as a result of this call in which case any + * pointers into the previous memory block are no longer valid. The `A` value + * is guaranteed not to change if there is sufficient capacity in the array. + * + * The `z` variant zeros the new element. + * + * Args: + * A: The dynamic array, can be NULL. + * + * Return: + * A pointer to the element in the array. + */ +#define darr_insert(A, I) _darr_insert_n(A, I, 1, false, MTYPE_DARR) +#define darr_insert_mt(A, I) _darr_insert_n(A, I, 1, false, MT) +#define darr_insertz(A, I) _darr_insert_n(A, I, 1, true, MTYPE_DARR) +#define darr_insertz_mt(A, I) _darr_insert_n(A, I, 1, true, MT) + +/** + * Remove `N` elements from the array starting at index `I`. + * + * Elements from `I` + `N` are shifted left by `N`. Array length is reduced by + * `N`. + * + * Args: + * A: The dynamic array, can be NULL. + */ +#define darr_remove_n(A, I, N) \ + do { \ + uint __i = (I); \ + uint __n = (N); \ + uint __len = darr_len(A); \ + if (!__len) \ + break; \ + else if (__i + __n < __len) { \ + memmove(&(A)[__i], &(A)[__i + __n], \ + _darr_esize(A) * (__len - (__i + __n))); \ + _darr_len(A) = __len - __n; \ + } else \ + _darr_len(A) = __i; \ + } while (0) + +/** + * Remove the `I`th element from the array. + * + * Previous elements from `I` + 1 are shifted left by 1, Array length is reduced + * by 1. + * + * Args: + * A: The dynamic array, can be NULL. + */ +#define darr_remove(A, I) darr_remove_n(A, I, 1) + + +#define _darr_append_n(A, N, Z, MT) \ + ({ \ + uint __len = darr_len(A); \ + darr_ensure_cap_mt(A, __len + (N), MT); \ + _darr_len(A) = __len + (N); \ + if (Z) \ + memset(&(A)[__len], 0, (N)*_darr_esize(A)); \ + &(A)[__len]; \ + }) +/** + * Extending the array's length by N. + * + * Args: + * A: The dynamic array, can be NULL. + * + * The `z` variant zeros new elements. + * + * Return: + * A pointer to the first of the added elements at the end of the array. + */ +#define darr_append_n(A, N) _darr_append_n(A, N, false, MTYPE_DARR) +#define darr_append_n_mt(A, N, MT) _darr_append_n(A, N, false, MT) +#define darr_append_nz(A, N) _darr_append_n(A, N, true, MTYPE_DARR) +#define darr_append_nz_mt(A, N, MT) _darr_append_n(A, N, true, MT) + +/** + * Extending the array's length by 1. + * + * Args: + * A: The dynamic array, can be NULL. + * + * The `z` variant zeros the new element. + * + * Return: + * A pointer to the new element at the end of the array. + */ +#define darr_append(A) _darr_append_n(A, 1, false, MTYPE_DARR) +#define darr_append_mt(A, MT) _darr_append_n(A, 1, false, MT) +#define darr_appendz(A) _darr_append_n(A, 1, true, MTYPE_DARR) +#define darr_appendz_mt(A, MT) _darr_append_n(A, 1, true, MT) + +/** + * Append an element `E` onto the array `A`, extending it's length by 1. + * + * The `z` variant zeros the new element. + * + * Args: + * A: The dynamic array, can be NULL. + * + * Return: + * A pointer to the element in the array. + */ +#define darr_push(A, E) (*darr_append(A) = (E)) +#define darr_push_mt(A, E, MT) (*darr_append_mt(A, MT) = (E)) +#define darr_pushz(A) (darr_appendz(A)) +#define darr_pushz_mt(A, MT) (darr_appendz_mt(A, MT)) + + +/** + * Pop the last `N` elements from the array decrementing the length by `N`. + * + * Args: + * A: The dynamic array, can be NULL. + */ +#define darr_pop_n(A, N) \ + do { \ + if ((A) && (N) >= _darr_len(A)) \ + darr_reset(A); \ + else \ + _darr_len(A) -= (N); \ + } while (0) + + +/** + * Pop the last element from the array decrementing the length by 1. + * + * Args: + * A: The dynamic array, can be NULL. + * + * Return: + * The element just popped. + */ +#define darr_pop(A) \ + ({ \ + uint __len = _darr_len(A); \ + assert(__len); \ + darr_remove(A, __len - 1); \ + /* count on fact that we don't resize */ \ + (A)[__len - 1]; \ + }) + +/** + * Return the address at the end of the array -- useful for iterating + * + * Args: + * A: The dynamic array, can be NULL. + * + * Return: + * The address of the end of the array (past the last elment) or NULL + * if `A` is NULL. + */ +#define darr_end(A) ((A) + darr_len(A)) + +/** + * darr_last() - Get a pointer to the last element of the array. + * darr_strnul() - Get a pointer to the NUL byte of the darr string or NULL. + * + * Args: + * A: The dynamic array, can be NULL. + * + * Return: + * A pointer to the last element of the array or NULL if the array is + * empty. + */ +#define darr_last(A) \ + ({ \ + uint __len = darr_len(A); \ + ((__len > 0) ? &(A)[__len - 1] : NULL); \ + }) +#define darr_strnul(S) darr_last(S) + +/** + * darr_in_sprintf() - sprintf into D. + * + * Args: + * D: The destination darr, D's value may be NULL. + * F: The format string + * ...: variable arguments for format string. + * + * Return: + * The dynamic_array D with the new string content. + */ +#define darr_in_sprintf(D, F, ...) __darr_in_sprintf(&(D), 0, F, __VA_ARGS__) + + +/** + * darr_in_strcat() - concat a string into a darr string. + * + * Args: + * D: The destination darr, D's value may be NULL. + * S: The string to concat onto D. + * + * Return: + * The dynamic_array D with the new string content. + */ +#define darr_in_strcat(D, S) \ + ({ \ + uint __dlen = darr_strlen(D); \ + uint __slen = strlen(S); \ + darr_ensure_cap_mt(D, __dlen + __slen + 1, MTYPE_DARR_STR); \ + if (darr_len(D) == 0) \ + *darr_append(D) = 0; \ + memcpy(darr_last(D), (S), __slen + 1); \ + _darr_len(D) += __slen; \ + D; \ + }) + +/** + * darr_in_strcatf() - concat a formatted string into a darr string. + * + * Args: + * D: The destination darr, D's value may be NULL. + * F: The format string to concat onto D after adding arguments. + * ...: The arguments for the format string. + * Return: + * The dynamic_array D with the new string content. + */ +#define darr_in_strcatf(D, F, ...) \ + __darr_in_sprintf(&(D), true, (F), __VA_ARGS__) + +/** + * darr_in_strcat_tail() - copies end of one darr str to another. + * + * This is a rather specialized function, it takes 2 darr's, a destination and a + * source. If the source is not longer than the destination nothing is done. + * Otherwise the characters in the source that lie beyond the length of the dest + * are added to the dest. No checking is done to make sure the common prefix + * matches. For example: + * + * D: "/foo" + * S: "/foo/bar" + * -> D: "/foo/bar" + * + * perhaps surprising results: + * D: "/foo" + * S: "/zoo/bar" + * -> D: "/foo/bar" + * + * Args: + * D: The destination darr, D's value may be NULL. + * S: The string to copy the tail from. + * + * Return: + * The dynamic_array D with the extended string content. + */ +#define darr_in_strcat_tail(D, S) \ + ({ \ + int __dsize, __ssize, __extra; \ + \ + if (darr_len(D) == 0) \ + *darr_append(D) = 0; \ + __dsize = darr_ilen(D); \ + __ssize = darr_ilen(S); \ + __extra = __ssize - __dsize; \ + if (__extra > 0) { \ + darr_ensure_cap_mt(D, (uint)__ssize, MTYPE_DARR_STR); \ + memcpy(darr_last(D), (S) + __dsize - 1, __extra + 1); \ + _darr_len(D) += __extra; \ + } \ + D; \ + }) + +/** + * darr_in_strdup_cap() - duplicate the string into a darr reserving capacity. + * darr_in_strdup() - duplicate the string into a darr. + * + * Args: + * D: The destination darr, D's value may be NULL. + * S: The string to duplicate. + * C: The capacity to reserve. + * + * Return: + * The dynamic_array D with the duplicated string. + */ +#define darr_in_strdup_cap(D, S, C) \ + ({ \ + size_t __size = strlen(S) + 1; \ + darr_reset(D); \ + darr_ensure_cap_mt(D, \ + ((size_t)(C) > __size) ? (size_t)(C) \ + : __size, \ + MTYPE_DARR_STR); \ + strlcpy(D, (S), darr_cap(D)); \ + darr_setlen((D), (size_t)__size); \ + D; \ + }) +#define darr_in_strdup(D, S) darr_in_strdup_cap(D, S, 1) + +/** + * darr_in_vsprintf() - vsprintf into D. + * + * Args: + * D: The destination darr, D's value may be NULL. + * F: The format string + * A: Varargs + * + * Return: + * The dynamic_array D with the new string content. + */ +#define darr_in_vsprintf(D, F, A) __darr_in_vsprintf(&(D), 0, F, A) + +/** + * darr_in_vstrcatf() - concat a formatted string into a darr string. + * + * Args: + * D: The destination darr, D's value may be NULL. + * F: The format string to concat onto D after adding arguments. + * A: Varargs + * + * Return: + * The dynamic_array D with the new string content. + */ +#define darr_in_vstrcatf(D, F, A) __darr_in_vsprintf(&(D), true, (F), (A)) + +/** + * darr_sprintf() - sprintf into a new dynamic array. + * + * Args: + * F: The format string + * ...: variable arguments for format string. + * + * Return: + * A char * dynamic_array with the new string content. + */ +#define darr_sprintf(F, ...) \ + ({ \ + char *d = NULL; \ + __darr_in_sprintf(&d, false, F, __VA_ARGS__); \ + d; \ + }) + +/** + * darr_strdup_cap() - duplicate the string reserving capacity. + * darr_strdup() - duplicate the string into a dynamic array. + * + * Args: + * S: The string to duplicate. + * C: The capacity to reserve. + * + * Return: + * The dynamic_array with the duplicated string. + */ +#define darr_strdup_cap(S, C) \ + ({ \ + size_t __size = strlen(S) + 1; \ + char *__s = NULL; \ + /* Cast to ssize_t to avoid warning when C == 0 */ \ + darr_ensure_cap_mt(__s, \ + ((ssize_t)(C) > (ssize_t)__size) \ + ? (size_t)(C) \ + : __size, \ + MTYPE_DARR_STR); \ + strlcpy(__s, (S), darr_cap(__s)); \ + darr_setlen(__s, (size_t)__size); \ + __s; \ + }) +#define darr_strdup(S) darr_strdup_cap(S, 0) + +/** + * darr_strlen() - get the length of the NUL terminated string in a darr. + * + * Args: + * S: The string to measure, value may be NULL. + * + * Return: + * The length of the NUL terminated string in @S + */ +#define darr_strlen(S) \ + ({ \ + uint __size = darr_len(S); \ + if (__size) \ + __size -= 1; \ + assert(!(S) || ((char *)(S))[__size] == 0); \ + __size; \ + }) + +/** + * darr_vsprintf() - vsprintf into a new dynamic array. + * + * Args: + * F: The format string + * A: Varargs + * + * Return: + * The dynamic_array D with the new string content. + */ +#define darr_vsprintf(F, A) \ + ({ \ + char *d = NULL; \ + darr_in_vsprintf(d, F, A); \ + d; \ + }) + +/** + * Iterate over array `A` using a pointer to each element in `P`. + * + * Args: + * A: The dynamic array, can be NULL. + * P: A variable with the same type as A used as the iterator. + */ +#define darr_foreach_p(A, P) for ((P) = (A); (P) < darr_end(A); (P)++) + +/** + * Iterate over array `A`s indices. + * + * Args: + * A: The dynamic array, can be NULL. + * I: A uint variable to store the current element index in. + */ +#define darr_foreach_i(A, I) for ((I) = 0; (I) < darr_len(A); (I)++) + +#endif /* _FRR_DARR_H_ */ diff --git a/lib/elf_py.c b/lib/elf_py.c index d473dc10cb..643495d8c7 100644 --- a/lib/elf_py.c +++ b/lib/elf_py.c @@ -1089,7 +1089,9 @@ static void elffile_add_dynreloc(struct elffile *w, Elf_Data *reldata, symidx = relw->symidx = GELF_R_SYM(rela->r_info); sym = relw->sym = gelf_getsym(symdata, symidx, &relw->_sym); if (sym) { - relw->symname = elfdata_strptr(strdata, sym->st_name); + if (strdata) + relw->symname = elfdata_strptr(strdata, + sym->st_name); relw->symvalid = GELF_ST_TYPE(sym->st_info) != STT_NOTYPE; relw->unresolved = sym->st_shndx == SHN_UNDEF; @@ -1140,7 +1142,7 @@ static PyObject *elffile_load(PyTypeObject *type, PyObject *args, fd = open(filename, O_RDONLY | O_NOCTTY); if (fd < 0 || fstat(fd, &st)) { PyErr_SetFromErrnoWithFilename(PyExc_OSError, filename); - if (fd > 0) + if (fd >= 0) close(fd); goto out; } diff --git a/lib/event.c b/lib/event.c index a8eb89f48d..a7851f6983 100644 --- a/lib/event.c +++ b/lib/event.c @@ -6,6 +6,8 @@ /* #define DEBUG */ #include <zebra.h> + +#include <signal.h> #include <sys/resource.h> #include "frrevent.h" @@ -55,11 +57,6 @@ static int event_timer_cmp(const struct event *a, const struct event *b) DECLARE_HEAP(event_timer_list, struct event, timeritem, event_timer_cmp); -#if defined(__APPLE__) -#include <mach/mach.h> -#include <mach/mach_time.h> -#endif - #define AWAKEN(m) \ do { \ const unsigned char wakebyte = 0x01; \ @@ -75,48 +72,48 @@ static struct list *masters; static void thread_free(struct event_loop *master, struct event *thread); -#ifndef EXCLUDE_CPU_TIME -#define EXCLUDE_CPU_TIME 0 -#endif -#ifndef CONSUMED_TIME_CHECK -#define CONSUMED_TIME_CHECK 0 -#endif - -bool cputime_enabled = !EXCLUDE_CPU_TIME; +bool cputime_enabled = true; unsigned long cputime_threshold = CONSUMED_TIME_CHECK; unsigned long walltime_threshold = CONSUMED_TIME_CHECK; /* CLI start ---------------------------------------------------------------- */ #include "lib/event_clippy.c" -static unsigned int cpu_record_hash_key(const struct cpu_event_history *a) +static uint32_t cpu_record_hash_key(const struct cpu_event_history *a) { int size = sizeof(a->func); return jhash(&a->func, size, 0); } -static bool cpu_record_hash_cmp(const struct cpu_event_history *a, - const struct cpu_event_history *b) +static int cpu_record_hash_cmp(const struct cpu_event_history *a, + const struct cpu_event_history *b) { - return a->func == b->func; + return numcmp((uintptr_t)a->func, (uintptr_t)b->func); } -static void *cpu_record_hash_alloc(struct cpu_event_history *a) +DECLARE_HASH(cpu_records, struct cpu_event_history, item, cpu_record_hash_cmp, + cpu_record_hash_key); + +static struct cpu_event_history *cpu_records_get(struct event_loop *loop, + void (*func)(struct event *e), + const char *funcname) { - struct cpu_event_history *new; + struct cpu_event_history ref = { .func = func }, *res; - new = XCALLOC(MTYPE_EVENT_STATS, sizeof(struct cpu_event_history)); - new->func = a->func; - new->funcname = a->funcname; - return new; + res = cpu_records_find(loop->cpu_records, &ref); + if (!res) { + res = XCALLOC(MTYPE_EVENT_STATS, sizeof(*res)); + res->func = func; + res->funcname = funcname; + cpu_records_add(loop->cpu_records, res); + } + return res; } -static void cpu_record_hash_free(void *a) +static void cpu_records_free(struct cpu_event_history **p) { - struct cpu_event_history *hist = a; - - XFREE(MTYPE_EVENT_STATS, hist); + XFREE(MTYPE_EVENT_STATS, *p); } static void vty_out_cpu_event_history(struct vty *vty, @@ -136,14 +133,11 @@ static void vty_out_cpu_event_history(struct vty *vty, a->types & (1 << EVENT_EXECUTE) ? 'X' : ' ', a->funcname); } -static void cpu_record_hash_print(struct hash_bucket *bucket, void *args[]) +static void cpu_record_print_one(struct vty *vty, uint8_t filter, + struct cpu_event_history *totals, + const struct cpu_event_history *a) { - struct cpu_event_history *totals = args[0]; struct cpu_event_history copy; - struct vty *vty = args[1]; - uint8_t *filter = args[2]; - - struct cpu_event_history *a = bucket->data; copy.total_active = atomic_load_explicit(&a->total_active, memory_order_seq_cst); @@ -165,7 +159,7 @@ static void cpu_record_hash_print(struct hash_bucket *bucket, void *args[]) copy.types = atomic_load_explicit(&a->types, memory_order_seq_cst); copy.funcname = a->funcname; - if (!(copy.types & *filter)) + if (!(copy.types & filter)) return; vty_out_cpu_event_history(vty, ©); @@ -185,7 +179,6 @@ static void cpu_record_hash_print(struct hash_bucket *bucket, void *args[]) static void cpu_record_print(struct vty *vty, uint8_t filter) { struct cpu_event_history tmp; - void *args[3] = {&tmp, vty, &filter}; struct event_loop *m; struct listnode *ln; @@ -220,15 +213,15 @@ static void cpu_record_print(struct vty *vty, uint8_t filter) "Active Runtime(ms) Invoked Avg uSec Max uSecs"); vty_out(vty, " Avg uSec Max uSecs"); vty_out(vty, - " CPU_Warn Wall_Warn Starv_Warn Type Thread\n"); - - if (m->cpu_record->count) - hash_iterate( - m->cpu_record, - (void (*)(struct hash_bucket *, - void *))cpu_record_hash_print, - args); - else + " CPU_Warn Wall_Warn Starv_Warn Type Event\n"); + + if (cpu_records_count(m->cpu_records)) { + struct cpu_event_history *rec; + + frr_each (cpu_records, m->cpu_records, rec) + cpu_record_print_one(vty, filter, &tmp, + rec); + } else vty_out(vty, "No data to display yet.\n"); vty_out(vty, "\n"); @@ -236,47 +229,41 @@ static void cpu_record_print(struct vty *vty, uint8_t filter) } vty_out(vty, "\n"); - vty_out(vty, "Total thread statistics\n"); + vty_out(vty, "Total Event statistics\n"); vty_out(vty, "-------------------------\n"); vty_out(vty, "%30s %18s %18s\n", "", "CPU (user+system):", "Real (wall-clock):"); vty_out(vty, "Active Runtime(ms) Invoked Avg uSec Max uSecs"); - vty_out(vty, " Avg uSec Max uSecs CPU_Warn Wall_Warn"); - vty_out(vty, " Type Thread\n"); + vty_out(vty, " Avg uSec Max uSecs CPU_Warn Wall_Warn Starv_Warn"); + vty_out(vty, " Type Event\n"); if (tmp.total_calls > 0) vty_out_cpu_event_history(vty, &tmp); } -static void cpu_record_hash_clear(struct hash_bucket *bucket, void *args[]) -{ - uint8_t *filter = args[0]; - struct hash *cpu_record = args[1]; - - struct cpu_event_history *a = bucket->data; - - if (!(a->types & *filter)) - return; - - hash_release(cpu_record, bucket->data); -} - static void cpu_record_clear(uint8_t filter) { - uint8_t *tmp = &filter; struct event_loop *m; struct listnode *ln; frr_with_mutex (&masters_mtx) { for (ALL_LIST_ELEMENTS_RO(masters, ln, m)) { frr_with_mutex (&m->mtx) { - void *args[2] = {tmp, m->cpu_record}; + struct cpu_event_history *item; + struct cpu_records_head old[1]; + + cpu_records_init(old); + cpu_records_swap_all(old, m->cpu_records); - hash_iterate( - m->cpu_record, - (void (*)(struct hash_bucket *, - void *))cpu_record_hash_clear, - args); + while ((item = cpu_records_pop(old))) { + if (item->types & filter) + cpu_records_free(&item); + else + cpu_records_add(m->cpu_records, + item); + } + + cpu_records_fini(old); } } } @@ -317,13 +304,16 @@ static uint8_t parse_filter(const char *filterstr) return filter; } -DEFUN_NOSH (show_thread_cpu, - show_thread_cpu_cmd, - "show thread cpu [FILTER]", - SHOW_STR - "Thread information\n" - "Thread CPU usage\n" - "Display filter (rwtex)\n") +#if CONFDATE > 20240707 + CPP_NOTICE("Remove `show thread ...` commands") +#endif +DEFUN_NOSH (show_event_cpu, + show_event_cpu_cmd, + "show event cpu [FILTER]", + SHOW_STR + "Event information\n" + "Event CPU usage\n" + "Display filter (rwtexb)\n") { uint8_t filter = (uint8_t)-1U; int idx = 0; @@ -342,6 +332,14 @@ DEFUN_NOSH (show_thread_cpu, return CMD_SUCCESS; } +ALIAS(show_event_cpu, + show_thread_cpu_cmd, + "show thread cpu [FILTER]", + SHOW_STR + "Thread information\n" + "Thread CPU usage\n" + "Display filter (rwtex)\n") + DEFPY (service_cputime_stats, service_cputime_stats_cmd, "[no] service cputime-stats", @@ -355,7 +353,7 @@ DEFPY (service_cputime_stats, DEFPY (service_cputime_warning, service_cputime_warning_cmd, - "[no] service cputime-warning (1-4294967295)", + "[no] service cputime-warning ![(1-4294967295)]", NO_STR "Set up miscellaneous service\n" "Warn for tasks exceeding CPU usage threshold\n" @@ -368,16 +366,9 @@ DEFPY (service_cputime_warning, return CMD_SUCCESS; } -ALIAS (service_cputime_warning, - no_service_cputime_warning_cmd, - "no service cputime-warning", - NO_STR - "Set up miscellaneous service\n" - "Warn for tasks exceeding CPU usage threshold\n") - DEFPY (service_walltime_warning, service_walltime_warning_cmd, - "[no] service walltime-warning (1-4294967295)", + "[no] service walltime-warning ![(1-4294967295)]", NO_STR "Set up miscellaneous service\n" "Warn for tasks exceeding total wallclock threshold\n" @@ -390,14 +381,7 @@ DEFPY (service_walltime_warning, return CMD_SUCCESS; } -ALIAS (service_walltime_warning, - no_service_walltime_warning_cmd, - "no service walltime-warning", - NO_STR - "Set up miscellaneous service\n" - "Warn for tasks exceeding total wallclock threshold\n") - -static void show_thread_poll_helper(struct vty *vty, struct event_loop *m) +static void show_event_poll_helper(struct vty *vty, struct event_loop *m) { const char *name = m->name ? m->name : "main"; char underline[strlen(name) + 1]; @@ -438,24 +422,30 @@ static void show_thread_poll_helper(struct vty *vty, struct event_loop *m) } } -DEFUN_NOSH (show_thread_poll, - show_thread_poll_cmd, - "show thread poll", - SHOW_STR - "Thread information\n" - "Show poll FD's and information\n") +DEFUN_NOSH (show_event_poll, + show_event_poll_cmd, + "show event poll", + SHOW_STR + "Event information\n" + "Event Poll Information\n") { struct listnode *node; struct event_loop *m; frr_with_mutex (&masters_mtx) { for (ALL_LIST_ELEMENTS_RO(masters, node, m)) - show_thread_poll_helper(vty, m); + show_event_poll_helper(vty, m); } return CMD_SUCCESS; } +ALIAS(show_event_poll, + show_thread_poll_cmd, + "show thread poll", + SHOW_STR + "Thread information\n" + "Show poll FD's and information\n") DEFUN (clear_thread_cpu, clear_thread_cpu_cmd, @@ -482,7 +472,7 @@ DEFUN (clear_thread_cpu, return CMD_SUCCESS; } -static void show_thread_timers_helper(struct vty *vty, struct event_loop *m) +static void show_event_timers_helper(struct vty *vty, struct event_loop *m) { const char *name = m->name ? m->name : "main"; char underline[strlen(name) + 1]; @@ -499,37 +489,45 @@ static void show_thread_timers_helper(struct vty *vty, struct event_loop *m) } } -DEFPY_NOSH (show_thread_timers, - show_thread_timers_cmd, - "show thread timers", - SHOW_STR - "Thread information\n" - "Show all timers and how long they have in the system\n") +DEFPY_NOSH (show_event_timers, + show_event_timers_cmd, + "show event timers", + SHOW_STR + "Event information\n" + "Show all timers and how long they have in the system\n") { struct listnode *node; struct event_loop *m; frr_with_mutex (&masters_mtx) { for (ALL_LIST_ELEMENTS_RO(masters, node, m)) - show_thread_timers_helper(vty, m); + show_event_timers_helper(vty, m); } return CMD_SUCCESS; } +ALIAS(show_event_timers, + show_thread_timers_cmd, + "show thread timers", + SHOW_STR + "Thread information\n" + "Show all timers and how long they have in the system\n") + void event_cmd_init(void) { install_element(VIEW_NODE, &show_thread_cpu_cmd); + install_element(VIEW_NODE, &show_event_cpu_cmd); install_element(VIEW_NODE, &show_thread_poll_cmd); + install_element(VIEW_NODE, &show_event_poll_cmd); install_element(ENABLE_NODE, &clear_thread_cpu_cmd); install_element(CONFIG_NODE, &service_cputime_stats_cmd); install_element(CONFIG_NODE, &service_cputime_warning_cmd); - install_element(CONFIG_NODE, &no_service_cputime_warning_cmd); install_element(CONFIG_NODE, &service_walltime_warning_cmd); - install_element(CONFIG_NODE, &no_service_walltime_warning_cmd); install_element(VIEW_NODE, &show_thread_timers_cmd); + install_element(VIEW_NODE, &show_event_timers_cmd); } /* CLI end ------------------------------------------------------------------ */ @@ -581,10 +579,7 @@ struct event_loop *event_master_create(const char *name) snprintf(tmhashname, sizeof(tmhashname), "%s - threadmaster event hash", name); - rv->cpu_record = hash_create_size( - 8, (unsigned int (*)(const void *))cpu_record_hash_key, - (bool (*)(const void *, const void *))cpu_record_hash_cmp, - tmhashname); + cpu_records_init(rv->cpu_records); event_list_init(&rv->event); event_list_init(&rv->ready); @@ -702,6 +697,7 @@ void event_master_free_unused(struct event_loop *m) /* Stop thread scheduler. */ void event_master_free(struct event_loop *m) { + struct cpu_event_history *record; struct event *t; frr_with_mutex (&masters_mtx) { @@ -724,7 +720,9 @@ void event_master_free(struct event_loop *m) list_delete(&m->cancel_req); m->cancel_req = NULL; - hash_clean_and_free(&m->cpu_record, cpu_record_hash_free); + while ((record = cpu_records_pop(m->cpu_records))) + cpu_records_free(&record); + cpu_records_fini(m->cpu_records); XFREE(MTYPE_EVENT_MASTER, m->name); XFREE(MTYPE_EVENT_MASTER, m->handler.pfds); @@ -797,7 +795,6 @@ static struct event *thread_get(struct event_loop *m, uint8_t type, const struct xref_eventsched *xref) { struct event *thread = event_list_pop(&m->unuse); - struct cpu_event_history tmp; if (!thread) { thread = XCALLOC(MTYPE_THREAD, sizeof(struct event)); @@ -811,7 +808,12 @@ static struct event *thread_get(struct event_loop *m, uint8_t type, thread->master = m; thread->arg = arg; thread->yield = EVENT_YIELD_TIME_SLOT; /* default */ - thread->ref = NULL; + /* thread->ref is zeroed either by XCALLOC above or by memset before + * being put on the "unuse" list by thread_add_unuse(). + * Setting it here again makes coverity complain about a missing + * lock :( + */ + /* thread->ref = NULL; */ thread->ignore_timer_late = false; /* @@ -825,13 +827,9 @@ static struct event *thread_get(struct event_loop *m, uint8_t type, * hash_get lookups. */ if ((thread->xref && thread->xref->funcname != xref->funcname) - || thread->func != func) { - tmp.func = func; - tmp.funcname = xref->funcname; - thread->hist = - hash_get(m->cpu_record, &tmp, - (void *(*)(void *))cpu_record_hash_alloc); - } + || thread->func != func) + thread->hist = cpu_records_get(m, func, xref->funcname); + thread->hist->total_active++; thread->func = func; thread->xref = xref; @@ -1491,9 +1489,9 @@ void event_cancel(struct event **thread) cr->thread = *thread; listnode_add(master->cancel_req, cr); do_event_cancel(master); - } - *thread = NULL; + *thread = NULL; + } } /** @@ -1620,12 +1618,70 @@ static int thread_process_io_helper(struct event_loop *m, struct event *thread, return 1; } +static inline void thread_process_io_inner_loop(struct event_loop *m, + unsigned int num, + struct pollfd *pfds, nfds_t *i, + uint32_t *ready) +{ + /* no event for current fd? immediately continue */ + if (pfds[*i].revents == 0) + return; + + *ready = *ready + 1; + + /* + * Unless someone has called event_cancel from another + * pthread, the only thing that could have changed in + * m->handler.pfds while we were asleep is the .events + * field in a given pollfd. Barring event_cancel() that + * value should be a superset of the values we have in our + * copy, so there's no need to update it. Similarily, + * barring deletion, the fd should still be a valid index + * into the master's pfds. + * + * We are including POLLERR here to do a READ event + * this is because the read should fail and the + * read function should handle it appropriately + */ + if (pfds[*i].revents & (POLLIN | POLLHUP | POLLERR)) { + thread_process_io_helper(m, m->read[pfds[*i].fd], POLLIN, + pfds[*i].revents, *i); + } + if (pfds[*i].revents & POLLOUT) + thread_process_io_helper(m, m->write[pfds[*i].fd], POLLOUT, + pfds[*i].revents, *i); + + /* + * if one of our file descriptors is garbage, remove the same + * from both pfds + update sizes and index + */ + if (pfds[*i].revents & POLLNVAL) { + memmove(m->handler.pfds + *i, m->handler.pfds + *i + 1, + (m->handler.pfdcount - *i - 1) * sizeof(struct pollfd)); + m->handler.pfdcount--; + m->handler.pfds[m->handler.pfdcount].fd = 0; + m->handler.pfds[m->handler.pfdcount].events = 0; + + memmove(pfds + *i, pfds + *i + 1, + (m->handler.copycount - *i - 1) * sizeof(struct pollfd)); + m->handler.copycount--; + m->handler.copy[m->handler.copycount].fd = 0; + m->handler.copy[m->handler.copycount].events = 0; + + *i = *i - 1; + } +} + /** * Process I/O events. * * Walks through file descriptor array looking for those pollfds whose .revents * field has something interesting. Deletes any invalid file descriptors. * + * Try to impart some impartiality to handling of io. The event + * system will cycle through the fd's available for io + * giving each one a chance to go first. + * * @param m the thread master * @param num the number of active file descriptors (return value of poll()) */ @@ -1633,58 +1689,15 @@ static void thread_process_io(struct event_loop *m, unsigned int num) { unsigned int ready = 0; struct pollfd *pfds = m->handler.copy; + nfds_t i, last_read = m->last_read % m->handler.copycount; - for (nfds_t i = 0; i < m->handler.copycount && ready < num; ++i) { - /* no event for current fd? immediately continue */ - if (pfds[i].revents == 0) - continue; + for (i = last_read; i < m->handler.copycount && ready < num; ++i) + thread_process_io_inner_loop(m, num, pfds, &i, &ready); - ready++; + for (i = 0; i < last_read && ready < num; ++i) + thread_process_io_inner_loop(m, num, pfds, &i, &ready); - /* - * Unless someone has called event_cancel from another - * pthread, the only thing that could have changed in - * m->handler.pfds while we were asleep is the .events - * field in a given pollfd. Barring event_cancel() that - * value should be a superset of the values we have in our - * copy, so there's no need to update it. Similarily, - * barring deletion, the fd should still be a valid index - * into the master's pfds. - * - * We are including POLLERR here to do a READ event - * this is because the read should fail and the - * read function should handle it appropriately - */ - if (pfds[i].revents & (POLLIN | POLLHUP | POLLERR)) { - thread_process_io_helper(m, m->read[pfds[i].fd], POLLIN, - pfds[i].revents, i); - } - if (pfds[i].revents & POLLOUT) - thread_process_io_helper(m, m->write[pfds[i].fd], - POLLOUT, pfds[i].revents, i); - - /* - * if one of our file descriptors is garbage, remove the same - * from both pfds + update sizes and index - */ - if (pfds[i].revents & POLLNVAL) { - memmove(m->handler.pfds + i, m->handler.pfds + i + 1, - (m->handler.pfdcount - i - 1) - * sizeof(struct pollfd)); - m->handler.pfdcount--; - m->handler.pfds[m->handler.pfdcount].fd = 0; - m->handler.pfds[m->handler.pfdcount].events = 0; - - memmove(pfds + i, pfds + i + 1, - (m->handler.copycount - i - 1) - * sizeof(struct pollfd)); - m->handler.copycount--; - m->handler.copy[m->handler.copycount].fd = 0; - m->handler.copy[m->handler.copycount].events = 0; - - i--; - } - } + m->last_read++; } /* Add all timers that have popped to the ready list. */ @@ -1864,12 +1877,6 @@ struct event *event_fetch(struct event_loop *m, struct event *fetch) return fetch; } -static unsigned long timeval_elapsed(struct timeval a, struct timeval b) -{ - return (((a.tv_sec - b.tv_sec) * TIMER_SECOND_MICRO) - + (a.tv_usec - b.tv_usec)); -} - unsigned long event_consumed_time(RUSAGE_T *now, RUSAGE_T *start, unsigned long *cputime) { @@ -1972,6 +1979,7 @@ void event_getrusage(RUSAGE_T *r) void event_call(struct event *thread) { RUSAGE_T before, after; + bool suppress_warnings = EVENT_ARG(thread); /* if the thread being called is the CLI, it may change cputime_enabled * ("service cputime-stats" command), which can result in nonsensical @@ -2032,6 +2040,9 @@ void event_call(struct event *thread) atomic_fetch_or_explicit(&thread->hist->types, 1 << thread->add_type, memory_order_seq_cst); + if (suppress_warnings) + return; + if (cputime_enabled_here && cputime_enabled && cputime_threshold && cputime > cputime_threshold) { /* @@ -2066,10 +2077,15 @@ void event_call(struct event *thread) /* Execute thread */ void _event_execute(const struct xref_eventsched *xref, struct event_loop *m, - void (*func)(struct event *), void *arg, int val) + void (*func)(struct event *), void *arg, int val, + struct event **eref) { struct event *thread; + /* Cancel existing scheduled task TODO -- nice to do in 1 lock cycle */ + if (eref) + event_cancel(eref); + /* Get or allocate new thread to execute. */ frr_with_mutex (&m->mtx) { thread = thread_get(m, EVENT_EVENT, func, arg, xref); diff --git a/lib/filter_cli.c b/lib/filter_cli.c index 5c3dc5e49d..529b46b6ad 100644 --- a/lib/filter_cli.c +++ b/lib/filter_cli.c @@ -1004,8 +1004,8 @@ ALIAS( int access_list_cmp(const struct lyd_node *dnode1, const struct lyd_node *dnode2) { - uint32_t seq1 = yang_dnode_get_uint32(dnode1, "./sequence"); - uint32_t seq2 = yang_dnode_get_uint32(dnode2, "./sequence"); + uint32_t seq1 = yang_dnode_get_uint32(dnode1, "sequence"); + uint32_t seq2 = yang_dnode_get_uint32(dnode2, "sequence"); return seq1 - seq2; } @@ -1022,23 +1022,23 @@ void access_list_show(struct vty *vty, const struct lyd_node *dnode, struct in_addr addr, mask; char macstr[PREFIX2STR_BUFFER]; - is_any = yang_dnode_exists(dnode, "./any"); + is_any = yang_dnode_exists(dnode, "any"); switch (type) { case YALT_IPV4: if (is_any) break; - if (yang_dnode_exists(dnode, "./host") - || yang_dnode_exists(dnode, "./network/address") - || yang_dnode_exists(dnode, "./source-any")) { + if (yang_dnode_exists(dnode, "host") + || yang_dnode_exists(dnode, "network/address") + || yang_dnode_exists(dnode, "source-any")) { cisco_style = true; - if (yang_dnode_exists(dnode, "./destination-host") + if (yang_dnode_exists(dnode, "destination-host") || yang_dnode_exists( dnode, "./destination-network/address") - || yang_dnode_exists(dnode, "./destination-any")) + || yang_dnode_exists(dnode, "destination-any")) cisco_extended = true; } else { - yang_dnode_get_prefix(&p, dnode, "./ipv4-prefix"); + yang_dnode_get_prefix(&p, dnode, "ipv4-prefix"); is_exact = yang_dnode_get_bool(dnode, "./ipv4-exact-match"); } @@ -1048,39 +1048,39 @@ void access_list_show(struct vty *vty, const struct lyd_node *dnode, if (is_any) break; - yang_dnode_get_prefix(&p, dnode, "./ipv6-prefix"); - is_exact = yang_dnode_get_bool(dnode, "./ipv6-exact-match"); + yang_dnode_get_prefix(&p, dnode, "ipv6-prefix"); + is_exact = yang_dnode_get_bool(dnode, "ipv6-exact-match"); break; case YALT_MAC: /* mac */ vty_out(vty, "mac "); if (is_any) break; - yang_dnode_get_prefix(&p, dnode, "./mac"); + yang_dnode_get_prefix(&p, dnode, "mac"); break; } vty_out(vty, "access-list %s seq %s %s", yang_dnode_get_string(dnode, "../name"), - yang_dnode_get_string(dnode, "./sequence"), - yang_dnode_get_string(dnode, "./action")); + yang_dnode_get_string(dnode, "sequence"), + yang_dnode_get_string(dnode, "action")); /* Handle Cisco style access lists. */ if (cisco_style) { if (cisco_extended) vty_out(vty, " ip"); - if (yang_dnode_exists(dnode, "./network")) { - yang_dnode_get_ipv4(&addr, dnode, "./network/address"); - yang_dnode_get_ipv4(&mask, dnode, "./network/mask"); + if (yang_dnode_exists(dnode, "network")) { + yang_dnode_get_ipv4(&addr, dnode, "network/address"); + yang_dnode_get_ipv4(&mask, dnode, "network/mask"); vty_out(vty, " %pI4 %pI4", &addr, &mask); - } else if (yang_dnode_exists(dnode, "./host")) { + } else if (yang_dnode_exists(dnode, "host")) { if (cisco_extended) vty_out(vty, " host"); vty_out(vty, " %s", - yang_dnode_get_string(dnode, "./host")); - } else if (yang_dnode_exists(dnode, "./source-any")) + yang_dnode_get_string(dnode, "host")); + } else if (yang_dnode_exists(dnode, "source-any")) vty_out(vty, " any"); /* Not extended, exit earlier. */ @@ -1090,17 +1090,17 @@ void access_list_show(struct vty *vty, const struct lyd_node *dnode, } /* Handle destination address. */ - if (yang_dnode_exists(dnode, "./destination-network")) { + if (yang_dnode_exists(dnode, "destination-network")) { yang_dnode_get_ipv4(&addr, dnode, "./destination-network/address"); yang_dnode_get_ipv4(&mask, dnode, "./destination-network/mask"); vty_out(vty, " %pI4 %pI4", &addr, &mask); - } else if (yang_dnode_exists(dnode, "./destination-host")) + } else if (yang_dnode_exists(dnode, "destination-host")) vty_out(vty, " host %s", yang_dnode_get_string(dnode, "./destination-host")); - else if (yang_dnode_exists(dnode, "./destination-any")) + else if (yang_dnode_exists(dnode, "destination-any")) vty_out(vty, " any"); vty_out(vty, "\n"); @@ -1644,8 +1644,8 @@ ALIAS( int prefix_list_cmp(const struct lyd_node *dnode1, const struct lyd_node *dnode2) { - uint32_t seq1 = yang_dnode_get_uint32(dnode1, "./sequence"); - uint32_t seq2 = yang_dnode_get_uint32(dnode2, "./sequence"); + uint32_t seq1 = yang_dnode_get_uint32(dnode1, "sequence"); + uint32_t seq2 = yang_dnode_get_uint32(dnode2, "sequence"); return seq1 - seq2; } @@ -1658,11 +1658,11 @@ void prefix_list_show(struct vty *vty, const struct lyd_node *dnode, bool is_any; struct prefix p; - is_any = yang_dnode_exists(dnode, "./any"); + is_any = yang_dnode_exists(dnode, "any"); switch (type) { case YPLT_IPV4: if (!is_any) - yang_dnode_get_prefix(&p, dnode, "./ipv4-prefix"); + yang_dnode_get_prefix(&p, dnode, "ipv4-prefix"); if (yang_dnode_exists(dnode, "./ipv4-prefix-length-greater-or-equal")) ge_str = yang_dnode_get_string( @@ -1692,8 +1692,8 @@ void prefix_list_show(struct vty *vty, const struct lyd_node *dnode, vty_out(vty, "prefix-list %s seq %s %s", yang_dnode_get_string(dnode, "../name"), - yang_dnode_get_string(dnode, "./sequence"), - yang_dnode_get_string(dnode, "./action")); + yang_dnode_get_string(dnode, "sequence"), + yang_dnode_get_string(dnode, "action")); if (is_any) { vty_out(vty, " any\n"); diff --git a/lib/filter_nb.c b/lib/filter_nb.c index 9511b8f5b5..1c436cc6f1 100644 --- a/lib/filter_nb.c +++ b/lib/filter_nb.c @@ -112,7 +112,7 @@ prefix_list_nb_validate_v4_af_type(const struct lyd_node *plist_dnode, { int af_type; - af_type = yang_dnode_get_enum(plist_dnode, "./type"); + af_type = yang_dnode_get_enum(plist_dnode, "type"); if (af_type != YPLT_IPV4) { snprintf(errmsg, errmsg_len, "prefix-list type %u is mismatched.", af_type); @@ -128,7 +128,7 @@ prefix_list_nb_validate_v6_af_type(const struct lyd_node *plist_dnode, { int af_type; - af_type = yang_dnode_get_enum(plist_dnode, "./type"); + af_type = yang_dnode_get_enum(plist_dnode, "type"); if (af_type != YPLT_IPV6) { snprintf(errmsg, errmsg_len, "prefix-list type %u is mismatched.", af_type); @@ -381,14 +381,14 @@ static void plist_dnode_to_prefix(const struct lyd_node *dnode, bool *any, *ge = 0; *le = 0; - if (yang_dnode_exists(dnode, "./any")) { + if (yang_dnode_exists(dnode, "any")) { *any = true; return; } switch (yang_dnode_get_enum(dnode, "../type")) { case YPLT_IPV4: - yang_dnode_get_prefix(p, dnode, "./ipv4-prefix"); + yang_dnode_get_prefix(p, dnode, "ipv4-prefix"); if (yang_dnode_exists(dnode, "./ipv4-prefix-length-greater-or-equal")) *ge = yang_dnode_get_uint8( @@ -399,7 +399,7 @@ static void plist_dnode_to_prefix(const struct lyd_node *dnode, bool *any, dnode, "./ipv4-prefix-length-lesser-or-equal"); break; case YPLT_IPV6: - yang_dnode_get_prefix(p, dnode, "./ipv6-prefix"); + yang_dnode_get_prefix(p, dnode, "ipv6-prefix"); if (yang_dnode_exists(dnode, "./ipv6-prefix-length-greater-or-equal")) *ge = yang_dnode_get_uint8( @@ -468,8 +468,8 @@ static int lib_access_list_create(struct nb_cb_create_args *args) if (args->event != NB_EV_APPLY) return NB_OK; - type = yang_dnode_get_enum(args->dnode, "./type"); - acl_name = yang_dnode_get_string(args->dnode, "./name"); + type = yang_dnode_get_enum(args->dnode, "type"); + acl_name = yang_dnode_get_string(args->dnode, "name"); switch (type) { case YALT_IPV4: @@ -550,7 +550,7 @@ static int lib_access_list_entry_create(struct nb_cb_create_args *args) return NB_OK; f = filter_new(); - f->seq = yang_dnode_get_uint32(args->dnode, "./sequence"); + f->seq = yang_dnode_get_uint32(args->dnode, "sequence"); acl = nb_running_get_entry(args->dnode, NULL, true); f->acl = acl; @@ -1123,8 +1123,8 @@ static int lib_prefix_list_create(struct nb_cb_create_args *args) if (args->event != NB_EV_APPLY) return NB_OK; - type = yang_dnode_get_enum(args->dnode, "./type"); - name = yang_dnode_get_string(args->dnode, "./name"); + type = yang_dnode_get_enum(args->dnode, "type"); + name = yang_dnode_get_string(args->dnode, "name"); switch (type) { case 0: /* ipv4 */ pl = prefix_list_get(AFI_IP, 0, name); @@ -1201,7 +1201,7 @@ static int lib_prefix_list_entry_create(struct nb_cb_create_args *args) pl = nb_running_get_entry(args->dnode, NULL, true); ple = prefix_list_entry_new(); ple->pl = pl; - ple->seq = yang_dnode_get_uint32(args->dnode, "./sequence"); + ple->seq = yang_dnode_get_uint32(args->dnode, "sequence"); prefix_list_entry_set_empty(ple); nb_running_set_entry(args->dnode, ple); diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c index c4ead01bf6..761969266a 100644 --- a/lib/frr_pthread.c +++ b/lib/frr_pthread.c @@ -5,6 +5,9 @@ */ #include <zebra.h> + +#include <signal.h> + #include <pthread.h> #ifdef HAVE_PTHREAD_NP_H #include <pthread_np.h> diff --git a/lib/frrdistance.h b/lib/frrdistance.h new file mode 100644 index 0000000000..d2fa76e610 --- /dev/null +++ b/lib/frrdistance.h @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Zebra distance header + * Copyright (C) 2023 NVIDIA Corporation + * Donald Sharp + * + * Distance related defines. FRR needs a common set + * of values for distance. + */ +#ifndef __FRRDISTANCE_H__ +#define __FRRDISTANCE_H__ + +/* Default Administrative Distance of each protocol. */ +#define ZEBRA_KERNEL_DISTANCE_DEFAULT 0 +#define ZEBRA_CONNECT_DISTANCE_DEFAULT 0 +#define ZEBRA_STATIC_DISTANCE_DEFAULT 1 +#define ZEBRA_RIP_DISTANCE_DEFAULT 120 +#define ZEBRA_RIPNG_DISTANCE_DEFAULT 120 +#define ZEBRA_OSPF_DISTANCE_DEFAULT 110 +#define ZEBRA_OSPF6_DISTANCE_DEFAULT 110 +#define ZEBRA_ISIS_DISTANCE_DEFAULT 115 +#define ZEBRA_IBGP_DISTANCE_DEFAULT 200 +#define ZEBRA_EBGP_DISTANCE_DEFAULT 20 +#define ZEBRA_TABLE_DISTANCE_DEFAULT 15 +#define ZEBRA_TABLEDIRECT_DISTANCE_DEFAULT 14 +#define ZEBRA_EIGRP_DISTANCE_DEFAULT 90 +#define ZEBRA_NHRP_DISTANCE_DEFAULT 10 +#define ZEBRA_LDP_DISTANCE_DEFAULT 150 +#define ZEBRA_BABEL_DISTANCE_DEFAULT 100 +#define ZEBRA_SHARP_DISTANCE_DEFAULT 150 +#define ZEBRA_PBR_DISTANCE_DEFAULT 200 +#define ZEBRA_OPENFABRIC_DISTANCE_DEFAULT 115 +#define ZEBRA_MAX_DISTANCE_DEFAULT 255 + +#endif diff --git a/lib/frrevent.h b/lib/frrevent.h index 2b0c52bb51..998727f079 100644 --- a/lib/frrevent.h +++ b/lib/frrevent.h @@ -18,6 +18,8 @@ extern "C" { #endif +#define CONSUMED_TIME_CHECK 5000000 + extern bool cputime_enabled; extern unsigned long cputime_threshold; /* capturing wallclock time is always enabled since it is fast (reading @@ -65,6 +67,8 @@ struct xref_eventsched { uint32_t event_type; }; +PREDECL_HASH(cpu_records); + /* Master of the theads. */ struct event_loop { char *name; @@ -76,7 +80,7 @@ struct event_loop { struct list *cancel_req; bool canceled; pthread_cond_t cancel_cond; - struct hash *cpu_record; + struct cpu_records_head cpu_records[1]; int io_pipe[2]; int fd_limit; struct fd_handler handler; @@ -87,6 +91,8 @@ struct event_loop { pthread_mutex_t mtx; pthread_t owner; + nfds_t last_read; + bool ready_run_loop; RUSAGE_T last_getrusage; }; @@ -130,6 +136,8 @@ struct event { #endif struct cpu_event_history { + struct cpu_records_item item; + void (*func)(struct event *e); atomic_size_t total_cpu_warn; atomic_size_t total_wall_warn; @@ -147,6 +155,12 @@ struct cpu_event_history { /* Struct timeval's tv_usec one second value. */ #define TIMER_SECOND_MICRO 1000000L +static inline unsigned long timeval_elapsed(struct timeval a, struct timeval b) +{ + return (((a.tv_sec - b.tv_sec) * TIMER_SECOND_MICRO) + + (a.tv_usec - b.tv_usec)); +} + /* Event yield time. */ #define EVENT_YIELD_TIME_SLOT 10 * 1000L /* 10ms */ @@ -195,7 +209,7 @@ struct cpu_event_history { _xref_t_a(timer_tv, TIMER, m, f, a, v, t) #define event_add_event(m, f, a, v, t) _xref_t_a(event, EVENT, m, f, a, v, t) -#define event_execute(m, f, a, v) \ +#define event_execute(m, f, a, v, p) \ ({ \ static const struct xref_eventsched _xref __attribute__( \ (used)) = { \ @@ -205,7 +219,7 @@ struct cpu_event_history { .event_type = EVENT_EXECUTE, \ }; \ XREF_LINK(_xref.xref); \ - _event_execute(&_xref, m, f, a, v); \ + _event_execute(&_xref, m, f, a, v, p); \ }) /* end */ /* Prototypes. */ @@ -241,7 +255,8 @@ extern void _event_add_event(const struct xref_eventsched *xref, extern void _event_execute(const struct xref_eventsched *xref, struct event_loop *master, - void (*fn)(struct event *), void *arg, int val); + void (*fn)(struct event *), void *arg, int val, + struct event **eref); extern void event_cancel(struct event **event); extern void event_cancel_async(struct event_loop *m, struct event **eptr, diff --git a/lib/frrlua.c b/lib/frrlua.c index 5b49d32a9c..2cab1a5460 100644 --- a/lib/frrlua.c +++ b/lib/frrlua.c @@ -259,31 +259,12 @@ void *lua_tosockunion(lua_State *L, int idx) return su; } -void lua_pushtimet(lua_State *L, const time_t *time) -{ - lua_pushinteger(L, *time); -} - -void lua_decode_timet(lua_State *L, int idx, time_t *t) -{ - *t = lua_tointeger(L, idx); - lua_pop(L, 1); -} - -void *lua_totimet(lua_State *L, int idx) -{ - time_t *t = XCALLOC(MTYPE_SCRIPT_RES, sizeof(time_t)); - - lua_decode_timet(L, idx, t); - return t; -} - -void lua_pushintegerp(lua_State *L, const long long *num) +void lua_pushintegerp(lua_State *L, const int *num) { lua_pushinteger(L, *num); } -void lua_decode_integerp(lua_State *L, int idx, long long *num) +void lua_decode_integerp(lua_State *L, int idx, int *num) { int isnum; *num = lua_tonumberx(L, idx, &isnum); @@ -293,7 +274,7 @@ void lua_decode_integerp(lua_State *L, int idx, long long *num) void *lua_tointegerp(lua_State *L, int idx) { - long long *num = XCALLOC(MTYPE_SCRIPT_RES, sizeof(long long)); + int *num = XCALLOC(MTYPE_SCRIPT_RES, sizeof(int)); lua_decode_integerp(L, idx, num); return num; @@ -351,32 +332,39 @@ void lua_pushnexthop_group(lua_State *L, const struct nexthop_group *ng) } } -void lua_decode_stringp(lua_State *L, int idx, char *str) +void lua_pushlonglongp(lua_State *L, const long long *num) { - strlcpy(str, lua_tostring(L, idx), strlen(str) + 1); + /* lua library function; this can take a long long */ + lua_pushinteger(L, *num); +} + +void lua_decode_longlongp(lua_State *L, int idx, long long *num) +{ + int isnum; + *num = lua_tonumberx(L, idx, &isnum); lua_pop(L, 1); + assert(isnum); } -void *lua_tostringp(lua_State *L, int idx) +void *lua_tolonglongp(lua_State *L, int idx) { - char *string = XSTRDUP(MTYPE_SCRIPT_RES, lua_tostring(L, idx)); + long long *num = XCALLOC(MTYPE_SCRIPT_RES, sizeof(long long)); - return string; + lua_decode_longlongp(L, idx, num); + return num; } -/* - * Decoder for const values, since we cannot modify them. - */ -void lua_decode_noop(lua_State *L, int idx, const void *ptr) +void lua_decode_stringp(lua_State *L, int idx, char *str) { + strlcpy(str, lua_tostring(L, idx), strlen(str) + 1); + lua_pop(L, 1); } - -/* - * Noop decoder for int. - */ -void lua_decode_integer_noop(lua_State *L, int idx, int i) +void *lua_tostringp(lua_State *L, int idx) { + char *string = XSTRDUP(MTYPE_SCRIPT_RES, lua_tostring(L, idx)); + + return string; } /* diff --git a/lib/frrlua.h b/lib/frrlua.h index bf6eb5fd91..dc0f4d9986 100644 --- a/lib/frrlua.h +++ b/lib/frrlua.h @@ -99,21 +99,6 @@ void lua_pushethaddr(lua_State *L, const struct ethaddr *addr); */ void *lua_toin6addr(lua_State *L, int idx); -/* - * Converts a time_t to a Lua value and pushes it on the stack. - */ -void lua_pushtimet(lua_State *L, const time_t *time); - -void lua_decode_timet(lua_State *L, int idx, time_t *time); - -/* - * Converts the Lua value at idx to a time_t. - * - * Returns: - * time_t allocated with MTYPE_TMP. - */ -void *lua_totimet(lua_State *L, int idx); - /* * Converts a sockunion to a Lua value and pushes it on the stack. */ @@ -136,9 +121,9 @@ void lua_pushnexthop(lua_State *L, const struct nexthop *nexthop); /* * Converts an int to a Lua value and pushes it on the stack. */ -void lua_pushintegerp(lua_State *L, const long long *num); +void lua_pushintegerp(lua_State *L, const int *num); -void lua_decode_integerp(lua_State *L, int idx, long long *num); +void lua_decode_integerp(lua_State *L, int idx, int *num); /* * Converts the Lua value at idx to an int. @@ -148,6 +133,21 @@ void lua_decode_integerp(lua_State *L, int idx, long long *num); */ void *lua_tointegerp(lua_State *L, int idx); +/* + * Converts a long long to a Lua value and pushes it on the stack. + */ +void lua_pushlonglongp(lua_State *L, const long long *num); + +void lua_decode_longlongp(lua_State *L, int idx, long long *num); + +/* + * Converts the Lua value at idx to a long long. + * + * Returns: + * long long allocated with MTYPE_TMP. + */ +void *lua_tolonglongp(lua_State *L, int idx); + void lua_decode_stringp(lua_State *L, int idx, char *str); /* @@ -158,13 +158,6 @@ void lua_decode_stringp(lua_State *L, int idx, char *str); */ void *lua_tostringp(lua_State *L, int idx); -/* - * No-op decoders - */ -void lua_decode_noop(lua_State *L, int idx, const void *ptr); - -void lua_decode_integer_noop(lua_State *L, int idx, int i); - /* * Retrieve an integer from table on the top of the stack. * diff --git a/lib/frrscript.c b/lib/frrscript.c index 1b99c7e2c6..acdd1df67b 100644 --- a/lib/frrscript.c +++ b/lib/frrscript.c @@ -25,6 +25,8 @@ DEFINE_MTYPE_STATIC(LIB, SCRIPT, "Scripting"); struct frrscript_names_head frrscript_names_hash; +void _lua_decode_noop(lua_State *L, ...) {} + /* * Wrapper for frrscript_names_add * Use this to register hook calls when a daemon starts up @@ -133,9 +135,6 @@ struct frrscript_codec frrscript_codecs_lib[] = { {.typename = "sockunion", .encoder = (encoder_func)lua_pushsockunion, .decoder = lua_tosockunion}, - {.typename = "time_t", - .encoder = (encoder_func)lua_pushtimet, - .decoder = lua_totimet}, {}}; /* Type codecs */ diff --git a/lib/frrscript.h b/lib/frrscript.h index 7ba4f0cbdb..ce313a1b63 100644 --- a/lib/frrscript.h +++ b/lib/frrscript.h @@ -180,6 +180,11 @@ void frrscript_fini(void); assert(lua_gettop(lfs->L) == 1); \ } while (0) +/* + * Noop function. Used below where we need a noop decoder for any type. + */ +void _lua_decode_noop(lua_State *, ...); + /* * Maps the type of value to its encoder/decoder. * Add new mappings here. @@ -192,13 +197,14 @@ void frrscript_fini(void); #define ENCODE_ARGS_WITH_STATE(L, value) \ _Generic((value), \ int : lua_pushinteger, \ -long long * : lua_pushintegerp, \ +int * : lua_pushintegerp, \ +long long : lua_pushinteger, \ +long long * : lua_pushlonglongp, \ struct prefix * : lua_pushprefix, \ struct interface * : lua_pushinterface, \ struct in_addr * : lua_pushinaddr, \ struct in6_addr * : lua_pushin6addr, \ union sockunion * : lua_pushsockunion, \ -time_t * : lua_pushtimet, \ char * : lua_pushstring_wrapper, \ struct attr * : lua_pushattr, \ struct peer * : lua_pushpeer, \ @@ -212,23 +218,16 @@ struct zebra_dplane_ctx * : lua_pushzebra_dplane_ctx \ #define DECODE_ARGS_WITH_STATE(L, value) \ _Generic((value), \ -int : lua_decode_integer_noop, \ -long long * : lua_decode_integerp, \ +int * : lua_decode_integerp, \ +long long * : lua_decode_longlongp, \ struct prefix * : lua_decode_prefix, \ struct interface * : lua_decode_interface, \ struct in_addr * : lua_decode_inaddr, \ struct in6_addr * : lua_decode_in6addr, \ union sockunion * : lua_decode_sockunion, \ -time_t * : lua_decode_timet, \ char * : lua_decode_stringp, \ struct attr * : lua_decode_attr, \ -struct peer * : lua_decode_noop, \ -const struct prefix * : lua_decode_noop, \ -const struct ipaddr * : lua_decode_noop, \ -const struct ethaddr * : lua_decode_noop, \ -const struct nexthop_group * : lua_decode_noop, \ -const struct nexthop * : lua_decode_noop, \ -struct zebra_dplane_ctx * : lua_decode_noop \ +default : _lua_decode_noop \ )((L), -1, (value)) /* diff --git a/lib/frrsendmmsg.h b/lib/frrsendmmsg.h new file mode 100644 index 0000000000..ea63d139aa --- /dev/null +++ b/lib/frrsendmmsg.h @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * FRR sendmmsg wrapper + * Copyright (C) 2024 by Nvidia, Inc. + * Donald Sharp + */ +#ifndef __FRRSENDMMSG_H__ +#define __FRRSENDMMSG_H__ + +#if !defined(HAVE_STRUCT_MMSGHDR_MSG_HDR) || !defined(HAVE_SENDMMSG) +/* avoid conflicts in case we have partial support */ +#define mmsghdr frr_mmsghdr +#define sendmmsg frr_sendmmsg + +struct mmsghdr { + struct msghdr msg_hdr; + unsigned int msg_len; +}; + +/* just go 1 at a time here, the loop this is used in will handle the rest */ +static inline int sendmmsg(int fd, struct mmsghdr *mmh, unsigned int len, + int flags) +{ + int rv = sendmsg(fd, &mmh->msg_hdr, 0); + + return rv > 0 ? 1 : rv; +} +#endif + +#endif diff --git a/lib/frrstr.c b/lib/frrstr.c index e5440c5093..1e743d4b0c 100644 --- a/lib/frrstr.c +++ b/lib/frrstr.c @@ -3,6 +3,7 @@ * FRR string processing utilities. * Copyright (C) 2018 Cumulus Networks, Inc. * Quentin Young + * Copyright (c) 2023, LabN Consulting, L.L.C. */ #include "zebra.h" @@ -225,3 +226,47 @@ char *frrstr_hex(char *buff, size_t bufsiz, const uint8_t *str, size_t num) return buff; } + +const char *frrstr_skip_over_char(const char *s, int skipc) +{ + int c, quote = 0; + + while ((c = *s++)) { + if (c == '\\') { + if (!*s++) + return NULL; + continue; + } + if (quote) { + if (c == quote) + quote = 0; + continue; + } + if (c == skipc) + return s; + if (c == '"' || c == '\'') + quote = c; + } + return NULL; +} + +/* + * Advance backward in string until reaching the char `toc` + * if beginning of string is reached w/o finding char return NULL + * + * /foo/bar'baz/booz'/foo + */ +const char *frrstr_back_to_char(const char *s, int toc) +{ + const char *next = s; + const char *prev = NULL; + + if (s[0] == 0) + return NULL; + if (!strpbrk(s, "'\"\\")) + return strrchr(s, toc); + while ((next = frrstr_skip_over_char(next, toc))) + prev = next - 1; + return prev; +} + diff --git a/lib/frrstr.h b/lib/frrstr.h index 19ba09e213..33a4992001 100644 --- a/lib/frrstr.h +++ b/lib/frrstr.h @@ -3,6 +3,7 @@ * FRR string processing utilities. * Copyright (C) 2018 Cumulus Networks, Inc. * Quentin Young + * Copyright (c) 2023, LabN Consulting, L.L.C. */ #ifndef _FRRSTR_H_ @@ -166,6 +167,19 @@ int all_digit(const char *str); */ char *frrstr_hex(char *buff, size_t bufsiz, const uint8_t *str, size_t num); +/* + * Advance past a given char `skipc` in a string, while honoring quoting and + * backslash escapes (i.e., ignore `skipc` which occur in quoted sections). + */ +const char *frrstr_skip_over_char(const char *s, int skipc); + +/* + * Advance back from end to a given char `toc` in a string, while honoring + * quoting and backslash escapes. `toc` chars inside quote or escaped are + * ignored. + */ +const char *frrstr_back_to_char(const char *s, int toc); + #ifdef __cplusplus } #endif diff --git a/lib/if.c b/lib/if.c index 6f567861d1..a68f7f21e1 100644 --- a/lib/if.c +++ b/lib/if.c @@ -42,15 +42,14 @@ RB_GENERATE(if_index_head, interface, index_entry, if_cmp_index_func); DEFINE_QOBJ_TYPE(interface); -DEFINE_HOOK(if_add, (struct interface * ifp), (ifp)); -DEFINE_KOOH(if_del, (struct interface * ifp), (ifp)); +DEFINE_HOOK(if_add, (struct interface *ifp), (ifp)); +DEFINE_KOOH(if_del, (struct interface *ifp), (ifp)); -static struct interface_master{ - int (*create_hook)(struct interface *ifp); - int (*up_hook)(struct interface *ifp); - int (*down_hook)(struct interface *ifp); - int (*destroy_hook)(struct interface *ifp); -} ifp_master = { 0, }; +DEFINE_HOOK(if_real, (struct interface *ifp), (ifp)); +DEFINE_KOOH(if_unreal, (struct interface *ifp), (ifp)); + +DEFINE_HOOK(if_up, (struct interface *ifp), (ifp)); +DEFINE_KOOH(if_down, (struct interface *ifp), (ifp)); /* Compare interface names, returning an integer greater than, equal to, or * less than 0, (following the strcmp convention), according to the @@ -98,8 +97,8 @@ int if_cmp_name_func(const char *p1, const char *p2) if (!*p2) return 1; - x1 = strtol(p1, (char **)&tmp1, 10); - x2 = strtol(p2, (char **)&tmp2, 10); + x1 = strtol(p1, &tmp1, 10); + x2 = strtol(p2, &tmp2, 10); /* let's compare numbers now */ if (x1 < x2) @@ -165,8 +164,7 @@ static struct interface *if_new(struct vrf *vrf) ifp->vrf = vrf; - ifp->connected = list_new(); - ifp->connected->del = ifp_connected_free; + if_connected_init(ifp->connected); ifp->nbr_connected = list_new(); ifp->nbr_connected->del = (void (*)(void *))nbr_connected_free; @@ -180,14 +178,12 @@ static struct interface *if_new(struct vrf *vrf) void if_new_via_zapi(struct interface *ifp) { - if (ifp_master.create_hook) - (*ifp_master.create_hook)(ifp); + hook_call(if_real, ifp); } void if_destroy_via_zapi(struct interface *ifp) { - if (ifp_master.destroy_hook) - (*ifp_master.destroy_hook)(ifp); + hook_call(if_unreal, ifp); ifp->oldifindex = ifp->ifindex; if_set_index(ifp, IFINDEX_INTERNAL); @@ -198,14 +194,12 @@ void if_destroy_via_zapi(struct interface *ifp) void if_up_via_zapi(struct interface *ifp) { - if (ifp_master.up_hook) - (*ifp_master.up_hook)(ifp); + hook_call(if_up, ifp); } void if_down_via_zapi(struct interface *ifp) { - if (ifp_master.down_hook) - (*ifp_master.down_hook)(ifp); + hook_call(if_down, ifp); } static struct interface *if_create_name(const char *name, struct vrf *vrf) @@ -248,11 +242,14 @@ void if_update_to_new_vrf(struct interface *ifp, vrf_id_t vrf_id) /* Delete interface structure. */ void if_delete_retain(struct interface *ifp) { + struct connected *ifc; + hook_call(if_del, ifp); QOBJ_UNREG(ifp); /* Free connected address list */ - list_delete_all_node(ifp->connected); + while ((ifc = if_connected_pop(ifp->connected))) + ifp_connected_free(ifc); /* Free connected nbr address list */ list_delete_all_node(ifp->nbr_connected); @@ -270,7 +267,7 @@ void if_delete(struct interface **ifp) if_delete_retain(ptr); - list_delete(&ptr->connected); + if_connected_fini(ptr->connected); list_delete(&ptr->nbr_connected); if_link_params_free(ptr); @@ -367,8 +364,7 @@ struct interface *if_lookup_by_name(const char *name, vrf_id_t vrf_id) struct vrf *vrf = vrf_lookup_by_id(vrf_id); struct interface if_tmp; - if (!vrf || !name - || strnlen(name, INTERFACE_NAMSIZ) == INTERFACE_NAMSIZ) + if (!vrf || !name || strnlen(name, IFNAMSIZ) == IFNAMSIZ) return NULL; strlcpy(if_tmp.name, name, sizeof(if_tmp.name)); @@ -379,7 +375,7 @@ struct interface *if_lookup_by_name_vrf(const char *name, struct vrf *vrf) { struct interface if_tmp; - if (!name || strnlen(name, INTERFACE_NAMSIZ) == INTERFACE_NAMSIZ) + if (!name || strnlen(name, IFNAMSIZ) == IFNAMSIZ) return NULL; strlcpy(if_tmp.name, name, sizeof(if_tmp.name)); @@ -391,7 +387,7 @@ static struct interface *if_lookup_by_name_all_vrf(const char *name) struct vrf *vrf; struct interface *ifp; - if (!name || strnlen(name, INTERFACE_NAMSIZ) == INTERFACE_NAMSIZ) + if (!name || strnlen(name, IFNAMSIZ) == IFNAMSIZ) return NULL; RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { @@ -433,7 +429,6 @@ struct interface *if_lookup_address_local(const void *src, int family, vrf_id_t vrf_id) { struct vrf *vrf = vrf_lookup_by_id(vrf_id); - struct listnode *cnode; struct interface *ifp, *best_down = NULL; struct prefix *p; struct connected *c; @@ -442,7 +437,7 @@ struct interface *if_lookup_address_local(const void *src, int family, return NULL; FOR_ALL_INTERFACES (vrf, ifp) { - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) { + frr_each (if_connected, ifp->connected, c) { p = c->address; if (!p || p->family != family) @@ -474,7 +469,6 @@ struct connected *if_lookup_address(const void *matchaddr, int family, struct vrf *vrf = vrf_lookup_by_id(vrf_id); struct prefix addr; int bestlen = 0; - struct listnode *cnode; struct interface *ifp; struct connected *c; struct connected *match; @@ -493,7 +487,7 @@ struct connected *if_lookup_address(const void *matchaddr, int family, match = NULL; FOR_ALL_INTERFACES (vrf, ifp) { - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) { + frr_each (if_connected, ifp->connected, c) { if (c->address && (c->address->family == AF_INET) && prefix_match(CONNECTED_PREFIX(c), &addr) && (c->address->prefixlen > bestlen)) { @@ -509,12 +503,11 @@ struct connected *if_lookup_address(const void *matchaddr, int family, struct interface *if_lookup_prefix(const struct prefix *prefix, vrf_id_t vrf_id) { struct vrf *vrf = vrf_lookup_by_id(vrf_id); - struct listnode *cnode; struct interface *ifp; struct connected *c; FOR_ALL_INTERFACES (vrf, ifp) { - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) { + frr_each (if_connected, ifp->connected, c) { if (prefix_cmp(c->address, prefix) == 0) { return ifp; } @@ -781,10 +774,9 @@ const char *if_flag_dump(unsigned long flag) /* For debugging */ static void if_dump(const struct interface *ifp) { - struct listnode *node; - struct connected *c __attribute__((unused)); + const struct connected *c; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, c)) + frr_each (if_connected_const, ifp->connected, c) zlog_info( "Interface %s vrf %s(%u) index %d metric %d mtu %d mtu6 %d %s", ifp->name, ifp->vrf->name, ifp->vrf->vrf_id, @@ -911,11 +903,10 @@ static int connected_same_prefix(const struct prefix *p1, /* count the number of connected addresses that are in the given family */ unsigned int connected_count_by_family(struct interface *ifp, int family) { - struct listnode *cnode; struct connected *connected; unsigned int cnt = 0; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) + frr_each (if_connected, ifp->connected, connected) if (connected->address->family == family) cnt++; @@ -925,14 +916,9 @@ unsigned int connected_count_by_family(struct interface *ifp, int family) struct connected *connected_lookup_prefix_exact(struct interface *ifp, const struct prefix *p) { - struct listnode *node; - struct listnode *next; struct connected *ifc; - for (node = listhead(ifp->connected); node; node = next) { - ifc = listgetdata(node); - next = node->next; - + frr_each (if_connected, ifp->connected, ifc) { if (connected_same_prefix(ifc->address, p)) return ifc; } @@ -942,17 +928,12 @@ struct connected *connected_lookup_prefix_exact(struct interface *ifp, struct connected *connected_delete_by_prefix(struct interface *ifp, struct prefix *p) { - struct listnode *node; - struct listnode *next; struct connected *ifc; /* In case of same prefix come, replace it with new one. */ - for (node = listhead(ifp->connected); node; node = next) { - ifc = listgetdata(node); - next = node->next; - + frr_each_safe (if_connected, ifp->connected, ifc) { if (connected_same_prefix(ifc->address, p)) { - listnode_delete(ifp->connected, ifc); + if_connected_del(ifp->connected, ifc); return ifc; } } @@ -964,13 +945,12 @@ struct connected *connected_delete_by_prefix(struct interface *ifp, struct connected *connected_lookup_prefix(struct interface *ifp, const struct prefix *addr) { - struct listnode *cnode; struct connected *c; struct connected *match; match = NULL; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) { + frr_each (if_connected, ifp->connected, c) { if (c->address && (c->address->family == addr->family) && prefix_match(CONNECTED_PREFIX(c), addr) && (!match @@ -1001,16 +981,15 @@ struct connected *connected_add_by_prefix(struct interface *ifp, } /* Add connected address to the interface. */ - listnode_add(ifp->connected, ifc); + if_connected_add_tail(ifp->connected, ifc); return ifc; } struct connected *connected_get_linklocal(struct interface *ifp) { - struct listnode *n; struct connected *c = NULL; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, n, c)) { + frr_each (if_connected, ifp->connected, c) { if (c->address->family == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&c->address->u.prefix6)) break; @@ -1340,14 +1319,14 @@ static void cli_show_interface(struct vty *vty, const struct lyd_node *dnode, char ifname[XPATH_MAXLEN]; char vrfname[XPATH_MAXLEN]; - netns_ifname_split(yang_dnode_get_string(dnode, "./name"), + netns_ifname_split(yang_dnode_get_string(dnode, "name"), ifname, vrfname); vty_out(vty, "interface %s", ifname); if (!strmatch(vrfname, VRF_DEFAULT_NAME)) vty_out(vty, " vrf %s", vrfname); } else { - const char *ifname = yang_dnode_get_string(dnode, "./name"); + const char *ifname = yang_dnode_get_string(dnode, "name"); vty_out(vty, "interface %s", ifname); } @@ -1477,17 +1456,6 @@ void if_cmd_init_default(void) if_cmd_init(if_nb_config_write); } -void if_zapi_callbacks(int (*create)(struct interface *ifp), - int (*up)(struct interface *ifp), - int (*down)(struct interface *ifp), - int (*destroy)(struct interface *ifp)) -{ - ifp_master.create_hook = create; - ifp_master.up_hook = up; - ifp_master.down_hook = down; - ifp_master.destroy_hook = destroy; -} - /* ------- Northbound callbacks ------- */ /* @@ -1498,7 +1466,7 @@ static int lib_interface_create(struct nb_cb_create_args *args) const char *ifname; struct interface *ifp; - ifname = yang_dnode_get_string(args->dnode, "./name"); + ifname = yang_dnode_get_string(args->dnode, "name"); switch (args->event) { case NB_EV_VALIDATE: diff --git a/lib/if.h b/lib/if.h index c6b4fd216a..fd5f6f7502 100644 --- a/lib/if.h +++ b/lib/if.h @@ -88,8 +88,6 @@ enum zebra_link_type { FreeBSD define value in /usr/include/net/if.h. #define IFNAMSIZ 16 */ - -#define INTERFACE_NAMSIZ IFNAMSIZ #define INTERFACE_HWADDR_MAX 20 typedef signed int ifindex_t; @@ -206,6 +204,8 @@ struct if_link_params { #define INTERFACE_LINK_PARAMS_SIZE sizeof(struct if_link_params) #define HAS_LINK_PARAMS(ifp) ((ifp)->link_params != NULL) +PREDECL_DLIST(if_connected); + /* Interface structure */ struct interface { RB_ENTRY(interface) name_entry, index_entry; @@ -218,7 +218,7 @@ struct interface { To delete, just set ifindex to IFINDEX_INTERNAL to indicate that the interface does not exist in the kernel. */ - char name[INTERFACE_NAMSIZ]; + char name[IFNAMSIZ]; /* Interface index (should be IFINDEX_INTERNAL for non-kernel or deleted interfaces). @@ -252,6 +252,9 @@ struct interface { /* Interface Speed in Mb/s */ uint32_t speed; + /* TX queue len */ + uint32_t txqlen; + /* Interface MTU. */ unsigned int mtu; /* IPv4 MTU */ unsigned int @@ -272,12 +275,8 @@ struct interface { /* description of the interface. */ char *desc; - /* Distribute list. */ - void *distribute_in; - void *distribute_out; - /* Connected address list. */ - struct list *connected; + struct if_connected_head connected[1]; /* Neighbor connected address list. */ struct list *nbr_connected; @@ -372,9 +371,6 @@ DECLARE_QOBJ_TYPE(interface); if (vrf) \ RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) -#define FOR_ALL_INTERFACES_ADDRESSES(ifp, connected, node) \ - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) - /* called from the library code whenever interfaces are created/deleted * note: interfaces may not be fully realized at that point; also they * may not exist in the system (ifindex = IFINDEX_INTERNAL) @@ -383,13 +379,34 @@ DECLARE_QOBJ_TYPE(interface); * can use 1000+ so they run after the daemon has initialised daemon-specific * interface data */ -DECLARE_HOOK(if_add, (struct interface * ifp), (ifp)); -DECLARE_KOOH(if_del, (struct interface * ifp), (ifp)); +DECLARE_HOOK(if_add, (struct interface *ifp), (ifp)); +DECLARE_KOOH(if_del, (struct interface *ifp), (ifp)); + +/* called (in daemons) when ZAPI tells us the interface actually exists + * (ifindex != IFINDEX_INTERNAL) + * + * WARNING: these 2 hooks NEVER CALLED inside zebra! + */ +DECLARE_HOOK(if_real, (struct interface *ifp), (ifp)); +DECLARE_KOOH(if_unreal, (struct interface *ifp), (ifp)); + +/* called (in daemons) on state changes on interfaces. Whether this is admin + * state (= pure config) or carrier state (= hardware link plugged) depends on + * zebra's "link-detect" configuration. By default, it's carrier state, so + * this won't happen until the interface actually has a link. + * + * WARNING: these 2 hooks NEVER CALLED inside zebra! + */ +DECLARE_HOOK(if_up, (struct interface *ifp), (ifp)); +DECLARE_KOOH(if_down, (struct interface *ifp), (ifp)); + #define METRIC_MAX (~0) /* Connected address structure. */ struct connected { + struct if_connected_item item; + /* Attached interface. */ struct interface *ifp; @@ -417,6 +434,8 @@ struct connected { #define ZEBRA_IFA_SECONDARY (1 << 0) #define ZEBRA_IFA_PEER (1 << 1) #define ZEBRA_IFA_UNNUMBERED (1 << 2) +#define ZEBRA_IFA_NOPREFIXROUTE (1 << 3) + /* N.B. the ZEBRA_IFA_PEER flag should be set if and only if a peer address has been configured. If this flag is set, the destination field must contain the peer address. @@ -439,6 +458,8 @@ struct connected { uint32_t metric; }; +DECLARE_DLIST(if_connected, struct connected, item); + /* Nbr Connected address structure. */ struct nbr_connected { /* Attached interface. */ @@ -509,9 +530,9 @@ extern int if_cmp_name_func(const char *p1, const char *p2); * This is useful for vrf route-leaking. So more than anything * else think before you use VRF_UNKNOWN */ -extern void if_update_to_new_vrf(struct interface *, vrf_id_t vrf_id); +extern void if_update_to_new_vrf(struct interface *ifp, vrf_id_t vrf_id); -extern struct interface *if_lookup_by_index(ifindex_t, vrf_id_t vrf_id); +extern struct interface *if_lookup_by_index(ifindex_t ifindex, vrf_id_t vrf_id); extern struct interface *if_vrf_lookup_by_index_next(ifindex_t ifindex, vrf_id_t vrf_id); extern struct interface *if_lookup_address_local(const void *matchaddr, @@ -542,7 +563,7 @@ extern int if_set_index(struct interface *ifp, ifindex_t ifindex); /* Delete the interface, but do not free the structure, and leave it in the interface list. It is often advisable to leave the pseudo interface structure because there may be configuration information attached. */ -extern void if_delete_retain(struct interface *); +extern void if_delete_retain(struct interface *ifp); /* Delete and free the interface structure: calls if_delete_retain and then deletes it from the interface list and frees the structure. */ @@ -560,13 +581,13 @@ extern int if_is_pointopoint(const struct interface *ifp); extern int if_is_multicast(const struct interface *ifp); extern void if_terminate(struct vrf *vrf); extern void if_dump_all(void); -extern const char *if_flag_dump(unsigned long); -extern const char *if_link_type_str(enum zebra_link_type); +extern const char *if_flag_dump(unsigned long flags); +extern const char *if_link_type_str(enum zebra_link_type zlt); /* Please use ifindex2ifname instead of if_indextoname where possible; ifindex2ifname uses internal interface info, whereas if_indextoname must make a system call. */ -extern const char *ifindex2ifname(ifindex_t, vrf_id_t vrf_id); +extern const char *ifindex2ifname(ifindex_t ifindex, vrf_id_t vrf_id); /* Please use ifname2ifindex instead of if_nametoindex where possible; ifname2ifindex uses internal interface info, whereas if_nametoindex must @@ -576,19 +597,20 @@ extern ifindex_t ifname2ifindex(const char *ifname, vrf_id_t vrf_id); /* Connected address functions. */ extern struct connected *connected_new(void); extern void connected_free(struct connected **connected); -extern void connected_add(struct interface *, struct connected *); -extern struct connected * -connected_add_by_prefix(struct interface *, struct prefix *, struct prefix *); -extern struct connected *connected_delete_by_prefix(struct interface *, - struct prefix *); -extern struct connected *connected_lookup_prefix(struct interface *, - const struct prefix *); -extern struct connected *connected_lookup_prefix_exact(struct interface *, - const struct prefix *); -extern unsigned int connected_count_by_family(struct interface *, int family); +extern struct connected *connected_add_by_prefix(struct interface *ifp, + struct prefix *p, + struct prefix *dest); +extern struct connected *connected_delete_by_prefix(struct interface *ifp, + struct prefix *p); +extern struct connected *connected_lookup_prefix(struct interface *ifp, + const struct prefix *p); +extern struct connected *connected_lookup_prefix_exact(struct interface *ifp, + const struct prefix *p); +extern unsigned int connected_count_by_family(struct interface *ifp, int family); extern struct nbr_connected *nbr_connected_new(void); -extern void nbr_connected_free(struct nbr_connected *); -struct nbr_connected *nbr_connected_check(struct interface *, struct prefix *); +extern void nbr_connected_free(struct nbr_connected *connected); +struct nbr_connected *nbr_connected_check(struct interface *ifp, + struct prefix *p); struct connected *connected_get_linklocal(struct interface *ifp); /* link parameters */ @@ -596,10 +618,10 @@ bool if_link_params_cmp(struct if_link_params *iflp1, struct if_link_params *iflp2); void if_link_params_copy(struct if_link_params *dst, struct if_link_params *src); -struct if_link_params *if_link_params_get(struct interface *); +struct if_link_params *if_link_params_get(struct interface *ifp); struct if_link_params *if_link_params_enable(struct interface *ifp); struct if_link_params *if_link_params_init(struct interface *ifp); -void if_link_params_free(struct interface *); +void if_link_params_free(struct interface *ifp); /* Northbound. */ struct vty; @@ -607,10 +629,6 @@ extern void if_vty_config_start(struct vty *vty, struct interface *ifp); extern void if_vty_config_end(struct vty *vty); extern void if_cmd_init(int (*config_write)(struct vty *)); extern void if_cmd_init_default(void); -extern void if_zapi_callbacks(int (*create)(struct interface *ifp), - int (*up)(struct interface *ifp), - int (*down)(struct interface *ifp), - int (*destroy)(struct interface *ifp)); extern void if_new_via_zapi(struct interface *ifp); extern void if_up_via_zapi(struct interface *ifp); diff --git a/lib/if_rmap.c b/lib/if_rmap.c index 42e162072f..5fe5061a3c 100644 --- a/lib/if_rmap.c +++ b/lib/if_rmap.c @@ -243,14 +243,14 @@ DEFPY_YANG(no_if_ipv6_route_map, no_if_ipv6_route_map_cmd, void cli_show_if_route_map(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - if (yang_dnode_exists(dnode, "./in-route-map")) + if (yang_dnode_exists(dnode, "in-route-map")) vty_out(vty, " route-map %s in %s\n", - yang_dnode_get_string(dnode, "./in-route-map"), - yang_dnode_get_string(dnode, "./interface")); - if (yang_dnode_exists(dnode, "./out-route-map")) + yang_dnode_get_string(dnode, "in-route-map"), + yang_dnode_get_string(dnode, "interface")); + if (yang_dnode_exists(dnode, "out-route-map")) vty_out(vty, " route-map %s out %s\n", - yang_dnode_get_string(dnode, "./out-route-map"), - yang_dnode_get_string(dnode, "./interface")); + yang_dnode_get_string(dnode, "out-route-map"), + yang_dnode_get_string(dnode, "interface")); } void if_rmap_yang_modify_cb(struct if_rmap_ctx *ctx, diff --git a/lib/imsg-buffer.c b/lib/imsg-buffer.c index 4f041ff66e..556e0cf904 100644 --- a/lib/imsg-buffer.c +++ b/lib/imsg-buffer.c @@ -6,6 +6,7 @@ */ #include <zebra.h> +#include <sys/uio.h> #include "queue.h" #include "imsg.h" diff --git a/lib/ipaddr.h b/lib/ipaddr.h index e3ad14d7db..c86e38c867 100644 --- a/lib/ipaddr.h +++ b/lib/ipaddr.h @@ -28,6 +28,7 @@ struct ipaddr { enum ipaddr_type_t ipa_type; union { uint8_t addr; + uint8_t addrbytes[16]; struct in_addr _v4_addr; struct in6_addr _v6_addr; } ip; diff --git a/lib/jhash.c b/lib/jhash.c index 0d561ef3a4..4e02112e09 100644 --- a/lib/jhash.c +++ b/lib/jhash.c @@ -86,34 +86,34 @@ uint32_t jhash(const void *key, uint32_t length, uint32_t initval) switch (len) { case 11: c += ((uint32_t)k[10] << 24); - /* fallthru */ + fallthrough; case 10: c += ((uint32_t)k[9] << 16); - /* fallthru */ + fallthrough; case 9: c += ((uint32_t)k[8] << 8); - /* fallthru */ + fallthrough; case 8: b += ((uint32_t)k[7] << 24); - /* fallthru */ + fallthrough; case 7: b += ((uint32_t)k[6] << 16); - /* fallthru */ + fallthrough; case 6: b += ((uint32_t)k[5] << 8); - /* fallthru */ + fallthrough; case 5: b += k[4]; - /* fallthru */ + fallthrough; case 4: a += ((uint32_t)k[3] << 24); - /* fallthru */ + fallthrough; case 3: a += ((uint32_t)k[2] << 16); - /* fallthru */ + fallthrough; case 2: a += ((uint32_t)k[1] << 8); - /* fallthru */ + fallthrough; case 1: a += k[0]; } @@ -148,7 +148,7 @@ uint32_t jhash2(const uint32_t *k, uint32_t length, uint32_t initval) switch (len) { case 2: b += k[1]; - /* fallthru */ + fallthrough; case 1: a += k[0]; } diff --git a/lib/keychain.c b/lib/keychain.c index 640746bb41..5ff0d1e43e 100644 --- a/lib/keychain.c +++ b/lib/keychain.c @@ -37,6 +37,7 @@ static void keychain_free(struct keychain *keychain) static struct key *key_new(void) { struct key *key = XCALLOC(MTYPE_KEY, sizeof(struct key)); + QOBJ_REG(key, key); return key; } @@ -77,7 +78,7 @@ static int key_cmp_func(void *arg1, void *arg2) static void key_delete_func(struct key *key) { if (key->string) - free(key->string); + XFREE(MTYPE_KEY, key->string); key_free(key); } @@ -1187,6 +1188,20 @@ static const struct cmd_variable_handler keychain_var_handlers[] = { {.completions = NULL} }; +void keychain_terminate(void) +{ + struct keychain *keychain; + + while (listcount(keychain_list)) { + keychain = listgetdata(listhead(keychain_list)); + + listnode_delete(keychain_list, keychain); + keychain_delete(keychain); + } + + list_delete(&keychain_list); +} + void keychain_init(void) { keychain_list = list_new(); diff --git a/lib/keychain.h b/lib/keychain.h index be93275a5d..c96b74ecce 100644 --- a/lib/keychain.h +++ b/lib/keychain.h @@ -82,6 +82,7 @@ struct key { DECLARE_QOBJ_TYPE(key); extern void keychain_init(void); +extern void keychain_terminate(void); extern struct keychain *keychain_lookup(const char *); extern struct key *key_lookup_for_accept(const struct keychain *, uint32_t); extern struct key *key_match_for_accept(const struct keychain *, const char *); diff --git a/lib/ldp_sync.h b/lib/ldp_sync.h index f7601ebf9d..3a6ae5b357 100644 --- a/lib/ldp_sync.h +++ b/lib/ldp_sync.h @@ -59,7 +59,7 @@ struct ldp_igp_sync_if_state { struct ldp_igp_sync_if_state_req { int proto; ifindex_t ifindex; - char name[INTERFACE_NAMSIZ]; + char name[IFNAMSIZ]; }; #ifdef __cplusplus diff --git a/lib/libfrr.c b/lib/libfrr.c index 33237df5fc..d38b4ec4c0 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -6,7 +6,11 @@ */ #include <zebra.h> + +#include <signal.h> +#include <sys/stat.h> #include <sys/un.h> +#include <fcntl.h> #include <sys/types.h> #include <sys/wait.h> @@ -218,7 +222,8 @@ bool frr_zclient_addr(struct sockaddr_storage *sa, socklen_t *sa_len, break; case '6': path++; - /* fallthrough */ + af = AF_INET6; + break; default: af = AF_INET6; break; diff --git a/lib/libospf.h b/lib/libospf.h index 9eaca9a1a8..9a643256c2 100644 --- a/lib/libospf.h +++ b/lib/libospf.h @@ -69,7 +69,8 @@ extern "C" { #define OSPF_MTU_IGNORE_DEFAULT 0 #define OSPF_FAST_HELLO_DEFAULT 0 #define OSPF_P2MP_DELAY_REFLOOD_DEFAULT false - +#define OSPF_OPAQUE_CAPABLE_DEFAULT true +#define OSPF_PREFIX_SUPPRESSION_DEFAULT false #define OSPF_AREA_BACKBONE 0x00000000 /* 0.0.0.0 */ #define OSPF_AREA_RANGE_COST_UNSPEC -1U diff --git a/lib/link_state.c b/lib/link_state.c index 58727a568b..25373bdb20 100644 --- a/lib/link_state.c +++ b/lib/link_state.c @@ -523,7 +523,9 @@ struct ls_vertex *ls_vertex_update(struct ls_ted *ted, struct ls_node *node) if (!ls_node_same(old->node, node)) { ls_node_del(old->node); old->node = node; - } + } else + ls_node_del(node); + old->status = UPDATE; return old; } @@ -805,7 +807,9 @@ struct ls_edge *ls_edge_update(struct ls_ted *ted, if (!ls_attributes_same(old->attributes, attributes)) { ls_attributes_del(old->attributes); old->attributes = attributes; - } + } else + ls_attributes_del(attributes); + old->status = UPDATE; return old; } @@ -902,7 +906,9 @@ struct ls_subnet *ls_subnet_update(struct ls_ted *ted, struct ls_prefix *pref) if (!ls_prefix_same(old->ls_pref, pref)) { ls_prefix_del(old->ls_pref); old->ls_pref = pref; - } + } else + ls_prefix_del(pref); + old->status = UPDATE; return old; } @@ -1138,31 +1144,13 @@ int ls_unregister(struct zclient *zclient, bool server) int ls_request_sync(struct zclient *zclient) { - struct stream *s; - uint16_t flags = 0; - /* Check buffer size */ if (STREAM_SIZE(zclient->obuf) < (ZEBRA_HEADER_SIZE + 3 * sizeof(uint32_t))) return -1; - s = zclient->obuf; - stream_reset(s); - - zclient_create_header(s, ZEBRA_OPAQUE_MESSAGE, VRF_DEFAULT); - - /* Set type and flags */ - stream_putl(s, LINK_STATE_SYNC); - stream_putw(s, flags); - /* Send destination client info */ - stream_putc(s, zclient->redist_default); - stream_putw(s, zclient->instance); - stream_putl(s, zclient->session_id); - - /* Put length into the header at the start of the stream. */ - stream_putw_at(s, 0, stream_get_endp(s)); - - return zclient_send_message(zclient); + /* No data with this message */ + return zclient_send_opaque(zclient, LINK_STATE_SYNC, NULL, 0); } static struct ls_node *ls_parse_node(struct stream *s) @@ -1623,23 +1611,15 @@ int ls_send_msg(struct zclient *zclient, struct ls_message *msg, (ZEBRA_HEADER_SIZE + sizeof(uint32_t) + sizeof(msg))) return -1; + /* Init the message, then encode the data inline. */ + if (dst == NULL) + zapi_opaque_init(zclient, LINK_STATE_UPDATE, flags); + else + zapi_opaque_unicast_init(zclient, LINK_STATE_UPDATE, flags, + dst->proto, dst->instance, + dst->session_id); + s = zclient->obuf; - stream_reset(s); - - zclient_create_header(s, ZEBRA_OPAQUE_MESSAGE, VRF_DEFAULT); - - /* Set sub-type, flags and destination for unicast message */ - stream_putl(s, LINK_STATE_UPDATE); - if (dst != NULL) { - SET_FLAG(flags, ZAPI_OPAQUE_FLAG_UNICAST); - stream_putw(s, flags); - /* Send destination client info */ - stream_putc(s, dst->proto); - stream_putw(s, dst->instance); - stream_putl(s, dst->session_id); - } else { - stream_putw(s, flags); - } /* Format Link State message */ if (ls_format_msg(s, msg) < 0) { @@ -1759,7 +1739,7 @@ struct ls_message *ls_subnet2msg(struct ls_message *msg, struct ls_vertex *ls_msg2vertex(struct ls_ted *ted, struct ls_message *msg, bool delete) { - struct ls_node *node = (struct ls_node *)msg->data.node; + struct ls_node *node = msg->data.node; struct ls_vertex *vertex = NULL; switch (msg->event) { @@ -1799,7 +1779,7 @@ struct ls_vertex *ls_msg2vertex(struct ls_ted *ted, struct ls_message *msg, struct ls_edge *ls_msg2edge(struct ls_ted *ted, struct ls_message *msg, bool delete) { - struct ls_attributes *attr = (struct ls_attributes *)msg->data.attr; + struct ls_attributes *attr = msg->data.attr; struct ls_edge *edge = NULL; switch (msg->event) { @@ -1839,7 +1819,7 @@ struct ls_edge *ls_msg2edge(struct ls_ted *ted, struct ls_message *msg, struct ls_subnet *ls_msg2subnet(struct ls_ted *ted, struct ls_message *msg, bool delete) { - struct ls_prefix *pref = (struct ls_prefix *)msg->data.prefix; + struct ls_prefix *pref = msg->data.prefix; struct ls_subnet *subnet = NULL; switch (msg->event) { diff --git a/lib/log.c b/lib/log.c index 00b897dca1..b18b37efa3 100644 --- a/lib/log.c +++ b/lib/log.c @@ -8,6 +8,10 @@ #include <zebra.h> +#ifdef HAVE_GLIBC_BACKTRACE +#include <execinfo.h> +#endif /* HAVE_GLIBC_BACKTRACE */ + #include "zclient.h" #include "log.h" #include "memory.h" @@ -351,7 +355,6 @@ static const struct zebra_desc_table command_types[] = { DESC_ENTRY(ZEBRA_VRF_ADD), DESC_ENTRY(ZEBRA_VRF_DELETE), DESC_ENTRY(ZEBRA_VRF_LABEL), - DESC_ENTRY(ZEBRA_INTERFACE_VRF_UPDATE), DESC_ENTRY(ZEBRA_BFD_CLIENT_REGISTER), DESC_ENTRY(ZEBRA_BFD_CLIENT_DEREGISTER), DESC_ENTRY(ZEBRA_INTERFACE_ENABLE_RADV), @@ -457,7 +460,9 @@ static const struct zebra_desc_table command_types[] = { DESC_ENTRY(ZEBRA_TC_CLASS_ADD), DESC_ENTRY(ZEBRA_TC_CLASS_DELETE), DESC_ENTRY(ZEBRA_TC_FILTER_ADD), - DESC_ENTRY(ZEBRA_TC_FILTER_DELETE)}; + DESC_ENTRY(ZEBRA_TC_FILTER_DELETE), + DESC_ENTRY(ZEBRA_OPAQUE_NOTIFY) +}; #undef DESC_ENTRY static const struct zebra_desc_table unknown = {0, "unknown", '?'}; @@ -546,6 +551,8 @@ int proto_redistnum(int afi, const char *s) return ZEBRA_ROUTE_KERNEL; else if (strmatch(s, "connected")) return ZEBRA_ROUTE_CONNECT; + else if (strmatch(s, "local")) + return ZEBRA_ROUTE_LOCAL; else if (strmatch(s, "static")) return ZEBRA_ROUTE_STATIC; else if (strmatch(s, "rip")) @@ -572,12 +579,16 @@ int proto_redistnum(int afi, const char *s) return ZEBRA_ROUTE_SHARP; else if (strmatch(s, "openfabric")) return ZEBRA_ROUTE_OPENFABRIC; + else if (strmatch(s, "table-direct")) + return ZEBRA_ROUTE_TABLE_DIRECT; } if (afi == AFI_IP6) { if (strmatch(s, "kernel")) return ZEBRA_ROUTE_KERNEL; else if (strmatch(s, "connected")) return ZEBRA_ROUTE_CONNECT; + else if (strmatch(s, "local")) + return ZEBRA_ROUTE_LOCAL; else if (strmatch(s, "static")) return ZEBRA_ROUTE_STATIC; else if (strmatch(s, "ripng")) @@ -602,6 +613,8 @@ int proto_redistnum(int afi, const char *s) return ZEBRA_ROUTE_SHARP; else if (strmatch(s, "openfabric")) return ZEBRA_ROUTE_OPENFABRIC; + else if (strmatch(s, "table-direct")) + return ZEBRA_ROUTE_TABLE_DIRECT; } return -1; } diff --git a/lib/log_vty.c b/lib/log_vty.c index 26e608d16b..fc298533ae 100644 --- a/lib/log_vty.c +++ b/lib/log_vty.c @@ -857,12 +857,24 @@ void log_config_write(struct vty *vty) } } +static int log_vty_fini(void) +{ + if (zt_file_cmdline.filename) + zlog_file_fini(&zt_file_cmdline); + if (zt_file.filename) + zlog_file_fini(&zt_file); + return 0; +} + + static int log_vty_init(const char *progname, const char *protoname, unsigned short instance, uid_t uid, gid_t gid) { zlog_progname = progname; zlog_protoname = protoname; + hook_register(zlog_fini, log_vty_fini); + zlog_set_prefix_ec(true); zlog_set_prefix_xid(true); diff --git a/lib/mgmt.proto b/lib/mgmt.proto index 8a11ff0fa5..5d83fca347 100644 --- a/lib/mgmt.proto +++ b/lib/mgmt.proto @@ -55,7 +55,10 @@ message YangData { enum CfgDataReqType { REQ_TYPE_NONE = 0; SET_DATA = 1; - DELETE_DATA = 2; + REMOVE_DATA = 2; + CREATE_DATA = 3; + DELETE_DATA = 4; + REPLACE_DATA = 5; } message YangCfgDataReq { @@ -94,16 +97,14 @@ message BeTxnReply { message BeCfgDataCreateReq { required uint64 txn_id = 1; - required uint64 batch_id = 2; - repeated YangCfgDataReq data_req = 3; - required bool end_of_data = 4; + repeated YangCfgDataReq data_req = 2; + required bool end_of_data = 3; } message BeCfgDataCreateReply { required uint64 txn_id = 1; - required uint64 batch_id = 2; - required bool success = 3; - optional string error_if_any = 4; + required bool success = 2; + optional string error_if_any = 3; } message BeCfgDataApplyReq { @@ -112,15 +113,8 @@ message BeCfgDataApplyReq { message BeCfgDataApplyReply { required uint64 txn_id = 1; - repeated uint64 batch_ids = 2; - required bool success = 3; - optional string error_if_any = 4; -} - -message BeOperDataGetReq { - required uint64 txn_id = 1; - required uint64 batch_id = 2; - repeated YangGetDataReq data = 3; + required bool success = 2; + optional string error_if_any = 3; } message YangDataReply { @@ -128,36 +122,6 @@ message YangDataReply { required int64 next_indx = 2; } -message BeOperDataGetReply { - required uint64 txn_id = 1; - required uint64 batch_id = 2; - required bool success = 3; - optional string error = 4; - optional YangDataReply data = 5; -} - -message BeOperDataNotify { - required YangDataReply data = 5; -} - -message BeConfigCmdReq { - required string cmd = 1; -} - -message BeConfigCmdReply { - required bool success = 1; - required string error_if_any = 2; -} - -message BeShowCmdReq { - required string cmd = 1; -} - -message BeShowCmdReply { - required bool success = 1; - required string cmd_ouput = 2; -} - // // Any message on the MGMTD Backend Interface. // @@ -171,13 +135,6 @@ message BeMessage { BeCfgDataCreateReply cfg_data_reply = 7; BeCfgDataApplyReq cfg_apply_req = 8; BeCfgDataApplyReply cfg_apply_reply = 9; - BeOperDataGetReq get_req = 10; - BeOperDataGetReply get_reply = 11; - BeOperDataNotify notify_data = 12; - BeConfigCmdReq cfg_cmd_req = 13; - BeConfigCmdReply cfg_cmd_reply = 14; - BeShowCmdReq show_cmd_req = 15; - BeShowCmdReply show_cmd_reply = 16; } } @@ -243,7 +200,8 @@ message FeSetConfigReply { required DatastoreId ds_id = 2; required uint64 req_id = 3; required bool success = 4; - optional string error_if_any = 5; + required bool implicit_commit = 5; + optional string error_if_any = 6; } message FeCommitConfigReq { @@ -266,36 +224,22 @@ message FeCommitConfigReply { optional string error_if_any = 8; } -message FeGetConfigReq { - required uint64 session_id = 1; - required DatastoreId ds_id = 2; - required uint64 req_id = 3; - repeated YangGetDataReq data = 4; -} - -message FeGetConfigReply { - required uint64 session_id = 1; - required DatastoreId ds_id = 2; - required uint64 req_id = 3; - required bool success = 4; - optional string error_if_any = 5; - optional YangDataReply data = 6; -} - -message FeGetDataReq { +message FeGetReq { required uint64 session_id = 1; - required DatastoreId ds_id = 2; - required uint64 req_id = 3; - repeated YangGetDataReq data = 4; + required bool config = 2; + required DatastoreId ds_id = 3; + required uint64 req_id = 4; + repeated YangGetDataReq data = 5; } -message FeGetDataReply { +message FeGetReply { required uint64 session_id = 1; - required DatastoreId ds_id = 2; - required uint64 req_id = 3; - required bool success = 4; - optional string error_if_any = 5; - optional YangDataReply data = 6; + required bool config = 2; + required DatastoreId ds_id = 3; + required uint64 req_id = 4; + required bool success = 5; + optional string error_if_any = 6; + optional YangDataReply data = 7; } message FeNotifyDataReq { @@ -321,10 +265,8 @@ message FeMessage { FeSetConfigReply setcfg_reply = 8; FeCommitConfigReq commcfg_req = 9; FeCommitConfigReply commcfg_reply = 10; - FeGetConfigReq getcfg_req = 11; - FeGetConfigReply getcfg_reply = 12; - FeGetDataReq getdata_req = 13; - FeGetDataReply getdata_reply = 14; + FeGetReq get_req = 11; + FeGetReply get_reply = 12; FeNotifyDataReq notify_data_req = 15; FeRegisterNotifyReq regnotify_req = 16; } diff --git a/lib/mgmt_be_client.c b/lib/mgmt_be_client.c index 534dc43405..16aea249a4 100644 --- a/lib/mgmt_be_client.c +++ b/lib/mgmt_be_client.c @@ -8,10 +8,12 @@ #include <zebra.h> #include "debug.h" #include "compiler.h" +#include "darr.h" #include "libfrr.h" -#include "mgmtd/mgmt.h" +#include "lib_errors.h" #include "mgmt_be_client.h" #include "mgmt_msg.h" +#include "mgmt_msg_native.h" #include "mgmt_pb.h" #include "network.h" #include "northbound.h" @@ -20,21 +22,15 @@ #include "lib/mgmt_be_client_clippy.c" -#define MGMTD_BE_CLIENT_DBG(fmt, ...) \ - DEBUGD(&mgmt_dbg_be_client, "BE-CLIENT: %s:" fmt, __func__, \ - ##__VA_ARGS__) -#define MGMTD_BE_CLIENT_ERR(fmt, ...) \ - zlog_err("BE-CLIENT: %s: ERROR: " fmt, __func__, ##__VA_ARGS__) -#define MGMTD_DBG_BE_CLIENT_CHECK() \ - DEBUG_MODE_CHECK(&mgmt_dbg_be_client, DEBUG_MODE_ALL) - +DEFINE_MTYPE_STATIC(LIB, MGMTD_BE_CLIENT, "backend client"); +DEFINE_MTYPE_STATIC(LIB, MGMTD_BE_CLIENT_NAME, "backend client name"); DEFINE_MTYPE_STATIC(LIB, MGMTD_BE_BATCH, "backend transaction batch data"); DEFINE_MTYPE_STATIC(LIB, MGMTD_BE_TXN, "backend transaction data"); +DEFINE_MTYPE_STATIC(LIB, MGMTD_BE_GT_CB_ARGS, "backend get-tree cb args"); enum mgmt_be_txn_event { MGMTD_BE_TXN_PROC_SETCFG = 1, MGMTD_BE_TXN_PROC_GETCFG, - MGMTD_BE_TXN_PROC_GETDATA }; struct mgmt_be_set_cfg_req { @@ -42,24 +38,20 @@ struct mgmt_be_set_cfg_req { uint16_t num_cfg_changes; }; -struct mgmt_be_get_data_req { - char *xpaths[MGMTD_MAX_NUM_DATA_REQ_IN_BATCH]; - uint16_t num_xpaths; -}; - struct mgmt_be_txn_req { enum mgmt_be_txn_event event; union { struct mgmt_be_set_cfg_req set_cfg; - struct mgmt_be_get_data_req get_data; } req; }; +struct be_oper_iter_arg { + struct lyd_node *root; /* the tree we are building */ + struct lyd_node *hint; /* last node added */ +}; + PREDECL_LIST(mgmt_be_batches); struct mgmt_be_batch_ctx { - /* Batch-Id as assigned by MGMTD */ - uint64_t batch_id; - struct mgmt_be_txn_req txn_req; uint32_t flags; @@ -70,8 +62,6 @@ struct mgmt_be_batch_ctx { #define MGMTD_BE_TXN_FLAGS_CFG_APPLIED (1U << 1) DECLARE_LIST(mgmt_be_batches, struct mgmt_be_batch_ctx, list_linkage); -struct mgmt_be_client_ctx; - PREDECL_LIST(mgmt_be_txns); struct mgmt_be_txn_ctx { /* Txn-Id as assigned by MGMTD */ @@ -79,7 +69,7 @@ struct mgmt_be_txn_ctx { uint32_t flags; struct mgmt_be_client_txn_ctx client_data; - struct mgmt_be_client_ctx *client_ctx; + struct mgmt_be_client *client; /* List of batches belonging to this transaction */ struct mgmt_be_batches_head cfg_batches; @@ -100,9 +90,11 @@ DECLARE_LIST(mgmt_be_txns, struct mgmt_be_txn_ctx, list_linkage); #define FOREACH_BE_APPLY_BATCH_IN_LIST(txn, batch) \ frr_each_safe (mgmt_be_batches, &(txn)->apply_cfgs, (batch)) -struct mgmt_be_client_ctx { +struct mgmt_be_client { struct msg_client client; + char *name; + struct nb_config *candidate_config; struct nb_config *running_config; @@ -114,25 +106,31 @@ struct mgmt_be_client_ctx { unsigned long avg_apply_nb_cfg_tm; struct mgmt_be_txns_head txn_head; - struct mgmt_be_client_params client_params; + + struct mgmt_be_client_cbs cbs; + uintptr_t user_data; }; #define FOREACH_BE_TXN_IN_LIST(client_ctx, txn) \ frr_each_safe (mgmt_be_txns, &(client_ctx)->txn_head, (txn)) -struct debug mgmt_dbg_be_client = {0, "Management backend client operations"}; +struct debug mgmt_dbg_be_client = { + .desc = "Management backend client operations" +}; -static struct mgmt_be_client_ctx mgmt_be_client_ctx = { - .client = {.conn = {.fd = -1}}}; +/* NOTE: only one client per proc for now. */ +static struct mgmt_be_client *__be_client; -const char *mgmt_be_client_names[MGMTD_BE_CLIENT_ID_MAX + 1] = { -#ifdef HAVE_STATICD - [MGMTD_BE_CLIENT_ID_STATICD] = "staticd", -#endif - [MGMTD_BE_CLIENT_ID_MAX] = "Unknown/Invalid", -}; +static int be_client_send_native_msg(struct mgmt_be_client *client_ctx, + void *msg, size_t len, + bool short_circuit_ok) +{ + return msg_conn_send_msg(&client_ctx->client.conn, + MGMT_MSG_VERSION_NATIVE, msg, len, NULL, + short_circuit_ok); +} -static int mgmt_be_client_send_msg(struct mgmt_be_client_ctx *client_ctx, +static int mgmt_be_client_send_msg(struct mgmt_be_client *client_ctx, Mgmtd__BeMessage *be_msg) { return msg_conn_send_msg( @@ -142,37 +140,15 @@ static int mgmt_be_client_send_msg(struct mgmt_be_client_ctx *client_ctx, } static struct mgmt_be_batch_ctx * -mgmt_be_find_batch_by_id(struct mgmt_be_txn_ctx *txn, - uint64_t batch_id) +mgmt_be_batch_create(struct mgmt_be_txn_ctx *txn) { struct mgmt_be_batch_ctx *batch = NULL; - FOREACH_BE_TXN_BATCH_IN_LIST (txn, batch) { - if (batch->batch_id == batch_id) - return batch; - } + batch = XCALLOC(MTYPE_MGMTD_BE_BATCH, sizeof(struct mgmt_be_batch_ctx)); - return NULL; -} + mgmt_be_batches_add_tail(&txn->cfg_batches, batch); -static struct mgmt_be_batch_ctx * -mgmt_be_batch_create(struct mgmt_be_txn_ctx *txn, uint64_t batch_id) -{ - struct mgmt_be_batch_ctx *batch = NULL; - - batch = mgmt_be_find_batch_by_id(txn, batch_id); - if (!batch) { - batch = XCALLOC(MTYPE_MGMTD_BE_BATCH, - sizeof(struct mgmt_be_batch_ctx)); - assert(batch); - - batch->batch_id = batch_id; - mgmt_be_batches_add_tail(&txn->cfg_batches, batch); - - MGMTD_BE_CLIENT_DBG("Added new batch-id: %" PRIu64 - " to transaction", - batch_id); - } + MGMTD_BE_CLIENT_DBG("Added new batch to transaction"); return batch; } @@ -216,45 +192,47 @@ static void mgmt_be_cleanup_all_batches(struct mgmt_be_txn_ctx *txn) } static struct mgmt_be_txn_ctx * -mgmt_be_find_txn_by_id(struct mgmt_be_client_ctx *client_ctx, - uint64_t txn_id) +mgmt_be_find_txn_by_id(struct mgmt_be_client *client_ctx, uint64_t txn_id, + bool warn) { struct mgmt_be_txn_ctx *txn = NULL; - FOREACH_BE_TXN_IN_LIST (client_ctx, txn) { + FOREACH_BE_TXN_IN_LIST (client_ctx, txn) if (txn->txn_id == txn_id) return txn; - } + if (warn) + MGMTD_BE_CLIENT_ERR("client %s unkonwn txn-id: %" PRIu64, + client_ctx->name, txn_id); return NULL; } static struct mgmt_be_txn_ctx * -mgmt_be_txn_create(struct mgmt_be_client_ctx *client_ctx, - uint64_t txn_id) +mgmt_be_txn_create(struct mgmt_be_client *client_ctx, uint64_t txn_id) { struct mgmt_be_txn_ctx *txn = NULL; - txn = mgmt_be_find_txn_by_id(client_ctx, txn_id); - if (!txn) { - txn = XCALLOC(MTYPE_MGMTD_BE_TXN, - sizeof(struct mgmt_be_txn_ctx)); - assert(txn); + txn = mgmt_be_find_txn_by_id(client_ctx, txn_id, false); + if (txn) { + MGMTD_BE_CLIENT_ERR("Can't create existing txn-id: %" PRIu64, + txn_id); + return NULL; + } - txn->txn_id = txn_id; - txn->client_ctx = client_ctx; - mgmt_be_batches_init(&txn->cfg_batches); - mgmt_be_batches_init(&txn->apply_cfgs); - mgmt_be_txns_add_tail(&client_ctx->txn_head, txn); + txn = XCALLOC(MTYPE_MGMTD_BE_TXN, sizeof(struct mgmt_be_txn_ctx)); + txn->txn_id = txn_id; + txn->client = client_ctx; + mgmt_be_batches_init(&txn->cfg_batches); + mgmt_be_batches_init(&txn->apply_cfgs); + mgmt_be_txns_add_tail(&client_ctx->txn_head, txn); - MGMTD_BE_CLIENT_DBG("Added new txn-id: %" PRIu64, txn_id); - } + MGMTD_BE_CLIENT_DBG("Created new txn-id: %" PRIu64, txn_id); return txn; } -static void mgmt_be_txn_delete(struct mgmt_be_client_ctx *client_ctx, - struct mgmt_be_txn_ctx **txn) +static void mgmt_be_txn_delete(struct mgmt_be_client *client_ctx, + struct mgmt_be_txn_ctx **txn) { char err_msg[] = "MGMT Transaction Delete"; @@ -274,12 +252,10 @@ static void mgmt_be_txn_delete(struct mgmt_be_client_ctx *client_ctx, * CFGDATA_CREATE_REQs. But first notify the client * about the transaction delete. */ - if (client_ctx->client_params.txn_notify) - (void)(*client_ctx->client_params - .txn_notify)( - (uintptr_t)client_ctx, - client_ctx->client_params.user_data, - &(*txn)->client_data, true); + if (client_ctx->cbs.txn_notify) + (void)(*client_ctx->cbs.txn_notify)(client_ctx, + client_ctx->user_data, + &(*txn)->client_data, true); mgmt_be_cleanup_all_batches(*txn); if ((*txn)->nb_txn) @@ -290,8 +266,7 @@ static void mgmt_be_txn_delete(struct mgmt_be_client_ctx *client_ctx, *txn = NULL; } -static void -mgmt_be_cleanup_all_txns(struct mgmt_be_client_ctx *client_ctx) +static void mgmt_be_cleanup_all_txns(struct mgmt_be_client *client_ctx) { struct mgmt_be_txn_ctx *txn = NULL; @@ -300,9 +275,43 @@ mgmt_be_cleanup_all_txns(struct mgmt_be_client_ctx *client_ctx) } } -static int mgmt_be_send_txn_reply(struct mgmt_be_client_ctx *client_ctx, - uint64_t txn_id, bool create, - bool success) + +/** + * Send an error back to MGMTD using native messaging. + * + * Args: + * client: the BE client. + * txn_id: the txn_id this error pertains to. + * short_circuit_ok: True if OK to short-circuit the call. + * error: An integer error value. + * errfmt: An error format string (i.e., printfrr) + * ...: args for use by the `errfmt` format string. + * + * Return: + * the return value from the underlying send message function. + */ +static int be_client_send_error(struct mgmt_be_client *client, uint64_t txn_id, + uint64_t req_id, bool short_circuit_ok, + int16_t error, const char *errfmt, ...) + PRINTFRR(6, 7); + +static int be_client_send_error(struct mgmt_be_client *client, uint64_t txn_id, + uint64_t req_id, bool short_circuit_ok, + int16_t error, const char *errfmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, errfmt); + ret = vmgmt_msg_native_send_error(&client->client.conn, txn_id, req_id, + short_circuit_ok, error, errfmt, ap); + va_end(ap); + + return ret; +} + +static int mgmt_be_send_txn_reply(struct mgmt_be_client *client_ctx, + uint64_t txn_id, bool create) { Mgmtd__BeMessage be_msg; Mgmtd__BeTxnReply txn_reply; @@ -310,7 +319,7 @@ static int mgmt_be_send_txn_reply(struct mgmt_be_client_ctx *client_ctx, mgmtd__be_txn_reply__init(&txn_reply); txn_reply.create = create; txn_reply.txn_id = txn_id; - txn_reply.success = success; + txn_reply.success = true; mgmtd__be_message__init(&be_msg); be_msg.message_case = MGMTD__BE_MESSAGE__MESSAGE_TXN_REPLY; @@ -321,64 +330,45 @@ static int mgmt_be_send_txn_reply(struct mgmt_be_client_ctx *client_ctx, return mgmt_be_client_send_msg(client_ctx, &be_msg); } -static int mgmt_be_process_txn_req(struct mgmt_be_client_ctx *client_ctx, - uint64_t txn_id, bool create) +static int mgmt_be_process_txn_req(struct mgmt_be_client *client_ctx, + uint64_t txn_id, bool create) { struct mgmt_be_txn_ctx *txn; - txn = mgmt_be_find_txn_by_id(client_ctx, txn_id); if (create) { - if (txn) { - /* - * Transaction with same txn-id already exists. - * Should not happen under any circumstances. - */ - MGMTD_BE_CLIENT_ERR( - "txn-id: %" PRIu64 " already exists", txn_id); - mgmt_be_send_txn_reply(client_ctx, txn_id, create, - false); - } + MGMTD_BE_CLIENT_DBG("Creating new txn-id %" PRIu64, txn_id); - MGMTD_BE_CLIENT_DBG("Created new txn-id %" PRIu64, txn_id); txn = mgmt_be_txn_create(client_ctx, txn_id); + if (!txn) + goto failed; - if (client_ctx->client_params.txn_notify) - (void)(*client_ctx->client_params - .txn_notify)( - (uintptr_t)client_ctx, - client_ctx->client_params.user_data, - &txn->client_data, false); + if (client_ctx->cbs.txn_notify) + (*client_ctx->cbs.txn_notify)(client_ctx, + client_ctx->user_data, + &txn->client_data, false); } else { - if (!txn) { - /* - * Transaction with same txn-id does not exists. - * Return sucess anyways. - */ - MGMTD_BE_CLIENT_DBG("txn-id: %" PRIu64 - " for delete does NOT exists", - txn_id); - } else { - MGMTD_BE_CLIENT_DBG("Delete txn-id: %" PRIu64, txn_id); + MGMTD_BE_CLIENT_DBG("Deleting txn-id: %" PRIu64, txn_id); + txn = mgmt_be_find_txn_by_id(client_ctx, txn_id, false); + if (txn) mgmt_be_txn_delete(client_ctx, &txn); - } } - mgmt_be_send_txn_reply(client_ctx, txn_id, create, true); + return mgmt_be_send_txn_reply(client_ctx, txn_id, create); - return 0; +failed: + msg_conn_disconnect(&client_ctx->client.conn, true); + return -1; } -static int -mgmt_be_send_cfgdata_create_reply(struct mgmt_be_client_ctx *client_ctx, - uint64_t txn_id, uint64_t batch_id, - bool success, const char *error_if_any) +static int mgmt_be_send_cfgdata_create_reply(struct mgmt_be_client *client_ctx, + uint64_t txn_id, bool success, + const char *error_if_any) { Mgmtd__BeMessage be_msg; Mgmtd__BeCfgDataCreateReply cfgdata_reply; mgmtd__be_cfg_data_create_reply__init(&cfgdata_reply); cfgdata_reply.txn_id = (uint64_t)txn_id; - cfgdata_reply.batch_id = (uint64_t)batch_id; cfgdata_reply.success = success; if (error_if_any) cfgdata_reply.error_if_any = (char *)error_if_any; @@ -387,9 +377,8 @@ mgmt_be_send_cfgdata_create_reply(struct mgmt_be_client_ctx *client_ctx, be_msg.message_case = MGMTD__BE_MESSAGE__MESSAGE_CFG_DATA_REPLY; be_msg.cfg_data_reply = &cfgdata_reply; - MGMTD_BE_CLIENT_DBG("Sending CFGDATA_CREATE_REPLY txn-id: %" PRIu64 - " batch-id: %" PRIu64, - txn_id, batch_id); + MGMTD_BE_CLIENT_DBG("Sending CFGDATA_CREATE_REPLY txn-id: %" PRIu64, + txn_id); return mgmt_be_client_send_msg(client_ctx, &be_msg); } @@ -398,7 +387,7 @@ static void mgmt_be_txn_cfg_abort(struct mgmt_be_txn_ctx *txn) { char errmsg[BUFSIZ] = {0}; - assert(txn && txn->client_ctx); + assert(txn && txn->client); if (txn->nb_txn) { MGMTD_BE_CLIENT_ERR( "Aborting configs after prep for txn-id: %" PRIu64, @@ -416,13 +405,13 @@ static void mgmt_be_txn_cfg_abort(struct mgmt_be_txn_ctx *txn) MGMTD_BE_CLIENT_DBG( "Reset candidate configurations after abort of txn-id: %" PRIu64, txn->txn_id); - nb_config_replace(txn->client_ctx->candidate_config, - txn->client_ctx->running_config, true); + nb_config_replace(txn->client->candidate_config, + txn->client->running_config, true); } static int mgmt_be_txn_cfg_prepare(struct mgmt_be_txn_ctx *txn) { - struct mgmt_be_client_ctx *client_ctx; + struct mgmt_be_client *client_ctx; struct mgmt_be_txn_req *txn_req = NULL; struct nb_context nb_ctx = {0}; struct timeval edit_nb_cfg_start; @@ -437,15 +426,15 @@ static int mgmt_be_txn_cfg_prepare(struct mgmt_be_txn_ctx *txn) size_t num_processed; int err; - assert(txn && txn->client_ctx); - client_ctx = txn->client_ctx; + assert(txn && txn->client); + client_ctx = txn->client; num_processed = 0; FOREACH_BE_TXN_BATCH_IN_LIST (txn, batch) { txn_req = &batch->txn_req; error = false; nb_ctx.client = NB_CLIENT_CLI; - nb_ctx.user = (void *)client_ctx->client_params.user_data; + nb_ctx.user = (void *)client_ctx->user_data; if (!txn->nb_txn) { /* @@ -460,15 +449,13 @@ static int mgmt_be_txn_cfg_prepare(struct mgmt_be_txn_ctx *txn) client_ctx->candidate_config, txn_req->req.set_cfg.cfg_changes, (size_t)txn_req->req.set_cfg.num_cfg_changes, - NULL, NULL, 0, err_buf, sizeof(err_buf), - &error); + NULL, err_buf, sizeof(err_buf), &error); if (error) { err_buf[sizeof(err_buf) - 1] = 0; MGMTD_BE_CLIENT_ERR( "Failed to update configs for txn-id: %" PRIu64 - " batch-id: %" PRIu64 " to candidate, err: '%s'", - txn->txn_id, batch->batch_id, err_buf); + txn->txn_id, err_buf); return -1; } gettimeofday(&edit_nb_cfg_end, NULL); @@ -492,7 +479,7 @@ static int mgmt_be_txn_cfg_prepare(struct mgmt_be_txn_ctx *txn) * Now prepare all the batches we have applied in one go. */ nb_ctx.client = NB_CLIENT_CLI; - nb_ctx.user = (void *)client_ctx->client_params.user_data; + nb_ctx.user = (void *)client_ctx->user_data; gettimeofday(&prep_nb_cfg_start, NULL); err = nb_candidate_commit_prepare(nb_ctx, client_ctx->candidate_config, @@ -531,9 +518,6 @@ static int mgmt_be_txn_cfg_prepare(struct mgmt_be_txn_ctx *txn) client_ctx->num_prep_nb_cfg++; FOREACH_BE_TXN_BATCH_IN_LIST (txn, batch) { - mgmt_be_send_cfgdata_create_reply( - client_ctx, txn->txn_id, batch->batch_id, - error ? false : true, error ? err_buf : NULL); if (!error) { SET_FLAG(batch->flags, MGMTD_BE_BATCH_FLAGS_CFG_PREPARED); @@ -542,6 +526,9 @@ static int mgmt_be_txn_cfg_prepare(struct mgmt_be_txn_ctx *txn) } } + mgmt_be_send_cfgdata_create_reply(client_ctx, txn->txn_id, + error ? false : true, error ? err_buf : NULL); + MGMTD_BE_CLIENT_DBG( "Avg-nb-edit-duration %lu uSec, nb-prep-duration %lu (avg: %lu) uSec, batch size %u", client_ctx->avg_edit_nb_cfg_tm, prep_nb_cfg_tm, @@ -556,39 +543,48 @@ static int mgmt_be_txn_cfg_prepare(struct mgmt_be_txn_ctx *txn) /* * Process all CFG_DATA_REQs received so far and prepare them all in one go. */ -static int -mgmt_be_update_setcfg_in_batch(struct mgmt_be_client_ctx *client_ctx, - struct mgmt_be_txn_ctx *txn, - uint64_t batch_id, - Mgmtd__YangCfgDataReq * cfg_req[], - int num_req) +static int mgmt_be_update_setcfg_in_batch(struct mgmt_be_client *client_ctx, + struct mgmt_be_txn_ctx *txn, + Mgmtd__YangCfgDataReq *cfg_req[], + int num_req) { struct mgmt_be_batch_ctx *batch = NULL; struct mgmt_be_txn_req *txn_req = NULL; int index; struct nb_cfg_change *cfg_chg; - batch = mgmt_be_batch_create(txn, batch_id); - if (!batch) { - MGMTD_BE_CLIENT_ERR("Batch create failed!"); - return -1; - } + batch = mgmt_be_batch_create(txn); + assert(batch); txn_req = &batch->txn_req; txn_req->event = MGMTD_BE_TXN_PROC_SETCFG; - MGMTD_BE_CLIENT_DBG("Created SETCFG request for batch-id: %" PRIu64 - " txn-id: %" PRIu64 " cfg-items:%d", - batch_id, txn->txn_id, num_req); + MGMTD_BE_CLIENT_DBG("Created SETCFG request for txn-id: %" PRIu64 + " cfg-items:%d", txn->txn_id, num_req); txn_req->req.set_cfg.num_cfg_changes = num_req; for (index = 0; index < num_req; index++) { cfg_chg = &txn_req->req.set_cfg.cfg_changes[index]; - if (cfg_req[index]->req_type - == MGMTD__CFG_DATA_REQ_TYPE__DELETE_DATA) + /* + * Treat all operations as destroy or modify, because we don't + * need additional existence checks on the backend. Everything + * is already checked by mgmtd. + */ + switch (cfg_req[index]->req_type) { + case MGMTD__CFG_DATA_REQ_TYPE__DELETE_DATA: + case MGMTD__CFG_DATA_REQ_TYPE__REMOVE_DATA: cfg_chg->operation = NB_OP_DESTROY; - else - cfg_chg->operation = NB_OP_CREATE; + break; + case MGMTD__CFG_DATA_REQ_TYPE__SET_DATA: + case MGMTD__CFG_DATA_REQ_TYPE__CREATE_DATA: + case MGMTD__CFG_DATA_REQ_TYPE__REPLACE_DATA: + cfg_chg->operation = NB_OP_MODIFY; + break; + case MGMTD__CFG_DATA_REQ_TYPE__REQ_TYPE_NONE: + case _MGMTD__CFG_DATA_REQ_TYPE_IS_INT_SIZE: + default: + continue; + } strlcpy(cfg_chg->xpath, cfg_req[index]->data->xpath, sizeof(cfg_chg->xpath)); @@ -611,39 +607,34 @@ mgmt_be_update_setcfg_in_batch(struct mgmt_be_client_ctx *client_ctx, return 0; } -static int -mgmt_be_process_cfgdata_req(struct mgmt_be_client_ctx *client_ctx, - uint64_t txn_id, uint64_t batch_id, - Mgmtd__YangCfgDataReq * cfg_req[], int num_req, - bool end_of_data) +static int mgmt_be_process_cfgdata_req(struct mgmt_be_client *client_ctx, + uint64_t txn_id, + Mgmtd__YangCfgDataReq *cfg_req[], + int num_req, bool end_of_data) { struct mgmt_be_txn_ctx *txn; - txn = mgmt_be_find_txn_by_id(client_ctx, txn_id); - if (!txn) { - MGMTD_BE_CLIENT_ERR("Invalid txn-id: %" PRIu64 - " from MGMTD server", - txn_id); - mgmt_be_send_cfgdata_create_reply( - client_ctx, txn_id, batch_id, false, - "Transaction context not created yet"); - } else { - mgmt_be_update_setcfg_in_batch(client_ctx, txn, batch_id, - cfg_req, num_req); - } + txn = mgmt_be_find_txn_by_id(client_ctx, txn_id, true); + if (!txn) + goto failed; + + mgmt_be_update_setcfg_in_batch(client_ctx, txn, cfg_req, num_req); if (txn && end_of_data) { - MGMTD_BE_CLIENT_DBG("Triggering CFG_PREPARE_REQ processing"); - mgmt_be_txn_cfg_prepare(txn); + MGMTD_BE_CLIENT_DBG("End of data; CFG_PREPARE_REQ processing"); + if (mgmt_be_txn_cfg_prepare(txn)) + goto failed; } return 0; +failed: + msg_conn_disconnect(&client_ctx->client.conn, true); + return -1; } -static int mgmt_be_send_apply_reply(struct mgmt_be_client_ctx *client_ctx, - uint64_t txn_id, uint64_t batch_ids[], - size_t num_batch_ids, bool success, - const char *error_if_any) +static int mgmt_be_send_apply_reply(struct mgmt_be_client *client_ctx, + uint64_t txn_id, bool success, + const char *error_if_any) { Mgmtd__BeMessage be_msg; Mgmtd__BeCfgDataApplyReply apply_reply; @@ -651,8 +642,6 @@ static int mgmt_be_send_apply_reply(struct mgmt_be_client_ctx *client_ctx, mgmtd__be_cfg_data_apply_reply__init(&apply_reply); apply_reply.success = success; apply_reply.txn_id = txn_id; - apply_reply.batch_ids = (uint64_t *)batch_ids; - apply_reply.n_batch_ids = num_batch_ids; if (error_if_any) apply_reply.error_if_any = (char *)error_if_any; @@ -661,32 +650,24 @@ static int mgmt_be_send_apply_reply(struct mgmt_be_client_ctx *client_ctx, be_msg.message_case = MGMTD__BE_MESSAGE__MESSAGE_CFG_APPLY_REPLY; be_msg.cfg_apply_reply = &apply_reply; - MGMTD_BE_CLIENT_DBG( - "Sending CFG_APPLY_REPLY txn-id %" PRIu64 - " %zu batch ids %" PRIu64 " - %" PRIu64, - txn_id, num_batch_ids, - success && num_batch_ids ? batch_ids[0] : 0, - success && num_batch_ids ? batch_ids[num_batch_ids - 1] : 0); + MGMTD_BE_CLIENT_DBG("Sending CFG_APPLY_REPLY txn-id %" PRIu64, txn_id); return mgmt_be_client_send_msg(client_ctx, &be_msg); } static int mgmt_be_txn_proc_cfgapply(struct mgmt_be_txn_ctx *txn) { - struct mgmt_be_client_ctx *client_ctx; + struct mgmt_be_client *client_ctx; struct timeval apply_nb_cfg_start; struct timeval apply_nb_cfg_end; unsigned long apply_nb_cfg_tm; struct mgmt_be_batch_ctx *batch; char err_buf[BUFSIZ]; - size_t num_processed; - static uint64_t batch_ids[MGMTD_BE_MAX_BATCH_IDS_IN_REQ]; - assert(txn && txn->client_ctx); - client_ctx = txn->client_ctx; + assert(txn && txn->client); + client_ctx = txn->client; assert(txn->nb_txn); - num_processed = 0; /* * Now apply all the batches we have applied in one go. @@ -704,9 +685,6 @@ static int mgmt_be_txn_proc_cfgapply(struct mgmt_be_txn_ctx *txn) client_ctx->num_apply_nb_cfg++; txn->nb_txn = NULL; - /* - * Send back CFG_APPLY_REPLY for all batches applied. - */ FOREACH_BE_APPLY_BATCH_IN_LIST (txn, batch) { /* * No need to delete the batch yet. Will be deleted during @@ -715,19 +693,9 @@ static int mgmt_be_txn_proc_cfgapply(struct mgmt_be_txn_ctx *txn) SET_FLAG(batch->flags, MGMTD_BE_TXN_FLAGS_CFG_APPLIED); mgmt_be_batches_del(&txn->apply_cfgs, batch); mgmt_be_batches_add_tail(&txn->cfg_batches, batch); - - batch_ids[num_processed] = batch->batch_id; - num_processed++; - if (num_processed == MGMTD_BE_MAX_BATCH_IDS_IN_REQ) { - mgmt_be_send_apply_reply(client_ctx, txn->txn_id, - batch_ids, num_processed, - true, NULL); - num_processed = 0; - } } - mgmt_be_send_apply_reply(client_ctx, txn->txn_id, batch_ids, - num_processed, true, NULL); + mgmt_be_send_apply_reply(client_ctx, txn->txn_id, true, NULL); MGMTD_BE_CLIENT_DBG("Nb-apply-duration %lu (avg: %lu) uSec", apply_nb_cfg_tm, client_ctx->avg_apply_nb_cfg_tm); @@ -735,30 +703,33 @@ static int mgmt_be_txn_proc_cfgapply(struct mgmt_be_txn_ctx *txn) return 0; } -static int -mgmt_be_process_cfg_apply(struct mgmt_be_client_ctx *client_ctx, - uint64_t txn_id) +static int mgmt_be_process_cfg_apply(struct mgmt_be_client *client_ctx, + uint64_t txn_id) { struct mgmt_be_txn_ctx *txn; - txn = mgmt_be_find_txn_by_id(client_ctx, txn_id); - if (!txn) { - mgmt_be_send_apply_reply(client_ctx, txn_id, NULL, 0, false, - "Transaction not created yet!"); - return -1; - } + txn = mgmt_be_find_txn_by_id(client_ctx, txn_id, true); + if (!txn) + goto failed; MGMTD_BE_CLIENT_DBG("Trigger CFG_APPLY_REQ processing"); - mgmt_be_txn_proc_cfgapply(txn); + if (mgmt_be_txn_proc_cfgapply(txn)) + goto failed; return 0; +failed: + msg_conn_disconnect(&client_ctx->client.conn, true); + return -1; } -static int -mgmt_be_client_handle_msg(struct mgmt_be_client_ctx *client_ctx, - Mgmtd__BeMessage *be_msg) + +static int mgmt_be_client_handle_msg(struct mgmt_be_client *client_ctx, + Mgmtd__BeMessage *be_msg) { /* + * On error we may have closed the connection so don't do anything with + * the client_ctx on return. + * * protobuf-c adds a max size enum with an internal, and changing by * version, name; cast to an int to avoid unhandled enum warnings */ @@ -778,13 +749,11 @@ mgmt_be_client_handle_msg(struct mgmt_be_client_ctx *client_ctx, break; case MGMTD__BE_MESSAGE__MESSAGE_CFG_DATA_REQ: MGMTD_BE_CLIENT_DBG("Got CFG_DATA_REQ txn-id: %" PRIu64 - " batch-id: %" PRIu64 " end-of-data %u", + " end-of-data %u", be_msg->cfg_data_req->txn_id, - be_msg->cfg_data_req->batch_id, be_msg->cfg_data_req->end_of_data); mgmt_be_process_cfgdata_req( client_ctx, be_msg->cfg_data_req->txn_id, - be_msg->cfg_data_req->batch_id, be_msg->cfg_data_req->data_req, be_msg->cfg_data_req->n_data_req, be_msg->cfg_data_req->end_of_data); @@ -795,27 +764,14 @@ mgmt_be_client_handle_msg(struct mgmt_be_client_ctx *client_ctx, mgmt_be_process_cfg_apply( client_ctx, (uint64_t)be_msg->cfg_apply_req->txn_id); break; - case MGMTD__BE_MESSAGE__MESSAGE_GET_REQ: - case MGMTD__BE_MESSAGE__MESSAGE_SUBSCR_REQ: - case MGMTD__BE_MESSAGE__MESSAGE_CFG_CMD_REQ: - case MGMTD__BE_MESSAGE__MESSAGE_SHOW_CMD_REQ: - MGMTD_BE_CLIENT_ERR("Got unhandled message type %u", - be_msg->message_case); - /* - * TODO: Add handling code in future. - */ - break; /* * NOTE: The following messages are always sent from Backend * clients to MGMTd only and/or need not be handled here. */ - case MGMTD__BE_MESSAGE__MESSAGE_GET_REPLY: + case MGMTD__BE_MESSAGE__MESSAGE_SUBSCR_REQ: case MGMTD__BE_MESSAGE__MESSAGE_TXN_REPLY: case MGMTD__BE_MESSAGE__MESSAGE_CFG_DATA_REPLY: case MGMTD__BE_MESSAGE__MESSAGE_CFG_APPLY_REPLY: - case MGMTD__BE_MESSAGE__MESSAGE_CFG_CMD_REPLY: - case MGMTD__BE_MESSAGE__MESSAGE_SHOW_CMD_REPLY: - case MGMTD__BE_MESSAGE__MESSAGE_NOTIFY_DATA: case MGMTD__BE_MESSAGE__MESSAGE__NOT_SET: default: /* @@ -830,15 +786,139 @@ mgmt_be_client_handle_msg(struct mgmt_be_client_ctx *client_ctx, return 0; } +struct be_client_tree_data_batch_args { + struct mgmt_be_client *client; + uint64_t txn_id; + uint64_t req_id; + LYD_FORMAT result_type; +}; + +/* + * Process the get-tree request on our local oper state + */ +static enum nb_error be_client_send_tree_data_batch(const struct lyd_node *tree, + void *arg, enum nb_error ret) +{ + struct be_client_tree_data_batch_args *args = arg; + struct mgmt_be_client *client = args->client; + struct mgmt_msg_tree_data *tree_msg = NULL; + bool more = false; + uint8_t **darrp; + LY_ERR err; + + if (ret == NB_YIELD) { + more = true; + ret = NB_OK; + } + if (ret != NB_OK) + goto done; + + tree_msg = mgmt_msg_native_alloc_msg(struct mgmt_msg_tree_data, 0, + MTYPE_MSG_NATIVE_TREE_DATA); + tree_msg->refer_id = args->txn_id; + tree_msg->req_id = args->req_id; + tree_msg->code = MGMT_MSG_CODE_TREE_DATA; + tree_msg->result_type = args->result_type; + tree_msg->more = more; + + darrp = mgmt_msg_native_get_darrp(tree_msg); + err = yang_print_tree_append(darrp, tree, args->result_type, + (LYD_PRINT_WD_EXPLICIT | + LYD_PRINT_WITHSIBLINGS)); + if (err) { + ret = NB_ERR; + goto done; + } + (void)be_client_send_native_msg(client, tree_msg, + mgmt_msg_native_get_msg_len(tree_msg), + false); +done: + mgmt_msg_native_free_msg(tree_msg); + if (ret) + be_client_send_error(client, args->txn_id, args->req_id, false, + -EINVAL, + "FE cilent %s txn-id %" PRIu64 + " error fetching oper state %d", + client->name, args->txn_id, ret); + if (ret != NB_OK || !more) + XFREE(MTYPE_MGMTD_BE_GT_CB_ARGS, args); + return ret; +} + +/* + * Process the get-tree request on our local oper state + */ +static void be_client_handle_get_tree(struct mgmt_be_client *client, + uint64_t txn_id, void *msgbuf, + size_t msg_len) +{ + struct mgmt_msg_get_tree *get_tree_msg = msgbuf; + struct be_client_tree_data_batch_args *args; + + MGMTD_BE_CLIENT_DBG("Received get-tree request for client %s txn-id %" PRIu64 + " req-id %" PRIu64, + client->name, txn_id, get_tree_msg->req_id); + + /* NOTE: removed the translator, if put back merge with northbound_cli + * code + */ + + args = XMALLOC(MTYPE_MGMTD_BE_GT_CB_ARGS, sizeof(*args)); + args->client = client; + args->txn_id = get_tree_msg->refer_id; + args->req_id = get_tree_msg->req_id; + args->result_type = get_tree_msg->result_type; + nb_oper_walk(get_tree_msg->xpath, NULL, 0, true, NULL, NULL, + be_client_send_tree_data_batch, args); +} + +/* + * Handle a native encoded message + * + * We don't create transactions with native messaging. + */ +static void be_client_handle_native_msg(struct mgmt_be_client *client, + struct mgmt_msg_header *msg, + size_t msg_len) +{ + uint64_t txn_id = msg->refer_id; + + switch (msg->code) { + case MGMT_MSG_CODE_GET_TREE: + be_client_handle_get_tree(client, txn_id, msg, msg_len); + break; + default: + MGMTD_BE_CLIENT_ERR("unknown native message txn-id %" PRIu64 + " req-id %" PRIu64 " code %u to client %s", + txn_id, msg->req_id, msg->code, + client->name); + be_client_send_error(client, msg->refer_id, msg->req_id, false, -1, + "BE cilent %s recv msg unknown txn-id %" PRIu64, + client->name, txn_id); + break; + } +} + static void mgmt_be_client_process_msg(uint8_t version, uint8_t *data, size_t len, struct msg_conn *conn) { - struct mgmt_be_client_ctx *client_ctx; + struct mgmt_be_client *client_ctx; struct msg_client *client; Mgmtd__BeMessage *be_msg; client = container_of(conn, struct msg_client, conn); - client_ctx = container_of(client, struct mgmt_be_client_ctx, client); + client_ctx = container_of(client, struct mgmt_be_client, client); + + if (version == MGMT_MSG_VERSION_NATIVE) { + struct mgmt_msg_header *msg = (typeof(msg))data; + + if (len >= sizeof(*msg)) + be_client_handle_native_msg(client_ctx, msg, len); + else + MGMTD_BE_CLIENT_ERR("native message to client %s too short %zu", + client_ctx->name, len); + return; + } be_msg = mgmtd__be_message__unpack(NULL, len, data); if (!be_msg) { @@ -853,17 +933,17 @@ static void mgmt_be_client_process_msg(uint8_t version, uint8_t *data, mgmtd__be_message__free_unpacked(be_msg, NULL); } -static int mgmt_be_send_subscr_req(struct mgmt_be_client_ctx *client_ctx, - bool subscr_xpaths, uint16_t num_reg_xpaths, - char **reg_xpaths) +int mgmt_be_send_subscr_req(struct mgmt_be_client *client_ctx, + bool subscr_xpaths, int num_xpaths, + char **reg_xpaths) { Mgmtd__BeMessage be_msg; Mgmtd__BeSubscribeReq subscr_req; mgmtd__be_subscribe_req__init(&subscr_req); - subscr_req.client_name = client_ctx->client_params.name; - subscr_req.n_xpath_reg = num_reg_xpaths; - if (num_reg_xpaths) + subscr_req.client_name = client_ctx->name; + subscr_req.n_xpath_reg = num_xpaths; + if (num_xpaths) subscr_req.xpath_reg = reg_xpaths; else subscr_req.xpath_reg = NULL; @@ -873,32 +953,36 @@ static int mgmt_be_send_subscr_req(struct mgmt_be_client_ctx *client_ctx, be_msg.message_case = MGMTD__BE_MESSAGE__MESSAGE_SUBSCR_REQ; be_msg.subscr_req = &subscr_req; - MGMTD_FE_CLIENT_DBG( - "Sending SUBSCR_REQ name: %s subscr_xpaths: %u num_xpaths: %zu", - subscr_req.client_name, subscr_req.subscribe_xpaths, - subscr_req.n_xpath_reg); + MGMTD_BE_CLIENT_DBG("Sending SUBSCR_REQ name: %s subscr_xpaths: %u num_xpaths: %zu", + subscr_req.client_name, subscr_req.subscribe_xpaths, + subscr_req.n_xpath_reg); return mgmt_be_client_send_msg(client_ctx, &be_msg); } -static int _notify_conenct_disconnect(struct msg_client *client, bool connected) +static int _notify_conenct_disconnect(struct msg_client *msg_client, + bool connected) { - struct mgmt_be_client_ctx *client_ctx = - container_of(client, struct mgmt_be_client_ctx, client); + struct mgmt_be_client *client = + container_of(msg_client, struct mgmt_be_client, client); int ret; if (connected) { - assert(client->conn.fd != -1); - ret = mgmt_be_send_subscr_req(client_ctx, false, 0, NULL); + assert(msg_client->conn.fd != -1); + ret = mgmt_be_send_subscr_req(client, false, 0, NULL); if (ret) return ret; } /* Notify BE client through registered callback (if any) */ - if (client_ctx->client_params.client_connect_notify) - (void)(*client_ctx->client_params.client_connect_notify)( - (uintptr_t)client_ctx, - client_ctx->client_params.user_data, connected); + if (client->cbs.client_connect_notify) + (void)(*client->cbs.client_connect_notify)( + client, client->user_data, connected); + + /* Cleanup any in-progress TXN on disconnect */ + if (!connected) + mgmt_be_cleanup_all_txns(client); + return 0; } @@ -914,28 +998,36 @@ static int mgmt_be_client_notify_disconenct(struct msg_conn *conn) return _notify_conenct_disconnect(client, false); } +/* + * Debug Flags + */ + +static void mgmt_debug_client_be_set(uint32_t flags, bool set) +{ + DEBUG_FLAGS_SET(&mgmt_dbg_be_client, flags, set); + + if (!__be_client) + return; + + __be_client->client.conn.debug = DEBUG_MODE_CHECK(&mgmt_dbg_be_client, + DEBUG_MODE_ALL); +} + DEFPY(debug_mgmt_client_be, debug_mgmt_client_be_cmd, "[no] debug mgmt client backend", NO_STR DEBUG_STR MGMTD_STR "client\n" "backend\n") { - uint32_t mode = DEBUG_NODE2MODE(vty->node); - - DEBUG_MODE_SET(&mgmt_dbg_be_client, mode, !no); + mgmt_debug_client_be_set(DEBUG_NODE2MODE(vty->node), !no); return CMD_SUCCESS; } -static void mgmt_debug_client_be_set_all(uint32_t flags, bool set) -{ - DEBUG_FLAGS_SET(&mgmt_dbg_be_client, flags, set); -} - static int mgmt_debug_be_client_config_write(struct vty *vty) { if (DEBUG_MODE_CHECK(&mgmt_dbg_be_client, DEBUG_MODE_CONF)) - vty_out(vty, "debug mgmt client frontend\n"); + vty_out(vty, "debug mgmt client backend\n"); return 1; } @@ -947,41 +1039,48 @@ void mgmt_debug_be_client_show_debug(struct vty *vty) } static struct debug_callbacks mgmt_dbg_be_client_cbs = { - .debug_set_all = mgmt_debug_client_be_set_all}; + .debug_set_all = mgmt_debug_client_be_set +}; static struct cmd_node mgmt_dbg_node = { - .name = "mgmt backend client", - .node = DEBUG_NODE, + .name = "debug mgmt client backend", + .node = MGMT_BE_DEBUG_NODE, .prompt = "", .config_write = mgmt_debug_be_client_config_write, }; -/* - * Initialize library and try connecting with MGMTD. - */ -uintptr_t mgmt_be_client_lib_init(struct mgmt_be_client_params *params, - struct event_loop *master_thread) +struct mgmt_be_client *mgmt_be_client_create(const char *client_name, + struct mgmt_be_client_cbs *cbs, + uintptr_t user_data, + struct event_loop *event_loop) { - /* Don't call twice */ - assert(!mgmt_be_client_ctx.client.conn.loop); + struct mgmt_be_client *client; + + if (__be_client) + return NULL; + + client = XCALLOC(MTYPE_MGMTD_BE_CLIENT, sizeof(*client)); + __be_client = client; /* Only call after frr_init() */ assert(running_config); - mgmt_be_client_ctx.running_config = running_config; - mgmt_be_client_ctx.candidate_config = nb_config_new(NULL); - mgmt_be_client_ctx.client_params = *params; - mgmt_be_txns_init(&mgmt_be_client_ctx.txn_head); - msg_client_init(&mgmt_be_client_ctx.client, master_thread, - MGMTD_BE_SERVER_PATH, mgmt_be_client_notify_conenct, + client->name = XSTRDUP(MTYPE_MGMTD_BE_CLIENT_NAME, client_name); + client->running_config = running_config; + client->candidate_config = nb_config_new(NULL); + if (cbs) + client->cbs = *cbs; + mgmt_be_txns_init(&client->txn_head); + msg_client_init(&client->client, event_loop, MGMTD_BE_SERVER_PATH, + mgmt_be_client_notify_conenct, mgmt_be_client_notify_disconenct, mgmt_be_client_process_msg, MGMTD_BE_MAX_NUM_MSG_PROC, - MGMTD_BE_MAX_NUM_MSG_WRITE, MGMTD_BE_MSG_MAX_LEN, false, + MGMTD_BE_MAX_NUM_MSG_WRITE, MGMTD_BE_MAX_MSG_LEN, false, "BE-client", MGMTD_DBG_BE_CLIENT_CHECK()); - MGMTD_BE_CLIENT_DBG("Initialized client '%s'", params->name); + MGMTD_BE_CLIENT_DBG("Initialized client '%s'", client_name); - return (uintptr_t)&mgmt_be_client_ctx; + return client; } @@ -993,86 +1092,21 @@ void mgmt_be_client_lib_vty_init(void) install_element(CONFIG_NODE, &debug_mgmt_client_be_cmd); } - -/* - * Subscribe with MGMTD for one or more YANG subtree(s). - */ -enum mgmt_result mgmt_be_subscribe_yang_data(uintptr_t lib_hndl, - char *reg_yang_xpaths[], - int num_reg_xpaths) -{ - struct mgmt_be_client_ctx *client_ctx; - - if (!num_reg_xpaths) - return MGMTD_SUCCESS; - - client_ctx = (struct mgmt_be_client_ctx *)lib_hndl; - if (!client_ctx) - return MGMTD_INVALID_PARAM; - - if (mgmt_be_send_subscr_req(client_ctx, true, num_reg_xpaths, - reg_yang_xpaths) - != 0) - return MGMTD_INTERNAL_ERROR; - - return MGMTD_SUCCESS; -} - -/* - * Unsubscribe with MGMTD for one or more YANG subtree(s). - */ -enum mgmt_result mgmt_be_unsubscribe_yang_data(uintptr_t lib_hndl, - char *reg_yang_xpaths[], - int num_reg_xpaths) -{ - struct mgmt_be_client_ctx *client_ctx; - - if (!num_reg_xpaths) - return MGMTD_SUCCESS; - - client_ctx = (struct mgmt_be_client_ctx *)lib_hndl; - if (!client_ctx) - return MGMTD_INVALID_PARAM; - - - if (mgmt_be_send_subscr_req(client_ctx, false, num_reg_xpaths, - reg_yang_xpaths) - < 0) - return MGMTD_INTERNAL_ERROR; - - return MGMTD_SUCCESS; -} - -/* - * Send one or more YANG notifications to MGMTD daemon. - */ -enum mgmt_result mgmt_be_send_yang_notify(uintptr_t lib_hndl, - Mgmtd__YangData * data_elems[], - int num_elems) -{ - struct mgmt_be_client_ctx *client_ctx; - - client_ctx = (struct mgmt_be_client_ctx *)lib_hndl; - if (!client_ctx) - return MGMTD_INVALID_PARAM; - - return MGMTD_SUCCESS; -} - -/* - * Destroy library and cleanup everything. - */ -void mgmt_be_client_lib_destroy(void) +void mgmt_be_client_destroy(struct mgmt_be_client *client) { - struct mgmt_be_client_ctx *client_ctx = &mgmt_be_client_ctx; + assert(client == __be_client); MGMTD_BE_CLIENT_DBG("Destroying MGMTD Backend Client '%s'", - client_ctx->client_params.name); + client->name); + + nb_oper_cancel_all_walks(); + msg_client_cleanup(&client->client); + mgmt_be_cleanup_all_txns(client); + mgmt_be_txns_fini(&client->txn_head); + nb_config_free(client->candidate_config); - msg_client_cleanup(&client_ctx->client); - mgmt_be_cleanup_all_txns(client_ctx); - mgmt_be_txns_fini(&client_ctx->txn_head); - nb_config_free(client_ctx->candidate_config); + XFREE(MTYPE_MGMTD_BE_CLIENT_NAME, client->name); + XFREE(MTYPE_MGMTD_BE_CLIENT, client); - memset(client_ctx, 0, sizeof(*client_ctx)); + __be_client = NULL; } diff --git a/lib/mgmt_be_client.h b/lib/mgmt_be_client.h index bbe938b5b4..8ad482cacf 100644 --- a/lib/mgmt_be_client.h +++ b/lib/mgmt_be_client.h @@ -14,52 +14,18 @@ extern "C" { #include "northbound.h" #include "mgmt_pb.h" -#include "mgmtd/mgmt_defines.h" - -/*************************************************************** - * Client IDs - ***************************************************************/ - -/* - * Add enum value for each supported component, wrap with - * #ifdef HAVE_COMPONENT - */ -enum mgmt_be_client_id { - MGMTD_BE_CLIENT_ID_MIN = 0, - MGMTD_BE_CLIENT_ID_INIT = -1, -#ifdef HAVE_STATICD - MGMTD_BE_CLIENT_ID_STATICD, -#endif - MGMTD_BE_CLIENT_ID_MAX -}; - -#define FOREACH_MGMTD_BE_CLIENT_ID(id) \ - for ((id) = MGMTD_BE_CLIENT_ID_MIN; \ - (id) < MGMTD_BE_CLIENT_ID_MAX; (id)++) +#include "mgmt_defines.h" /*************************************************************** * Constants ***************************************************************/ -#define MGMTD_BE_CLIENT_ERROR_STRING_MAX_LEN 32 - -#define MGMTD_BE_DEFAULT_CONN_RETRY_INTVL_SEC 5 - -#define MGMTD_BE_MSG_PROC_DELAY_USEC 10 -#define MGMTD_BE_MAX_NUM_MSG_PROC 500 - -#define MGMTD_BE_MSG_WRITE_DELAY_MSEC 1 +#define MGMTD_BE_MAX_NUM_MSG_PROC 500 #define MGMTD_BE_MAX_NUM_MSG_WRITE 1000 +#define MGMTD_BE_MAX_MSG_LEN (64 * 1024) -#define GMGD_BE_MAX_NUM_REQ_ITEMS 64 - -#define MGMTD_BE_MSG_MAX_LEN 16384 - -#define MGMTD_SOCKET_BE_SEND_BUF_SIZE 65535 -#define MGMTD_SOCKET_BE_RECV_BUF_SIZE MGMTD_SOCKET_BE_SEND_BUF_SIZE - -#define MGMTD_MAX_CFG_CHANGES_IN_BATCH \ - ((10 * MGMTD_BE_MSG_MAX_LEN) / \ +#define MGMTD_MAX_CFG_CHANGES_IN_BATCH \ + ((10 * MGMTD_BE_MAX_MSG_LEN) / \ (MGMTD_MAX_XPATH_LEN + MGMTD_MAX_YANG_VALUE_LEN)) /* @@ -68,11 +34,11 @@ enum mgmt_be_client_id { * that gets added to sent message */ #define MGMTD_BE_CFGDATA_PACKING_EFFICIENCY 0.8 -#define MGMTD_BE_CFGDATA_MAX_MSG_LEN \ - (MGMTD_BE_MSG_MAX_LEN * MGMTD_BE_CFGDATA_PACKING_EFFICIENCY) +#define MGMTD_BE_CFGDATA_MAX_MSG_LEN \ + (MGMTD_BE_MAX_MSG_LEN * MGMTD_BE_CFGDATA_PACKING_EFFICIENCY) -#define MGMTD_BE_MAX_BATCH_IDS_IN_REQ \ - (MGMTD_BE_MSG_MAX_LEN - 128) / sizeof(uint64_t) +#define MGMTD_BE_MAX_BATCH_IDS_IN_REQ \ + (MGMTD_BE_MAX_MSG_LEN - 128) / sizeof(uint64_t) #define MGMTD_BE_CONTAINER_NODE_VAL "<<container>>" @@ -82,114 +48,60 @@ enum mgmt_be_client_id { #define MGMTD_BE_MAX_CLIENTS_PER_XPATH_REG 32 +struct mgmt_be_client; + struct mgmt_be_client_txn_ctx { uintptr_t *user_ctx; }; -/* - * All the client-specific information this library needs to - * initialize itself, setup connection with MGMTD BackEnd interface - * and carry on all required procedures appropriately. +/** + * Backend client callbacks. * - * BackEnd clients need to initialise a instance of this structure - * with appropriate data and pass it while calling the API - * to initialize the library (See mgmt_be_client_lib_init for - * more details). + * Callbacks: + * client_connect_notify: called when connection is made/lost to mgmtd. + * txn_notify: called when a txn has been created */ -struct mgmt_be_client_params { - char name[MGMTD_CLIENT_NAME_MAX_LEN]; - uintptr_t user_data; - unsigned long conn_retry_intvl_sec; - - void (*client_connect_notify)(uintptr_t lib_hndl, - uintptr_t usr_data, - bool connected); - - void (*client_subscribe_notify)( - uintptr_t lib_hndl, uintptr_t usr_data, - struct nb_yang_xpath **xpath, - enum mgmt_result subscribe_result[], int num_paths); - - void (*txn_notify)( - uintptr_t lib_hndl, uintptr_t usr_data, - struct mgmt_be_client_txn_ctx *txn_ctx, bool destroyed); +struct mgmt_be_client_cbs { + void (*client_connect_notify)(struct mgmt_be_client *client, + uintptr_t usr_data, bool connected); - enum mgmt_result (*data_validate)( - uintptr_t lib_hndl, uintptr_t usr_data, - struct mgmt_be_client_txn_ctx *txn_ctx, - struct nb_yang_xpath *xpath, struct nb_yang_value *data, - bool delete, char *error_if_any); - - enum mgmt_result (*data_apply)( - uintptr_t lib_hndl, uintptr_t usr_data, - struct mgmt_be_client_txn_ctx *txn_ctx, - struct nb_yang_xpath *xpath, struct nb_yang_value *data, - bool delete); - - enum mgmt_result (*get_data_elem)( - uintptr_t lib_hndl, uintptr_t usr_data, - struct mgmt_be_client_txn_ctx *txn_ctx, - struct nb_yang_xpath *xpath, struct nb_yang_xpath_elem *elem); - - enum mgmt_result (*get_data)( - uintptr_t lib_hndl, uintptr_t usr_data, - struct mgmt_be_client_txn_ctx *txn_ctx, - struct nb_yang_xpath *xpath, bool keys_only, - struct nb_yang_xpath_elem **elems, int *num_elems, - int *next_key); - - enum mgmt_result (*get_next_data)( - uintptr_t lib_hndl, uintptr_t usr_data, - struct mgmt_be_client_txn_ctx *txn_ctx, - struct nb_yang_xpath *xpath, bool keys_only, - struct nb_yang_xpath_elem **elems, int *num_elems); + void (*txn_notify)(struct mgmt_be_client *client, uintptr_t usr_data, + struct mgmt_be_client_txn_ctx *txn_ctx, + bool destroyed); }; /*************************************************************** * Global data exported ***************************************************************/ -extern const char *mgmt_be_client_names[MGMTD_BE_CLIENT_ID_MAX + 1]; - -static inline const char *mgmt_be_client_id2name(enum mgmt_be_client_id id) -{ - if (id > MGMTD_BE_CLIENT_ID_MAX) - id = MGMTD_BE_CLIENT_ID_MAX; - return mgmt_be_client_names[id]; -} - -static inline enum mgmt_be_client_id -mgmt_be_client_name2id(const char *name) -{ - enum mgmt_be_client_id id; - - FOREACH_MGMTD_BE_CLIENT_ID (id) { - if (!strncmp(mgmt_be_client_names[id], name, - MGMTD_CLIENT_NAME_MAX_LEN)) - return id; - } - - return MGMTD_BE_CLIENT_ID_MAX; -} +extern struct debug mgmt_dbg_be_client; /*************************************************************** * API prototypes ***************************************************************/ -/* - * Initialize library and try connecting with MGMTD. - * - * params - * Backend client parameters. +#define MGMTD_BE_CLIENT_DBG(fmt, ...) \ + DEBUGD(&mgmt_dbg_be_client, "BE-CLIENT: %s: " fmt, __func__, \ + ##__VA_ARGS__) +#define MGMTD_BE_CLIENT_ERR(fmt, ...) \ + zlog_err("BE-CLIENT: %s: ERROR: " fmt, __func__, ##__VA_ARGS__) +#define MGMTD_DBG_BE_CLIENT_CHECK() \ + DEBUG_MODE_CHECK(&mgmt_dbg_be_client, DEBUG_MODE_ALL) + +/** + * Create backend client and connect to MGMTD. * - * master_thread - * Thread master. + * Args: + * client_name: the name of the client + * cbs: callbacks for various events. + * event_loop: the main event loop. * * Returns: - * Backend client lib handler (nothing but address of mgmt_be_client_ctx) + * Backend client object. */ -extern uintptr_t mgmt_be_client_lib_init(struct mgmt_be_client_params *params, - struct event_loop *master_thread); +extern struct mgmt_be_client * +mgmt_be_client_create(const char *name, struct mgmt_be_client_cbs *cbs, + uintptr_t user_data, struct event_loop *event_loop); /* * Initialize library vty (adds debug support). @@ -206,13 +118,13 @@ extern void mgmt_be_client_lib_vty_init(void); extern void mgmt_debug_be_client_show_debug(struct vty *vty); /* - * Subscribe with MGMTD for one or more YANG subtree(s). + * [Un]-subscribe with MGMTD for one or more YANG subtree(s). * - * lib_hndl - * Client library handler. + * client + * The client object. * * reg_yang_xpaths - * Yang xpath(s) that needs to be subscribed to. + * Yang xpath(s) that needs to be [un]-subscribed from/to * * num_xpaths * Number of xpaths @@ -220,52 +132,14 @@ extern void mgmt_debug_be_client_show_debug(struct vty *vty); * Returns: * MGMTD_SUCCESS on success, MGMTD_* otherwise. */ -extern enum mgmt_result mgmt_be_subscribe_yang_data(uintptr_t lib_hndl, - char **reg_yang_xpaths, - int num_xpaths); - -/* - * Send one or more YANG notifications to MGMTD daemon. - * - * lib_hndl - * Client library handler. - * - * data_elems - * Yang data elements from data tree. - * - * num_elems - * Number of data elements. - * - * Returns: - * MGMTD_SUCCESS on success, MGMTD_* otherwise. - */ -extern enum mgmt_result -mgmt_be_send_yang_notify(uintptr_t lib_hndl, Mgmtd__YangData **data_elems, - int num_elems); - -/* - * Un-subscribe with MGMTD for one or more YANG subtree(s). - * - * lib_hndl - * Client library handler. - * - * reg_yang_xpaths - * Yang xpath(s) that needs to be un-subscribed from. - * - * num_reg_xpaths - * Number of subscribed xpaths - * - * Returns: - * MGMTD_SUCCESS on success, MGMTD_* otherwise. - */ -enum mgmt_result mgmt_be_unsubscribe_yang_data(uintptr_t lib_hndl, - char **reg_yang_xpaths, - int num_reg_xpaths); +extern int mgmt_be_send_subscr_req(struct mgmt_be_client *client, + bool subscr_xpaths, int num_xpaths, + char **reg_xpaths); /* - * Destroy library and cleanup everything. + * Destroy backend client and cleanup everything. */ -extern void mgmt_be_client_lib_destroy(void); +extern void mgmt_be_client_destroy(struct mgmt_be_client *client); #ifdef __cplusplus } diff --git a/mgmtd/mgmt_defines.h b/lib/mgmt_defines.h similarity index 63% rename from mgmtd/mgmt_defines.h rename to lib/mgmt_defines.h index 40fa67075d..3b7f8f1ef6 100644 --- a/mgmtd/mgmt_defines.h +++ b/lib/mgmt_defines.h @@ -32,27 +32,4 @@ enum mgmt_result { MGMTD_UNKNOWN_FAILURE }; -enum mgmt_fe_event { - MGMTD_FE_SERVER = 1, - MGMTD_FE_CONN_READ, - MGMTD_FE_CONN_WRITE, - MGMTD_FE_PROC_MSG -}; - -enum mgmt_be_event { - MGMTD_BE_SERVER = 1, - MGMTD_BE_CONN_INIT, - MGMTD_BE_CONN_READ, - MGMTD_BE_CONN_WRITE, - MGMTD_BE_PROC_MSG, - MGMTD_BE_SCHED_CFG_PREPARE, - MGMTD_BE_RESCHED_CFG_PREPARE, - MGMTD_BE_SCHED_CFG_APPLY, - MGMTD_BE_RESCHED_CFG_APPLY, -}; - -#define MGMTD_TXN_ID_NONE 0 - -#define MGMTD_TXN_BATCH_ID_NONE 0 - #endif /* _FRR_MGMTD_DEFINES_H */ diff --git a/lib/mgmt_fe_client.c b/lib/mgmt_fe_client.c index 83f60ea58b..0bea663004 100644 --- a/lib/mgmt_fe_client.c +++ b/lib/mgmt_fe_client.c @@ -12,6 +12,7 @@ #include "libfrr.h" #include "mgmt_fe_client.h" #include "mgmt_msg.h" +#include "mgmt_msg_native.h" #include "mgmt_pb.h" #include "network.h" #include "stream.h" @@ -19,14 +20,12 @@ #include "lib/mgmt_fe_client_clippy.c" -struct mgmt_fe_client_ctx; - PREDECL_LIST(mgmt_sessions); struct mgmt_fe_client_session { uint64_t client_id; /* FE client identifies itself with this ID */ uint64_t session_id; /* FE adapter identified session with this ID */ - struct mgmt_fe_client_ctx *client_ctx; + struct mgmt_fe_client *client; uintptr_t user_ctx; struct mgmt_sessions_item list_linkage; @@ -34,29 +33,51 @@ struct mgmt_fe_client_session { DECLARE_LIST(mgmt_sessions, struct mgmt_fe_client_session, list_linkage); -DEFINE_MTYPE_STATIC(LIB, MGMTD_FE_SESSION, "MGMTD Frontend session"); +DEFINE_MTYPE_STATIC(LIB, MGMTD_FE_CLIENT, "frontend client"); +DEFINE_MTYPE_STATIC(LIB, MGMTD_FE_CLIENT_NAME, "frontend client name"); +DEFINE_MTYPE_STATIC(LIB, MGMTD_FE_SESSION, "frontend session"); -struct mgmt_fe_client_ctx { +struct mgmt_fe_client { struct msg_client client; - struct mgmt_fe_client_params client_params; - struct mgmt_sessions_head client_sessions; + char *name; + struct mgmt_fe_client_cbs cbs; + uintptr_t user_data; + struct mgmt_sessions_head sessions; }; -#define FOREACH_SESSION_IN_LIST(client_ctx, session) \ - frr_each_safe (mgmt_sessions, &(client_ctx)->client_sessions, (session)) +#define FOREACH_SESSION_IN_LIST(client, session) \ + frr_each_safe (mgmt_sessions, &(client)->sessions, (session)) -struct debug mgmt_dbg_fe_client = {0, "Management frontend client operations"}; +struct debug mgmt_dbg_fe_client = { + .desc = "Management frontend client operations" +}; -static struct mgmt_fe_client_ctx mgmt_fe_client_ctx = { - .client = {.conn = {.fd = -1}}}; +/* NOTE: only one client per proc for now. */ +static struct mgmt_fe_client *__fe_client; + +static inline const char *dsid2name(Mgmtd__DatastoreId id) +{ + switch ((int)id) { + case MGMTD_DS_NONE: + return "none"; + case MGMTD_DS_RUNNING: + return "running"; + case MGMTD_DS_CANDIDATE: + return "candidate"; + case MGMTD_DS_OPERATIONAL: + return "operational"; + default: + return "unknown-datastore-id"; + } +} static struct mgmt_fe_client_session * -mgmt_fe_find_session_by_client_id(struct mgmt_fe_client_ctx *client_ctx, +mgmt_fe_find_session_by_client_id(struct mgmt_fe_client *client, uint64_t client_id) { struct mgmt_fe_client_session *session; - FOREACH_SESSION_IN_LIST (client_ctx, session) { + FOREACH_SESSION_IN_LIST (client, session) { if (session->client_id == client_id) { MGMTD_FE_CLIENT_DBG("Found session-id %" PRIu64 " using client-id %" PRIu64, @@ -70,12 +91,12 @@ mgmt_fe_find_session_by_client_id(struct mgmt_fe_client_ctx *client_ctx, } static struct mgmt_fe_client_session * -mgmt_fe_find_session_by_session_id(struct mgmt_fe_client_ctx *client_ctx, +mgmt_fe_find_session_by_session_id(struct mgmt_fe_client *client, uint64_t session_id) { struct mgmt_fe_client_session *session; - FOREACH_SESSION_IN_LIST (client_ctx, session) { + FOREACH_SESSION_IN_LIST (client, session) { if (session->session_id == session_id) { MGMTD_FE_CLIENT_DBG( "Found session of client-id %" PRIu64 @@ -89,24 +110,24 @@ mgmt_fe_find_session_by_session_id(struct mgmt_fe_client_ctx *client_ctx, return NULL; } -static int mgmt_fe_client_send_msg(struct mgmt_fe_client_ctx *client_ctx, +static int mgmt_fe_client_send_msg(struct mgmt_fe_client *client, Mgmtd__FeMessage *fe_msg, bool short_circuit_ok) { return msg_conn_send_msg( - &client_ctx->client.conn, MGMT_MSG_VERSION_PROTOBUF, fe_msg, + &client->client.conn, MGMT_MSG_VERSION_PROTOBUF, fe_msg, mgmtd__fe_message__get_packed_size(fe_msg), (size_t(*)(void *, void *))mgmtd__fe_message__pack, short_circuit_ok); } -static int mgmt_fe_send_register_req(struct mgmt_fe_client_ctx *client_ctx) +static int mgmt_fe_send_register_req(struct mgmt_fe_client *client) { Mgmtd__FeMessage fe_msg; Mgmtd__FeRegisterReq rgstr_req; mgmtd__fe_register_req__init(&rgstr_req); - rgstr_req.client_name = client_ctx->client_params.name; + rgstr_req.client_name = client->name; mgmtd__fe_message__init(&fe_msg); fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_REGISTER_REQ; @@ -115,27 +136,24 @@ static int mgmt_fe_send_register_req(struct mgmt_fe_client_ctx *client_ctx) MGMTD_FE_CLIENT_DBG( "Sending REGISTER_REQ message to MGMTD Frontend server"); - return mgmt_fe_client_send_msg(client_ctx, &fe_msg, true); + return mgmt_fe_client_send_msg(client, &fe_msg, true); } -static int mgmt_fe_send_session_req(struct mgmt_fe_client_ctx *client_ctx, +static int mgmt_fe_send_session_req(struct mgmt_fe_client *client, struct mgmt_fe_client_session *session, bool create) { Mgmtd__FeMessage fe_msg; Mgmtd__FeSessionReq sess_req; - bool scok; mgmtd__fe_session_req__init(&sess_req); sess_req.create = create; if (create) { sess_req.id_case = MGMTD__FE_SESSION_REQ__ID_CLIENT_CONN_ID; sess_req.client_conn_id = session->client_id; - scok = true; } else { sess_req.id_case = MGMTD__FE_SESSION_REQ__ID_SESSION_ID; sess_req.session_id = session->session_id; - scok = false; } mgmtd__fe_message__init(&fe_msg); @@ -146,12 +164,12 @@ static int mgmt_fe_send_session_req(struct mgmt_fe_client_ctx *client_ctx, "Sending SESSION_REQ %s message for client-id %" PRIu64, create ? "create" : "destroy", session->client_id); - return mgmt_fe_client_send_msg(client_ctx, &fe_msg, scok); + return mgmt_fe_client_send_msg(client, &fe_msg, true); } -static int mgmt_fe_send_lockds_req(struct mgmt_fe_client_ctx *client_ctx, - uint64_t session_id, bool lock, - uint64_t req_id, Mgmtd__DatastoreId ds_id) +int mgmt_fe_send_lockds_req(struct mgmt_fe_client *client, uint64_t session_id, + uint64_t req_id, Mgmtd__DatastoreId ds_id, + bool lock, bool scok) { (void)req_id; Mgmtd__FeMessage fe_msg; @@ -168,18 +186,17 @@ static int mgmt_fe_send_lockds_req(struct mgmt_fe_client_ctx *client_ctx, fe_msg.lockds_req = &lockds_req; MGMTD_FE_CLIENT_DBG( - "Sending %sLOCK_REQ message for Ds:%d session-id %" PRIu64, - lock ? "" : "UN", ds_id, session_id); + "Sending LOCKDS_REQ (%sLOCK) message for DS:%s session-id %" PRIu64, + lock ? "" : "UN", dsid2name(ds_id), session_id); + - return mgmt_fe_client_send_msg(client_ctx, &fe_msg, false); + return mgmt_fe_client_send_msg(client, &fe_msg, scok); } -static int mgmt_fe_send_setcfg_req(struct mgmt_fe_client_ctx *client_ctx, - uint64_t session_id, uint64_t req_id, - Mgmtd__DatastoreId ds_id, - Mgmtd__YangCfgDataReq **data_req, - int num_data_reqs, bool implicit_commit, - Mgmtd__DatastoreId dst_ds_id) +int mgmt_fe_send_setcfg_req(struct mgmt_fe_client *client, uint64_t session_id, + uint64_t req_id, Mgmtd__DatastoreId ds_id, + Mgmtd__YangCfgDataReq **data_req, int num_data_reqs, + bool implicit_commit, Mgmtd__DatastoreId dst_ds_id) { (void)req_id; Mgmtd__FeMessage fe_msg; @@ -199,18 +216,18 @@ static int mgmt_fe_send_setcfg_req(struct mgmt_fe_client_ctx *client_ctx, fe_msg.setcfg_req = &setcfg_req; MGMTD_FE_CLIENT_DBG( - "Sending SET_CONFIG_REQ message for Ds:%d session-id %" PRIu64 + "Sending SET_CONFIG_REQ message for DS:%s session-id %" PRIu64 " (#xpaths:%d)", - ds_id, session_id, num_data_reqs); + dsid2name(ds_id), session_id, num_data_reqs); - return mgmt_fe_client_send_msg(client_ctx, &fe_msg, false); + return mgmt_fe_client_send_msg(client, &fe_msg, false); } -static int mgmt_fe_send_commitcfg_req(struct mgmt_fe_client_ctx *client_ctx, - uint64_t session_id, uint64_t req_id, - Mgmtd__DatastoreId src_ds_id, - Mgmtd__DatastoreId dest_ds_id, - bool validate_only, bool abort) +int mgmt_fe_send_commitcfg_req(struct mgmt_fe_client *client, + uint64_t session_id, uint64_t req_id, + Mgmtd__DatastoreId src_ds_id, + Mgmtd__DatastoreId dest_ds_id, + bool validate_only, bool abort) { (void)req_id; Mgmtd__FeMessage fe_msg; @@ -229,76 +246,46 @@ static int mgmt_fe_send_commitcfg_req(struct mgmt_fe_client_ctx *client_ctx, fe_msg.commcfg_req = &commitcfg_req; MGMTD_FE_CLIENT_DBG( - "Sending COMMIT_CONFIG_REQ message for Src-Ds:%d, Dst-Ds:%d session-id %" PRIu64, - src_ds_id, dest_ds_id, session_id); + "Sending COMMIT_CONFIG_REQ message for Src-DS:%s, Dst-DS:%s session-id %" PRIu64, + dsid2name(src_ds_id), dsid2name(dest_ds_id), session_id); - return mgmt_fe_client_send_msg(client_ctx, &fe_msg, false); + return mgmt_fe_client_send_msg(client, &fe_msg, false); } -static int mgmt_fe_send_getcfg_req(struct mgmt_fe_client_ctx *client_ctx, - uint64_t session_id, uint64_t req_id, - Mgmtd__DatastoreId ds_id, - Mgmtd__YangGetDataReq *data_req[], - int num_data_reqs) +int mgmt_fe_send_get_req(struct mgmt_fe_client *client, uint64_t session_id, + uint64_t req_id, bool is_config, + Mgmtd__DatastoreId ds_id, + Mgmtd__YangGetDataReq *data_req[], int num_data_reqs) { (void)req_id; Mgmtd__FeMessage fe_msg; - Mgmtd__FeGetConfigReq getcfg_req; + Mgmtd__FeGetReq getcfg_req; - mgmtd__fe_get_config_req__init(&getcfg_req); + mgmtd__fe_get_req__init(&getcfg_req); getcfg_req.session_id = session_id; + getcfg_req.config = is_config; getcfg_req.ds_id = ds_id; getcfg_req.req_id = req_id; getcfg_req.data = data_req; getcfg_req.n_data = (size_t)num_data_reqs; mgmtd__fe_message__init(&fe_msg); - fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REQ; - fe_msg.getcfg_req = &getcfg_req; + fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GET_REQ; + fe_msg.get_req = &getcfg_req; - MGMTD_FE_CLIENT_DBG( - "Sending GET_CONFIG_REQ message for Ds:%d session-id %" PRIu64 - " (#xpaths:%d)", - ds_id, session_id, num_data_reqs); + MGMTD_FE_CLIENT_DBG("Sending GET_REQ (iscfg %d) message for DS:%s session-id %" PRIu64 + " (#xpaths:%d)", + is_config, dsid2name(ds_id), session_id, + num_data_reqs); - return mgmt_fe_client_send_msg(client_ctx, &fe_msg, false); + return mgmt_fe_client_send_msg(client, &fe_msg, false); } -static int mgmt_fe_send_getdata_req(struct mgmt_fe_client_ctx *client_ctx, - uint64_t session_id, uint64_t req_id, - Mgmtd__DatastoreId ds_id, - Mgmtd__YangGetDataReq *data_req[], - int num_data_reqs) -{ - (void)req_id; - Mgmtd__FeMessage fe_msg; - Mgmtd__FeGetDataReq getdata_req; - - mgmtd__fe_get_data_req__init(&getdata_req); - getdata_req.session_id = session_id; - getdata_req.ds_id = ds_id; - getdata_req.req_id = req_id; - getdata_req.data = data_req; - getdata_req.n_data = (size_t)num_data_reqs; - - mgmtd__fe_message__init(&fe_msg); - fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GETDATA_REQ; - fe_msg.getdata_req = &getdata_req; - - MGMTD_FE_CLIENT_DBG( - "Sending GET_CONFIG_REQ message for Ds:%d session-id %" PRIu64 - " (#xpaths:%d)", - ds_id, session_id, num_data_reqs); - - return mgmt_fe_client_send_msg(client_ctx, &fe_msg, false); -} - -static int mgmt_fe_send_regnotify_req(struct mgmt_fe_client_ctx *client_ctx, - uint64_t session_id, uint64_t req_id, - Mgmtd__DatastoreId ds_id, - bool register_req, - Mgmtd__YangDataXPath *data_req[], - int num_data_reqs) +int mgmt_fe_send_regnotify_req(struct mgmt_fe_client *client, + uint64_t session_id, uint64_t req_id, + Mgmtd__DatastoreId ds_id, bool register_req, + Mgmtd__YangDataXPath *data_req[], + int num_data_reqs) { (void)req_id; Mgmtd__FeMessage fe_msg; @@ -315,10 +302,39 @@ static int mgmt_fe_send_regnotify_req(struct mgmt_fe_client_ctx *client_ctx, fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_REGNOTIFY_REQ; fe_msg.regnotify_req = ®ntfy_req; - return mgmt_fe_client_send_msg(client_ctx, &fe_msg, false); + return mgmt_fe_client_send_msg(client, &fe_msg, false); +} + +/* + * Send get-tree request. + */ +int mgmt_fe_send_get_tree_req(struct mgmt_fe_client *client, + uint64_t session_id, uint64_t req_id, + LYD_FORMAT result_type, const char *xpath) +{ + struct mgmt_msg_get_tree *msg; + size_t xplen = strlen(xpath); + int ret; + + msg = mgmt_msg_native_alloc_msg(struct mgmt_msg_get_tree, xplen + 1, + MTYPE_MSG_NATIVE_GET_TREE); + msg->refer_id = session_id; + msg->req_id = req_id; + msg->code = MGMT_MSG_CODE_GET_TREE; + msg->result_type = result_type; + strlcpy(msg->xpath, xpath, xplen + 1); + + MGMTD_FE_CLIENT_DBG("Sending GET_TREE_REQ session-id %" PRIu64 + " req-id %" PRIu64 " xpath: %s", + session_id, req_id, xpath); + + ret = mgmt_msg_native_send_msg(&client->client.conn, msg, false); + mgmt_msg_native_free_msg(msg); + return ret; } -static int mgmt_fe_client_handle_msg(struct mgmt_fe_client_ctx *client_ctx, + +static int mgmt_fe_client_handle_msg(struct mgmt_fe_client *client, Mgmtd__FeMessage *fe_msg) { struct mgmt_fe_client_session *session = NULL; @@ -338,8 +354,7 @@ static int mgmt_fe_client_handle_msg(struct mgmt_fe_client_ctx *client_ctx, fe_msg->session_reply->session_id); session = mgmt_fe_find_session_by_client_id( - client_ctx, - fe_msg->session_reply->client_conn_id); + client, fe_msg->session_reply->client_conn_id); if (session && fe_msg->session_reply->success) { MGMTD_FE_CLIENT_DBG( @@ -358,17 +373,14 @@ static int mgmt_fe_client_handle_msg(struct mgmt_fe_client_ctx *client_ctx, fe_msg->session_reply->session_id); session = mgmt_fe_find_session_by_session_id( - client_ctx, fe_msg->session_req->session_id); + client, fe_msg->session_req->session_id); } /* The session state may be deleted by the callback */ - if (session && session->client_ctx && - session->client_ctx->client_params.client_session_notify) - (*session->client_ctx->client_params - .client_session_notify)( - (uintptr_t)client_ctx, - client_ctx->client_params.user_data, - session->client_id, + if (session && session->client && + session->client->cbs.client_session_notify) + (*session->client->cbs.client_session_notify)( + client, client->user_data, session->client_id, fe_msg->session_reply->create, fe_msg->session_reply->success, fe_msg->session_reply->session_id, @@ -378,14 +390,12 @@ static int mgmt_fe_client_handle_msg(struct mgmt_fe_client_ctx *client_ctx, MGMTD_FE_CLIENT_DBG("Got LOCKDS_REPLY for session-id %" PRIu64, fe_msg->lockds_reply->session_id); session = mgmt_fe_find_session_by_session_id( - client_ctx, fe_msg->lockds_reply->session_id); - - if (session && session->client_ctx && - session->client_ctx->client_params.lock_ds_notify) - (*session->client_ctx->client_params.lock_ds_notify)( - (uintptr_t)client_ctx, - client_ctx->client_params.user_data, - session->client_id, + client, fe_msg->lockds_reply->session_id); + + if (session && session->client && + session->client->cbs.lock_ds_notify) + (*session->client->cbs.lock_ds_notify)( + client, client->user_data, session->client_id, fe_msg->lockds_reply->session_id, session->user_ctx, fe_msg->lockds_reply->req_id, fe_msg->lockds_reply->lock, @@ -398,18 +408,17 @@ static int mgmt_fe_client_handle_msg(struct mgmt_fe_client_ctx *client_ctx, fe_msg->setcfg_reply->session_id); session = mgmt_fe_find_session_by_session_id( - client_ctx, fe_msg->setcfg_reply->session_id); - - if (session && session->client_ctx && - session->client_ctx->client_params.set_config_notify) - (*session->client_ctx->client_params.set_config_notify)( - (uintptr_t)client_ctx, - client_ctx->client_params.user_data, - session->client_id, + client, fe_msg->setcfg_reply->session_id); + + if (session && session->client && + session->client->cbs.set_config_notify) + (*session->client->cbs.set_config_notify)( + client, client->user_data, session->client_id, fe_msg->setcfg_reply->session_id, session->user_ctx, fe_msg->setcfg_reply->req_id, fe_msg->setcfg_reply->success, fe_msg->setcfg_reply->ds_id, + fe_msg->setcfg_reply->implicit_commit, fe_msg->setcfg_reply->error_if_any); break; case MGMTD__FE_MESSAGE__MESSAGE_COMMCFG_REPLY: @@ -417,15 +426,12 @@ static int mgmt_fe_client_handle_msg(struct mgmt_fe_client_ctx *client_ctx, fe_msg->commcfg_reply->session_id); session = mgmt_fe_find_session_by_session_id( - client_ctx, fe_msg->commcfg_reply->session_id); - - if (session && session->client_ctx && - session->client_ctx->client_params.commit_config_notify) - (*session->client_ctx->client_params - .commit_config_notify)( - (uintptr_t)client_ctx, - client_ctx->client_params.user_data, - session->client_id, + client, fe_msg->commcfg_reply->session_id); + + if (session && session->client && + session->client->cbs.commit_config_notify) + (*session->client->cbs.commit_config_notify)( + client, client->user_data, session->client_id, fe_msg->commcfg_reply->session_id, session->user_ctx, fe_msg->commcfg_reply->req_id, @@ -435,62 +441,33 @@ static int mgmt_fe_client_handle_msg(struct mgmt_fe_client_ctx *client_ctx, fe_msg->commcfg_reply->validate_only, fe_msg->commcfg_reply->error_if_any); break; - case MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REPLY: - MGMTD_FE_CLIENT_DBG("Got GETCFG_REPLY for session-id %" PRIu64, - fe_msg->getcfg_reply->session_id); - - session = mgmt_fe_find_session_by_session_id( - client_ctx, fe_msg->getcfg_reply->session_id); - - if (session && session->client_ctx && - session->client_ctx->client_params.get_data_notify) - (*session->client_ctx->client_params.get_data_notify)( - (uintptr_t)client_ctx, - client_ctx->client_params.user_data, - session->client_id, - fe_msg->getcfg_reply->session_id, - session->user_ctx, fe_msg->getcfg_reply->req_id, - fe_msg->getcfg_reply->success, - fe_msg->getcfg_reply->ds_id, - fe_msg->getcfg_reply->data - ? fe_msg->getcfg_reply->data->data - : NULL, - fe_msg->getcfg_reply->data - ? fe_msg->getcfg_reply->data->n_data - : 0, - fe_msg->getcfg_reply->data - ? fe_msg->getcfg_reply->data->next_indx - : 0, - fe_msg->getcfg_reply->error_if_any); - break; - case MGMTD__FE_MESSAGE__MESSAGE_GETDATA_REPLY: - MGMTD_FE_CLIENT_DBG("Got GETDATA_REPLY for session-id %" PRIu64, - fe_msg->getdata_reply->session_id); - - session = mgmt_fe_find_session_by_session_id( - client_ctx, fe_msg->getdata_reply->session_id); - - if (session && session->client_ctx && - session->client_ctx->client_params.get_data_notify) - (*session->client_ctx->client_params.get_data_notify)( - (uintptr_t)client_ctx, - client_ctx->client_params.user_data, - session->client_id, - fe_msg->getdata_reply->session_id, - session->user_ctx, - fe_msg->getdata_reply->req_id, - fe_msg->getdata_reply->success, - fe_msg->getdata_reply->ds_id, - fe_msg->getdata_reply->data - ? fe_msg->getdata_reply->data->data + case MGMTD__FE_MESSAGE__MESSAGE_GET_REPLY: + MGMTD_FE_CLIENT_DBG("Got GET_REPLY for session-id %" PRIu64, + fe_msg->get_reply->session_id); + + session = + mgmt_fe_find_session_by_session_id(client, + fe_msg->get_reply + ->session_id); + + if (session && session->client && + session->client->cbs.get_data_notify) + (*session->client->cbs.get_data_notify)( + client, client->user_data, session->client_id, + fe_msg->get_reply->session_id, + session->user_ctx, fe_msg->get_reply->req_id, + fe_msg->get_reply->success, + fe_msg->get_reply->ds_id, + fe_msg->get_reply->data + ? fe_msg->get_reply->data->data : NULL, - fe_msg->getdata_reply->data - ? fe_msg->getdata_reply->data->n_data + fe_msg->get_reply->data + ? fe_msg->get_reply->data->n_data : 0, - fe_msg->getdata_reply->data - ? fe_msg->getdata_reply->data->next_indx + fe_msg->get_reply->data + ? fe_msg->get_reply->data->next_indx : 0, - fe_msg->getdata_reply->error_if_any); + fe_msg->get_reply->error_if_any); break; case MGMTD__FE_MESSAGE__MESSAGE_NOTIFY_DATA_REQ: case MGMTD__FE_MESSAGE__MESSAGE_REGNOTIFY_REQ: @@ -507,8 +484,7 @@ static int mgmt_fe_client_handle_msg(struct mgmt_fe_client_ctx *client_ctx, case MGMTD__FE_MESSAGE__MESSAGE_LOCKDS_REQ: case MGMTD__FE_MESSAGE__MESSAGE_SETCFG_REQ: case MGMTD__FE_MESSAGE__MESSAGE_COMMCFG_REQ: - case MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REQ: - case MGMTD__FE_MESSAGE__MESSAGE_GETDATA_REQ: + case MGMTD__FE_MESSAGE__MESSAGE_GET_REQ: case MGMTD__FE_MESSAGE__MESSAGE__NOT_SET: default: /* @@ -523,15 +499,93 @@ static int mgmt_fe_client_handle_msg(struct mgmt_fe_client_ctx *client_ctx, return 0; } +/* + * Handle a native encoded message + */ +static void fe_client_handle_native_msg(struct mgmt_fe_client *client, + struct mgmt_msg_header *msg, + size_t msg_len) +{ + struct mgmt_fe_client_session *session; + struct mgmt_msg_tree_data *tree_msg; + struct mgmt_msg_error *err_msg; + + MGMTD_FE_CLIENT_DBG("Got GET_TREE reply for session-id %" PRIu64, + msg->refer_id); + + session = mgmt_fe_find_session_by_session_id(client, msg->refer_id); + + if (!session || !session->client) { + MGMTD_FE_CLIENT_ERR("No session for received native msg session-id %" PRIu64, + msg->refer_id); + return; + } + + switch (msg->code) { + case MGMT_MSG_CODE_ERROR: + if (!session->client->cbs.error_notify) + return; + + err_msg = (typeof(err_msg))msg; + if (!MGMT_MSG_VALIDATE_NUL_TERM(err_msg, msg_len)) { + MGMTD_FE_CLIENT_ERR("Corrupt error msg recv"); + return; + } + session->client->cbs.error_notify(client, client->user_data, + session->client_id, + msg->refer_id, + session->user_ctx, + msg->req_id, err_msg->error, + err_msg->errstr); + break; + case MGMT_MSG_CODE_TREE_DATA: + if (!session->client->cbs.get_tree_notify) + return; + + tree_msg = (typeof(tree_msg))msg; + if (msg_len < sizeof(*tree_msg)) { + MGMTD_FE_CLIENT_ERR("Corrupt tree-data msg recv"); + return; + } + session->client->cbs.get_tree_notify(client, client->user_data, + session->client_id, + msg->refer_id, + session->user_ctx, + msg->req_id, + MGMTD_DS_OPERATIONAL, + tree_msg->result_type, + tree_msg->result, + msg_len - sizeof(*tree_msg), + tree_msg->partial_error); + break; + default: + MGMTD_FE_CLIENT_ERR("unknown native message session-id %" PRIu64 + " req-id %" PRIu64 " code %u", + msg->refer_id, msg->req_id, msg->code); + break; + } +} + static void mgmt_fe_client_process_msg(uint8_t version, uint8_t *data, size_t len, struct msg_conn *conn) { - struct mgmt_fe_client_ctx *client_ctx; - struct msg_client *client; + struct mgmt_fe_client *client; + struct msg_client *msg_client; Mgmtd__FeMessage *fe_msg; - client = container_of(conn, struct msg_client, conn); - client_ctx = container_of(client, struct mgmt_fe_client_ctx, client); + msg_client = container_of(conn, struct msg_client, conn); + client = container_of(msg_client, struct mgmt_fe_client, client); + + if (version == MGMT_MSG_VERSION_NATIVE) { + struct mgmt_msg_header *msg = (typeof(msg))data; + + if (len >= sizeof(*msg)) + fe_client_handle_native_msg(client, msg, len); + else + MGMTD_FE_CLIENT_ERR("native message to FE client %s too short %zu", + client->name, len); + return; + } fe_msg = mgmtd__fe_message__unpack(NULL, len, data); if (!fe_msg) { @@ -542,41 +596,38 @@ static void mgmt_fe_client_process_msg(uint8_t version, uint8_t *data, MGMTD_FE_CLIENT_DBG( "Decoded %zu bytes of message(msg: %u/%u) from server", len, fe_msg->message_case, fe_msg->message_case); - (void)mgmt_fe_client_handle_msg(client_ctx, fe_msg); + (void)mgmt_fe_client_handle_msg(client, fe_msg); mgmtd__fe_message__free_unpacked(fe_msg, NULL); } -static int _notify_connect_disconnect(struct msg_client *client, bool connected) +static int _notify_connect_disconnect(struct msg_client *msg_client, + bool connected) { - struct mgmt_fe_client_ctx *client_ctx = - container_of(client, struct mgmt_fe_client_ctx, client); + struct mgmt_fe_client *client = + container_of(msg_client, struct mgmt_fe_client, client); struct mgmt_fe_client_session *session; int ret; /* Send REGISTER_REQ message */ if (connected) { - if ((ret = mgmt_fe_send_register_req(client_ctx)) != 0) + if ((ret = mgmt_fe_send_register_req(client)) != 0) return ret; } /* Walk list of sessions for this FE client deleting them */ - if (!connected && mgmt_sessions_count(&client_ctx->client_sessions)) { + if (!connected && mgmt_sessions_count(&client->sessions)) { MGMTD_FE_CLIENT_DBG("Cleaning up existing sessions"); - FOREACH_SESSION_IN_LIST (client_ctx, session) { - assert(session->client_ctx); + FOREACH_SESSION_IN_LIST (client, session) { + assert(session->client); /* unlink from list first this avoids double free */ - mgmt_sessions_del(&client_ctx->client_sessions, - session); + mgmt_sessions_del(&client->sessions, session); /* notify FE client the session is being deleted */ - if (session->client_ctx->client_params - .client_session_notify) { - (*session->client_ctx->client_params - .client_session_notify)( - (uintptr_t)client_ctx, - client_ctx->client_params.user_data, + if (session->client->cbs.client_session_notify) { + (*session->client->cbs.client_session_notify)( + client, client->user_data, session->client_id, false, true, session->session_id, session->user_ctx); } @@ -586,10 +637,9 @@ static int _notify_connect_disconnect(struct msg_client *client, bool connected) } /* Notify FE client through registered callback (if any). */ - if (client_ctx->client_params.client_connect_notify) - (void)(*client_ctx->client_params.client_connect_notify)( - (uintptr_t)client_ctx, - client_ctx->client_params.user_data, connected); + if (client->cbs.client_connect_notify) + (void)(*client->cbs.client_connect_notify)( + client, client->user_data, connected); return 0; } @@ -605,6 +655,16 @@ static int mgmt_fe_client_notify_disconnect(struct msg_conn *conn) return _notify_connect_disconnect(client, false); } +static void mgmt_debug_client_fe_set(uint32_t mode, bool set) +{ + DEBUG_FLAGS_SET(&mgmt_dbg_fe_client, mode, set); + + if (!__fe_client) + return; + + __fe_client->client.conn.debug = DEBUG_MODE_CHECK(&mgmt_dbg_fe_client, + DEBUG_MODE_ALL); +} DEFPY(debug_mgmt_client_fe, debug_mgmt_client_fe_cmd, "[no] debug mgmt client frontend", @@ -612,18 +672,11 @@ DEFPY(debug_mgmt_client_fe, debug_mgmt_client_fe_cmd, "client\n" "frontend\n") { - uint32_t mode = DEBUG_NODE2MODE(vty->node); - - DEBUG_MODE_SET(&mgmt_dbg_fe_client, mode, !no); + mgmt_debug_client_fe_set(DEBUG_NODE2MODE(vty->node), !no); return CMD_SUCCESS; } -static void mgmt_debug_client_fe_set_all(uint32_t flags, bool set) -{ - DEBUG_FLAGS_SET(&mgmt_dbg_fe_client, flags, set); -} - static int mgmt_debug_fe_client_config_write(struct vty *vty) { if (DEBUG_MODE_CHECK(&mgmt_dbg_fe_client, DEBUG_MODE_CONF)) @@ -639,11 +692,12 @@ void mgmt_debug_fe_client_show_debug(struct vty *vty) } static struct debug_callbacks mgmt_dbg_fe_client_cbs = { - .debug_set_all = mgmt_debug_client_fe_set_all}; + .debug_set_all = mgmt_debug_client_fe_set +}; static struct cmd_node mgmt_dbg_node = { - .name = "mgmt client frontend", - .node = DEBUG_NODE, + .name = "debug mgmt client frontend", + .node = MGMT_FE_DEBUG_NODE, .prompt = "", .config_write = mgmt_debug_fe_client_config_write, }; @@ -651,26 +705,36 @@ static struct cmd_node mgmt_dbg_node = { /* * Initialize library and try connecting with MGMTD. */ -uintptr_t mgmt_fe_client_lib_init(struct mgmt_fe_client_params *params, - struct event_loop *master_thread) +struct mgmt_fe_client *mgmt_fe_client_create(const char *client_name, + struct mgmt_fe_client_cbs *cbs, + uintptr_t user_data, + struct event_loop *event_loop) { - /* Don't call twice */ - assert(!mgmt_fe_client_ctx.client.conn.loop); + struct mgmt_fe_client *client; + + if (__fe_client) + return NULL; + + client = XCALLOC(MTYPE_MGMTD_FE_CLIENT, sizeof(*client)); + __fe_client = client; - mgmt_fe_client_ctx.client_params = *params; + client->name = XSTRDUP(MTYPE_MGMTD_FE_CLIENT_NAME, client_name); + client->user_data = user_data; + if (cbs) + client->cbs = *cbs; - mgmt_sessions_init(&mgmt_fe_client_ctx.client_sessions); + mgmt_sessions_init(&client->sessions); - msg_client_init(&mgmt_fe_client_ctx.client, master_thread, - MGMTD_FE_SERVER_PATH, mgmt_fe_client_notify_connect, + msg_client_init(&client->client, event_loop, MGMTD_FE_SERVER_PATH, + mgmt_fe_client_notify_connect, mgmt_fe_client_notify_disconnect, mgmt_fe_client_process_msg, MGMTD_FE_MAX_NUM_MSG_PROC, - MGMTD_FE_MAX_NUM_MSG_WRITE, MGMTD_FE_MSG_MAX_LEN, true, + MGMTD_FE_MAX_NUM_MSG_WRITE, MGMTD_FE_MAX_MSG_LEN, true, "FE-client", MGMTD_DBG_FE_CLIENT_CHECK()); - MGMTD_FE_CLIENT_DBG("Initialized client '%s'", params->name); + MGMTD_FE_CLIENT_DBG("Initialized client '%s'", client_name); - return (uintptr_t)&mgmt_fe_client_ctx; + return client; } void mgmt_fe_client_lib_vty_init(void) @@ -681,39 +745,41 @@ void mgmt_fe_client_lib_vty_init(void) install_element(CONFIG_NODE, &debug_mgmt_client_fe_cmd); } -uint mgmt_fe_client_session_count(uintptr_t lib_hndl) +uint mgmt_fe_client_session_count(struct mgmt_fe_client *client) { - struct mgmt_fe_client_ctx *client_ctx = - (struct mgmt_fe_client_ctx *)lib_hndl; + return mgmt_sessions_count(&client->sessions); +} - return mgmt_sessions_count(&client_ctx->client_sessions); +bool mgmt_fe_client_current_msg_short_circuit(struct mgmt_fe_client *client) +{ + return client->client.conn.is_short_circuit; +} + +const char *mgmt_fe_client_name(struct mgmt_fe_client *client) +{ + return client->name; } /* * Create a new Session for a Frontend Client connection. */ -enum mgmt_result mgmt_fe_create_client_session(uintptr_t lib_hndl, +enum mgmt_result mgmt_fe_create_client_session(struct mgmt_fe_client *client, uint64_t client_id, uintptr_t user_ctx) { - struct mgmt_fe_client_ctx *client_ctx; struct mgmt_fe_client_session *session; - client_ctx = (struct mgmt_fe_client_ctx *)lib_hndl; - if (!client_ctx) - return MGMTD_INVALID_PARAM; - session = XCALLOC(MTYPE_MGMTD_FE_SESSION, sizeof(struct mgmt_fe_client_session)); assert(session); session->user_ctx = user_ctx; session->client_id = client_id; - session->client_ctx = client_ctx; + session->client = client; session->session_id = 0; - mgmt_sessions_add_tail(&client_ctx->client_sessions, session); + mgmt_sessions_add_tail(&client->sessions, session); - if (mgmt_fe_send_session_req(client_ctx, session, true) != 0) { + if (mgmt_fe_send_session_req(client, session, true) != 0) { XFREE(MTYPE_MGMTD_FE_SESSION, session); return MGMTD_INTERNAL_ERROR; } @@ -724,189 +790,46 @@ enum mgmt_result mgmt_fe_create_client_session(uintptr_t lib_hndl, /* * Delete an existing Session for a Frontend Client connection. */ -enum mgmt_result mgmt_fe_destroy_client_session(uintptr_t lib_hndl, +enum mgmt_result mgmt_fe_destroy_client_session(struct mgmt_fe_client *client, uint64_t client_id) { - struct mgmt_fe_client_ctx *client_ctx; struct mgmt_fe_client_session *session; - client_ctx = (struct mgmt_fe_client_ctx *)lib_hndl; - if (!client_ctx) - return MGMTD_INVALID_PARAM; - - session = mgmt_fe_find_session_by_client_id(client_ctx, client_id); - if (!session || session->client_ctx != client_ctx) + session = mgmt_fe_find_session_by_client_id(client, client_id); + if (!session || session->client != client) return MGMTD_INVALID_PARAM; if (session->session_id && - mgmt_fe_send_session_req(client_ctx, session, false) != 0) + mgmt_fe_send_session_req(client, session, false) != 0) MGMTD_FE_CLIENT_ERR( "Failed to send session destroy request for the session-id %" PRIu64, session->session_id); - mgmt_sessions_del(&client_ctx->client_sessions, session); + mgmt_sessions_del(&client->sessions, session); XFREE(MTYPE_MGMTD_FE_SESSION, session); return MGMTD_SUCCESS; } -static void mgmt_fe_destroy_client_sessions(uintptr_t lib_hndl) -{ - struct mgmt_fe_client_ctx *client_ctx; - struct mgmt_fe_client_session *session; - - client_ctx = (struct mgmt_fe_client_ctx *)lib_hndl; - if (!client_ctx) - return; - - FOREACH_SESSION_IN_LIST (client_ctx, session) - mgmt_fe_destroy_client_session(lib_hndl, session->client_id); -} - /* - * Send UN/LOCK_DS_REQ to MGMTD for a specific Datastore DS. - */ -enum mgmt_result mgmt_fe_lock_ds(uintptr_t lib_hndl, uint64_t session_id, - uint64_t req_id, Mgmtd__DatastoreId ds_id, - bool lock_ds) -{ - struct mgmt_fe_client_ctx *client_ctx; - - client_ctx = (struct mgmt_fe_client_ctx *)lib_hndl; - if (!client_ctx) - return MGMTD_INVALID_PARAM; - - if (mgmt_fe_send_lockds_req(client_ctx, session_id, lock_ds, req_id, - ds_id) != 0) - return MGMTD_INTERNAL_ERROR; - - return MGMTD_SUCCESS; -} - -/* - * Send SET_CONFIG_REQ to MGMTD for one or more config data(s). - */ -enum mgmt_result mgmt_fe_set_config_data(uintptr_t lib_hndl, - uint64_t session_id, uint64_t req_id, - Mgmtd__DatastoreId ds_id, - Mgmtd__YangCfgDataReq **config_req, - int num_reqs, bool implicit_commit, - Mgmtd__DatastoreId dst_ds_id) -{ - struct mgmt_fe_client_ctx *client_ctx; - - client_ctx = (struct mgmt_fe_client_ctx *)lib_hndl; - if (!client_ctx) - return MGMTD_INVALID_PARAM; - - if (mgmt_fe_send_setcfg_req(client_ctx, session_id, req_id, ds_id, - config_req, num_reqs, implicit_commit, - dst_ds_id) != 0) - return MGMTD_INTERNAL_ERROR; - - return MGMTD_SUCCESS; -} - -/* - * Send SET_CONFIG_REQ to MGMTD for one or more config data(s). - */ -enum mgmt_result mgmt_fe_commit_config_data(uintptr_t lib_hndl, - uint64_t session_id, - uint64_t req_id, - Mgmtd__DatastoreId src_ds_id, - Mgmtd__DatastoreId dst_ds_id, - bool validate_only, bool abort) -{ - struct mgmt_fe_client_ctx *client_ctx; - - client_ctx = (struct mgmt_fe_client_ctx *)lib_hndl; - if (!client_ctx) - return MGMTD_INVALID_PARAM; - - if (mgmt_fe_send_commitcfg_req(client_ctx, session_id, req_id, - src_ds_id, dst_ds_id, validate_only, - abort) != 0) - return MGMTD_INTERNAL_ERROR; - - return MGMTD_SUCCESS; -} - -/* - * Send GET_CONFIG_REQ to MGMTD for one or more config data item(s). - */ -enum mgmt_result mgmt_fe_get_config_data(uintptr_t lib_hndl, - uint64_t session_id, uint64_t req_id, - Mgmtd__DatastoreId ds_id, - Mgmtd__YangGetDataReq *data_req[], - int num_reqs) -{ - struct mgmt_fe_client_ctx *client_ctx; - - client_ctx = (struct mgmt_fe_client_ctx *)lib_hndl; - if (!client_ctx) - return MGMTD_INVALID_PARAM; - - if (mgmt_fe_send_getcfg_req(client_ctx, session_id, req_id, ds_id, - data_req, num_reqs) != 0) - return MGMTD_INTERNAL_ERROR; - - return MGMTD_SUCCESS; -} - -/* - * Send GET_DATA_REQ to MGMTD for one or more config data item(s). - */ -enum mgmt_result mgmt_fe_get_data(uintptr_t lib_hndl, uint64_t session_id, - uint64_t req_id, Mgmtd__DatastoreId ds_id, - Mgmtd__YangGetDataReq *data_req[], - int num_reqs) -{ - struct mgmt_fe_client_ctx *client_ctx; - - client_ctx = (struct mgmt_fe_client_ctx *)lib_hndl; - if (!client_ctx) - return MGMTD_INVALID_PARAM; - - if (mgmt_fe_send_getdata_req(client_ctx, session_id, req_id, ds_id, - data_req, num_reqs) != 0) - return MGMTD_INTERNAL_ERROR; - - return MGMTD_SUCCESS; -} - -/* - * Send NOTIFY_REGISTER_REQ to MGMTD daemon. + * Destroy library and cleanup everything. */ -enum mgmt_result -mgmt_fe_register_yang_notify(uintptr_t lib_hndl, uint64_t session_id, - uint64_t req_id, Mgmtd__DatastoreId ds_id, - bool register_req, - Mgmtd__YangDataXPath *data_req[], int num_reqs) +void mgmt_fe_client_destroy(struct mgmt_fe_client *client) { - struct mgmt_fe_client_ctx *client_ctx; + struct mgmt_fe_client_session *session; - client_ctx = (struct mgmt_fe_client_ctx *)lib_hndl; - if (!client_ctx) - return MGMTD_INVALID_PARAM; + assert(client == __fe_client); - if (mgmt_fe_send_regnotify_req(client_ctx, session_id, req_id, ds_id, - register_req, data_req, num_reqs) != 0) - return MGMTD_INTERNAL_ERROR; + MGMTD_FE_CLIENT_DBG("Destroying MGMTD Frontend Client '%s'", + client->name); - return MGMTD_SUCCESS; -} + FOREACH_SESSION_IN_LIST (client, session) + mgmt_fe_destroy_client_session(client, session->client_id); -/* - * Destroy library and cleanup everything. - */ -void mgmt_fe_client_lib_destroy(void) -{ - struct mgmt_fe_client_ctx *client_ctx = &mgmt_fe_client_ctx; + msg_client_cleanup(&client->client); - MGMTD_FE_CLIENT_DBG("Destroying MGMTD Frontend Client '%s'", - client_ctx->client_params.name); + XFREE(MTYPE_MGMTD_FE_CLIENT_NAME, client->name); + XFREE(MTYPE_MGMTD_FE_CLIENT, client); - mgmt_fe_destroy_client_sessions((uintptr_t)client_ctx); - msg_client_cleanup(&client_ctx->client); - memset(client_ctx, 0, sizeof(*client_ctx)); + __fe_client = NULL; } diff --git a/lib/mgmt_fe_client.h b/lib/mgmt_fe_client.h index 7ce6c5eef5..f3292d18fd 100644 --- a/lib/mgmt_fe_client.h +++ b/lib/mgmt_fe_client.h @@ -14,7 +14,7 @@ extern "C" { #include "mgmt_pb.h" #include "frrevent.h" -#include "mgmtd/mgmt_defines.h" +#include "mgmt_defines.h" /*************************************************************** * Macros @@ -25,22 +25,11 @@ extern "C" { * connections. */ -#define MGMTD_FE_CLIENT_ERROR_STRING_MAX_LEN 32 - -#define MGMTD_FE_DEFAULT_CONN_RETRY_INTVL_SEC 5 - #define MGMTD_FE_MSG_PROC_DELAY_USEC 10 -#define MGMTD_FE_MAX_NUM_MSG_PROC 500 -#define MGMTD_FE_MSG_WRITE_DELAY_MSEC 1 +#define MGMTD_FE_MAX_NUM_MSG_PROC 500 #define MGMTD_FE_MAX_NUM_MSG_WRITE 100 - -#define GMGD_FE_MAX_NUM_REQ_ITEMS 64 - -#define MGMTD_FE_MSG_MAX_LEN 9000 - -#define MGMTD_SOCKET_FE_SEND_BUF_SIZE 65535 -#define MGMTD_SOCKET_FE_RECV_BUF_SIZE MGMTD_SOCKET_FE_SEND_BUF_SIZE +#define MGMTD_FE_MAX_MSG_LEN (64 * 1024) /*************************************************************** * Data-structures @@ -56,6 +45,9 @@ extern "C" { #define MGMTD_DS_OPERATIONAL MGMTD__DATASTORE_ID__OPERATIONAL_DS #define MGMTD_DS_MAX_ID MGMTD_DS_OPERATIONAL + 1 +struct mgmt_fe_client; + + /* * All the client specific information this library needs to * initialize itself, setup connection with MGMTD FrontEnd interface @@ -66,69 +58,82 @@ extern "C" { * to initialize the library (See mgmt_fe_client_lib_init for * more details). */ -struct mgmt_fe_client_params { - char name[MGMTD_CLIENT_NAME_MAX_LEN]; - uintptr_t user_data; - unsigned long conn_retry_intvl_sec; - - void (*client_connect_notify)(uintptr_t lib_hndl, - uintptr_t user_data, - bool connected); - - void (*client_session_notify)(uintptr_t lib_hndl, - uintptr_t user_data, - uint64_t client_id, +struct mgmt_fe_client_cbs { + void (*client_connect_notify)(struct mgmt_fe_client *client, + uintptr_t user_data, bool connected); + + void (*client_session_notify)(struct mgmt_fe_client *client, + uintptr_t user_data, uint64_t client_id, bool create, bool success, uintptr_t session_id, - uintptr_t user_session_ctx); + uintptr_t user_session_client); - void (*lock_ds_notify)(uintptr_t lib_hndl, uintptr_t user_data, - uint64_t client_id, uintptr_t session_id, - uintptr_t user_session_ctx, uint64_t req_id, + void (*lock_ds_notify)(struct mgmt_fe_client *client, + uintptr_t user_data, uint64_t client_id, + uintptr_t session_id, + uintptr_t user_session_client, uint64_t req_id, bool lock_ds, bool success, Mgmtd__DatastoreId ds_id, char *errmsg_if_any); - void (*set_config_notify)(uintptr_t lib_hndl, uintptr_t user_data, - uint64_t client_id, uintptr_t session_id, - uintptr_t user_session_ctx, uint64_t req_id, - bool success, Mgmtd__DatastoreId ds_id, + void (*set_config_notify)(struct mgmt_fe_client *client, + uintptr_t user_data, uint64_t client_id, + uintptr_t session_id, + uintptr_t user_session_client, + uint64_t req_id, bool success, + Mgmtd__DatastoreId ds_id, bool implcit_commit, char *errmsg_if_any); - void (*commit_config_notify)( - uintptr_t lib_hndl, uintptr_t user_data, uint64_t client_id, - uintptr_t session_id, uintptr_t user_session_ctx, - uint64_t req_id, bool success, Mgmtd__DatastoreId src_ds_id, - Mgmtd__DatastoreId dst_ds_id, bool validate_only, - char *errmsg_if_any); - - enum mgmt_result (*get_data_notify)( - uintptr_t lib_hndl, uintptr_t user_data, uint64_t client_id, - uintptr_t session_id, uintptr_t user_session_ctx, - uint64_t req_id, bool success, Mgmtd__DatastoreId ds_id, - Mgmtd__YangData **yang_data, size_t num_data, int next_key, - char *errmsg_if_any); - - enum mgmt_result (*data_notify)( - uint64_t client_id, uint64_t session_id, uintptr_t user_data, - uint64_t req_id, Mgmtd__DatastoreId ds_id, - Mgmtd__YangData **yang_data, size_t num_data); + void (*commit_config_notify)(struct mgmt_fe_client *client, + uintptr_t user_data, uint64_t client_id, + uintptr_t session_id, + uintptr_t user_session_client, + uint64_t req_id, bool success, + Mgmtd__DatastoreId src_ds_id, + Mgmtd__DatastoreId dst_ds_id, + bool validate_only, char *errmsg_if_any); + + int (*get_data_notify)(struct mgmt_fe_client *client, + uintptr_t user_data, uint64_t client_id, + uintptr_t session_id, + uintptr_t user_session_client, uint64_t req_id, + bool success, Mgmtd__DatastoreId ds_id, + Mgmtd__YangData **yang_data, size_t num_data, + int next_key, char *errmsg_if_any); + + int (*data_notify)(uint64_t client_id, uint64_t session_id, + uintptr_t user_data, uint64_t req_id, + Mgmtd__DatastoreId ds_id, + Mgmtd__YangData **yang_data, size_t num_data); + + /* Called when get-tree result is returned */ + int (*get_tree_notify)(struct mgmt_fe_client *client, + uintptr_t user_data, uint64_t client_id, + uint64_t session_id, uintptr_t session_ctx, + uint64_t req_id, Mgmtd__DatastoreId ds_id, + LYD_FORMAT result_type, void *result, size_t len, + int partial_error); + + /* Called when new native error is returned */ + int (*error_notify)(struct mgmt_fe_client *client, uintptr_t user_data, + uint64_t client_id, uint64_t session_id, + uintptr_t session_ctx, uint64_t req_id, int error, + const char *errstr); }; extern struct debug mgmt_dbg_fe_client; +/*************************************************************** + * API prototypes + ***************************************************************/ + #define MGMTD_FE_CLIENT_DBG(fmt, ...) \ - DEBUGD(&mgmt_dbg_fe_client, "FE-CLIENT: %s:" fmt, __func__, \ + DEBUGD(&mgmt_dbg_fe_client, "FE-CLIENT: %s: " fmt, __func__, \ ##__VA_ARGS__) #define MGMTD_FE_CLIENT_ERR(fmt, ...) \ zlog_err("FE-CLIENT: %s: ERROR: " fmt, __func__, ##__VA_ARGS__) #define MGMTD_DBG_FE_CLIENT_CHECK() \ DEBUG_MODE_CHECK(&mgmt_dbg_fe_client, DEBUG_MODE_ALL) - -/*************************************************************** - * API prototypes - ***************************************************************/ - /* * Initialize library and try connecting with MGMTD FrontEnd interface. * @@ -139,17 +144,18 @@ extern struct debug mgmt_dbg_fe_client; * Thread master. * * Returns: - * Frontend client lib handler (nothing but address of mgmt_fe_client_ctx) + * Frontend client lib handler (nothing but address of mgmt_fe_client) */ -extern uintptr_t mgmt_fe_client_lib_init(struct mgmt_fe_client_params *params, - struct event_loop *master_thread); +extern struct mgmt_fe_client * +mgmt_fe_client_create(const char *client_name, struct mgmt_fe_client_cbs *cbs, + uintptr_t user_data, struct event_loop *event_loop); /* * Initialize library vty (adds debug support). * - * This call should be added to your component when enabling other vty code to - * enable mgmtd client debugs. When adding, one needs to also add a their - * component in `xref2vtysh.py` as well. + * This call should be added to your component when enabling other vty + * code to enable mgmtd client debugs. When adding, one needs to also + * add a their component in `xref2vtysh.py` as well. */ extern void mgmt_fe_client_lib_vty_init(void); @@ -167,15 +173,15 @@ extern void mgmt_debug_fe_client_show_debug(struct vty *vty); * client_id * Unique identifier of client. * - * user_ctx + * user_client * Client context. * * Returns: * MGMTD_SUCCESS on success, MGMTD_* otherwise. */ -extern enum mgmt_result mgmt_fe_create_client_session(uintptr_t lib_hndl, - uint64_t client_id, - uintptr_t user_ctx); +extern enum mgmt_result +mgmt_fe_create_client_session(struct mgmt_fe_client *client, uint64_t client_id, + uintptr_t user_client); /* * Delete an existing Session for a Frontend Client connection. @@ -187,10 +193,11 @@ extern enum mgmt_result mgmt_fe_create_client_session(uintptr_t lib_hndl, * Unique identifier of client. * * Returns: - * MGMTD_SUCCESS on success, MGMTD_* otherwise. + * 0 on success, otherwise msg_conn_send_msg() return values. */ -extern enum mgmt_result mgmt_fe_destroy_client_session(uintptr_t lib_hndl, - uint64_t client_id); +extern enum mgmt_result +mgmt_fe_destroy_client_session(struct mgmt_fe_client *client, + uint64_t client_id); /* * Send UN/LOCK_DS_REQ to MGMTD for a specific Datastore DS. @@ -211,11 +218,12 @@ extern enum mgmt_result mgmt_fe_destroy_client_session(uintptr_t lib_hndl, * TRUE for lock request, FALSE for unlock request. * * Returns: - * MGMTD_SUCCESS on success, MGMTD_* otherwise. + * 0 on success, otherwise msg_conn_send_msg() return values. */ -extern enum mgmt_result mgmt_fe_lock_ds(uintptr_t lib_hndl, uint64_t session_id, - uint64_t req_id, - Mgmtd__DatastoreId ds_id, bool lock_ds); +extern int mgmt_fe_send_lockds_req(struct mgmt_fe_client *client, + uint64_t session_id, uint64_t req_id, + Mgmtd__DatastoreId ds_id, bool lock_ds, + bool scok); /* * Send SET_CONFIG_REQ to MGMTD for one or more config data(s). @@ -245,13 +253,15 @@ extern enum mgmt_result mgmt_fe_lock_ds(uintptr_t lib_hndl, uint64_t session_id, * Destination Datastore ID where data needs to be set. * * Returns: - * MGMTD_SUCCESS on success, MGMTD_* otherwise. + * 0 on success, otherwise msg_conn_send_msg() return values. */ -extern enum mgmt_result -mgmt_fe_set_config_data(uintptr_t lib_hndl, uint64_t session_id, - uint64_t req_id, Mgmtd__DatastoreId ds_id, - Mgmtd__YangCfgDataReq **config_req, int num_req, - bool implicit_commit, Mgmtd__DatastoreId dst_ds_id); + +extern int mgmt_fe_send_setcfg_req(struct mgmt_fe_client *client, + uint64_t session_id, uint64_t req_id, + Mgmtd__DatastoreId ds_id, + Mgmtd__YangCfgDataReq **config_req, + int num_req, bool implicit_commit, + Mgmtd__DatastoreId dst_ds_id); /* * Send SET_COMMMIT_REQ to MGMTD for one or more config data(s). @@ -278,16 +288,19 @@ mgmt_fe_set_config_data(uintptr_t lib_hndl, uint64_t session_id, * TRUE if need to restore Src DS back to Dest DS, FALSE otherwise. * * Returns: - * MGMTD_SUCCESS on success, MGMTD_* otherwise. + * 0 on success, otherwise msg_conn_send_msg() return values. */ -extern enum mgmt_result -mgmt_fe_commit_config_data(uintptr_t lib_hndl, uint64_t session_id, - uint64_t req_id, Mgmtd__DatastoreId src_ds_id, - Mgmtd__DatastoreId dst_ds_id, bool validate_only, - bool abort); +extern int mgmt_fe_send_commitcfg_req(struct mgmt_fe_client *client, + uint64_t session_id, uint64_t req_id, + Mgmtd__DatastoreId src_ds_id, + Mgmtd__DatastoreId dst_ds_id, + bool validate_only, bool abort); /* - * Send GET_CONFIG_REQ to MGMTD for one or more config data item(s). + * Send GET_REQ to MGMTD for one or more config data item(s). + * + * If is_config is true gets config from the MGMTD datastore, otherwise + * operational state is queried from the backend clients. * * lib_hndl * Client library handler. @@ -295,6 +308,9 @@ mgmt_fe_commit_config_data(uintptr_t lib_hndl, uint64_t session_id, * session_id * Client session ID. * + * is_config + * True if get-config else get-data. + * * req_id * Client request ID. * @@ -302,30 +318,19 @@ mgmt_fe_commit_config_data(uintptr_t lib_hndl, uint64_t session_id, * Datastore ID (Running/Candidate) * * data_req - * Get config requested. + * Get xpaths requested. * * num_req - * Number of get config requests. + * Number of get xpath requests. * * Returns: - * MGMTD_SUCCESS on success, MGMTD_* otherwise. + * 0 on success, otherwise msg_conn_send_msg() return values. */ -extern enum mgmt_result -mgmt_fe_get_config_data(uintptr_t lib_hndl, uint64_t session_id, - uint64_t req_id, Mgmtd__DatastoreId ds_id, - Mgmtd__YangGetDataReq **data_req, int num_reqs); +extern int mgmt_fe_send_get_req(struct mgmt_fe_client *client, + uint64_t session_id, uint64_t req_id, + bool is_config, Mgmtd__DatastoreId ds_id, + Mgmtd__YangGetDataReq **data_req, int num_reqs); -/* - * Send GET_DATA_REQ to MGMTD for one or more data item(s). - * - * Similar to get config request but supports getting data - * from operational ds aka backend clients directly. - */ -extern enum mgmt_result mgmt_fe_get_data(uintptr_t lib_hndl, - uint64_t session_id, uint64_t req_id, - Mgmtd__DatastoreId ds_id, - Mgmtd__YangGetDataReq **data_req, - int num_reqs); /* * Send NOTIFY_REGISTER_REQ to MGMTD daemon. @@ -352,23 +357,66 @@ extern enum mgmt_result mgmt_fe_get_data(uintptr_t lib_hndl, * Number of data requests. * * Returns: - * MGMTD_SUCCESS on success, MGMTD_* otherwise. + * 0 on success, otherwise msg_conn_send_msg() return values. */ -extern enum mgmt_result -mgmt_fe_register_yang_notify(uintptr_t lib_hndl, uint64_t session_id, - uint64_t req_id, Mgmtd__DatastoreId ds_id, - bool register_req, Mgmtd__YangDataXPath **data_req, - int num_reqs); +extern int mgmt_fe_send_regnotify_req(struct mgmt_fe_client *client, + uint64_t session_id, uint64_t req_id, + Mgmtd__DatastoreId ds_id, + bool register_req, + Mgmtd__YangDataXPath **data_req, + int num_reqs); + +/* + * Send GET-TREE to MGMTD daemon. + * + * client + * Client object. + * + * session_id + * Client session ID. + * + * req_id + * Client request ID. + * + * result_type + * The LYD_FORMAT of the result. + * + * xpath + * the xpath to get. + * + * Returns: + * 0 on success, otherwise msg_conn_send_msg() return values. + */ +extern int mgmt_fe_send_get_tree_req(struct mgmt_fe_client *client, + uint64_t session_id, uint64_t req_id, + LYD_FORMAT result_type, const char *xpath); /* * Destroy library and cleanup everything. */ -extern void mgmt_fe_client_lib_destroy(void); +extern void mgmt_fe_client_destroy(struct mgmt_fe_client *client); /* * Get count of open sessions. */ -extern uint mgmt_fe_client_session_count(uintptr_t lib_hndl); +extern uint mgmt_fe_client_session_count(struct mgmt_fe_client *client); + +/* + * True if the current handled message is being short-circuited + */ +extern bool +mgmt_fe_client_current_msg_short_circuit(struct mgmt_fe_client *client); + +/** + * Get the name of the client + * + * Args: + * The client object. + * + * Return: + * The name of the client. + */ +extern const char *mgmt_fe_client_name(struct mgmt_fe_client *client); #ifdef __cplusplus } diff --git a/lib/mgmt_msg.c b/lib/mgmt_msg.c index 0d9802a2b3..aff9af7e84 100644 --- a/lib/mgmt_msg.c +++ b/lib/mgmt_msg.c @@ -7,12 +7,15 @@ * Copyright (c) 2023, LabN Consulting, L.L.C. */ #include <zebra.h> +#include <sys/stat.h> + #include "debug.h" #include "network.h" #include "sockopt.h" #include "stream.h" #include "frrevent.h" #include "mgmt_msg.h" +#include "mgmt_msg_native.h" #define MGMT_MSG_DBG(dbgtag, fmt, ...) \ @@ -59,11 +62,12 @@ enum mgmt_msg_rsched mgmt_msg_read(struct mgmt_msg_state *ms, int fd, */ while (avail > sizeof(struct mgmt_msg_hdr)) { n = stream_read_try(ms->ins, fd, avail); - MGMT_MSG_DBG(dbgtag, "got %zd bytes", n); /* -2 is normal nothing read, and to retry */ - if (n == -2) + if (n == -2) { + MGMT_MSG_DBG(dbgtag, "nothing more to read"); break; + } if (n <= 0) { if (n == 0) MGMT_MSG_ERR(ms, "got EOF/disconnect"); @@ -73,6 +77,7 @@ enum mgmt_msg_rsched mgmt_msg_read(struct mgmt_msg_state *ms, int fd, safe_strerror(errno)); return MSR_DISCONNECT; } + MGMT_MSG_DBG(dbgtag, "read %zd bytes", n); ms->nrxb += n; avail -= n; } @@ -82,7 +87,7 @@ enum mgmt_msg_rsched mgmt_msg_read(struct mgmt_msg_state *ms, int fd, */ assert(stream_get_getp(ms->ins) == 0); left = stream_get_endp(ms->ins); - while (left > (long)sizeof(struct mgmt_msg_hdr)) { + while (left > (ssize_t)sizeof(struct mgmt_msg_hdr)) { mhdr = (struct mgmt_msg_hdr *)(STREAM_DATA(ms->ins) + total); if (!MGMT_MSG_IS_MARKER(mhdr->marker)) { MGMT_MSG_DBG(dbgtag, "recv corrupt buffer, disconnect"); @@ -97,8 +102,30 @@ enum mgmt_msg_rsched mgmt_msg_read(struct mgmt_msg_state *ms, int fd, mcount++; } - if (!mcount) + if (!mcount) { + /* Didn't manage to read a full message */ + if (mhdr && avail == 0) { + struct stream *news; + /* + * Message was longer than what was left and we have no + * available space to read more in. B/c mcount == 0 the + * message starts at the beginning of the stream so + * therefor the stream is too small to fit the message.. + * Resize the stream to fit. + */ + if (mhdr->len > MGMT_MSG_MAX_MSG_ALLOC_LEN) { + MGMT_MSG_ERR(ms, "corrupt msg len rcvd %u", + mhdr->len); + return MSR_DISCONNECT; + } + news = stream_new(mhdr->len); + stream_put(news, mhdr, left); + stream_set_endp(news, left); + stream_free(ms->ins); + ms->ins = news; + } return MSR_SCHED_STREAM; + } /* * We have read at least one message into the stream, queue it up. @@ -106,7 +133,11 @@ enum mgmt_msg_rsched mgmt_msg_read(struct mgmt_msg_state *ms, int fd, mhdr = (struct mgmt_msg_hdr *)(STREAM_DATA(ms->ins) + total); stream_set_endp(ms->ins, total); stream_fifo_push(&ms->inq, ms->ins); - ms->ins = stream_new(ms->max_msg_sz); + if (left < (ssize_t)sizeof(struct mgmt_msg_hdr)) + ms->ins = stream_new(ms->max_msg_sz); + else + /* handle case where message is greater than max */ + ms->ins = stream_new(MAX(ms->max_msg_sz, mhdr->len)); if (left) { stream_put(ms->ins, mhdr, left); stream_set_endp(ms->ins, left); @@ -178,7 +209,7 @@ bool mgmt_msg_procbufs(struct mgmt_msg_state *ms, } /** - * Write data from a onto the socket, using streams that have been queued for + * Write data onto the socket, using streams that have been queued for * sending by mgmt_msg_send_msg. This function should be reschedulable. * * Args: @@ -290,23 +321,26 @@ int mgmt_msg_send_msg(struct mgmt_msg_state *ms, uint8_t version, void *msg, size_t endp, n; size_t mlen = len + sizeof(*mhdr); - if (mlen > ms->max_msg_sz) { - MGMT_MSG_ERR(ms, "Message %zu > max size %zu, dropping", mlen, - ms->max_msg_sz); - return -1; - } + if (mlen > ms->max_msg_sz) + MGMT_MSG_DBG(dbgtag, "Sending large msg size %zu > max size %zu", + mlen, ms->max_msg_sz); if (!ms->outs) { - MGMT_MSG_DBG(dbgtag, "creating new stream for msg len %zu", - len); - ms->outs = stream_new(ms->max_msg_sz); + MGMT_MSG_DBG(dbgtag, "creating new stream for msg len %zu", mlen); + ms->outs = stream_new(MAX(ms->max_msg_sz, mlen)); + } else if (mlen > ms->max_msg_sz && ms->outs->endp == 0) { + /* msg is larger than stream max size get a fit-to-size stream */ + MGMT_MSG_DBG(dbgtag, + "replacing old stream with fit-to-size for msg len %zu", + mlen); + stream_free(ms->outs); + ms->outs = stream_new(mlen); } else if (STREAM_WRITEABLE(ms->outs) < mlen) { - MGMT_MSG_DBG( - dbgtag, - "enq existing stream len %zu and creating new stream for msg len %zu", - STREAM_WRITEABLE(ms->outs), mlen); + MGMT_MSG_DBG(dbgtag, + "enq existing stream len %zu and creating new stream for msg len %zu", + STREAM_WRITEABLE(ms->outs), mlen); stream_fifo_push(&ms->outq, ms->outs); - ms->outs = stream_new(ms->max_msg_sz); + ms->outs = stream_new(MAX(ms->max_msg_sz, mlen)); } else { MGMT_MSG_DBG( dbgtag, @@ -315,6 +349,16 @@ int mgmt_msg_send_msg(struct mgmt_msg_state *ms, uint8_t version, void *msg, } s = ms->outs; + if (dbgtag && version == MGMT_MSG_VERSION_NATIVE) { + struct mgmt_msg_header *native_msg = msg; + + MGMT_MSG_DBG( + dbgtag, + "Sending native msg sess/txn-id %"PRIu64" req-id %"PRIu64" code %u", + native_msg->refer_id, native_msg->req_id, native_msg->code); + + } + /* We have a stream with space, pack the message into it. */ mhdr = (struct mgmt_msg_hdr *)(STREAM_DATA(s) + s->endp); mhdr->marker = MGMT_MSG_MARKER(version); @@ -425,6 +469,8 @@ void mgmt_msg_destroy(struct mgmt_msg_state *ms) mgmt_msg_reset_writes(ms); if (ms->ins) stream_free(ms->ins); + if (ms->outs) + stream_free(ms->outs); free(ms->idtag); } @@ -546,20 +592,26 @@ int msg_conn_send_msg(struct msg_conn *conn, uint8_t version, void *msg, if (conn->remote_conn && short_circuit_ok) { uint8_t *buf = msg; size_t n = mlen; + bool old; if (packf) { buf = XMALLOC(MTYPE_TMP, mlen); n = packf(msg, buf); } + ++conn->short_circuit_depth; MGMT_MSG_DBG(dbgtag, "SC send: depth %u msg: %p", - ++conn->short_circuit_depth, msg); + conn->short_circuit_depth, msg); + old = conn->remote_conn->is_short_circuit; + conn->remote_conn->is_short_circuit = true; conn->remote_conn->handle_msg(version, buf, n, conn->remote_conn); + conn->remote_conn->is_short_circuit = old; + --conn->short_circuit_depth; MGMT_MSG_DBG(dbgtag, "SC return from depth: %u msg: %p", - conn->short_circuit_depth--, msg); + conn->short_circuit_depth, msg); if (packf) XFREE(MTYPE_TMP, buf); @@ -626,13 +678,13 @@ static void msg_client_sched_connect(struct msg_client *client, &client->conn_retry_tmr); } -static bool msg_client_connect_short_circuit(struct msg_client *client) +static int msg_client_connect_short_circuit(struct msg_client *client) { struct msg_conn *server_conn; struct msg_server *server; const char *dbgtag = client->conn.debug ? client->conn.mstate.idtag : NULL; - union sockunion su = {0}; + union sockunion su = {}; int sockets[2]; frr_each (msg_server_list, &msg_servers, server) @@ -640,10 +692,9 @@ static bool msg_client_connect_short_circuit(struct msg_client *client) break; if (!server) { MGMT_MSG_DBG(dbgtag, - "no short-circuit connection available for %s", + "no short-circuit server available yet for %s", client->sopath); - - return false; + return -1; } if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets)) { @@ -651,7 +702,7 @@ static bool msg_client_connect_short_circuit(struct msg_client *client) &client->conn.mstate, "socketpair failed trying to short-circuit connection on %s: %s", client->sopath, safe_strerror(errno)); - return false; + return -1; } /* client side */ @@ -659,12 +710,13 @@ static bool msg_client_connect_short_circuit(struct msg_client *client) set_nonblocking(sockets[0]); setsockopt_so_sendbuf(sockets[0], client->conn.mstate.max_write_buf); setsockopt_so_recvbuf(sockets[0], client->conn.mstate.max_read_buf); - client->conn.is_short_circuit = true; /* server side */ memset(&su, 0, sizeof(union sockunion)); server_conn = server->create(sockets[1], &su); - server_conn->is_short_circuit = true; + server_conn->debug = DEBUG_MODE_CHECK(server->debug, DEBUG_MODE_ALL) + ? true + : false; client->conn.remote_conn = server_conn; server_conn->remote_conn = &client->conn; @@ -681,7 +733,7 @@ static bool msg_client_connect_short_circuit(struct msg_client *client) client->sopath, client->conn.mstate.idtag, client->conn.fd, server_conn->mstate.idtag, server_conn->fd); - return true; + return 0; } @@ -691,11 +743,12 @@ static void msg_client_connect(struct msg_client *client) struct msg_conn *conn = &client->conn; const char *dbgtag = conn->debug ? conn->mstate.idtag : NULL; - if (!client->short_circuit_ok || - !msg_client_connect_short_circuit(client)) + if (!client->short_circuit_ok) conn->fd = mgmt_msg_connect(client->sopath, MSG_CONN_SEND_BUF_SIZE, MSG_CONN_RECV_BUF_SIZE, dbgtag); + else if (msg_client_connect_short_circuit(client)) + conn->fd = -1; if (conn->fd == -1) /* retry the connection */ @@ -735,7 +788,6 @@ void msg_client_init(struct msg_client *client, struct event_loop *tm, mgmt_msg_init(&conn->mstate, max_read_buf, max_write_buf, max_msg_sz, idtag); - /* XXX maybe just have client kick this off */ /* Start trying to connect to server */ msg_client_sched_connect(client, 0); } @@ -758,8 +810,9 @@ void msg_client_cleanup(struct msg_client *client) static void msg_server_accept(struct event *event) { struct msg_server *server = EVENT_ARG(event); - int fd; + struct msg_conn *conn; union sockunion su; + int fd; if (server->fd < 0) return; @@ -782,7 +835,11 @@ static void msg_server_accept(struct event *event) DEBUGD(server->debug, "Accepted new %s connection", server->idtag); - server->create(fd, &su); + conn = server->create(fd, &su); + if (conn) + conn->debug = DEBUG_MODE_CHECK(server->debug, DEBUG_MODE_ALL) + ? true + : false; } int msg_server_init(struct msg_server *server, const char *sopath, diff --git a/lib/mgmt_msg.h b/lib/mgmt_msg.h index 9fdcb9ecd3..6bdc9a6cfc 100644 --- a/lib/mgmt_msg.h +++ b/lib/mgmt_msg.h @@ -24,6 +24,8 @@ DECLARE_MTYPE(MSG_CONN); #define MGMT_MSG_VERSION_PROTOBUF 0 #define MGMT_MSG_VERSION_NATIVE 1 +/* The absolute maximum message size (16MB) */ +#define MGMT_MSG_MAX_MSG_ALLOC_LEN (16 * 1024 * 1024) struct mgmt_msg_state { struct stream *ins; @@ -98,8 +100,8 @@ struct msg_conn { struct msg_conn *conn); void *user; uint short_circuit_depth; + bool is_short_circuit; /* true when the message being handled is SC */ bool is_client; - bool is_short_circuit; bool debug; }; @@ -136,6 +138,10 @@ struct msg_client { extern void msg_client_cleanup(struct msg_client *client); /* + * If `short_circuit_ok` is true, then the client-server connection will use a + * socketpair() rather than a unix-domain socket. This must be passed true if + * you wish to send messages short-circuit later. + * * `notify_disconnect` is not called when the user `msg_client_cleanup` is * called for a client which is currently connected. The socket is closed * but there is no notification. diff --git a/lib/mgmt_msg_native.c b/lib/mgmt_msg_native.c new file mode 100644 index 0000000000..b6dc126d49 --- /dev/null +++ b/lib/mgmt_msg_native.c @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * June 29 2023, Christian Hopps <chopps@labn.net> + * + * Copyright (c) 2023, LabN Consulting, L.L.C. + * + */ +#include <zebra.h> +#include "mgmt_msg_native.h" + +DEFINE_MGROUP(MSG_NATIVE, "Native message allocations"); +DEFINE_MTYPE(MSG_NATIVE, MSG_NATIVE_MSG, "native mgmt msg"); +DEFINE_MTYPE(MSG_NATIVE, MSG_NATIVE_ERROR, "native error msg"); +DEFINE_MTYPE(MSG_NATIVE, MSG_NATIVE_GET_TREE, "native get tree msg"); +DEFINE_MTYPE(MSG_NATIVE, MSG_NATIVE_TREE_DATA, "native tree data msg"); + +int vmgmt_msg_native_send_error(struct msg_conn *conn, uint64_t sess_or_txn_id, + uint64_t req_id, bool short_circuit_ok, + int16_t error, const char *errfmt, va_list ap) +{ + struct mgmt_msg_error *msg; + char *errstr; + ssize_t slen; + int ret; + + errstr = darr_vsprintf(errfmt, ap); + slen = strlen(errstr); + + msg = mgmt_msg_native_alloc_msg(typeof(*msg), slen + 1, + MTYPE_MSG_NATIVE_ERROR); + msg->refer_id = sess_or_txn_id; + msg->req_id = req_id; + msg->code = MGMT_MSG_CODE_ERROR; + msg->error = error; + strlcpy(msg->errstr, errstr, slen + 1); + darr_free(errstr); + + if (conn->debug) + zlog_debug("Sending error %d session-id %" PRIu64 + " req-id %" PRIu64 " scok %d errstr: %s", + error, sess_or_txn_id, req_id, short_circuit_ok, + msg->errstr); + + ret = mgmt_msg_native_send_msg(conn, msg, short_circuit_ok); + mgmt_msg_native_free_msg(msg); + return ret; +} diff --git a/lib/mgmt_msg_native.h b/lib/mgmt_msg_native.h new file mode 100644 index 0000000000..3f6283025c --- /dev/null +++ b/lib/mgmt_msg_native.h @@ -0,0 +1,380 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * June 29 2023, Christian Hopps <chopps@labn.net> + * + * Copyright (c) 2023, LabN Consulting, L.L.C. + * + */ + +#ifndef _FRR_MGMT_MSG_NATIVE_H_ +#define _FRR_MGMT_MSG_NATIVE_H_ + +#ifdef __cplusplus +extern "C" { +#elif 0 +} +#endif + +#include <zebra.h> +#include "compiler.h" +#include "darr.h" +#include "memory.h" +#include "mgmt_msg.h" +#include "mgmt_defines.h" + +#include <stdalign.h> + +/* + * ================== + * Native Message API + * ================== + * + * ----------------------- + * Defining A New Message: + * ----------------------- + * + * 1) Start with `struct mgmt_msg_header` as the first (unnamed) field. + * + * 2) Add fixed-width fields. Add on natural aligned boundaries (*) + * + * 3) [Optional] Add a zero-length variable field. Add aligned on a 64-bit + * boundary, this is done so that: `value = (HDR + 1)` works. + * + * 4) Define a new MTYPE for the new message type (see DECLARE_MTYPE below + * as well as the paired DEFINE_MTYPE in mgmt_msg_native.c) + * + * These rules are so the messages may be read from and written directly to + * "the wire", easily, using common programming languages (e.g., C, rust, go, + * python, ...) + * + * (*) Natrual aligned boundaries, i.e., uint16_t on 2-byte boundary, uint64_t + * on 8-byte boundaries, ...) + * + * ------------------------------ + * Allocating New Native Messages + * ------------------------------ + * + * For fixed-length and variable length messages one should allocate new + * messages with the mgmt_msg_native_alloc_msg() passing in the newly defined + * MTYPE. Likewise, to free the message one should use + * mgmt_msg_native_free_msg(). + * + * Unknown Variable Length Messages: + * --------------------------------- + * + * If using a zero-length variable length field and the length is not known at + * message creation time, you can use the `native` API function + * mgmt_msg_native_append() to add data to the end of the message, or if a more + * full set of operations are required, the darr_xxxx() API is also available as + * in the Advanced section below. + * + * Notable API Functions: + * --------------------------------- + * + * mgmt_msg_native_alloc_msg() - Allocate a native msg. + * mgmt_msg_native_free_msg() - Free a native msg. + * mgmt_msg_native_append() - Append data to the end of the msg. + * mgmt_msg_native_get_msg_len() - Get the total length of the msg. + * mgmt_msg_native_send_msg() - Send the message. + * + * + * ------------------------------------- + * [Advanced Use] Dynamic Array Messages + * ------------------------------------- + * + * NOTE: Most users can simply use mgmt_msg_native_append() and skip this + * section. + * + * This section is only important to understand if you wish to utilize the fact + * that native messages allocated with mgmt_msg_native_alloc_msg are + * actually allocated as uint8_t dynamic arrays (`darr`). + * + * You can utilize all the darr_xxxx() API to manipulate the variable length + * message data in a native message. To do so you simply need to understand that + * the native message is actually a `uint8_t *` darr. So, for example, to append + * data to the end of a message one could do the following: + * + * void append_metric_path(struct mgmt_msg_my_msg *msg) + * { + * msg = (struct mggm_msg_my_msg *) + * darr_strcat((uint8_t *)msg, "/metric"); + * + * // ... + * } + * + * NOTE: If reallocs happen the original passed in pointer will be updated; + * however, any other pointers into the message will become invalid, and so they + * should always be discarded or reinitialized after using any reallocating + * darr_xxx() API functions. + * + * void append_metric_path(struct mgmt_msg_my_msg *msg) + * { + * char *xpath = msg->xpath; // pointer into message + * + * darr_in_strcat((uint8_t *)msg, "/metric"); + * // msg may have been updated to point at new memory + * + * xpath = NULL; // now invalid + * xpath = msg->xpath; // reinitialize + * // ... + * } + * + * Rather than worry about this, it's typical when using dynamic arrays to always + * work from the main pointer to the dynamic array, rather than caching multiple + * pointers into the data. Modern compilers will optimize the code so that it + * adds no extra execution cost. + * + * void append_metric_path(struct mgmt_msg_my_msg *msg) + * { + * darr_in_strcat((uint8_t *)msg, "/metric"); + * + * // Use `msg->xpath` directly rather creating and using an + * // `xpath = msg->xpath` local variable. + * + * if (strcmp(msg->xpath, "foobar/metric")) { + * // ... + * } + * } + * + */ + +DECLARE_MTYPE(MSG_NATIVE_MSG); +DECLARE_MTYPE(MSG_NATIVE_ERROR); +DECLARE_MTYPE(MSG_NATIVE_GET_TREE); +DECLARE_MTYPE(MSG_NATIVE_TREE_DATA); + +/* + * Native message codes + */ +#define MGMT_MSG_CODE_ERROR 0 +#define MGMT_MSG_CODE_GET_TREE 1 +#define MGMT_MSG_CODE_TREE_DATA 2 + +/** + * struct mgmt_msg_header - Header common to all native messages. + * + * @code: the actual type of the message. + * @resv: Set to zero, ignore on receive. + * @vsplit: If a variable section is split in 2, the length of first part. + * @refer_id: the session, txn, conn, etc, this message is associated with. + * @req_id: the request this message is for. + */ +struct mgmt_msg_header { + uint16_t code; + uint16_t resv; + uint32_t vsplit; + uint64_t refer_id; + uint64_t req_id; +}; +_Static_assert(sizeof(struct mgmt_msg_header) == 3 * 8, "Bad padding"); +_Static_assert(sizeof(struct mgmt_msg_header) == + offsetof(struct mgmt_msg_header, req_id) + + sizeof(((struct mgmt_msg_header *)0)->req_id), + "Size mismatch"); + +/** + * struct mgmt_msg_error - Common error message. + * + * @error: An error value. + * @errst: Description of error can be 0 length. + * + * This common error message can be used for replies for many msg requests + * (req_id). + */ +struct mgmt_msg_error { + struct mgmt_msg_header; + int16_t error; + uint8_t resv2[6]; + + alignas(8) char errstr[]; +}; +_Static_assert(sizeof(struct mgmt_msg_error) == + offsetof(struct mgmt_msg_error, errstr), + "Size mismatch"); + +/** + * struct mgmt_msg_get_tree - Message carrying xpath query request. + * + * @result_type: ``LYD_FORMAT`` for the returned result. + * @xpath: the query for the data to return. + */ +struct mgmt_msg_get_tree { + struct mgmt_msg_header; + uint8_t result_type; + uint8_t resv2[7]; + + alignas(8) char xpath[]; +}; +_Static_assert(sizeof(struct mgmt_msg_get_tree) == + offsetof(struct mgmt_msg_get_tree, xpath), + "Size mismatch"); + +/** + * struct mgmt_msg_tree_data - Message carrying tree data. + * + * @partial_error: If the full result could not be returned do to this error. + * @result_type: ``LYD_FORMAT`` for format of the @result value. + * @more: if this is a partial return and there will be more coming. + * @result: The tree data in @result_type format. + * + */ +struct mgmt_msg_tree_data { + struct mgmt_msg_header; + int8_t partial_error; + uint8_t result_type; + uint8_t more; + uint8_t resv2[5]; + + alignas(8) uint8_t result[]; +}; +_Static_assert(sizeof(struct mgmt_msg_tree_data) == + offsetof(struct mgmt_msg_tree_data, result), + "Size mismatch"); + +#define MGMT_MSG_VALIDATE_NUL_TERM(msgp, len) \ + ((len) >= sizeof(*msg) + 1 && ((char *)msgp)[(len)-1] == 0) + + +/** + * Send a native message error to the other end of the connection. + * + * This function is normally used by the server-side to indicate a failure to + * process a client request. For this server side handling of client messages + * which expect a reply, either that reply or this error should be returned, as + * closing the connection is not allowed during message handling. + * + * Args: + * conn: the connection. + * sess_or_txn_id: Session ID (to FE client) or Txn ID (from BE client) + * req_id: which req_id this error is associated with. + * short_circuit_ok: if short circuit sending is OK. + * error: the error value + * errfmt: vprintfrr style format string + * ap: the variable args for errfmt. + * + * Return: + * The return value of ``msg_conn_send_msg``. + */ +extern int vmgmt_msg_native_send_error(struct msg_conn *conn, + uint64_t sess_or_txn_id, uint64_t req_id, + bool short_circuit_ok, int16_t error, + const char *errfmt, va_list ap) + PRINTFRR(6, 0); + +/** + * mgmt_msg_native_alloc_msg() - Create a native appendable msg. + * @msg_type: The message structure type. + * @var_len: The initial additional length to add to the message. + * @mem_type: The initial additional length to add to the message. + * + * This function takes a C type (e.g., `struct mgmt_msg_get_tree`) as an + * argument and returns a new native message. The newly allocated message + * can be used with the other `native` functions. + * + * Importantly the mgmt_msg_native_append() function can be used to add data + * to the end of the message, and mgmt_msg_get_native_msg_len() can be used + * to obtain the total length of the message (i.e., the fixed sized header plus + * the variable length data that has been appended). + * + * Additionally, a dynamic array (darr) pointer can be obtained using + * mgmt_msg_get_native_darr() which allows adding and manipulating the + * variable data that follows the fixed sized header. + * + * Return: A `msg_type` object created using a dynamic_array. + */ +#define mgmt_msg_native_alloc_msg(msg_type, var_len, mem_type) \ + ({ \ + uint8_t *buf = NULL; \ + (msg_type *)darr_append_nz_mt(buf, \ + sizeof(msg_type) + (var_len), \ + mem_type); \ + }) + +/** + * mgmt_msg_free_native_msg() - Free a native msg. + * @msg - pointer to message allocated by mgmt_msg_create_native_msg(). + */ +#define mgmt_msg_native_free_msg(msg) darr_free(msg) + +/** + * mgmt_msg_native_get_msg_len() - Get the total length of the msg. + * @msg: the native message. + * + * Return: the total length of the message, fixed + variable length. + */ +#define mgmt_msg_native_get_msg_len(msg) (darr_len((uint8_t *)(msg))) + +/** + * mgmt_msg_native_append() - Append data to the end of the msg. + * @msg: (IN/OUT) Pointer to the native message, variable may be updated. + * @data: data to append. + * @len: length of data to append. + * + * Append @data of length @len to the native message @msg. + * + * NOTE: Be aware @msg pointer may change as a result of reallocating the + * message to fit the new data. Any other pointers into the old message should + * be discarded. + * + * Return: a pointer to the newly appended data. + */ +#define mgmt_msg_native_append(msg, data, len) \ + memcpy(darr_append(*mgmt_msg_native_get_darrp(msg), len), data, len) + +/** + * mgmt_msg_native_send_msg(msg, short_circuit_ok) - Send a native msg. + * @conn: the mgmt_msg connection. + * @msg: the native message. + * @short_circuit_ok: True if short-circuit sending is required. + * + * Return: The error return value of msg_conn_send_msg(). + */ +#define mgmt_msg_native_send_msg(conn, msg, short_circuit_ok) \ + msg_conn_send_msg(conn, MGMT_MSG_VERSION_NATIVE, msg, \ + mgmt_msg_native_get_msg_len(msg), NULL, \ + short_circuit_ok) + +/** + * mgmt_msg_native_get_darrp() - Return a ptr to the dynamic array ptr. + * @msg: Pointer to the native message. + * + * NOTE: Most users can simply use mgmt_msg_native_append() instead of this. + * + * This function obtains a pointer to the dynamic byte array for this message, + * this array actually includes the message header if one is going to look at + * the length value. With that in mind any of the `darr_*()` functions/API may + * be used to manipulate the variable data at the end of the message. + * + * NOTE: The pointer returned is actually a pointer to the message pointer + * passed in to this function. This pointer to pointer is required so that + * realloc can be done inside the darr API. + * + * NOTE: If reallocs happen the original passed in pointer will be updated; + * however, any other pointers into the message will become invalid and so they + * should always be discarded after using the returned value. + * + * Example: + * + * void append_metric_path(struct mgmt_msg_my_msg *msg) + * { + * char *xpath = msg->xpath; // pointer into message + * uint8_t **darp; + * + * darrp = mgmt_msg_native_get_darrp(msg); + * darr_in_strcat(*darrp, "/metric"); + * + * xpath = NULL; // now invalid + * xpath = msg->xpath; + * } + * + * + * Return: A pointer to the first argument -- which is a pointer to a pointer to + * a dynamic array. + */ +#define mgmt_msg_native_get_darrp(msg) ((uint8_t **)&(msg)) + +#ifdef __cplusplus +} +#endif + +#endif /* _FRR_MGMT_MSG_NATIVE_H_ */ diff --git a/lib/mlag.c b/lib/mlag.c index a370bf8924..62d00ff9a4 100644 --- a/lib/mlag.c +++ b/lib/mlag.c @@ -92,7 +92,7 @@ int mlag_lib_decode_mlag_hdr(struct stream *s, struct mlag_msg *msg, } #define MLAG_MROUTE_ADD_LENGTH \ - (VRF_NAMSIZ + INTERFACE_NAMSIZ + 4 + 4 + 4 + 4 + 1 + 1 + 4) + (VRF_NAMSIZ + IFNAMSIZ + 4 + 4 + 4 + 4 + 1 + 1 + 4) int mlag_lib_decode_mroute_add(struct stream *s, struct mlag_mroute_add *msg, size_t *length) @@ -108,14 +108,14 @@ int mlag_lib_decode_mroute_add(struct stream *s, struct mlag_mroute_add *msg, STREAM_GETC(s, msg->am_i_dr); STREAM_GETC(s, msg->am_i_dual_active); STREAM_GETL(s, msg->vrf_id); - STREAM_GET(msg->intf_name, s, INTERFACE_NAMSIZ); + STREAM_GET(msg->intf_name, s, IFNAMSIZ); return 0; stream_failure: return -1; } -#define MLAG_MROUTE_DEL_LENGTH (VRF_NAMSIZ + INTERFACE_NAMSIZ + 4 + 4 + 4 + 4) +#define MLAG_MROUTE_DEL_LENGTH (VRF_NAMSIZ + IFNAMSIZ + 4 + 4 + 4 + 4) int mlag_lib_decode_mroute_del(struct stream *s, struct mlag_mroute_del *msg, size_t *length) @@ -128,7 +128,7 @@ int mlag_lib_decode_mroute_del(struct stream *s, struct mlag_mroute_del *msg, STREAM_GETL(s, msg->group_ip); STREAM_GETL(s, msg->owner_id); STREAM_GETL(s, msg->vrf_id); - STREAM_GET(msg->intf_name, s, INTERFACE_NAMSIZ); + STREAM_GET(msg->intf_name, s, IFNAMSIZ); return 0; stream_failure: @@ -140,7 +140,7 @@ int mlag_lib_decode_mlag_status(struct stream *s, struct mlag_status *msg) if (s == NULL || msg == NULL) return -1; - STREAM_GET(msg->peerlink_rif, s, INTERFACE_NAMSIZ); + STREAM_GET(msg->peerlink_rif, s, IFNAMSIZ); STREAM_GETL(s, msg->my_role); STREAM_GETL(s, msg->peer_state); return 0; diff --git a/lib/mlag.h b/lib/mlag.h index 3aef0d77a8..91c550b07c 100644 --- a/lib/mlag.h +++ b/lib/mlag.h @@ -65,7 +65,7 @@ struct mlag_frr_status { }; struct mlag_status { - char peerlink_rif[INTERFACE_NAMSIZ]; + char peerlink_rif[IFNAMSIZ]; enum mlag_role my_role; enum mlag_state peer_state; }; @@ -86,7 +86,7 @@ struct mlag_mroute_add { bool am_i_dr; bool am_i_dual_active; vrf_id_t vrf_id; - char intf_name[INTERFACE_NAMSIZ]; + char intf_name[IFNAMSIZ]; }; struct mlag_mroute_del { @@ -95,7 +95,7 @@ struct mlag_mroute_del { uint32_t group_ip; enum mlag_owner owner_id; vrf_id_t vrf_id; - char intf_name[INTERFACE_NAMSIZ]; + char intf_name[IFNAMSIZ]; }; struct mlag_msg { diff --git a/lib/netns_linux.c b/lib/netns_linux.c index 297e2c5952..8fa4bc6fe0 100644 --- a/lib/netns_linux.c +++ b/lib/netns_linux.c @@ -5,6 +5,7 @@ */ #include <zebra.h> +#include <fcntl.h> #ifdef HAVE_NETNS #undef _GNU_SOURCE @@ -502,12 +503,19 @@ void ns_init_management(ns_id_t default_ns_id, ns_id_t internal_ns) void ns_terminate(void) { struct ns *ns; + struct ns_map_nsid *ns_map; while (!RB_EMPTY(ns_head, &ns_tree)) { ns = RB_ROOT(ns_head, &ns_tree); ns_delete(ns); } + + while (!RB_EMPTY(ns_map_nsid_head, &ns_map_nsid_list)) { + ns_map = RB_ROOT(ns_map_nsid_head, &ns_map_nsid_list); + RB_REMOVE(ns_map_nsid_head, &ns_map_nsid_list, ns_map); + XFREE(MTYPE_NS, ns_map); + } } int ns_switch_to_netns(const char *name) diff --git a/lib/network.c b/lib/network.c index af1c7db443..b768693889 100644 --- a/lib/network.c +++ b/lib/network.c @@ -5,6 +5,7 @@ */ #include <zebra.h> +#include <fcntl.h> #include "log.h" #include "network.h" #include "lib_errors.h" diff --git a/lib/nexthop.c b/lib/nexthop.c index dcbb76b68e..4ddb53cd96 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -56,6 +56,7 @@ static int _nexthop_srv6_cmp(const struct nexthop *nh1, const struct nexthop *nh2) { int ret = 0; + int i = 0; if (!nh1->nh_srv6 && !nh2->nh_srv6) return 0; @@ -78,9 +79,26 @@ static int _nexthop_srv6_cmp(const struct nexthop *nh1, if (ret != 0) return ret; - ret = memcmp(&nh1->nh_srv6->seg6_segs, - &nh2->nh_srv6->seg6_segs, - sizeof(struct in6_addr)); + if (!nh1->nh_srv6->seg6_segs && !nh2->nh_srv6->seg6_segs) + return 0; + + if (!nh1->nh_srv6->seg6_segs && nh2->nh_srv6->seg6_segs) + return -1; + + if (nh1->nh_srv6->seg6_segs && !nh2->nh_srv6->seg6_segs) + return 1; + + if (nh1->nh_srv6->seg6_segs->num_segs != + nh2->nh_srv6->seg6_segs->num_segs) + return -1; + + for (i = 0; i < nh1->nh_srv6->seg6_segs->num_segs; i++) { + ret = memcmp(&nh1->nh_srv6->seg6_segs->seg[i], + &nh2->nh_srv6->seg6_segs->seg[i], + sizeof(struct in6_addr)); + if (ret != 0) + break; + } return ret; } @@ -155,7 +173,7 @@ static int _nexthop_cmp_no_labels(const struct nexthop *next1, ret = _nexthop_gateway_cmp(next1, next2); if (ret != 0) return ret; - /* Intentional Fall-Through */ + fallthrough; case NEXTHOP_TYPE_IFINDEX: if (next1->ifindex < next2->ifindex) return -1; @@ -277,7 +295,7 @@ int nexthop_cmp_basic(const struct nexthop *nh1, ret = nexthop_g_addr_cmp(nh1->type, &nh1->gate, &nh2->gate); if (ret != 0) return ret; - /* Intentional Fall-Through */ + fallthrough; case NEXTHOP_TYPE_IFINDEX: if (nh1->ifindex < nh2->ifindex) return -1; @@ -362,7 +380,7 @@ struct nexthop *nexthop_new(void) * The linux kernel does some weird stuff with adding +1 to * all nexthop weights it gets over netlink. * To handle this, just default everything to 1 right from - * from the beginning so we don't have to special case + * the beginning so we don't have to special case * default weights in the linux netlink code. * * 1 should be a valid on all platforms anyway. @@ -568,15 +586,25 @@ void nexthop_del_srv6_seg6local(struct nexthop *nexthop) if (!nexthop->nh_srv6) return; + if (nexthop->nh_srv6->seg6local_action == ZEBRA_SEG6_LOCAL_ACTION_UNSPEC) + return; + nexthop->nh_srv6->seg6local_action = ZEBRA_SEG6_LOCAL_ACTION_UNSPEC; - if (sid_zero(&nexthop->nh_srv6->seg6_segs)) + if (nexthop->nh_srv6->seg6_segs && + (nexthop->nh_srv6->seg6_segs->num_segs == 0 || + sid_zero(nexthop->nh_srv6->seg6_segs))) + XFREE(MTYPE_NH_SRV6, nexthop->nh_srv6->seg6_segs); + + if (nexthop->nh_srv6->seg6_segs == NULL) XFREE(MTYPE_NH_SRV6, nexthop->nh_srv6); } -void nexthop_add_srv6_seg6(struct nexthop *nexthop, - const struct in6_addr *segs) +void nexthop_add_srv6_seg6(struct nexthop *nexthop, const struct in6_addr *segs, + int num_segs) { + int i; + if (!segs) return; @@ -584,7 +612,22 @@ void nexthop_add_srv6_seg6(struct nexthop *nexthop, nexthop->nh_srv6 = XCALLOC(MTYPE_NH_SRV6, sizeof(struct nexthop_srv6)); - nexthop->nh_srv6->seg6_segs = *segs; + /* Enforce limit on srv6 seg stack size */ + if (num_segs > SRV6_MAX_SIDS) + num_segs = SRV6_MAX_SIDS; + + if (!nexthop->nh_srv6->seg6_segs) { + nexthop->nh_srv6->seg6_segs = + XCALLOC(MTYPE_NH_SRV6, + sizeof(struct seg6_seg_stack) + + num_segs * sizeof(struct in6_addr)); + } + + nexthop->nh_srv6->seg6_segs->num_segs = num_segs; + + for (i = 0; i < num_segs; i++) + memcpy(&nexthop->nh_srv6->seg6_segs->seg[i], &segs[i], + sizeof(struct in6_addr)); } void nexthop_del_srv6_seg6(struct nexthop *nexthop) @@ -592,12 +635,14 @@ void nexthop_del_srv6_seg6(struct nexthop *nexthop) if (!nexthop->nh_srv6) return; - memset(&nexthop->nh_srv6->seg6_segs, 0, - sizeof(nexthop->nh_srv6->seg6_segs)); - - if (nexthop->nh_srv6->seg6local_action == - ZEBRA_SEG6_LOCAL_ACTION_UNSPEC) - XFREE(MTYPE_NH_SRV6, nexthop->nh_srv6); + if (nexthop->nh_srv6->seg6local_action == ZEBRA_SEG6_LOCAL_ACTION_UNSPEC && + nexthop->nh_srv6->seg6_segs) { + memset(nexthop->nh_srv6->seg6_segs->seg, 0, + sizeof(struct in6_addr) * + nexthop->nh_srv6->seg6_segs->num_segs); + XFREE(MTYPE_NH_SRV6, nexthop->nh_srv6->seg6_segs); + } + XFREE(MTYPE_NH_SRV6, nexthop->nh_srv6); } const char *nexthop2str(const struct nexthop *nexthop, char *str, int size) @@ -743,11 +788,32 @@ uint32_t nexthop_hash_quick(const struct nexthop *nexthop) } if (nexthop->nh_srv6) { - key = jhash_1word(nexthop->nh_srv6->seg6local_action, key); - key = jhash(&nexthop->nh_srv6->seg6local_ctx, - sizeof(nexthop->nh_srv6->seg6local_ctx), key); - key = jhash(&nexthop->nh_srv6->seg6_segs, - sizeof(nexthop->nh_srv6->seg6_segs), key); + int segs_num = 0; + int i = 0; + + if (nexthop->nh_srv6->seg6local_action != + ZEBRA_SEG6_LOCAL_ACTION_UNSPEC) { + key = jhash_1word(nexthop->nh_srv6->seg6local_action, + key); + key = jhash(&nexthop->nh_srv6->seg6local_ctx, + sizeof(nexthop->nh_srv6->seg6local_ctx), + key); + if (nexthop->nh_srv6->seg6_segs) + key = jhash(&nexthop->nh_srv6->seg6_segs->seg[0], + sizeof(struct in6_addr), key); + } else { + if (nexthop->nh_srv6->seg6_segs) { + segs_num = nexthop->nh_srv6->seg6_segs->num_segs; + while (segs_num >= 1) { + key = jhash(&nexthop->nh_srv6->seg6_segs + ->seg[i], + sizeof(struct in6_addr), + key); + segs_num -= 1; + i += 1; + } + } + } } return key; @@ -797,6 +863,7 @@ void nexthop_copy_no_recurse(struct nexthop *copy, memcpy(©->gate, &nexthop->gate, sizeof(nexthop->gate)); memcpy(©->src, &nexthop->src, sizeof(nexthop->src)); memcpy(©->rmap_src, &nexthop->rmap_src, sizeof(nexthop->rmap_src)); + memcpy(©->rmac, &nexthop->rmac, sizeof(nexthop->rmac)); copy->rparent = rparent; if (nexthop->nh_label) nexthop_add_labels(copy, nexthop->nh_label_type, @@ -809,9 +876,13 @@ void nexthop_copy_no_recurse(struct nexthop *copy, nexthop_add_srv6_seg6local(copy, nexthop->nh_srv6->seg6local_action, &nexthop->nh_srv6->seg6local_ctx); - if (!sid_zero(&nexthop->nh_srv6->seg6_segs)) + if (nexthop->nh_srv6->seg6_segs && + nexthop->nh_srv6->seg6_segs->num_segs && + !sid_zero(nexthop->nh_srv6->seg6_segs)) nexthop_add_srv6_seg6(copy, - &nexthop->nh_srv6->seg6_segs); + &nexthop->nh_srv6->seg6_segs->seg[0], + nexthop->nh_srv6->seg6_segs + ->num_segs); } } @@ -932,6 +1003,8 @@ ssize_t printfrr_nhs(struct fbuf *buf, const struct nexthop *nexthop) ret += bputs(buf, "blackhole"); break; } + + ret += bprintfrr(buf, " vrfid %u", nexthop->vrf_id); return ret; } diff --git a/lib/nexthop.h b/lib/nexthop.h index 43dd71e112..bed6447d49 100644 --- a/lib/nexthop.h +++ b/lib/nexthop.h @@ -125,6 +125,12 @@ struct nexthop { vni_t vni; } nh_encap; + /* EVPN router's MAC. + * Don't support multiple RMAC from the same VTEP yet, so it's not + * included in hash key. + */ + struct ethaddr rmac; + /* SR-TE color used for matching SR-TE policies */ uint32_t srte_color; @@ -151,8 +157,8 @@ void nexthop_del_labels(struct nexthop *); void nexthop_add_srv6_seg6local(struct nexthop *nexthop, uint32_t action, const struct seg6local_context *ctx); void nexthop_del_srv6_seg6local(struct nexthop *nexthop); -void nexthop_add_srv6_seg6(struct nexthop *nexthop, - const struct in6_addr *segs); +void nexthop_add_srv6_seg6(struct nexthop *nexthop, const struct in6_addr *seg, + int num_segs); void nexthop_del_srv6_seg6(struct nexthop *nexthop); /* diff --git a/lib/nexthop_group.c b/lib/nexthop_group.c index 0613fc6736..3f408e0a71 100644 --- a/lib/nexthop_group.c +++ b/lib/nexthop_group.c @@ -81,7 +81,8 @@ uint8_t nexthop_group_nexthop_num(const struct nexthop_group *nhg) return num; } -uint8_t nexthop_group_nexthop_num_no_recurse(const struct nexthop_group *nhg) +static uint8_t +nexthop_group_nexthop_num_no_recurse(const struct nexthop_group *nhg) { struct nexthop *nhop; uint8_t num = 0; @@ -105,20 +106,6 @@ uint8_t nexthop_group_active_nexthop_num(const struct nexthop_group *nhg) return num; } -uint8_t -nexthop_group_active_nexthop_num_no_recurse(const struct nexthop_group *nhg) -{ - struct nexthop *nhop; - uint8_t num = 0; - - for (nhop = nhg->nexthop; nhop; nhop = nhop->next) { - if (CHECK_FLAG(nhop->flags, NEXTHOP_FLAG_ACTIVE)) - num++; - } - - return num; -} - bool nexthop_group_has_label(const struct nexthop_group *nhg) { struct nexthop *nhop; @@ -180,7 +167,7 @@ static struct nexthop *nhg_nh_find(const struct nexthop_group *nhg, &nexthop->gate, &nh->gate); if (ret != 0) continue; - /* Intentional Fall-Through */ + fallthrough; case NEXTHOP_TYPE_IFINDEX: if (nexthop->ifindex != nh->ifindex) continue; @@ -1047,6 +1034,7 @@ void nexthop_group_write_nexthop_simple(struct vty *vty, vty_out(vty, "%pI6 %s", &nh->gate.ipv6, ifname); break; case NEXTHOP_TYPE_BLACKHOLE: + vty_out(vty, "%s", "drop"); break; } } @@ -1247,9 +1235,9 @@ void nexthop_group_disable_vrf(struct vrf *vrf) struct nexthop_hold *nhh; RB_FOREACH (nhgc, nhgc_entry_head, &nhgc_entries) { - struct listnode *node; + struct listnode *node, *nnode; - for (ALL_LIST_ELEMENTS_RO(nhgc->nhg_list, node, nhh)) { + for (ALL_LIST_ELEMENTS(nhgc->nhg_list, node, nnode, nhh)) { struct nexthop nhop; struct nexthop *nh; @@ -1270,6 +1258,10 @@ void nexthop_group_disable_vrf(struct vrf *vrf) nhg_hooks.del_nexthop(nhgc, nh); nexthop_free(nh); + + list_delete_node(nhgc->nhg_list, node); + + nhgl_delete(nhh); } } } diff --git a/lib/nexthop_group.h b/lib/nexthop_group.h index 78237e464f..822a35439c 100644 --- a/lib/nexthop_group.h +++ b/lib/nexthop_group.h @@ -151,11 +151,7 @@ extern void nexthop_group_json_nexthop(json_object *j, /* Return the number of nexthops in this nhg */ extern uint8_t nexthop_group_nexthop_num(const struct nexthop_group *nhg); extern uint8_t -nexthop_group_nexthop_num_no_recurse(const struct nexthop_group *nhg); -extern uint8_t nexthop_group_active_nexthop_num(const struct nexthop_group *nhg); -extern uint8_t -nexthop_group_active_nexthop_num_no_recurse(const struct nexthop_group *nhg); extern bool nexthop_group_has_label(const struct nexthop_group *nhg); diff --git a/lib/northbound.c b/lib/northbound.c index 775f6ff92f..42e4ebbcc9 100644 --- a/lib/northbound.c +++ b/lib/northbound.c @@ -6,6 +6,7 @@ #include <zebra.h> +#include "darr.h" #include "libfrr.h" #include "log.h" #include "lib_errors.h" @@ -70,12 +71,6 @@ static int nb_transaction_process(enum nb_event event, char *errmsg, size_t errmsg_len); static void nb_transaction_apply_finish(struct nb_transaction *transaction, char *errmsg, size_t errmsg_len); -static int nb_oper_data_iter_node(const struct lysc_node *snode, - const char *xpath, const void *list_entry, - const struct yang_list_keys *list_keys, - struct yang_translator *translator, - bool first, uint32_t flags, - nb_oper_data_cb cb, void *arg); static int nb_node_check_config_only(const struct lysc_node *snode, void *arg) { @@ -130,8 +125,8 @@ static int nb_node_new_cb(const struct lysc_node *snode, void *arg) assert(snode->priv == NULL); ((struct lysc_node *)snode)->priv = nb_node; - if (module && module->ignore_cbs) - SET_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS); + if (module && module->ignore_cfg_cbs) + SET_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CFG_CBS); return YANG_ITER_CONTINUE; } @@ -174,6 +169,26 @@ struct nb_node *nb_node_find(const char *path) return snode->priv; } +struct nb_node **nb_nodes_find(const char *xpath) +{ + struct lysc_node **snodes = NULL; + struct nb_node **nb_nodes = NULL; + bool simple; + LY_ERR err; + uint i; + + err = yang_resolve_snode_xpath(ly_native_ctx, xpath, &snodes, &simple); + if (err) + return NULL; + + darr_ensure_i(nb_nodes, darr_lasti(snodes)); + darr_foreach_i (snodes, i) + nb_nodes[i] = snodes[i]->priv; + darr_free(snodes); + return nb_nodes; +} + + void nb_node_set_dependency_cbs(const char *dependency_xpath, const char *dependant_xpath, struct nb_dependency_callbacks *cbs) @@ -194,12 +209,12 @@ bool nb_node_has_dependency(struct nb_node *node) } static int nb_node_validate_cb(const struct nb_node *nb_node, - enum nb_operation operation, + enum nb_cb_operation operation, int callback_implemented, bool optional) { bool valid; - valid = nb_operation_is_valid(operation, nb_node->snode); + valid = nb_cb_operation_is_valid(operation, nb_node->snode); /* * Add an exception for operational data callbacks. A rw list usually @@ -211,15 +226,15 @@ static int nb_node_validate_cb(const struct nb_node *nb_node, * depends on context (e.g. some daemons might augment "frr-interface" * while others don't). */ - if (!valid && callback_implemented && operation != NB_OP_GET_NEXT - && operation != NB_OP_GET_KEYS && operation != NB_OP_LOOKUP_ENTRY) + if (!valid && callback_implemented && operation != NB_CB_GET_NEXT + && operation != NB_CB_GET_KEYS && operation != NB_CB_LOOKUP_ENTRY) flog_warn(EC_LIB_NB_CB_UNNEEDED, "unneeded '%s' callback for '%s'", - nb_operation_name(operation), nb_node->xpath); + nb_cb_operation_name(operation), nb_node->xpath); if (!optional && valid && !callback_implemented) { flog_err(EC_LIB_NB_CB_MISSING, "missing '%s' callback for '%s'", - nb_operation_name(operation), nb_node->xpath); + nb_cb_operation_name(operation), nb_node->xpath); return 1; } @@ -235,30 +250,30 @@ static unsigned int nb_node_validate_cbs(const struct nb_node *nb_node) { unsigned int error = 0; - if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS)) + if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CFG_CBS)) return error; - error += nb_node_validate_cb(nb_node, NB_OP_CREATE, + error += nb_node_validate_cb(nb_node, NB_CB_CREATE, !!nb_node->cbs.create, false); - error += nb_node_validate_cb(nb_node, NB_OP_MODIFY, + error += nb_node_validate_cb(nb_node, NB_CB_MODIFY, !!nb_node->cbs.modify, false); - error += nb_node_validate_cb(nb_node, NB_OP_DESTROY, + error += nb_node_validate_cb(nb_node, NB_CB_DESTROY, !!nb_node->cbs.destroy, false); - error += nb_node_validate_cb(nb_node, NB_OP_MOVE, !!nb_node->cbs.move, + error += nb_node_validate_cb(nb_node, NB_CB_MOVE, !!nb_node->cbs.move, false); - error += nb_node_validate_cb(nb_node, NB_OP_PRE_VALIDATE, + error += nb_node_validate_cb(nb_node, NB_CB_PRE_VALIDATE, !!nb_node->cbs.pre_validate, true); - error += nb_node_validate_cb(nb_node, NB_OP_APPLY_FINISH, + error += nb_node_validate_cb(nb_node, NB_CB_APPLY_FINISH, !!nb_node->cbs.apply_finish, true); - error += nb_node_validate_cb(nb_node, NB_OP_GET_ELEM, + error += nb_node_validate_cb(nb_node, NB_CB_GET_ELEM, !!nb_node->cbs.get_elem, false); - error += nb_node_validate_cb(nb_node, NB_OP_GET_NEXT, + error += nb_node_validate_cb(nb_node, NB_CB_GET_NEXT, !!nb_node->cbs.get_next, false); - error += nb_node_validate_cb(nb_node, NB_OP_GET_KEYS, + error += nb_node_validate_cb(nb_node, NB_CB_GET_KEYS, !!nb_node->cbs.get_keys, false); - error += nb_node_validate_cb(nb_node, NB_OP_LOOKUP_ENTRY, + error += nb_node_validate_cb(nb_node, NB_CB_LOOKUP_ENTRY, !!nb_node->cbs.lookup_entry, false); - error += nb_node_validate_cb(nb_node, NB_OP_RPC, !!nb_node->cbs.rpc, + error += nb_node_validate_cb(nb_node, NB_CB_RPC, !!nb_node->cbs.rpc, false); return error; @@ -305,8 +320,6 @@ struct nb_config *nb_config_new(struct lyd_node *dnode) config->dnode = yang_dnode_new(ly_native_ctx, true); config->version = 0; - RB_INIT(nb_config_cbs, &config->cfg_chgs); - return config; } @@ -314,7 +327,7 @@ void nb_config_free(struct nb_config *config) { if (config->dnode) yang_dnode_free(config->dnode); - nb_config_diff_del_changes(&config->cfg_chgs); + XFREE(MTYPE_NB_CONFIG, config); } @@ -326,8 +339,6 @@ struct nb_config *nb_config_dup(const struct nb_config *config) dup->dnode = yang_dnode_dup(config->dnode); dup->version = config->version; - RB_INIT(nb_config_cbs, &dup->cfg_chgs); - return dup; } @@ -398,7 +409,7 @@ static inline int nb_config_cb_compare(const struct nb_config_cb *a, RB_GENERATE(nb_config_cbs, nb_config_cb, entry, nb_config_cb_compare); static void nb_config_diff_add_change(struct nb_config_cbs *changes, - enum nb_operation operation, + enum nb_cb_operation operation, uint32_t *seq, const struct lyd_node *dnode) { @@ -438,7 +449,7 @@ void nb_config_diff_del_changes(struct nb_config_cbs *changes) void nb_config_diff_created(const struct lyd_node *dnode, uint32_t *seq, struct nb_config_cbs *changes) { - enum nb_operation operation; + enum nb_cb_operation operation; struct lyd_node *child; /* Ignore unimplemented nodes. */ @@ -451,10 +462,10 @@ void nb_config_diff_created(const struct lyd_node *dnode, uint32_t *seq, if (lyd_is_default(dnode)) break; - if (nb_operation_is_valid(NB_OP_CREATE, dnode->schema)) - operation = NB_OP_CREATE; - else if (nb_operation_is_valid(NB_OP_MODIFY, dnode->schema)) - operation = NB_OP_MODIFY; + if (nb_cb_operation_is_valid(NB_CB_CREATE, dnode->schema)) + operation = NB_CB_CREATE; + else if (nb_cb_operation_is_valid(NB_CB_MODIFY, dnode->schema)) + operation = NB_CB_MODIFY; else return; @@ -462,8 +473,8 @@ void nb_config_diff_created(const struct lyd_node *dnode, uint32_t *seq, break; case LYS_CONTAINER: case LYS_LIST: - if (nb_operation_is_valid(NB_OP_CREATE, dnode->schema)) - nb_config_diff_add_change(changes, NB_OP_CREATE, seq, + if (nb_cb_operation_is_valid(NB_CB_CREATE, dnode->schema)) + nb_config_diff_add_change(changes, NB_CB_CREATE, seq, dnode); /* Process child nodes recursively. */ @@ -483,8 +494,8 @@ static void nb_config_diff_deleted(const struct lyd_node *dnode, uint32_t *seq, if (!dnode->schema->priv) return; - if (nb_operation_is_valid(NB_OP_DESTROY, dnode->schema)) - nb_config_diff_add_change(changes, NB_OP_DESTROY, seq, dnode); + if (nb_cb_operation_is_valid(NB_CB_DESTROY, dnode->schema)) + nb_config_diff_add_change(changes, NB_CB_DESTROY, seq, dnode); else if (CHECK_FLAG(dnode->schema->nodetype, LYS_CONTAINER)) { struct lyd_node *child; @@ -633,7 +644,7 @@ void nb_config_diff(const struct nb_config *config1, /* either moving an entry or changing a value */ target = yang_dnode_get(config2->dnode, path); assert(target); - nb_config_diff_add_change(changes, NB_OP_MODIFY, + nb_config_diff_add_change(changes, NB_CB_MODIFY, &seq, target); break; case 'n': /* none */ @@ -648,15 +659,42 @@ void nb_config_diff(const struct nb_config *config1, lyd_free_all(diff); } +static int dnode_create(struct nb_config *candidate, const char *xpath, + const char *value, uint32_t options, + struct lyd_node **new_dnode) +{ + struct lyd_node *dnode; + LY_ERR err; + + err = lyd_new_path(candidate->dnode, ly_native_ctx, xpath, value, + options, &dnode); + if (err) { + flog_warn(EC_LIB_LIBYANG, "%s: lyd_new_path(%s) failed: %d", + __func__, xpath, err); + return NB_ERR; + } else if (dnode) { + err = lyd_new_implicit_tree(dnode, LYD_IMPLICIT_NO_STATE, NULL); + if (err) { + flog_warn(EC_LIB_LIBYANG, + "%s: lyd_new_implicit_all failed: %d", + __func__, err); + } + } + if (new_dnode) + *new_dnode = dnode; + return NB_OK; +} + int nb_candidate_edit(struct nb_config *candidate, const struct nb_node *nb_node, enum nb_operation operation, const char *xpath, const struct yang_data *previous, const struct yang_data *data) { - struct lyd_node *dnode, *dep_dnode; + struct lyd_node *dnode, *dep_dnode, *old_dnode, *parent; char xpath_edit[XPATH_MAXLEN]; char dep_xpath[XPATH_MAXLEN]; + uint32_t options = 0; LY_ERR err; /* Use special notation for leaf-lists (RFC 6020, section 9.13.5). */ @@ -669,23 +707,14 @@ int nb_candidate_edit(struct nb_config *candidate, switch (operation) { case NB_OP_CREATE: case NB_OP_MODIFY: - err = lyd_new_path(candidate->dnode, ly_native_ctx, xpath_edit, - (void *)data->value, LYD_NEW_PATH_UPDATE, + options = LYD_NEW_PATH_UPDATE; + fallthrough; + case NB_OP_CREATE_EXCL: + err = dnode_create(candidate, xpath_edit, data->value, options, &dnode); if (err) { - flog_warn(EC_LIB_LIBYANG, - "%s: lyd_new_path(%s) failed: %d", __func__, - xpath_edit, err); - return NB_ERR; + return err; } else if (dnode) { - /* Create default nodes */ - LY_ERR err = lyd_new_implicit_tree( - dnode, LYD_IMPLICIT_NO_STATE, NULL); - if (err) { - flog_warn(EC_LIB_LIBYANG, - "%s: lyd_new_implicit_all failed: %d", - __func__, err); - } /* * create dependency * @@ -697,33 +726,24 @@ int nb_candidate_edit(struct nb_config *candidate, nb_node->dep_cbs.get_dependency_xpath( dnode, dep_xpath); - err = lyd_new_path(candidate->dnode, - ly_native_ctx, dep_xpath, - NULL, LYD_NEW_PATH_UPDATE, - &dep_dnode); - /* Create default nodes */ - if (!err && dep_dnode) - err = lyd_new_implicit_tree( - dep_dnode, - LYD_IMPLICIT_NO_STATE, NULL); + err = dnode_create(candidate, dep_xpath, NULL, + LYD_NEW_PATH_UPDATE, NULL); if (err) { - flog_warn( - EC_LIB_LIBYANG, - "%s: dependency: lyd_new_path(%s) failed: %d", - __func__, dep_xpath, err); - return NB_ERR; + lyd_free_tree(dnode); + return err; } } } break; case NB_OP_DESTROY: + case NB_OP_DELETE: dnode = yang_dnode_get(candidate->dnode, xpath_edit); - if (!dnode) - /* - * Return a special error code so the caller can choose - * whether to ignore it or not. - */ - return NB_ERR_NOT_FOUND; + if (!dnode) { + if (operation == NB_OP_DELETE) + return NB_ERR; + else + return NB_OK; + } /* destroy dependant */ if (nb_node->dep_cbs.get_dependant_xpath) { nb_node->dep_cbs.get_dependant_xpath(dnode, dep_xpath); @@ -734,90 +754,76 @@ int nb_candidate_edit(struct nb_config *candidate, } lyd_free_tree(dnode); break; + case NB_OP_REPLACE: + old_dnode = yang_dnode_get(candidate->dnode, xpath_edit); + if (old_dnode) { + parent = lyd_parent(old_dnode); + lyd_unlink_tree(old_dnode); + } + err = dnode_create(candidate, xpath_edit, data->value, options, + &dnode); + if (!err && dnode && !old_dnode) { + /* create dependency if the node didn't exist */ + nb_node = dnode->schema->priv; + if (nb_node->dep_cbs.get_dependency_xpath) { + nb_node->dep_cbs.get_dependency_xpath( + dnode, dep_xpath); + + err = dnode_create(candidate, dep_xpath, NULL, + LYD_NEW_PATH_UPDATE, NULL); + if (err) + lyd_free_tree(dnode); + } + } + if (old_dnode) { + /* restore original node on error, free it otherwise */ + if (err) { + if (parent) + lyd_insert_child(parent, old_dnode); + else + lyd_insert_sibling(candidate->dnode, + old_dnode, NULL); + return err; + } + + lyd_free_tree(old_dnode); + } + break; case NB_OP_MOVE: /* TODO: update configuration. */ break; - case NB_OP_PRE_VALIDATE: - case NB_OP_APPLY_FINISH: - case NB_OP_GET_ELEM: - case NB_OP_GET_NEXT: - case NB_OP_GET_KEYS: - case NB_OP_LOOKUP_ENTRY: - case NB_OP_RPC: - flog_warn(EC_LIB_DEVELOPMENT, - "%s: unknown operation (%u) [xpath %s]", __func__, - operation, xpath_edit); - return NB_ERR; } return NB_OK; } -static void nb_update_candidate_changes(struct nb_config *candidate, - struct nb_cfg_change *change, - uint32_t *seq) +const char *nb_operation_name(enum nb_operation operation) { - enum nb_operation oper = change->operation; - char *xpath = change->xpath; - struct lyd_node *root = NULL; - struct lyd_node *dnode; - struct nb_config_cbs *cfg_chgs = &candidate->cfg_chgs; - int op; - - switch (oper) { + switch (operation) { + case NB_OP_CREATE_EXCL: + return "create exclusive"; case NB_OP_CREATE: + return "create"; case NB_OP_MODIFY: - root = yang_dnode_get(candidate->dnode, xpath); - break; + return "modify"; case NB_OP_DESTROY: - root = yang_dnode_get(running_config->dnode, xpath); - /* code */ - break; + return "destroy"; + case NB_OP_DELETE: + return "delete"; + case NB_OP_REPLACE: + return "replace"; case NB_OP_MOVE: - case NB_OP_PRE_VALIDATE: - case NB_OP_APPLY_FINISH: - case NB_OP_GET_ELEM: - case NB_OP_GET_NEXT: - case NB_OP_GET_KEYS: - case NB_OP_LOOKUP_ENTRY: - case NB_OP_RPC: - break; - default: - assert(!"non-enum value, invalid"); + return "move"; } - if (!root) - return; - - LYD_TREE_DFS_BEGIN (root, dnode) { - op = nb_lyd_diff_get_op(dnode); - switch (op) { - case 'c': - nb_config_diff_created(dnode, seq, cfg_chgs); - LYD_TREE_DFS_continue = 1; - break; - case 'd': - nb_config_diff_deleted(dnode, seq, cfg_chgs); - LYD_TREE_DFS_continue = 1; - break; - case 'r': - nb_config_diff_add_change(cfg_chgs, NB_OP_MODIFY, seq, - dnode); - break; - default: - break; - } - LYD_TREE_DFS_END(root, dnode); - } + assert(!"Reached end of function we should never hit"); } -static bool nb_is_operation_allowed(struct nb_node *nb_node, - struct nb_cfg_change *change) +bool nb_is_operation_allowed(struct nb_node *nb_node, enum nb_operation oper) { - enum nb_operation oper = change->operation; - if (lysc_is_key(nb_node->snode)) { - if (oper == NB_OP_MODIFY || oper == NB_OP_DESTROY) + if (oper == NB_OP_MODIFY || oper == NB_OP_DESTROY + || oper == NB_OP_DELETE || oper == NB_OP_REPLACE) return false; } return true; @@ -825,11 +831,9 @@ static bool nb_is_operation_allowed(struct nb_node *nb_node, void nb_candidate_edit_config_changes( struct nb_config *candidate_config, struct nb_cfg_change cfg_changes[], - size_t num_cfg_changes, const char *xpath_base, const char *curr_xpath, - int xpath_index, char *err_buf, int err_bufsize, bool *error) + size_t num_cfg_changes, const char *xpath_base, char *err_buf, + int err_bufsize, bool *error) { - uint32_t seq = 0; - if (error) *error = false; @@ -840,25 +844,19 @@ void nb_candidate_edit_config_changes( for (size_t i = 0; i < num_cfg_changes; i++) { struct nb_cfg_change *change = &cfg_changes[i]; struct nb_node *nb_node; + char *change_xpath = change->xpath; char xpath[XPATH_MAXLEN]; + const char *value; struct yang_data *data; int ret; - /* Handle relative XPaths. */ memset(xpath, 0, sizeof(xpath)); - if (xpath_index > 0 && - (xpath_base[0] == '.' || change->xpath[0] == '.')) - strlcpy(xpath, curr_xpath, sizeof(xpath)); - if (xpath_base[0]) { - if (xpath_base[0] == '.') - strlcat(xpath, xpath_base + 1, sizeof(xpath)); - else - strlcat(xpath, xpath_base, sizeof(xpath)); + /* If change xpath is relative, prepend base xpath. */ + if (change_xpath[0] == '.') { + strlcpy(xpath, xpath_base, sizeof(xpath)); + change_xpath++; /* skip '.' */ } - if (change->xpath[0] == '.') - strlcat(xpath, change->xpath + 1, sizeof(xpath)); - else - strlcpy(xpath, change->xpath, sizeof(xpath)); + strlcat(xpath, change_xpath, sizeof(xpath)); /* Find the northbound node associated to the data path. */ nb_node = nb_node_find(xpath); @@ -870,7 +868,7 @@ void nb_candidate_edit_config_changes( continue; } /* Find if the node to be edited is not a key node */ - if (!nb_is_operation_allowed(nb_node, change)) { + if (!nb_is_operation_allowed(nb_node, change->operation)) { zlog_err(" Xpath %s points to key node", xpath); if (error) *error = true; @@ -878,9 +876,10 @@ void nb_candidate_edit_config_changes( } /* If the value is not set, get the default if it exists. */ - if (change->value == NULL) - change->value = yang_snode_get_default(nb_node->snode); - data = yang_data_new(xpath, change->value); + value = change->value; + if (value == NULL) + value = yang_snode_get_default(nb_node->snode); + data = yang_data_new(xpath, value); /* * Ignore "not found" errors when editing the candidate @@ -889,7 +888,7 @@ void nb_candidate_edit_config_changes( ret = nb_candidate_edit(candidate_config, nb_node, change->operation, xpath, NULL, data); yang_data_free(data); - if (ret != NB_OK && ret != NB_ERR_NOT_FOUND) { + if (ret != NB_OK) { flog_warn( EC_LIB_NB_CANDIDATE_EDIT_ERROR, "%s: failed to edit candidate configuration: operation [%s] xpath [%s]", @@ -899,17 +898,11 @@ void nb_candidate_edit_config_changes( *error = true; continue; } - nb_update_candidate_changes(candidate_config, change, &seq); } if (error && *error) { char buf[BUFSIZ]; - /* - * Failure to edit the candidate configuration should never - * happen in practice, unless there's a bug in the code. When - * that happens, log the error but otherwise ignore it. - */ snprintf(err_buf, err_bufsize, "%% Failed to edit configuration.\n\n%s", yang_print_errors(ly_native_ctx, buf, sizeof(buf))); @@ -946,9 +939,19 @@ int nb_candidate_update(struct nb_config *candidate) int nb_candidate_validate_yang(struct nb_config *candidate, bool no_state, char *errmsg, size_t errmsg_len) { - if (lyd_validate_all(&candidate->dnode, ly_native_ctx, - no_state ? LYD_VALIDATE_NO_STATE - : LYD_VALIDATE_PRESENT, + uint32_t options = 0; + +#ifdef LYD_VALIDATE_MULTI_ERROR + /* libyang 2.1.36+ */ + options |= LYD_VALIDATE_MULTI_ERROR; +#endif + + if (no_state) + SET_FLAG(options, LYD_VALIDATE_NO_STATE); + else + SET_FLAG(options, LYD_VALIDATE_PRESENT); + + if (lyd_validate_all(&candidate->dnode, ly_native_ctx, options, NULL) != 0) { yang_print_errors(ly_native_ctx, errmsg, errmsg_len); return NB_ERR_VALIDATION; @@ -1190,7 +1193,7 @@ int nb_running_lock_check(enum nb_client client, const void *user) } static void nb_log_config_callback(const enum nb_event event, - enum nb_operation operation, + enum nb_cb_operation operation, const struct lyd_node *dnode) { const char *value; @@ -1207,7 +1210,7 @@ static void nb_log_config_callback(const enum nb_event event, zlog_debug( "northbound callback: event [%s] op [%s] xpath [%s] value [%s]", - nb_event_name(event), nb_operation_name(operation), xpath, + nb_event_name(event), nb_cb_operation_name(operation), xpath, value); } @@ -1221,9 +1224,9 @@ static int nb_callback_create(struct nb_context *context, bool unexpected_error = false; int ret; - assert(!CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS)); + assert(!CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CFG_CBS)); - nb_log_config_callback(event, NB_OP_CREATE, dnode); + nb_log_config_callback(event, NB_CB_CREATE, dnode); args.context = context; args.event = event; @@ -1272,9 +1275,9 @@ static int nb_callback_modify(struct nb_context *context, bool unexpected_error = false; int ret; - assert(!CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS)); + assert(!CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CFG_CBS)); - nb_log_config_callback(event, NB_OP_MODIFY, dnode); + nb_log_config_callback(event, NB_CB_MODIFY, dnode); args.context = context; args.event = event; @@ -1323,9 +1326,9 @@ static int nb_callback_destroy(struct nb_context *context, bool unexpected_error = false; int ret; - assert(!CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS)); + assert(!CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CFG_CBS)); - nb_log_config_callback(event, NB_OP_DESTROY, dnode); + nb_log_config_callback(event, NB_CB_DESTROY, dnode); args.context = context; args.event = event; @@ -1368,9 +1371,9 @@ static int nb_callback_move(struct nb_context *context, bool unexpected_error = false; int ret; - assert(!CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS)); + assert(!CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CFG_CBS)); - nb_log_config_callback(event, NB_OP_MOVE, dnode); + nb_log_config_callback(event, NB_CB_MOVE, dnode); args.context = context; args.event = event; @@ -1413,10 +1416,10 @@ static int nb_callback_pre_validate(struct nb_context *context, bool unexpected_error = false; int ret; - if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS)) + if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CFG_CBS)) return 0; - nb_log_config_callback(NB_EV_VALIDATE, NB_OP_PRE_VALIDATE, dnode); + nb_log_config_callback(NB_EV_VALIDATE, NB_CB_PRE_VALIDATE, dnode); args.dnode = dnode; args.errmsg = errmsg; @@ -1447,10 +1450,10 @@ static void nb_callback_apply_finish(struct nb_context *context, { struct nb_cb_apply_finish_args args = {}; - if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS)) + if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CFG_CBS)) return; - nb_log_config_callback(NB_EV_APPLY, NB_OP_APPLY_FINISH, dnode); + nb_log_config_callback(NB_EV_APPLY, NB_CB_APPLY_FINISH, dnode); args.context = context; args.dnode = dnode; @@ -1465,7 +1468,7 @@ struct yang_data *nb_callback_get_elem(const struct nb_node *nb_node, { struct nb_cb_get_elem_args args = {}; - if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS)) + if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CFG_CBS)) return NULL; DEBUGD(&nb_dbg_cbs_state, @@ -1483,7 +1486,7 @@ const void *nb_callback_get_next(const struct nb_node *nb_node, { struct nb_cb_get_next_args args = {}; - if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS)) + if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CFG_CBS)) return NULL; DEBUGD(&nb_dbg_cbs_state, @@ -1500,7 +1503,7 @@ int nb_callback_get_keys(const struct nb_node *nb_node, const void *list_entry, { struct nb_cb_get_keys_args args = {}; - if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS)) + if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CFG_CBS)) return 0; DEBUGD(&nb_dbg_cbs_state, @@ -1518,7 +1521,7 @@ const void *nb_callback_lookup_entry(const struct nb_node *nb_node, { struct nb_cb_lookup_entry_args args = {}; - if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS)) + if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CFG_CBS)) return NULL; DEBUGD(&nb_dbg_cbs_state, @@ -1530,13 +1533,57 @@ const void *nb_callback_lookup_entry(const struct nb_node *nb_node, return nb_node->cbs.lookup_entry(&args); } +const void *nb_callback_lookup_node_entry(struct lyd_node *node, + const void *parent_list_entry) +{ + struct yang_list_keys keys; + struct nb_cb_lookup_entry_args args = {}; + const struct nb_node *nb_node = node->schema->priv; + + if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CFG_CBS)) + return NULL; + + if (yang_get_node_keys(node, &keys)) { + flog_warn(EC_LIB_LIBYANG, + "%s: can't get keys for lookup from existing data node %s", + __func__, node->schema->name); + return NULL; + } + + DEBUGD(&nb_dbg_cbs_state, + "northbound callback (lookup_node_entry): node [%s] parent_list_entry [%p]", + nb_node->xpath, parent_list_entry); + + args.parent_list_entry = parent_list_entry; + args.keys = &keys; + return nb_node->cbs.lookup_entry(&args); +} + +const void *nb_callback_lookup_next(const struct nb_node *nb_node, + const void *parent_list_entry, + const struct yang_list_keys *keys) +{ + struct nb_cb_lookup_entry_args args = {}; + + if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CFG_CBS)) + return NULL; + + DEBUGD(&nb_dbg_cbs_state, + "northbound callback (lookup_entry): node [%s] parent_list_entry [%p]", + nb_node->xpath, parent_list_entry); + + args.parent_list_entry = parent_list_entry; + args.keys = keys; + return nb_node->cbs.lookup_next(&args); +} + int nb_callback_rpc(const struct nb_node *nb_node, const char *xpath, const struct list *input, struct list *output, char *errmsg, size_t errmsg_len) { struct nb_cb_rpc_args args = {}; - if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS)) + if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CFG_CBS)) return 0; DEBUGD(&nb_dbg_cbs_rpc, "northbound RPC: %s", xpath); @@ -1558,14 +1605,14 @@ static int nb_callback_configuration(struct nb_context *context, struct nb_config_change *change, char *errmsg, size_t errmsg_len) { - enum nb_operation operation = change->cb.operation; + enum nb_cb_operation operation = change->cb.operation; char xpath[XPATH_MAXLEN]; const struct nb_node *nb_node = change->cb.nb_node; const struct lyd_node *dnode = change->cb.dnode; union nb_resource *resource; int ret = NB_ERR; - if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS)) + if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CFG_CBS)) return NB_OK; if (event == NB_EV_VALIDATE) @@ -1574,29 +1621,29 @@ static int nb_callback_configuration(struct nb_context *context, resource = &change->resource; switch (operation) { - case NB_OP_CREATE: + case NB_CB_CREATE: ret = nb_callback_create(context, nb_node, event, dnode, resource, errmsg, errmsg_len); break; - case NB_OP_MODIFY: + case NB_CB_MODIFY: ret = nb_callback_modify(context, nb_node, event, dnode, resource, errmsg, errmsg_len); break; - case NB_OP_DESTROY: + case NB_CB_DESTROY: ret = nb_callback_destroy(context, nb_node, event, dnode, errmsg, errmsg_len); break; - case NB_OP_MOVE: + case NB_CB_MOVE: ret = nb_callback_move(context, nb_node, event, dnode, errmsg, errmsg_len); break; - case NB_OP_PRE_VALIDATE: - case NB_OP_APPLY_FINISH: - case NB_OP_GET_ELEM: - case NB_OP_GET_NEXT: - case NB_OP_GET_KEYS: - case NB_OP_LOOKUP_ENTRY: - case NB_OP_RPC: + case NB_CB_PRE_VALIDATE: + case NB_CB_APPLY_FINISH: + case NB_CB_GET_ELEM: + case NB_CB_GET_NEXT: + case NB_CB_GET_KEYS: + case NB_CB_LOOKUP_ENTRY: + case NB_CB_RPC: yang_dnode_get_path(dnode, xpath, sizeof(xpath)); flog_err(EC_LIB_DEVELOPMENT, "%s: unknown operation (%u) [xpath %s]", __func__, @@ -1612,28 +1659,28 @@ static int nb_callback_configuration(struct nb_context *context, flog_warn(EC_LIB_NB_CB_CONFIG_VALIDATE, "error processing configuration change: error [%s] event [%s] operation [%s] xpath [%s]%s%s", nb_err_name(ret), nb_event_name(event), - nb_operation_name(operation), xpath, + nb_cb_operation_name(operation), xpath, errmsg[0] ? " message: " : "", errmsg); break; case NB_EV_PREPARE: flog_warn(EC_LIB_NB_CB_CONFIG_PREPARE, "error processing configuration change: error [%s] event [%s] operation [%s] xpath [%s]%s%s", nb_err_name(ret), nb_event_name(event), - nb_operation_name(operation), xpath, + nb_cb_operation_name(operation), xpath, errmsg[0] ? " message: " : "", errmsg); break; case NB_EV_ABORT: flog_warn(EC_LIB_NB_CB_CONFIG_ABORT, "error processing configuration change: error [%s] event [%s] operation [%s] xpath [%s]%s%s", nb_err_name(ret), nb_event_name(event), - nb_operation_name(operation), xpath, + nb_cb_operation_name(operation), xpath, errmsg[0] ? " message: " : "", errmsg); break; case NB_EV_APPLY: flog_err(EC_LIB_NB_CB_CONFIG_APPLY, "error processing configuration change: error [%s] event [%s] operation [%s] xpath [%s]%s%s", nb_err_name(ret), nb_event_name(event), - nb_operation_name(operation), xpath, + nb_cb_operation_name(operation), xpath, errmsg[0] ? " message: " : "", errmsg); break; default: @@ -1781,7 +1828,7 @@ static void nb_transaction_apply_finish(struct nb_transaction *transaction, * (the 'apply_finish' callbacks from the node ancestors should * be called though). */ - if (change->cb.operation == NB_OP_DESTROY) { + if (change->cb.operation == NB_CB_DESTROY) { char xpath[XPATH_MAXLEN]; dnode = lyd_parent(dnode); @@ -1832,394 +1879,15 @@ static void nb_transaction_apply_finish(struct nb_transaction *transaction, } } -static int nb_oper_data_iter_children(const struct lysc_node *snode, - const char *xpath, const void *list_entry, - const struct yang_list_keys *list_keys, - struct yang_translator *translator, - bool first, uint32_t flags, - nb_oper_data_cb cb, void *arg) -{ - const struct lysc_node *child; - - LY_LIST_FOR (lysc_node_child(snode), child) { - int ret; - - ret = nb_oper_data_iter_node(child, xpath, list_entry, - list_keys, translator, false, - flags, cb, arg); - if (ret != NB_OK) - return ret; - } - - return NB_OK; -} - -static int nb_oper_data_iter_leaf(const struct nb_node *nb_node, - const char *xpath, const void *list_entry, - const struct yang_list_keys *list_keys, - struct yang_translator *translator, - uint32_t flags, nb_oper_data_cb cb, void *arg) -{ - struct yang_data *data; - - if (CHECK_FLAG(nb_node->snode->flags, LYS_CONFIG_W)) - return NB_OK; - - /* Ignore list keys. */ - if (lysc_is_key(nb_node->snode)) - return NB_OK; - - data = nb_callback_get_elem(nb_node, xpath, list_entry); - if (data == NULL) - /* Leaf of type "empty" is not present. */ - return NB_OK; - - return (*cb)(nb_node->snode, translator, data, arg); -} - -static int nb_oper_data_iter_container(const struct nb_node *nb_node, - const char *xpath, - const void *list_entry, - const struct yang_list_keys *list_keys, - struct yang_translator *translator, - uint32_t flags, nb_oper_data_cb cb, - void *arg) -{ - const struct lysc_node *snode = nb_node->snode; - - if (CHECK_FLAG(nb_node->flags, F_NB_NODE_CONFIG_ONLY)) - return NB_OK; - - /* Read-only presence containers. */ - if (nb_node->cbs.get_elem) { - struct yang_data *data; - int ret; - - data = nb_callback_get_elem(nb_node, xpath, list_entry); - if (data == NULL) - /* Presence container is not present. */ - return NB_OK; - - ret = (*cb)(snode, translator, data, arg); - if (ret != NB_OK) - return ret; - } - - /* Read-write presence containers. */ - if (CHECK_FLAG(snode->flags, LYS_CONFIG_W)) { - struct lysc_node_container *scontainer; - - scontainer = (struct lysc_node_container *)snode; - if (CHECK_FLAG(scontainer->flags, LYS_PRESENCE) - && !yang_dnode_get(running_config->dnode, xpath)) - return NB_OK; - } - - /* Iterate over the child nodes. */ - return nb_oper_data_iter_children(snode, xpath, list_entry, list_keys, - translator, false, flags, cb, arg); -} - -static int -nb_oper_data_iter_leaflist(const struct nb_node *nb_node, const char *xpath, - const void *parent_list_entry, - const struct yang_list_keys *parent_list_keys, - struct yang_translator *translator, uint32_t flags, - nb_oper_data_cb cb, void *arg) -{ - const void *list_entry = NULL; - - if (CHECK_FLAG(nb_node->snode->flags, LYS_CONFIG_W)) - return NB_OK; - - do { - struct yang_data *data; - int ret; - - list_entry = nb_callback_get_next(nb_node, parent_list_entry, - list_entry); - if (!list_entry) - /* End of the list. */ - break; - - data = nb_callback_get_elem(nb_node, xpath, list_entry); - if (data == NULL) - continue; - - ret = (*cb)(nb_node->snode, translator, data, arg); - if (ret != NB_OK) - return ret; - } while (list_entry); - - return NB_OK; -} - -static int nb_oper_data_iter_list(const struct nb_node *nb_node, - const char *xpath_list, - const void *parent_list_entry, - const struct yang_list_keys *parent_list_keys, - struct yang_translator *translator, - uint32_t flags, nb_oper_data_cb cb, void *arg) -{ - const struct lysc_node *snode = nb_node->snode; - const void *list_entry = NULL; - uint32_t position = 1; - - if (CHECK_FLAG(nb_node->flags, F_NB_NODE_CONFIG_ONLY)) - return NB_OK; - - /* Iterate over all list entries. */ - do { - const struct lysc_node_leaf *skey; - struct yang_list_keys list_keys = {}; - char xpath[XPATH_MAXLEN * 2]; - int ret; - - /* Obtain list entry. */ - list_entry = nb_callback_get_next(nb_node, parent_list_entry, - list_entry); - if (!list_entry) - /* End of the list. */ - break; - - if (!CHECK_FLAG(nb_node->flags, F_NB_NODE_KEYLESS_LIST)) { - /* Obtain the list entry keys. */ - if (nb_callback_get_keys(nb_node, list_entry, - &list_keys) - != NB_OK) { - flog_warn(EC_LIB_NB_CB_STATE, - "%s: failed to get list keys", - __func__); - return NB_ERR; - } - - /* Build XPath of the list entry. */ - strlcpy(xpath, xpath_list, sizeof(xpath)); - unsigned int i = 0; - LY_FOR_KEYS (snode, skey) { - assert(i < list_keys.num); - snprintf(xpath + strlen(xpath), - sizeof(xpath) - strlen(xpath), - "[%s='%s']", skey->name, - list_keys.key[i]); - i++; - } - assert(i == list_keys.num); - } else { - /* - * Keyless list - build XPath using a positional index. - */ - snprintf(xpath, sizeof(xpath), "%s[%u]", xpath_list, - position); - position++; - } - - /* Iterate over the child nodes. */ - ret = nb_oper_data_iter_children( - nb_node->snode, xpath, list_entry, &list_keys, - translator, false, flags, cb, arg); - if (ret != NB_OK) - return ret; - } while (list_entry); - - return NB_OK; -} - -static int nb_oper_data_iter_node(const struct lysc_node *snode, - const char *xpath_parent, - const void *list_entry, - const struct yang_list_keys *list_keys, - struct yang_translator *translator, - bool first, uint32_t flags, - nb_oper_data_cb cb, void *arg) -{ - struct nb_node *nb_node; - char xpath[XPATH_MAXLEN]; - int ret = NB_OK; - - if (!first && CHECK_FLAG(flags, NB_OPER_DATA_ITER_NORECURSE) - && CHECK_FLAG(snode->nodetype, LYS_CONTAINER | LYS_LIST)) - return NB_OK; - - /* Update XPath. */ - strlcpy(xpath, xpath_parent, sizeof(xpath)); - if (!first && snode->nodetype != LYS_USES) { - struct lysc_node *parent; - - /* Get the real parent. */ - parent = snode->parent; - - /* - * When necessary, include the namespace of the augmenting - * module. - */ - if (parent && parent->module != snode->module) - snprintf(xpath + strlen(xpath), - sizeof(xpath) - strlen(xpath), "/%s:%s", - snode->module->name, snode->name); - else - snprintf(xpath + strlen(xpath), - sizeof(xpath) - strlen(xpath), "/%s", - snode->name); - } - - nb_node = snode->priv; - switch (snode->nodetype) { - case LYS_CONTAINER: - ret = nb_oper_data_iter_container(nb_node, xpath, list_entry, - list_keys, translator, flags, - cb, arg); - break; - case LYS_LEAF: - ret = nb_oper_data_iter_leaf(nb_node, xpath, list_entry, - list_keys, translator, flags, cb, - arg); - break; - case LYS_LEAFLIST: - ret = nb_oper_data_iter_leaflist(nb_node, xpath, list_entry, - list_keys, translator, flags, - cb, arg); - break; - case LYS_LIST: - ret = nb_oper_data_iter_list(nb_node, xpath, list_entry, - list_keys, translator, flags, cb, - arg); - break; - case LYS_USES: - ret = nb_oper_data_iter_children(snode, xpath, list_entry, - list_keys, translator, false, - flags, cb, arg); - break; - default: - break; - } - - return ret; -} - -int nb_oper_data_iterate(const char *xpath, struct yang_translator *translator, - uint32_t flags, nb_oper_data_cb cb, void *arg) -{ - struct nb_node *nb_node; - const void *list_entry = NULL; - struct yang_list_keys list_keys; - struct list *list_dnodes; - struct lyd_node *dnode, *dn; - struct listnode *ln; - int ret; - - nb_node = nb_node_find(xpath); - if (!nb_node) { - flog_warn(EC_LIB_YANG_UNKNOWN_DATA_PATH, - "%s: unknown data path: %s", __func__, xpath); - return NB_ERR; - } - - /* For now this function works only with containers and lists. */ - if (!CHECK_FLAG(nb_node->snode->nodetype, LYS_CONTAINER | LYS_LIST)) { - flog_warn( - EC_LIB_NB_OPERATIONAL_DATA, - "%s: can't iterate over YANG leaf or leaf-list [xpath %s]", - __func__, xpath); - return NB_ERR; - } - - /* - * Create a data tree from the XPath so that we can parse the keys of - * all YANG lists (if any). - */ - - LY_ERR err = lyd_new_path2(NULL, ly_native_ctx, xpath, NULL, 0, 0, - LYD_NEW_PATH_UPDATE, NULL, &dnode); - if (err || !dnode) { - const char *errmsg = - err ? ly_errmsg(ly_native_ctx) : "node not found"; - flog_warn(EC_LIB_LIBYANG, "%s: lyd_new_path() failed %s", - __func__, errmsg); - return NB_ERR; - } - - /* - * Create a linked list to sort the data nodes starting from the root. - */ - list_dnodes = list_new(); - for (dn = dnode; dn; dn = lyd_parent(dn)) { - if (dn->schema->nodetype != LYS_LIST || !lyd_child(dn)) - continue; - listnode_add_head(list_dnodes, dn); - } - /* - * Use the northbound callbacks to find list entry pointer corresponding - * to the given XPath. - */ - for (ALL_LIST_ELEMENTS_RO(list_dnodes, ln, dn)) { - struct lyd_node *child; - struct nb_node *nn; - unsigned int n = 0; - - /* Obtain the list entry keys. */ - memset(&list_keys, 0, sizeof(list_keys)); - LY_LIST_FOR (lyd_child(dn), child) { - if (!lysc_is_key(child->schema)) - break; - strlcpy(list_keys.key[n], - yang_dnode_get_string(child, NULL), - sizeof(list_keys.key[n])); - n++; - } - list_keys.num = n; - if (list_keys.num != yang_snode_num_keys(dn->schema)) { - list_delete(&list_dnodes); - yang_dnode_free(dnode); - return NB_ERR_NOT_FOUND; - } - - /* Find the list entry pointer. */ - nn = dn->schema->priv; - if (!nn->cbs.lookup_entry) { - flog_warn( - EC_LIB_NB_OPERATIONAL_DATA, - "%s: data path doesn't support iteration over operational data: %s", - __func__, xpath); - list_delete(&list_dnodes); - yang_dnode_free(dnode); - return NB_ERR; - } - - list_entry = - nb_callback_lookup_entry(nn, list_entry, &list_keys); - if (list_entry == NULL) { - list_delete(&list_dnodes); - yang_dnode_free(dnode); - return NB_ERR_NOT_FOUND; - } - } - - /* If a list entry was given, iterate over that list entry only. */ - if (dnode->schema->nodetype == LYS_LIST && lyd_child(dnode)) - ret = nb_oper_data_iter_children( - nb_node->snode, xpath, list_entry, &list_keys, - translator, true, flags, cb, arg); - else - ret = nb_oper_data_iter_node(nb_node->snode, xpath, list_entry, - &list_keys, translator, true, - flags, cb, arg); - - list_delete(&list_dnodes); - yang_dnode_free(dnode); - - return ret; -} - -bool nb_operation_is_valid(enum nb_operation operation, - const struct lysc_node *snode) +bool nb_cb_operation_is_valid(enum nb_cb_operation operation, + const struct lysc_node *snode) { struct nb_node *nb_node = snode->priv; struct lysc_node_container *scontainer; struct lysc_node_leaf *sleaf; switch (operation) { - case NB_OP_CREATE: + case NB_CB_CREATE: if (!CHECK_FLAG(snode->flags, LYS_CONFIG_W)) return false; @@ -2241,7 +1909,7 @@ bool nb_operation_is_valid(enum nb_operation operation, return false; } return true; - case NB_OP_MODIFY: + case NB_CB_MODIFY: if (!CHECK_FLAG(snode->flags, LYS_CONFIG_W)) return false; @@ -2259,7 +1927,7 @@ bool nb_operation_is_valid(enum nb_operation operation, return false; } return true; - case NB_OP_DESTROY: + case NB_CB_DESTROY: if (!CHECK_FLAG(snode->flags, LYS_CONFIG_W)) return false; @@ -2295,7 +1963,7 @@ bool nb_operation_is_valid(enum nb_operation operation, return false; } return true; - case NB_OP_MOVE: + case NB_CB_MOVE: if (!CHECK_FLAG(snode->flags, LYS_CONFIG_W)) return false; @@ -2309,12 +1977,12 @@ bool nb_operation_is_valid(enum nb_operation operation, return false; } return true; - case NB_OP_PRE_VALIDATE: - case NB_OP_APPLY_FINISH: + case NB_CB_PRE_VALIDATE: + case NB_CB_APPLY_FINISH: if (!CHECK_FLAG(snode->flags, LYS_CONFIG_W)) return false; return true; - case NB_OP_GET_ELEM: + case NB_CB_GET_ELEM: if (!CHECK_FLAG(snode->flags, LYS_CONFIG_R)) return false; @@ -2331,7 +1999,7 @@ bool nb_operation_is_valid(enum nb_operation operation, return false; } return true; - case NB_OP_GET_NEXT: + case NB_CB_GET_NEXT: switch (snode->nodetype) { case LYS_LIST: if (CHECK_FLAG(nb_node->flags, F_NB_NODE_CONFIG_ONLY)) @@ -2345,8 +2013,8 @@ bool nb_operation_is_valid(enum nb_operation operation, return false; } return true; - case NB_OP_GET_KEYS: - case NB_OP_LOOKUP_ENTRY: + case NB_CB_GET_KEYS: + case NB_CB_LOOKUP_ENTRY: switch (snode->nodetype) { case LYS_LIST: if (CHECK_FLAG(nb_node->flags, F_NB_NODE_CONFIG_ONLY)) @@ -2358,7 +2026,7 @@ bool nb_operation_is_valid(enum nb_operation operation, return false; } return true; - case NB_OP_RPC: + case NB_CB_RPC: if (CHECK_FLAG(snode->flags, LYS_CONFIG_W | LYS_CONFIG_R)) return false; @@ -2560,30 +2228,30 @@ const char *nb_event_name(enum nb_event event) assert(!"Reached end of function we should never hit"); } -const char *nb_operation_name(enum nb_operation operation) +const char *nb_cb_operation_name(enum nb_cb_operation operation) { switch (operation) { - case NB_OP_CREATE: + case NB_CB_CREATE: return "create"; - case NB_OP_MODIFY: + case NB_CB_MODIFY: return "modify"; - case NB_OP_DESTROY: + case NB_CB_DESTROY: return "destroy"; - case NB_OP_MOVE: + case NB_CB_MOVE: return "move"; - case NB_OP_PRE_VALIDATE: + case NB_CB_PRE_VALIDATE: return "pre_validate"; - case NB_OP_APPLY_FINISH: + case NB_CB_APPLY_FINISH: return "apply_finish"; - case NB_OP_GET_ELEM: + case NB_CB_GET_ELEM: return "get_elem"; - case NB_OP_GET_NEXT: + case NB_CB_GET_NEXT: return "get_next"; - case NB_OP_GET_KEYS: + case NB_CB_GET_KEYS: return "get_keys"; - case NB_OP_LOOKUP_ENTRY: + case NB_CB_LOOKUP_ENTRY: return "lookup_entry"; - case NB_OP_RPC: + case NB_CB_RPC: return "rpc"; } @@ -2609,6 +2277,8 @@ const char *nb_err_name(enum nb_error error) return "failed to allocate resource"; case NB_ERR_INCONSISTENCY: return "internal inconsistency"; + case NB_YIELD: + return "should yield"; } assert(!"Reached end of function we should never hit"); @@ -2640,10 +2310,6 @@ const char *nb_client_name(enum nb_client client) static void nb_load_callbacks(const struct frr_yang_module_info *module) { - - if (module->ignore_cbs) - return; - for (size_t i = 0; module->nodes[i].xpath; i++) { struct nb_node *nb_node; uint32_t priority; @@ -2690,7 +2356,6 @@ void nb_init(struct event_loop *tm, size_t nmodules, bool db_enabled) { struct yang_module *loaded[nmodules], **loadedp = loaded; - bool explicit_compile; /* * Currently using this explicit compile feature in libyang2 leads to @@ -2698,8 +2363,9 @@ void nb_init(struct event_loop *tm, * of modules until they have all been loaded into the context. This * avoids multiple recompiles of the same modules as they are * imported/augmented etc. + * (Done as a #define to make coverity happy) */ - explicit_compile = false; +#define explicit_compile false nb_db_enabled = db_enabled; @@ -2734,10 +2400,15 @@ void nb_init(struct event_loop *tm, /* Initialize the northbound CLI. */ nb_cli_init(tm); + + /* Initialize oper-state */ + nb_oper_init(tm); } void nb_terminate(void) { + nb_oper_terminate(); + /* Terminate the northbound CLI. */ nb_cli_terminate(); diff --git a/lib/northbound.h b/lib/northbound.h index 1723a87e4e..4f9ab565d9 100644 --- a/lib/northbound.h +++ b/lib/northbound.h @@ -83,28 +83,22 @@ enum nb_event { }; /* - * Northbound operations. + * Northbound callback operations. * * Refer to the documentation comments of nb_callbacks for more details. */ -enum nb_operation { - NB_OP_CREATE, - NB_OP_MODIFY, - NB_OP_DESTROY, - NB_OP_MOVE, - NB_OP_PRE_VALIDATE, - NB_OP_APPLY_FINISH, - NB_OP_GET_ELEM, - NB_OP_GET_NEXT, - NB_OP_GET_KEYS, - NB_OP_LOOKUP_ENTRY, - NB_OP_RPC, -}; - -struct nb_cfg_change { - char xpath[XPATH_MAXLEN]; - enum nb_operation operation; - const char *value; +enum nb_cb_operation { + NB_CB_CREATE, + NB_CB_MODIFY, + NB_CB_DESTROY, + NB_CB_MOVE, + NB_CB_PRE_VALIDATE, + NB_CB_APPLY_FINISH, + NB_CB_GET_ELEM, + NB_CB_GET_NEXT, + NB_CB_GET_KEYS, + NB_CB_LOOKUP_ENTRY, + NB_CB_RPC, }; union nb_resource { @@ -484,6 +478,22 @@ struct nb_callbacks { */ const void *(*lookup_entry)(struct nb_cb_lookup_entry_args *args); + /* + * Operational data callback for YANG lists. + * + * The callback function should return the next list entry that would + * follow a list entry with the keys given as a parameter. Keyless + * lists don't need to implement this callback. + * + * args + * Refer to the documentation comments of nb_cb_lookup_entry_args for + * details. + * + * Returns: + * Pointer to the list entry if found, or NULL if not found. + */ + const void *(*lookup_next)(struct nb_cb_lookup_entry_args *args); + /* * RPC and action callback. * @@ -597,8 +607,8 @@ struct nb_node { #define F_NB_NODE_CONFIG_ONLY 0x01 /* The YANG list doesn't contain key leafs. */ #define F_NB_NODE_KEYLESS_LIST 0x02 -/* Ignore callbacks for this node */ -#define F_NB_NODE_IGNORE_CBS 0x04 +/* Ignore config callbacks for this node */ +#define F_NB_NODE_IGNORE_CFG_CBS 0x04 /* * HACK: old gcc versions (< 5.x) have a bug that prevents C99 flexible arrays @@ -612,10 +622,11 @@ struct frr_yang_module_info { const char *name; /* - * Ignore callbacks for this module. Set this to true to - * load module without any callbacks. + * Ignore configuration callbacks for this module. Set this to true to + * load module with only CLI-related callbacks. This is useful for + * modules loaded in mgmtd. */ - bool ignore_cbs; + bool ignore_cfg_cbs; /* Northbound callbacks. */ const struct { @@ -644,6 +655,7 @@ enum nb_error { NB_ERR_VALIDATION, NB_ERR_RESOURCE, NB_ERR_INCONSISTENCY, + NB_YIELD, }; /* Default priority. */ @@ -676,7 +688,7 @@ struct nb_context { /* Northbound configuration callback. */ struct nb_config_cb { RB_ENTRY(nb_config_cb) entry; - enum nb_operation operation; + enum nb_cb_operation operation; uint32_t seq; const struct nb_node *nb_node; const struct lyd_node *dnode; @@ -703,7 +715,26 @@ struct nb_transaction { struct nb_config { struct lyd_node *dnode; uint32_t version; - struct nb_config_cbs cfg_chgs; +}; + +/* + * Northbound operations. The semantics of operations is explained in RFC 8072, + * section 2.5: https://datatracker.ietf.org/doc/html/rfc8072#section-2.5. + */ +enum nb_operation { + NB_OP_CREATE_EXCL, /* "create" */ + NB_OP_CREATE, /* "merge" - kept for backward compatibility */ + NB_OP_MODIFY, /* "merge" */ + NB_OP_DESTROY, /* "remove" */ + NB_OP_DELETE, /* "delete" */ + NB_OP_REPLACE, /* "replace" */ + NB_OP_MOVE, /* "move" */ +}; + +struct nb_cfg_change { + char xpath[XPATH_MAXLEN]; + enum nb_operation operation; + const char *value; }; /* Callback function used by nb_oper_data_iterate(). */ @@ -711,6 +742,29 @@ typedef int (*nb_oper_data_cb)(const struct lysc_node *snode, struct yang_translator *translator, struct yang_data *data, void *arg); +/** + * nb_oper_data_finish_cb() - finish a portion or all of a oper data walk. + * @tree - r/o copy of the tree created during this portion of the walk. + * @arg - finish arg passed to nb_op_iterate_yielding. + * @ret - NB_OK if done with walk, NB_YIELD if done with portion, otherwise an + * error. + * + * If nb_op_iterate_yielding() was passed with @should_batch set then this + * callback will be invoked during each portion (batch) of the walk. + * + * The @tree is read-only and should not be modified or freed. + * + * If this function returns anything but NB_OK then the walk will be terminated. + * and this function will not be called again regardless of if @ret was + * `NB_YIELD` or not. + * + * Return: NB_OK to continue or complete the walk normally, otherwise an error + * to immediately terminate the walk. + */ +/* Callback function used by nb_oper_data_iter_yielding(). */ +typedef enum nb_error (*nb_oper_data_finish_cb)(const struct lyd_node *tree, + void *arg, enum nb_error ret); + /* Iterate over direct child nodes only. */ #define NB_OPER_DATA_ITER_NORECURSE 0x0001 @@ -744,6 +798,11 @@ extern int nb_callback_get_keys(const struct nb_node *nb_node, extern const void *nb_callback_lookup_entry(const struct nb_node *nb_node, const void *parent_list_entry, const struct yang_list_keys *keys); +extern const void *nb_callback_lookup_node_entry(struct lyd_node *node, + const void *parent_list_entry); +extern const void *nb_callback_lookup_next(const struct nb_node *nb_node, + const void *parent_list_entry, + const struct yang_list_keys *keys); extern int nb_callback_rpc(const struct nb_node *nb_node, const char *xpath, const struct list *input, struct list *output, char *errmsg, size_t errmsg_len); @@ -769,6 +828,14 @@ void nb_nodes_delete(void); */ extern struct nb_node *nb_node_find(const char *xpath); +/** + * nb_nodes_find() - find the NB nodes corresponding to complex xpath. + * @xpath: XPath to search for (with or without predicates). + * + * Return: a dynamic array (darr) of `struct nb_node *`s. + */ +extern struct nb_node **nb_nodes_find(const char *xpath); + extern void nb_node_set_dependency_cbs(const char *dependency_xpath, const char *dependant_xpath, struct nb_dependency_callbacks *cbs); @@ -842,6 +909,32 @@ extern void nb_config_replace(struct nb_config *config_dst, struct nb_config *config_src, bool preserve_source); +/* + * Return a human-readable string representing a northbound operation. + * + * operation + * Northbound operation. + * + * Returns: + * String representation of the given northbound operation. + */ +extern const char *nb_operation_name(enum nb_operation operation); + +/* + * Validate if the northbound operation is allowed for the given node. + * + * nb_node + * Northbound node. + * + * operation + * Operation we want to check. + * + * Returns: + * true if the operation is allowed, false otherwise. + */ +extern bool nb_is_operation_allowed(struct nb_node *nb_node, + enum nb_operation oper); + /* * Edit a candidate configuration. * @@ -866,7 +959,6 @@ extern void nb_config_replace(struct nb_config *config_dst, * * Returns: * - NB_OK on success. - * - NB_ERR_NOT_FOUND when the element to be deleted was not found. * - NB_ERR for other errors. */ extern int nb_candidate_edit(struct nb_config *candidate, @@ -917,12 +1009,6 @@ extern bool nb_candidate_needs_update(const struct nb_config *candidate); * xpath_base * Base xpath for config. * - * curr_xpath - * Current xpath for config. - * - * xpath_index - * Index of xpath being processed. - * * err_buf * Buffer to store human-readable error message in case of error. * @@ -934,8 +1020,8 @@ extern bool nb_candidate_needs_update(const struct nb_config *candidate); */ extern void nb_candidate_edit_config_changes( struct nb_config *candidate_config, struct nb_cfg_change cfg_changes[], - size_t num_cfg_changes, const char *xpath_base, const char *curr_xpath, - int xpath_index, char *err_buf, int err_bufsize, bool *error); + size_t num_cfg_changes, const char *xpath_base, char *err_buf, + int err_bufsize, bool *error); /* * Delete candidate configuration changes. @@ -1258,7 +1344,7 @@ extern int nb_running_unlock(enum nb_client client, const void *user); extern int nb_running_lock_check(enum nb_client client, const void *user); /* - * Iterate over operational data. + * Iterate over operational data -- deprecated. * * xpath * Data path of the YANG data we want to iterate over. @@ -1269,21 +1355,60 @@ extern int nb_running_lock_check(enum nb_client client, const void *user); * flags * NB_OPER_DATA_ITER_ flags to control how the iteration is performed. * + * should_batch + * Should call finish cb with partial results (i.e., creating batches) + * * cb * Function to call with each data node. * * arg * Arbitrary argument passed as the fourth parameter in each call to 'cb'. * + * tree + * If non-NULL will contain the data tree built from the walk. + * * Returns: * NB_OK on success, NB_ERR otherwise. */ -extern int nb_oper_data_iterate(const char *xpath, - struct yang_translator *translator, - uint32_t flags, nb_oper_data_cb cb, void *arg); +extern enum nb_error nb_oper_iterate_legacy(const char *xpath, + struct yang_translator *translator, + uint32_t flags, nb_oper_data_cb cb, + void *arg, struct lyd_node **tree); + +/** + * nb_oper_walk() - walk the schema building operational state. + * @xpath - + * @translator - + * @flags - + * @should_batch - should allow yielding and processing portions of the tree. + * @cb - callback invoked for each non-list, non-container node. + * @arg - arg to pass to @cb. + * @finish - function to call when done with portion or all of walk. + * @finish_arg - arg to pass to @finish. + * + * Return: walk - a cookie that can be used to cancel the walk. + */ +extern void *nb_oper_walk(const char *xpath, struct yang_translator *translator, + uint32_t flags, bool should_batch, nb_oper_data_cb cb, + void *arg, nb_oper_data_finish_cb finish, + void *finish_arg); + +/** + * nb_oper_cancel_walk() - cancel the in progress walk. + * @walk - value returned from nb_op_iterate_yielding() + * + * Should only be called on an in-progress walk. It is invalid to cancel and + * already finished walk. The walks `finish` callback will not be called. + */ +extern void nb_oper_cancel_walk(void *walk); + +/** + * nb_op_cancel_all_walks() - cancel all in progress walks. + */ +extern void nb_oper_cancel_all_walks(void); /* - * Validate if the northbound operation is valid for the given node. + * Validate if the northbound callback operation is valid for the given node. * * operation * Operation we want to check. @@ -1294,8 +1419,8 @@ extern int nb_oper_data_iterate(const char *xpath, * Returns: * true if the operation is valid, false otherwise. */ -extern bool nb_operation_is_valid(enum nb_operation operation, - const struct lysc_node *snode); +extern bool nb_cb_operation_is_valid(enum nb_cb_operation operation, + const struct lysc_node *snode); /* * Send a YANG notification. This is a no-op unless the 'nb_notification_send' @@ -1419,15 +1544,15 @@ extern void *nb_running_get_entry_non_rec(const struct lyd_node *dnode, extern const char *nb_event_name(enum nb_event event); /* - * Return a human-readable string representing a northbound operation. + * Return a human-readable string representing a northbound callback operation. * * operation - * Northbound operation. + * Northbound callback operation. * * Returns: - * String representation of the given northbound operation. + * String representation of the given northbound callback operation. */ -extern const char *nb_operation_name(enum nb_operation operation); +extern const char *nb_cb_operation_name(enum nb_cb_operation operation); /* * Return a human-readable string representing a northbound error. @@ -1488,6 +1613,9 @@ extern void nb_init(struct event_loop *tm, */ extern void nb_terminate(void); +extern void nb_oper_init(struct event_loop *loop); +extern void nb_oper_terminate(void); + #ifdef __cplusplus } #endif diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c index e9c89d2029..92d4ffb2ba 100644 --- a/lib/northbound_cli.c +++ b/lib/northbound_cli.c @@ -5,6 +5,7 @@ */ #include <zebra.h> +#include <sys/stat.h> #include "libfrr.h" #include "lib/version.h" @@ -147,8 +148,7 @@ static int nb_cli_apply_changes_internal(struct vty *vty, nb_candidate_edit_config_changes( vty->candidate_config, vty->cfg_changes, vty->num_cfg_changes, - xpath_base, VTY_CURR_XPATH, vty->xpath_index, buf, sizeof(buf), - &error); + xpath_base, buf, sizeof(buf), &error); if (error) { /* * Failure to edit the candidate configuration should never @@ -180,8 +180,26 @@ static int nb_cli_apply_changes_internal(struct vty *vty, return CMD_SUCCESS; } +static void create_xpath_base_abs(struct vty *vty, char *xpath_base_abs, + size_t xpath_base_abs_size, + const char *xpath_base) +{ + memset(xpath_base_abs, 0, xpath_base_abs_size); + + if (xpath_base[0] == 0) + xpath_base = "."; + + /* If base xpath is relative, prepend current vty xpath. */ + if (vty->xpath_index > 0 && xpath_base[0] == '.') { + strlcpy(xpath_base_abs, VTY_CURR_XPATH, xpath_base_abs_size); + xpath_base++; /* skip '.' */ + } + strlcat(xpath_base_abs, xpath_base, xpath_base_abs_size); +} + int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt, ...) { + char xpath_base_abs[XPATH_MAXLEN] = {}; char xpath_base[XPATH_MAXLEN] = {}; bool implicit_commit; int ret; @@ -195,6 +213,9 @@ int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt, ...) va_end(ap); } + create_xpath_base_abs(vty, xpath_base_abs, sizeof(xpath_base_abs), + xpath_base); + if (vty_mgmt_should_process_cli_apply_changes(vty)) { VTY_CHECK_XPATH; @@ -202,18 +223,20 @@ int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt, ...) return CMD_SUCCESS; implicit_commit = vty_needs_implicit_commit(vty); - ret = vty_mgmt_send_config_data(vty); + ret = vty_mgmt_send_config_data(vty, xpath_base_abs, + implicit_commit); if (ret >= 0 && !implicit_commit) vty->mgmt_num_pending_setcfg++; return ret; } - return nb_cli_apply_changes_internal(vty, xpath_base, false); + return nb_cli_apply_changes_internal(vty, xpath_base_abs, false); } int nb_cli_apply_changes_clear_pending(struct vty *vty, const char *xpath_base_fmt, ...) { + char xpath_base_abs[XPATH_MAXLEN] = {}; char xpath_base[XPATH_MAXLEN] = {}; bool implicit_commit; int ret; @@ -227,17 +250,28 @@ int nb_cli_apply_changes_clear_pending(struct vty *vty, va_end(ap); } + create_xpath_base_abs(vty, xpath_base_abs, sizeof(xpath_base_abs), + xpath_base); + if (vty_mgmt_should_process_cli_apply_changes(vty)) { VTY_CHECK_XPATH; - + /* + * The legacy user wanted to clear pending (i.e., perform a + * commit immediately) due to some non-yang compatible + * functionality. This new mgmtd code however, continues to send + * changes putting off the commit until XFRR_end is received + * (i.e., end-of-config-file). This should be fine b/c all + * conversions to mgmtd require full proper implementations. + */ implicit_commit = vty_needs_implicit_commit(vty); - ret = vty_mgmt_send_config_data(vty); + ret = vty_mgmt_send_config_data(vty, xpath_base_abs, + implicit_commit); if (ret >= 0 && !implicit_commit) vty->mgmt_num_pending_setcfg++; return ret; } - return nb_cli_apply_changes_internal(vty, xpath_base, true); + return nb_cli_apply_changes_internal(vty, xpath_base_abs, true); } int nb_cli_rpc(struct vty *vty, const char *xpath, struct list *input, @@ -756,7 +790,7 @@ DEFUN (config_exclusive, "Configuration from vty interface\n" "Configure exclusively from this terminal\n") { - return vty_config_enter(vty, true, true); + return vty_config_enter(vty, true, true, false); } /* Configure using a private candidate configuration. */ @@ -766,7 +800,7 @@ DEFUN (config_private, "Configuration from vty interface\n" "Configure using a private candidate configuration\n") { - return vty_config_enter(vty, true, false); + return vty_config_enter(vty, true, false, false); } DEFPY (config_commit, @@ -1404,11 +1438,9 @@ static int nb_cli_oper_data_cb(const struct lysc_node *snode, } exit: - yang_data_free(data); return NB_OK; error: - yang_data_free(data); return NB_ERR; } @@ -1457,9 +1489,14 @@ DEFPY (show_yang_operational_data, ly_ctx = ly_native_ctx; /* Obtain data. */ - dnode = yang_dnode_new(ly_ctx, false); - ret = nb_oper_data_iterate(xpath, translator, 0, nb_cli_oper_data_cb, - dnode); + if (translator) { + dnode = yang_dnode_new(ly_ctx, false); + ret = nb_oper_iterate_legacy(xpath, translator, 0, + nb_cli_oper_data_cb, dnode, NULL); + } else { + dnode = NULL; + ret = nb_oper_iterate_legacy(xpath, NULL, 0, NULL, NULL, &dnode); + } if (ret != NB_OK) { if (format == LYD_JSON) vty_out(vty, "{}\n"); @@ -1467,7 +1504,8 @@ DEFPY (show_yang_operational_data, /* embed ly_last_errmsg() when we get newer libyang */ vty_out(vty, "<!-- Not found -->\n"); } - yang_dnode_free(dnode); + if (dnode) + yang_dnode_free(dnode); return CMD_WARNING; } diff --git a/lib/northbound_cli.h b/lib/northbound_cli.h index c8f8a8481a..1a45794d45 100644 --- a/lib/northbound_cli.h +++ b/lib/northbound_cli.h @@ -32,7 +32,7 @@ extern struct nb_config *vty_shared_candidate_config; * XPath (absolute or relative) of the configuration option being edited. * * operation - * Operation to apply (either NB_OP_CREATE, NB_OP_MODIFY or NB_OP_DELETE). + * Operation to apply (either NB_OP_CREATE, NB_OP_MODIFY or NB_OP_DESTROY). * * value * New value of the configuration option. Should be NULL for typeless YANG diff --git a/lib/northbound_confd.c b/lib/northbound_confd.c index 34406a110b..8503d18002 100644 --- a/lib/northbound_confd.c +++ b/lib/northbound_confd.c @@ -221,7 +221,7 @@ frr_confd_cdb_diff_iter(confd_hkeypath_t *kp, enum cdb_iter_op cdb_op, nb_op = NB_OP_DESTROY; break; case MOP_VALUE_SET: - if (nb_operation_is_valid(NB_OP_MODIFY, nb_node->snode)) + if (nb_is_operation_allowed(nb_node, NB_OP_MODIFY)) nb_op = NB_OP_MODIFY; else /* Ignore list keys modifications. */ diff --git a/lib/northbound_grpc.cpp b/lib/northbound_grpc.cpp index 6c33351cef..7957752589 100644 --- a/lib/northbound_grpc.cpp +++ b/lib/northbound_grpc.cpp @@ -427,25 +427,11 @@ static struct lyd_node *get_dnode_config(const std::string &path) return dnode; } -static int get_oper_data_cb(const struct lysc_node *snode, - struct yang_translator *translator, - struct yang_data *data, void *arg) -{ - struct lyd_node *dnode = static_cast<struct lyd_node *>(arg); - int ret = yang_dnode_edit(dnode, data->xpath, data->value); - yang_data_free(data); - - return (ret == 0) ? NB_OK : NB_ERR; -} - static struct lyd_node *get_dnode_state(const std::string &path) { - struct lyd_node *dnode = yang_dnode_new(ly_native_ctx, false); - if (nb_oper_data_iterate(path.c_str(), NULL, 0, get_oper_data_cb, dnode) - != NB_OK) { - yang_dnode_free(dnode); - return NULL; - } + struct lyd_node *dnode = NULL; + + (void)nb_oper_iterate_legacy(path.c_str(), NULL, 0, NULL, NULL, &dnode); return dnode; } diff --git a/lib/northbound_oper.c b/lib/northbound_oper.c new file mode 100644 index 0000000000..d382bdcfa6 --- /dev/null +++ b/lib/northbound_oper.c @@ -0,0 +1,1846 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * October 14 2023, Christian Hopps <chopps@labn.net> + * + * Copyright (C) 2018 NetDEF, Inc. + * Renato Westphal + * Copyright (c) 2023, LabN Consulting, L.L.C. + * + */ + +#include <zebra.h> +#include "darr.h" +#include "debug.h" +#include "frrevent.h" +#include "frrstr.h" +#include "lib_errors.h" +#include "monotime.h" +#include "northbound.h" + +/* + * YANG model yielding design restrictions: + * + * In order to be able to yield and guarantee we have a valid data tree at the + * point of yielding we must know that each parent has all it's siblings + * collected to represent a complete element. + * + * Basically, there should be a only single branch in the schema tree that + * supports yielding. In practice this means: + * + * list node schema with lookup next: + * - must not have any lookup-next list node sibling schema + * - must not have any list or container node siblings with lookup-next descendants. + * - any parent list nodes must also be lookup-next list nodes + * + * We must also process containers with lookup-next descendants last. + */ + +DEFINE_MTYPE_STATIC(LIB, NB_YIELD_STATE, "NB Yield State"); +DEFINE_MTYPE_STATIC(LIB, NB_NODE_INFOS, "NB Node Infos"); + +/* Amount of time allowed to spend constructing oper-state prior to yielding */ +#define NB_OP_WALK_INTERVAL_MS 50 +#define NB_OP_WALK_INTERVAL_US (NB_OP_WALK_INTERVAL_MS * 1000) + +/* ---------- */ +/* Data Types */ +/* ---------- */ +PREDECL_LIST(nb_op_walks); + +/* + * This is our information about a node on the branch we are looking at + */ +struct nb_op_node_info { + struct lyd_node *inner; + const struct lysc_node *schema; /* inner schema in case we rm inner */ + struct yang_list_keys keys; /* if list, keys to locate element */ + const void *list_entry; /* opaque entry from user or NULL */ + uint xpath_len; /* length of the xpath string for this node */ + uint niters; /* # list elems create this iteration */ + uint nents; /* # list elems create so far */ + bool query_specific_entry : 1; /* this info is specific specified */ + bool has_lookup_next : 1; /* if this node support lookup next */ + bool lookup_next_ok : 1; /* if this and all previous support */ +}; + +/** + * struct nb_op_yield_state - tracking required state for yielding. + * + * @xpath: current xpath representing the node_info stack. + * @xpath_orig: the original query string from the user + * @node_infos: the container stack for the walk from root to current + * @schema_path: the schema nodes along the path indicated by the query string. + * this will include the choice and case nodes which are not + * present in the query string. + * @query_tokstr: the query string tokenized with NUL bytes. + * @query_tokens: the string pointers to each query token (node). + * @non_specific_predicate: tracks if a query_token is non-specific predicate. + * @walk_root_level: The topmost specific node, +1 is where we start walking. + * @walk_start_level: @walk_root_level + 1. + * @query_base_level: the level the query string stops at and full walks + * commence below that. + */ +struct nb_op_yield_state { + /* Walking state */ + char *xpath; + char *xpath_orig; + struct nb_op_node_info *node_infos; + const struct lysc_node **schema_path; + char *query_tokstr; + char **query_tokens; + uint8_t *non_specific_predicate; + int walk_root_level; + int walk_start_level; + int query_base_level; + bool query_list_entry; /* XXX query was for a specific list entry */ + + /* Yielding state */ + bool query_did_entry; /* currently processing the entry */ + bool should_batch; + struct timeval start_time; + struct yang_translator *translator; + uint32_t flags; + nb_oper_data_cb cb; + void *cb_arg; + nb_oper_data_finish_cb finish; + void *finish_arg; + struct event *walk_ev; + struct nb_op_walks_item link; +}; + +DECLARE_LIST(nb_op_walks, struct nb_op_yield_state, link); + +/* ---------------- */ +/* Global Variables */ +/* ---------------- */ + +static struct event_loop *event_loop; +static struct nb_op_walks_head nb_op_walks; + +/* --------------------- */ +/* Function Declarations */ +/* --------------------- */ + +static enum nb_error nb_op_yield(struct nb_op_yield_state *ys); +static struct lyd_node *ys_root_node(struct nb_op_yield_state *ys); + +/* -------------------- */ +/* Function Definitions */ +/* -------------------- */ + +static inline struct nb_op_yield_state * +nb_op_create_yield_state(const char *xpath, struct yang_translator *translator, + uint32_t flags, bool should_batch, nb_oper_data_cb cb, + void *cb_arg, nb_oper_data_finish_cb finish, + void *finish_arg) +{ + struct nb_op_yield_state *ys; + + ys = XCALLOC(MTYPE_NB_YIELD_STATE, sizeof(*ys)); + ys->xpath = darr_strdup_cap(xpath, (size_t)XPATH_MAXLEN); + ys->xpath_orig = darr_strdup(xpath); + ys->translator = translator; + ys->flags = flags; + ys->should_batch = should_batch; + ys->cb = cb; + ys->cb_arg = cb_arg; + ys->finish = finish; + ys->finish_arg = finish_arg; + + nb_op_walks_add_tail(&nb_op_walks, ys); + + return ys; +} + +static inline void nb_op_free_yield_state(struct nb_op_yield_state *ys, + bool nofree_tree) +{ + if (ys) { + EVENT_OFF(ys->walk_ev); + nb_op_walks_del(&nb_op_walks, ys); + /* if we have a branch then free up it's libyang tree */ + if (!nofree_tree && ys_root_node(ys)) + lyd_free_all(ys_root_node(ys)); + darr_free(ys->query_tokens); + darr_free(ys->non_specific_predicate); + darr_free(ys->query_tokstr); + darr_free(ys->schema_path); + darr_free(ys->node_infos); + darr_free(ys->xpath_orig); + darr_free(ys->xpath); + XFREE(MTYPE_NB_YIELD_STATE, ys); + } +} + +static const struct lysc_node *ys_get_walk_stem_tip(struct nb_op_yield_state *ys) +{ + if (ys->walk_start_level <= 0) + return NULL; + return ys->node_infos[ys->walk_start_level - 1].schema; +} + +static struct lyd_node *ys_root_node(struct nb_op_yield_state *ys) +{ + if (!darr_len(ys->node_infos)) + return NULL; + return ys->node_infos[0].inner; +} + +static void ys_trim_xpath(struct nb_op_yield_state *ys) +{ + uint len = darr_len(ys->node_infos); + + if (len == 0) + darr_setlen(ys->xpath, 1); + else + darr_setlen(ys->xpath, darr_last(ys->node_infos)->xpath_len + 1); + ys->xpath[darr_len(ys->xpath) - 1] = 0; +} + +static void ys_pop_inner(struct nb_op_yield_state *ys) +{ + uint len = darr_len(ys->node_infos); + + assert(len); + darr_setlen(ys->node_infos, len - 1); + ys_trim_xpath(ys); +} + +static void ys_free_inner(struct nb_op_yield_state *ys, + struct nb_op_node_info *ni) +{ + if (!CHECK_FLAG(ni->schema->nodetype, LYS_CASE | LYS_CHOICE)) + lyd_free_tree(ni->inner); + ni->inner = NULL; +} + +static void nb_op_get_keys(struct lyd_node_inner *list_node, + struct yang_list_keys *keys) +{ + struct lyd_node *child; + uint n = 0; + + keys->num = 0; + LY_LIST_FOR (list_node->child, child) { + if (!lysc_is_key(child->schema)) + break; + strlcpy(keys->key[n], yang_dnode_get_string(child, NULL), + sizeof(keys->key[n])); + n++; + } + + keys->num = n; +} + +/** + * __move_back_to_next() - move back to the next lookup-next schema + */ +static bool __move_back_to_next(struct nb_op_yield_state *ys, int i) +{ + struct nb_op_node_info *ni; + int j; + + /* + * We will free the subtree we are trimming back to, or we will be done + * with the walk and will free the root on cleanup. + */ + + /* pop any node_info we dropped below on entry */ + for (j = darr_ilen(ys->node_infos) - 1; j > i; j--) + ys_pop_inner(ys); + + for (; i >= ys->walk_root_level; i--) { + if (ys->node_infos[i].has_lookup_next) + break; + ys_pop_inner(ys); + } + + if (i < ys->walk_root_level) + return false; + + ni = &ys->node_infos[i]; + + /* + * The i'th node has been lost after a yield so trim it from the tree + * now. + */ + ys_free_inner(ys, ni); + ni->list_entry = NULL; + + /* + * Leave the empty-of-data node_info on top, __walk will deal with + * this, by doing a lookup-next with the keys which we still have. + */ + + return true; +} + +static void nb_op_resume_data_tree(struct nb_op_yield_state *ys) +{ + struct nb_op_node_info *ni; + struct nb_node *nn; + const void *parent_entry; + const void *list_entry; + uint i; + + /* + * IMPORTANT: On yielding: we always yield during list iteration and + * after the initial list element has been created and handled, so the + * top of the yield stack will always point at a list node. + * + * Additionally, that list node has been processed and was in the + * process of being "get_next"d when we yielded. We process the + * lookup-next list node last so all the rest of the data (to the left) + * has been gotten. NOTE: To keep this simple we will require only a + * single lookup-next sibling in any parents list of children. + * + * Walk the rightmost branch (the node info stack) from base to tip + * verifying all list nodes are still present. If not we backup to the + * node which has a lookup next, and we prune the branch to this node. + * If the list node that went away is the topmost we will be using + * lookup_next, but if it's a parent then the list_entry will have been + * restored. + */ + darr_foreach_i (ys->node_infos, i) { + ni = &ys->node_infos[i]; + nn = ni->schema->priv; + + if (!CHECK_FLAG(ni->schema->nodetype, LYS_LIST)) + continue; + + assert(ni->list_entry != NULL || + ni == darr_last(ys->node_infos)); + + /* Verify the entry is still present */ + parent_entry = (i == 0 ? NULL : ni[-1].list_entry); + list_entry = nb_callback_lookup_entry(nn, parent_entry, + &ni->keys); + if (!list_entry || list_entry != ni->list_entry) { + /* May be NULL or a different pointer + * move back to first of + * container with last lookup_next list node + * (which may be this one) and get next. + */ + if (!__move_back_to_next(ys, i)) + DEBUGD(&nb_dbg_events, + "%s: Nothing to resume after delete during walk (yield)", + __func__); + return; + } + } +} + +/* + * Can only yield if all list nodes to root have lookup_next() callbacks + * + * In order to support lookup_next() the list_node get_next() callback + * needs to return ordered (i.e., sorted) results. + */ + +/* ======================= */ +/* Start of walk init code */ +/* ======================= */ + +/** + * __xpath_pop_node() - remove the last node from xpath string + * @xpath: an xpath string + * + * Return: NB_OK or NB_ERR_NOT_FOUND if nothing left to pop. + */ +static int __xpath_pop_node(char *xpath) +{ + int len = strlen(xpath); + bool abs = xpath[0] == '/'; + char *slash; + + /* "//" or "/" => NULL */ + if (abs && (len == 1 || (len == 2 && xpath[1] == '/'))) + return NB_ERR_NOT_FOUND; + + slash = (char *)frrstr_back_to_char(xpath, '/'); + /* "/foo/bar/" or "/foo/bar//" => "/foo " */ + if (slash && slash == &xpath[len - 1]) { + xpath[--len] = 0; + slash = (char *)frrstr_back_to_char(xpath, '/'); + if (slash && slash == &xpath[len - 1]) { + xpath[--len] = 0; + slash = (char *)frrstr_back_to_char(xpath, '/'); + } + } + if (!slash) + return NB_ERR_NOT_FOUND; + *slash = 0; + return NB_OK; +} + +/** + * nb_op_xpath_to_trunk() - generate a lyd_node tree (trunk) using an xpath. + * @xpath_in: xpath query string to build trunk from. + * @dnode: resulting tree (trunk) + * + * Use the longest prefix of @xpath_in as possible to resolve to a tree (trunk). + * This is logically as if we walked along the xpath string resolving each + * nodename reference (in particular list nodes) until we could not. + * + * Return: error if any, if no error then @dnode contains the tree (trunk). + */ +static enum nb_error nb_op_xpath_to_trunk(const char *xpath_in, + struct lyd_node **trunk) +{ + char *xpath = NULL; + enum nb_error ret = NB_OK; + LY_ERR err; + + darr_in_strdup(xpath, xpath_in); + for (;;) { + err = lyd_new_path2(NULL, ly_native_ctx, xpath, NULL, 0, 0, + LYD_NEW_PATH_UPDATE, NULL, trunk); + if (err == LY_SUCCESS) + break; + + ret = __xpath_pop_node(xpath); + if (ret != NB_OK) + break; + } + darr_free(xpath); + return ret; +} + +/* + * Finish initializing the node info based on the xpath string, and previous + * node_infos on the stack. If this node is a list node, obtain the specific + * list-entry object. + */ +static enum nb_error nb_op_ys_finalize_node_info(struct nb_op_yield_state *ys, + uint index) +{ + struct nb_op_node_info *ni = &ys->node_infos[index]; + struct lyd_node *inner = ni->inner; + struct nb_node *nn = ni->schema->priv; + bool yield_ok = ys->finish != NULL; + + ni->has_lookup_next = nn->cbs.lookup_next != NULL; + + /* track the last list_entry until updated by new list node */ + ni->list_entry = index == 0 ? NULL : ni[-1].list_entry; + + /* Assert that we are walking the rightmost branch */ + assert(!inner->parent || inner == inner->parent->child->prev); + + if (CHECK_FLAG(inner->schema->nodetype, + LYS_CASE | LYS_CHOICE | LYS_CONTAINER)) { + /* containers have only zero or one child on a branch of a tree */ + inner = ((struct lyd_node_inner *)inner)->child; + assert(!inner || inner->prev == inner); + ni->lookup_next_ok = yield_ok && + (index == 0 || ni[-1].lookup_next_ok); + return NB_OK; + } + + assert(CHECK_FLAG(inner->schema->nodetype, LYS_LIST)); + + ni->lookup_next_ok = yield_ok && ni->has_lookup_next && + (index == 0 || ni[-1].lookup_next_ok); + + nb_op_get_keys((struct lyd_node_inner *)inner, &ni->keys); + + /* A list entry cannot be present in a tree w/o it's keys */ + assert(ni->keys.num == yang_snode_num_keys(inner->schema)); + + /* + * Get this nodes opaque list_entry object + */ + + if (!nn->cbs.lookup_entry) { + flog_warn(EC_LIB_NB_OPERATIONAL_DATA, + "%s: data path doesn't support iteration over operational data: %s", + __func__, ys->xpath); + return NB_ERR_NOT_FOUND; + } + + /* ni->list_entry starts as the parent entry of this node */ + ni->list_entry = nb_callback_lookup_entry(nn, ni->list_entry, &ni->keys); + if (ni->list_entry == NULL) { + flog_warn(EC_LIB_NB_OPERATIONAL_DATA, + "%s: list entry lookup failed", __func__); + return NB_ERR_NOT_FOUND; + } + + /* + * By definition any list element we can get a specific list_entry for + * is specific. + */ + ni->query_specific_entry = true; + + return NB_OK; +} + +/** + * nb_op_ys_init_node_infos() - initialize the node info stack from the query. + * @ys: the yield state for this tree walk. + * + * On starting a walk we initialize the node_info stack as deeply as possible + * based on specific node references in the query string. We will stop at the + * point in the query string that is not specific (e.g., a list element without + * it's keys predicate) + * + * Return: northbound return value (enum nb_error) + */ +static enum nb_error nb_op_ys_init_node_infos(struct nb_op_yield_state *ys) +{ + struct nb_op_node_info *ni; + struct lyd_node *inner; + struct lyd_node *node = NULL; + enum nb_error ret; + uint i, len; + char *tmp; + + /* + * Obtain the trunk of the data node tree of the query. + * + * These are the nodes from the root that could be specifically + * identified with the query string. The trunk ends when a no specific + * node could be identified (e.g., a list-node name with no keys). + */ + + ret = nb_op_xpath_to_trunk(ys->xpath, &node); + if (ret || !node) { + flog_warn(EC_LIB_LIBYANG, + "%s: can't instantiate concrete path using xpath: %s", + __func__, ys->xpath); + if (!ret) + ret = NB_ERR_NOT_FOUND; + return ret; + } + + /* Move up to the container if on a leaf currently. */ + if (node && + !CHECK_FLAG(node->schema->nodetype, LYS_CONTAINER | LYS_LIST)) + node = &node->parent->node; + assert(CHECK_FLAG(node->schema->nodetype, LYS_CONTAINER | LYS_LIST)); + if (!node) + return NB_ERR_NOT_FOUND; + + inner = node; + for (len = 1; inner->parent; len++) + inner = &inner->parent->node; + + darr_append_nz_mt(ys->node_infos, len, MTYPE_NB_NODE_INFOS); + + /* + * For each node find the prefix of the xpath query that identified it + * -- save the prefix length. + */ + inner = node; + for (i = len; i > 0; i--, inner = &inner->parent->node) { + ni = &ys->node_infos[i - 1]; + ni->inner = inner; + ni->schema = inner->schema; + /* + * NOTE: we could build this by hand with a litte more effort, + * but this simple implementation works and won't be expensive + * since the number of nodes is small and only done once per + * query. + */ + tmp = yang_dnode_get_path(inner, NULL, 0); + ni->xpath_len = strlen(tmp); + + /* Replace users supplied xpath with the libyang returned value */ + if (i == len) + darr_in_strdup(ys->xpath, tmp); + + /* The prefix must match the prefix of the stored xpath */ + assert(!strncmp(tmp, ys->xpath, ni->xpath_len)); + free(tmp); + } + + /* + * Obtain the specific list-entry objects for each list node on the + * trunk and finish initializing the node_info structs. + */ + + darr_foreach_i (ys->node_infos, i) { + ret = nb_op_ys_finalize_node_info(ys, i); + if (ret != NB_OK) { + if (ys->node_infos[0].inner) + lyd_free_all(ys->node_infos[0].inner); + darr_free(ys->node_infos); + return ret; + } + } + + ys->walk_start_level = darr_len(ys->node_infos); + + ys->walk_root_level = (int)ys->walk_start_level - 1; + + return NB_OK; +} + +/* ================ */ +/* End of init code */ +/* ================ */ + +/** + * nb_op_add_leaf() - Add leaf data to the get tree results + * @ys - the yield state for this tree walk. + * @nb_node - the northbound node representing this leaf. + * @xpath - the xpath (with key predicates) to this leaf value. + * + * Return: northbound return value (enum nb_error) + */ +static enum nb_error nb_op_iter_leaf(struct nb_op_yield_state *ys, + const struct nb_node *nb_node, + const char *xpath) +{ + const struct lysc_node *snode = nb_node->snode; + struct nb_op_node_info *ni = darr_last(ys->node_infos); + struct yang_data *data; + enum nb_error ret = NB_OK; + LY_ERR err; + + if (CHECK_FLAG(snode->flags, LYS_CONFIG_W)) + return NB_OK; + + /* Ignore list keys. */ + if (lysc_is_key(snode)) + return NB_OK; + + data = nb_callback_get_elem(nb_node, xpath, ni->list_entry); + if (data == NULL) + return NB_OK; + + /* Add a dnode to our tree */ + err = lyd_new_term(ni->inner, snode->module, snode->name, data->value, + false, NULL); + if (err) { + yang_data_free(data); + return NB_ERR_RESOURCE; + } + + if (ys->cb) + ret = (*ys->cb)(nb_node->snode, ys->translator, data, + ys->cb_arg); + yang_data_free(data); + + return ret; +} + +static enum nb_error nb_op_iter_leaflist(struct nb_op_yield_state *ys, + const struct nb_node *nb_node, + const char *xpath) +{ + const struct lysc_node *snode = nb_node->snode; + struct nb_op_node_info *ni = darr_last(ys->node_infos); + const void *list_entry = NULL; + enum nb_error ret = NB_OK; + LY_ERR err; + + if (CHECK_FLAG(snode->flags, LYS_CONFIG_W)) + return NB_OK; + + do { + struct yang_data *data; + + list_entry = nb_callback_get_next(nb_node, ni->list_entry, + list_entry); + if (!list_entry) + /* End of the list. */ + break; + + data = nb_callback_get_elem(nb_node, xpath, list_entry); + if (data == NULL) + continue; + + /* Add a dnode to our tree */ + err = lyd_new_term(ni->inner, snode->module, snode->name, + data->value, false, NULL); + if (err) { + yang_data_free(data); + return NB_ERR_RESOURCE; + } + + if (ys->cb) + ret = (*ys->cb)(nb_node->snode, ys->translator, data, + ys->cb_arg); + yang_data_free(data); + } while (ret == NB_OK && list_entry); + + return ret; +} + + +static bool nb_op_schema_path_has_predicate(struct nb_op_yield_state *ys, + int level) +{ + if (level > darr_lasti(ys->query_tokens)) + return false; + return strchr(ys->query_tokens[level], '[') != NULL; +} + +/** + * nb_op_empty_container_ok() - determine if should keep empty container node. + * + * Return: true if the empty container should be kept. + */ +static bool nb_op_empty_container_ok(const struct lysc_node *snode, + const char *xpath, const void *list_entry) +{ + struct nb_node *nn = snode->priv; + struct yang_data *data; + + if (!CHECK_FLAG(snode->flags, LYS_PRESENCE)) + return false; + + if (!nn->cbs.get_elem) + return false; + + data = nb_callback_get_elem(nn, xpath, list_entry); + if (data) { + yang_data_free(data); + return true; + } + return false; +} + +/** + * nb_op_get_child_path() - add child node name to the xpath. + * @xpath_parent - a darr string for the parent node. + * @schild - the child schema node. + * @xpath_child - a previous return value from this function to reuse. + */ +static char *nb_op_get_child_path(const char *xpath_parent, + const struct lysc_node *schild, + char *xpath_child) +{ + /* "/childname" */ + uint space, extra = strlen(schild->name) + 1; + bool new_mod = (!schild->parent || + schild->parent->module != schild->module); + int n; + + if (new_mod) + /* "modulename:" */ + extra += strlen(schild->module->name) + 1; + space = darr_len(xpath_parent) + extra; + + if (xpath_parent == xpath_child) + darr_ensure_cap(xpath_child, space); + else + darr_in_strdup_cap(xpath_child, xpath_parent, space); + if (new_mod) + n = snprintf(darr_strnul(xpath_child), extra + 1, "/%s:%s", + schild->module->name, schild->name); + else + n = snprintf(darr_strnul(xpath_child), extra + 1, "/%s", + schild->name); + assert(n == (int)extra); + _darr_len(xpath_child) += extra; + return xpath_child; +} + +static bool __is_yielding_node(const struct lysc_node *snode) +{ + struct nb_node *nn = snode->priv; + + return nn->cbs.lookup_next != NULL; +} + +static const struct lysc_node *__sib_next(bool yn, const struct lysc_node *sib) +{ + for (; sib; sib = sib->next) { + /* Always skip keys. */ + if (lysc_is_key(sib)) + continue; + if (yn == __is_yielding_node(sib)) + return sib; + } + return NULL; +} + +/** + * nb_op_sib_next() - Return the next sibling to walk to + * @ys: the yield state for this tree walk. + * @sib: the currently being visited sibling + * + * Return: the next sibling to walk to, walking non-yielding before yielding. + */ +static const struct lysc_node *nb_op_sib_next(struct nb_op_yield_state *ys, + const struct lysc_node *sib) +{ + struct lysc_node *parent = sib->parent; + bool yn = __is_yielding_node(sib); + + /* + * If the node info stack is shorter than the schema path then we are + * doign specific query still on the node from the schema path (should + * match) so just return NULL (i.e., don't process siblings) + */ + if (darr_len(ys->schema_path) > darr_len(ys->node_infos)) + return NULL; + /* + * If sib is on top of the node info stack then + * 1) it's a container node -or- + * 2) it's a list node that we were walking and we've reach the last entry + * 3) if sib is a list and the list was empty we never would have + * pushed sib on the stack so the top of the stack is the parent + * + * If the query string included this node then we do not process any + * siblings as we are not walking all the parent's children just this + * specified one give by the query string. + */ + if (sib == darr_last(ys->node_infos)->schema && + darr_len(ys->schema_path) >= darr_len(ys->node_infos)) + return NULL; + /* case (3) */ + else if (sib->nodetype == LYS_LIST && + parent == darr_last(ys->node_infos)->schema && + darr_len(ys->schema_path) > darr_len(ys->node_infos)) + return NULL; + + sib = __sib_next(yn, sib->next); + if (sib) + return sib; + if (yn) + return NULL; + return __sib_next(true, lysc_node_child(parent)); +} +/* + * sib_walk((struct lyd_node *)ni->inner->node.parent->parent->parent->parent->parent->parent->parent) + */ + +/** + * nb_op_sib_first() - obtain the first child to walk to + * @ys: the yield state for this tree walk. + * @parent: the parent whose child we seek + * @skip_keys: if should skip over keys + * + * Return: the first child to continue the walk to, starting with non-yielding + * siblings then yielding ones. There should be no more than 1 yielding sibling. + */ +static const struct lysc_node *nb_op_sib_first(struct nb_op_yield_state *ys, + const struct lysc_node *parent) +{ + const struct lysc_node *sib = lysc_node_child(parent); + const struct lysc_node *first_sib; + + /* + * NOTE: when we want to handle root level walks we will need to use + * lys_getnext() to walk root level of each module and + * ly_ctx_get_module_iter() to walk the modules. + */ + assert(darr_len(ys->node_infos) > 0); + + /* + * The top of the node stack points at @parent. + * + * If the schema path (original query) is longer than our current node + * info stack (current xpath location), we are building back up to the + * base of the user query, return the next schema node from the query + * string (schema_path). + */ + if (darr_last(ys->node_infos) != NULL && + !CHECK_FLAG(darr_last(ys->node_infos)->schema->nodetype, + LYS_CASE | LYS_CHOICE)) + assert(darr_last(ys->node_infos)->schema == parent); + if (darr_lasti(ys->node_infos) < ys->query_base_level) + return ys->schema_path[darr_lasti(ys->node_infos) + 1]; + + /* We always skip keys. */ + while (sib && lysc_is_key(sib)) + sib = sib->next; + if (!sib) + return NULL; + + /* Return non-yielding node's first */ + first_sib = sib; + if (__is_yielding_node(sib)) { + sib = __sib_next(false, sib); + if (sib) + return sib; + } + return first_sib; +} + +/* + * "3-dimensional" walk from base of the tree to the tip in-order. + * + * The actual tree is only 2-dimensional as list nodes are organized as adjacent + * siblings under a common parent perhaps with other siblings to each side; + * however, using 3d view here is easier to diagram. + * + * - A list node is yielding if it has a lookup_next callback. + * - All other node types are not yielding. + * - There's only one yielding node in a list of children (i.e., siblings). + * + * We visit all non-yielding children prior to the yielding child. + * That way we have the fullest tree possible even when something is deleted + * during a yield. + * --- child/parent descendant poinilnters + * ... next/prev sibling pointers + * o.o list entries pointers + * ~~~ diagram extension connector + * 1 + * / \ + * / \ o~~~~12 + * / \ . / \ + * 2.......5 o~~~9 13...14 + * / \ | . / \ + * 3...4 6 10...11 Cont Nodes: 1,2,5 + * / \ List Nodes: 6,9,12 + * 7...8 Leaf Nodes: 3,4,7,8,10,11,13,14 + * Schema Leaf A: 3 + * Schema Leaf B: 4 + * Schema Leaf C: 7,10,13 + * Schema Leaf D: 8,11,14 + */ +static enum nb_error __walk(struct nb_op_yield_state *ys, bool is_resume) +{ + const struct lysc_node *walk_stem_tip = ys_get_walk_stem_tip(ys); + const struct lysc_node *sib; + const void *parent_list_entry = NULL; + const void *list_entry = NULL; + struct nb_op_node_info *ni, *pni; + struct lyd_node *node; + struct nb_node *nn; + char *xpath_child = NULL; + // bool at_query_base; + bool at_root_level, list_start, is_specific_node; + enum nb_error ret = NB_OK; + LY_ERR err; + int at_clevel; + uint len; + + + monotime(&ys->start_time); + + /* Don't currently support walking all root nodes */ + if (!walk_stem_tip) + return NB_ERR_NOT_FOUND; + + if (ys->schema_path[0]->nodetype == LYS_CHOICE) { + flog_err(EC_LIB_NB_OPERATIONAL_DATA, + "%s: unable to walk root level choice node from module: %s", + __func__, ys->schema_path[0]->module->name); + return NB_ERR; + } + + /* + * If we are resuming then start with the list container on top. + * Otherwise get the first child of the container we are walking, + * starting with non-yielding children. + */ + if (is_resume) + sib = darr_last(ys->node_infos)->schema; + else { + /* + * Start with non-yielding children first. + * + * When adding root level walks, the sibling list are the root + * level nodes of all modules + */ + sib = nb_op_sib_first(ys, walk_stem_tip); + if (!sib) + return NB_ERR_NOT_FOUND; + } + + + while (true) { + /* Grab the top container/list node info on the stack */ + at_clevel = darr_lasti(ys->node_infos); + ni = &ys->node_infos[at_clevel]; + + /* + * This is the level of the last specific node at init + * time. +1 would be the first non-specific list or + * non-container if present in the container node. + */ + at_root_level = at_clevel == ys->walk_root_level; + + if (!sib) { + /* + * We've reached the end of the siblings inside a + * containing node; either a container, case, choice, or + * a specific list node entry. + * + * We handle case/choice/container node inline; however, + * for lists we are only done with a specific entry and + * need to move to the next element on the list so we + * drop down into the switch for that case. + */ + + /* Grab the containing node. */ + sib = ni->schema; + + if (CHECK_FLAG(sib->nodetype, + LYS_CASE | LYS_CHOICE | LYS_CONTAINER)) { + /* If we added an empty container node (no + * children) and it's not a presence container + * or it's not backed by the get_elem callback, + * remove the node from the tree. + */ + if (sib->nodetype == LYS_CONTAINER && + !lyd_child(ni->inner) && + !nb_op_empty_container_ok(sib, ys->xpath, + ni->list_entry)) + ys_free_inner(ys, ni); + + /* If we have returned to our original walk base, + * then we are done with the walk. + */ + if (at_root_level) { + ret = NB_OK; + goto done; + } + /* + * Grab the sibling of the container we are + * about to pop, so we will be mid-walk on the + * parent containers children. + */ + sib = nb_op_sib_next(ys, sib); + + /* Pop container node to the parent container */ + ys_pop_inner(ys); + + /* + * If are were working on a user narrowed path + * then we are done with these siblings. + */ + if (darr_len(ys->schema_path) > + darr_len(ys->node_infos)) + sib = NULL; + + /* Start over */ + continue; + } + /* + * If we are here we have reached the end of the + * children of a list entry node. sib points + * at the list node info. + */ + } + + if (CHECK_FLAG(sib->nodetype, + LYS_LEAF | LYS_LEAFLIST | LYS_CONTAINER)) + xpath_child = nb_op_get_child_path(ys->xpath, sib, + xpath_child); + else if (CHECK_FLAG(sib->nodetype, LYS_CASE | LYS_CHOICE)) + darr_in_strdup(xpath_child, ys->xpath); + + nn = sib->priv; + + switch (sib->nodetype) { + case LYS_LEAF: + /* + * If we have a non-specific walk to a specific leaf + * (e.g., "..../route-entry/metric") and the leaf value + * is not present, then we are left with the data nodes + * of the stem of the branch to the missing leaf data. + * For containers this will get cleaned up by the + * container code above that looks for no children; + * however, this doesn't work for lists. + * + * (FN:A) We need a similar check for empty list + * elements. Empty list elements below the + * query_base_level (i.e., the schema path length) + * should be cleaned up as they don't support anything + * the user is querying for, if they are above the + * query_base_level then they are part of the walk and + * should be kept. + */ + ret = nb_op_iter_leaf(ys, nn, xpath_child); + if (ret != NB_OK) + goto done; + sib = nb_op_sib_next(ys, sib); + continue; + case LYS_LEAFLIST: + ret = nb_op_iter_leaflist(ys, nn, xpath_child); + if (ret != NB_OK) + goto done; + sib = nb_op_sib_next(ys, sib); + continue; + case LYS_CASE: + case LYS_CHOICE: + case LYS_CONTAINER: + if (CHECK_FLAG(nn->flags, F_NB_NODE_CONFIG_ONLY)) { + sib = nb_op_sib_next(ys, sib); + continue; + } + + if (sib->nodetype != LYS_CONTAINER) { + /* Case/choice use parent inner. */ + /* TODO: thus we don't support root level choice */ + node = ni->inner; + } else { + err = lyd_new_inner(ni->inner, sib->module, + sib->name, false, &node); + if (err) { + ret = NB_ERR_RESOURCE; + goto done; + } + } + + /* push this choice/container node on top of the stack */ + ni = darr_appendz(ys->node_infos); + ni->inner = node; + ni->schema = sib; + ni->lookup_next_ok = ni[-1].lookup_next_ok; + ni->list_entry = ni[-1].list_entry; + + darr_in_strdup(ys->xpath, xpath_child); + ni->xpath_len = darr_strlen(ys->xpath); + + sib = nb_op_sib_first(ys, sib); + continue; + case LYS_LIST: + + /* + * Notes: + * + * NOTE: ni->inner may be NULL here if we resumed and it + * was gone. ni->schema and ni->keys will still be + * valid. + * + * NOTE: At this point sib is never NULL; however, if it + * was NULL at the top of the loop, then we were done + * working on a list element's children and will be + * attempting to get the next list element here so sib + * == ni->schema (i.e., !list_start). + * + * (FN:A): Before doing this let's remove empty list + * elements that are "inside" the query string as they + * represent a stem which didn't lead to actual data + * being requested by the user -- for example, + * ".../route-entry/metric" if metric is not present we + * don't want to return an empty route-entry to the + * user. + */ + + node = NULL; + list_start = ni->schema != sib; + if (list_start) { + /* + * List iteration: First Element + * ----------------------------- + * + * Our node info wasn't on top (wasn't an entry + * for sib) so this is a new list iteration, we + * will push our node info below. The top is our + * parent. + */ + if (CHECK_FLAG(nn->flags, + F_NB_NODE_CONFIG_ONLY)) { + sib = nb_op_sib_next(ys, sib); + continue; + } + /* we are now at one level higher */ + at_clevel += 1; + pni = ni; + ni = NULL; + } else { + /* + * List iteration: Next Element + * ---------------------------- + * + * This is the case where `sib == NULL` at the + * top of the loop, so, we just completed the + * walking the children of a list entry, i.e., + * we are done with that list entry. + * + * `sib` was reset to point at the our list node + * at the top of node_infos. + * + * Within this node_info, `ys->xpath`, `inner`, + * `list_entry`, and `xpath_len` are for the + * previous list entry, and need to be updated. + */ + pni = darr_len(ys->node_infos) > 1 ? &ni[-1] + : NULL; + } + + parent_list_entry = pni ? pni->list_entry : NULL; + list_entry = ni ? ni->list_entry : NULL; + + /* + * Before yielding we check to see if we are doing a + * specific list entry instead of a full list iteration. + * We do not want to yield during specific list entry + * processing. + */ + + /* + * If we are at a list start check to see if the node + * has a predicate. If so we will try and fetch the data + * node now that we've built part of the tree, if the + * predicates are keys or only depend on the tree already + * built, it should create the element for us. + */ + is_specific_node = false; + if (list_start && + at_clevel <= darr_lasti(ys->query_tokens) && + !ys->non_specific_predicate[at_clevel] && + nb_op_schema_path_has_predicate(ys, at_clevel)) { + err = lyd_new_path(pni->inner, NULL, + ys->query_tokens[at_clevel], + NULL, 0, &node); + if (!err) + is_specific_node = true; + else if (err == LY_EVALID) + ys->non_specific_predicate[at_clevel] = true; + else { + flog_err(EC_LIB_NB_OPERATIONAL_DATA, + "%s: unable to create node for specific query string: %s: %s", + __func__, + ys->query_tokens[at_clevel], + yang_ly_strerrcode(err)); + ret = NB_ERR; + goto done; + } + } + + if (list_entry && ni->query_specific_entry) { + /* + * Ending specific list entry processing. + */ + assert(!list_start); + is_specific_node = true; + list_entry = NULL; + } + + /* + * Should we yield? + * + * Don't yield if we have a specific entry. + */ + if (!is_specific_node && ni && ni->lookup_next_ok && + // make sure we advance, if the interval is + // fast and we are very slow. + ((monotime_since(&ys->start_time, NULL) > + NB_OP_WALK_INTERVAL_US && + ni->niters) || + (ni->niters + 1) % 10000 == 0)) { + /* This is a yield supporting list node and + * we've been running at least our yield + * interval, so yield. + * + * NOTE: we never yield on list_start, and we + * are always about to be doing a get_next. + */ + DEBUGD(&nb_dbg_events, + "%s: yielding after %u iterations", + __func__, ni->niters); + + ni->niters = 0; + ret = NB_YIELD; + goto done; + } + + /* + * Now get the backend list_entry opaque object for + * this list entry from the backend. + */ + + if (is_specific_node) { + /* + * Specific List Entry: + * -------------------- + */ + if (list_start) { + list_entry = + nb_callback_lookup_node_entry( + node, parent_list_entry); + /* + * If the node we created from a + * specific predicate entry is not + * actually there we need to delete the + * node from our data tree + */ + if (!list_entry) { + lyd_free_tree(node); + node = NULL; + } + } + } else if (!list_start && !list_entry && + ni->has_lookup_next) { + /* + * After Yield: + * ------------ + * After a yield the list_entry may have become + * invalid, so use lookup_next callback with + * parent and keys instead to find next element. + */ + list_entry = + nb_callback_lookup_next(nn, + parent_list_entry, + &ni->keys); + } else { + /* + * Normal List Iteration: + * ---------------------- + * Start (list_entry == NULL) or continue + * (list_entry != NULL) the list iteration. + */ + /* Obtain [next] list entry. */ + list_entry = + nb_callback_get_next(nn, + parent_list_entry, + list_entry); + } + + /* + * (FN:A) Reap empty list element? Check to see if we + * should reap an empty list element. We do this if the + * empty list element exists at or below the query base + * (i.e., it's not part of the walk, but a failed find + * on a more specific query e.g., for below the + * `route-entry` element for a query + * `.../route-entry/metric` where the list element had + * no metric value. + * + * However, if the user query is for a key of a list + * element, then when we reach that list element it will + * have no non-key children, check for this condition + * and do not reap if true. + */ + if (!list_start && ni->inner && + !lyd_child_no_keys(ni->inner) && + /* not the top element with a key match */ + !((darr_ilen(ys->node_infos) == + darr_ilen(ys->schema_path) - 1) && + lysc_is_key((*darr_last(ys->schema_path)))) && + /* is this at or below the base? */ + darr_ilen(ys->node_infos) <= ys->query_base_level) + ys_free_inner(ys, ni); + + + if (!list_entry) { + /* + * List Iteration Done + * ------------------- + */ + + /* + * Grab next sibling of the list node + */ + if (is_specific_node) + sib = NULL; + else + sib = nb_op_sib_next(ys, sib); + + /* + * If we are at the walk root (base) level then + * that specifies a list and we are done iterating + * the list, so we are done with the walk entirely. + */ + if (!sib && at_clevel == ys->walk_root_level) { + ret = NB_OK; + goto done; + } + + /* + * Pop the our list node info back to our + * parent. + * + * We only do this if we've already pushed a + * node for the current list schema. For + * `list_start` this hasn't happened yet, as + * would have happened below. So when list_start + * is true but list_entry if NULL we + * are processing an empty list. + */ + if (!list_start) + ys_pop_inner(ys); + + /* + * We should never be below the walk root + */ + assert(darr_lasti(ys->node_infos) >= + ys->walk_root_level); + + /* Move on to the sibling of the list node */ + continue; + } + + /* + * From here on, we have selected a new top node_info + * list entry (either newly pushed or replacing the + * previous entry in the walk), and we are filling in + * the details. + */ + + if (list_start) { + /* + * Starting iteration of a list type or + * processing a specific entry, push the list + * node_info on stack. + */ + ni = darr_appendz(ys->node_infos); + pni = &ni[-1]; /* memory may have moved */ + ni->has_lookup_next = nn->cbs.lookup_next != + NULL; + ni->lookup_next_ok = ((!pni && ys->finish) || + pni->lookup_next_ok) && + ni->has_lookup_next; + ni->query_specific_entry = is_specific_node; + ni->niters = 0; + ni->nents = 0; + + /* this will be our predicate-less xpath */ + ys->xpath = nb_op_get_child_path(ys->xpath, sib, + ys->xpath); + } else { + /* + * Reset our xpath to the list node (i.e., + * remove the entry predicates) + */ + if (ni->query_specific_entry) { + flog_warn(EC_LIB_NB_OPERATIONAL_DATA, + "%s: unexpected state", + __func__); + } + assert(!ni->query_specific_entry); + len = strlen(sib->name) + 1; /* "/sibname" */ + if (pni) + len += pni->xpath_len; + darr_setlen(ys->xpath, len + 1); + ys->xpath[len] = 0; + ni->xpath_len = len; + } + + /* Need to get keys. */ + + if (!CHECK_FLAG(nn->flags, F_NB_NODE_KEYLESS_LIST)) { + ret = nb_callback_get_keys(nn, list_entry, + &ni->keys); + if (ret) { + darr_pop(ys->node_infos); + ret = NB_ERR_RESOURCE; + goto done; + } + } + /* + * Append predicates to xpath. + */ + len = darr_strlen(ys->xpath); + if (ni->keys.num) { + yang_get_key_preds(ys->xpath + len, sib, + &ni->keys, + darr_cap(ys->xpath) - len); + } else { + /* add a position predicate (1s based?) */ + darr_ensure_avail(ys->xpath, 10); + snprintf(ys->xpath + len, + darr_cap(ys->xpath) - len + 1, "[%u]", + ni->nents + 1); + } + darr_setlen(ys->xpath, + strlen(ys->xpath + len) + len + 1); + ni->xpath_len = darr_strlen(ys->xpath); + + /* + * Create the new list entry node. + */ + + if (!node) { + err = yang_lyd_new_list((struct lyd_node_inner *) + ni[-1] + .inner, + sib, &ni->keys, &node); + if (err) { + darr_pop(ys->node_infos); + ret = NB_ERR_RESOURCE; + goto done; + } + } + + /* + * Save the new list entry with the list node info + */ + ni->inner = node; + ni->schema = node->schema; + ni->list_entry = list_entry; + ni->niters += 1; + ni->nents += 1; + + /* Skip over the key children, they've been created. */ + sib = nb_op_sib_first(ys, sib); + continue; + + default: + /*FALLTHROUGH*/ + case LYS_ANYXML: + case LYS_ANYDATA: + /* These schema types are not currently handled */ + flog_warn(EC_LIB_NB_OPERATIONAL_DATA, + "%s: unsupported schema node type: %s", + __func__, lys_nodetype2str(sib->nodetype)); + sib = nb_op_sib_next(ys, sib); + continue; + } + } + +done: + darr_free(xpath_child); + return ret; +} + +static void nb_op_walk_continue(struct event *thread) +{ + struct nb_op_yield_state *ys = EVENT_ARG(thread); + enum nb_error ret = NB_OK; + + DEBUGD(&nb_dbg_cbs_state, "northbound oper-state: resuming %s", + ys->xpath); + + nb_op_resume_data_tree(ys); + + /* if we've popped past the walk start level we're done */ + if (darr_lasti(ys->node_infos) < ys->walk_root_level) + goto finish; + + /* otherwise we are at a resumable node */ + assert(darr_last(ys->node_infos)->has_lookup_next); + + ret = __walk(ys, true); + if (ret == NB_YIELD) { + if (nb_op_yield(ys) != NB_OK) { + if (ys->should_batch) + goto stopped; + else + goto finish; + } + return; + } +finish: + (*ys->finish)(ys_root_node(ys), ys->finish_arg, ret); +stopped: + nb_op_free_yield_state(ys, false); +} + +static void __free_siblings(struct lyd_node *this) +{ + struct lyd_node *next, *sib; + uint count = 0; + + LY_LIST_FOR_SAFE(lyd_first_sibling(this), next, sib) + { + if (lysc_is_key(sib->schema)) + continue; + if (sib == this) + continue; + lyd_free_tree(sib); + count++; + } + DEBUGD(&nb_dbg_events, "NB oper-state: deleted %u siblings", count); +} + +/* + * Trim Algorithm: + * + * Delete final lookup-next list node and subtree, leave stack slot with keys. + * + * Then walking up the stack, delete all siblings except: + * 1. right-most container or list node (must be lookup-next by design) + * 2. keys supporting existing parent list node. + * + * NOTE the topmost node on the stack will be the final lookup-nexxt list node, + * as we only yield on lookup-next list nodes. + * + */ +static void nb_op_trim_yield_state(struct nb_op_yield_state *ys) +{ + struct nb_op_node_info *ni; + int i = darr_lasti(ys->node_infos); + + assert(i >= 0); + + DEBUGD(&nb_dbg_events, "NB oper-state: start trimming: top: %d", i); + + ni = &ys->node_infos[i]; + assert(ni->has_lookup_next); + + DEBUGD(&nb_dbg_events, "NB oper-state: deleting tree at level %d", i); + __free_siblings(ni->inner); + ys_free_inner(ys, ni); + + while (--i > 0) { + DEBUGD(&nb_dbg_events, + "NB oper-state: deleting siblings at level: %d", i); + __free_siblings(ys->node_infos[i].inner); + } + DEBUGD(&nb_dbg_events, "NB oper-state: stop trimming: new top: %d", + (int)darr_lasti(ys->node_infos)); +} + +static enum nb_error nb_op_yield(struct nb_op_yield_state *ys) +{ + enum nb_error ret; + unsigned long min_us = MAX(1, NB_OP_WALK_INTERVAL_US / 50000); + struct timeval tv = { .tv_sec = 0, .tv_usec = min_us }; + + DEBUGD(&nb_dbg_events, "NB oper-state: yielding %s for %lus (should_batch %d)", + ys->xpath, tv.tv_usec, ys->should_batch); + + if (ys->should_batch) { + /* + * TODO: add ability of finish to influence the timer. + * This will allow, for example, flow control based on how long + * it takes finish to process the batch. + */ + ret = (*ys->finish)(ys_root_node(ys), ys->finish_arg, NB_YIELD); + if (ret != NB_OK) + return ret; + /* now trim out that data we just "finished" */ + nb_op_trim_yield_state(ys); + + } + + event_add_timer_tv(event_loop, nb_op_walk_continue, ys, &tv, + &ys->walk_ev); + return NB_OK; +} + +static enum nb_error nb_op_ys_init_schema_path(struct nb_op_yield_state *ys, + struct nb_node **last) +{ + struct nb_node **nb_nodes = NULL; + const struct lysc_node *sn; + struct nb_node *nblast; + char *s, *s2; + int count; + uint i; + + /* + * Get the schema node stack for the entire query string + * + * The user might pass in something like "//metric" which may resolve to + * more than one schema node ("trunks"). nb_node_find() returns a single + * node though. We should expand the functionality to get the set of + * nodes that matches the xpath (not path) query and save that set in + * the yield state. Then we should do a walk using the users query + * string over each schema trunk in the set. + */ + nblast = nb_node_find(ys->xpath); + if (!nblast) { + nb_nodes = nb_nodes_find(ys->xpath); + nblast = darr_len(nb_nodes) ? nb_nodes[0] : NULL; + darr_free(nb_nodes); + } + if (!nblast) { + flog_warn(EC_LIB_YANG_UNKNOWN_DATA_PATH, + "%s: unknown data path: %s", __func__, ys->xpath); + return NB_ERR; + } + *last = nblast; + + /* + * Create a stack of schema nodes one element per node in the query + * path, only the top (last) element may be a non-container type. + * + * NOTE: appears to be a bug in nb_node linkage where parent can be NULL, + * or I'm misunderstanding the code, in any case we use the libyang + * linkage to walk which works fine. + * + * XXX: we don't actually support choice/case yet, they are container + * types in the libyang schema, but won't be in data so our length + * checking gets messed up. + */ + for (sn = nblast->snode, count = 0; sn; count++, sn = sn->parent) + if (sn != nblast->snode) + assert(CHECK_FLAG(sn->nodetype, + LYS_CONTAINER | LYS_LIST | + LYS_CHOICE | LYS_CASE)); + /* create our arrays */ + darr_append_n(ys->schema_path, count); + darr_append_n(ys->query_tokens, count); + darr_append_nz(ys->non_specific_predicate, count); + for (sn = nblast->snode; sn; sn = sn->parent) + ys->schema_path[--count] = sn; + + /* + * Now tokenize the query string and get pointers to each token + */ + + /* Get copy of query string start after initial '/'s */ + s = ys->xpath; + while (*s && *s == '/') + s++; + ys->query_tokstr = darr_strdup(s); + s = ys->query_tokstr; + + darr_foreach_i (ys->schema_path, i) { + const char *modname = ys->schema_path[i]->module->name; + const char *name = ys->schema_path[i]->name; + int nlen = strlen(name); + int mnlen = 0; + + /* + * Technically the query_token for choice/case should probably be pointing at + * the child (leaf) rather than the parent (container), however, + * we only use these for processing list nodes so KISS. + */ + if (CHECK_FLAG(ys->schema_path[i]->nodetype, + LYS_CASE | LYS_CHOICE)) { + ys->query_tokens[i] = ys->query_tokens[i - 1]; + continue; + } + + while (true) { + s2 = strstr(s, name); + if (!s2) + goto error; + + if (s2[-1] == ':') { + mnlen = strlen(modname) + 1; + if (ys->query_tokstr > s2 - mnlen || + strncmp(s2 - mnlen, modname, mnlen - 1)) + goto error; + s2 -= mnlen; + nlen += mnlen; + } + + s = s2; + if ((i == 0 || s[-1] == '/') && + (s[nlen] == 0 || s[nlen] == '[' || s[nlen] == '/')) + break; + /* + * Advance past the incorrect match, must have been + * part of previous predicate. + */ + s += nlen; + } + + /* NUL terminate previous token and save this one */ + if (i > 0) + s[-1] = 0; + ys->query_tokens[i] = s; + s += nlen; + } + + /* NOTE: need to subtract choice/case nodes when these are supported */ + ys->query_base_level = darr_lasti(ys->schema_path); + + return NB_OK; + +error: + darr_free(ys->query_tokstr); + darr_free(ys->schema_path); + darr_free(ys->query_tokens); + darr_free(ys->non_specific_predicate); + return NB_ERR; +} + + +/** + * nb_op_walk_start() - Start walking oper-state directed by query string. + * @ys: partially initialized yield state for this walk. + * + */ +static enum nb_error nb_op_walk_start(struct nb_op_yield_state *ys) +{ + struct nb_node *nblast; + enum nb_error ret; + + /* + * Get nb_node path (stack) corresponding to the xpath query + */ + ret = nb_op_ys_init_schema_path(ys, &nblast); + if (ret != NB_OK) + return ret; + + + /* + * Get the node_info path (stack) corresponding to the uniquely + * resolvable data nodes from the beginning of the xpath query. + */ + ret = nb_op_ys_init_node_infos(ys); + if (ret != NB_OK) + return ret; + + return __walk(ys, false); +} + + +void *nb_oper_walk(const char *xpath, struct yang_translator *translator, + uint32_t flags, bool should_batch, nb_oper_data_cb cb, + void *cb_arg, nb_oper_data_finish_cb finish, void *finish_arg) +{ + struct nb_op_yield_state *ys; + enum nb_error ret; + + ys = nb_op_create_yield_state(xpath, translator, flags, should_batch, + cb, cb_arg, finish, finish_arg); + + ret = nb_op_walk_start(ys); + if (ret == NB_YIELD) { + if (nb_op_yield(ys) != NB_OK) { + if (ys->should_batch) + goto stopped; + else + goto finish; + } + return ys; + } +finish: + (void)(*ys->finish)(ys_root_node(ys), ys->finish_arg, ret); +stopped: + nb_op_free_yield_state(ys, false); + return NULL; +} + + +void nb_oper_cancel_walk(void *walk) +{ + if (walk) + nb_op_free_yield_state(walk, false); +} + + +void nb_oper_cancel_all_walks(void) +{ + struct nb_op_yield_state *ys; + + frr_each_safe (nb_op_walks, &nb_op_walks, ys) + nb_oper_cancel_walk(ys); +} + + +/* + * The old API -- remove when we've update the users to yielding. + */ +enum nb_error nb_oper_iterate_legacy(const char *xpath, + struct yang_translator *translator, + uint32_t flags, nb_oper_data_cb cb, + void *cb_arg, struct lyd_node **tree) +{ + struct nb_op_yield_state *ys; + enum nb_error ret; + + ys = nb_op_create_yield_state(xpath, translator, flags, false, cb, + cb_arg, NULL, NULL); + + ret = nb_op_walk_start(ys); + assert(ret != NB_YIELD); + + if (tree && ret == NB_OK) + *tree = ys_root_node(ys); + else { + if (ys_root_node(ys)) + yang_dnode_free(ys_root_node(ys)); + if (tree) + *tree = NULL; + } + + nb_op_free_yield_state(ys, true); + return ret; +} + +void nb_oper_init(struct event_loop *loop) +{ + event_loop = loop; + nb_op_walks_init(&nb_op_walks); +} + +void nb_oper_terminate(void) +{ + nb_oper_cancel_all_walks(); +} diff --git a/lib/northbound_sysrepo.c b/lib/northbound_sysrepo.c index 7fd4af8356..198d96e381 100644 --- a/lib/northbound_sysrepo.c +++ b/lib/northbound_sysrepo.c @@ -118,6 +118,9 @@ static int yang_data_frr2sr(struct yang_data *frr_data, sr_val_t *sr_data) sr_data->type = SR_INT64_T; sr_data->data.int64_val = yang_str2int64(frr_data->value); break; + case LY_TYPE_LEAFREF: + sr_val_set_str_data(sr_data, SR_STRING_T, frr_data->value); + break; case LY_TYPE_STRING: sr_val_set_str_data(sr_data, SR_STRING_T, frr_data->value); break; @@ -137,6 +140,11 @@ static int yang_data_frr2sr(struct yang_data *frr_data, sr_val_t *sr_data) sr_data->type = SR_UINT64_T; sr_data->data.uint64_val = yang_str2uint64(frr_data->value); break; + case LY_TYPE_UNION: + /* No way to deal with this using un-typed yang_data object */ + sr_val_set_str_data(sr_data, SR_STRING_T, frr_data->value); + break; + case LY_TYPE_UNKNOWN: default: return -1; } @@ -178,12 +186,12 @@ static int frr_sr_process_change(struct nb_config *candidate, /* Map operation values. */ switch (sr_op) { case SR_OP_CREATED: + nb_op = NB_OP_CREATE; + break; case SR_OP_MODIFIED: - if (nb_operation_is_valid(NB_OP_CREATE, nb_node->snode)) - nb_op = NB_OP_CREATE; - else if (nb_operation_is_valid(NB_OP_MODIFY, nb_node->snode)) { + if (nb_is_operation_allowed(nb_node, NB_OP_MODIFY)) nb_op = NB_OP_MODIFY; - } else + else /* Ignore list keys modifications. */ return NB_OK; break; @@ -193,7 +201,7 @@ static int frr_sr_process_change(struct nb_config *candidate, * notified about the removal of all of its leafs, even the ones * that are non-optional. We need to ignore these notifications. */ - if (!nb_operation_is_valid(NB_OP_DESTROY, nb_node->snode)) + if (!nb_is_operation_allowed(nb_node, NB_OP_DESTROY)) return NB_OK; nb_op = NB_OP_DESTROY; @@ -213,7 +221,7 @@ static int frr_sr_process_change(struct nb_config *candidate, ret = nb_candidate_edit(candidate, nb_node, nb_op, xpath, NULL, data); yang_data_free(data); - if (ret != NB_OK && ret != NB_ERR_NOT_FOUND) { + if (ret != NB_OK) { flog_warn( EC_LIB_NB_CANDIDATE_EDIT_ERROR, "%s: failed to edit candidate configuration: operation [%s] xpath [%s]", @@ -340,6 +348,8 @@ static int frr_sr_config_change_cb(sr_session_ctx_t *session, uint32_t sub_id, return frr_sr_config_change_cb_apply(session, module_name); case SR_EV_ABORT: return frr_sr_config_change_cb_abort(session, module_name); + case SR_EV_RPC: + case SR_EV_UPDATE: default: flog_err(EC_LIB_LIBSYSREPO, "%s: unexpected sysrepo event: %u", __func__, sr_ev); @@ -347,39 +357,16 @@ static int frr_sr_config_change_cb(sr_session_ctx_t *session, uint32_t sub_id, } } -static int frr_sr_state_data_iter_cb(const struct lysc_node *snode, - struct yang_translator *translator, - struct yang_data *data, void *arg) -{ - struct lyd_node *dnode = arg; - LY_ERR ly_errno; - - ly_errno = 0; - ly_errno = lyd_new_path(NULL, ly_native_ctx, data->xpath, data->value, - 0, &dnode); - if (ly_errno) { - flog_warn(EC_LIB_LIBYANG, "%s: lyd_new_path() failed", - __func__); - yang_data_free(data); - return NB_ERR; - } - - yang_data_free(data); - return NB_OK; -} - /* Callback for state retrieval. */ static int frr_sr_state_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *module_name, const char *xpath, const char *request_xpath, uint32_t request_id, struct lyd_node **parent, void *private_ctx) { - struct lyd_node *dnode; + struct lyd_node *dnode = NULL; dnode = *parent; - if (nb_oper_data_iterate(request_xpath, NULL, 0, - frr_sr_state_data_iter_cb, dnode) - != NB_OK) { + if (nb_oper_iterate_legacy(request_xpath, NULL, 0, NULL, NULL, &dnode)) { flog_warn(EC_LIB_NB_OPERATIONAL_DATA, "%s: failed to obtain operational data [xpath %s]", __func__, xpath); diff --git a/lib/ntop.c b/lib/ntop.c index 49e1b152c9..89b4d5ecdc 100644 --- a/lib/ntop.c +++ b/lib/ntop.c @@ -158,7 +158,7 @@ const char *frr_inet_ntop(int af, const void * restrict src, return dst; } -#if !defined(INET_NTOP_NO_OVERRIDE) && !defined(__APPLE__) +#if !defined(INET_NTOP_NO_OVERRIDE) /* we want to override libc inet_ntop, but make sure it shows up in backtraces * as frr_inet_ntop (to avoid confusion while debugging) */ diff --git a/lib/pbr.h b/lib/pbr.h index e8563afb3b..fe2d32a44a 100644 --- a/lib/pbr.h +++ b/lib/pbr.h @@ -1,6 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* Policy Based Routing (PBR) main header * Copyright (C) 2018 6WIND + * Portions: + * Copyright (c) 2021 The MITRE Corporation. + * Copyright (c) 2023 LabN Consulting, L.L.C. */ #ifndef _PBR_H @@ -25,30 +28,44 @@ extern "C" { * specified. */ struct pbr_filter { - uint32_t filter_bm; /* not encoded by zapi - */ -#define PBR_FILTER_SRC_IP (1 << 0) -#define PBR_FILTER_DST_IP (1 << 1) -#define PBR_FILTER_SRC_PORT (1 << 2) -#define PBR_FILTER_DST_PORT (1 << 3) -#define PBR_FILTER_FWMARK (1 << 4) -#define PBR_FILTER_PROTO (1 << 5) -#define PBR_FILTER_SRC_PORT_RANGE (1 << 6) -#define PBR_FILTER_DST_PORT_RANGE (1 << 7) -#define PBR_FILTER_DSFIELD (1 << 8) -#define PBR_FILTER_IP_PROTOCOL (1 << 9) + uint32_t filter_bm; +#define PBR_FILTER_SRC_IP (1 << 0) +#define PBR_FILTER_DST_IP (1 << 1) +#define PBR_FILTER_SRC_PORT (1 << 2) +#define PBR_FILTER_DST_PORT (1 << 3) +#define PBR_FILTER_FWMARK (1 << 4) +#define PBR_FILTER_IP_PROTOCOL (1 << 5) +#define PBR_FILTER_SRC_PORT_RANGE (1 << 6) +#define PBR_FILTER_DST_PORT_RANGE (1 << 7) +#define PBR_FILTER_DSCP (1 << 8) +#define PBR_FILTER_ECN (1 << 9) +#define PBR_FILTER_PCP (1 << 10) +#define PBR_FILTER_VLAN_FLAGS (1 << 11) +#define PBR_FILTER_VLAN_ID (1 << 12) #define PBR_DSFIELD_DSCP (0xfc) /* Upper 6 bits of DS field: DSCP */ #define PBR_DSFIELD_ECN (0x03) /* Lower 2 bits of DS field: BCN */ - /* Source and Destination IP address with masks. */ +#define PBR_PCP (0x07) /* 3-bit value 0..7 for prioritization*/ + +#define PBR_VLAN_FLAGS_NO_WILD 0 +#define PBR_VLAN_FLAGS_TAGGED (1 << 0) +#define PBR_VLAN_FLAGS_UNTAGGED (1 << 1) +#define PBR_VLAN_FLAGS_UNTAGGED_0 (1 << 2) + + /* Source and Destination IP address with masks */ struct prefix src_ip; struct prefix dst_ip; - /* Source and Destination higher-layer (TCP/UDP) port numbers. */ + /* Source and Destination layer 4 (TCP/UDP/etc.) port numbers */ uint16_t src_port; uint16_t dst_port; + /* Filter by VLAN and prioritization */ + uint8_t pcp; + uint16_t vlan_id; + uint16_t vlan_flags; + /* Filter by Differentiated Services field */ uint8_t dsfield; /* DSCP (6 bits) & ECN (2 bits) */ @@ -69,14 +86,39 @@ struct pbr_filter { * the user criteria may directly point to a table too. */ struct pbr_action { + uint32_t flags; + +#define PBR_ACTION_TABLE (1 << 0) +#define PBR_ACTION_QUEUE_ID (1 << 1) +#define PBR_ACTION_PCP (1 << 2) +#define PBR_ACTION_VLAN_ID (1 << 3) +#define PBR_ACTION_VLAN_STRIP_INNER_ANY (1 << 4) +#define PBR_ACTION_SRC_IP (1 << 5) +#define PBR_ACTION_DST_IP (1 << 6) +#define PBR_ACTION_SRC_PORT (1 << 7) +#define PBR_ACTION_DST_PORT (1 << 8) +#define PBR_ACTION_DSCP (1 << 9) +#define PBR_ACTION_ECN (1 << 10) +#define PBR_ACTION_DROP (1 << 11) /* nexthop == blackhole */ + + uint32_t table; + uint32_t queue_id; + /* VLAN */ uint8_t pcp; uint16_t vlan_id; - uint16_t vlan_flags; - uint32_t queue_id; + /* Source and Destination IP addresses */ + union sockunion src_ip; + union sockunion dst_ip; - uint32_t table; + /* Source and Destination layer 4 (TCP/UDP/etc.) port numbers */ + uint32_t src_port; + uint32_t dst_port; + + /* Differentiated Services field */ + uint8_t dscp; /* stored here already shifted to upper 6 bits */ + uint8_t ecn; /* stored here as lower 2 bits */ }; /* @@ -88,6 +130,7 @@ struct pbr_action { */ struct pbr_rule { vrf_id_t vrf_id; + uint8_t family; /* netlink: select which rule database */ uint32_t seq; uint32_t priority; @@ -95,7 +138,7 @@ struct pbr_rule { struct pbr_filter filter; struct pbr_action action; - char ifname[INTERFACE_NAMSIZ + 1]; + char ifname[IFNAMSIZ + 1]; }; /* TCP flags value shared @@ -130,8 +173,8 @@ struct pbr_rule { #define MATCH_FLOW_LABEL_SET (1 << 12) #define MATCH_FLOW_LABEL_INVERSE_SET (1 << 13) -extern int zapi_pbr_rule_encode(uint8_t cmd, struct stream *s, - struct pbr_rule *zrule); +extern int zapi_pbr_rule_encode(struct stream *s, struct pbr_rule *r); +extern bool zapi_pbr_rule_decode(struct stream *s, struct pbr_rule *r); #ifdef __cplusplus } diff --git a/lib/pid_output.c b/lib/pid_output.c index 064a7bb47f..ce1b7d1969 100644 --- a/lib/pid_output.c +++ b/lib/pid_output.c @@ -5,6 +5,7 @@ */ #include <zebra.h> +#include <sys/stat.h> #include <fcntl.h> #include <log.h> #include "lib/version.h" diff --git a/lib/plist.c b/lib/plist.c index d8ce83d219..2f5827cf43 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -336,22 +336,6 @@ prefix_list_entry_lookup(struct prefix_list *plist, struct prefix *prefix, return NULL; } -static bool -prefix_list_entry_lookup_prefix(struct prefix_list *plist, - struct prefix_list_entry *plist_entry) -{ - struct prefix_list_entry *pentry = NULL; - - for (pentry = plist->head; pentry; pentry = pentry->next) { - if (pentry == plist_entry) - continue; - if (prefix_same(&pentry->prefix, &plist_entry->prefix)) - return true; - } - - return false; -} - static void trie_walk_affected(size_t validbits, struct pltrie_table *table, uint8_t byte, struct prefix_list_entry *object, void (*fn)(struct prefix_list_entry *object, @@ -418,17 +402,54 @@ static void prefix_list_trie_del(struct prefix_list *plist, } } +/** + * Find duplicated prefix entry (same prefix but different entry) in prefix + * list. + */ +static bool prefix_list_entry_is_duplicated(struct prefix_list *list, + struct prefix_list_entry *entry) +{ + size_t depth, maxdepth = list->master->trie_depth; + uint8_t byte, *bytes = entry->prefix.u.val; + size_t validbits = entry->prefix.prefixlen; + struct pltrie_table *table = list->trie; + struct prefix_list_entry *pentry; + + for (depth = 0; validbits > PLC_BITS && depth < maxdepth - 1; depth++) { + byte = bytes[depth]; + if (!table->entries[byte].next_table) + return NULL; + + table = table->entries[byte].next_table; + validbits -= PLC_BITS; + } + + byte = bytes[depth]; + if (validbits > PLC_BITS) + pentry = table->entries[byte].final_chain; + else + pentry = table->entries[byte].up_chain; + + for (; pentry; pentry = pentry->next_best) { + if (pentry == entry) + continue; + if (prefix_same(&pentry->prefix, &entry->prefix)) + return true; + } + + return false; +} void prefix_list_entry_delete(struct prefix_list *plist, - struct prefix_list_entry *pentry, int update_list) + struct prefix_list_entry *pentry, + int update_list) { - bool duplicate = false; + bool duplicate; if (plist == NULL || pentry == NULL) return; - if (prefix_list_entry_lookup_prefix(plist, pentry)) - duplicate = true; + duplicate = prefix_list_entry_is_duplicated(plist, pentry); prefix_list_trie_del(plist, pentry); @@ -579,14 +600,13 @@ static void prefix_list_entry_add(struct prefix_list *plist, void prefix_list_entry_update_start(struct prefix_list_entry *ple) { struct prefix_list *pl = ple->pl; - bool duplicate = false; + bool duplicate; /* Not installed, nothing to do. */ if (!ple->installed) return; - if (prefix_list_entry_lookup_prefix(pl, ple)) - duplicate = true; + duplicate = prefix_list_entry_is_duplicated(pl, ple); prefix_list_trie_del(pl, ple); diff --git a/lib/prefix.c b/lib/prefix.c index b8cad910f4..f342c4c1db 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -261,7 +261,7 @@ int evpn_type5_prefix_match(const struct prefix *n, const struct prefix *p) return 0; prefixlen = evp->prefix.prefix_addr.ip_prefix_length; - np = &evp->prefix.prefix_addr.ip.ip.addr; + np = evp->prefix.prefix_addr.ip.ip.addrbytes; /* If n's prefix is longer than p's one return 0. */ if (prefixlen > p->prefixlen) @@ -355,6 +355,41 @@ void prefix_copy(union prefixptr udest, union prefixconstptr usrc) } } +bool evpn_addr_same(const struct evpn_addr *e1, const struct evpn_addr *e2) +{ + if (e1->route_type != e2->route_type) + return false; + if (e1->route_type == BGP_EVPN_AD_ROUTE) + return (!memcmp(&e1->ead_addr.esi.val, + &e2->ead_addr.esi.val, ESI_BYTES) && + e1->ead_addr.eth_tag == e2->ead_addr.eth_tag && + !ipaddr_cmp(&e1->ead_addr.ip, &e2->ead_addr.ip)); + if (e1->route_type == BGP_EVPN_MAC_IP_ROUTE) + return (e1->macip_addr.eth_tag == e2->macip_addr.eth_tag && + e1->macip_addr.ip_prefix_length + == e2->macip_addr.ip_prefix_length && + !memcmp(&e1->macip_addr.mac, + &e2->macip_addr.mac, ETH_ALEN) && + !ipaddr_cmp(&e1->macip_addr.ip, &e2->macip_addr.ip)); + if (e1->route_type == BGP_EVPN_IMET_ROUTE) + return (e1->imet_addr.eth_tag == e2->imet_addr.eth_tag && + e1->imet_addr.ip_prefix_length + == e2->imet_addr.ip_prefix_length && + !ipaddr_cmp(&e1->imet_addr.ip, &e2->imet_addr.ip)); + if (e1->route_type == BGP_EVPN_ES_ROUTE) + return (!memcmp(&e1->es_addr.esi.val, + &e2->es_addr.esi.val, ESI_BYTES) && + e1->es_addr.ip_prefix_length + == e2->es_addr.ip_prefix_length && + !ipaddr_cmp(&e1->es_addr.ip, &e2->es_addr.ip)); + if (e1->route_type == BGP_EVPN_IP_PREFIX_ROUTE) + return (e1->prefix_addr.eth_tag == e2->prefix_addr.eth_tag && + e1->prefix_addr.ip_prefix_length + == e2->prefix_addr.ip_prefix_length && + !ipaddr_cmp(&e1->prefix_addr.ip, &e2->prefix_addr.ip)); + return true; +} + /* * Return 1 if the address/netmask contained in the prefix structure * is the same, and else return 0. For this routine, 'same' requires @@ -387,8 +422,7 @@ int prefix_same(union prefixconstptr up1, union prefixconstptr up2) sizeof(struct ethaddr))) return 1; if (p1->family == AF_EVPN) - if (!memcmp(&p1->u.prefix_evpn, &p2->u.prefix_evpn, - sizeof(struct evpn_addr))) + if (evpn_addr_same(&p1->u.prefix_evpn, &p2->u.prefix_evpn)) return 1; if (p1->family == AF_FLOWSPEC) { if (p1->u.prefix_flowspec.family != diff --git a/lib/prefix.h b/lib/prefix.h index 90b792b33c..14f2695933 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -286,23 +286,25 @@ struct prefix_sg { struct in_addr grp; }; +/* clang-format off */ union prefixptr { - prefixtype(prefixptr, struct prefix, p) - prefixtype(prefixptr, struct prefix_ipv4, p4) - prefixtype(prefixptr, struct prefix_ipv6, p6) - prefixtype(prefixptr, struct prefix_evpn, evp) - prefixtype(prefixptr, struct prefix_fs, fs) - prefixtype(prefixptr, struct prefix_rd, rd) + uniontype(prefixptr, struct prefix, p) + uniontype(prefixptr, struct prefix_ipv4, p4) + uniontype(prefixptr, struct prefix_ipv6, p6) + uniontype(prefixptr, struct prefix_evpn, evp) + uniontype(prefixptr, struct prefix_fs, fs) + uniontype(prefixptr, struct prefix_rd, rd) } TRANSPARENT_UNION; union prefixconstptr { - prefixtype(prefixconstptr, const struct prefix, p) - prefixtype(prefixconstptr, const struct prefix_ipv4, p4) - prefixtype(prefixconstptr, const struct prefix_ipv6, p6) - prefixtype(prefixconstptr, const struct prefix_evpn, evp) - prefixtype(prefixconstptr, const struct prefix_fs, fs) - prefixtype(prefixconstptr, const struct prefix_rd, rd) + uniontype(prefixconstptr, const struct prefix, p) + uniontype(prefixconstptr, const struct prefix_ipv4, p4) + uniontype(prefixconstptr, const struct prefix_ipv6, p6) + uniontype(prefixconstptr, const struct prefix_evpn, evp) + uniontype(prefixconstptr, const struct prefix_fs, fs) + uniontype(prefixconstptr, const struct prefix_rd, rd) } TRANSPARENT_UNION; +/* clang-format on */ #ifndef INET_ADDRSTRLEN #define INET_ADDRSTRLEN 16 @@ -377,9 +379,9 @@ static inline void ipv4_addr_copy(struct in_addr *dst, #endif /*s6_addr32*/ /* Prototypes. */ -extern int str2family(const char *); -extern int afi2family(afi_t); -extern afi_t family2afi(int); +extern int str2family(const char *string); +extern int afi2family(afi_t afi); +extern afi_t family2afi(int family); extern const char *family2str(int family); extern const char *safi2str(safi_t safi); extern const char *afi2str(afi_t afi); @@ -409,14 +411,15 @@ extern void prefix_free(struct prefix **p); extern void prefix_free_lists(void *arg); extern const char *prefix_family_str(union prefixconstptr pu); extern int prefix_blen(union prefixconstptr pu); -extern int str2prefix(const char *, struct prefix *); +extern int str2prefix(const char *string, struct prefix *prefix); #define PREFIX2STR_BUFFER PREFIX_STRLEN extern void prefix_mcast_inet4_dump(const char *onfail, struct in_addr addr, char *buf, int buf_size); extern const char *prefix_sg2str(const struct prefix_sg *sg, char *str); -extern const char *prefix2str(union prefixconstptr, char *, int); +extern const char *prefix2str(union prefixconstptr upfx, char *buffer, + int size); extern int evpn_type5_prefix_match(const struct prefix *evpn_pfx, const struct prefix *match_pfx); extern int prefix_match(union prefixconstptr unet, union prefixconstptr upfx); @@ -427,6 +430,7 @@ extern int prefix_cmp(union prefixconstptr ua, union prefixconstptr ub); extern int prefix_common_bits(union prefixconstptr ua, union prefixconstptr ub); extern void prefix_copy(union prefixptr udst, union prefixconstptr usrc); extern void apply_mask(union prefixptr pu); +extern bool evpn_addr_same(const struct evpn_addr *e1, const struct evpn_addr *e2); #ifdef __clang_analyzer__ /* clang-SA doesn't understand transparent unions, making it think that the @@ -436,36 +440,37 @@ extern void apply_mask(union prefixptr pu); #define prefix_copy(a, b) ({ memset(a, 0, sizeof(*a)); prefix_copy(a, b); }) #endif -extern struct prefix *sockunion2hostprefix(const union sockunion *, +extern struct prefix *sockunion2hostprefix(const union sockunion *su, struct prefix *p); -extern void prefix2sockunion(const struct prefix *, union sockunion *); +extern void prefix2sockunion(const struct prefix *p, union sockunion *su); -extern int str2prefix_eth(const char *, struct prefix_eth *); +extern int str2prefix_eth(const char *string, struct prefix_eth *p); extern struct prefix_ipv4 *prefix_ipv4_new(void); extern void prefix_ipv4_free(struct prefix_ipv4 **p); -extern int str2prefix_ipv4(const char *, struct prefix_ipv4 *); -extern void apply_mask_ipv4(struct prefix_ipv4 *); +extern int str2prefix_ipv4(const char *string, struct prefix_ipv4 *p); +extern void apply_mask_ipv4(struct prefix_ipv4 *p); -extern int prefix_ipv4_any(const struct prefix_ipv4 *); -extern void apply_classful_mask_ipv4(struct prefix_ipv4 *); +extern int prefix_ipv4_any(const struct prefix_ipv4 *p); +extern void apply_classful_mask_ipv4(struct prefix_ipv4 *p); -extern uint8_t ip_masklen(struct in_addr); -extern void masklen2ip(const int, struct in_addr *); +extern uint8_t ip_masklen(struct in_addr addr); +extern void masklen2ip(const int length, struct in_addr *addr); /* given the address of a host on a network and the network mask length, * calculate the broadcast address for that network; * special treatment for /31 according to RFC3021 section 3.3 */ extern in_addr_t ipv4_broadcast_addr(in_addr_t hostaddr, int masklen); -extern int netmask_str2prefix_str(const char *, const char *, char *, size_t); +extern int netmask_str2prefix_str(const char *net_str, const char *mask_str, + char *prefix_str, size_t prefix_str_len); extern struct prefix_ipv6 *prefix_ipv6_new(void); extern void prefix_ipv6_free(struct prefix_ipv6 **p); -extern int str2prefix_ipv6(const char *, struct prefix_ipv6 *); -extern void apply_mask_ipv6(struct prefix_ipv6 *); +extern int str2prefix_ipv6(const char *str, struct prefix_ipv6 *p); +extern void apply_mask_ipv6(struct prefix_ipv6 *p); -extern int ip6_masklen(struct in6_addr); -extern void masklen2ip6(const int, struct in6_addr *); +extern int ip6_masklen(struct in6_addr netmask); +extern void masklen2ip6(const int masklen, struct in6_addr *netmask); extern int is_zero_mac(const struct ethaddr *mac); extern bool is_mcast_mac(const struct ethaddr *mac); diff --git a/lib/printf/README b/lib/printf/README index ac283642d7..46d51cec6a 100644 --- a/lib/printf/README +++ b/lib/printf/README @@ -1,6 +1,6 @@ -This is the printf implementation from FreeBSD. It was imported on 2019-05-12, -from SVN revision 347514 (but the code hadn't been touched for 2 years before -that.) +This is the printf implementation from FreeBSD. The history of this code is: +- imported on 2019-05-12, from SVN revision 347514 +- resynced on 2023-09-03, to pick up `%b` implementation Please don't reindent or otherwise mangle the files to make importing fixes easy (not that there are significant changes likely to happen...) diff --git a/lib/printf/printf-pos.c b/lib/printf/printf-pos.c index ac775bea4e..b2ba1a714d 100644 --- a/lib/printf/printf-pos.c +++ b/lib/printf/printf-pos.c @@ -355,7 +355,7 @@ reswitch: switch (ch) { goto rflag; case 'C': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'c': error = addtype(&types, (flags & LONGINT) ? T_WINT : T_INT); @@ -364,7 +364,7 @@ reswitch: switch (ch) { break; case 'D': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'd': case 'i': if ((error = addsarg(&types, flags))) @@ -408,7 +408,7 @@ reswitch: switch (ch) { #endif case 'O': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'o': if ((error = adduarg(&types, flags))) goto error; @@ -419,7 +419,7 @@ reswitch: switch (ch) { break; case 'S': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 's': error = addtype(&types, (flags & LONGINT) ? TP_WCHAR : TP_CHAR); @@ -428,7 +428,7 @@ reswitch: switch (ch) { break; case 'U': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'u': case 'X': case 'x': @@ -549,7 +549,7 @@ reswitch: switch (ch) { goto rflag; case 'C': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'c': error = addtype(&types, (flags & LONGINT) ? T_WINT : T_INT); @@ -558,7 +558,7 @@ reswitch: switch (ch) { break; case 'D': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'd': case 'i': if ((error = addsarg(&types, flags))) @@ -602,7 +602,7 @@ reswitch: switch (ch) { #endif case 'O': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'o': if ((error = adduarg(&types, flags))) goto error; @@ -613,7 +613,7 @@ reswitch: switch (ch) { break; case 'S': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 's': error = addtype(&types, (flags & LONGINT) ? TP_WCHAR : TP_CHAR); @@ -622,7 +622,7 @@ reswitch: switch (ch) { break; case 'U': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'u': case 'X': case 'x': diff --git a/lib/printf/printfcommon.h b/lib/printf/printfcommon.h index 5c45520b4c..f777be8805 100644 --- a/lib/printf/printfcommon.h +++ b/lib/printf/printfcommon.h @@ -8,7 +8,7 @@ * Chris Torek. * * Copyright (c) 2011 The FreeBSD Foundation - * All rights reserved. + * * Portions of this software were developed by David Chisnall * under sponsorship from the FreeBSD Foundation. * @@ -35,8 +35,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ /* @@ -70,7 +68,7 @@ io_print(struct io_state *iop, const CHAR * __restrict ptr, size_t len) { size_t copylen = len; - if (!iop->cb) + if (!iop->cb || !len) return 0; if (iop->avail < copylen) copylen = iop->avail; @@ -171,6 +169,13 @@ __ultoa(u_long val, CHAR *endp, int base, int octzero, const char *xdigs) } while (sval != 0); break; + case 2: + do { + *--cp = to_char(val & 1); + val >>= 1; + } while (val); + break; + case 8: do { *--cp = to_char(val & 7); @@ -221,6 +226,13 @@ __ujtoa(uintmax_t val, CHAR *endp, int base, int octzero, const char *xdigs) } while (sval != 0); break; + case 2: + do { + *--cp = to_char(val & 1); + val >>= 1; + } while (val); + break; + case 8: do { *--cp = to_char(val & 7); diff --git a/lib/printf/printflocal.h b/lib/printf/printflocal.h index bac80e801c..4b030912fe 100644 --- a/lib/printf/printflocal.h +++ b/lib/printf/printflocal.h @@ -30,8 +30,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD$ */ #include "compiler.h" diff --git a/lib/printf/vfprintf.c b/lib/printf/vfprintf.c index cc886834fa..2083642d5e 100644 --- a/lib/printf/vfprintf.c +++ b/lib/printf/vfprintf.c @@ -8,7 +8,7 @@ * Chris Torek. * * Copyright (c) 2011 The FreeBSD Foundation - * All rights reserved. + * * Portions of this software were developed by David Chisnall * under sponsorship from the FreeBSD Foundation. * @@ -340,7 +340,7 @@ reswitch: switch (ch) { if (width >= 0) goto rflag; width = -width; - /* FALLTHROUGH */ + fallthrough; case '-': flags |= LADJUST; goto rflag; @@ -419,9 +419,22 @@ reswitch: switch (ch) { case 'z': flags |= SIZET; goto rflag; + case 'B': + case 'b': + if (flags & INTMAX_SIZE) + ujval = UJARG(); + else + ulval = UARG(); + base = 2; + /* leading 0b/B only if non-zero */ + if (flags & ALT && + (flags & INTMAX_SIZE ? ujval != 0 : ulval != 0)) + ox[1] = ch; + goto nosign; + break; case 'C': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'c': #ifdef WCHAR_SUPPORT if (flags & LONGINT) { @@ -447,7 +460,7 @@ reswitch: switch (ch) { break; case 'D': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'd': case 'i': if (flags & INTMAX_SIZE) @@ -538,7 +551,7 @@ reswitch: switch (ch) { break; case 'O': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'o': if (flags & INTMAX_SIZE) ujval = UJARG(); @@ -582,7 +595,7 @@ reswitch: switch (ch) { goto nosign; case 'S': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 's': #ifdef WCHAR_SUPPORT if (flags & LONGINT) { @@ -608,7 +621,7 @@ reswitch: switch (ch) { break; case 'U': flags |= LONGINT; - /*FALLTHROUGH*/ + fallthrough; case 'u': if (flags & INTMAX_SIZE) ujval = UJARG(); diff --git a/lib/privs.c b/lib/privs.c index accd9895ff..717a2e48d6 100644 --- a/lib/privs.c +++ b/lib/privs.c @@ -6,6 +6,15 @@ * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. */ #include <zebra.h> + +#include <pwd.h> +#include <grp.h> + +#ifdef HAVE_LCAPS +#include <sys/capability.h> +#include <sys/prctl.h> +#endif /* HAVE_LCAPS */ + #include "log.h" #include "privs.h" #include "memory.h" diff --git a/lib/pullwr.c b/lib/pullwr.c index 3967eb5875..919a663db5 100644 --- a/lib/pullwr.c +++ b/lib/pullwr.c @@ -6,6 +6,8 @@ #include "zebra.h" +#include <sys/ioctl.h> + #include "pullwr.h" #include "memory.h" #include "monotime.h" diff --git a/lib/resolver.c b/lib/resolver.c index 99bf356eb3..d8245e3816 100644 --- a/lib/resolver.c +++ b/lib/resolver.c @@ -335,3 +335,8 @@ void resolver_init(struct event_loop *tm) install_element(CONFIG_NODE, &debug_resolver_cmd); install_element(ENABLE_NODE, &debug_resolver_cmd); } + +void resolver_terminate(void) +{ + ares_destroy(state.channel); +} diff --git a/lib/resolver.h b/lib/resolver.h index 87e8ecdc4a..882f960a45 100644 --- a/lib/resolver.h +++ b/lib/resolver.h @@ -23,6 +23,7 @@ struct resolver_query { }; void resolver_init(struct event_loop *tm); +void resolver_terminate(void); void resolver_resolve(struct resolver_query *query, int af, vrf_id_t vrf_id, const char *hostname, void (*cb)(struct resolver_query *, const char *, int, diff --git a/lib/route_types.txt b/lib/route_types.txt index a82273a6dc..93cbc36e97 100644 --- a/lib/route_types.txt +++ b/lib/route_types.txt @@ -49,6 +49,7 @@ ZEBRA_ROUTE_SYSTEM, system, NULL, 'X', 0, 0, 0, "Reserved", none ZEBRA_ROUTE_KERNEL, kernel, zebra, 'K', 1, 1, 1, "kernel route", zebra ZEBRA_ROUTE_CONNECT, connected, zebra, 'C', 1, 1, 1, "connected", zebra +ZEBRA_ROUTE_LOCAL, local, zebra, 'L', 1, 1, 1, "local", zebra ZEBRA_ROUTE_STATIC, static, zebra, 'S', 1, 1, 1, "static", zebra ZEBRA_ROUTE_RIP, rip, ripd, 'R', 1, 0, 1, "RIP", ripd ZEBRA_ROUTE_RIPNG, ripng, ripngd, 'R', 0, 1, 1, "RIPng", ripngd @@ -86,6 +87,7 @@ ZEBRA_ROUTE_OPENFABRIC, openfabric, fabricd, 'f', 1, 1, 1, "OpenFabric", fa ZEBRA_ROUTE_VRRP, vrrp, vrrpd, '-', 0, 0, 0, "VRRP", vrrpd ZEBRA_ROUTE_NHG, zebra, none, '-', 0, 0, 0, "Nexthop Group", none ZEBRA_ROUTE_SRTE, srte, none, '-', 0, 0, 0, "SR-TE", none +ZEBRA_ROUTE_TABLE_DIRECT, table-direct, zebra, 't', 1, 1, 1, "Table-Direct", zebra ZEBRA_ROUTE_ALL, wildcard, none, '-', 0, 0, 0, "-", none @@ -93,6 +95,7 @@ ZEBRA_ROUTE_ALL, wildcard, none, '-', 0, 0, 0, "-", no ZEBRA_ROUTE_SYSTEM, "Reserved route type, for internal use only" ZEBRA_ROUTE_KERNEL, "Kernel routes (not installed via the zebra RIB)" ZEBRA_ROUTE_CONNECT,"Connected routes (directly attached subnet or host)" +ZEBRA_ROUTE_LOCAL, "Local routes (directly attached host route)" ZEBRA_ROUTE_STATIC, "Statically configured routes" ZEBRA_ROUTE_RIP, "Routing Information Protocol (RIP)" ZEBRA_ROUTE_RIPNG, "Routing Information Protocol next-generation (IPv6) (RIPng)" @@ -116,3 +119,4 @@ ZEBRA_ROUTE_BFD, "Bidirectional Fowarding Detection (BFD)" ZEBRA_ROUTE_VRRP, "Virtual Router Redundancy Protocol (VRRP)" ZEBRA_ROUTE_OPENFABRIC, "OpenFabric Routing Protocol" ZEBRA_ROUTE_NHG, "Zebra Nexthop Groups (NHG)" +ZEBRA_ROUTE_TABLE_DIRECT, "Non-main Kernel Routing Table - Direct" diff --git a/lib/routemap.c b/lib/routemap.c index 39455841e3..e8a92cda0b 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -1070,20 +1070,17 @@ static int vty_show_route_map(struct vty *vty, const char *name, bool use_json) { struct route_map *map; json_object *json = NULL; - json_object *json_proto = NULL; - if (use_json) { + if (use_json) json = json_object_new_object(); - json_proto = json_object_new_object(); - json_object_object_add(json, frr_protonameinst, json_proto); - } else + else vty_out(vty, "%s:\n", frr_protonameinst); if (name) { map = route_map_lookup_by_name(name); if (map) { - vty_show_route_map_entry(vty, map, json_proto); + vty_show_route_map_entry(vty, map, json); } else if (!use_json) { vty_out(vty, "%s: 'route-map %s' not found\n", frr_protonameinst, name); @@ -1099,7 +1096,7 @@ static int vty_show_route_map(struct vty *vty, const char *name, bool use_json) list_sort(maplist, sort_route_map); for (ALL_LIST_ELEMENTS_RO(maplist, ln, map)) - vty_show_route_map_entry(vty, map, json_proto); + vty_show_route_map_entry(vty, map, json); list_delete(&maplist); } @@ -2554,6 +2551,9 @@ route_map_result_t route_map_apply_ext(struct route_map *map, struct prefix conv; if (recursion > RMAP_RECURSION_LIMIT) { + if (map) + map->applied++; + flog_warn( EC_LIB_RMAP_RECURSION_LIMIT, "route-map recursion limit (%d) reached, discarding route", @@ -2563,6 +2563,8 @@ route_map_result_t route_map_apply_ext(struct route_map *map, } if (map == NULL || map->head == NULL) { + if (map) + map->applied++; ret = RMAP_DENYMATCH; goto route_map_apply_end; } @@ -3140,13 +3142,13 @@ DEFPY (rmap_clear_counters, } -DEFUN (rmap_show_name, - rmap_show_name_cmd, - "show route-map [WORD] [json]", - SHOW_STR - "route-map information\n" - "route-map name\n" - JSON_STR) +DEFUN_NOSH (rmap_show_name, + rmap_show_name_cmd, + "show route-map [WORD] [json]", + SHOW_STR + "route-map information\n" + "route-map name\n" + JSON_STR) { bool uj = use_json(argc, argv); int idx = 0; diff --git a/lib/routemap.h b/lib/routemap.h index 7277744dc5..08e341221d 100644 --- a/lib/routemap.h +++ b/lib/routemap.h @@ -348,6 +348,8 @@ DECLARE_QOBJ_TYPE(route_map); (strmatch(A, "frr-bgp-route-map:comm-list-delete")) #define IS_SET_LCOMM_LIST_DEL(A) \ (strmatch(A, "frr-bgp-route-map:large-comm-list-delete")) +#define IS_SET_EXTCOMM_LIST_DEL(A) \ + (strmatch(A, "frr-bgp-route-map:extended-comm-list-delete")) #define IS_SET_LCOMMUNITY(A) \ (strmatch(A, "frr-bgp-route-map:set-large-community")) #define IS_SET_COMMUNITY(A) \ @@ -362,6 +364,9 @@ DECLARE_QOBJ_TYPE(route_map); (strmatch(A, "frr-bgp-route-map:set-extcommunity-soo")) #define IS_SET_EXTCOMMUNITY_LB(A) \ (strmatch(A, "frr-bgp-route-map:set-extcommunity-lb")) +#define IS_SET_EXTCOMMUNITY_COLOR(A) \ + (strmatch(A, "frr-bgp-route-map:set-extcommunity-color")) + #define IS_SET_AGGREGATOR(A) \ (strmatch(A, "frr-bgp-route-map:aggregator")) #define IS_SET_AS_PREPEND(A) \ diff --git a/lib/routemap_cli.c b/lib/routemap_cli.c index 0ccc78e838..f24d574278 100644 --- a/lib/routemap_cli.c +++ b/lib/routemap_cli.c @@ -90,8 +90,8 @@ DEFPY_YANG( int route_map_instance_cmp(const struct lyd_node *dnode1, const struct lyd_node *dnode2) { - uint16_t seq1 = yang_dnode_get_uint16(dnode1, "./sequence"); - uint16_t seq2 = yang_dnode_get_uint16(dnode2, "./sequence"); + uint16_t seq1 = yang_dnode_get_uint16(dnode1, "sequence"); + uint16_t seq2 = yang_dnode_get_uint16(dnode2, "sequence"); return seq1 - seq2; } @@ -100,8 +100,8 @@ void route_map_instance_show(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { const char *name = yang_dnode_get_string(dnode, "../name"); - const char *action = yang_dnode_get_string(dnode, "./action"); - const char *sequence = yang_dnode_get_string(dnode, "./sequence"); + const char *action = yang_dnode_get_string(dnode, "action"); + const char *sequence = yang_dnode_get_string(dnode, "sequence"); vty_out(vty, "route-map %s %s %s\n", name, action, sequence); @@ -526,7 +526,7 @@ DEFPY_YANG( void route_map_condition_show(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - const char *condition = yang_dnode_get_string(dnode, "./condition"); + const char *condition = yang_dnode_get_string(dnode, "condition"); const struct lyd_node *ln; const char *acl; @@ -729,6 +729,10 @@ void route_map_condition_show(struct vty *vty, const struct lyd_node *dnode, dnode, "./rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match")) vty_out(vty, " exact-match"); + if (yang_dnode_get_bool( + dnode, + "./rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-any")) + vty_out(vty, " any"); vty_out(vty, "\n"); } else if (IS_MATCH_LCOMMUNITY(condition)) { vty_out(vty, " match large-community %s", @@ -739,6 +743,10 @@ void route_map_condition_show(struct vty *vty, const struct lyd_node *dnode, dnode, "./rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-exact-match")) vty_out(vty, " exact-match"); + if (yang_dnode_get_bool( + dnode, + "./rmap-match-condition/frr-bgp-route-map:comm-list/comm-list-name-any")) + vty_out(vty, " any"); vty_out(vty, "\n"); } else if (IS_MATCH_EXTCOMMUNITY(condition)) { vty_out(vty, " match extcommunity %s\n", @@ -1042,7 +1050,7 @@ DEFUN_YANG (no_set_srte_color, void route_map_action_show(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - const char *action = yang_dnode_get_string(dnode, "./action"); + const char *action = yang_dnode_get_string(dnode, "action"); const struct lyd_node *ln; const char *acl; @@ -1094,7 +1102,7 @@ void route_map_action_show(struct vty *vty, const struct lyd_node *dnode, "./rmap-set-action/max-metric")); } else if (IS_SET_TAG(action)) { vty_out(vty, " set tag %s\n", - yang_dnode_get_string(dnode, "./rmap-set-action/tag")); + yang_dnode_get_string(dnode, "rmap-set-action/tag")); } else if (IS_SET_SR_TE_COLOR(action)) { vty_out(vty, " set sr-te color %s\n", yang_dnode_get_string(dnode, @@ -1186,6 +1194,16 @@ void route_map_action_show(struct vty *vty, const struct lyd_node *dnode, assert(acl); vty_out(vty, " set large-comm-list %s delete\n", acl); + } else if (IS_SET_EXTCOMM_LIST_DEL(action)) { + acl = NULL; + ln = yang_dnode_get(dnode, "rmap-set-action/frr-bgp-route-map:comm-list-name"); + + if (ln) + acl = yang_dnode_get_string(ln, NULL); + + assert(acl); + + vty_out(vty, " set extended-comm-list %s delete\n", acl); } else if (IS_SET_LCOMMUNITY(action)) { if (yang_dnode_exists( dnode, @@ -1259,6 +1277,11 @@ void route_map_action_show(struct vty *vty, const struct lyd_node *dnode, strlcat(str, " non-transitive", sizeof(str)); vty_out(vty, " set extcommunity bandwidth %s\n", str); + } else if (IS_SET_EXTCOMMUNITY_COLOR(action)) { + vty_out(vty, " set extcommunity color %s\n", + yang_dnode_get_string( + dnode, + "./rmap-set-action/frr-bgp-route-map:extcommunity-color")); } else if (IS_SET_EXTCOMMUNITY_NONE(action)) { if (yang_dnode_get_bool( dnode, diff --git a/lib/routemap_northbound.c b/lib/routemap_northbound.c index 4659850994..a7a77cc23b 100644 --- a/lib/routemap_northbound.c +++ b/lib/routemap_northbound.c @@ -98,7 +98,7 @@ static int lib_route_map_create(struct nb_cb_create_args *args) /* NOTHING */ break; case NB_EV_APPLY: - rm_name = yang_dnode_get_string(args->dnode, "./name"); + rm_name = yang_dnode_get_string(args->dnode, "name"); rm = route_map_get(rm_name); nb_running_set_entry(args->dnode, rm); break; @@ -167,8 +167,8 @@ static int lib_route_map_entry_create(struct nb_cb_create_args *args) /* NOTHING */ break; case NB_EV_APPLY: - sequence = yang_dnode_get_uint16(args->dnode, "./sequence"); - action = yang_dnode_get_enum(args->dnode, "./action") == 0 + sequence = yang_dnode_get_uint16(args->dnode, "sequence"); + action = yang_dnode_get_enum(args->dnode, "action") == 0 ? RMAP_PERMIT : RMAP_DENY; rm = nb_running_get_entry(args->dnode, NULL, true); @@ -353,6 +353,7 @@ static int lib_route_map_entry_exit_policy_modify(struct nb_cb_modify_args *args) { struct route_map_index *rmi; + struct route_map *map; int rm_action; int policy; @@ -363,7 +364,6 @@ lib_route_map_entry_exit_policy_modify(struct nb_cb_modify_args *args) case 0: /* permit-or-deny */ break; case 1: /* next */ - /* FALLTHROUGH */ case 2: /* goto */ rm_action = yang_dnode_get_enum(args->dnode, "../action"); @@ -382,6 +382,7 @@ lib_route_map_entry_exit_policy_modify(struct nb_cb_modify_args *args) break; case NB_EV_APPLY: rmi = nb_running_get_entry(args->dnode, NULL, true); + map = rmi->map; policy = yang_dnode_get_enum(args->dnode, NULL); switch (policy) { @@ -395,6 +396,14 @@ lib_route_map_entry_exit_policy_modify(struct nb_cb_modify_args *args) rmi->exitpolicy = RMAP_GOTO; break; } + + /* Execute event hook. */ + if (route_map_master.event_hook) { + (*route_map_master.event_hook)(map->name); + route_map_notify_dependencies(map->name, + RMAP_EVENT_CALL_ADDED); + } + break; } @@ -875,7 +884,7 @@ static int lib_route_map_entry_set_action_ipv4_address_modify( yang_dnode_get_ipv4(&ia, args->dnode, NULL); if (ia.s_addr == INADDR_ANY || !ipv4_unicast_valid(&ia)) return NB_ERR_VALIDATION; - /* FALLTHROUGH */ + return NB_OK; case NB_EV_PREPARE: case NB_EV_ABORT: return NB_OK; @@ -934,7 +943,7 @@ static int lib_route_map_entry_set_action_ipv6_address_modify( yang_dnode_get_ipv6(&i6a, args->dnode, NULL); if (!IN6_IS_ADDR_LINKLOCAL(&i6a)) return NB_ERR_VALIDATION; - /* FALLTHROUGH */ + return NB_OK; case NB_EV_PREPARE: case NB_EV_ABORT: return NB_OK; diff --git a/lib/routing_nb_config.c b/lib/routing_nb_config.c index f4fe48f5b3..2b20e6c14b 100644 --- a/lib/routing_nb_config.c +++ b/lib/routing_nb_config.c @@ -44,7 +44,7 @@ int routing_control_plane_protocols_control_plane_protocol_create( * find the vrf and store the pointer. */ if (nb_node_has_dependency(args->dnode->schema->priv)) { - vrfname = yang_dnode_get_string(args->dnode, "./vrf"); + vrfname = yang_dnode_get_string(args->dnode, "vrf"); vrf = vrf_lookup_by_name(vrfname); assert(vrf); nb_running_set_entry(args->dnode, vrf); @@ -76,7 +76,7 @@ static void vrf_to_control_plane_protocol(const struct lyd_node *dnode, { const char *vrf; - vrf = yang_dnode_get_string(dnode, "./name"); + vrf = yang_dnode_get_string(dnode, "name"); snprintf(xpath, XPATH_MAXLEN, FRR_ROUTING_KEY_XPATH_VRF, vrf); } @@ -86,7 +86,7 @@ static void control_plane_protocol_to_vrf(const struct lyd_node *dnode, { const char *vrf; - vrf = yang_dnode_get_string(dnode, "./vrf"); + vrf = yang_dnode_get_string(dnode, "vrf"); snprintf(xpath, XPATH_MAXLEN, FRR_VRF_KEY_XPATH, vrf); } diff --git a/lib/sha256.c b/lib/sha256.c index ccf260fa7b..08e08eb06b 100644 --- a/lib/sha256.c +++ b/lib/sha256.c @@ -344,7 +344,7 @@ void HMAC__SHA256_Final(unsigned char digest[32], HMAC_SHA256_CTX *ctx) void PBKDF2_SHA256(const uint8_t *passwd, size_t passwdlen, const uint8_t *salt, size_t saltlen, uint64_t c, uint8_t *buf, size_t dkLen) { - HMAC_SHA256_CTX PShctx, hctx; + HMAC_SHA256_CTX PShctx = {}, hctx; size_t i; uint8_t ivec[4]; uint8_t U[32]; diff --git a/lib/sigevent.c b/lib/sigevent.c index 3cd65eb800..06f80db4cc 100644 --- a/lib/sigevent.c +++ b/lib/sigevent.c @@ -4,6 +4,8 @@ */ #include <zebra.h> + +#include <signal.h> #include <sigevent.h> #include <log.h> #include <memory.h> diff --git a/lib/sockopt.c b/lib/sockopt.c index 0c4adb0b7c..b9b9a71167 100644 --- a/lib/sockopt.c +++ b/lib/sockopt.c @@ -10,13 +10,12 @@ #include "sockunion.h" #include "lib_errors.h" -#if (defined(__FreeBSD__) \ - && ((__FreeBSD_version >= 500022 && __FreeBSD_version < 700000) \ - || (__FreeBSD_version < 500000 && __FreeBSD_version >= 440000))) \ - || (defined(__NetBSD__) && defined(__NetBSD_Version__) \ - && __NetBSD_Version__ >= 106010000) \ - || defined(__OpenBSD__) || defined(__APPLE__) \ - || defined(__DragonFly__) || defined(__sun) +#if (defined(__FreeBSD__) && \ + ((__FreeBSD_version >= 500022 && __FreeBSD_version < 700000) || \ + (__FreeBSD_version < 500000 && __FreeBSD_version >= 440000))) || \ + (defined(__NetBSD__) && defined(__NetBSD_Version__) && \ + __NetBSD_Version__ >= 106010000) || \ + defined(__OpenBSD__) || defined(__DragonFly__) || defined(__sun) #define HAVE_BSD_STRUCT_IP_MREQ_HACK #endif @@ -24,9 +23,12 @@ void setsockopt_so_recvbuf(int sock, int size) { int orig_req = size; - while (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)) - == -1) + while (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)) == + -1) { + if (size == 0) + break; size /= 2; + } if (size != orig_req) flog_err(EC_LIB_SOCKET, @@ -38,9 +40,12 @@ void setsockopt_so_sendbuf(const int sock, int size) { int orig_req = size; - while (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)) - == -1) + while (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)) == + -1) { + if (size == 0) + break; size /= 2; + } if (size != orig_req) flog_err(EC_LIB_SOCKET, diff --git a/lib/sockunion.h b/lib/sockunion.h index e507255999..146651225c 100644 --- a/lib/sockunion.h +++ b/lib/sockunion.h @@ -7,10 +7,13 @@ #ifndef _ZEBRA_SOCKUNION_H #define _ZEBRA_SOCKUNION_H +#include "compiler.h" + #include "privs.h" #include "if.h" #include <sys/un.h> #ifdef __OpenBSD__ +#include <net/route.h> #include <netmpls/mpls.h> #endif @@ -27,8 +30,40 @@ union sockunion { struct sockaddr_mpls smpls; struct sockaddr_rtlabel rtlabel; #endif + + /* sockaddr_storage is guaranteed to be larger than the others */ + struct sockaddr_storage sa_storage; }; +/* clang-format off */ +/* for functions that want to accept any sockaddr pointer without casts */ +union sockaddrptr { + uniontype(sockaddrptr, union sockunion, su) + uniontype(sockaddrptr, struct sockaddr, sa) + uniontype(sockaddrptr, struct sockaddr_in, sin) + uniontype(sockaddrptr, struct sockaddr_in6, sin6) + uniontype(sockaddrptr, struct sockaddr_un, sun) +#ifdef __OpenBSD__ + uniontype(sockaddrptr, struct sockaddr_mpls, smpls) + uniontype(sockaddrptr, struct sockaddr_rtlabel, rtlabel) +#endif + uniontype(sockaddrptr, struct sockaddr_storage, sa_storage) +} TRANSPARENT_UNION; + +union sockaddrconstptr { + uniontype(sockaddrconstptr, const union sockunion, su) + uniontype(sockaddrconstptr, const struct sockaddr, sa) + uniontype(sockaddrconstptr, const struct sockaddr_in, sin) + uniontype(sockaddrconstptr, const struct sockaddr_in6, sin6) + uniontype(sockaddrconstptr, const struct sockaddr_un, sun) +#ifdef __OpenBSD__ + uniontype(sockaddrconstptr, const struct sockaddr_mpls, smpls) + uniontype(sockaddrconstptr, const struct sockaddr_rtlabel, rtlabel) +#endif + uniontype(sockaddrconstptr, const struct sockaddr_storage, sa_storage) +} TRANSPARENT_UNION; +/* clang-format on */ + enum connect_result { connect_error, connect_success, connect_in_progress }; /* Default address family. */ diff --git a/lib/srv6.c b/lib/srv6.c index 09835f3ea8..dceb6ab48b 100644 --- a/lib/srv6.c +++ b/lib/srv6.c @@ -108,7 +108,7 @@ const char *seg6local_context2str(char *str, size_t size, } } -static void srv6_locator_chunk_list_free(void *data) +void srv6_locator_chunk_list_free(void *data) { struct srv6_locator_chunk *chunk = data; diff --git a/lib/srv6.h b/lib/srv6.h index 0d3ee7d2ff..433c5c14fd 100644 --- a/lib/srv6.h +++ b/lib/srv6.h @@ -14,8 +14,11 @@ #include <arpa/inet.h> #include <netinet/in.h> -#define SRV6_MAX_SIDS 16 +#define SRV6_MAX_SIDS 16 +#define SRV6_MAX_SEGS 8 #define SRV6_LOCNAME_SIZE 256 +#define SRH_BASE_HEADER_LENGTH 8 +#define SRH_SEGMENT_LENGTH 16 #ifdef __cplusplus extern "C" { @@ -24,6 +27,16 @@ extern "C" { #define sid2str(sid, str, size) \ inet_ntop(AF_INET6, sid, str, size) +/* SRv6 flavors manipulation macros */ +#define CHECK_SRV6_FLV_OP(OPS,OP) ((OPS) & (1 << OP)) +#define SET_SRV6_FLV_OP(OPS,OP) (OPS) |= (1 << OP) +#define UNSET_SRV6_FLV_OP(OPS,OP) (OPS) &= ~(1 << OP) +#define RESET_SRV6_FLV_OP(OPS) (OPS) = 0 + +/* SRv6 Flavors default values */ +#define ZEBRA_DEFAULT_SEG6_LOCAL_FLV_LCBLOCK_LEN 32 +#define ZEBRA_DEFAULT_SEG6_LOCAL_FLV_LCNODE_FN_LEN 16 + enum seg6_mode_t { INLINE, ENCAP, @@ -50,15 +63,47 @@ enum seg6local_action_t { ZEBRA_SEG6_LOCAL_ACTION_END_DT46 = 16, }; +/* Flavor operations for SRv6 End* Behaviors */ +enum seg6local_flavor_op { + ZEBRA_SEG6_LOCAL_FLV_OP_UNSPEC = 0, + /* PSP Flavor as per RFC 8986 section #4.16.1 */ + ZEBRA_SEG6_LOCAL_FLV_OP_PSP = 1, + /* USP Flavor as per RFC 8986 section #4.16.2 */ + ZEBRA_SEG6_LOCAL_FLV_OP_USP = 2, + /* USD Flavor as per RFC 8986 section #4.16.3 */ + ZEBRA_SEG6_LOCAL_FLV_OP_USD = 3, + /* NEXT-C-SID Flavor as per draft-ietf-spring-srv6-srh-compression-03 + section 4.1 */ + ZEBRA_SEG6_LOCAL_FLV_OP_NEXT_CSID = 4, +}; + +#define SRV6_SEG_STRLEN 1024 + struct seg6_segs { size_t num_segs; struct in6_addr segs[256]; }; +struct seg6local_flavors_info { + /* Flavor operations */ + uint32_t flv_ops; + + /* Locator-Block length, expressed in bits */ + uint8_t lcblock_len; + /* Locator-Node Function length, expressed in bits */ + uint8_t lcnode_func_len; +}; + +struct seg6_seg_stack { + uint8_t num_segs; + struct in6_addr seg[0]; /* 1 or more segs */ +}; + struct seg6local_context { struct in_addr nh4; struct in6_addr nh6; uint32_t table; + struct seg6local_flavors_info flv; }; struct srv6_locator { @@ -115,14 +160,18 @@ struct srv6_locator_chunk { * https://www.iana.org/assignments/segment-routing/segment-routing.xhtml */ enum srv6_endpoint_behavior_codepoint { - SRV6_ENDPOINT_BEHAVIOR_RESERVED = 0x0000, - SRV6_ENDPOINT_BEHAVIOR_END_DT6 = 0x0012, - SRV6_ENDPOINT_BEHAVIOR_END_DT4 = 0x0013, - SRV6_ENDPOINT_BEHAVIOR_END_DT46 = 0x0014, - SRV6_ENDPOINT_BEHAVIOR_END_DT6_USID = 0x003E, - SRV6_ENDPOINT_BEHAVIOR_END_DT4_USID = 0x003F, - SRV6_ENDPOINT_BEHAVIOR_END_DT46_USID = 0x0040, - SRV6_ENDPOINT_BEHAVIOR_OPAQUE = 0xFFFF, + SRV6_ENDPOINT_BEHAVIOR_RESERVED = 0x0000, + SRV6_ENDPOINT_BEHAVIOR_END = 0x0001, + SRV6_ENDPOINT_BEHAVIOR_END_X = 0x0005, + SRV6_ENDPOINT_BEHAVIOR_END_DT6 = 0x0012, + SRV6_ENDPOINT_BEHAVIOR_END_DT4 = 0x0013, + SRV6_ENDPOINT_BEHAVIOR_END_DT46 = 0x0014, + SRV6_ENDPOINT_BEHAVIOR_END_NEXT_CSID = 0x002B, + SRV6_ENDPOINT_BEHAVIOR_END_X_NEXT_CSID = 0x002C, + SRV6_ENDPOINT_BEHAVIOR_END_DT6_USID = 0x003E, + SRV6_ENDPOINT_BEHAVIOR_END_DT4_USID = 0x003F, + SRV6_ENDPOINT_BEHAVIOR_END_DT46_USID = 0x0040, + SRV6_ENDPOINT_BEHAVIOR_OPAQUE = 0xFFFF, }; struct nexthop_srv6 { @@ -131,7 +180,7 @@ struct nexthop_srv6 { struct seg6local_context seg6local_ctx; /* SRv6 Headend-behaviour */ - struct in6_addr seg6_segs; + struct seg6_seg_stack *seg6_segs; }; static inline const char *seg6_mode2str(enum seg6_mode_t mode) @@ -167,12 +216,21 @@ static inline bool sid_diff( return !sid_same(a, b); } -static inline bool sid_zero( - const struct in6_addr *a) + +static inline bool sid_zero(const struct seg6_seg_stack *a) +{ + struct in6_addr zero = {}; + + assert(a); + + return sid_same(&a->seg[0], &zero); +} + +static inline bool sid_zero_ipv6(const struct in6_addr *a) { struct in6_addr zero = {}; - return sid_same(a, &zero); + return sid_same(&a[0], &zero); } static inline void *sid_copy(struct in6_addr *dst, @@ -194,6 +252,7 @@ int snprintf_seg6_segs(char *str, extern struct srv6_locator *srv6_locator_alloc(const char *name); extern struct srv6_locator_chunk *srv6_locator_chunk_alloc(void); extern void srv6_locator_free(struct srv6_locator *locator); +extern void srv6_locator_chunk_list_free(void *data); extern void srv6_locator_chunk_free(struct srv6_locator_chunk **chunk); json_object *srv6_locator_chunk_json(const struct srv6_locator_chunk *chunk); json_object *srv6_locator_json(const struct srv6_locator *loc); diff --git a/lib/subdir.am b/lib/subdir.am index c046c3c43c..4f203c0c84 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -25,6 +25,7 @@ lib_libfrr_la_SOURCES = \ lib/command_parse.y \ lib/cspf.c \ lib/csv.c \ + lib/darr.c \ lib/debug.c \ lib/defaults.c \ lib/distribute.c \ @@ -67,6 +68,7 @@ lib_libfrr_la_SOURCES = \ lib/mgmt_be_client.c \ lib/mgmt_fe_client.c \ lib/mgmt_msg.c \ + lib/mgmt_msg_native.c \ lib/mlag.c \ lib/module.c \ lib/mpls.c \ @@ -79,6 +81,7 @@ lib_libfrr_la_SOURCES = \ lib/northbound.c \ lib/northbound_cli.c \ lib/northbound_db.c \ + lib/northbound_oper.c \ lib/ntop.c \ lib/openbsd-tree.c \ lib/pid_output.c \ @@ -209,6 +212,7 @@ pkginclude_HEADERS += \ lib/compiler.h \ lib/cspf.h \ lib/csv.h \ + lib/darr.h \ lib/db.h \ lib/debug.h \ lib/defaults.h \ @@ -217,11 +221,13 @@ pkginclude_HEADERS += \ lib/filter.h \ lib/flex_algo.h \ lib/freebsd-queue.h \ + lib/frrdistance.h \ lib/frrlua.h \ lib/frrscript.h \ lib/frr_pthread.h \ lib/frratomic.h \ lib/frrcu.h \ + lib/frrsendmmsg.h \ lib/frrstr.h \ lib/graph.h \ lib/hash.h \ @@ -250,8 +256,10 @@ pkginclude_HEADERS += \ lib/memory.h \ lib/mgmt.pb-c.h \ lib/mgmt_be_client.h \ + lib/mgmt_defines.h \ lib/mgmt_fe_client.h \ lib/mgmt_msg.h \ + lib/mgmt_msg_native.h \ lib/mgmt_pb.h \ lib/module.h \ lib/monotime.h \ diff --git a/lib/systemd.c b/lib/systemd.c index 56a53a6e78..a82c376cfd 100644 --- a/lib/systemd.c +++ b/lib/systemd.c @@ -5,6 +5,7 @@ */ #include <zebra.h> +#include <sys/stat.h> #include <sys/un.h> #include "frrevent.h" diff --git a/lib/table.c b/lib/table.c index 380852b54d..3bf93894ec 100644 --- a/lib/table.c +++ b/lib/table.c @@ -334,7 +334,6 @@ void route_node_delete(struct route_node *node) struct route_node *parent; assert(node->lock == 0); - assert(node->info == NULL); if (node->l_left && node->l_right) return; diff --git a/lib/typesafe.h b/lib/typesafe.h index 8eb59c33b7..93258c5954 100644 --- a/lib/typesafe.h +++ b/lib/typesafe.h @@ -17,12 +17,14 @@ extern "C" { /* generic macros for all list-like types */ +/* to iterate using the const variants of the functions, append "_const" to + * the name of the container, e.g. "frr_each (my_list, head, item)" becomes + * "frr_each (my_list_const, head, item)" + */ + #define frr_each(prefix, head, item) \ for (item = prefix##_first(head); item; \ item = prefix##_next(head, item)) -#define frr_each_const(prefix, head, item) \ - for (item = prefix##_const_first(head); item; \ - item = prefix##_const_next(head, item)) #define frr_each_safe(prefix, head, item) \ for (typeof(prefix##_next_safe(head, NULL)) prefix##_safe = \ prefix##_next_safe(head, \ @@ -793,13 +795,16 @@ struct thash_head { uint8_t minshift, maxshift; }; -#define _HASH_SIZE(tabshift) \ - ((1U << (tabshift)) >> 1) +#define _HASH_SIZE(tabshift) \ + ({ \ + assume((tabshift) <= 31); \ + (1U << (tabshift)) >> 1; \ + }) #define HASH_SIZE(head) \ _HASH_SIZE((head).tabshift) #define _HASH_KEY(tabshift, val) \ ({ \ - assume((tabshift) >= 2 && (tabshift) <= 33); \ + assume((tabshift) >= 2 && (tabshift) <= 31); \ (val) >> (33 - (tabshift)); \ }) #define HASH_KEY(head, val) \ diff --git a/lib/vector.c b/lib/vector.c index bbea67c12f..60d383101a 100644 --- a/lib/vector.c +++ b/lib/vector.c @@ -4,6 +4,7 @@ */ #include <zebra.h> +#include <string.h> #include "vector.h" #include "memory.h" diff --git a/lib/vrf.c b/lib/vrf.c index 73f5d8ff72..48071f2bd6 100644 --- a/lib/vrf.c +++ b/lib/vrf.c @@ -5,6 +5,7 @@ */ #include <zebra.h> +#include <sys/ioctl.h> #include "if.h" #include "vrf.h" @@ -384,54 +385,80 @@ static void vrf_hash_bitmap_free(void *data) XFREE(MTYPE_VRF_BITMAP, bit); } -vrf_bitmap_t vrf_bitmap_init(void) +void vrf_bitmap_init(vrf_bitmap_t *pbmap) { - return hash_create_size(32, vrf_hash_bitmap_key, vrf_hash_bitmap_cmp, - "VRF BIT HASH"); + *pbmap = NULL; } -void vrf_bitmap_free(vrf_bitmap_t bmap) +void vrf_bitmap_free(vrf_bitmap_t *pbmap) { - struct hash *vrf_hash = bmap; + struct hash *vrf_hash; + + if (!*pbmap) + return; + + vrf_hash = *pbmap; hash_clean_and_free(&vrf_hash, vrf_hash_bitmap_free); } -void vrf_bitmap_set(vrf_bitmap_t bmap, vrf_id_t vrf_id) +void vrf_bitmap_set(vrf_bitmap_t *pbmap, vrf_id_t vrf_id) { struct vrf_bit_set lookup = { .vrf_id = vrf_id }; - struct hash *vrf_hash = bmap; + struct hash *vrf_hash; struct vrf_bit_set *bit; - if (vrf_hash == NULL || vrf_id == VRF_UNKNOWN) + if (vrf_id == VRF_UNKNOWN) return; + if (!*pbmap) + *pbmap = vrf_hash = + hash_create_size(2, vrf_hash_bitmap_key, + vrf_hash_bitmap_cmp, "VRF BIT HASH"); + else + vrf_hash = *pbmap; + bit = hash_get(vrf_hash, &lookup, vrf_hash_bitmap_alloc); bit->set = true; } -void vrf_bitmap_unset(vrf_bitmap_t bmap, vrf_id_t vrf_id) +void vrf_bitmap_unset(vrf_bitmap_t *pbmap, vrf_id_t vrf_id) { struct vrf_bit_set lookup = { .vrf_id = vrf_id }; - struct hash *vrf_hash = bmap; + struct hash *vrf_hash; struct vrf_bit_set *bit; - if (vrf_hash == NULL || vrf_id == VRF_UNKNOWN) + if (vrf_id == VRF_UNKNOWN) + return; + + /* + * If the hash is not created then unsetting is unnecessary + */ + if (!*pbmap) + return; + + vrf_hash = *pbmap; + + /* + * If we can't look it up, no need to unset it! + */ + bit = hash_lookup(vrf_hash, &lookup); + if (!bit) return; - bit = hash_get(vrf_hash, &lookup, vrf_hash_bitmap_alloc); bit->set = false; } -int vrf_bitmap_check(vrf_bitmap_t bmap, vrf_id_t vrf_id) +int vrf_bitmap_check(vrf_bitmap_t *pbmap, vrf_id_t vrf_id) { struct vrf_bit_set lookup = { .vrf_id = vrf_id }; - struct hash *vrf_hash = bmap; + struct hash *vrf_hash; struct vrf_bit_set *bit; - if (vrf_hash == NULL || vrf_id == VRF_UNKNOWN) + if (!*pbmap || vrf_id == VRF_UNKNOWN) return 0; + vrf_hash = *pbmap; bit = hash_lookup(vrf_hash, &lookup); if (bit) return bit->set; @@ -888,7 +915,7 @@ static int lib_vrf_create(struct nb_cb_create_args *args) const char *vrfname; struct vrf *vrfp; - vrfname = yang_dnode_get_string(args->dnode, "./name"); + vrfname = yang_dnode_get_string(args->dnode, "name"); if (args->event != NB_EV_APPLY) return NB_OK; @@ -961,6 +988,19 @@ static const void *lib_vrf_lookup_entry(struct nb_cb_lookup_entry_args *args) return vrf; } +static const void *lib_vrf_lookup_next(struct nb_cb_lookup_entry_args *args) +{ + const char *vrfname = args->keys->key[0]; + struct vrf vrfkey, *vrf; + + strlcpy(vrfkey.name, vrfname, sizeof(vrfkey.name)); + vrf = RB_FIND(vrf_name_head, &vrfs_by_name, &vrfkey); + if (!strcmp(vrf->name, vrfname)) + vrf = RB_NEXT(vrf_name_head, vrf); + + return vrf; +} + /* * XPath: /frr-vrf:lib/vrf/id */ @@ -998,6 +1038,7 @@ const struct frr_yang_module_info frr_vrf_info = { .get_next = lib_vrf_get_next, .get_keys = lib_vrf_get_keys, .lookup_entry = lib_vrf_lookup_entry, + .lookup_next = lib_vrf_lookup_next, }, .priority = NB_DFLT_PRIORITY - 2, }, diff --git a/lib/vrf.h b/lib/vrf.h index 956730bac6..f66a9e6b32 100644 --- a/lib/vrf.h +++ b/lib/vrf.h @@ -167,15 +167,14 @@ extern void *vrf_info_lookup(vrf_id_t); /* * VRF bit-map: maintaining flags, one bit per VRF ID */ - typedef void *vrf_bitmap_t; #define VRF_BITMAP_NULL NULL -extern vrf_bitmap_t vrf_bitmap_init(void); -extern void vrf_bitmap_free(vrf_bitmap_t); -extern void vrf_bitmap_set(vrf_bitmap_t, vrf_id_t); -extern void vrf_bitmap_unset(vrf_bitmap_t, vrf_id_t); -extern int vrf_bitmap_check(vrf_bitmap_t, vrf_id_t); +extern void vrf_bitmap_init(vrf_bitmap_t *pbmap); +extern void vrf_bitmap_free(vrf_bitmap_t *pbmap); +extern void vrf_bitmap_set(vrf_bitmap_t *pbmap, vrf_id_t vrf_id); +extern void vrf_bitmap_unset(vrf_bitmap_t *pbmap, vrf_id_t vrf_id); +extern int vrf_bitmap_check(vrf_bitmap_t *pbmap, vrf_id_t vrf_id); /* * VRF initializer/destructor diff --git a/lib/vty.c b/lib/vty.c index 4cf63508bf..5f9f0dc243 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -6,6 +6,8 @@ #include <zebra.h> +#include <fcntl.h> +#include <sys/stat.h> #include <lib/version.h> #include <sys/types.h> #include <sys/types.h> @@ -68,9 +70,8 @@ enum vty_event { struct nb_config *vty_mgmt_candidate_config; -static uintptr_t mgmt_lib_hndl; +static struct mgmt_fe_client *mgmt_fe_client; static bool mgmt_fe_connected; -static bool mgmt_candidate_ds_wr_locked; static uint64_t mgmt_client_id_next; static uint64_t mgmt_last_req_id = UINT64_MAX; @@ -129,23 +130,51 @@ char const *const mgmt_daemons[] = { }; uint mgmt_daemons_count = array_size(mgmt_daemons); -void vty_mgmt_resume_response(struct vty *vty, bool success) + +static int vty_mgmt_lock_candidate_inline(struct vty *vty) +{ + assert(!vty->mgmt_locked_candidate_ds); + (void)vty_mgmt_send_lockds_req(vty, MGMTD_DS_CANDIDATE, true, true); + return vty->mgmt_locked_candidate_ds ? 0 : -1; +} + +static int vty_mgmt_unlock_candidate_inline(struct vty *vty) +{ + assert(vty->mgmt_locked_candidate_ds); + (void)vty_mgmt_send_lockds_req(vty, MGMTD_DS_CANDIDATE, false, true); + return vty->mgmt_locked_candidate_ds ? -1 : 0; +} + +static int vty_mgmt_lock_running_inline(struct vty *vty) +{ + assert(!vty->mgmt_locked_running_ds); + (void)vty_mgmt_send_lockds_req(vty, MGMTD_DS_RUNNING, true, true); + return vty->mgmt_locked_running_ds ? 0 : -1; +} + +static int vty_mgmt_unlock_running_inline(struct vty *vty) +{ + assert(vty->mgmt_locked_running_ds); + (void)vty_mgmt_send_lockds_req(vty, MGMTD_DS_RUNNING, false, true); + return vty->mgmt_locked_running_ds ? -1 : 0; +} + +void vty_mgmt_resume_response(struct vty *vty, int ret) { uint8_t header[4] = {0, 0, 0, 0}; - int ret = CMD_SUCCESS; - if (!vty->mgmt_req_pending) { + if (!vty->mgmt_req_pending_cmd) { zlog_err( - "vty response called without setting mgmt_req_pending"); + "vty resume response called without mgmt_req_pending_cmd"); return; } - if (!success) - ret = CMD_WARNING_CONFIG_FAILED; - - vty->mgmt_req_pending = false; + MGMTD_FE_CLIENT_DBG("resuming CLI cmd after %s on vty session-id: %" PRIu64 + " with '%s'", + vty->mgmt_req_pending_cmd, vty->mgmt_session_id, + ret == CMD_SUCCESS ? "success" : "failed"); - MGMTD_FE_CLIENT_DBG("resuming: %s:", success ? "succeeded" : "failed"); + vty->mgmt_req_pending_cmd = NULL; if (vty->type != VTY_FILE) { header[3] = ret; @@ -351,11 +380,14 @@ int vty_json_no_pretty(struct vty *vty, struct json_object *json) return vty_json_helper(vty, json, JSON_C_TO_STRING_NOSLASHESCAPE); } -void vty_json_empty(struct vty *vty) +void vty_json_empty(struct vty *vty, struct json_object *json) { - json_object *json = json_object_new_object(); + json_object *jsonobj = json; + + if (!json) + jsonobj = json_object_new_object(); - vty_json(vty, json); + vty_json(vty, jsonobj); } /* Output current time to the vty. */ @@ -1533,7 +1565,7 @@ static void vty_read(struct event *thread) break; case '\r': vty->escape = VTY_CR; - /* fallthru */ + fallthrough; case '\n': vty_out(vty, "\n"); buffer_flush_available(vty->obuf, vty->wfd); @@ -1640,16 +1672,16 @@ struct vty *vty_new(void) new->max = VTY_BUFSIZ; new->pass_fd = -1; - if (mgmt_lib_hndl) { + if (mgmt_fe_client) { if (!mgmt_client_id_next) mgmt_client_id_next++; new->mgmt_client_id = mgmt_client_id_next++; - if (mgmt_fe_create_client_session( - mgmt_lib_hndl, new->mgmt_client_id, - (uintptr_t) new) != MGMTD_SUCCESS) - zlog_err( - "Failed to open a MGMTD Frontend session for VTY session %p!!", - new); + new->mgmt_session_id = 0; + mgmt_fe_create_client_session( + mgmt_fe_client, new->mgmt_client_id, (uintptr_t) new); + /* we short-circuit create the session so it must be set now */ + assertf(new->mgmt_session_id != 0, + "Failed to create client session for VTY"); } return new; @@ -2198,10 +2230,11 @@ bool mgmt_vty_read_configs(void) vty->node = CONFIG_NODE; vty->config = true; vty->pending_allowed = true; + vty->candidate_config = vty_shared_candidate_config; - vty->mgmt_locked_candidate_ds = true; - mgmt_candidate_ds_wr_locked = true; + vty_mgmt_lock_candidate_inline(vty); + vty_mgmt_lock_running_inline(vty); for (index = 0; index < array_size(mgmt_daemons); index++) { snprintf(path, sizeof(path), "%s/%s.conf", frr_sysconfdir, @@ -2217,6 +2250,8 @@ bool mgmt_vty_read_configs(void) line_num = 0; (void)config_from_file(vty, confp, &line_num); count++; + + fclose(confp); } snprintf(path, sizeof(path), "%s/mgmtd.conf", frr_sysconfdir); @@ -2240,12 +2275,19 @@ bool mgmt_vty_read_configs(void) line_num = 0; (void)config_from_file(vty, confp, &line_num); count++; + + fclose(confp); } - vty->pending_allowed = false; + /* Conditionally unlock as the config file may have "exit"d early which + * would then have unlocked things. + */ + if (vty->mgmt_locked_running_ds) + vty_mgmt_unlock_running_inline(vty); + if (vty->mgmt_locked_candidate_ds) + vty_mgmt_unlock_candidate_inline(vty); - vty->mgmt_locked_candidate_ds = false; - mgmt_candidate_ds_wr_locked = false; + vty->pending_allowed = false; if (!count) vty_close(vty); @@ -2270,6 +2312,19 @@ static void vtysh_read(struct event *thread) sock = EVENT_FD(thread); vty = EVENT_ARG(thread); + /* + * This code looks like it can read multiple commands from the `buf` + * value returned by read(); however, it cannot in some cases. + * + * There are multiple paths out of the "copying to vty->buf" loop, which + * lose any content not yet copied from the stack `buf`, `passfd`, + * `CMD_SUSPEND` and finally if a front-end for mgmtd (generally this + * would be mgmtd itself). So these code paths are counting on vtysh not + * sending us more than 1 command line before waiting on the reply to + * that command. + */ + assert(vty->type == VTY_SHELL_SERV); + if ((nbytes = read(sock, buf, VTY_READ_BUFSIZ)) <= 0) { if (nbytes < 0) { if (ERRNO_IO_RETRY(errno)) { @@ -2313,8 +2368,7 @@ static void vtysh_read(struct event *thread) printf("result: %d\n", ret); printf("vtysh node: %d\n", vty->node); #endif /* VTYSH_DEBUG */ - - if (vty->pass_fd != -1) { + if (vty->pass_fd >= 0) { memset(vty->pass_fd_status, 0, 4); vty->pass_fd_status[3] = ret; vty->status = VTY_PASSFD; @@ -2332,6 +2386,13 @@ static void vtysh_read(struct event *thread) * => skip vty_event(VTYSH_READ, vty)! */ return; + } else { + assertf(vty->status != VTY_PASSFD, + "%p address=%s passfd=%d", vty, + vty->address, vty->pass_fd); + + /* normalize other invalid values */ + vty->pass_fd = -1; } /* hack for asynchronous "write integrated" @@ -2344,8 +2405,13 @@ static void vtysh_read(struct event *thread) /* with new infra we need to stop response till * we get response through callback. */ - if (vty->mgmt_req_pending) + if (vty->mgmt_req_pending_cmd) { + MGMTD_FE_CLIENT_DBG( + "postpone CLI response pending mgmtd %s on vty session-id %" PRIu64, + vty->mgmt_req_pending_cmd, + vty->mgmt_session_id); return; + } /* warning: watchfrr hardcodes this result write */ @@ -2419,15 +2485,24 @@ void vty_close(struct vty *vty) vty->status = VTY_CLOSE; - if (mgmt_lib_hndl && vty->mgmt_session_id) { - mgmt_fe_destroy_client_session(mgmt_lib_hndl, - vty->mgmt_client_id); - vty->mgmt_session_id = 0; - } + /* + * If we reach here with pending config to commit we will be losing it + * so warn the user. + */ + if (vty->mgmt_num_pending_setcfg) + MGMTD_FE_CLIENT_ERR( + "vty closed, uncommitted config will be lost."); /* Drop out of configure / transaction if needed. */ vty_config_exit(vty); + if (mgmt_fe_client && vty->mgmt_session_id) { + MGMTD_FE_CLIENT_DBG("closing vty session"); + mgmt_fe_destroy_client_session(mgmt_fe_client, + vty->mgmt_client_id); + vty->mgmt_session_id = 0; + } + /* Cancel threads.*/ EVENT_OFF(vty->t_read); EVENT_OFF(vty->t_write); @@ -2786,28 +2861,41 @@ bool vty_read_config(struct nb_config *config, const char *config_file, return true; } -int vty_config_enter(struct vty *vty, bool private_config, bool exclusive) +int vty_config_enter(struct vty *vty, bool private_config, bool exclusive, + bool file_lock) { - if (exclusive && nb_running_lock(NB_CLIENT_CLI, vty)) { + if (exclusive && !vty_mgmt_fe_enabled() && + nb_running_lock(NB_CLIENT_CLI, vty)) { vty_out(vty, "%% Configuration is locked by other client\n"); return CMD_WARNING; } - if (vty_mgmt_fe_enabled()) { - if (!mgmt_candidate_ds_wr_locked) { - if (vty_mgmt_send_lockds_req(vty, MGMTD_DS_CANDIDATE, - true) != 0) { - vty_out(vty, "Not able to lock candidate DS\n"); - return CMD_WARNING; - } - } else { + /* + * We only need to do a lock when reading a config file as we will be + * sending a batch of setcfg changes followed by a single commit + * message. For user interactive mode we are doing implicit commits + * those will obtain the lock (or not) when they try and commit. + */ + if (file_lock && vty_mgmt_fe_enabled() && !private_config) { + if (vty_mgmt_lock_candidate_inline(vty)) { vty_out(vty, - "Candidate DS already locked by different session\n"); - return CMD_WARNING; + "%% Can't enter config; candidate datastore locked by another session\n"); + return CMD_WARNING_CONFIG_FAILED; + } + if (vty_mgmt_lock_running_inline(vty)) { + vty_out(vty, + "%% Can't enter config; running datastore locked by another session\n"); + vty_mgmt_unlock_candidate_inline(vty); + return CMD_WARNING_CONFIG_FAILED; } + assert(vty->mgmt_locked_candidate_ds); + assert(vty->mgmt_locked_running_ds); - vty->mgmt_locked_candidate_ds = true; - mgmt_candidate_ds_wr_locked = true; + /* + * As datastores are locked explicitly, we don't need implicit + * commits and should allow pending changes. + */ + vty->pending_allowed = true; } vty->node = CONFIG_NODE; @@ -2820,23 +2908,24 @@ int vty_config_enter(struct vty *vty, bool private_config, bool exclusive) vty->candidate_config_base = nb_config_dup(running_config); vty_out(vty, "Warning: uncommitted changes will be discarded on exit.\n\n"); - } else { - /* - * NOTE: On the MGMTD daemon we point the VTY candidate DS to - * the global MGMTD candidate DS. Else we point to the VTY - * Shared Candidate Config. - */ - vty->candidate_config = vty_mgmt_candidate_config - ? vty_mgmt_candidate_config - : vty_shared_candidate_config; - if (frr_get_cli_mode() == FRR_CLI_TRANSACTIONAL) - vty->candidate_config_base = - nb_config_dup(running_config); + return CMD_SUCCESS; } + /* + * NOTE: On the MGMTD daemon we point the VTY candidate DS to + * the global MGMTD candidate DS. Else we point to the VTY + * Shared Candidate Config. + */ + vty->candidate_config = vty_mgmt_candidate_config + ? vty_mgmt_candidate_config + : vty_shared_candidate_config; + if (frr_get_cli_mode() == FRR_CLI_TRANSACTIONAL) + vty->candidate_config_base = nb_config_dup(running_config); + return CMD_SUCCESS; } + void vty_config_exit(struct vty *vty) { enum node_type node = vty->node; @@ -2861,21 +2950,15 @@ int vty_config_node_exit(struct vty *vty) { vty->xpath_index = 0; - /* - * If we are not reading config file and we are mgmtd FE and we are - * locked then unlock. - */ - if (vty->type != VTY_FILE && vty_mgmt_fe_enabled() && - mgmt_candidate_ds_wr_locked && vty->mgmt_locked_candidate_ds) { - if (vty_mgmt_send_lockds_req(vty, MGMTD_DS_CANDIDATE, false) != - 0) { - vty_out(vty, "Not able to unlock candidate DS\n"); - return CMD_WARNING; - } + /* TODO: could we check for un-commited changes here? */ - vty->mgmt_locked_candidate_ds = false; - mgmt_candidate_ds_wr_locked = false; - } + vty->pending_allowed = false; + + if (vty->mgmt_locked_running_ds) + vty_mgmt_unlock_running_inline(vty); + + if (vty->mgmt_locked_candidate_ds) + vty_mgmt_unlock_candidate_inline(vty); /* Perform any pending commits. */ (void)nb_cli_pending_commit_check(vty); @@ -3391,8 +3474,8 @@ void vty_init_vtysh(void) * functionality linked into it. This design choice was taken for efficiency. */ -static void vty_mgmt_server_connected(uintptr_t lib_hndl, uintptr_t usr_data, - bool connected) +static void vty_mgmt_server_connected(struct mgmt_fe_client *client, + uintptr_t usr_data, bool connected) { MGMTD_FE_CLIENT_DBG("Got %sconnected %s MGMTD Frontend Server", !connected ? "dis: " : "", @@ -3403,7 +3486,7 @@ static void vty_mgmt_server_connected(uintptr_t lib_hndl, uintptr_t usr_data, * The fe client library will delete all session on disconnect before * calling us. */ - assert(mgmt_fe_client_session_count(lib_hndl) == 0); + assert(mgmt_fe_client_session_count(client) == 0); mgmt_fe_connected = connected; @@ -3417,10 +3500,10 @@ static void vty_mgmt_server_connected(uintptr_t lib_hndl, uintptr_t usr_data, /* * A session has successfully been created for a vty. */ -static void vty_mgmt_session_notify(uintptr_t lib_hndl, uintptr_t usr_data, - uint64_t client_id, bool create, - bool success, uintptr_t session_id, - uintptr_t session_ctx) +static void vty_mgmt_session_notify(struct mgmt_fe_client *client, + uintptr_t usr_data, uint64_t client_id, + bool create, bool success, + uintptr_t session_id, uintptr_t session_ctx) { struct vty *vty; @@ -3440,38 +3523,50 @@ static void vty_mgmt_session_notify(uintptr_t lib_hndl, uintptr_t usr_data, vty->mgmt_session_id = session_id; } else { vty->mgmt_session_id = 0; - vty_close(vty); + /* We may come here by way of vty_close() and short-circuits */ + if (vty->status != VTY_CLOSE) + vty_close(vty); } } -static void vty_mgmt_ds_lock_notified(uintptr_t lib_hndl, uintptr_t usr_data, - uint64_t client_id, uintptr_t session_id, +static void vty_mgmt_ds_lock_notified(struct mgmt_fe_client *client, + uintptr_t usr_data, uint64_t client_id, + uintptr_t session_id, uintptr_t session_ctx, uint64_t req_id, bool lock_ds, bool success, Mgmtd__DatastoreId ds_id, char *errmsg_if_any) { struct vty *vty; + bool is_short_circuit = mgmt_fe_client_current_msg_short_circuit(client); vty = (struct vty *)session_ctx; - if (!success) { - zlog_err("%socking for DS %u failed, Err: '%s'", - lock_ds ? "L" : "Unl", ds_id, errmsg_if_any); - vty_out(vty, "ERROR: %socking for DS %u failed, Err: '%s'\n", - lock_ds ? "L" : "Unl", ds_id, errmsg_if_any); - } else { + assert(ds_id == MGMTD_DS_CANDIDATE || ds_id == MGMTD_DS_RUNNING); + if (!success) + zlog_err("%socking for DS %u failed, Err: '%s' vty %p", + lock_ds ? "L" : "Unl", ds_id, errmsg_if_any, vty); + else { MGMTD_FE_CLIENT_DBG("%socked DS %u successfully", lock_ds ? "L" : "Unl", ds_id); + if (ds_id == MGMTD_DS_CANDIDATE) + vty->mgmt_locked_candidate_ds = lock_ds; + else + vty->mgmt_locked_running_ds = lock_ds; } - vty_mgmt_resume_response(vty, success); + if (!is_short_circuit && vty->mgmt_req_pending_cmd) { + assert(!strcmp(vty->mgmt_req_pending_cmd, "MESSAGE_LOCKDS_REQ")); + vty_mgmt_resume_response(vty, + success ? CMD_SUCCESS : CMD_WARNING); + } } static void vty_mgmt_set_config_result_notified( - uintptr_t lib_hndl, uintptr_t usr_data, uint64_t client_id, + struct mgmt_fe_client *client, uintptr_t usr_data, uint64_t client_id, uintptr_t session_id, uintptr_t session_ctx, uint64_t req_id, - bool success, Mgmtd__DatastoreId ds_id, char *errmsg_if_any) + bool success, Mgmtd__DatastoreId ds_id, bool implicit_commit, + char *errmsg_if_any) { struct vty *vty; @@ -3489,11 +3584,18 @@ static void vty_mgmt_set_config_result_notified( client_id, req_id); } - vty_mgmt_resume_response(vty, success); + if (implicit_commit) { + /* In this case the changes have been applied, we are done */ + vty_mgmt_unlock_candidate_inline(vty); + vty_mgmt_unlock_running_inline(vty); + } + + vty_mgmt_resume_response(vty, success ? CMD_SUCCESS + : CMD_WARNING_CONFIG_FAILED); } static void vty_mgmt_commit_config_result_notified( - uintptr_t lib_hndl, uintptr_t usr_data, uint64_t client_id, + struct mgmt_fe_client *client, uintptr_t usr_data, uint64_t client_id, uintptr_t session_id, uintptr_t session_ctx, uint64_t req_id, bool success, Mgmtd__DatastoreId src_ds_id, Mgmtd__DatastoreId dst_ds_id, bool validate_only, char *errmsg_if_any) @@ -3517,11 +3619,12 @@ static void vty_mgmt_commit_config_result_notified( vty_out(vty, "MGMTD: %s\n", errmsg_if_any); } - vty_mgmt_resume_response(vty, success); + vty_mgmt_resume_response(vty, success ? CMD_SUCCESS + : CMD_WARNING_CONFIG_FAILED); } -static enum mgmt_result vty_mgmt_get_data_result_notified( - uintptr_t lib_hndl, uintptr_t usr_data, uint64_t client_id, +static int vty_mgmt_get_data_result_notified( + struct mgmt_fe_client *client, uintptr_t usr_data, uint64_t client_id, uintptr_t session_id, uintptr_t session_ctx, uint64_t req_id, bool success, Mgmtd__DatastoreId ds_id, Mgmtd__YangData **yang_data, size_t num_data, int next_key, char *errmsg_if_any) @@ -3537,8 +3640,8 @@ static enum mgmt_result vty_mgmt_get_data_result_notified( client_id, errmsg_if_any ? errmsg_if_any : "Unknown"); vty_out(vty, "ERROR: GET_DATA request failed, Error: %s\n", errmsg_if_any ? errmsg_if_any : "Unknown"); - vty_mgmt_resume_response(vty, success); - return MGMTD_INTERNAL_ERROR; + vty_mgmt_resume_response(vty, CMD_WARNING); + return -1; } MGMTD_FE_CLIENT_DBG("GET_DATA request succeeded, client 0x%" PRIx64 @@ -3556,38 +3659,240 @@ static enum mgmt_result vty_mgmt_get_data_result_notified( } if (next_key < 0) { vty_out(vty, "]\n"); - vty_mgmt_resume_response(vty, success); + vty_mgmt_resume_response(vty, CMD_SUCCESS); } - return MGMTD_SUCCESS; + return 0; +} + +static ssize_t vty_mgmt_libyang_print(void *user_data, const void *buf, + size_t count) +{ + struct vty *vty = user_data; + + vty_out(vty, "%.*s", (int)count, (const char *)buf); + return count; +} + +static void vty_out_yang_error(struct vty *vty, LYD_FORMAT format, + struct ly_err_item *ei) +{ + bool have_apptag = ei->apptag && ei->apptag[0] != 0; + bool have_path = ei->path && ei->path[0] != 0; + bool have_msg = ei->msg && ei->msg[0] != 0; + const char *severity = NULL; + const char *evalid = NULL; + const char *ecode = NULL; + LY_ERR err = ei->no; + + if (ei->level == LY_LLERR) + severity = "error"; + else if (ei->level == LY_LLWRN) + severity = "warning"; + + ecode = yang_ly_strerrcode(err); + if (err == LY_EVALID && ei->vecode != LYVE_SUCCESS) + evalid = yang_ly_strvecode(ei->vecode); + + switch (format) { + case LYD_XML: + vty_out(vty, + "<rpc-error xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"); + vty_out(vty, "<error-type>application</error-type>"); + if (severity) + vty_out(vty, "<error-severity>%s</error-severity>", + severity); + if (ecode) + vty_out(vty, "<error-code>%s</error-code>", ecode); + if (evalid) + vty_out(vty, "<error-validation>%s</error-validation>\n", + evalid); + if (have_path) + vty_out(vty, "<error-path>%s</error-path>\n", ei->path); + if (have_apptag) + vty_out(vty, "<error-app-tag>%s</error-app-tag>\n", + ei->apptag); + if (have_msg) + vty_out(vty, "<error-message>%s</error-message>\n", + ei->msg); + + vty_out(vty, "</rpc-error>"); + break; + case LYD_JSON: + vty_out(vty, "{ \"error-type\": \"application\""); + if (severity) + vty_out(vty, ", \"error-severity\": \"%s\"", severity); + if (ecode) + vty_out(vty, ", \"error-code\": \"%s\"", ecode); + if (evalid) + vty_out(vty, ", \"error-validation\": \"%s\"", evalid); + if (have_path) + vty_out(vty, ", \"error-path\": \"%s\"", ei->path); + if (have_apptag) + vty_out(vty, ", \"error-app-tag\": \"%s\"", ei->apptag); + if (have_msg) + vty_out(vty, ", \"error-message\": \"%s\"", ei->msg); + + vty_out(vty, "}"); + break; + case LYD_UNKNOWN: + case LYD_LYB: + default: + vty_out(vty, "%% error"); + if (severity) + vty_out(vty, " severity: %s", severity); + if (evalid) + vty_out(vty, " invalid: %s", evalid); + if (have_path) + vty_out(vty, " path: %s", ei->path); + if (have_apptag) + vty_out(vty, " app-tag: %s", ei->apptag); + if (have_msg) + vty_out(vty, " msg: %s", ei->msg); + break; + } } -static struct mgmt_fe_client_params client_params = { +static uint vty_out_yang_errors(struct vty *vty, LYD_FORMAT format) +{ + struct ly_err_item *ei = ly_err_first(ly_native_ctx); + uint count; + + if (!ei) + return 0; + + if (format == LYD_JSON) + vty_out(vty, "\"ietf-restconf:errors\": [ "); + + for (count = 0; ei; count++, ei = ei->next) { + if (count) + vty_out(vty, ", "); + vty_out_yang_error(vty, format, ei); + } + + if (format == LYD_JSON) + vty_out(vty, " ]"); + + ly_err_clean(ly_native_ctx, NULL); + + return count; +} + + +static int vty_mgmt_get_tree_result_notified( + struct mgmt_fe_client *client, uintptr_t user_data, uint64_t client_id, + uint64_t session_id, uintptr_t session_ctx, uint64_t req_id, + Mgmtd__DatastoreId ds_id, LYD_FORMAT result_type, void *result, + size_t len, int partial_error) +{ + struct vty *vty; + struct lyd_node *dnode; + int ret = CMD_SUCCESS; + LY_ERR err; + + vty = (struct vty *)session_ctx; + + MGMTD_FE_CLIENT_DBG("GET_TREE request %ssucceeded, client 0x%" PRIx64 + " req-id %" PRIu64, + partial_error ? "partially " : "", client_id, + req_id); + + assert(result_type == LYD_LYB || + result_type == vty->mgmt_req_pending_data); + + if (vty->mgmt_req_pending_data == LYD_XML && partial_error) + vty_out(vty, + "<!-- some errors occurred gathering results -->\n"); + + if (result_type == LYD_LYB) { + /* + * parse binary into tree and print in the specified format + */ + result_type = vty->mgmt_req_pending_data; + + err = lyd_parse_data_mem(ly_native_ctx, result, LYD_LYB, 0, 0, + &dnode); + if (!err) + err = lyd_print_clb(vty_mgmt_libyang_print, vty, dnode, + result_type, LYD_PRINT_WITHSIBLINGS); + lyd_free_all(dnode); + + if (vty_out_yang_errors(vty, result_type) || err) + ret = CMD_WARNING; + } else { + /* + * Print the in-format result + */ + assert(result_type == LYD_XML || result_type == LYD_JSON); + vty_out(vty, "%.*s\n", (int)len - 1, (const char *)result); + } + + vty_mgmt_resume_response(vty, ret); + + return 0; +} + +static int vty_mgmt_error_notified(struct mgmt_fe_client *client, + uintptr_t user_data, uint64_t client_id, + uint64_t session_id, uintptr_t session_ctx, + uint64_t req_id, int error, + const char *errstr) +{ + struct vty *vty = (struct vty *)session_ctx; + const char *cname = mgmt_fe_client_name(client); + + if (!vty->mgmt_req_pending_cmd) { + MGMTD_FE_CLIENT_DBG("Erorr with no pending command: %d returned for client %s 0x%" PRIx64 + " session-id %" PRIu64 " req-id %" PRIu64 + "error-str %s", + error, cname, client_id, session_id, req_id, + errstr); + vty_out(vty, + "%% Error %d from MGMTD for %s with no pending command: %s\n", + error, cname, errstr); + return CMD_WARNING; + } + + MGMTD_FE_CLIENT_DBG("Erorr %d returned for client %s 0x%" PRIx64 + " session-id %" PRIu64 " req-id %" PRIu64 + "error-str %s", + error, cname, client_id, session_id, req_id, errstr); + + vty_out(vty, "%% %s (for %s, client %s)\n", errstr, + vty->mgmt_req_pending_cmd, cname); + + vty_mgmt_resume_response(vty, error ? CMD_WARNING : CMD_SUCCESS); + + return 0; +} + +static struct mgmt_fe_client_cbs mgmt_cbs = { .client_connect_notify = vty_mgmt_server_connected, .client_session_notify = vty_mgmt_session_notify, .lock_ds_notify = vty_mgmt_ds_lock_notified, .set_config_notify = vty_mgmt_set_config_result_notified, .commit_config_notify = vty_mgmt_commit_config_result_notified, .get_data_notify = vty_mgmt_get_data_result_notified, + .get_tree_notify = vty_mgmt_get_tree_result_notified, + .error_notify = vty_mgmt_error_notified, + }; void vty_init_mgmt_fe(void) { - if (!vty_master) { - zlog_err("Always call vty_mgmt_init_fe() after vty_init()!!"); - return; - } + char name[40]; - assert(!mgmt_lib_hndl); - snprintf(client_params.name, sizeof(client_params.name), "%s-%lld", - frr_get_progname(), (long long)getpid()); - mgmt_lib_hndl = mgmt_fe_client_lib_init(&client_params, vty_master); - assert(mgmt_lib_hndl); + assert(vty_master); + assert(!mgmt_fe_client); + snprintf(name, sizeof(name), "vty-%s-%ld", frr_get_progname(), + (long)getpid()); + mgmt_fe_client = mgmt_fe_client_create(name, &mgmt_cbs, 0, vty_master); + assert(mgmt_fe_client); } bool vty_mgmt_fe_enabled(void) { - return mgmt_lib_hndl && mgmt_fe_connected; + return mgmt_fe_client && mgmt_fe_connected; } bool vty_mgmt_should_process_cli_apply_changes(struct vty *vty) @@ -3596,37 +3901,37 @@ bool vty_mgmt_should_process_cli_apply_changes(struct vty *vty) } int vty_mgmt_send_lockds_req(struct vty *vty, Mgmtd__DatastoreId ds_id, - bool lock) + bool lock, bool scok) { - enum mgmt_result ret; + assert(mgmt_fe_client); + assert(vty->mgmt_session_id); - if (mgmt_lib_hndl && vty->mgmt_session_id) { - vty->mgmt_req_id++; - ret = mgmt_fe_lock_ds(mgmt_lib_hndl, vty->mgmt_session_id, - vty->mgmt_req_id, ds_id, lock); - if (ret != MGMTD_SUCCESS) { - zlog_err("Failed sending %sLOCK-DS-REQ req-id %" PRIu64, - lock ? "" : "UN", vty->mgmt_req_id); - vty_out(vty, "Failed to send %sLOCK-DS-REQ to MGMTD!\n", - lock ? "" : "UN"); - return -1; - } - - vty->mgmt_req_pending = true; + vty->mgmt_req_id++; + if (mgmt_fe_send_lockds_req(mgmt_fe_client, vty->mgmt_session_id, + vty->mgmt_req_id, ds_id, lock, scok)) { + zlog_err("Failed sending %sLOCK-DS-REQ req-id %" PRIu64, + lock ? "" : "UN", vty->mgmt_req_id); + vty_out(vty, "Failed to send %sLOCK-DS-REQ to MGMTD!\n", + lock ? "" : "UN"); + return -1; } + if (!scok) + vty->mgmt_req_pending_cmd = "MESSAGE_LOCKDS_REQ"; + return 0; } -int vty_mgmt_send_config_data(struct vty *vty) +int vty_mgmt_send_config_data(struct vty *vty, const char *xpath_base, + bool implicit_commit) { Mgmtd__YangDataValue value[VTY_MAXCFGCHANGES]; Mgmtd__YangData cfg_data[VTY_MAXCFGCHANGES]; Mgmtd__YangCfgDataReq cfg_req[VTY_MAXCFGCHANGES]; Mgmtd__YangCfgDataReq *cfgreq[VTY_MAXCFGCHANGES] = {0}; + char xpath[VTY_MAXCFGCHANGES][XPATH_MAXLEN]; + char *change_xpath; size_t indx; - int cnt; - bool implicit_commit = false; if (vty->type == VTY_FILE) { /* @@ -3634,118 +3939,142 @@ int vty_mgmt_send_config_data(struct vty *vty) * changes until we are done reading the file and have modified * the local candidate DS. */ - assert(vty->mgmt_locked_candidate_ds); /* no-one else should be sending data right now */ assert(!vty->mgmt_num_pending_setcfg); return 0; } + /* If we are FE client and we have a vty then we have a session */ + assert(mgmt_fe_client && vty->mgmt_client_id && vty->mgmt_session_id); - if (mgmt_lib_hndl && vty->mgmt_client_id && !vty->mgmt_session_id) { - /* - * We are connected to mgmtd but we do not yet have an - * established session. this means we need to send any changes - * made during this "down-time" to all backend clients when this - * FE client finishes coming up. - */ - MGMTD_FE_CLIENT_DBG("skipping as no session exists"); + if (!vty->num_cfg_changes) return 0; - } - if (mgmt_lib_hndl && vty->mgmt_session_id) { - cnt = 0; - for (indx = 0; indx < vty->num_cfg_changes; indx++) { - mgmt_yang_data_init(&cfg_data[cnt]); + /* grab the candidate and running lock prior to sending implicit commit + * command + */ + if (implicit_commit) { + if (vty_mgmt_lock_candidate_inline(vty)) { + vty_out(vty, + "%% command failed, could not lock candidate DS\n"); + return -1; + } else if (vty_mgmt_lock_running_inline(vty)) { + vty_out(vty, + "%% command failed, could not lock running DS\n"); + vty_mgmt_unlock_candidate_inline(vty); + return -1; + } + } - if (vty->cfg_changes[indx].value) { - mgmt_yang_data_value_init(&value[cnt]); - value[cnt].encoded_str_val = - (char *)vty->cfg_changes[indx].value; - value[cnt].value_case = - MGMTD__YANG_DATA_VALUE__VALUE_ENCODED_STR_VAL; - cfg_data[cnt].value = &value[cnt]; - } + if (xpath_base == NULL) + xpath_base = ""; - cfg_data[cnt].xpath = vty->cfg_changes[indx].xpath; + for (indx = 0; indx < vty->num_cfg_changes; indx++) { + mgmt_yang_data_init(&cfg_data[indx]); - mgmt_yang_cfg_data_req_init(&cfg_req[cnt]); - cfg_req[cnt].data = &cfg_data[cnt]; - switch (vty->cfg_changes[indx].operation) { - case NB_OP_DESTROY: - cfg_req[cnt].req_type = - MGMTD__CFG_DATA_REQ_TYPE__DELETE_DATA; - break; + if (vty->cfg_changes[indx].value) { + mgmt_yang_data_value_init(&value[indx]); + value[indx].encoded_str_val = + (char *)vty->cfg_changes[indx].value; + value[indx].value_case = + MGMTD__YANG_DATA_VALUE__VALUE_ENCODED_STR_VAL; + cfg_data[indx].value = &value[indx]; + } - case NB_OP_CREATE: - case NB_OP_MODIFY: - case NB_OP_MOVE: - case NB_OP_PRE_VALIDATE: - case NB_OP_APPLY_FINISH: - cfg_req[cnt].req_type = - MGMTD__CFG_DATA_REQ_TYPE__SET_DATA; - break; - case NB_OP_GET_ELEM: - case NB_OP_GET_NEXT: - case NB_OP_GET_KEYS: - case NB_OP_LOOKUP_ENTRY: - case NB_OP_RPC: - assert(!"Invalid type of operation"); - break; - default: - assert(!"non-enum value, invalid"); - } + change_xpath = vty->cfg_changes[indx].xpath; - cfgreq[cnt] = &cfg_req[cnt]; - cnt++; + memset(xpath[indx], 0, sizeof(xpath[indx])); + /* If change xpath is relative, prepend base xpath. */ + if (change_xpath[0] == '.') { + strlcpy(xpath[indx], xpath_base, sizeof(xpath[indx])); + change_xpath++; /* skip '.' */ } + strlcat(xpath[indx], change_xpath, sizeof(xpath[indx])); - vty->mgmt_req_id++; - implicit_commit = vty_needs_implicit_commit(vty); - if (cnt && mgmt_fe_set_config_data( - mgmt_lib_hndl, vty->mgmt_session_id, - vty->mgmt_req_id, MGMTD_DS_CANDIDATE, cfgreq, - cnt, implicit_commit, - MGMTD_DS_RUNNING) != MGMTD_SUCCESS) { - zlog_err("Failed to send %d Config Xpaths to MGMTD!!", - (int)indx); - vty_out(vty, "Failed to send SETCFG-REQ to MGMTD!\n"); - return -1; + cfg_data[indx].xpath = xpath[indx]; + + mgmt_yang_cfg_data_req_init(&cfg_req[indx]); + cfg_req[indx].data = &cfg_data[indx]; + switch (vty->cfg_changes[indx].operation) { + case NB_OP_DELETE: + cfg_req[indx].req_type = + MGMTD__CFG_DATA_REQ_TYPE__DELETE_DATA; + break; + + case NB_OP_DESTROY: + cfg_req[indx].req_type = + MGMTD__CFG_DATA_REQ_TYPE__REMOVE_DATA; + break; + + case NB_OP_CREATE_EXCL: + cfg_req[indx].req_type = + MGMTD__CFG_DATA_REQ_TYPE__CREATE_DATA; + break; + + case NB_OP_REPLACE: + cfg_req[indx].req_type = + MGMTD__CFG_DATA_REQ_TYPE__REPLACE_DATA; + break; + + case NB_OP_CREATE: + case NB_OP_MODIFY: + case NB_OP_MOVE: + cfg_req[indx].req_type = + MGMTD__CFG_DATA_REQ_TYPE__SET_DATA; + break; + default: + assertf(false, + "Invalid operation type for send config: %d", + vty->cfg_changes[indx].operation); + /*NOTREACHED*/ + abort(); } - vty->mgmt_req_pending = true; + cfgreq[indx] = &cfg_req[indx]; } + if (!indx) + return 0; + + vty->mgmt_req_id++; + if (mgmt_fe_send_setcfg_req(mgmt_fe_client, vty->mgmt_session_id, + vty->mgmt_req_id, MGMTD_DS_CANDIDATE, + cfgreq, indx, implicit_commit, + MGMTD_DS_RUNNING)) { + zlog_err("Failed to send %zu config xpaths to mgmtd", indx); + vty_out(vty, "%% Failed to send commands to mgmtd\n"); + return -1; + } + + vty->mgmt_req_pending_cmd = "MESSAGE_SETCFG_REQ"; return 0; } int vty_mgmt_send_commit_config(struct vty *vty, bool validate_only, bool abort) { - enum mgmt_result ret; - - if (mgmt_lib_hndl && vty->mgmt_session_id) { + if (mgmt_fe_client && vty->mgmt_session_id) { vty->mgmt_req_id++; - ret = mgmt_fe_commit_config_data( - mgmt_lib_hndl, vty->mgmt_session_id, vty->mgmt_req_id, - MGMTD_DS_CANDIDATE, MGMTD_DS_RUNNING, validate_only, - abort); - if (ret != MGMTD_SUCCESS) { + if (mgmt_fe_send_commitcfg_req( + mgmt_fe_client, vty->mgmt_session_id, + vty->mgmt_req_id, MGMTD_DS_CANDIDATE, + MGMTD_DS_RUNNING, validate_only, abort)) { zlog_err("Failed sending COMMIT-REQ req-id %" PRIu64, vty->mgmt_req_id); vty_out(vty, "Failed to send COMMIT-REQ to MGMTD!\n"); return -1; } - vty->mgmt_req_pending = true; + vty->mgmt_req_pending_cmd = "MESSAGE_COMMCFG_REQ"; vty->mgmt_num_pending_setcfg = 0; } return 0; } -int vty_mgmt_send_get_config(struct vty *vty, Mgmtd__DatastoreId datastore, - const char **xpath_list, int num_req) +int vty_mgmt_send_get_req(struct vty *vty, bool is_config, + Mgmtd__DatastoreId datastore, const char **xpath_list, + int num_req) { - enum mgmt_result ret; Mgmtd__YangData yang_data[VTY_MAXCFGCHANGES]; Mgmtd__YangGetDataReq get_req[VTY_MAXCFGCHANGES]; Mgmtd__YangGetDataReq *getreq[VTY_MAXCFGCHANGES]; @@ -3762,56 +4091,38 @@ int vty_mgmt_send_get_config(struct vty *vty, Mgmtd__DatastoreId datastore, get_req[i].data = &yang_data[i]; getreq[i] = &get_req[i]; } - ret = mgmt_fe_get_config_data(mgmt_lib_hndl, vty->mgmt_session_id, - vty->mgmt_req_id, datastore, getreq, - num_req); - - if (ret != MGMTD_SUCCESS) { - zlog_err( - "Failed to send GET-CONFIG to MGMTD for req-id %" PRIu64 - ".", - vty->mgmt_req_id); + if (mgmt_fe_send_get_req(mgmt_fe_client, vty->mgmt_session_id, + vty->mgmt_req_id, is_config, datastore, getreq, + num_req)) { + zlog_err("Failed to send GET- to MGMTD for req-id %" PRIu64 ".", + vty->mgmt_req_id); vty_out(vty, "Failed to send GET-CONFIG to MGMTD!\n"); return -1; } - vty->mgmt_req_pending = true; + vty->mgmt_req_pending_cmd = "MESSAGE_GETCFG_REQ"; return 0; } -int vty_mgmt_send_get_data(struct vty *vty, Mgmtd__DatastoreId datastore, - const char **xpath_list, int num_req) +int vty_mgmt_send_get_tree_req(struct vty *vty, LYD_FORMAT result_type, + const char *xpath) { - enum mgmt_result ret; - Mgmtd__YangData yang_data[VTY_MAXCFGCHANGES]; - Mgmtd__YangGetDataReq get_req[VTY_MAXCFGCHANGES]; - Mgmtd__YangGetDataReq *getreq[VTY_MAXCFGCHANGES]; - int i; + LYD_FORMAT intern_format = result_type; vty->mgmt_req_id++; - for (i = 0; i < num_req; i++) { - mgmt_yang_get_data_req_init(&get_req[i]); - mgmt_yang_data_init(&yang_data[i]); - - yang_data->xpath = (char *)xpath_list[i]; - - get_req[i].data = &yang_data[i]; - getreq[i] = &get_req[i]; - } - ret = mgmt_fe_get_data(mgmt_lib_hndl, vty->mgmt_session_id, - vty->mgmt_req_id, datastore, getreq, num_req); - - if (ret != MGMTD_SUCCESS) { - zlog_err("Failed to send GET-DATA to MGMTD for req-id %" PRIu64 - ".", - vty->mgmt_req_id); - vty_out(vty, "Failed to send GET-DATA to MGMTD!\n"); + if (mgmt_fe_send_get_tree_req(mgmt_fe_client, vty->mgmt_session_id, + vty->mgmt_req_id, intern_format, xpath)) { + zlog_err("Failed to send GET-TREE to MGMTD session-id: %" PRIu64 + " req-id %" PRIu64 ".", + vty->mgmt_session_id, vty->mgmt_req_id); + vty_out(vty, "Failed to send GET-TREE to MGMTD!\n"); return -1; } - vty->mgmt_req_pending = true; + vty->mgmt_req_pending_cmd = "MESSAGE_GET_TREE_REQ"; + vty->mgmt_req_pending_data = result_type; return 0; } @@ -3862,9 +4173,9 @@ void vty_terminate(void) { struct vty *vty; - if (mgmt_lib_hndl) { - mgmt_fe_client_lib_destroy(); - mgmt_lib_hndl = 0; + if (mgmt_fe_client) { + mgmt_fe_client_destroy(mgmt_fe_client); + mgmt_fe_client = 0; } memset(vty_cwd, 0x00, sizeof(vty_cwd)); diff --git a/lib/vty.h b/lib/vty.h index 28f27d0d47..5866eccde0 100644 --- a/lib/vty.h +++ b/lib/vty.h @@ -147,7 +147,6 @@ struct vty { /* Dynamic transaction information. */ bool pending_allowed; bool pending_commit; - bool no_implicit_commit; char *pending_cmds_buf; size_t pending_cmds_buflen; size_t pending_cmds_bufpos; @@ -229,8 +228,14 @@ struct vty { /* set when we have sent mgmtd a *REQ command in response to some vty * CLI command and we are waiting on the reply so we can respond to the * vty user. */ - bool mgmt_req_pending; + const char *mgmt_req_pending_cmd; + uintptr_t mgmt_req_pending_data; bool mgmt_locked_candidate_ds; + bool mgmt_locked_running_ds; + /* Need to track when we file-lock in vtysh to re-lock on end/conf t + * workaround + */ + bool vtysh_file_locked; }; static inline void vty_push_context(struct vty *vty, int node, uint64_t id) @@ -373,7 +378,7 @@ extern bool vty_set_include(struct vty *vty, const char *regexp); */ extern int vty_json(struct vty *vty, struct json_object *json); extern int vty_json_no_pretty(struct vty *vty, struct json_object *json); -extern void vty_json_empty(struct vty *vty); +extern void vty_json_empty(struct vty *vty, struct json_object *json); /* post fd to be passed to the vtysh client * fd is owned by the VTY code after this and will be closed when done */ @@ -391,7 +396,7 @@ extern void vty_close(struct vty *); extern char *vty_get_cwd(void); extern void vty_update_xpath(const char *oldpath, const char *newpath); extern int vty_config_enter(struct vty *vty, bool private_config, - bool exclusive); + bool exclusive, bool file_lock); extern void vty_config_exit(struct vty *); extern int vty_config_node_exit(struct vty *); extern int vty_shell(struct vty *); @@ -408,25 +413,22 @@ extern bool vty_mgmt_fe_enabled(void); extern bool vty_mgmt_should_process_cli_apply_changes(struct vty *vty); extern bool mgmt_vty_read_configs(void); -extern int vty_mgmt_send_config_data(struct vty *vty); +extern int vty_mgmt_send_config_data(struct vty *vty, const char *xpath_base, + bool implicit_commit); extern int vty_mgmt_send_commit_config(struct vty *vty, bool validate_only, bool abort); -extern int vty_mgmt_send_get_config(struct vty *vty, - Mgmtd__DatastoreId datastore, - const char **xpath_list, int num_req); -extern int vty_mgmt_send_get_data(struct vty *vty, Mgmtd__DatastoreId datastore, - const char **xpath_list, int num_req); +extern int vty_mgmt_send_get_req(struct vty *vty, bool is_config, + Mgmtd__DatastoreId datastore, + const char **xpath_list, int num_req); +extern int vty_mgmt_send_get_tree_req(struct vty *vty, LYD_FORMAT result_type, + const char *xpath); extern int vty_mgmt_send_lockds_req(struct vty *vty, Mgmtd__DatastoreId ds_id, - bool lock); -extern void vty_mgmt_resume_response(struct vty *vty, bool success); + bool lock, bool scok); +extern void vty_mgmt_resume_response(struct vty *vty, int ret); static inline bool vty_needs_implicit_commit(struct vty *vty) { - return (frr_get_cli_mode() == FRR_CLI_CLASSIC - ? ((vty->pending_allowed || vty->no_implicit_commit) - ? false - : true) - : false); + return frr_get_cli_mode() == FRR_CLI_CLASSIC && !vty->pending_allowed; } #ifdef __cplusplus diff --git a/lib/wheel.c b/lib/wheel.c index e17995c64a..2520e81d49 100644 --- a/lib/wheel.c +++ b/lib/wheel.c @@ -57,7 +57,7 @@ static void wheel_timer_thread(struct event *t) wheel = EVENT_ARG(t); - event_execute(wheel->master, wheel_timer_thread_helper, wheel, 0); + event_execute(wheel->master, wheel_timer_thread_helper, wheel, 0, NULL); } struct timer_wheel *wheel_init(struct event_loop *master, int period, diff --git a/lib/workqueue.c b/lib/workqueue.c index fa5d585360..d630af1d1d 100644 --- a/lib/workqueue.c +++ b/lib/workqueue.c @@ -42,6 +42,15 @@ static void work_queue_item_free(struct work_queue_item *item) return; } +static inline void work_queue_item_dequeue(struct work_queue *wq, + struct work_queue_item *item) +{ + assert(wq->item_count > 0); + + wq->item_count--; + STAILQ_REMOVE(&wq->items, item, work_queue_item, wq); +} + static void work_queue_item_remove(struct work_queue *wq, struct work_queue_item *item) { @@ -133,6 +142,13 @@ static int work_queue_schedule(struct work_queue *wq, unsigned int delay) return 0; } +static inline void work_queue_item_enqueue(struct work_queue *wq, + struct work_queue_item *item) +{ + STAILQ_INSERT_TAIL(&wq->items, item, wq); + wq->item_count++; +} + void work_queue_add(struct work_queue *wq, void *data) { struct work_queue_item *item; @@ -265,17 +281,14 @@ void work_queue_run(struct event *thread) do { ret = wq->spec.workfunc(wq, item->data); item->ran++; - } while ((ret == WQ_RETRY_NOW) - && (item->ran < wq->spec.max_retries)); + } while (item->ran < wq->spec.max_retries); switch (ret) { case WQ_QUEUE_BLOCKED: { /* decrement item->ran again, cause this isn't an item - * specific error, and fall through to WQ_RETRY_LATER + * specific error, and retry later */ item->ran--; - } - case WQ_RETRY_LATER: { goto stats; } case WQ_REQUEUE: { @@ -295,10 +308,6 @@ void work_queue_run(struct event *thread) titem = item; break; } - case WQ_RETRY_NOW: - /* a RETRY_NOW that gets here has exceeded max_tries, same as - * ERROR */ - /* fallthru */ case WQ_SUCCESS: default: { work_queue_item_remove(wq, item); @@ -350,8 +359,7 @@ void work_queue_run(struct event *thread) /* Is the queue done yet? If it is, call the completion callback. */ if (!work_queue_empty(wq)) { - if (ret == WQ_RETRY_LATER || - ret == WQ_QUEUE_BLOCKED) + if (ret == WQ_QUEUE_BLOCKED) work_queue_schedule(wq, wq->spec.retry); else work_queue_schedule(wq, 0); diff --git a/lib/workqueue.h b/lib/workqueue.h index 5d84739d5c..a495fe8615 100644 --- a/lib/workqueue.h +++ b/lib/workqueue.h @@ -26,9 +26,7 @@ DECLARE_MTYPE(WORK_QUEUE); /* action value, for use by item processor and item error handlers */ typedef enum { WQ_SUCCESS = 0, - WQ_RETRY_NOW, /* retry immediately */ - WQ_RETRY_LATER, /* retry later, cease processing work queue */ - WQ_REQUEUE, /* requeue item, continue processing work queue */ + WQ_REQUEUE, /* requeue item, continue processing work queue */ WQ_QUEUE_BLOCKED, /* Queue cant be processed at this time. * Similar to WQ_RETRY_LATER, but doesn't penalise * the particular item.. */ @@ -117,22 +115,6 @@ work_queue_last_item(struct work_queue *wq) return STAILQ_LAST(&wq->items, work_queue_item, wq); } -static inline void work_queue_item_enqueue(struct work_queue *wq, - struct work_queue_item *item) -{ - STAILQ_INSERT_TAIL(&wq->items, item, wq); - wq->item_count++; -} - -static inline void work_queue_item_dequeue(struct work_queue *wq, - struct work_queue_item *item) -{ - assert(wq->item_count > 0); - - wq->item_count--; - STAILQ_REMOVE(&wq->items, item, work_queue_item, wq); -} - /* create a new work queue, of given name. * user must fill in the spec of the returned work queue before adding * anything to it @@ -160,6 +142,7 @@ bool work_queue_is_scheduled(struct work_queue *wq); /* Helpers, exported for thread.c and command.c */ extern void work_queue_run(struct event *thread); +/* Function to initialize the workqueue cli */ extern void workqueue_cmd_init(void); #ifdef __cplusplus diff --git a/lib/yang.c b/lib/yang.c index 4dd8654217..2860108d64 100644 --- a/lib/yang.c +++ b/lib/yang.c @@ -6,6 +6,7 @@ #include <zebra.h> +#include "darr.h" #include "log.h" #include "lib_errors.h" #include "yang.h" @@ -250,19 +251,44 @@ void yang_snode_get_path(const struct lysc_node *snode, } } -struct lysc_node *yang_find_snode(struct ly_ctx *ly_ctx, const char *xpath, - uint32_t options) +LY_ERR yang_resolve_snode_xpath(struct ly_ctx *ly_ctx, const char *xpath, + struct lysc_node ***snodes, bool *simple) { struct lysc_node *snode; struct ly_set *set; LY_ERR err; - err = lys_find_xpath(ly_native_ctx, NULL, xpath, options, &set); - if (err || !set->count) - return NULL; + /* lys_find_path will not resolve complex xpaths */ + snode = (struct lysc_node *)lys_find_path(ly_ctx, NULL, xpath, 0); + if (snode) { + *darr_append(*snodes) = snode; + *simple = true; + return LY_SUCCESS; + } - snode = set->snodes[0]; + /* Try again to catch complex query cases */ + err = lys_find_xpath(ly_native_ctx, NULL, xpath, 0, &set); + if (err) + return err; + if (!set->count) { + ly_set_free(set, NULL); + return LY_ENOTFOUND; + } + + *simple = false; + darr_ensure_i(*snodes, set->count - 1); + memcpy(*snodes, set->snodes, set->count * sizeof(set->snodes[0])); ly_set_free(set, NULL); + return LY_SUCCESS; +} + + +struct lysc_node *yang_find_snode(struct ly_ctx *ly_ctx, const char *xpath, + uint32_t options) +{ + struct lysc_node *snode; + + snode = (struct lysc_node *)lys_find_path(ly_ctx, NULL, xpath, 0); return snode; } @@ -370,33 +396,10 @@ unsigned int yang_snode_num_keys(const struct lysc_node *snode) return count; } -void yang_dnode_get_path(const struct lyd_node *dnode, char *xpath, - size_t xpath_len) +char *yang_dnode_get_path(const struct lyd_node *dnode, char *xpath, + size_t xpath_len) { - lyd_path(dnode, LYD_PATH_STD, xpath, xpath_len); -} - -const char *yang_dnode_get_schema_name(const struct lyd_node *dnode, - const char *xpath_fmt, ...) -{ - if (xpath_fmt) { - va_list ap; - char xpath[XPATH_MAXLEN]; - - va_start(ap, xpath_fmt); - vsnprintf(xpath, sizeof(xpath), xpath_fmt, ap); - va_end(ap); - - dnode = yang_dnode_get(dnode, xpath); - if (!dnode) { - flog_err(EC_LIB_YANG_DNODE_NOT_FOUND, - "%s: couldn't find %s", __func__, xpath); - zlog_backtrace(LOG_ERR); - abort(); - } - } - - return dnode->schema->name; + return lyd_path(dnode, LYD_PATH_STD, xpath, xpath_len); } struct lyd_node *yang_dnode_get(const struct lyd_node *dnode, const char *xpath) @@ -680,10 +683,40 @@ static void ly_log_cb(LY_LOG_LEVEL level, const char *msg, const char *path) zlog(priority, "libyang: %s", msg); } +static ssize_t yang_print_darr(void *arg, const void *buf, size_t count) +{ + uint8_t *dst = darr_append_n(*(uint8_t **)arg, count); + + memcpy(dst, buf, count); + return count; +} + +LY_ERR yang_print_tree_append(uint8_t **darr, const struct lyd_node *root, + LYD_FORMAT format, uint32_t options) +{ + LY_ERR err; + + err = lyd_print_clb(yang_print_darr, darr, root, format, options); + if (err) + zlog_err("Failed to save yang tree: %s", ly_last_errmsg()); + else if (format != LYD_LYB) + *darr_append(*darr) = 0; + return err; +} + +uint8_t *yang_print_tree(const struct lyd_node *root, LYD_FORMAT format, + uint32_t options) +{ + uint8_t *darr = NULL; + + if (yang_print_tree_append(&darr, root, format, options)) + return NULL; + return darr; +} + const char *yang_print_errors(struct ly_ctx *ly_ctx, char *buf, size_t buf_len) { struct ly_err_item *ei; - const char *path; ei = ly_err_first(ly_ctx); if (!ei) @@ -691,18 +724,16 @@ const char *yang_print_errors(struct ly_ctx *ly_ctx, char *buf, size_t buf_len) strlcpy(buf, "YANG error(s):\n", buf_len); for (; ei; ei = ei->next) { - strlcat(buf, " ", buf_len); + if (ei->path) { + strlcat(buf, " Path: ", buf_len); + strlcat(buf, ei->path, buf_len); + strlcat(buf, "\n", buf_len); + } + strlcat(buf, " Error: ", buf_len); strlcat(buf, ei->msg, buf_len); strlcat(buf, "\n", buf_len); } - path = ly_errpath(ly_ctx); - if (path) { - strlcat(buf, " YANG path: ", buf_len); - strlcat(buf, path, buf_len); - strlcat(buf, "\n", buf_len); - } - ly_err_clean(ly_ctx, NULL); return buf; @@ -723,6 +754,7 @@ struct ly_ctx *yang_ctx_new_setup(bool embedded_modules, bool explicit_compile) { struct ly_ctx *ctx = NULL; const char *yang_models_path = YANG_MODELS_PATH; + uint options; LY_ERR err; if (access(yang_models_path, R_OK | X_OK)) { @@ -736,7 +768,7 @@ struct ly_ctx *yang_ctx_new_setup(bool embedded_modules, bool explicit_compile) YANG_MODELS_PATH); } - uint options = LY_CTX_NO_YANGLIBRARY | LY_CTX_DISABLE_SEARCHDIR_CWD; + options = LY_CTX_NO_YANGLIBRARY | LY_CTX_DISABLE_SEARCHDIR_CWD; if (explicit_compile) options |= LY_CTX_EXPLICIT_COMPILE; err = ly_ctx_new(yang_models_path, options, &ctx); @@ -927,3 +959,272 @@ uint32_t yang_get_list_elements_count(const struct lyd_node *node) } while (node); return count; } + +int yang_get_key_preds(char *s, const struct lysc_node *snode, + struct yang_list_keys *keys, ssize_t space) +{ + const struct lysc_node_leaf *skey; + ssize_t len2, len = 0; + ssize_t i = 0; + + LY_FOR_KEYS (snode, skey) { + assert(i < keys->num); + len2 = snprintf(s + len, space - len, "[%s='%s']", skey->name, + keys->key[i]); + if (len2 > space - len) + len = space; + else + len += len2; + i++; + } + + assert(i == keys->num); + return i; +} + +int yang_get_node_keys(struct lyd_node *node, struct yang_list_keys *keys) +{ + struct lyd_node *child = lyd_child(node); + + keys->num = 0; + for (; child && lysc_is_key(child->schema); child = child->next) { + const char *value = lyd_get_value(child); + + if (!value) + return NB_ERR; + strlcpy(keys->key[keys->num], value, + sizeof(keys->key[keys->num])); + keys->num++; + } + return NB_OK; +} + +/* + * ------------------------ + * Libyang Future Functions + * ------------------------ + * + * All these functions are implemented in libyang versions (perhaps unreleased) + * beyond what we require currently so we must supply the functionality. + */ + +/* + * Safe to remove after libyang v2.1.xxx is required (.144 has a bug so + * something > .144) https://github.com/CESNET/libyang/issues/2149 + */ +LY_ERR yang_lyd_new_list(struct lyd_node_inner *parent, + const struct lysc_node *snode, + const struct yang_list_keys *list_keys, + struct lyd_node **node) +{ +#if defined(HAVE_LYD_NEW_LIST3) && 0 + LY_ERR err; + const char *keys[LIST_MAXKEYS]; + + assert(list_keys->num <= LIST_MAXKEYS); + for (int i = 0; i < list_keys->num; i++) + keys[i] = list_keys->key[i]; + + err = lyd_new_list3(&parent->node, snode->module, snode->name, keys, + NULL, 0, node); + return err; +#else + struct lyd_node *pnode = &parent->node; + const char(*keys)[LIST_MAXKEYLEN] = list_keys->key; + + assert(list_keys->num <= 8); + switch (list_keys->num) { + case 0: + return lyd_new_list(pnode, snode->module, snode->name, false, + node); + case 1: + return lyd_new_list(pnode, snode->module, snode->name, false, + node, keys[0]); + case 2: + return lyd_new_list(pnode, snode->module, snode->name, false, + node, keys[0], keys[1]); + case 3: + return lyd_new_list(pnode, snode->module, snode->name, false, + node, keys[0], keys[1], keys[2]); + case 4: + return lyd_new_list(pnode, snode->module, snode->name, false, + node, keys[0], keys[1], keys[2], keys[3]); + case 5: + return lyd_new_list(pnode, snode->module, snode->name, false, + node, keys[0], keys[1], keys[2], keys[3], + keys[4]); + case 6: + return lyd_new_list(pnode, snode->module, snode->name, false, + node, keys[0], keys[1], keys[2], keys[3], + keys[4], keys[5]); + case 7: + return lyd_new_list(pnode, snode->module, snode->name, false, + node, keys[0], keys[1], keys[2], keys[3], + keys[4], keys[5], keys[6]); + case 8: + return lyd_new_list(pnode, snode->module, snode->name, false, + node, keys[0], keys[1], keys[2], keys[3], + keys[4], keys[5], keys[6], keys[7]); + } + _Static_assert(LIST_MAXKEYS == 8, "max key mismatch in switch unroll"); + /*NOTREACHED*/ + return LY_EINVAL; +#endif +} + + +/* + * Safe to remove after libyang v2.1.144 is required + */ +LY_ERR yang_lyd_trim_xpath(struct lyd_node **root, const char *xpath) +{ + LY_ERR err; +#ifdef HAVE_LYD_TRIM_XPATH + err = lyd_trim_xpath(root, xpath, NULL); + if (err) { + flog_err_sys(EC_LIB_LIBYANG, + "cannot obtain specific result for xpath \"%s\": %s", + xpath, yang_ly_strerrcode(err)); + return err; + } + return LY_SUCCESS; +#else + struct lyd_node *node; + struct lyd_node **remove = NULL; + struct ly_set *set = NULL; + uint32_t i; + + *root = lyd_first_sibling(*root); + + err = lyd_find_xpath3(NULL, *root, xpath, NULL, &set); + if (err) { + flog_err_sys(EC_LIB_LIBYANG, + "cannot obtain specific result for xpath \"%s\": %s", + xpath, yang_ly_strerrcode(err)); + return err; + } + /* + * Mark keepers and sweep deleting non-keepers. + * + * NOTE: We assume the data-nodes have NULL priv pointers and use that + * for our mark. + */ + + /* Mark */ + for (i = 0; i < set->count; i++) { + for (node = set->dnodes[i]; node; node = &node->parent->node) { + if (node->priv) + break; + if (node == set->dnodes[i]) + node->priv = (void *)2; + else + node->priv = (void *)1; + } + } + + darr_ensure_cap(remove, 128); + LYD_TREE_DFS_BEGIN (*root, node) { + /* + * If this is a direct matching node then include it's subtree + * which won't be marked and would otherwise be removed. + */ + if (node->priv == (void *)2) + LYD_TREE_DFS_continue = 1; + else if (!node->priv) { + *darr_append(remove) = node; + LYD_TREE_DFS_continue = 1; + } + LYD_TREE_DFS_END(*root, node); + } + darr_foreach_i (remove, i) { + if (remove[i] == *root) + *root = (*root)->next; + lyd_free_tree(remove[i]); + } + darr_free(remove); + + if (set) + ly_set_free(set, NULL); + + return LY_SUCCESS; +#endif +} + +/* + * Safe to remove after libyang v2.1.128 is required + */ +const char *yang_ly_strerrcode(LY_ERR err) +{ +#ifdef HAVE_LY_STRERRCODE + return ly_strerrcode(err); +#else + switch (err) { + case LY_SUCCESS: + return "ok"; + case LY_EMEM: + return "out of memory"; + case LY_ESYS: + return "system error"; + case LY_EINVAL: + return "invalid value given"; + case LY_EEXIST: + return "item exists"; + case LY_ENOTFOUND: + return "item not found"; + case LY_EINT: + return "operation interrupted"; + case LY_EVALID: + return "validation failed"; + case LY_EDENIED: + return "access denied"; + case LY_EINCOMPLETE: + return "incomplete"; + case LY_ERECOMPILE: + return "compile error"; + case LY_ENOT: + return "not"; + case LY_EPLUGIN: + case LY_EOTHER: + return "other"; + default: + return "unknown"; + } +#endif +} + +/* + * Safe to remove after libyang v2.1.128 is required + */ +const char *yang_ly_strvecode(LY_VECODE vecode) +{ +#ifdef HAVE_LY_STRVECODE + return ly_strvecode(vecode); +#else + switch (vecode) { + case LYVE_SUCCESS: + return ""; + case LYVE_SYNTAX: + return "syntax"; + case LYVE_SYNTAX_YANG: + return "yang-syntax"; + case LYVE_SYNTAX_YIN: + return "yin-syntax"; + case LYVE_REFERENCE: + return "reference"; + case LYVE_XPATH: + return "xpath"; + case LYVE_SEMANTICS: + return "semantics"; + case LYVE_SYNTAX_XML: + return "xml-syntax"; + case LYVE_SYNTAX_JSON: + return "json-syntax"; + case LYVE_DATA: + return "data"; + case LYVE_OTHER: + return "other"; + default: + return "unknown"; + } +#endif +} diff --git a/lib/yang.h b/lib/yang.h index 37369c09bf..dbb7f7163b 100644 --- a/lib/yang.h +++ b/lib/yang.h @@ -317,30 +317,16 @@ extern unsigned int yang_snode_num_keys(const struct lysc_node *snode); * libyang data node to be processed. * * xpath - * Pointer to previously allocated buffer. + * Pointer to previously allocated buffer or NULL. * * xpath_len - * Size of the xpath buffer. - */ -extern void yang_dnode_get_path(const struct lyd_node *dnode, char *xpath, - size_t xpath_len); - -/* - * Return the schema name of the given libyang data node. - * - * dnode - * libyang data node. - * - * xpath_fmt - * Optional XPath expression (absolute or relative) to specify a different - * data node to operate on in the same data tree. + * Size of the xpath buffer if xpath non-NULL. * - * Returns: - * Schema name of the libyang data node. + * If xpath is NULL, the returned string (if non-NULL) needs to be free()d by + * the caller. */ -extern const char *yang_dnode_get_schema_name(const struct lyd_node *dnode, - const char *xpath_fmt, ...) - PRINTFRR(2, 3); +extern char *yang_dnode_get_path(const struct lyd_node *dnode, char *xpath, + size_t xpath_len); /* * Find a libyang data node by its YANG data path. @@ -600,6 +586,39 @@ extern struct ly_ctx *yang_ctx_new_setup(bool embedded_modules, */ extern void yang_debugging_set(bool enable); + +/* + * "Print" the yang tree in `root` into dynamic sized array. + * + * Args: + * root: root of the subtree to "print" along with siblings. + * format: LYD_FORMAT of output (see lyd_print_mem) + * options: printing options (see lyd_print_mem) + * + * Return: + * A darr dynamic array with the "printed" output or NULL on failure. + */ +extern uint8_t *yang_print_tree(const struct lyd_node *root, LYD_FORMAT format, + uint32_t options); + +/* + * "Print" the yang tree in `root` into an existing dynamic sized array. + * + * This function does not initialize or free the dynamic array, the array can + * already existing data, the tree will be appended to this data. + * + * Args: + * darr: existing `uint8_t *`, dynamic array. + * root: root of the subtree to "print" along with siblings. + * format: LYD_FORMAT of output (see lyd_print_mem) + * options: printing options (see lyd_print_mem) + * + * Return: + * LY_ERR from underlying calls. + */ +extern LY_ERR yang_print_tree_append(uint8_t **darr, const struct lyd_node *root, + LYD_FORMAT format, uint32_t options); + /* * Print libyang error messages into the provided buffer. * @@ -693,6 +712,44 @@ bool yang_is_last_list_dnode(const struct lyd_node *dnode); /* API to check if the given node is last node in the data tree level */ bool yang_is_last_level_dnode(const struct lyd_node *dnode); +/* Create a YANG predicate string based on the keys */ +extern int yang_get_key_preds(char *s, const struct lysc_node *snode, + struct yang_list_keys *keys, ssize_t space); + +/* Get YANG keys from an existing dnode */ +extern int yang_get_node_keys(struct lyd_node *node, struct yang_list_keys *keys); + +/** + * yang_resolve_snodes() - Resolve an XPath to matching schema nodes. + * @ly_ctx: libyang context to operate on. + * @xpath: the path or XPath to resolve. + * @snodes: [OUT] pointer for resulting dynamic array (darr) of schema node + * pointers. + * @simple: [OUT] indicates if @xpath was resolvable simply or not. Non-simple + * means that the @xpath is not a simple path and utilizes XPath 1.0 + * functionality beyond simple key predicates. + * + * This function can be used to find the schema node (or nodes) that correspond + * to a given @xpath. If the @xpath includes non-key predicates (e.g., using + * functions) then @simple will be set to false, and @snodes may contain more + * than a single schema node. + * + * Return: a libyang error or LY_SUCCESS. + */ +extern LY_ERR yang_resolve_snode_xpath(struct ly_ctx *ly_ctx, const char *xpath, + struct lysc_node ***snodes, bool *simple); + +/* + * Libyang future functions + */ +extern const char *yang_ly_strerrcode(LY_ERR err); +extern const char *yang_ly_strvecode(LY_VECODE vecode); +extern LY_ERR yang_lyd_new_list(struct lyd_node_inner *parent, + const struct lysc_node *snode, + const struct yang_list_keys *keys, + struct lyd_node **nodes); +extern LY_ERR yang_lyd_trim_xpath(struct lyd_node **rootp, const char *xpath); + #ifdef __cplusplus } #endif diff --git a/lib/yang_translator.c b/lib/yang_translator.c index eae7577a0d..005f6422f3 100644 --- a/lib/yang_translator.c +++ b/lib/yang_translator.c @@ -146,7 +146,7 @@ struct yang_translator *yang_translator_load(const char *path) */ assert(dnode); - family = yang_dnode_get_string(dnode, "./family"); + family = yang_dnode_get_string(dnode, "family"); translator = yang_translator_find(family); if (translator != NULL) { flog_warn(EC_LIB_YANG_TRANSLATOR_LOAD, @@ -182,7 +182,7 @@ struct yang_translator *yang_translator_load(const char *path) tmodule = XCALLOC(MTYPE_YANG_TRANSLATOR_MODULE, sizeof(*tmodule)); - module_name = yang_dnode_get_string(set->dnodes[i], "./name"); + module_name = yang_dnode_get_string(set->dnodes[i], "name"); tmodule->module = ly_ctx_load_module(translator->ly_ctx, module_name, NULL, NULL); if (!tmodule->module) { @@ -233,7 +233,7 @@ struct yang_translator *yang_translator_load(const char *path) const struct lysc_node *snode_custom, *snode_native; xpath_custom = - yang_dnode_get_string(set->dnodes[i], "./custom"); + yang_dnode_get_string(set->dnodes[i], "custom"); snode_custom = yang_find_snode(translator->ly_ctx, xpath_custom, 0); @@ -246,7 +246,7 @@ struct yang_translator *yang_translator_load(const char *path) } xpath_native = - yang_dnode_get_string(set->dnodes[i], "./native"); + yang_dnode_get_string(set->dnodes[i], "native"); snode_native = yang_find_snode(ly_native_ctx, xpath_native, 0); if (!snode_native) { flog_warn(EC_LIB_YANG_TRANSLATOR_LOAD, diff --git a/lib/zclient.c b/lib/zclient.c index 8526cbfaa1..2a7d2a8c5b 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -41,8 +41,20 @@ static void zclient_event(enum zclient_event, struct zclient *); static void zebra_interface_if_set_value(struct stream *s, struct interface *ifp); -struct zclient_options zclient_options_default = {.receive_notify = false, - .synchronous = false}; +const struct zclient_options zclient_options_default = { + .synchronous = false, + .auxiliary = false, +}; + +const struct zclient_options zclient_options_sync = { + .synchronous = true, + .auxiliary = true, +}; + +const struct zclient_options zclient_options_auxiliary = { + .synchronous = false, + .auxiliary = true, +}; struct sockaddr_storage zclient_addr; socklen_t zclient_addr_len; @@ -52,7 +64,7 @@ static int zclient_debug; /* Allocate zclient structure. */ struct zclient *zclient_new(struct event_loop *master, - struct zclient_options *opt, + const struct zclient_options *opt, zclient_handler *const *handlers, size_t n_handlers) { struct zclient *zclient; @@ -69,8 +81,8 @@ struct zclient *zclient_new(struct event_loop *master, zclient->handlers = handlers; zclient->n_handlers = n_handlers; - zclient->receive_notify = opt->receive_notify; zclient->synchronous = opt->synchronous; + zclient->auxiliary = opt->auxiliary; return zclient; } @@ -180,14 +192,14 @@ void zclient_stop(struct zclient *zclient) for (afi = AFI_IP; afi < AFI_MAX; afi++) { for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { - vrf_bitmap_free(zclient->redist[afi][i]); + vrf_bitmap_free(&zclient->redist[afi][i]); zclient->redist[afi][i] = VRF_BITMAP_NULL; } redist_del_instance( &zclient->mi_redist[afi][zclient->redist_default], zclient->instance); - vrf_bitmap_free(zclient->default_information[afi]); + vrf_bitmap_free(&zclient->default_information[afi]); zclient->default_information[afi] = VRF_BITMAP_NULL; } } @@ -392,10 +404,6 @@ enum zclient_send_status zclient_send_hello(struct zclient *zclient) stream_putc(s, zclient->redist_default); stream_putw(s, zclient->instance); stream_putl(s, zclient->session_id); - if (zclient->receive_notify) - stream_putc(s, 1); - else - stream_putc(s, 0); if (zclient->synchronous) stream_putc(s, 1); else @@ -494,7 +502,7 @@ void zclient_send_reg_requests(struct zclient *zclient, vrf_id_t vrf_id) /* Set unwanted redistribute route. */ for (afi = AFI_IP; afi < AFI_MAX; afi++) - vrf_bitmap_set(zclient->redist[afi][zclient->redist_default], + vrf_bitmap_set(&zclient->redist[afi][zclient->redist_default], vrf_id); /* Flush all redistribute request. */ @@ -524,15 +532,15 @@ void zclient_send_reg_requests(struct zclient *zclient, vrf_id_t vrf_id) /* Resend all redistribute request. */ for (afi = AFI_IP; afi < AFI_MAX; afi++) { for (i = 0; i < ZEBRA_ROUTE_MAX; i++) - if (i != zclient->redist_default - && vrf_bitmap_check(zclient->redist[afi][i], - vrf_id)) + if (i != zclient->redist_default && + vrf_bitmap_check(&zclient->redist[afi][i], vrf_id)) zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD, zclient, afi, i, 0, vrf_id); /* If default information is needed. */ - if (vrf_bitmap_check(zclient->default_information[afi], vrf_id)) + if (vrf_bitmap_check(&zclient->default_information[afi], + vrf_id)) zebra_redistribute_default_send( ZEBRA_REDISTRIBUTE_DEFAULT_ADD, zclient, afi, vrf_id); @@ -561,7 +569,7 @@ void zclient_send_dereg_requests(struct zclient *zclient, vrf_id_t vrf_id) /* Set unwanted redistribute route. */ for (afi = AFI_IP; afi < AFI_MAX; afi++) - vrf_bitmap_unset(zclient->redist[afi][zclient->redist_default], + vrf_bitmap_unset(&zclient->redist[afi][zclient->redist_default], vrf_id); /* Flush all redistribute request. */ @@ -591,15 +599,15 @@ void zclient_send_dereg_requests(struct zclient *zclient, vrf_id_t vrf_id) /* Flush all redistribute request. */ for (afi = AFI_IP; afi < AFI_MAX; afi++) { for (i = 0; i < ZEBRA_ROUTE_MAX; i++) - if (i != zclient->redist_default - && vrf_bitmap_check(zclient->redist[afi][i], - vrf_id)) + if (i != zclient->redist_default && + vrf_bitmap_check(&zclient->redist[afi][i], vrf_id)) zebra_redistribute_send( ZEBRA_REDISTRIBUTE_DELETE, zclient, afi, i, 0, vrf_id); /* If default information is needed. */ - if (vrf_bitmap_check(zclient->default_information[afi], vrf_id)) + if (vrf_bitmap_check(&zclient->default_information[afi], + vrf_id)) zebra_redistribute_default_send( ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, zclient, afi, vrf_id); @@ -726,7 +734,7 @@ void zclient_init(struct zclient *zclient, int redist_default, /* Clear redistribution flags. */ for (afi = AFI_IP; afi < AFI_MAX; afi++) for (i = 0; i < ZEBRA_ROUTE_MAX; i++) - zclient->redist[afi][i] = vrf_bitmap_init(); + vrf_bitmap_init(&zclient->redist[afi][i]); /* Set unwanted redistribute route. bgpd does not need BGP route redistribution. */ @@ -738,7 +746,7 @@ void zclient_init(struct zclient *zclient, int redist_default, instance); /* Set default-information redistribute to zero. */ - zclient->default_information[afi] = vrf_bitmap_init(); + vrf_bitmap_init(&zclient->default_information[afi]); } if (zclient_debug) @@ -891,7 +899,7 @@ static int zapi_nexthop_cmp_no_labels(const struct zapi_nexthop *next1, &next2->gate); if (ret != 0) return ret; - /* Intentional Fall-Through */ + fallthrough; case NEXTHOP_TYPE_IFINDEX: if (next1->ifindex < next2->ifindex) return -1; @@ -1061,10 +1069,11 @@ int zapi_nexthop_encode(struct stream *s, const struct zapi_nexthop *api_nh, sizeof(struct seg6local_context)); } - if (CHECK_FLAG(nh_flags, ZAPI_NEXTHOP_FLAG_SEG6)) - stream_write(s, &api_nh->seg6_segs, - sizeof(struct in6_addr)); - + if (CHECK_FLAG(nh_flags, ZAPI_NEXTHOP_FLAG_SEG6)) { + stream_putc(s, api_nh->seg_num); + stream_put(s, &api_nh->seg6_segs[0], + api_nh->seg_num * sizeof(struct in6_addr)); + } done: return ret; } @@ -1430,9 +1439,18 @@ int zapi_nexthop_decode(struct stream *s, struct zapi_nexthop *api_nh, sizeof(struct seg6local_context)); } - if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_SEG6)) - STREAM_GET(&api_nh->seg6_segs, s, - sizeof(struct in6_addr)); + if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_SEG6)) { + STREAM_GETC(s, api_nh->seg_num); + if (api_nh->seg_num > SRV6_MAX_SIDS) { + flog_err(EC_LIB_ZAPI_ENCODE, + "%s: invalid number of SRv6 Segs (%u)", + __func__, api_nh->seg_num); + return -1; + } + + STREAM_GET(&api_nh->seg6_segs[0], s, + api_nh->seg_num * sizeof(struct in6_addr)); + } /* Success */ ret = 0; @@ -1611,30 +1629,237 @@ static void zapi_encode_prefix(struct stream *s, struct prefix *p, stream_put(s, &p->u.prefix, prefix_blen(p)); } -int zapi_pbr_rule_encode(uint8_t cmd, struct stream *s, struct pbr_rule *zrule) +static bool zapi_decode_prefix(struct stream *s, struct prefix *p) { - stream_reset(s); - zclient_create_header(s, cmd, zrule->vrf_id); + STREAM_GETC(s, p->family); + STREAM_GETC(s, p->prefixlen); + STREAM_GET(&(p->u.prefix), s, prefix_blen(p)); + return true; + +stream_failure: + return false; +} + +static void zapi_encode_sockunion(struct stream *s, const union sockunion *su) +{ + int family = sockunion_family(su); + size_t addrlen = family2addrsize(family); + + /* + * Must know length to encode + */ + assert(addrlen); + + stream_putc(s, (uint8_t)family); + + stream_write(s, sockunion_get_addr(su), addrlen); +} + +static bool zapi_decode_sockunion(struct stream *s, union sockunion *su) +{ + uint8_t family; + size_t addrlen; + uint8_t buf[sizeof(union sockunion)]; + + memset(su, 0, sizeof(*su)); + + STREAM_GETC(s, family); + sockunion_family(su) = family; + + addrlen = family2addrsize(family); + if (!addrlen) + return false; + + if (addrlen > sizeof(buf)) + return false; + + STREAM_GET(buf, s, addrlen); + sockunion_set(su, family, buf, addrlen); + return true; + +stream_failure: + return false; +} + +/* + * Encode filter subsection of pbr_rule + */ +static void zapi_pbr_rule_filter_encode(struct stream *s, struct pbr_filter *f) +{ + assert(f->src_ip.family == f->dst_ip.family); + assert((f->src_ip.family == AF_INET) || (f->src_ip.family == AF_INET6)); + + stream_putl(s, f->filter_bm); + + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_IP_PROTOCOL)) + stream_putc(s, f->ip_proto); + + /* addresses */ + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_SRC_IP)) + zapi_encode_prefix(s, &f->src_ip, f->src_ip.family); + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_DST_IP)) + zapi_encode_prefix(s, &f->dst_ip, f->dst_ip.family); + + /* port numbers */ + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_SRC_PORT)) + stream_putw(s, f->src_port); + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_DST_PORT)) + stream_putw(s, f->dst_port); + + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_DSCP)) + stream_putc(s, f->dsfield & PBR_DSFIELD_DSCP); + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_ECN)) + stream_putc(s, f->dsfield & PBR_DSFIELD_ECN); + + /* vlan */ + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_PCP)) + stream_putc(s, f->pcp); + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_VLAN_ID)) + stream_putw(s, f->vlan_id); + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_VLAN_FLAGS)) + stream_putw(s, f->vlan_flags); + + + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_FWMARK)) + stream_putl(s, f->fwmark); +} + +static bool zapi_pbr_rule_filter_decode(struct stream *s, struct pbr_filter *f) +{ + uint8_t dscp = 0; + uint8_t ecn = 0; + + STREAM_GETL(s, f->filter_bm); + + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_IP_PROTOCOL)) + STREAM_GETC(s, f->ip_proto); + + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_SRC_IP)) + if (!zapi_decode_prefix(s, &(f->src_ip))) + goto stream_failure; + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_DST_IP)) + if (!zapi_decode_prefix(s, &(f->dst_ip))) + goto stream_failure; + + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_SRC_PORT)) + STREAM_GETW(s, f->src_port); + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_DST_PORT)) + STREAM_GETW(s, f->dst_port); + + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_DSCP)) + STREAM_GETC(s, dscp); + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_ECN)) + STREAM_GETC(s, ecn); + f->dsfield = (dscp & PBR_DSFIELD_DSCP) | (ecn & PBR_DSFIELD_ECN); + + /* vlan */ + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_PCP)) + STREAM_GETC(s, f->pcp); + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_VLAN_ID)) + STREAM_GETW(s, f->vlan_id); + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_VLAN_FLAGS)) + STREAM_GETW(s, f->vlan_flags); + + if (CHECK_FLAG(f->filter_bm, PBR_FILTER_FWMARK)) + STREAM_GETL(s, f->fwmark); + + return true; + +stream_failure: + return false; +} + +static void zapi_pbr_rule_action_encode(struct stream *s, struct pbr_action *a) +{ + stream_putl(s, a->flags); + + if (CHECK_FLAG(a->flags, PBR_ACTION_TABLE)) + stream_putl(s, a->table); + if (CHECK_FLAG(a->flags, PBR_ACTION_QUEUE_ID)) + stream_putl(s, a->queue_id); + + /* L3 */ + if (CHECK_FLAG(a->flags, PBR_ACTION_SRC_IP)) + zapi_encode_sockunion(s, &a->src_ip); + if (CHECK_FLAG(a->flags, PBR_ACTION_DST_IP)) + zapi_encode_sockunion(s, &a->dst_ip); + if (CHECK_FLAG(a->flags, PBR_ACTION_SRC_PORT)) + stream_putw(s, a->src_port); + if (CHECK_FLAG(a->flags, PBR_ACTION_DST_PORT)) + stream_putw(s, a->dst_port); + + if (CHECK_FLAG(a->flags, PBR_ACTION_DSCP)) + stream_putc(s, a->dscp & PBR_DSFIELD_DSCP); + if (CHECK_FLAG(a->flags, PBR_ACTION_ECN)) + stream_putc(s, a->ecn & PBR_DSFIELD_ECN); + + /* L2 */ + if (CHECK_FLAG(a->flags, PBR_ACTION_PCP)) + stream_putc(s, a->pcp); + if (CHECK_FLAG(a->flags, PBR_ACTION_VLAN_ID)) + stream_putw(s, a->vlan_id); +} + +static bool zapi_pbr_rule_action_decode(struct stream *s, struct pbr_action *a) +{ + STREAM_GETL(s, a->flags); + if (CHECK_FLAG(a->flags, PBR_ACTION_TABLE)) + STREAM_GETL(s, a->table); + if (CHECK_FLAG(a->flags, PBR_ACTION_QUEUE_ID)) + STREAM_GETL(s, a->queue_id); + + /* L3 */ + if (CHECK_FLAG(a->flags, PBR_ACTION_SRC_IP)) { + if (!zapi_decode_sockunion(s, &(a->src_ip))) + goto stream_failure; + } + if (CHECK_FLAG(a->flags, PBR_ACTION_DST_IP)) + if (!zapi_decode_sockunion(s, &(a->dst_ip))) + goto stream_failure; + + if (CHECK_FLAG(a->flags, PBR_ACTION_SRC_PORT)) + STREAM_GETW(s, a->src_port); + if (CHECK_FLAG(a->flags, PBR_ACTION_DST_PORT)) + STREAM_GETW(s, a->dst_port); + + if (CHECK_FLAG(a->flags, PBR_ACTION_DSCP)) { + STREAM_GETC(s, a->dscp); + a->dscp &= PBR_DSFIELD_DSCP; + } + if (CHECK_FLAG(a->flags, PBR_ACTION_ECN)) { + STREAM_GETC(s, a->ecn); + a->ecn &= PBR_DSFIELD_ECN; + } + + /* L2 */ + if (CHECK_FLAG(a->flags, PBR_ACTION_PCP)) + STREAM_GETC(s, a->pcp); + if (CHECK_FLAG(a->flags, PBR_ACTION_VLAN_ID)) + STREAM_GETW(s, a->vlan_id); + + return true; + +stream_failure: + return false; +} + +int zapi_pbr_rule_encode(struct stream *s, struct pbr_rule *r) +{ /* - * We are sending one item at a time at the moment + * PBR record count is always 1 */ stream_putl(s, 1); - stream_putl(s, zrule->seq); - stream_putl(s, zrule->priority); - stream_putl(s, zrule->unique); + stream_putc(s, r->family); + stream_putl(s, r->seq); + stream_putl(s, r->priority); + stream_putl(s, r->unique); - zapi_encode_prefix(s, &(zrule->filter.src_ip), - zrule->filter.src_ip.family); - stream_putw(s, zrule->filter.src_port); /* src port */ - zapi_encode_prefix(s, &(zrule->filter.dst_ip), - zrule->filter.src_ip.family); - stream_putw(s, zrule->filter.dst_port); /* dst port */ - stream_putw(s, zrule->filter.fwmark); /* fwmark */ + zapi_pbr_rule_filter_encode(s, &(r->filter)); + zapi_pbr_rule_action_encode(s, &(r->action)); - stream_putl(s, zrule->action.table); - stream_put(s, zrule->ifname, INTERFACE_NAMSIZ); + stream_put(s, r->ifname, IFNAMSIZ); /* Put length at the first point of the stream. */ stream_putw_at(s, 0, stream_get_endp(s)); @@ -1642,6 +1867,29 @@ int zapi_pbr_rule_encode(uint8_t cmd, struct stream *s, struct pbr_rule *zrule) return 0; } +bool zapi_pbr_rule_decode(struct stream *s, struct pbr_rule *r) +{ + /* NB caller has already read 4-byte rule count */ + + memset(r, 0, sizeof(*r)); + + STREAM_GETC(s, r->family); + STREAM_GETL(s, r->seq); + STREAM_GETL(s, r->priority); + STREAM_GETL(s, r->unique); + + if (!zapi_pbr_rule_filter_decode(s, &(r->filter))) + goto stream_failure; + if (!zapi_pbr_rule_action_decode(s, &(r->action))) + goto stream_failure; + + STREAM_GET(r->ifname, s, IFNAMSIZ); + return true; + +stream_failure: + return false; +} + int zapi_tc_qdisc_encode(uint8_t cmd, struct stream *s, struct tc_qdisc *qdisc) { stream_reset(s); @@ -1794,7 +2042,7 @@ bool zapi_rule_notify_decode(struct stream *s, uint32_t *seqno, STREAM_GETL(s, seq); STREAM_GETL(s, prio); STREAM_GETL(s, uni); - STREAM_GET(ifname, s, INTERFACE_NAMSIZ); + STREAM_GET(ifname, s, IFNAMSIZ); if (zclient_debug) zlog_debug("%s: %u %u %u %s", __func__, seq, prio, uni, ifname); @@ -1902,8 +2150,8 @@ struct nexthop *nexthop_from_zapi_nexthop(const struct zapi_nexthop *znh) nexthop_add_srv6_seg6local(n, znh->seg6local_action, &znh->seg6local_ctx); - if (!sid_zero(&znh->seg6_segs)) - nexthop_add_srv6_seg6(n, &znh->seg6_segs); + if (znh->seg_num && !sid_zero_ipv6(znh->seg6_segs)) + nexthop_add_srv6_seg6(n, &znh->seg6_segs[0], znh->seg_num); return n; } @@ -1963,10 +2211,14 @@ int zapi_nexthop_from_nexthop(struct zapi_nexthop *znh, sizeof(struct seg6local_context)); } - if (!sid_zero(&nh->nh_srv6->seg6_segs)) { + if (nh->nh_srv6->seg6_segs && nh->nh_srv6->seg6_segs->num_segs && + !sid_zero(nh->nh_srv6->seg6_segs)) { SET_FLAG(znh->flags, ZAPI_NEXTHOP_FLAG_SEG6); - memcpy(&znh->seg6_segs, &nh->nh_srv6->seg6_segs, - sizeof(struct in6_addr)); + znh->seg_num = nh->nh_srv6->seg6_segs->num_segs; + for (i = 0; i < nh->nh_srv6->seg6_segs->num_segs; i++) + memcpy(&znh->seg6_segs[i], + &nh->nh_srv6->seg6_segs->seg[i], + sizeof(struct in6_addr)); } } @@ -2025,8 +2277,8 @@ const char *zapi_nexthop2str(const struct zapi_nexthop *znh, char *buf, /* * Decode the nexthop-tracking update message */ -bool zapi_nexthop_update_decode(struct stream *s, struct prefix *match, - struct zapi_route *nhr) +static bool zapi_nexthop_update_decode(struct stream *s, struct prefix *match, + struct zapi_route *nhr) { uint32_t i; @@ -2282,12 +2534,12 @@ static int zclient_vrf_delete(ZAPI_CALLBACK_ARGS) static int zclient_interface_add(ZAPI_CALLBACK_ARGS) { struct interface *ifp; - char ifname_tmp[INTERFACE_NAMSIZ + 1] = {}; + char ifname_tmp[IFNAMSIZ + 1] = {}; struct stream *s = zclient->ibuf; struct vrf *vrf; /* Read interface name. */ - STREAM_GET(ifname_tmp, s, INTERFACE_NAMSIZ); + STREAM_GET(ifname_tmp, s, IFNAMSIZ); /* Lookup/create interface by name. */ vrf = vrf_lookup_by_id(vrf_id); @@ -2318,10 +2570,10 @@ static int zclient_interface_add(ZAPI_CALLBACK_ARGS) struct interface *zebra_interface_state_read(struct stream *s, vrf_id_t vrf_id) { struct interface *ifp; - char ifname_tmp[INTERFACE_NAMSIZ + 1] = {}; + char ifname_tmp[IFNAMSIZ + 1] = {}; /* Read interface name. */ - STREAM_GET(ifname_tmp, s, INTERFACE_NAMSIZ); + STREAM_GET(ifname_tmp, s, IFNAMSIZ); /* Lookup this by interface index. */ ifp = if_lookup_by_name(ifname_tmp, vrf_id); @@ -2531,6 +2783,7 @@ static void zebra_interface_if_set_value(struct stream *s, STREAM_GETC(s, ifp->ptm_status); STREAM_GETL(s, ifp->metric); STREAM_GETL(s, ifp->speed); + STREAM_GETL(s, ifp->txqlen); STREAM_GETL(s, ifp->mtu); STREAM_GETL(s, ifp->mtu6); STREAM_GETL(s, ifp->bandwidth); @@ -2806,36 +3059,6 @@ zebra_interface_nbr_address_read(int type, struct stream *s, vrf_id_t vrf_id) return NULL; } -struct interface *zebra_interface_vrf_update_read(struct stream *s, - vrf_id_t vrf_id, - vrf_id_t *new_vrf_id) -{ - char ifname[INTERFACE_NAMSIZ + 1] = {}; - struct interface *ifp; - vrf_id_t new_id; - - /* Read interface name. */ - STREAM_GET(ifname, s, INTERFACE_NAMSIZ); - - /* Lookup interface. */ - ifp = if_lookup_by_name(ifname, vrf_id); - if (ifp == NULL) { - flog_err(EC_LIB_ZAPI_ENCODE, - "INTERFACE_VRF_UPDATE: Cannot find IF %s in VRF %d", - ifname, vrf_id); - return NULL; - } - - /* Fetch new VRF Id. */ - STREAM_GETL(s, new_id); - - *new_vrf_id = new_id; - return ifp; - -stream_failure: - return NULL; -} - /* filter unwanted messages until the expected one arrives */ static int zclient_read_sync_response(struct zclient *zclient, uint16_t expected_cmd) @@ -3701,7 +3924,7 @@ enum zclient_send_status zebra_send_pw(struct zclient *zclient, int command, stream_reset(s); zclient_create_header(s, command, VRF_DEFAULT); - stream_write(s, pw->ifname, INTERFACE_NAMSIZ); + stream_write(s, pw->ifname, IFNAMSIZ); stream_putl(s, pw->ifindex); /* Put type */ @@ -3748,7 +3971,7 @@ int zebra_read_pw_status_update(ZAPI_CALLBACK_ARGS, struct zapi_pw_status *pw) s = zclient->ibuf; /* Get data. */ - stream_get(pw->ifname, s, INTERFACE_NAMSIZ); + stream_get(pw->ifname, s, IFNAMSIZ); STREAM_GETL(s, pw->ifindex); STREAM_GETL(s, pw->status); @@ -3779,6 +4002,7 @@ static int zclient_capability_decode(ZAPI_CALLBACK_ARGS) cap.mpls_enabled = !!mpls_enabled; STREAM_GETL(s, cap.ecmp); STREAM_GETC(s, cap.role); + STREAM_GETC(s, cap.v6_with_v4_nexthop); if (zclient->zebra_capabilities) (*zclient->zebra_capabilities)(&cap); @@ -3823,6 +4047,53 @@ enum zclient_send_status zclient_send_mlag_data(struct zclient *client, return zclient_send_message(client); } +/* + * Init/header setup for opaque zapi messages + */ +enum zclient_send_status zapi_opaque_init(struct zclient *zclient, + uint32_t type, uint16_t flags) +{ + struct stream *s; + + s = zclient->obuf; + stream_reset(s); + + zclient_create_header(s, ZEBRA_OPAQUE_MESSAGE, VRF_DEFAULT); + + /* Send sub-type and flags */ + stream_putl(s, type); + stream_putw(s, flags); + + /* Source daemon identifiers */ + stream_putc(s, zclient->redist_default); + stream_putw(s, zclient->instance); + stream_putl(s, zclient->session_id); + + return ZCLIENT_SEND_SUCCESS; +} + +/* + * Init, header setup for opaque unicast messages. + */ +enum zclient_send_status +zapi_opaque_unicast_init(struct zclient *zclient, uint32_t type, uint16_t flags, + uint8_t proto, uint16_t instance, uint32_t session_id) +{ + struct stream *s; + + s = zclient->obuf; + + /* Common init */ + zapi_opaque_init(zclient, type, flags | ZAPI_OPAQUE_FLAG_UNICAST); + + /* Send destination client info */ + stream_putc(s, proto); + stream_putw(s, instance); + stream_putl(s, session_id); + + return ZCLIENT_SEND_SUCCESS; +} + /* * Send an OPAQUE message, contents opaque to zebra. The message header * is a message subtype. @@ -3840,16 +4111,12 @@ enum zclient_send_status zclient_send_opaque(struct zclient *zclient, return ZCLIENT_SEND_FAILURE; s = zclient->obuf; - stream_reset(s); - - zclient_create_header(s, ZEBRA_OPAQUE_MESSAGE, VRF_DEFAULT); - /* Send sub-type and flags */ - stream_putl(s, type); - stream_putw(s, flags); + zapi_opaque_init(zclient, type, flags); /* Send opaque data */ - stream_write(s, data, datasize); + if (datasize > 0) + stream_write(s, data, datasize); /* Put length into the header at the start of the stream. */ stream_putw_at(s, 0, stream_get_endp(s)); @@ -3876,22 +4143,14 @@ zclient_send_opaque_unicast(struct zclient *zclient, uint32_t type, return ZCLIENT_SEND_FAILURE; s = zclient->obuf; - stream_reset(s); - - zclient_create_header(s, ZEBRA_OPAQUE_MESSAGE, VRF_DEFAULT); - /* Send sub-type and flags */ - SET_FLAG(flags, ZAPI_OPAQUE_FLAG_UNICAST); - stream_putl(s, type); - stream_putw(s, flags); - - /* Send destination client info */ - stream_putc(s, proto); - stream_putw(s, instance); - stream_putl(s, session_id); + /* Common init */ + zapi_opaque_unicast_init(zclient, type, flags, proto, instance, + session_id); /* Send opaque data */ - stream_write(s, data, datasize); + if (datasize > 0) + stream_write(s, data, datasize); /* Put length into the header at the start of the stream. */ stream_putw_at(s, 0, stream_get_endp(s)); @@ -3910,11 +4169,16 @@ int zclient_opaque_decode(struct stream *s, struct zapi_opaque_msg *info) STREAM_GETL(s, info->type); STREAM_GETW(s, info->flags); - /* Decode unicast client info if present */ + /* Decode sending daemon info */ + STREAM_GETC(s, info->src_proto); + STREAM_GETW(s, info->src_instance); + STREAM_GETL(s, info->src_session_id); + + /* Decode unicast destination info, if present */ if (CHECK_FLAG(info->flags, ZAPI_OPAQUE_FLAG_UNICAST)) { - STREAM_GETC(s, info->proto); - STREAM_GETW(s, info->instance); - STREAM_GETL(s, info->session_id); + STREAM_GETC(s, info->dest_proto); + STREAM_GETW(s, info->dest_instance); + STREAM_GETL(s, info->dest_session_id); } info->len = STREAM_READABLE(s); @@ -4012,6 +4276,28 @@ int zapi_client_close_notify_decode(struct stream *s, return -1; } +static int zclient_nexthop_update(ZAPI_CALLBACK_ARGS) +{ + struct vrf *vrf = vrf_lookup_by_id(vrf_id); + struct prefix match; + struct zapi_route route; + + if (!vrf) { + zlog_warn("nexthop update for unknown VRF ID %u", vrf_id); + return 0; + } + + if (!zapi_nexthop_update_decode(zclient->ibuf, &match, &route)) { + zlog_err("failed to decode nexthop update"); + return -1; + } + + if (zclient->nexthop_update) + zclient->nexthop_update(vrf, &match, &route); + + return 0; +} + static zclient_handler *const lib_handlers[] = { /* fundamentals */ [ZEBRA_CAPABILITIES] = zclient_capability_decode, @@ -4025,6 +4311,9 @@ static zclient_handler *const lib_handlers[] = { [ZEBRA_INTERFACE_UP] = zclient_interface_up, [ZEBRA_INTERFACE_DOWN] = zclient_interface_down, + /* NHT pre-decode */ + [ZEBRA_NEXTHOP_UPDATE] = zclient_nexthop_update, + /* BFD */ [ZEBRA_BFD_DEST_REPLAY] = zclient_bfd_session_replay, [ZEBRA_INTERFACE_BFD_DEST_UPDATE] = zclient_bfd_session_update, @@ -4133,7 +4422,8 @@ static void zclient_read(struct event *thread) zlog_debug("zclient %p command %s VRF %u", zclient, zserv_command_string(command), vrf_id); - if (command < array_size(lib_handlers) && lib_handlers[command]) + if (!zclient->auxiliary && command < array_size(lib_handlers) && + lib_handlers[command]) lib_handlers[command](command, zclient, length, vrf_id); if (command < zclient->n_handlers && zclient->handlers[command]) zclient->handlers[command](command, zclient, length, vrf_id); @@ -4168,15 +4458,15 @@ void zclient_redistribute(int command, struct zclient *zclient, afi_t afi, } else { if (command == ZEBRA_REDISTRIBUTE_ADD) { - if (vrf_bitmap_check(zclient->redist[afi][type], + if (vrf_bitmap_check(&zclient->redist[afi][type], vrf_id)) return; - vrf_bitmap_set(zclient->redist[afi][type], vrf_id); + vrf_bitmap_set(&zclient->redist[afi][type], vrf_id); } else { - if (!vrf_bitmap_check(zclient->redist[afi][type], + if (!vrf_bitmap_check(&zclient->redist[afi][type], vrf_id)) return; - vrf_bitmap_unset(zclient->redist[afi][type], vrf_id); + vrf_bitmap_unset(&zclient->redist[afi][type], vrf_id); } } @@ -4191,14 +4481,15 @@ void zclient_redistribute_default(int command, struct zclient *zclient, { if (command == ZEBRA_REDISTRIBUTE_DEFAULT_ADD) { - if (vrf_bitmap_check(zclient->default_information[afi], vrf_id)) + if (vrf_bitmap_check(&zclient->default_information[afi], + vrf_id)) return; - vrf_bitmap_set(zclient->default_information[afi], vrf_id); + vrf_bitmap_set(&zclient->default_information[afi], vrf_id); } else { - if (!vrf_bitmap_check(zclient->default_information[afi], + if (!vrf_bitmap_check(&zclient->default_information[afi], vrf_id)) return; - vrf_bitmap_unset(zclient->default_information[afi], vrf_id); + vrf_bitmap_unset(&zclient->default_information[afi], vrf_id); } if (zclient->sock > 0) @@ -4472,3 +4763,125 @@ int zclient_send_zebra_gre_request(struct zclient *client, zclient_send_message(client); return 0; } + + +/* + * Opaque notification features + */ + +/* + * Common encode helper for opaque notifications, both registration + * and async notification messages. + */ +static int opaque_notif_encode_common(struct stream *s, uint32_t msg_type, + bool request, bool reg, uint8_t proto, + uint16_t instance, uint32_t session_id) +{ + int ret = 0; + uint8_t val = 0; + + stream_reset(s); + + zclient_create_header(s, ZEBRA_OPAQUE_NOTIFY, VRF_DEFAULT); + + /* Notification or request */ + if (request) + val = 1; + stream_putc(s, val); + + if (reg) + val = 1; + else + val = 0; + stream_putc(s, val); + + stream_putl(s, msg_type); + + stream_putc(s, proto); + stream_putw(s, instance); + stream_putl(s, session_id); + + /* And capture message length */ + stream_putw_at(s, 0, stream_get_endp(s)); + + return ret; +} + +/* + * Encode a zapi opaque message type notification into buffer 's' + */ +int zclient_opaque_notif_encode(struct stream *s, uint32_t msg_type, bool reg, + uint8_t proto, uint16_t instance, + uint32_t session_id) +{ + return opaque_notif_encode_common(s, msg_type, false /* !request */, + reg, proto, instance, session_id); +} + +/* + * Decode an incoming zapi opaque message type notification + */ +int zclient_opaque_notif_decode(struct stream *s, + struct zapi_opaque_notif_info *info) +{ + uint8_t val; + + memset(info, 0, sizeof(*info)); + + STREAM_GETC(s, val); /* Registration or notification */ + info->request = (val != 0); + + STREAM_GETC(s, val); + info->reg = (val != 0); + + STREAM_GETL(s, info->msg_type); + + STREAM_GETC(s, info->proto); + STREAM_GETW(s, info->instance); + STREAM_GETL(s, info->session_id); + + return 0; + +stream_failure: + return -1; +} + +/* + * Encode and send a zapi opaque message type notification request to zebra + */ +enum zclient_send_status zclient_opaque_request_notify(struct zclient *zclient, + uint32_t msgtype) +{ + struct stream *s; + + if (!zclient || zclient->sock < 0) + return ZCLIENT_SEND_FAILURE; + + s = zclient->obuf; + + opaque_notif_encode_common(s, msgtype, true /* request */, + true /* register */, zclient->redist_default, + zclient->instance, zclient->session_id); + + return zclient_send_message(zclient); +} + +/* + * Encode and send a request to drop notifications for an opaque message type. + */ +enum zclient_send_status zclient_opaque_drop_notify(struct zclient *zclient, + uint32_t msgtype) +{ + struct stream *s; + + if (!zclient || zclient->sock < 0) + return ZCLIENT_SEND_FAILURE; + + s = zclient->obuf; + + opaque_notif_encode_common(s, msgtype, true /* req */, + false /* unreg */, zclient->redist_default, + zclient->instance, zclient->session_id); + + return zclient_send_message(zclient); +} diff --git a/lib/zclient.h b/lib/zclient.h index e43393fd70..8d7faeb223 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -87,7 +87,9 @@ enum zserv_client_capabilities { extern struct sockaddr_storage zclient_addr; extern socklen_t zclient_addr_len; -/* Zebra message types. */ +/* Zebra message types. Please update the corresponding + * command_types array with any changes! + */ typedef enum { ZEBRA_INTERFACE_ADD, ZEBRA_INTERFACE_DELETE, @@ -125,7 +127,6 @@ typedef enum { ZEBRA_VRF_ADD, ZEBRA_VRF_DELETE, ZEBRA_VRF_LABEL, - ZEBRA_INTERFACE_VRF_UPDATE, ZEBRA_BFD_CLIENT_REGISTER, ZEBRA_BFD_CLIENT_DEREGISTER, ZEBRA_INTERFACE_ENABLE_RADV, @@ -232,7 +233,11 @@ typedef enum { ZEBRA_TC_CLASS_DELETE, ZEBRA_TC_FILTER_ADD, ZEBRA_TC_FILTER_DELETE, + ZEBRA_OPAQUE_NOTIFY, } zebra_message_types_t; +/* Zebra message types. Please update the corresponding + * command_types array with any changes! + */ enum zebra_error_types { ZEBRA_UNKNOWN_ERROR, /* Error of unknown type */ @@ -268,6 +273,7 @@ struct zclient_capabilities { uint32_t ecmp; bool mpls_enabled; enum mlag_role role; + bool v6_with_v4_nexthop; }; /* Graceful Restart Capabilities message */ @@ -287,6 +293,8 @@ struct zapi_cap { typedef int (zclient_handler)(ZAPI_CALLBACK_ARGS); /* clang-format on */ +struct zapi_route; + /* Structure for the zebra client. */ struct zclient { /* The thread master we schedule ourselves on */ @@ -295,12 +303,14 @@ struct zclient { /* Privileges to change socket values */ struct zebra_privs_t *privs; - /* Do we care about failure events for route install? */ - bool receive_notify; - /* Is this a synchronous client? */ bool synchronous; + /* Auxiliary clients don't execute standard library handlers + * (which otherwise would duplicate VRF/interface add/delete/etc. + */ + bool auxiliary; + /* BFD enabled with bfd_protocol_integration_init() */ bool bfd_integration; @@ -342,6 +352,19 @@ struct zclient { void (*zebra_connected)(struct zclient *); void (*zebra_capabilities)(struct zclient_capabilities *cap); + /* + * match -> is the prefix that the calling daemon asked to be matched + * against. + * nhr->prefix -> is the actual prefix that was matched against in the + * rib itself. + * + * This distinction is made because a LPM can be made if there is a + * covering route. This way the upper level protocol can make a + * decision point about whether or not it wants to use the match or not. + */ + void (*nexthop_update)(struct vrf *vrf, struct prefix *match, + struct zapi_route *nhr); + int (*handle_error)(enum zebra_error_types error); /* @@ -431,7 +454,8 @@ struct zapi_nexthop { struct seg6local_context seg6local_ctx; /* SRv6 Headend-behaviour */ - struct in6_addr seg6_segs; + int seg_num; + struct in6_addr seg6_segs[SRV6_MAX_SEGS]; }; /* @@ -622,7 +646,7 @@ struct zapi_sr_policy { }; struct zapi_pw { - char ifname[INTERFACE_NAMSIZ]; + char ifname[IFNAMSIZ]; ifindex_t ifindex; int type; int af; @@ -635,7 +659,7 @@ struct zapi_pw { }; struct zapi_pw_status { - char ifname[INTERFACE_NAMSIZ]; + char ifname[IFNAMSIZ]; ifindex_t ifindex; uint32_t status; }; @@ -812,11 +836,18 @@ extern char *zclient_evpn_dump_macip_flags(uint8_t flags, char *buf, enum zebra_neigh_state { ZEBRA_NEIGH_INACTIVE = 0, ZEBRA_NEIGH_ACTIVE = 1 }; struct zclient_options { - bool receive_notify; bool synchronous; + + /* auxiliary = don't call common lib/ handlers that manage bits. + * Those should only run once, on the "main" zclient, which this is + * not. (This is also set for synchronous clients.) + */ + bool auxiliary; }; -extern struct zclient_options zclient_options_default; +extern const struct zclient_options zclient_options_default; +extern const struct zclient_options zclient_options_sync; +extern const struct zclient_options zclient_options_auxiliary; /* link layer representation for GRE like interfaces * ip_in is the underlay IP, ip_out is the tunnel dest @@ -858,12 +889,12 @@ int zclient_neigh_ip_encode(struct stream *s, uint16_t cmd, union sockunion *in, ((uint32_t)250000000) /* Bottom 28 bits then rounded down */ #define ZEBRA_NHG_PROTO_SPACING (ZEBRA_NHG_PROTO_UPPER / ZEBRA_ROUTE_MAX) #define ZEBRA_NHG_PROTO_LOWER \ - (ZEBRA_NHG_PROTO_SPACING * (ZEBRA_ROUTE_CONNECT + 1)) + (ZEBRA_NHG_PROTO_SPACING * (ZEBRA_ROUTE_LOCAL + 1)) extern uint32_t zclient_get_nhg_start(uint32_t proto); extern struct zclient *zclient_new(struct event_loop *m, - struct zclient_options *opt, + const struct zclient_options *opt, zclient_handler *const *handlers, size_t n_handlers); @@ -1012,9 +1043,6 @@ extern struct connected *zebra_interface_address_read(int, struct stream *, vrf_id_t); extern struct nbr_connected * zebra_interface_nbr_address_read(int, struct stream *, vrf_id_t); -extern struct interface *zebra_interface_vrf_update_read(struct stream *s, - vrf_id_t vrf_id, - vrf_id_t *new_vrf_id); extern int zebra_router_id_update_read(struct stream *s, struct prefix *rid); extern struct interface *zebra_interface_link_params_read(struct stream *s, @@ -1116,18 +1144,6 @@ int zapi_nexthop_from_nexthop(struct zapi_nexthop *znh, const struct nexthop *nh); int zapi_backup_nexthop_from_nexthop(struct zapi_nexthop *znh, const struct nexthop *nh); -/* - * match -> is the prefix that the calling daemon asked to be matched - * against. - * nhr->prefix -> is the actual prefix that was matched against in the - * rib itself. - * - * This distinction is made because a LPM can be made if there is a - * covering route. This way the upper level protocol can make a decision - * point about whether or not it wants to use the match or not. - */ -extern bool zapi_nexthop_update_decode(struct stream *s, struct prefix *match, - struct zapi_route *nhr); const char *zapi_nexthop2str(const struct zapi_nexthop *znh, char *buf, int bufsize); @@ -1150,6 +1166,15 @@ static inline void zapi_route_set_blackhole(struct zapi_route *api, SET_FLAG(api->message, ZAPI_MESSAGE_NEXTHOP); }; +static inline void zapi_route_set_nhg_id(struct zapi_route *api, + uint32_t *nhg_id) +{ + api->nexthop_num = 0; + api->nhgid = *nhg_id; + if (api->nhgid) + SET_FLAG(api->message, ZAPI_MESSAGE_NHG); +}; + extern enum zclient_send_status zclient_send_mlag_register(struct zclient *client, uint32_t bit_map); extern enum zclient_send_status @@ -1176,16 +1201,33 @@ zclient_send_opaque_unicast(struct zclient *zclient, uint32_t type, uint32_t session_id, const uint8_t *data, size_t datasize); +/* Init functions also provided for clients who want to encode their + * data inline into the zclient's stream buffer. Please use these instead + * of hand-encoding the header info, since that may change over time. + * Note that these will reset the zclient's outbound stream before encoding. + */ +enum zclient_send_status zapi_opaque_init(struct zclient *zclient, + uint32_t type, uint16_t flags); + +enum zclient_send_status +zapi_opaque_unicast_init(struct zclient *zclient, uint32_t type, uint16_t flags, + uint8_t proto, uint16_t instance, uint32_t session_id); + /* Struct representing the decoded opaque header info */ struct zapi_opaque_msg { uint32_t type; /* Subtype */ uint16_t len; /* len after zapi header and this info */ uint16_t flags; - /* Client-specific info - *if* UNICAST flag is set */ - uint8_t proto; - uint16_t instance; - uint32_t session_id; + /* Sending client info */ + uint8_t src_proto; + uint16_t src_instance; + uint32_t src_session_id; + + /* Destination client info - *if* UNICAST flag is set */ + uint8_t dest_proto; + uint16_t dest_instance; + uint32_t dest_session_id; }; #define ZAPI_OPAQUE_FLAG_UNICAST 0x01 @@ -1201,6 +1243,34 @@ struct zapi_opaque_reg_info { uint32_t session_id; }; +/* Simple struct conveying information about opaque notifications. + * Daemons can request notifications about the status of registration for + * opaque message types. For example, a client daemon can request notification + * when a server registers to receive a certain message code. Or a server can + * request notification when a subscriber registers for its output. + */ +struct zapi_opaque_notif_info { + bool request; /* Request to register, or notification from zebra */ + bool reg; /* Register or unregister */ + uint32_t msg_type; /* Target message code */ + + /* For notif registration, zapi info for the client. + * For notifications, zapi info for the message's server/registrant. + * For notification that there is no server/registrant, not present. + */ + uint8_t proto; + uint16_t instance; + uint32_t session_id; +}; + +/* The same ZAPI message is used for daemon->zebra requests, and for + * zebra->daemon notifications. + * Daemons send 'request' true, and 'reg' true or false. + * Zebra sends 'request' false, 'reg' set if the notification is a + * server/receiver registration for the message type, and false if the event + * is the end of registrations. + */ + /* Decode incoming opaque */ int zclient_opaque_decode(struct stream *msg, struct zapi_opaque_msg *info); @@ -1211,6 +1281,19 @@ enum zclient_send_status zclient_unregister_opaque(struct zclient *zclient, int zapi_opaque_reg_decode(struct stream *msg, struct zapi_opaque_reg_info *info); +/* Opaque notification features */ +enum zclient_send_status zclient_opaque_request_notify(struct zclient *zclient, + uint32_t msgtype); +enum zclient_send_status zclient_opaque_drop_notify(struct zclient *zclient, + uint32_t msgtype); + +/* Encode, decode an incoming zapi opaque notification */ +int zclient_opaque_notif_encode(struct stream *s, uint32_t msg_type, + bool reg /* register or unreg*/, uint8_t proto, + uint16_t instance, uint32_t session_id); +int zclient_opaque_notif_decode(struct stream *s, + struct zapi_opaque_notif_info *info); + /* * Registry of opaque message types. Please do not reuse an in-use * type code; some daemons are likely relying on it. diff --git a/lib/zebra.h b/lib/zebra.h index ecc87f58f1..8b0800c257 100644 --- a/lib/zebra.h +++ b/lib/zebra.h @@ -17,17 +17,9 @@ #include <stdlib.h> #include <stddef.h> #include <ctype.h> -#include <errno.h> -#include <fcntl.h> -#include <signal.h> -#include <string.h> -#include <pwd.h> -#include <grp.h> #ifdef HAVE_STROPTS_H #include <stropts.h> #endif /* HAVE_STROPTS_H */ -#include <sys/select.h> -#include <sys/stat.h> #include <sys/types.h> #include <sys/param.h> #ifdef HAVE_SYS_SYSCTL_H @@ -37,22 +29,15 @@ #include <sys/sysctl.h> #endif #endif /* HAVE_SYS_SYSCTL_H */ -#include <sys/ioctl.h> #ifdef HAVE_SYS_CONF_H #include <sys/conf.h> #endif /* HAVE_SYS_CONF_H */ #ifdef HAVE_SYS_KSYM_H #include <sys/ksym.h> #endif /* HAVE_SYS_KSYM_H */ -#include <syslog.h> #include <sys/time.h> #include <time.h> -#include <sys/uio.h> -#include <sys/utsname.h> -#include <sys/resource.h> -#include <limits.h> #include <inttypes.h> -#include <stdbool.h> #ifdef HAVE_SYS_ENDIAN_H #include <sys/endian.h> #endif @@ -63,11 +48,6 @@ /* misc include group */ #include <stdarg.h> -#ifdef HAVE_LCAPS -#include <sys/capability.h> -#include <sys/prctl.h> -#endif /* HAVE_LCAPS */ - /* network include group */ #include <sys/socket.h> @@ -76,10 +56,6 @@ #include <sys/sockio.h> #endif /* HAVE_SYS_SOCKIO_H */ -#ifdef __APPLE__ -#define __APPLE_USE_RFC_3542 -#endif - #ifndef HAVE_LIBCRYPT #ifdef HAVE_LIBCRYPTO #include <openssl/des.h> @@ -87,15 +63,9 @@ #endif #endif -#ifdef CRYPTO_OPENSSL -#include <openssl/evp.h> -#include <openssl/hmac.h> -#endif - #include "openbsd-tree.h" #include <netinet/in.h> -#include <netinet/in_systm.h> #include <netinet/ip.h> #include <netinet/tcp.h> @@ -113,14 +83,9 @@ #include <net/if_var.h> #endif /* HAVE_NET_IF_VAR_H */ -#include <net/route.h> - -#ifdef HAVE_NETLINK -#include <linux/netlink.h> -#include <linux/rtnetlink.h> -#include <linux/filter.h> -#else +#ifndef HAVE_NETLINK #define RT_TABLE_MAIN 0 +#define RT_TABLE_LOCAL RT_TABLE_MAIN #endif /* HAVE_NETLINK */ #include <netdb.h> @@ -146,37 +111,14 @@ #include <netinet6/in.h> #endif /* HAVE_NETINET6_IN_H */ - #ifdef HAVE_NETINET6_IP6_H #include <netinet6/ip6.h> #endif /* HAVE_NETINET6_IP6_H */ -#include <netinet/icmp6.h> - #ifdef HAVE_NETINET6_ND6_H #include <netinet6/nd6.h> #endif /* HAVE_NETINET6_ND6_H */ -/* Some systems do not define UINT32_MAX, etc.. from inttypes.h - * e.g. this makes life easier for FBSD 4.11 users. - */ -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#ifdef HAVE_GLIBC_BACKTRACE -#include <execinfo.h> -#endif /* HAVE_GLIBC_BACKTRACE */ - /* Local includes: */ #if !defined(__GNUC__) #define __attribute__(x) @@ -210,26 +152,6 @@ size_t strlcpy(char *__restrict dest, void explicit_bzero(void *buf, size_t len); #endif -#if !defined(HAVE_STRUCT_MMSGHDR_MSG_HDR) || !defined(HAVE_SENDMMSG) -/* avoid conflicts in case we have partial support */ -#define mmsghdr frr_mmsghdr -#define sendmmsg frr_sendmmsg - -struct mmsghdr { - struct msghdr msg_hdr; - unsigned int msg_len; -}; - -/* just go 1 at a time here, the loop this is used in will handle the rest */ -static inline int sendmmsg(int fd, struct mmsghdr *mmh, unsigned int len, - int flags) -{ - int rv = sendmsg(fd, &mmh->msg_hdr, 0); - - return rv > 0 ? 1 : rv; -} -#endif - /* * RFC 3542 defines several macros for using struct cmsghdr. * Here, we define those that are not present @@ -283,10 +205,9 @@ struct in_pktinfo { * OpenBSD: network byte order, apart from older versions which are as per * *BSD */ -#if defined(__NetBSD__) \ - || (defined(__FreeBSD__) && (__FreeBSD_version < 1100030)) \ - || (defined(__OpenBSD__) && (OpenBSD < 200311)) \ - || (defined(__APPLE__)) +#if defined(__NetBSD__) || \ + (defined(__FreeBSD__) && (__FreeBSD_version < 1100030)) || \ + (defined(__OpenBSD__) && (OpenBSD < 200311)) #define HAVE_IP_HDRINCL_BSD_ORDER #endif @@ -303,12 +224,6 @@ struct in_pktinfo { /* default zebra TCP port for zclient */ #define ZEBRA_PORT 2600 -/* - * The compiler.h header is used for anyone using the CPP_NOTICE - * since this is universally needed, let's add it to zebra.h - */ -#include "compiler.h" - /* Zebra route's types are defined in route_types.h */ #include "lib/route_types.h" @@ -358,27 +273,6 @@ typedef enum { for (afi = AFI_IP; afi < AFI_MAX; afi++) \ for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) -/* Default Administrative Distance of each protocol. */ -#define ZEBRA_KERNEL_DISTANCE_DEFAULT 0 -#define ZEBRA_CONNECT_DISTANCE_DEFAULT 0 -#define ZEBRA_STATIC_DISTANCE_DEFAULT 1 -#define ZEBRA_RIP_DISTANCE_DEFAULT 120 -#define ZEBRA_RIPNG_DISTANCE_DEFAULT 120 -#define ZEBRA_OSPF_DISTANCE_DEFAULT 110 -#define ZEBRA_OSPF6_DISTANCE_DEFAULT 110 -#define ZEBRA_ISIS_DISTANCE_DEFAULT 115 -#define ZEBRA_IBGP_DISTANCE_DEFAULT 200 -#define ZEBRA_EBGP_DISTANCE_DEFAULT 20 -#define ZEBRA_TABLE_DISTANCE_DEFAULT 15 -#define ZEBRA_EIGRP_DISTANCE_DEFAULT 90 -#define ZEBRA_NHRP_DISTANCE_DEFAULT 10 -#define ZEBRA_LDP_DISTANCE_DEFAULT 150 -#define ZEBRA_BABEL_DISTANCE_DEFAULT 100 -#define ZEBRA_SHARP_DISTANCE_DEFAULT 150 -#define ZEBRA_PBR_DISTANCE_DEFAULT 200 -#define ZEBRA_OPENFABRIC_DISTANCE_DEFAULT 115 -#define ZEBRA_MAX_DISTANCE_DEFAULT 255 - /* Flag manipulation macros. */ #define CHECK_FLAG(V,F) ((V) & (F)) #define SET_FLAG(V,F) (V) |= (F) diff --git a/lib/zlog.c b/lib/zlog.c index 309a955fa9..77592c33ff 100644 --- a/lib/zlog.c +++ b/lib/zlog.c @@ -4,6 +4,12 @@ */ #include "zebra.h" +#include <sys/stat.h> +#include <fcntl.h> + +#ifdef HAVE_GLIBC_BACKTRACE +#include <execinfo.h> +#endif /* HAVE_GLIBC_BACKTRACE */ #include <unistd.h> #include <sys/time.h> @@ -32,9 +38,6 @@ #ifdef __DragonFly__ #include <sys/lwp.h> #endif -#ifdef __APPLE__ -#include <mach/mach_traps.h> -#endif #ifdef HAVE_LIBUNWIND #define UNW_LOCAL_ONLY diff --git a/lib/zlog_5424.c b/lib/zlog_5424.c index c15bdece29..4c60d4b405 100644 --- a/lib/zlog_5424.c +++ b/lib/zlog_5424.c @@ -13,6 +13,9 @@ */ #include "zebra.h" +#include <fcntl.h> + +#include "frrsendmmsg.h" #include "zlog_5424.h" @@ -877,10 +880,15 @@ static int zlog_5424_open(struct zlog_cfg_5424 *zcf, int sock_type) switch (zcf->dst) { case ZLOG_5424_DST_NONE: - break; + return -1; case ZLOG_5424_DST_FD: fd = dup(zcf->fd); + if (fd < 0) { + flog_err_sys(EC_LIB_SYSTEM_CALL, + "failed to dup() log file descriptor: %m (FD limit too low?)"); + return -1; + } optlen = sizeof(sock_type); if (!getsockopt(fd, SOL_SOCKET, SO_TYPE, &sock_type, &optlen)) { @@ -891,7 +899,7 @@ static int zlog_5424_open(struct zlog_cfg_5424 *zcf, int sock_type) case ZLOG_5424_DST_FIFO: if (!zcf->filename) - break; + return -1; if (!zcf->file_nocreate) { frr_with_privs (lib_privs) { @@ -904,15 +912,15 @@ static int zlog_5424_open(struct zlog_cfg_5424 *zcf, int sock_type) if (err == 0) do_chown = true; else if (errno != EEXIST) - break; + return -1; } flags = O_NONBLOCK; - /* fallthru */ + fallthrough; case ZLOG_5424_DST_FILE: if (!zcf->filename) - break; + return -1; frr_with_privs (lib_privs) { fd = open(zcf->filename, flags | O_WRONLY | O_APPEND | @@ -924,7 +932,7 @@ static int zlog_5424_open(struct zlog_cfg_5424 *zcf, int sock_type) flog_err_sys(EC_LIB_SYSTEM_CALL, "could not open log file %pSE: %m", zcf->filename); - break; + return -1; } frr_with_privs (lib_privs) { @@ -952,11 +960,11 @@ static int zlog_5424_open(struct zlog_cfg_5424 *zcf, int sock_type) flog_err_sys(EC_LIB_SYSTEM_CALL, "could not open or create log file %pSE: %m", zcf->filename); - break; + return -1; case ZLOG_5424_DST_UNIX: if (!zcf->filename) - break; + return -1; memset(&sa, 0, sizeof(sa)); sa.sun_family = AF_UNIX; @@ -988,6 +996,7 @@ static int zlog_5424_open(struct zlog_cfg_5424 *zcf, int sock_type) "could not connect to log unix path %pSE: %m", zcf->filename); need_reconnect = true; + /* no return -1 here, trigger retry code below */ } else { /* datagram sockets are connectionless, restarting * the receiver may lose some packets but will resume diff --git a/lib/zlog_live.c b/lib/zlog_live.c index 4d3c3508bf..1b7696c893 100644 --- a/lib/zlog_live.c +++ b/lib/zlog_live.c @@ -5,6 +5,8 @@ #include "zebra.h" +#include "frrsendmmsg.h" + #include "zlog_live.h" #include "memory.h" diff --git a/lib/zlog_targets.c b/lib/zlog_targets.c index b0f7571492..bbd228f28c 100644 --- a/lib/zlog_targets.c +++ b/lib/zlog_targets.c @@ -5,6 +5,7 @@ #include "zebra.h" +#include <fcntl.h> #include <sys/un.h> #include <syslog.h> diff --git a/mgmtd/mgmt.c b/mgmtd/mgmt.c index 77c4473e49..8d41643065 100644 --- a/mgmtd/mgmt.c +++ b/mgmtd/mgmt.c @@ -52,17 +52,26 @@ void mgmt_init(void) /* Initialize the MGMTD Frontend Adapter Module */ mgmt_fe_adapter_init(mm->master); - /* Initialize the CLI frontend client */ + /* + * Initialize the CLI frontend client -- this queues an event for the + * client to short-circuit connect to the server (ourselves). + */ vty_init_mgmt_fe(); - /* MGMTD VTY commands installation. */ + /* + * MGMTD VTY commands installation -- the frr lib code will queue an + * event to read the config files which needs to happen after the + * connect from above is made. + */ mgmt_vty_init(); /* * Initialize the MGMTD Backend Adapter Module * - * We do this after the FE stuff so that we always read our config file - * prior to any BE connection. + * We do this after the FE stuff so that we have read our config file + * prior to any BE connection. Setting up the server will queue a + * "socket read" event to accept BE connections. So the code is counting + * on the above 2 events to run prior to any `accept` event from here. */ mgmt_be_adapter_init(mm->master); } diff --git a/mgmtd/mgmt.h b/mgmtd/mgmt.h index f52d478bc2..d46b1341ec 100644 --- a/mgmtd/mgmt.h +++ b/mgmtd/mgmt.h @@ -13,14 +13,14 @@ #include "vrf.h" #include "defaults.h" #include "stream.h" +#include "mgmt_defines.h" #include "mgmtd/mgmt_memory.h" -#include "mgmtd/mgmt_defines.h" #include "mgmtd/mgmt_history.h" #include "mgmtd/mgmt_txn.h" #include "mgmtd/mgmt_ds.h" -#define MGMTD_VTY_PORT 2622 +#define MGMTD_VTY_PORT 2623 #define MGMTD_SOCKET_BUF_SIZE 65535 #define MGMTD_MAX_COMMIT_LIST 10 @@ -70,11 +70,6 @@ struct mgmt_master { extern struct mgmt_master *mm; /* Inline functions */ -static inline unsigned long timeval_elapsed(struct timeval a, struct timeval b) -{ - return (((a.tv_sec - b.tv_sec) * TIMER_SECOND_MICRO) - + (a.tv_usec - b.tv_usec)); -} /* * Remove trailing separator from a string. diff --git a/mgmtd/mgmt_be_adapter.c b/mgmtd/mgmt_be_adapter.c index 2d01f8ecad..eb6e79f2a5 100644 --- a/mgmtd/mgmt_be_adapter.c +++ b/mgmtd/mgmt_be_adapter.c @@ -8,11 +8,14 @@ */ #include <zebra.h> +#include "darr.h" #include "frrevent.h" +#include "frrstr.h" #include "sockopt.h" #include "network.h" #include "libfrr.h" #include "mgmt_msg.h" +#include "mgmt_msg_native.h" #include "mgmt_pb.h" #include "mgmtd/mgmt.h" #include "mgmtd/mgmt_memory.h" @@ -20,137 +23,79 @@ #include "mgmtd/mgmt_be_adapter.h" #define MGMTD_BE_ADAPTER_DBG(fmt, ...) \ - DEBUGD(&mgmt_debug_be, "BE-ADAPTER: %s:" fmt, __func__, ##__VA_ARGS__) + DEBUGD(&mgmt_debug_be, "BE-ADAPTER: %s: " fmt, __func__, ##__VA_ARGS__) #define MGMTD_BE_ADAPTER_ERR(fmt, ...) \ zlog_err("BE-ADAPTER: %s: ERROR: " fmt, __func__, ##__VA_ARGS__) #define FOREACH_ADAPTER_IN_LIST(adapter) \ frr_each_safe (mgmt_be_adapters, &mgmt_be_adapters, (adapter)) -/* - * Static mapping of YANG XPath regular expressions and - * the corresponding interested backend clients. - * NOTE: Thiis is a static mapping defined by all MGMTD - * backend client modules (for now, till we develop a - * more dynamic way of creating and updating this map). - * A running map is created by MGMTD in run-time to - * handle real-time mapping of YANG xpaths to one or - * more interested backend client adapters. - * - * Please see xpath_map_reg[] in lib/mgmt_be_client.c - * for the actual map - */ -struct mgmt_be_xpath_map_init { - const char *xpath_regexp; - uint subscr_info[MGMTD_BE_CLIENT_ID_MAX]; -}; +/* ---------- */ +/* Client IDs */ +/* ---------- */ -struct mgmt_be_xpath_map { - char *xpath_regexp; - uint subscr_info[MGMTD_BE_CLIENT_ID_MAX]; -}; - -struct mgmt_be_client_xpath { - const char *xpath; - uint subscribed; -}; - -struct mgmt_be_client_xpath_map { - struct mgmt_be_client_xpath *xpaths; - uint nxpaths; +const char *mgmt_be_client_names[MGMTD_BE_CLIENT_ID_MAX + 1] = { + [MGMTD_BE_CLIENT_ID_ZEBRA] = "zebra", +#ifdef HAVE_STATICD + [MGMTD_BE_CLIENT_ID_STATICD] = "staticd", +#endif + [MGMTD_BE_CLIENT_ID_MAX] = "Unknown/Invalid", }; -struct mgmt_be_get_adapter_config_params { - struct mgmt_be_client_adapter *adapter; - struct nb_config_cbs *cfg_chgs; - uint32_t seq; -}; +/* ------------- */ +/* XPATH MAPPING */ +/* ------------- */ /* - * Static mapping of YANG XPath regular expressions and - * the corresponding interested backend clients. - * NOTE: Thiis is a static mapping defined by all MGMTD - * backend client modules (for now, till we develop a - * more dynamic way of creating and updating this map). - * A running map is created by MGMTD in run-time to - * handle real-time mapping of YANG xpaths to one or - * more interested backend client adapters. + * Mapping of YANG XPath prefixes to their corresponding backend clients. */ -static const struct mgmt_be_xpath_map_init mgmt_xpath_map_init[] = { - { - .xpath_regexp = "/frr-vrf:lib/*", - .subscr_info = - { -#if HAVE_STATICD - [MGMTD_BE_CLIENT_ID_STATICD] = - MGMT_SUBSCR_VALIDATE_CFG | - MGMT_SUBSCR_NOTIFY_CFG, -#endif - }, - }, - { - .xpath_regexp = "/frr-interface:lib/*", - .subscr_info = - { -#if HAVE_STATICD - [MGMTD_BE_CLIENT_ID_STATICD] = - MGMT_SUBSCR_VALIDATE_CFG | - MGMT_SUBSCR_NOTIFY_CFG, -#endif - }, - }, - - { - .xpath_regexp = - "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/*", - .subscr_info = - { -#if HAVE_STATICD - [MGMTD_BE_CLIENT_ID_STATICD] = - MGMT_SUBSCR_VALIDATE_CFG | - MGMT_SUBSCR_NOTIFY_CFG, -#endif - }, - }, +struct mgmt_be_xpath_map { + char *xpath_prefix; + uint64_t clients; }; - /* * Each client gets their own map, but also union all the strings into the * above map as well. */ #if HAVE_STATICD -static struct mgmt_be_client_xpath staticd_xpaths[] = { - { - .xpath = "/frr-vrf:lib/*", - .subscribed = MGMT_SUBSCR_VALIDATE_CFG | MGMT_SUBSCR_NOTIFY_CFG, - }, - { - .xpath = "/frr-interface:lib/*", - .subscribed = MGMT_SUBSCR_VALIDATE_CFG | MGMT_SUBSCR_NOTIFY_CFG, - }, - { - .xpath = - "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/*", - .subscribed = MGMT_SUBSCR_VALIDATE_CFG | MGMT_SUBSCR_NOTIFY_CFG, - }, +static const char *const staticd_xpaths[] = { + "/frr-vrf:lib", + "/frr-interface:lib", + "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd", + NULL, }; #endif -static struct mgmt_be_client_xpath_map - mgmt_client_xpaths[MGMTD_BE_CLIENT_ID_MAX] = { +static const char *const *be_client_xpaths[MGMTD_BE_CLIENT_ID_MAX] = { + #ifdef HAVE_STATICD - [MGMTD_BE_CLIENT_ID_STATICD] = {staticd_xpaths, - array_size(staticd_xpaths)}, + [MGMTD_BE_CLIENT_ID_STATICD] = staticd_xpaths, #endif }; -#define MGMTD_BE_MAX_NUM_XPATH_MAP 256 +static const char *const zebra_oper_xpaths[] = { + "/frr-interface:lib/interface", + "/frr-vrf:lib/vrf/frr-zebra:zebra", + "/frr-zebra:zebra", + NULL, +}; -/* We would like to have a better ADT than one with O(n) - comparisons */ -static struct mgmt_be_xpath_map *mgmt_xpath_map; -static uint mgmt_num_xpath_maps; +static const char *const *be_client_oper_xpaths[MGMTD_BE_CLIENT_ID_MAX] = { + [MGMTD_BE_CLIENT_ID_ZEBRA] = zebra_oper_xpaths, +}; + +/* + * We would like to have a better ADT than one with O(n) comparisons + * + * Perhaps it's possible to sort this array in a way that allows binary search + * to find the start, then walk until no possible match can follow? Intuition + * says this probably involves exact match/no-match on a stem in the map array + * or something like that. + */ + +static struct mgmt_be_xpath_map *be_cfg_xpath_map; +static struct mgmt_be_xpath_map *be_oper_xpath_map; static struct event_loop *mgmt_loop; static struct msg_server mgmt_be_server = {.fd = -1}; @@ -160,12 +105,33 @@ static struct mgmt_be_adapters_head mgmt_be_adapters; static struct mgmt_be_client_adapter *mgmt_be_adapters_by_id[MGMTD_BE_CLIENT_ID_MAX]; + /* Forward declarations */ static void mgmt_be_adapter_sched_init_event(struct mgmt_be_client_adapter *adapter); -static uint mgmt_be_get_subscr_for_xpath_and_client( - const char *xpath, enum mgmt_be_client_id client_id, uint subscr_mask); +static bool be_is_client_interested(const char *xpath, + enum mgmt_be_client_id id, bool config); + +const char *mgmt_be_client_id2name(enum mgmt_be_client_id id) +{ + if (id > MGMTD_BE_CLIENT_ID_MAX) + return "invalid client id"; + return mgmt_be_client_names[id]; +} + +static enum mgmt_be_client_id mgmt_be_client_name2id(const char *name) +{ + enum mgmt_be_client_id id; + + FOREACH_MGMTD_BE_CLIENT_ID (id) { + if (!strncmp(mgmt_be_client_names[id], name, + MGMTD_CLIENT_NAME_MAX_LEN)) + return id; + } + + return MGMTD_BE_CLIENT_ID_MAX; +} static struct mgmt_be_client_adapter * mgmt_be_find_adapter_by_fd(int conn_fd) @@ -193,161 +159,92 @@ mgmt_be_find_adapter_by_name(const char *name) return NULL; } -static void mgmt_be_xpath_map_init(void) +static void mgmt_register_client_xpath(enum mgmt_be_client_id id, + const char *xpath, bool config) { - uint i; + struct mgmt_be_xpath_map **maps, *map; - MGMTD_BE_ADAPTER_DBG("Init XPath Maps"); + maps = config ? &be_cfg_xpath_map : &be_oper_xpath_map; - mgmt_num_xpath_maps = array_size(mgmt_xpath_map_init); - mgmt_xpath_map = - calloc(1, sizeof(*mgmt_xpath_map) * mgmt_num_xpath_maps); - for (i = 0; i < mgmt_num_xpath_maps; i++) { - MGMTD_BE_ADAPTER_DBG(" - XPATH: '%s'", - mgmt_xpath_map_init[i].xpath_regexp); - mgmt_xpath_map[i].xpath_regexp = XSTRDUP( - MTYPE_MGMTD_XPATH, mgmt_xpath_map_init[i].xpath_regexp); - memcpy(mgmt_xpath_map[i].subscr_info, - mgmt_xpath_map_init[i].subscr_info, - sizeof(mgmt_xpath_map_init[i].subscr_info)); + darr_foreach_p (*maps, map) { + if (!strcmp(xpath, map->xpath_prefix)) { + map->clients |= (1u << id); + return; + } } - MGMTD_BE_ADAPTER_DBG("Total XPath Maps: %u", mgmt_num_xpath_maps); + /* we didn't find a matching entry */ + map = darr_append(*maps); + map->xpath_prefix = XSTRDUP(MTYPE_MGMTD_XPATH, xpath); + map->clients = (1ul << id); } -static void mgmt_be_xpath_map_cleanup(void) +/* + * initial the combined maps from per client maps + */ +static void mgmt_be_xpath_map_init(void) { - uint i; + enum mgmt_be_client_id id; + const char *const *init; - for (i = 0; i < mgmt_num_xpath_maps; i++) - XFREE(MTYPE_MGMTD_XPATH, mgmt_xpath_map[i].xpath_regexp); - free(mgmt_xpath_map); -} + MGMTD_BE_ADAPTER_DBG("Init XPath Maps"); -static int mgmt_be_eval_regexp_match(const char *xpath_regexp, - const char *xpath) -{ - int match_len = 0, re_indx = 0, xp_indx = 0; - int rexp_len, xpath_len; - bool match = true, re_wild = false, xp_wild = false; - bool delim = false, enter_wild_match = false; - char wild_delim = 0; + FOREACH_MGMTD_BE_CLIENT_ID (id) { + /* Initialize the common config init map */ + for (init = be_client_xpaths[id]; init && *init; init++) { + MGMTD_BE_ADAPTER_DBG(" - CFG XPATH: '%s'", *init); + mgmt_register_client_xpath(id, *init, true); + } - rexp_len = strlen(xpath_regexp); - xpath_len = strlen(xpath); + /* Initialize the common oper init map */ + for (init = be_client_oper_xpaths[id]; init && *init; init++) { + MGMTD_BE_ADAPTER_DBG(" - OPER XPATH: '%s'", *init); + mgmt_register_client_xpath(id, *init, false); + } + } - /* - * Remove the trailing wildcard from the regexp and Xpath. - */ - if (rexp_len && xpath_regexp[rexp_len-1] == '*') - rexp_len--; - if (xpath_len && xpath[xpath_len-1] == '*') - xpath_len--; + MGMTD_BE_ADAPTER_DBG("Total Cfg XPath Maps: %u", + darr_len(be_cfg_xpath_map)); + MGMTD_BE_ADAPTER_DBG("Total Oper XPath Maps: %u", + darr_len(be_oper_xpath_map)); +} - if (!rexp_len || !xpath_len) - return 0; +static void mgmt_be_xpath_map_cleanup(void) +{ + struct mgmt_be_xpath_map *map; - for (re_indx = 0, xp_indx = 0; - match && re_indx < rexp_len && xp_indx < xpath_len;) { - match = (xpath_regexp[re_indx] == xpath[xp_indx]); + darr_foreach_p (be_cfg_xpath_map, map) + XFREE(MTYPE_MGMTD_XPATH, map->xpath_prefix); + darr_free(be_cfg_xpath_map); - /* - * Check if we need to enter wildcard matching. - */ - if (!enter_wild_match && !match && - (xpath_regexp[re_indx] == '*' - || xpath[xp_indx] == '*')) { - /* - * Found wildcard - */ - enter_wild_match = - (xpath_regexp[re_indx-1] == '/' - || xpath_regexp[re_indx-1] == '\'' - || xpath[xp_indx-1] == '/' - || xpath[xp_indx-1] == '\''); - if (enter_wild_match) { - if (xpath_regexp[re_indx] == '*') { - /* - * Begin RE wildcard match. - */ - re_wild = true; - wild_delim = xpath_regexp[re_indx-1]; - } else if (xpath[xp_indx] == '*') { - /* - * Begin XP wildcard match. - */ - xp_wild = true; - wild_delim = xpath[xp_indx-1]; - } - } - } + darr_foreach_p (be_oper_xpath_map, map) + XFREE(MTYPE_MGMTD_XPATH, map->xpath_prefix); + darr_free(be_oper_xpath_map); +} - /* - * Check if we need to exit wildcard matching. - */ - if (enter_wild_match) { - if (re_wild && xpath[xp_indx] == wild_delim) { - /* - * End RE wildcard matching. - */ - re_wild = false; - if (re_indx < rexp_len-1) - re_indx++; - enter_wild_match = false; - } else if (xp_wild - && xpath_regexp[re_indx] == wild_delim) { - /* - * End XP wildcard matching. - */ - xp_wild = false; - if (xp_indx < xpath_len-1) - xp_indx++; - enter_wild_match = false; - } - } - match = (xp_wild || re_wild - || xpath_regexp[re_indx] == xpath[xp_indx]); +/* + * Check if either path or xpath is a prefix of the other. Before checking the + * xpath is converted to a regular path string (e..g, removing key value + * specifiers). + */ +static bool mgmt_be_xpath_prefix(const char *path, const char *xpath) +{ + int xc, pc; - /* - * Check if we found a delimiter in both the Xpaths - */ - if ((xpath_regexp[re_indx] == '/' - && xpath[xp_indx] == '/') - || (xpath_regexp[re_indx] == ']' - && xpath[xp_indx] == ']') - || (xpath_regexp[re_indx] == '[' - && xpath[xp_indx] == '[')) { - /* - * Increment the match count if we have a - * new delimiter. - */ - if (match && re_indx && xp_indx && !delim) - match_len++; - delim = true; - } else { - delim = false; + while ((xc = *xpath++)) { + if (xc == '[') { + xpath = frrstr_skip_over_char(xpath, ']'); + if (!xpath) + return false; + continue; } - - /* - * Proceed to the next character in the RE/XP string as - * necessary. - */ - if (!re_wild) - re_indx++; - if (!xp_wild) - xp_indx++; + pc = *path++; + if (!pc) + return true; + if (pc != xc) + return false; } - - /* - * If we finished matching and the last token was a full match - * increment the match count appropriately. - */ - if (match && !delim && - (xpath_regexp[re_indx] == '/' - || xpath_regexp[re_indx] == ']')) - match_len++; - - return match_len; + return true; } static void mgmt_be_adapter_delete(struct mgmt_be_client_adapter *adapter) @@ -400,7 +297,6 @@ mgmt_be_adapter_cleanup_old_conn(struct mgmt_be_client_adapter *adapter) } } - static int mgmt_be_adapter_send_msg(struct mgmt_be_client_adapter *adapter, Mgmtd__BeMessage *be_msg) { @@ -492,9 +388,8 @@ mgmt_be_adapter_handle_msg(struct mgmt_be_client_adapter *adapter, case MGMTD__BE_MESSAGE__MESSAGE_CFG_DATA_REPLY: MGMTD_BE_ADAPTER_DBG( "Got CFGDATA_REPLY from '%s' txn-id %" PRIx64 - " batch-id %" PRIu64 " err:'%s'", - adapter->name, be_msg->cfg_data_reply->txn_id, - be_msg->cfg_data_reply->batch_id, + " err:'%s'", adapter->name, + be_msg->cfg_data_reply->txn_id, be_msg->cfg_data_reply->error_if_any ? be_msg->cfg_data_reply->error_if_any : "None"); @@ -503,21 +398,16 @@ mgmt_be_adapter_handle_msg(struct mgmt_be_client_adapter *adapter, */ mgmt_txn_notify_be_cfgdata_reply( be_msg->cfg_data_reply->txn_id, - be_msg->cfg_data_reply->batch_id, be_msg->cfg_data_reply->success, be_msg->cfg_data_reply->error_if_any, adapter); break; case MGMTD__BE_MESSAGE__MESSAGE_CFG_APPLY_REPLY: MGMTD_BE_ADAPTER_DBG( "Got %s CFG_APPLY_REPLY from '%s' txn-id %" PRIx64 - " for %zu batches id %" PRIu64 "-%" PRIu64 " err:'%s'", + " err:'%s'", be_msg->cfg_apply_reply->success ? "successful" : "failed", adapter->name, be_msg->cfg_apply_reply->txn_id, - be_msg->cfg_apply_reply->n_batch_ids, - be_msg->cfg_apply_reply->batch_ids[0], - be_msg->cfg_apply_reply->batch_ids - [be_msg->cfg_apply_reply->n_batch_ids - 1], be_msg->cfg_apply_reply->error_if_any ? be_msg->cfg_apply_reply->error_if_any : "None"); @@ -527,29 +417,16 @@ mgmt_be_adapter_handle_msg(struct mgmt_be_client_adapter *adapter, mgmt_txn_notify_be_cfg_apply_reply( be_msg->cfg_apply_reply->txn_id, be_msg->cfg_apply_reply->success, - (uint64_t *)be_msg->cfg_apply_reply->batch_ids, - be_msg->cfg_apply_reply->n_batch_ids, be_msg->cfg_apply_reply->error_if_any, adapter); break; - case MGMTD__BE_MESSAGE__MESSAGE_GET_REPLY: - case MGMTD__BE_MESSAGE__MESSAGE_CFG_CMD_REPLY: - case MGMTD__BE_MESSAGE__MESSAGE_SHOW_CMD_REPLY: - case MGMTD__BE_MESSAGE__MESSAGE_NOTIFY_DATA: - /* - * TODO: Add handling code in future. - */ - break; /* * NOTE: The following messages are always sent from MGMTD to * Backend clients only and/or need not be handled on MGMTd. */ case MGMTD__BE_MESSAGE__MESSAGE_SUBSCR_REPLY: - case MGMTD__BE_MESSAGE__MESSAGE_GET_REQ: case MGMTD__BE_MESSAGE__MESSAGE_TXN_REQ: case MGMTD__BE_MESSAGE__MESSAGE_CFG_DATA_REQ: case MGMTD__BE_MESSAGE__MESSAGE_CFG_APPLY_REQ: - case MGMTD__BE_MESSAGE__MESSAGE_CFG_CMD_REQ: - case MGMTD__BE_MESSAGE__MESSAGE_SHOW_CMD_REQ: case MGMTD__BE_MESSAGE__MESSAGE__NOT_SET: default: /* @@ -564,8 +441,8 @@ mgmt_be_adapter_handle_msg(struct mgmt_be_client_adapter *adapter, return 0; } -static int mgmt_be_send_txn_req(struct mgmt_be_client_adapter *adapter, - uint64_t txn_id, bool create) +int mgmt_be_send_txn_req(struct mgmt_be_client_adapter *adapter, + uint64_t txn_id, bool create) { Mgmtd__BeMessage be_msg; Mgmtd__BeTxnReq txn_req; @@ -584,17 +461,15 @@ static int mgmt_be_send_txn_req(struct mgmt_be_client_adapter *adapter, return mgmt_be_adapter_send_msg(adapter, &be_msg); } -static int -mgmt_be_send_cfgdata_create_req(struct mgmt_be_client_adapter *adapter, - uint64_t txn_id, uint64_t batch_id, - Mgmtd__YangCfgDataReq **cfgdata_reqs, - size_t num_reqs, bool end_of_data) +int mgmt_be_send_cfgdata_req(struct mgmt_be_client_adapter *adapter, + uint64_t txn_id, + Mgmtd__YangCfgDataReq **cfgdata_reqs, + size_t num_reqs, bool end_of_data) { Mgmtd__BeMessage be_msg; Mgmtd__BeCfgDataCreateReq cfgdata_req; mgmtd__be_cfg_data_create_req__init(&cfgdata_req); - cfgdata_req.batch_id = batch_id; cfgdata_req.txn_id = txn_id; cfgdata_req.data_req = cfgdata_reqs; cfgdata_req.n_data_req = num_reqs; @@ -606,14 +481,14 @@ mgmt_be_send_cfgdata_create_req(struct mgmt_be_client_adapter *adapter, MGMTD_BE_ADAPTER_DBG( "Sending CFGDATA_CREATE_REQ to '%s' txn-id: %" PRIu64 - " batch-id: %" PRIu64, - adapter->name, txn_id, batch_id); + " last: %s", + adapter->name, txn_id, end_of_data ? "yes" : "no"); return mgmt_be_adapter_send_msg(adapter, &be_msg); } -static int mgmt_be_send_cfgapply_req(struct mgmt_be_client_adapter *adapter, - uint64_t txn_id) +int mgmt_be_send_cfgapply_req(struct mgmt_be_client_adapter *adapter, + uint64_t txn_id) { Mgmtd__BeMessage be_msg; Mgmtd__BeCfgDataApplyReq apply_req; @@ -631,12 +506,77 @@ static int mgmt_be_send_cfgapply_req(struct mgmt_be_client_adapter *adapter, return mgmt_be_adapter_send_msg(adapter, &be_msg); } +int mgmt_be_send_native(enum mgmt_be_client_id id, void *msg) +{ + struct mgmt_be_client_adapter *adapter = mgmt_be_get_adapter_by_id(id); + + if (!adapter) + return -1; + + return mgmt_msg_native_send_msg(adapter->conn, msg, false); +} + +/* + * Handle a native encoded message + */ +static void be_adapter_handle_native_msg(struct mgmt_be_client_adapter *adapter, + struct mgmt_msg_header *msg, + size_t msg_len) +{ + struct mgmt_msg_tree_data *tree_msg; + struct mgmt_msg_error *error_msg; + + /* get the transaction */ + + switch (msg->code) { + case MGMT_MSG_CODE_ERROR: + error_msg = (typeof(error_msg))msg; + MGMTD_BE_ADAPTER_DBG("Got ERROR from '%s' txn-id %" PRIx64, + adapter->name, msg->refer_id); + + /* Forward the reply to the txn module */ + mgmt_txn_notify_error(adapter, msg->refer_id, msg->req_id, + error_msg->error, error_msg->errstr); + + break; + case MGMT_MSG_CODE_TREE_DATA: + /* tree data from a backend client */ + tree_msg = (typeof(tree_msg))msg; + MGMTD_BE_ADAPTER_DBG("Got TREE_DATA from '%s' txn-id %" PRIx64, + adapter->name, msg->refer_id); + + /* Forward the reply to the txn module */ + mgmt_txn_notify_tree_data_reply(adapter, tree_msg, msg_len); + break; + default: + MGMTD_BE_ADAPTER_ERR("unknown native message txn-id %" PRIu64 + " req-id %" PRIu64 + " code %u from BE client for adapter %s", + msg->refer_id, msg->req_id, msg->code, + adapter->name); + break; + } +} + + static void mgmt_be_adapter_process_msg(uint8_t version, uint8_t *data, size_t len, struct msg_conn *conn) { struct mgmt_be_client_adapter *adapter = conn->user; - Mgmtd__BeMessage *be_msg = mgmtd__be_message__unpack(NULL, len, data); + Mgmtd__BeMessage *be_msg; + + if (version == MGMT_MSG_VERSION_NATIVE) { + struct mgmt_msg_header *msg = (typeof(msg))data; + if (len >= sizeof(*msg)) + be_adapter_handle_native_msg(adapter, msg, len); + else + MGMTD_BE_ADAPTER_ERR("native message to adapter %s too short %zu", + adapter->name, len); + return; + } + + be_msg = mgmtd__be_message__unpack(NULL, len, data); if (!be_msg) { MGMTD_BE_ADAPTER_DBG( "Failed to decode %zu bytes for adapter: %s", len, @@ -649,17 +589,26 @@ static void mgmt_be_adapter_process_msg(uint8_t version, uint8_t *data, mgmtd__be_message__free_unpacked(be_msg, NULL); } -static void mgmt_be_iter_and_get_cfg(struct mgmt_ds_ctx *ds_ctx, - const char *xpath, struct lyd_node *node, +/* + * Args for callback + */ +struct mgmt_be_get_adapter_config_params { + struct mgmt_be_client_adapter *adapter; + struct nb_config_cbs *cfg_chgs; + uint32_t seq; +}; + +/* + * Callback to store the change a node in the datastore if it should be sync'd + * to the adapter (i.e., if the adapter is subscribed to it). + */ +static void mgmt_be_iter_and_get_cfg(const char *xpath, struct lyd_node *node, struct nb_node *nb_node, void *ctx) { struct mgmt_be_get_adapter_config_params *parms = ctx; struct mgmt_be_client_adapter *adapter = parms->adapter; - uint subscr; - subscr = mgmt_be_get_subscr_for_xpath_and_client( - xpath, adapter->id, MGMT_SUBSCR_NOTIFY_CFG); - if (subscr) + if (be_is_client_interested(xpath, adapter->id, true)) nb_config_diff_created(node, &parms->seq, parms->cfg_chgs); } @@ -781,11 +730,15 @@ struct msg_conn *mgmt_be_create_adapter(int conn_fd, union sockunion *from) mgmt_be_adapters_add_tail(&mgmt_be_adapters, adapter); RB_INIT(nb_config_cbs, &adapter->cfg_chgs); - adapter->conn = msg_server_conn_create( - mgmt_loop, conn_fd, mgmt_be_adapter_notify_disconnect, - mgmt_be_adapter_process_msg, MGMTD_BE_MAX_NUM_MSG_PROC, - MGMTD_BE_MAX_NUM_MSG_WRITE, MGMTD_BE_MSG_MAX_LEN, adapter, - "BE-adapter"); + adapter->conn = msg_server_conn_create(mgmt_loop, conn_fd, + mgmt_be_adapter_notify_disconnect, + mgmt_be_adapter_process_msg, + MGMTD_BE_MAX_NUM_MSG_PROC, + MGMTD_BE_MAX_NUM_MSG_WRITE, + MGMTD_BE_MAX_MSG_LEN, adapter, + "BE-adapter"); + + adapter->conn->debug = DEBUG_MODE_CHECK(&mgmt_debug_be, DEBUG_MODE_ALL); MGMTD_BE_ADAPTER_DBG("Added new MGMTD Backend adapter '%s'", adapter->name); @@ -796,8 +749,7 @@ struct msg_conn *mgmt_be_create_adapter(int conn_fd, union sockunion *from) struct mgmt_be_client_adapter * mgmt_be_get_adapter_by_id(enum mgmt_be_client_id id) { - return (id < MGMTD_BE_CLIENT_ID_MAX ? mgmt_be_adapters_by_id[id] - : NULL); + return (id < MGMTD_BE_CLIENT_ID_MAX ? mgmt_be_adapters_by_id[id] : NULL); } struct mgmt_be_client_adapter * @@ -806,11 +758,23 @@ mgmt_be_get_adapter_by_name(const char *name) return mgmt_be_find_adapter_by_name(name); } +void mgmt_be_adapter_toggle_client_debug(bool set) +{ + struct mgmt_be_client_adapter *adapter; + + FOREACH_ADAPTER_IN_LIST (adapter) + adapter->conn->debug = set; +} + +/* + * Get a full set of changes for all the config that an adapter is subscribed to + * receive. + */ int mgmt_be_get_adapter_config(struct mgmt_be_client_adapter *adapter, - struct mgmt_ds_ctx *ds_ctx, - struct nb_config_cbs **cfg_chgs) + struct nb_config_cbs **cfg_chgs) { struct mgmt_be_get_adapter_config_params parms; + struct nb_config *cfg_root = mgmt_ds_get_nb_config(mm->running_ds); assert(cfg_chgs); @@ -826,111 +790,73 @@ int mgmt_be_get_adapter_config(struct mgmt_be_client_adapter *adapter, parms.cfg_chgs = &adapter->cfg_chgs; parms.seq = 0; - mgmt_ds_iter_data(ds_ctx, "", mgmt_be_iter_and_get_cfg, - (void *)&parms); + mgmt_ds_iter_data(MGMTD_DS_RUNNING, cfg_root, "", + mgmt_be_iter_and_get_cfg, (void *)&parms); } *cfg_chgs = &adapter->cfg_chgs; return 0; } -int mgmt_be_create_txn(struct mgmt_be_client_adapter *adapter, - uint64_t txn_id) -{ - return mgmt_be_send_txn_req(adapter, txn_id, true); -} - -int mgmt_be_destroy_txn(struct mgmt_be_client_adapter *adapter, - uint64_t txn_id) -{ - return mgmt_be_send_txn_req(adapter, txn_id, false); -} - -int mgmt_be_send_cfg_data_create_req(struct mgmt_be_client_adapter *adapter, - uint64_t txn_id, uint64_t batch_id, - struct mgmt_be_cfgreq *cfg_req, - bool end_of_data) -{ - return mgmt_be_send_cfgdata_create_req( - adapter, txn_id, batch_id, cfg_req->cfgdata_reqs, - cfg_req->num_reqs, end_of_data); -} - -extern int -mgmt_be_send_cfg_apply_req(struct mgmt_be_client_adapter *adapter, - uint64_t txn_id) -{ - return mgmt_be_send_cfgapply_req(adapter, txn_id); -} - -void mgmt_be_get_subscr_info_for_xpath( - const char *xpath, struct mgmt_be_client_subscr_info *subscr_info) +uint64_t mgmt_be_interested_clients(const char *xpath, bool config) { + struct mgmt_be_xpath_map *maps, *map; enum mgmt_be_client_id id; - uint i; + uint64_t clients; + + maps = config ? be_cfg_xpath_map : be_oper_xpath_map; - memset(subscr_info, 0, sizeof(*subscr_info)); + clients = 0; MGMTD_BE_ADAPTER_DBG("XPATH: '%s'", xpath); - for (i = 0; i < mgmt_num_xpath_maps; i++) { - if (!mgmt_be_eval_regexp_match(mgmt_xpath_map[i].xpath_regexp, - xpath)) - continue; - FOREACH_MGMTD_BE_CLIENT_ID (id) { - subscr_info->xpath_subscr[id] |= - mgmt_xpath_map[i].subscr_info[id]; - } - } + darr_foreach_p (maps, map) + if (mgmt_be_xpath_prefix(map->xpath_prefix, xpath)) + clients |= map->clients; if (DEBUG_MODE_CHECK(&mgmt_debug_be, DEBUG_MODE_ALL)) { - FOREACH_MGMTD_BE_CLIENT_ID (id) { - if (!subscr_info->xpath_subscr[id]) - continue; - MGMTD_BE_ADAPTER_DBG("Cient: %s: subscribed: 0x%x", - mgmt_be_client_id2name(id), - subscr_info->xpath_subscr[id]); - } + FOREACH_BE_CLIENT_BITS (id, clients) + MGMTD_BE_ADAPTER_DBG("Cient: %s: subscribed", + mgmt_be_client_id2name(id)); } + return clients; } /** - * Return the subscription info bits for a given `xpath` for a given - * `client_id`. + * Return true if `client_id` is interested in `xpath` for `config` + * or oper (!`config`). * * Args: - * xpath - the xpath to check for subscription information. + * xpath - the xpath to check for interest. * client_id - the BE client being checked for. - * subscr_mask - The subscr bits the caller is interested in seeing - * if set. + * bool - check for config (vs oper) subscription. * * Returns: - * The subscription info bits. + * Interested or not. */ -static uint mgmt_be_get_subscr_for_xpath_and_client( - const char *xpath, enum mgmt_be_client_id client_id, uint subscr_mask) +static bool be_is_client_interested(const char *xpath, + enum mgmt_be_client_id id, bool config) { - struct mgmt_be_client_xpath_map *map; - uint subscr = 0; - uint i; + const char *const *xpaths; - assert(client_id < MGMTD_BE_CLIENT_ID_MAX); + assert(id < MGMTD_BE_CLIENT_ID_MAX); MGMTD_BE_ADAPTER_DBG("Checking client: %s for xpath: '%s'", - mgmt_be_client_id2name(client_id), xpath); - - map = &mgmt_client_xpaths[client_id]; - for (i = 0; i < map->nxpaths; i++) { - if (!mgmt_be_eval_regexp_match(map->xpaths[i].xpath, xpath)) - continue; - MGMTD_BE_ADAPTER_DBG("xpath: %s: matched: %s", - map->xpaths[i].xpath, xpath); - subscr |= map->xpaths[i].subscribed; - if ((subscr & subscr_mask) == subscr_mask) - break; + mgmt_be_client_id2name(id), xpath); + + xpaths = config ? be_client_xpaths[id] : be_client_oper_xpaths[id]; + if (xpaths) { + for (; *xpaths; xpaths++) { + if (mgmt_be_xpath_prefix(*xpaths, xpath)) { + MGMTD_BE_ADAPTER_DBG("xpath: %s: matched: %s", + *xpaths, xpath); + return true; + } + } } - MGMTD_BE_ADAPTER_DBG("client: %s: subscribed: 0x%x", - mgmt_be_client_id2name(client_id), subscr); - return subscr; + + MGMTD_BE_ADAPTER_DBG("client: %s: not interested", + mgmt_be_client_id2name(id)); + return false; } void mgmt_be_adapter_status_write(struct vty *vty) @@ -957,57 +883,49 @@ void mgmt_be_adapter_status_write(struct vty *vty) (int)mgmt_be_adapters_count(&mgmt_be_adapters)); } -void mgmt_be_xpath_register_write(struct vty *vty) +static void be_show_xpath_register(struct vty *vty, + struct mgmt_be_xpath_map *map) { - uint indx; enum mgmt_be_client_id id; - struct mgmt_be_client_adapter *adapter; - uint info; - - vty_out(vty, "MGMTD Backend XPath Registry\n"); - - for (indx = 0; indx < mgmt_num_xpath_maps; indx++) { - vty_out(vty, " - XPATH: '%s'\n", - mgmt_xpath_map[indx].xpath_regexp); - FOREACH_MGMTD_BE_CLIENT_ID (id) { - info = mgmt_xpath_map[indx].subscr_info[id]; - if (!info) - continue; - vty_out(vty, - " -- Client: '%s'\tValidate:%d, Notify:%d, Own:%d\n", - mgmt_be_client_id2name(id), - (info & MGMT_SUBSCR_VALIDATE_CFG) != 0, - (info & MGMT_SUBSCR_NOTIFY_CFG) != 0, - (info & MGMT_SUBSCR_OPER_OWN) != 0); - adapter = mgmt_be_get_adapter_by_id(id); - if (adapter) - vty_out(vty, " -- Adapter: %p\n", adapter); - } + const char *astr; + + vty_out(vty, " - xpath: '%s'\n", map->xpath_prefix); + FOREACH_BE_CLIENT_BITS (id, map->clients) { + astr = mgmt_be_get_adapter_by_id(id) ? "active" : "inactive"; + vty_out(vty, " -- %s-client: '%s'\n", astr, + mgmt_be_client_id2name(id)); } +} +void mgmt_be_xpath_register_write(struct vty *vty) +{ + struct mgmt_be_xpath_map *map; + + vty_out(vty, "MGMTD Backend CFG XPath Registry: Count: %u\n", + darr_len(be_oper_xpath_map)); + darr_foreach_p (be_cfg_xpath_map, map) + be_show_xpath_register(vty, map); - vty_out(vty, "Total XPath Registries: %u\n", mgmt_num_xpath_maps); + vty_out(vty, "\nMGMTD Backend OPER XPath Registry: Count: %u\n", + darr_len(be_oper_xpath_map)); + darr_foreach_p (be_oper_xpath_map, map) + be_show_xpath_register(vty, map); } -void mgmt_be_xpath_subscr_info_write(struct vty *vty, const char *xpath) +void mgmt_be_show_xpath_registries(struct vty *vty, const char *xpath) { - struct mgmt_be_client_subscr_info subscr; enum mgmt_be_client_id id; struct mgmt_be_client_adapter *adapter; - uint info; + uint64_t cclients, oclients, combined; - mgmt_be_get_subscr_info_for_xpath(xpath, &subscr); + cclients = mgmt_be_interested_clients(xpath, true); + oclients = mgmt_be_interested_clients(xpath, false); + combined = cclients | oclients; vty_out(vty, "XPath: '%s'\n", xpath); - FOREACH_MGMTD_BE_CLIENT_ID (id) { - info = subscr.xpath_subscr[id]; - if (!info) - continue; - vty_out(vty, - " -- Client: '%s'\tValidate:%d, Notify:%d, Own:%d\n", - mgmt_be_client_id2name(id), - (info & MGMT_SUBSCR_VALIDATE_CFG) != 0, - (info & MGMT_SUBSCR_NOTIFY_CFG) != 0, - (info & MGMT_SUBSCR_OPER_OWN) != 0); + FOREACH_BE_CLIENT_BITS (id, combined) { + vty_out(vty, " -- Client: '%s'\tconfig:%d oper:%d\n", + mgmt_be_client_id2name(id), IS_IDBIT_SET(cclients, id), + IS_IDBIT_SET(oclients, id)); adapter = mgmt_be_get_adapter_by_id(id); if (adapter) vty_out(vty, " -- Adapter: %p\n", adapter); diff --git a/mgmtd/mgmt_be_adapter.h b/mgmtd/mgmt_be_adapter.h index 8f4eef5fb3..96e807f6c4 100644 --- a/mgmtd/mgmt_be_adapter.h +++ b/mgmtd/mgmt_be_adapter.h @@ -12,7 +12,7 @@ #include "mgmt_be_client.h" #include "mgmt_msg.h" -#include "mgmtd/mgmt_defines.h" +#include "mgmt_defines.h" #include "mgmtd/mgmt_ds.h" #define MGMTD_BE_CONN_INIT_DELAY_MSEC 50 @@ -20,6 +20,22 @@ #define MGMTD_FIND_ADAPTER_BY_INDEX(adapter_index) \ mgmt_adaptr_ref[adapter_index] +/** + * CLIENT-ID + * + * Add enum value for each supported component, wrap with + * #ifdef HAVE_COMPONENT + */ +enum mgmt_be_client_id { +#ifdef HAVE_STATICD + MGMTD_BE_CLIENT_ID_STATICD, +#endif + MGMTD_BE_CLIENT_ID_ZEBRA, + MGMTD_BE_CLIENT_ID_MAX +}; +#define MGMTD_BE_CLIENT_ID_MIN 0 + + enum mgmt_be_req_type { MGMTD_BE_REQ_NONE = 0, MGMTD_BE_REQ_CFG_VALIDATE, @@ -49,8 +65,6 @@ struct mgmt_be_client_adapter { enum mgmt_be_client_id id; uint32_t flags; char name[MGMTD_CLIENT_NAME_MAX_LEN]; - uint8_t num_xpath_reg; - char xpath_reg[MGMTD_MAX_NUM_XPATH_REG][MGMTD_MAX_XPATH_LEN]; int refcount; @@ -81,9 +95,36 @@ DECLARE_LIST(mgmt_be_adapters, struct mgmt_be_client_adapter, list_linkage); #define MGMT_SUBSCR_OPER_OWN 0x4 #define MGMT_SUBSCR_ALL 0x7 -struct mgmt_be_client_subscr_info { - uint xpath_subscr[MGMTD_BE_CLIENT_ID_MAX]; -}; +/* --------- */ +/* CLIENT-ID */ +/* --------- */ + +#define FOREACH_MGMTD_BE_CLIENT_ID(id) \ + for ((id) = MGMTD_BE_CLIENT_ID_MIN; (id) < MGMTD_BE_CLIENT_ID_MAX; \ + (id)++) + +#define IS_IDBIT_SET(v, id) (!IS_IDBIT_UNSET(v, id)) +#define IS_IDBIT_UNSET(v, id) (!((v) & (1ull << (id)))) + +#define __GET_NEXT_SET(id, bits) \ + ({ \ + enum mgmt_be_client_id __id = (id); \ + \ + for (; __id < MGMTD_BE_CLIENT_ID_MAX && \ + IS_IDBIT_UNSET(bits, __id); \ + __id++) \ + ; \ + __id; \ + }) + +#define FOREACH_BE_CLIENT_BITS(id, bits) \ + for ((id) = __GET_NEXT_SET(MGMTD_BE_CLIENT_ID_MIN, bits); \ + (id) < MGMTD_BE_CLIENT_ID_MAX; \ + (id) = __GET_NEXT_SET((id) + 1, bits)) + +/* ---------- */ +/* Prototypes */ +/* ---------- */ /* Initialise backend adapter module. */ extern void mgmt_be_adapter_init(struct event_loop *tm); @@ -109,19 +150,19 @@ mgmt_be_get_adapter_by_name(const char *name); extern struct mgmt_be_client_adapter * mgmt_be_get_adapter_by_id(enum mgmt_be_client_id id); -/* Fetch backend adapter config. */ -extern int -mgmt_be_get_adapter_config(struct mgmt_be_client_adapter *adapter, - struct mgmt_ds_ctx *ds_ctx, - struct nb_config_cbs **cfg_chgs); +/* Get the client name given a client ID */ +extern const char *mgmt_be_client_id2name(enum mgmt_be_client_id id); -/* Create a transaction. */ -extern int mgmt_be_create_txn(struct mgmt_be_client_adapter *adapter, - uint64_t txn_id); +/* Toggle debug on or off for connected clients. */ +extern void mgmt_be_adapter_toggle_client_debug(bool set); -/* Destroy a transaction. */ -extern int mgmt_be_destroy_txn(struct mgmt_be_client_adapter *adapter, - uint64_t txn_id); +/* Fetch backend adapter config. */ +extern int mgmt_be_get_adapter_config(struct mgmt_be_client_adapter *adapter, + struct nb_config_cbs **cfg_chgs); + +/* Create/destroy a transaction. */ +extern int mgmt_be_send_txn_req(struct mgmt_be_client_adapter *adapter, + uint64_t txn_id, bool create); /* * Send config data create request to backend client. @@ -132,11 +173,11 @@ extern int mgmt_be_destroy_txn(struct mgmt_be_client_adapter *adapter, * txn_id * Unique transaction identifier. * - * batch_id - * Request batch ID. + * cfgdata_reqs + * An array of pointer to Mgmtd__YangCfgDataReq. * - * cfg_req - * Config data request. + * num_reqs + * Length of the cfgdata_reqs array. * * end_of_data * TRUE if the data from last batch, FALSE otherwise. @@ -144,37 +185,15 @@ extern int mgmt_be_destroy_txn(struct mgmt_be_client_adapter *adapter, * Returns: * 0 on success, -1 on failure. */ -extern int mgmt_be_send_cfg_data_create_req( - struct mgmt_be_client_adapter *adapter, uint64_t txn_id, - uint64_t batch_id, struct mgmt_be_cfgreq *cfg_req, bool end_of_data); - -/* - * Send config validate request to backend client. - * - * adaptr - * Backend adapter information. - * - * txn_id - * Unique transaction identifier. - * - * batch_ids - * List of request batch IDs. - * - * num_batch_ids - * Number of batch ids. - * - * Returns: - * 0 on success, -1 on failure. - */ -extern int -mgmt_be_send_cfg_validate_req(struct mgmt_be_client_adapter *adapter, - uint64_t txn_id, uint64_t batch_ids[], - size_t num_batch_ids); +extern int mgmt_be_send_cfgdata_req(struct mgmt_be_client_adapter *adapter, + uint64_t txn_id, + Mgmtd__YangCfgDataReq **cfgdata_reqs, + size_t num_reqs, bool end_of_data); /* * Send config apply request to backend client. * - * adaptr + * adapter * Backend adapter information. * * txn_id @@ -183,9 +202,8 @@ mgmt_be_send_cfg_validate_req(struct mgmt_be_client_adapter *adapter, * Returns: * 0 on success, -1 on failure. */ -extern int -mgmt_be_send_cfg_apply_req(struct mgmt_be_client_adapter *adapter, - uint64_t txn_id); +extern int mgmt_be_send_cfgapply_req(struct mgmt_be_client_adapter *adapter, + uint64_t txn_id); /* * Dump backend adapter status to vty. @@ -197,23 +215,32 @@ extern void mgmt_be_adapter_status_write(struct vty *vty); */ extern void mgmt_be_xpath_register_write(struct vty *vty); + +/** + * Send a native message to a backend client + * + * Args: + * adapter: the client to send the message to. + * msg: a native message from mgmt_msg_native_alloc_msg() + * + * Return: + * Any return value from msg_conn_send_msg(). + */ +extern int mgmt_be_send_native(enum mgmt_be_client_id id, void *msg); + /** * Lookup the clients which are subscribed to a given `xpath` * and the way they are subscribed. * * Args: * xpath - the xpath to check for subscription information. - * subscr_info - An array of uint indexed by client id - * each eleemnt holds the subscription info - * for that client. + * config - true for config interest false for oper interest. */ -extern void mgmt_be_get_subscr_info_for_xpath( - const char *xpath, struct mgmt_be_client_subscr_info *subscr_info); +extern uint64_t mgmt_be_interested_clients(const char *xpath, bool config); /* * Dump backend client information for a given xpath to vty. */ -extern void mgmt_be_xpath_subscr_info_write(struct vty *vty, - const char *xpath); +extern void mgmt_be_show_xpath_registries(struct vty *vty, const char *xpath); #endif /* _FRR_MGMTD_BE_ADAPTER_H_ */ diff --git a/mgmtd/mgmt_ds.c b/mgmtd/mgmt_ds.c index 3fd47862b2..8ed15b1726 100644 --- a/mgmtd/mgmt_ds.c +++ b/mgmtd/mgmt_ds.c @@ -16,13 +16,15 @@ #include "libyang/libyang.h" #define MGMTD_DS_DBG(fmt, ...) \ - DEBUGD(&mgmt_debug_ds, "%s:" fmt, __func__, ##__VA_ARGS__) + DEBUGD(&mgmt_debug_ds, "DS: %s: " fmt, __func__, ##__VA_ARGS__) #define MGMTD_DS_ERR(fmt, ...) \ zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__) struct mgmt_ds_ctx { Mgmtd__DatastoreId ds_id; - int lock; /* 0 unlocked, >0 read locked < write locked */ + + bool locked; + uint64_t vty_session_id; /* Owner of the lock or 0 */ bool config_ds; @@ -76,38 +78,21 @@ static int mgmt_ds_dump_in_memory(struct mgmt_ds_ctx *ds_ctx, static int mgmt_ds_replace_dst_with_src_ds(struct mgmt_ds_ctx *src, struct mgmt_ds_ctx *dst) { - struct lyd_node *dst_dnode, *src_dnode; - if (!src || !dst) return -1; - MGMTD_DS_DBG("Replacing %d with %d", dst->ds_id, src->ds_id); - - src_dnode = src->config_ds ? src->root.cfg_root->dnode - : dst->root.dnode_root; - dst_dnode = dst->config_ds ? dst->root.cfg_root->dnode - : dst->root.dnode_root; - - if (dst_dnode) - yang_dnode_free(dst_dnode); - /* Not using nb_config_replace as the oper ds does not contain nb_config - */ - dst_dnode = yang_dnode_dup(src_dnode); - if (dst->config_ds) - dst->root.cfg_root->dnode = dst_dnode; - else - dst->root.dnode_root = dst_dnode; + MGMTD_DS_DBG("Replacing %s with %s", mgmt_ds_id2name(dst->ds_id), + mgmt_ds_id2name(src->ds_id)); - if (src->ds_id == MGMTD_DS_CANDIDATE) { - /* - * Drop the changes in scratch-buffer. - */ - MGMTD_DS_DBG("Emptying Candidate Scratch buffer!"); - nb_config_diff_del_changes(&src->root.cfg_root->cfg_chgs); + if (src->config_ds && dst->config_ds) + nb_config_replace(dst->root.cfg_root, src->root.cfg_root, true); + else { + assert(!src->config_ds && !dst->config_ds); + if (dst->root.dnode_root) + yang_dnode_free(dst->root.dnode_root); + dst->root.dnode_root = yang_dnode_dup(src->root.dnode_root); } - /* TODO: Update the versions if nb_config present */ - return 0; } @@ -115,31 +100,24 @@ static int mgmt_ds_merge_src_with_dst_ds(struct mgmt_ds_ctx *src, struct mgmt_ds_ctx *dst) { int ret; - struct lyd_node **dst_dnode, *src_dnode; if (!src || !dst) return -1; MGMTD_DS_DBG("Merging DS %d with %d", dst->ds_id, src->ds_id); - - src_dnode = src->config_ds ? src->root.cfg_root->dnode - : dst->root.dnode_root; - dst_dnode = dst->config_ds ? &dst->root.cfg_root->dnode - : &dst->root.dnode_root; - ret = lyd_merge_siblings(dst_dnode, src_dnode, 0); + if (src->config_ds && dst->config_ds) + ret = nb_config_merge(dst->root.cfg_root, src->root.cfg_root, + true); + else { + assert(!src->config_ds && !dst->config_ds); + ret = lyd_merge_siblings(&dst->root.dnode_root, + src->root.dnode_root, 0); + } if (ret != 0) { - MGMTD_DS_ERR("lyd_merge() failed with err %d", ret); + MGMTD_DS_ERR("merge failed with err: %d", ret); return ret; } - if (src->ds_id == MGMTD_DS_CANDIDATE) { - /* - * Drop the changes in scratch-buffer. - */ - MGMTD_DS_DBG("Emptying Candidate Scratch buffer!"); - nb_config_diff_del_changes(&src->root.cfg_root->cfg_chgs); - } - return 0; } @@ -210,9 +188,11 @@ int mgmt_ds_init(struct mgmt_master *mm) void mgmt_ds_destroy(void) { - /* - * TODO: Free the datastores. - */ + nb_config_free(candidate.root.cfg_root); + candidate.root.cfg_root = NULL; + + yang_dnode_free(oper.root.dnode_root); + oper.root.dnode_root = NULL; } struct mgmt_ds_ctx *mgmt_ds_get_ctx_by_id(struct mgmt_master *mm, @@ -242,40 +222,33 @@ bool mgmt_ds_is_config(struct mgmt_ds_ctx *ds_ctx) return ds_ctx->config_ds; } -int mgmt_ds_read_lock(struct mgmt_ds_ctx *ds_ctx) +bool mgmt_ds_is_locked(struct mgmt_ds_ctx *ds_ctx, uint64_t session_id) { - if (!ds_ctx) - return EINVAL; - if (ds_ctx->lock < 0) - return EBUSY; - ++ds_ctx->lock; - return 0; + assert(ds_ctx); + return (ds_ctx->locked && ds_ctx->vty_session_id == session_id); } -int mgmt_ds_write_lock(struct mgmt_ds_ctx *ds_ctx) +int mgmt_ds_lock(struct mgmt_ds_ctx *ds_ctx, uint64_t session_id) { - if (!ds_ctx) - return EINVAL; - if (ds_ctx->lock != 0) + assert(ds_ctx); + + if (ds_ctx->locked) return EBUSY; - ds_ctx->lock = -1; + + ds_ctx->locked = true; + ds_ctx->vty_session_id = session_id; return 0; } -int mgmt_ds_unlock(struct mgmt_ds_ctx *ds_ctx) +void mgmt_ds_unlock(struct mgmt_ds_ctx *ds_ctx) { - if (!ds_ctx) - return EINVAL; - if (ds_ctx->lock > 0) - --ds_ctx->lock; - else if (ds_ctx->lock < 0) { - assert(ds_ctx->lock == -1); - ds_ctx->lock = 0; - } else { - assert(ds_ctx->lock != 0); - return EINVAL; - } - return 0; + assert(ds_ctx); + if (!ds_ctx->locked) + zlog_warn( + "%s: WARNING: unlock on unlocked in DS:%s last session-id %" PRIu64, + __func__, mgmt_ds_id2name(ds_ctx->ds_id), + ds_ctx->vty_session_id); + ds_ctx->locked = 0; } int mgmt_ds_copy_dss(struct mgmt_ds_ctx *src_ds_ctx, @@ -312,10 +285,9 @@ struct nb_config *mgmt_ds_get_nb_config(struct mgmt_ds_ctx *ds_ctx) } static int mgmt_walk_ds_nodes( - struct mgmt_ds_ctx *ds_ctx, const char *base_xpath, + struct nb_config *root, const char *base_xpath, struct lyd_node *base_dnode, - void (*mgmt_ds_node_iter_fn)(struct mgmt_ds_ctx *ds_ctx, - const char *xpath, struct lyd_node *node, + void (*mgmt_ds_node_iter_fn)(const char *xpath, struct lyd_node *node, struct nb_node *nb_node, void *ctx), void *ctx) { @@ -334,10 +306,7 @@ static int mgmt_walk_ds_nodes( * This function only returns the first node of a possible set * of matches issuing a warning if more than 1 matches */ - base_dnode = yang_dnode_get( - ds_ctx->config_ds ? ds_ctx->root.cfg_root->dnode - : ds_ctx->root.dnode_root, - base_xpath); + base_dnode = yang_dnode_get(root->dnode, base_xpath); if (!base_dnode) return -1; @@ -346,7 +315,7 @@ static int mgmt_walk_ds_nodes( sizeof(xpath))); nbnode = (struct nb_node *)base_dnode->schema->priv; - (*mgmt_ds_node_iter_fn)(ds_ctx, base_xpath, base_dnode, nbnode, ctx); + (*mgmt_ds_node_iter_fn)(base_xpath, base_dnode, nbnode, ctx); /* * If the base_xpath points to a leaf node we can skip the tree walk. @@ -368,7 +337,7 @@ static int mgmt_walk_ds_nodes( MGMTD_DS_DBG(" -- Child xpath: %s", xpath); - ret = mgmt_walk_ds_nodes(ds_ctx, xpath, dnode, + ret = mgmt_walk_ds_nodes(root, xpath, dnode, mgmt_ds_node_iter_fn, ctx); if (ret != 0) break; @@ -457,9 +426,9 @@ int mgmt_ds_load_config_from_file(struct mgmt_ds_ctx *dst, return 0; } -int mgmt_ds_iter_data(struct mgmt_ds_ctx *ds_ctx, const char *base_xpath, - void (*mgmt_ds_node_iter_fn)(struct mgmt_ds_ctx *ds_ctx, - const char *xpath, +int mgmt_ds_iter_data(Mgmtd__DatastoreId ds_id, struct nb_config *root, + const char *base_xpath, + void (*mgmt_ds_node_iter_fn)(const char *xpath, struct lyd_node *node, struct nb_node *nb_node, void *ctx), @@ -470,7 +439,7 @@ int mgmt_ds_iter_data(struct mgmt_ds_ctx *ds_ctx, const char *base_xpath, struct lyd_node *base_dnode = NULL; struct lyd_node *node; - if (!ds_ctx) + if (!root) return -1; strlcpy(xpath, base_xpath, sizeof(xpath)); @@ -482,12 +451,11 @@ int mgmt_ds_iter_data(struct mgmt_ds_ctx *ds_ctx, const char *base_xpath, * Oper-state should be kept in mind though for the prefix walk */ - MGMTD_DS_DBG(" -- START DS walk for DSid: %d", ds_ctx->ds_id); + MGMTD_DS_DBG(" -- START DS walk for DSid: %d", ds_id); /* If the base_xpath is empty then crawl the sibblings */ if (xpath[0] == 0) { - base_dnode = ds_ctx->config_ds ? ds_ctx->root.cfg_root->dnode - : ds_ctx->root.dnode_root; + base_dnode = root->dnode; /* get first top-level sibling */ while (base_dnode->parent) @@ -497,11 +465,11 @@ int mgmt_ds_iter_data(struct mgmt_ds_ctx *ds_ctx, const char *base_xpath, base_dnode = base_dnode->prev; LY_LIST_FOR (base_dnode, node) { - ret = mgmt_walk_ds_nodes(ds_ctx, xpath, node, + ret = mgmt_walk_ds_nodes(root, xpath, node, mgmt_ds_node_iter_fn, ctx); } } else - ret = mgmt_walk_ds_nodes(ds_ctx, xpath, base_dnode, + ret = mgmt_walk_ds_nodes(root, xpath, base_dnode, mgmt_ds_node_iter_fn, ctx); return ret; diff --git a/mgmtd/mgmt_ds.h b/mgmtd/mgmt_ds.h index e5c88742dd..ca08e37dac 100644 --- a/mgmtd/mgmt_ds.h +++ b/mgmtd/mgmt_ds.h @@ -11,8 +11,8 @@ #include "mgmt_fe_client.h" #include "northbound.h" +#include "mgmt_defines.h" -#include "mgmtd/mgmt_defines.h" #include "mgmtd/mgmt_be_adapter.h" #include "mgmtd/mgmt_fe_adapter.h" @@ -179,19 +179,19 @@ extern struct mgmt_ds_ctx *mgmt_ds_get_ctx_by_id(struct mgmt_master *mm, extern bool mgmt_ds_is_config(struct mgmt_ds_ctx *ds_ctx); /* - * Acquire read lock to a ds given a ds_handle + * Check if a given datastore is locked by a given session */ -extern int mgmt_ds_read_lock(struct mgmt_ds_ctx *ds_ctx); +extern bool mgmt_ds_is_locked(struct mgmt_ds_ctx *ds_ctx, uint64_t session_id); /* * Acquire write lock to a ds given a ds_handle */ -extern int mgmt_ds_write_lock(struct mgmt_ds_ctx *ds_ctx); +extern int mgmt_ds_lock(struct mgmt_ds_ctx *ds_ctx, uint64_t session_id); /* * Remove a lock from ds given a ds_handle */ -extern int mgmt_ds_unlock(struct mgmt_ds_ctx *ds_ctx); +extern void mgmt_ds_unlock(struct mgmt_ds_ctx *ds_ctx); /* * Copy from source to destination datastore. @@ -233,8 +233,11 @@ extern int mgmt_ds_delete_data_nodes(struct mgmt_ds_ctx *ds_ctx, /* * Iterate over datastore data. * - * ds_ctx - * Datastore context. + * ds_id + * Datastore ID.. + * + * root + * The root of the tree to iterate over. * * base_xpath * Base YANG xpath from where needs to be iterated. @@ -252,9 +255,9 @@ extern int mgmt_ds_delete_data_nodes(struct mgmt_ds_ctx *ds_ctx, * 0 on success, -1 on failure. */ extern int mgmt_ds_iter_data( - struct mgmt_ds_ctx *ds_ctx, const char *base_xpath, - void (*mgmt_ds_node_iter_fn)(struct mgmt_ds_ctx *ds_ctx, - const char *xpath, struct lyd_node *node, + Mgmtd__DatastoreId ds_id, struct nb_config *root, + const char *base_xpath, + void (*mgmt_ds_node_iter_fn)(const char *xpath, struct lyd_node *node, struct nb_node *nb_node, void *ctx), void *ctx); diff --git a/mgmtd/mgmt_fe_adapter.c b/mgmtd/mgmt_fe_adapter.c index 7509d24a6a..b7c7a0fff1 100644 --- a/mgmtd/mgmt_fe_adapter.c +++ b/mgmtd/mgmt_fe_adapter.c @@ -8,20 +8,23 @@ */ #include <zebra.h> +#include "darr.h" #include "sockopt.h" #include "network.h" #include "libfrr.h" #include "mgmt_fe_client.h" #include "mgmt_msg.h" +#include "mgmt_msg_native.h" #include "mgmt_pb.h" #include "hash.h" #include "jhash.h" #include "mgmtd/mgmt.h" +#include "mgmtd/mgmt_ds.h" #include "mgmtd/mgmt_memory.h" #include "mgmtd/mgmt_fe_adapter.h" #define MGMTD_FE_ADAPTER_DBG(fmt, ...) \ - DEBUGD(&mgmt_debug_fe, "FE-ADAPTER: %s:" fmt, __func__, ##__VA_ARGS__) + DEBUGD(&mgmt_debug_fe, "FE-ADAPTER: %s: " fmt, __func__, ##__VA_ARGS__) #define MGMTD_FE_ADAPTER_ERR(fmt, ...) \ zlog_err("FE-ADAPTER: %s: ERROR: " fmt, __func__, ##__VA_ARGS__) @@ -39,9 +42,7 @@ struct mgmt_fe_session_ctx { uint64_t client_id; uint64_t txn_id; uint64_t cfg_txn_id; - uint8_t ds_write_locked[MGMTD_DS_MAX_ID]; - uint8_t ds_read_locked[MGMTD_DS_MAX_ID]; - uint8_t ds_locked_implict[MGMTD_DS_MAX_ID]; + uint8_t ds_locked[MGMTD_DS_MAX_ID]; struct event *proc_cfg_txn_clnp; struct event *proc_show_txn_clnp; @@ -71,114 +72,57 @@ mgmt_fe_session_write_lock_ds(Mgmtd__DatastoreId ds_id, struct mgmt_ds_ctx *ds_ctx, struct mgmt_fe_session_ctx *session) { - if (!session->ds_write_locked[ds_id]) { - if (mgmt_ds_write_lock(ds_ctx) != 0) { + if (session->ds_locked[ds_id]) + zlog_warn("multiple lock taken by session-id: %" PRIu64 + " on DS:%s", + session->session_id, mgmt_ds_id2name(ds_id)); + else { + if (mgmt_ds_lock(ds_ctx, session->session_id)) { MGMTD_FE_ADAPTER_DBG( - "Failed to lock the DS %u for session-id: %" PRIu64 + "Failed to lock the DS:%s for session-id: %" PRIu64 " from %s!", - ds_id, session->session_id, + mgmt_ds_id2name(ds_id), session->session_id, session->adapter->name); return -1; } - session->ds_write_locked[ds_id] = true; + session->ds_locked[ds_id] = true; MGMTD_FE_ADAPTER_DBG( - "Write-Locked the DS %u for session-id: %" PRIu64 + "Write-Locked the DS:%s for session-id: %" PRIu64 " from %s", - ds_id, session->session_id, session->adapter->name); - } - - return 0; -} - -static int -mgmt_fe_session_read_lock_ds(Mgmtd__DatastoreId ds_id, - struct mgmt_ds_ctx *ds_ctx, - struct mgmt_fe_session_ctx *session) -{ - if (!session->ds_read_locked[ds_id]) { - if (mgmt_ds_read_lock(ds_ctx) != 0) { - MGMTD_FE_ADAPTER_DBG( - "Failed to lock the DS %u for session-is: %" PRIu64 - " from %s", - ds_id, session->session_id, - session->adapter->name); - return -1; - } - - session->ds_read_locked[ds_id] = true; - MGMTD_FE_ADAPTER_DBG( - "Read-Locked the DS %u for session-id: %" PRIu64 - " from %s", - ds_id, session->session_id, session->adapter->name); + mgmt_ds_id2name(ds_id), session->session_id, + session->adapter->name); } return 0; } -static int mgmt_fe_session_unlock_ds(Mgmtd__DatastoreId ds_id, - struct mgmt_ds_ctx *ds_ctx, - struct mgmt_fe_session_ctx *session, - bool unlock_write, bool unlock_read) +static void mgmt_fe_session_unlock_ds(Mgmtd__DatastoreId ds_id, + struct mgmt_ds_ctx *ds_ctx, + struct mgmt_fe_session_ctx *session) { - if (unlock_write && session->ds_write_locked[ds_id]) { - session->ds_write_locked[ds_id] = false; - session->ds_locked_implict[ds_id] = false; - if (mgmt_ds_unlock(ds_ctx) != 0) { - MGMTD_FE_ADAPTER_DBG( - "Failed to unlock the DS %u taken earlier by session-id: %" PRIu64 - " from %s", - ds_id, session->session_id, - session->adapter->name); - return -1; - } + if (!session->ds_locked[ds_id]) + zlog_warn("unlock unlocked by session-id: %" PRIu64 " on DS:%s", + session->session_id, mgmt_ds_id2name(ds_id)); - MGMTD_FE_ADAPTER_DBG( - "Unlocked DS %u write-locked earlier by session-id: %" PRIu64 - " from %s", - ds_id, session->session_id, session->adapter->name); - } else if (unlock_read && session->ds_read_locked[ds_id]) { - session->ds_read_locked[ds_id] = false; - session->ds_locked_implict[ds_id] = false; - if (mgmt_ds_unlock(ds_ctx) != 0) { - MGMTD_FE_ADAPTER_DBG( - "Failed to unlock the DS %u taken earlier by session-id: %" PRIu64 - " from %s", - ds_id, session->session_id, - session->adapter->name); - return -1; - } - - MGMTD_FE_ADAPTER_DBG( - "Unlocked DS %u read-locked earlier by session-id: %" PRIu64 - " from %s", - ds_id, session->session_id, session->adapter->name); - } - - return 0; + session->ds_locked[ds_id] = false; + mgmt_ds_unlock(ds_ctx); + MGMTD_FE_ADAPTER_DBG( + "Unlocked DS:%s write-locked earlier by session-id: %" PRIu64 + " from %s", + mgmt_ds_id2name(ds_id), session->session_id, + session->adapter->name); } static void mgmt_fe_session_cfg_txn_cleanup(struct mgmt_fe_session_ctx *session) { - Mgmtd__DatastoreId ds_id; - struct mgmt_ds_ctx *ds_ctx; - /* * Ensure any uncommitted changes in Candidate DS * is discarded. */ mgmt_ds_copy_dss(mm->running_ds, mm->candidate_ds, false); - for (ds_id = 0; ds_id < MGMTD_DS_MAX_ID; ds_id++) { - ds_ctx = mgmt_ds_get_ctx_by_id(mm, ds_id); - if (ds_ctx) { - if (session->ds_locked_implict[ds_id]) - mgmt_fe_session_unlock_ds( - ds_id, ds_ctx, session, true, false); - } - } - /* * Destroy the actual transaction created earlier. */ @@ -189,17 +133,6 @@ mgmt_fe_session_cfg_txn_cleanup(struct mgmt_fe_session_ctx *session) static void mgmt_fe_session_show_txn_cleanup(struct mgmt_fe_session_ctx *session) { - Mgmtd__DatastoreId ds_id; - struct mgmt_ds_ctx *ds_ctx; - - for (ds_id = 0; ds_id < MGMTD_DS_MAX_ID; ds_id++) { - ds_ctx = mgmt_ds_get_ctx_by_id(mm, ds_id); - if (ds_ctx) { - mgmt_fe_session_unlock_ds(ds_id, ds_ctx, session, - false, true); - } - } - /* * Destroy the transaction created recently. */ @@ -240,25 +173,29 @@ mgmt_fe_session_compute_commit_timers(struct mgmt_commit_stats *cmt_stats) } } -static void mgmt_fe_cleanup_session(struct mgmt_fe_session_ctx **session) +static void mgmt_fe_cleanup_session(struct mgmt_fe_session_ctx **sessionp) { - if ((*session)->adapter) { - mgmt_fe_session_cfg_txn_cleanup((*session)); - mgmt_fe_session_show_txn_cleanup((*session)); - mgmt_fe_session_unlock_ds(MGMTD_DS_CANDIDATE, mm->candidate_ds, - *session, true, true); - mgmt_fe_session_unlock_ds(MGMTD_DS_RUNNING, mm->running_ds, - *session, true, true); - - mgmt_fe_sessions_del(&(*session)->adapter->fe_sessions, - *session); - assert((*session)->adapter->refcount > 1); - mgmt_fe_adapter_unlock(&(*session)->adapter); + Mgmtd__DatastoreId ds_id; + struct mgmt_ds_ctx *ds_ctx; + struct mgmt_fe_session_ctx *session = *sessionp; + + if (session->adapter) { + mgmt_fe_session_cfg_txn_cleanup(session); + mgmt_fe_session_show_txn_cleanup(session); + for (ds_id = 0; ds_id < MGMTD_DS_MAX_ID; ds_id++) { + ds_ctx = mgmt_ds_get_ctx_by_id(mm, ds_id); + if (ds_ctx && session->ds_locked[ds_id]) + mgmt_fe_session_unlock_ds(ds_id, ds_ctx, + session); + } + mgmt_fe_sessions_del(&session->adapter->fe_sessions, session); + assert(session->adapter->refcount > 1); + mgmt_fe_adapter_unlock(&session->adapter); } - hash_release(mgmt_fe_sessions, *session); - XFREE(MTYPE_MGMTD_FE_SESSION, *session); - *session = NULL; + hash_release(mgmt_fe_sessions, session); + XFREE(MTYPE_MGMTD_FE_SESSION, session); + *sessionp = NULL; } static struct mgmt_fe_session_ctx * @@ -311,6 +248,23 @@ mgmt_session_id2ctx(uint64_t session_id) return session; } +void mgmt_fe_adapter_toggle_client_debug(bool set) +{ + struct mgmt_fe_client_adapter *adapter; + + FOREACH_ADAPTER_IN_LIST (adapter) + adapter->conn->debug = set; +} + +static struct mgmt_fe_session_ctx *fe_adapter_session_by_txn_id(uint64_t txn_id) +{ + uint64_t session_id = mgmt_txn_get_session_id(txn_id); + + if (session_id == MGMTD_SESSION_ID_NONE) + return NULL; + return mgmt_session_id2ctx(session_id); +} + static struct mgmt_fe_session_ctx * mgmt_fe_create_session(struct mgmt_fe_client_adapter *adapter, uint64_t client_id) @@ -338,9 +292,16 @@ mgmt_fe_create_session(struct mgmt_fe_client_adapter *adapter, return session; } -static int mgmt_fe_adapter_send_msg(struct mgmt_fe_client_adapter *adapter, - Mgmtd__FeMessage *fe_msg, - bool short_circuit_ok) +static int fe_adapter_send_native_msg(struct mgmt_fe_client_adapter *adapter, + void *msg, size_t len, + bool short_circuit_ok) +{ + return msg_conn_send_msg(adapter->conn, MGMT_MSG_VERSION_NATIVE, msg, + len, NULL, short_circuit_ok); +} + +static int fe_adapter_send_msg(struct mgmt_fe_client_adapter *adapter, + Mgmtd__FeMessage *fe_msg, bool short_circuit_ok) { return msg_conn_send_msg( adapter->conn, MGMT_MSG_VERSION_PROTOBUF, fe_msg, @@ -349,10 +310,9 @@ static int mgmt_fe_adapter_send_msg(struct mgmt_fe_client_adapter *adapter, short_circuit_ok); } -static int -mgmt_fe_send_session_reply(struct mgmt_fe_client_adapter *adapter, - struct mgmt_fe_session_ctx *session, - bool create, bool success) +static int fe_adapter_send_session_reply(struct mgmt_fe_client_adapter *adapter, + struct mgmt_fe_session_ctx *session, + bool create, bool success) { Mgmtd__FeMessage fe_msg; Mgmtd__FeSessionReply session_reply; @@ -374,16 +334,17 @@ mgmt_fe_send_session_reply(struct mgmt_fe_client_adapter *adapter, "Sending SESSION_REPLY message to MGMTD Frontend client '%s'", adapter->name); - return mgmt_fe_adapter_send_msg(adapter, &fe_msg, true); + return fe_adapter_send_msg(adapter, &fe_msg, true); } -static int mgmt_fe_send_lockds_reply(struct mgmt_fe_session_ctx *session, - Mgmtd__DatastoreId ds_id, - uint64_t req_id, bool lock_ds, - bool success, const char *error_if_any) +static int fe_adapter_send_lockds_reply(struct mgmt_fe_session_ctx *session, + Mgmtd__DatastoreId ds_id, + uint64_t req_id, bool lock_ds, + bool success, const char *error_if_any) { Mgmtd__FeMessage fe_msg; Mgmtd__FeLockDsReply lockds_reply; + bool scok = session->adapter->conn->is_short_circuit; assert(session->adapter); @@ -401,13 +362,13 @@ static int mgmt_fe_send_lockds_reply(struct mgmt_fe_session_ctx *session, fe_msg.lockds_reply = &lockds_reply; MGMTD_FE_ADAPTER_DBG( - "Sending LOCK_DS_REPLY message to MGMTD Frontend client '%s'", - session->adapter->name); + "Sending LOCK_DS_REPLY message to MGMTD Frontend client '%s' scok: %d", + session->adapter->name, scok); - return mgmt_fe_adapter_send_msg(session->adapter, &fe_msg, false); + return fe_adapter_send_msg(session->adapter, &fe_msg, scok); } -static int mgmt_fe_send_setcfg_reply(struct mgmt_fe_session_ctx *session, +static int fe_adapter_send_set_cfg_reply(struct mgmt_fe_session_ctx *session, Mgmtd__DatastoreId ds_id, uint64_t req_id, bool success, const char *error_if_any, @@ -427,6 +388,7 @@ static int mgmt_fe_send_setcfg_reply(struct mgmt_fe_session_ctx *session, setcfg_reply.ds_id = ds_id; setcfg_reply.req_id = req_id; setcfg_reply.success = success; + setcfg_reply.implicit_commit = implicit_commit; if (error_if_any) setcfg_reply.error_if_any = (char *)error_if_any; @@ -450,10 +412,10 @@ static int mgmt_fe_send_setcfg_reply(struct mgmt_fe_session_ctx *session, gettimeofday(&session->adapter->setcfg_stats.last_end, NULL); mgmt_fe_adapter_compute_set_cfg_timers(&session->adapter->setcfg_stats); - return mgmt_fe_adapter_send_msg(session->adapter, &fe_msg, false); + return fe_adapter_send_msg(session->adapter, &fe_msg, false); } -static int mgmt_fe_send_commitcfg_reply( +static int fe_adapter_send_commit_cfg_reply( struct mgmt_fe_session_ctx *session, Mgmtd__DatastoreId src_ds_id, Mgmtd__DatastoreId dst_ds_id, uint64_t req_id, enum mgmt_result result, bool validate_only, const char *error_if_any) @@ -496,85 +458,67 @@ static int mgmt_fe_send_commitcfg_reply( if (mm->perf_stats_en) gettimeofday(&session->adapter->cmt_stats.last_end, NULL); mgmt_fe_session_compute_commit_timers(&session->adapter->cmt_stats); - return mgmt_fe_adapter_send_msg(session->adapter, &fe_msg, false); + return fe_adapter_send_msg(session->adapter, &fe_msg, false); } -static int mgmt_fe_send_getcfg_reply(struct mgmt_fe_session_ctx *session, - Mgmtd__DatastoreId ds_id, - uint64_t req_id, bool success, - Mgmtd__YangDataReply *data, - const char *error_if_any) +static int fe_adapter_send_get_reply(struct mgmt_fe_session_ctx *session, + Mgmtd__DatastoreId ds_id, uint64_t req_id, + bool success, Mgmtd__YangDataReply *data, + const char *error_if_any) { Mgmtd__FeMessage fe_msg; - Mgmtd__FeGetConfigReply getcfg_reply; + Mgmtd__FeGetReply get_reply; assert(session->adapter); - mgmtd__fe_get_config_reply__init(&getcfg_reply); - getcfg_reply.session_id = session->session_id; - getcfg_reply.ds_id = ds_id; - getcfg_reply.req_id = req_id; - getcfg_reply.success = success; - getcfg_reply.data = data; + mgmtd__fe_get_reply__init(&get_reply); + get_reply.session_id = session->session_id; + get_reply.ds_id = ds_id; + get_reply.req_id = req_id; + get_reply.success = success; + get_reply.data = data; if (error_if_any) - getcfg_reply.error_if_any = (char *)error_if_any; + get_reply.error_if_any = (char *)error_if_any; mgmtd__fe_message__init(&fe_msg); - fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REPLY; - fe_msg.getcfg_reply = &getcfg_reply; + fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GET_REPLY; + fe_msg.get_reply = &get_reply; - MGMTD_FE_ADAPTER_DBG( - "Sending GET_CONFIG_REPLY message to MGMTD Frontend client '%s'", - session->adapter->name); + MGMTD_FE_ADAPTER_DBG("Sending GET_REPLY message to MGMTD Frontend client '%s'", + session->adapter->name); /* * Cleanup the SHOW transaction associated with this session. */ if (session->txn_id && (!success || (data && data->next_indx < 0))) - mgmt_fe_session_register_event( - session, MGMTD_FE_SESSION_SHOW_TXN_CLNUP); + mgmt_fe_session_register_event(session, + MGMTD_FE_SESSION_SHOW_TXN_CLNUP); - return mgmt_fe_adapter_send_msg(session->adapter, &fe_msg, false); + return fe_adapter_send_msg(session->adapter, &fe_msg, false); } -static int mgmt_fe_send_getdata_reply(struct mgmt_fe_session_ctx *session, - Mgmtd__DatastoreId ds_id, - uint64_t req_id, bool success, - Mgmtd__YangDataReply *data, - const char *error_if_any) -{ - Mgmtd__FeMessage fe_msg; - Mgmtd__FeGetDataReply getdata_reply; - - assert(session->adapter); - - mgmtd__fe_get_data_reply__init(&getdata_reply); - getdata_reply.session_id = session->session_id; - getdata_reply.ds_id = ds_id; - getdata_reply.req_id = req_id; - getdata_reply.success = success; - getdata_reply.data = data; - if (error_if_any) - getdata_reply.error_if_any = (char *)error_if_any; +static int fe_adapter_send_error(struct mgmt_fe_session_ctx *session, + uint64_t req_id, bool short_circuit_ok, + int16_t error, const char *errfmt, ...) + PRINTFRR(5, 6); - mgmtd__fe_message__init(&fe_msg); - fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GETDATA_REPLY; - fe_msg.getdata_reply = &getdata_reply; - - MGMTD_FE_ADAPTER_DBG( - "Sending GET_DATA_REPLY message to MGMTD Frontend client '%s'", - session->adapter->name); +static int fe_adapter_send_error(struct mgmt_fe_session_ctx *session, + uint64_t req_id, bool short_circuit_ok, + int16_t error, const char *errfmt, ...) +{ + va_list ap; + int ret; - /* - * Cleanup the SHOW transaction associated with this session. - */ - if (session->txn_id && (!success || (data && data->next_indx < 0))) - mgmt_fe_session_register_event( - session, MGMTD_FE_SESSION_SHOW_TXN_CLNUP); + va_start(ap, errfmt); + ret = vmgmt_msg_native_send_error(session->adapter->conn, + session->session_id, req_id, + short_circuit_ok, error, errfmt, ap); + va_end(ap); - return mgmt_fe_adapter_send_msg(session->adapter, &fe_msg, false); + return ret; } + static void mgmt_fe_session_cfg_txn_clnup(struct event *thread) { struct mgmt_fe_session_ctx *session; @@ -625,19 +569,6 @@ mgmt_fe_find_adapter_by_fd(int conn_fd) return NULL; } -static struct mgmt_fe_client_adapter * -mgmt_fe_find_adapter_by_name(const char *name) -{ - struct mgmt_fe_client_adapter *adapter; - - FOREACH_ADAPTER_IN_LIST (adapter) { - if (!strncmp(adapter->name, name, sizeof(adapter->name))) - return adapter; - } - - return NULL; -} - static void mgmt_fe_adapter_delete(struct mgmt_fe_client_adapter *adapter) { struct mgmt_fe_session_ctx *session; @@ -665,8 +596,7 @@ static int mgmt_fe_adapter_notify_disconnect(struct msg_conn *conn) } /* - * XXX chopps: get rid of this, we should have deleted sessions when there was a - * disconnect + * Purge any old connections that share the same client name with `adapter` */ static void mgmt_fe_adapter_cleanup_old_conn(struct mgmt_fe_client_adapter *adapter) @@ -674,17 +604,16 @@ mgmt_fe_adapter_cleanup_old_conn(struct mgmt_fe_client_adapter *adapter) struct mgmt_fe_client_adapter *old; FOREACH_ADAPTER_IN_LIST (old) { - if (old != adapter && - !strncmp(adapter->name, old->name, sizeof(adapter->name))) { - /* - * We have a Zombie lingering around - */ - MGMTD_FE_ADAPTER_DBG( - "Client '%s' (FD:%d) seems to have reconnected. Removing old connection (FD:%d)!", - adapter->name, adapter->conn->fd, - old->conn->fd); - msg_conn_disconnect(old->conn, false); - } + if (old == adapter) + continue; + if (strncmp(adapter->name, old->name, sizeof(adapter->name))) + continue; + + MGMTD_FE_ADAPTER_DBG( + "Client '%s' (FD:%d) seems to have reconnected. Removing old connection (FD:%d)", + adapter->name, adapter->conn->fd, + old->conn->fd); + msg_conn_disconnect(old->conn, false); } } @@ -694,57 +623,48 @@ mgmt_fe_session_handle_lockds_req_msg(struct mgmt_fe_session_ctx *session, { struct mgmt_ds_ctx *ds_ctx; - /* - * Next check first if the SETCFG_REQ is for Candidate DS - * or not. Report failure if its not. MGMTD currently only - * supports editing the Candidate DS. - */ - if (lockds_req->ds_id != MGMTD_DS_CANDIDATE) { - mgmt_fe_send_lockds_reply( + if (lockds_req->ds_id != MGMTD_DS_CANDIDATE && + lockds_req->ds_id != MGMTD_DS_RUNNING) { + fe_adapter_send_lockds_reply( session, lockds_req->ds_id, lockds_req->req_id, lockds_req->lock, false, - "Lock/Unlock on datastores other than Candidate DS not permitted!"); + "Lock/Unlock on DS other than candidate or running DS not supported"); return -1; } ds_ctx = mgmt_ds_get_ctx_by_id(mm, lockds_req->ds_id); if (!ds_ctx) { - mgmt_fe_send_lockds_reply( - session, lockds_req->ds_id, lockds_req->req_id, - lockds_req->lock, false, - "Failed to retrieve handle for DS!"); + fe_adapter_send_lockds_reply(session, lockds_req->ds_id, + lockds_req->req_id, + lockds_req->lock, false, + "Failed to retrieve handle for DS!"); return -1; } if (lockds_req->lock) { - if (mgmt_fe_session_write_lock_ds(lockds_req->ds_id, - ds_ctx, session) - != 0) { - mgmt_fe_send_lockds_reply( + if (mgmt_fe_session_write_lock_ds(lockds_req->ds_id, ds_ctx, + session)) { + fe_adapter_send_lockds_reply( session, lockds_req->ds_id, lockds_req->req_id, lockds_req->lock, false, "Lock already taken on DS by another session!"); return -1; } - - session->ds_locked_implict[lockds_req->ds_id] = false; } else { - if (!session->ds_write_locked[lockds_req->ds_id]) { - mgmt_fe_send_lockds_reply( + if (!session->ds_locked[lockds_req->ds_id]) { + fe_adapter_send_lockds_reply( session, lockds_req->ds_id, lockds_req->req_id, lockds_req->lock, false, "Lock on DS was not taken by this session!"); return 0; } - (void)mgmt_fe_session_unlock_ds(lockds_req->ds_id, ds_ctx, - session, true, false); + mgmt_fe_session_unlock_ds(lockds_req->ds_id, ds_ctx, session); } - if (mgmt_fe_send_lockds_reply(session, lockds_req->ds_id, - lockds_req->req_id, lockds_req->lock, - true, NULL) - != 0) { + if (fe_adapter_send_lockds_reply(session, lockds_req->ds_id, + lockds_req->req_id, lockds_req->lock, + true, NULL) != 0) { MGMTD_FE_ADAPTER_DBG( "Failed to send LOCK_DS_REPLY for DS %u session-id: %" PRIu64 " from %s", @@ -764,95 +684,66 @@ static int mgmt_fe_session_handle_setcfg_req_msg(struct mgmt_fe_session_ctx *session, Mgmtd__FeSetConfigReq *setcfg_req) { - uint64_t cfg_session_id; - struct mgmt_ds_ctx *ds_ctx, *dst_ds_ctx; + struct mgmt_ds_ctx *ds_ctx, *dst_ds_ctx = NULL; + bool txn_created = false; if (mm->perf_stats_en) gettimeofday(&session->adapter->setcfg_stats.last_start, NULL); - /* - * Next check first if the SETCFG_REQ is for Candidate DS - * or not. Report failure if its not. MGMTD currently only - * supports editing the Candidate DS. - */ + /* MGMTD currently only supports editing the candidate DS. */ if (setcfg_req->ds_id != MGMTD_DS_CANDIDATE) { - mgmt_fe_send_setcfg_reply( + fe_adapter_send_set_cfg_reply( session, setcfg_req->ds_id, setcfg_req->req_id, false, - "Set-Config on datastores other than Candidate DS not permitted!", + "Set-Config on datastores other than Candidate DS not supported", setcfg_req->implicit_commit); return 0; } - - /* - * Get the DS handle. - */ ds_ctx = mgmt_ds_get_ctx_by_id(mm, setcfg_req->ds_id); - if (!ds_ctx) { - mgmt_fe_send_setcfg_reply( + assert(ds_ctx); + + /* MGMTD currently only supports targetting the running DS. */ + if (setcfg_req->implicit_commit && + setcfg_req->commit_ds_id != MGMTD_DS_RUNNING) { + fe_adapter_send_set_cfg_reply( session, setcfg_req->ds_id, setcfg_req->req_id, false, - "No such DS exists!", setcfg_req->implicit_commit); + "Implicit commit on datastores other than running DS not supported", + setcfg_req->implicit_commit); + return 0; + } + dst_ds_ctx = mgmt_ds_get_ctx_by_id(mm, setcfg_req->commit_ds_id); + assert(dst_ds_ctx); + + /* User should have write lock to change the DS */ + if (!session->ds_locked[setcfg_req->ds_id]) { + fe_adapter_send_set_cfg_reply(session, setcfg_req->ds_id, + setcfg_req->req_id, false, + "Candidate DS is not locked", + setcfg_req->implicit_commit); return 0; } if (session->cfg_txn_id == MGMTD_TXN_ID_NONE) { - /* - * Check first if the current session can run a CONFIG - * transaction or not. Report failure if a CONFIG transaction - * from another session is already in progress. - */ - cfg_session_id = mgmt_config_txn_in_progress(); - if (cfg_session_id != MGMTD_SESSION_ID_NONE) { - assert(cfg_session_id != session->session_id); - mgmt_fe_send_setcfg_reply( - session, setcfg_req->ds_id, setcfg_req->req_id, - false, - "Configuration already in-progress through a different user session!", - setcfg_req->implicit_commit); - goto mgmt_fe_sess_handle_setcfg_req_failed; - } - - - /* - * Try taking write-lock on the requested DS (if not already). - */ - if (!session->ds_write_locked[setcfg_req->ds_id]) { - MGMTD_FE_ADAPTER_ERR( - "SETCFG_REQ on session-id: %" PRIu64 - " without obtaining lock", - session->session_id); - if (mgmt_fe_session_write_lock_ds(setcfg_req->ds_id, - ds_ctx, session) - != 0) { - mgmt_fe_send_setcfg_reply( - session, setcfg_req->ds_id, - setcfg_req->req_id, false, - "Failed to lock the DS!", - setcfg_req->implicit_commit); - goto mgmt_fe_sess_handle_setcfg_req_failed; - } - - session->ds_locked_implict[setcfg_req->ds_id] = true; - } + /* as we have the lock no-one else should have a config txn */ + assert(mgmt_config_txn_in_progress() == MGMTD_SESSION_ID_NONE); - /* - * Start a CONFIG Transaction (if not started already) - */ + /* Start a CONFIG Transaction (if not started already) */ session->cfg_txn_id = mgmt_create_txn(session->session_id, MGMTD_TXN_TYPE_CONFIG); if (session->cfg_txn_id == MGMTD_SESSION_ID_NONE) { - mgmt_fe_send_setcfg_reply( + fe_adapter_send_set_cfg_reply( session, setcfg_req->ds_id, setcfg_req->req_id, false, "Failed to create a Configuration session!", setcfg_req->implicit_commit); - goto mgmt_fe_sess_handle_setcfg_req_failed; + return 0; } + txn_created = true; MGMTD_FE_ADAPTER_DBG("Created new Config txn-id: %" PRIu64 " for session-id %" PRIu64, session->cfg_txn_id, session->session_id); } else { - MGMTD_FE_ADAPTER_ERR("Config txn-id: %" PRIu64 + MGMTD_FE_ADAPTER_DBG("Config txn-id: %" PRIu64 " for session-id: %" PRIu64 " already created", session->cfg_txn_id, session->session_id); @@ -862,7 +753,7 @@ mgmt_fe_session_handle_setcfg_req_msg(struct mgmt_fe_session_ctx *session, * In this scenario need to skip cleanup of the txn, * so setting implicit commit to false. */ - mgmt_fe_send_setcfg_reply( + fe_adapter_send_set_cfg_reply( session, setcfg_req->ds_id, setcfg_req->req_id, false, "A Configuration transaction is already in progress!", @@ -871,247 +762,97 @@ mgmt_fe_session_handle_setcfg_req_msg(struct mgmt_fe_session_ctx *session, } } - dst_ds_ctx = 0; - if (setcfg_req->implicit_commit) { - dst_ds_ctx = - mgmt_ds_get_ctx_by_id(mm, setcfg_req->commit_ds_id); - if (!dst_ds_ctx) { - mgmt_fe_send_setcfg_reply( - session, setcfg_req->ds_id, setcfg_req->req_id, - false, "No such commit DS exists!", - setcfg_req->implicit_commit); - return 0; - } - } - - /* - * Create the SETConfig request under the transaction. - */ - if (mgmt_txn_send_set_config_req( - session->cfg_txn_id, setcfg_req->req_id, setcfg_req->ds_id, - ds_ctx, setcfg_req->data, setcfg_req->n_data, - setcfg_req->implicit_commit, setcfg_req->commit_ds_id, - dst_ds_ctx) - != 0) { - mgmt_fe_send_setcfg_reply( - session, setcfg_req->ds_id, setcfg_req->req_id, false, - "Request processing for SET-CONFIG failed!", - setcfg_req->implicit_commit); - goto mgmt_fe_sess_handle_setcfg_req_failed; + /* Create the SETConfig request under the transaction. */ + if (mgmt_txn_send_set_config_req(session->cfg_txn_id, setcfg_req->req_id, + setcfg_req->ds_id, ds_ctx, + setcfg_req->data, setcfg_req->n_data, + setcfg_req->implicit_commit, + setcfg_req->commit_ds_id, + dst_ds_ctx) != 0) { + fe_adapter_send_set_cfg_reply(session, setcfg_req->ds_id, + setcfg_req->req_id, false, + "Request processing for SET-CONFIG failed!", + setcfg_req->implicit_commit); + + /* delete transaction if we just created it */ + if (txn_created) + mgmt_destroy_txn(&session->cfg_txn_id); } return 0; - -mgmt_fe_sess_handle_setcfg_req_failed: - - /* - * Delete transaction created recently. - */ - if (session->cfg_txn_id != MGMTD_TXN_ID_NONE) - mgmt_destroy_txn(&session->cfg_txn_id); - if (ds_ctx && session->ds_write_locked[setcfg_req->ds_id]) - mgmt_fe_session_unlock_ds(setcfg_req->ds_id, ds_ctx, session, - true, false); - - return 0; } -static int -mgmt_fe_session_handle_getcfg_req_msg(struct mgmt_fe_session_ctx *session, - Mgmtd__FeGetConfigReq *getcfg_req) +static int mgmt_fe_session_handle_get_req_msg(struct mgmt_fe_session_ctx *session, + Mgmtd__FeGetReq *get_req) { struct mgmt_ds_ctx *ds_ctx; + struct nb_config *cfg_root = NULL; + Mgmtd__DatastoreId ds_id = get_req->ds_id; + uint64_t req_id = get_req->req_id; - /* - * Get the DS handle. - */ - ds_ctx = mgmt_ds_get_ctx_by_id(mm, getcfg_req->ds_id); - if (!ds_ctx) { - mgmt_fe_send_getcfg_reply(session, getcfg_req->ds_id, - getcfg_req->req_id, false, NULL, - "No such DS exists!"); - return 0; - } - - /* - * Next check first if the GETCFG_REQ is for Candidate DS - * or not. Report failure if its not. MGMTD currently only - * supports editing the Candidate DS. - */ - if (getcfg_req->ds_id != MGMTD_DS_CANDIDATE - && getcfg_req->ds_id != MGMTD_DS_RUNNING) { - mgmt_fe_send_getcfg_reply( - session, getcfg_req->ds_id, getcfg_req->req_id, false, - NULL, - "Get-Config on datastores other than Candidate or Running DS not permitted!"); + if (ds_id != MGMTD_DS_CANDIDATE && ds_id != MGMTD_DS_RUNNING) { + fe_adapter_send_get_reply(session, ds_id, req_id, false, NULL, + "get-req on unsupported datastore"); return 0; } + ds_ctx = mgmt_ds_get_ctx_by_id(mm, ds_id); + assert(ds_ctx); if (session->txn_id == MGMTD_TXN_ID_NONE) { - /* - * Try taking read-lock on the requested DS (if not already - * locked). If the DS has already been write-locked by a ongoing - * CONFIG transaction we may allow reading the contents of the - * same DS. - */ - if (!session->ds_read_locked[getcfg_req->ds_id] - && !session->ds_write_locked[getcfg_req->ds_id]) { - if (mgmt_fe_session_read_lock_ds(getcfg_req->ds_id, - ds_ctx, session) - != 0) { - mgmt_fe_send_getcfg_reply( - session, getcfg_req->ds_id, - getcfg_req->req_id, false, NULL, - "Failed to lock the DS! Another session might have locked it!"); - goto mgmt_fe_sess_handle_getcfg_req_failed; - } - - session->ds_locked_implict[getcfg_req->ds_id] = true; - } - /* * Start a SHOW Transaction (if not started already) */ session->txn_id = mgmt_create_txn(session->session_id, MGMTD_TXN_TYPE_SHOW); if (session->txn_id == MGMTD_SESSION_ID_NONE) { - mgmt_fe_send_getcfg_reply( - session, getcfg_req->ds_id, getcfg_req->req_id, - false, NULL, - "Failed to create a Show transaction!"); - goto mgmt_fe_sess_handle_getcfg_req_failed; + fe_adapter_send_get_reply(session, ds_id, req_id, false, + NULL, + "Failed to create a Show transaction!"); + return -1; } MGMTD_FE_ADAPTER_DBG("Created new show txn-id: %" PRIu64 " for session-id: %" PRIu64, session->txn_id, session->session_id); } else { - MGMTD_FE_ADAPTER_DBG("Show txn-id: %" PRIu64 - " for session-id: %" PRIu64 - " already created", + fe_adapter_send_get_reply(session, ds_id, req_id, false, NULL, + "Request processing for GET failed!"); + MGMTD_FE_ADAPTER_DBG("Transaction in progress txn-id: %" PRIu64 + " for session-id: %" PRIu64, session->txn_id, session->session_id); + return -1; } /* - * Create a GETConfig request under the transaction. - */ - if (mgmt_txn_send_get_config_req(session->txn_id, getcfg_req->req_id, - getcfg_req->ds_id, ds_ctx, - getcfg_req->data, getcfg_req->n_data) - != 0) { - mgmt_fe_send_getcfg_reply( - session, getcfg_req->ds_id, getcfg_req->req_id, false, - NULL, "Request processing for GET-CONFIG failed!"); - goto mgmt_fe_sess_handle_getcfg_req_failed; - } - - return 0; - -mgmt_fe_sess_handle_getcfg_req_failed: - - /* - * Destroy the transaction created recently. + * Get a copy of the datastore config root, avoids locking. */ - if (session->txn_id != MGMTD_TXN_ID_NONE) - mgmt_destroy_txn(&session->txn_id); - if (ds_ctx && session->ds_read_locked[getcfg_req->ds_id]) - mgmt_fe_session_unlock_ds(getcfg_req->ds_id, ds_ctx, session, - false, true); - - return -1; -} - -static int -mgmt_fe_session_handle_getdata_req_msg(struct mgmt_fe_session_ctx *session, - Mgmtd__FeGetDataReq *getdata_req) -{ - struct mgmt_ds_ctx *ds_ctx; + cfg_root = nb_config_dup(mgmt_ds_get_nb_config(ds_ctx)); /* - * Get the DS handle. + * Create a GET request under the transaction. */ - ds_ctx = mgmt_ds_get_ctx_by_id(mm, getdata_req->ds_id); - if (!ds_ctx) { - mgmt_fe_send_getdata_reply(session, getdata_req->ds_id, - getdata_req->req_id, false, NULL, - "No such DS exists!"); - return 0; - } - - if (session->txn_id == MGMTD_TXN_ID_NONE) { - /* - * Try taking read-lock on the requested DS (if not already - * locked). If the DS has already been write-locked by a ongoing - * CONFIG transaction we may allow reading the contents of the - * same DS. - */ - if (!session->ds_read_locked[getdata_req->ds_id] - && !session->ds_write_locked[getdata_req->ds_id]) { - if (mgmt_fe_session_read_lock_ds(getdata_req->ds_id, - ds_ctx, session) - != 0) { - mgmt_fe_send_getdata_reply( - session, getdata_req->ds_id, - getdata_req->req_id, false, NULL, - "Failed to lock the DS! Another session might have locked it!"); - goto mgmt_fe_sess_handle_getdata_req_failed; - } - - session->ds_locked_implict[getdata_req->ds_id] = true; - } - - /* - * Start a SHOW Transaction (if not started already) - */ - session->txn_id = mgmt_create_txn(session->session_id, - MGMTD_TXN_TYPE_SHOW); - if (session->txn_id == MGMTD_SESSION_ID_NONE) { - mgmt_fe_send_getdata_reply( - session, getdata_req->ds_id, - getdata_req->req_id, false, NULL, - "Failed to create a Show transaction!"); - goto mgmt_fe_sess_handle_getdata_req_failed; - } - - MGMTD_FE_ADAPTER_DBG("Created new Show Txn %" PRIu64 - " for session %" PRIu64, - session->txn_id, session->session_id); - } else { - MGMTD_FE_ADAPTER_DBG("Show txn-id: %" PRIu64 - " for session %" PRIu64 " already created", - session->txn_id, session->session_id); - } + if (mgmt_txn_send_get_req(session->txn_id, req_id, ds_id, cfg_root, + get_req->data, get_req->n_data)) { + fe_adapter_send_get_reply(session, ds_id, req_id, false, NULL, + "Request processing for GET failed!"); - /* - * Create a GETData request under the transaction. - */ - if (mgmt_txn_send_get_data_req(session->txn_id, getdata_req->req_id, - getdata_req->ds_id, ds_ctx, - getdata_req->data, getdata_req->n_data) - != 0) { - mgmt_fe_send_getdata_reply( - session, getdata_req->ds_id, getdata_req->req_id, false, - NULL, "Request processing for GET-CONFIG failed!"); - goto mgmt_fe_sess_handle_getdata_req_failed; + goto failed; } return 0; - -mgmt_fe_sess_handle_getdata_req_failed: - +failed: + if (cfg_root) + nb_config_free(cfg_root); /* * Destroy the transaction created recently. */ if (session->txn_id != MGMTD_TXN_ID_NONE) mgmt_destroy_txn(&session->txn_id); - if (ds_ctx && session->ds_read_locked[getdata_req->ds_id]) - mgmt_fe_session_unlock_ds(getdata_req->ds_id, ds_ctx, - session, false, true); - return -1; } + static int mgmt_fe_session_handle_commit_config_req_msg( struct mgmt_fe_session_ctx *session, Mgmtd__FeCommitConfigReq *commcfg_req) @@ -1121,43 +862,30 @@ static int mgmt_fe_session_handle_commit_config_req_msg( if (mm->perf_stats_en) gettimeofday(&session->adapter->cmt_stats.last_start, NULL); session->adapter->cmt_stats.commit_cnt++; - /* - * Get the source DS handle. - */ - src_ds_ctx = mgmt_ds_get_ctx_by_id(mm, commcfg_req->src_ds_id); - if (!src_ds_ctx) { - mgmt_fe_send_commitcfg_reply( - session, commcfg_req->src_ds_id, commcfg_req->dst_ds_id, - commcfg_req->req_id, MGMTD_INTERNAL_ERROR, - commcfg_req->validate_only, - "No such source DS exists!"); - return 0; - } - /* - * Get the destination DS handle. - */ - dst_ds_ctx = mgmt_ds_get_ctx_by_id(mm, commcfg_req->dst_ds_id); - if (!dst_ds_ctx) { - mgmt_fe_send_commitcfg_reply( + /* Validate source and dest DS */ + if (commcfg_req->src_ds_id != MGMTD_DS_CANDIDATE || + commcfg_req->dst_ds_id != MGMTD_DS_RUNNING) { + fe_adapter_send_commit_cfg_reply( session, commcfg_req->src_ds_id, commcfg_req->dst_ds_id, commcfg_req->req_id, MGMTD_INTERNAL_ERROR, commcfg_req->validate_only, - "No such destination DS exists!"); + "Source/Dest for commit must be candidate/running DS"); return 0; } + src_ds_ctx = mgmt_ds_get_ctx_by_id(mm, commcfg_req->src_ds_id); + assert(src_ds_ctx); + dst_ds_ctx = mgmt_ds_get_ctx_by_id(mm, commcfg_req->dst_ds_id); + assert(dst_ds_ctx); - /* - * Next check first if the COMMCFG_REQ is for Candidate DS - * or not. Report failure if its not. MGMTD currently only - * supports editing the Candidate DS. - */ - if (commcfg_req->dst_ds_id != MGMTD_DS_RUNNING) { - mgmt_fe_send_commitcfg_reply( + /* User should have lock on both source and dest DS */ + if (!session->ds_locked[commcfg_req->dst_ds_id] || + !session->ds_locked[commcfg_req->src_ds_id]) { + fe_adapter_send_commit_cfg_reply( session, commcfg_req->src_ds_id, commcfg_req->dst_ds_id, - commcfg_req->req_id, MGMTD_INTERNAL_ERROR, + commcfg_req->req_id, MGMTD_DS_LOCK_FAILED, commcfg_req->validate_only, - "Set-Config on datastores other than Running DS not permitted!"); + "Commit requires lock on candidate and/or running DS"); return 0; } @@ -1168,11 +896,10 @@ static int mgmt_fe_session_handle_commit_config_req_msg( session->cfg_txn_id = mgmt_create_txn(session->session_id, MGMTD_TXN_TYPE_CONFIG); if (session->cfg_txn_id == MGMTD_SESSION_ID_NONE) { - mgmt_fe_send_commitcfg_reply( + fe_adapter_send_commit_cfg_reply( session, commcfg_req->src_ds_id, commcfg_req->dst_ds_id, commcfg_req->req_id, - MGMTD_INTERNAL_ERROR, - commcfg_req->validate_only, + MGMTD_INTERNAL_ERROR, commcfg_req->validate_only, "Failed to create a Configuration session!"); return 0; } @@ -1182,26 +909,6 @@ static int mgmt_fe_session_handle_commit_config_req_msg( session->cfg_txn_id, session->session_id); } - - /* - * Try taking write-lock on the destination DS (if not already). - */ - if (!session->ds_write_locked[commcfg_req->dst_ds_id]) { - if (mgmt_fe_session_write_lock_ds(commcfg_req->dst_ds_id, - dst_ds_ctx, session) - != 0) { - mgmt_fe_send_commitcfg_reply( - session, commcfg_req->src_ds_id, - commcfg_req->dst_ds_id, commcfg_req->req_id, - MGMTD_DS_LOCK_FAILED, - commcfg_req->validate_only, - "Failed to lock the destination DS!"); - return 0; - } - - session->ds_locked_implict[commcfg_req->dst_ds_id] = true; - } - /* * Create COMMITConfig request under the transaction */ @@ -1209,9 +916,8 @@ static int mgmt_fe_session_handle_commit_config_req_msg( session->cfg_txn_id, commcfg_req->req_id, commcfg_req->src_ds_id, src_ds_ctx, commcfg_req->dst_ds_id, dst_ds_ctx, commcfg_req->validate_only, commcfg_req->abort, - false) - != 0) { - mgmt_fe_send_commitcfg_reply( + false) != 0) { + fe_adapter_send_commit_cfg_reply( session, commcfg_req->src_ds_id, commcfg_req->dst_ds_id, commcfg_req->req_id, MGMTD_INTERNAL_ERROR, commcfg_req->validate_only, @@ -1256,8 +962,8 @@ mgmt_fe_adapter_handle_msg(struct mgmt_fe_client_adapter *adapter, session = mgmt_fe_create_session( adapter, fe_msg->session_req->client_conn_id); - mgmt_fe_send_session_reply(adapter, session, true, - session ? true : false); + fe_adapter_send_session_reply(adapter, session, true, + session ? true : false); } else if ( !fe_msg->session_req->create && fe_msg->session_req->id_case @@ -1269,8 +975,8 @@ mgmt_fe_adapter_handle_msg(struct mgmt_fe_client_adapter *adapter, session = mgmt_session_id2ctx( fe_msg->session_req->session_id); - mgmt_fe_send_session_reply(adapter, session, false, - true); + fe_adapter_send_session_reply(adapter, session, false, + true); mgmt_fe_cleanup_session(&session); } break; @@ -1278,10 +984,10 @@ mgmt_fe_adapter_handle_msg(struct mgmt_fe_client_adapter *adapter, session = mgmt_session_id2ctx( fe_msg->lockds_req->session_id); MGMTD_FE_ADAPTER_DBG( - "Got %sLOCKDS_REQ for DS:%d for session-id %" PRIu64 + "Got LOCKDS_REQ (%sLOCK) for DS:%s for session-id %" PRIu64 " from '%s'", fe_msg->lockds_req->lock ? "" : "UN", - fe_msg->lockds_req->ds_id, + mgmt_ds_id2name(fe_msg->lockds_req->ds_id), fe_msg->lockds_req->session_id, adapter->name); mgmt_fe_session_handle_lockds_req_msg( session, fe_msg->lockds_req); @@ -1291,11 +997,11 @@ mgmt_fe_adapter_handle_msg(struct mgmt_fe_client_adapter *adapter, fe_msg->setcfg_req->session_id); session->adapter->setcfg_stats.set_cfg_count++; MGMTD_FE_ADAPTER_DBG( - "Got SETCFG_REQ (%d Xpaths, Implicit:%c) on DS:%d for session-id %" PRIu64 + "Got SETCFG_REQ (%d Xpaths, Implicit:%c) on DS:%s for session-id %" PRIu64 " from '%s'", (int)fe_msg->setcfg_req->n_data, fe_msg->setcfg_req->implicit_commit ? 'T' : 'F', - fe_msg->setcfg_req->ds_id, + mgmt_ds_id2name(fe_msg->setcfg_req->ds_id), fe_msg->setcfg_req->session_id, adapter->name); mgmt_fe_session_handle_setcfg_req_msg( @@ -1305,38 +1011,23 @@ mgmt_fe_adapter_handle_msg(struct mgmt_fe_client_adapter *adapter, session = mgmt_session_id2ctx( fe_msg->commcfg_req->session_id); MGMTD_FE_ADAPTER_DBG( - "Got COMMCFG_REQ for src-DS:%d dst-DS:%d (Abort:%c) on session-id %" PRIu64 + "Got COMMCFG_REQ for src-DS:%s dst-DS:%s (Abort:%c) on session-id %" PRIu64 " from '%s'", - fe_msg->commcfg_req->src_ds_id, - fe_msg->commcfg_req->dst_ds_id, + mgmt_ds_id2name(fe_msg->commcfg_req->src_ds_id), + mgmt_ds_id2name(fe_msg->commcfg_req->dst_ds_id), fe_msg->commcfg_req->abort ? 'T' : 'F', fe_msg->commcfg_req->session_id, adapter->name); mgmt_fe_session_handle_commit_config_req_msg( session, fe_msg->commcfg_req); break; - case MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REQ: - session = mgmt_session_id2ctx( - fe_msg->getcfg_req->session_id); - MGMTD_FE_ADAPTER_DBG( - "Got GETCFG_REQ for DS:%d (xpaths: %d) on session-id %" PRIu64 - " from '%s'", - fe_msg->getcfg_req->ds_id, - (int)fe_msg->getcfg_req->n_data, - fe_msg->getcfg_req->session_id, adapter->name); - mgmt_fe_session_handle_getcfg_req_msg( - session, fe_msg->getcfg_req); - break; - case MGMTD__FE_MESSAGE__MESSAGE_GETDATA_REQ: - session = mgmt_session_id2ctx( - fe_msg->getdata_req->session_id); - MGMTD_FE_ADAPTER_DBG( - "Got GETDATA_REQ for DS:%d (xpaths: %d) on session-id %" PRIu64 - " from '%s'", - fe_msg->getdata_req->ds_id, - (int)fe_msg->getdata_req->n_data, - fe_msg->getdata_req->session_id, adapter->name); - mgmt_fe_session_handle_getdata_req_msg( - session, fe_msg->getdata_req); + case MGMTD__FE_MESSAGE__MESSAGE_GET_REQ: + session = mgmt_session_id2ctx(fe_msg->get_req->session_id); + MGMTD_FE_ADAPTER_DBG("Got GET_REQ for DS:%s (xpaths: %d) on session-id %" PRIu64 + " from '%s'", + mgmt_ds_id2name(fe_msg->get_req->ds_id), + (int)fe_msg->get_req->n_data, + fe_msg->get_req->session_id, adapter->name); + mgmt_fe_session_handle_get_req_msg(session, fe_msg->get_req); break; case MGMTD__FE_MESSAGE__MESSAGE_NOTIFY_DATA_REQ: case MGMTD__FE_MESSAGE__MESSAGE_REGNOTIFY_REQ: @@ -1355,8 +1046,7 @@ mgmt_fe_adapter_handle_msg(struct mgmt_fe_client_adapter *adapter, case MGMTD__FE_MESSAGE__MESSAGE_LOCKDS_REPLY: case MGMTD__FE_MESSAGE__MESSAGE_SETCFG_REPLY: case MGMTD__FE_MESSAGE__MESSAGE_COMMCFG_REPLY: - case MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REPLY: - case MGMTD__FE_MESSAGE__MESSAGE_GETDATA_REPLY: + case MGMTD__FE_MESSAGE__MESSAGE_GET_REPLY: case MGMTD__FE_MESSAGE__MESSAGE__NOT_SET: default: /* @@ -1371,12 +1061,215 @@ mgmt_fe_adapter_handle_msg(struct mgmt_fe_client_adapter *adapter, return 0; } +/** + * Send result of get-tree request back to the FE client. + * + * Args: + * session: the session. + * req_id: the request ID. + * short_circuit_ok: if allowed to short circuit the message. + * result_format: LYD_FORMAT for the sent output. + * tree: the tree to send, can be NULL which will send an empty tree. + * partial_error: if an error occurred during gathering results. + * + * Return: + * Any error that occurs -- the message is likely not sent if non-zero. + */ +static int fe_adapter_send_tree_data(struct mgmt_fe_session_ctx *session, + uint64_t req_id, bool short_circuit_ok, + uint8_t result_type, + const struct lyd_node *tree, + int partial_error) + +{ + struct mgmt_msg_tree_data *msg; + struct lyd_node *empty = NULL; + uint8_t *buf = NULL; + int ret = 0; + + darr_append_n(buf, offsetof(typeof(*msg), result)); + msg = (typeof(msg))buf; + msg->refer_id = session->session_id; + msg->req_id = req_id; + msg->code = MGMT_MSG_CODE_TREE_DATA; + msg->partial_error = partial_error; + msg->result_type = result_type; + + if (!tree) { + empty = yang_dnode_new(ly_native_ctx, false); + tree = empty; + } + + ret = yang_print_tree_append(&buf, tree, result_type, + (LYD_PRINT_WD_EXPLICIT | + LYD_PRINT_WITHSIBLINGS)); + /* buf may have been reallocated and moved */ + msg = (typeof(msg))buf; + (void)msg; /* suppress clang-SA unused warning on safety code */ + + if (ret != LY_SUCCESS) { + MGMTD_FE_ADAPTER_ERR("Error building get-tree result for client %s session-id %" PRIu64 + " req-id %" PRIu64 + " scok %d result type %u", + session->adapter->name, session->session_id, + req_id, short_circuit_ok, result_type); + goto done; + } + + MGMTD_FE_ADAPTER_DBG("Sending get-tree result from adapter %s to session-id %" PRIu64 + " req-id %" PRIu64 " scok %d result type %u len %u", + session->adapter->name, session->session_id, req_id, + short_circuit_ok, result_type, darr_len(buf)); + + ret = fe_adapter_send_native_msg(session->adapter, buf, darr_len(buf), + short_circuit_ok); +done: + if (empty) + yang_dnode_free(empty); + darr_free(buf); + + return ret; +} + +/** + * fe_adapter_handle_get_tree() - Handle a get-tree message from a FE client. + * @session: the client session. + * @msg_raw: the message data. + * @msg_len: the length of the message data. + */ +static void fe_adapter_handle_get_tree(struct mgmt_fe_session_ctx *session, + void *__msg, size_t msg_len) +{ + struct mgmt_msg_get_tree *msg = __msg; + struct lysc_node **snodes = NULL; + char *xpath_resolved = NULL; + uint64_t req_id = msg->req_id; + uint64_t clients; + bool simple_xpath; + LY_ERR err; + int ret; + + MGMTD_FE_ADAPTER_DBG("Received get-tree request from client %s for session-id %" PRIu64 + " req-id %" PRIu64, + session->adapter->name, session->session_id, + msg->req_id); + + if (!MGMT_MSG_VALIDATE_NUL_TERM(msg, msg_len)) { + fe_adapter_send_error(session, req_id, false, -EINVAL, + "Invalid message rcvd from session-id: %" PRIu64, + session->session_id); + goto done; + } + + if (session->txn_id != MGMTD_TXN_ID_NONE) { + fe_adapter_send_error(session, req_id, false, -EINPROGRESS, + "Transaction in progress txn-id: %" PRIu64 + " for session-id: %" PRIu64, + session->txn_id, session->session_id); + goto done; + } + + + err = yang_resolve_snode_xpath(ly_native_ctx, msg->xpath, &snodes, + &simple_xpath); + if (err) { + fe_adapter_send_error(session, req_id, false, -EINPROGRESS, + "XPath doesn't resolve for session-id: %" PRIu64, + session->session_id); + goto done; + } + darr_free(snodes); + + clients = mgmt_be_interested_clients(msg->xpath, false); + if (!clients) { + MGMTD_FE_ADAPTER_DBG("No backends provide xpath: %s for txn-id: %" PRIu64 + " session-id: %" PRIu64, + msg->xpath, session->txn_id, + session->session_id); + + fe_adapter_send_tree_data(session, req_id, false, + msg->result_type, NULL, 0); + goto done; + } + + /* Start a SHOW Transaction */ + session->txn_id = mgmt_create_txn(session->session_id, + MGMTD_TXN_TYPE_SHOW); + if (session->txn_id == MGMTD_SESSION_ID_NONE) { + fe_adapter_send_error(session, req_id, false, -EINPROGRESS, + "failed to create a 'show' txn"); + goto done; + } + + MGMTD_FE_ADAPTER_DBG("Created new show txn-id: %" PRIu64 + " for session-id: %" PRIu64, + session->txn_id, session->session_id); + + /* Create a GET-TREE request under the transaction */ + ret = mgmt_txn_send_get_tree_oper(session->txn_id, req_id, clients, + msg->result_type, simple_xpath, + msg->xpath); + if (ret) { + /* destroy the just created txn */ + mgmt_destroy_txn(&session->txn_id); + fe_adapter_send_error(session, req_id, false, -EINPROGRESS, + "failed to create a 'show' txn"); + } +done: + darr_free(snodes); + darr_free(xpath_resolved); +} + +/** + * Handle a native encoded message from the FE client. + */ +static void fe_adapter_handle_native_msg(struct mgmt_fe_client_adapter *adapter, + struct mgmt_msg_header *msg, + size_t msg_len) +{ + struct mgmt_fe_session_ctx *session; + + session = mgmt_session_id2ctx(msg->refer_id); + if (!session) { + MGMTD_FE_ADAPTER_ERR("adapter %s: recv msg unknown session-id %" PRIu64, + adapter->name, msg->refer_id); + return; + } + assert(session->adapter == adapter); + + switch (msg->code) { + case MGMT_MSG_CODE_GET_TREE: + fe_adapter_handle_get_tree(session, msg, msg_len); + break; + default: + MGMTD_FE_ADAPTER_ERR("unknown native message session-id %" PRIu64 + " req-id %" PRIu64 + " code %u to FE adapter %s", + msg->refer_id, msg->req_id, msg->code, + adapter->name); + break; + } +} + + static void mgmt_fe_adapter_process_msg(uint8_t version, uint8_t *data, size_t len, struct msg_conn *conn) { struct mgmt_fe_client_adapter *adapter = conn->user; - Mgmtd__FeMessage *fe_msg = mgmtd__fe_message__unpack(NULL, len, data); + Mgmtd__FeMessage *fe_msg; + if (version == MGMT_MSG_VERSION_NATIVE) { + struct mgmt_msg_header *msg = (typeof(msg))data; + + if (len >= sizeof(*msg)) + fe_adapter_handle_native_msg(adapter, msg, len); + else + MGMTD_FE_ADAPTER_ERR("native message to adapter %s too short %zu", + adapter->name, len); + return; + } + + fe_msg = mgmtd__fe_message__unpack(NULL, len, data); if (!fe_msg) { MGMTD_FE_ADAPTER_DBG( "Failed to decode %zu bytes for adapter: %s", len, @@ -1480,9 +1373,12 @@ struct msg_conn *mgmt_fe_create_adapter(int conn_fd, union sockunion *from) adapter->conn = msg_server_conn_create( mgmt_loop, conn_fd, mgmt_fe_adapter_notify_disconnect, mgmt_fe_adapter_process_msg, MGMTD_FE_MAX_NUM_MSG_PROC, - MGMTD_FE_MAX_NUM_MSG_WRITE, MGMTD_FE_MSG_MAX_LEN, + MGMTD_FE_MAX_NUM_MSG_WRITE, MGMTD_FE_MAX_MSG_LEN, adapter, "FE-adapter"); + adapter->conn->debug = DEBUG_MODE_CHECK(&mgmt_debug_fe, + DEBUG_MODE_ALL); + adapter->setcfg_stats.min_tm = ULONG_MAX; adapter->cmt_stats.min_tm = ULONG_MAX; MGMTD_FE_ADAPTER_DBG("Added new MGMTD Frontend adapter '%s'", @@ -1491,11 +1387,6 @@ struct msg_conn *mgmt_fe_create_adapter(int conn_fd, union sockunion *from) return adapter->conn; } -struct mgmt_fe_client_adapter *mgmt_fe_get_adapter(const char *name) -{ - return mgmt_fe_find_adapter_by_name(name); -} - int mgmt_fe_send_set_cfg_reply(uint64_t session_id, uint64_t txn_id, Mgmtd__DatastoreId ds_id, uint64_t req_id, enum mgmt_result result, @@ -1514,9 +1405,9 @@ int mgmt_fe_send_set_cfg_reply(uint64_t session_id, uint64_t txn_id, return -1; } - return mgmt_fe_send_setcfg_reply( - session, ds_id, req_id, result == MGMTD_SUCCESS ? true : false, - error_if_any, implicit_commit); + return fe_adapter_send_set_cfg_reply(session, ds_id, req_id, + result == MGMTD_SUCCESS, + error_if_any, implicit_commit); } int mgmt_fe_send_commit_cfg_reply(uint64_t session_id, uint64_t txn_id, @@ -1532,16 +1423,16 @@ int mgmt_fe_send_commit_cfg_reply(uint64_t session_id, uint64_t txn_id, if (!session || session->cfg_txn_id != txn_id) return -1; - return mgmt_fe_send_commitcfg_reply(session, src_ds_id, dst_ds_id, + return fe_adapter_send_commit_cfg_reply(session, src_ds_id, dst_ds_id, req_id, result, validate_only, error_if_any); } -int mgmt_fe_send_get_cfg_reply(uint64_t session_id, uint64_t txn_id, - Mgmtd__DatastoreId ds_id, uint64_t req_id, - enum mgmt_result result, - Mgmtd__YangDataReply *data_resp, - const char *error_if_any) +int mgmt_fe_send_get_reply(uint64_t session_id, uint64_t txn_id, + Mgmtd__DatastoreId ds_id, uint64_t req_id, + enum mgmt_result result, + Mgmtd__YangDataReply *data_resp, + const char *error_if_any) { struct mgmt_fe_session_ctx *session; @@ -1549,38 +1440,59 @@ int mgmt_fe_send_get_cfg_reply(uint64_t session_id, uint64_t txn_id, if (!session || session->txn_id != txn_id) return -1; - return mgmt_fe_send_getcfg_reply(session, ds_id, req_id, - result == MGMTD_SUCCESS, data_resp, - error_if_any); + return fe_adapter_send_get_reply(session, ds_id, req_id, + result == MGMTD_SUCCESS, data_resp, + error_if_any); } -int mgmt_fe_send_get_data_reply(uint64_t session_id, uint64_t txn_id, - Mgmtd__DatastoreId ds_id, uint64_t req_id, - enum mgmt_result result, - Mgmtd__YangDataReply *data_resp, - const char *error_if_any) +int mgmt_fe_adapter_send_tree_data(uint64_t session_id, uint64_t txn_id, + uint64_t req_id, LYD_FORMAT result_type, + const struct lyd_node *tree, + int partial_error, bool short_circuit_ok) { struct mgmt_fe_session_ctx *session; + int ret; session = mgmt_session_id2ctx(session_id); if (!session || session->txn_id != txn_id) return -1; - return mgmt_fe_send_getdata_reply(session, ds_id, req_id, - result == MGMTD_SUCCESS, - data_resp, error_if_any); + ret = fe_adapter_send_tree_data(session, req_id, short_circuit_ok, + result_type, tree, partial_error); + + mgmt_destroy_txn(&session->txn_id); + + return ret; } -int mgmt_fe_send_data_notify(Mgmtd__DatastoreId ds_id, - Mgmtd__YangData * data_resp[], int num_data) +/** + * Send an error back to the FE client and cleanup any in-progress txn. + */ +int mgmt_fe_adapter_txn_error(uint64_t txn_id, uint64_t req_id, + bool short_circuit_ok, int16_t error, + const char *errstr) { - /* struct mgmt_fe_session_ctx *session; */ + struct mgmt_fe_session_ctx *session; + int ret; + + session = fe_adapter_session_by_txn_id(txn_id); + if (!session) { + MGMTD_FE_ADAPTER_ERR("failed sending error for txn-id %" PRIu64 + " session not found", + txn_id); + return -ENOENT; + } - return 0; + + ret = fe_adapter_send_error(session, req_id, false, error, "%s", errstr); + + mgmt_destroy_txn(&session->txn_id); + + return ret; } -struct mgmt_setcfg_stats * -mgmt_fe_get_session_setcfg_stats(uint64_t session_id) + +struct mgmt_setcfg_stats *mgmt_fe_get_session_setcfg_stats(uint64_t session_id) { struct mgmt_fe_session_ctx *session; @@ -1738,18 +1650,10 @@ void mgmt_fe_adapter_status_write(struct vty *vty, bool detail) session->session_id); vty_out(vty, " DS-Locks:\n"); FOREACH_MGMTD_DS_ID (ds_id) { - if (session->ds_write_locked[ds_id] - || session->ds_read_locked[ds_id]) { + if (session->ds_locked[ds_id]) { locked = true; - vty_out(vty, - " %s\t\t\t%s, %s\n", - mgmt_ds_id2name(ds_id), - session->ds_write_locked[ds_id] - ? "Write" - : "Read", - session->ds_locked_implict[ds_id] - ? "Implicit" - : "Explicit"); + vty_out(vty, " %s\n", + mgmt_ds_id2name(ds_id)); } } if (!locked) diff --git a/mgmtd/mgmt_fe_adapter.h b/mgmtd/mgmt_fe_adapter.h index fef205f36a..09d64415bc 100644 --- a/mgmtd/mgmt_fe_adapter.h +++ b/mgmtd/mgmt_fe_adapter.h @@ -12,7 +12,7 @@ #include "mgmt_fe_client.h" #include "mgmt_msg.h" -#include "mgmtd/mgmt_defines.h" +#include "mgmt_defines.h" struct mgmt_fe_client_adapter; struct mgmt_master; @@ -87,10 +87,6 @@ mgmt_fe_adapter_unlock(struct mgmt_fe_client_adapter **adapter); extern struct msg_conn *mgmt_fe_create_adapter(int conn_fd, union sockunion *su); -/* Fetch frontend adapter given a name */ -extern struct mgmt_fe_client_adapter * -mgmt_fe_get_adapter(const char *name); - /* * Send set-config reply to the frontend client. * @@ -134,29 +130,59 @@ extern int mgmt_fe_send_commit_cfg_reply( enum mgmt_result result, const char *error_if_any); /* - * Send get-config reply to the frontend client. + * Send get-config/get-data reply to the frontend client. */ -extern int mgmt_fe_send_get_cfg_reply(uint64_t session_id, uint64_t txn_id, - Mgmtd__DatastoreId ds_id, +extern int mgmt_fe_send_get_reply(uint64_t session_id, uint64_t txn_id, + Mgmtd__DatastoreId ds_id, uint64_t req_id, + enum mgmt_result result, + Mgmtd__YangDataReply *data_resp, + const char *error_if_any); + +/** + * Send get-tree data reply back to client. + * + * This also cleans up and frees the transaction. + * + * Args: + * session_id: the session. + * txn_id: the txn_id this data pertains to + * req_id: the req id for the get_tree message + * result_type: the format of the result data. + * tree: the results. + * partial_error: if there were errors while gather results. + * short_circuit_ok: True if OK to short-circuit the call. + * + * Return: + * the return value from the underlying send function. + * + */ +extern int mgmt_fe_adapter_send_tree_data(uint64_t session_id, uint64_t txn_id, uint64_t req_id, - enum mgmt_result result, - Mgmtd__YangDataReply *data_resp, - const char *error_if_any); + LYD_FORMAT result_type, + const struct lyd_node *tree, + int partial_error, + bool short_circuit_ok); -/* - * Send get-data reply to the frontend client. +/** + * Send an error back to the FE client using native messaging. + * + * This also cleans up and frees the transaction. + * + * Args: + * txn_id: the txn_id this error pertains to. + * short_circuit_ok: True if OK to short-circuit the call. + * error: An integer error value. + * errfmt: An error format string (i.e., printfrr) + * ...: args for use by the `errfmt` format string. + * + * Return: + * the return value from the underlying send function. + * */ -extern int mgmt_fe_send_get_data_reply( - uint64_t session_id, uint64_t txn_id, Mgmtd__DatastoreId ds_id, - uint64_t req_id, enum mgmt_result result, - Mgmtd__YangDataReply *data_resp, const char *error_if_any); +extern int mgmt_fe_adapter_txn_error(uint64_t txn_id, uint64_t req_id, + bool short_circuit_ok, int16_t error, + const char *errstr); -/* - * Send data notify to the frontend client. - */ -extern int mgmt_fe_send_data_notify(Mgmtd__DatastoreId ds_id, - Mgmtd__YangData * data_resp[], - int num_data); /* Fetch frontend client session set-config stats */ extern struct mgmt_setcfg_stats * @@ -169,4 +195,8 @@ mgmt_fe_get_session_commit_stats(uint64_t session_id); extern void mgmt_fe_adapter_status_write(struct vty *vty, bool detail); extern void mgmt_fe_adapter_perf_measurement(struct vty *vty, bool config); extern void mgmt_fe_adapter_reset_perf_stats(struct vty *vty); + +/* Toggle debug on or off for connected clients. */ +extern void mgmt_fe_adapter_toggle_client_debug(bool set); + #endif /* _FRR_MGMTD_FE_ADAPTER_H_ */ diff --git a/mgmtd/mgmt_history.c b/mgmtd/mgmt_history.c index ab84b1efcf..ddc5a1844e 100644 --- a/mgmtd/mgmt_history.c +++ b/mgmtd/mgmt_history.c @@ -196,23 +196,21 @@ static int mgmt_history_rollback_to_cmt(struct vty *vty, } src_ds_ctx = mgmt_ds_get_ctx_by_id(mm, MGMTD_DS_CANDIDATE); - if (!src_ds_ctx) { - vty_out(vty, "ERROR: Couldnot access Candidate datastore!\n"); - return -1; - } - - /* - * Note: Write lock on src_ds is not required. This is already - * taken in 'conf te'. - */ dst_ds_ctx = mgmt_ds_get_ctx_by_id(mm, MGMTD_DS_RUNNING); - if (!dst_ds_ctx) { - vty_out(vty, "ERROR: Couldnot access Running datastore!\n"); + assert(src_ds_ctx); + assert(dst_ds_ctx); + + ret = mgmt_ds_lock(src_ds_ctx, vty->mgmt_session_id); + if (ret != 0) { + vty_out(vty, + "Failed to lock the DS %u for rollback Reason: %s!\n", + MGMTD_DS_RUNNING, strerror(ret)); return -1; } - ret = mgmt_ds_write_lock(dst_ds_ctx); + ret = mgmt_ds_lock(dst_ds_ctx, vty->mgmt_session_id); if (ret != 0) { + mgmt_ds_unlock(src_ds_ctx); vty_out(vty, "Failed to lock the DS %u for rollback Reason: %s!\n", MGMTD_DS_RUNNING, strerror(ret)); @@ -223,39 +221,49 @@ static int mgmt_history_rollback_to_cmt(struct vty *vty, ret = mgmt_ds_load_config_from_file( src_ds_ctx, cmt_info->cmt_json_file, false); if (ret != 0) { - mgmt_ds_unlock(dst_ds_ctx); vty_out(vty, "Error with parsing the file with error code %d\n", ret); - return ret; + goto failed_unlock; } } /* Internally trigger a commit-request. */ ret = mgmt_txn_rollback_trigger_cfg_apply(src_ds_ctx, dst_ds_ctx); if (ret != 0) { - mgmt_ds_unlock(dst_ds_ctx); vty_out(vty, "Error with creating commit apply txn with error code %d\n", ret); - return ret; + goto failed_unlock; } mgmt_history_dump_cmt_record_index(); + /* + * TODO: Cleanup: the generic TXN code currently checks for rollback + * and does the unlock when it completes. + */ + /* * Block the rollback command from returning till the rollback * is completed. On rollback completion mgmt_history_rollback_complete() * shall be called to resume the rollback command return to VTYSH. */ - vty->mgmt_req_pending = true; + vty->mgmt_req_pending_cmd = "ROLLBACK"; rollback_vty = vty; return 0; + +failed_unlock: + mgmt_ds_unlock(src_ds_ctx); + mgmt_ds_unlock(dst_ds_ctx); + return ret; } void mgmt_history_rollback_complete(bool success) { - vty_mgmt_resume_response(rollback_vty, success); + vty_mgmt_resume_response(rollback_vty, + success ? CMD_SUCCESS + : CMD_WARNING_CONFIG_FAILED); rollback_vty = NULL; } diff --git a/mgmtd/mgmt_history.h b/mgmtd/mgmt_history.h index d3f7958952..5d9b662694 100644 --- a/mgmtd/mgmt_history.h +++ b/mgmtd/mgmt_history.h @@ -74,9 +74,11 @@ mgmt_time_to_string(struct timespec *tv, bool long_fmt, char *buffer, size_t sz) if (long_fmt) { n = strftime(buffer, sz, MGMT_LONG_TIME_FMT, &tm); + assert(n < sz); snprintf(&buffer[n], sz - n, ",%09lu", tv->tv_nsec); } else { n = strftime(buffer, sz, MGMT_SHORT_TIME_FMT, &tm); + assert(n < sz); snprintf(&buffer[n], sz - n, "%09lu", tv->tv_nsec); } diff --git a/mgmtd/mgmt_main.c b/mgmtd/mgmt_main.c index 39362fa74a..a70235717f 100644 --- a/mgmtd/mgmt_main.c +++ b/mgmtd/mgmt_main.c @@ -185,12 +185,37 @@ static void mgmt_vrf_terminate(void) vrf_terminate(); } +#ifdef HAVE_STATICD +extern const struct frr_yang_module_info frr_staticd_info; +#endif + + +/* + * These are stub info structs that are used to load the modules used by backend + * clients into mgmtd. The modules are used by libyang in order to support + * parsing binary data returns from the backend. + */ +const struct frr_yang_module_info zebra_info = { + .name = "frr-zebra", + .ignore_cfg_cbs = true, + .nodes = { { .xpath = NULL } }, +}; + +const struct frr_yang_module_info affinity_map_info = { + .name = "frr-affinity-map", + .ignore_cfg_cbs = true, + .nodes = { { .xpath = NULL } }, +}; + +const struct frr_yang_module_info zebra_route_map_info = { + .name = "frr-zebra-route-map", + .ignore_cfg_cbs = true, + .nodes = { { .xpath = NULL } }, +}; + /* * List of YANG modules to be loaded in the process context of * MGMTd. - * - * NOTE: In future this will also include the YANG modules of - * all individual Backend clients. */ static const struct frr_yang_module_info *const mgmt_yang_modules[] = { &frr_filter_info, @@ -198,14 +223,17 @@ static const struct frr_yang_module_info *const mgmt_yang_modules[] = { &frr_route_map_info, &frr_routing_info, &frr_vrf_info, -/* - * YANG module info supported by backend clients get added here. - * NOTE: Always set .ignore_cbs true for to avoid validating - * backend northbound callbacks during loading. - */ + + /* + * YANG module info used by backend clients get added here. + */ + + &zebra_info, + &affinity_map_info, + &zebra_route_map_info, + #ifdef HAVE_STATICD - &(struct frr_yang_module_info){.name = "frr-staticd", - .ignore_cbs = true}, + &frr_staticd_info, #endif }; diff --git a/mgmtd/mgmt_memory.c b/mgmtd/mgmt_memory.c index b2a0f0e848..0fce61aa97 100644 --- a/mgmtd/mgmt_memory.c +++ b/mgmtd/mgmt_memory.c @@ -29,5 +29,6 @@ DEFINE_MTYPE(MGMTD, MGMTD_TXN_SETCFG_REQ, "txn set-config requests"); DEFINE_MTYPE(MGMTD, MGMTD_TXN_COMMCFG_REQ, "txn commit-config requests"); DEFINE_MTYPE(MGMTD, MGMTD_TXN_GETDATA_REQ, "txn get-data requests"); DEFINE_MTYPE(MGMTD, MGMTD_TXN_GETDATA_REPLY, "txn get-data replies"); +DEFINE_MTYPE(MGMTD, MGMTD_TXN_GETTREE_REQ, "txn get-tree requests"); DEFINE_MTYPE(MGMTD, MGMTD_TXN_CFG_BATCH, "txn config batches"); DEFINE_MTYPE(MGMTD, MGMTD_CMT_INFO, "commit info"); diff --git a/mgmtd/mgmt_memory.h b/mgmtd/mgmt_memory.h index 06518e3838..d5b6aa632e 100644 --- a/mgmtd/mgmt_memory.h +++ b/mgmtd/mgmt_memory.h @@ -23,6 +23,7 @@ DECLARE_MTYPE(MGMTD_TXN_SETCFG_REQ); DECLARE_MTYPE(MGMTD_TXN_COMMCFG_REQ); DECLARE_MTYPE(MGMTD_TXN_GETDATA_REQ); DECLARE_MTYPE(MGMTD_TXN_GETDATA_REPLY); +DECLARE_MTYPE(MGMTD_TXN_GETTREE_REQ); DECLARE_MTYPE(MGMTD_TXN_CFG_BATCH); DECLARE_MTYPE(MGMTD_BE_ADAPTER_MSG_BUF); DECLARE_MTYPE(MGMTD_CMT_INFO); diff --git a/mgmtd/mgmt_txn.c b/mgmtd/mgmt_txn.c index bf59224338..76ea5c63c1 100644 --- a/mgmtd/mgmt_txn.c +++ b/mgmtd/mgmt_txn.c @@ -7,27 +7,31 @@ */ #include <zebra.h> +#include "darr.h" #include "hash.h" #include "jhash.h" #include "libfrr.h" +#include "mgmt_msg.h" +#include "mgmt_msg_native.h" #include "mgmtd/mgmt.h" #include "mgmtd/mgmt_memory.h" #include "mgmtd/mgmt_txn.h" #define MGMTD_TXN_DBG(fmt, ...) \ - DEBUGD(&mgmt_debug_txn, "%s:" fmt, __func__, ##__VA_ARGS__) + DEBUGD(&mgmt_debug_txn, "TXN: %s: " fmt, __func__, ##__VA_ARGS__) #define MGMTD_TXN_ERR(fmt, ...) \ zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__) -#define MGMTD_TXN_LOCK(txn) mgmt_txn_lock(txn, __FILE__, __LINE__) +#define MGMTD_TXN_LOCK(txn) mgmt_txn_lock(txn, __FILE__, __LINE__) #define MGMTD_TXN_UNLOCK(txn) mgmt_txn_unlock(txn, __FILE__, __LINE__) enum mgmt_txn_event { MGMTD_TXN_PROC_SETCFG = 1, MGMTD_TXN_PROC_COMMITCFG, MGMTD_TXN_PROC_GETCFG, - MGMTD_TXN_PROC_GETDATA, + MGMTD_TXN_PROC_GETTREE, MGMTD_TXN_COMMITCFG_TIMEOUT, + MGMTD_TXN_GETTREE_TIMEOUT, MGMTD_TXN_CLEANUP }; @@ -53,8 +57,7 @@ enum mgmt_commit_phase { MGMTD_COMMIT_PHASE_MAX }; -static inline const char * -mgmt_commit_phase2str(enum mgmt_commit_phase cmt_phase) +static inline const char *mgmt_commit_phase2str(enum mgmt_commit_phase cmt_phase) { switch (cmt_phase) { case MGMTD_COMMIT_PHASE_PREPARE_CFG: @@ -78,17 +81,14 @@ PREDECL_LIST(mgmt_txn_batches); struct mgmt_txn_be_cfg_batch { struct mgmt_txn_ctx *txn; - uint64_t batch_id; enum mgmt_be_client_id be_id; struct mgmt_be_client_adapter *be_adapter; - uint xp_subscr[MGMTD_MAX_CFG_CHANGES_IN_BATCH]; Mgmtd__YangCfgDataReq cfg_data[MGMTD_MAX_CFG_CHANGES_IN_BATCH]; - Mgmtd__YangCfgDataReq * cfg_datap[MGMTD_MAX_CFG_CHANGES_IN_BATCH]; + Mgmtd__YangCfgDataReq *cfg_datap[MGMTD_MAX_CFG_CHANGES_IN_BATCH]; Mgmtd__YangData data[MGMTD_MAX_CFG_CHANGES_IN_BATCH]; Mgmtd__YangDataValue value[MGMTD_MAX_CFG_CHANGES_IN_BATCH]; size_t num_cfg_data; int buf_space_left; - enum mgmt_commit_phase comm_phase; struct mgmt_txn_batches_item list_linkage; }; @@ -112,6 +112,8 @@ struct mgmt_commit_cfg_req { enum mgmt_commit_phase curr_phase; enum mgmt_commit_phase next_phase; + enum mgmt_commit_phase be_phase[MGMTD_BE_CLIENT_ID_MAX]; + /* * Set of config changes to commit. This is used only * when changes are NOT to be determined by comparing @@ -126,27 +128,17 @@ struct mgmt_commit_cfg_req { * Details on all the Backend Clients associated with * this commit. */ - struct mgmt_be_client_subscr_info subscr_info; + uint64_t clients; /* * List of backend batches for this commit to be validated * and applied at the backend. - * - * FIXME: Need to re-think this design for the case set of - * validators for a given YANG data item is different from - * the set of notifiers for the same. We may need to have - * separate list of batches for VALIDATE and APPLY. */ - struct mgmt_txn_batches_head curr_batches[MGMTD_BE_CLIENT_ID_MAX]; - struct mgmt_txn_batches_head next_batches[MGMTD_BE_CLIENT_ID_MAX]; + struct mgmt_txn_batches_head batches[MGMTD_BE_CLIENT_ID_MAX]; /* - * The last batch added for any backend client. This is always on - * 'curr_batches' + * The last batch added for any backend client. */ - struct mgmt_txn_be_cfg_batch - *last_be_cfg_batch[MGMTD_BE_CLIENT_ID_MAX]; - struct hash *batches; - uint64_t next_batch_id; + struct mgmt_txn_be_cfg_batch *last_be_cfg_batch[MGMTD_BE_CLIENT_ID_MAX]; struct mgmt_commit_stats *cmt_stats; }; @@ -157,14 +149,14 @@ struct mgmt_get_data_reply { int last_batch; Mgmtd__YangDataReply data_reply; Mgmtd__YangData reply_data[MGMTD_MAX_NUM_DATA_REPLY_IN_BATCH]; - Mgmtd__YangData * reply_datap[MGMTD_MAX_NUM_DATA_REPLY_IN_BATCH]; + Mgmtd__YangData *reply_datap[MGMTD_MAX_NUM_DATA_REPLY_IN_BATCH]; Mgmtd__YangDataValue reply_value[MGMTD_MAX_NUM_DATA_REPLY_IN_BATCH]; char *reply_xpathp[MGMTD_MAX_NUM_DATA_REPLY_IN_BATCH]; }; struct mgmt_get_data_req { Mgmtd__DatastoreId ds_id; - struct mgmt_ds_ctx *ds_ctx; + struct nb_config *cfg_root; char *xpaths[MGMTD_MAX_NUM_DATA_REQ_IN_BATCH]; int num_xpaths; @@ -178,6 +170,17 @@ struct mgmt_get_data_req { int total_reply; }; + +struct txn_req_get_tree { + char *xpath; /* xpath of tree to get */ + uint64_t sent_clients; /* Bitmask of clients sent req to */ + uint64_t recv_clients; /* Bitmask of clients recv reply from */ + int32_t partial_error; /* an error while gather results */ + uint8_t result_type; /* LYD_FORMAT for results */ + uint8_t simple_xpath; /* if xpath is simple */ + struct lyd_node *client_results; /* result tree from clients */ +}; + struct mgmt_txn_req { struct mgmt_txn_ctx *txn; enum mgmt_txn_event req_event; @@ -185,6 +188,7 @@ struct mgmt_txn_req { union { struct mgmt_set_cfg_req *set_cfg; struct mgmt_get_data_req *get_data; + struct txn_req_get_tree *get_tree; struct mgmt_commit_cfg_req commit_cfg; } req; @@ -208,7 +212,9 @@ struct mgmt_txn_ctx { struct event *proc_comm_cfg; struct event *proc_get_cfg; struct event *proc_get_data; + struct event *proc_get_tree; struct event *comm_cfg_timeout; + struct event *get_tree_timeout; struct event *clnup; /* List of backend adapters involved in this transaction */ @@ -218,6 +224,10 @@ struct mgmt_txn_ctx { struct mgmt_txns_item list_linkage; + /* TODO: why do we need unique lists for each type of transaction since + * a transaction is of only 1 type? + */ + /* * List of pending set-config requests for a given * transaction/session. Just one list for requests @@ -233,13 +243,9 @@ struct mgmt_txn_ctx { */ struct mgmt_txn_reqs_head get_cfg_reqs; /* - * List of pending get-data requests for a given - * transaction/session Two lists, one for requests - * not processed at all, and one for requests that - * has been sent to backend for processing. + * List of pending get-tree requests. */ - struct mgmt_txn_reqs_head get_data_reqs; - struct mgmt_txn_reqs_head pending_get_datas; + struct mgmt_txn_reqs_head get_tree_reqs; /* * There will always be one commit-config allowed for a given * transaction/session. No need to maintain lists for it. @@ -256,8 +262,8 @@ static int mgmt_txn_send_commit_cfg_reply(struct mgmt_txn_ctx *txn, enum mgmt_result result, const char *error_if_any); -static inline const char * -mgmt_txn_commit_phase_str(struct mgmt_txn_ctx *txn, bool curr) +static inline const char *mgmt_txn_commit_phase_str(struct mgmt_txn_ctx *txn, + bool curr) { if (!txn->commit_cfg_req) return "None"; @@ -267,148 +273,82 @@ mgmt_txn_commit_phase_str(struct mgmt_txn_ctx *txn, bool curr) : txn->commit_cfg_req->req.commit_cfg.next_phase)); } -static void mgmt_txn_lock(struct mgmt_txn_ctx *txn, const char *file, - int line); +static void mgmt_txn_lock(struct mgmt_txn_ctx *txn, const char *file, int line); static void mgmt_txn_unlock(struct mgmt_txn_ctx **txn, const char *file, - int line); -static int -mgmt_txn_send_be_txn_delete(struct mgmt_txn_ctx *txn, - struct mgmt_be_client_adapter *adapter); + int line); +static int mgmt_txn_send_be_txn_delete(struct mgmt_txn_ctx *txn, + struct mgmt_be_client_adapter *adapter); static struct event_loop *mgmt_txn_tm; static struct mgmt_master *mgmt_txn_mm; static void mgmt_txn_register_event(struct mgmt_txn_ctx *txn, - enum mgmt_txn_event event); - -static int -mgmt_move_be_commit_to_next_phase(struct mgmt_txn_ctx *txn, - struct mgmt_be_client_adapter *adapter); + enum mgmt_txn_event event); static struct mgmt_txn_be_cfg_batch * -mgmt_txn_cfg_batch_alloc(struct mgmt_txn_ctx *txn, - enum mgmt_be_client_id id, - struct mgmt_be_client_adapter *be_adapter) +mgmt_txn_cfg_batch_alloc(struct mgmt_txn_ctx *txn, enum mgmt_be_client_id id, + struct mgmt_be_client_adapter *be_adapter) { - struct mgmt_txn_be_cfg_batch *cfg_btch; + struct mgmt_txn_be_cfg_batch *batch; - cfg_btch = XCALLOC(MTYPE_MGMTD_TXN_CFG_BATCH, - sizeof(struct mgmt_txn_be_cfg_batch)); - assert(cfg_btch); - cfg_btch->be_id = id; + batch = XCALLOC(MTYPE_MGMTD_TXN_CFG_BATCH, + sizeof(struct mgmt_txn_be_cfg_batch)); + assert(batch); + batch->be_id = id; - cfg_btch->txn = txn; + batch->txn = txn; MGMTD_TXN_LOCK(txn); assert(txn->commit_cfg_req); - mgmt_txn_batches_add_tail( - &txn->commit_cfg_req->req.commit_cfg.curr_batches[id], - cfg_btch); - cfg_btch->be_adapter = be_adapter; - cfg_btch->buf_space_left = MGMTD_BE_CFGDATA_MAX_MSG_LEN; + mgmt_txn_batches_add_tail(&txn->commit_cfg_req->req.commit_cfg + .batches[id], + batch); + batch->be_adapter = be_adapter; + batch->buf_space_left = MGMTD_BE_CFGDATA_MAX_MSG_LEN; if (be_adapter) mgmt_be_adapter_lock(be_adapter); - txn->commit_cfg_req->req.commit_cfg.last_be_cfg_batch[id] = - cfg_btch; - if (!txn->commit_cfg_req->req.commit_cfg.next_batch_id) - txn->commit_cfg_req->req.commit_cfg.next_batch_id++; - cfg_btch->batch_id = - txn->commit_cfg_req->req.commit_cfg.next_batch_id++; - hash_get(txn->commit_cfg_req->req.commit_cfg.batches, cfg_btch, - hash_alloc_intern); + txn->commit_cfg_req->req.commit_cfg.last_be_cfg_batch[id] = batch; - return cfg_btch; + return batch; } -static void -mgmt_txn_cfg_batch_free(struct mgmt_txn_be_cfg_batch **cfg_btch) +static void mgmt_txn_cfg_batch_free(struct mgmt_txn_be_cfg_batch **batch) { size_t indx; struct mgmt_commit_cfg_req *cmtcfg_req; - MGMTD_TXN_DBG(" freeing batch-id: %" PRIu64 " txn-id %" PRIu64, - (*cfg_btch)->batch_id, (*cfg_btch)->txn->txn_id); + MGMTD_TXN_DBG(" freeing batch txn-id %" PRIu64, (*batch)->txn->txn_id); - assert((*cfg_btch)->txn - && (*cfg_btch)->txn->type == MGMTD_TXN_TYPE_CONFIG); + assert((*batch)->txn && (*batch)->txn->type == MGMTD_TXN_TYPE_CONFIG); - cmtcfg_req = &(*cfg_btch)->txn->commit_cfg_req->req.commit_cfg; - hash_release(cmtcfg_req->batches, *cfg_btch); - mgmt_txn_batches_del(&cmtcfg_req->curr_batches[(*cfg_btch)->be_id], - *cfg_btch); - mgmt_txn_batches_del(&cmtcfg_req->next_batches[(*cfg_btch)->be_id], - *cfg_btch); + cmtcfg_req = &(*batch)->txn->commit_cfg_req->req.commit_cfg; + mgmt_txn_batches_del(&cmtcfg_req->batches[(*batch)->be_id], *batch); - if ((*cfg_btch)->be_adapter) - mgmt_be_adapter_unlock(&(*cfg_btch)->be_adapter); + if ((*batch)->be_adapter) + mgmt_be_adapter_unlock(&(*batch)->be_adapter); - for (indx = 0; indx < (*cfg_btch)->num_cfg_data; indx++) { - if ((*cfg_btch)->data[indx].xpath) { - free((*cfg_btch)->data[indx].xpath); - (*cfg_btch)->data[indx].xpath = NULL; + for (indx = 0; indx < (*batch)->num_cfg_data; indx++) { + if ((*batch)->data[indx].xpath) { + free((*batch)->data[indx].xpath); + (*batch)->data[indx].xpath = NULL; } } - MGMTD_TXN_UNLOCK(&(*cfg_btch)->txn); - - XFREE(MTYPE_MGMTD_TXN_CFG_BATCH, *cfg_btch); - *cfg_btch = NULL; -} - -static unsigned int mgmt_txn_cfgbatch_hash_key(const void *data) -{ - const struct mgmt_txn_be_cfg_batch *batch = data; - - return jhash2((uint32_t *) &batch->batch_id, - sizeof(batch->batch_id) / sizeof(uint32_t), 0); -} - -static bool mgmt_txn_cfgbatch_hash_cmp(const void *d1, const void *d2) -{ - const struct mgmt_txn_be_cfg_batch *batch1 = d1; - const struct mgmt_txn_be_cfg_batch *batch2 = d2; - - return (batch1->batch_id == batch2->batch_id); -} - -static void mgmt_txn_cfgbatch_hash_free(void *data) -{ - struct mgmt_txn_be_cfg_batch *batch = data; - - mgmt_txn_cfg_batch_free(&batch); -} - -static inline struct mgmt_txn_be_cfg_batch * -mgmt_txn_cfgbatch_id2ctx(struct mgmt_txn_ctx *txn, uint64_t batch_id) -{ - struct mgmt_txn_be_cfg_batch key = {0}; - struct mgmt_txn_be_cfg_batch *batch; - - if (!txn->commit_cfg_req) - return NULL; - - key.batch_id = batch_id; - batch = hash_lookup(txn->commit_cfg_req->req.commit_cfg.batches, - &key); + MGMTD_TXN_UNLOCK(&(*batch)->txn); - return batch; + XFREE(MTYPE_MGMTD_TXN_CFG_BATCH, *batch); + *batch = NULL; } static void mgmt_txn_cleanup_be_cfg_batches(struct mgmt_txn_ctx *txn, enum mgmt_be_client_id id) { - struct mgmt_txn_be_cfg_batch *cfg_btch; + struct mgmt_txn_be_cfg_batch *batch; struct mgmt_txn_batches_head *list; - list = &txn->commit_cfg_req->req.commit_cfg.curr_batches[id]; - FOREACH_TXN_CFG_BATCH_IN_LIST (list, cfg_btch) - mgmt_txn_cfg_batch_free(&cfg_btch); - - mgmt_txn_batches_fini(list); - - list = &txn->commit_cfg_req->req.commit_cfg.next_batches[id]; - FOREACH_TXN_CFG_BATCH_IN_LIST (list, cfg_btch) - mgmt_txn_cfg_batch_free(&cfg_btch); + list = &txn->commit_cfg_req->req.commit_cfg.batches[id]; + FOREACH_TXN_CFG_BATCH_IN_LIST (list, batch) + mgmt_txn_cfg_batch_free(&batch); mgmt_txn_batches_fini(list); @@ -416,8 +356,8 @@ static void mgmt_txn_cleanup_be_cfg_batches(struct mgmt_txn_ctx *txn, } static struct mgmt_txn_req *mgmt_txn_req_alloc(struct mgmt_txn_ctx *txn, - uint64_t req_id, - enum mgmt_txn_event req_event) + uint64_t req_id, + enum mgmt_txn_event req_event) { struct mgmt_txn_req *txn_req; enum mgmt_be_client_id id; @@ -446,16 +386,13 @@ static struct mgmt_txn_req *mgmt_txn_req_alloc(struct mgmt_txn_ctx *txn, txn_req->req_id, txn->txn_id, txn->session_id); FOREACH_MGMTD_BE_CLIENT_ID (id) { + txn_req->req.commit_cfg.be_phase[id] = + MGMTD_COMMIT_PHASE_PREPARE_CFG; mgmt_txn_batches_init( - &txn_req->req.commit_cfg.curr_batches[id]); - mgmt_txn_batches_init( - &txn_req->req.commit_cfg.next_batches[id]); + &txn_req->req.commit_cfg.batches[id]); } - txn_req->req.commit_cfg.batches = - hash_create(mgmt_txn_cfgbatch_hash_key, - mgmt_txn_cfgbatch_hash_cmp, - "MGMT Config Batches"); + txn_req->req.commit_cfg.curr_phase = MGMTD_COMMIT_PHASE_PREPARE_CFG; break; case MGMTD_TXN_PROC_GETCFG: txn_req->req.get_data = @@ -467,17 +404,16 @@ static struct mgmt_txn_req *mgmt_txn_req_alloc(struct mgmt_txn_ctx *txn, " txn-id: %" PRIu64 " session-id: %" PRIu64, txn_req->req_id, txn->txn_id, txn->session_id); break; - case MGMTD_TXN_PROC_GETDATA: - txn_req->req.get_data = - XCALLOC(MTYPE_MGMTD_TXN_GETDATA_REQ, - sizeof(struct mgmt_get_data_req)); - assert(txn_req->req.get_data); - mgmt_txn_reqs_add_tail(&txn->get_data_reqs, txn_req); - MGMTD_TXN_DBG("Added a new GETDATA req-id: %" PRIu64 + case MGMTD_TXN_PROC_GETTREE: + txn_req->req.get_tree = XCALLOC(MTYPE_MGMTD_TXN_GETTREE_REQ, + sizeof(struct txn_req_get_tree)); + mgmt_txn_reqs_add_tail(&txn->get_tree_reqs, txn_req); + MGMTD_TXN_DBG("Added a new GETTREE req-id: %" PRIu64 " txn-id: %" PRIu64 " session-id: %" PRIu64, txn_req->req_id, txn->txn_id, txn->session_id); break; case MGMTD_TXN_COMMITCFG_TIMEOUT: + case MGMTD_TXN_GETTREE_TIMEOUT: case MGMTD_TXN_CLEANUP: break; } @@ -491,26 +427,29 @@ static void mgmt_txn_req_free(struct mgmt_txn_req **txn_req) { int indx; struct mgmt_txn_reqs_head *req_list = NULL; - struct mgmt_txn_reqs_head *pending_list = NULL; enum mgmt_be_client_id id; struct mgmt_be_client_adapter *adapter; + struct mgmt_commit_cfg_req *ccreq; + bool cleanup; switch ((*txn_req)->req_event) { case MGMTD_TXN_PROC_SETCFG: for (indx = 0; indx < (*txn_req)->req.set_cfg->num_cfg_changes; indx++) { if ((*txn_req)->req.set_cfg->cfg_changes[indx].value) { - MGMTD_TXN_DBG( - "Freeing value for %s at %p ==> '%s'", - (*txn_req) - ->req.set_cfg->cfg_changes[indx] - .xpath, - (*txn_req) - ->req.set_cfg->cfg_changes[indx] - .value, - (*txn_req) - ->req.set_cfg->cfg_changes[indx] - .value); + MGMTD_TXN_DBG("Freeing value for %s at %p ==> '%s'", + (*txn_req) + ->req.set_cfg + ->cfg_changes[indx] + .xpath, + (*txn_req) + ->req.set_cfg + ->cfg_changes[indx] + .value, + (*txn_req) + ->req.set_cfg + ->cfg_changes[indx] + .value); free((void *)(*txn_req) ->req.set_cfg->cfg_changes[indx] .value); @@ -526,32 +465,31 @@ static void mgmt_txn_req_free(struct mgmt_txn_req **txn_req) MGMTD_TXN_DBG("Deleting COMMITCFG req-id: %" PRIu64 " txn-id: %" PRIu64, (*txn_req)->req_id, (*txn_req)->txn->txn_id); + + ccreq = &(*txn_req)->req.commit_cfg; + cleanup = (ccreq->curr_phase >= MGMTD_COMMIT_PHASE_TXN_CREATE && + ccreq->curr_phase < MGMTD_COMMIT_PHASE_TXN_DELETE); + FOREACH_MGMTD_BE_CLIENT_ID (id) { /* * Send TXN_DELETE to cleanup state for this * transaction on backend */ - if ((*txn_req)->req.commit_cfg.curr_phase >= - MGMTD_COMMIT_PHASE_TXN_CREATE && - (*txn_req)->req.commit_cfg.curr_phase < - MGMTD_COMMIT_PHASE_TXN_DELETE && - (*txn_req) - ->req.commit_cfg.subscr_info - .xpath_subscr[id]) { - adapter = mgmt_be_get_adapter_by_id(id); - if (adapter) - mgmt_txn_send_be_txn_delete( - (*txn_req)->txn, adapter); - } - mgmt_txn_cleanup_be_cfg_batches((*txn_req)->txn, - id); - if ((*txn_req)->req.commit_cfg.batches) { - hash_clean((*txn_req)->req.commit_cfg.batches, - mgmt_txn_cfgbatch_hash_free); - hash_free((*txn_req)->req.commit_cfg.batches); - (*txn_req)->req.commit_cfg.batches = NULL; - } + /* + * Get rid of the batches first so we don't end up doing + * anything more with them + */ + mgmt_txn_cleanup_be_cfg_batches((*txn_req)->txn, id); + + /* + * If we were in the middle of the state machine then + * send a txn delete message + */ + adapter = mgmt_be_get_adapter_by_id(id); + if (adapter && cleanup && IS_IDBIT_SET(ccreq->clients, id)) + mgmt_txn_send_be_txn_delete((*txn_req)->txn, + adapter); } break; case MGMTD_TXN_PROC_GETCFG: @@ -568,42 +506,32 @@ static void mgmt_txn_req_free(struct mgmt_txn_req **txn_req) if ((*txn_req)->req.get_data->reply) XFREE(MTYPE_MGMTD_TXN_GETDATA_REPLY, (*txn_req)->req.get_data->reply); + + if ((*txn_req)->req.get_data->cfg_root) + nb_config_free((*txn_req)->req.get_data->cfg_root); + XFREE(MTYPE_MGMTD_TXN_GETDATA_REQ, (*txn_req)->req.get_data); break; - case MGMTD_TXN_PROC_GETDATA: - for (indx = 0; indx < (*txn_req)->req.get_data->num_xpaths; - indx++) { - if ((*txn_req)->req.get_data->xpaths[indx]) - free((void *)(*txn_req) - ->req.get_data->xpaths[indx]); - } - pending_list = &(*txn_req)->txn->pending_get_datas; - req_list = &(*txn_req)->txn->get_data_reqs; - MGMTD_TXN_DBG("Deleting GETDATA req-id: %" PRIu64 - " txn-id: %" PRIu64, + case MGMTD_TXN_PROC_GETTREE: + MGMTD_TXN_DBG("Deleting GETTREE req-id: %" PRIu64 + " of txn-id: %" PRIu64, (*txn_req)->req_id, (*txn_req)->txn->txn_id); - if ((*txn_req)->req.get_data->reply) - XFREE(MTYPE_MGMTD_TXN_GETDATA_REPLY, - (*txn_req)->req.get_data->reply); - XFREE(MTYPE_MGMTD_TXN_GETDATA_REQ, (*txn_req)->req.get_data); + req_list = &(*txn_req)->txn->get_tree_reqs; + lyd_free_all((*txn_req)->req.get_tree->client_results); + XFREE(MTYPE_MGMTD_XPATH, (*txn_req)->req.get_tree->xpath); + XFREE(MTYPE_MGMTD_TXN_GETTREE_REQ, (*txn_req)->req.get_tree); break; case MGMTD_TXN_COMMITCFG_TIMEOUT: + case MGMTD_TXN_GETTREE_TIMEOUT: case MGMTD_TXN_CLEANUP: break; } - if ((*txn_req)->pending_be_proc && pending_list) { - mgmt_txn_reqs_del(pending_list, *txn_req); - MGMTD_TXN_DBG("Removed req-id: %" PRIu64 - " from pending-list (left:%zu)", - (*txn_req)->req_id, - mgmt_txn_reqs_count(pending_list)); - } else if (req_list) { + if (req_list) { mgmt_txn_reqs_del(req_list, *txn_req); MGMTD_TXN_DBG("Removed req-id: %" PRIu64 " from request-list (left:%zu)", - (*txn_req)->req_id, - mgmt_txn_reqs_count(req_list)); + (*txn_req)->req_id, mgmt_txn_reqs_count(req_list)); } (*txn_req)->pending_be_proc = false; @@ -635,42 +563,45 @@ static void mgmt_txn_process_set_cfg(struct event *thread) txn->session_id); FOREACH_TXN_REQ_IN_LIST (&txn->set_cfg_reqs, txn_req) { - error = false; assert(txn_req->req_event == MGMTD_TXN_PROC_SETCFG); ds_ctx = txn_req->req.set_cfg->ds_ctx; if (!ds_ctx) { - mgmt_fe_send_set_cfg_reply( - txn->session_id, txn->txn_id, - txn_req->req.set_cfg->ds_id, txn_req->req_id, - MGMTD_INTERNAL_ERROR, "No such datastore!", - txn_req->req.set_cfg->implicit_commit); - error = true; + mgmt_fe_send_set_cfg_reply(txn->session_id, txn->txn_id, + txn_req->req.set_cfg->ds_id, + txn_req->req_id, + MGMTD_INTERNAL_ERROR, + "No such datastore!", + txn_req->req.set_cfg + ->implicit_commit); goto mgmt_txn_process_set_cfg_done; } nb_config = mgmt_ds_get_nb_config(ds_ctx); if (!nb_config) { - mgmt_fe_send_set_cfg_reply( - txn->session_id, txn->txn_id, - txn_req->req.set_cfg->ds_id, txn_req->req_id, - MGMTD_INTERNAL_ERROR, - "Unable to retrieve DS Config Tree!", - txn_req->req.set_cfg->implicit_commit); - error = true; + mgmt_fe_send_set_cfg_reply(txn->session_id, txn->txn_id, + txn_req->req.set_cfg->ds_id, + txn_req->req_id, + MGMTD_INTERNAL_ERROR, + "Unable to retrieve DS Config Tree!", + txn_req->req.set_cfg + ->implicit_commit); goto mgmt_txn_process_set_cfg_done; } error = false; - nb_candidate_edit_config_changes( - nb_config, txn_req->req.set_cfg->cfg_changes, - (size_t)txn_req->req.set_cfg->num_cfg_changes, NULL, - NULL, 0, err_buf, sizeof(err_buf), &error); + nb_candidate_edit_config_changes(nb_config, + txn_req->req.set_cfg->cfg_changes, + (size_t)txn_req->req.set_cfg + ->num_cfg_changes, + NULL, err_buf, sizeof(err_buf), + &error); if (error) { - mgmt_fe_send_set_cfg_reply( - txn->session_id, txn->txn_id, - txn_req->req.set_cfg->ds_id, txn_req->req_id, - MGMTD_INTERNAL_ERROR, err_buf, - txn_req->req.set_cfg->implicit_commit); + mgmt_fe_send_set_cfg_reply(txn->session_id, txn->txn_id, + txn_req->req.set_cfg->ds_id, + txn_req->req_id, + MGMTD_INTERNAL_ERROR, err_buf, + txn_req->req.set_cfg + ->implicit_commit); goto mgmt_txn_process_set_cfg_done; } @@ -678,45 +609,50 @@ static void mgmt_txn_process_set_cfg(struct event *thread) assert(mgmt_txn_reqs_count(&txn->set_cfg_reqs) == 1); assert(txn_req->req.set_cfg->dst_ds_ctx); - ret = mgmt_ds_write_lock( - txn_req->req.set_cfg->dst_ds_ctx); - if (ret != 0) { - MGMTD_TXN_ERR( - "Failed to lock DS %u txn-id: %" PRIu64 - " session-id: %" PRIu64 " err: %s", - txn_req->req.set_cfg->dst_ds_id, - txn->txn_id, txn->session_id, - strerror(ret)); - mgmt_txn_send_commit_cfg_reply( - txn, MGMTD_DS_LOCK_FAILED, - "Lock running DS before implicit commit failed!"); + /* We expect the user to have locked the DST DS */ + if (!mgmt_ds_is_locked(txn_req->req.set_cfg->dst_ds_ctx, + txn->session_id)) { + MGMTD_TXN_ERR("DS %u not locked for implicit commit txn-id: %" PRIu64 + " session-id: %" PRIu64 " err: %s", + txn_req->req.set_cfg->dst_ds_id, + txn->txn_id, txn->session_id, + strerror(ret)); + mgmt_fe_send_set_cfg_reply( + txn->session_id, txn->txn_id, + txn_req->req.set_cfg->ds_id, + txn_req->req_id, MGMTD_DS_LOCK_FAILED, + "running DS not locked for implicit commit", + txn_req->req.set_cfg->implicit_commit); goto mgmt_txn_process_set_cfg_done; } - mgmt_txn_send_commit_config_req( - txn->txn_id, txn_req->req_id, - txn_req->req.set_cfg->ds_id, - txn_req->req.set_cfg->ds_ctx, - txn_req->req.set_cfg->dst_ds_id, - txn_req->req.set_cfg->dst_ds_ctx, false, - false, true); + mgmt_txn_send_commit_config_req(txn->txn_id, + txn_req->req_id, + txn_req->req.set_cfg + ->ds_id, + txn_req->req.set_cfg + ->ds_ctx, + txn_req->req.set_cfg + ->dst_ds_id, + txn_req->req.set_cfg + ->dst_ds_ctx, + false, false, true); if (mm->perf_stats_en) gettimeofday(&cmt_stats->last_start, NULL); cmt_stats->commit_cnt++; - } else if (mgmt_fe_send_set_cfg_reply( - txn->session_id, txn->txn_id, - txn_req->req.set_cfg->ds_id, - txn_req->req_id, MGMTD_SUCCESS, NULL, false) - != 0) { - MGMTD_TXN_ERR( - "Failed to send SET_CONFIG_REPLY txn-id %" PRIu64 - " session-id: %" PRIu64, - txn->txn_id, txn->session_id); - error = true; + } else if (mgmt_fe_send_set_cfg_reply(txn->session_id, + txn->txn_id, + txn_req->req.set_cfg->ds_id, + txn_req->req_id, + MGMTD_SUCCESS, NULL, + false) != 0) { + MGMTD_TXN_ERR("Failed to send SET_CONFIG_REPLY txn-id %" PRIu64 + " session-id: %" PRIu64, + txn->txn_id, txn->session_id); } - mgmt_txn_process_set_cfg_done: +mgmt_txn_process_set_cfg_done: /* * Note: The following will remove it from the list as well. @@ -730,19 +666,17 @@ static void mgmt_txn_process_set_cfg(struct event *thread) left = mgmt_txn_reqs_count(&txn->set_cfg_reqs); if (left) { - MGMTD_TXN_DBG( - "Processed maximum number of Set-Config requests (%d/%d/%d). Rescheduling for rest.", - num_processed, MGMTD_TXN_MAX_NUM_SETCFG_PROC, - (int)left); + MGMTD_TXN_DBG("Processed maximum number of Set-Config requests (%d/%d/%d). Rescheduling for rest.", + num_processed, MGMTD_TXN_MAX_NUM_SETCFG_PROC, + (int)left); mgmt_txn_register_event(txn, MGMTD_TXN_PROC_SETCFG); } } static int mgmt_txn_send_commit_cfg_reply(struct mgmt_txn_ctx *txn, - enum mgmt_result result, - const char *error_if_any) + enum mgmt_result result, + const char *error_if_any) { - int ret = 0; bool success, create_cmt_info_rec; if (!txn->commit_cfg_req) @@ -750,29 +684,35 @@ static int mgmt_txn_send_commit_cfg_reply(struct mgmt_txn_ctx *txn, success = (result == MGMTD_SUCCESS || result == MGMTD_NO_CFG_CHANGES); - if (!txn->commit_cfg_req->req.commit_cfg.implicit && txn->session_id - && mgmt_fe_send_commit_cfg_reply( - txn->session_id, txn->txn_id, - txn->commit_cfg_req->req.commit_cfg.src_ds_id, - txn->commit_cfg_req->req.commit_cfg.dst_ds_id, - txn->commit_cfg_req->req_id, - txn->commit_cfg_req->req.commit_cfg.validate_only, - result, error_if_any) - != 0) { - MGMTD_TXN_ERR( - "Failed to send COMMIT-CONFIG-REPLY txn-id: %" PRIu64 - " session-id: %" PRIu64, - txn->txn_id, txn->session_id); - } - - if (txn->commit_cfg_req->req.commit_cfg.implicit && txn->session_id - && mgmt_fe_send_set_cfg_reply( - txn->session_id, txn->txn_id, - txn->commit_cfg_req->req.commit_cfg.src_ds_id, - txn->commit_cfg_req->req_id, - success ? MGMTD_SUCCESS : MGMTD_INTERNAL_ERROR, - error_if_any, true) - != 0) { + /* TODO: these replies should not be send if it's a rollback + * b/c right now that is special cased.. that special casing should be + * removed; however... + */ + if (!txn->commit_cfg_req->req.commit_cfg.implicit && txn->session_id && + !txn->commit_cfg_req->req.commit_cfg.rollback && + mgmt_fe_send_commit_cfg_reply(txn->session_id, txn->txn_id, + txn->commit_cfg_req->req.commit_cfg + .src_ds_id, + txn->commit_cfg_req->req.commit_cfg + .dst_ds_id, + txn->commit_cfg_req->req_id, + txn->commit_cfg_req->req.commit_cfg + .validate_only, + result, error_if_any) != 0) { + MGMTD_TXN_ERR("Failed to send COMMIT-CONFIG-REPLY txn-id: %" PRIu64 + " session-id: %" PRIu64, + txn->txn_id, txn->session_id); + } + + if (txn->commit_cfg_req->req.commit_cfg.implicit && txn->session_id && + !txn->commit_cfg_req->req.commit_cfg.rollback && + mgmt_fe_send_set_cfg_reply(txn->session_id, txn->txn_id, + txn->commit_cfg_req->req.commit_cfg + .src_ds_id, + txn->commit_cfg_req->req_id, + success ? MGMTD_SUCCESS + : MGMTD_INTERNAL_ERROR, + error_if_any, true) != 0) { MGMTD_TXN_ERR("Failed to send SET-CONFIG-REPLY txn-id: %" PRIu64 " session-id: %" PRIu64, txn->txn_id, txn->session_id); @@ -780,6 +720,7 @@ static int mgmt_txn_send_commit_cfg_reply(struct mgmt_txn_ctx *txn, if (success) { /* Stop the commit-timeout timer */ + /* XXX why only on success? */ EVENT_OFF(txn->comm_cfg_timeout); create_cmt_info_rec = @@ -790,10 +731,10 @@ static int mgmt_txn_send_commit_cfg_reply(struct mgmt_txn_ctx *txn, * Successful commit: Merge Src DS into Dst DS if and only if * this was not a validate-only or abort request. */ - if ((txn->session_id - && !txn->commit_cfg_req->req.commit_cfg.validate_only - && !txn->commit_cfg_req->req.commit_cfg.abort) - || txn->commit_cfg_req->req.commit_cfg.rollback) { + if ((txn->session_id && + !txn->commit_cfg_req->req.commit_cfg.validate_only && + !txn->commit_cfg_req->req.commit_cfg.abort) || + txn->commit_cfg_req->req.commit_cfg.rollback) { mgmt_ds_copy_dss(txn->commit_cfg_req->req.commit_cfg .src_ds_ctx, txn->commit_cfg_req->req.commit_cfg @@ -805,8 +746,7 @@ static int mgmt_txn_send_commit_cfg_reply(struct mgmt_txn_ctx *txn, * Restore Src DS back to Dest DS only through a commit abort * request. */ - if (txn->session_id - && txn->commit_cfg_req->req.commit_cfg.abort) + if (txn->session_id && txn->commit_cfg_req->req.commit_cfg.abort) mgmt_ds_copy_dss(txn->commit_cfg_req->req.commit_cfg .dst_ds_ctx, txn->commit_cfg_req->req.commit_cfg @@ -826,27 +766,18 @@ static int mgmt_txn_send_commit_cfg_reply(struct mgmt_txn_ctx *txn, } if (txn->commit_cfg_req->req.commit_cfg.rollback) { - ret = mgmt_ds_unlock( - txn->commit_cfg_req->req.commit_cfg.dst_ds_ctx); - if (ret != 0) - MGMTD_TXN_ERR( - "Failed to unlock the dst DS during rollback : %s", - strerror(ret)); - + mgmt_ds_unlock(txn->commit_cfg_req->req.commit_cfg.src_ds_ctx); + mgmt_ds_unlock(txn->commit_cfg_req->req.commit_cfg.dst_ds_ctx); /* * Resume processing the rollback command. + * + * TODO: there's no good reason to special case rollback, the + * rollback boolean should be passed back to the FE client and it + * can do the right thing. */ mgmt_history_rollback_complete(success); } - if (txn->commit_cfg_req->req.commit_cfg.implicit) - if (mgmt_ds_unlock( - txn->commit_cfg_req->req.commit_cfg.dst_ds_ctx) - != 0) - MGMTD_TXN_ERR( - "Failed to unlock the dst DS during implicit : %s", - strerror(ret)); - txn->commit_cfg_req->req.commit_cfg.cmt_stats = NULL; mgmt_txn_req_free(&txn->commit_cfg_req); @@ -861,49 +792,10 @@ static int mgmt_txn_send_commit_cfg_reply(struct mgmt_txn_ctx *txn, return 0; } -static void -mgmt_move_txn_cfg_batch_to_next(struct mgmt_commit_cfg_req *cmtcfg_req, - struct mgmt_txn_be_cfg_batch *cfg_btch, - struct mgmt_txn_batches_head *src_list, - struct mgmt_txn_batches_head *dst_list, - bool update_commit_phase, - enum mgmt_commit_phase to_phase) -{ - mgmt_txn_batches_del(src_list, cfg_btch); - - if (update_commit_phase) { - MGMTD_TXN_DBG("Move txn-id %" PRIu64 " batch-id: %" PRIu64 - " from '%s' --> '%s'", - cfg_btch->txn->txn_id, cfg_btch->batch_id, - mgmt_commit_phase2str(cfg_btch->comm_phase), - mgmt_txn_commit_phase_str(cfg_btch->txn, false)); - cfg_btch->comm_phase = to_phase; - } - - mgmt_txn_batches_add_tail(dst_list, cfg_btch); -} - -static void mgmt_move_txn_cfg_batches(struct mgmt_txn_ctx *txn, - struct mgmt_commit_cfg_req *cmtcfg_req, - struct mgmt_txn_batches_head *src_list, - struct mgmt_txn_batches_head *dst_list, - bool update_commit_phase, - enum mgmt_commit_phase to_phase) -{ - struct mgmt_txn_be_cfg_batch *cfg_btch; - - FOREACH_TXN_CFG_BATCH_IN_LIST (src_list, cfg_btch) { - mgmt_move_txn_cfg_batch_to_next(cmtcfg_req, cfg_btch, src_list, - dst_list, update_commit_phase, - to_phase); - } -} - static int mgmt_try_move_commit_to_next_phase(struct mgmt_txn_ctx *txn, struct mgmt_commit_cfg_req *cmtcfg_req) { - struct mgmt_txn_batches_head *curr_list, *next_list; enum mgmt_be_client_id id; MGMTD_TXN_DBG("txn-id: %" PRIu64 ", Phase(current:'%s' next:'%s')", @@ -914,8 +806,8 @@ mgmt_try_move_commit_to_next_phase(struct mgmt_txn_ctx *txn, * Check if all clients has moved to next phase or not. */ FOREACH_MGMTD_BE_CLIENT_ID (id) { - if (cmtcfg_req->subscr_info.xpath_subscr[id] && - mgmt_txn_batches_count(&cmtcfg_req->curr_batches[id])) { + if (IS_IDBIT_SET(cmtcfg_req->clients, id) && + cmtcfg_req->be_phase[id] == cmtcfg_req->curr_phase) { /* * There's atleast once client who hasn't moved to * next phase. @@ -938,74 +830,29 @@ mgmt_try_move_commit_to_next_phase(struct mgmt_txn_ctx *txn, */ cmtcfg_req->curr_phase = cmtcfg_req->next_phase; cmtcfg_req->next_phase++; - MGMTD_TXN_DBG("Move back all config batches for txn-id: %" PRIu64 - " from next to current branch", - txn->txn_id); - FOREACH_MGMTD_BE_CLIENT_ID (id) { - curr_list = &cmtcfg_req->curr_batches[id]; - next_list = &cmtcfg_req->next_batches[id]; - mgmt_move_txn_cfg_batches(txn, cmtcfg_req, next_list, - curr_list, false, 0); - } mgmt_txn_register_event(txn, MGMTD_TXN_PROC_COMMITCFG); return 0; } -static int -mgmt_move_be_commit_to_next_phase(struct mgmt_txn_ctx *txn, - struct mgmt_be_client_adapter *adapter) -{ - struct mgmt_commit_cfg_req *cmtcfg_req; - struct mgmt_txn_batches_head *curr_list, *next_list; - - if (txn->type != MGMTD_TXN_TYPE_CONFIG || !txn->commit_cfg_req) - return -1; - - cmtcfg_req = &txn->commit_cfg_req->req.commit_cfg; - - MGMTD_TXN_DBG("Move txn-id: %" PRIu64 - " for '%s' Phase(current: '%s' next:'%s')", - txn->txn_id, adapter->name, - mgmt_txn_commit_phase_str(txn, true), - mgmt_txn_commit_phase_str(txn, false)); - - MGMTD_TXN_DBG( - "Move all config batches for '%s' from current to next list", - adapter->name); - curr_list = &cmtcfg_req->curr_batches[adapter->id]; - next_list = &cmtcfg_req->next_batches[adapter->id]; - mgmt_move_txn_cfg_batches(txn, cmtcfg_req, curr_list, next_list, true, - cmtcfg_req->next_phase); - - MGMTD_TXN_DBG("txn-id: %" PRIu64 ", Phase(current:'%s' next:'%s')", - txn->txn_id, mgmt_txn_commit_phase_str(txn, true), - mgmt_txn_commit_phase_str(txn, false)); - - /* - * Check if all clients has moved to next phase or not. - */ - mgmt_try_move_commit_to_next_phase(txn, cmtcfg_req); - - return 0; -} - +/* + * This is the real workhorse + */ static int mgmt_txn_create_config_batches(struct mgmt_txn_req *txn_req, - struct nb_config_cbs *changes) + struct nb_config_cbs *changes) { struct nb_config_cb *cb, *nxt; struct nb_config_change *chg; - struct mgmt_txn_be_cfg_batch *cfg_btch; - struct mgmt_be_client_subscr_info subscr_info; + struct mgmt_txn_be_cfg_batch *batch; char *xpath = NULL, *value = NULL; char err_buf[1024]; enum mgmt_be_client_id id; struct mgmt_be_client_adapter *adapter; struct mgmt_commit_cfg_req *cmtcfg_req; - bool found_validator; int num_chgs = 0; int xpath_len, value_len; + uint64_t clients, chg_clients; cmtcfg_req = &txn_req->req.commit_cfg; @@ -1022,7 +869,7 @@ static int mgmt_txn_create_config_batches(struct mgmt_txn_req *txn_req, (void)mgmt_txn_send_commit_cfg_reply( txn_req->txn, MGMTD_INTERNAL_ERROR, "Internal error! Could not get Xpath from Ds node!"); - goto mgmt_txn_create_config_batches_failed; + return -1; } value = (char *)lyd_get_value(chg->cb.dnode); @@ -1030,118 +877,101 @@ static int mgmt_txn_create_config_batches(struct mgmt_txn_req *txn_req, value = (char *)MGMTD_BE_CONTAINER_NODE_VAL; MGMTD_TXN_DBG("XPATH: %s, Value: '%s'", xpath, - value ? value : "NIL"); + value ? value : "NIL"); + + clients = mgmt_be_interested_clients(xpath, true); - mgmt_be_get_subscr_info_for_xpath(xpath, &subscr_info); + chg_clients = 0; xpath_len = strlen(xpath) + 1; value_len = strlen(value) + 1; - found_validator = false; - FOREACH_MGMTD_BE_CLIENT_ID (id) { - if (!(subscr_info.xpath_subscr[id] & - (MGMT_SUBSCR_VALIDATE_CFG | - MGMT_SUBSCR_NOTIFY_CFG))) - continue; - + FOREACH_BE_CLIENT_BITS (id, clients) { adapter = mgmt_be_get_adapter_by_id(id); if (!adapter) continue; - cfg_btch = cmtcfg_req->last_be_cfg_batch[id]; - if (!cfg_btch - || (cfg_btch->num_cfg_data - == MGMTD_MAX_CFG_CHANGES_IN_BATCH) - || (cfg_btch->buf_space_left - < (xpath_len + value_len))) { + chg_clients |= (1ull << id); + + batch = cmtcfg_req->last_be_cfg_batch[id]; + if (!batch || + (batch->num_cfg_data == + MGMTD_MAX_CFG_CHANGES_IN_BATCH) || + (batch->buf_space_left < (xpath_len + value_len))) { /* Allocate a new config batch */ - cfg_btch = mgmt_txn_cfg_batch_alloc( - txn_req->txn, id, adapter); + batch = mgmt_txn_cfg_batch_alloc(txn_req->txn, + id, adapter); } - cfg_btch->buf_space_left -= (xpath_len + value_len); - memcpy(&cfg_btch->xp_subscr[cfg_btch->num_cfg_data], - &subscr_info.xpath_subscr[id], - sizeof(cfg_btch->xp_subscr[0])); + batch->buf_space_left -= (xpath_len + value_len); mgmt_yang_cfg_data_req_init( - &cfg_btch->cfg_data[cfg_btch->num_cfg_data]); - cfg_btch->cfg_datap[cfg_btch->num_cfg_data] = - &cfg_btch->cfg_data[cfg_btch->num_cfg_data]; - - if (chg->cb.operation == NB_OP_DESTROY) - cfg_btch->cfg_data[cfg_btch->num_cfg_data] - .req_type = - MGMTD__CFG_DATA_REQ_TYPE__DELETE_DATA; + &batch->cfg_data[batch->num_cfg_data]); + batch->cfg_datap[batch->num_cfg_data] = + &batch->cfg_data[batch->num_cfg_data]; + + /* + * On the backend, we don't really care if it's CREATE + * or MODIFY, because the existence was already checked + * on the frontend. Therefore we use SET for both. + */ + if (chg->cb.operation == NB_CB_DESTROY) + batch->cfg_data[batch->num_cfg_data].req_type = + MGMTD__CFG_DATA_REQ_TYPE__REMOVE_DATA; else - cfg_btch->cfg_data[cfg_btch->num_cfg_data] - .req_type = + batch->cfg_data[batch->num_cfg_data].req_type = MGMTD__CFG_DATA_REQ_TYPE__SET_DATA; - mgmt_yang_data_init( - &cfg_btch->data[cfg_btch->num_cfg_data]); - cfg_btch->cfg_data[cfg_btch->num_cfg_data].data = - &cfg_btch->data[cfg_btch->num_cfg_data]; - cfg_btch->data[cfg_btch->num_cfg_data].xpath = - strdup(xpath); + mgmt_yang_data_init(&batch->data[batch->num_cfg_data]); + batch->cfg_data[batch->num_cfg_data].data = + &batch->data[batch->num_cfg_data]; + batch->data[batch->num_cfg_data].xpath = strdup(xpath); mgmt_yang_data_value_init( - &cfg_btch->value[cfg_btch->num_cfg_data]); - cfg_btch->data[cfg_btch->num_cfg_data].value = - &cfg_btch->value[cfg_btch->num_cfg_data]; - cfg_btch->value[cfg_btch->num_cfg_data].value_case = + &batch->value[batch->num_cfg_data]); + batch->data[batch->num_cfg_data].value = + &batch->value[batch->num_cfg_data]; + batch->value[batch->num_cfg_data].value_case = MGMTD__YANG_DATA_VALUE__VALUE_ENCODED_STR_VAL; - cfg_btch->value[cfg_btch->num_cfg_data] - .encoded_str_val = value; + batch->value[batch->num_cfg_data].encoded_str_val = + value; value = NULL; - if (subscr_info.xpath_subscr[id] & - MGMT_SUBSCR_VALIDATE_CFG) - found_validator = true; - - cmtcfg_req->subscr_info.xpath_subscr[id] |= - subscr_info.xpath_subscr[id]; - MGMTD_TXN_DBG(" -- %s, {V:%d, N:%d}, batch-id: %" PRIu64 - " item:%d", - adapter->name, - (subscr_info.xpath_subscr[id] & - MGMT_SUBSCR_VALIDATE_CFG) != 0, - (subscr_info.xpath_subscr[id] & - MGMT_SUBSCR_NOTIFY_CFG) != 0, - cfg_btch->batch_id, - (int)cfg_btch->num_cfg_data); - - cfg_btch->num_cfg_data++; + MGMTD_TXN_DBG(" -- %s, batch item:%d", adapter->name, + (int)batch->num_cfg_data); + + batch->num_cfg_data++; num_chgs++; } - if (!found_validator) { + if (!chg_clients) { snprintf(err_buf, sizeof(err_buf), "No validator module found for XPATH: '%s", xpath); MGMTD_TXN_ERR("***** %s", err_buf); } + cmtcfg_req->clients |= chg_clients; + free(xpath); - xpath = NULL; } cmtcfg_req->cmt_stats->last_batch_cnt = num_chgs; if (!num_chgs) { - (void)mgmt_txn_send_commit_cfg_reply( - txn_req->txn, MGMTD_NO_CFG_CHANGES, - "No changes found to commit!"); - goto mgmt_txn_create_config_batches_failed; + (void)mgmt_txn_send_commit_cfg_reply(txn_req->txn, + MGMTD_NO_CFG_CHANGES, + "No changes found to commit!"); + return -1; + } + + /* Move all BE clients to create phase */ + FOREACH_MGMTD_BE_CLIENT_ID(id) { + if (IS_IDBIT_SET(cmtcfg_req->clients, id)) + cmtcfg_req->be_phase[id] = + MGMTD_COMMIT_PHASE_TXN_CREATE; } cmtcfg_req->next_phase = MGMTD_COMMIT_PHASE_TXN_CREATE; return 0; - -mgmt_txn_create_config_batches_failed: - - if (xpath) - free(xpath); - - return -1; } static int mgmt_txn_prepare_config(struct mgmt_txn_ctx *txn) @@ -1162,8 +992,7 @@ static int mgmt_txn_prepare_config(struct mgmt_txn_ctx *txn) goto mgmt_txn_prep_config_validation_done; } - if (txn->commit_cfg_req->req.commit_cfg.src_ds_id - != MGMTD_DS_CANDIDATE) { + if (txn->commit_cfg_req->req.commit_cfg.src_ds_id != MGMTD_DS_CANDIDATE) { (void)mgmt_txn_send_commit_cfg_reply( txn, MGMTD_INVALID_PARAM, "Source DS cannot be any other than CANDIDATE!"); @@ -1171,8 +1000,7 @@ static int mgmt_txn_prepare_config(struct mgmt_txn_ctx *txn) goto mgmt_txn_prepare_config_done; } - if (txn->commit_cfg_req->req.commit_cfg.dst_ds_id - != MGMTD_DS_RUNNING) { + if (txn->commit_cfg_req->req.commit_cfg.dst_ds_id != MGMTD_DS_RUNNING) { (void)mgmt_txn_send_commit_cfg_reply( txn, MGMTD_INVALID_PARAM, "Destination DS cannot be any other than RUNNING!"); @@ -1181,16 +1009,15 @@ static int mgmt_txn_prepare_config(struct mgmt_txn_ctx *txn) } if (!txn->commit_cfg_req->req.commit_cfg.src_ds_ctx) { - (void)mgmt_txn_send_commit_cfg_reply( - txn, MGMTD_INVALID_PARAM, "No such source datastore!"); + (void)mgmt_txn_send_commit_cfg_reply(txn, MGMTD_INVALID_PARAM, + "No such source datastore!"); ret = -1; goto mgmt_txn_prepare_config_done; } if (!txn->commit_cfg_req->req.commit_cfg.dst_ds_ctx) { - (void)mgmt_txn_send_commit_cfg_reply( - txn, MGMTD_INVALID_PARAM, - "No such destination datastore!"); + (void)mgmt_txn_send_commit_cfg_reply(txn, MGMTD_INVALID_PARAM, + "No such destination datastore!"); ret = -1; goto mgmt_txn_prepare_config_done; } @@ -1201,8 +1028,7 @@ static int mgmt_txn_prepare_config(struct mgmt_txn_ctx *txn) * That should trigger a restore of Candidate datastore to * Running. */ - (void)mgmt_txn_send_commit_cfg_reply(txn, MGMTD_SUCCESS, - NULL); + (void)mgmt_txn_send_commit_cfg_reply(txn, MGMTD_SUCCESS, NULL); goto mgmt_txn_prepare_config_done; } @@ -1217,33 +1043,35 @@ static int mgmt_txn_prepare_config(struct mgmt_txn_ctx *txn) } /* - * Check for diffs from scratch buffer. If found empty - * get the diff from Candidate DS itself. + * Validate YANG contents of the source DS and get the diff + * between source and destination DS contents. */ - cfg_chgs = &nb_config->cfg_chgs; - if (RB_EMPTY(nb_config_cbs, cfg_chgs)) { - /* - * This could be the case when the config is directly - * loaded onto the candidate DS from a file. Get the - * diff from a full comparison of the candidate and - * running DSs. - */ - nb_config_diff( - mgmt_ds_get_nb_config(txn->commit_cfg_req->req - .commit_cfg.dst_ds_ctx), - nb_config, &changes); - cfg_chgs = &changes; - del_cfg_chgs = true; + char err_buf[BUFSIZ] = { 0 }; + + ret = nb_candidate_validate_yang(nb_config, true, err_buf, + sizeof(err_buf) - 1); + if (ret != NB_OK) { + if (strncmp(err_buf, " ", strlen(err_buf)) == 0) + strlcpy(err_buf, "Validation failed", sizeof(err_buf)); + (void)mgmt_txn_send_commit_cfg_reply(txn, MGMTD_INVALID_PARAM, + err_buf); + ret = -1; + goto mgmt_txn_prepare_config_done; } + nb_config_diff(mgmt_ds_get_nb_config(txn->commit_cfg_req->req.commit_cfg + .dst_ds_ctx), + nb_config, &changes); + cfg_chgs = &changes; + del_cfg_chgs = true; + if (RB_EMPTY(nb_config_cbs, cfg_chgs)) { /* * This means there's no changes to commit whatsoever * is the source of the changes in config. */ - (void)mgmt_txn_send_commit_cfg_reply( - txn, MGMTD_NO_CFG_CHANGES, - "No changes found to be committed!"); + (void)mgmt_txn_send_commit_cfg_reply(txn, MGMTD_NO_CFG_CHANGES, + "No changes found to be committed!"); ret = -1; goto mgmt_txn_prepare_config_done; } @@ -1253,36 +1081,20 @@ static int mgmt_txn_prepare_config(struct mgmt_txn_ctx *txn) gettimeofday(&txn->commit_cfg_req->req.commit_cfg.cmt_stats ->validate_start, NULL); - /* - * Validate YANG contents of the source DS and get the diff - * between source and destination DS contents. - */ - char err_buf[1024] = {0}; - nb_ctx.client = NB_CLIENT_MGMTD_SERVER; - nb_ctx.user = (void *)txn; - - ret = nb_candidate_validate_yang(nb_config, false, err_buf, - sizeof(err_buf) - 1); - if (ret != NB_OK) { - if (strncmp(err_buf, " ", strlen(err_buf)) == 0) - strlcpy(err_buf, "Validation failed", sizeof(err_buf)); - (void)mgmt_txn_send_commit_cfg_reply(txn, MGMTD_INVALID_PARAM, - err_buf); - ret = -1; - goto mgmt_txn_prepare_config_done; - } /* * Perform application level validations locally on the MGMTD * process by calling application specific validation routines * loaded onto MGMTD process using libraries. */ + nb_ctx.client = NB_CLIENT_MGMTD_SERVER; + nb_ctx.user = (void *)txn; ret = nb_candidate_validate_code(&nb_ctx, nb_config, &changes, err_buf, sizeof(err_buf) - 1); if (ret != NB_OK) { if (strncmp(err_buf, " ", strlen(err_buf)) == 0) strlcpy(err_buf, "Validation failed", sizeof(err_buf)); (void)mgmt_txn_send_commit_cfg_reply(txn, MGMTD_INVALID_PARAM, - err_buf); + err_buf); ret = -1; goto mgmt_txn_prepare_config_done; } @@ -1291,8 +1103,7 @@ static int mgmt_txn_prepare_config(struct mgmt_txn_ctx *txn) /* * This was a validate-only COMMIT request return success. */ - (void)mgmt_txn_send_commit_cfg_reply(txn, MGMTD_SUCCESS, - NULL); + (void)mgmt_txn_send_commit_cfg_reply(txn, MGMTD_SUCCESS, NULL); goto mgmt_txn_prepare_config_done; } #endif /* ifdef MGMTD_LOCAL_VALIDATIONS_ENABLED */ @@ -1337,28 +1148,19 @@ static int mgmt_txn_send_be_txn_create(struct mgmt_txn_ctx *txn) enum mgmt_be_client_id id; struct mgmt_be_client_adapter *adapter; struct mgmt_commit_cfg_req *cmtcfg_req; - struct mgmt_txn_be_cfg_batch *cfg_btch; assert(txn->type == MGMTD_TXN_TYPE_CONFIG && txn->commit_cfg_req); cmtcfg_req = &txn->commit_cfg_req->req.commit_cfg; FOREACH_MGMTD_BE_CLIENT_ID (id) { - if (cmtcfg_req->subscr_info.xpath_subscr[id]) { + if (IS_IDBIT_SET(cmtcfg_req->clients, id)) { adapter = mgmt_be_get_adapter_by_id(id); - if (mgmt_be_create_txn(adapter, txn->txn_id) - != 0) { + if (mgmt_be_send_txn_req(adapter, txn->txn_id, true)) { (void)mgmt_txn_send_commit_cfg_reply( txn, MGMTD_INTERNAL_ERROR, "Could not send TXN_CREATE to backend adapter"); return -1; } - - FOREACH_TXN_CFG_BATCH_IN_LIST ( - &txn->commit_cfg_req->req.commit_cfg - .curr_batches[id], - cfg_btch) - cfg_btch->comm_phase = - MGMTD_COMMIT_PHASE_TXN_CREATE; } } @@ -1379,54 +1181,47 @@ static int mgmt_txn_send_be_txn_create(struct mgmt_txn_ctx *txn) return 0; } -static int -mgmt_txn_send_be_cfg_data(struct mgmt_txn_ctx *txn, - struct mgmt_be_client_adapter *adapter) +static int mgmt_txn_send_be_cfg_data(struct mgmt_txn_ctx *txn, + struct mgmt_be_client_adapter *adapter) { struct mgmt_commit_cfg_req *cmtcfg_req; - struct mgmt_txn_be_cfg_batch *cfg_btch; - struct mgmt_be_cfgreq cfg_req = {0}; + struct mgmt_txn_be_cfg_batch *batch; + struct mgmt_be_cfgreq cfg_req = { 0 }; size_t num_batches, indx; assert(txn->type == MGMTD_TXN_TYPE_CONFIG && txn->commit_cfg_req); cmtcfg_req = &txn->commit_cfg_req->req.commit_cfg; - assert(cmtcfg_req->subscr_info.xpath_subscr[adapter->id]); + assert(IS_IDBIT_SET(cmtcfg_req->clients, adapter->id)); indx = 0; - num_batches = - mgmt_txn_batches_count(&cmtcfg_req->curr_batches[adapter->id]); - FOREACH_TXN_CFG_BATCH_IN_LIST (&cmtcfg_req->curr_batches[adapter->id], - cfg_btch) { + num_batches = mgmt_txn_batches_count(&cmtcfg_req->batches[adapter->id]); + FOREACH_TXN_CFG_BATCH_IN_LIST (&cmtcfg_req->batches[adapter->id], + batch) { assert(cmtcfg_req->next_phase == MGMTD_COMMIT_PHASE_SEND_CFG); - cfg_req.cfgdata_reqs = cfg_btch->cfg_datap; - cfg_req.num_reqs = cfg_btch->num_cfg_data; + cfg_req.cfgdata_reqs = batch->cfg_datap; + cfg_req.num_reqs = batch->num_cfg_data; indx++; - if (mgmt_be_send_cfg_data_create_req( - adapter, txn->txn_id, cfg_btch->batch_id, &cfg_req, - indx == num_batches ? true : false) - != 0) { + if (mgmt_be_send_cfgdata_req(adapter, txn->txn_id, + cfg_req.cfgdata_reqs, + cfg_req.num_reqs, + indx == num_batches)) { (void)mgmt_txn_send_commit_cfg_reply( txn, MGMTD_INTERNAL_ERROR, "Internal Error! Could not send config data to backend!"); - MGMTD_TXN_ERR( - "Could not send CFGDATA_CREATE txn-id: %" PRIu64 - " batch-id: %" PRIu64 " to client '%s", - txn->txn_id, cfg_btch->batch_id, adapter->name); + MGMTD_TXN_ERR("Could not send CFGDATA_CREATE txn-id: %" PRIu64 + " to client '%s", txn->txn_id, adapter->name); return -1; } cmtcfg_req->cmt_stats->last_num_cfgdata_reqs++; - mgmt_move_txn_cfg_batch_to_next( - cmtcfg_req, cfg_btch, - &cmtcfg_req->curr_batches[adapter->id], - &cmtcfg_req->next_batches[adapter->id], true, - MGMTD_COMMIT_PHASE_SEND_CFG); } + cmtcfg_req->be_phase[adapter->id] = MGMTD_COMMIT_PHASE_SEND_CFG; + /* - * This could ne the last Backend Client to send CFGDATA_CREATE_REQ to. + * This could be the last Backend Client to send CFGDATA_CREATE_REQ to. * Try moving the commit to next phase. */ mgmt_try_move_commit_to_next_phase(txn, cmtcfg_req); @@ -1434,28 +1229,18 @@ mgmt_txn_send_be_cfg_data(struct mgmt_txn_ctx *txn, return 0; } -static int -mgmt_txn_send_be_txn_delete(struct mgmt_txn_ctx *txn, - struct mgmt_be_client_adapter *adapter) +static int mgmt_txn_send_be_txn_delete(struct mgmt_txn_ctx *txn, + struct mgmt_be_client_adapter *adapter) { - struct mgmt_commit_cfg_req *cmtcfg_req; - struct mgmt_txn_be_cfg_batch *cfg_btch; - - assert(txn->type == MGMTD_TXN_TYPE_CONFIG && txn->commit_cfg_req); + struct mgmt_commit_cfg_req *cmtcfg_req = + &txn->commit_cfg_req->req.commit_cfg; - cmtcfg_req = &txn->commit_cfg_req->req.commit_cfg; - if (cmtcfg_req->subscr_info.xpath_subscr[adapter->id]) { - adapter = mgmt_be_get_adapter_by_id(adapter->id); - (void)mgmt_be_destroy_txn(adapter, txn->txn_id); + assert(txn->type == MGMTD_TXN_TYPE_CONFIG); - FOREACH_TXN_CFG_BATCH_IN_LIST ( - &txn->commit_cfg_req->req.commit_cfg - .curr_batches[adapter->id], - cfg_btch) - cfg_btch->comm_phase = MGMTD_COMMIT_PHASE_TXN_DELETE; - } + if (IS_IDBIT_UNSET(cmtcfg_req->clients, adapter->id)) + return 0; - return 0; + return mgmt_be_send_txn_req(adapter, txn->txn_id, false); } static void mgmt_txn_cfg_commit_timedout(struct event *thread) @@ -1483,6 +1268,77 @@ static void mgmt_txn_cfg_commit_timedout(struct event *thread) "Operation on the backend timed-out. Aborting commit!"); } + +static int txn_get_tree_data_done(struct mgmt_txn_ctx *txn, + struct mgmt_txn_req *txn_req) +{ + struct txn_req_get_tree *get_tree = txn_req->req.get_tree; + uint64_t req_id = txn_req->req_id; + int ret = NB_OK; + + /* cancel timer and send reply onward */ + EVENT_OFF(txn->get_tree_timeout); + + if (!get_tree->simple_xpath && get_tree->client_results) { + /* + * We have a complex query so Filter results by the xpath query. + */ + if (yang_lyd_trim_xpath(&get_tree->client_results, + txn_req->req.get_tree->xpath)) + ret = NB_ERR; + } + + if (ret == NB_OK) + ret = mgmt_fe_adapter_send_tree_data(txn->session_id, + txn->txn_id, + txn_req->req_id, + get_tree->result_type, + get_tree->client_results, + get_tree->partial_error, + false); + + /* we're done with the request */ + mgmt_txn_req_free(&txn_req); + + if (ret) { + MGMTD_TXN_ERR("Error sending the results of GETTREE for txn-id %" PRIu64 + " req_id %" PRIu64 " to requested type %u", + txn->txn_id, req_id, get_tree->result_type); + + (void)mgmt_fe_adapter_txn_error(txn->txn_id, req_id, false, ret, + "Error converting results of GETTREE"); + } + + return ret; +} + + +static void txn_get_tree_timeout(struct event *thread) +{ + struct mgmt_txn_ctx *txn; + struct mgmt_txn_req *txn_req; + + txn_req = (struct mgmt_txn_req *)EVENT_ARG(thread); + txn = txn_req->txn; + + assert(txn); + assert(txn->type == MGMTD_TXN_TYPE_SHOW); + + + MGMTD_TXN_ERR("Backend timeout txn-id: %" PRIu64 " ending get-tree", + txn->txn_id); + + /* + * Send a get-tree data reply. + * + * NOTE: The transaction cleanup will be triggered from Front-end + * adapter. + */ + + txn_req->req.get_tree->partial_error = -ETIMEDOUT; + txn_get_tree_data_done(txn, txn_req); +} + /* * Send CFG_APPLY_REQs to all the backend client. * @@ -1496,8 +1352,6 @@ static int mgmt_txn_send_be_cfg_apply(struct mgmt_txn_ctx *txn) enum mgmt_be_client_id id; struct mgmt_be_client_adapter *adapter; struct mgmt_commit_cfg_req *cmtcfg_req; - struct mgmt_txn_batches_head *btch_list; - struct mgmt_txn_be_cfg_batch *cfg_btch; assert(txn->type == MGMTD_TXN_TYPE_CONFIG && txn->commit_cfg_req); @@ -1506,21 +1360,17 @@ static int mgmt_txn_send_be_cfg_apply(struct mgmt_txn_ctx *txn) /* * If this was a validate-only COMMIT request return success. */ - (void)mgmt_txn_send_commit_cfg_reply(txn, MGMTD_SUCCESS, - NULL); + (void)mgmt_txn_send_commit_cfg_reply(txn, MGMTD_SUCCESS, NULL); return 0; } FOREACH_MGMTD_BE_CLIENT_ID (id) { - if (cmtcfg_req->subscr_info.xpath_subscr[id] & - MGMT_SUBSCR_NOTIFY_CFG) { + if (IS_IDBIT_SET(cmtcfg_req->clients, id)) { adapter = mgmt_be_get_adapter_by_id(id); if (!adapter) return -1; - btch_list = &cmtcfg_req->curr_batches[id]; - if (mgmt_be_send_cfg_apply_req(adapter, txn->txn_id) - != 0) { + if (mgmt_be_send_cfgapply_req(adapter, txn->txn_id)) { (void)mgmt_txn_send_commit_cfg_reply( txn, MGMTD_INTERNAL_ERROR, "Could not send CFG_APPLY_REQ to backend adapter"); @@ -1530,10 +1380,6 @@ static int mgmt_txn_send_be_cfg_apply(struct mgmt_txn_ctx *txn) UNSET_FLAG(adapter->flags, MGMTD_BE_ADAPTER_FLAGS_CFG_SYNCED); - - FOREACH_TXN_CFG_BATCH_IN_LIST (btch_list, cfg_btch) - cfg_btch->comm_phase = - MGMTD_COMMIT_PHASE_APPLY_CFG; } } @@ -1557,8 +1403,7 @@ static void mgmt_txn_process_commit_cfg(struct event *thread) assert(txn); MGMTD_TXN_DBG("Processing COMMIT_CONFIG for txn-id: %" PRIu64 - " session-id: %" PRIu64 - " Phase(Current:'%s', Next: '%s')", + " session-id: %" PRIu64 " Phase(Current:'%s', Next: '%s')", txn->txn_id, txn->session_id, mgmt_txn_commit_phase_str(txn, true), mgmt_txn_commit_phase_str(txn, false)); @@ -1588,16 +1433,14 @@ static void mgmt_txn_process_commit_cfg(struct event *thread) */ #ifndef MGMTD_LOCAL_VALIDATIONS_ENABLED assert(cmtcfg_req->next_phase == MGMTD_COMMIT_PHASE_APPLY_CFG); - MGMTD_TXN_DBG( - "txn-id: %" PRIu64 " session-id: %" PRIu64 - " trigger sending CFG_VALIDATE_REQ to all backend clients", - txn->txn_id, txn->session_id); + MGMTD_TXN_DBG("txn-id: %" PRIu64 " session-id: %" PRIu64 + " trigger sending CFG_VALIDATE_REQ to all backend clients", + txn->txn_id, txn->session_id); #else /* ifndef MGMTD_LOCAL_VALIDATIONS_ENABLED */ assert(cmtcfg_req->next_phase == MGMTD_COMMIT_PHASE_APPLY_CFG); - MGMTD_TXN_DBG( - "txn-id: %" PRIu64 " session-id: %" PRIu64 - " trigger sending CFG_APPLY_REQ to all backend clients", - txn->txn_id, txn->session_id); + MGMTD_TXN_DBG("txn-id: %" PRIu64 " session-id: %" PRIu64 + " trigger sending CFG_APPLY_REQ to all backend clients", + txn->txn_id, txn->session_id); #endif /* ifndef MGMTD_LOCAL_VALIDATIONS_ENABLED */ break; case MGMTD_COMMIT_PHASE_APPLY_CFG: @@ -1678,7 +1521,7 @@ static void mgmt_reset_get_data_reply_buf(struct mgmt_get_data_req *get_data) } static void mgmt_txn_send_getcfg_reply_data(struct mgmt_txn_req *txn_req, - struct mgmt_get_data_req *get_req) + struct mgmt_get_data_req *get_req) { struct mgmt_get_data_reply *get_reply; Mgmtd__YangDataReply *data_reply; @@ -1691,45 +1534,32 @@ static void mgmt_txn_send_getcfg_reply_data(struct mgmt_txn_req *txn_req, mgmt_yang_data_reply_init(data_reply); data_reply->n_data = get_reply->num_reply; data_reply->data = get_reply->reply_datap; - data_reply->next_indx = - (!get_reply->last_batch ? get_req->total_reply : -1); + data_reply->next_indx = (!get_reply->last_batch ? get_req->total_reply + : -1); MGMTD_TXN_DBG("Sending %zu Get-Config/Data replies next-index:%" PRId64, data_reply->n_data, data_reply->next_indx); switch (txn_req->req_event) { case MGMTD_TXN_PROC_GETCFG: - if (mgmt_fe_send_get_cfg_reply( - txn_req->txn->session_id, txn_req->txn->txn_id, - get_req->ds_id, txn_req->req_id, MGMTD_SUCCESS, - data_reply, NULL) - != 0) { - MGMTD_TXN_ERR( - "Failed to send GET-CONFIG-REPLY txn-id: %" PRIu64 - " session-id: %" PRIu64 " req-id: %" PRIu64, - txn_req->txn->txn_id, txn_req->txn->session_id, - txn_req->req_id); - } - break; - case MGMTD_TXN_PROC_GETDATA: - if (mgmt_fe_send_get_data_reply( - txn_req->txn->session_id, txn_req->txn->txn_id, - get_req->ds_id, txn_req->req_id, MGMTD_SUCCESS, - data_reply, NULL) - != 0) { - MGMTD_TXN_ERR( - "Failed to send GET-DATA-REPLY txn-id: %" PRIu64 - " session-id: %" PRIu64 " req-id: %" PRIu64, - txn_req->txn->txn_id, txn_req->txn->session_id, - txn_req->req_id); + if (mgmt_fe_send_get_reply(txn_req->txn->session_id, + txn_req->txn->txn_id, get_req->ds_id, + txn_req->req_id, MGMTD_SUCCESS, + data_reply, NULL) != 0) { + MGMTD_TXN_ERR("Failed to send GET-CONFIG-REPLY txn-id: %" PRIu64 + " session-id: %" PRIu64 + " req-id: %" PRIu64, + txn_req->txn->txn_id, + txn_req->txn->session_id, txn_req->req_id); } break; case MGMTD_TXN_PROC_SETCFG: case MGMTD_TXN_PROC_COMMITCFG: + case MGMTD_TXN_PROC_GETTREE: + case MGMTD_TXN_GETTREE_TIMEOUT: case MGMTD_TXN_COMMITCFG_TIMEOUT: case MGMTD_TXN_CLEANUP: - MGMTD_TXN_ERR("Invalid Txn-Req-Event %u", - txn_req->req_event); + MGMTD_TXN_ERR("Invalid Txn-Req-Event %u", txn_req->req_event); break; } @@ -1739,11 +1569,8 @@ static void mgmt_txn_send_getcfg_reply_data(struct mgmt_txn_req *txn_req, mgmt_reset_get_data_reply_buf(get_req); } -static void mgmt_txn_iter_and_send_get_cfg_reply(struct mgmt_ds_ctx *ds_ctx, - const char *xpath, - struct lyd_node *node, - struct nb_node *nb_node, - void *ctx) +static void txn_iter_get_config_data_cb(const char *xpath, struct lyd_node *node, + struct nb_node *nb_node, void *ctx) { struct mgmt_txn_req *txn_req; struct mgmt_get_data_req *get_req; @@ -1758,8 +1585,7 @@ static void mgmt_txn_iter_and_send_get_cfg_reply(struct mgmt_ds_ctx *ds_ctx, if (!(node->schema->nodetype & LYD_NODE_TERM)) return; - assert(txn_req->req_event == MGMTD_TXN_PROC_GETCFG - || txn_req->req_event == MGMTD_TXN_PROC_GETDATA); + assert(txn_req->req_event == MGMTD_TXN_PROC_GETCFG); get_req = txn_req->req.get_data; assert(get_req); @@ -1777,7 +1603,7 @@ static void mgmt_txn_iter_and_send_get_cfg_reply(struct mgmt_ds_ctx *ds_ctx, get_reply->num_reply++; get_req->total_reply++; MGMTD_TXN_DBG(" [%d] XPATH: '%s', Value: '%s'", get_req->total_reply, - data->xpath, data_value->encoded_str_val); + data->xpath, data_value->encoded_str_val); if (get_reply->num_reply == MGMTD_MAX_NUM_DATA_REPLY_IN_BATCH) mgmt_txn_send_getcfg_reply_data(txn_req, get_req); @@ -1785,7 +1611,7 @@ static void mgmt_txn_iter_and_send_get_cfg_reply(struct mgmt_ds_ctx *ds_ctx, static int mgmt_txn_get_config(struct mgmt_txn_ctx *txn, struct mgmt_txn_req *txn_req, - struct mgmt_ds_ctx *ds_ctx) + struct nb_config *root) { int indx; struct mgmt_get_data_req *get_data; @@ -1797,10 +1623,9 @@ static int mgmt_txn_get_config(struct mgmt_txn_ctx *txn, get_data->reply = XCALLOC(MTYPE_MGMTD_TXN_GETDATA_REPLY, sizeof(struct mgmt_get_data_reply)); if (!get_data->reply) { - mgmt_fe_send_get_cfg_reply( - txn->session_id, txn->txn_id, - get_data->ds_id, txn_req->req_id, - MGMTD_INTERNAL_ERROR, NULL, + mgmt_fe_send_get_reply( + txn->session_id, txn->txn_id, get_data->ds_id, + txn_req->req_id, MGMTD_INTERNAL_ERROR, NULL, "Internal error: Unable to allocate reply buffers!"); goto mgmt_txn_get_config_failed; } @@ -1813,26 +1638,27 @@ static int mgmt_txn_get_config(struct mgmt_txn_ctx *txn, get_reply = get_data->reply; for (indx = 0; indx < get_data->num_xpaths; indx++) { MGMTD_TXN_DBG("Trying to get all data under '%s'", - get_data->xpaths[indx]); + get_data->xpaths[indx]); mgmt_init_get_data_reply(get_reply); /* * mgmt_ds_iter_data works on path prefixes, but the user may * want to also use an xpath regexp we need to add this * functionality. */ - if (mgmt_ds_iter_data(get_data->ds_ctx, get_data->xpaths[indx], - mgmt_txn_iter_and_send_get_cfg_reply, + if (mgmt_ds_iter_data(get_data->ds_id, root, + get_data->xpaths[indx], + txn_iter_get_config_data_cb, (void *)txn_req) == -1) { MGMTD_TXN_DBG("Invalid Xpath '%s", - get_data->xpaths[indx]); - mgmt_fe_send_get_cfg_reply( - txn->session_id, txn->txn_id, - get_data->ds_id, txn_req->req_id, - MGMTD_INTERNAL_ERROR, NULL, "Invalid xpath"); + get_data->xpaths[indx]); + mgmt_fe_send_get_reply(txn->session_id, txn->txn_id, + get_data->ds_id, txn_req->req_id, + MGMTD_INTERNAL_ERROR, NULL, + "Invalid xpath"); goto mgmt_txn_get_config_failed; } MGMTD_TXN_DBG("Got %d remaining data-replies for xpath '%s'", - get_reply->num_reply, get_data->xpaths[indx]); + get_reply->num_reply, get_data->xpaths[indx]); get_reply->last_batch = true; mgmt_txn_send_getcfg_reply_data(txn_req, get_data); } @@ -1852,7 +1678,7 @@ static void mgmt_txn_process_get_cfg(struct event *thread) { struct mgmt_txn_ctx *txn; struct mgmt_txn_req *txn_req; - struct mgmt_ds_ctx *ds_ctx; + struct nb_config *cfg_root; int num_processed = 0; bool error; @@ -1867,28 +1693,18 @@ static void mgmt_txn_process_get_cfg(struct event *thread) FOREACH_TXN_REQ_IN_LIST (&txn->get_cfg_reqs, txn_req) { error = false; assert(txn_req->req_event == MGMTD_TXN_PROC_GETCFG); - ds_ctx = txn_req->req.get_data->ds_ctx; - if (!ds_ctx) { - mgmt_fe_send_get_cfg_reply( - txn->session_id, txn->txn_id, - txn_req->req.get_data->ds_id, txn_req->req_id, - MGMTD_INTERNAL_ERROR, NULL, - "No such datastore!"); - error = true; - goto mgmt_txn_process_get_cfg_done; - } - - if (mgmt_txn_get_config(txn, txn_req, ds_ctx) != 0) { - MGMTD_TXN_ERR( - "Unable to retrieve config from DS %d txn-id: %" PRIu64 - " session-id: %" PRIu64 " req-id: %" PRIu64, - txn_req->req.get_data->ds_id, txn->txn_id, - txn->session_id, txn_req->req_id); + cfg_root = txn_req->req.get_data->cfg_root; + assert(cfg_root); + + if (mgmt_txn_get_config(txn, txn_req, cfg_root) != 0) { + MGMTD_TXN_ERR("Unable to retrieve config from DS %d txn-id: %" PRIu64 + " session-id: %" PRIu64 + " req-id: %" PRIu64, + txn_req->req.get_data->ds_id, txn->txn_id, + txn->session_id, txn_req->req_id); error = true; } - mgmt_txn_process_get_cfg_done: - if (error) { /* * Delete the txn request. @@ -1908,99 +1724,15 @@ static void mgmt_txn_process_get_cfg(struct event *thread) } if (mgmt_txn_reqs_count(&txn->get_cfg_reqs)) { - MGMTD_TXN_DBG( - "Processed maximum number of Get-Config requests (%d/%d). Rescheduling for rest.", - num_processed, MGMTD_TXN_MAX_NUM_GETCFG_PROC); + MGMTD_TXN_DBG("Processed maximum number of Get-Config requests (%d/%d). Rescheduling for rest.", + num_processed, MGMTD_TXN_MAX_NUM_GETCFG_PROC); mgmt_txn_register_event(txn, MGMTD_TXN_PROC_GETCFG); } } -static void mgmt_txn_process_get_data(struct event *thread) -{ - struct mgmt_txn_ctx *txn; - struct mgmt_txn_req *txn_req; - struct mgmt_ds_ctx *ds_ctx; - int num_processed = 0; - bool error; - - txn = (struct mgmt_txn_ctx *)EVENT_ARG(thread); - assert(txn); - - MGMTD_TXN_DBG("Processing %zu GET_DATA requests txn-id: %" PRIu64 - " session-id: %" PRIu64, - mgmt_txn_reqs_count(&txn->get_data_reqs), txn->txn_id, - txn->session_id); - - FOREACH_TXN_REQ_IN_LIST (&txn->get_data_reqs, txn_req) { - error = false; - assert(txn_req->req_event == MGMTD_TXN_PROC_GETDATA); - ds_ctx = txn_req->req.get_data->ds_ctx; - if (!ds_ctx) { - mgmt_fe_send_get_data_reply( - txn->session_id, txn->txn_id, - txn_req->req.get_data->ds_id, txn_req->req_id, - MGMTD_INTERNAL_ERROR, NULL, - "No such datastore!"); - error = true; - goto mgmt_txn_process_get_data_done; - } - - if (mgmt_ds_is_config(ds_ctx)) { - if (mgmt_txn_get_config(txn, txn_req, ds_ctx) - != 0) { - MGMTD_TXN_ERR( - "Unable to retrieve config from DS %d txn-id %" PRIu64 - " session-id: %" PRIu64 - " req-id: %" PRIu64, - txn_req->req.get_data->ds_id, - txn->txn_id, txn->session_id, - txn_req->req_id); - error = true; - } - } else { - /* - * TODO: Trigger GET procedures for Backend - * For now return back error. - */ - mgmt_fe_send_get_data_reply( - txn->session_id, txn->txn_id, - txn_req->req.get_data->ds_id, txn_req->req_id, - MGMTD_INTERNAL_ERROR, NULL, - "GET-DATA on Oper DS is not supported yet!"); - error = true; - } - - mgmt_txn_process_get_data_done: - - if (error) { - /* - * Delete the txn request. - * Note: The following will remove it from the list - * as well. - */ - mgmt_txn_req_free(&txn_req); - } - - /* - * Else the transaction would have been already deleted or - * moved to corresponding pending list. No need to delete it. - */ - num_processed++; - if (num_processed == MGMTD_TXN_MAX_NUM_GETDATA_PROC) - break; - } - - if (mgmt_txn_reqs_count(&txn->get_data_reqs)) { - MGMTD_TXN_DBG( - "Processed maximum number of Get-Data requests (%d/%d). Rescheduling for rest.", - num_processed, MGMTD_TXN_MAX_NUM_GETDATA_PROC); - mgmt_txn_register_event(txn, MGMTD_TXN_PROC_GETDATA); - } -} - static struct mgmt_txn_ctx * mgmt_fe_find_txn_by_session_id(struct mgmt_master *cm, uint64_t session_id, - enum mgmt_txn_type type) + enum mgmt_txn_type type) { struct mgmt_txn_ctx *txn; @@ -2013,13 +1745,13 @@ mgmt_fe_find_txn_by_session_id(struct mgmt_master *cm, uint64_t session_id, } static struct mgmt_txn_ctx *mgmt_txn_create_new(uint64_t session_id, - enum mgmt_txn_type type) + enum mgmt_txn_type type) { struct mgmt_txn_ctx *txn = NULL; /* * For 'CONFIG' transaction check if one is already created - * or not. + * or not. TODO: figure out what code counts on this and fix it. */ if (type == MGMTD_TXN_TYPE_CONFIG && mgmt_txn_mm->cfg_txn) { if (mgmt_config_txn_in_progress() == session_id) @@ -2027,8 +1759,7 @@ static struct mgmt_txn_ctx *mgmt_txn_create_new(uint64_t session_id, goto mgmt_create_txn_done; } - txn = mgmt_fe_find_txn_by_session_id(mgmt_txn_mm, session_id, - type); + txn = mgmt_fe_find_txn_by_session_id(mgmt_txn_mm, session_id, type); if (!txn) { txn = XCALLOC(MTYPE_MGMTD_TXN, sizeof(struct mgmt_txn_ctx)); assert(txn); @@ -2036,10 +1767,10 @@ static struct mgmt_txn_ctx *mgmt_txn_create_new(uint64_t session_id, txn->session_id = session_id; txn->type = type; mgmt_txns_add_tail(&mgmt_txn_mm->txn_list, txn); + /* TODO: why do we need N lists for one transaction */ mgmt_txn_reqs_init(&txn->set_cfg_reqs); mgmt_txn_reqs_init(&txn->get_cfg_reqs); - mgmt_txn_reqs_init(&txn->get_data_reqs); - mgmt_txn_reqs_init(&txn->pending_get_datas); + mgmt_txn_reqs_init(&txn->get_tree_reqs); txn->commit_cfg_req = NULL; txn->refcount = 0; if (!mgmt_txn_mm->next_txn_id) @@ -2069,7 +1800,7 @@ static unsigned int mgmt_txn_hash_key(const void *data) { const struct mgmt_txn_ctx *txn = data; - return jhash2((uint32_t *) &txn->txn_id, + return jhash2((uint32_t *)&txn->txn_id, sizeof(txn->txn_id) / sizeof(uint32_t), 0); } @@ -2093,9 +1824,8 @@ static void mgmt_txn_hash_init(void) if (!mgmt_txn_mm || mgmt_txn_mm->txn_hash) return; - mgmt_txn_mm->txn_hash = hash_create(mgmt_txn_hash_key, - mgmt_txn_hash_cmp, - "MGMT Transactions"); + mgmt_txn_mm->txn_hash = hash_create(mgmt_txn_hash_key, mgmt_txn_hash_cmp, + "MGMT Transactions"); } static void mgmt_txn_hash_destroy(void) @@ -2103,16 +1833,14 @@ static void mgmt_txn_hash_destroy(void) if (!mgmt_txn_mm || !mgmt_txn_mm->txn_hash) return; - hash_clean(mgmt_txn_mm->txn_hash, - mgmt_txn_hash_free); + hash_clean(mgmt_txn_mm->txn_hash, mgmt_txn_hash_free); hash_free(mgmt_txn_mm->txn_hash); mgmt_txn_mm->txn_hash = NULL; } -static inline struct mgmt_txn_ctx * -mgmt_txn_id2ctx(uint64_t txn_id) +static inline struct mgmt_txn_ctx *mgmt_txn_id2ctx(uint64_t txn_id) { - struct mgmt_txn_ctx key = {0}; + struct mgmt_txn_ctx key = { 0 }; struct mgmt_txn_ctx *txn; if (!mgmt_txn_mm || !mgmt_txn_mm->txn_hash) @@ -2124,8 +1852,14 @@ mgmt_txn_id2ctx(uint64_t txn_id) return txn; } -static void mgmt_txn_lock(struct mgmt_txn_ctx *txn, const char *file, - int line) +uint64_t mgmt_txn_get_session_id(uint64_t txn_id) +{ + struct mgmt_txn_ctx *txn = mgmt_txn_id2ctx(txn_id); + + return txn ? txn->session_id : MGMTD_SESSION_ID_NONE; +} + +static void mgmt_txn_lock(struct mgmt_txn_ctx *txn, const char *file, int line) { txn->refcount++; MGMTD_TXN_DBG("%s:%d --> Lock %s txn-id: %" PRIu64 " refcnt: %d", file, @@ -2134,7 +1868,7 @@ static void mgmt_txn_lock(struct mgmt_txn_ctx *txn, const char *file, } static void mgmt_txn_unlock(struct mgmt_txn_ctx **txn, const char *file, - int line) + int line) { assert(*txn && (*txn)->refcount); @@ -2150,6 +1884,7 @@ static void mgmt_txn_unlock(struct mgmt_txn_ctx **txn, const char *file, EVENT_OFF((*txn)->proc_get_data); EVENT_OFF((*txn)->proc_comm_cfg); EVENT_OFF((*txn)->comm_cfg_timeout); + EVENT_OFF((*txn)->get_tree_timeout); hash_release(mgmt_txn_mm->txn_hash, *txn); mgmt_txns_del(&mgmt_txn_mm->txn_list, *txn); @@ -2171,8 +1906,7 @@ static void mgmt_txn_cleanup_txn(struct mgmt_txn_ctx **txn) mgmt_txn_delete(txn); } -static void -mgmt_txn_cleanup_all_txns(void) +static void mgmt_txn_cleanup_all_txns(void) { struct mgmt_txn_ctx *txn; @@ -2194,40 +1928,44 @@ static void mgmt_txn_cleanup(struct event *thread) } static void mgmt_txn_register_event(struct mgmt_txn_ctx *txn, - enum mgmt_txn_event event) + enum mgmt_txn_event event) { - struct timeval tv = {.tv_sec = 0, - .tv_usec = MGMTD_TXN_PROC_DELAY_USEC}; + struct timeval tv = { .tv_sec = 0, + .tv_usec = MGMTD_TXN_PROC_DELAY_USEC }; assert(mgmt_txn_mm && mgmt_txn_tm); switch (event) { case MGMTD_TXN_PROC_SETCFG: - event_add_timer_tv(mgmt_txn_tm, mgmt_txn_process_set_cfg, - txn, &tv, &txn->proc_set_cfg); + event_add_timer_tv(mgmt_txn_tm, mgmt_txn_process_set_cfg, txn, + &tv, &txn->proc_set_cfg); break; case MGMTD_TXN_PROC_COMMITCFG: event_add_timer_tv(mgmt_txn_tm, mgmt_txn_process_commit_cfg, - txn, &tv, &txn->proc_comm_cfg); + txn, &tv, &txn->proc_comm_cfg); break; case MGMTD_TXN_PROC_GETCFG: - event_add_timer_tv(mgmt_txn_tm, mgmt_txn_process_get_cfg, - txn, &tv, &txn->proc_get_cfg); - break; - case MGMTD_TXN_PROC_GETDATA: - event_add_timer_tv(mgmt_txn_tm, mgmt_txn_process_get_data, - txn, &tv, &txn->proc_get_data); + event_add_timer_tv(mgmt_txn_tm, mgmt_txn_process_get_cfg, txn, + &tv, &txn->proc_get_cfg); break; case MGMTD_TXN_COMMITCFG_TIMEOUT: - event_add_timer_msec(mgmt_txn_tm, - mgmt_txn_cfg_commit_timedout, txn, - MGMTD_TXN_CFG_COMMIT_MAX_DELAY_MSEC, - &txn->comm_cfg_timeout); + event_add_timer(mgmt_txn_tm, mgmt_txn_cfg_commit_timedout, txn, + MGMTD_TXN_CFG_COMMIT_MAX_DELAY_SEC, + &txn->comm_cfg_timeout); + break; + case MGMTD_TXN_GETTREE_TIMEOUT: + event_add_timer(mgmt_txn_tm, txn_get_tree_timeout, txn, + MGMTD_TXN_GET_TREE_MAX_DELAY_SEC, + &txn->get_tree_timeout); break; case MGMTD_TXN_CLEANUP: tv.tv_usec = MGMTD_TXN_CLEANUP_DELAY_USEC; event_add_timer_tv(mgmt_txn_tm, mgmt_txn_cleanup, txn, &tv, - &txn->clnup); + &txn->clnup); + break; + case MGMTD_TXN_PROC_GETTREE: + assert(!"code bug do not register this event"); + break; } } @@ -2268,11 +2006,6 @@ uint64_t mgmt_create_txn(uint64_t session_id, enum mgmt_txn_type type) return txn ? txn->txn_id : MGMTD_TXN_ID_NONE; } -bool mgmt_txn_id_is_valid(uint64_t txn_id) -{ - return mgmt_txn_id2ctx(txn_id) ? true : false; -} - void mgmt_destroy_txn(uint64_t *txn_id) { struct mgmt_txn_ctx *txn; @@ -2285,30 +2018,20 @@ void mgmt_destroy_txn(uint64_t *txn_id) *txn_id = MGMTD_TXN_ID_NONE; } -enum mgmt_txn_type mgmt_get_txn_type(uint64_t txn_id) -{ - struct mgmt_txn_ctx *txn; - - txn = mgmt_txn_id2ctx(txn_id); - if (!txn) - return MGMTD_TXN_TYPE_NONE; - - return txn->type; -} - int mgmt_txn_send_set_config_req(uint64_t txn_id, uint64_t req_id, - Mgmtd__DatastoreId ds_id, - struct mgmt_ds_ctx *ds_ctx, - Mgmtd__YangCfgDataReq **cfg_req, - size_t num_req, bool implicit_commit, - Mgmtd__DatastoreId dst_ds_id, - struct mgmt_ds_ctx *dst_ds_ctx) + Mgmtd__DatastoreId ds_id, + struct mgmt_ds_ctx *ds_ctx, + Mgmtd__YangCfgDataReq **cfg_req, + size_t num_req, bool implicit_commit, + Mgmtd__DatastoreId dst_ds_id, + struct mgmt_ds_ctx *dst_ds_ctx) { struct mgmt_txn_ctx *txn; struct mgmt_txn_req *txn_req; size_t indx; uint16_t *num_chgs; struct nb_cfg_change *cfg_chg; + struct nb_node *node; txn = mgmt_txn_id2ctx(txn_id); if (!txn) @@ -2327,40 +2050,54 @@ int mgmt_txn_send_set_config_req(uint64_t txn_id, uint64_t req_id, for (indx = 0; indx < num_req; indx++) { cfg_chg = &txn_req->req.set_cfg->cfg_changes[*num_chgs]; - if (cfg_req[indx]->req_type - == MGMTD__CFG_DATA_REQ_TYPE__DELETE_DATA) + switch (cfg_req[indx]->req_type) { + case MGMTD__CFG_DATA_REQ_TYPE__DELETE_DATA: + cfg_chg->operation = NB_OP_DELETE; + break; + case MGMTD__CFG_DATA_REQ_TYPE__REMOVE_DATA: cfg_chg->operation = NB_OP_DESTROY; - else if (cfg_req[indx]->req_type - == MGMTD__CFG_DATA_REQ_TYPE__SET_DATA) - cfg_chg->operation = - mgmt_ds_find_data_node_by_xpath( - ds_ctx, cfg_req[indx]->data->xpath) - ? NB_OP_MODIFY - : NB_OP_CREATE; - else + break; + case MGMTD__CFG_DATA_REQ_TYPE__SET_DATA: + /* + * For backward compatibility, we need to allow creating + * *new* list keys with SET_DATA operation. NB_OP_MODIFY + * is not allowed for keys, so use NB_OP_CREATE_EXCL. + */ + node = nb_node_find(cfg_req[indx]->data->xpath); + if (node && lysc_is_key(node->snode)) + cfg_chg->operation = NB_OP_CREATE_EXCL; + else + cfg_chg->operation = NB_OP_MODIFY; + break; + case MGMTD__CFG_DATA_REQ_TYPE__CREATE_DATA: + cfg_chg->operation = NB_OP_CREATE_EXCL; + break; + case MGMTD__CFG_DATA_REQ_TYPE__REPLACE_DATA: + cfg_chg->operation = NB_OP_REPLACE; + break; + case MGMTD__CFG_DATA_REQ_TYPE__REQ_TYPE_NONE: + case _MGMTD__CFG_DATA_REQ_TYPE_IS_INT_SIZE: + default: continue; + } - MGMTD_TXN_DBG( - "XPath: '%s', Value: '%s'", cfg_req[indx]->data->xpath, - (cfg_req[indx]->data->value - && cfg_req[indx] - ->data->value - ->encoded_str_val - ? cfg_req[indx]->data->value->encoded_str_val - : "NULL")); + MGMTD_TXN_DBG("XPath: '%s', Value: '%s'", + cfg_req[indx]->data->xpath, + (cfg_req[indx]->data->value && + cfg_req[indx]->data->value->encoded_str_val + ? cfg_req[indx]->data->value->encoded_str_val + : "NULL")); strlcpy(cfg_chg->xpath, cfg_req[indx]->data->xpath, sizeof(cfg_chg->xpath)); - cfg_chg->value = (cfg_req[indx]->data->value - && cfg_req[indx] - ->data->value - ->encoded_str_val - ? strdup(cfg_req[indx] - ->data->value - ->encoded_str_val) - : NULL); + cfg_chg->value = + (cfg_req[indx]->data->value && + cfg_req[indx]->data->value->encoded_str_val + ? strdup(cfg_req[indx] + ->data->value->encoded_str_val) + : NULL); if (cfg_chg->value) MGMTD_TXN_DBG("Allocated value at %p ==> '%s'", - cfg_chg->value, cfg_chg->value); + cfg_chg->value, cfg_chg->value); (*num_chgs)++; } @@ -2375,12 +2112,12 @@ int mgmt_txn_send_set_config_req(uint64_t txn_id, uint64_t req_id, } int mgmt_txn_send_commit_config_req(uint64_t txn_id, uint64_t req_id, - Mgmtd__DatastoreId src_ds_id, - struct mgmt_ds_ctx *src_ds_ctx, - Mgmtd__DatastoreId dst_ds_id, - struct mgmt_ds_ctx *dst_ds_ctx, - bool validate_only, bool abort, - bool implicit) + Mgmtd__DatastoreId src_ds_id, + struct mgmt_ds_ctx *src_ds_ctx, + Mgmtd__DatastoreId dst_ds_id, + struct mgmt_ds_ctx *dst_ds_ctx, + bool validate_only, bool abort, + bool implicit) { struct mgmt_txn_ctx *txn; struct mgmt_txn_req *txn_req; @@ -2415,7 +2152,7 @@ int mgmt_txn_send_commit_config_req(uint64_t txn_id, uint64_t req_id, } int mgmt_txn_notify_be_adapter_conn(struct mgmt_be_client_adapter *adapter, - bool connect) + bool connect) { struct mgmt_txn_ctx *txn; struct mgmt_txn_req *txn_req; @@ -2426,9 +2163,8 @@ int mgmt_txn_notify_be_adapter_conn(struct mgmt_be_client_adapter *adapter, memset(&dummy_stats, 0, sizeof(dummy_stats)); if (connect) { /* Get config for this single backend client */ - mgmt_be_get_adapter_config(adapter, mm->running_ds, - &adapter_cfgs); + mgmt_be_get_adapter_config(adapter, &adapter_cfgs); if (!adapter_cfgs || RB_EMPTY(nb_config_cbs, adapter_cfgs)) { SET_FLAG(adapter->flags, MGMTD_BE_ADAPTER_FLAGS_CFG_SYNCED); @@ -2441,9 +2177,8 @@ int mgmt_txn_notify_be_adapter_conn(struct mgmt_be_client_adapter *adapter, */ txn = mgmt_txn_create_new(0, MGMTD_TXN_TYPE_CONFIG); if (!txn) { - MGMTD_TXN_ERR( - "Failed to create CONFIG Transaction for downloading CONFIGs for client '%s'", - adapter->name); + MGMTD_TXN_ERR("Failed to create CONFIG Transaction for downloading CONFIGs for client '%s'", + adapter->name); return -1; } @@ -2454,8 +2189,7 @@ int mgmt_txn_notify_be_adapter_conn(struct mgmt_be_client_adapter *adapter, * Set the changeset for transaction to commit and trigger the * commit request. */ - txn_req = - mgmt_txn_req_alloc(txn, 0, MGMTD_TXN_PROC_COMMITCFG); + txn_req = mgmt_txn_req_alloc(txn, 0, MGMTD_TXN_PROC_COMMITCFG); txn_req->req.commit_cfg.src_ds_id = MGMTD_DS_NONE; txn_req->req.commit_cfg.src_ds_ctx = 0; txn_req->req.commit_cfg.dst_ds_id = MGMTD_DS_NONE; @@ -2481,12 +2215,11 @@ int mgmt_txn_notify_be_adapter_conn(struct mgmt_be_client_adapter *adapter, * completed */ if (txn->type == MGMTD_TXN_TYPE_CONFIG) { cmtcfg_req = txn->commit_cfg_req - ? &txn->commit_cfg_req - ->req.commit_cfg + ? &txn->commit_cfg_req->req + .commit_cfg : NULL; - if (cmtcfg_req && - cmtcfg_req->subscr_info - .xpath_subscr[adapter->id]) { + if (cmtcfg_req && IS_IDBIT_SET(cmtcfg_req->clients, + adapter->id)) { mgmt_txn_send_commit_cfg_reply( txn, MGMTD_INTERNAL_ERROR, "Backend daemon disconnected while processing commit!"); @@ -2498,9 +2231,8 @@ int mgmt_txn_notify_be_adapter_conn(struct mgmt_be_client_adapter *adapter, return 0; } -int mgmt_txn_notify_be_txn_reply(uint64_t txn_id, bool create, - bool success, - struct mgmt_be_client_adapter *adapter) +int mgmt_txn_notify_be_txn_reply(uint64_t txn_id, bool create, bool success, + struct mgmt_be_client_adapter *adapter) { struct mgmt_txn_ctx *txn; struct mgmt_commit_cfg_req *cmtcfg_req = NULL; @@ -2520,8 +2252,8 @@ int mgmt_txn_notify_be_txn_reply(uint64_t txn_id, bool create, * Done with TXN_CREATE. Move the backend client to * next phase. */ - assert(cmtcfg_req->curr_phase - == MGMTD_COMMIT_PHASE_TXN_CREATE); + assert(cmtcfg_req->curr_phase == + MGMTD_COMMIT_PHASE_TXN_CREATE); /* * Send CFGDATA_CREATE-REQs to the backend immediately. @@ -2532,24 +2264,17 @@ int mgmt_txn_notify_be_txn_reply(uint64_t txn_id, bool create, txn, MGMTD_INTERNAL_ERROR, "Internal error! Failed to initiate transaction at backend!"); } - } else { - /* - * Done with TXN_DELETE. Move the backend client to next phase. - */ - if (false) - mgmt_move_be_commit_to_next_phase(txn, adapter); } return 0; } -int mgmt_txn_notify_be_cfgdata_reply( - uint64_t txn_id, uint64_t batch_id, bool success, char *error_if_any, - struct mgmt_be_client_adapter *adapter) +int mgmt_txn_notify_be_cfgdata_reply(uint64_t txn_id, bool success, + char *error_if_any, + struct mgmt_be_client_adapter *adapter) { struct mgmt_txn_ctx *txn; - struct mgmt_txn_be_cfg_batch *cfg_btch; - struct mgmt_commit_cfg_req *cmtcfg_req = NULL; + struct mgmt_commit_cfg_req *cmtcfg_req; txn = mgmt_txn_id2ctx(txn_id); if (!txn || txn->type != MGMTD_TXN_TYPE_CONFIG) @@ -2559,32 +2284,23 @@ int mgmt_txn_notify_be_cfgdata_reply( return -1; cmtcfg_req = &txn->commit_cfg_req->req.commit_cfg; - cfg_btch = mgmt_txn_cfgbatch_id2ctx(txn, batch_id); - if (!cfg_btch || cfg_btch->txn != txn) - return -1; - if (!success) { - MGMTD_TXN_ERR( - "CFGDATA_CREATE_REQ sent to '%s' failed txn-id: %" PRIu64 - " batch-id %" PRIu64 " err: %s", - adapter->name, txn->txn_id, cfg_btch->batch_id, - error_if_any ? error_if_any : "None"); + MGMTD_TXN_ERR("CFGDATA_CREATE_REQ sent to '%s' failed txn-id: %" PRIu64 + " err: %s", adapter->name, txn->txn_id, + error_if_any ? error_if_any : "None"); mgmt_txn_send_commit_cfg_reply( txn, MGMTD_INTERNAL_ERROR, - error_if_any ? error_if_any : - "Internal error! Failed to download config data to backend!"); + error_if_any + ? error_if_any + : "Internal error! Failed to download config data to backend!"); return 0; } - MGMTD_TXN_DBG( - "CFGDATA_CREATE_REQ sent to '%s' was successful txn-id: %" PRIu64 - " batch-id %" PRIu64 " err: %s", - adapter->name, txn->txn_id, cfg_btch->batch_id, - error_if_any ? error_if_any : "None"); - mgmt_move_txn_cfg_batch_to_next( - cmtcfg_req, cfg_btch, &cmtcfg_req->curr_batches[adapter->id], - &cmtcfg_req->next_batches[adapter->id], true, - MGMTD_COMMIT_PHASE_APPLY_CFG); + MGMTD_TXN_DBG("CFGDATA_CREATE_REQ sent to '%s' was successful txn-id: %" PRIu64 + " err: %s", adapter->name, txn->txn_id, + error_if_any ? error_if_any : "None"); + + cmtcfg_req->be_phase[adapter->id] = MGMTD_COMMIT_PHASE_APPLY_CFG; mgmt_try_move_commit_to_next_phase(txn, cmtcfg_req); @@ -2592,55 +2308,39 @@ int mgmt_txn_notify_be_cfgdata_reply( } int mgmt_txn_notify_be_cfg_apply_reply(uint64_t txn_id, bool success, - uint64_t batch_ids[], - size_t num_batch_ids, char *error_if_any, + char *error_if_any, struct mgmt_be_client_adapter *adapter) { struct mgmt_txn_ctx *txn; - struct mgmt_txn_be_cfg_batch *cfg_btch; struct mgmt_commit_cfg_req *cmtcfg_req = NULL; - size_t indx; txn = mgmt_txn_id2ctx(txn_id); - if (!txn || txn->type != MGMTD_TXN_TYPE_CONFIG - || !txn->commit_cfg_req) + if (!txn || txn->type != MGMTD_TXN_TYPE_CONFIG || !txn->commit_cfg_req) return -1; cmtcfg_req = &txn->commit_cfg_req->req.commit_cfg; if (!success) { - MGMTD_TXN_ERR( - "CFGDATA_APPLY_REQ sent to '%s' failed txn-id: %" PRIu64 - " batch ids %" PRIu64 " - %" PRIu64 " err: %s", - adapter->name, txn->txn_id, batch_ids[0], - batch_ids[num_batch_ids - 1], - error_if_any ? error_if_any : "None"); + MGMTD_TXN_ERR("CFGDATA_APPLY_REQ sent to '%s' failed txn-id: %" PRIu64 + " err: %s", + adapter->name, txn->txn_id, + error_if_any ? error_if_any : "None"); mgmt_txn_send_commit_cfg_reply( txn, MGMTD_INTERNAL_ERROR, - error_if_any ? error_if_any : - "Internal error! Failed to apply config data on backend!"); + error_if_any + ? error_if_any + : "Internal error! Failed to apply config data on backend!"); return 0; } - for (indx = 0; indx < num_batch_ids; indx++) { - cfg_btch = mgmt_txn_cfgbatch_id2ctx(txn, batch_ids[indx]); - if (cfg_btch->txn != txn) - return -1; - mgmt_move_txn_cfg_batch_to_next( - cmtcfg_req, cfg_btch, - &cmtcfg_req->curr_batches[adapter->id], - &cmtcfg_req->next_batches[adapter->id], true, - MGMTD_COMMIT_PHASE_TXN_DELETE); - } + cmtcfg_req->be_phase[adapter->id] = MGMTD_COMMIT_PHASE_TXN_DELETE; - if (!mgmt_txn_batches_count(&cmtcfg_req->curr_batches[adapter->id])) { - /* - * All configuration for the specific backend has been applied. - * Send TXN-DELETE to wrap up the transaction for this backend. - */ - SET_FLAG(adapter->flags, MGMTD_BE_ADAPTER_FLAGS_CFG_SYNCED); - mgmt_txn_send_be_txn_delete(txn, adapter); - } + /* + * All configuration for the specific backend has been applied. + * Send TXN-DELETE to wrap up the transaction for this backend. + */ + SET_FLAG(adapter->flags, MGMTD_BE_ADAPTER_FLAGS_CFG_SYNCED); + mgmt_txn_send_be_txn_delete(txn, adapter); mgmt_try_move_commit_to_next_phase(txn, cmtcfg_req); if (mm->perf_stats_en) @@ -2649,43 +2349,23 @@ int mgmt_txn_notify_be_cfg_apply_reply(uint64_t txn_id, bool success, return 0; } -int mgmt_txn_send_commit_config_reply(uint64_t txn_id, - enum mgmt_result result, - const char *error_if_any) -{ - struct mgmt_txn_ctx *txn; - - txn = mgmt_txn_id2ctx(txn_id); - if (!txn) - return -1; - - if (!txn->commit_cfg_req) { - MGMTD_TXN_ERR("NO commit in-progress txn-id: %" PRIu64 - " session-id: %" PRIu64, - txn->txn_id, txn->session_id); - return -1; - } - - return mgmt_txn_send_commit_cfg_reply(txn, result, error_if_any); -} - -int mgmt_txn_send_get_config_req(uint64_t txn_id, uint64_t req_id, - Mgmtd__DatastoreId ds_id, - struct mgmt_ds_ctx *ds_ctx, - Mgmtd__YangGetDataReq **data_req, - size_t num_reqs) +int mgmt_txn_send_get_req(uint64_t txn_id, uint64_t req_id, + Mgmtd__DatastoreId ds_id, struct nb_config *cfg_root, + Mgmtd__YangGetDataReq **data_req, size_t num_reqs) { struct mgmt_txn_ctx *txn; struct mgmt_txn_req *txn_req; + enum mgmt_txn_event req_event; size_t indx; txn = mgmt_txn_id2ctx(txn_id); if (!txn) return -1; - txn_req = mgmt_txn_req_alloc(txn, req_id, MGMTD_TXN_PROC_GETCFG); + req_event = MGMTD_TXN_PROC_GETCFG; + txn_req = mgmt_txn_req_alloc(txn, req_id, req_event); txn_req->req.get_data->ds_id = ds_id; - txn_req->req.get_data->ds_ctx = ds_ctx; + txn_req->req.get_data->cfg_root = cfg_root; for (indx = 0; indx < num_reqs && indx < MGMTD_MAX_NUM_DATA_REPLY_IN_BATCH; indx++) { @@ -2695,42 +2375,209 @@ int mgmt_txn_send_get_config_req(uint64_t txn_id, uint64_t req_id, txn_req->req.get_data->num_xpaths++; } - mgmt_txn_register_event(txn, MGMTD_TXN_PROC_GETCFG); + mgmt_txn_register_event(txn, req_event); return 0; } -int mgmt_txn_send_get_data_req(uint64_t txn_id, uint64_t req_id, - Mgmtd__DatastoreId ds_id, - struct mgmt_ds_ctx *ds_ctx, - Mgmtd__YangGetDataReq **data_req, - size_t num_reqs) + +/** + * Send get-tree requests to each client indicated in `clients` bitmask, which + * has registered operational state that matches the given `xpath` + */ +int mgmt_txn_send_get_tree_oper(uint64_t txn_id, uint64_t req_id, + uint64_t clients, LYD_FORMAT result_type, + bool simple_xpath, const char *xpath) { + struct mgmt_msg_get_tree *msg; struct mgmt_txn_ctx *txn; struct mgmt_txn_req *txn_req; - size_t indx; + struct txn_req_get_tree *get_tree; + enum mgmt_be_client_id id; + ssize_t slen = strlen(xpath); + int ret; txn = mgmt_txn_id2ctx(txn_id); if (!txn) return -1; - txn_req = mgmt_txn_req_alloc(txn, req_id, MGMTD_TXN_PROC_GETDATA); - txn_req->req.get_data->ds_id = ds_id; - txn_req->req.get_data->ds_ctx = ds_ctx; - for (indx = 0; - indx < num_reqs && indx < MGMTD_MAX_NUM_DATA_REPLY_IN_BATCH; - indx++) { - MGMTD_TXN_DBG("XPath: '%s'", data_req[indx]->data->xpath); - txn_req->req.get_data->xpaths[indx] = - strdup(data_req[indx]->data->xpath); - txn_req->req.get_data->num_xpaths++; + /* If error in this function below here, be sure to free the req */ + txn_req = mgmt_txn_req_alloc(txn, req_id, MGMTD_TXN_PROC_GETTREE); + get_tree = txn_req->req.get_tree; + get_tree->result_type = result_type; + get_tree->simple_xpath = simple_xpath; + get_tree->xpath = XSTRDUP(MTYPE_MGMTD_XPATH, xpath); + + msg = mgmt_msg_native_alloc_msg(struct mgmt_msg_get_tree, slen + 1, + MTYPE_MSG_NATIVE_GET_TREE); + msg->refer_id = txn_id; + msg->req_id = req_id; + msg->code = MGMT_MSG_CODE_GET_TREE; + /* Always operate with the binary format in the backend */ + msg->result_type = LYD_LYB; + strlcpy(msg->xpath, xpath, slen + 1); + + assert(clients); + FOREACH_BE_CLIENT_BITS (id, clients) { + ret = mgmt_be_send_native(id, msg); + if (ret) { + MGMTD_TXN_ERR("Could not send get-tree message to backend client %s", + mgmt_be_client_id2name(id)); + continue; + } + + MGMTD_TXN_DBG("Sent get-tree req to backend client %s", + mgmt_be_client_id2name(id)); + + /* record that we sent the request to the client */ + get_tree->sent_clients |= (1u << id); } - mgmt_txn_register_event(txn, MGMTD_TXN_PROC_GETDATA); + mgmt_msg_native_free_msg(msg); + /* Start timeout timer - pulled out of register event code so we can + * pass a different arg + */ + event_add_timer(mgmt_txn_tm, txn_get_tree_timeout, txn_req, + MGMTD_TXN_GET_TREE_MAX_DELAY_SEC, + &txn->get_tree_timeout); return 0; } +/* + * Error reply from the backend client. + */ +int mgmt_txn_notify_error(struct mgmt_be_client_adapter *adapter, + uint64_t txn_id, uint64_t req_id, int error, + const char *errstr) +{ + enum mgmt_be_client_id id = adapter->id; + struct mgmt_txn_ctx *txn = mgmt_txn_id2ctx(txn_id); + struct txn_req_get_tree *get_tree; + struct mgmt_txn_req *txn_req; + + if (!txn) { + MGMTD_TXN_ERR("Error reply from %s cannot find txn-id %" PRIu64, + adapter->name, txn_id); + return -1; + } + + /* Find the request. */ + FOREACH_TXN_REQ_IN_LIST (&txn->get_tree_reqs, txn_req) + if (txn_req->req_id == req_id) + break; + if (!txn_req) { + MGMTD_TXN_ERR("Error reply from %s for txn-id %" PRIu64 + " cannot find req_id %" PRIu64, + adapter->name, txn_id, req_id); + return -1; + } + + MGMTD_TXN_ERR("Error reply from %s for txn-id %" PRIu64 + " req_id %" PRIu64, + adapter->name, txn_id, req_id); + + switch (txn_req->req_event) { + case MGMTD_TXN_PROC_GETTREE: + get_tree = txn_req->req.get_tree; + get_tree->recv_clients |= (1u << id); + get_tree->partial_error = error; + + /* check if done yet */ + if (get_tree->recv_clients != get_tree->sent_clients) + return 0; + return txn_get_tree_data_done(txn, txn_req); + + /* non-native message events */ + case MGMTD_TXN_PROC_SETCFG: + case MGMTD_TXN_PROC_COMMITCFG: + case MGMTD_TXN_PROC_GETCFG: + case MGMTD_TXN_COMMITCFG_TIMEOUT: + case MGMTD_TXN_GETTREE_TIMEOUT: + case MGMTD_TXN_CLEANUP: + default: + assert(!"non-native req event in native erorr path"); + return -1; + } +} + +/* + * Get-tree data from the backend client. + */ +int mgmt_txn_notify_tree_data_reply(struct mgmt_be_client_adapter *adapter, + struct mgmt_msg_tree_data *data_msg, + size_t msg_len) +{ + uint64_t txn_id = data_msg->refer_id; + uint64_t req_id = data_msg->req_id; + + enum mgmt_be_client_id id = adapter->id; + struct mgmt_txn_ctx *txn = mgmt_txn_id2ctx(txn_id); + struct mgmt_txn_req *txn_req; + struct txn_req_get_tree *get_tree; + struct lyd_node *tree = NULL; + LY_ERR err; + + if (!txn) { + MGMTD_TXN_ERR("GETTREE reply from %s for a missing txn-id %" PRIu64, + adapter->name, txn_id); + return -1; + } + + /* Find the request. */ + FOREACH_TXN_REQ_IN_LIST (&txn->get_tree_reqs, txn_req) + if (txn_req->req_id == req_id) + break; + if (!txn_req) { + MGMTD_TXN_ERR("GETTREE reply from %s for txn-id %" PRIu64 + " missing req_id %" PRIu64, + adapter->name, txn_id, req_id); + return -1; + } + + get_tree = txn_req->req.get_tree; + + /* store the result */ + err = lyd_parse_data_mem(ly_native_ctx, (const char *)data_msg->result, + data_msg->result_type, + LYD_PARSE_STRICT | LYD_PARSE_ONLY, + 0 /*LYD_VALIDATE_OPERATIONAL*/, &tree); + if (err) { + MGMTD_TXN_ERR("GETTREE reply from %s for txn-id %" PRIu64 + " req_id %" PRIu64 + " error parsing result of type %u", + adapter->name, txn_id, req_id, + data_msg->result_type); + } + if (!err) { + /* TODO: we could merge ly_errs here if it's not binary */ + + if (!get_tree->client_results) + get_tree->client_results = tree; + else + err = lyd_merge_siblings(&get_tree->client_results, + tree, LYD_MERGE_DESTRUCT); + if (err) { + MGMTD_TXN_ERR("GETTREE reply from %s for txn-id %" PRIu64 + " req_id %" PRIu64 " error merging result", + adapter->name, txn_id, req_id); + } + } + if (!get_tree->partial_error) + get_tree->partial_error = (data_msg->partial_error + ? data_msg->partial_error + : (int)err); + + if (!data_msg->more) + get_tree->recv_clients |= (1u << id); + + /* check if done yet */ + if (get_tree->recv_clients != get_tree->sent_clients) + return 0; + + return txn_get_tree_data_done(txn, txn_req); +} + void mgmt_txn_status_write(struct vty *vty) { struct mgmt_txn_ctx *txn; @@ -2754,10 +2601,11 @@ int mgmt_txn_rollback_trigger_cfg_apply(struct mgmt_ds_ctx *src_ds_ctx, struct mgmt_ds_ctx *dst_ds_ctx) { static struct nb_config_cbs changes; + static struct mgmt_commit_stats dummy_stats; + struct nb_config_cbs *cfg_chgs = NULL; struct mgmt_txn_ctx *txn; struct mgmt_txn_req *txn_req; - static struct mgmt_commit_stats dummy_stats; memset(&changes, 0, sizeof(changes)); memset(&dummy_stats, 0, sizeof(dummy_stats)); diff --git a/mgmtd/mgmt_txn.h b/mgmtd/mgmt_txn.h index be781ab954..39d8cde169 100644 --- a/mgmtd/mgmt_txn.h +++ b/mgmtd/mgmt_txn.h @@ -9,23 +9,23 @@ #ifndef _FRR_MGMTD_TXN_H_ #define _FRR_MGMTD_TXN_H_ +#include "lib/mgmt_msg_native.h" #include "mgmtd/mgmt_be_adapter.h" #include "mgmtd/mgmt.h" #include "mgmtd/mgmt_ds.h" -#define MGMTD_TXN_PROC_DELAY_MSEC 5 #define MGMTD_TXN_PROC_DELAY_USEC 10 #define MGMTD_TXN_MAX_NUM_SETCFG_PROC 128 #define MGMTD_TXN_MAX_NUM_GETCFG_PROC 128 #define MGMTD_TXN_MAX_NUM_GETDATA_PROC 128 -#define MGMTD_TXN_SEND_CFGVALIDATE_DELAY_MSEC 100 -#define MGMTD_TXN_SEND_CFGAPPLY_DELAY_MSEC 100 -#define MGMTD_TXN_CFG_COMMIT_MAX_DELAY_MSEC 30000 /* 30 seconds */ +#define MGMTD_TXN_CFG_COMMIT_MAX_DELAY_SEC 600 +#define MGMTD_TXN_GET_TREE_MAX_DELAY_SEC 600 -#define MGMTD_TXN_CLEANUP_DELAY_MSEC 100 #define MGMTD_TXN_CLEANUP_DELAY_USEC 10 +#define MGMTD_TXN_ID_NONE 0 + /* * The following definition enables local validation of config * on the MGMTD process by loading client-defined NB callbacks @@ -78,6 +78,12 @@ extern void mgmt_txn_destroy(void); */ extern uint64_t mgmt_config_txn_in_progress(void); +/** + * Get the session ID associated with the given ``txn-id``. + * + */ +extern uint64_t mgmt_txn_get_session_id(uint64_t txn_id); + /* * Create transaction. * @@ -100,16 +106,6 @@ extern uint64_t mgmt_create_txn(uint64_t session_id, enum mgmt_txn_type type); */ extern void mgmt_destroy_txn(uint64_t *txn_id); -/* - * Check if transaction is valid given an ID. - */ -extern bool mgmt_txn_id_is_valid(uint64_t txn_id); - -/* - * Returns the type of transaction given an ID. - */ -extern enum mgmt_txn_type mgmt_get_txn_type(uint64_t txn_id); - /* * Send set-config request to be processed later in transaction. * @@ -179,38 +175,43 @@ extern int mgmt_txn_send_set_config_req(uint64_t txn_id, uint64_t req_id, * 0 on success, -1 on failures. */ extern int mgmt_txn_send_commit_config_req(uint64_t txn_id, uint64_t req_id, - Mgmtd__DatastoreId src_ds_id, - struct mgmt_ds_ctx *dst_ds_ctx, - Mgmtd__DatastoreId dst_ds_id, - struct mgmt_ds_ctx *src_ds_ctx, - bool validate_only, bool abort, - bool implicit); - -extern int mgmt_txn_send_commit_config_reply(uint64_t txn_id, - enum mgmt_result result, - const char *error_if_any); + Mgmtd__DatastoreId src_ds_id, + struct mgmt_ds_ctx *dst_ds_ctx, + Mgmtd__DatastoreId dst_ds_id, + struct mgmt_ds_ctx *src_ds_ctx, + bool validate_only, bool abort, + bool implicit); /* - * Send get-config request to be processed later in transaction. + * Send get-{cfg,data} request to be processed later in transaction. * - * Similar to set-config request. + * Is get-config if cfg_root is provided and the config is gathered locally, + * otherwise it's get-data and data is fetched from backedn clients. */ -extern int mgmt_txn_send_get_config_req(uint64_t txn_id, uint64_t req_id, - Mgmtd__DatastoreId ds_id, - struct mgmt_ds_ctx *ds_ctx, - Mgmtd__YangGetDataReq **data_req, - size_t num_reqs); +extern int mgmt_txn_send_get_req(uint64_t txn_id, uint64_t req_id, + Mgmtd__DatastoreId ds_id, + struct nb_config *cfg_root, + Mgmtd__YangGetDataReq **data_req, + size_t num_reqs); -/* - * Send get-data request to be processed later in transaction. + +/** + * Send get-tree to the backend `clients`. * - * Similar to get-config request, but here data is fetched from backedn client. + * Args: + * txn_id: Transaction identifier. + * req_id: FE client request identifier. + * clients: Bitmask of clients to send get-tree to. + * result_type: LYD_FORMAT result format. + * simple_xpath: true if xpath is simple (only key predicates). + * xpath: The xpath to get the tree from. + * + * Return: + * 0 on success. */ -extern int mgmt_txn_send_get_data_req(uint64_t txn_id, uint64_t req_id, - Mgmtd__DatastoreId ds_id, - struct mgmt_ds_ctx *ds_ctx, - Mgmtd__YangGetDataReq **data_req, - size_t num_reqs); +extern int mgmt_txn_send_get_tree_oper(uint64_t txn_id, uint64_t req_id, + uint64_t clients, LYD_FORMAT result_type, + bool simple_xpath, const char *xpath); /* * Notifiy backend adapter on connection. @@ -230,8 +231,8 @@ mgmt_txn_notify_be_txn_reply(uint64_t txn_id, bool create, bool success, * Reply to backend adapater with config data create request. */ extern int -mgmt_txn_notify_be_cfgdata_reply(uint64_t txn_id, uint64_t batch_id, - bool success, char *error_if_any, +mgmt_txn_notify_be_cfgdata_reply(uint64_t txn_id, bool success, + char *error_if_any, struct mgmt_be_client_adapter *adapter); /* @@ -247,10 +248,37 @@ extern int mgmt_txn_notify_be_cfg_validate_reply( */ extern int mgmt_txn_notify_be_cfg_apply_reply(uint64_t txn_id, bool success, - uint64_t batch_ids[], - size_t num_batch_ids, char *error_if_any, + char *error_if_any, struct mgmt_be_client_adapter *adapter); + +/** + * Process a reply from a backend client to our get-tree request + * + * Args: + * adapter: The adapter that received the result. + * txn_id: The transaction for this get-tree request. + * req_id: The request ID for this transaction. + * error: the integer error value (negative) + * errstr: the string description of the error. + */ +int mgmt_txn_notify_error(struct mgmt_be_client_adapter *adapter, + uint64_t txn_id, uint64_t req_id, int error, + const char *errstr); + +/** + * Process a reply from a backend client to our get-tree request + * + * Args: + * adapter: The adapter that received the result. + * data_msg: The message from the backend. + * msg_len: Total length of the message. + */ + +extern int mgmt_txn_notify_tree_data_reply(struct mgmt_be_client_adapter *adapter, + struct mgmt_msg_tree_data *data_msg, + size_t msg_len); + /* * Dump transaction status to vty. */ diff --git a/mgmtd/mgmt_vty.c b/mgmtd/mgmt_vty.c index 93c5145d71..2591930e4a 100644 --- a/mgmtd/mgmt_vty.c +++ b/mgmtd/mgmt_vty.c @@ -144,6 +144,23 @@ DEFPY(mgmt_commit, return CMD_SUCCESS; } +DEFPY(mgmt_create_config_data, mgmt_create_config_data_cmd, + "mgmt create-config WORD$path VALUE", + MGMTD_STR + "Create configuration data\n" + "XPath expression specifying the YANG data path\n" + "Value of the data to create\n") +{ + strlcpy(vty->cfg_changes[0].xpath, path, + sizeof(vty->cfg_changes[0].xpath)); + vty->cfg_changes[0].value = value; + vty->cfg_changes[0].operation = NB_OP_CREATE_EXCL; + vty->num_cfg_changes = 1; + + vty_mgmt_send_config_data(vty, NULL, false); + return CMD_SUCCESS; +} + DEFPY(mgmt_set_config_data, mgmt_set_config_data_cmd, "mgmt set-config WORD$path VALUE", MGMTD_STR @@ -154,12 +171,10 @@ DEFPY(mgmt_set_config_data, mgmt_set_config_data_cmd, strlcpy(vty->cfg_changes[0].xpath, path, sizeof(vty->cfg_changes[0].xpath)); vty->cfg_changes[0].value = value; - vty->cfg_changes[0].operation = NB_OP_CREATE; + vty->cfg_changes[0].operation = NB_OP_MODIFY; vty->num_cfg_changes = 1; - vty->no_implicit_commit = true; - vty_mgmt_send_config_data(vty); - vty->no_implicit_commit = false; + vty_mgmt_send_config_data(vty, NULL, false); return CMD_SUCCESS; } @@ -170,15 +185,48 @@ DEFPY(mgmt_delete_config_data, mgmt_delete_config_data_cmd, "XPath expression specifying the YANG data path\n") { + strlcpy(vty->cfg_changes[0].xpath, path, + sizeof(vty->cfg_changes[0].xpath)); + vty->cfg_changes[0].value = NULL; + vty->cfg_changes[0].operation = NB_OP_DELETE; + vty->num_cfg_changes = 1; + + vty_mgmt_send_config_data(vty, NULL, false); + return CMD_SUCCESS; +} + +DEFPY(mgmt_remove_config_data, mgmt_remove_config_data_cmd, + "mgmt remove-config WORD$path", + MGMTD_STR + "Remove configuration data\n" + "XPath expression specifying the YANG data path\n") +{ + strlcpy(vty->cfg_changes[0].xpath, path, sizeof(vty->cfg_changes[0].xpath)); vty->cfg_changes[0].value = NULL; vty->cfg_changes[0].operation = NB_OP_DESTROY; vty->num_cfg_changes = 1; - vty->no_implicit_commit = true; - vty_mgmt_send_config_data(vty); - vty->no_implicit_commit = false; + vty_mgmt_send_config_data(vty, NULL, false); + return CMD_SUCCESS; +} + +DEFPY(mgmt_replace_config_data, mgmt_replace_config_data_cmd, + "mgmt replace-config WORD$path VALUE", + MGMTD_STR + "Replace configuration data\n" + "XPath expression specifying the YANG data path\n" + "Value of the data to set\n") +{ + + strlcpy(vty->cfg_changes[0].xpath, path, + sizeof(vty->cfg_changes[0].xpath)); + vty->cfg_changes[0].value = value; + vty->cfg_changes[0].operation = NB_OP_REPLACE; + vty->num_cfg_changes = 1; + + vty_mgmt_send_config_data(vty, NULL, false); return CMD_SUCCESS; } @@ -198,27 +246,37 @@ DEFPY(show_mgmt_get_config, show_mgmt_get_config_cmd, datastore = mgmt_ds_name2id(dsname); xpath_list[0] = path; - vty_mgmt_send_get_config(vty, datastore, xpath_list, 1); + vty_mgmt_send_get_req(vty, true, datastore, xpath_list, 1); return CMD_SUCCESS; } DEFPY(show_mgmt_get_data, show_mgmt_get_data_cmd, - "show mgmt get-data [candidate|operational|running]$dsname WORD$path", - SHOW_STR MGMTD_STR - "Get data from a specific datastore\n" - "Candidate datastore\n" - "Operational datastore (default)\n" - "Running datastore\n" - "XPath expression specifying the YANG data path\n") + "show mgmt get-data WORD$path [json|xml]$fmt", + SHOW_STR + MGMTD_STR + "Get a data from the operational datastore\n" + "XPath expression specifying the YANG data root\n" + "JSON output format\n" + "XML output format\n") { - const char *xpath_list[VTY_MAXCFGCHANGES] = {0}; - Mgmtd__DatastoreId datastore = MGMTD_DS_OPERATIONAL; + LYD_FORMAT format = (fmt && fmt[0] == 'x') ? LYD_XML : LYD_JSON; + int plen = strlen(path); + char *xpath = NULL; + + /* get rid of extraneous trailing slash-* or single '/' unless root */ + if (plen > 2 && ((path[plen - 2] == '/' && path[plen - 1] == '*') || + (path[plen - 2] != '/' && path[plen - 1] == '/'))) { + plen = path[plen - 1] == '/' ? plen - 1 : plen - 2; + xpath = XSTRDUP(MTYPE_TMP, path); + xpath[plen] = 0; + path = xpath; + } - if (dsname) - datastore = mgmt_ds_name2id(dsname); + vty_mgmt_send_get_tree_req(vty, format, path); + + if (xpath) + XFREE(MTYPE_TMP, xpath); - xpath_list[0] = path; - vty_mgmt_send_get_data(vty, datastore, xpath_list, 1); return CMD_SUCCESS; } @@ -243,7 +301,7 @@ DEFPY(show_mgmt_dump_data, LYD_FORMAT format = fmt[0] == 'j' ? LYD_JSON : LYD_XML; FILE *f = NULL; - if (datastore) + if (dsname) datastore = mgmt_ds_name2id(dsname); ds_ctx = mgmt_ds_get_ctx_by_id(mm, datastore); @@ -277,7 +335,7 @@ DEFPY(show_mgmt_map_xpath, "Get YANG Backend Subscription\n" "XPath expression specifying the YANG data path\n") { - mgmt_be_xpath_subscr_info_write(vty, path); + mgmt_be_show_xpath_registries(vty, path); return CMD_SUCCESS; } @@ -383,7 +441,7 @@ DEFPY(mgmt_rollback, int config_write_mgmt_debug(struct vty *vty); static struct cmd_node debug_node = { - .name = "debug", + .name = "mgmt debug", .node = DEBUG_NODE, .prompt = "", .config_write = config_write_mgmt_debug, @@ -442,12 +500,18 @@ DEFPY(debug_mgmt, debug_mgmt_cmd, { uint32_t mode = DEBUG_NODE2MODE(vty->node); - if (be) + if (be) { DEBUG_MODE_SET(&mgmt_debug_be, mode, !no); + mgmt_be_adapter_toggle_client_debug( + DEBUG_MODE_CHECK(&mgmt_debug_be, DEBUG_MODE_ALL)); + } if (ds) DEBUG_MODE_SET(&mgmt_debug_ds, mode, !no); - if (fe) + if (fe) { DEBUG_MODE_SET(&mgmt_debug_fe, mode, !no); + mgmt_fe_adapter_toggle_client_debug( + DEBUG_MODE_CHECK(&mgmt_debug_fe, DEBUG_MODE_ALL)); + } if (txn) DEBUG_MODE_SET(&mgmt_debug_txn, mode, !no); @@ -456,9 +520,34 @@ DEFPY(debug_mgmt, debug_mgmt_cmd, static void mgmt_config_read_in(struct event *event) { - mgmt_vty_read_configs(); + if (vty_mgmt_fe_enabled()) + mgmt_vty_read_configs(); + else { + zlog_warn("%s: no connection to front-end server, retry in 1s", + __func__); + event_add_timer(mm->master, mgmt_config_read_in, NULL, 1, + &mgmt_daemon_info->read_in); + } } +static int mgmtd_config_write(struct vty *vty) +{ + struct lyd_node *root; + + LY_LIST_FOR (running_config->dnode, root) { + nb_cli_show_dnode_cmds(vty, root, false); + } + + return 1; +} + +static struct cmd_node mgmtd_node = { + .name = "mgmtd", + .node = MGMTD_NODE, + .prompt = "", + .config_write = mgmtd_config_write, +}; + void mgmt_vty_init(void) { /* @@ -476,6 +565,7 @@ void mgmt_vty_init(void) &mgmt_daemon_info->read_in); install_node(&debug_node); + install_node(&mgmtd_node); install_element(VIEW_NODE, &show_mgmt_be_adapter_cmd); install_element(VIEW_NODE, &show_mgmt_be_xpath_reg_cmd); @@ -489,8 +579,11 @@ void mgmt_vty_init(void) install_element(VIEW_NODE, &show_mgmt_cmt_hist_cmd); install_element(CONFIG_NODE, &mgmt_commit_cmd); + install_element(CONFIG_NODE, &mgmt_create_config_data_cmd); install_element(CONFIG_NODE, &mgmt_set_config_data_cmd); install_element(CONFIG_NODE, &mgmt_delete_config_data_cmd); + install_element(CONFIG_NODE, &mgmt_remove_config_data_cmd); + install_element(CONFIG_NODE, &mgmt_replace_config_data_cmd); install_element(CONFIG_NODE, &mgmt_load_config_cmd); install_element(CONFIG_NODE, &mgmt_save_config_cmd); install_element(CONFIG_NODE, &mgmt_rollback_cmd); diff --git a/mgmtd/subdir.am b/mgmtd/subdir.am index 67b45d5bd9..89a6596f49 100644 --- a/mgmtd/subdir.am +++ b/mgmtd/subdir.am @@ -33,11 +33,6 @@ mgmtd_libmgmtd_a_SOURCES = \ mgmtd/mgmt_vty.c \ # end -mgmtdheaderdir = $(pkgincludedir)/mgmtd -mgmtdheader_HEADERS = \ - mgmtd/mgmt_defines.h \ - # end - noinst_HEADERS += \ mgmtd/mgmt.h \ mgmtd/mgmt_be_adapter.h \ diff --git a/nhrpd/linux.c b/nhrpd/linux.c index eb98166872..b25df9ff2f 100644 --- a/nhrpd/linux.c +++ b/nhrpd/linux.c @@ -5,8 +5,10 @@ #include "zebra.h" +#include <fcntl.h> #include <errno.h> #include <linux/if_packet.h> +#include <sys/ioctl.h> #include "nhrp_protocol.h" #include "os.h" diff --git a/nhrpd/netlink_arp.c b/nhrpd/netlink_arp.c index 2e22f8e247..bcecf9fc09 100644 --- a/nhrpd/netlink_arp.c +++ b/nhrpd/netlink_arp.c @@ -7,6 +7,10 @@ #include "config.h" #endif +#ifdef GNU_LINUX +#include <linux/rtnetlink.h> +#endif + #include <fcntl.h> #include <net/if.h> #include <netinet/if_ether.h> diff --git a/nhrpd/nhrp_cache.c b/nhrpd/nhrp_cache.c index 1a11e0d98b..e0b8f7bf88 100644 --- a/nhrpd/nhrp_cache.c +++ b/nhrpd/nhrp_cache.c @@ -70,6 +70,8 @@ static void nhrp_cache_free(struct nhrp_cache *c) notifier_call(&c->notifier_list, NOTIFY_CACHE_DELETE); assert(!notifier_active(&c->notifier_list)); hash_release(nifp->cache_hash, c); + if (c->cur.peer) + nhrp_peer_notify_del(c->cur.peer, &c->peer_notifier); nhrp_peer_unref(c->cur.peer); nhrp_peer_unref(c->new.peer); EVENT_OFF(c->t_timeout); diff --git a/nhrpd/nhrp_interface.c b/nhrpd/nhrp_interface.c index 7c84fde367..b82743f001 100644 --- a/nhrpd/nhrp_interface.c +++ b/nhrpd/nhrp_interface.c @@ -259,13 +259,12 @@ static void nhrp_interface_update_address(struct interface *ifp, afi_t afi, struct nhrp_afi_data *if_ad = &nifp->afi[afi]; struct nhrp_cache *nc; struct connected *c, *best; - struct listnode *cnode; union sockunion addr; char buf[PREFIX_STRLEN]; /* Select new best match preferring primary address */ best = NULL; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) { + frr_each (if_connected, ifp->connected, c) { if (PREFIX_FAMILY(c->address) != family) continue; if (best == NULL) { diff --git a/nhrpd/nhrp_main.c b/nhrpd/nhrp_main.c index 593498ca13..983a03282b 100644 --- a/nhrpd/nhrp_main.c +++ b/nhrpd/nhrp_main.c @@ -88,10 +88,12 @@ static void nhrp_request_stop(void) nhrp_zebra_terminate(); vici_terminate(); evmgr_terminate(); - nhrp_vc_terminate(); vrf_terminate(); + nhrp_vc_terminate(); debugf(NHRP_DEBUG_COMMON, "Done."); + + resolver_terminate(); frr_fini(); exit(0); @@ -155,8 +157,10 @@ int main(int argc, char **argv) nhrp_vc_init(); nhrp_packet_init(); vici_init(); - if_zapi_callbacks(nhrp_ifp_create, nhrp_ifp_up, - nhrp_ifp_down, nhrp_ifp_destroy); + hook_register_prio(if_real, 0, nhrp_ifp_create); + hook_register_prio(if_up, 0, nhrp_ifp_up); + hook_register_prio(if_down, 0, nhrp_ifp_down); + hook_register_prio(if_unreal, 0, nhrp_ifp_destroy); nhrp_zebra_init(); nhrp_shortcut_init(); diff --git a/nhrpd/nhrp_multicast.c b/nhrpd/nhrp_multicast.c index fdc1a31f25..aead982842 100644 --- a/nhrpd/nhrp_multicast.c +++ b/nhrpd/nhrp_multicast.c @@ -7,6 +7,10 @@ #include "config.h" #endif +#ifdef GNU_LINUX +#include <linux/rtnetlink.h> +#endif + #include <fcntl.h> #include <net/if.h> #include <net/ethernet.h> diff --git a/nhrpd/nhrp_packet.c b/nhrpd/nhrp_packet.c index 9d0b30cfee..c6bd3bbbde 100644 --- a/nhrpd/nhrp_packet.c +++ b/nhrpd/nhrp_packet.c @@ -270,7 +270,7 @@ int nhrp_ext_reply(struct zbuf *zb, struct nhrp_packet_header *hdr, default: if (type & NHRP_EXTENSION_FLAG_COMPULSORY) goto err; - /* fallthru */ + fallthrough; case NHRP_EXTENSION_FORWARD_TRANSIT_NHS: case NHRP_EXTENSION_REVERSE_TRANSIT_NHS: /* Supported compulsory extensions, and any diff --git a/nhrpd/nhrp_peer.c b/nhrpd/nhrp_peer.c index ffb6cf7506..6e7857c777 100644 --- a/nhrpd/nhrp_peer.c +++ b/nhrpd/nhrp_peer.c @@ -45,7 +45,8 @@ static void nhrp_peer_check_delete(struct nhrp_peer *p) EVENT_OFF(p->t_fallback); EVENT_OFF(p->t_timer); - hash_release(nifp->peer_hash, p); + if (nifp->peer_hash) + hash_release(nifp->peer_hash, p); nhrp_interface_notify_del(p->ifp, &p->ifp_notifier); nhrp_vc_notify_del(p->vc, &p->vc_notifier); XFREE(MTYPE_NHRP_PEER, p); @@ -139,7 +140,7 @@ static void nhrp_peer_ifp_notify(struct notifier_block *n, unsigned long cmd) nhrp_peer_vc_notify); __nhrp_peer_check(p); } - /* fallthru */ /* to post config update */ + fallthrough; /* to post config update */ case NOTIFY_INTERFACE_ADDRESS_CHANGED: notifier_call(&p->notifier_list, NOTIFY_PEER_IFCONFIG_CHANGED); break; @@ -1050,7 +1051,7 @@ static void nhrp_peer_forward(struct nhrp_peer *p, * append our selves to the transit NHS list */ goto err; - /* fallthru */ + fallthrough; case NHRP_EXTENSION_RESPONDER_ADDRESS: /* Supported compulsory extensions, and any * non-compulsory that is not explicitly handled, @@ -1220,7 +1221,7 @@ void nhrp_peer_recv(struct nhrp_peer *p, struct zbuf *zb) /* FIXME: send error-indication */ } } - /* fallthru */ /* FIXME: double check, is this correct? */ + fallthrough; /* FIXME: double check, is this correct? */ case NHRP_ROUTE_OFF_NBMA: if (packet_types[hdr->type].handler) { packet_types[hdr->type].handler(&pp); diff --git a/nhrpd/nhrp_route.c b/nhrpd/nhrp_route.c index bf7ba5f650..060e60314d 100644 --- a/nhrpd/nhrp_route.c +++ b/nhrpd/nhrp_route.c @@ -108,11 +108,10 @@ void nhrp_route_update_nhrp(const struct prefix *p, struct interface *ifp) void nhrp_route_announce(int add, enum nhrp_cache_type type, const struct prefix *p, struct interface *ifp, - const union sockunion *nexthop, uint32_t mtu) + const union sockunion *nexthop_ref, uint32_t mtu) { struct zapi_route api; struct zapi_nexthop *api_nh; - union sockunion *nexthop_ref = (union sockunion *)nexthop; if (zclient->sock < 0) return; @@ -125,9 +124,10 @@ void nhrp_route_announce(int add, enum nhrp_cache_type type, switch (type) { case NHRP_CACHE_NEGATIVE: + /* Fill in a blackhole nexthop */ zapi_route_set_blackhole(&api, BLACKHOLE_REJECT); ifp = NULL; - nexthop = NULL; + nexthop_ref = NULL; break; case NHRP_CACHE_DYNAMIC: case NHRP_CACHE_NHS: diff --git a/nhrpd/nhrp_vc.c b/nhrpd/nhrp_vc.c index 2c3201438b..6f3346c95c 100644 --- a/nhrpd/nhrp_vc.c +++ b/nhrpd/nhrp_vc.c @@ -214,4 +214,5 @@ void nhrp_vc_terminate(void) { nhrp_vc_reset(); hash_clean(nhrp_vc_hash, nhrp_vc_free); + hash_free(nhrp_vc_hash); } diff --git a/nhrpd/vici.c b/nhrpd/vici.c index 2f76362603..8162ac06a6 100644 --- a/nhrpd/vici.c +++ b/nhrpd/vici.c @@ -10,6 +10,7 @@ #include <string.h> #include <sys/socket.h> #include <sys/un.h> +#include <fcntl.h> #include "frrevent.h" #include "zbuf.h" diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c index 713dd82075..d1c2b8bfc9 100644 --- a/ospf6d/ospf6_asbr.c +++ b/ospf6d/ospf6_asbr.c @@ -481,7 +481,7 @@ void ospf6_asbr_update_route_ecmp_path(struct ospf6_route *old, static int ospf6_ase_forward_address_check(struct ospf6 *ospf6, struct in6_addr *fwd_addr) { - struct listnode *anode, *node, *cnode; + struct listnode *anode, *node; struct ospf6_interface *oi; struct ospf6_area *oa; struct interface *ifp; @@ -494,7 +494,7 @@ static int ospf6_ase_forward_address_check(struct ospf6 *ospf6, continue; ifp = oi->interface; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) { + frr_each (if_connected, ifp->connected, c) { if (IPV6_ADDR_SAME(&c->address->u.prefix6, fwd_addr)) return 0; @@ -1376,6 +1376,55 @@ ospf6_external_aggr_match(struct ospf6 *ospf6, struct prefix *p) return node->info; } +static void ospf6_external_lsa_fwd_addr_set(struct ospf6 *ospf6, + const struct in6_addr *nexthop, + struct in6_addr *fwd_addr) +{ + struct vrf *vrf; + struct interface *ifp; + struct prefix nh; + + /* Initialize forwarding address to zero. */ + memset(fwd_addr, 0, sizeof(*fwd_addr)); + + vrf = vrf_lookup_by_id(ospf6->vrf_id); + if (!vrf) + return; + + nh.family = AF_INET6; + nh.u.prefix6 = *nexthop; + nh.prefixlen = IPV6_MAX_BITLEN; + + /* + * Use the route's nexthop as the forwarding address if it meets the + * following conditions: + * - It's a global address. + * - The associated nexthop interface is OSPF-enabled. + */ + if (IN6_IS_ADDR_UNSPECIFIED(nexthop) || IN6_IS_ADDR_LINKLOCAL(nexthop)) + return; + + FOR_ALL_INTERFACES (vrf, ifp) { + struct ospf6_interface *oi = ifp->info; + struct connected *connected; + + if (!oi || CHECK_FLAG(oi->flag, OSPF6_INTERFACE_DISABLE)) + continue; + + frr_each (if_connected, ifp->connected, connected) { + if (connected->address->family != AF_INET6) + continue; + if (IN6_IS_ADDR_LINKLOCAL(&connected->address->u.prefix6)) + continue; + if (!prefix_match(connected->address, &nh)) + continue; + + *fwd_addr = *nexthop; + return; + } + } +} + void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex, struct prefix *prefix, unsigned int nexthop_num, @@ -1470,10 +1519,8 @@ void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex, if (nexthop_num && nexthop) { ospf6_route_add_nexthop(match, ifindex, nexthop); - if (!IN6_IS_ADDR_UNSPECIFIED(nexthop) - && !IN6_IS_ADDR_LINKLOCAL(nexthop)) - memcpy(&info->forwarding, nexthop, - sizeof(struct in6_addr)); + ospf6_external_lsa_fwd_addr_set(ospf6, nexthop, + &info->forwarding); } else ospf6_route_add_nexthop(match, ifindex, NULL); @@ -1520,10 +1567,8 @@ void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex, info->type = type; if (nexthop_num && nexthop) { ospf6_route_add_nexthop(route, ifindex, nexthop); - if (!IN6_IS_ADDR_UNSPECIFIED(nexthop) - && !IN6_IS_ADDR_LINKLOCAL(nexthop)) - memcpy(&info->forwarding, nexthop, - sizeof(struct in6_addr)); + ospf6_external_lsa_fwd_addr_set(ospf6, nexthop, + &info->forwarding); } else ospf6_route_add_nexthop(route, ifindex, NULL); diff --git a/ospf6d/ospf6_auth_trailer.c b/ospf6d/ospf6_auth_trailer.c index 68817b5d08..54b951654a 100644 --- a/ospf6d/ospf6_auth_trailer.c +++ b/ospf6d/ospf6_auth_trailer.c @@ -4,6 +4,13 @@ */ #include "zebra.h" +#include <sys/stat.h> + +#ifdef CRYPTO_OPENSSL +#include <openssl/evp.h> +#include <openssl/hmac.h> +#endif + #include "config.h" #include "memory.h" #include "ospf6d.h" @@ -604,20 +611,19 @@ void ospf6_auth_digest_send(struct in6_addr *src, struct ospf6_interface *oi, else return; - ospf6->seqnum_l++; if (ospf6->seqnum_l == 0xFFFFFFFF) { - ospf6->seqnum_h++; - ospf6->seqnum_l = 0; + if (ospf6->seqnum_h == 0xFFFFFFFF) { + /* Key must be reset, which is not handled as of now. */ + zlog_err("Sequence number wrapped; key must be reset."); + ospf6->seqnum_h = 0; + } else { + ospf6->seqnum_h++; + } ospf6_auth_seqno_nvm_update(ospf6); - } - /* Key must be reset. which is not handled as of now. */ - if ((ospf6->seqnum_l == 0xFFFFFFFF) - && (ospf6->seqnum_h == 0xFFFFFFFF)) { ospf6->seqnum_l = 0; - ospf6->seqnum_h = 0; - zlog_err( - "Both Higher and Lower sequence number has wrapped. Need to reset the key"); + } else { + ospf6->seqnum_l++; } memset(apad, 0, sizeof(apad)); @@ -665,7 +671,7 @@ void ospf6_auth_update_digest(struct ospf6_interface *oi, struct ospf6_auth_hdr *ospf6_auth, char *auth_str, uint32_t pkt_len, enum keychain_hash_algo algo) { - static const uint16_t cpid = 1; + const uint16_t cpid = htons(OSPFV3_CRYPTO_PROTO_ID); uint32_t hash_len = keychain_get_hash_len(algo); uint32_t block_s = keychain_get_block_size(algo); uint32_t k_len = strlen(auth_str); diff --git a/ospf6d/ospf6_auth_trailer.h b/ospf6d/ospf6_auth_trailer.h index 924b89503f..3f82a7b197 100644 --- a/ospf6d/ospf6_auth_trailer.h +++ b/ospf6d/ospf6_auth_trailer.h @@ -15,6 +15,8 @@ #define OSPF6_AUTHENTICATION_NULL 0 #define OSPF6_AUTHENTICATION_CRYPTOGRAPHIC 1 +#define OSPFV3_CRYPTO_PROTO_ID 1 + /* Auth debug options */ extern unsigned char conf_debug_ospf6_auth[2]; diff --git a/ospf6d/ospf6_flood.c b/ospf6d/ospf6_flood.c index a81d5222d6..98d3bbc519 100644 --- a/ospf6d/ospf6_flood.c +++ b/ospf6d/ospf6_flood.c @@ -389,7 +389,7 @@ void ospf6_flood_interface(struct ospf6_neighbor *from, struct ospf6_lsa *lsa, if (req == on->last_ls_req) { /* sanity check refcount */ assert(req->lock >= 2); - req = ospf6_lsa_unlock(req); + ospf6_lsa_unlock(&req); on->last_ls_req = NULL; } if (req) @@ -406,7 +406,7 @@ void ospf6_flood_interface(struct ospf6_neighbor *from, struct ospf6_lsa *lsa, zlog_debug( "Received is newer, remove requesting"); if (req == on->last_ls_req) { - req = ospf6_lsa_unlock(req); + ospf6_lsa_unlock(&req); on->last_ls_req = NULL; } if (req) @@ -1045,6 +1045,7 @@ void ospf6_receive_lsa(struct ospf6_neighbor *from, zlog_debug( "%s, GraceLSA doesn't exist in lsdb, so discarding GraceLSA", __func__); + ospf6_lsa_delete(new); return; } } else { diff --git a/ospf6d/ospf6_gr.c b/ospf6d/ospf6_gr.c index ecaaa038ab..69230e572b 100644 --- a/ospf6d/ospf6_gr.c +++ b/ospf6d/ospf6_gr.c @@ -293,8 +293,10 @@ static int ospf6_router_lsa_contains_adj(struct ospf6_area *area, if (lsdesc->type != OSPF6_ROUTER_LSDESC_POINTTOPOINT) continue; - if (lsdesc->neighbor_router_id == neighbor_router_id) + if (lsdesc->neighbor_router_id == neighbor_router_id) { + ospf6_lsa_unlock(&lsa); return RTR_LSA_ADJ_FOUND; + } } } @@ -511,8 +513,10 @@ static bool ospf6_gr_check_adjs(struct ospf6 *ospf6) for (ALL_LSDB_TYPED_ADVRTR(area->lsdb, type, router, lsa_self)) { found = true; - if (!ospf6_gr_check_adjs_lsa(area, lsa_self)) + if (!ospf6_gr_check_adjs_lsa(area, lsa_self)) { + ospf6_lsa_unlock(&lsa_self); return false; + } } if (!found) return false; diff --git a/ospf6d/ospf6_gr_helper.c b/ospf6d/ospf6_gr_helper.c index 216d78c1cc..be1042f260 100644 --- a/ospf6d/ospf6_gr_helper.c +++ b/ospf6d/ospf6_gr_helper.c @@ -134,7 +134,7 @@ static int ospf6_extract_grace_lsa_fields(struct ospf6_lsa *lsa, uint16_t length = 0; int sum = 0; - lsah = (struct ospf6_lsa_header *)lsa->header; + lsah = lsa->header; if (ntohs(lsah->length) <= OSPF6_LSA_HEADER_SIZE) { if (IS_DEBUG_OSPF6_GR) zlog_debug("%s: undersized (%u B) lsa", __func__, @@ -228,9 +228,9 @@ static bool ospf6_check_chg_in_rxmt_list(struct ospf6_neighbor *nbr) lsa->header->adv_router, lsa->lsdb); if (lsa_in_db && lsa_in_db->tobe_acknowledged) { - ospf6_lsa_unlock(lsa); + ospf6_lsa_unlock(&lsa); if (lsanext) - ospf6_lsa_unlock(lsanext); + ospf6_lsa_unlock(&lsanext); return OSPF6_TRUE; } @@ -1231,7 +1231,7 @@ static int ospf6_grace_lsa_show_info(struct vty *vty, struct ospf6_lsa *lsa, uint16_t length = 0; int sum = 0; - lsah = (struct ospf6_lsa_header *)lsa->header; + lsah = lsa->header; if (ntohs(lsah->length) <= OSPF6_LSA_HEADER_SIZE) { if (IS_DEBUG_OSPF6_GR) zlog_debug("%s: undersized (%u B) lsa", __func__, diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c index ea059c4be6..652d502c8e 100644 --- a/ospf6d/ospf6_interface.c +++ b/ospf6d/ospf6_interface.c @@ -49,8 +49,9 @@ DEFINE_HOOK(ospf6_interface_change, unsigned char conf_debug_ospf6_interface = 0; const char *const ospf6_interface_state_str[] = { - "None", "Down", "Loopback", "Waiting", "PointToPoint", - "DROther", "BDR", "DR", NULL}; + "None", "Down", "Loopback", "Waiting", "PointToPoint", + "PtMultipoint", "DROther", "BDR", "DR", NULL +}; int ospf6_interface_neighbor_count(struct ospf6_interface *oi) { @@ -83,8 +84,7 @@ struct ospf6_interface *ospf6_interface_lookup_by_ifindex(ifindex_t ifindex, } /* schedule routing table recalculation */ -static void ospf6_interface_lsdb_hook(struct ospf6_lsa *lsa, - unsigned int reason) +static void ospf6_interface_lsdb_hook(struct ospf6_lsa *lsa, unsigned int reason) { struct ospf6_interface *oi; @@ -131,6 +131,7 @@ static uint32_t ospf6_interface_get_cost(struct ospf6_interface *oi) uint32_t cost; uint32_t bw, refbw; struct ospf6 *ospf6; + /* interface speed and bw can be 0 in some platforms, * use ospf default bw. If bw is configured then it would * be used. @@ -152,6 +153,15 @@ static uint32_t ospf6_interface_get_cost(struct ospf6_interface *oi) cost = (uint32_t)((double)refbw / (double)bw + (double)0.5); if (cost < 1) cost = 1; + + /* If the interface type is point-to-multipoint or the interface + * is in the state Loopback, the global scope IPv6 addresses + * associated with the interface (if any) are copied into the + * intra-area-prefix-LSA with the PrefixOptions LA-bit set, the + * PrefixLength set to 128, and the metric set to 0. + */ + if (if_is_loopback(oi->interface)) + cost = 0; } return cost; @@ -217,9 +227,8 @@ struct ospf6_interface *ospf6_interface_create(struct interface *ifp) iobuflen = ospf6_iobuf_size(ifp->mtu6); if (oi->ifmtu > iobuflen) { if (IS_OSPF6_DEBUG_INTERFACE) - zlog_debug( - "Interface %s: IfMtu is adjusted to I/O buffer size: %d.", - ifp->name, iobuflen); + zlog_debug("Interface %s: IfMtu is adjusted to I/O buffer size: %d.", + ifp->name, iobuflen); oi->ifmtu = iobuflen; } @@ -232,8 +241,8 @@ struct ospf6_interface *ospf6_interface_create(struct interface *ifp) oi->lsdb->hook_remove = ospf6_interface_lsdb_hook_remove; oi->lsdb_self = ospf6_lsdb_create(oi); - oi->route_connected = - OSPF6_ROUTE_TABLE_CREATE(INTERFACE, CONNECTED_ROUTES); + oi->route_connected = OSPF6_ROUTE_TABLE_CREATE(INTERFACE, + CONNECTED_ROUTES); oi->route_connected->scope = oi; /* link both */ @@ -309,7 +318,7 @@ void ospf6_interface_disable(struct ospf6_interface *oi) { SET_FLAG(oi->flag, OSPF6_INTERFACE_DISABLE); - event_execute(master, interface_down, oi, 0); + event_execute(master, interface_down, oi, 0, NULL); ospf6_lsdb_remove_all(oi->lsdb); ospf6_lsdb_remove_all(oi->lsdb_self); @@ -334,12 +343,11 @@ void ospf6_interface_disable(struct ospf6_interface *oi) static struct in6_addr * ospf6_interface_get_linklocal_address(struct interface *ifp) { - struct listnode *n; struct connected *c; struct in6_addr *l = (struct in6_addr *)NULL; /* for each connected address */ - for (ALL_LIST_ELEMENTS_RO(ifp->connected, n, c)) { + frr_each (if_connected, ifp->connected, c) { /* if family not AF_INET6, ignore */ if (c->address->family != AF_INET6) continue; @@ -370,26 +378,24 @@ void ospf6_interface_state_update(struct interface *ifp) iobuflen = ospf6_iobuf_size(ifp->mtu6); if (oi->ifmtu > iobuflen) { if (IS_OSPF6_DEBUG_INTERFACE) - zlog_debug( - "Interface %s: IfMtu is adjusted to I/O buffer size: %d.", - ifp->name, iobuflen); + zlog_debug("Interface %s: IfMtu is adjusted to I/O buffer size: %d.", + ifp->name, iobuflen); oi->ifmtu = iobuflen; } } else if (oi->c_ifmtu > ifp->mtu6) { oi->ifmtu = ifp->mtu6; - zlog_warn( - "Configured mtu %u on %s overridden by kernel %u", - oi->c_ifmtu, ifp->name, ifp->mtu6); + zlog_warn("Configured mtu %u on %s overridden by kernel %u", + oi->c_ifmtu, ifp->name, ifp->mtu6); } else oi->ifmtu = oi->c_ifmtu; } - if (if_is_operative(ifp) - && (ospf6_interface_get_linklocal_address(oi->interface) - || if_is_loopback(oi->interface))) - event_execute(master, interface_up, oi, 0); + if (if_is_operative(ifp) && + (ospf6_interface_get_linklocal_address(oi->interface) || + if_is_loopback(oi->interface))) + event_execute(master, interface_up, oi, 0, NULL); else - event_execute(master, interface_down, oi, 0); + event_execute(master, interface_down, oi, 0, NULL); return; } @@ -397,9 +403,7 @@ void ospf6_interface_state_update(struct interface *ifp) void ospf6_interface_connected_route_update(struct interface *ifp) { struct ospf6_interface *oi; - struct ospf6_route *route; struct connected *c; - struct listnode *node, *nnode; struct in6_addr nh_addr; oi = (struct ospf6_interface *)ifp->info; @@ -419,7 +423,7 @@ void ospf6_interface_connected_route_update(struct interface *ifp) /* update "route to advertise" interface route table */ ospf6_route_remove_all(oi->route_connected); - for (ALL_LIST_ELEMENTS(oi->interface->connected, node, nnode, c)) { + frr_each (if_connected, ifp->connected, c) { if (c->address->family != AF_INET6) continue; @@ -443,14 +447,43 @@ void ospf6_interface_connected_route_update(struct interface *ifp) ret = prefix_list_apply(plist, (void *)c->address); if (ret == PREFIX_DENY) { if (IS_OSPF6_DEBUG_INTERFACE) - zlog_debug( - "%pFX on %s filtered by prefix-list %s ", - c->address, oi->interface->name, - oi->plist_name); + zlog_debug("%pFX on %s filtered by prefix-list %s ", + c->address, + oi->interface->name, + oi->plist_name); continue; } } + if (oi->state == OSPF6_INTERFACE_LOOPBACK || + oi->state == OSPF6_INTERFACE_POINTTOMULTIPOINT || + oi->state == OSPF6_INTERFACE_POINTTOPOINT) { + struct ospf6_route *la_route; + + la_route = ospf6_route_create(oi->area->ospf6); + la_route->prefix = *c->address; + la_route->prefix.prefixlen = 128; + la_route->prefix_options |= OSPF6_PREFIX_OPTION_LA; + + la_route->type = OSPF6_DEST_TYPE_NETWORK; + la_route->path.area_id = oi->area->area_id; + la_route->path.type = OSPF6_PATH_TYPE_INTRA; + la_route->path.cost = 0; + inet_pton(AF_INET6, "::1", &nh_addr); + ospf6_route_add_nexthop(la_route, oi->interface->ifindex, + &nh_addr); + ospf6_route_add(la_route, oi->route_connected); + } + + if (oi->state == OSPF6_INTERFACE_POINTTOMULTIPOINT && + !oi->p2xp_connected_pfx_include) + continue; + if (oi->state == OSPF6_INTERFACE_POINTTOPOINT && + oi->p2xp_connected_pfx_exclude) + continue; + + struct ospf6_route *route; + route = ospf6_route_create(oi->area->ospf6); memcpy(&route->prefix, c->address, sizeof(struct prefix)); apply_mask(&route->prefix); @@ -459,8 +492,7 @@ void ospf6_interface_connected_route_update(struct interface *ifp) route->path.type = OSPF6_PATH_TYPE_INTRA; route->path.cost = oi->cost; inet_pton(AF_INET6, "::1", &nh_addr); - ospf6_route_add_nexthop(route, oi->interface->ifindex, - &nh_addr); + ospf6_route_add_nexthop(route, oi->interface->ifindex, &nh_addr); ospf6_route_add(route, oi->route_connected); } @@ -496,17 +528,17 @@ static int ospf6_interface_state_change(uint8_t next_state, ospf6 = oi->area->ospf6; - if ((prev_state == OSPF6_INTERFACE_DR - || prev_state == OSPF6_INTERFACE_BDR) - && (next_state != OSPF6_INTERFACE_DR - && next_state != OSPF6_INTERFACE_BDR)) + if ((prev_state == OSPF6_INTERFACE_DR || + prev_state == OSPF6_INTERFACE_BDR) && + (next_state != OSPF6_INTERFACE_DR && + next_state != OSPF6_INTERFACE_BDR)) ospf6_sso(oi->interface->ifindex, &alldrouters6, IPV6_LEAVE_GROUP, ospf6->fd); - if ((prev_state != OSPF6_INTERFACE_DR - && prev_state != OSPF6_INTERFACE_BDR) - && (next_state == OSPF6_INTERFACE_DR - || next_state == OSPF6_INTERFACE_BDR)) + if ((prev_state != OSPF6_INTERFACE_DR && + prev_state != OSPF6_INTERFACE_BDR) && + (next_state == OSPF6_INTERFACE_DR || + next_state == OSPF6_INTERFACE_BDR)) ospf6_sso(oi->interface->ifindex, &alldrouters6, IPV6_JOIN_GROUP, ospf6->fd); @@ -516,14 +548,17 @@ static int ospf6_interface_state_change(uint8_t next_state, OSPF6_NETWORK_LSA_EXECUTE(oi); OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT(oi); OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi->area); - OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT(oi); - } else if (prev_state == OSPF6_INTERFACE_DR - || next_state == OSPF6_INTERFACE_DR) { + } else if (prev_state == OSPF6_INTERFACE_DR || + next_state == OSPF6_INTERFACE_DR) { OSPF6_NETWORK_LSA_SCHEDULE(oi); OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi); OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi->area); } + if (next_state == OSPF6_INTERFACE_POINTTOPOINT || + next_state == OSPF6_INTERFACE_POINTTOMULTIPOINT) + ospf6_if_p2xp_up(oi); + hook_call(ospf6_interface_change, oi, next_state, prev_state); return 0; @@ -538,8 +573,8 @@ static int ospf6_interface_state_change(uint8_t next_state, static struct ospf6_neighbor *better_bdrouter(struct ospf6_neighbor *a, struct ospf6_neighbor *b) { - if ((a == NULL || !IS_ELIGIBLE(a) || a->drouter == a->router_id) - && (b == NULL || !IS_ELIGIBLE(b) || b->drouter == b->router_id)) + if ((a == NULL || !IS_ELIGIBLE(a) || a->drouter == a->router_id) && + (b == NULL || !IS_ELIGIBLE(b) || b->drouter == b->router_id)) return NULL; else if (a == NULL || !IS_ELIGIBLE(a) || a->drouter == a->router_id) return b; @@ -568,8 +603,8 @@ static struct ospf6_neighbor *better_bdrouter(struct ospf6_neighbor *a, static struct ospf6_neighbor *better_drouter(struct ospf6_neighbor *a, struct ospf6_neighbor *b) { - if ((a == NULL || !IS_ELIGIBLE(a) || a->drouter != a->router_id) - && (b == NULL || !IS_ELIGIBLE(b) || b->drouter != b->router_id)) + if ((a == NULL || !IS_ELIGIBLE(a) || a->drouter != a->router_id) && + (b == NULL || !IS_ELIGIBLE(b) || b->drouter != b->router_id)) return NULL; else if (a == NULL || !IS_ELIGIBLE(a) || a->drouter != a->router_id) return b; @@ -632,10 +667,10 @@ uint8_t dr_election(struct ospf6_interface *oi) drouter = bdrouter; /* the router itself is newly/no longer DR/BDR (4) */ - if ((drouter == &myself && myself.drouter != myself.router_id) - || (drouter != &myself && myself.drouter == myself.router_id) - || (bdrouter == &myself && myself.bdrouter != myself.router_id) - || (bdrouter != &myself && myself.bdrouter == myself.router_id)) { + if ((drouter == &myself && myself.drouter != myself.router_id) || + (drouter != &myself && myself.drouter == myself.router_id) || + (bdrouter == &myself && myself.bdrouter != myself.router_id) || + (bdrouter != &myself && myself.bdrouter == myself.router_id)) { myself.drouter = (drouter ? drouter->router_id : htonl(0)); myself.bdrouter = (bdrouter ? bdrouter->router_id : htonl(0)); @@ -709,8 +744,8 @@ static bool ifmaddr_check(ifindex_t ifindex, struct in6_addr *addr) continue; sdl = (struct sockaddr_dl *)ifma->ifma_name; sin6 = (struct sockaddr_in6 *)ifma->ifma_addr; - if (sdl->sdl_index == ifindex - && memcmp(&sin6->sin6_addr, addr, IPV6_MAX_BYTELEN) == 0) { + if (sdl->sdl_index == ifindex && + memcmp(&sin6->sin6_addr, addr, IPV6_MAX_BYTELEN) == 0) { found = true; break; } @@ -750,11 +785,10 @@ void interface_up(struct event *thread) } /* check interface has a link-local address */ - if (!(ospf6_interface_get_linklocal_address(oi->interface) - || if_is_loopback(oi->interface))) { - zlog_warn( - "Interface %s has no link local address, can't execute [InterfaceUp]", - oi->interface->name); + if (!(ospf6_interface_get_linklocal_address(oi->interface) || + if_is_loopback(oi->interface))) { + zlog_warn("Interface %s has no link local address, can't execute [InterfaceUp]", + oi->interface->name); return; } @@ -771,9 +805,8 @@ void interface_up(struct event *thread) /* If no area assigned, return */ if (oi->area == NULL) { - zlog_warn( - "%s: Not scheduling Hello for %s as there is no area assigned yet", - __func__, oi->interface->name); + zlog_warn("%s: Not scheduling Hello for %s as there is no area assigned yet", + __func__, oi->interface->name); return; } @@ -798,9 +831,8 @@ void interface_up(struct event *thread) * the interface actually left the group. */ if (ifmaddr_check(oi->interface->ifindex, &allspfrouters6)) { - zlog_info( - "Interface %s is still in all routers group, rescheduling for SSO", - oi->interface->name); + zlog_info("Interface %s is still in all routers group, rescheduling for SSO", + oi->interface->name); event_add_timer(master, interface_up, oi, OSPF6_INTERFACE_SSO_RETRY_INT, &oi->thread_sso); return; @@ -811,12 +843,10 @@ void interface_up(struct event *thread) /* Join AllSPFRouters */ if (ospf6_sso(oi->interface->ifindex, &allspfrouters6, IPV6_JOIN_GROUP, - ospf6->fd) - < 0) { + ospf6->fd) < 0) { if (oi->sso_try_cnt++ < OSPF6_INTERFACE_SSO_RETRY_MAX) { - zlog_info( - "Scheduling %s for sso retry, trial count: %d", - oi->interface->name, oi->sso_try_cnt); + zlog_info("Scheduling %s for sso retry, trial count: %d", + oi->interface->name, oi->sso_try_cnt); event_add_timer(master, interface_up, oi, OSPF6_INTERFACE_SSO_RETRY_INT, &oi->thread_sso); @@ -829,8 +859,8 @@ void interface_up(struct event *thread) ospf6_interface_connected_route_update(oi->interface); /* Schedule Hello */ - if (!CHECK_FLAG(oi->flag, OSPF6_INTERFACE_PASSIVE) - && !if_is_loopback(oi->interface)) { + if (!CHECK_FLAG(oi->flag, OSPF6_INTERFACE_PASSIVE) && + !if_is_loopback(oi->interface)) { event_add_timer(master, ospf6_hello_send, oi, 0, &oi->thread_send_hello); } @@ -840,6 +870,9 @@ void interface_up(struct event *thread) ospf6_interface_state_change(OSPF6_INTERFACE_LOOPBACK, oi); } else if (oi->type == OSPF_IFTYPE_POINTOPOINT) { ospf6_interface_state_change(OSPF6_INTERFACE_POINTTOPOINT, oi); + } else if (oi->type == OSPF_IFTYPE_POINTOMULTIPOINT) { + ospf6_interface_state_change(OSPF6_INTERFACE_POINTTOMULTIPOINT, + oi); } else if (oi->priority == 0) ospf6_interface_state_change(OSPF6_INTERFACE_DROTHER, oi); else { @@ -890,9 +923,8 @@ void neighbor_change(struct event *thread) zlog_debug("Interface Event %s: [NeighborChange]", oi->interface->name); - if (oi->state == OSPF6_INTERFACE_DROTHER - || oi->state == OSPF6_INTERFACE_BDR - || oi->state == OSPF6_INTERFACE_DR) + if (oi->state == OSPF6_INTERFACE_DROTHER || + oi->state == OSPF6_INTERFACE_BDR || oi->state == OSPF6_INTERFACE_DR) ospf6_interface_state_change(dr_election(oi), oi); } @@ -968,6 +1000,8 @@ static const char *ospf6_iftype_str(uint8_t iftype) return "BROADCAST"; case OSPF_IFTYPE_POINTOPOINT: return "POINTOPOINT"; + case OSPF_IFTYPE_POINTOMULTIPOINT: + return "POINTOMULTIPOINT"; } return "UNKNOWN"; } @@ -979,7 +1013,6 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp, struct ospf6_interface *oi; struct connected *c; struct prefix *p; - struct listnode *i; char strbuf[PREFIX2STR_BUFFER], drouter[32], bdrouter[32]; uint8_t default_iftype; struct timeval res, now; @@ -1026,7 +1059,7 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp, if (use_json) { json_arr = json_object_new_array(); - for (ALL_LIST_ELEMENTS_RO(ifp->connected, i, c)) { + frr_each (if_connected, ifp->connected, c) { json_addr = json_object_new_object(); p = c->address; prefix2str(p, strbuf, sizeof(strbuf)); @@ -1058,7 +1091,7 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp, } else { vty_out(vty, " Internet Address:\n"); - for (ALL_LIST_ELEMENTS_RO(ifp->connected, i, c)) { + frr_each (if_connected, ifp->connected, c) { p = c->address; prefix2str(p, strbuf, sizeof(strbuf)); switch (p->family) { @@ -1077,12 +1110,10 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp, if (use_json) { if (oi->area) { - json_object_boolean_true_add(json_obj, - "attachedToArea"); + json_object_boolean_true_add(json_obj, "attachedToArea"); json_object_int_add(json_obj, "instanceId", oi->instance_id); - json_object_int_add(json_obj, "interfaceMtu", - oi->ifmtu); + json_object_int_add(json_obj, "interfaceMtu", oi->ifmtu); json_object_int_add(json_obj, "autoDetect", ifp->mtu6); json_object_string_add(json_obj, "mtuMismatchDetection", oi->mtu_ignore ? "disabled" @@ -1122,9 +1153,9 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp, oi->dead_interval); json_object_int_add(json_obj, "timerIntervalsConfigRetransmit", oi->rxmt_interval); - json_object_boolean_add( - json_obj, "timerPassiveIface", - !!CHECK_FLAG(oi->flag, OSPF6_INTERFACE_PASSIVE)); + json_object_boolean_add(json_obj, "timerPassiveIface", + !!CHECK_FLAG(oi->flag, + OSPF6_INTERFACE_PASSIVE)); } else { vty_out(vty, " State %s, Transmit Delay %d sec, Priority %d\n", ospf6_interface_state_str[oi->state], oi->transdelay, @@ -1157,24 +1188,23 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp, if (use_json) { timerclear(&res); if (event_is_scheduled(oi->thread_send_lsupdate)) - timersub(&oi->thread_send_lsupdate->u.sands, &now, - &res); + timersub(&oi->thread_send_lsupdate->u.sands, &now, &res); timerstring(&res, duration, sizeof(duration)); json_object_int_add(json_obj, "pendingLsaLsUpdateCount", oi->lsupdate_list->count); json_object_string_add(json_obj, "pendingLsaLsUpdateTime", duration); - json_object_string_add( - json_obj, "lsUpdateSendThread", - (event_is_scheduled(oi->thread_send_lsupdate) ? "on" - : "off")); + json_object_string_add(json_obj, "lsUpdateSendThread", + (event_is_scheduled( + oi->thread_send_lsupdate) + ? "on" + : "off")); json_arr = json_object_new_array(); for (ALL_LSDB(oi->lsupdate_list, lsa, lsanext)) - json_object_array_add( - json_arr, json_object_new_string(lsa->name)); - json_object_object_add(json_obj, "pendingLsaLsUpdate", - json_arr); + json_object_array_add(json_arr, + json_object_new_string(lsa->name)); + json_object_object_add(json_obj, "pendingLsaLsUpdate", json_arr); timerclear(&res); if (event_is_scheduled(oi->thread_send_lsack)) @@ -1185,15 +1215,15 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp, oi->lsack_list->count); json_object_string_add(json_obj, "pendingLsaLsAckTime", duration); - json_object_string_add( - json_obj, "lsAckSendThread", - (event_is_scheduled(oi->thread_send_lsack) ? "on" - : "off")); + json_object_string_add(json_obj, "lsAckSendThread", + (event_is_scheduled(oi->thread_send_lsack) + ? "on" + : "off")); json_arr = json_object_new_array(); for (ALL_LSDB(oi->lsack_list, lsa, lsanext)) - json_object_array_add( - json_arr, json_object_new_string(lsa->name)); + json_object_array_add(json_arr, + json_object_new_string(lsa->name)); json_object_object_add(json_obj, "pendingLsaLsAck", json_arr); if (oi->gr.hello_delay.interval != 0) @@ -1202,8 +1232,7 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp, } else { timerclear(&res); if (event_is_scheduled(oi->thread_send_lsupdate)) - timersub(&oi->thread_send_lsupdate->u.sands, &now, - &res); + timersub(&oi->thread_send_lsupdate->u.sands, &now, &res); timerstring(&res, duration, sizeof(duration)); vty_out(vty, " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n", @@ -1235,9 +1264,8 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp, if (use_json) { struct json_object *json_bfd = json_object_new_object(); - json_object_int_add( - json_bfd, "detectMultiplier", - oi->bfd_config.detection_multiplier); + json_object_int_add(json_bfd, "detectMultiplier", + oi->bfd_config.detection_multiplier); json_object_int_add(json_bfd, "rxMinInterval", oi->bfd_config.min_rx); json_object_int_add(json_bfd, "txMinInterval", @@ -1260,8 +1288,7 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp, OSPF6_AUTH_TRAILER_KEYCHAIN)) { json_object_string_add(json_auth, "authType", "keychain"); - json_object_string_add(json_auth, - "keychainName", + json_object_string_add(json_auth, "keychainName", oi->at_data.keychain); } else if (CHECK_FLAG(oi->at_data.flags, OSPF6_AUTH_TRAILER_MANUAL_KEY)) @@ -1301,11 +1328,10 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp, /* Find the global address to be used as a forwarding address in NSSA LSA.*/ struct in6_addr *ospf6_interface_get_global_address(struct interface *ifp) { - struct listnode *n; struct connected *c; /* for each connected address */ - for (ALL_LIST_ELEMENTS_RO(ifp->connected, n, c)) { + frr_each (if_connected, ifp->connected, c) { /* if family not AF_INET6, ignore */ if (c->address->family != AF_INET6) continue; @@ -1323,7 +1349,6 @@ static int show_ospf6_interface_common(struct vty *vty, vrf_id_t vrf_id, int idx_ifname, int intf_idx, int json_idx, bool uj) { - struct vrf *vrf = vrf_lookup_by_id(vrf_id); struct interface *ifp; json_object *json; @@ -1453,18 +1478,15 @@ static int ospf6_interface_show_traffic(struct vty *vty, json_object_int_add(json_interface, "lsReqTx", oi->ls_req_out); json_object_int_add(json_interface, - "lsUpdateRx", - oi->ls_upd_in); - json_object_int_add(json_interface, - "lsUpdateTx", + "lsUpdateRx", oi->ls_upd_in); + json_object_int_add(json_interface, "lsUpdateTx", oi->ls_upd_out); json_object_int_add(json_interface, "lsAckRx", oi->ls_ack_in); json_object_int_add(json_interface, "lsAckTx", oi->ls_ack_out); - json_object_object_add(json, - oi->interface->name, + json_object_object_add(json, oi->interface->name, json_interface); } else vty_out(vty, @@ -1650,8 +1672,8 @@ DEFUN(show_ipv6_ospf6_interface_ifname_prefix, } oi = ifp->info; - if (oi == NULL - || CHECK_FLAG(oi->flag, OSPF6_INTERFACE_DISABLE)) { + if (oi == NULL || + CHECK_FLAG(oi->flag, OSPF6_INTERFACE_DISABLE)) { vty_out(vty, "Interface %s not attached to area\n", argv[idx_ifname]->arg); @@ -1678,8 +1700,7 @@ DEFUN(show_ipv6_ospf6_interface_prefix, show_ipv6_ospf6_interface_prefix_cmd, |<X:X::X:X|X:X::X:X/M> [<match|detail>]\ >] [json]", SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR - "All VRFs\n" INTERFACE_STR - "Display connected prefixes to advertise\n" + "All VRFs\n" INTERFACE_STR "Display connected prefixes to advertise\n" "Display details of the prefixes\n" OSPF6_ROUTE_ADDRESS_STR OSPF6_ROUTE_PREFIX_STR OSPF6_ROUTE_MATCH_STR "Display details of the prefixes\n" JSON_STR) @@ -1704,9 +1725,9 @@ DEFUN(show_ipv6_ospf6_interface_prefix, show_ipv6_ospf6_interface_prefix_cmd, vrf = vrf_lookup_by_id(ospf6->vrf_id); FOR_ALL_INTERFACES (vrf, ifp) { oi = (struct ospf6_interface *)ifp->info; - if (oi == NULL - || CHECK_FLAG(oi->flag, - OSPF6_INTERFACE_DISABLE)) + if (oi == NULL || + CHECK_FLAG(oi->flag, + OSPF6_INTERFACE_DISABLE)) continue; ospf6_route_table_show(vty, idx_prefix, argc, @@ -1781,14 +1802,11 @@ void ospf6_interface_stop(struct ospf6_interface *oi) } /* interface variable set command */ -DEFUN (ipv6_ospf6_area, - ipv6_ospf6_area_cmd, - "ipv6 ospf6 area <A.B.C.D|(0-4294967295)>", - IP6_STR - OSPF6_STR - "Specify the OSPF6 area ID\n" - "OSPF6 area ID in IPv4 address notation\n" - "OSPF6 area ID in decimal notation\n") +DEFUN(ipv6_ospf6_area, ipv6_ospf6_area_cmd, + "ipv6 ospf6 area <A.B.C.D|(0-4294967295)>", + IP6_STR OSPF6_STR "Specify the OSPF6 area ID\n" + "OSPF6 area ID in IPv4 address notation\n" + "OSPF6 area ID in decimal notation\n") { VTY_DECLVAR_CONTEXT(interface, ifp); struct ospf6_interface *oi; @@ -1822,15 +1840,11 @@ DEFUN (ipv6_ospf6_area, return CMD_SUCCESS; } -DEFUN (no_ipv6_ospf6_area, - no_ipv6_ospf6_area_cmd, - "no ipv6 ospf6 area [<A.B.C.D|(0-4294967295)>]", - NO_STR - IP6_STR - OSPF6_STR - "Specify the OSPF6 area ID\n" - "OSPF6 area ID in IPv4 address notation\n" - "OSPF6 area ID in decimal notation\n") +DEFUN(no_ipv6_ospf6_area, no_ipv6_ospf6_area_cmd, + "no ipv6 ospf6 area [<A.B.C.D|(0-4294967295)>]", + NO_STR IP6_STR OSPF6_STR "Specify the OSPF6 area ID\n" + "OSPF6 area ID in IPv4 address notation\n" + "OSPF6 area ID in decimal notation\n") { VTY_DECLVAR_CONTEXT(interface, ifp); struct ospf6_interface *oi; @@ -1850,14 +1864,9 @@ DEFUN (no_ipv6_ospf6_area, return CMD_SUCCESS; } -DEFUN (ipv6_ospf6_ifmtu, - ipv6_ospf6_ifmtu_cmd, - "ipv6 ospf6 ifmtu (1-65535)", - IP6_STR - OSPF6_STR - "Interface MTU\n" - "OSPFv3 Interface MTU\n" - ) +DEFUN(ipv6_ospf6_ifmtu, ipv6_ospf6_ifmtu_cmd, "ipv6 ospf6 ifmtu (1-65535)", + IP6_STR OSPF6_STR "Interface MTU\n" + "OSPFv3 Interface MTU\n") { VTY_DECLVAR_CONTEXT(interface, ifp); int idx_number = 3; @@ -1906,15 +1915,10 @@ DEFUN (ipv6_ospf6_ifmtu, return CMD_SUCCESS; } -DEFUN (no_ipv6_ospf6_ifmtu, - no_ipv6_ospf6_ifmtu_cmd, - "no ipv6 ospf6 ifmtu [(1-65535)]", - NO_STR - IP6_STR - OSPF6_STR - "Interface MTU\n" - "OSPFv3 Interface MTU\n" - ) +DEFUN(no_ipv6_ospf6_ifmtu, no_ipv6_ospf6_ifmtu_cmd, + "no ipv6 ospf6 ifmtu [(1-65535)]", + NO_STR IP6_STR OSPF6_STR "Interface MTU\n" + "OSPFv3 Interface MTU\n") { VTY_DECLVAR_CONTEXT(interface, ifp); struct ospf6_interface *oi; @@ -1952,13 +1956,9 @@ DEFUN (no_ipv6_ospf6_ifmtu, return CMD_SUCCESS; } -DEFUN (ipv6_ospf6_cost, - ipv6_ospf6_cost_cmd, - "ipv6 ospf6 cost (1-65535)", - IP6_STR - OSPF6_STR - "Interface cost\n" - "Outgoing metric of this interface\n") +DEFUN(ipv6_ospf6_cost, ipv6_ospf6_cost_cmd, "ipv6 ospf6 cost (1-65535)", + IP6_STR OSPF6_STR "Interface cost\n" + "Outgoing metric of this interface\n") { VTY_DECLVAR_CONTEXT(interface, ifp); int idx_number = 3; @@ -1989,14 +1989,10 @@ DEFUN (ipv6_ospf6_cost, return CMD_SUCCESS; } -DEFUN (no_ipv6_ospf6_cost, - no_ipv6_ospf6_cost_cmd, - "no ipv6 ospf6 cost [(1-65535)]", - NO_STR - IP6_STR - OSPF6_STR - "Calculate interface cost from bandwidth\n" - "Outgoing metric of this interface\n") +DEFUN(no_ipv6_ospf6_cost, no_ipv6_ospf6_cost_cmd, + "no ipv6 ospf6 cost [(1-65535)]", + NO_STR IP6_STR OSPF6_STR "Calculate interface cost from bandwidth\n" + "Outgoing metric of this interface\n") { VTY_DECLVAR_CONTEXT(interface, ifp); struct ospf6_interface *oi; @@ -2014,12 +2010,11 @@ DEFUN (no_ipv6_ospf6_cost, return CMD_SUCCESS; } -DEFUN (auto_cost_reference_bandwidth, - auto_cost_reference_bandwidth_cmd, - "auto-cost reference-bandwidth (1-4294967)", - "Calculate OSPF interface cost according to bandwidth\n" - "Use reference bandwidth method to assign OSPF cost\n" - "The reference bandwidth in terms of Mbits per second\n") +DEFUN(auto_cost_reference_bandwidth, auto_cost_reference_bandwidth_cmd, + "auto-cost reference-bandwidth (1-4294967)", + "Calculate OSPF interface cost according to bandwidth\n" + "Use reference bandwidth method to assign OSPF cost\n" + "The reference bandwidth in terms of Mbits per second\n") { VTY_DECLVAR_CONTEXT(ospf6, o); int idx_number = 2; @@ -2046,13 +2041,11 @@ DEFUN (auto_cost_reference_bandwidth, return CMD_SUCCESS; } -DEFUN (no_auto_cost_reference_bandwidth, - no_auto_cost_reference_bandwidth_cmd, - "no auto-cost reference-bandwidth [(1-4294967)]", - NO_STR - "Calculate OSPF interface cost according to bandwidth\n" - "Use reference bandwidth method to assign OSPF cost\n" - "The reference bandwidth in terms of Mbits per second\n") +DEFUN(no_auto_cost_reference_bandwidth, no_auto_cost_reference_bandwidth_cmd, + "no auto-cost reference-bandwidth [(1-4294967)]", + NO_STR "Calculate OSPF interface cost according to bandwidth\n" + "Use reference bandwidth method to assign OSPF cost\n" + "The reference bandwidth in terms of Mbits per second\n") { VTY_DECLVAR_CONTEXT(ospf6, o); struct ospf6_area *oa; @@ -2071,11 +2064,10 @@ DEFUN (no_auto_cost_reference_bandwidth, } -DEFUN (ospf6_write_multiplier, - ospf6_write_multiplier_cmd, - "write-multiplier (1-100)", - "Write multiplier\n" - "Maximum number of interface serviced per write\n") +DEFUN(ospf6_write_multiplier, ospf6_write_multiplier_cmd, + "write-multiplier (1-100)", + "Write multiplier\n" + "Maximum number of interface serviced per write\n") { VTY_DECLVAR_CONTEXT(ospf6, o); uint32_t write_oi_count; @@ -2090,12 +2082,10 @@ DEFUN (ospf6_write_multiplier, return CMD_SUCCESS; } -DEFUN (no_ospf6_write_multiplier, - no_ospf6_write_multiplier_cmd, - "no write-multiplier (1-100)", - NO_STR - "Write multiplier\n" - "Maximum number of interface serviced per write\n") +DEFUN(no_ospf6_write_multiplier, no_ospf6_write_multiplier_cmd, + "no write-multiplier (1-100)", + NO_STR "Write multiplier\n" + "Maximum number of interface serviced per write\n") { VTY_DECLVAR_CONTEXT(ospf6, o); @@ -2103,13 +2093,9 @@ DEFUN (no_ospf6_write_multiplier, return CMD_SUCCESS; } -DEFUN (ipv6_ospf6_hellointerval, - ipv6_ospf6_hellointerval_cmd, - "ipv6 ospf6 hello-interval (1-65535)", - IP6_STR - OSPF6_STR - "Time between HELLO packets\n" - SECONDS_STR) +DEFUN(ipv6_ospf6_hellointerval, ipv6_ospf6_hellointerval_cmd, + "ipv6 ospf6 hello-interval (1-65535)", + IP6_STR OSPF6_STR "Time between HELLO packets\n" SECONDS_STR) { VTY_DECLVAR_CONTEXT(interface, ifp); int idx_number = 3; @@ -2137,23 +2123,15 @@ DEFUN (ipv6_ospf6_hellointerval, return CMD_SUCCESS; } -ALIAS (ipv6_ospf6_hellointerval, - no_ipv6_ospf6_hellointerval_cmd, - "no ipv6 ospf6 hello-interval [(1-65535)]", - NO_STR - IP6_STR - OSPF6_STR - "Time between HELLO packets\n" - SECONDS_STR) +ALIAS(ipv6_ospf6_hellointerval, no_ipv6_ospf6_hellointerval_cmd, + "no ipv6 ospf6 hello-interval [(1-65535)]", + NO_STR IP6_STR OSPF6_STR "Time between HELLO packets\n" SECONDS_STR) /* interface variable set command */ -DEFUN (ipv6_ospf6_deadinterval, - ipv6_ospf6_deadinterval_cmd, - "ipv6 ospf6 dead-interval (1-65535)", - IP6_STR - OSPF6_STR - "Interval time after which a neighbor is declared down\n" - SECONDS_STR) +DEFUN(ipv6_ospf6_deadinterval, ipv6_ospf6_deadinterval_cmd, + "ipv6 ospf6 dead-interval (1-65535)", + IP6_STR OSPF6_STR + "Interval time after which a neighbor is declared down\n" SECONDS_STR) { VTY_DECLVAR_CONTEXT(interface, ifp); int idx_number = 3; @@ -2171,22 +2149,16 @@ DEFUN (ipv6_ospf6_deadinterval, return CMD_SUCCESS; } -ALIAS (ipv6_ospf6_deadinterval, - no_ipv6_ospf6_deadinterval_cmd, - "no ipv6 ospf6 dead-interval [(1-65535)]", - NO_STR - IP6_STR - OSPF6_STR - "Interval time after which a neighbor is declared down\n" - SECONDS_STR) +ALIAS(ipv6_ospf6_deadinterval, no_ipv6_ospf6_deadinterval_cmd, + "no ipv6 ospf6 dead-interval [(1-65535)]", + NO_STR IP6_STR OSPF6_STR + "Interval time after which a neighbor is declared down\n" SECONDS_STR) DEFPY(ipv6_ospf6_gr_hdelay, ipv6_ospf6_gr_hdelay_cmd, "ipv6 ospf6 graceful-restart hello-delay (1-1800)", - IP6_STR - OSPF6_STR - "Graceful Restart parameters\n" - "Delay the sending of the first hello packets.\n" - "Delay in seconds\n") + IP6_STR OSPF6_STR "Graceful Restart parameters\n" + "Delay the sending of the first hello packets.\n" + "Delay in seconds\n") { VTY_DECLVAR_CONTEXT(interface, ifp); struct ospf6_interface *oi; @@ -2203,12 +2175,9 @@ DEFPY(ipv6_ospf6_gr_hdelay, ipv6_ospf6_gr_hdelay_cmd, DEFPY(no_ipv6_ospf6_gr_hdelay, no_ipv6_ospf6_gr_hdelay_cmd, "no ipv6 ospf6 graceful-restart hello-delay [(1-1800)]", - NO_STR - IP6_STR - OSPF6_STR - "Graceful Restart parameters\n" - "Delay the sending of the first hello packets.\n" - "Delay in seconds\n") + NO_STR IP6_STR OSPF6_STR "Graceful Restart parameters\n" + "Delay the sending of the first hello packets.\n" + "Delay in seconds\n") { VTY_DECLVAR_CONTEXT(interface, ifp); struct ospf6_interface *oi; @@ -2225,13 +2194,9 @@ DEFPY(no_ipv6_ospf6_gr_hdelay, no_ipv6_ospf6_gr_hdelay_cmd, } /* interface variable set command */ -DEFUN (ipv6_ospf6_transmitdelay, - ipv6_ospf6_transmitdelay_cmd, - "ipv6 ospf6 transmit-delay (1-3600)", - IP6_STR - OSPF6_STR - "Link state transmit delay\n" - SECONDS_STR) +DEFUN(ipv6_ospf6_transmitdelay, ipv6_ospf6_transmitdelay_cmd, + "ipv6 ospf6 transmit-delay (1-3600)", + IP6_STR OSPF6_STR "Link state transmit delay\n" SECONDS_STR) { VTY_DECLVAR_CONTEXT(interface, ifp); int idx_number = 3; @@ -2249,23 +2214,15 @@ DEFUN (ipv6_ospf6_transmitdelay, return CMD_SUCCESS; } -ALIAS (ipv6_ospf6_transmitdelay, - no_ipv6_ospf6_transmitdelay_cmd, - "no ipv6 ospf6 transmit-delay [(1-3600)]", - NO_STR - IP6_STR - OSPF6_STR - "Link state transmit delay\n" - SECONDS_STR) +ALIAS(ipv6_ospf6_transmitdelay, no_ipv6_ospf6_transmitdelay_cmd, + "no ipv6 ospf6 transmit-delay [(1-3600)]", + NO_STR IP6_STR OSPF6_STR "Link state transmit delay\n" SECONDS_STR) /* interface variable set command */ -DEFUN (ipv6_ospf6_retransmitinterval, - ipv6_ospf6_retransmitinterval_cmd, - "ipv6 ospf6 retransmit-interval (1-65535)", - IP6_STR - OSPF6_STR - "Time between retransmitting lost link state advertisements\n" - SECONDS_STR) +DEFUN(ipv6_ospf6_retransmitinterval, ipv6_ospf6_retransmitinterval_cmd, + "ipv6 ospf6 retransmit-interval (1-65535)", + IP6_STR OSPF6_STR + "Time between retransmitting lost link state advertisements\n" SECONDS_STR) { VTY_DECLVAR_CONTEXT(interface, ifp); int idx_number = 3; @@ -2283,23 +2240,16 @@ DEFUN (ipv6_ospf6_retransmitinterval, return CMD_SUCCESS; } -ALIAS (ipv6_ospf6_retransmitinterval, - no_ipv6_ospf6_retransmitinterval_cmd, - "no ipv6 ospf6 retransmit-interval [(1-65535)]", - NO_STR - IP6_STR - OSPF6_STR - "Time between retransmitting lost link state advertisements\n" - SECONDS_STR) +ALIAS(ipv6_ospf6_retransmitinterval, no_ipv6_ospf6_retransmitinterval_cmd, + "no ipv6 ospf6 retransmit-interval [(1-65535)]", + NO_STR IP6_STR OSPF6_STR + "Time between retransmitting lost link state advertisements\n" SECONDS_STR) /* interface variable set command */ -DEFUN (ipv6_ospf6_priority, - ipv6_ospf6_priority_cmd, - "ipv6 ospf6 priority (0-255)", - IP6_STR - OSPF6_STR - "Router priority\n" - "Priority value\n") +DEFUN(ipv6_ospf6_priority, ipv6_ospf6_priority_cmd, + "ipv6 ospf6 priority (0-255)", + IP6_STR OSPF6_STR "Router priority\n" + "Priority value\n") { VTY_DECLVAR_CONTEXT(interface, ifp); int idx_number = 3; @@ -2315,10 +2265,9 @@ DEFUN (ipv6_ospf6_priority, ? OSPF6_INTERFACE_PRIORITY : strtoul(argv[idx_number]->arg, NULL, 10); - if (oi->area - && (oi->state == OSPF6_INTERFACE_DROTHER - || oi->state == OSPF6_INTERFACE_BDR - || oi->state == OSPF6_INTERFACE_DR)) { + if (oi->area && (oi->state == OSPF6_INTERFACE_DROTHER || + oi->state == OSPF6_INTERFACE_BDR || + oi->state == OSPF6_INTERFACE_DR)) { if (ospf6_interface_state_change(dr_election(oi), oi) == -1) OSPF6_LINK_LSA_SCHEDULE(oi); } @@ -2326,22 +2275,15 @@ DEFUN (ipv6_ospf6_priority, return CMD_SUCCESS; } -ALIAS (ipv6_ospf6_priority, - no_ipv6_ospf6_priority_cmd, - "no ipv6 ospf6 priority [(0-255)]", - NO_STR - IP6_STR - OSPF6_STR - "Router priority\n" - "Priority value\n") +ALIAS(ipv6_ospf6_priority, no_ipv6_ospf6_priority_cmd, + "no ipv6 ospf6 priority [(0-255)]", + NO_STR IP6_STR OSPF6_STR "Router priority\n" + "Priority value\n") -DEFUN (ipv6_ospf6_instance, - ipv6_ospf6_instance_cmd, - "ipv6 ospf6 instance-id (0-255)", - IP6_STR - OSPF6_STR - "Instance ID for this interface\n" - "Instance ID value\n") +DEFUN(ipv6_ospf6_instance, ipv6_ospf6_instance_cmd, + "ipv6 ospf6 instance-id (0-255)", + IP6_STR OSPF6_STR "Instance ID for this interface\n" + "Instance ID value\n") { VTY_DECLVAR_CONTEXT(interface, ifp); int idx_number = 3; @@ -2359,22 +2301,14 @@ DEFUN (ipv6_ospf6_instance, return CMD_SUCCESS; } -ALIAS (ipv6_ospf6_instance, - no_ipv6_ospf6_instance_cmd, - "no ipv6 ospf6 instance-id [(0-255)]", - NO_STR - IP6_STR - OSPF6_STR - "Instance ID for this interface\n" - "Instance ID value\n") +ALIAS(ipv6_ospf6_instance, no_ipv6_ospf6_instance_cmd, + "no ipv6 ospf6 instance-id [(0-255)]", + NO_STR IP6_STR OSPF6_STR "Instance ID for this interface\n" + "Instance ID value\n") -DEFUN (ipv6_ospf6_passive, - ipv6_ospf6_passive_cmd, - "ipv6 ospf6 passive", - IP6_STR - OSPF6_STR - "Passive interface; no adjacency will be formed on this interface\n" - ) +DEFUN(ipv6_ospf6_passive, ipv6_ospf6_passive_cmd, "ipv6 ospf6 passive", + IP6_STR OSPF6_STR + "Passive interface; no adjacency will be formed on this interface\n") { VTY_DECLVAR_CONTEXT(interface, ifp); struct ospf6_interface *oi; @@ -2400,14 +2334,9 @@ DEFUN (ipv6_ospf6_passive, return CMD_SUCCESS; } -DEFUN (no_ipv6_ospf6_passive, - no_ipv6_ospf6_passive_cmd, - "no ipv6 ospf6 passive", - NO_STR - IP6_STR - OSPF6_STR - "passive interface: No Adjacency will be formed on this I/F\n" - ) +DEFUN(no_ipv6_ospf6_passive, no_ipv6_ospf6_passive_cmd, "no ipv6 ospf6 passive", + NO_STR IP6_STR OSPF6_STR + "passive interface: No Adjacency will be formed on this I/F\n") { VTY_DECLVAR_CONTEXT(interface, ifp); struct ospf6_interface *oi; @@ -2430,13 +2359,8 @@ DEFUN (no_ipv6_ospf6_passive, return CMD_SUCCESS; } -DEFUN (ipv6_ospf6_mtu_ignore, - ipv6_ospf6_mtu_ignore_cmd, - "ipv6 ospf6 mtu-ignore", - IP6_STR - OSPF6_STR - "Disable MTU mismatch detection on this interface\n" - ) +DEFUN(ipv6_ospf6_mtu_ignore, ipv6_ospf6_mtu_ignore_cmd, "ipv6 ospf6 mtu-ignore", + IP6_STR OSPF6_STR "Disable MTU mismatch detection on this interface\n") { VTY_DECLVAR_CONTEXT(interface, ifp); struct ospf6_interface *oi; @@ -2452,14 +2376,10 @@ DEFUN (ipv6_ospf6_mtu_ignore, return CMD_SUCCESS; } -DEFUN (no_ipv6_ospf6_mtu_ignore, - no_ipv6_ospf6_mtu_ignore_cmd, - "no ipv6 ospf6 mtu-ignore", - NO_STR - IP6_STR - OSPF6_STR - "Disable MTU mismatch detection on this interface\n" - ) +DEFUN(no_ipv6_ospf6_mtu_ignore, no_ipv6_ospf6_mtu_ignore_cmd, + "no ipv6 ospf6 mtu-ignore", + NO_STR IP6_STR OSPF6_STR + "Disable MTU mismatch detection on this interface\n") { VTY_DECLVAR_CONTEXT(interface, ifp); struct ospf6_interface *oi; @@ -2475,15 +2395,11 @@ DEFUN (no_ipv6_ospf6_mtu_ignore, return CMD_SUCCESS; } -DEFUN (ipv6_ospf6_advertise_prefix_list, - ipv6_ospf6_advertise_prefix_list_cmd, - "ipv6 ospf6 advertise prefix-list WORD", - IP6_STR - OSPF6_STR - "Advertising options\n" - "Filter prefix using prefix-list\n" - "Prefix list name\n" - ) +DEFUN(ipv6_ospf6_advertise_prefix_list, ipv6_ospf6_advertise_prefix_list_cmd, + "ipv6 ospf6 advertise prefix-list WORD", + IP6_STR OSPF6_STR "Advertising options\n" + "Filter prefix using prefix-list\n" + "Prefix list name\n") { VTY_DECLVAR_CONTEXT(interface, ifp); int idx_word = 4; @@ -2513,15 +2429,12 @@ DEFUN (ipv6_ospf6_advertise_prefix_list, return CMD_SUCCESS; } -DEFUN (no_ipv6_ospf6_advertise_prefix_list, - no_ipv6_ospf6_advertise_prefix_list_cmd, - "no ipv6 ospf6 advertise prefix-list [WORD]", - NO_STR - IP6_STR - OSPF6_STR - "Advertising options\n" - "Filter prefix using prefix-list\n" - "Prefix list name\n") +DEFUN(no_ipv6_ospf6_advertise_prefix_list, + no_ipv6_ospf6_advertise_prefix_list_cmd, + "no ipv6 ospf6 advertise prefix-list [WORD]", + NO_STR IP6_STR OSPF6_STR "Advertising options\n" + "Filter prefix using prefix-list\n" + "Prefix list name\n") { VTY_DECLVAR_CONTEXT(interface, ifp); struct ospf6_interface *oi; @@ -2549,15 +2462,12 @@ DEFUN (no_ipv6_ospf6_advertise_prefix_list, return CMD_SUCCESS; } -DEFUN (ipv6_ospf6_network, - ipv6_ospf6_network_cmd, - "ipv6 ospf6 network <broadcast|point-to-point>", - IP6_STR - OSPF6_STR - "Network type\n" - "Specify OSPF6 broadcast network\n" - "Specify OSPF6 point-to-point network\n" - ) +DEFUN(ipv6_ospf6_network, ipv6_ospf6_network_cmd, + "ipv6 ospf6 network <broadcast|point-to-point|point-to-multipoint>", + IP6_STR OSPF6_STR "Network type\n" + "Specify OSPF6 broadcast network\n" + "Specify OSPF6 point-to-point network\n" + "Specify OSPF6 point-to-multipoint network\n") { VTY_DECLVAR_CONTEXT(interface, ifp); int idx_network = 3; @@ -2582,24 +2492,25 @@ DEFUN (ipv6_ospf6_network, return CMD_SUCCESS; } oi->type = OSPF_IFTYPE_POINTOPOINT; + } else if (strncmp(argv[idx_network]->arg, "point-to-m", 10) == 0) { + if (oi->type == OSPF_IFTYPE_POINTOMULTIPOINT) { + return CMD_SUCCESS; + } + oi->type = OSPF_IFTYPE_POINTOMULTIPOINT; } /* Reset the interface */ - event_execute(master, interface_down, oi, 0); - event_execute(master, interface_up, oi, 0); + event_execute(master, interface_down, oi, 0, NULL); + event_execute(master, interface_up, oi, 0, NULL); return CMD_SUCCESS; } -DEFUN (no_ipv6_ospf6_network, - no_ipv6_ospf6_network_cmd, - "no ipv6 ospf6 network [<broadcast|point-to-point>]", - NO_STR - IP6_STR - OSPF6_STR - "Set default network type\n" - "Specify OSPF6 broadcast network\n" - "Specify OSPF6 point-to-point network\n") +DEFUN(no_ipv6_ospf6_network, no_ipv6_ospf6_network_cmd, + "no ipv6 ospf6 network [<broadcast|point-to-point>]", + NO_STR IP6_STR OSPF6_STR "Set default network type\n" + "Specify OSPF6 broadcast network\n" + "Specify OSPF6 point-to-point network\n") { VTY_DECLVAR_CONTEXT(interface, ifp); struct ospf6_interface *oi; @@ -2608,9 +2519,8 @@ DEFUN (no_ipv6_ospf6_network, assert(ifp); oi = (struct ospf6_interface *)ifp->info; - if (oi == NULL) { + if (oi == NULL) return CMD_SUCCESS; - } oi->type_cfg = false; @@ -2621,12 +2531,101 @@ DEFUN (no_ipv6_ospf6_network, oi->type = type; /* Reset the interface */ - event_execute(master, interface_down, oi, 0); - event_execute(master, interface_up, oi, 0); + event_execute(master, interface_down, oi, 0, NULL); + event_execute(master, interface_up, oi, 0, NULL); + + return CMD_SUCCESS; +} + +DEFPY(ipv6_ospf6_p2xp_only_cfg_neigh, ipv6_ospf6_p2xp_only_cfg_neigh_cmd, + "[no] ipv6 ospf6 p2p-p2mp config-neighbors-only", + NO_STR IP6_STR OSPF6_STR + "Point-to-point and Point-to-Multipoint parameters\n" + "Only form adjacencies with explicitly configured neighbors\n") +{ + VTY_DECLVAR_CONTEXT(interface, ifp); + struct ospf6_interface *oi = ifp->info; + + if (no) { + if (!oi) + return CMD_SUCCESS; + + oi->p2xp_only_cfg_neigh = false; + return CMD_SUCCESS; + } + + if (!oi) + oi = ospf6_interface_create(ifp); + oi->p2xp_only_cfg_neigh = true; return CMD_SUCCESS; } +DEFPY(ipv6_ospf6_p2xp_no_multicast_hello, ipv6_ospf6_p2xp_no_multicast_hello_cmd, + "[no] ipv6 ospf6 p2p-p2mp disable-multicast-hello", + NO_STR IP6_STR OSPF6_STR + "Point-to-point and Point-to-Multipoint parameters\n" + "Do not send multicast hellos\n") +{ + VTY_DECLVAR_CONTEXT(interface, ifp); + struct ospf6_interface *oi = ifp->info; + + if (no) { + if (!oi) + return CMD_SUCCESS; + + oi->p2xp_no_multicast_hello = false; + return CMD_SUCCESS; + } + + if (!oi) + oi = ospf6_interface_create(ifp); + + oi->p2xp_no_multicast_hello = true; + return CMD_SUCCESS; +} + +DEFPY(ipv6_ospf6_p2xp_connected_pfx, ipv6_ospf6_p2xp_connected_pfx_cmd, + "[no] ipv6 ospf6 p2p-p2mp connected-prefixes <include$incl|exclude$excl>", + NO_STR IP6_STR OSPF6_STR + "Point-to-point and Point-to-Multipoint parameters\n" + "Adjust handling of directly connected prefixes\n" + "Advertise prefixes and own /128 (default for PtP)\n" + "Ignore, only advertise own /128 (default for PtMP)\n") +{ + VTY_DECLVAR_CONTEXT(interface, ifp); + struct ospf6_interface *oi = ifp->info; + bool old_incl, old_excl; + + if (no && !oi) + return CMD_SUCCESS; + + if (!oi) + oi = ospf6_interface_create(ifp); + + old_incl = oi->p2xp_connected_pfx_include; + old_excl = oi->p2xp_connected_pfx_exclude; + oi->p2xp_connected_pfx_include = false; + oi->p2xp_connected_pfx_exclude = false; + + if (incl && !no) + oi->p2xp_connected_pfx_include = true; + if (excl && !no) + oi->p2xp_connected_pfx_exclude = true; + + if (oi->p2xp_connected_pfx_include != old_incl || + oi->p2xp_connected_pfx_exclude != old_excl) + ospf6_interface_connected_route_update(ifp); + return CMD_SUCCESS; +} + +ALIAS(ipv6_ospf6_p2xp_connected_pfx, no_ipv6_ospf6_p2xp_connected_pfx_cmd, + "no ipv6 ospf6 p2p-p2mp connected-prefixes", + NO_STR IP6_STR OSPF6_STR + "Point-to-point and Point-to-Multipoint parameters\n" + "Adjust handling of directly connected prefixes\n") + + static int config_write_ospf6_interface(struct vty *vty, struct vrf *vrf) { struct ospf6_interface *oi; @@ -2686,7 +2685,10 @@ static int config_write_ospf6_interface(struct vty *vty, struct vrf *vrf) if (oi->mtu_ignore) vty_out(vty, " ipv6 ospf6 mtu-ignore\n"); - if (oi->type_cfg && oi->type == OSPF_IFTYPE_POINTOPOINT) + if (oi->type_cfg && oi->type == OSPF_IFTYPE_POINTOMULTIPOINT) + vty_out(vty, + " ipv6 ospf6 network point-to-multipoint\n"); + else if (oi->type_cfg && oi->type == OSPF_IFTYPE_POINTOPOINT) vty_out(vty, " ipv6 ospf6 network point-to-point\n"); else if (oi->type_cfg && oi->type == OSPF_IFTYPE_BROADCAST) vty_out(vty, " ipv6 ospf6 network broadcast\n"); @@ -2695,7 +2697,22 @@ static int config_write_ospf6_interface(struct vty *vty, struct vrf *vrf) vty_out(vty, " ipv6 ospf6 graceful-restart hello-delay %u\n", oi->gr.hello_delay.interval); + if (oi->p2xp_only_cfg_neigh) + vty_out(vty, + " ipv6 ospf6 p2p-p2mp config-neighbors-only\n"); + + if (oi->p2xp_no_multicast_hello) + vty_out(vty, + " ipv6 ospf6 p2p-p2mp disable-multicast-hello\n"); + + if (oi->p2xp_connected_pfx_include) + vty_out(vty, + " ipv6 ospf6 p2p-p2mp connected-prefixes include\n"); + else if (oi->p2xp_connected_pfx_exclude) + vty_out(vty, + " ipv6 ospf6 p2p-p2mp connected-prefixes exclude\n"); + config_write_ospf6_p2xp_neighbor(vty, oi); ospf6_bfd_write_config(vty, oi); ospf6_auth_write_config(vty, &oi->at_data); @@ -2733,10 +2750,10 @@ static int ospf6_ifp_create(struct interface *ifp) static int ospf6_ifp_up(struct interface *ifp) { if (IS_OSPF6_DEBUG_ZEBRA(RECV)) - zlog_debug( - "Zebra Interface state change: %s index %d flags %llx metric %d mtu %d bandwidth %d", - ifp->name, ifp->ifindex, (unsigned long long)ifp->flags, - ifp->metric, ifp->mtu6, ifp->bandwidth); + zlog_debug("Zebra Interface state change: %s index %d flags %llx metric %d mtu %d bandwidth %d", + ifp->name, ifp->ifindex, + (unsigned long long)ifp->flags, ifp->metric, + ifp->mtu6, ifp->bandwidth); ospf6_interface_state_update(ifp); @@ -2746,10 +2763,10 @@ static int ospf6_ifp_up(struct interface *ifp) static int ospf6_ifp_down(struct interface *ifp) { if (IS_OSPF6_DEBUG_ZEBRA(RECV)) - zlog_debug( - "Zebra Interface state change: %s index %d flags %llx metric %d mtu %d bandwidth %d", - ifp->name, ifp->ifindex, (unsigned long long)ifp->flags, - ifp->metric, ifp->mtu6, ifp->bandwidth); + zlog_debug("Zebra Interface state change: %s index %d flags %llx metric %d mtu %d bandwidth %d", + ifp->name, ifp->ifindex, + (unsigned long long)ifp->flags, ifp->metric, + ifp->mtu6, ifp->bandwidth); ospf6_interface_state_update(ifp); @@ -2776,13 +2793,14 @@ void ospf6_interface_init(void) { /* Install interface node. */ if_cmd_init(config_write_interface); - if_zapi_callbacks(ospf6_ifp_create, ospf6_ifp_up, - ospf6_ifp_down, ospf6_ifp_destroy); + hook_register_prio(if_real, 0, ospf6_ifp_create); + hook_register_prio(if_up, 0, ospf6_ifp_up); + hook_register_prio(if_down, 0, ospf6_ifp_down); + hook_register_prio(if_unreal, 0, ospf6_ifp_destroy); install_element(VIEW_NODE, &show_ipv6_ospf6_interface_prefix_cmd); install_element(VIEW_NODE, &show_ipv6_ospf6_interface_ifname_cmd); - install_element(VIEW_NODE, - &show_ipv6_ospf6_interface_ifname_prefix_cmd); + install_element(VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd); install_element(VIEW_NODE, &show_ipv6_ospf6_interface_traffic_cmd); install_element(INTERFACE_NODE, &ipv6_ospf6_area_cmd); @@ -2820,6 +2838,11 @@ void ospf6_interface_init(void) install_element(INTERFACE_NODE, &ipv6_ospf6_network_cmd); install_element(INTERFACE_NODE, &no_ipv6_ospf6_network_cmd); + install_element(INTERFACE_NODE, &ipv6_ospf6_p2xp_only_cfg_neigh_cmd); + install_element(INTERFACE_NODE, &ipv6_ospf6_p2xp_no_multicast_hello_cmd); + install_element(INTERFACE_NODE, &ipv6_ospf6_p2xp_connected_pfx_cmd); + install_element(INTERFACE_NODE, &no_ipv6_ospf6_p2xp_connected_pfx_cmd); + /* reference bandwidth commands */ install_element(OSPF6_NODE, &auto_cost_reference_bandwidth_cmd); install_element(OSPF6_NODE, &no_auto_cost_reference_bandwidth_cmd); @@ -2845,21 +2868,14 @@ void ospf6_interface_clear(struct interface *ifp) zlog_debug("Interface %s: clear by reset", ifp->name); /* Reset the interface */ - event_execute(master, interface_down, oi, 0); - event_execute(master, interface_up, oi, 0); + event_execute(master, interface_down, oi, 0, NULL); + event_execute(master, interface_up, oi, 0, NULL); } /* Clear interface */ -DEFUN (clear_ipv6_ospf6_interface, - clear_ipv6_ospf6_interface_cmd, - "clear ipv6 ospf6 [vrf NAME] interface [IFNAME]", - CLEAR_STR - IP6_STR - OSPF6_STR - VRF_CMD_HELP_STR - INTERFACE_STR - IFNAME_STR - ) +DEFUN(clear_ipv6_ospf6_interface, clear_ipv6_ospf6_interface_cmd, + "clear ipv6 ospf6 [vrf NAME] interface [IFNAME]", + CLEAR_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR INTERFACE_STR IFNAME_STR) { struct vrf *vrf; int idx_vrf = 3; @@ -2900,26 +2916,16 @@ void install_element_ospf6_clear_interface(void) install_element(ENABLE_NODE, &clear_ipv6_ospf6_interface_cmd); } -DEFUN (debug_ospf6_interface, - debug_ospf6_interface_cmd, - "debug ospf6 interface", - DEBUG_STR - OSPF6_STR - "Debug OSPFv3 Interface\n" - ) +DEFUN(debug_ospf6_interface, debug_ospf6_interface_cmd, "debug ospf6 interface", + DEBUG_STR OSPF6_STR "Debug OSPFv3 Interface\n") { OSPF6_DEBUG_INTERFACE_ON(); return CMD_SUCCESS; } -DEFUN (no_debug_ospf6_interface, - no_debug_ospf6_interface_cmd, - "no debug ospf6 interface", - NO_STR - DEBUG_STR - OSPF6_STR - "Debug OSPFv3 Interface\n" - ) +DEFUN(no_debug_ospf6_interface, no_debug_ospf6_interface_cmd, + "no debug ospf6 interface", + NO_STR DEBUG_STR OSPF6_STR "Debug OSPFv3 Interface\n") { OSPF6_DEBUG_INTERFACE_OFF(); return CMD_SUCCESS; @@ -2956,10 +2962,9 @@ void ospf6_auth_write_config(struct vty *vty, struct ospf6_auth_data *at_data) DEFUN(ipv6_ospf6_intf_auth_trailer_keychain, ipv6_ospf6_intf_auth_trailer_keychain_cmd, "ipv6 ospf6 authentication keychain KEYCHAIN_NAME", - IP6_STR OSPF6_STR - "Enable authentication on this interface\n" - "Keychain\n" - "Keychain name\n") + IP6_STR OSPF6_STR "Enable authentication on this interface\n" + "Keychain\n" + "Keychain name\n") { VTY_DECLVAR_CONTEXT(interface, ifp); int keychain_idx = 4; @@ -2980,8 +2985,8 @@ DEFUN(ipv6_ospf6_intf_auth_trailer_keychain, if (oi->at_data.keychain) XFREE(MTYPE_OSPF6_AUTH_KEYCHAIN, oi->at_data.keychain); - oi->at_data.keychain = - XSTRDUP(MTYPE_OSPF6_AUTH_KEYCHAIN, argv[keychain_idx]->arg); + oi->at_data.keychain = XSTRDUP(MTYPE_OSPF6_AUTH_KEYCHAIN, + argv[keychain_idx]->arg); return CMD_SUCCESS; } @@ -2989,10 +2994,9 @@ DEFUN(ipv6_ospf6_intf_auth_trailer_keychain, DEFUN(no_ipv6_ospf6_intf_auth_trailer_keychain, no_ipv6_ospf6_intf_auth_trailer_keychain_cmd, "no ipv6 ospf6 authentication keychain [KEYCHAIN_NAME]", - NO_STR IP6_STR OSPF6_STR - "Enable authentication on this interface\n" - "Keychain\n" - "Keychain name\n") + NO_STR IP6_STR OSPF6_STR "Enable authentication on this interface\n" + "Keychain\n" + "Keychain name\n") { VTY_DECLVAR_CONTEXT(interface, ifp); struct ospf6_interface *oi; @@ -3018,18 +3022,17 @@ DEFUN(ipv6_ospf6_intf_auth_trailer_key, ipv6_ospf6_intf_auth_trailer_key_cmd, "ipv6 ospf6 authentication key-id (1-65535) hash-algo " "<md5|hmac-sha-1|hmac-sha-256|hmac-sha-384|hmac-sha-512> " "key WORD", - IP6_STR OSPF6_STR - "Authentication\n" - "Key ID\n" - "Key ID value\n" - "Cryptographic-algorithm\n" - "Use MD5 algorithm\n" - "Use HMAC-SHA-1 algorithm\n" - "Use HMAC-SHA-256 algorithm\n" - "Use HMAC-SHA-384 algorithm\n" - "Use HMAC-SHA-512 algorithm\n" - "Password\n" - "Password string (key)\n") + IP6_STR OSPF6_STR "Authentication\n" + "Key ID\n" + "Key ID value\n" + "Cryptographic-algorithm\n" + "Use MD5 algorithm\n" + "Use HMAC-SHA-1 algorithm\n" + "Use HMAC-SHA-256 algorithm\n" + "Use HMAC-SHA-384 algorithm\n" + "Use HMAC-SHA-512 algorithm\n" + "Password\n" + "Password string (key)\n") { VTY_DECLVAR_CONTEXT(interface, ifp); int key_id_idx = 4; @@ -3063,8 +3066,8 @@ DEFUN(ipv6_ospf6_intf_auth_trailer_key, ipv6_ospf6_intf_auth_trailer_key_cmd, oi->at_data.key_id = (uint16_t)strtol(argv[key_id_idx]->arg, NULL, 10); if (oi->at_data.auth_key) XFREE(MTYPE_OSPF6_AUTH_MANUAL_KEY, oi->at_data.auth_key); - oi->at_data.auth_key = - XSTRDUP(MTYPE_OSPF6_AUTH_MANUAL_KEY, argv[password_idx]->arg); + oi->at_data.auth_key = XSTRDUP(MTYPE_OSPF6_AUTH_MANUAL_KEY, + argv[password_idx]->arg); return CMD_SUCCESS; } @@ -3074,18 +3077,17 @@ DEFUN(no_ipv6_ospf6_intf_auth_trailer_key, "no ipv6 ospf6 authentication key-id [(1-65535) hash-algo " "<md5|hmac-sha-1|hmac-sha-256|hmac-sha-384|hmac-sha-512> " "key WORD]", - NO_STR IP6_STR OSPF6_STR - "Authentication\n" - "Key ID\n" - "Key ID value\n" - "Cryptographic-algorithm\n" - "Use MD5 algorithm\n" - "Use HMAC-SHA-1 algorithm\n" - "Use HMAC-SHA-256 algorithm\n" - "Use HMAC-SHA-384 algorithm\n" - "Use HMAC-SHA-512 algorithm\n" - "Password\n" - "Password string (key)\n") + NO_STR IP6_STR OSPF6_STR "Authentication\n" + "Key ID\n" + "Key ID value\n" + "Cryptographic-algorithm\n" + "Use MD5 algorithm\n" + "Use HMAC-SHA-1 algorithm\n" + "Use HMAC-SHA-256 algorithm\n" + "Use HMAC-SHA-384 algorithm\n" + "Use HMAC-SHA-512 algorithm\n" + "Password\n" + "Password string (key)\n") { VTY_DECLVAR_CONTEXT(interface, ifp); struct ospf6_interface *oi; diff --git a/ospf6d/ospf6_interface.h b/ospf6d/ospf6_interface.h index 5942df0ab5..2b42af390a 100644 --- a/ospf6d/ospf6_interface.h +++ b/ospf6d/ospf6_interface.h @@ -34,6 +34,25 @@ struct ospf6_auth_data { uint32_t rx_drop; /* Pkt drop due to auth fail while reading */ }; +PREDECL_RBTREE_UNIQ(ospf6_if_p2xp_neighcfgs); + +struct ospf6_if_p2xp_neighcfg { + struct ospf6_if_p2xp_neighcfgs_item item; + + struct ospf6_interface *ospf6_if; + struct in6_addr addr; + + bool cfg_cost : 1; + + uint32_t cost; + uint16_t poll_interval; + + /* NULL if down */ + struct ospf6_neighbor *active; + + struct event *t_unicast_hello; +}; + /* Interface structure */ struct ospf6_interface { /* IF info from zebra */ @@ -66,6 +85,20 @@ struct ospf6_interface { uint8_t type; bool type_cfg; + /* P2P/P2MP behavior: */ + + /* disable hellos on standard multicast? */ + bool p2xp_no_multicast_hello; + /* only allow explicitly configured neighbors? */ + bool p2xp_only_cfg_neigh; + /* override mode default for advertising connected prefixes. + * both false by default (= do include for PtP, exclude for PtMP) + */ + bool p2xp_connected_pfx_include; + bool p2xp_connected_pfx_exclude; + + struct ospf6_if_p2xp_neighcfgs_head p2xp_neighs; + /* Router Priority */ uint8_t priority; @@ -171,15 +204,16 @@ struct ospf6_interface { DECLARE_QOBJ_TYPE(ospf6_interface); /* interface state */ -#define OSPF6_INTERFACE_NONE 0 -#define OSPF6_INTERFACE_DOWN 1 -#define OSPF6_INTERFACE_LOOPBACK 2 -#define OSPF6_INTERFACE_WAITING 3 -#define OSPF6_INTERFACE_POINTTOPOINT 4 -#define OSPF6_INTERFACE_DROTHER 5 -#define OSPF6_INTERFACE_BDR 6 -#define OSPF6_INTERFACE_DR 7 -#define OSPF6_INTERFACE_MAX 8 +#define OSPF6_INTERFACE_NONE 0 +#define OSPF6_INTERFACE_DOWN 1 +#define OSPF6_INTERFACE_LOOPBACK 2 +#define OSPF6_INTERFACE_WAITING 3 +#define OSPF6_INTERFACE_POINTTOPOINT 4 +#define OSPF6_INTERFACE_POINTTOMULTIPOINT 5 +#define OSPF6_INTERFACE_DROTHER 6 +#define OSPF6_INTERFACE_BDR 7 +#define OSPF6_INTERFACE_DR 8 +#define OSPF6_INTERFACE_MAX 9 extern const char *const ospf6_interface_state_str[]; diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index 301fccecd7..cb036752e8 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -87,7 +87,7 @@ static int ospf6_router_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, char buf[32], name[32], bits[16], options[32]; struct ospf6_router_lsa *router_lsa; struct ospf6_router_lsdesc *lsdesc; - json_object *json_arr; + json_object *json_arr = NULL; json_object *json_loop; router_lsa = @@ -321,13 +321,14 @@ void ospf6_router_lsa_originate(struct event *thread) } /* Point-to-Point interfaces */ - if (oi->type == OSPF_IFTYPE_POINTOPOINT) { + if (oi->type == OSPF_IFTYPE_POINTOPOINT + || oi->type == OSPF_IFTYPE_POINTOMULTIPOINT) { for (ALL_LIST_ELEMENTS_RO(oi->neighbor_list, j, on)) { if (on->state != OSPF6_NEIGHBOR_FULL) continue; lsdesc->type = OSPF6_ROUTER_LSDESC_POINTTOPOINT; - lsdesc->metric = htons(oi->cost); + lsdesc->metric = htons(ospf6_neighbor_cost(on)); lsdesc->interface_id = htonl(oi->interface->ifindex); lsdesc->neighbor_interface_id = @@ -460,7 +461,7 @@ static int ospf6_network_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, struct ospf6_network_lsa *network_lsa; struct ospf6_network_lsdesc *lsdesc; char buf[128], options[32]; - json_object *json_arr; + json_object *json_arr = NULL; network_lsa = (struct ospf6_network_lsa *)((caddr_t)lsa->header @@ -1068,6 +1069,7 @@ void ospf6_intra_prefix_lsa_originate_stub(struct event *thread) if (oi->state != OSPF6_INTERFACE_LOOPBACK && oi->state != OSPF6_INTERFACE_POINTTOPOINT + && oi->state != OSPF6_INTERFACE_POINTTOMULTIPOINT && full_count != 0) { if (IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX)) zlog_debug(" Interface %s is not stub, ignore", diff --git a/ospf6d/ospf6_intra.h b/ospf6d/ospf6_intra.h index 0f286f0ab1..7d154cb4c6 100644 --- a/ospf6d/ospf6_intra.h +++ b/ospf6d/ospf6_intra.h @@ -181,20 +181,21 @@ struct ospf6_intra_prefix_lsa { do { \ if (CHECK_FLAG((oa)->flag, OSPF6_AREA_ENABLE)) \ event_execute(master, ospf6_router_lsa_originate, oa, \ - 0); \ + 0, NULL); \ } while (0) #define OSPF6_NETWORK_LSA_EXECUTE(oi) \ do { \ EVENT_OFF((oi)->thread_network_lsa); \ - event_execute(master, ospf6_network_lsa_originate, oi, 0); \ + event_execute(master, ospf6_network_lsa_originate, oi, 0, \ + NULL); \ } while (0) #define OSPF6_LINK_LSA_EXECUTE(oi) \ do { \ if (!CHECK_FLAG((oi)->flag, OSPF6_INTERFACE_DISABLE)) \ event_execute(master, ospf6_link_lsa_originate, oi, \ - 0); \ + 0, NULL); \ } while (0) #define OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT(oi) \ @@ -202,13 +203,13 @@ struct ospf6_intra_prefix_lsa { EVENT_OFF((oi)->thread_intra_prefix_lsa); \ event_execute(master, \ ospf6_intra_prefix_lsa_originate_transit, oi, \ - 0); \ + 0, NULL); \ } while (0) #define OSPF6_AS_EXTERN_LSA_EXECUTE(oi) \ do { \ EVENT_OFF((oi)->thread_as_extern_lsa); \ - event_execute(master, ospf6_orig_as_external_lsa, oi, 0); \ + event_execute(master, ospf6_orig_as_external_lsa, oi, 0, NULL);\ } while (0) /* Function Prototypes */ diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c index 2b806afe06..bc39579653 100644 --- a/ospf6d/ospf6_lsa.c +++ b/ospf6d/ospf6_lsa.c @@ -333,7 +333,7 @@ void ospf6_lsa_premature_aging(struct ospf6_lsa *lsa) ospf6_flood_clear(lsa); lsa->header->age = htons(OSPF_LSA_MAXAGE); - event_execute(master, ospf6_lsa_expire, lsa, 0); + event_execute(master, ospf6_lsa_expire, lsa, 0, NULL); } /* check which is more recent. if a is more recent, return -1; @@ -797,17 +797,17 @@ struct ospf6_lsa *ospf6_lsa_lock(struct ospf6_lsa *lsa) } /* decrement reference counter of struct ospf6_lsa */ -struct ospf6_lsa *ospf6_lsa_unlock(struct ospf6_lsa *lsa) +void ospf6_lsa_unlock(struct ospf6_lsa **lsa) { /* decrement reference counter */ - assert(lsa->lock > 0); - lsa->lock--; + assert((*lsa)->lock > 0); + (*lsa)->lock--; - if (lsa->lock != 0) - return lsa; + if ((*lsa)->lock != 0) + return; - ospf6_lsa_delete(lsa); - return NULL; + ospf6_lsa_delete(*lsa); + *lsa = NULL; } diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h index be7b94f3d3..c9ac27df88 100644 --- a/ospf6d/ospf6_lsa.h +++ b/ospf6d/ospf6_lsa.h @@ -239,7 +239,7 @@ extern void ospf6_lsa_delete(struct ospf6_lsa *lsa); extern struct ospf6_lsa *ospf6_lsa_copy(struct ospf6_lsa *lsa); extern struct ospf6_lsa *ospf6_lsa_lock(struct ospf6_lsa *lsa); -extern struct ospf6_lsa *ospf6_lsa_unlock(struct ospf6_lsa *lsa); +extern void ospf6_lsa_unlock(struct ospf6_lsa **lsa); extern void ospf6_lsa_expire(struct event *thread); extern void ospf6_lsa_refresh(struct event *thread); diff --git a/ospf6d/ospf6_lsdb.c b/ospf6d/ospf6_lsdb.c index 7925a8b2f4..c9cbdf8e92 100644 --- a/ospf6d/ospf6_lsdb.c +++ b/ospf6d/ospf6_lsdb.c @@ -139,7 +139,7 @@ void ospf6_lsdb_add(struct ospf6_lsa *lsa, struct ospf6_lsdb *lsdb) } /* to free the lookup lock in node get*/ route_unlock_node(current); - ospf6_lsa_unlock(old); + ospf6_lsa_unlock(&old); } ospf6_lsdb_count_assert(lsdb); @@ -168,7 +168,7 @@ void ospf6_lsdb_remove(struct ospf6_lsa *lsa, struct ospf6_lsdb *lsdb) route_unlock_node(node); /* to free the lookup lock */ route_unlock_node(node); /* to free the original lock */ - ospf6_lsa_unlock(lsa); + ospf6_lsa_unlock(&lsa); ospf6_lsdb_count_assert(lsdb); } @@ -236,8 +236,10 @@ struct ospf6_lsa *ospf6_find_inter_prefix_lsa(struct ospf6 *ospf6, prefix.prefixlen = prefix_lsa->prefix.prefix_length; ospf6_prefix_in6_addr(&prefix.u.prefix6, prefix_lsa, &prefix_lsa->prefix); - if (prefix_same(p, &prefix)) + if (prefix_same(p, &prefix)) { + ospf6_lsa_unlock(&lsa); return lsa; + } } return NULL; @@ -326,7 +328,7 @@ struct ospf6_lsa *ospf6_lsdb_next(const struct route_node *iterend, { struct route_node *node = lsa->rn; - ospf6_lsa_unlock(lsa); + ospf6_lsa_unlock(&lsa); do node = route_next_until(node, iterend); @@ -359,7 +361,7 @@ void ospf6_lsdb_lsa_unlock(struct ospf6_lsa *lsa) if (lsa != NULL) { if (lsa->rn != NULL) route_unlock_node(lsa->rn); - ospf6_lsa_unlock(lsa); + ospf6_lsa_unlock(&lsa); } } @@ -396,7 +398,7 @@ int ospf6_lsdb_maxage_remover(struct ospf6_lsdb *lsdb) ospf6_lsa_checksum(lsa->header); EVENT_OFF(lsa->refresh); - event_execute(master, ospf6_lsa_refresh, lsa, 0); + event_execute(master, ospf6_lsa_refresh, lsa, 0, NULL); } else { zlog_debug("calling ospf6_lsdb_remove %s", lsa->name); ospf6_lsdb_remove(lsa, lsdb); diff --git a/ospf6d/ospf6_lsdb.h b/ospf6d/ospf6_lsdb.h index a2444f1c14..604406d75f 100644 --- a/ospf6d/ospf6_lsdb.h +++ b/ospf6d/ospf6_lsdb.h @@ -63,11 +63,11 @@ extern struct ospf6_lsa *ospf6_lsdb_next(const struct route_node *iterend, * it really early. */ #define ALL_LSDB(lsdb, lsa, lsanext) \ - const struct route_node *iterend = \ - ospf6_lsdb_head(lsdb, 0, 0, 0, &lsa); \ - (lsa) != NULL && ospf6_lsa_lock(lsa) \ - && ((lsanext) = ospf6_lsdb_next(iterend, (lsa)), 1); \ - ospf6_lsa_unlock(lsa), (lsa) = (lsanext) + const struct route_node *iterend = ospf6_lsdb_head(lsdb, 0, 0, 0, \ + &lsa); \ + (lsa) != NULL && ospf6_lsa_lock(lsa) && \ + ((lsanext) = ospf6_lsdb_next(iterend, (lsa)), 1); \ + ospf6_lsa_unlock(&lsa), (lsa) = (lsanext) extern void ospf6_lsdb_remove_all(struct ospf6_lsdb *lsdb); extern void ospf6_lsdb_lsa_unlock(struct ospf6_lsa *lsa); diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c index fdb93475d4..b61c8f9a5f 100644 --- a/ospf6d/ospf6_main.c +++ b/ospf6d/ospf6_main.c @@ -103,7 +103,11 @@ static void __attribute__((noreturn)) ospf6_exit(int status) zclient_free(zclient); } + ospf6_master_delete(); + frr_fini(); + + keychain_terminate(); exit(status); } @@ -173,6 +177,32 @@ FRR_DAEMON_INFO(ospf6d, OSPF6, .vty_port = OSPF6_VTY_PORT, .n_yang_modules = array_size(ospf6d_yang_modules), ); +/* Max wait time for config to load before accepting hellos */ +#define OSPF6_PRE_CONFIG_MAX_WAIT_SECONDS 600 + +static void ospf6_config_finish(struct event *t) +{ + zlog_err("OSPF6 configuration end timer expired after %d seconds.", + OSPF6_PRE_CONFIG_MAX_WAIT_SECONDS); +} + +static void ospf6_config_start(void) +{ + if (IS_OSPF6_DEBUG_EVENT) + zlog_debug("ospf6d config start received"); + EVENT_OFF(t_ospf6_cfg); + event_add_timer(master, ospf6_config_finish, NULL, + OSPF6_PRE_CONFIG_MAX_WAIT_SECONDS, &t_ospf6_cfg); +} + +static void ospf6_config_end(void) +{ + if (IS_OSPF6_DEBUG_EVENT) + zlog_debug("ospf6d config end received"); + + EVENT_OFF(t_ospf6_cfg); +} + /* Main routine of ospf6d. Treatment of argument and starting ospf finite state machine is handled here. */ int main(int argc, char *argv[], char *envp[]) @@ -217,6 +247,9 @@ int main(int argc, char *argv[], char *envp[]) /* initialize ospf6 */ ospf6_init(master); + /* Configuration processing callback initialization. */ + cmd_init_config_callbacks(ospf6_config_start, ospf6_config_end); + frr_config_fork(); frr_run(master); diff --git a/ospf6d/ospf6_message.c b/ospf6d/ospf6_message.c index 032988a91f..d13799c0e8 100644 --- a/ospf6d/ospf6_message.c +++ b/ospf6d/ospf6_message.c @@ -268,6 +268,18 @@ static struct ospf6_packet *ospf6_packet_new(size_t size) return new; } +static struct ospf6_packet *ospf6_packet_dup(struct ospf6_packet *old) +{ + struct ospf6_packet *new; + + new = XCALLOC(MTYPE_OSPF6_PACKET, sizeof(struct ospf6_packet)); + new->s = stream_dup(old->s); + new->dst = old->dst; + new->length = old->length; + + return new; +} + static void ospf6_packet_free(struct ospf6_packet *op) { if (op->s) @@ -407,6 +419,25 @@ static void ospf6_hello_recv(struct in6_addr *src, struct in6_addr *dst, hello = (struct ospf6_hello *)((caddr_t)oh + sizeof(struct ospf6_header)); + if ((oi->state == OSPF6_INTERFACE_POINTTOPOINT + || oi->state == OSPF6_INTERFACE_POINTTOMULTIPOINT) + && oi->p2xp_only_cfg_neigh) { + /* NEVER, never, ever, do this on broadcast (or NBMA)! + * DR/BDR election requires everyone to talk to everyone else + * only for PtP/PtMP we can be selective in adjacencies! + */ + struct ospf6_if_p2xp_neighcfg *p2xp_cfg; + + p2xp_cfg = ospf6_if_p2xp_find(oi, src); + if (!p2xp_cfg) { + if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR)) + zlog_debug( + "ignoring PtP/PtMP hello from %pI6, neighbor not configured", + src); + return; + } + } + /* HelloInterval check */ if (ntohs(hello->hello_interval) != oi->hello_interval) { zlog_warn( @@ -479,7 +510,7 @@ static void ospf6_hello_recv(struct in6_addr *src, struct in6_addr *dst, on->hello_in++; /* Always override neighbor's source address */ - memcpy(&on->linklocal_addr, src, sizeof(struct in6_addr)); + ospf6_neighbor_lladdr_set(on, src); /* Neighbor ifindex check */ if (on->ifindex != (ifindex_t)ntohl(hello->interface_id)) { @@ -535,9 +566,9 @@ static void ospf6_hello_recv(struct in6_addr *src, struct in6_addr *dst, oi->hello_in++; /* Execute neighbor events */ - event_execute(master, hello_received, on, 0); + event_execute(master, hello_received, on, 0, NULL); if (twoway) - event_execute(master, twoway_received, on, 0); + event_execute(master, twoway_received, on, 0, NULL); else { if (OSPF6_GR_IS_ACTIVE_HELPER(on)) { if (IS_DEBUG_OSPF6_GR) @@ -553,7 +584,7 @@ static void ospf6_hello_recv(struct in6_addr *src, struct in6_addr *dst, * receives one_way hellow when it acts as HELPER for * that specific neighbor. */ - event_execute(master, oneway_received, on, 0); + event_execute(master, oneway_received, on, 0, NULL); } } @@ -624,15 +655,15 @@ static void ospf6_dbdesc_recv_master(struct ospf6_header *oh, return; case OSPF6_NEIGHBOR_INIT: - event_execute(master, twoway_received, on, 0); + event_execute(master, twoway_received, on, 0, NULL); if (on->state != OSPF6_NEIGHBOR_EXSTART) { if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR)) zlog_debug( "Neighbor state is not ExStart, ignore"); return; } - /* else fall through to ExStart */ - /* fallthru */ + /* else fall through to ExStart */ + fallthrough; case OSPF6_NEIGHBOR_EXSTART: /* if neighbor obeys us as our slave, schedule negotiation_done and process LSA Headers. Otherwise, ignore this message */ @@ -640,7 +671,7 @@ static void ospf6_dbdesc_recv_master(struct ospf6_header *oh, && !CHECK_FLAG(dbdesc->bits, OSPF6_DBDESC_IBIT) && ntohl(dbdesc->seqnum) == on->dbdesc_seqnum) { /* execute NegotiationDone */ - event_execute(master, negotiation_done, on, 0); + event_execute(master, negotiation_done, on, 0, NULL); /* Record neighbor options */ memcpy(on->options, dbdesc->options, @@ -650,8 +681,8 @@ static void ospf6_dbdesc_recv_master(struct ospf6_header *oh, on->ospf6_if->interface->vrf->name, on->name); return; } - /* fall through to exchange */ - + /* fall through to exchange */ + fallthrough; case OSPF6_NEIGHBOR_EXCHANGE: if (!memcmp(dbdesc, &on->dbdesc_last, sizeof(struct ospf6_dbdesc))) { @@ -828,15 +859,15 @@ static void ospf6_dbdesc_recv_slave(struct ospf6_header *oh, return; case OSPF6_NEIGHBOR_INIT: - event_execute(master, twoway_received, on, 0); + event_execute(master, twoway_received, on, 0, NULL); if (on->state != OSPF6_NEIGHBOR_EXSTART) { if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR)) zlog_debug( "Neighbor state is not ExStart, ignore"); return; } - /* else fall through to ExStart */ - /* fallthru */ + /* else fall through to ExStart */ + fallthrough; case OSPF6_NEIGHBOR_EXSTART: /* If the neighbor is Master, act as Slave. Schedule negotiation_done @@ -855,7 +886,7 @@ static void ospf6_dbdesc_recv_slave(struct ospf6_header *oh, on->dbdesc_seqnum = ntohl(dbdesc->seqnum); /* schedule NegotiationDone */ - event_execute(master, negotiation_done, on, 0); + event_execute(master, negotiation_done, on, 0, NULL); /* Record neighbor options */ memcpy(on->options, dbdesc->options, @@ -2239,8 +2270,6 @@ static void ospf6_write(struct event *thread) void ospf6_hello_send(struct event *thread) { struct ospf6_interface *oi; - struct ospf6_packet *op; - uint16_t length = OSPF6_HEADER_SIZE; oi = (struct ospf6_interface *)EVENT_ARG(thread); @@ -2248,6 +2277,17 @@ void ospf6_hello_send(struct event *thread) if (oi->gr.hello_delay.t_grace_send) return; + /* Check if config is still being processed */ + if (event_is_scheduled(t_ospf6_cfg)) { + if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_HELLO, SEND)) + zlog_debug( + "Suppressing Hello on interface %s during config load", + oi->interface->name); + event_add_timer(master, ospf6_hello_send, oi, + oi->hello_interval, &oi->thread_send_hello); + return; + } + if (oi->state <= OSPF6_INTERFACE_DOWN) { if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_HELLO, SEND_HDR)) zlog_debug("Unable to send Hello on down interface %s", @@ -2255,6 +2295,20 @@ void ospf6_hello_send(struct event *thread) return; } + event_add_timer(master, ospf6_hello_send, oi, oi->hello_interval, + &oi->thread_send_hello); + + ospf6_hello_send_addr(oi, NULL); +} + +/* used to send polls for PtP/PtMP too */ +void ospf6_hello_send_addr(struct ospf6_interface *oi, + const struct in6_addr *addr) +{ + struct ospf6_packet *op; + uint16_t length = OSPF6_HEADER_SIZE; + bool anything = false; + op = ospf6_packet_new(oi->ifmtu); ospf6_make_header(OSPF6_MESSAGE_TYPE_HELLO, oi, op->s); @@ -2273,20 +2327,40 @@ void ospf6_hello_send(struct event *thread) /* Set packet length. */ op->length = length; - op->dst = allspfrouters6; - - ospf6_fill_hdr_checksum(oi, op); + if ((oi->state == OSPF6_INTERFACE_POINTTOPOINT + || oi->state == OSPF6_INTERFACE_POINTTOMULTIPOINT) + && !addr && oi->p2xp_no_multicast_hello) { + struct listnode *node; + struct ospf6_neighbor *on; + struct ospf6_packet *opdup; + + for (ALL_LIST_ELEMENTS_RO(oi->neighbor_list, node, on)) { + if (on->state < OSPF6_NEIGHBOR_INIT) + /* poll-interval for these */ + continue; + + opdup = ospf6_packet_dup(op); + opdup->dst = on->linklocal_addr; + ospf6_fill_hdr_checksum(oi, opdup); + ospf6_packet_add_top(oi, opdup); + anything = true; + } - /* Add packet to the top of the interface output queue, so that they - * can't get delayed by things like long queues of LS Update packets - */ - ospf6_packet_add_top(oi, op); + ospf6_packet_free(op); + } else { + op->dst = addr ? *addr : allspfrouters6; - /* set next thread */ - event_add_timer(master, ospf6_hello_send, oi, oi->hello_interval, - &oi->thread_send_hello); + /* Add packet to the top of the interface output queue, so that + * they can't get delayed by things like long queues of LS + * Update packets + */ + ospf6_fill_hdr_checksum(oi, op); + ospf6_packet_add_top(oi, op); + anything = true; + } - OSPF6_MESSAGE_WRITE_ON(oi); + if (anything) + OSPF6_MESSAGE_WRITE_ON(oi); } static uint16_t ospf6_make_dbdesc(struct ospf6_neighbor *on, struct stream *s) @@ -2324,9 +2398,9 @@ static uint16_t ospf6_make_dbdesc(struct ospf6_neighbor *on, struct stream *s) if ((length + sizeof(struct ospf6_lsa_header) + OSPF6_HEADER_SIZE) > ospf6_packet_max(on->ospf6_if)) { - ospf6_lsa_unlock(lsa); + ospf6_lsa_unlock(&lsa); if (lsanext) - ospf6_lsa_unlock(lsanext); + ospf6_lsa_unlock(&lsanext); break; } stream_put(s, lsa->header, @@ -2404,9 +2478,9 @@ void ospf6_dbdesc_send_newone(struct event *thread) if (size + sizeof(struct ospf6_lsa_header) > ospf6_packet_max(on->ospf6_if)) { - ospf6_lsa_unlock(lsa); + ospf6_lsa_unlock(&lsa); if (lsanext) - ospf6_lsa_unlock(lsanext); + ospf6_lsa_unlock(&lsanext); break; } @@ -2425,7 +2499,7 @@ void ospf6_dbdesc_send_newone(struct event *thread) event_add_event(master, exchange_done, on, 0, &on->thread_exchange_done); - event_execute(master, ospf6_dbdesc_send, on, 0); + event_execute(master, ospf6_dbdesc_send, on, 0, NULL); } static uint16_t ospf6_make_lsreq(struct ospf6_neighbor *on, struct stream *s) @@ -2436,9 +2510,9 @@ static uint16_t ospf6_make_lsreq(struct ospf6_neighbor *on, struct stream *s) for (ALL_LSDB(on->request_list, lsa, lsanext)) { if ((length + OSPF6_HEADER_SIZE) > ospf6_packet_max(on->ospf6_if)) { - ospf6_lsa_unlock(lsa); + ospf6_lsa_unlock(&lsa); if (lsanext) - ospf6_lsa_unlock(lsanext); + ospf6_lsa_unlock(&lsanext); break; } stream_putw(s, 0); /* reserved */ @@ -2451,7 +2525,7 @@ static uint16_t ospf6_make_lsreq(struct ospf6_neighbor *on, struct stream *s) if (last_req != NULL) { if (on->last_ls_req != NULL) - on->last_ls_req = ospf6_lsa_unlock(on->last_ls_req); + ospf6_lsa_unlock(&on->last_ls_req); ospf6_lsa_lock(last_req); on->last_ls_req = last_req; @@ -2522,7 +2596,8 @@ void ospf6_lsreq_send(struct event *thread) /* schedule loading_done if request list is empty */ if (on->request_list->count == 0) { - event_add_event(master, loading_done, on, 0, NULL); + event_add_event(master, loading_done, on, 0, + &on->event_loading_done); return; } @@ -2565,9 +2640,7 @@ static void ospf6_send_lsupdate(struct ospf6_neighbor *on, struct ospf6_interface *oi, struct ospf6_packet *op) { - if (on) { - if ((on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT) || (on->ospf6_if->state == OSPF6_INTERFACE_DR) || (on->ospf6_if->state == OSPF6_INTERFACE_BDR)) @@ -2584,6 +2657,8 @@ static void ospf6_send_lsupdate(struct ospf6_neighbor *on, op->dst = alldrouters6; } if (oi) { + struct ospf6 *ospf6; + ospf6_fill_hdr_checksum(oi, op); ospf6_packet_add(oi, op); /* If ospf instance is being deleted, send the packet @@ -2591,12 +2666,27 @@ static void ospf6_send_lsupdate(struct ospf6_neighbor *on, */ if ((oi->area == NULL) || (oi->area->ospf6 == NULL)) return; - if (oi->area->ospf6->inst_shutdown) { + + ospf6 = oi->area->ospf6; + if (ospf6->inst_shutdown) { if (oi->on_write_q == 0) { - listnode_add(oi->area->ospf6->oi_write_q, oi); + listnode_add(ospf6->oi_write_q, oi); oi->on_write_q = 1; } - event_execute(master, ospf6_write, oi->area->ospf6, 0); + /* + * When ospf6d immediately calls event_execute + * for items in the oi_write_q. The event_execute + * will call ospf6_write and cause the oi_write_q + * to be emptied. *IF* there is already an event + * scheduled for the oi_write_q by something else + * then when it wakes up in the future and attempts + * to cycle through items in the queue it will + * assert. Let's stop the t_write event and + * if ospf6_write doesn't finish up the work + * it will schedule itself again. + */ + event_cancel(&ospf6->t_write); + event_execute(master, ospf6_write, ospf6, 0, NULL); } else OSPF6_MESSAGE_WRITE_ON(oi); } @@ -2917,9 +3007,9 @@ static uint16_t ospf6_make_lsack_interface(struct ospf6_interface *oi, event_add_event(master, ospf6_lsack_send_interface, oi, 0, &oi->thread_send_lsack); - ospf6_lsa_unlock(lsa); + ospf6_lsa_unlock(&lsa); if (lsanext) - ospf6_lsa_unlock(lsanext); + ospf6_lsa_unlock(&lsanext); break; } ospf6_lsa_age_update_to_send(lsa, oi->transdelay); diff --git a/ospf6d/ospf6_message.h b/ospf6d/ospf6_message.h index 2b25b07445..24340793ff 100644 --- a/ospf6d/ospf6_message.h +++ b/ospf6d/ospf6_message.h @@ -50,6 +50,8 @@ extern unsigned char conf_debug_ospf6_message[]; #define OSPF6_MESSAGE_TYPE_ALL 0x6 /* For debug option */ #define OSPF6_MESSAGE_TYPE_MAX 0x6 /* same as OSPF6_MESSAGE_TYPE_ALL */ +struct ospf6_interface; + struct ospf6_packet { struct ospf6_packet *next; @@ -169,6 +171,9 @@ extern void ospf6_lsupdate_send_neighbor(struct event *thread); extern void ospf6_lsack_send_interface(struct event *thread); extern void ospf6_lsack_send_neighbor(struct event *thread); +extern void ospf6_hello_send_addr(struct ospf6_interface *oi, + const struct in6_addr *addr); + extern int config_write_ospf6_debug_message(struct vty *); extern void install_element_ospf6_debug_message(void); extern const char *ospf6_message_type(int type); diff --git a/ospf6d/ospf6_neighbor.c b/ospf6d/ospf6_neighbor.c index 42e4074522..a6089b2641 100644 --- a/ospf6d/ospf6_neighbor.c +++ b/ospf6d/ospf6_neighbor.c @@ -34,6 +34,16 @@ #include "lib/json.h" DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_NEIGHBOR, "OSPF6 neighbor"); +DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_NEIGHBOR_P2XP_CFG, + "OSPF6 PtP/PtMP neighbor config"); + +static int ospf6_if_p2xp_neighcfg_cmp(const struct ospf6_if_p2xp_neighcfg *a, + const struct ospf6_if_p2xp_neighcfg *b); + +DECLARE_RBTREE_UNIQ(ospf6_if_p2xp_neighcfgs, struct ospf6_if_p2xp_neighcfg, + item, ospf6_if_p2xp_neighcfg_cmp); + +static void p2xp_neigh_refresh(struct ospf6_neighbor *on, uint32_t prev_cost); DEFINE_HOOK(ospf6_neighbor_change, (struct ospf6_neighbor * on, int state, int next_state), @@ -42,13 +52,14 @@ DEFINE_HOOK(ospf6_neighbor_change, unsigned char conf_debug_ospf6_neighbor = 0; const char *const ospf6_neighbor_state_str[] = { - "None", "Down", "Attempt", "Init", "Twoway", - "ExStart", "ExChange", "Loading", "Full", NULL}; + "None", "Down", "Attempt", "Init", "Twoway", + "ExStart", "ExChange", "Loading", "Full", NULL +}; const char *const ospf6_neighbor_event_str[] = { - "NoEvent", "HelloReceived", "2-WayReceived", "NegotiationDone", - "ExchangeDone", "LoadingDone", "AdjOK?", "SeqNumberMismatch", - "BadLSReq", "1-WayReceived", "InactivityTimer", + "NoEvent", "HelloReceived", "2-WayReceived", "NegotiationDone", + "ExchangeDone", "LoadingDone", "AdjOK?", "SeqNumberMismatch", + "BadLSReq", "1-WayReceived", "InactivityTimer", }; int ospf6_neighbor_cmp(void *va, void *vb) @@ -98,9 +109,10 @@ static void ospf6_neighbor_clear_ls_lists(struct ospf6_neighbor *on) ospf6_lsdb_remove_all(on->summary_list); if (on->last_ls_req) { - ospf6_lsa_unlock(on->last_ls_req); + ospf6_lsa_unlock(&on->last_ls_req); on->last_ls_req = NULL; } + ospf6_lsdb_remove_all(on->request_list); for (ALL_LSDB(on->retrans_list, lsa, lsanext)) { ospf6_decrement_retrans_count(lsa); @@ -118,8 +130,7 @@ struct ospf6_neighbor *ospf6_neighbor_create(uint32_t router_id, on = XCALLOC(MTYPE_OSPF6_NEIGHBOR, sizeof(struct ospf6_neighbor)); inet_ntop(AF_INET, &router_id, buf, sizeof(buf)); - snprintf(on->name, sizeof(on->name), "%s%%%s", buf, - oi->interface->name); + snprintf(on->name, sizeof(on->name), "%s%%%s", buf, oi->interface->name); on->ospf6_if = oi; on->state = OSPF6_NEIGHBOR_DOWN; on->state_change = 0; @@ -149,6 +160,9 @@ struct ospf6_neighbor *ospf6_neighbor_create(uint32_t router_id, void ospf6_neighbor_delete(struct ospf6_neighbor *on) { + if (on->p2xp_cfg) + on->p2xp_cfg->active = NULL; + ospf6_neighbor_clear_ls_lists(on); ospf6_lsdb_remove_all(on->dbdesc_list); @@ -173,6 +187,7 @@ void ospf6_neighbor_delete(struct ospf6_neighbor *on) EVENT_OFF(on->thread_send_lsack); EVENT_OFF(on->thread_exchange_done); EVENT_OFF(on->thread_adj_ok); + EVENT_OFF(on->event_loading_done); EVENT_OFF(on->gr_helper_info.t_grace_timer); @@ -180,6 +195,22 @@ void ospf6_neighbor_delete(struct ospf6_neighbor *on) XFREE(MTYPE_OSPF6_NEIGHBOR, on); } +void ospf6_neighbor_lladdr_set(struct ospf6_neighbor *on, + const struct in6_addr *addr) +{ + if (IPV6_ADDR_SAME(addr, &on->linklocal_addr)) + return; + + memcpy(&on->linklocal_addr, addr, sizeof(struct in6_addr)); + + if (on->ospf6_if->type == OSPF_IFTYPE_POINTOPOINT || + on->ospf6_if->type == OSPF_IFTYPE_POINTOMULTIPOINT) { + uint32_t prev_cost = ospf6_neighbor_cost(on); + + p2xp_neigh_refresh(on, prev_cost); + } +} + static void ospf6_neighbor_state_change(uint8_t next_state, struct ospf6_neighbor *on, int event) { @@ -196,31 +227,28 @@ static void ospf6_neighbor_state_change(uint8_t next_state, /* log */ if (IS_OSPF6_DEBUG_NEIGHBOR(STATE)) { - zlog_debug( - "Neighbor state change %s (Router-ID: %pI4): [%s]->[%s] (%s)", - on->name, &on->router_id, - ospf6_neighbor_state_str[prev_state], - ospf6_neighbor_state_str[next_state], - ospf6_neighbor_event_string(event)); + zlog_debug("Neighbor state change %s (Router-ID: %pI4): [%s]->[%s] (%s)", + on->name, &on->router_id, + ospf6_neighbor_state_str[prev_state], + ospf6_neighbor_state_str[next_state], + ospf6_neighbor_event_string(event)); } /* Optionally notify about adjacency changes */ if (CHECK_FLAG(on->ospf6_if->area->ospf6->config_flags, - OSPF6_LOG_ADJACENCY_CHANGES) - && (CHECK_FLAG(on->ospf6_if->area->ospf6->config_flags, - OSPF6_LOG_ADJACENCY_DETAIL) - || (next_state == OSPF6_NEIGHBOR_FULL) - || (next_state < prev_state))) - zlog_notice( - "AdjChg: Nbr %pI4(%s) on %s: %s -> %s (%s)", - &on->router_id, - vrf_id_to_name(on->ospf6_if->interface->vrf->vrf_id), - on->name, ospf6_neighbor_state_str[prev_state], - ospf6_neighbor_state_str[next_state], - ospf6_neighbor_event_string(event)); - - if (prev_state == OSPF6_NEIGHBOR_FULL - || next_state == OSPF6_NEIGHBOR_FULL) { + OSPF6_LOG_ADJACENCY_CHANGES) && + (CHECK_FLAG(on->ospf6_if->area->ospf6->config_flags, + OSPF6_LOG_ADJACENCY_DETAIL) || + (next_state == OSPF6_NEIGHBOR_FULL) || (next_state < prev_state))) + zlog_notice("AdjChg: Nbr %pI4(%s) on %s: %s -> %s (%s)", + &on->router_id, + vrf_id_to_name(on->ospf6_if->interface->vrf->vrf_id), + on->name, ospf6_neighbor_state_str[prev_state], + ospf6_neighbor_state_str[next_state], + ospf6_neighbor_event_string(event)); + + if (prev_state == OSPF6_NEIGHBOR_FULL || + next_state == OSPF6_NEIGHBOR_FULL) { if (!OSPF6_GR_IS_ACTIVE_HELPER(on)) { OSPF6_ROUTER_LSA_SCHEDULE(on->ospf6_if->area); if (on->ospf6_if->state == OSPF6_INTERFACE_DR) { @@ -233,12 +261,11 @@ static void ospf6_neighbor_state_change(uint8_t next_state, on->ospf6_if->area->intra_prefix_originate = 1; if (!OSPF6_GR_IS_ACTIVE_HELPER(on)) - OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB( - on->ospf6_if->area); + OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(on->ospf6_if->area); - if ((prev_state == OSPF6_NEIGHBOR_LOADING - || prev_state == OSPF6_NEIGHBOR_EXCHANGE) - && next_state == OSPF6_NEIGHBOR_FULL) { + if ((prev_state == OSPF6_NEIGHBOR_LOADING || + prev_state == OSPF6_NEIGHBOR_EXCHANGE) && + next_state == OSPF6_NEIGHBOR_FULL) { OSPF6_AS_EXTERN_LSA_SCHEDULE(on->ospf6_if); on->ospf6_if->area->full_nbrs++; } @@ -247,10 +274,10 @@ static void ospf6_neighbor_state_change(uint8_t next_state, on->ospf6_if->area->full_nbrs--; } - if ((prev_state == OSPF6_NEIGHBOR_EXCHANGE - || prev_state == OSPF6_NEIGHBOR_LOADING) - && (next_state != OSPF6_NEIGHBOR_EXCHANGE - && next_state != OSPF6_NEIGHBOR_LOADING)) + if ((prev_state == OSPF6_NEIGHBOR_EXCHANGE || + prev_state == OSPF6_NEIGHBOR_LOADING) && + (next_state != OSPF6_NEIGHBOR_EXCHANGE && + next_state != OSPF6_NEIGHBOR_LOADING)) ospf6_maxage_remove(on->ospf6_if->area->ospf6); hook_call(ospf6_neighbor_change, on, next_state, prev_state); @@ -260,13 +287,14 @@ static void ospf6_neighbor_state_change(uint8_t next_state, /* RFC2328 section 10.4 */ static int need_adjacency(struct ospf6_neighbor *on) { - if (on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT - || on->ospf6_if->state == OSPF6_INTERFACE_DR - || on->ospf6_if->state == OSPF6_INTERFACE_BDR) + if (on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT || + on->ospf6_if->state == OSPF6_INTERFACE_POINTTOMULTIPOINT || + on->ospf6_if->state == OSPF6_INTERFACE_DR || + on->ospf6_if->state == OSPF6_INTERFACE_BDR) return 1; - if (on->ospf6_if->drouter == on->router_id - || on->ospf6_if->bdrouter == on->router_id) + if (on->ospf6_if->drouter == on->router_id || + on->ospf6_if->bdrouter == on->router_id) return 1; return 0; @@ -420,15 +448,15 @@ void exchange_done(struct event *thread) /* Check loading state. */ void ospf6_check_nbr_loading(struct ospf6_neighbor *on) { - /* RFC2328 Section 10.9: When the neighbor responds to these requests with the proper Link State Update packet(s), the Link state request list is truncated and a new Link State Request packet is sent. */ - if ((on->state == OSPF6_NEIGHBOR_LOADING) - || (on->state == OSPF6_NEIGHBOR_EXCHANGE)) { + if ((on->state == OSPF6_NEIGHBOR_LOADING) || + (on->state == OSPF6_NEIGHBOR_EXCHANGE)) { if (on->request_list->count == 0) - event_add_event(master, loading_done, on, 0, NULL); + event_add_event(master, loading_done, on, 0, + &on->event_loading_done); else if (on->last_ls_req == NULL) { EVENT_OFF(on->thread_send_lsreq); event_add_event(master, ospf6_lsreq_send, on, 0, @@ -584,9 +612,8 @@ void inactivity_timer(struct event *thread) on->drouter = on->prev_drouter = 0; on->bdrouter = on->prev_bdrouter = 0; - ospf6_neighbor_state_change( - OSPF6_NEIGHBOR_DOWN, on, - OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER); + ospf6_neighbor_state_change(OSPF6_NEIGHBOR_DOWN, on, + OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER); event_add_event(master, neighbor_change, on->ospf6_if, 0, NULL); listnode_delete(on->ospf6_if->neighbor_list, on); @@ -594,9 +621,8 @@ void inactivity_timer(struct event *thread) } else { if (IS_DEBUG_OSPF6_GR) - zlog_debug( - "%s, Acting as HELPER for this neighbour, So restart the dead timer.", - __PRETTY_FUNCTION__); + zlog_debug("%s, Acting as HELPER for this neighbour, So restart the dead timer.", + __PRETTY_FUNCTION__); event_add_timer(master, inactivity_timer, on, on->ospf6_if->dead_interval, @@ -604,8 +630,224 @@ void inactivity_timer(struct event *thread) } } +/* P2P/P2MP stuff */ + +uint32_t ospf6_neighbor_cost(struct ospf6_neighbor *on) +{ + if (on->p2xp_cfg && on->p2xp_cfg->cfg_cost) + return on->p2xp_cfg->cost; + return on->ospf6_if->cost; +} + +static int ospf6_if_p2xp_neighcfg_cmp(const struct ospf6_if_p2xp_neighcfg *a, + const struct ospf6_if_p2xp_neighcfg *b) +{ + return IPV6_ADDR_CMP(&a->addr, &b->addr); +} + +struct ospf6_if_p2xp_neighcfg *ospf6_if_p2xp_find(struct ospf6_interface *oi, + const struct in6_addr *addr) +{ + struct ospf6_if_p2xp_neighcfg ref; + + if (!oi) + return NULL; + + ref.addr = *addr; + return ospf6_if_p2xp_neighcfgs_find(&oi->p2xp_neighs, &ref); +} + +static struct ospf6_if_p2xp_neighcfg * +ospf6_if_p2xp_get(struct ospf6_interface *oi, const struct in6_addr *addr) +{ + struct ospf6_if_p2xp_neighcfg ref, *ret; + + if (!oi) + return NULL; + + ref.addr = *addr; + ret = ospf6_if_p2xp_neighcfgs_find(&oi->p2xp_neighs, &ref); + if (!ret) { + ret = XCALLOC(MTYPE_OSPF6_NEIGHBOR_P2XP_CFG, sizeof(*ret)); + ret->addr = *addr; + ret->ospf6_if = oi; + + ospf6_if_p2xp_neighcfgs_add(&oi->p2xp_neighs, ret); + } + + return ret; +} + +static void ospf6_if_p2xp_destroy(struct ospf6_if_p2xp_neighcfg *p2xp_cfg) +{ + EVENT_OFF(p2xp_cfg->t_unicast_hello); + ospf6_if_p2xp_neighcfgs_del(&p2xp_cfg->ospf6_if->p2xp_neighs, p2xp_cfg); + + XFREE(MTYPE_OSPF6_NEIGHBOR_P2XP_CFG, p2xp_cfg); +} + +static void p2xp_neigh_refresh(struct ospf6_neighbor *on, uint32_t prev_cost) +{ + if (on->p2xp_cfg) + on->p2xp_cfg->active = NULL; + on->p2xp_cfg = ospf6_if_p2xp_find(on->ospf6_if, &on->linklocal_addr); + if (on->p2xp_cfg) + on->p2xp_cfg->active = on; + + if (ospf6_neighbor_cost(on) != prev_cost) + OSPF6_ROUTER_LSA_SCHEDULE(on->ospf6_if->area); +} /* vty functions */ + +#ifndef VTYSH_EXTRACT_PL +#include "ospf6d/ospf6_neighbor_clippy.c" +#endif + +DEFPY(ipv6_ospf6_p2xp_neigh, ipv6_ospf6_p2xp_neigh_cmd, + "[no] ipv6 ospf6 neighbor X:X::X:X", + NO_STR IP6_STR OSPF6_STR "Configure static neighbor\n" + "Neighbor link-local address\n") +{ + VTY_DECLVAR_CONTEXT(interface, ifp); + struct ospf6_interface *oi = ifp->info; + struct ospf6_if_p2xp_neighcfg *p2xp_cfg; + + if (!oi) { + if (no) + return CMD_SUCCESS; + oi = ospf6_interface_create(ifp); + } + + if (no) { + struct ospf6_neighbor *on; + uint32_t prev_cost = 0; + + p2xp_cfg = ospf6_if_p2xp_find(oi, &neighbor); + if (!p2xp_cfg) + return CMD_SUCCESS; + + on = p2xp_cfg->active; + if (on) + prev_cost = ospf6_neighbor_cost(on); + + p2xp_cfg->active = NULL; + ospf6_if_p2xp_destroy(p2xp_cfg); + + if (on) { + on->p2xp_cfg = NULL; + p2xp_neigh_refresh(on, prev_cost); + } + return CMD_SUCCESS; + } + + (void)ospf6_if_p2xp_get(oi, &neighbor); + return CMD_SUCCESS; +} + +DEFPY(ipv6_ospf6_p2xp_neigh_cost, ipv6_ospf6_p2xp_neigh_cost_cmd, + "[no] ipv6 ospf6 neighbor X:X::X:X cost (1-65535)", + NO_STR IP6_STR OSPF6_STR "Configure static neighbor\n" + "Neighbor link-local address\n" + "Outgoing metric for this neighbor\n" + "Outgoing metric for this neighbor\n") +{ + VTY_DECLVAR_CONTEXT(interface, ifp); + struct ospf6_interface *oi = ifp->info; + struct ospf6_if_p2xp_neighcfg *p2xp_cfg; + uint32_t prev_cost = 0; + + if (!oi) { + if (no) + return CMD_SUCCESS; + oi = ospf6_interface_create(ifp); + } + + p2xp_cfg = ospf6_if_p2xp_get(oi, &neighbor); + + if (p2xp_cfg->active) + prev_cost = ospf6_neighbor_cost(p2xp_cfg->active); + + if (no) { + p2xp_cfg->cfg_cost = false; + p2xp_cfg->cost = 0; + } else { + p2xp_cfg->cfg_cost = true; + p2xp_cfg->cost = cost; + } + + if (p2xp_cfg->active) + p2xp_neigh_refresh(p2xp_cfg->active, prev_cost); + return CMD_SUCCESS; +} + +static void p2xp_unicast_hello_send(struct event *event); + +static void p2xp_unicast_hello_sched(struct ospf6_if_p2xp_neighcfg *p2xp_cfg) +{ + if (!p2xp_cfg->poll_interval || + (p2xp_cfg->ospf6_if->state != OSPF6_INTERFACE_POINTTOMULTIPOINT && + p2xp_cfg->ospf6_if->state != OSPF6_INTERFACE_POINTTOPOINT)) + /* state check covers DOWN state too */ + EVENT_OFF(p2xp_cfg->t_unicast_hello); + else + event_add_timer(master, p2xp_unicast_hello_send, p2xp_cfg, + p2xp_cfg->poll_interval, + &p2xp_cfg->t_unicast_hello); +} + +void ospf6_if_p2xp_up(struct ospf6_interface *oi) +{ + struct ospf6_if_p2xp_neighcfg *p2xp_cfg; + + frr_each (ospf6_if_p2xp_neighcfgs, &oi->p2xp_neighs, p2xp_cfg) + p2xp_unicast_hello_sched(p2xp_cfg); +} + +static void p2xp_unicast_hello_send(struct event *event) +{ + struct ospf6_if_p2xp_neighcfg *p2xp_cfg = EVENT_ARG(event); + struct ospf6_interface *oi = p2xp_cfg->ospf6_if; + + if (oi->state != OSPF6_INTERFACE_POINTTOPOINT && + oi->state != OSPF6_INTERFACE_POINTTOMULTIPOINT) + return; + + p2xp_unicast_hello_sched(p2xp_cfg); + + if (p2xp_cfg->active && p2xp_cfg->active->state >= OSPF6_NEIGHBOR_INIT) + return; + + ospf6_hello_send_addr(oi, &p2xp_cfg->addr); +} + +DEFPY(ipv6_ospf6_p2xp_neigh_poll_interval, + ipv6_ospf6_p2xp_neigh_poll_interval_cmd, + "[no] ipv6 ospf6 neighbor X:X::X:X poll-interval (1-65535)", + NO_STR IP6_STR OSPF6_STR "Configure static neighbor\n" + "Neighbor link-local address\n" + "Send unicast hellos to neighbor when down\n" + "Unicast hello interval when down (seconds)\n") +{ + VTY_DECLVAR_CONTEXT(interface, ifp); + struct ospf6_interface *oi = ifp->info; + struct ospf6_if_p2xp_neighcfg *p2xp_cfg; + + if (!oi) { + if (no) + return CMD_SUCCESS; + oi = ospf6_interface_create(ifp); + } + if (no) + poll_interval = 0; + + p2xp_cfg = ospf6_if_p2xp_get(oi, &neighbor); + p2xp_cfg->poll_interval = poll_interval; + + p2xp_unicast_hello_sched(p2xp_cfg); + return CMD_SUCCESS; +} + /* show neighbor structure */ static void ospf6_neighbor_show(struct vty *vty, struct ospf6_neighbor *on, json_object *json_array, bool use_json) @@ -628,8 +870,8 @@ static void ospf6_neighbor_show(struct vty *vty, struct ospf6_neighbor *on, /* Dead time */ h = m = s = 0; if (on->inactivity_timer) { - s = monotime_until(&on->inactivity_timer->u.sands, NULL) - / 1000000LL; + s = monotime_until(&on->inactivity_timer->u.sands, NULL) / + 1000000LL; h = s / 3600; s -= h * 3600; m = s / 60; @@ -640,6 +882,8 @@ static void ospf6_neighbor_show(struct vty *vty, struct ospf6_neighbor *on, /* Neighbor State */ if (on->ospf6_if->type == OSPF_IFTYPE_POINTOPOINT) snprintf(nstate, sizeof(nstate), "PointToPoint"); + else if (on->ospf6_if->type == OSPF_IFTYPE_POINTOMULTIPOINT) + snprintf(nstate, sizeof(nstate), "PtMultipoint"); else { if (on->router_id == on->drouter) snprintf(nstate, sizeof(nstate), "DR"); @@ -670,9 +914,9 @@ static void ospf6_neighbor_show(struct vty *vty, struct ospf6_neighbor *on, json_object_string_add(json_route, "duration", duration); json_object_string_add(json_route, "interfaceName", on->ospf6_if->interface->name); - json_object_string_add( - json_route, "interfaceState", - ospf6_interface_state_str[on->ospf6_if->state]); + json_object_string_add(json_route, "interfaceState", + ospf6_interface_state_str + [on->ospf6_if->state]); json_object_array_add(json_array, json_route); } else @@ -717,9 +961,9 @@ static void ospf6_neighbor_show_drchoice(struct vty *vty, json_object_string_add(json_route, "bdRouter", bdrouter); json_object_string_add(json_route, "interfaceName", on->ospf6_if->interface->name); - json_object_string_add( - json_route, "interfaceState", - ospf6_interface_state_str[on->ospf6_if->state]); + json_object_string_add(json_route, "interfaceState", + ospf6_interface_state_str + [on->ospf6_if->state]); json_object_array_add(json_array, json_route); } else @@ -774,9 +1018,8 @@ static void ospf6_neighbor_show_detail(struct vty *vty, (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT) ? "Initial " : ""), - (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT) - ? "More" - : ""), + (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT) ? "More" + : ""), (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT) ? "Master" : "Slave")); @@ -790,8 +1033,8 @@ static void ospf6_neighbor_show_detail(struct vty *vty, json_object_int_add(json_neighbor, "summaryListCount", on->summary_list->count); for (ALL_LSDB(on->summary_list, lsa, lsanext)) - json_object_array_add( - json_array, json_object_new_string(lsa->name)); + json_object_array_add(json_array, + json_object_new_string(lsa->name)); json_object_object_add(json_neighbor, "summaryListLsa", json_array); @@ -799,8 +1042,8 @@ static void ospf6_neighbor_show_detail(struct vty *vty, json_object_int_add(json_neighbor, "requestListCount", on->request_list->count); for (ALL_LSDB(on->request_list, lsa, lsanext)) - json_object_array_add( - json_array, json_object_new_string(lsa->name)); + json_object_array_add(json_array, + json_object_new_string(lsa->name)); json_object_object_add(json_neighbor, "requestListLsa", json_array); @@ -808,8 +1051,8 @@ static void ospf6_neighbor_show_detail(struct vty *vty, json_object_int_add(json_neighbor, "reTransListCount", on->retrans_list->count); for (ALL_LSDB(on->retrans_list, lsa, lsanext)) - json_object_array_add( - json_array, json_object_new_string(lsa->name)); + json_object_array_add(json_array, + json_object_new_string(lsa->name)); json_object_object_add(json_neighbor, "reTransListLsa", json_array); @@ -822,14 +1065,14 @@ static void ospf6_neighbor_show_detail(struct vty *vty, on->dbdesc_list->count); json_object_string_add(json_neighbor, "pendingLsaDbDescTime", duration); - json_object_string_add( - json_neighbor, "dbDescSendThread", - (event_is_scheduled(on->thread_send_dbdesc) ? "on" - : "off")); + json_object_string_add(json_neighbor, "dbDescSendThread", + (event_is_scheduled(on->thread_send_dbdesc) + ? "on" + : "off")); json_array = json_object_new_array(); for (ALL_LSDB(on->dbdesc_list, lsa, lsanext)) - json_object_array_add( - json_array, json_object_new_string(lsa->name)); + json_object_array_add(json_array, + json_object_new_string(lsa->name)); json_object_object_add(json_neighbor, "pendingLsaDbDesc", json_array); @@ -841,35 +1084,35 @@ static void ospf6_neighbor_show_detail(struct vty *vty, on->request_list->count); json_object_string_add(json_neighbor, "pendingLsaLsReqTime", duration); - json_object_string_add( - json_neighbor, "lsReqSendThread", - (event_is_scheduled(on->thread_send_lsreq) ? "on" - : "off")); + json_object_string_add(json_neighbor, "lsReqSendThread", + (event_is_scheduled(on->thread_send_lsreq) + ? "on" + : "off")); json_array = json_object_new_array(); for (ALL_LSDB(on->request_list, lsa, lsanext)) - json_object_array_add( - json_array, json_object_new_string(lsa->name)); + json_object_array_add(json_array, + json_object_new_string(lsa->name)); json_object_object_add(json_neighbor, "pendingLsaLsReq", json_array); timerclear(&res); if (event_is_scheduled(on->thread_send_lsupdate)) - timersub(&on->thread_send_lsupdate->u.sands, &now, - &res); + timersub(&on->thread_send_lsupdate->u.sands, &now, &res); timerstring(&res, duration, sizeof(duration)); json_object_int_add(json_neighbor, "pendingLsaLsUpdateCount", on->lsupdate_list->count); json_object_string_add(json_neighbor, "pendingLsaLsUpdateTime", duration); - json_object_string_add( - json_neighbor, "lsUpdateSendThread", - (event_is_scheduled(on->thread_send_lsupdate) ? "on" - : "off")); + json_object_string_add(json_neighbor, "lsUpdateSendThread", + (event_is_scheduled( + on->thread_send_lsupdate) + ? "on" + : "off")); json_array = json_object_new_array(); for (ALL_LSDB(on->lsupdate_list, lsa, lsanext)) - json_object_array_add( - json_array, json_object_new_string(lsa->name)); + json_object_array_add(json_array, + json_object_new_string(lsa->name)); json_object_object_add(json_neighbor, "pendingLsaLsUpdate", json_array); @@ -881,14 +1124,14 @@ static void ospf6_neighbor_show_detail(struct vty *vty, on->lsack_list->count); json_object_string_add(json_neighbor, "pendingLsaLsAckTime", duration); - json_object_string_add( - json_neighbor, "lsAckSendThread", - (event_is_scheduled(on->thread_send_lsack) ? "on" - : "off")); + json_object_string_add(json_neighbor, "lsAckSendThread", + (event_is_scheduled(on->thread_send_lsack) + ? "on" + : "off")); json_array = json_object_new_array(); for (ALL_LSDB(on->lsack_list, lsa, lsanext)) - json_object_array_add( - json_array, json_object_new_string(lsa->name)); + json_object_array_add(json_array, + json_object_new_string(lsa->name)); json_object_object_add(json_neighbor, "pendingLsaLsAck", json_array); @@ -897,36 +1140,36 @@ static void ospf6_neighbor_show_detail(struct vty *vty, if (on->auth_present == true) { json_object_string_add(json_neighbor, "authStatus", "enabled"); - json_object_int_add( - json_neighbor, "recvdHelloHigherSeqNo", - on->seqnum_h[OSPF6_MESSAGE_TYPE_HELLO]); - json_object_int_add( - json_neighbor, "recvdHelloLowerSeqNo", - on->seqnum_l[OSPF6_MESSAGE_TYPE_HELLO]); - json_object_int_add( - json_neighbor, "recvdDBDescHigherSeqNo", - on->seqnum_h[OSPF6_MESSAGE_TYPE_DBDESC]); - json_object_int_add( - json_neighbor, "recvdDBDescLowerSeqNo", - on->seqnum_l[OSPF6_MESSAGE_TYPE_DBDESC]); - json_object_int_add( - json_neighbor, "recvdLSReqHigherSeqNo", - on->seqnum_h[OSPF6_MESSAGE_TYPE_LSREQ]); - json_object_int_add( - json_neighbor, "recvdLSReqLowerSeqNo", - on->seqnum_l[OSPF6_MESSAGE_TYPE_LSREQ]); - json_object_int_add( - json_neighbor, "recvdLSUpdHigherSeqNo", - on->seqnum_h[OSPF6_MESSAGE_TYPE_LSUPDATE]); - json_object_int_add( - json_neighbor, "recvdLSUpdLowerSeqNo", - on->seqnum_l[OSPF6_MESSAGE_TYPE_LSUPDATE]); - json_object_int_add( - json_neighbor, "recvdLSAckHigherSeqNo", - on->seqnum_h[OSPF6_MESSAGE_TYPE_LSACK]); - json_object_int_add( - json_neighbor, "recvdLSAckLowerSeqNo", - on->seqnum_l[OSPF6_MESSAGE_TYPE_LSACK]); + json_object_int_add(json_neighbor, + "recvdHelloHigherSeqNo", + on->seqnum_h[OSPF6_MESSAGE_TYPE_HELLO]); + json_object_int_add(json_neighbor, + "recvdHelloLowerSeqNo", + on->seqnum_l[OSPF6_MESSAGE_TYPE_HELLO]); + json_object_int_add(json_neighbor, + "recvdDBDescHigherSeqNo", + on->seqnum_h[OSPF6_MESSAGE_TYPE_DBDESC]); + json_object_int_add(json_neighbor, + "recvdDBDescLowerSeqNo", + on->seqnum_l[OSPF6_MESSAGE_TYPE_DBDESC]); + json_object_int_add(json_neighbor, + "recvdLSReqHigherSeqNo", + on->seqnum_h[OSPF6_MESSAGE_TYPE_LSREQ]); + json_object_int_add(json_neighbor, + "recvdLSReqLowerSeqNo", + on->seqnum_l[OSPF6_MESSAGE_TYPE_LSREQ]); + json_object_int_add(json_neighbor, + "recvdLSUpdHigherSeqNo", + on->seqnum_h[OSPF6_MESSAGE_TYPE_LSUPDATE]); + json_object_int_add(json_neighbor, + "recvdLSUpdLowerSeqNo", + on->seqnum_l[OSPF6_MESSAGE_TYPE_LSUPDATE]); + json_object_int_add(json_neighbor, + "recvdLSAckHigherSeqNo", + on->seqnum_h[OSPF6_MESSAGE_TYPE_LSACK]); + json_object_int_add(json_neighbor, + "recvdLSAckLowerSeqNo", + on->seqnum_l[OSPF6_MESSAGE_TYPE_LSACK]); } else json_object_string_add(json_neighbor, "authStatus", "disabled"); @@ -948,9 +1191,8 @@ static void ospf6_neighbor_show_detail(struct vty *vty, (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT) ? "Initial " : ""), - (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT) - ? "More " - : ""), + (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT) ? "More " + : ""), (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT) ? "Master" : "Slave"), @@ -997,8 +1239,7 @@ static void ospf6_neighbor_show_detail(struct vty *vty, timerclear(&res); if (event_is_scheduled(on->thread_send_lsupdate)) - timersub(&on->thread_send_lsupdate->u.sands, &now, - &res); + timersub(&on->thread_send_lsupdate->u.sands, &now, &res); timerstring(&res, duration, sizeof(duration)); vty_out(vty, " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n", @@ -1138,8 +1379,7 @@ DEFUN(show_ipv6_ospf6_neighbor, show_ipv6_ospf6_neighbor_cmd, static int ospf6_neighbor_show_common(struct vty *vty, int argc, struct cmd_token **argv, - struct ospf6 *ospf6, int idx_ipv4, - bool uj) + struct ospf6 *ospf6, int idx_ipv4, bool uj) { struct ospf6_neighbor *on; struct ospf6_interface *oi; @@ -1211,16 +1451,18 @@ void ospf6_neighbor_init(void) { install_element(VIEW_NODE, &show_ipv6_ospf6_neighbor_cmd); install_element(VIEW_NODE, &show_ipv6_ospf6_neighbor_one_cmd); + + install_element(INTERFACE_NODE, &ipv6_ospf6_p2xp_neigh_cmd); + install_element(INTERFACE_NODE, &ipv6_ospf6_p2xp_neigh_cost_cmd); + install_element(INTERFACE_NODE, + &ipv6_ospf6_p2xp_neigh_poll_interval_cmd); } -DEFUN (debug_ospf6_neighbor, - debug_ospf6_neighbor_cmd, - "debug ospf6 neighbor [<state|event>]", - DEBUG_STR - OSPF6_STR - "Debug OSPFv3 Neighbor\n" - "Debug OSPFv3 Neighbor State Change\n" - "Debug OSPFv3 Neighbor Event\n") +DEFUN(debug_ospf6_neighbor, debug_ospf6_neighbor_cmd, + "debug ospf6 neighbor [<state|event>]", + DEBUG_STR OSPF6_STR "Debug OSPFv3 Neighbor\n" + "Debug OSPFv3 Neighbor State Change\n" + "Debug OSPFv3 Neighbor Event\n") { int idx_type = 3; unsigned char level = 0; @@ -1238,15 +1480,11 @@ DEFUN (debug_ospf6_neighbor, } -DEFUN (no_debug_ospf6_neighbor, - no_debug_ospf6_neighbor_cmd, - "no debug ospf6 neighbor [<state|event>]", - NO_STR - DEBUG_STR - OSPF6_STR - "Debug OSPFv3 Neighbor\n" - "Debug OSPFv3 Neighbor State Change\n" - "Debug OSPFv3 Neighbor Event\n") +DEFUN(no_debug_ospf6_neighbor, no_debug_ospf6_neighbor_cmd, + "no debug ospf6 neighbor [<state|event>]", + NO_STR DEBUG_STR OSPF6_STR "Debug OSPFv3 Neighbor\n" + "Debug OSPFv3 Neighbor State Change\n" + "Debug OSPFv3 Neighbor Event\n") { int idx_type = 4; unsigned char level = 0; @@ -1264,12 +1502,8 @@ DEFUN (no_debug_ospf6_neighbor, } -DEFUN (no_debug_ospf6, - no_debug_ospf6_cmd, - "no debug ospf6", - NO_STR - DEBUG_STR - OSPF6_STR) +DEFUN(no_debug_ospf6, no_debug_ospf6_cmd, "no debug ospf6", + NO_STR DEBUG_STR OSPF6_STR) { unsigned int i; @@ -1284,12 +1518,11 @@ DEFUN (no_debug_ospf6, ospf6_lsa_debug_set_all(false); for (i = 0; i < 6; i++) - OSPF6_DEBUG_MESSAGE_OFF(i, - OSPF6_DEBUG_NEIGHBOR_STATE - | OSPF6_DEBUG_NEIGHBOR_EVENT); + OSPF6_DEBUG_MESSAGE_OFF(i, OSPF6_DEBUG_NEIGHBOR_STATE | + OSPF6_DEBUG_NEIGHBOR_EVENT); - OSPF6_DEBUG_NEIGHBOR_OFF(OSPF6_DEBUG_NEIGHBOR_STATE - | OSPF6_DEBUG_NEIGHBOR_EVENT); + OSPF6_DEBUG_NEIGHBOR_OFF(OSPF6_DEBUG_NEIGHBOR_STATE | + OSPF6_DEBUG_NEIGHBOR_EVENT); OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_TABLE); OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTRA); OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTER); @@ -1313,6 +1546,25 @@ int config_write_ospf6_debug_neighbor(struct vty *vty) return 0; } +int config_write_ospf6_p2xp_neighbor(struct vty *vty, struct ospf6_interface *oi) +{ + struct ospf6_if_p2xp_neighcfg *p2xp_cfg; + + frr_each (ospf6_if_p2xp_neighcfgs, &oi->p2xp_neighs, p2xp_cfg) { + vty_out(vty, " ipv6 ospf6 neighbor %pI6\n", &p2xp_cfg->addr); + + if (p2xp_cfg->poll_interval) + vty_out(vty, + " ipv6 ospf6 neighbor %pI6 poll-interval %u\n", + &p2xp_cfg->addr, p2xp_cfg->poll_interval); + + if (p2xp_cfg->cfg_cost) + vty_out(vty, " ipv6 ospf6 neighbor %pI6 cost %u\n", + &p2xp_cfg->addr, p2xp_cfg->cost); + } + return 0; +} + void install_element_ospf6_debug_neighbor(void) { install_element(ENABLE_NODE, &debug_ospf6_neighbor_cmd); diff --git a/ospf6d/ospf6_neighbor.h b/ospf6d/ospf6_neighbor.h index 5ec754d3a4..60a76215b7 100644 --- a/ospf6d/ospf6_neighbor.h +++ b/ospf6d/ospf6_neighbor.h @@ -6,8 +6,11 @@ #ifndef OSPF6_NEIGHBOR_H #define OSPF6_NEIGHBOR_H +#include "typesafe.h" #include "hook.h" +#include "ospf6_message.h" + /* Forward declaration(s). */ struct ospf6_area; @@ -52,6 +55,8 @@ struct ospf6_helper_info { uint32_t rejected_reason; }; +struct ospf6_if_p2xp_neighcfg; + /* Neighbor structure */ struct ospf6_neighbor { /* Neighbor Router ID String */ @@ -60,6 +65,11 @@ struct ospf6_neighbor { /* OSPFv3 Interface this neighbor belongs to */ struct ospf6_interface *ospf6_if; + /* P2P/P2MP config for this neighbor. + * can be NULL if not explicitly configured! + */ + struct ospf6_if_p2xp_neighcfg *p2xp_cfg; + /* Neighbor state */ uint8_t state; @@ -123,6 +133,7 @@ struct ospf6_neighbor { struct event *thread_send_lsack; struct event *thread_exchange_done; struct event *thread_adj_ok; + struct event *event_loading_done; /* BFD information */ struct bfd_session_params *bfd_session; @@ -189,6 +200,14 @@ struct ospf6_neighbor *ospf6_neighbor_create(uint32_t router_id, struct ospf6_interface *oi); void ospf6_neighbor_delete(struct ospf6_neighbor *on); +void ospf6_neighbor_lladdr_set(struct ospf6_neighbor *on, + const struct in6_addr *addr); +struct ospf6_if_p2xp_neighcfg *ospf6_if_p2xp_find(struct ospf6_interface *oi, + const struct in6_addr *addr); +void ospf6_if_p2xp_up(struct ospf6_interface *oi); + +uint32_t ospf6_neighbor_cost(struct ospf6_neighbor *on); + /* Neighbor event */ extern void hello_received(struct event *thread); extern void twoway_received(struct event *thread); @@ -204,6 +223,8 @@ extern void ospf6_check_nbr_loading(struct ospf6_neighbor *on); extern void ospf6_neighbor_init(void); extern int config_write_ospf6_debug_neighbor(struct vty *vty); +extern int config_write_ospf6_p2xp_neighbor(struct vty *vty, + struct ospf6_interface *oi); extern void install_element_ospf6_debug_neighbor(void); DECLARE_HOOK(ospf6_neighbor_change, diff --git a/ospf6d/ospf6_nssa.c b/ospf6d/ospf6_nssa.c index e7a10eba41..405ae90528 100644 --- a/ospf6d/ospf6_nssa.c +++ b/ospf6d/ospf6_nssa.c @@ -1436,7 +1436,7 @@ DEFPY (no_area_nssa_range, SET_FLAG(range->flag, OSPF6_ROUTE_REMOVE); /* Redo summaries if required */ - event_execute(master, ospf6_abr_task_timer, ospf6, 0); + event_execute(master, ospf6_abr_task_timer, ospf6, 0, NULL); } ospf6_route_remove(range, oa->nssa_range_table); diff --git a/ospf6d/ospf6_route.c b/ospf6d/ospf6_route.c index 443032933d..10a1208e93 100644 --- a/ospf6d/ospf6_route.c +++ b/ospf6d/ospf6_route.c @@ -363,7 +363,7 @@ void ospf6_route_zebra_copy_nexthops(struct ospf6_route *route, case NEXTHOP_TYPE_IPV6_IFINDEX: nexthops[i].ifindex = nh->ifindex; - /* FALLTHROUGH */ + fallthrough; case NEXTHOP_TYPE_IPV6: nexthops[i].gate.ipv6 = nh->address; break; @@ -540,6 +540,10 @@ int ospf6_route_cmp(struct ospf6_route *ra, struct ospf6_route *rb) if (ra->path.area_id != rb->path.area_id) return (ntohl(ra->path.area_id) - ntohl(rb->path.area_id)); + if ((ra->prefix_options & OSPF6_PREFIX_OPTION_LA) + != (rb->prefix_options & OSPF6_PREFIX_OPTION_LA)) + return ra->prefix_options & OSPF6_PREFIX_OPTION_LA ? -1 : 1; + return 0; } diff --git a/ospf6d/ospf6_route.h b/ospf6d/ospf6_route.h index c2125951ec..2c1d17efc3 100644 --- a/ospf6d/ospf6_route.h +++ b/ospf6d/ospf6_route.h @@ -67,7 +67,7 @@ static inline bool ospf6_nexthop_is_same(const struct ospf6_nexthop *nha, case NEXTHOP_TYPE_IPV6_IFINDEX: if (nha->ifindex != nhb->ifindex) return false; - /* FALLTHROUGH */ + fallthrough; case NEXTHOP_TYPE_IPV6: if (!IN6_ARE_ADDR_EQUAL(&nha->address, &nhb->address)) return false; diff --git a/ospf6d/ospf6_snmp.c b/ospf6d/ospf6_snmp.c index f88667bfd0..17cdcdae8e 100644 --- a/ospf6d/ospf6_snmp.c +++ b/ospf6d/ospf6_snmp.c @@ -697,8 +697,8 @@ static uint8_t *ospfv3GeneralGroup(struct variable *v, oid *name, case OSPFv3REFERENCEBANDWIDTH: if (ospf6) return SNMP_INTEGER(ospf6->ref_bandwidth); - /* Otherwise, like for "not implemented". */ - /* fallthru */ + /* Otherwise, like for "not implemented". */ + return NULL; case OSPFv3RESTARTSUPPORT: case OSPFv3RESTARTINTERVAL: case OSPFv3RESTARTSTRICTLSACHECKING: @@ -1126,6 +1126,8 @@ static uint8_t *ospfv3IfEntry(struct variable *v, oid *name, size_t *length, return SNMP_INTEGER(1); else if (oi->type == OSPF_IFTYPE_POINTOPOINT) return SNMP_INTEGER(3); + else if (oi->type == OSPF_IFTYPE_POINTOMULTIPOINT) + return SNMP_INTEGER(5); else break; /* Unknown, don't put anything */ case OSPFv3IFADMINSTATUS: @@ -1367,6 +1369,7 @@ static int ospf6TrapIfStateChange(struct ospf6_interface *oi, int next_state, /* Terminal state or regression */ if ((next_state != OSPF6_INTERFACE_POINTTOPOINT) + && (next_state != OSPF6_INTERFACE_POINTTOMULTIPOINT) && (next_state != OSPF6_INTERFACE_DROTHER) && (next_state != OSPF6_INTERFACE_BDR) && (next_state != OSPF6_INTERFACE_DR) && (next_state >= prev_state)) diff --git a/ospf6d/ospf6_top.c b/ospf6d/ospf6_top.c index 01c962194c..63672a96e7 100644 --- a/ospf6d/ospf6_top.c +++ b/ospf6d/ospf6_top.c @@ -16,6 +16,7 @@ #include "defaults.h" #include "lib/json.h" #include "lib_errors.h" +#include "frrdistance.h" #include "ospf6_proto.h" #include "ospf6_message.h" @@ -140,20 +141,20 @@ static void ospf6_set_redist_vrf_bitmaps(struct ospf6 *ospf6, bool set) "%s: setting redist vrf %d bitmap for type %d", __func__, ospf6->vrf_id, type); if (set) - vrf_bitmap_set(zclient->redist[AFI_IP6][type], + vrf_bitmap_set(&zclient->redist[AFI_IP6][type], ospf6->vrf_id); else - vrf_bitmap_unset(zclient->redist[AFI_IP6][type], + vrf_bitmap_unset(&zclient->redist[AFI_IP6][type], ospf6->vrf_id); } red_list = ospf6->redist[DEFAULT_ROUTE]; if (red_list) { if (set) - vrf_bitmap_set(zclient->default_information[AFI_IP6], + vrf_bitmap_set(&zclient->default_information[AFI_IP6], ospf6->vrf_id); else - vrf_bitmap_unset(zclient->default_information[AFI_IP6], + vrf_bitmap_unset(&zclient->default_information[AFI_IP6], ospf6->vrf_id); } } @@ -485,6 +486,7 @@ void ospf6_delete(struct ospf6 *o) struct ospf6_area *oa; struct vrf *vrf; struct ospf6_external_aggr_rt *aggr; + uint32_t i; QOBJ_UNREG(o); @@ -531,6 +533,13 @@ void ospf6_delete(struct ospf6 *o) } route_table_finish(o->rt_aggr_tbl); + for (i = 0; i <= ZEBRA_ROUTE_MAX; i++) { + if (!o->redist[i]) + continue; + + list_delete(&o->redist[i]); + } + XFREE(MTYPE_OSPF6_TOP, o->name); XFREE(MTYPE_OSPF6_TOP, o); } @@ -575,6 +584,11 @@ void ospf6_master_init(struct event_loop *master) om6->master = master; } +void ospf6_master_delete(void) +{ + list_delete(&om6->ospf6); +} + static void ospf6_maxage_remover(struct event *thread) { struct ospf6 *o = (struct ospf6 *)EVENT_ARG(thread); @@ -1056,148 +1070,6 @@ DEFUN (no_ospf6_distance_ospf6, return CMD_SUCCESS; } -DEFUN_HIDDEN (ospf6_interface_area, - ospf6_interface_area_cmd, - "interface IFNAME area <A.B.C.D|(0-4294967295)>", - "Enable routing on an IPv6 interface\n" - IFNAME_STR - "Specify the OSPF6 area ID\n" - "OSPF6 area ID in IPv4 address notation\n" - "OSPF6 area ID in decimal notation\n" - ) -{ - VTY_DECLVAR_CONTEXT(ospf6, ospf6); - int idx_ifname = 1; - int idx_ipv4 = 3; - struct ospf6_area *oa; - struct ospf6_interface *oi; - struct interface *ifp; - uint32_t area_id; - int format; - - vty_out(vty, - "This command is deprecated, because it is not VRF-aware.\n"); - vty_out(vty, - "Please, use \"ipv6 ospf6 area\" on an interface instead.\n"); - - /* find/create ospf6 interface */ - ifp = if_get_by_name(argv[idx_ifname]->arg, ospf6->vrf_id, ospf6->name); - oi = (struct ospf6_interface *)ifp->info; - if (oi == NULL) - oi = ospf6_interface_create(ifp); - if (oi->area) { - vty_out(vty, "%s already attached to Area %s\n", - oi->interface->name, oi->area->name); - return CMD_SUCCESS; - } - - if (str2area_id(argv[idx_ipv4]->arg, &area_id, &format)) { - vty_out(vty, "Malformed Area-ID: %s\n", argv[idx_ipv4]->arg); - return CMD_WARNING_CONFIG_FAILED; - } - - oi->area_id = area_id; - oi->area_id_format = format; - - oa = ospf6_area_lookup(area_id, ospf6); - if (oa == NULL) - oa = ospf6_area_create(area_id, ospf6, format); - - /* attach interface to area */ - listnode_add(oa->if_list, oi); /* sort ?? */ - oi->area = oa; - - SET_FLAG(oa->flag, OSPF6_AREA_ENABLE); - - /* ospf6 process is currently disabled, not much more to do */ - if (CHECK_FLAG(ospf6->flag, OSPF6_DISABLED)) - return CMD_SUCCESS; - - /* start up */ - ospf6_interface_enable(oi); - - /* If the router is ABR, originate summary routes */ - if (ospf6_check_and_set_router_abr(ospf6)) { - ospf6_abr_enable_area(oa); - ospf6_schedule_abr_task(oa->ospf6); - } - - return CMD_SUCCESS; -} - -DEFUN_HIDDEN (no_ospf6_interface_area, - no_ospf6_interface_area_cmd, - "no interface IFNAME area <A.B.C.D|(0-4294967295)>", - NO_STR - "Disable routing on an IPv6 interface\n" - IFNAME_STR - "Specify the OSPF6 area ID\n" - "OSPF6 area ID in IPv4 address notation\n" - "OSPF6 area ID in decimal notation\n" - ) -{ - VTY_DECLVAR_CONTEXT(ospf6, ospf6); - int idx_ifname = 2; - int idx_ipv4 = 4; - struct ospf6_interface *oi; - struct ospf6_area *oa; - struct interface *ifp; - uint32_t area_id; - - vty_out(vty, - "This command is deprecated, because it is not VRF-aware.\n"); - vty_out(vty, - "Please, use \"no ipv6 ospf6 area\" on an interface instead.\n"); - - /* find/create ospf6 interface */ - ifp = if_get_by_name(argv[idx_ifname]->arg, ospf6->vrf_id, ospf6->name); - - if (ifp == NULL) { - vty_out(vty, "No such interface %s\n", argv[idx_ifname]->arg); - return CMD_SUCCESS; - } - - oi = (struct ospf6_interface *)ifp->info; - if (oi == NULL) { - vty_out(vty, "Interface %s not enabled\n", ifp->name); - return CMD_SUCCESS; - } - - /* parse Area-ID */ - if (inet_pton(AF_INET, argv[idx_ipv4]->arg, &area_id) != 1) - area_id = htonl(strtoul(argv[idx_ipv4]->arg, NULL, 10)); - - /* Verify Area */ - if (oi->area == NULL) { - vty_out(vty, "%s not attached to area %s\n", - oi->interface->name, argv[idx_ipv4]->arg); - return CMD_SUCCESS; - } - - if (oi->area->area_id != area_id) { - vty_out(vty, "Wrong Area-ID: %s is attached to area %s\n", - oi->interface->name, oi->area->name); - return CMD_SUCCESS; - } - - ospf6_interface_disable(oi); - - oa = oi->area; - listnode_delete(oi->area->if_list, oi); - oi->area = (struct ospf6_area *)NULL; - - /* Withdraw inter-area routes from this area, if necessary */ - if (oa->if_list->count == 0) { - UNSET_FLAG(oa->flag, OSPF6_AREA_ENABLE); - ospf6_abr_disable_area(oa); - } - - oi->area_id = 0; - oi->area_id_format = OSPF6_AREA_FMT_UNSET; - - return CMD_SUCCESS; -} - DEFUN (ospf6_stub_router_admin, ospf6_stub_router_admin_cmd, "stub-router administrative", @@ -2015,7 +1887,7 @@ ospf6_show_summary_address(struct vty *vty, struct ospf6 *ospf6, if (!uj) { ospf6_show_vrf_name(vty, ospf6, json_vrf); - vty_out(vty, "aggregation delay interval :%u(in seconds)\n\n", + vty_out(vty, "aggregation delay interval: %u(in seconds)\n\n", ospf6->aggr_delay_interval); vty_out(vty, "%s\n", header); } else { @@ -2346,8 +2218,6 @@ void ospf6_top_init(void) install_element(OSPF6_NODE, &ospf6_timers_lsa_cmd); install_element(OSPF6_NODE, &no_ospf6_timers_lsa_cmd); - install_element(OSPF6_NODE, &ospf6_interface_area_cmd); - install_element(OSPF6_NODE, &no_ospf6_interface_area_cmd); install_element(OSPF6_NODE, &ospf6_stub_router_admin_cmd); install_element(OSPF6_NODE, &no_ospf6_stub_router_admin_cmd); diff --git a/ospf6d/ospf6_top.h b/ospf6d/ospf6_top.h index a38dad8fce..8288413c10 100644 --- a/ospf6d/ospf6_top.h +++ b/ospf6d/ospf6_top.h @@ -236,6 +236,8 @@ extern struct ospf6_master *om6; /* prototypes */ extern void ospf6_master_init(struct event_loop *master); +extern void ospf6_master_delete(void); + extern void install_element_ospf6_clear_process(void); extern void ospf6_top_init(void); extern void ospf6_delete(struct ospf6 *o); diff --git a/ospf6d/ospf6_zebra.c b/ospf6d/ospf6_zebra.c index 0f631c4d01..3245578b07 100644 --- a/ospf6d/ospf6_zebra.c +++ b/ospf6d/ospf6_zebra.c @@ -97,9 +97,9 @@ static int ospf6_router_id_update_zebra(ZAPI_CALLBACK_ARGS) /* redistribute function */ void ospf6_zebra_redistribute(int type, vrf_id_t vrf_id) { - if (vrf_bitmap_check(zclient->redist[AFI_IP6][type], vrf_id)) + if (vrf_bitmap_check(&zclient->redist[AFI_IP6][type], vrf_id)) return; - vrf_bitmap_set(zclient->redist[AFI_IP6][type], vrf_id); + vrf_bitmap_set(&zclient->redist[AFI_IP6][type], vrf_id); if (zclient->sock > 0) zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD, zclient, @@ -108,9 +108,9 @@ void ospf6_zebra_redistribute(int type, vrf_id_t vrf_id) void ospf6_zebra_no_redistribute(int type, vrf_id_t vrf_id) { - if (!vrf_bitmap_check(zclient->redist[AFI_IP6][type], vrf_id)) + if (!vrf_bitmap_check(&zclient->redist[AFI_IP6][type], vrf_id)) return; - vrf_bitmap_unset(zclient->redist[AFI_IP6][type], vrf_id); + vrf_bitmap_unset(&zclient->redist[AFI_IP6][type], vrf_id); if (zclient->sock > 0) zebra_redistribute_send(ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP6, type, 0, vrf_id); @@ -147,30 +147,22 @@ void ospf6_zebra_import_default_route(struct ospf6 *ospf6, bool unreg) __func__); } -static int ospf6_zebra_import_check_update(ZAPI_CALLBACK_ARGS) +static void ospf6_zebra_import_check_update(struct vrf *vrf, + struct prefix *matched, + struct zapi_route *nhr) { struct ospf6 *ospf6; - struct zapi_route nhr; - struct prefix matched; - ospf6 = ospf6_lookup_by_vrf_id(vrf_id); + ospf6 = (struct ospf6 *)vrf->info; if (ospf6 == NULL || !IS_OSPF6_ASBR(ospf6)) - return 0; - - if (!zapi_nexthop_update_decode(zclient->ibuf, &matched, &nhr)) { - zlog_err("%s[%u]: Failure to decode route", __func__, - ospf6->vrf_id); - return -1; - } + return; - if (matched.family != AF_INET6 || matched.prefixlen != 0 || - nhr.type == ZEBRA_ROUTE_OSPF6) - return 0; + if (matched->family != AF_INET6 || matched->prefixlen != 0 || + nhr->type == ZEBRA_ROUTE_OSPF6) + return; - ospf6->nssa_default_import_check.status = !!nhr.nexthop_num; + ospf6->nssa_default_import_check.status = !!nhr->nexthop_num; ospf6_abr_nssa_type_7_defaults(ospf6); - - return 0; } static int ospf6_zebra_if_address_update_add(ZAPI_CALLBACK_ARGS) @@ -333,10 +325,10 @@ DEFUN(show_zebra, json_object_int_add(json_zebra, "fail", zclient->fail); json_object_int_add( json_zebra, "redistributeDefault", - vrf_bitmap_check(zclient->default_information[AFI_IP6], + vrf_bitmap_check(&zclient->default_information[AFI_IP6], VRF_DEFAULT)); for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { - if (vrf_bitmap_check(zclient->redist[AFI_IP6][i], + if (vrf_bitmap_check(&zclient->redist[AFI_IP6][i], VRF_DEFAULT)) json_object_array_add( json_array, @@ -351,11 +343,11 @@ DEFUN(show_zebra, vty_out(vty, "Zebra Information\n"); vty_out(vty, " fail: %d\n", zclient->fail); vty_out(vty, " redistribute default: %d\n", - vrf_bitmap_check(zclient->default_information[AFI_IP6], + vrf_bitmap_check(&zclient->default_information[AFI_IP6], VRF_DEFAULT)); vty_out(vty, " redistribute:"); for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { - if (vrf_bitmap_check(zclient->redist[AFI_IP6][i], + if (vrf_bitmap_check(&zclient->redist[AFI_IP6][i], VRF_DEFAULT)) vty_out(vty, " %s", zebra_route_string(i)); } @@ -763,7 +755,6 @@ static zclient_handler *const ospf6_handlers[] = { [ZEBRA_INTERFACE_ADDRESS_DELETE] = ospf6_zebra_if_address_update_delete, [ZEBRA_REDISTRIBUTE_ROUTE_ADD] = ospf6_zebra_read_route, [ZEBRA_REDISTRIBUTE_ROUTE_DEL] = ospf6_zebra_read_route, - [ZEBRA_NEXTHOP_UPDATE] = ospf6_zebra_import_check_update, }; void ospf6_zebra_init(struct event_loop *master) @@ -773,6 +764,7 @@ void ospf6_zebra_init(struct event_loop *master) array_size(ospf6_handlers)); zclient_init(zclient, ZEBRA_ROUTE_OSPF6, 0, &ospf6d_privs); zclient->zebra_connected = ospf6_zebra_connected; + zclient->nexthop_update = ospf6_zebra_import_check_update; /* Install command element for zebra node. */ install_element(VIEW_NODE, &show_ospf6_zebra_cmd); diff --git a/ospf6d/ospf6_zebra.h b/ospf6d/ospf6_zebra.h index 9f41dfca9a..7669b5e2c0 100644 --- a/ospf6d/ospf6_zebra.h +++ b/ospf6d/ospf6_zebra.h @@ -38,7 +38,7 @@ extern void ospf6_zebra_route_update_remove(struct ospf6_route *request, extern void ospf6_zebra_redistribute(int, vrf_id_t vrf_id); extern void ospf6_zebra_no_redistribute(int, vrf_id_t vrf_id); #define ospf6_zebra_is_redistribute(type, vrf_id) \ - vrf_bitmap_check(zclient->redist[AFI_IP6][type], vrf_id) + vrf_bitmap_check(&zclient->redist[AFI_IP6][type], vrf_id) extern void ospf6_zebra_init(struct event_loop *tm); extern void ospf6_zebra_import_default_route(struct ospf6 *ospf6, bool unreg); extern void ospf6_zebra_add_discard(struct ospf6_route *request, diff --git a/ospf6d/ospf6d.c b/ospf6d/ospf6d.c index 214007d041..d90a950d79 100644 --- a/ospf6d/ospf6d.c +++ b/ospf6d/ospf6d.c @@ -34,9 +34,16 @@ #include "lib/json.h" #include "ospf6_nssa.h" #include "ospf6_auth_trailer.h" +#include "ospf6d/ospf6d_clippy.c" DEFINE_MGROUP(OSPF6D, "ospf6d"); +/* OSPF6 config processing timer thread */ +struct event *t_ospf6_cfg; + +/* OSPF6 debug event state */ +unsigned char conf_debug_ospf6_event; + struct route_node *route_prev(struct route_node *node) { struct route_node *end; @@ -62,6 +69,7 @@ struct route_node *route_prev(struct route_node *node) } static int config_write_ospf6_debug(struct vty *vty); +static int config_write_ospf6_debug_event(struct vty *vty); static struct cmd_node debug_node = { .name = "debug", .node = DEBUG_NODE, @@ -85,6 +93,7 @@ static int config_write_ospf6_debug(struct vty *vty) config_write_ospf6_debug_nssa(vty); config_write_ospf6_debug_gr_helper(vty); config_write_ospf6_debug_auth(vty); + config_write_ospf6_debug_event(vty); return 0; } @@ -1374,6 +1383,29 @@ DEFUN(show_ipv6_ospf6_linkstate_detail, show_ipv6_ospf6_linkstate_detail_cmd, return CMD_SUCCESS; } +DEFPY(debug_ospf6_event, debug_ospf6_event_cmd, "[no] debug ospf6 event", + NO_STR DEBUG_STR OSPF6_STR "Debug OSPFv3 event function\n") +{ + if (!no) + OSPF6_DEBUG_EVENT_ON(); + else + OSPF6_DEBUG_EVENT_OFF(); + return CMD_SUCCESS; +} + +static int config_write_ospf6_debug_event(struct vty *vty) +{ + if (IS_OSPF6_DEBUG_EVENT) + vty_out(vty, "debug ospf6 event\n"); + return 0; +} + +static void install_element_ospf6_debug_event(void) +{ + install_element(ENABLE_NODE, &debug_ospf6_event_cmd); + install_element(CONFIG_NODE, &debug_ospf6_event_cmd); +} + /* Install ospf related commands. */ void ospf6_init(struct event_loop *master) { @@ -1447,6 +1479,7 @@ void ospf6_init(struct event_loop *master) VIEW_NODE, &show_ipv6_ospf6_database_type_self_originated_linkstate_id_cmd); install_element(VIEW_NODE, &show_ipv6_ospf6_database_aggr_router_cmd); + install_element_ospf6_debug_event(); install_element_ospf6_debug_auth(); ospf6_interface_auth_trailer_cmd_init(); install_element_ospf6_clear_intf_auth(); diff --git a/ospf6d/ospf6d.h b/ospf6d/ospf6d.h index 980a365265..c927ee7566 100644 --- a/ospf6d/ospf6d.h +++ b/ospf6d/ospf6d.h @@ -15,6 +15,9 @@ DECLARE_MGROUP(OSPF6D); /* global variables */ extern struct event_loop *master; +/* OSPF config processing timer thread */ +extern struct event *t_ospf6_cfg; + /* Historical for KAME. */ #ifndef IPV6_JOIN_GROUP #ifdef IPV6_ADD_MEMBERSHIP @@ -105,6 +108,12 @@ extern struct event_loop *master; extern struct zebra_privs_t ospf6d_privs; +/* Event Debug option */ +extern unsigned char conf_debug_ospf6_event; +#define OSPF6_DEBUG_EVENT_ON() (conf_debug_ospf6_event = 1) +#define OSPF6_DEBUG_EVENT_OFF() (conf_debug_ospf6_event = 0) +#define IS_OSPF6_DEBUG_EVENT (conf_debug_ospf6_event) + /* Function Prototypes */ extern struct route_node *route_prev(struct route_node *node); diff --git a/ospf6d/subdir.am b/ospf6d/subdir.am index c34db3012d..5f89af9508 100644 --- a/ospf6d/subdir.am +++ b/ospf6d/subdir.am @@ -75,6 +75,7 @@ ospf6d_ospf6d_snmp_la_LDFLAGS = $(MODULE_LDFLAGS) ospf6d_ospf6d_snmp_la_LIBADD = lib/libfrrsnmp.la clippy_scan += \ + ospf6d/ospf6d.c \ ospf6d/ospf6_top.c \ ospf6d/ospf6_area.c \ ospf6d/ospf6_asbr.c \ @@ -82,8 +83,10 @@ clippy_scan += \ ospf6d/ospf6_lsa.c \ ospf6d/ospf6_gr_helper.c \ ospf6d/ospf6_gr.c \ + ospf6d/ospf6_interface.c \ ospf6d/ospf6_nssa.c \ ospf6d/ospf6_route.c \ + ospf6d/ospf6_neighbor.c \ # end nodist_ospf6d_ospf6d_SOURCES = \ diff --git a/ospfd/ospf_apiserver.c b/ospfd/ospf_apiserver.c index 34e59c545b..419113e6d7 100644 --- a/ospfd/ospf_apiserver.c +++ b/ospfd/ospf_apiserver.c @@ -2092,7 +2092,7 @@ void ospf_apiserver_flush_opaque_lsa(struct ospf_apiserver *apiserv, lsa, (void *)¶m, 0); break; case OSPF_OPAQUE_AS_LSA: - LSDB_LOOP (OPAQUE_LINK_LSDB(ospf), rn, lsa) + LSDB_LOOP (OPAQUE_AS_LSDB(ospf), rn, lsa) apiserver_flush_opaque_type_callback(lsa, (void *)¶m, 0); break; diff --git a/ospfd/ospf_asbr.c b/ospfd/ospf_asbr.c index 1b68f6e022..5baad1754d 100644 --- a/ospfd/ospf_asbr.c +++ b/ospfd/ospf_asbr.c @@ -265,17 +265,17 @@ void ospf_asbr_status_update(struct ospf *ospf, uint8_t status) } /* If there's redistribution configured, we need to refresh external - * LSAs in order to install Type-7 and flood to all NSSA Areas + * LSAs (e.g. when default-metric changes or NSSA settings change). */ -static void ospf_asbr_nssa_redist_update_timer(struct event *thread) +static void ospf_asbr_redist_update_timer(struct event *thread) { struct ospf *ospf = EVENT_ARG(thread); int type; - ospf->t_asbr_nssa_redist_update = NULL; + ospf->t_asbr_redist_update = NULL; if (IS_DEBUG_OSPF_EVENT) - zlog_debug("Running ASBR NSSA redistribution update on timer"); + zlog_debug("Running ASBR redistribution update on timer"); for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { struct list *red_list; @@ -295,14 +295,14 @@ static void ospf_asbr_nssa_redist_update_timer(struct event *thread) ospf_external_lsa_refresh_default(ospf); } -void ospf_schedule_asbr_nssa_redist_update(struct ospf *ospf) +void ospf_schedule_asbr_redist_update(struct ospf *ospf) { if (IS_DEBUG_OSPF_EVENT) - zlog_debug("Scheduling ASBR NSSA redistribution update"); + zlog_debug("Scheduling ASBR redistribution update"); - event_add_timer(master, ospf_asbr_nssa_redist_update_timer, ospf, - OSPF_ASBR_NSSA_REDIST_UPDATE_DELAY, - &ospf->t_asbr_nssa_redist_update); + event_add_timer(master, ospf_asbr_redist_update_timer, ospf, + OSPF_ASBR_REDIST_UPDATE_DELAY, + &ospf->t_asbr_redist_update); } void ospf_redistribute_withdraw(struct ospf *ospf, uint8_t type, @@ -987,6 +987,7 @@ static void ospf_handle_external_aggr_update(struct ospf *ospf) &aggr->match_extnl_hash, (void *)ospf_aggr_handle_external_info); + ospf_external_aggregator_free(aggr); } else if (aggr->action == OSPF_ROUTE_AGGR_MODIFY) { aggr->action = OSPF_ROUTE_AGGR_NONE; diff --git a/ospfd/ospf_asbr.h b/ospfd/ospf_asbr.h index dfb9d965c5..6158d65f22 100644 --- a/ospfd/ospf_asbr.h +++ b/ospfd/ospf_asbr.h @@ -95,7 +95,7 @@ struct ospf_external_aggr_rt { }; #define OSPF_ASBR_CHECK_DELAY 30 -#define OSPF_ASBR_NSSA_REDIST_UPDATE_DELAY 9 +#define OSPF_ASBR_REDIST_UPDATE_DELAY 9 extern void ospf_external_route_remove(struct ospf *, struct prefix_ipv4 *); extern struct external_info *ospf_external_info_new(struct ospf *, uint8_t, @@ -113,7 +113,7 @@ extern struct external_info *ospf_external_info_lookup(struct ospf *, uint8_t, unsigned short, struct prefix_ipv4 *); extern void ospf_asbr_status_update(struct ospf *, uint8_t); -extern void ospf_schedule_asbr_nssa_redist_update(struct ospf *ospf); +extern void ospf_schedule_asbr_redist_update(struct ospf *ospf); extern void ospf_redistribute_withdraw(struct ospf *, uint8_t, unsigned short); extern void ospf_asbr_check(void); diff --git a/ospfd/ospf_ase.c b/ospfd/ospf_ase.c index 610b5fc08e..bd80fb32e7 100644 --- a/ospfd/ospf_ase.c +++ b/ospfd/ospf_ase.c @@ -75,10 +75,7 @@ struct ospf_route *ospf_find_asbr_route(struct ospf *ospf, best = or ; else if (best->cost == or->cost - && IPV4_ADDR_CMP( - &best->u.std.area_id, - & or->u.std.area_id) - < 0) + && IPV4_ADDR_CMP(&best->u.std.area_id,& or->u.std.area_id) < 0) best = or ; } @@ -88,9 +85,7 @@ struct ospf_route *ospf_find_asbr_route(struct ospf *ospf, return best; } -struct ospf_route *ospf_find_asbr_route_through_area(struct route_table *rtrs, - struct prefix_ipv4 *asbr, - struct ospf_area *area) +struct ospf_route *ospf_find_asbr_route_through_area(struct route_table *rtrs, struct prefix_ipv4 *asbr, struct ospf_area *area) { struct route_node *rn; @@ -320,8 +315,7 @@ int ospf_ase_calculate_route(struct ospf *ospf, struct ospf_lsa *lsa) if (rn == NULL || (asbr_route = rn->info) == NULL) { if (IS_DEBUG_OSPF(lsa, LSA)) - zlog_debug( - "Route[External]: Can't find route to forwarding address"); + zlog_debug("Route[External]: Can't find route to forwarding address"); if (rn) route_unlock_node(rn); return 0; @@ -443,8 +437,7 @@ int ospf_ase_calculate_route(struct ospf *ospf, struct ospf_lsa *lsa) zlog_debug("Route[External]: Routes are equal"); ospf_route_copy_nexthops(or, asbr_route->paths); if (al->e[0].fwd_addr.s_addr != INADDR_ANY) - ospf_ase_complete_direct_routes( - or, al->e[0].fwd_addr); + ospf_ase_complete_direct_routes(or, al->e[0].fwd_addr); } } /* Make sure setting newly calculated ASBR route.*/ @@ -533,8 +526,7 @@ static int ospf_ase_compare_tables(struct ospf *ospf, if ((or = rn->info)) { if (!(new_rn = route_node_lookup(new_external_route, &rn->p))) - ospf_zebra_delete( - ospf, (struct prefix_ipv4 *)&rn->p, or); + ospf_zebra_delete(ospf, (struct prefix_ipv4 *)&rn->p, or); else route_unlock_node(new_rn); } @@ -581,8 +573,7 @@ static void ospf_ase_calculate_timer(struct event *t) if (area->external_routing == OSPF_AREA_NSSA) LSDB_LOOP (NSSA_LSDB(area), rn, lsa) - ospf_ase_calculate_route(ospf, - lsa); + ospf_ase_calculate_route(ospf, lsa); } /* kevinm: And add the NSSA routes in ospf_top */ LSDB_LOOP (NSSA_LSDB(ospf), rn, lsa) diff --git a/ospfd/ospf_auth.c b/ospfd/ospf_auth.c new file mode 100644 index 0000000000..2b090dca1e --- /dev/null +++ b/ospfd/ospf_auth.c @@ -0,0 +1,722 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2023 Amnesh Inc. + * Mahdi Varasteh + */ + +#include <zebra.h> +#include <sys/stat.h> + +#ifdef CRYPTO_OPENSSL +#include <openssl/evp.h> +#include <openssl/hmac.h> +#endif + +#include "linklist.h" +#include "if.h" +#include "checksum.h" + +#include "ospfd/ospfd.h" +#include "ospfd/ospf_errors.h" +#include "ospfd/ospf_interface.h" +#include "ospfd/ospf_asbr.h" +#include "ospfd/ospf_lsa.h" +#include "ospfd/ospf_lsdb.h" +#include "ospfd/ospf_neighbor.h" +#include "ospfd/ospf_auth.h" +#include "ospfd/ospf_nsm.h" +#include "ospfd/ospf_dump.h" +#include "ospfd/ospf_packet.h" +#include "ospfd/ospf_network.h" +#include "ospfd/ospf_flood.h" +#include "ospfd/ospf_dump.h" +#include "ospfd/ospf_bfd.h" +#include "ospfd/ospf_gr.h" +#ifdef CRYPTO_INTERNAL +#include "sha256.h" +#include "md5.h" +#endif + +const uint8_t ospf_auth_apad[KEYCHAIN_MAX_HASH_SIZE] = { + 0x87, 0x8F, 0xE1, 0xF3, 0x87, 0x8F, 0xE1, 0xF3, 0x87, 0x8F, 0xE1, + 0xF3, 0x87, 0x8F, 0xE1, 0xF3, 0x87, 0x8F, 0xE1, 0xF3, 0x87, 0x8F, + 0xE1, 0xF3, 0x87, 0x8F, 0xE1, 0xF3, 0x87, 0x8F, 0xE1, 0xF3, 0x87, + 0x8F, 0xE1, 0xF3, 0x87, 0x8F, 0xE1, 0xF3, 0x87, 0x8F, 0xE1, 0xF3, + 0x87, 0x8F, 0xE1, 0xF3, 0x87, 0x8F, 0xE1, 0xF3, 0x87, 0x8F, 0xE1, + 0xF3, 0x87, 0x8F, 0xE1, 0xF3, 0x87, 0x8F, 0xE1, 0xF3 +}; + +static int ospf_check_sum(struct ospf_header *ospfh) +{ + uint32_t ret; + uint16_t sum; + + /* clear auth_data for checksum. */ + memset(ospfh->u.auth_data, 0, OSPF_AUTH_SIMPLE_SIZE); + + /* keep checksum and clear. */ + sum = ospfh->checksum; + memset(&ospfh->checksum, 0, sizeof(uint16_t)); + + /* calculate checksum. */ + ret = in_cksum(ospfh, ntohs(ospfh->length)); + + if (ret != sum) { + zlog_info("%s: checksum mismatch, my %X, his %X", __func__, ret, + sum); + return 0; + } + + return 1; +} + +#ifdef CRYPTO_OPENSSL +static const EVP_MD *ospf_auth_get_openssl_evp_md_from_key(struct key *key) +{ + if (key->hash_algo == KEYCHAIN_ALGO_HMAC_SHA1) + return EVP_get_digestbyname("sha1"); + else if (key->hash_algo == KEYCHAIN_ALGO_HMAC_SHA256) + return EVP_get_digestbyname("sha256"); + else if (key->hash_algo == KEYCHAIN_ALGO_HMAC_SHA384) + return EVP_get_digestbyname("sha384"); + else if (key->hash_algo == KEYCHAIN_ALGO_HMAC_SHA512) + return EVP_get_digestbyname("sha512"); + return NULL; +} +#endif + +static int ospf_auth_check_hmac_sha_digest(struct ospf_interface *oi, + struct ospf_header *ospfh, + struct ip *iph, + struct key *key) +{ + unsigned char digest[KEYCHAIN_MAX_HASH_SIZE]; + struct ospf_neighbor *nbr; + uint16_t length = ntohs(ospfh->length); + uint16_t hash_length = keychain_get_hash_len(key->hash_algo); +#ifdef CRYPTO_OPENSSL + uint32_t openssl_hash_length = hash_length; + HMAC_CTX *ctx; + const EVP_MD *md_alg = ospf_auth_get_openssl_evp_md_from_key(key); + + if (!md_alg) { + flog_warn(EC_OSPF_AUTH, + "interface %s: invalid HMAC algorithm, Router-ID: %pI4", + IF_NAME(oi), &ospfh->router_id); + return 0; + } +#elif CRYPTO_INTERNAL + HMAC_SHA256_CTX ctx; + + if (key->hash_algo != KEYCHAIN_ALGO_HMAC_SHA256) { + flog_warn(EC_OSPF_AUTH, + "interface %s: HMAC algorithm not supported, Router-ID: %pI4", + IF_NAME(oi), &ospfh->router_id); + return 0; + } +#endif + /* check crypto seqnum. */ + nbr = ospf_nbr_lookup(oi, iph, ospfh); + + if (nbr && + ntohl(nbr->crypt_seqnum) > ntohl(ospfh->u.crypt.crypt_seqnum)) { + flog_warn(EC_OSPF_AUTH, + "interface %s: ospf_check_hmac_sha bad sequence %u (expect %d), Router-ID: %pI4", + IF_NAME(oi), ntohl(ospfh->u.crypt.crypt_seqnum), + ntohl(nbr->crypt_seqnum), &ospfh->router_id); + return 0; + } +#ifdef CRYPTO_OPENSSL + ctx = HMAC_CTX_new(); + HMAC_Init_ex(ctx, key->string, strlen(key->string), md_alg, NULL); + HMAC_Update(ctx, (const unsigned char *)ospfh, length); + HMAC_Update(ctx, (const unsigned char *)ospf_auth_apad, hash_length); + HMAC_Final(ctx, digest, &openssl_hash_length); + HMAC_CTX_free(ctx); +#elif CRYPTO_INTERNAL + memset(&ctx, 0, sizeof(ctx)); + HMAC__SHA256_Init(&ctx, key->string, strlen(key->string)); + HMAC__SHA256_Update(&ctx, ospfh, length); + HMAC__SHA256_Update(&ctx, ospf_auth_apad, hash_length); + HMAC__SHA256_Final(digest, &ctx); +#endif + if (memcmp((caddr_t)ospfh + length, digest, hash_length)) { + flog_warn(EC_OSPF_AUTH, + "interface %s: ospf_check_hmac_sha checksum mismatch %u, Router-ID: %pI4", + IF_NAME(oi), length, &ospfh->router_id); + return 0; + } + if (nbr) + nbr->crypt_seqnum = ospfh->u.crypt.crypt_seqnum; + return 1; +} + +static int ospf_auth_check_md5_digest(struct ospf_interface *oi, + struct ospf_header *ospfh, struct ip *iph, struct key *key) +{ +#ifdef CRYPTO_OPENSSL + EVP_MD_CTX *ctx; +#elif CRYPTO_INTERNAL + MD5_CTX ctx; +#endif + char auth_key[OSPF_AUTH_MD5_SIZE + 1]; + unsigned char digest[OSPF_AUTH_MD5_SIZE]; + struct ospf_neighbor *nbr; + struct crypt_key *ck = NULL; + uint16_t length = ntohs(ospfh->length); + + if (length < sizeof(struct ospf_header)) {/* for coverity's sake */ + flog_warn(EC_OSPF_AUTH, + "%s: Invalid packet length of %u received on interface %s, Router-ID: %pI4", + __func__, length, IF_NAME(oi), &ospfh->router_id); + return 0; + } + + if (key == NULL) { + ck = ospf_crypt_key_lookup(OSPF_IF_PARAM(oi, auth_crypt), + ospfh->u.crypt.key_id); + if (ck == NULL) { + flog_warn( + EC_OSPF_AUTH, + "interface %s: %s no key %d, Router-ID: %pI4", + IF_NAME(oi), __func__, ospfh->u.crypt.key_id, &ospfh->router_id); + return 0; + } + } + /* check crypto seqnum. */ + nbr = ospf_nbr_lookup(oi, iph, ospfh); + + if (nbr && + ntohl(nbr->crypt_seqnum) > ntohl(ospfh->u.crypt.crypt_seqnum)) { + flog_warn(EC_OSPF_AUTH, + "interface %s: %s bad sequence %d (expect %d), Router-ID: %pI4", + IF_NAME(oi), __func__, ntohl(ospfh->u.crypt.crypt_seqnum), + ntohl(nbr->crypt_seqnum), &ospfh->router_id); + return 0; + } + + memset(auth_key, 0, OSPF_AUTH_MD5_SIZE + 1); + if (ck == NULL) + strlcpy(auth_key, key->string, OSPF_AUTH_MD5_SIZE + 1); + else + strlcpy(auth_key, (char *)ck->auth_key, OSPF_AUTH_MD5_SIZE + 1); + /* Generate a digest for the ospf packet - their digest + our digest. */ +#ifdef CRYPTO_OPENSSL + uint32_t md5_size = OSPF_AUTH_MD5_SIZE; + + ctx = EVP_MD_CTX_new(); + EVP_DigestInit(ctx, EVP_md5()); + EVP_DigestUpdate(ctx, ospfh, length); + EVP_DigestUpdate(ctx, auth_key, OSPF_AUTH_MD5_SIZE); + EVP_DigestFinal(ctx, digest, &md5_size); + EVP_MD_CTX_free(ctx); +#elif CRYPTO_INTERNAL + memset(&ctx, 0, sizeof(ctx)); + MD5Init(&ctx); + MD5Update(&ctx, ospfh, length); + MD5Update(&ctx, auth_key, OSPF_AUTH_MD5_SIZE); + MD5Final(digest, &ctx); +#endif + + /* compare the two */ + if (memcmp((caddr_t)ospfh + length, digest, OSPF_AUTH_MD5_SIZE)) { + flog_warn(EC_OSPF_AUTH, + "interface %s: ospf_check_md5 checksum mismatch, Router-ID: %pI4", + IF_NAME(oi), &ospfh->router_id); + return 0; + } + + /* save neighbor's crypt_seqnum */ + if (nbr) + nbr->crypt_seqnum = ospfh->u.crypt.crypt_seqnum; + return 1; +} + +static int ospf_auth_make_md5_digest(struct ospf_interface *oi, + struct ospf_packet *op, struct key *key) +{ + void *ibuf = STREAM_DATA(op->s); + struct ospf_header *ospfh = (struct ospf_header *)ibuf; + unsigned char digest[OSPF_AUTH_MD5_SIZE]; + uint16_t length = ntohs(ospfh->length); +#ifdef CRYPTO_OPENSSL + EVP_MD_CTX *ctx; +#elif CRYPTO_INTERNAL + MD5_CTX ctx; +#endif + char auth_key[OSPF_AUTH_MD5_SIZE + 1]; + + if ((length < (sizeof(struct ospf_header))) || (length > op->length)) { /* for coverity's sake */ + flog_warn(EC_OSPF_AUTH, + "%s: Invalid packet length of %u received on interface %s, Router-ID: %pI4", + __func__, length, IF_NAME(oi), &ospfh->router_id); + return 0; + } + + memset(auth_key, 0, OSPF_AUTH_MD5_SIZE + 1); + strlcpy(auth_key, key->string, OSPF_AUTH_MD5_SIZE + 1); + /* Generate a digest for the ospf packet - their digest + our digest. */ +#ifdef CRYPTO_OPENSSL + uint32_t md5_size = OSPF_AUTH_MD5_SIZE; + + ctx = EVP_MD_CTX_new(); + EVP_DigestInit(ctx, EVP_md5()); + EVP_DigestUpdate(ctx, ospfh, length); + EVP_DigestUpdate(ctx, auth_key, OSPF_AUTH_MD5_SIZE); + EVP_DigestFinal(ctx, digest, &md5_size); + EVP_MD_CTX_free(ctx); +#elif CRYPTO_INTERNAL + memset(&ctx, 0, sizeof(ctx)); + MD5Init(&ctx); + MD5Update(&ctx, ospfh, length); + MD5Update(&ctx, auth_key, OSPF_AUTH_MD5_SIZE); + MD5Final(digest, &ctx); +#endif + + stream_put(op->s, digest, OSPF_AUTH_MD5_SIZE); + + op->length = ntohs(ospfh->length) + OSPF_AUTH_MD5_SIZE; + + if (stream_get_endp(op->s) != op->length) + /* XXX size_t */ + flog_warn(EC_OSPF_AUTH, + "%s: length mismatch stream %lu ospf_packet %u, Router-ID %pI4", + __func__, (unsigned long)stream_get_endp(op->s), + op->length, &ospfh->router_id); + + return OSPF_AUTH_MD5_SIZE; +} + +static int ospf_auth_make_hmac_sha_digest(struct ospf_interface *oi, + struct ospf_packet *op, + struct key *key) +{ + void *ibuf; + struct ospf_header *ospfh; + unsigned char digest[KEYCHAIN_MAX_HASH_SIZE] = { 0 }; + uint16_t hash_length = keychain_get_hash_len(key->hash_algo); + + ibuf = STREAM_DATA(op->s); + ospfh = (struct ospf_header *)ibuf; +#ifdef CRYPTO_OPENSSL + uint32_t openssl_hash_length = hash_length; + HMAC_CTX *ctx; + const EVP_MD *md_alg = ospf_auth_get_openssl_evp_md_from_key(key); + + if (!md_alg) { + flog_warn(EC_OSPF_AUTH, + "interface %s: invalid HMAC algorithm, Router-ID: %pI4", + IF_NAME(oi), &ospfh->router_id); + return 0; + } +#elif CRYPTO_INTERNAL + HMAC_SHA256_CTX ctx; + + if (key->hash_algo != KEYCHAIN_ALGO_HMAC_SHA256) { + flog_warn(EC_OSPF_AUTH, + "interface %s: HMAC algorithm not supported, Router-ID: %pI4", + IF_NAME(oi), &ospfh->router_id); + return 0; + } +#endif +#ifdef CRYPTO_OPENSSL + ctx = HMAC_CTX_new(); + HMAC_Init_ex(ctx, key->string, strlen(key->string), md_alg, NULL); + HMAC_Update(ctx, (const unsigned char *)ospfh, ntohs(ospfh->length)); + HMAC_Update(ctx, (const unsigned char *)ospf_auth_apad, hash_length); + HMAC_Final(ctx, digest, &openssl_hash_length); + HMAC_CTX_free(ctx); +#elif CRYPTO_INTERNAL + memset(&ctx, 0, sizeof(ctx)); + HMAC__SHA256_Init(&ctx, key->string, strlen(key->string)); + HMAC__SHA256_Update(&ctx, ospfh, ntohs(ospfh->length)); + HMAC__SHA256_Update(&ctx, ospf_auth_apad, hash_length); + HMAC__SHA256_Final(digest, &ctx); +#endif + stream_put(op->s, digest, hash_length); + + op->length = ntohs(ospfh->length) + hash_length; + + if (stream_get_endp(op->s) != op->length) + /* XXX size_t */ + flog_warn(EC_OSPF_AUTH, + "%s: length mismatch stream %lu ospf_packet %u, Router-ID %pI4", + __func__, (unsigned long)stream_get_endp(op->s), + op->length, &ospfh->router_id); + + return hash_length; +} + +int ospf_auth_check_digest(struct ospf_interface *oi, struct ip *iph, struct ospf_header *ospfh) +{ + struct keychain *keychain = NULL; + struct key *key = NULL; + int key_id = ospfh->u.crypt.key_id; + uint8_t auth_data_len = ospfh->u.crypt.auth_data_len; + + if (!OSPF_IF_PARAM(oi, keychain_name)) + return ospf_auth_check_md5_digest(oi, ospfh, iph, NULL); + + keychain = keychain_lookup(OSPF_IF_PARAM(oi, keychain_name)); + if (!keychain) { + if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) + flog_warn(EC_OSPF_AUTH, + "interface %s: Keychain %s is not available, Router-ID %pI4", + IF_NAME(oi), OSPF_IF_PARAM(oi, keychain_name), + &ospfh->router_id); + return 0; + } + + key = key_lookup_for_accept(keychain, key_id); + if (!key) { + if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) + flog_warn(EC_OSPF_AUTH, + "interface %s: Key ID %d not found in keychain %s, Router-ID %pI4", + IF_NAME(oi), key_id, keychain->name, + &ospfh->router_id); + return 0; + } + + if (key->string == NULL || key->hash_algo == KEYCHAIN_ALGO_NULL) { + if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) + flog_warn(EC_OSPF_AUTH, + "interface %s: Key ID %d in keychain %s is incomplete, Router-ID %pI4", + IF_NAME(oi), key_id, keychain->name, + &ospfh->router_id); + return 0; + } + + if (keychain_get_hash_len(key->hash_algo) != auth_data_len) { + if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) + flog_warn(EC_OSPF_AUTH, + "interface %s: Key ID %d in keychain %s hash length mismatch, Router-ID %pI4", + IF_NAME(oi), key_id, keychain->name, + &ospfh->router_id); + return 0; + } + + /* Backward compatibility with RFC 2328 keyed-MD5 authentication */ + if (key->hash_algo == KEYCHAIN_ALGO_MD5) + return ospf_auth_check_md5_digest(oi, ospfh, iph, key); + + return ospf_auth_check_hmac_sha_digest(oi, ospfh, iph, key); +} + +int ospf_auth_make_digest(struct ospf_interface *oi, struct ospf_packet *op) +{ + struct ospf_header *ospfh; + void *ibuf; + struct keychain *keychain = NULL; + struct key *key = NULL; + int key_id; + + ibuf = STREAM_DATA(op->s); + ospfh = (struct ospf_header *)ibuf; + + key_id = ospfh->u.crypt.key_id; + + if (!OSPF_IF_PARAM(oi, keychain_name)) { + if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) + flog_warn(EC_OSPF_AUTH, + "interface %s: Keychain is not set, Router-ID %pI4", + IF_NAME(oi), &ospfh->router_id); + return 0; + } + + keychain = oi->keychain; + if (!keychain) { + if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, SEND)) + flog_warn(EC_OSPF_AUTH, + "interface %s: Keychain %s is not available to send, Router-ID %pI4", + IF_NAME(oi), OSPF_IF_PARAM(oi, keychain_name), + &ospfh->router_id); + return 0; + } + + key = oi->key; + if (!key) { + if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, SEND)) + flog_warn(EC_OSPF_AUTH, + "interface %s: Key ID %d not found in keychain %s, Router-ID %pI4", + IF_NAME(oi), key_id, keychain->name, + &ospfh->router_id); + return 0; + } + + if (key->string == NULL || key->hash_algo == KEYCHAIN_ALGO_NULL) { + if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, SEND)) + flog_warn(EC_OSPF_AUTH, + "interface %s: Key ID %d in keychain %s is incomplete, Router-ID %pI4", + IF_NAME(oi), key_id, keychain->name, + &ospfh->router_id); + return 0; + } + + /* Backward compatibility with RFC 2328 keyed-MD5 authentication */ + if (key->hash_algo == KEYCHAIN_ALGO_MD5) + return ospf_auth_make_md5_digest(oi, op, key); + else + return ospf_auth_make_hmac_sha_digest(oi, op, key); +} + +/* This function is called from ospf_write(), it will detect the + * authentication scheme and if it is MD5, it will change the sequence + * and update the MD5 digest. + */ + +int ospf_auth_make(struct ospf_interface *oi, struct ospf_packet *op) +{ + struct ospf_header *ospfh; + unsigned char digest[OSPF_AUTH_MD5_SIZE] = {0}; +#ifdef CRYPTO_OPENSSL + EVP_MD_CTX *ctx; +#elif CRYPTO_INTERNAL + MD5_CTX ctx; +#endif + void *ibuf; + uint32_t t; + struct crypt_key *ck; + const uint8_t *auth_key = NULL; + + ibuf = STREAM_DATA(op->s); + ospfh = (struct ospf_header *)ibuf; + + if (ntohs(ospfh->auth_type) != OSPF_AUTH_CRYPTOGRAPHIC) + return 0; + + /* We do this here so when we dup a packet, we don't have to + * waste CPU rewriting other headers. + + Note that frr_time /deliberately/ is not used here. + */ + t = (time(NULL) & 0xFFFFFFFF); + if (t > oi->crypt_seqnum) + oi->crypt_seqnum = t; + else + oi->crypt_seqnum++; + + ospfh->u.crypt.crypt_seqnum = htonl(oi->crypt_seqnum); + + /* Get MD5 Authentication key from auth_key list. */ + if (list_isempty(OSPF_IF_PARAM(oi, auth_crypt)) && OSPF_IF_PARAM(oi, keychain_name) == NULL) + auth_key = (const uint8_t *)digest; + else if (!list_isempty(OSPF_IF_PARAM(oi, auth_crypt))) { + ck = listgetdata(listtail(OSPF_IF_PARAM(oi, auth_crypt))); + auth_key = ck->auth_key; + } + + if (auth_key) { + /* Generate a digest for the entire packet + our secret key. */ +#ifdef CRYPTO_OPENSSL + uint32_t md5_size = OSPF_AUTH_MD5_SIZE; + + ctx = EVP_MD_CTX_new(); + EVP_DigestInit(ctx, EVP_md5()); + EVP_DigestUpdate(ctx, ibuf, ntohs(ospfh->length)); + EVP_DigestUpdate(ctx, auth_key, OSPF_AUTH_MD5_SIZE); + EVP_DigestFinal(ctx, digest, &md5_size); + EVP_MD_CTX_free(ctx); +#elif CRYPTO_INTERNAL + memset(&ctx, 0, sizeof(ctx)); + MD5Init(&ctx); + MD5Update(&ctx, ibuf, ntohs(ospfh->length)); + MD5Update(&ctx, auth_key, OSPF_AUTH_MD5_SIZE); + MD5Final(digest, &ctx); +#endif + + /* Append md5 digest to the end of the stream. */ + stream_put(op->s, digest, OSPF_AUTH_MD5_SIZE); + + /* We do *NOT* increment the OSPF header length. */ + op->length = ntohs(ospfh->length) + OSPF_AUTH_MD5_SIZE; + + if (stream_get_endp(op->s) != op->length) + /* XXX size_t */ + flog_warn( + EC_OSPF_AUTH, + "%s: length mismatch stream %lu ospf_packet %u, Router-ID %pI4", + __func__, (unsigned long)stream_get_endp(op->s), + op->length, &ospfh->router_id); + + return OSPF_AUTH_MD5_SIZE; + } else + return ospf_auth_make_digest(oi, op); +} + +/* Return 1, if the packet is properly authenticated and checksummed, + * 0 otherwise. In particular, check that AuType header field is valid and + * matches the locally configured AuType, and that D.5 requirements are met. + */ +int ospf_auth_check(struct ospf_interface *oi, struct ip *iph, + struct ospf_header *ospfh) +{ + uint16_t iface_auth_type; + uint16_t pkt_auth_type = ntohs(ospfh->auth_type); + + iface_auth_type = ospf_auth_type(oi); + + switch (pkt_auth_type) { + case OSPF_AUTH_NULL: /* RFC2328 D.5.1 */ + if (iface_auth_type != OSPF_AUTH_NULL) { + if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) + flog_warn( + EC_OSPF_PACKET, + "interface %s: auth-type mismatch, local %s, rcvd Null, Router-ID %pI4", + IF_NAME(oi), + lookup_msg(ospf_auth_type_str, + iface_auth_type, NULL), + &ospfh->router_id); + return 0; + } + if (!ospf_check_sum(ospfh)) { + if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) + flog_warn( + EC_OSPF_PACKET, + "interface %s: Null auth OK, but checksum error, Router-ID %pI4", + IF_NAME(oi), + &ospfh->router_id); + return 0; + } + return 1; + case OSPF_AUTH_SIMPLE: /* RFC2328 D.5.2 */ + if (iface_auth_type != OSPF_AUTH_SIMPLE) { + if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) + flog_warn( + EC_OSPF_PACKET, + "interface %s: auth-type mismatch, local %s, rcvd Simple, Router-ID %pI4", + IF_NAME(oi), + lookup_msg(ospf_auth_type_str, + iface_auth_type, NULL), + &ospfh->router_id); + return 0; + } + if (memcmp(OSPF_IF_PARAM(oi, auth_simple), ospfh->u.auth_data, + OSPF_AUTH_SIMPLE_SIZE)) { + if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) + flog_warn( + EC_OSPF_PACKET, + "interface %s: Simple auth failed, Router-ID %pI4", + IF_NAME(oi), &ospfh->router_id); + return 0; + } + if (!ospf_check_sum(ospfh)) { + if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) + flog_warn( + EC_OSPF_PACKET, + "interface %s: Simple auth OK, checksum error, Router-ID %pI4", + IF_NAME(oi), + &ospfh->router_id); + return 0; + } + return 1; + case OSPF_AUTH_CRYPTOGRAPHIC: /* RFC2328 D.5.3 */ + if (iface_auth_type != OSPF_AUTH_CRYPTOGRAPHIC) { + if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) + flog_warn( + EC_OSPF_PACKET, + "interface %s: auth-type mismatch, local %s, rcvd Cryptographic, Router-ID %pI4", + IF_NAME(oi), + lookup_msg(ospf_auth_type_str, + iface_auth_type, NULL), + &ospfh->router_id); + return 0; + } + if (ospfh->checksum) { + if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) + flog_warn( + EC_OSPF_PACKET, + "interface %s: OSPF header checksum is not 0, Router-ID %pI4", + IF_NAME(oi), &ospfh->router_id); + return 0; + } + /* If `authentication message-digest` key is not set, we try keychain crypto */ + if (OSPF_IF_PARAM(oi, keychain_name) || !list_isempty(OSPF_IF_PARAM(oi, auth_crypt))) + return ospf_auth_check_digest(oi, iph, ospfh); + if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) + flog_warn( + EC_OSPF_AUTH, + "interface %s: MD5 auth failed, Router-ID %pI4", + IF_NAME(oi), &ospfh->router_id); + return 0; + default: + if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) + flog_warn( + EC_OSPF_PACKET, + "interface %s: invalid packet auth-type (%02x), Router-ID %pI4", + IF_NAME(oi), pkt_auth_type, &ospfh->router_id); + return 0; + } +} + +/* OSPF authentication checking function */ +int ospf_auth_type(struct ospf_interface *oi) +{ + int auth_type; + + if (OSPF_IF_PARAM(oi, auth_type) == OSPF_AUTH_NOTSET) + auth_type = oi->area->auth_type; + else + auth_type = OSPF_IF_PARAM(oi, auth_type); + + /* Handle case where MD5 key list, or a key-chain, is not configured aka Cisco */ + if (auth_type == OSPF_AUTH_CRYPTOGRAPHIC + && (list_isempty(OSPF_IF_PARAM(oi, auth_crypt)) + && OSPF_IF_PARAM(oi, keychain_name) == NULL)) + return OSPF_AUTH_NULL; + + return auth_type; +} + +/* Make Authentication Data. */ +int ospf_auth_make_data(struct ospf_interface *oi, struct ospf_header *ospfh) +{ + struct crypt_key *ck; + + switch (ospf_auth_type(oi)) { + case OSPF_AUTH_NULL: + /* memset (ospfh->u.auth_data, 0, sizeof(ospfh->u.auth_data)); + */ + break; + case OSPF_AUTH_SIMPLE: + memcpy(ospfh->u.auth_data, OSPF_IF_PARAM(oi, auth_simple), + OSPF_AUTH_SIMPLE_SIZE); + break; + case OSPF_AUTH_CRYPTOGRAPHIC: + if (OSPF_IF_PARAM(oi, keychain_name)) { + oi->keychain = keychain_lookup(OSPF_IF_PARAM(oi, keychain_name)); + if (oi->keychain) + oi->key = key_lookup_for_send(oi->keychain); + if (oi->key) { + ospfh->u.crypt.zero = 0; + ospfh->u.crypt.key_id = oi->key->index; + ospfh->u.crypt.auth_data_len = keychain_get_hash_len(oi->key->hash_algo); + } else { + /* If key is not set, then set 0. */ + ospfh->u.crypt.zero = 0; + ospfh->u.crypt.key_id = 0; + ospfh->u.crypt.auth_data_len = OSPF_AUTH_MD5_SIZE; + } + } else { + /* If key is not set, then set 0. */ + if (list_isempty(OSPF_IF_PARAM(oi, auth_crypt))) { + ospfh->u.crypt.zero = 0; + ospfh->u.crypt.key_id = 0; + ospfh->u.crypt.auth_data_len = OSPF_AUTH_MD5_SIZE; + } else { + ck = listgetdata( + listtail(OSPF_IF_PARAM(oi, auth_crypt))); + ospfh->u.crypt.zero = 0; + ospfh->u.crypt.key_id = ck->key_id; + ospfh->u.crypt.auth_data_len = OSPF_AUTH_MD5_SIZE; + } + } + /* note: the seq is done in ospf_auth_make() */ + break; + default: + /* memset (ospfh->u.auth_data, 0, sizeof(ospfh->u.auth_data)); + */ + break; + } + + return 0; +} diff --git a/ospfd/ospf_auth.h b/ospfd/ospf_auth.h new file mode 100644 index 0000000000..6f6d3db588 --- /dev/null +++ b/ospfd/ospf_auth.h @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2023 Amnesh Inc. + * Mahdi Varasteh + */ + +#ifndef _ZEBRA_OSPF_AUTH_H +#define _ZEBRA_OSPF_AUTH_H + +#include <ospfd/ospf_gr.h> +#include <ospfd/ospf_packet.h> + +int ospf_auth_check(struct ospf_interface *oi, struct ip *iph, struct ospf_header *ospfh); +int ospf_auth_check_digest(struct ospf_interface *oi, struct ip *iph, struct ospf_header *ospfh); +int ospf_auth_make(struct ospf_interface *oi, struct ospf_packet *op); +int ospf_auth_make_digest(struct ospf_interface *oi, struct ospf_packet *op); +int ospf_auth_type(struct ospf_interface *oi); +int ospf_auth_make_data(struct ospf_interface *oi, struct ospf_header *ospfh); + +#endif /* _ZEBRA_OSPF_AUTH_H */ diff --git a/ospfd/ospf_errors.c b/ospfd/ospf_errors.c index 16aa3ab526..cf58c6ad8b 100644 --- a/ospfd/ospf_errors.c +++ b/ospfd/ospf_errors.c @@ -19,9 +19,9 @@ static struct log_ref ferr_ospf_warn[] = { .suggestion = "Do not use this particular set command for an ospf route-map", }, { - .code = EC_OSPF_MD5, - .title = "OSPF has noticed a MD5 issue", - .description = "Something has gone wrong with the calculation of the MD5 data", + .code = EC_OSPF_AUTH, + .title = "OSPF has noticed an authentication issue", + .description = "Something has gone wrong with the calculation of the authentication data", .suggestion = "Ensure your key is correct, gather log data from this side as well as peer and open an Issue", }, { diff --git a/ospfd/ospf_errors.h b/ospfd/ospf_errors.h index dcf9a65ce9..e63cb7409c 100644 --- a/ospfd/ospf_errors.h +++ b/ospfd/ospf_errors.h @@ -22,7 +22,7 @@ enum ospf_log_refs { EC_OSPF_INVALID_ALGORITHM, EC_OSPF_FSM_INVALID_STATE, EC_OSPF_SET_METRIC_PLUS, - EC_OSPF_MD5, + EC_OSPF_AUTH, EC_OSPF_PACKET, EC_OSPF_LARGE_LSA, EC_OSPF_LSA_UNEXPECTED, diff --git a/ospfd/ospf_ext.c b/ospfd/ospf_ext.c index 75b58035a3..d82c2146c7 100644 --- a/ospfd/ospf_ext.c +++ b/ospfd/ospf_ext.c @@ -1734,8 +1734,12 @@ static uint16_t show_vty_ext_link_adj_sid(struct vty *vty, struct tlv_header *tlvh) { struct ext_subtlv_adj_sid *top = (struct ext_subtlv_adj_sid *)tlvh; + uint8_t tlv_size; - check_tlv_size(EXT_SUBTLV_ADJ_SID_SIZE, "Adjacency SID"); + tlv_size = CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG) + ? SID_LABEL_SIZE(EXT_SUBTLV_ADJ_SID_SIZE) + : SID_INDEX_SIZE(EXT_SUBTLV_ADJ_SID_SIZE); + check_tlv_size(tlv_size, "Adjacency SID"); vty_out(vty, " Adj-SID Sub-TLV: Length %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\t%s: %u\n", @@ -1755,8 +1759,12 @@ static uint16_t show_vty_ext_link_lan_adj_sid(struct vty *vty, { struct ext_subtlv_lan_adj_sid *top = (struct ext_subtlv_lan_adj_sid *)tlvh; + uint8_t tlv_size; - check_tlv_size(EXT_SUBTLV_LAN_ADJ_SID_SIZE, "Lan-Adjacency SID"); + tlv_size = CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG) + ? SID_LABEL_SIZE(EXT_SUBTLV_LAN_ADJ_SID_SIZE) + : SID_INDEX_SIZE(EXT_SUBTLV_LAN_ADJ_SID_SIZE); + check_tlv_size(tlv_size, "LAN-Adjacency SID"); vty_out(vty, " LAN-Adj-SID Sub-TLV: Length %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\tNeighbor ID: %pI4\n\t%s: %u\n", @@ -1867,8 +1875,12 @@ static uint16_t show_vty_ext_pref_pref_sid(struct vty *vty, { struct ext_subtlv_prefix_sid *top = (struct ext_subtlv_prefix_sid *)tlvh; + uint8_t tlv_size; - check_tlv_size(EXT_SUBTLV_PREFIX_SID_SIZE, "Prefix SID"); + tlv_size = CHECK_FLAG(top->flags, EXT_SUBTLV_PREFIX_SID_VFLG) + ? SID_LABEL_SIZE(EXT_SUBTLV_PREFIX_SID_SIZE) + : SID_INDEX_SIZE(EXT_SUBTLV_PREFIX_SID_SIZE); + check_tlv_size(tlv_size, "Prefix SID"); vty_out(vty, " Prefix SID Sub-TLV: Length %u\n\tAlgorithm: %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\t%s: %u\n", diff --git a/ospfd/ospf_flood.c b/ospfd/ospf_flood.c index a4d0f77faf..95a593ad4d 100644 --- a/ospfd/ospf_flood.c +++ b/ospfd/ospf_flood.c @@ -154,11 +154,11 @@ struct external_info *ospf_external_info_check(struct ospf *ospf, redist_on = is_default_prefix4(&p) ? vrf_bitmap_check( - zclient->default_information[AFI_IP], - ospf->vrf_id) - : (zclient->mi_redist[AFI_IP][type].enabled - || vrf_bitmap_check( - zclient->redist[AFI_IP][type], + &zclient->default_information[AFI_IP], + ospf->vrf_id) + : (zclient->mi_redist[AFI_IP][type].enabled || + vrf_bitmap_check( + &zclient->redist[AFI_IP][type], ospf->vrf_id)); // Pending: check for MI above. if (redist_on) { @@ -568,6 +568,15 @@ int ospf_flood_through_interface(struct ospf_interface *oi, if (!ospf_if_is_enable(oi)) return 0; + if (IS_OPAQUE_LSA(lsa->data->type) && + !OSPF_IF_PARAM(oi, opaque_capable)) { + if (IS_DEBUG_OSPF(lsa, LSA_FLOODING)) + zlog_debug( + "%s: Skipping interface %s (%s) with opaque disabled.", + __func__, IF_NAME(oi), ospf_get_name(oi->ospf)); + return 0; + } + /* If flood reduction is configured, set the DC bit on the lsa. */ if (IS_LSA_SELF(lsa)) { if (OSPF_FR_CONFIG(oi->area->ospf, oi->area)) { @@ -945,7 +954,7 @@ int ospf_flood_through(struct ospf *ospf, struct ospf_neighbor *inbr, if (IS_DEBUG_OSPF_NSSA) zlog_debug("%s: LOCAL NSSA FLOOD of Type-7.", __func__); - /* Fallthrough */ + fallthrough; default: lsa_ack_flag = ospf_flood_through_area(lsa->area, inbr, lsa); break; diff --git a/ospfd/ospf_gr.c b/ospfd/ospf_gr.c index 2a346f2388..c23c42052f 100644 --- a/ospfd/ospf_gr.c +++ b/ospfd/ospf_gr.c @@ -773,8 +773,15 @@ static void ospf_gr_prepare(void) } /* Send a Grace-LSA to all neighbors. */ - for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, inode, oi)) - ospf_gr_lsa_originate(oi, OSPF_GR_SW_RESTART, false); + for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, inode, oi)) { + if (OSPF_IF_PARAM(oi, opaque_capable)) + ospf_gr_lsa_originate(oi, OSPF_GR_SW_RESTART, + false); + else + zlog_debug( + "GR: skipping grace LSA on interface %s (%s) with opaque capability disabled", + IF_NAME(oi), ospf_get_name(oi->ospf)); + } /* Record end of the grace period in non-volatile memory. */ ospf_gr_nvm_update(ospf, true); diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c index 2c66cb3cfc..0969ae15bd 100644 --- a/ospfd/ospf_interface.c +++ b/ospfd/ospf_interface.c @@ -271,6 +271,10 @@ struct ospf_interface *ospf_if_new(struct ospf *ospf, struct interface *ifp, QOBJ_REG(oi, ospf_interface); + /* If first oi, check per-intf write socket */ + if (ospf->oi_running && ospf->intf_socket_enabled) + ospf_ifp_sock_init(ifp); + if (IS_DEBUG_OSPF_EVENT) zlog_debug("%s: ospf interface %s vrf %s id %u created", __func__, ifp->name, ospf_get_name(ospf), @@ -327,12 +331,16 @@ void ospf_if_cleanup(struct ospf_interface *oi) void ospf_if_free(struct ospf_interface *oi) { + struct interface *ifp = oi->ifp; + ospf_if_down(oi); ospf_fifo_free(oi->obuf); assert(oi->state == ISM_Down); + ospf_opaque_type9_lsa_if_cleanup(oi); + ospf_opaque_type9_lsa_term(oi); QOBJ_UNREG(oi); @@ -361,6 +369,10 @@ void ospf_if_free(struct ospf_interface *oi) event_cancel_event(master, oi); + /* If last oi, close per-interface socket */ + if (ospf_oi_count(ifp) == 0) + ospf_ifp_sock_close(ifp); + memset(oi, 0, sizeof(*oi)); XFREE(MTYPE_OSPF_IF, oi); } @@ -370,26 +382,6 @@ int ospf_if_is_up(struct ospf_interface *oi) return if_is_up(oi->ifp); } -struct ospf_interface *ospf_if_exists(struct ospf_interface *oic) -{ - struct listnode *node; - struct ospf *ospf; - struct ospf_interface *oi; - - if (!oic) - return NULL; - - ospf = oic->ospf; - if (ospf == NULL) - return NULL; - - for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) - if (oi == oic) - return oi; - - return NULL; -} - /* Lookup OSPF interface by router LSA posistion */ struct ospf_interface *ospf_if_lookup_by_lsa_pos(struct ospf_area *area, int lsa_pos) @@ -538,6 +530,8 @@ static struct ospf_if_params *ospf_new_if_params(void) UNSET_IF_PARAM(oip, auth_crypt); UNSET_IF_PARAM(oip, auth_type); UNSET_IF_PARAM(oip, if_area); + UNSET_IF_PARAM(oip, opaque_capable); + UNSET_IF_PARAM(oip, keychain_name); oip->auth_crypt = list_new(); @@ -546,6 +540,7 @@ static struct ospf_if_params *ospf_new_if_params(void) oip->ptp_dmvpn = 0; oip->p2mp_delay_reflood = OSPF_P2MP_DELAY_REFLOOD_DEFAULT; + oip->opaque_capable = OSPF_OPAQUE_CAPABLE_DEFAULT; return oip; } @@ -554,6 +549,7 @@ static void ospf_del_if_params(struct interface *ifp, struct ospf_if_params *oip) { list_delete(&oip->auth_crypt); + XFREE(MTYPE_OSPF_IF_PARAMS, oip->keychain_name); ospf_interface_disable_bfd(ifp, oip); ldp_sync_info_free(&(oip->ldp_sync_info)); XFREE(MTYPE_OSPF_IF_PARAMS, oip); @@ -575,19 +571,22 @@ void ospf_free_if_params(struct interface *ifp, struct in_addr addr) oip = rn->info; route_unlock_node(rn); - if (!OSPF_IF_PARAM_CONFIGURED(oip, output_cost_cmd) - && !OSPF_IF_PARAM_CONFIGURED(oip, transmit_delay) - && !OSPF_IF_PARAM_CONFIGURED(oip, retransmit_interval) - && !OSPF_IF_PARAM_CONFIGURED(oip, passive_interface) - && !OSPF_IF_PARAM_CONFIGURED(oip, v_hello) - && !OSPF_IF_PARAM_CONFIGURED(oip, fast_hello) - && !OSPF_IF_PARAM_CONFIGURED(oip, v_wait) - && !OSPF_IF_PARAM_CONFIGURED(oip, priority) - && !OSPF_IF_PARAM_CONFIGURED(oip, type) - && !OSPF_IF_PARAM_CONFIGURED(oip, auth_simple) - && !OSPF_IF_PARAM_CONFIGURED(oip, auth_type) - && !OSPF_IF_PARAM_CONFIGURED(oip, if_area) - && listcount(oip->auth_crypt) == 0) { + if (!OSPF_IF_PARAM_CONFIGURED(oip, output_cost_cmd) && + !OSPF_IF_PARAM_CONFIGURED(oip, transmit_delay) && + !OSPF_IF_PARAM_CONFIGURED(oip, retransmit_interval) && + !OSPF_IF_PARAM_CONFIGURED(oip, passive_interface) && + !OSPF_IF_PARAM_CONFIGURED(oip, v_hello) && + !OSPF_IF_PARAM_CONFIGURED(oip, fast_hello) && + !OSPF_IF_PARAM_CONFIGURED(oip, v_wait) && + !OSPF_IF_PARAM_CONFIGURED(oip, priority) && + !OSPF_IF_PARAM_CONFIGURED(oip, type) && + !OSPF_IF_PARAM_CONFIGURED(oip, auth_simple) && + !OSPF_IF_PARAM_CONFIGURED(oip, auth_type) && + !OSPF_IF_PARAM_CONFIGURED(oip, if_area) && + !OSPF_IF_PARAM_CONFIGURED(oip, opaque_capable) && + !OSPF_IF_PARAM_CONFIGURED(oip, prefix_suppression) && + !OSPF_IF_PARAM_CONFIGURED(oip, keychain_name) && + listcount(oip->auth_crypt) == 0) { ospf_del_if_params(ifp, oip); rn->info = NULL; route_unlock_node(rn); @@ -693,6 +692,11 @@ int ospf_if_new_hook(struct interface *ifp) SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type); IF_DEF_PARAMS(ifp)->auth_type = OSPF_AUTH_NOTSET; + SET_IF_PARAM(IF_DEF_PARAMS(ifp), opaque_capable); + IF_DEF_PARAMS(ifp)->opaque_capable = OSPF_OPAQUE_CAPABLE_DEFAULT; + + IF_DEF_PARAMS(ifp)->prefix_suppression = OSPF_PREFIX_SUPPRESSION_DEFAULT; + rc = ospf_opaque_new_if(ifp); return rc; } @@ -910,7 +914,7 @@ struct ospf_interface *ospf_vl_new(struct ospf *ospf, { struct ospf_interface *voi; struct interface *vi; - char ifname[INTERFACE_NAMSIZ]; + char ifname[IFNAMSIZ]; struct ospf_area *area; struct in_addr area_id; struct connected *co; @@ -940,7 +944,7 @@ struct ospf_interface *ospf_vl_new(struct ospf *ospf, UNSET_FLAG(vi->status, ZEBRA_INTERFACE_LINKDETECTION); co = connected_new(); co->ifp = vi; - listnode_add(vi->connected, co); + if_connected_add_tail(vi->connected, co); p = prefix_ipv4_new(); p->family = AF_INET; @@ -1145,7 +1149,7 @@ static int ospf_vl_set_params(struct ospf_area *area, if (IS_DEBUG_OSPF_EVENT) zlog_debug( "found back link through VL"); - /* fallthru */ + fallthrough; case LSA_LINK_TYPE_TRANSIT: case LSA_LINK_TYPE_POINTOPOINT: if (!IPV4_ADDR_SAME(&vl_data->peer_addr, @@ -1346,18 +1350,28 @@ static int ospf_ifp_create(struct interface *ifp) if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE)) zlog_debug( - "Zebra: interface add %s vrf %s[%u] index %d flags %llx metric %d mtu %d speed %u", + "Zebra: interface add %s vrf %s[%u] index %d flags %llx metric %d mtu %d speed %u status 0x%x", ifp->name, ifp->vrf->name, ifp->vrf->vrf_id, ifp->ifindex, (unsigned long long)ifp->flags, - ifp->metric, ifp->mtu, ifp->speed); + ifp->metric, ifp->mtu, ifp->speed, ifp->status); assert(ifp->info); oii = ifp->info; oii->curr_mtu = ifp->mtu; - if (IF_DEF_PARAMS(ifp) - && !OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), type)) { + /* Change ospf type param based on following + * condition: + * ospf type params is not set (first creation), + * OR ospf param type is changed based on + * link event, currently only handle for + * loopback interface type, for other ospf interface, + * type can be set from user config which needs to be + * preserved. + */ + if (IF_DEF_PARAMS(ifp) && + (!OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), type) || + if_is_loopback(ifp))) { SET_IF_PARAM(IF_DEF_PARAMS(ifp), type); IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp); } @@ -1394,7 +1408,8 @@ static int ospf_ifp_up(struct interface *ifp) /* Open per-intf write socket if configured */ ospf = ifp->vrf->info; - if (ospf && ospf->intf_socket_enabled) + + if (ospf && ospf->oi_running && ospf->intf_socket_enabled) ospf_ifp_sock_init(ifp); ospf_if_recalculate_output_cost(ifp); @@ -1529,8 +1544,10 @@ void ospf_reset_hello_timer(struct interface *ifp, struct in_addr addr, void ospf_if_init(void) { - if_zapi_callbacks(ospf_ifp_create, ospf_ifp_up, - ospf_ifp_down, ospf_ifp_destroy); + hook_register_prio(if_real, 0, ospf_ifp_create); + hook_register_prio(if_up, 0, ospf_ifp_up); + hook_register_prio(if_down, 0, ospf_ifp_down); + hook_register_prio(if_unreal, 0, ospf_ifp_destroy); /* Initialize Zebra interface data structure. */ hook_register_prio(if_add, 0, ospf_if_new_hook); diff --git a/ospfd/ospf_interface.h b/ospfd/ospf_interface.h index ec1afa1b8b..08a2b11273 100644 --- a/ospfd/ospf_interface.h +++ b/ospfd/ospf_interface.h @@ -10,6 +10,7 @@ #include "lib/bfd.h" #include "qobj.h" #include "hook.h" +#include "keychain.h" #include "ospfd/ospf_packet.h" #include "ospfd/ospf_spf.h" @@ -81,6 +82,9 @@ struct ospf_if_params { /* Fast-Hellos */ DECLARE_IF_PARAM(uint8_t, fast_hello); + /* Prefix-Suppression */ + DECLARE_IF_PARAM(bool, prefix_suppression); + /* Authentication data. */ uint8_t auth_simple[OSPF_AUTH_SIMPLE_SIZE + 1]; /* Simple password. */ uint8_t auth_simple__config : 1; @@ -89,6 +93,8 @@ struct ospf_if_params { auth_crypt); /* List of Auth cryptographic data. */ DECLARE_IF_PARAM(int, auth_type); /* OSPF authentication type */ + DECLARE_IF_PARAM(char*, keychain_name); /* OSPF HMAC Cryptographic Authentication*/ + /* Other, non-configuration state */ uint32_t network_lsa_seqnum; /* Network LSA seqnum */ @@ -112,6 +118,9 @@ struct ospf_if_params { /* point-to-multipoint delayed reflooding configuration */ bool p2mp_delay_reflood; + + /* Opaque LSA capability at interface level (see RFC5250) */ + DECLARE_IF_PARAM(bool, opaque_capable); }; enum { MEMBER_ALLROUTERS = 0, @@ -273,6 +282,10 @@ struct ospf_interface { uint32_t full_nbrs; + /* Buffered values for keychain and key */ + struct keychain *keychain; + struct key *key; + QOBJ_FIELDS; }; DECLARE_QOBJ_TYPE(ospf_interface); @@ -287,7 +300,6 @@ extern int ospf_if_up(struct ospf_interface *oi); extern int ospf_if_down(struct ospf_interface *oi); extern int ospf_if_is_up(struct ospf_interface *oi); -extern struct ospf_interface *ospf_if_exists(struct ospf_interface *oi); extern struct ospf_interface *ospf_if_lookup_by_lsa_pos(struct ospf_area *area, int lsa_pos); extern struct ospf_interface * diff --git a/ospfd/ospf_ism.h b/ospfd/ospf_ism.h index 426dda7733..bbb059c789 100644 --- a/ospfd/ospf_ism.h +++ b/ospfd/ospf_ism.h @@ -69,7 +69,7 @@ /* Macro for OSPF execute event. */ #define OSPF_ISM_EVENT_EXECUTE(I, E) \ - event_execute(master, ospf_ism_event, (I), (E)) + event_execute(master, ospf_ism_event, (I), (E), NULL) /* Prototypes. */ extern void ospf_ism_event(struct event *thread); diff --git a/ospfd/ospf_ldp_sync.c b/ospfd/ospf_ldp_sync.c index b97e87faa0..4aab880d22 100644 --- a/ospfd/ospf_ldp_sync.c +++ b/ospfd/ospf_ldp_sync.c @@ -637,6 +637,9 @@ static int show_ip_ospf_mpls_ldp_interface_common(struct vty *vty, rn = route_next(rn)) { oi = rn->info; + if (oi == NULL) + continue; + if (use_json) { json_interface_sub = json_object_new_object(); @@ -672,6 +675,9 @@ static int show_ip_ospf_mpls_ldp_interface_common(struct vty *vty, rn = route_next(rn)) { oi = rn->info; + if (oi == NULL) + continue; + if (use_json) json_interface_sub = json_object_new_object(); diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index 67f1faf8a9..f125fa93b1 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -539,16 +539,23 @@ static int lsa_link_ptop_set(struct stream **s, struct ospf_interface *oi) } /* no need for a stub link for unnumbered interfaces */ - if (oi->ptp_dmvpn - || !CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) { - /* Regardless of the state of the neighboring router, we must - add a Type 3 link (stub network). - N.B. Options 1 & 2 share basically the same logic. */ - masklen2ip(oi->address->prefixlen, &mask); - id.s_addr = CONNECTED_PREFIX(oi->connected)->u.prefix4.s_addr - & mask.s_addr; - links += link_info_set(s, id, mask, LSA_LINK_TYPE_STUB, 0, - oi->output_cost); + if (OSPF_IF_PARAM(oi, prefix_suppression)) { + if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) + zlog_debug("LSA[Type1]: Interface %s stub link omitted due prefix-suppression", + oi->ifp->name); + } else { + if (oi->ptp_dmvpn || + !CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) { + /* Regardless of the state of the neighboring router, we must + add a Type 3 link (stub network). + N.B. Options 1 & 2 share basically the same logic. */ + masklen2ip(oi->address->prefixlen, &mask); + id.s_addr = + CONNECTED_PREFIX(oi->connected)->u.prefix4.s_addr & + mask.s_addr; + links += link_info_set(s, id, mask, LSA_LINK_TYPE_STUB, + 0, oi->output_cost); + } } return links; @@ -563,10 +570,15 @@ static int lsa_link_broadcast_set(struct stream **s, struct ospf_interface *oi) /* Describe Type 3 Link. */ if (oi->state == ISM_Waiting) { + if (OSPF_IF_PARAM(oi, prefix_suppression)) { + if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) + zlog_debug("LSA[Type1]: Interface %s stub link omitted due prefix-suppression", + oi->ifp->name); + return 0; + } if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) - zlog_debug( - "LSA[Type1]: Interface %s is in state Waiting. Adding stub interface", - oi->ifp->name); + zlog_debug("LSA[Type1]: Interface %s is in state Waiting. Adding stub interface", + oi->ifp->name); masklen2ip(oi->address->prefixlen, &mask); id.s_addr = oi->address->u.prefix4.s_addr & mask.s_addr; return link_info_set(s, id, mask, LSA_LINK_TYPE_STUB, 0, @@ -587,10 +599,15 @@ static int lsa_link_broadcast_set(struct stream **s, struct ospf_interface *oi) } /* Describe type 3 link. */ else { + if (OSPF_IF_PARAM(oi, prefix_suppression)) { + if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) + zlog_debug("LSA[Type1]: Interface %s stub link omitted due prefix-suppression", + oi->ifp->name); + return 0; + } if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) - zlog_debug( - "LSA[Type1]: Interface %s has no DR. Adding stub interface", - oi->ifp->name); + zlog_debug("LSA[Type1]: Interface %s has no DR. Adding stub interface", + oi->ifp->name); masklen2ip(oi->address->prefixlen, &mask); id.s_addr = oi->address->u.prefix4.s_addr & mask.s_addr; return link_info_set(s, id, mask, LSA_LINK_TYPE_STUB, 0, @@ -603,7 +620,7 @@ static int lsa_link_loopback_set(struct stream **s, struct ospf_interface *oi) struct in_addr id, mask; /* Describe Type 3 Link. */ - if (oi->state != ISM_Loopback) + if ((oi->state != ISM_Loopback) || OSPF_IF_PARAM(oi, prefix_suppression)) return 0; mask.s_addr = 0xffffffff; @@ -645,9 +662,15 @@ static int lsa_link_ptomp_set(struct stream **s, struct ospf_interface *oi) struct in_addr id, mask; uint16_t cost = ospf_link_cost(oi); - mask.s_addr = 0xffffffff; - id.s_addr = oi->address->u.prefix4.s_addr; - links += link_info_set(s, id, mask, LSA_LINK_TYPE_STUB, 0, 0); + if (OSPF_IF_PARAM(oi, prefix_suppression)) { + if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) + zlog_debug("LSA[Type1]: Interface %s stub link omitted due prefix-suppression", + oi->ifp->name); + } else { + mask.s_addr = 0xffffffff; + id.s_addr = oi->address->u.prefix4.s_addr; + links += link_info_set(s, id, mask, LSA_LINK_TYPE_STUB, 0, 0); + } if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) zlog_debug("PointToMultipoint: running ptomultip_set"); @@ -1006,7 +1029,14 @@ static void ospf_network_lsa_body_set(struct stream *s, struct route_node *rn; struct ospf_neighbor *nbr; - masklen2ip(oi->address->prefixlen, &mask); + if (OSPF_IF_PARAM(oi, prefix_suppression)) { + mask.s_addr = 0xffffffff; + if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) + zlog_debug("LSA[Type2]: Interface %s network mask set to host mask due prefix-suppression", + oi->ifp->name); + } else { + masklen2ip(oi->address->prefixlen, &mask); + } stream_put_ipv4(s, mask.s_addr); /* The network-LSA lists those routers that are fully adjacent to @@ -2007,7 +2037,6 @@ static struct ospf_lsa *ospf_lsa_translated_nssa_new(struct ospf *ospf, /* add translated flag, checksum and lock new lsa */ SET_FLAG(new->flags, OSPF_LSA_LOCAL_XLT); /* Translated from 7 */ - new = ospf_lsa_lock(new); return new; } @@ -3067,13 +3096,14 @@ struct ospf_lsa *ospf_lsa_install(struct ospf *ospf, struct ospf_interface *oi, /* Incoming "oi" for this LSA has set at LSUpd * reception. */ } - /* Fallthrough */ + fallthrough; case OSPF_OPAQUE_AREA_LSA: case OSPF_OPAQUE_AS_LSA: new = ospf_opaque_lsa_install(lsa, rt_recalc); break; case OSPF_AS_NSSA_LSA: new = ospf_external_lsa_install(ospf, lsa, rt_recalc); + break; default: /* type-6,8,9....nothing special */ break; } @@ -3751,7 +3781,7 @@ void ospf_flush_self_originated_lsas_now(struct ospf *ospf) */ if (ospf->t_maxage != NULL) { EVENT_OFF(ospf->t_maxage); - event_execute(master, ospf_maxage_lsa_remover, ospf, 0); + event_execute(master, ospf_maxage_lsa_remover, ospf, 0, NULL); } return; diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c index 1f476a7e3d..a2a1c4a94f 100644 --- a/ospfd/ospf_main.c +++ b/ospfd/ospf_main.c @@ -27,6 +27,7 @@ #include "vrf.h" #include "libfrr.h" #include "routemap.h" +#include "keychain.h" #include "ospfd/ospfd.h" #include "ospfd/ospf_interface.h" @@ -88,6 +89,7 @@ static void sigint(void) zlog_notice("Terminating on signal"); bfd_protocol_integration_set_shutdown(true); ospf_terminate(); + exit(0); } @@ -134,6 +136,32 @@ FRR_DAEMON_INFO(ospfd, OSPF, .vty_port = OSPF_VTY_PORT, .n_yang_modules = array_size(ospfd_yang_modules), ); +/** Max wait time for config to load before accepting hellos */ +#define OSPF_PRE_CONFIG_MAX_WAIT_SECONDS 600 + +static void ospf_config_finish(struct event *t) +{ + zlog_err("OSPF configuration end timer expired after %d seconds.", + OSPF_PRE_CONFIG_MAX_WAIT_SECONDS); +} + +static void ospf_config_start(void) +{ + EVENT_OFF(t_ospf_cfg); + if (IS_DEBUG_OSPF_EVENT) + zlog_debug("ospfd config start callback received."); + event_add_timer(master, ospf_config_finish, NULL, + OSPF_PRE_CONFIG_MAX_WAIT_SECONDS, &t_ospf_cfg); +} + +static void ospf_config_end(void) +{ + if (IS_DEBUG_OSPF_EVENT) + zlog_debug("ospfd config end callback received."); + + EVENT_OFF(t_ospf_cfg); +} + /* OSPFd main routine. */ int main(int argc, char **argv) { @@ -192,6 +220,10 @@ int main(int argc, char **argv) access_list_init(); prefix_list_init(); + keychain_init(); + + /* Configuration processing callback initialization. */ + cmd_init_config_callbacks(ospf_config_start, ospf_config_end); /* OSPFd inits. */ ospf_if_init(); diff --git a/ospfd/ospf_network.c b/ospfd/ospf_network.c index aff8ed05c7..801f75ad18 100644 --- a/ospfd/ospf_network.c +++ b/ospfd/ospf_network.c @@ -159,7 +159,8 @@ int ospf_if_ipmulticast(int fd, struct prefix *p, ifindex_t ifindex) * Helper to open and set up a socket; returns the new fd on success, * -1 on error. */ -static int sock_init_common(vrf_id_t vrf_id, const char *name, int *pfd) +static int sock_init_common(vrf_id_t vrf_id, const char *name, int proto, + int *pfd) { int ospf_sock; int ret, hincl = 1; @@ -170,8 +171,7 @@ static int sock_init_common(vrf_id_t vrf_id, const char *name, int *pfd) } frr_with_privs(&ospfd_privs) { - ospf_sock = vrf_socket(AF_INET, SOCK_RAW, IPPROTO_OSPFIGP, - vrf_id, name); + ospf_sock = vrf_socket(AF_INET, SOCK_RAW, proto, vrf_id, name); if (ospf_sock < 0) { flog_err(EC_LIB_SOCKET, "%s: socket: %s", __func__, safe_strerror(errno)); @@ -244,7 +244,8 @@ int ospf_sock_init(struct ospf *ospf) if (ospf->fd > 0) return -1; - ret = sock_init_common(ospf->vrf_id, ospf->name, &(ospf->fd)); + ret = sock_init_common(ospf->vrf_id, ospf->name, IPPROTO_OSPFIGP, + &(ospf->fd)); if (ret >= 0) /* Update socket buffer sizes */ ospf_sock_bufsize_update(ospf, ospf->fd, OSPF_SOCK_BOTH); @@ -258,8 +259,8 @@ int ospf_sock_init(struct ospf *ospf) int ospf_ifp_sock_init(struct interface *ifp) { struct ospf_if_info *oii; - struct ospf_interface *oi; - struct ospf *ospf; + struct ospf_interface *oi = NULL; + struct ospf *ospf = NULL; struct route_node *rn; int ret; @@ -270,17 +271,26 @@ int ospf_ifp_sock_init(struct interface *ifp) if (oii->oii_fd > 0) return 0; - rn = route_top(IF_OIFS(ifp)); - if (rn && rn->info) { - oi = rn->info; - ospf = oi->ospf; - } else + for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { + if (rn && rn->info) { + oi = rn->info; + ospf = oi->ospf; + break; + } + } + + if (ospf == NULL) return -1; - ret = sock_init_common(ifp->vrf->vrf_id, ifp->name, &oii->oii_fd); + ret = sock_init_common(ifp->vrf->vrf_id, ifp->name, IPPROTO_OSPFIGP, + &oii->oii_fd); - if (ret >= 0) /* Update socket buffer sizes */ - ospf_sock_bufsize_update(ospf, oii->oii_fd, OSPF_SOCK_BOTH); + if (ret >= 0) { /* Update socket buffer sizes */ + /* Write-only, so no recv buf */ + setsockopt_so_recvbuf(oii->oii_fd, 0); + + ospf_sock_bufsize_update(ospf, oii->oii_fd, OSPF_SOCK_SEND); + } if (IS_DEBUG_OSPF_EVENT) zlog_debug("%s: ifp %s, oii %p, fd %d", __func__, ifp->name, diff --git a/ospfd/ospf_nsm.c b/ospfd/ospf_nsm.c index bcbe028795..08aa103686 100644 --- a/ospfd/ospf_nsm.c +++ b/ospfd/ospf_nsm.c @@ -107,7 +107,7 @@ static void nsm_timer_set(struct ospf_neighbor *nbr) case NSM_Down: EVENT_OFF(nbr->t_inactivity); EVENT_OFF(nbr->t_hello_reply); - /* fallthru */ + fallthrough; case NSM_Attempt: case NSM_Init: case NSM_TwoWay: @@ -219,7 +219,7 @@ static int ospf_db_summary_add(struct ospf_neighbor *nbr, struct ospf_lsa *lsa) case OSPF_OPAQUE_LINK_LSA: /* Exclude type-9 LSAs that does not have the same "oi" with * "nbr". */ - if (ospf_if_exists(lsa->oi) != nbr->oi) + if (lsa->oi != nbr->oi) return 0; break; case OSPF_OPAQUE_AREA_LSA: diff --git a/ospfd/ospf_nsm.h b/ospfd/ospf_nsm.h index 9973b4870d..82e17208aa 100644 --- a/ospfd/ospf_nsm.h +++ b/ospfd/ospf_nsm.h @@ -49,7 +49,7 @@ /* Macro for OSPF NSM execute event. */ #define OSPF_NSM_EVENT_EXECUTE(N, E) \ - event_execute(master, ospf_nsm_event, (N), (E)) + event_execute(master, ospf_nsm_event, (N), (E), NULL) /* Prototypes. */ extern void ospf_nsm_event(struct event *e); diff --git a/ospfd/ospf_opaque.c b/ospfd/ospf_opaque.c index 6894c6a009..24a850c737 100644 --- a/ospfd/ospf_opaque.c +++ b/ospfd/ospf_opaque.c @@ -257,7 +257,7 @@ static void free_opaque_info_per_type(struct opaque_info_per_type *oipt, struct ospf_opaque_functab { uint8_t opaque_type; - struct opaque_info_per_type *oipt; + uint32_t ref_count; int (*new_if_hook)(struct interface *ifp); int (*del_if_hook)(struct interface *ifp); @@ -280,9 +280,28 @@ static struct list *ospf_opaque_type9_funclist; static struct list *ospf_opaque_type10_funclist; static struct list *ospf_opaque_type11_funclist; +static void ospf_opaque_functab_ref(struct ospf_opaque_functab *functab) +{ + functab->ref_count++; +} + +static void ospf_opaque_functab_deref(struct ospf_opaque_functab *functab) +{ + assert(functab->ref_count); + functab->ref_count--; + if (functab->ref_count == 0) + XFREE(MTYPE_OSPF_OPAQUE_FUNCTAB, functab); +} + static void ospf_opaque_del_functab(void *val) { - XFREE(MTYPE_OSPF_OPAQUE_FUNCTAB, val); + struct ospf_opaque_functab *functab = (struct ospf_opaque_functab *)val; + + if (IS_DEBUG_OSPF_EVENT) + zlog_debug("%s: Opaque LSA functab list deletion callback type %u (%p)", + __func__, functab->opaque_type, functab); + + ospf_opaque_functab_deref(functab); return; } @@ -290,6 +309,9 @@ static void ospf_opaque_funclist_init(void) { struct list *funclist; + if (IS_DEBUG_OSPF_EVENT) + zlog_debug("%s: Function list initialize", __func__); + funclist = ospf_opaque_wildcard_funclist = list_new(); funclist->del = ospf_opaque_del_functab; @@ -308,6 +330,9 @@ static void ospf_opaque_funclist_term(void) { struct list *funclist; + if (IS_DEBUG_OSPF_EVENT) + zlog_debug("%s: Function list terminate", __func__); + funclist = ospf_opaque_wildcard_funclist; list_delete(&funclist); @@ -383,18 +408,24 @@ int ospf_register_opaque_functab( for (ALL_LIST_ELEMENTS(funclist, node, nnode, functab)) if (functab->opaque_type == opaque_type) { - flog_warn( - EC_OSPF_LSA, - "%s: Duplicated entry?: lsa_type(%u), opaque_type(%u)", - __func__, lsa_type, opaque_type); - return -1; + if (IS_DEBUG_OSPF_EVENT) + zlog_debug("%s: Opaque LSA functab found type %u, (%p)", + __func__, functab->opaque_type, + functab); + break; } - new = XCALLOC(MTYPE_OSPF_OPAQUE_FUNCTAB, - sizeof(struct ospf_opaque_functab)); + if (functab == NULL) + new = XCALLOC(MTYPE_OSPF_OPAQUE_FUNCTAB, + sizeof(struct ospf_opaque_functab)); + else { + if (IS_DEBUG_OSPF_EVENT) + zlog_debug("%s: Re-register Opaque LSA type %u, opaque type %u, (%p)", + __func__, lsa_type, opaque_type, functab); + return 0; + } new->opaque_type = opaque_type; - new->oipt = NULL; new->new_if_hook = new_if_hook; new->del_if_hook = del_if_hook; new->ism_change_hook = ism_change_hook; @@ -408,7 +439,12 @@ int ospf_register_opaque_functab( new->new_lsa_hook = new_lsa_hook; new->del_lsa_hook = del_lsa_hook; + if (IS_DEBUG_OSPF_EVENT) + zlog_debug("%s: Register Opaque LSA type %u, opaque type %u, (%p)", + __func__, lsa_type, opaque_type, new); + listnode_add(funclist, new); + ospf_opaque_functab_ref(new); return 0; } @@ -422,15 +458,18 @@ void ospf_delete_opaque_functab(uint8_t lsa_type, uint8_t opaque_type) if ((funclist = ospf_get_opaque_funclist(lsa_type)) != NULL) for (ALL_LIST_ELEMENTS(funclist, node, nnode, functab)) { if (functab->opaque_type == opaque_type) { - /* Cleanup internal control information, if it - * still remains. */ - if (functab->oipt != NULL) - free_opaque_info_per_type(functab->oipt, - true); - /* Dequeue listnode entry from the list. */ + if (IS_DEBUG_OSPF_EVENT) + zlog_debug("%s: Delete Opaque functab LSA type %u, opaque type %u, (%p)", + __func__, lsa_type, + opaque_type, functab); + + /* Dequeue listnode entry from the function table + * list coreesponding to the opaque LSA type. + * Note that the list deletion callback frees + * the functab entry memory. + */ listnode_delete(funclist, functab); - - XFREE(MTYPE_OSPF_OPAQUE_FUNCTAB, functab); + ospf_opaque_functab_deref(functab); break; } } @@ -565,10 +604,15 @@ register_opaque_info_per_type(struct ospf_opaque_functab *functab, oipt->opaque_type = GET_OPAQUE_TYPE(ntohl(new->data->id.s_addr)); oipt->status = PROC_NORMAL; oipt->functab = functab; - functab->oipt = oipt; + ospf_opaque_functab_ref(functab); oipt->id_list = list_new(); oipt->id_list->del = free_opaque_info_per_id; + if (IS_DEBUG_OSPF_EVENT) + zlog_debug("%s: Register Opaque info-per-type LSA type %u, opaque type %u, (%p), Functab (%p)", + __func__, oipt->lsa_type, oipt->opaque_type, oipt, + oipt->functab); + out: return oipt; } @@ -614,6 +658,15 @@ static void free_opaque_info_per_type(struct opaque_info_per_type *oipt, } listnode_delete(l, oipt); } + + if (oipt->functab) + ospf_opaque_functab_deref(oipt->functab); + + if (IS_DEBUG_OSPF_EVENT) + zlog_debug("%s: Free Opaque info-per-type LSA type %u, opaque type %u, (%p), Functab (%p)", + __func__, oipt->lsa_type, oipt->opaque_type, oipt, + oipt->functab); + XFREE(MTYPE_OPAQUE_INFO_PER_TYPE, oipt); return; } @@ -746,6 +799,45 @@ int ospf_opaque_is_owned(struct ospf_lsa *lsa) return (oipt != NULL && lookup_opaque_info_by_id(oipt, lsa) != NULL); } +/* + * Cleanup Link-Local LSAs assocaited with an interface that is being deleted. + * Since these LSAs are stored in the area link state database (LSDB) as opposed + * to a separate per-interface, they must be deleted from the area database. + * Since their flooding scope is solely the deleted OSPF interface, there is no + * need to attempt to flush them from the routing domain. For link local LSAs + * originated via the OSPF server API, LSA deletion before interface deletion + * is required so that the callback can access the OSPF interface address. + */ +void ospf_opaque_type9_lsa_if_cleanup(struct ospf_interface *oi) +{ + struct route_node *rn; + struct ospf_lsdb *lsdb; + struct ospf_lsa *lsa; + + lsdb = oi->area->lsdb; + LSDB_LOOP (OPAQUE_LINK_LSDB(oi->area), rn, lsa) + /* + * While the LSA shouldn't be referenced on any LSA + * lists since the flooding scoped is confined to the + * interface being deleted, clear the pointer to the + * deleted interface to avoid references and set the + * age to MAXAGE to avoid flush processing when the LSA + * is removed from the interface opaque info list. + */ + if (lsa->oi == oi) { + if (IS_DEBUG_OSPF_EVENT) + zlog_debug("Delete Type-9 Opaque-LSA on interface delete: [opaque-type=%u, opaque-id=%x]", + GET_OPAQUE_TYPE( + ntohl(lsa->data->id.s_addr)), + GET_OPAQUE_ID(ntohl( + lsa->data->id.s_addr))); + ospf_lsdb_delete(lsdb, lsa); + lsa->data->ls_age = htons(OSPF_LSA_MAXAGE); + lsa->oi = NULL; + ospf_lsa_discard(lsa); + } +} + /*------------------------------------------------------------------------* * Following are (vty) configuration functions for Opaque-LSAs handling. *------------------------------------------------------------------------*/ @@ -1851,9 +1943,9 @@ static void ospf_opaque_type9_lsa_reoriginate_timer(struct event *t) return; } - if (!CHECK_FLAG(top->config, OSPF_OPAQUE_CAPABLE) - || !ospf_if_is_enable(oi) - || ospf_nbr_count_opaque_capable(oi) == 0) { + if (!CHECK_FLAG(top->config, OSPF_OPAQUE_CAPABLE) || + !OSPF_IF_PARAM(oi, opaque_capable) || !ospf_if_is_enable(oi) || + ospf_nbr_count_opaque_capable(oi) == 0) { if (IS_DEBUG_OSPF_EVENT) zlog_debug( "Suspend re-origination of Type-9 Opaque-LSAs (opaque-type=%u) for a while...", diff --git a/ospfd/ospf_opaque.h b/ospfd/ospf_opaque.h index e0c78cd6dc..54651f8f58 100644 --- a/ospfd/ospf_opaque.h +++ b/ospfd/ospf_opaque.h @@ -109,6 +109,7 @@ extern void ospf_opaque_term(void); extern void ospf_opaque_finish(void); extern int ospf_opaque_type9_lsa_init(struct ospf_interface *oi); extern void ospf_opaque_type9_lsa_term(struct ospf_interface *oi); +extern void ospf_opaque_type9_lsa_if_cleanup(struct ospf_interface *oi); extern int ospf_opaque_type10_lsa_init(struct ospf_area *area); extern void ospf_opaque_type10_lsa_term(struct ospf_area *area); extern int ospf_opaque_type11_lsa_init(struct ospf *ospf); diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c index d010b8b6e6..4bf4ae9597 100644 --- a/ospfd/ospf_packet.c +++ b/ospfd/ospf_packet.c @@ -41,6 +41,7 @@ #include "ospfd/ospf_errors.h" #include "ospfd/ospf_zebra.h" #include "ospfd/ospf_gr.h" +#include "ospfd/ospf_auth.h" /* * OSPF Fragmentation / fragmented writes @@ -99,27 +100,6 @@ static const uint16_t ospf_lsa_minlen[] = { OSPF_OPAQUE_LSA_MIN_SIZE, /* OSPF_OPAQUE_AS_LSA */ }; -/* for ospf_check_auth() */ -static int ospf_check_sum(struct ospf_header *); - -/* OSPF authentication checking function */ -static int ospf_auth_type(struct ospf_interface *oi) -{ - int auth_type; - - if (OSPF_IF_PARAM(oi, auth_type) == OSPF_AUTH_NOTSET) - auth_type = oi->area->auth_type; - else - auth_type = OSPF_IF_PARAM(oi, auth_type); - - /* Handle case where MD5 key list is not configured aka Cisco */ - if (auth_type == OSPF_AUTH_CRYPTOGRAPHIC - && list_isempty(OSPF_IF_PARAM(oi, auth_crypt))) - return OSPF_AUTH_NULL; - - return auth_type; -} - static struct ospf_packet *ospf_packet_new(size_t size) { struct ospf_packet *new; @@ -258,8 +238,8 @@ static struct ospf_packet *ospf_packet_dup(struct ospf_packet *op) "ospf_packet_dup stream %lu ospf_packet %u size mismatch", (unsigned long)STREAM_SIZE(op->s), op->length); - /* Reserve space for MD5 authentication that may be added later. */ - new = ospf_packet_new(stream_get_endp(op->s) + OSPF_AUTH_MD5_SIZE); + /* Reserve space for MD5/HMAC SHA authentication that may be added later. */ + new = ospf_packet_new(stream_get_endp(op->s) + KEYCHAIN_MAX_HASH_SIZE); stream_copy(new->s, op->s); new->dst = op->dst; @@ -274,7 +254,7 @@ static unsigned int ospf_packet_authspace(struct ospf_interface *oi) int auth = 0; if (ospf_auth_type(oi) == OSPF_AUTH_CRYPTOGRAPHIC) - auth = OSPF_AUTH_MD5_SIZE; + auth = KEYCHAIN_MAX_HASH_SIZE; return auth; } @@ -290,155 +270,6 @@ static unsigned int ospf_packet_max(struct ospf_interface *oi) return max; } - -static int ospf_check_md5_digest(struct ospf_interface *oi, - struct ospf_header *ospfh) -{ -#ifdef CRYPTO_OPENSSL - EVP_MD_CTX *ctx; -#elif CRYPTO_INTERNAL - MD5_CTX ctx; -#endif - unsigned char digest[OSPF_AUTH_MD5_SIZE]; - struct crypt_key *ck; - struct ospf_neighbor *nbr; - uint16_t length = ntohs(ospfh->length); - - /* Get secret key. */ - ck = ospf_crypt_key_lookup(OSPF_IF_PARAM(oi, auth_crypt), - ospfh->u.crypt.key_id); - if (ck == NULL) { - flog_warn( - EC_OSPF_MD5, - "interface %s: ospf_check_md5 no key %d, Router-ID: %pI4", - IF_NAME(oi), ospfh->u.crypt.key_id, &ospfh->router_id); - return 0; - } - - /* check crypto seqnum. */ - nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, &ospfh->router_id); - - if (nbr - && ntohl(nbr->crypt_seqnum) > ntohl(ospfh->u.crypt.crypt_seqnum)) { - flog_warn( - EC_OSPF_MD5, - "interface %s: ospf_check_md5 bad sequence %d (expect %d), Router-ID: %pI4", - IF_NAME(oi), ntohl(ospfh->u.crypt.crypt_seqnum), - ntohl(nbr->crypt_seqnum), &ospfh->router_id); - return 0; - } - - /* Generate a digest for the ospf packet - their digest + our digest. */ -#ifdef CRYPTO_OPENSSL - unsigned int md5_size = OSPF_AUTH_MD5_SIZE; - ctx = EVP_MD_CTX_new(); - EVP_DigestInit(ctx, EVP_md5()); - EVP_DigestUpdate(ctx, ospfh, length); - EVP_DigestUpdate(ctx, ck->auth_key, OSPF_AUTH_MD5_SIZE); - EVP_DigestFinal(ctx, digest, &md5_size); - EVP_MD_CTX_free(ctx); -#elif CRYPTO_INTERNAL - memset(&ctx, 0, sizeof(ctx)); - MD5Init(&ctx); - MD5Update(&ctx, ospfh, length); - MD5Update(&ctx, ck->auth_key, OSPF_AUTH_MD5_SIZE); - MD5Final(digest, &ctx); -#endif - - /* compare the two */ - if (memcmp((caddr_t)ospfh + length, digest, OSPF_AUTH_MD5_SIZE)) { - flog_warn( - EC_OSPF_MD5, - "interface %s: ospf_check_md5 checksum mismatch, Router-ID: %pI4", - IF_NAME(oi), &ospfh->router_id); - return 0; - } - - /* save neighbor's crypt_seqnum */ - if (nbr) - nbr->crypt_seqnum = ospfh->u.crypt.crypt_seqnum; - return 1; -} - -/* This function is called from ospf_write(), it will detect the - authentication scheme and if it is MD5, it will change the sequence - and update the MD5 digest. */ -static int ospf_make_md5_digest(struct ospf_interface *oi, - struct ospf_packet *op) -{ - struct ospf_header *ospfh; - unsigned char digest[OSPF_AUTH_MD5_SIZE] = {0}; -#ifdef CRYPTO_OPENSSL - EVP_MD_CTX *ctx; -#elif CRYPTO_INTERNAL - MD5_CTX ctx; -#endif - void *ibuf; - uint32_t t; - struct crypt_key *ck; - const uint8_t *auth_key; - - ibuf = STREAM_DATA(op->s); - ospfh = (struct ospf_header *)ibuf; - - if (ntohs(ospfh->auth_type) != OSPF_AUTH_CRYPTOGRAPHIC) - return 0; - - /* We do this here so when we dup a packet, we don't have to - waste CPU rewriting other headers. - - Note that frr_time /deliberately/ is not used here */ - t = (time(NULL) & 0xFFFFFFFF); - if (t > oi->crypt_seqnum) - oi->crypt_seqnum = t; - else - oi->crypt_seqnum++; - - ospfh->u.crypt.crypt_seqnum = htonl(oi->crypt_seqnum); - - /* Get MD5 Authentication key from auth_key list. */ - if (list_isempty(OSPF_IF_PARAM(oi, auth_crypt))) - auth_key = (const uint8_t *)digest; - else { - ck = listgetdata(listtail(OSPF_IF_PARAM(oi, auth_crypt))); - auth_key = ck->auth_key; - } - - /* Generate a digest for the entire packet + our secret key. */ -#ifdef CRYPTO_OPENSSL - unsigned int md5_size = OSPF_AUTH_MD5_SIZE; - ctx = EVP_MD_CTX_new(); - EVP_DigestInit(ctx, EVP_md5()); - EVP_DigestUpdate(ctx, ibuf, ntohs(ospfh->length)); - EVP_DigestUpdate(ctx, auth_key, OSPF_AUTH_MD5_SIZE); - EVP_DigestFinal(ctx, digest, &md5_size); - EVP_MD_CTX_free(ctx); -#elif CRYPTO_INTERNAL - memset(&ctx, 0, sizeof(ctx)); - MD5Init(&ctx); - MD5Update(&ctx, ibuf, ntohs(ospfh->length)); - MD5Update(&ctx, auth_key, OSPF_AUTH_MD5_SIZE); - MD5Final(digest, &ctx); -#endif - - /* Append md5 digest to the end of the stream. */ - stream_put(op->s, digest, OSPF_AUTH_MD5_SIZE); - - /* We do *NOT* increment the OSPF header length. */ - op->length = ntohs(ospfh->length) + OSPF_AUTH_MD5_SIZE; - - if (stream_get_endp(op->s) != op->length) - /* XXX size_t */ - flog_warn( - EC_OSPF_MD5, - "%s: length mismatch stream %lu ospf_packet %u, Router-ID %pI4", - __func__, (unsigned long)stream_get_endp(op->s), - op->length, &ospfh->router_id); - - return OSPF_AUTH_MD5_SIZE; -} - - static void ospf_ls_req_timer(struct event *thread) { struct ospf_neighbor *nbr; @@ -677,7 +508,7 @@ static void ospf_write(struct event *thread) ospf_if_ipmulticast(fd, oi->address, oi->ifp->ifindex); /* Rewrite the md5 signature & update the seq */ - ospf_make_md5_digest(oi, op); + ospf_auth_make(oi, op); /* Retrieve OSPF packet type. */ stream_set_getp(op->s, 1); @@ -953,8 +784,9 @@ static void ospf_hello(struct ip *iph, struct ospf_header *ospfh, } #endif /* REJECT_IF_TBIT_ON */ - if (CHECK_FLAG(oi->ospf->config, OSPF_OPAQUE_CAPABLE) - && CHECK_FLAG(hello->options, OSPF_OPTION_O)) { + if (CHECK_FLAG(oi->ospf->config, OSPF_OPAQUE_CAPABLE) && + OSPF_IF_PARAM(oi, opaque_capable) && + CHECK_FLAG(hello->options, OSPF_OPTION_O)) { /* * This router does know the correct usage of O-bit * the bit should be set in DD packet only. @@ -1210,7 +1042,7 @@ static void ospf_db_desc_proc(struct stream *s, struct ospf_interface *oi, /* Neighbour has a more recent LSA, we must request it */ ospf_ls_request_add(nbr, new); - /* fallthru */ + fallthrough; case 0: /* If we have a copy of this LSA, it's either less * recent @@ -1362,8 +1194,9 @@ static void ospf_db_desc(struct ip *iph, struct ospf_header *ospfh, } #endif /* REJECT_IF_TBIT_ON */ - if (CHECK_FLAG(dd->options, OSPF_OPTION_O) - && !CHECK_FLAG(oi->ospf->config, OSPF_OPAQUE_CAPABLE)) { + if (CHECK_FLAG(dd->options, OSPF_OPTION_O) && + (!CHECK_FLAG(oi->ospf->config, OSPF_OPAQUE_CAPABLE) || + !OSPF_IF_PARAM(oi, opaque_capable))) { /* * This node is not configured to handle O-bit, for now. * Clear it to ignore unsupported capability proposed by @@ -1398,7 +1231,7 @@ static void ospf_db_desc(struct ip *iph, struct ospf_header *ospfh, through to case ExStart below. */ if (nbr->state != NSM_ExStart) break; - /* fallthru */ + fallthrough; case NSM_ExStart: /* Initial DBD */ if ((IS_SET_DD_ALL(dd->flags) == OSPF_DD_FLAG_ALL) @@ -1448,7 +1281,8 @@ static void ospf_db_desc(struct ip *iph, struct ospf_header *ospfh, /* This is where the real Options are saved */ nbr->options = dd->options; - if (CHECK_FLAG(oi->ospf->config, OSPF_OPAQUE_CAPABLE)) { + if (CHECK_FLAG(oi->ospf->config, OSPF_OPAQUE_CAPABLE) && + OSPF_IF_PARAM(oi, opaque_capable)) { if (IS_DEBUG_OSPF_EVENT) zlog_debug( "Neighbor[%pI4] is %sOpaque-capable.", @@ -1807,7 +1641,7 @@ static struct list *ospf_ls_upd_list_lsa(struct ospf_neighbor *nbr, case OSPF_OPAQUE_LINK_LSA: lsa->oi = oi; /* Remember incoming interface for flooding control. */ - /* Fallthrough */ + fallthrough; default: lsa->area = oi->area; break; @@ -2473,142 +2307,6 @@ static int ospf_check_network_mask(struct ospf_interface *oi, return 0; } -/* Return 1, if the packet is properly authenticated and checksummed, - 0 otherwise. In particular, check that AuType header field is valid and - matches the locally configured AuType, and that D.5 requirements are met. */ -static int ospf_check_auth(struct ospf_interface *oi, struct ospf_header *ospfh) -{ - struct crypt_key *ck; - uint16_t iface_auth_type; - uint16_t pkt_auth_type = ntohs(ospfh->auth_type); - - switch (pkt_auth_type) { - case OSPF_AUTH_NULL: /* RFC2328 D.5.1 */ - if (OSPF_AUTH_NULL != (iface_auth_type = ospf_auth_type(oi))) { - if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) - flog_warn( - EC_OSPF_PACKET, - "interface %s: auth-type mismatch, local %s, rcvd Null, Router-ID %pI4", - IF_NAME(oi), - lookup_msg(ospf_auth_type_str, - iface_auth_type, NULL), - &ospfh->router_id); - return 0; - } - if (!ospf_check_sum(ospfh)) { - if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) - flog_warn( - EC_OSPF_PACKET, - "interface %s: Null auth OK, but checksum error, Router-ID %pI4", - IF_NAME(oi), - &ospfh->router_id); - return 0; - } - return 1; - case OSPF_AUTH_SIMPLE: /* RFC2328 D.5.2 */ - if (OSPF_AUTH_SIMPLE - != (iface_auth_type = ospf_auth_type(oi))) { - if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) - flog_warn( - EC_OSPF_PACKET, - "interface %s: auth-type mismatch, local %s, rcvd Simple, Router-ID %pI4", - IF_NAME(oi), - lookup_msg(ospf_auth_type_str, - iface_auth_type, NULL), - &ospfh->router_id); - return 0; - } - if (memcmp(OSPF_IF_PARAM(oi, auth_simple), ospfh->u.auth_data, - OSPF_AUTH_SIMPLE_SIZE)) { - if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) - flog_warn( - EC_OSPF_PACKET, - "interface %s: Simple auth failed, Router-ID %pI4", - IF_NAME(oi), &ospfh->router_id); - return 0; - } - if (!ospf_check_sum(ospfh)) { - if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) - flog_warn( - EC_OSPF_PACKET, - "interface %s: Simple auth OK, checksum error, Router-ID %pI4", - IF_NAME(oi), - &ospfh->router_id); - return 0; - } - return 1; - case OSPF_AUTH_CRYPTOGRAPHIC: /* RFC2328 D.5.3 */ - if (OSPF_AUTH_CRYPTOGRAPHIC - != (iface_auth_type = ospf_auth_type(oi))) { - if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) - flog_warn( - EC_OSPF_PACKET, - "interface %s: auth-type mismatch, local %s, rcvd Cryptographic, Router-ID %pI4", - IF_NAME(oi), - lookup_msg(ospf_auth_type_str, - iface_auth_type, NULL), - &ospfh->router_id); - return 0; - } - if (ospfh->checksum) { - if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) - flog_warn( - EC_OSPF_PACKET, - "interface %s: OSPF header checksum is not 0, Router-ID %pI4", - IF_NAME(oi), &ospfh->router_id); - return 0; - } - /* only MD5 crypto method can pass ospf_packet_examin() */ - if (NULL == (ck = listgetdata( - listtail(OSPF_IF_PARAM(oi, auth_crypt)))) - || ospfh->u.crypt.key_id != ck->key_id || - /* Condition above uses the last key ID on the list, - which is - different from what ospf_crypt_key_lookup() does. A - bug? */ - !ospf_check_md5_digest(oi, ospfh)) { - if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) - flog_warn( - EC_OSPF_MD5, - "interface %s: MD5 auth failed, Router-ID %pI4", - IF_NAME(oi), &ospfh->router_id); - return 0; - } - return 1; - default: - if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV)) - flog_warn( - EC_OSPF_PACKET, - "interface %s: invalid packet auth-type (%02x), Router-ID %pI4", - IF_NAME(oi), pkt_auth_type, &ospfh->router_id); - return 0; - } -} - -static int ospf_check_sum(struct ospf_header *ospfh) -{ - uint32_t ret; - uint16_t sum; - - /* clear auth_data for checksum. */ - memset(ospfh->u.auth_data, 0, OSPF_AUTH_SIMPLE_SIZE); - - /* keep checksum and clear. */ - sum = ospfh->checksum; - memset(&ospfh->checksum, 0, sizeof(uint16_t)); - - /* calculate checksum. */ - ret = in_cksum(ospfh, ntohs(ospfh->length)); - - if (ret != sum) { - zlog_info("%s: checksum mismatch, my %X, his %X", __func__, ret, - sum); - return 0; - } - - return 1; -} - /* Verify, that given link/TOS records are properly sized/aligned and match Router-LSA "# links" and "# TOS" fields as specified in RFC2328 A.4.2. */ static unsigned ospf_router_lsa_links_examin(struct router_lsa_link *link, @@ -2832,14 +2530,14 @@ static unsigned ospf_packet_examin(struct ospf_header *oh, if (ntohs(oh->auth_type) != OSPF_AUTH_CRYPTOGRAPHIC) bytesauth = 0; else { - if (oh->u.crypt.auth_data_len != OSPF_AUTH_MD5_SIZE) { + if (oh->u.crypt.auth_data_len > KEYCHAIN_MAX_HASH_SIZE) { if (IS_DEBUG_OSPF_PACKET(0, RECV)) zlog_debug( "%s: unsupported crypto auth length (%u B)", __func__, oh->u.crypt.auth_data_len); return MSG_NG; } - bytesauth = OSPF_AUTH_MD5_SIZE; + bytesauth = oh->u.crypt.auth_data_len; } if (bytesdeclared + bytesauth > bytesonwire) { if (IS_DEBUG_OSPF_PACKET(0, RECV)) @@ -2950,7 +2648,7 @@ static int ospf_verify_header(struct stream *ibuf, struct ospf_interface *oi, /* Check authentication. The function handles logging actions, where * required. */ - if (!ospf_check_auth(oi, ospfh)) + if (!ospf_auth_check(oi, iph, ospfh)) return -1; return 0; @@ -3258,44 +2956,6 @@ static void ospf_make_header(int type, struct ospf_interface *oi, stream_forward_endp(s, OSPF_HEADER_SIZE); } -/* Make Authentication Data. */ -static int ospf_make_auth(struct ospf_interface *oi, struct ospf_header *ospfh) -{ - struct crypt_key *ck; - - switch (ospf_auth_type(oi)) { - case OSPF_AUTH_NULL: - /* memset (ospfh->u.auth_data, 0, sizeof(ospfh->u.auth_data)); - */ - break; - case OSPF_AUTH_SIMPLE: - memcpy(ospfh->u.auth_data, OSPF_IF_PARAM(oi, auth_simple), - OSPF_AUTH_SIMPLE_SIZE); - break; - case OSPF_AUTH_CRYPTOGRAPHIC: - /* If key is not set, then set 0. */ - if (list_isempty(OSPF_IF_PARAM(oi, auth_crypt))) { - ospfh->u.crypt.zero = 0; - ospfh->u.crypt.key_id = 0; - ospfh->u.crypt.auth_data_len = OSPF_AUTH_MD5_SIZE; - } else { - ck = listgetdata( - listtail(OSPF_IF_PARAM(oi, auth_crypt))); - ospfh->u.crypt.zero = 0; - ospfh->u.crypt.key_id = ck->key_id; - ospfh->u.crypt.auth_data_len = OSPF_AUTH_MD5_SIZE; - } - /* note: the seq is done in ospf_make_md5_digest() */ - break; - default: - /* memset (ospfh->u.auth_data, 0, sizeof(ospfh->u.auth_data)); - */ - break; - } - - return 0; -} - /* Fill rest of OSPF header. */ static void ospf_fill_header(struct ospf_interface *oi, struct stream *s, uint16_t length) @@ -3314,7 +2974,9 @@ static void ospf_fill_header(struct ospf_interface *oi, struct stream *s, ospfh->checksum = 0; /* Add Authentication Data. */ - ospf_make_auth(oi, ospfh); + oi->keychain = NULL; + oi->key = NULL; + ospf_auth_make_data(oi, ospfh); } static int ospf_make_hello(struct ospf_interface *oi, struct stream *s) @@ -3435,7 +3097,8 @@ static int ospf_make_db_desc(struct ospf_interface *oi, /* Set Options. */ options = OPTIONS(oi); - if (CHECK_FLAG(oi->ospf->config, OSPF_OPAQUE_CAPABLE)) + if (CHECK_FLAG(oi->ospf->config, OSPF_OPAQUE_CAPABLE) && + OSPF_IF_PARAM(oi, opaque_capable)) SET_FLAG(options, OSPF_OPTION_O); if (OSPF_FR_CONFIG(oi->ospf, oi->area)) SET_FLAG(options, OSPF_OPTION_DC); @@ -3682,6 +3345,16 @@ static void ospf_hello_send_sub(struct ospf_interface *oi, in_addr_t addr) struct ospf_packet *op; uint16_t length = OSPF_HEADER_SIZE; + /* Check if config is still being processed */ + if (event_is_scheduled(t_ospf_cfg)) { + if (IS_DEBUG_OSPF_PACKET(0, SEND)) + zlog_debug( + "Suppressing hello to %pI4 on %s during config load", + &(addr), IF_NAME(oi)); + + return; + } + op = ospf_packet_new(oi->ifp->mtu); /* Prepare OSPF common header. */ diff --git a/ospfd/ospf_ri.c b/ospfd/ospf_ri.c index 725443f490..c6aaf3f5a0 100644 --- a/ospfd/ospf_ri.c +++ b/ospfd/ospf_ri.c @@ -153,6 +153,7 @@ static int ospf_router_info_unregister(void) void ospf_router_info_term(void) { + list_delete(&OspfRI.area_info); list_delete(&OspfRI.pce_info.pce_domain); list_delete(&OspfRI.pce_info.pce_neighbor); diff --git a/ospfd/ospf_route.c b/ospfd/ospf_route.c index 75868056ad..170909fa90 100644 --- a/ospfd/ospf_route.c +++ b/ospfd/ospf_route.c @@ -48,6 +48,7 @@ struct ospf_route *ospf_route_new(void) new->paths = list_new(); new->paths->del = (void (*)(void *))ospf_path_free; + new->u.std.transit = false; return new; } @@ -462,6 +463,12 @@ void ospf_intra_add_transit(struct route_table *rt, struct vertex *v, the IP network number, which can be obtained by masking the Vertex ID (Link State ID) with its associated subnet mask (found in the body of the associated network-LSA). */ + if (lsa->mask.s_addr == 0xffffffff) { + if (IS_DEBUG_OSPF_EVENT) + zlog_debug("Suppress installing LSA[Type2,%pI4] route due to host mask", + &(lsa->header.id)); + return; + } p.family = AF_INET; p.prefix = v->id; p.prefixlen = ip_masklen(lsa->mask); @@ -500,6 +507,7 @@ void ospf_intra_add_transit(struct route_table *rt, struct vertex *v, or->cost = v->distance; or->type = OSPF_DESTINATION_NETWORK; or->u.std.origin = (struct lsa_header *)lsa; + or->u.std.transit = true; ospf_route_copy_nexthops_from_vertex(area, or, v); @@ -684,6 +692,8 @@ void ospf_intra_add_stub(struct route_table *rt, struct router_lsa_link *link, __func__); } } + if (rn->info) + ospf_route_free(rn->info); rn->info = or ; @@ -849,7 +859,7 @@ void ospf_route_copy_nexthops_from_vertex(struct ospf_area *area, || area->spf_dry_run) { path = ospf_path_new(); path->nexthop = nexthop->router; - path->adv_router = v->id; + path->adv_router = v->lsa->adv_router; if (oi) { path->ifindex = oi->ifp->ifindex; diff --git a/ospfd/ospf_route.h b/ospfd/ospf_route.h index 7639a0049e..44e80216d7 100644 --- a/ospfd/ospf_route.h +++ b/ospfd/ospf_route.h @@ -69,6 +69,8 @@ struct route_standard { /* */ uint8_t flags; /* From router-LSA */ + + bool transit; /* Transit network or not */ }; struct route_external { diff --git a/ospfd/ospf_snmp.c b/ospfd/ospf_snmp.c index fcc43e7311..fc0c143c28 100644 --- a/ospfd/ospf_snmp.c +++ b/ospfd/ospf_snmp.c @@ -906,7 +906,7 @@ static struct ospf_lsa *ospfLsdbLookup(struct variable *v, oid *name, area = ospf_area_lookup_by_area_id(ospf, *area_id); if (!area) return NULL; - offset += IN_ADDR_SIZE; + offset++; /* Type. */ *type = *offset; @@ -914,7 +914,7 @@ static struct ospf_lsa *ospfLsdbLookup(struct variable *v, oid *name, /* LS ID. */ oid2in_addr(offset, IN_ADDR_SIZE, ls_id); - offset += IN_ADDR_SIZE; + offset++; /* Router ID. */ oid2in_addr(offset, IN_ADDR_SIZE, router_id); @@ -971,7 +971,7 @@ static struct ospf_lsa *ospfLsdbLookup(struct variable *v, oid *name, } /* Router ID. */ - offset += IN_ADDR_SIZE; + offset++; offsetlen -= IN_ADDR_SIZE; len = offsetlen; @@ -996,11 +996,11 @@ static struct ospf_lsa *ospfLsdbLookup(struct variable *v, oid *name, /* Fill in value. */ offset = name + v->namelen; oid_copy_in_addr(offset, area_id); - offset += IN_ADDR_SIZE; + offset++; *offset = lsa->data->type; offset++; oid_copy_in_addr(offset, &lsa->data->id); - offset += IN_ADDR_SIZE; + offset++; oid_copy_in_addr(offset, &lsa->data->adv_router); @@ -1106,7 +1106,7 @@ static struct ospf_area_range *ospfAreaRangeLookup(struct variable *v, if (!area) return NULL; - offset += IN_ADDR_SIZE; + offset++; /* Lookup area range. */ oid2in_addr(offset, IN_ADDR_SIZE, range_net); @@ -1135,7 +1135,7 @@ static struct ospf_area_range *ospfAreaRangeLookup(struct variable *v, return NULL; do { - offset += IN_ADDR_SIZE; + offset++; offsetlen -= IN_ADDR_SIZE; len = offsetlen; @@ -1157,7 +1157,7 @@ static struct ospf_area_range *ospfAreaRangeLookup(struct variable *v, /* Fill in value. */ offset = name + v->namelen; oid_copy_in_addr(offset, area_id); - offset += IN_ADDR_SIZE; + offset++; oid_copy_in_addr(offset, range_net); return range; @@ -1348,7 +1348,7 @@ static int ospf_snmp_if_update(struct interface *ifp) ifindex = 0; /* Lookup first IPv4 address entry. */ - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { + frr_each (if_connected, ifp->connected, ifc) { p = CONNECTED_ID(ifc); if (p->family == AF_INET) { @@ -1396,11 +1396,10 @@ static int ospf_snmp_if_update(struct interface *ifp) static int ospf_snmp_is_if_have_addr(struct interface *ifp) { - struct listnode *nn; struct connected *ifc; /* Is this interface having any connected IPv4 address ? */ - for (ALL_LIST_ELEMENTS_RO(ifp->connected, nn, ifc)) { + frr_each (if_connected, ifp->connected, ifc) { if (CONNECTED_PREFIX(ifc)->family == AF_INET) return 1; } @@ -1560,7 +1559,7 @@ static struct ospf_interface *ospfIfLookup(struct variable *v, oid *name, *length = v->namelen + IN_ADDR_SIZE + 1; offset = name + v->namelen; oid_copy_in_addr(offset, ifaddr); - offset += IN_ADDR_SIZE; + offset++; *offset = *ifindex; return oi; } @@ -1704,7 +1703,7 @@ static struct ospf_interface *ospfIfMetricLookup(struct variable *v, oid *name, *length = v->namelen + IN_ADDR_SIZE + 1 + 1; offset = name + v->namelen; oid_copy_in_addr(offset, ifaddr); - offset += IN_ADDR_SIZE; + offset++; *offset = *ifindex; offset++; *offset = OSPF_SNMP_METRIC_VALUE; @@ -2242,7 +2241,7 @@ static struct ospf_lsa *ospfExtLsdbLookup(struct variable *v, oid *name, /* LS ID. */ oid2in_addr(offset, IN_ADDR_SIZE, ls_id); - offset += IN_ADDR_SIZE; + offset++; /* Router ID. */ oid2in_addr(offset, IN_ADDR_SIZE, router_id); @@ -2270,7 +2269,7 @@ static struct ospf_lsa *ospfExtLsdbLookup(struct variable *v, oid *name, oid2in_addr(offset, len, ls_id); - offset += IN_ADDR_SIZE; + offset++; offsetlen -= IN_ADDR_SIZE; /* Router ID. */ @@ -2293,7 +2292,7 @@ static struct ospf_lsa *ospfExtLsdbLookup(struct variable *v, oid *name, *offset = OSPF_AS_EXTERNAL_LSA; offset++; oid_copy_in_addr(offset, &lsa->data->id); - offset += IN_ADDR_SIZE; + offset++; oid_copy_in_addr(offset, &lsa->data->adv_router); return lsa; diff --git a/ospfd/ospf_te.c b/ospfd/ospf_te.c index 3cf39e5fb5..d203b5ef4d 100644 --- a/ospfd/ospf_te.c +++ b/ospfd/ospf_te.c @@ -980,8 +980,8 @@ static void ospf_mpls_te_nsm_change(struct ospf_neighbor *nbr, int old_state) struct ospf_interface *oi = nbr->oi; struct mpls_te_link *lp; - /* Process Neighbor only when its state is NSM Full */ - if (nbr->state != NSM_Full) + /* Process Link only when neighbor old or new state is NSM Full */ + if (nbr->state != NSM_Full && old_state != NSM_Full) return; /* Get interface information for Traffic Engineering */ @@ -1839,6 +1839,7 @@ static void ospf_te_delete_subnet(struct ls_ted *ted, struct in_addr addr) p.family = AF_INET; p.prefixlen = IPV4_MAX_BITLEN; p.u.prefix4 = addr; + ote_debug(" |- Delete Subnet info. for Prefix %pFX", &p); subnet = ls_find_subnet(ted, &p); /* Remove subnet if found */ @@ -1851,8 +1852,7 @@ static void ospf_te_delete_subnet(struct ls_ted *ted, struct in_addr addr) /** * Parse Router LSA. This function will create or update corresponding Vertex, - * Edge and Subnet. It also remove Edge and Subnet if they are marked as Orphan - * once Router LSA is parsed. + * Edge and Subnet. * * @param ted Link State Traffic Engineering Database * @param lsa OSPF Link State Advertisement @@ -1864,9 +1864,6 @@ static int ospf_te_parse_router_lsa(struct ls_ted *ted, struct ospf_lsa *lsa) struct router_lsa *rl; enum ls_node_type type; struct ls_vertex *vertex; - struct ls_edge *edge; - struct ls_subnet *subnet; - struct listnode *node; int len, links; /* Sanity Check */ @@ -1909,13 +1906,6 @@ static int ospf_te_parse_router_lsa(struct ls_ted *ted, struct ospf_lsa *lsa) vertex->status = SYNC; } - /* Mark outgoing Edge and Subnet as ORPHAN to detect deletion */ - for (ALL_LIST_ELEMENTS_RO(vertex->outgoing_edges, node, edge)) - edge->status = ORPHAN; - - for (ALL_LIST_ELEMENTS_RO(vertex->prefixes, node, subnet)) - subnet->status = ORPHAN; - /* Then, process Link Information */ len = lsa->size - OSPF_LSA_HEADER_SIZE - OSPF_ROUTER_LSA_MIN_SIZE; links = ntohs(rl->links); @@ -1948,11 +1938,6 @@ static int ospf_te_parse_router_lsa(struct ls_ted *ted, struct ospf_lsa *lsa) break; } } - /* Clean remaining Orphan Edges or Subnets */ - if (OspfMplsTE.export) - ls_vertex_clean(ted, vertex, zclient); - else - ls_vertex_clean(ted, vertex, NULL); return 0; } @@ -2405,7 +2390,10 @@ static int ospf_te_delete_te(struct ls_ted *ted, struct ospf_lsa *lsa) ote_debug(" |- Delete TE info. for Edge %pI4", &edge->attributes->standard.local); - /* Remove Link State Attributes TE information */ + /* First remove the associated Subnet */ + ospf_te_delete_subnet(ted, attr->standard.local); + + /* Then ,remove Link State Attributes TE information */ memset(&attr->standard, 0, sizeof(struct ls_standard)); attr->flags &= 0x0FFFF; memset(&attr->extended, 0, sizeof(struct ls_extended)); @@ -2420,7 +2408,6 @@ static int ospf_te_delete_te(struct ls_ted *ted, struct ospf_lsa *lsa) edge->status = SYNC; } else { /* Remove completely the Edge if Segment Routing is not set */ - ospf_te_delete_subnet(ted, attr->standard.local); edge->status = DELETE; ospf_te_export(LS_MSG_TYPE_ATTRIBUTES, edge); ls_edge_del_all(ted, edge); diff --git a/ospfd/ospf_ti_lfa.c b/ospfd/ospf_ti_lfa.c index 07fc503947..d8a2613075 100644 --- a/ospfd/ospf_ti_lfa.c +++ b/ospfd/ospf_ti_lfa.c @@ -64,6 +64,7 @@ ospf_ti_lfa_find_p_node(struct vertex *pc_node, struct p_space *p_space, struct vertex_parent *pc_vertex_parent; curr_node = listnode_lookup(q_space->pc_path, pc_node); + assert(curr_node); pc_node_parent = listgetdata(curr_node->next); q_space->p_node_info->type = OSPF_TI_LFA_UNDEFINED_NODE; @@ -105,6 +106,7 @@ static void ospf_ti_lfa_find_q_node(struct vertex *pc_node, struct vertex_parent *pc_vertex_parent; curr_node = listnode_lookup(q_space->pc_path, pc_node); + assert(curr_node); next_node = curr_node->next; pc_node_parent = listgetdata(next_node); pc_vertex_parent = @@ -219,7 +221,7 @@ static struct list *ospf_ti_lfa_cut_out_pc_path(struct list *pc_vertex_list, current_listnode = listnode_lookup(pc_path, current_vertex); /* Note that the post-convergence paths are reversed. */ - for (;;) { + while (current_listnode) { current_vertex = listgetdata(current_listnode); listnode_add(inner_pc_path, current_vertex); @@ -268,6 +270,7 @@ static void ospf_ti_lfa_generate_inner_label_stack( end_label = MPLS_INVALID_LABEL; if (p_node_info->node->id.s_addr == p_space->root->id.s_addr) { pc_p_node = listnode_lookup(q_space->pc_path, p_space->pc_spf); + assert(pc_p_node); start_vertex = listgetdata(pc_p_node->prev); start_label = ospf_sr_get_adj_sid_by_id(&p_node_info->node->id, &start_vertex->id); @@ -275,6 +278,7 @@ static void ospf_ti_lfa_generate_inner_label_stack( if (q_node_info->node->id.s_addr == q_space->root->id.s_addr) { pc_q_node = listnode_lookup(q_space->pc_path, listnode_head(q_space->pc_path)); + assert(pc_q_node); end_vertex = listgetdata(pc_q_node->next); end_label = ospf_sr_get_adj_sid_by_id(&end_vertex->id, &q_node_info->node->id); @@ -690,6 +694,7 @@ static void ospf_ti_lfa_generate_q_spaces(struct ospf_area *area, __func__, &p_space->root->id, &q_space->root->id, res_buf); + list_delete(&q_space->vertex_list); XFREE(MTYPE_OSPF_Q_SPACE, q_space->p_node_info); XFREE(MTYPE_OSPF_Q_SPACE, q_space->q_node_info); XFREE(MTYPE_OSPF_Q_SPACE, q_space); diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 0ee42e0e70..877c9bd634 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -21,6 +21,8 @@ #include <lib/json.h> #include "defaults.h" #include "lib/printfrr.h" +#include "keychain.h" +#include "frrdistance.h" #include "ospfd/ospfd.h" #include "ospfd/ospf_asbr.h" @@ -40,6 +42,7 @@ #include "ospfd/ospf_bfd.h" #include "ospfd/ospf_ldp_sync.h" #include "ospfd/ospf_network.h" +#include "ospfd/ospf_memory.h" FRR_CFG_DEFAULT_BOOL(OSPF_LOG_ADJACENCY_CHANGES, { .val_bool = true, .match_profile = "datacenter", }, @@ -808,6 +811,8 @@ struct ospf_vl_config_data { char *auth_key; /* simple password if present */ int crypto_key_id; /* Cryptographic key ID */ char *md5_key; /* MD5 authentication key */ + char *keychain; /* Cryptographic keychain */ + int del_keychain; int hello_interval; /* Obvious what these are... */ int retransmit_interval; int transmit_delay; @@ -890,6 +895,10 @@ static int ospf_vl_set_security(struct ospf_vl_data *vl_data, strlcpy((char *)IF_DEF_PARAMS(ifp)->auth_simple, vl_config->auth_key, sizeof(IF_DEF_PARAMS(ifp)->auth_simple)); + } else if (vl_config->keychain) { + SET_IF_PARAM(IF_DEF_PARAMS(ifp), keychain_name); + XFREE(MTYPE_OSPF_IF_PARAMS, IF_DEF_PARAMS(ifp)->keychain_name); + IF_DEF_PARAMS(ifp)->keychain_name = XSTRDUP(MTYPE_OSPF_IF_PARAMS, vl_config->keychain); } else if (vl_config->md5_key) { if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, vl_config->crypto_key_id) @@ -918,6 +927,9 @@ static int ospf_vl_set_security(struct ospf_vl_data *vl_data, ospf_crypt_key_delete(IF_DEF_PARAMS(ifp)->auth_crypt, vl_config->crypto_key_id); + } else if (vl_config->del_keychain) { + UNSET_IF_PARAM(IF_DEF_PARAMS(ifp), keychain_name); + XFREE(MTYPE_OSPF_IF_PARAMS, IF_DEF_PARAMS(ifp)->keychain_name); } return CMD_SUCCESS; @@ -1022,9 +1034,11 @@ static int ospf_vl_set(struct ospf *ospf, struct ospf_vl_config_data *vl_config) DEFUN (ospf_area_vlink, ospf_area_vlink_cmd, - "area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D [authentication [<message-digest|null>]] [<message-digest-key (1-255) md5 KEY|authentication-key AUTH_KEY>]", + "area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D [authentication [<key-chain KEYCHAIN_NAME|message-digest|null>]] [<message-digest-key (1-255) md5 KEY|authentication-key AUTH_KEY>]", VLINK_HELPSTR_IPADDR "Enable authentication on this virtual link\n" + "Use a key-chain for cryptographic authentication keys\n" + "Key-chain name\n" "Use message-digest authentication\n" "Use null authentication\n" VLINK_HELPSTR_AUTH_MD5 @@ -1067,7 +1081,10 @@ DEFUN (ospf_area_vlink, vl_config.auth_type = OSPF_AUTH_SIMPLE; } - if (argv_find(argv, argc, "message-digest", &idx)) { + if (argv_find(argv, argc, "key-chain", &idx)) { + vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC; + vl_config.keychain = argv[idx+1]->arg; + } else if (argv_find(argv, argc, "message-digest", &idx)) { /* authentication message-digest */ vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC; } else if (argv_find(argv, argc, "null", &idx)) { @@ -1097,10 +1114,12 @@ DEFUN (ospf_area_vlink, DEFUN (no_ospf_area_vlink, no_ospf_area_vlink_cmd, - "no area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D [authentication [<message-digest|null>]] [<message-digest-key (1-255) md5 KEY|authentication-key AUTH_KEY>]", + "no area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D [authentication [<key-chain KEYCHAIN_NAME|message-digest|null>]] [<message-digest-key (1-255) md5 KEY|authentication-key AUTH_KEY>]", NO_STR VLINK_HELPSTR_IPADDR "Enable authentication on this virtual link\n" + "Use a key-chain for cryptographic authentication keys\n" + "Key-chain name\n" "Use message-digest authentication\n" "Use null authentication\n" VLINK_HELPSTR_AUTH_MD5 @@ -1160,6 +1179,11 @@ DEFUN (no_ospf_area_vlink, vl_config.auth_type = OSPF_AUTH_NOTSET; } + if (argv_find(argv, argc, "key-chain", &idx)) { + vl_config.del_keychain = 1; + vl_config.keychain = NULL; + } + if (argv_find(argv, argc, "message-digest-key", &idx)) { vl_config.md5_key = NULL; vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); @@ -1529,7 +1553,7 @@ DEFPY (ospf_area_nssa, /* Flush the external LSA for the specified area */ ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA); ospf_schedule_abr_task(ospf); - ospf_schedule_asbr_nssa_redist_update(ospf); + ospf_schedule_asbr_redist_update(ospf); return CMD_SUCCESS; } @@ -2058,6 +2082,13 @@ DEFUN (ospf_abr_type, if (ospf->abr_type != abr_type) { ospf->abr_type = abr_type; ospf_schedule_abr_task(ospf); + + /* The ABR task might not initiate SPF recalculation if the + * OSPF flags remain the same. And inter-area routes would not + * be added/deleted according to the new ABR type. So this + * needs to be done here too. + */ + ospf_spf_calculate_schedule(ospf, SPF_FLAG_ABR_STATUS_CHANGE); } return CMD_SUCCESS; @@ -3590,18 +3621,41 @@ static void ospf_interface_auth_show(struct vty *vty, struct ospf_interface *oi, case OSPF_AUTH_CRYPTOGRAPHIC: { struct crypt_key *ckey; - if (list_isempty(OSPF_IF_PARAM(oi, auth_crypt))) - return; - - ckey = listgetdata(listtail(OSPF_IF_PARAM(oi, auth_crypt))); - if (ckey) { + if (OSPF_IF_PARAM(oi, keychain_name)) { if (use_json) { json_object_string_add(json, "authentication", - "authenticationMessageDigest"); + "authenticationKeyChain"); + json_object_string_add(json, "keychain", + OSPF_IF_PARAM(oi, keychain_name)); } else { vty_out(vty, " Cryptographic authentication enabled\n"); - vty_out(vty, " Algorithm:MD5\n"); + struct keychain *keychain = keychain_lookup(OSPF_IF_PARAM(oi, keychain_name)); + + if (keychain) { + struct key *key = key_lookup_for_send(keychain); + + if (key) { + vty_out(vty, " Sending SA: Key %u, Algorithm %s - key chain %s\n", + key->index, keychain_get_algo_name_by_id(key->hash_algo), + OSPF_IF_PARAM(oi, keychain_name)); + } + } + } + } else { + if (list_isempty(OSPF_IF_PARAM(oi, auth_crypt))) + return; + + ckey = listgetdata(listtail(OSPF_IF_PARAM(oi, auth_crypt))); + if (ckey) { + if (use_json) { + json_object_string_add(json, "authentication", + "authenticationMessageDigest"); + } else { + vty_out(vty, + " Cryptographic authentication enabled\n"); + vty_out(vty, " Algorithm:MD5\n"); + } } } break; @@ -3621,6 +3675,8 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, struct route_node *rn; uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed; struct ospf_if_params *params; + json_object *json_ois = NULL; + json_object *json_oi = NULL; /* Is interface up? */ if (use_json) { @@ -3671,17 +3727,33 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, } } + if (use_json) { + json_ois = json_object_new_object(); + json_object_object_add(json_interface_sub, "interfaceIp", + json_ois); + } + for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { struct ospf_interface *oi = rn->info; if (oi == NULL) continue; +#if CONFDATE > 20240601 + CPP_NOTICE( + "Use all fields following ospfEnabled from interfaceIp hierarchy") +#endif + + if (use_json) + json_oi = json_object_new_object(); + if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) { - if (use_json) + if (use_json) { json_object_boolean_true_add(json_interface_sub, "ifUnnumbered"); - else + json_object_boolean_true_add(json_oi, + "ifUnnumbered"); + } else vty_out(vty, " This interface is UNNUMBERED,"); } else { struct in_addr dest; @@ -3695,6 +3767,13 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, json_object_int_add(json_interface_sub, "ipAddressPrefixlen", oi->address->prefixlen); + + json_object_string_addf( + json_oi, "ipAddress", "%pI4", + &oi->address->u.prefix4); + json_object_int_add(json_oi, + "ipAddressPrefixlen", + oi->address->prefixlen); } else vty_out(vty, " Internet Address %pFX,", oi->address); @@ -3717,17 +3796,29 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, } if (use_json) { - json_object_string_add( - json_interface_sub, - "ospfIfType", dstr); - if (oi->type == OSPF_IFTYPE_VIRTUALLINK) + json_object_string_add(json_interface_sub, + "ospfIfType", dstr); + + json_object_string_add(json_oi, "ospfIfType", + dstr); + + if (oi->type == OSPF_IFTYPE_VIRTUALLINK) { json_object_string_addf( json_interface_sub, "vlinkPeer", "%pI4", &dest); - else + + json_object_string_addf(json_oi, + "vlinkPeer", + "%pI4", &dest); + } else { json_object_string_addf( json_interface_sub, "localIfUsed", "%pI4", &dest); + + json_object_string_addf(json_oi, + "localIfUsed", + "%pI4", &dest); + } } else vty_out(vty, " %s %pI4,", dstr, &dest); @@ -3735,10 +3826,18 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, if (use_json) { json_object_string_add(json_interface_sub, "area", ospf_area_desc_string(oi->area)); - if (OSPF_IF_PARAM(oi, mtu_ignore)) + + json_object_string_add(json_oi, "area", + ospf_area_desc_string(oi->area)); + + if (OSPF_IF_PARAM(oi, mtu_ignore)) { + json_object_boolean_true_add( + json_oi, "mtuMismatchDetect"); json_object_boolean_true_add( json_interface_sub, "mtuMismatchDetect"); + } + json_object_string_addf(json_interface_sub, "routerId", "%pI4", &ospf->router_id); json_object_string_add(json_interface_sub, @@ -3746,14 +3845,29 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, ospf_network_type_str[oi->type]); json_object_int_add(json_interface_sub, "cost", oi->output_cost); - json_object_int_add( - json_interface_sub, "transmitDelaySecs", - OSPF_IF_PARAM(oi, transmit_delay)); + json_object_int_add(json_interface_sub, + "transmitDelaySecs", + OSPF_IF_PARAM(oi, transmit_delay)); json_object_string_add(json_interface_sub, "state", lookup_msg(ospf_ism_state_msg, oi->state, NULL)); json_object_int_add(json_interface_sub, "priority", PRIORITY(oi)); + + json_object_string_addf(json_oi, "routerId", "%pI4", + &ospf->router_id); + json_object_string_add(json_oi, "networkType", + ospf_network_type_str[oi->type]); + json_object_int_add(json_oi, "cost", oi->output_cost); + json_object_int_add(json_oi, "transmitDelaySecs", + OSPF_IF_PARAM(oi, transmit_delay)); + json_object_string_add(json_oi, "state", + lookup_msg(ospf_ism_state_msg, + oi->state, NULL)); + json_object_int_add(json_oi, "priority", PRIORITY(oi)); + json_object_boolean_add( + json_interface_sub, "opaqueCapable", + OSPF_IF_PARAM(oi, opaque_capable)); } else { vty_out(vty, " Area %s\n", ospf_area_desc_string(oi->area)); @@ -3773,6 +3887,9 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, OSPF_IF_PARAM(oi, transmit_delay), lookup_msg(ospf_ism_state_msg, oi->state, NULL), PRIORITY(oi)); + if (!OSPF_IF_PARAM(oi, opaque_capable)) + vty_out(vty, + " Opaque LSA capability disabled on interface\n"); } /* Show DR information. */ @@ -3791,6 +3908,13 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, json_interface_sub, "drAddress", "%pI4", &nbr->address.u.prefix4); + + json_object_string_addf( + json_oi, "drId", "%pI4", + &nbr->router_id); + json_object_string_addf( + json_oi, "drAddress", "%pI4", + &nbr->address.u.prefix4); } else { vty_out(vty, " Designated Router (ID) %pI4", @@ -3816,6 +3940,13 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, json_interface_sub, "bdrAddress", "%pI4", &nbr->address.u.prefix4); + + json_object_string_addf( + json_oi, "bdrId", "%pI4", + &nbr->router_id); + json_object_string_addf( + json_oi, "bdrAddress", "%pI4", + &nbr->address.u.prefix4); } else { vty_out(vty, " Backup Designated Router (ID) %pI4,", @@ -3831,28 +3962,43 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, if (oi->params && ntohl(oi->params->network_lsa_seqnum) != OSPF_INITIAL_SEQUENCE_NUMBER) { - if (use_json) + if (use_json) { json_object_int_add( json_interface_sub, "networkLsaSequence", ntohl(oi->params->network_lsa_seqnum)); - else + + json_object_int_add( + json_oi, "networkLsaSequence", + ntohl(oi->params->network_lsa_seqnum)); + } else { vty_out(vty, " Saved Network-LSA sequence number 0x%x\n", ntohl(oi->params->network_lsa_seqnum)); + } } if (use_json) { if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { - if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) + if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) { json_object_boolean_true_add( json_interface_sub, "mcastMemberOspfAllRouters"); - if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) + + json_object_boolean_true_add( + json_oi, + "mcastMemberOspfAllRouters"); + } + if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { json_object_boolean_true_add( json_interface_sub, "mcastMemberOspfDesignatedRouters"); + + json_object_boolean_true_add( + json_oi, + "mcastMemberOspfDesignatedRouters"); + } } } else { vty_out(vty, " Multicast group memberships:"); @@ -3868,23 +4014,38 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, } if (use_json) { - if (OSPF_IF_PARAM(oi, fast_hello) == 0) + if (OSPF_IF_PARAM(oi, fast_hello) == 0) { json_object_int_add( json_interface_sub, "timerMsecs", OSPF_IF_PARAM(oi, v_hello) * 1000); - else + + json_object_int_add(json_oi, "timerMsecs", + OSPF_IF_PARAM(oi, v_hello) * + 1000); + } else { json_object_int_add( json_interface_sub, "timerMsecs", 1000 / OSPF_IF_PARAM(oi, fast_hello)); - json_object_int_add(json_interface_sub, - "timerDeadSecs", + + json_object_int_add( + json_oi, "timerMsecs", + 1000 / OSPF_IF_PARAM(oi, fast_hello)); + } + json_object_int_add(json_interface_sub, "timerDeadSecs", OSPF_IF_PARAM(oi, v_wait)); - json_object_int_add(json_interface_sub, - "timerWaitSecs", + json_object_int_add(json_interface_sub, "timerWaitSecs", OSPF_IF_PARAM(oi, v_wait)); json_object_int_add( json_interface_sub, "timerRetransmitSecs", OSPF_IF_PARAM(oi, retransmit_interval)); + + json_object_int_add(json_oi, "timerDeadSecs", + OSPF_IF_PARAM(oi, v_wait)); + json_object_int_add(json_oi, "timerWaitSecs", + OSPF_IF_PARAM(oi, v_wait)); + json_object_int_add( + json_oi, "timerRetransmitSecs", + OSPF_IF_PARAM(oi, retransmit_interval)); } else { vty_out(vty, " Timer intervals configured,"); vty_out(vty, " Hello "); @@ -3913,17 +4074,23 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, json_object_int_add(json_interface_sub, "timerHelloInMsecs", time_store); + json_object_int_add(json_oi, + "timerHelloInMsecs", + time_store); } else vty_out(vty, " Hello due in %s\n", ospf_timer_dump(oi->t_hello, timebuf, sizeof(timebuf))); } else /* passive-interface is set */ { - if (use_json) + if (use_json) { json_object_boolean_true_add( json_interface_sub, "timerPassiveIface"); - else + + json_object_boolean_true_add( + json_oi, "timerPassiveIface"); + } else vty_out(vty, " No Hellos (Passive interface)\n"); } @@ -3934,13 +4101,17 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, json_object_int_add(json_interface_sub, "nbrAdjacentCount", ospf_nbr_count(oi, NSM_Full)); + + json_object_int_add(json_oi, "nbrCount", + ospf_nbr_count(oi, 0)); + json_object_int_add(json_oi, "nbrAdjacentCount", + ospf_nbr_count(oi, NSM_Full)); } else vty_out(vty, " Neighbor Count is %d, Adjacent neighbor count is %d\n", ospf_nbr_count(oi, 0), ospf_nbr_count(oi, NSM_Full)); - params = IF_DEF_PARAMS(ifp); if (params && OSPF_IF_PARAM_CONFIGURED(params, v_gr_hello_delay)) { @@ -3948,6 +4119,9 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, json_object_int_add(json_interface_sub, "grHelloDelaySecs", params->v_gr_hello_delay); + + json_object_int_add(json_oi, "grHelloDelaySecs", + params->v_gr_hello_delay); } else vty_out(vty, " Graceful Restart hello delay: %us\n", @@ -3956,18 +4130,45 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, ospf_interface_bfd_show(vty, ifp, json_interface_sub); + if (use_json) { + json_object_boolean_add(json_interface_sub, + "prefixSuppression", + OSPF_IF_PARAM(oi, + prefix_suppression)); + json_object_boolean_add(json_oi, "prefixSuppression", + OSPF_IF_PARAM(oi, + prefix_suppression)); + } else { + if (OSPF_IF_PARAM(oi, prefix_suppression)) + vty_out(vty, + " Suppress advertisement of interface IP prefix\n"); + } + /* OSPF Authentication information */ ospf_interface_auth_show(vty, oi, json_interface_sub, use_json); + + ospf_interface_auth_show(vty, oi, json_oi, use_json); if (oi->type == OSPF_IFTYPE_POINTOMULTIPOINT) { - if (use_json) + if (use_json) { json_object_boolean_add(json_interface_sub, "p2mpDelayReflood", oi->p2mp_delay_reflood); - else + + json_object_boolean_add(json_oi, + "p2mpDelayReflood", + oi->p2mp_delay_reflood); + } else { vty_out(vty, " %sDelay reflooding LSAs received on P2MP interface\n", oi->p2mp_delay_reflood ? "" : "Don't "); + } } + + /* Add ospf_interface object to main json blob using SIP as key + */ + if (use_json) + json_object_object_addf(json_ois, json_oi, "%pI4", + &oi->address->u.prefix4); } } @@ -4175,6 +4376,9 @@ static int show_ip_ospf_interface_traffic_common( rn = route_next(rn)) { oi = rn->info; + if (oi == NULL) + continue; + if (use_json) { json_interface_sub = json_object_new_object(); @@ -5506,7 +5710,7 @@ DEFPY(show_ip_ospf_neighbor_id, "%% OSPF is not enabled in vrf %s\n", vrf_name); else - vty_json_empty(vty); + vty_json_empty(vty, NULL); return CMD_SUCCESS; } ret = show_ip_ospf_neighbor_id_common( @@ -6007,7 +6211,7 @@ DEFPY(show_ip_ospf_neighbor_int, if (!ospf || !ospf->oi_running) { if (json) - vty_json_empty(vty); + vty_json_empty(vty, NULL); return ret; } @@ -6017,7 +6221,7 @@ DEFPY(show_ip_ospf_neighbor_int, ifp = if_lookup_by_name(ifname, vrf_id); if (!ifp) { if (json) - vty_json_empty(vty); + vty_json_empty(vty, NULL); else vty_out(vty, "No such interface.\n"); return ret; @@ -6054,7 +6258,7 @@ DEFPY(show_ip_ospf_neighbor_int_detail, "%% OSPF is not enabled in vrf %s\n", vrf_name); else - vty_json_empty(vty); + vty_json_empty(vty, NULL); return CMD_SUCCESS; } return show_ip_ospf_neighbor_int_detail_common( @@ -7378,24 +7582,26 @@ DEFPY (show_ip_ospf_database, DEFUN (ip_ospf_authentication_args, ip_ospf_authentication_args_addr_cmd, - "ip ospf authentication <null|message-digest> [A.B.C.D]", + "ip ospf authentication <null|message-digest|key-chain KEYCHAIN_NAME> [A.B.C.D]", "IP Information\n" "OSPF interface commands\n" "Enable authentication on this interface\n" "Use null authentication\n" "Use message-digest authentication\n" + "Use a key-chain for cryptographic authentication keys\n" + "Key-chain name\n" "Address of interface\n") { VTY_DECLVAR_CONTEXT(interface, ifp); int idx_encryption = 3; - int idx_ipv4 = 4; + int idx_ipv4 = argc-1; struct in_addr addr; int ret; struct ospf_if_params *params; params = IF_DEF_PARAMS(ifp); - if (argc == 5) { + if (argv[idx_ipv4]->type == IPV4_TKN) { ret = inet_aton(argv[idx_ipv4]->arg, &addr); if (!ret) { vty_out(vty, @@ -7418,6 +7624,17 @@ DEFUN (ip_ospf_authentication_args, if (argv[idx_encryption]->arg[0] == 'm') { SET_IF_PARAM(params, auth_type); params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC; + UNSET_IF_PARAM(params, keychain_name); + XFREE(MTYPE_OSPF_IF_PARAMS, params->keychain_name); + return CMD_SUCCESS; + } + + if (argv[idx_encryption]->arg[0] == 'k') { + SET_IF_PARAM(params, auth_type); + params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC; + SET_IF_PARAM(params, keychain_name); + params->keychain_name = XSTRDUP(MTYPE_OSPF_IF_PARAMS, argv[idx_encryption+1]->arg); + UNSET_IF_PARAM(params, auth_crypt); return CMD_SUCCESS; } @@ -7461,18 +7678,20 @@ DEFUN (ip_ospf_authentication, DEFUN (no_ip_ospf_authentication_args, no_ip_ospf_authentication_args_addr_cmd, - "no ip ospf authentication <null|message-digest> [A.B.C.D]", + "no ip ospf authentication <null|message-digest|key-chain [KEYCHAIN_NAME]> [A.B.C.D]", NO_STR "IP Information\n" "OSPF interface commands\n" "Enable authentication on this interface\n" "Use null authentication\n" "Use message-digest authentication\n" + "Use a key-chain for cryptographic authentication keys\n" + "Key-chain name\n" "Address of interface\n") { VTY_DECLVAR_CONTEXT(interface, ifp); int idx_encryption = 4; - int idx_ipv4 = 5; + int idx_ipv4 = argc-1; struct in_addr addr; int ret; struct ospf_if_params *params; @@ -7481,7 +7700,7 @@ DEFUN (no_ip_ospf_authentication_args, params = IF_DEF_PARAMS(ifp); - if (argc == 6) { + if (argv[idx_ipv4]->type == IPV4_TKN) { ret = inet_aton(argv[idx_ipv4]->arg, &addr); if (!ret) { vty_out(vty, @@ -7496,6 +7715,10 @@ DEFUN (no_ip_ospf_authentication_args, } params->auth_type = OSPF_AUTH_NOTSET; UNSET_IF_PARAM(params, auth_type); + + XFREE(MTYPE_OSPF_IF_PARAMS, params->keychain_name); + UNSET_IF_PARAM(params, keychain_name); + if (params != IF_DEF_PARAMS(ifp)) { ospf_free_if_params(ifp, addr); ospf_if_update_params(ifp, addr); @@ -7503,7 +7726,8 @@ DEFUN (no_ip_ospf_authentication_args, } else { if (argv[idx_encryption]->arg[0] == 'n') { auth_type = OSPF_AUTH_NULL; - } else if (argv[idx_encryption]->arg[0] == 'm') { + } else if (argv[idx_encryption]->arg[0] == 'm' || + argv[idx_encryption]->arg[0] == 'k') { auth_type = OSPF_AUTH_CRYPTOGRAPHIC; } else { vty_out(vty, "Unexpected input encountered\n"); @@ -7519,6 +7743,8 @@ DEFUN (no_ip_ospf_authentication_args, if (params->auth_type == auth_type) { params->auth_type = OSPF_AUTH_NOTSET; UNSET_IF_PARAM(params, auth_type); + XFREE(MTYPE_OSPF_IF_PARAMS, params->keychain_name); + UNSET_IF_PARAM(params, keychain_name); } for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; @@ -7527,6 +7753,8 @@ DEFUN (no_ip_ospf_authentication_args, if (params->auth_type == auth_type) { params->auth_type = OSPF_AUTH_NOTSET; UNSET_IF_PARAM(params, auth_type); + XFREE(MTYPE_OSPF_IF_PARAMS, params->keychain_name); + UNSET_IF_PARAM(params, keychain_name); if (params != IF_DEF_PARAMS(ifp)) { ospf_free_if_params( ifp, rn->p.u.prefix4); @@ -8074,7 +8302,7 @@ DEFUN_HIDDEN (ospf_dead_interval, DEFUN (ip_ospf_dead_interval_minimal, ip_ospf_dead_interval_minimal_addr_cmd, - "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]", + "ip ospf dead-interval minimal hello-multiplier (2-20) [A.B.C.D]", "IP Information\n" "OSPF interface commands\n" "Interval time after which a neighbor is declared down\n" @@ -8095,7 +8323,7 @@ DEFUN (ip_ospf_dead_interval_minimal, DEFUN (no_ip_ospf_dead_interval, no_ip_ospf_dead_interval_cmd, - "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", + "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (2-20)> [A.B.C.D]]", NO_STR "IP Information\n" "OSPF interface commands\n" @@ -8162,7 +8390,7 @@ DEFUN (no_ip_ospf_dead_interval, DEFUN_HIDDEN (no_ospf_dead_interval, no_ospf_dead_interval_cmd, - "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", + "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (2-20)> [A.B.C.D]]", NO_STR "OSPF interface commands\n" "Interval time after which a neighbor is declared down\n" @@ -9483,6 +9711,8 @@ DEFUN (ospf_default_metric, ospf->default_metric = metric; + ospf_schedule_asbr_redist_update(ospf); + return CMD_SUCCESS; } @@ -9497,6 +9727,8 @@ DEFUN (no_ospf_default_metric, ospf->default_metric = -1; + ospf_schedule_asbr_redist_update(ospf); + return CMD_SUCCESS; } @@ -9673,6 +9905,111 @@ DEFUN (no_ip_ospf_mtu_ignore, return CMD_SUCCESS; } +DEFPY(ip_ospf_capability_opaque, ip_ospf_capability_opaque_addr_cmd, + "[no] ip ospf capability opaque [A.B.C.D]$ip_addr", + NO_STR + "IP Information\n" + "OSPF interface commands\n" + "Disable OSPF capability on this interface\n" + "Disable OSPF opaque LSA capability on this interface\n" + "Address of interface\n") +{ + VTY_DECLVAR_CONTEXT(interface, ifp); + struct route_node *rn; + bool old_opaque_capable; + bool opaque_capable_change; + + struct ospf_if_params *params; + params = IF_DEF_PARAMS(ifp); + + if (ip_addr.s_addr != INADDR_ANY) { + params = ospf_get_if_params(ifp, ip_addr); + ospf_if_update_params(ifp, ip_addr); + } + + old_opaque_capable = params->opaque_capable; + params->opaque_capable = (no) ? false : true; + opaque_capable_change = (old_opaque_capable != params->opaque_capable); + if (params->opaque_capable != OSPF_OPAQUE_CAPABLE_DEFAULT) + SET_IF_PARAM(params, opaque_capable); + else { + UNSET_IF_PARAM(params, opaque_capable); + if (params != IF_DEF_PARAMS(ifp)) { + ospf_free_if_params(ifp, ip_addr); + ospf_if_update_params(ifp, ip_addr); + } + } + + /* + * If there is a change to the opaque capability, flap the interface + * to reset all the neighbor adjacencies. + */ + if (opaque_capable_change) { + for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { + struct ospf_interface *oi = rn->info; + + if (oi && (oi->state > ISM_Down) && + (ip_addr.s_addr == INADDR_ANY || + IPV4_ADDR_SAME(&oi->address->u.prefix4, + &ip_addr))) { + OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); + OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); + } + } + } + return CMD_SUCCESS; +} + + +DEFPY(ip_ospf_prefix_suppression, ip_ospf_prefix_suppression_addr_cmd, + "[no] ip ospf prefix-suppression [A.B.C.D]$ip_addr", NO_STR + "IP Information\n" + "OSPF interface commands\n" + "Supress OSPF prefix advertisement on this interface\n" + "Address of interface\n") +{ + VTY_DECLVAR_CONTEXT(interface, ifp); + struct route_node *rn; + bool prefix_suppression_change; + struct ospf_if_params *params; + + params = IF_DEF_PARAMS(ifp); + + if (ip_addr.s_addr != INADDR_ANY) { + params = ospf_get_if_params(ifp, ip_addr); + ospf_if_update_params(ifp, ip_addr); + } + + prefix_suppression_change = (params->prefix_suppression == (bool)no); + params->prefix_suppression = (no) ? false : true; + if (params->prefix_suppression != OSPF_PREFIX_SUPPRESSION_DEFAULT) + SET_IF_PARAM(params, prefix_suppression); + else { + UNSET_IF_PARAM(params, prefix_suppression); + if (params != IF_DEF_PARAMS(ifp)) { + ospf_free_if_params(ifp, ip_addr); + ospf_if_update_params(ifp, ip_addr); + } + } + + /* + * If there is a change to the prefix suppression, update the Router-LSA. + */ + if (prefix_suppression_change) { + for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { + struct ospf_interface *oi = rn->info; + + if (oi && (oi->state > ISM_Down) && + (ip_addr.s_addr == INADDR_ANY || + IPV4_ADDR_SAME(&oi->address->u.prefix4, &ip_addr))) { + (void)ospf_router_lsa_update_area(oi->area); + if (oi->state == ISM_DR) + ospf_network_lsa_update(oi); + } + } + } + return CMD_SUCCESS; +} DEFUN (ospf_max_metric_router_lsa_admin, ospf_max_metric_router_lsa_admin_cmd, @@ -10471,38 +10808,23 @@ DEFPY (show_ip_ospf_gr_helper, } ospf = ospf_lookup_by_inst_name(inst, vrf_name); - - if (ospf == NULL || !ospf->oi_running) { - - if (uj) - vty_json(vty, json); - else - vty_out(vty, - "%% OSPF is not enabled in vrf %s\n", - vrf_name); - - return CMD_SUCCESS; - } - } else { /* Default Vrf */ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); + } - if (ospf == NULL || !ospf->oi_running) { - - if (uj) - vty_json(vty, json); - else - vty_out(vty, - "%% OSPF is not enabled in vrf default\n"); + if (ospf == NULL || !ospf->oi_running) { - return CMD_SUCCESS; - } + if (uj) + vty_json(vty, json); + else + vty_out(vty, + "%% OSPF is not enabled in vrf %s\n", vrf_name ? vrf_name : "default"); - ospf_show_gr_helper_details(vty, ospf, use_vrf, json, uj, - detail); + return CMD_SUCCESS; } + ospf_show_gr_helper_details(vty, ospf, use_vrf, json, uj, detail); if (uj) vty_json(vty, json); @@ -10541,7 +10863,7 @@ static void config_write_stub_router(struct vty *vty, struct ospf *ospf) static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, struct route_table *rt, - json_object *json) + json_object *json, bool detail) { struct route_node *rn; struct ospf_route * or ; @@ -10601,15 +10923,17 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, if (json) { json_object_string_add(json_route, "routeType", "N"); + json_object_boolean_add(json_route, "transit", + or->u.std.transit); json_object_int_add(json_route, "cost", or->cost); json_object_string_addf(json_route, "area", "%pI4", &or->u.std.area_id); } else { - vty_out(vty, "N %-18s [%d] area: %pI4\n", - buf1, or->cost, - &or->u.std.area_id); + vty_out(vty, "N %s %-18s [%d] area: %pI4\n", + or->u.std.transit && detail ? "T" : " ", + buf1, or->cost, &or->u.std.area_id); } break; default: @@ -10666,6 +10990,11 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, ifindex2ifname( path->ifindex, ospf->vrf_id)); + json_object_string_addf( + json_nexthop, + "advertisedRouter", + "%pI4", + &path->adv_router); } else { vty_out(vty, "%24s via %pI4, %s\n", @@ -10675,6 +11004,11 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, path->ifindex, ospf->vrf_id)); } + if (detail && !json) + vty_out(vty, + "%24s adv %pI4\n", + "", + &path->adv_router); } } } @@ -10829,7 +11163,7 @@ static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf, static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, struct route_table *rt, - json_object *json) + json_object *json, bool detail) { struct route_node *rn; struct ospf_route *er; @@ -10933,6 +11267,11 @@ static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, ifindex2ifname( path->ifindex, ospf->vrf_id)); + json_object_string_addf( + json_nexthop, + "advertisedRouter", + "%pI4", + &path->adv_router); } else { vty_out(vty, "%24s via %pI4, %s\n", @@ -10942,6 +11281,10 @@ static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, path->ifindex, ospf->vrf_id)); } + if (detail && !json) + vty_out(vty, + "%24s adv %pI4\n", "", + &path->adv_router); } } } @@ -11228,7 +11571,8 @@ DEFUN (show_ip_ospf_instance_border_routers, } static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf, - json_object *json, uint8_t use_vrf) + json_object *json, uint8_t use_vrf, + bool detail) { json_object *json_vrf = NULL; @@ -11255,8 +11599,15 @@ static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf, return CMD_SUCCESS; } + if (detail && json == NULL) { + vty_out(vty, "Codes: N - network T - transitive\n"); + vty_out(vty, " IA - inter-area E - external route\n"); + vty_out(vty, " D - destination R - router\n\n"); + } + /* Show Network routes. */ - show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf); + show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf, + detail); /* Show Router routes. */ show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf); @@ -11267,7 +11618,7 @@ static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf, /* Show AS External routes. */ show_ip_ospf_route_external(vty, ospf, ospf->old_external_route, - json_vrf); + json_vrf, detail); if (json) { if (use_vrf) { @@ -11285,13 +11636,14 @@ static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf, DEFUN (show_ip_ospf_route, show_ip_ospf_route_cmd, - "show ip ospf [vrf <NAME|all>] route [json]", + "show ip ospf [vrf <NAME|all>] route [detail] [json]", SHOW_STR IP_STR "OSPF information\n" VRF_CMD_HELP_STR "All VRFs\n" "OSPF routing table\n" + "Detailed information\n" JSON_STR) { struct ospf *ospf = NULL; @@ -11300,14 +11652,19 @@ DEFUN (show_ip_ospf_route, bool all_vrf = false; int ret = CMD_SUCCESS; int inst = 0; + int idx = 0; int idx_vrf = 0; uint8_t use_vrf = 0; bool uj = use_json(argc, argv); + bool detail = false; json_object *json = NULL; if (uj) json = json_object_new_object(); + if (argv_find(argv, argc, "detail", &idx)) + detail = true; + OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); /* vrf input is provided could be all or specific vrf*/ @@ -11321,8 +11678,8 @@ DEFUN (show_ip_ospf_route, if (!ospf->oi_running) continue; ospf_output = true; - ret = show_ip_ospf_route_common(vty, ospf, json, - use_vrf); + ret = show_ip_ospf_route_common( + vty, ospf, json, use_vrf, detail); } if (uj) { @@ -11359,7 +11716,8 @@ DEFUN (show_ip_ospf_route, } if (ospf) { - ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf); + ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf, + detail); /* Keep Non-pretty format */ if (uj) vty_out(vty, "%s\n", @@ -11375,16 +11733,22 @@ DEFUN (show_ip_ospf_route, DEFUN (show_ip_ospf_instance_route, show_ip_ospf_instance_route_cmd, - "show ip ospf (1-65535) route", + "show ip ospf (1-65535) route [detail]", SHOW_STR IP_STR "OSPF information\n" "Instance ID\n" - "OSPF routing table\n") + "OSPF routing table\n" + "Detailed information\n") { int idx_number = 3; + int idx = 0; struct ospf *ospf; unsigned short instance = 0; + bool detail = false; + + if (argv_find(argv, argc, "detail", &idx)) + detail = true; instance = strtoul(argv[idx_number]->arg, NULL, 10); if (instance != ospf_instance) @@ -11394,7 +11758,7 @@ DEFUN (show_ip_ospf_instance_route, if (!ospf || !ospf->oi_running) return CMD_SUCCESS; - return show_ip_ospf_route_common(vty, ospf, NULL, 0); + return show_ip_ospf_route_common(vty, ospf, NULL, 0, detail); } @@ -11616,7 +11980,7 @@ static int ospf_show_summary_address(struct vty *vty, struct ospf *ospf, ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); if (!uj) { - vty_out(vty, "aggregation delay interval :%u(in seconds)\n\n", + vty_out(vty, "aggregation delay interval: %u(in seconds)\n\n", ospf->aggr_delay_interval); } else { json_object_int_add(json_vrf, "aggregationDelayInterval", @@ -11790,11 +12154,11 @@ static const char *const ospf_int_type_str[] = { "loopback" }; -static const char *interface_config_auth_str(struct ospf_if_params *params) +static int interface_config_auth_str(struct ospf_if_params *params, char *buf) { if (!OSPF_IF_PARAM_CONFIGURED(params, auth_type) || params->auth_type == OSPF_AUTH_NOTSET) - return NULL; + return 0; /* Translation tables are not that much help * here due to syntax @@ -11802,16 +12166,22 @@ static const char *interface_config_auth_str(struct ospf_if_params *params) switch (params->auth_type) { case OSPF_AUTH_NULL: - return " null"; + snprintf(buf, BUFSIZ, " null"); + break; case OSPF_AUTH_SIMPLE: - return ""; + snprintf(buf, BUFSIZ, " "); + break; case OSPF_AUTH_CRYPTOGRAPHIC: - return " message-digest"; + if (OSPF_IF_PARAM_CONFIGURED(params, keychain_name)) + snprintf(buf, BUFSIZ, " key-chain %s", params->keychain_name); + else + snprintf(buf, BUFSIZ, " message-digest"); + break; } - return ""; + return 1; } static int config_write_interface_one(struct vty *vty, struct vrf *vrf) @@ -11821,7 +12191,8 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf) struct crypt_key *ck; struct route_node *rn = NULL; struct ospf_if_params *params; - const char *auth_str; + char buf[BUFSIZ]; + int ret = 0; int write = 0; FOR_ALL_INTERFACES (vrf, ifp) { @@ -11862,10 +12233,10 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf) } /* OSPF interface authentication print */ - auth_str = interface_config_auth_str(params); - if (auth_str) { + ret = interface_config_auth_str(params, buf); + if (ret) { vty_out(vty, " ip ospf authentication%s", - auth_str); + buf); if (params != IF_DEF_PARAMS(ifp) && rn) vty_out(vty, " %pI4", &rn->p.u.prefix4); @@ -12037,6 +12408,37 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf) if (params && params->ldp_sync_info) ospf_ldp_sync_if_write_config(vty, params); + /* Capability opaque print. */ + if (OSPF_IF_PARAM_CONFIGURED(params, opaque_capable) && + params->opaque_capable != + OSPF_OPAQUE_CAPABLE_DEFAULT) { + if (params->opaque_capable == false) + vty_out(vty, + " no ip ospf capability opaque"); + else + vty_out(vty, + " ip ospf capability opaque"); + if (params != IF_DEF_PARAMS(ifp) && rn) + vty_out(vty, " %pI4", &rn->p.u.prefix4); + vty_out(vty, "\n"); + } + + /* prefix-suppression print. */ + if (OSPF_IF_PARAM_CONFIGURED(params, + prefix_suppression) && + params->prefix_suppression != + OSPF_PREFIX_SUPPRESSION_DEFAULT) { + if (params->prefix_suppression == false) + vty_out(vty, + " no ip ospf prefix-suppression"); + else + vty_out(vty, + " ip ospf prefix-suppression"); + if (params != IF_DEF_PARAMS(ifp) && rn) + vty_out(vty, " %pI4", &rn->p.u.prefix4); + vty_out(vty, "\n"); + } + while (1) { if (rn == NULL) rn = route_top(IF_OIFS_PARAMS(ifp)); @@ -12274,8 +12676,9 @@ static int config_write_virtual_link(struct vty *vty, struct ospf *ospf) { struct listnode *node; struct ospf_vl_data *vl_data; - const char *auth_str; char buf[INET_ADDRSTRLEN]; + char buf2[BUFSIZ]; + int ret = 0; /* Virtual-Link print */ for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) { @@ -12308,12 +12711,12 @@ static int config_write_virtual_link(struct vty *vty, struct ospf *ospf) vty_out(vty, " area %s virtual-link %pI4\n", buf, &vl_data->vl_peer); /* Auth type */ - auth_str = interface_config_auth_str( - IF_DEF_PARAMS(oi->ifp)); - if (auth_str) + ret = interface_config_auth_str( + IF_DEF_PARAMS(oi->ifp), buf2); + if (ret) vty_out(vty, " area %s virtual-link %pI4 authentication%s\n", - buf, &vl_data->vl_peer, auth_str); + buf, &vl_data->vl_peer, buf2); /* Auth key */ if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0] != '\0') @@ -12846,6 +13249,12 @@ static void ospf_vty_if_init(void) install_element(INTERFACE_NODE, &ip_ospf_passive_cmd); install_element(INTERFACE_NODE, &no_ip_ospf_passive_cmd); + /* "ip ospf capability opaque" commands. */ + install_element(INTERFACE_NODE, &ip_ospf_capability_opaque_addr_cmd); + + /* "ip ospf prefix-suppression" commands. */ + install_element(INTERFACE_NODE, &ip_ospf_prefix_suppression_addr_cmd); + /* These commands are compatibitliy for previous version. */ install_element(INTERFACE_NODE, &ospf_authentication_key_cmd); install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd); diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index 27d74cd4fc..bb6cc3a89c 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -47,7 +47,7 @@ DEFINE_MTYPE_STATIC(OSPFD, OSPF_REDISTRIBUTE, "OSPF Redistriute"); /* Zebra structure to hold current status. */ struct zclient *zclient = NULL; /* and for the Synchronous connection to the Label Manager */ -static struct zclient *zclient_sync; +struct zclient *zclient_sync; /* For registering threads. */ extern struct event_loop *master; @@ -162,29 +162,6 @@ static int ospf_interface_link_params(ZAPI_CALLBACK_ARGS) return 0; } -/* VRF update for an interface. */ -static int ospf_interface_vrf_update(ZAPI_CALLBACK_ARGS) -{ - struct interface *ifp = NULL; - vrf_id_t new_vrf_id; - - ifp = zebra_interface_vrf_update_read(zclient->ibuf, vrf_id, - &new_vrf_id); - if (!ifp) - return 0; - - if (IS_DEBUG_OSPF_EVENT) - zlog_debug( - "%s: Rx Interface %s VRF change vrf_id %u New vrf %s id %u", - __func__, ifp->name, vrf_id, - ospf_vrf_id_to_name(new_vrf_id), new_vrf_id); - - /*if_update(ifp, ifp->name, strlen(ifp->name), new_vrf_id);*/ - if_update_to_new_vrf(ifp, new_vrf_id); - - return 0; -} - /* Nexthop, ifindex, distance and metric information. */ static void ospf_zebra_add_nexthop(struct ospf *ospf, struct ospf_path *path, struct zapi_route *api) @@ -814,16 +791,16 @@ int ospf_is_type_redistributed(struct ospf *ospf, int type, unsigned short instance) { return (DEFAULT_ROUTE_TYPE(type) - ? vrf_bitmap_check(zclient->default_information[AFI_IP], - ospf->vrf_id) - : ((instance - && redist_check_instance( + ? vrf_bitmap_check( + &zclient->default_information[AFI_IP], + ospf->vrf_id) + : ((instance && + redist_check_instance( &zclient->mi_redist[AFI_IP][type], - instance)) - || (!instance - && vrf_bitmap_check( - zclient->redist[AFI_IP][type], - ospf->vrf_id)))); + instance)) || + (!instance && + vrf_bitmap_check(&zclient->redist[AFI_IP][type], + ospf->vrf_id)))); } int ospf_redistribute_update(struct ospf *ospf, struct ospf_redist *red, @@ -1510,30 +1487,20 @@ void ospf_zebra_import_default_route(struct ospf *ospf, bool unreg) __func__); } -static int ospf_zebra_import_check_update(ZAPI_CALLBACK_ARGS) +static void ospf_zebra_import_check_update(struct vrf *vrf, struct prefix *match, + struct zapi_route *nhr) { - struct ospf *ospf; - struct zapi_route nhr; - struct prefix matched; + struct ospf *ospf = vrf->info; - ospf = ospf_lookup_by_vrf_id(vrf_id); if (ospf == NULL || !IS_OSPF_ASBR(ospf)) - return 0; - - if (!zapi_nexthop_update_decode(zclient->ibuf, &matched, &nhr)) { - zlog_err("%s[%u]: Failure to decode route", __func__, - ospf->vrf_id); - return -1; - } + return; - if (matched.family != AF_INET || matched.prefixlen != 0 || - nhr.type == ZEBRA_ROUTE_OSPF) - return 0; + if (match->family != AF_INET || match->prefixlen != 0 || + nhr->type == ZEBRA_ROUTE_OSPF) + return; - ospf->nssa_default_import_check.status = !!nhr.nexthop_num; + ospf->nssa_default_import_check.status = !!nhr->nexthop_num; ospf_abr_nssa_type7_defaults(ospf); - - return 0; } int ospf_distribute_list_out_set(struct ospf *ospf, int type, const char *name) @@ -2161,9 +2128,9 @@ static int ospf_opaque_msg_handler(ZAPI_CALLBACK_ARGS) switch (info.type) { case LINK_STATE_SYNC: - STREAM_GETC(s, dst.proto); - STREAM_GETW(s, dst.instance); - STREAM_GETL(s, dst.session_id); + dst.proto = info.src_proto; + dst.instance = info.src_instance; + dst.session_id = info.src_session_id; dst.type = LINK_STATE_SYNC; ret = ospf_te_sync_ted(dst); break; @@ -2203,11 +2170,9 @@ static zclient_handler *const ospf_handlers[] = { [ZEBRA_INTERFACE_ADDRESS_ADD] = ospf_interface_address_add, [ZEBRA_INTERFACE_ADDRESS_DELETE] = ospf_interface_address_delete, [ZEBRA_INTERFACE_LINK_PARAMS] = ospf_interface_link_params, - [ZEBRA_INTERFACE_VRF_UPDATE] = ospf_interface_vrf_update, [ZEBRA_REDISTRIBUTE_ROUTE_ADD] = ospf_zebra_read_route, [ZEBRA_REDISTRIBUTE_ROUTE_DEL] = ospf_zebra_read_route, - [ZEBRA_NEXTHOP_UPDATE] = ospf_zebra_import_check_update, [ZEBRA_OPAQUE_MESSAGE] = ospf_opaque_msg_handler, @@ -2221,11 +2186,10 @@ void ospf_zebra_init(struct event_loop *master, unsigned short instance) array_size(ospf_handlers)); zclient_init(zclient, ZEBRA_ROUTE_OSPF, instance, &ospfd_privs); zclient->zebra_connected = ospf_zebra_connected; + zclient->nexthop_update = ospf_zebra_import_check_update; /* Initialize special zclient for synchronous message exchanges. */ - struct zclient_options options = zclient_options_default; - options.synchronous = true; - zclient_sync = zclient_new(master, &options, NULL, 0); + zclient_sync = zclient_new(master, &zclient_options_sync, NULL, 0); zclient_sync->sock = -1; zclient_sync->redist_default = ZEBRA_ROUTE_OSPF; zclient_sync->instance = instance; diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index 51e937f42c..4c4666db52 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -60,7 +60,10 @@ struct ospf_master *om; unsigned short ospf_instance; extern struct zclient *zclient; +extern struct zclient *zclient_sync; +/* OSPF config processing timer thread */ +struct event *t_ospf_cfg; static void ospf_remove_vls_through_area(struct ospf *, struct ospf_area *); static void ospf_network_free(struct ospf *, struct ospf_network *); @@ -572,39 +575,12 @@ static struct ospf *ospf_lookup_by_name(const char *vrf_name) return NULL; } -/* Handle the second half of deferred shutdown. This is called either - * from the deferred-shutdown timer thread, or directly through - * ospf_deferred_shutdown_check. - * - * Function is to cleanup G-R state, if required then call ospf_finish_final - * to complete shutdown of this ospf instance. Possibly exit if the - * whole process is being shutdown and this was the last OSPF instance. - */ -static void ospf_deferred_shutdown_finish(struct ospf *ospf) -{ - ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED; - EVENT_OFF(ospf->t_deferred_shutdown); - - ospf_finish_final(ospf); - - /* *ospf is now invalid */ - - /* ospfd being shut-down? If so, was this the last ospf instance? */ - if (CHECK_FLAG(om->options, OSPF_MASTER_SHUTDOWN) - && (listcount(om->ospf) == 0)) { - frr_fini(); - exit(0); - } - - return; -} - -/* Timer thread for G-R */ +/* Timer thread for deferred shutdown */ static void ospf_deferred_shutdown_timer(struct event *t) { struct ospf *ospf = EVENT_ARG(t); - ospf_deferred_shutdown_finish(ospf); + ospf_finish_final(ospf); } /* Check whether deferred-shutdown must be scheduled, otherwise call @@ -631,15 +607,12 @@ static void ospf_deferred_shutdown_check(struct ospf *ospf) ospf_router_lsa_update_area(area); } timeout = ospf->stub_router_shutdown_time; + OSPF_TIMER_ON(ospf->t_deferred_shutdown, + ospf_deferred_shutdown_timer, timeout); } else { /* No timer needed */ - ospf_deferred_shutdown_finish(ospf); - return; + ospf_finish_final(ospf); } - - OSPF_TIMER_ON(ospf->t_deferred_shutdown, ospf_deferred_shutdown_timer, - timeout); - return; } /* Shut down the entire process */ @@ -654,10 +627,6 @@ void ospf_terminate(void) SET_FLAG(om->options, OSPF_MASTER_SHUTDOWN); - /* Skip some steps if OSPF not actually running */ - if (listcount(om->ospf) == 0) - goto done; - for (ALL_LIST_ELEMENTS(om->ospf, node, nnode, ospf)) ospf_finish(ospf); @@ -675,27 +644,31 @@ void ospf_terminate(void) /* Cleanup vrf info */ ospf_vrf_terminate(); + keychain_terminate(); + + ospf_opaque_term(); + list_delete(&om->ospf); + /* Deliberately go back up, hopefully to thread scheduler, as * One or more ospf_finish()'s may have deferred shutdown to a timer * thread */ zclient_stop(zclient); zclient_free(zclient); + zclient_stop(zclient_sync); + zclient_free(zclient_sync); -done: frr_fini(); } void ospf_finish(struct ospf *ospf) { - /* let deferred shutdown decide */ - ospf_deferred_shutdown_check(ospf); - - /* if ospf_deferred_shutdown returns, then ospf_finish_final is - * deferred to expiry of G-S timer thread. Return back up, hopefully - * to thread scheduler. - */ - return; + if (CHECK_FLAG(om->options, OSPF_MASTER_SHUTDOWN)) + ospf_finish_final(ospf); + else { + /* let deferred shutdown decide */ + ospf_deferred_shutdown_check(ospf); + } } /* Final cleanup of ospf instance */ @@ -801,25 +774,6 @@ static void ospf_finish_final(struct ospf *ospf) ospf_area_free(area); } - /* Cancel all timers. */ - EVENT_OFF(ospf->t_read); - EVENT_OFF(ospf->t_write); - EVENT_OFF(ospf->t_spf_calc); - EVENT_OFF(ospf->t_ase_calc); - EVENT_OFF(ospf->t_maxage); - EVENT_OFF(ospf->t_maxage_walker); - EVENT_OFF(ospf->t_abr_task); - EVENT_OFF(ospf->t_abr_fr); - EVENT_OFF(ospf->t_asbr_check); - EVENT_OFF(ospf->t_asbr_nssa_redist_update); - EVENT_OFF(ospf->t_distribute_update); - EVENT_OFF(ospf->t_lsa_refresher); - EVENT_OFF(ospf->t_opaque_lsa_self); - EVENT_OFF(ospf->t_sr_update); - EVENT_OFF(ospf->t_default_routemap_timer); - EVENT_OFF(ospf->t_external_aggr); - EVENT_OFF(ospf->gr_info.t_grace_period); - LSDB_LOOP (OPAQUE_AS_LSDB(ospf), rn, lsa) ospf_discard_from_db(ospf, ospf->lsdb, lsa); LSDB_LOOP (EXTERNAL_LSDB(ospf), rn, lsa) @@ -907,8 +861,27 @@ static void ospf_finish_final(struct ospf *ospf) } } - route_table_finish(ospf->rt_aggr_tbl); + /* Cancel all timers. */ + EVENT_OFF(ospf->t_read); + EVENT_OFF(ospf->t_write); + EVENT_OFF(ospf->t_spf_calc); + EVENT_OFF(ospf->t_ase_calc); + EVENT_OFF(ospf->t_maxage); + EVENT_OFF(ospf->t_maxage_walker); + EVENT_OFF(ospf->t_deferred_shutdown); + EVENT_OFF(ospf->t_abr_task); + EVENT_OFF(ospf->t_abr_fr); + EVENT_OFF(ospf->t_asbr_check); + EVENT_OFF(ospf->t_asbr_redist_update); + EVENT_OFF(ospf->t_distribute_update); + EVENT_OFF(ospf->t_lsa_refresher); + EVENT_OFF(ospf->t_opaque_lsa_self); + EVENT_OFF(ospf->t_sr_update); + EVENT_OFF(ospf->t_default_routemap_timer); + EVENT_OFF(ospf->t_external_aggr); + EVENT_OFF(ospf->gr_info.t_grace_period); + route_table_finish(ospf->rt_aggr_tbl); ospf_free_refresh_queue(ospf); @@ -931,6 +904,15 @@ static void ospf_finish_final(struct ospf *ospf) XFREE(MTYPE_OSPF_TOP, ospf); } +static void ospf_range_table_node_destroy(route_table_delegate_t *delegate, + struct route_table *table, struct route_node *node) +{ + XFREE(MTYPE_OSPF_AREA_RANGE, node->info); + XFREE(MTYPE_ROUTE_NODE, node); +} + +route_table_delegate_t ospf_range_table_delegate = {.create_node = route_node_create, + .destroy_node = ospf_range_table_node_destroy}; /* allocate new OSPF Area object */ struct ospf_area *ospf_area_new(struct ospf *ospf, struct in_addr area_id) @@ -967,8 +949,8 @@ struct ospf_area *ospf_area_new(struct ospf *ospf, struct in_addr area_id) ospf_opaque_type10_lsa_init(new); new->oiflist = list_new(); - new->ranges = route_table_init(); - new->nssa_ranges = route_table_init(); + new->ranges = route_table_init_with_delegate(&ospf_range_table_delegate); + new->nssa_ranges = route_table_init_with_delegate(&ospf_range_table_delegate); if (area_id.s_addr == OSPF_AREA_BACKBONE) ospf->backbone = new; @@ -1244,8 +1226,9 @@ int ospf_network_unset(struct ospf *ospf, struct prefix_ipv4 *p, { struct route_node *rn; struct ospf_network *network; - struct listnode *node, *nnode; + struct listnode *node; struct ospf_interface *oi; + struct list *ospf_oiflist = NULL; rn = route_node_lookup(ospf->networks, (struct prefix *)p); if (rn == NULL) @@ -1260,8 +1243,9 @@ int ospf_network_unset(struct ospf *ospf, struct prefix_ipv4 *p, rn->info = NULL; route_unlock_node(rn); /* initial reference */ - /* Find interfaces that are not configured already. */ - for (ALL_LIST_ELEMENTS(ospf->oiflist, node, nnode, oi)) { + ospf_oiflist = list_dup(ospf->oiflist); + /* Find interfaces that are not configured already. */ + for (ALL_LIST_ELEMENTS_RO(ospf_oiflist, node, oi)) { if (oi->type == OSPF_IFTYPE_VIRTUALLINK) continue; @@ -1269,6 +1253,8 @@ int ospf_network_unset(struct ospf *ospf, struct prefix_ipv4 *p, ospf_network_run_subnet(ospf, oi->connected, NULL, NULL); } + list_delete(&ospf_oiflist); + /* Update connected redistribute. */ update_redistributed(ospf, 0); /* interfaces possibly removed */ ospf_area_check_free(ospf, area_id); @@ -1276,6 +1262,7 @@ int ospf_network_unset(struct ospf *ospf, struct prefix_ipv4 *p, return 1; } + /* Ensure there's an OSPF instance, as "ip ospf area" enabled OSPF means * there might not be any 'router ospf' config. * @@ -1424,7 +1411,6 @@ static void ospf_network_run_interface(struct ospf *ospf, struct interface *ifp, struct prefix *p, struct ospf_area *given_area) { - struct listnode *cnode; struct connected *co; if (memcmp(ifp->name, "VLINK", 5) == 0) @@ -1436,7 +1422,7 @@ static void ospf_network_run_interface(struct ospf *ospf, struct interface *ifp, /* if interface prefix is match specified prefix, then create socket and join multicast group. */ - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, co)) + frr_each (if_connected, ifp->connected, co) ospf_network_run_subnet(ospf, co, p, given_area); } @@ -2282,20 +2268,20 @@ static void ospf_set_redist_vrf_bitmaps(struct ospf *ospf, bool set) "%s: setting redist vrf %d bitmap for type %d", __func__, ospf->vrf_id, type); if (set) - vrf_bitmap_set(zclient->redist[AFI_IP][type], + vrf_bitmap_set(&zclient->redist[AFI_IP][type], ospf->vrf_id); else - vrf_bitmap_unset(zclient->redist[AFI_IP][type], + vrf_bitmap_unset(&zclient->redist[AFI_IP][type], ospf->vrf_id); } red_list = ospf->redist[DEFAULT_ROUTE]; if (red_list) { if (set) - vrf_bitmap_set(zclient->default_information[AFI_IP], + vrf_bitmap_set(&zclient->default_information[AFI_IP], ospf->vrf_id); else - vrf_bitmap_unset(zclient->default_information[AFI_IP], + vrf_bitmap_unset(&zclient->default_information[AFI_IP], ospf->vrf_id); } } diff --git a/ospfd/ospfd.h b/ospfd/ospfd.h index 36936b16f4..2ab7db119e 100644 --- a/ospfd/ospfd.h +++ b/ospfd/ospfd.h @@ -70,6 +70,9 @@ /* Default socket buffer size */ #define OSPF_DEFAULT_SOCK_BUFSIZE (8 * 1024 * 1024) +/* OSPF config processing timer thread */ +extern struct event *t_ospf_cfg; + struct ospf_external { unsigned short instance; struct route_table *external_info; @@ -265,8 +268,8 @@ struct ospf { struct event *t_abr_task; /* ABR task timer. */ struct event *t_abr_fr; /* ABR FR timer. */ struct event *t_asbr_check; /* ASBR check timer. */ - struct event *t_asbr_nssa_redist_update; /* ASBR NSSA redistribution - update timer. */ + struct event *t_asbr_redist_update; /* ASBR redistribution update + timer. */ struct event *t_distribute_update; /* Distirbute list update timer. */ struct event *t_spf_calc; /* SPF calculation timer. */ struct event *t_ase_calc; /* ASE calculation timer. */ diff --git a/ospfd/subdir.am b/ospfd/subdir.am index 44ee3b0f13..4803aae68d 100644 --- a/ospfd/subdir.am +++ b/ospfd/subdir.am @@ -56,6 +56,7 @@ ospfd_libfrrospf_a_SOURCES = \ ospfd/ospf_zebra.c \ ospfd/ospfd.c \ ospfd/ospf_gr_helper.c \ + ospfd/ospf_auth.c \ # end if OSPFD @@ -106,6 +107,7 @@ noinst_HEADERS += \ ospfd/ospf_te.h \ ospfd/ospf_vty.h \ ospfd/ospf_zebra.h \ + ospfd/ospf_auth.h \ # end ospfd_ospfd_LDADD = ospfd/libfrrospf.a ospfd/libfrrospfclient.a lib/libfrr.la $(LIBCAP) $(LIBM) diff --git a/pathd/path_cli.c b/pathd/path_cli.c index 45f4ac7ab8..e22931c13e 100644 --- a/pathd/path_cli.c +++ b/pathd/path_cli.c @@ -287,7 +287,7 @@ void cli_show_srte_segment_list(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { vty_out(vty, " segment-list %s\n", - yang_dnode_get_string(dnode, "./name")); + yang_dnode_get_string(dnode, "name")); } void cli_show_srte_segment_list_end(struct vty *vty, @@ -546,37 +546,37 @@ void cli_show_srte_segment_list_segment(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - vty_out(vty, " index %s", yang_dnode_get_string(dnode, "./index")); - if (yang_dnode_exists(dnode, "./sid-value")) { + vty_out(vty, " index %s", yang_dnode_get_string(dnode, "index")); + if (yang_dnode_exists(dnode, "sid-value")) { vty_out(vty, " mpls label %s", - yang_dnode_get_string(dnode, "./sid-value")); + yang_dnode_get_string(dnode, "sid-value")); } - if (yang_dnode_exists(dnode, "./nai")) { + if (yang_dnode_exists(dnode, "nai")) { struct ipaddr addr; struct ipaddr addr_rmt; - switch (yang_dnode_get_enum(dnode, "./nai/type")) { + switch (yang_dnode_get_enum(dnode, "nai/type")) { case SRTE_SEGMENT_NAI_TYPE_IPV4_NODE: case SRTE_SEGMENT_NAI_TYPE_IPV4_LOCAL_IFACE: case SRTE_SEGMENT_NAI_TYPE_IPV4_ALGORITHM: - yang_dnode_get_ip(&addr, dnode, "./nai/local-address"); + yang_dnode_get_ip(&addr, dnode, "nai/local-address"); vty_out(vty, " nai prefix %pI4", &addr.ipaddr_v4); break; case SRTE_SEGMENT_NAI_TYPE_IPV6_NODE: case SRTE_SEGMENT_NAI_TYPE_IPV6_LOCAL_IFACE: case SRTE_SEGMENT_NAI_TYPE_IPV6_ALGORITHM: - yang_dnode_get_ip(&addr, dnode, "./nai/local-address"); + yang_dnode_get_ip(&addr, dnode, "nai/local-address"); vty_out(vty, " nai prefix %pI6", &addr.ipaddr_v6); break; case SRTE_SEGMENT_NAI_TYPE_IPV4_ADJACENCY: - yang_dnode_get_ip(&addr, dnode, "./nai/local-address"); + yang_dnode_get_ip(&addr, dnode, "nai/local-address"); yang_dnode_get_ip(&addr_rmt, dnode, "./nai/remote-address"); vty_out(vty, " nai adjacency %pI4", &addr.ipaddr_v4); vty_out(vty, " %pI4", &addr_rmt.ipaddr_v4); break; case SRTE_SEGMENT_NAI_TYPE_IPV6_ADJACENCY: - yang_dnode_get_ip(&addr, dnode, "./nai/local-address"); + yang_dnode_get_ip(&addr, dnode, "nai/local-address"); yang_dnode_get_ip(&addr_rmt, dnode, "./nai/remote-address"); vty_out(vty, " nai adjacency %pI6", &addr.ipaddr_v6); @@ -585,17 +585,17 @@ void cli_show_srte_segment_list_segment(struct vty *vty, default: break; } - if (yang_dnode_exists(dnode, "./nai/local-prefix-len")) { + if (yang_dnode_exists(dnode, "nai/local-prefix-len")) { vty_out(vty, "/%s", yang_dnode_get_string( dnode, "./nai/local-prefix-len")); } - if (yang_dnode_exists(dnode, "./nai/local-interface")) { + if (yang_dnode_exists(dnode, "nai/local-interface")) { vty_out(vty, " iface %s", yang_dnode_get_string(dnode, "./nai/local-interface")); } - if (yang_dnode_exists(dnode, "./nai/algorithm")) { + if (yang_dnode_exists(dnode, "nai/algorithm")) { vty_out(vty, " algorithm %s", yang_dnode_get_string(dnode, "./nai/algorithm")); @@ -658,8 +658,8 @@ void cli_show_srte_policy(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { vty_out(vty, " policy color %s endpoint %s\n", - yang_dnode_get_string(dnode, "./color"), - yang_dnode_get_string(dnode, "./endpoint")); + yang_dnode_get_string(dnode, "color"), + yang_dnode_get_string(dnode, "endpoint")); } void cli_show_srte_policy_end(struct vty *vty, const struct lyd_node *dnode) @@ -860,7 +860,7 @@ DEFPY(srte_candidate_no_affinity_filter, srte_candidate_no_affinity_filter_cmd, DEFPY(srte_candidate_metric, srte_candidate_metric_cmd, - "metric [bound$bound] <igp|te|hc|abc|lmll|cigp|cte|pigp|pte|phc|msd|pd|pdv|pl|ppd|ppdv|ppl|nap|nlp|dc|bnc>$type METRIC$value [required$required]", + "metric [bound$bound] <igp|te|hc|abc|lmll|cigp|cte|pigp|pte|phc|msd|pd|pdv|pl|ppd|ppdv|ppl|nap|nlp|dc|bnc>$type METRIC$value [required$required] [computed$computed]", "Define a metric constraint\n" "If the metric is bounded\n" "IGP metric\n" @@ -885,7 +885,8 @@ DEFPY(srte_candidate_metric, "Domain Count metric\n" "Border Node Count metric\n" "Metric value\n" - "Required constraint\n") + "Required constraint\n" + "Force the PCE to provide the computed path metric\n") { char xpath[XPATH_CANDIDATE_MAXLEN]; snprintf(xpath, sizeof(xpath), "./constraints/metrics[type='%s']/value", @@ -899,12 +900,16 @@ DEFPY(srte_candidate_metric, "./constraints/metrics[type='%s']/required", type); nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, required ? "true" : "false"); + snprintf(xpath, sizeof(xpath), + "./constraints/metrics[type='%s']/is-computed", type); + nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, + computed ? "true" : "false"); return nb_cli_apply_changes(vty, NULL); } DEFPY(srte_candidate_no_metric, srte_candidate_no_metric_cmd, - "no metric [bound] <igp|te|hc|abc|lmll|cigp|cte|pigp|pte|phc|msd|pd|pdv|pl|ppd|ppdv|ppl|nap|nlp|dc|bnc>$type [METRIC$value] [required$required]", + "no metric [bound] <igp|te|hc|abc|lmll|cigp|cte|pigp|pte|phc|msd|pd|pdv|pl|ppd|ppdv|ppl|nap|nlp|dc|bnc>$type [METRIC$value] [required$required] [computed$computed]", NO_STR "Remove a metric constraint\n" "If the metric is bounded\n" @@ -930,7 +935,8 @@ DEFPY(srte_candidate_no_metric, "Domain Count metric\n" "Border Node Count metric\n" "Metric value\n" - "Required constraint\n") + "Required constraint\n" + "Force the PCE to provide the computed path metric\n") { char xpath[XPATH_CANDIDATE_MAXLEN]; snprintf(xpath, sizeof(xpath), "./constraints/metrics[type='%s']", @@ -1164,7 +1170,8 @@ static void config_write_float(struct vty *vty, float value) static void config_write_metric(struct vty *vty, enum srte_candidate_metric_type type, - float value, bool required, bool is_bound) + float value, bool required, bool is_bound, + bool is_computed) { const char *name = metric_type_name(type); if (name == NULL) @@ -1173,6 +1180,7 @@ static void config_write_metric(struct vty *vty, metric_type_name(type)); config_write_float(vty, value); vty_out(vty, required ? " required" : ""); + vty_out(vty, is_computed ? " computed" : ""); vty_out(vty, "\n"); } @@ -1180,16 +1188,18 @@ static int config_write_metric_cb(const struct lyd_node *dnode, void *arg) { struct vty *vty = arg; enum srte_candidate_metric_type type; - bool required, is_bound = false; + bool required, is_bound = false, is_computed = false; float value; - type = yang_dnode_get_enum(dnode, "./type"); - value = (float)yang_dnode_get_dec64(dnode, "./value"); - required = yang_dnode_get_bool(dnode, "./required"); - if (yang_dnode_exists(dnode, "./is-bound")) - is_bound = yang_dnode_get_bool(dnode, "./is-bound"); + type = yang_dnode_get_enum(dnode, "type"); + value = (float)yang_dnode_get_dec64(dnode, "value"); + required = yang_dnode_get_bool(dnode, "required"); + if (yang_dnode_exists(dnode, "is-bound")) + is_bound = yang_dnode_get_bool(dnode, "is-bound"); + if (yang_dnode_exists(dnode, "is-computed")) + is_computed = yang_dnode_get_bool(dnode, "is-computed"); - config_write_metric(vty, type, value, required, is_bound); + config_write_metric(vty, type, value, required, is_bound, is_computed); return YANG_ITER_CONTINUE; } @@ -1201,18 +1211,18 @@ void cli_show_srte_policy_candidate_path(struct vty *vty, uint32_t affinity; bool required; enum objfun_type objfun_type; - const char *type = yang_dnode_get_string(dnode, "./type"); + const char *type = yang_dnode_get_string(dnode, "type"); vty_out(vty, " candidate-path preference %s name %s %s", - yang_dnode_get_string(dnode, "./preference"), - yang_dnode_get_string(dnode, "./name"), type); + yang_dnode_get_string(dnode, "preference"), + yang_dnode_get_string(dnode, "name"), type); if (strmatch(type, "explicit")) vty_out(vty, " segment-list %s", - yang_dnode_get_string(dnode, "./segment-list-name")); + yang_dnode_get_string(dnode, "segment-list-name")); vty_out(vty, "\n"); if (strmatch(type, "dynamic")) { - if (yang_dnode_exists(dnode, "./constraints/bandwidth")) { + if (yang_dnode_exists(dnode, "constraints/bandwidth")) { bandwidth = (float)yang_dnode_get_dec64( dnode, "./constraints/bandwidth/value"); required = yang_dnode_get_bool( @@ -1262,7 +1272,7 @@ void cli_show_srte_policy_candidate_path(struct vty *vty, void cli_show_srte_policy_candidate_path_end(struct vty *vty, const struct lyd_node *dnode) { - const char *type = yang_dnode_get_string(dnode, "./type"); + const char *type = yang_dnode_get_string(dnode, "type"); if (strmatch(type, "dynamic")) vty_out(vty, " exit\n"); diff --git a/pathd/path_nb.c b/pathd/path_nb.c index 9e919571dd..e1c0cc3efa 100644 --- a/pathd/path_nb.c +++ b/pathd/path_nb.c @@ -313,8 +313,8 @@ int iter_objfun_cb(const struct lyd_node *dnode, void *arg) pref = &of_arg->prefs[of_arg->free_slot++]; - pref->index = yang_dnode_get_uint32(dnode, "./index"); - pref->type = yang_dnode_get_enum(dnode, "./type"); + pref->index = yang_dnode_get_uint32(dnode, "index"); + pref->type = yang_dnode_get_enum(dnode, "type"); /* Simplistic insertion sort */ p = &of_arg->first; diff --git a/pathd/path_nb_config.c b/pathd/path_nb_config.c index ad24f23dd9..48531ba433 100644 --- a/pathd/path_nb_config.c +++ b/pathd/path_nb_config.c @@ -31,7 +31,7 @@ int pathd_srte_segment_list_create(struct nb_cb_create_args *args) if (args->event != NB_EV_APPLY) return NB_OK; - name = yang_dnode_get_string(args->dnode, "./name"); + name = yang_dnode_get_string(args->dnode, "name"); segment_list = srte_segment_list_add(name); nb_running_set_entry(args->dnode, segment_list); SET_FLAG(segment_list->flags, F_SEGMENT_LIST_NEW); @@ -104,7 +104,7 @@ int pathd_srte_segment_list_segment_create(struct nb_cb_create_args *args) return NB_OK; segment_list = nb_running_get_entry(args->dnode, NULL, true); - index = yang_dnode_get_uint32(args->dnode, "./index"); + index = yang_dnode_get_uint32(args->dnode, "index"); segment = srte_segment_entry_add(segment_list, index); nb_running_set_entry(args->dnode, segment); SET_FLAG(segment_list->flags, F_SEGMENT_LIST_MODIFIED); @@ -191,9 +191,9 @@ void pathd_srte_segment_list_segment_nai_apply_finish( const char *algo_buf, *local_prefix_len_buf; segment = nb_running_get_entry(args->dnode, NULL, true); - type = yang_dnode_get_enum(args->dnode, "./type"); + type = yang_dnode_get_enum(args->dnode, "type"); - yang_dnode_get_ip(&local_addr, args->dnode, "./local-address"); + yang_dnode_get_ip(&local_addr, args->dnode, "local-address"); switch (type) { case SRTE_SEGMENT_NAI_TYPE_IPV4_NODE: @@ -208,12 +208,12 @@ void pathd_srte_segment_list_segment_nai_apply_finish( yang_dnode_get_ip(&remote_addr, args->dnode, "./remote-address"); local_iface = - yang_dnode_get_uint32(args->dnode, "./local-interface"); + yang_dnode_get_uint32(args->dnode, "local-interface"); remote_iface = yang_dnode_get_uint32(args->dnode, "./remote-interface"); break; case SRTE_SEGMENT_NAI_TYPE_IPV4_ALGORITHM: - algo_buf = yang_dnode_get_string(args->dnode, "./algorithm"); + algo_buf = yang_dnode_get_string(args->dnode, "algorithm"); algo = atoi(algo_buf); local_prefix_len_buf = yang_dnode_get_string( args->dnode, "./local-prefix-len"); @@ -221,7 +221,7 @@ void pathd_srte_segment_list_segment_nai_apply_finish( break; case SRTE_SEGMENT_NAI_TYPE_IPV4_LOCAL_IFACE: local_iface = - yang_dnode_get_uint32(args->dnode, "./local-interface"); + yang_dnode_get_uint32(args->dnode, "local-interface"); local_prefix_len_buf = yang_dnode_get_string( args->dnode, "./local-prefix-len"); local_prefix_len = atoi(local_prefix_len_buf); @@ -254,8 +254,8 @@ int pathd_srte_policy_create(struct nb_cb_create_args *args) if (args->event != NB_EV_APPLY) return NB_OK; - color = yang_dnode_get_uint32(args->dnode, "./color"); - yang_dnode_get_ip(&endpoint, args->dnode, "./endpoint"); + color = yang_dnode_get_uint32(args->dnode, "color"); + yang_dnode_get_ip(&endpoint, args->dnode, "endpoint"); policy = srte_policy_add(color, &endpoint, SRTE_ORIGIN_LOCAL, NULL); nb_running_set_entry(args->dnode, policy); @@ -377,7 +377,7 @@ int pathd_srte_policy_candidate_path_create(struct nb_cb_create_args *args) return NB_OK; policy = nb_running_get_entry(args->dnode, NULL, true); - preference = yang_dnode_get_uint32(args->dnode, "./preference"); + preference = yang_dnode_get_uint32(args->dnode, "preference"); candidate = srte_candidate_add(policy, preference, SRTE_ORIGIN_LOCAL, NULL); nb_running_set_entry(args->dnode, candidate); @@ -539,7 +539,7 @@ int pathd_srte_policy_candidate_path_metrics_destroy( assert(args->context != NULL); candidate = nb_running_get_entry(args->dnode, NULL, true); - type = yang_dnode_get_enum(args->dnode, "./type"); + type = yang_dnode_get_enum(args->dnode, "type"); srte_candidate_unset_metric(candidate, type); return NB_OK; @@ -557,13 +557,13 @@ void pathd_srte_policy_candidate_path_metrics_apply_finish( candidate = nb_running_get_entry(args->dnode, NULL, true); - type = yang_dnode_get_enum(args->dnode, "./type"); - value = (float)yang_dnode_get_dec64(args->dnode, "./value"); - required = yang_dnode_get_bool(args->dnode, "./required"); - if (yang_dnode_exists(args->dnode, "./is-bound")) - is_bound = yang_dnode_get_bool(args->dnode, "./is-bound"); - if (yang_dnode_exists(args->dnode, "./is-computed")) - is_computed = yang_dnode_get_bool(args->dnode, "./is-computed"); + type = yang_dnode_get_enum(args->dnode, "type"); + value = (float)yang_dnode_get_dec64(args->dnode, "value"); + required = yang_dnode_get_bool(args->dnode, "required"); + if (yang_dnode_exists(args->dnode, "is-bound")) + is_bound = yang_dnode_get_bool(args->dnode, "is-bound"); + if (yang_dnode_exists(args->dnode, "is-computed")) + is_computed = yang_dnode_get_bool(args->dnode, "is-computed"); srte_candidate_set_metric(candidate, type, value, required, is_bound, is_computed); @@ -597,8 +597,8 @@ void pathd_srte_policy_candidate_path_objfun_apply_finish( bool required; candidate = nb_running_get_entry(args->dnode, NULL, true); - required = yang_dnode_get_bool(args->dnode, "./required"); - type = yang_dnode_get_enum(args->dnode, "./type"); + required = yang_dnode_get_bool(args->dnode, "required"); + type = yang_dnode_get_enum(args->dnode, "type"); srte_candidate_set_objfun(candidate, required, type); } @@ -739,8 +739,8 @@ void pathd_srte_policy_candidate_path_bandwidth_apply_finish( assert(args->context != NULL); candidate = nb_running_get_entry(args->dnode, NULL, true); - value = (float)yang_dnode_get_dec64(args->dnode, "./value"); - required = yang_dnode_get_bool(args->dnode, "./required"); + value = (float)yang_dnode_get_dec64(args->dnode, "value"); + required = yang_dnode_get_bool(args->dnode, "required"); srte_candidate_set_bandwidth(candidate, value, required); } diff --git a/pathd/path_pcep.h b/pathd/path_pcep.h index 5c6a02372f..d6dbcb5c08 100644 --- a/pathd/path_pcep.h +++ b/pathd/path_pcep.h @@ -25,6 +25,7 @@ DECLARE_MTYPE(PCEP); #define PCEP_DEBUG_MODE_PATH 0x02 #define PCEP_DEBUG_MODE_PCEP 0x04 #define PCEP_DEBUG_MODE_PCEPLIB 0x08 +#define PCEP_DEBUG_MODE_ALL 0x0F #define PCEP_DEBUG(fmt, ...) \ do { \ if (DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_BASIC)) \ diff --git a/pathd/path_pcep_cli.c b/pathd/path_pcep_cli.c index 6c660a3d08..e0926ea62d 100644 --- a/pathd/path_pcep_cli.c +++ b/pathd/path_pcep_cli.c @@ -52,6 +52,7 @@ static int pcep_cli_pce_config_write(struct vty *vty); static int pcep_cli_pcep_pce_config_write(struct vty *vty); /* Internal Util Function declarations */ +static void reset_pcc_peer(const char *peer_name); static struct pce_opts_cli *pcep_cli_find_pce(const char *pce_name); static bool pcep_cli_add_pce(struct pce_opts_cli *pce_opts_cli); static struct pce_opts_cli *pcep_cli_create_pce_opts(const char *name); @@ -457,28 +458,32 @@ static void pcep_cli_remove_pce_connection(struct pce_opts *pce_opts) * VTY command implementations */ -static int path_pcep_cli_debug(struct vty *vty, const char *no_str, - const char *basic_str, const char *path_str, - const char *message_str, const char *pceplib_str) +static int path_pcep_cli_debug(struct vty *vty, const char *debug_type, bool set) { uint32_t mode = DEBUG_NODE2MODE(vty->node); - bool no = (no_str != NULL); - DEBUG_MODE_SET(&pcep_g->dbg, mode, !no); - - if (basic_str != NULL) { - DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_BASIC, !no); - } - if (path_str != NULL) { - DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_PATH, !no); - } - if (message_str != NULL) { - DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEP, !no); - } - if (pceplib_str != NULL) { - DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEPLIB, !no); + /* Global Set */ + if (debug_type == NULL) { + DEBUG_MODE_SET(&pcep_g->dbg, mode, set); + DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_ALL, set); + return CMD_SUCCESS; } + DEBUG_MODE_SET(&pcep_g->dbg, mode, true); + + if (strcmp(debug_type, "basic") == 0) + DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_BASIC, set); + else if (strcmp(debug_type, "path") == 0) + DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_PATH, set); + else if (strcmp(debug_type, "message") == 0) + DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEP, set); + else if (strcmp(debug_type, "pceplib") == 0) + DEBUG_FLAGS_SET(&pcep_g->dbg, PCEP_DEBUG_MODE_PCEPLIB, set); + + /* Unset the pcep debug mode if there is no flag at least set*/ + if (!DEBUG_FLAGS_CHECK(&pcep_g->dbg, PCEP_DEBUG_MODE_ALL)) + DEBUG_MODE_SET(&pcep_g->dbg, mode, false); + return CMD_SUCCESS; } @@ -741,64 +746,86 @@ static int path_pcep_cli_show_srte_pcep_pce(struct vty *vty, return CMD_SUCCESS; } -static int path_pcep_cli_peer_sr_draft07(struct vty *vty) +static int path_pcep_cli_peer_sr_draft07(struct vty *vty, bool reset) { struct pcep_config_group_opts *pce_config = NULL; + struct pce_opts *pce_opts = ¤t_pce_opts_g->pce_opts; + bool pce_in_use = false; if (vty->node == PCEP_PCE_NODE) { - /* TODO need to see if the pce is in use, and reset the - * connection */ pce_config = ¤t_pce_opts_g->pce_config_group_opts; current_pce_opts_g->merged = false; + pce_in_use = pcep_cli_pcc_has_pce(pce_opts->pce_name); } else if (vty->node == PCEP_PCE_CONFIG_NODE) { pce_config = current_pcep_config_group_opts_g; } else { return CMD_ERR_NO_MATCH; } - pce_config->draft07 = true; + pce_config->draft07 = reset ? DEFAULT_SR_DRAFT07 : true; + + if (pce_in_use) { + vty_out(vty, "%% PCE in use, resetting pcc peer session...\n"); + reset_pcc_peer(pce_opts->pce_name); + } return CMD_SUCCESS; } -static int path_pcep_cli_peer_pce_initiated(struct vty *vty) +static int path_pcep_cli_peer_pce_initiated(struct vty *vty, bool reset) { struct pcep_config_group_opts *pce_config = NULL; + struct pce_opts *pce_opts = ¤t_pce_opts_g->pce_opts; + bool pce_in_use = false; if (vty->node == PCEP_PCE_NODE) { - /* TODO need to see if the pce is in use, and reset the - * connection */ pce_config = ¤t_pce_opts_g->pce_config_group_opts; current_pce_opts_g->merged = false; + pce_in_use = pcep_cli_pcc_has_pce(pce_opts->pce_name); } else if (vty->node == PCEP_PCE_CONFIG_NODE) { pce_config = current_pcep_config_group_opts_g; } else { return CMD_ERR_NO_MATCH; } - pce_config->pce_initiated = true; + pce_config->pce_initiated = reset ? DEFAULT_PCE_INITIATED : true; + + if (pce_in_use) { + vty_out(vty, "%% PCE in use, resetting pcc peer session...\n"); + reset_pcc_peer(pce_opts->pce_name); + } return CMD_SUCCESS; } static int path_pcep_cli_peer_tcp_md5_auth(struct vty *vty, - const char *tcp_md5_auth) + const char *tcp_md5_auth, + bool reset) { struct pcep_config_group_opts *pce_config = NULL; + struct pce_opts *pce_opts = ¤t_pce_opts_g->pce_opts; + bool pce_in_use = false; if (vty->node == PCEP_PCE_NODE) { - /* TODO need to see if the pce is in use, and reset the - * connection */ pce_config = ¤t_pce_opts_g->pce_config_group_opts; current_pce_opts_g->merged = false; + pce_in_use = pcep_cli_pcc_has_pce(pce_opts->pce_name); } else if (vty->node == PCEP_PCE_CONFIG_NODE) { pce_config = current_pcep_config_group_opts_g; } else { return CMD_ERR_NO_MATCH; } - strlcpy(pce_config->tcp_md5_auth, tcp_md5_auth, - sizeof(pce_config->tcp_md5_auth)); + if (reset) + pce_config->tcp_md5_auth[0] = '\0'; + else + strlcpy(pce_config->tcp_md5_auth, tcp_md5_auth, + sizeof(pce_config->tcp_md5_auth)); + + if (pce_in_use) { + vty_out(vty, "%% PCE in use, resetting pcc peer session...\n"); + reset_pcc_peer(pce_opts->pce_name); + } return CMD_SUCCESS; } @@ -841,20 +868,29 @@ static int path_pcep_cli_peer_source_address(struct vty *vty, struct in_addr *ip, const char *ipv6_str, struct in6_addr *ipv6, - const char *port_str, long port) + const char *port_str, long port, + bool reset) { struct pcep_config_group_opts *pce_config = NULL; + struct pce_opts *pce_opts = ¤t_pce_opts_g->pce_opts; + bool pce_in_use = false; + if (vty->node == PCEP_PCE_NODE) { - /* TODO need to see if the pce is in use, and reset the - * connection */ pce_config = ¤t_pce_opts_g->pce_config_group_opts; current_pce_opts_g->merged = false; + pce_in_use = pcep_cli_pcc_has_pce(pce_opts->pce_name); } else if (vty->node == PCEP_PCE_CONFIG_NODE) { pce_config = current_pcep_config_group_opts_g; } else { return CMD_ERR_NO_MATCH; } + if (reset) { + pce_config->source_ip.ipa_type = IPADDR_NONE; + pce_config->source_port = 0; + return CMD_SUCCESS; + } + /* Handle the optional source IP */ if (ipv6_str != NULL) { pce_config->source_ip.ipa_type = IPADDR_V6; @@ -870,6 +906,11 @@ static int path_pcep_cli_peer_source_address(struct vty *vty, PCEP_VTYSH_INT_ARG_CHECK(port_str, port, pce_config->source_port, 0, 65535); + if (pce_in_use) { + vty_out(vty, "%% PCE in use, resetting pcc peer session...\n"); + reset_pcc_peer(pce_opts->pce_name); + } + return CMD_SUCCESS; } @@ -910,11 +951,13 @@ static int path_pcep_cli_peer_timers( const char *delegation_timeout_str, long delegation_timeout) { struct pcep_config_group_opts *pce_config = NULL; + struct pce_opts *pce_opts = ¤t_pce_opts_g->pce_opts; + bool pce_in_use = false; + if (vty->node == PCEP_PCE_NODE) { - /* TODO need to see if the pce is in use, and reset the - * connection */ pce_config = ¤t_pce_opts_g->pce_config_group_opts; current_pce_opts_g->merged = false; + pce_in_use = pcep_cli_pcc_has_pce(pce_opts->pce_name); } else if (vty->node == PCEP_PCE_CONFIG_NODE) { pce_config = current_pcep_config_group_opts_g; } else { @@ -952,6 +995,11 @@ static int path_pcep_cli_peer_timers( PCEP_VTYSH_INT_ARG_CHECK(delegation_timeout_str, delegation_timeout, pce_config->delegation_timeout_seconds, 0, 61); + if (pce_in_use) { + vty_out(vty, "%% PCE in use, resetting pcc peer session...\n"); + reset_pcc_peer(pce_opts->pce_name); + } + return CMD_SUCCESS; } @@ -974,14 +1022,49 @@ static int path_pcep_cli_pcc_delete(struct vty *vty) } static int path_pcep_cli_pcc_pcc_msd(struct vty *vty, const char *msd_str, - long msd) + long msd, bool reset) { - pcc_msd_configured_g = true; - PCEP_VTYSH_INT_ARG_CHECK(msd_str, msd, pcc_msd_g, 0, 33); + if (reset) + pcc_msd_configured_g = false; + else if (msd_str) { + pcc_msd_configured_g = true; + PCEP_VTYSH_INT_ARG_CHECK(msd_str, msd, pcc_msd_g, 0, 33); + } return CMD_SUCCESS; } +void reset_pcc_peer(const char *peer_name) +{ + struct pce_opts_cli *pce_opts_cli = pcep_cli_find_pce(peer_name); + + /* Remove the pcc peer */ + pcep_cli_remove_pce_connection(&pce_opts_cli->pce_opts); + struct pce_opts *pce_opts_copy = + XMALLOC(MTYPE_PCEP, sizeof(struct pce_opts)); + memcpy(pce_opts_copy, &pce_opts_cli->pce_opts, sizeof(struct pce_opts)); + pcep_ctrl_remove_pcc(pcep_g->fpt, pce_opts_copy); + + /* Re-add the pcc peer */ + pcep_cli_merge_pcep_pce_config_options(pce_opts_cli); + pcep_cli_add_pce_connection(&pce_opts_cli->pce_opts); + + /* Update the pcc_opts */ + struct pcc_opts *pcc_opts_copy = + XMALLOC(MTYPE_PCEP, sizeof(struct pcc_opts)); + memcpy(&pcc_opts_copy->addr, + &pce_opts_cli->pce_opts.config_opts.source_ip, + sizeof(pcc_opts_copy->addr)); + pcc_opts_copy->msd = pcc_msd_g; + pcc_opts_copy->port = pce_opts_cli->pce_opts.config_opts.source_port; + pcep_ctrl_update_pcc_options(pcep_g->fpt, pcc_opts_copy); + + /* Update the pce_opts */ + pce_opts_copy = XMALLOC(MTYPE_PCEP, sizeof(struct pce_opts)); + memcpy(pce_opts_copy, &pce_opts_cli->pce_opts, sizeof(struct pce_opts)); + pcep_ctrl_update_pce_options(pcep_g->fpt, pce_opts_copy); +} + static int path_pcep_cli_pcc_pcc_peer(struct vty *vty, const char *peer_name, const char *precedence_str, long precedence) @@ -1623,7 +1706,7 @@ int pcep_cli_pce_config_write(struct vty *vty) &pce_opts->addr.ipaddr_v4); } if (pce_opts->port != PCEP_DEFAULT_PORT) { - vty_out(vty, " %s %d", PCEP_VTYSH_ARG_PORT, + vty_out(vty, " %s %d", PCEP_VTYSH_ARG_PORT, pce_opts->port); } vty_out(vty, "%s\n", buf); @@ -1709,7 +1792,7 @@ DEFPY(show_debugging_pathd_pcep, DEFPY(pcep_cli_debug, pcep_cli_debug_cmd, - "[no] debug pathd pcep [basic]$basic_str [path]$path_str [message]$message_str [pceplib]$pceplib_str", + "[no] debug pathd pcep [<basic|path|message|pceplib>$debug_type]", NO_STR DEBUG_STR "pathd debugging\n" "pcep module debugging\n" @@ -1718,8 +1801,7 @@ DEFPY(pcep_cli_debug, "pcep message debugging\n" "pceplib debugging\n") { - return path_pcep_cli_debug(vty, no, basic_str, path_str, message_str, - pceplib_str); + return path_pcep_cli_debug(vty, debug_type, !no); } DEFPY(pcep_cli_show_srte_pcep_counters, @@ -1743,6 +1825,35 @@ DEFPY_NOSH( return CMD_SUCCESS; } +DEFPY( + pcep_cli_no_pcep, + pcep_cli_no_pcep_cmd, + "no pcep", + NO_STR + "PCEP configuration\n") +{ + /* Delete PCCs */ + path_pcep_cli_pcc_delete(vty); + + for (int i = 0; i < MAX_PCE; i++) { + /* Delete PCEs */ + if (pcep_g->pce_opts_cli[i] != NULL) { + XFREE(MTYPE_PCEP, pcep_g->pce_opts_cli[i]); + pcep_g->pce_opts_cli[i] = NULL; + pcep_g->num_pce_opts_cli--; + } + + /* Delete PCE-CONFIGs */ + if (pcep_g->config_group_opts[i] != NULL) { + XFREE(MTYPE_PCEP, pcep_g->config_group_opts[i]); + pcep_g->config_group_opts[i] = NULL; + pcep_g->num_config_group_opts--; + } + } + + return CMD_SUCCESS; +} + DEFPY_NOSH( pcep_cli_pcep_pce_config, pcep_cli_pcep_pce_config_cmd, @@ -1810,27 +1921,30 @@ DEFPY(pcep_cli_show_srte_pcep_pce, DEFPY(pcep_cli_peer_sr_draft07, pcep_cli_peer_sr_draft07_cmd, - "sr-draft07", + "[no] sr-draft07", + NO_STR "Configure PCC to send PCEP Open with SR draft07\n") { - return path_pcep_cli_peer_sr_draft07(vty); + return path_pcep_cli_peer_sr_draft07(vty, no); } DEFPY(pcep_cli_peer_pce_initiated, pcep_cli_peer_pce_initiated_cmd, - "pce-initiated", + "[no] pce-initiated", + NO_STR "Configure PCC to accept PCE initiated LSPs\n") { - return path_pcep_cli_peer_pce_initiated(vty); + return path_pcep_cli_peer_pce_initiated(vty, no); } DEFPY(pcep_cli_peer_tcp_md5_auth, pcep_cli_peer_tcp_md5_auth_cmd, - "tcp-md5-auth WORD", + "[no] tcp-md5-auth WORD", + NO_STR "Configure PCC TCP-MD5 RFC2385 Authentication\n" "TCP-MD5 Authentication string\n") { - return path_pcep_cli_peer_tcp_md5_auth(vty, tcp_md5_auth); + return path_pcep_cli_peer_tcp_md5_auth(vty, tcp_md5_auth, no); } DEFPY(pcep_cli_peer_address, @@ -1850,7 +1964,8 @@ DEFPY(pcep_cli_peer_address, DEFPY(pcep_cli_peer_source_address, pcep_cli_peer_source_address_cmd, - "source-address [ip A.B.C.D | ipv6 X:X::X:X] [port (1024-65535)]", + "[no] source-address [ip A.B.C.D | ipv6 X:X::X:X] [port (1024-65535)]", + NO_STR "PCE source IP Address configuration\n" "PCE source IPv4 address\n" "PCE source IPv4 address value\n" @@ -1860,7 +1975,7 @@ DEFPY(pcep_cli_peer_source_address, "Source PCE server port value\n") { return path_pcep_cli_peer_source_address(vty, ip_str, &ip, ipv6_str, - &ipv6, port_str, port); + &ipv6, port_str, port, no); } DEFPY(pcep_cli_peer_pcep_pce_config_ref, @@ -1932,7 +2047,17 @@ DEFPY(pcep_cli_pcc_pcc_msd, "PCC maximum SID depth \n" "PCC maximum SID depth value\n") { - return path_pcep_cli_pcc_pcc_msd(vty, msd_str, msd); + return path_pcep_cli_pcc_pcc_msd(vty, msd_str, msd, false); +} + +DEFPY(no_pcep_cli_pcc_pcc_msd, + no_pcep_cli_pcc_pcc_msd_cmd, + "no msd [(1-32)]", + NO_STR + "PCC maximum SID depth \n" + "PCC maximum SID depth value\n") +{ + return path_pcep_cli_pcc_pcc_msd(vty, msd_str, msd, true); } DEFPY(pcep_cli_pcc_pcc_peer, @@ -2008,6 +2133,7 @@ void pcep_cli_init(void) install_default(PCEP_NODE); install_element(SR_TRAFFIC_ENG_NODE, &pcep_cli_pcep_cmd); + install_element(SR_TRAFFIC_ENG_NODE, &pcep_cli_no_pcep_cmd); /* PCEP configuration group related configuration commands */ install_element(PCEP_NODE, &pcep_cli_pcep_pce_config_cmd); @@ -2036,6 +2162,7 @@ void pcep_cli_init(void) install_element(PCEP_NODE, &pcep_cli_no_pcc_cmd); install_element(PCEP_PCC_NODE, &pcep_cli_pcc_pcc_peer_cmd); install_element(PCEP_PCC_NODE, &pcep_cli_pcc_pcc_msd_cmd); + install_element(PCEP_PCC_NODE, &no_pcep_cli_pcc_pcc_msd_cmd); /* Top commands */ install_element(CONFIG_NODE, &pcep_cli_debug_cmd); diff --git a/pathd/path_pcep_debug.c b/pathd/path_pcep_debug.c index 7d04587b8d..7bff9c7b9c 100644 --- a/pathd/path_pcep_debug.c +++ b/pathd/path_pcep_debug.c @@ -1312,6 +1312,8 @@ void _format_path_hop(int ps, struct path_hop *hop) void _format_pcep_event(int ps, pcep_event *event) { + char buf[32]; + if (event == NULL) { PATHD_FORMAT("NULL\n"); } else { @@ -1320,7 +1322,7 @@ void _format_pcep_event(int ps, pcep_event *event) PATHD_FORMAT("%*sevent_type: %s\n", ps2, "", pcep_event_type_name(event->event_type)); PATHD_FORMAT("%*sevent_time: %s", ps2, "", - ctime(&event->event_time)); + ctime_r(&event->event_time, buf)); if (event->session == NULL) { PATHD_FORMAT("%*ssession: NULL\n", ps2, ""); } else { diff --git a/pathd/path_zebra.c b/pathd/path_zebra.c index dad26383e9..645fa50856 100644 --- a/pathd/path_zebra.c +++ b/pathd/path_zebra.c @@ -320,9 +320,6 @@ static zclient_handler *const path_handlers[] = { */ void path_zebra_init(struct event_loop *master) { - struct zclient_options options = zclient_options_default; - options.synchronous = true; - /* Initialize asynchronous zclient. */ zclient = zclient_new(master, &zclient_options_default, path_handlers, array_size(path_handlers)); @@ -330,7 +327,7 @@ void path_zebra_init(struct event_loop *master) zclient->zebra_connected = path_zebra_connected; /* Initialize special zclient for synchronous message exchanges. */ - zclient_sync = zclient_new(master, &options, NULL, 0); + zclient_sync = zclient_new(master, &zclient_options_sync, NULL, 0); zclient_sync->sock = -1; zclient_sync->redist_default = ZEBRA_ROUTE_SRTE; zclient_sync->instance = 1; @@ -344,4 +341,6 @@ void path_zebra_stop(void) { zclient_stop(zclient); zclient_free(zclient); + zclient_stop(zclient_sync); + zclient_free(zclient_sync); } diff --git a/pbrd/pbr_main.c b/pbrd/pbr_main.c index c4708d3f08..dd4893bb78 100644 --- a/pbrd/pbr_main.c +++ b/pbrd/pbr_main.c @@ -71,6 +71,8 @@ static void sigint(void) pbr_vrf_terminate(); + pbr_zebra_destroy(); + frr_fini(); exit(0); @@ -158,8 +160,10 @@ int main(int argc, char **argv, char **envp) access_list_init(); pbr_nht_init(); pbr_map_init(); - if_zapi_callbacks(pbr_ifp_create, pbr_ifp_up, - pbr_ifp_down, pbr_ifp_destroy); + hook_register_prio(if_real, 0, pbr_ifp_create); + hook_register_prio(if_up, 0, pbr_ifp_up); + hook_register_prio(if_down, 0, pbr_ifp_down); + hook_register_prio(if_unreal, 0, pbr_ifp_destroy); pbr_zebra_init(); pbr_vrf_init(); pbr_vty_init(); diff --git a/pbrd/pbr_map.c b/pbrd/pbr_map.c index 16cea3b4cd..8f7a46377c 100644 --- a/pbrd/pbr_map.c +++ b/pbrd/pbr_map.c @@ -3,6 +3,9 @@ * PBR-map Code * Copyright (C) 2018 Cumulus Networks, Inc. * Donald Sharp + * Portions: + * Copyright (c) 2021 The MITRE Corporation. + * Copyright (c) 2023 LabN Consulting, L.L.C. */ #include <zebra.h> @@ -16,6 +19,7 @@ #include "memory.h" #include "log.h" #include "vty.h" +#include "pbr.h" #include "pbr_nht.h" #include "pbr_map.h" @@ -58,7 +62,7 @@ static int pbr_map_sequence_compare(const struct pbr_map_sequence *pbrms1, return 1; } -static void pbr_map_sequence_delete(struct pbr_map_sequence *pbrms) +void pbr_map_sequence_delete(struct pbr_map_sequence *pbrms) { XFREE(MTYPE_TMP, pbrms->internal_nhg_name); @@ -353,6 +357,11 @@ extern void pbr_map_delete(struct pbr_map_sequence *pbrms) if (pbrms->nhg) pbr_nht_delete_individual_nexthop(pbrms); + if (pbrms->nhgrp_name) + XFREE(MTYPE_TMP, pbrms->nhgrp_name); + + prefix_free(&pbrms->dst); + listnode_delete(pbrm->seqnumbers, pbrms); if (pbrm->seqnumbers->count == 0) { @@ -486,9 +495,9 @@ uint8_t pbr_map_decode_dscp_enum(const char *name) struct pbr_map_sequence *pbrms_get(const char *name, uint32_t seqno) { - struct pbr_map *pbrm; - struct pbr_map_sequence *pbrms; - struct listnode *node; + struct pbr_map *pbrm = NULL; + struct pbr_map_sequence *pbrms = NULL; + struct listnode *node = NULL; pbrm = pbrm_find(name); if (!pbrm) { @@ -526,10 +535,6 @@ struct pbr_map_sequence *pbrms_get(const char *name, uint32_t seqno) pbrms->ruleno = pbr_nht_get_next_rule(seqno); pbrms->parent = pbrm; - pbrms->action_vlan_id = 0; - pbrms->action_vlan_flags = 0; - pbrms->action_pcp = 0; - pbrms->action_queue_id = PBR_MAP_UNDEFINED_QUEUE_ID; pbrms->reason = @@ -594,11 +599,42 @@ pbr_map_sequence_check_nexthops_valid(struct pbr_map_sequence *pbrms) static void pbr_map_sequence_check_not_empty(struct pbr_map_sequence *pbrms) { - if (!pbrms->src && !pbrms->dst && !pbrms->mark && !pbrms->dsfield - && !pbrms->action_vlan_id && !pbrms->action_vlan_flags - && !pbrms->action_pcp - && pbrms->action_queue_id == PBR_MAP_UNDEFINED_QUEUE_ID) + /* clang-format off */ + if ( + !CHECK_FLAG(pbrms->filter_bm, ( + PBR_FILTER_SRC_IP | + PBR_FILTER_DST_IP | + PBR_FILTER_SRC_PORT | + PBR_FILTER_DST_PORT | + + PBR_FILTER_IP_PROTOCOL | + PBR_FILTER_DSCP | + PBR_FILTER_ECN | + + PBR_FILTER_FWMARK | + PBR_FILTER_PCP | + PBR_FILTER_VLAN_ID | + PBR_FILTER_VLAN_FLAGS + )) && + !CHECK_FLAG(pbrms->action_bm, ( + PBR_ACTION_SRC_IP | + PBR_ACTION_DST_IP | + PBR_ACTION_SRC_PORT | + PBR_ACTION_DST_PORT | + + PBR_ACTION_DSCP | + PBR_ACTION_ECN | + + PBR_ACTION_PCP | + PBR_ACTION_VLAN_ID | + PBR_ACTION_VLAN_STRIP_INNER_ANY | + + PBR_ACTION_QUEUE_ID + )) + ) { pbrms->reason |= PBR_MAP_INVALID_EMPTY; + } + /* clang-format on */ } static void pbr_map_sequence_check_vlan_actions(struct pbr_map_sequence *pbrms) @@ -611,7 +647,8 @@ static void pbr_map_sequence_check_vlan_actions(struct pbr_map_sequence *pbrms) * The strip vlan action removes any inner tag, so it is invalid to * specify both a set and strip action. */ - if ((pbrms->action_vlan_id != 0) && (pbrms->action_vlan_flags != 0)) + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_VLAN_ID) && + (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_VLAN_STRIP_INNER_ANY))) pbrms->reason |= PBR_MAP_INVALID_SET_STRIP_VLAN; } @@ -734,7 +771,6 @@ void pbr_map_policy_delete(struct pbr_map *pbrm, struct pbr_map_interface *pmi) struct pbr_map_sequence *pbrms; bool sent = false; - for (ALL_LIST_ELEMENTS_RO(pbrm->seqnumbers, node, pbrms)) if (pbr_send_pbr_map(pbrms, pmi, false, true)) sent = true; /* rule removal sent to zebra */ diff --git a/pbrd/pbr_map.h b/pbrd/pbr_map.h index c9da431b38..9fb674bd6e 100644 --- a/pbrd/pbr_map.h +++ b/pbrd/pbr_map.h @@ -3,6 +3,9 @@ * PBR-map Header * Copyright (C) 2018 Cumulus Networks, Inc. * Donald Sharp + * Portions: + * Copyright (c) 2023 LabN Consulting, L.L.C. + * Copyright (c) 2021 The MITRE Corporation */ #ifndef __PBR_MAP_H__ #define __PBR_MAP_H__ @@ -53,6 +56,14 @@ struct pbr_map_interface { bool delete; }; +enum pbr_forwarding_type { + PBR_FT_UNSPEC = 0, + PBR_FT_VRF_UNCHANGED, + PBR_FT_SETVRF, + PBR_FT_NEXTHOP_GROUP, + PBR_FT_NEXTHOP_SINGLE, +}; + struct pbr_map_sequence { struct pbr_map *parent; @@ -71,40 +82,64 @@ struct pbr_map_sequence { */ uint32_t ruleno; + + /***************************************************************** + * Filter fields + * gpz 230716: I hope to replace all of the filter fields with + * 'struct pbr_filter' from lib/pbr.h. + *****************************************************************/ + /* - * src and dst ports + * same bit definitions as in lib/pbr.h */ + uint32_t filter_bm; + + /* Family of the src/dst. Needed when deleting since we clear them */ + unsigned char family; + + /* src and dst IP addresses */ + struct prefix *src; + struct prefix *dst; + + /* src and dst UDP/TCP ports */ uint16_t src_prt; uint16_t dst_prt; - /* - * The ip protocol we want to match on - */ uint8_t ip_proto; - /* - * Our policy Catchers - */ - struct prefix *src; - struct prefix *dst; + uint8_t match_pcp; + uint16_t match_vlan_id; /* bits defined in lib/pbr.h */ + + uint16_t match_vlan_flags; + uint8_t dsfield; uint32_t mark; + /***************************************************************** + * Action fields + *****************************************************************/ + /* - * Actions + * same bit definitions as in lib/pbr.h */ + uint32_t action_bm; + + union sockunion action_src; + union sockunion action_dst; + + uint16_t action_src_port; + uint16_t action_dst_port; + + uint8_t action_dscp; + uint8_t action_ecn; + uint8_t action_pcp; uint8_t action_vlan_id; -#define PBR_MAP_STRIP_INNER_ANY (1 << 0) - uint8_t action_vlan_flags; #define PBR_MAP_UNDEFINED_QUEUE_ID 0 uint32_t action_queue_id; - /* - * Family of the src/dst. Needed when deleting since we clear them - */ - unsigned char family; + enum pbr_forwarding_type forwarding_type; /* * Use interface's vrf. @@ -216,6 +251,8 @@ extern void pbr_map_policy_install(const char *name); extern void pbr_map_policy_delete(struct pbr_map *pbrm, struct pbr_map_interface *pmi); +extern void pbr_map_sequence_delete(struct pbr_map_sequence *pbrms); + extern void pbr_map_check_vrf_nh_group_change(const char *nh_group, struct pbr_vrf *pbr_vrf, uint32_t old_vrf_id); diff --git a/pbrd/pbr_nht.c b/pbrd/pbr_nht.c index 405a2d6588..b9d1ca9bb7 100644 --- a/pbrd/pbr_nht.c +++ b/pbrd/pbr_nht.c @@ -534,6 +534,7 @@ void pbr_nht_set_seq_nhg_data(struct pbr_map_sequence *pbrms, case NEXTHOP_TYPE_IPV4: case NEXTHOP_TYPE_IPV4_IFINDEX: pbrms->family = AF_INET; + break; case NEXTHOP_TYPE_IFINDEX: case NEXTHOP_TYPE_BLACKHOLE: break; @@ -549,6 +550,7 @@ void pbr_nht_set_seq_nhg(struct pbr_map_sequence *pbrms, const char *name) return; pbrms->nhgrp_name = XSTRDUP(MTYPE_TMP, name); + pbrms->forwarding_type = PBR_FT_NEXTHOP_GROUP; nhgc = nhgc_find(name); if (!nhgc) @@ -572,6 +574,7 @@ void pbr_nht_add_individual_nexthop(struct pbr_map_sequence *pbrms, MTYPE_TMP, pbr_nht_nexthop_make_name(pbrms->parent->name, PBR_NHC_NAMELEN, pbrms->seqno, buf)); + pbrms->forwarding_type = PBR_FT_NEXTHOP_SINGLE; nh = nexthop_new(); memcpy(nh, nhop, sizeof(*nh)); @@ -887,7 +890,7 @@ static void pbr_nht_individual_nexthop_update(struct pbr_nexthop_cache *pnhc, pbr_nht_individual_nexthop_interface_update(pnhc, pnhi); break; } - /* Intentional fall thru */ + fallthrough; case NEXTHOP_TYPE_IPV4_IFINDEX: case NEXTHOP_TYPE_IPV4: case NEXTHOP_TYPE_IPV6: diff --git a/pbrd/pbr_nht.h b/pbrd/pbr_nht.h index 9b67492fbc..a702a57155 100644 --- a/pbrd/pbr_nht.h +++ b/pbrd/pbr_nht.h @@ -36,7 +36,7 @@ struct pbr_nexthop_cache { struct pbr_nexthop_group_cache *parent; char vrf_name[VRF_NAMSIZ + 1]; - char intf_name[INTERFACE_NAMSIZ + 1]; + char intf_name[IFNAMSIZ + 1]; struct nexthop nexthop; diff --git a/pbrd/pbr_vty.c b/pbrd/pbr_vty.c index c4e36ebd46..64d88847c8 100644 --- a/pbrd/pbr_vty.c +++ b/pbrd/pbr_vty.c @@ -3,6 +3,9 @@ * PBR - vty code * Copyright (C) 2018 Cumulus Networks, Inc. * Donald Sharp + * Portions: + * Copyright (c) 2021 The MITRE Corporation. + * Copyright (c) 2023 LabN Consulting, L.L.C. */ #include <zebra.h> @@ -25,12 +28,61 @@ #include "pbrd/pbr_debug.h" #include "pbrd/pbr_vty_clippy.c" -DEFUN_NOSH(pbr_map, pbr_map_cmd, "pbr-map PBRMAP seq (1-700)", +/* clang-format off */ +DEFPY (pbr_set_table_range, + pbr_set_table_range_cmd, + "pbr table range (10000-4294966272)$lb (10000-4294966272)$ub", + PBR_STR + "Set table ID range\n" + "Set table ID range\n" + "Lower bound for table ID range\n" + "Upper bound for table ID range\n") +{ + /* clang-format on */ + /* upper bound is 2^32 - 2^10 */ + int ret = CMD_WARNING; + const int minrange = 1000; + + /* validate given bounds */ + if (lb > ub) + vty_out(vty, "%% Lower bound must be less than upper bound\n"); + else if (ub - lb < minrange) + vty_out(vty, "%% Range breadth must be at least %d\n", minrange); + else { + ret = CMD_SUCCESS; + pbr_nht_set_tableid_range((uint32_t)lb, (uint32_t)ub); + } + + return ret; +} + +/* clang-format off */ +DEFPY (no_pbr_set_table_range, + no_pbr_set_table_range_cmd, + "no pbr table range [(10000-4294966272)$lb (10000-4294966272)$ub]", + NO_STR + PBR_STR + "Set table ID range\n" + "Set table ID range\n" + "Lower bound for table ID range\n" + "Upper bound for table ID range\n") +{ + /* clang-format on */ + pbr_nht_set_tableid_range(PBR_NHT_DEFAULT_LOW_TABLEID, + PBR_NHT_DEFAULT_HIGH_TABLEID); + return CMD_SUCCESS; +} + +/* clang-format off */ +DEFUN_NOSH(pbr_map, + pbr_map_cmd, + "pbr-map PBRMAP seq (1-700)", "Create pbr-map or enter pbr-map command mode\n" "The name of the PBR MAP\n" "Sequence to insert in existing pbr-map entry\n" "Sequence number\n") { + /* clang-format on */ const char *pbrm_name = argv[1]->arg; uint32_t seqno = atoi(argv[3]->arg); struct pbr_map_sequence *pbrms; @@ -41,13 +93,17 @@ DEFUN_NOSH(pbr_map, pbr_map_cmd, "pbr-map PBRMAP seq (1-700)", return CMD_SUCCESS; } -DEFUN_NOSH(no_pbr_map, no_pbr_map_cmd, "no pbr-map PBRMAP [seq (1-700)]", +/* clang-format off */ +DEFUN_NOSH(no_pbr_map, + no_pbr_map_cmd, + "no pbr-map PBRMAP [seq (1-700)]", NO_STR "Delete pbr-map\n" "The name of the PBR MAP\n" "Sequence to delete from existing pbr-map entry\n" "Sequence number\n") { + /* clang-format on */ const char *pbrm_name = argv[2]->arg; uint32_t seqno = 0; struct pbr_map *pbrm = pbrm_find(pbrm_name); @@ -67,300 +123,540 @@ DEFUN_NOSH(no_pbr_map, no_pbr_map_cmd, "no pbr-map PBRMAP [seq (1-700)]", continue; pbr_map_delete(pbrms); + pbr_map_sequence_delete(pbrms); } return CMD_SUCCESS; } -DEFPY(pbr_set_table_range, - pbr_set_table_range_cmd, - "pbr table range (10000-4294966272)$lb (10000-4294966272)$ub", - PBR_STR - "Set table ID range\n" - "Set table ID range\n" - "Lower bound for table ID range\n" - "Upper bound for table ID range\n") -{ - /* upper bound is 2^32 - 2^10 */ - int ret = CMD_WARNING; - const int minrange = 1000; +/*********************************************************************** + * pbrms/rule Match L3 Fields + ***********************************************************************/ - /* validate given bounds */ - if (lb > ub) - vty_out(vty, "%% Lower bound must be less than upper bound\n"); - else if (ub - lb < minrange) - vty_out(vty, "%% Range breadth must be at least %d\n", minrange); - else { - ret = CMD_SUCCESS; - pbr_nht_set_tableid_range((uint32_t) lb, (uint32_t) ub); +/* + * Address Family Matters + * + * Linux Kernel constraints + * ------------------------ + * The underlying linux kernel dataplane requires that rules be + * installed into an IPv4-specific or an IPv6-specific database. + * + * Not only do we need to designate an address-family for rule + * installation, but we ALSO must have the same address-family + * available to be able to delete the rule from the correct kernel + * database. + * + * Determining the address-family + * ------------------------------ + * In the current code, we do our best to infer the correct family + * from any configured IP-address match or set clauses in a rule. + * Absent any of those fields, the NHT code also tries to glean the + * address family from resolved nexthops or nexthop-groups. All of + * those opportunistic address-family determinations are stored in + * the "family" field of struct pbr_map_sequence. + * + * This "family" field value is needed particularly when deleting + * a rule piece-by-piece because at the end, the match/set fields + * will be empty. Maybe it would be possible to handle this issue + * as an internal zebra matter in the future. + * + * We also attempt to maintain address-family consistency among the + * various configured fields in a rule. So far, these fields are + * src/dst IP-address match/set values. + * + * It is probably possible to perform the same address-family check in + * the CLI for single nexthops (set nexthop A.B.C.D|X:X::X:X) but the + * address-family is not immediately available for nexthop-groups. + * In both the single-nexthop and nexthop-group, the NHT resolution code + * sets the "family" field of struct pbr_map_sequence asynchronously. + * + * There isn't currently any flagging of rules that have a consistent + * set of src/dst IP-address match/set values but an asynchronously-resolved + * nexthop-group that has a different address-family. + * + * The match/set IP-address handlers below blindly set "family"; it's + * probably possible to wrongly set "family" to, e.g., IPv4 this way after + * a v6 NHG has been resolved and break rule removal. It's not clear + * how to best address this potential issue. + */ +static bool pbr_family_consistent(struct pbr_map_sequence *pbrms, + uint8_t family, uint32_t skip_filter_bm, + uint32_t skip_action_bm, const char **msg) +{ + uint32_t filter_bm = pbrms->filter_bm & ~skip_filter_bm; + uint32_t action_bm = pbrms->action_bm & ~skip_action_bm; + + if (CHECK_FLAG(filter_bm, PBR_FILTER_SRC_IP) && + (family != pbrms->src->family)) { + if (msg) + *msg = "match src-ip"; + return false; } - - return ret; + if (CHECK_FLAG(filter_bm, PBR_FILTER_DST_IP) && + (family != pbrms->dst->family)) { + if (msg) + *msg = "match dst-ip"; + return false; + } + if (CHECK_FLAG(action_bm, PBR_ACTION_SRC_IP) && + (family != sockunion_family(&pbrms->action_src))) { + if (msg) + *msg = "set src-ip"; + return false; + } + if (CHECK_FLAG(filter_bm, PBR_ACTION_DST_IP) && + (family != sockunion_family(&pbrms->action_dst))) { + if (msg) + *msg = "set dst-ip"; + return false; + } + return true; } -DEFPY(no_pbr_set_table_range, no_pbr_set_table_range_cmd, - "no pbr table range [(10000-4294966272)$lb (10000-4294966272)$ub]", - NO_STR - PBR_STR - "Set table ID range\n" - "Set table ID range\n" - "Lower bound for table ID range\n" - "Upper bound for table ID range\n") -{ - pbr_nht_set_tableid_range(PBR_NHT_DEFAULT_LOW_TABLEID, - PBR_NHT_DEFAULT_HIGH_TABLEID); - return CMD_SUCCESS; -} -DEFPY(pbr_map_match_src, pbr_map_match_src_cmd, - "[no] match src-ip <A.B.C.D/M|X:X::X:X/M>$prefix", +/* clang-format off */ +DEFPY (pbr_map_match_src, + pbr_map_match_src_cmd, + "[no] match src-ip ![<A.B.C.D/M|X:X::X:X/M>$prefix]", NO_STR "Match the rest of the command\n" - "Choose the src ip or ipv6 prefix to use\n" + "Choose the src ipv4 or ipv6 prefix to use\n" "v4 Prefix\n" "v6 Prefix\n") { + /* clang-format on */ struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); + const char *fmsg = NULL; if (!pbrms) return CMD_WARNING_CONFIG_FAILED; - if (pbrms->dst && prefix->family != pbrms->dst->family) { - vty_out(vty, "Cannot mismatch families within match src/dst\n"); - return CMD_WARNING_CONFIG_FAILED; + if (no) { + if (!CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_SRC_IP)) + return CMD_SUCCESS; + prefix_free(&pbrms->src); + UNSET_FLAG(pbrms->filter_bm, PBR_FILTER_SRC_IP); + goto check; } + assert(prefix); + if (!pbr_family_consistent(pbrms, prefix->family, PBR_FILTER_SRC_IP, 0, + &fmsg)) { + vty_out(vty, "Address family mismatch (%s)\n", fmsg); + return CMD_WARNING_CONFIG_FAILED; + } pbrms->family = prefix->family; - if (!no) { - if (pbrms->src) { - if (prefix_same(pbrms->src, prefix)) - return CMD_SUCCESS; - } else - pbrms->src = prefix_new(); - - prefix_copy(pbrms->src, prefix); + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_SRC_IP)) { + if (prefix_same(pbrms->src, prefix)) + return CMD_SUCCESS; } else - prefix_free(&pbrms->src); + pbrms->src = prefix_new(); + prefix_copy(pbrms->src, prefix); + SET_FLAG(pbrms->filter_bm, PBR_FILTER_SRC_IP); + +check: pbr_map_check(pbrms, true); return CMD_SUCCESS; } -DEFPY(pbr_map_match_dst, pbr_map_match_dst_cmd, - "[no] match dst-ip <A.B.C.D/M|X:X::X:X/M>$prefix", +/* clang-format off */ +DEFPY (pbr_map_match_dst, + pbr_map_match_dst_cmd, + "[no] match dst-ip ![<A.B.C.D/M|X:X::X:X/M>$prefix]", NO_STR "Match the rest of the command\n" - "Choose the dst ip or ipv6 prefix to use\n" + "Choose the dst ipv4 or ipv6 prefix to use\n" "v4 Prefix\n" "v6 Prefix\n") { + /* clang-format on */ struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); + const char *fmsg = NULL; if (!pbrms) return CMD_WARNING_CONFIG_FAILED; - if (pbrms->src && prefix->family != pbrms->src->family) { - vty_out(vty, "Cannot mismatch families within match src/dst\n"); - return CMD_WARNING_CONFIG_FAILED; + if (no) { + if (!CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_DST_IP)) + return CMD_SUCCESS; + prefix_free(&pbrms->dst); + UNSET_FLAG(pbrms->filter_bm, PBR_FILTER_DST_IP); + goto check; } + assert(prefix); + if (!pbr_family_consistent(pbrms, prefix->family, PBR_FILTER_DST_IP, 0, + &fmsg)) { + vty_out(vty, "Address family mismatch (%s)\n", fmsg); + return CMD_WARNING_CONFIG_FAILED; + } pbrms->family = prefix->family; - if (!no) { - if (pbrms->dst) { - if (prefix_same(pbrms->dst, prefix)) - return CMD_SUCCESS; - } else - pbrms->dst = prefix_new(); - - prefix_copy(pbrms->dst, prefix); + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_DST_IP)) { + if (prefix_same(pbrms->dst, prefix)) + return CMD_SUCCESS; } else - prefix_free(&pbrms->dst); + pbrms->dst = prefix_new(); + prefix_copy(pbrms->dst, prefix); + SET_FLAG(pbrms->filter_bm, PBR_FILTER_DST_IP); + +check: pbr_map_check(pbrms, true); return CMD_SUCCESS; } -DEFPY(pbr_map_match_ip_proto, pbr_map_match_ip_proto_cmd, - "[no] match ip-protocol [tcp|udp]$ip_proto", - NO_STR - "Match the rest of the command\n" - "Choose an ip-protocol\n" - "Match on tcp flows\n" - "Match on udp flows\n") +/* clang-format off */ +DEFPY (pbr_map_match_ip_proto, + pbr_map_match_ip_proto_cmd, + "[no] match ip-protocol ![PROTO$ip_proto]", + NO_STR + "Match the rest of the command\n" + "Choose an ip-protocol\n" + "Protocol name\n") { + /* clang-format on */ struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); - struct protoent *p; + struct protoent *p = NULL; if (!pbrms) return CMD_WARNING_CONFIG_FAILED; - if (!no) { + if (no) { + if (!CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_IP_PROTOCOL)) + return CMD_SUCCESS; + UNSET_FLAG(pbrms->filter_bm, PBR_FILTER_IP_PROTOCOL); + goto check; + } + + if (ip_proto) p = getprotobyname(ip_proto); - if (!p) { - vty_out(vty, "Unable to convert %s to proto id\n", - ip_proto); - return CMD_WARNING; - } - pbrms->ip_proto = p->p_proto; - } else - pbrms->ip_proto = 0; + if (!ip_proto || !p) { + vty_out(vty, "Unable to convert %s to proto id\n", + (ip_proto ? ip_proto : "(null)")); + return CMD_WARNING_CONFIG_FAILED; + } + pbrms->ip_proto = p->p_proto; + SET_FLAG(pbrms->filter_bm, PBR_FILTER_IP_PROTOCOL); + +check: + pbr_map_check(pbrms, true); return CMD_SUCCESS; } -DEFPY(pbr_map_match_src_port, pbr_map_match_src_port_cmd, - "[no] match src-port (1-65535)$port", - NO_STR - "Match the rest of the command\n" - "Choose the source port to use\n" - "The Source Port\n") +/* clang-format off */ +DEFPY (pbr_map_match_src_port, + pbr_map_match_src_port_cmd, + "[no] match src-port ![(1-65535)$port]", + NO_STR + "Match the rest of the command\n" + "Choose the source port to use\n" + "The Source Port\n") { + /* clang-format on */ struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); if (!pbrms) return CMD_WARNING_CONFIG_FAILED; - if (!no) { - if (pbrms->src_prt == port) + if (no) { + if (!CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_SRC_PORT)) return CMD_SUCCESS; - else - pbrms->src_prt = port; - } else - pbrms->src_prt = 0; + UNSET_FLAG(pbrms->filter_bm, PBR_FILTER_SRC_PORT); + goto check; + } - pbr_map_check(pbrms, true); + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_SRC_PORT) && + (pbrms->src_prt == port)) { + return CMD_SUCCESS; + } + pbrms->src_prt = port; + SET_FLAG(pbrms->filter_bm, PBR_FILTER_SRC_PORT); +check: + pbr_map_check(pbrms, true); return CMD_SUCCESS; } -DEFPY(pbr_map_match_dst_port, pbr_map_match_dst_port_cmd, - "[no] match dst-port (1-65535)$port", - NO_STR - "Match the rest of the command\n" - "Choose the destination port to use\n" - "The Destination Port\n") +/* clang-format off */ +DEFPY (pbr_map_match_dst_port, + pbr_map_match_dst_port_cmd, + "[no] match dst-port ![(1-65535)$port]", + NO_STR + "Match the rest of the command\n" + "Choose the destination port to use\n" + "The Destination Port\n") { + /* clang-format on */ struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); if (!pbrms) return CMD_WARNING_CONFIG_FAILED; - if (!no) { - if (pbrms->dst_prt == port) + if (no) { + if (!CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_DST_PORT)) return CMD_SUCCESS; - else - pbrms->dst_prt = port; - } else - pbrms->dst_prt = 0; + UNSET_FLAG(pbrms->filter_bm, PBR_FILTER_DST_PORT); + goto check; + } - pbr_map_check(pbrms, true); + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_DST_PORT) && + (pbrms->dst_prt == port)) { + return CMD_SUCCESS; + } + pbrms->dst_prt = port; + SET_FLAG(pbrms->filter_bm, PBR_FILTER_DST_PORT); +check: + pbr_map_check(pbrms, true); return CMD_SUCCESS; } -DEFPY(pbr_map_match_dscp, pbr_map_match_dscp_cmd, - "[no] match dscp DSCP$dscp", - NO_STR - "Match the rest of the command\n" - "Match based on IP DSCP field\n" - "DSCP value (below 64) or standard codepoint name\n") +/* clang-format off */ +DEFPY (pbr_map_match_dscp, + pbr_map_match_dscp_cmd, + "[no] match dscp ![DSCP$dscp]", + NO_STR + "Match the rest of the command\n" + "Match based on IP DSCP field\n" + "DSCP value (below 64) or standard codepoint name\n") { + /* clang-format on */ struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); - char dscpname[100]; - uint8_t rawDscp; if (!pbrms) return CMD_WARNING_CONFIG_FAILED; - /* Discriminate dscp enums (cs0, cs1 etc.) and numbers */ - bool isANumber = true; - for (int i = 0; i < (int)strlen(dscp); i++) { - /* Letters are not numbers */ - if (!isdigit(dscp[i])) - isANumber = false; + if (no) { + if (!CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_DSCP)) + return CMD_SUCCESS; + UNSET_FLAG(pbrms->filter_bm, PBR_FILTER_DSCP); + pbrms->dsfield &= ~PBR_DSFIELD_DSCP; + goto check; + } - /* Lowercase the dscp enum (if needed) */ - if (isupper(dscp[i])) - dscpname[i] = tolower(dscp[i]); - else - dscpname[i] = dscp[i]; + unsigned long ul_dscp; + char *pend = NULL; + uint8_t shifted_dscp; + + assert(dscp); + ul_dscp = strtoul(dscp, &pend, 0); + if (pend && *pend) + ul_dscp = pbr_map_decode_dscp_enum(dscp); + + if (ul_dscp > (PBR_DSFIELD_DSCP >> 2)) { + vty_out(vty, "Invalid dscp value: %s%s\n", dscp, + ((pend && *pend) ? "" : " (numeric value must be in range 0-63)")); + return CMD_WARNING_CONFIG_FAILED; } - dscpname[strlen(dscp)] = '\0'; - if (isANumber) { - /* dscp passed is a regular number */ - long dscpAsNum = strtol(dscp, NULL, 0); + shifted_dscp = (ul_dscp << 2) & PBR_DSFIELD_DSCP; - if (dscpAsNum > PBR_DSFIELD_DSCP >> 2) { - /* Refuse to install on overflow */ - vty_out(vty, "dscp (%s) must be less than 64\n", dscp); - return CMD_WARNING_CONFIG_FAILED; - } - rawDscp = dscpAsNum; - } else { - /* check dscp if it is an enum like cs0 */ - rawDscp = pbr_map_decode_dscp_enum(dscpname); - if (rawDscp > PBR_DSFIELD_DSCP) { - vty_out(vty, "Invalid dscp value: %s\n", dscpname); - return CMD_WARNING_CONFIG_FAILED; - } + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_DSCP) && + ((pbrms->dsfield & PBR_DSFIELD_DSCP) == shifted_dscp)) { + return CMD_SUCCESS; } - if (!no) { - if (((pbrms->dsfield & PBR_DSFIELD_DSCP) >> 2) == rawDscp) + /* Set the DSCP bits of the DSField */ + pbrms->dsfield = (pbrms->dsfield & ~PBR_DSFIELD_DSCP) | shifted_dscp; + SET_FLAG(pbrms->filter_bm, PBR_FILTER_DSCP); + +check: + pbr_map_check(pbrms, true); + return CMD_SUCCESS; +} + +/* clang-format off */ +DEFPY (pbr_map_match_ecn, + pbr_map_match_ecn_cmd, + "[no] match ecn ![(0-3)$ecn]", + NO_STR + "Match the rest of the command\n" + "Match based on IP ECN field\n" + "Explicit Congestion Notification\n") +{ + /* clang-format on */ + struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); + + if (!pbrms) + return CMD_WARNING_CONFIG_FAILED; + + if (no) { + if (!CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_ECN)) return CMD_SUCCESS; + UNSET_FLAG(pbrms->filter_bm, PBR_FILTER_ECN); + pbrms->dsfield &= ~PBR_DSFIELD_ECN; + goto check; + } - /* Set the DSCP bits of the DSField */ - pbrms->dsfield = - (pbrms->dsfield & ~PBR_DSFIELD_DSCP) | (rawDscp << 2); - } else { - pbrms->dsfield &= ~PBR_DSFIELD_DSCP; + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_ECN) && + ((pbrms->dsfield & PBR_DSFIELD_ECN) == ecn)) { + return CMD_SUCCESS; } + /* Set the ECN bits of the DSField */ + pbrms->dsfield = (pbrms->dsfield & ~PBR_DSFIELD_ECN) | ecn; + SET_FLAG(pbrms->filter_bm, PBR_FILTER_ECN); + +check: pbr_map_check(pbrms, true); + return CMD_SUCCESS; +} +/*********************************************************************** + * pbrms/rule Match L2 fields + ***********************************************************************/ + +/* clang-format off */ +DEFPY (pbr_map_match_pcp, + pbr_map_match_pcp_cmd, + "[no] match pcp ![(0-7)$pcp]", + NO_STR + "Match spec follows\n" + "Match based on 802.1p Priority Code Point (PCP) value\n" + "PCP value to match\n") +{ + /* clang-format on */ + struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); + + if (!pbrms) + return CMD_WARNING_CONFIG_FAILED; + + if (no) { + if (!CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_PCP)) + return CMD_SUCCESS; + UNSET_FLAG(pbrms->filter_bm, PBR_FILTER_PCP); + goto check; + } + + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_PCP) && + (pbrms->match_pcp == pcp)) { + return CMD_SUCCESS; + } + + pbrms->match_pcp = pcp; + SET_FLAG(pbrms->filter_bm, PBR_FILTER_PCP); + +check: + pbr_map_check(pbrms, true); return CMD_SUCCESS; } -DEFPY(pbr_map_match_ecn, pbr_map_match_ecn_cmd, - "[no] match ecn (0-3)$ecn", - NO_STR - "Match the rest of the command\n" - "Match based on IP ECN field\n" - "Explicit Congestion Notification\n") +/* clang-format off */ +DEFPY (pbr_map_match_vlan_id, + pbr_map_match_vlan_id_cmd, + "[no] match vlan ![(1-4094)$vlan_id]", + NO_STR + "Match spec follows\n" + "Match based on VLAN ID\n" + "VLAN ID to match\n") { + /* clang-format on */ struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); if (!pbrms) return CMD_WARNING_CONFIG_FAILED; - if (!no) { - if ((pbrms->dsfield & PBR_DSFIELD_ECN) == ecn) + if (no) { + if (!CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_VLAN_ID)) return CMD_SUCCESS; + UNSET_FLAG(pbrms->filter_bm, PBR_FILTER_VLAN_ID); + goto check; + } - /* Set the ECN bits of the DSField */ - pbrms->dsfield = (pbrms->dsfield & ~PBR_DSFIELD_ECN) | ecn; - } else { - pbrms->dsfield &= ~PBR_DSFIELD_ECN; + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_VLAN_ID) && + (pbrms->match_vlan_id == vlan_id)) { + return CMD_SUCCESS; } + /* + * Maintaining previous behavior: setting a vlan_id match + * automatically clears any vlan_flags matching. + */ + UNSET_FLAG(pbrms->filter_bm, PBR_FILTER_VLAN_FLAGS); + SET_FLAG(pbrms->filter_bm, PBR_FILTER_VLAN_ID); + pbrms->match_vlan_id = vlan_id; + +check: pbr_map_check(pbrms, true); + return CMD_SUCCESS; +} + +/* clang-format off */ +DEFPY (pbr_map_match_vlan_tag, + pbr_map_match_vlan_tag_cmd, + "[no] match vlan ![<tagged|untagged|untagged-or-zero>$tag_type]", + NO_STR + "Match the rest of the command\n" + "Match based on VLAN tagging\n" + "Match all tagged frames\n" + "Match all untagged frames\n" + "Match untagged frames, or tagged frames with id zero\n") +{ + /* clang-format on */ + struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); + uint16_t vlan_flags; + + if (!pbrms) + return CMD_WARNING_CONFIG_FAILED; + if (no) { + if (!CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_VLAN_FLAGS)) + return CMD_SUCCESS; + UNSET_FLAG(pbrms->filter_bm, PBR_FILTER_VLAN_FLAGS); + goto check; + } + + assert(tag_type); + if (strmatch(tag_type, "tagged")) + vlan_flags = PBR_VLAN_FLAGS_TAGGED; + else if (strmatch(tag_type, "untagged")) + vlan_flags = PBR_VLAN_FLAGS_UNTAGGED; + else if (strmatch(tag_type, "untagged-or-zero")) + vlan_flags = PBR_VLAN_FLAGS_UNTAGGED_0; + else { + vty_out(vty, "unknown vlan flag\n"); + return CMD_WARNING_CONFIG_FAILED; + } + + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_VLAN_FLAGS) && + (pbrms->match_vlan_flags == vlan_flags)) { + return CMD_SUCCESS; + } + + /* + * Maintaining previous behavior: setting a vlan_flags match + * automatically clears any vlan_id matching. + */ + UNSET_FLAG(pbrms->filter_bm, PBR_FILTER_VLAN_ID); + SET_FLAG(pbrms->filter_bm, PBR_FILTER_VLAN_FLAGS); + pbrms->match_vlan_flags = vlan_flags; + +check: + pbr_map_check(pbrms, true); return CMD_SUCCESS; } -DEFPY(pbr_map_match_mark, pbr_map_match_mark_cmd, - "[no] match mark (1-4294967295)$mark", +/*********************************************************************** + * pbrms/rule Match meta + ***********************************************************************/ + +/* clang-format off */ +DEFPY (pbr_map_match_mark, + pbr_map_match_mark_cmd, + "[no] match mark ![(1-4294967295)$mark]", NO_STR "Match the rest of the command\n" "Choose the mark value to use\n" "mark\n") { + /* clang-format on */ struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); if (!pbrms) @@ -371,139 +667,466 @@ DEFPY(pbr_map_match_mark, pbr_map_match_mark_cmd, return CMD_WARNING_CONFIG_FAILED; #endif - if (!no) { - if (pbrms->mark) - if (pbrms->mark == (uint32_t)mark) - return CMD_SUCCESS; + if (no) { + if (!CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_FWMARK)) + return CMD_SUCCESS; + UNSET_FLAG(pbrms->filter_bm, PBR_FILTER_FWMARK); + goto check; + } - pbrms->mark = (uint32_t)mark; - } else - pbrms->mark = 0; + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_FWMARK) && + (pbrms->mark == (uint32_t)mark)) { + return CMD_SUCCESS; + } + pbrms->mark = (uint32_t)mark; + SET_FLAG(pbrms->filter_bm, PBR_FILTER_FWMARK); + +check: pbr_map_check(pbrms, true); return CMD_SUCCESS; } -static void pbrms_clear_set_vrf_config(struct pbr_map_sequence *pbrms) +/*********************************************************************** + * pbrms/rule Action Set L3 Fields + ***********************************************************************/ + +/* clang-format off */ +DEFPY (pbr_map_action_src, + pbr_map_action_src_cmd, + "[no] set src-ip ![<A.B.C.D|X:X::X:X>$su]", + NO_STR + "Set command\n" + "Set the src ipv4 or ipv6 prefix\n" + "v4 Prefix\n" + "v6 Prefix\n") { - if (pbrms->vrf_lookup || pbrms->vrf_unchanged) { - pbr_map_delete_vrf(pbrms); - pbrms->vrf_name[0] = '\0'; - pbrms->vrf_lookup = false; - pbrms->vrf_unchanged = false; + /* clang-format on */ + struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); + const char *fmsg = NULL; + + if (!pbrms) + return CMD_WARNING_CONFIG_FAILED; + + if (no) { + if (!CHECK_FLAG(pbrms->action_bm, PBR_ACTION_SRC_IP)) + return CMD_SUCCESS; + UNSET_FLAG(pbrms->action_bm, PBR_ACTION_SRC_IP); + goto check; + } + + assert(su); + if (!pbr_family_consistent(pbrms, sockunion_family(su), + PBR_ACTION_SRC_IP, 0, &fmsg)) { + vty_out(vty, "Address family mismatch (%s)\n", fmsg); + return CMD_WARNING_CONFIG_FAILED; + } + pbrms->family = sockunion_family(su); + + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_SRC_IP) && + (sockunion_same(&pbrms->action_src, su))) { + return CMD_SUCCESS; } + pbrms->action_src = *su; + SET_FLAG(pbrms->action_bm, PBR_ACTION_SRC_IP); + +check: + pbr_map_check(pbrms, true); + return CMD_SUCCESS; } -static void pbrms_clear_set_nhg_config(struct pbr_map_sequence *pbrms) +/* clang-format off */ +DEFPY (pbr_map_action_dst, + pbr_map_action_dst_cmd, + "[no] set dst-ip ![<A.B.C.D|X:X::X:X>$su]", + NO_STR + "Set command\n" + "Set the dst ipv4 or ipv6 prefix\n" + "v4 Prefix\n" + "v6 Prefix\n") { - if (pbrms->nhgrp_name) - pbr_map_delete_nexthops(pbrms); + /* clang-format on */ + struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); + const char *fmsg = NULL; + + if (!pbrms) + return CMD_WARNING_CONFIG_FAILED; + + if (no) { + if (!CHECK_FLAG(pbrms->action_bm, PBR_ACTION_DST_IP)) + return CMD_SUCCESS; + UNSET_FLAG(pbrms->action_bm, PBR_ACTION_DST_IP); + goto check; + } + + assert(su); + if (!pbr_family_consistent(pbrms, sockunion_family(su), + PBR_ACTION_DST_IP, 0, &fmsg)) { + vty_out(vty, "Address family mismatch (%s)\n", fmsg); + return CMD_WARNING_CONFIG_FAILED; + } + pbrms->family = sockunion_family(su); + + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_DST_IP) && + (sockunion_same(&pbrms->action_dst, su))) { + return CMD_SUCCESS; + } + pbrms->action_dst = *su; + SET_FLAG(pbrms->action_bm, PBR_ACTION_DST_IP); + +check: + pbr_map_check(pbrms, true); + return CMD_SUCCESS; } -static void pbrms_clear_set_nexthop_config(struct pbr_map_sequence *pbrms) +/* clang-format off */ +DEFPY (pbr_map_action_src_port, + pbr_map_action_src_port_cmd, + "[no] set src-port ![(1-65535)$port]", + NO_STR + "Set command\n" + "Set Source Port\n" + "The Source Port\n") { - if (pbrms->nhg) - pbr_nht_delete_individual_nexthop(pbrms); + /* clang-format on */ + struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); + + if (!pbrms) + return CMD_WARNING_CONFIG_FAILED; + + if (no) { + if (!CHECK_FLAG(pbrms->action_bm, PBR_ACTION_SRC_PORT)) + return CMD_SUCCESS; + UNSET_FLAG(pbrms->action_bm, PBR_ACTION_SRC_PORT); + goto check; + } + + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_SRC_PORT) && + (pbrms->action_src_port == port)) + return CMD_SUCCESS; + + pbrms->action_src_port = port; + SET_FLAG(pbrms->action_bm, PBR_ACTION_SRC_PORT); + +check: + pbr_map_check(pbrms, true); + return CMD_SUCCESS; } -static void pbrms_clear_set_config(struct pbr_map_sequence *pbrms) +/* clang-format off */ +DEFPY (pbr_map_action_dst_port, + pbr_map_action_dst_port_cmd, + "[no] set dst-port ![(1-65535)$port]", + NO_STR + "Set command\n" + "Set Destination Port\n" + "The Destination Port\n") { - pbrms_clear_set_vrf_config(pbrms); - pbrms_clear_set_nhg_config(pbrms); - pbrms_clear_set_nexthop_config(pbrms); + /* clang-format on */ + struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); - pbrms->nhs_installed = false; -} + if (!pbrms) + return CMD_WARNING_CONFIG_FAILED; + if (no) { + if (!CHECK_FLAG(pbrms->action_bm, PBR_ACTION_DST_PORT)) + return CMD_SUCCESS; + UNSET_FLAG(pbrms->action_bm, PBR_ACTION_DST_PORT); + goto check; + } + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_DST_PORT) && + (pbrms->action_dst_port == port)) + return CMD_SUCCESS; -DEFPY(pbr_map_action_queue_id, pbr_map_action_queue_id_cmd, - "[no] set queue-id <(1-65535)$queue_id>", - NO_STR - "Set the rest of the command\n" - "Set based on egress port queue id\n" - "A valid value in range 1..65535 \n") + SET_FLAG(pbrms->action_bm, PBR_ACTION_DST_PORT); + pbrms->action_dst_port = port; + +check: + pbr_map_check(pbrms, true); + return CMD_SUCCESS; +} + +/* clang-format off */ +DEFPY (pbr_map_action_dscp, + pbr_map_action_dscp_cmd, + "[no] set dscp ![DSCP$dscp]", + NO_STR + "Set command\n" + "Set IP DSCP field\n" + "DSCP numeric value (0-63) or standard codepoint name\n") { + /* clang-format on */ struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); if (!pbrms) return CMD_WARNING_CONFIG_FAILED; - if (!no) - pbrms->action_queue_id = queue_id; - else if ((uint32_t)queue_id == pbrms->action_queue_id) - pbrms->action_queue_id = PBR_MAP_UNDEFINED_QUEUE_ID; + if (no) { + if (!CHECK_FLAG(pbrms->action_bm, PBR_ACTION_DSCP)) + return CMD_SUCCESS; + UNSET_FLAG(pbrms->action_bm, PBR_ACTION_DSCP); + goto check; + } - pbr_map_check(pbrms, true); + unsigned long ul_dscp; + char *pend = NULL; + uint8_t shifted_dscp; + + assert(dscp); + ul_dscp = strtoul(dscp, &pend, 0); + if (pend && *pend) + ul_dscp = pbr_map_decode_dscp_enum(dscp); + + if (ul_dscp > (PBR_DSFIELD_DSCP >> 2)) { + vty_out(vty, "Invalid dscp value: %s%s\n", dscp, + ((pend && *pend) ? "" : " (numeric value must be in range 0-63)")); + return CMD_WARNING_CONFIG_FAILED; + } + + shifted_dscp = (ul_dscp << 2) & PBR_DSFIELD_DSCP; + + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_DSCP) && + (pbrms->action_dscp == shifted_dscp)) { + return CMD_SUCCESS; + } + SET_FLAG(pbrms->action_bm, PBR_ACTION_DSCP); + pbrms->action_dscp = shifted_dscp; +check: + pbr_map_check(pbrms, true); return CMD_SUCCESS; } -DEFPY(pbr_map_action_pcp, pbr_map_action_pcp_cmd, "[no] set pcp <(0-7)$pcp>", - NO_STR - "Set the rest of the command\n" - "Set based on 802.1p Priority Code Point (PCP) value\n" - "A valid value in range 0..7\n") +/* clang-format off */ +DEFPY (pbr_map_action_ecn, + pbr_map_action_ecn_cmd, + "[no] set ecn ![(0-3)$ecn]", + NO_STR + "Set command\n" + "Set IP ECN field\n" + "Explicit Congestion Notification value\n") { + /* clang-format on */ struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); if (!pbrms) return CMD_WARNING_CONFIG_FAILED; - if (!no) - pbrms->action_pcp = pcp; - else if (pcp == pbrms->action_pcp) - pbrms->action_pcp = 0; + if (no) { + if (!CHECK_FLAG(pbrms->action_bm, PBR_ACTION_ECN)) + return CMD_SUCCESS; + UNSET_FLAG(pbrms->action_bm, PBR_ACTION_ECN); + goto check; + } + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_ECN) && + (pbrms->action_ecn == ecn)) { + return CMD_SUCCESS; + } + SET_FLAG(pbrms->action_bm, PBR_ACTION_ECN); + pbrms->action_ecn = ecn; +check: pbr_map_check(pbrms, true); - return CMD_SUCCESS; } -DEFPY(pbr_map_action_vlan_id, pbr_map_action_vlan_id_cmd, - "[no] set vlan <(1-4094)$vlan_id>", - NO_STR - "Set the rest of the command\n" - "Set action for VLAN tagging\n" - "A valid value in range 1..4094\n") + +/*********************************************************************** + * pbrms/rule Action Set Meta + ***********************************************************************/ + +/* clang-format off */ +DEFPY (pbr_map_action_queue_id, + pbr_map_action_queue_id_cmd, + "[no] set queue-id ![(1-65535)$queue_id]", + NO_STR + "Set the rest of the command\n" + "Set based on egress port queue id\n" + "A valid value in range 1..65535 \n") { + /* clang-format on */ struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); if (!pbrms) return CMD_WARNING_CONFIG_FAILED; - if (!no) - pbrms->action_vlan_id = vlan_id; - else if (pbrms->action_vlan_id == vlan_id) - pbrms->action_vlan_id = 0; + if (no) { + if (!CHECK_FLAG(pbrms->action_bm, PBR_ACTION_QUEUE_ID)) + return CMD_SUCCESS; + UNSET_FLAG(pbrms->action_bm, PBR_ACTION_QUEUE_ID); + goto check; + } + + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_QUEUE_ID) && + (pbrms->action_queue_id == (uint32_t)queue_id)) { + return CMD_SUCCESS; + } + pbrms->action_queue_id = (uint32_t)queue_id; + SET_FLAG(pbrms->action_bm, PBR_ACTION_QUEUE_ID); +check: pbr_map_check(pbrms, true); + return CMD_SUCCESS; +} + + +/*********************************************************************** + * pbrms/rule Action Set L2 Fields + ***********************************************************************/ + +/* clang-format off */ +DEFPY (pbr_map_action_pcp, + pbr_map_action_pcp_cmd, + "[no] set pcp ![(0-7)$pcp]", + NO_STR + "Set the rest of the command\n" + "Set based on 802.1p Priority Code Point (PCP) value\n" + "A valid value in range 0..7\n") +{ + /* clang-format on */ + struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); + + if (!pbrms) + return CMD_WARNING_CONFIG_FAILED; + if (no) { + if (!CHECK_FLAG(pbrms->action_bm, PBR_ACTION_PCP)) + return CMD_SUCCESS; + UNSET_FLAG(pbrms->action_bm, PBR_ACTION_PCP); + goto check; + } + + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_PCP) && + pbrms->action_pcp == pcp) { + return CMD_SUCCESS; + } + + pbrms->action_pcp = pcp; + SET_FLAG(pbrms->action_bm, PBR_ACTION_PCP); + +check: + pbr_map_check(pbrms, true); return CMD_SUCCESS; } -DEFPY(pbr_map_action_strip_vlan, pbr_map_action_strip_vlan_cmd, - "[no] strip vlan", - NO_STR - "Strip the vlan tags from frame\n" - "Strip any inner vlan tag \n") +/* clang-format off */ +DEFPY (pbr_map_action_vlan_id, + pbr_map_action_vlan_id_cmd, + "[no] set vlan ![(1-4094)$vlan_id]", + NO_STR + "Set the rest of the command\n" + "Set action for VLAN tagging\n" + "A valid value in range 1..4094\n") { + /* clang-format on */ struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); if (!pbrms) return CMD_WARNING_CONFIG_FAILED; - if (!no) - pbrms->action_vlan_flags = PBR_MAP_STRIP_INNER_ANY; - else - pbrms->action_vlan_flags = 0; + if (no) { + if (!CHECK_FLAG(pbrms->action_bm, PBR_ACTION_VLAN_ID)) + return CMD_SUCCESS; + UNSET_FLAG(pbrms->action_bm, PBR_ACTION_VLAN_ID); + goto check; + } + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_VLAN_ID) && + (pbrms->action_vlan_id == vlan_id)) { + return CMD_SUCCESS; + } + + /* + * Setting a vlan_id action automatically clears any strip-inner action + */ + pbrms->action_vlan_id = vlan_id; + UNSET_FLAG(pbrms->action_bm, PBR_ACTION_VLAN_STRIP_INNER_ANY); + SET_FLAG(pbrms->action_bm, PBR_ACTION_VLAN_ID); + +check: pbr_map_check(pbrms, true); + return CMD_SUCCESS; +} + +/* clang-format off */ +DEFPY (pbr_map_action_strip_vlan, + pbr_map_action_strip_vlan_cmd, + "[no] strip vlan", + NO_STR + "Strip the vlan tags from frame\n" + "Strip any inner vlan tag\n") +{ + /* clang-format on */ + struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); + + if (!pbrms) + return CMD_WARNING_CONFIG_FAILED; + if (no) { + if (!CHECK_FLAG(pbrms->action_bm, + PBR_ACTION_VLAN_STRIP_INNER_ANY)) + return CMD_SUCCESS; + UNSET_FLAG(pbrms->action_bm, PBR_ACTION_VLAN_STRIP_INNER_ANY); + goto check; + } + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_VLAN_STRIP_INNER_ANY)) + return CMD_SUCCESS; + + /* + * Setting a strip-inner action automatically clears any vlan_id action + */ + UNSET_FLAG(pbrms->action_bm, PBR_ACTION_VLAN_ID); + SET_FLAG(pbrms->action_bm, PBR_ACTION_VLAN_STRIP_INNER_ANY); + +check: + pbr_map_check(pbrms, true); return CMD_SUCCESS; } +/*********************************************************************** + * pbrms/rule Action Forwarding + ***********************************************************************/ + +static void pbrms_clear_set_vrf_config(struct pbr_map_sequence *pbrms) +{ + if (pbrms->vrf_lookup || pbrms->vrf_unchanged) { + pbr_map_delete_vrf(pbrms); + pbrms->vrf_name[0] = '\0'; + pbrms->vrf_lookup = false; + pbrms->vrf_unchanged = false; + } +} + +static void pbrms_clear_set_nhg_config(struct pbr_map_sequence *pbrms) +{ + if (pbrms->nhgrp_name) + pbr_map_delete_nexthops(pbrms); +} + +static void pbrms_clear_set_nexthop_config(struct pbr_map_sequence *pbrms) +{ + if (pbrms->nhg) + pbr_nht_delete_individual_nexthop(pbrms); +} + +static void pbrms_clear_set_config(struct pbr_map_sequence *pbrms) +{ + pbrms_clear_set_vrf_config(pbrms); + pbrms_clear_set_nhg_config(pbrms); + pbrms_clear_set_nexthop_config(pbrms); + + pbrms->nhs_installed = false; + + pbrms->forwarding_type = PBR_FT_UNSPEC; + + /* clear advisory flag indicating nexthop == blackhole */ + UNSET_FLAG(pbrms->action_bm, PBR_ACTION_DROP); +} + + + DEFPY(pbr_map_nexthop_group, pbr_map_nexthop_group_cmd, "set nexthop-group NHGNAME$name", "Set for the PBR-MAP\n" @@ -554,22 +1177,27 @@ DEFPY(no_pbr_map_nexthop_group, no_pbr_map_nexthop_group_cmd, return CMD_SUCCESS; } -DEFPY(pbr_map_nexthop, pbr_map_nexthop_cmd, - "set nexthop\ +/* clang-format off */ +DEFPY (pbr_map_nexthop, + pbr_map_nexthop_cmd, + "set nexthop\ <\ <A.B.C.D|X:X::X:X>$addr [INTERFACE$intf]\ |INTERFACE$intf\ + |blackhole$bh\ >\ [nexthop-vrf NAME$vrf_name]", - "Set for the PBR-MAP\n" - "Specify one of the nexthops in this map\n" - "v4 Address\n" - "v6 Address\n" - "Interface to use\n" - "Interface to use\n" - "If the nexthop is in a different vrf tell us\n" - "The nexthop-vrf Name\n") + "Set for the PBR-MAP\n" + "Specify one of the nexthops in this map\n" + "v4 Address\n" + "v6 Address\n" + "Interface to use\n" + "Interface to use\n" + "Blackhole route\n" + "If the nexthop is in a different vrf tell us\n" + "The nexthop-vrf Name\n") { + /* clang-format on */ struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); struct vrf *vrf; struct nexthop nhop; @@ -651,8 +1279,13 @@ DEFPY(pbr_map_nexthop, pbr_map_nexthop_cmd, nhop.type = NEXTHOP_TYPE_IPV6; } } - } else + } else if (bh) { + nhop.type = NEXTHOP_TYPE_BLACKHOLE; + /* advisory flag for non-linux dataplanes */ + SET_FLAG(pbrms->action_bm, PBR_ACTION_DROP); + } else { nhop.type = NEXTHOP_TYPE_IFINDEX; + } if (pbrms->nhg) nh = nexthop_exists(pbrms->nhg, &nhop); @@ -681,23 +1314,28 @@ DEFPY(pbr_map_nexthop, pbr_map_nexthop_cmd, return CMD_SUCCESS; } -DEFPY(no_pbr_map_nexthop, no_pbr_map_nexthop_cmd, - "no set nexthop\ +/* clang-format off */ +DEFPY (no_pbr_map_nexthop, + no_pbr_map_nexthop_cmd, + "no set nexthop\ [<\ <A.B.C.D|X:X::X:X>$addr [INTERFACE$intf]\ |INTERFACE$intf\ + |blackhole$bh\ >\ [nexthop-vrf NAME$vrf_name]]", - NO_STR - "Set for the PBR-MAP\n" - "Specify one of the nexthops in this map\n" - "v4 Address\n" - "v6 Address\n" - "Interface to use\n" - "Interface to use\n" - "If the nexthop is in a different vrf tell us\n" - "The nexthop-vrf Name\n") + NO_STR + "Set for the PBR-MAP\n" + "Specify one of the nexthops in this map\n" + "v4 Address\n" + "v6 Address\n" + "Interface to use\n" + "Interface to use\n" + "Blackhole route\n" + "If the nexthop is in a different vrf tell us\n" + "The nexthop-vrf Name\n") { + /* clang-format on */ struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); if (!pbrms) @@ -723,10 +1361,12 @@ DEFPY(pbr_map_vrf, pbr_map_vrf_cmd, /* * If an equivalent set vrf * exists, just return success. */ - if (vrf_name && pbrms->vrf_lookup - && strncmp(pbrms->vrf_name, vrf_name, sizeof(pbrms->vrf_name)) == 0) + if ((pbrms->forwarding_type == PBR_FT_SETVRF) && + vrf_name && + strncmp(pbrms->vrf_name, vrf_name, sizeof(pbrms->vrf_name)) == 0) return CMD_SUCCESS; - else if (!vrf_name && pbrms->vrf_unchanged) /* Unchanged already set */ + else if (!vrf_name && (pbrms->forwarding_type == PBR_FT_VRF_UNCHANGED)) + /* Unchanged already set */ return CMD_SUCCESS; if (vrf_name && !pbr_vrf_lookup_by_name(vrf_name)) { @@ -739,9 +1379,12 @@ DEFPY(pbr_map_vrf, pbr_map_vrf_cmd, if (vrf_name) { pbrms->vrf_lookup = true; + pbrms->forwarding_type = PBR_FT_SETVRF; strlcpy(pbrms->vrf_name, vrf_name, sizeof(pbrms->vrf_name)); - } else + } else { + pbrms->forwarding_type = PBR_FT_VRF_UNCHANGED; pbrms->vrf_unchanged = true; + } pbr_map_check(pbrms, true); @@ -766,13 +1409,19 @@ DEFPY(no_pbr_map_vrf, no_pbr_map_vrf_cmd, return CMD_SUCCESS; } -DEFPY (pbr_policy, +/*********************************************************************** + * Policy + ***********************************************************************/ + +/* clang-format off */ +DEFPY (pbr_policy, pbr_policy_cmd, "[no] pbr-policy PBRMAP$mapname", NO_STR "Policy to use\n" "Name of the pbr-map to apply\n") { + /* clang-format on */ VTY_DECLVAR_CONTEXT(interface, ifp); struct pbr_map *pbrm, *old_pbrm; struct pbr_interface *pbr_ifp = ifp->info; @@ -879,43 +1528,93 @@ static void vty_show_pbrms(struct vty *vty, pbrms->installed ? "yes" : "no", pbrms->reason ? rbuf : "Valid"); - if (pbrms->ip_proto) { + /* match clauses first */ + + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_IP_PROTOCOL)) { struct protoent *p; p = getprotobynumber(pbrms->ip_proto); vty_out(vty, " IP Protocol Match: %s\n", p->p_name); } - if (pbrms->src) + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_SRC_IP)) vty_out(vty, " SRC IP Match: %pFX\n", pbrms->src); - if (pbrms->dst) + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_DST_IP)) vty_out(vty, " DST IP Match: %pFX\n", pbrms->dst); - if (pbrms->src_prt) + + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_SRC_PORT)) vty_out(vty, " SRC Port Match: %u\n", pbrms->src_prt); - if (pbrms->dst_prt) + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_DST_PORT)) vty_out(vty, " DST Port Match: %u\n", pbrms->dst_prt); - if (pbrms->dsfield & PBR_DSFIELD_DSCP) + + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_DSCP)) vty_out(vty, " DSCP Match: %u\n", (pbrms->dsfield & PBR_DSFIELD_DSCP) >> 2); - if (pbrms->dsfield & PBR_DSFIELD_ECN) + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_ECN)) vty_out(vty, " ECN Match: %u\n", pbrms->dsfield & PBR_DSFIELD_ECN); - if (pbrms->mark) + + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_FWMARK)) vty_out(vty, " MARK Match: %u\n", pbrms->mark); + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_PCP)) + vty_out(vty, " PCP Match: %d\n", pbrms->match_pcp); + + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_VLAN_ID)) + vty_out(vty, " Match VLAN ID: %u\n", + pbrms->match_vlan_id); + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_VLAN_FLAGS)) { + if (pbrms->match_vlan_flags == PBR_VLAN_FLAGS_TAGGED) + vty_out(vty, " Match VLAN tagged frames\n"); + if (pbrms->match_vlan_flags == PBR_VLAN_FLAGS_UNTAGGED) + vty_out(vty, " Match VLAN untagged frames\n"); + if (pbrms->match_vlan_flags == PBR_VLAN_FLAGS_UNTAGGED_0) + vty_out(vty, " Match VLAN untagged or ID 0\n"); + } - if (pbrms->action_queue_id != PBR_MAP_UNDEFINED_QUEUE_ID) - vty_out(vty, " Set Queue ID %u\n", - pbrms->action_queue_id); + /* set actions */ + + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_SRC_IP)) + vty_out(vty, " Set SRC IP: %pSU\n", &pbrms->action_src); + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_DST_IP)) + vty_out(vty, " Set DST IP: %pSU\n", &pbrms->action_dst); + + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_SRC_PORT)) + vty_out(vty, " Set Src port: %u\n", + pbrms->action_src_port); + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_DST_PORT)) + vty_out(vty, " Set Dst port: %u\n", + pbrms->action_dst_port); + + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_DSCP)) + vty_out(vty, " Set DSCP: %u\n", (pbrms->action_dscp) >> 2); + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_ECN)) + vty_out(vty, " Set ECN: %u\n", pbrms->action_ecn); - if (pbrms->action_vlan_id != 0) + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_VLAN_ID)) vty_out(vty, " Set VLAN ID %u\n", pbrms->action_vlan_id); - if (pbrms->action_vlan_flags == PBR_MAP_STRIP_INNER_ANY) + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_VLAN_STRIP_INNER_ANY)) vty_out(vty, " Strip VLAN ID\n"); - if (pbrms->action_pcp) + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_PCP)) vty_out(vty, " Set PCP %u\n", pbrms->action_pcp); + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_QUEUE_ID)) + vty_out(vty, " Set Queue ID: %u\n", + pbrms->action_queue_id); + - if (pbrms->nhgrp_name) { + switch (pbrms->forwarding_type) { + case PBR_FT_UNSPEC: + vty_out(vty, " Nexthop-Group: Unknown Installed: no\n"); + break; + case PBR_FT_VRF_UNCHANGED: + vty_out(vty, " VRF Unchanged (use interface vrf)\n"); + break; + case PBR_FT_SETVRF: + assert(pbrms->vrf_name); + vty_out(vty, " VRF Lookup: %s\n", pbrms->vrf_name); + break; + case PBR_FT_NEXTHOP_GROUP: + assert(pbrms->nhgrp_name); vty_out(vty, " Nexthop-Group: %s\n", pbrms->nhgrp_name); if (detail) @@ -929,8 +1628,9 @@ static void vty_show_pbrms(struct vty *vty, pbr_nht_get_installed(pbrms->nhgrp_name) ? "yes" : "no", pbr_nht_get_table(pbrms->nhgrp_name)); - - } else if (pbrms->nhg) { + break; + case PBR_FT_NEXTHOP_SINGLE: + assert(pbrms->internal_nhg_name); vty_out(vty, " "); pbrms_nexthop_group_write_individual_nexthop(vty, pbrms); if (detail) @@ -945,13 +1645,7 @@ static void vty_show_pbrms(struct vty *vty, ? "yes" : "no", pbr_nht_get_table(pbrms->internal_nhg_name)); - - } else if (pbrms->vrf_unchanged) { - vty_out(vty, " VRF Unchanged (use interface vrf)\n"); - } else if (pbrms->vrf_lookup) { - vty_out(vty, " VRF Lookup: %s\n", pbrms->vrf_name); - } else { - vty_out(vty, " Nexthop-Group: Unknown Installed: no\n"); + break; } } @@ -973,12 +1667,22 @@ static void vty_json_pbrms(json_object *j, struct vty *vty, json_object_int_add(jpbrm, "sequenceNumber", pbrms->seqno); json_object_int_add(jpbrm, "ruleNumber", pbrms->ruleno); json_object_boolean_add(jpbrm, "vrfUnchanged", pbrms->vrf_unchanged); - json_object_boolean_add(jpbrm, "installed", - pbr_nht_get_installed(nhg_name)); + json_object_boolean_add(jpbrm, "installed", pbrms->installed); json_object_string_add(jpbrm, "installedReason", pbrms->reason ? rbuf : "Valid"); - if (nhg_name) { + switch (pbrms->forwarding_type) { + case PBR_FT_UNSPEC: + break; + case PBR_FT_VRF_UNCHANGED: + break; + case PBR_FT_SETVRF: + assert(pbrms->vrf_name); + json_object_string_add(jpbrm, "vrfName", pbrms->vrf_name); + break; + case PBR_FT_NEXTHOP_GROUP: + case PBR_FT_NEXTHOP_SINGLE: + assert(nhg_name); nexthop_group = json_object_new_object(); json_object_int_add(nexthop_group, "tableId", @@ -990,24 +1694,93 @@ static void vty_json_pbrms(json_object *j, struct vty *vty, pbrms->nhs_installed); json_object_object_add(jpbrm, "nexthopGroup", nexthop_group); + break; } - if (pbrms->vrf_lookup) - json_object_string_add(jpbrm, "vrfName", pbrms->vrf_name); - if (pbrms->src) + /* + * Match clauses + */ + + /* IP Header */ + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_IP_PROTOCOL)) + json_object_int_add(jpbrm, "matchIpProtocol", pbrms->ip_proto); + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_SRC_IP)) json_object_string_addf(jpbrm, "matchSrc", "%pFX", pbrms->src); - if (pbrms->dst) + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_DST_IP)) json_object_string_addf(jpbrm, "matchDst", "%pFX", pbrms->dst); - if (pbrms->mark) - json_object_int_add(jpbrm, "matchMark", pbrms->mark); - if (pbrms->dsfield & PBR_DSFIELD_DSCP) + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_SRC_PORT)) + json_object_int_add(jpbrm, "matchSrcPort", pbrms->src_prt); + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_DST_PORT)) + json_object_int_add(jpbrm, "matchDstPort", pbrms->dst_prt); + + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_DSCP)) json_object_int_add(jpbrm, "matchDscp", (pbrms->dsfield & PBR_DSFIELD_DSCP) >> 2); - if (pbrms->dsfield & PBR_DSFIELD_ECN) + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_ECN)) json_object_int_add(jpbrm, "matchEcn", pbrms->dsfield & PBR_DSFIELD_ECN); + /* L2 headers */ + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_PCP)) + json_object_int_add(jpbrm, "matchPcp", pbrms->match_pcp); + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_VLAN_ID)) + json_object_int_add(jpbrm, "matchVlanId", pbrms->match_vlan_id); + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_VLAN_FLAGS)) { + const char *p = "?"; + + if (pbrms->match_vlan_flags == PBR_VLAN_FLAGS_TAGGED) + p = "tagged"; + if (pbrms->match_vlan_flags == PBR_VLAN_FLAGS_UNTAGGED) + p = "untagged"; + if (pbrms->match_vlan_flags == PBR_VLAN_FLAGS_UNTAGGED_0) + p = "untagged-or-0"; + + json_object_string_addf(jpbrm, "matchVlanFlags", "%s", p); + } + + /* meta */ + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_FWMARK)) + json_object_int_add(jpbrm, "matchMark", pbrms->mark); + + /* + * action clauses + */ + + /* IP header fields */ + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_SRC_IP)) + json_object_string_addf(jpbrm, "actionSetSrcIpAddr", "%pSU", + &pbrms->action_src); + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_DST_IP)) + json_object_string_addf(jpbrm, "actionSetDstIpAddr", "%pSU", + &pbrms->action_dst); + + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_SRC_PORT)) + json_object_int_add(jpbrm, "actionSetSrcPort", + pbrms->action_src_port); + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_DST_PORT)) + json_object_int_add(jpbrm, "actionSetDstPort", + pbrms->action_dst_port); + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_DSCP)) + json_object_int_add(jpbrm, "actionSetDscp", + pbrms->action_dscp >> 2); + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_ECN)) + json_object_int_add(jpbrm, "actionSetEcn", pbrms->action_ecn); + + /* L2 header fields */ + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_VLAN_STRIP_INNER_ANY)) + json_object_boolean_true_add(jpbrm, "actionVlanStripInnerAny"); + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_VLAN_ID)) + json_object_int_add(jpbrm, "actionSetVlanId", + pbrms->action_vlan_id); + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_PCP)) + json_object_int_add(jpbrm, "actionSetPcp", pbrms->action_pcp); + + /* meta */ + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_QUEUE_ID)) + json_object_int_add(jpbrm, "actionSetQueueId", + pbrms->action_queue_id); + json_object_array_add(j, jpbrm); } @@ -1044,7 +1817,7 @@ static void vty_json_pbr_map(json_object *j, struct vty *vty, DEFPY (show_pbr_map, show_pbr_map_cmd, - "show pbr map [NAME$name] [detail$detail|json$json]", + "show pbr map [NAME$name] [detail$detail] [json$json]", SHOW_STR PBR_STR "PBR Map\n" @@ -1273,60 +2046,99 @@ static int pbr_vty_map_config_write_sequence(struct vty *vty, { vty_out(vty, "pbr-map %s seq %u\n", pbrm->name, pbrms->seqno); - if (pbrms->src) + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_IP_PROTOCOL)) { + struct protoent *p; + + p = getprotobynumber(pbrms->ip_proto); + vty_out(vty, " match ip-protocol %s\n", p->p_name); + } + + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_SRC_IP)) vty_out(vty, " match src-ip %pFX\n", pbrms->src); - if (pbrms->dst) + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_DST_IP)) vty_out(vty, " match dst-ip %pFX\n", pbrms->dst); - if (pbrms->src_prt) + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_SRC_PORT)) vty_out(vty, " match src-port %u\n", pbrms->src_prt); - if (pbrms->dst_prt) + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_DST_PORT)) vty_out(vty, " match dst-port %u\n", pbrms->dst_prt); - if (pbrms->ip_proto) { - struct protoent *p; - - p = getprotobynumber(pbrms->ip_proto); - vty_out(vty, " match ip-protocol %s\n", p->p_name); - } - - if (pbrms->dsfield & PBR_DSFIELD_DSCP) + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_DSCP)) vty_out(vty, " match dscp %u\n", (pbrms->dsfield & PBR_DSFIELD_DSCP) >> 2); - if (pbrms->dsfield & PBR_DSFIELD_ECN) + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_ECN)) vty_out(vty, " match ecn %u\n", pbrms->dsfield & PBR_DSFIELD_ECN); - if (pbrms->mark) - vty_out(vty, " match mark %u\n", pbrms->mark); - + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_PCP)) + vty_out(vty, " match pcp %d\n", pbrms->match_pcp); + + /* L2 headers */ + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_VLAN_ID)) + vty_out(vty, " match vlan %u\n", pbrms->match_vlan_id); + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_VLAN_FLAGS)) { + if (pbrms->match_vlan_flags == PBR_VLAN_FLAGS_TAGGED) + vty_out(vty, " match vlan tagged\n"); + if (pbrms->match_vlan_flags == PBR_VLAN_FLAGS_UNTAGGED) + vty_out(vty, " match vlan untagged\n"); + if (pbrms->match_vlan_flags == PBR_VLAN_FLAGS_UNTAGGED_0) + vty_out(vty, " match vlan untagged-or-zero\n"); + } - if (pbrms->action_queue_id != PBR_MAP_UNDEFINED_QUEUE_ID) - vty_out(vty, " set queue-id %d\n", pbrms->action_queue_id); + /* meta */ + if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_FWMARK)) + vty_out(vty, " match mark %u\n", pbrms->mark); - if (pbrms->action_pcp) - vty_out(vty, " set pcp %d\n", pbrms->action_pcp); + /* + * action clauses + */ - if (pbrms->action_vlan_id) + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_SRC_IP)) + vty_out(vty, " set src-ip %pSU\n", &pbrms->action_src); + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_DST_IP)) + vty_out(vty, " set dst-ip %pSU\n", &pbrms->action_dst); + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_SRC_PORT)) + vty_out(vty, " set src-port %d\n", pbrms->action_src_port); + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_DST_PORT)) + vty_out(vty, " set dst-port %d\n", pbrms->action_dst_port); + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_DSCP)) + vty_out(vty, " set dscp %u\n", (pbrms->action_dscp) >> 2); + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_ECN)) + vty_out(vty, " set ecn %u\n", pbrms->action_ecn); + + /* L2 header fields */ + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_VLAN_STRIP_INNER_ANY)) + vty_out(vty, " strip vlan any\n"); + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_VLAN_ID)) vty_out(vty, " set vlan %u\n", pbrms->action_vlan_id); + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_PCP)) + vty_out(vty, " set pcp %d\n", pbrms->action_pcp); - if (pbrms->action_vlan_flags == PBR_MAP_STRIP_INNER_ANY) - vty_out(vty, " strip vlan any\n"); + /* meta */ + if (CHECK_FLAG(pbrms->action_bm, PBR_ACTION_QUEUE_ID)) + vty_out(vty, " set queue-id %d\n", pbrms->action_queue_id); - if (pbrms->vrf_unchanged) + switch (pbrms->forwarding_type) { + case PBR_FT_UNSPEC: + break; + case PBR_FT_VRF_UNCHANGED: vty_out(vty, " set vrf unchanged\n"); - - if (pbrms->vrf_lookup) + break; + case PBR_FT_SETVRF: + assert(pbrms->vrf_name); vty_out(vty, " set vrf %s\n", pbrms->vrf_name); - - if (pbrms->nhgrp_name) + break; + case PBR_FT_NEXTHOP_GROUP: + assert(pbrms->nhgrp_name); vty_out(vty, " set nexthop-group %s\n", pbrms->nhgrp_name); - - if (pbrms->nhg) { + break; + case PBR_FT_NEXTHOP_SINGLE: + assert(pbrms->nhg); vty_out(vty, " set "); pbrms_nexthop_group_write_individual_nexthop(vty, pbrms); + break; } vty_out(vty, "exit\n"); @@ -1394,6 +2206,7 @@ void pbr_vty_init(void) install_element(CONFIG_NODE, &pbr_set_table_range_cmd); install_element(CONFIG_NODE, &no_pbr_set_table_range_cmd); install_element(INTERFACE_NODE, &pbr_policy_cmd); + install_element(PBRMAP_NODE, &pbr_map_match_ip_proto_cmd); install_element(PBRMAP_NODE, &pbr_map_match_src_port_cmd); install_element(PBRMAP_NODE, &pbr_map_match_dst_port_cmd); @@ -1401,11 +2214,22 @@ void pbr_vty_init(void) install_element(PBRMAP_NODE, &pbr_map_match_dst_cmd); install_element(PBRMAP_NODE, &pbr_map_match_dscp_cmd); install_element(PBRMAP_NODE, &pbr_map_match_ecn_cmd); + install_element(PBRMAP_NODE, &pbr_map_match_vlan_id_cmd); + install_element(PBRMAP_NODE, &pbr_map_match_vlan_tag_cmd); + install_element(PBRMAP_NODE, &pbr_map_match_pcp_cmd); install_element(PBRMAP_NODE, &pbr_map_match_mark_cmd); + install_element(PBRMAP_NODE, &pbr_map_action_queue_id_cmd); install_element(PBRMAP_NODE, &pbr_map_action_strip_vlan_cmd); install_element(PBRMAP_NODE, &pbr_map_action_vlan_id_cmd); install_element(PBRMAP_NODE, &pbr_map_action_pcp_cmd); + install_element(PBRMAP_NODE, &pbr_map_action_src_cmd); + install_element(PBRMAP_NODE, &pbr_map_action_dst_cmd); + install_element(PBRMAP_NODE, &pbr_map_action_dscp_cmd); + install_element(PBRMAP_NODE, &pbr_map_action_ecn_cmd); + install_element(PBRMAP_NODE, &pbr_map_action_src_port_cmd); + install_element(PBRMAP_NODE, &pbr_map_action_dst_port_cmd); + install_element(PBRMAP_NODE, &pbr_map_nexthop_group_cmd); install_element(PBRMAP_NODE, &no_pbr_map_nexthop_group_cmd); install_element(PBRMAP_NODE, &pbr_map_nexthop_cmd); diff --git a/pbrd/pbr_zebra.c b/pbrd/pbr_zebra.c index 097c9f2964..dd15beaff4 100644 --- a/pbrd/pbr_zebra.c +++ b/pbrd/pbr_zebra.c @@ -3,6 +3,9 @@ * Zebra connect code. * Copyright (C) 2018 Cumulus Networks, Inc. * Donald Sharp + * Portions: + * Copyright (c) 2021 The MITRE Corporation. + * Copyright (c) 2023 LabN Consulting, L.L.C. */ #include <zebra.h> @@ -20,6 +23,7 @@ #include "log.h" #include "nexthop.h" #include "nexthop_group.h" +#include "pbr.h" #include "pbr_nht.h" #include "pbr_map.h" @@ -125,29 +129,6 @@ int pbr_ifp_down(struct interface *ifp) return 0; } -static int interface_vrf_update(ZAPI_CALLBACK_ARGS) -{ - struct interface *ifp; - vrf_id_t new_vrf_id; - - ifp = zebra_interface_vrf_update_read(zclient->ibuf, vrf_id, - &new_vrf_id); - - if (!ifp) { - DEBUGD(&pbr_dbg_zebra, "%s: VRF change interface not found", - __func__); - - return 0; - } - - DEBUGD(&pbr_dbg_zebra, "%s: %s VRF change %u -> %u", __func__, - ifp->name, vrf_id, new_vrf_id); - - if_update_to_new_vrf(ifp, new_vrf_id); - - return 0; -} - static int route_notify_owner(ZAPI_CALLBACK_ARGS) { struct prefix p; @@ -197,7 +178,7 @@ static int rule_notify_owner(ZAPI_CALLBACK_ARGS) enum zapi_rule_notify_owner note; struct pbr_map_sequence *pbrms; struct pbr_map_interface *pmi; - char ifname[INTERFACE_NAMSIZ + 1]; + char ifname[IFNAMSIZ + 1]; uint64_t installed; if (!zapi_rule_notify_decode(zclient->ibuf, &seqno, &priority, &unique, @@ -241,6 +222,8 @@ static int rule_notify_owner(ZAPI_CALLBACK_ARGS) static void zebra_connected(struct zclient *zclient) { DEBUGD(&pbr_dbg_zebra, "%s: Registering for fun and profit", __func__); + + zebra_route_notify_send(ZEBRA_ROUTE_NOTIFY_REQUEST, zclient, true); zclient_send_reg_requests(zclient, VRF_DEFAULT); } @@ -383,38 +366,30 @@ void route_delete(struct pbr_nexthop_group_cache *pnhgc, afi_t afi) } } -static int pbr_zebra_nexthop_update(ZAPI_CALLBACK_ARGS) +static void pbr_zebra_nexthop_update(struct vrf *vrf, struct prefix *matched, + struct zapi_route *nhr) { - struct zapi_route nhr; - struct prefix matched; uint32_t i; - if (!zapi_nexthop_update_decode(zclient->ibuf, &matched, &nhr)) { - zlog_err("Failure to decode Nexthop update message"); - return 0; - } - if (DEBUG_MODE_CHECK(&pbr_dbg_zebra, DEBUG_MODE_ALL)) { - DEBUGD(&pbr_dbg_zebra, "%s: Received Nexthop update: %pFX against %pFX", - __func__, &matched, &nhr.prefix); + __func__, matched, &nhr->prefix); DEBUGD(&pbr_dbg_zebra, "%s: (Nexthops(%u)", __func__, - nhr.nexthop_num); + nhr->nexthop_num); - for (i = 0; i < nhr.nexthop_num; i++) { + for (i = 0; i < nhr->nexthop_num; i++) { DEBUGD(&pbr_dbg_zebra, "%s: Type: %d: vrf: %d, ifindex: %d gate: %pI4", - __func__, nhr.nexthops[i].type, - nhr.nexthops[i].vrf_id, nhr.nexthops[i].ifindex, - &nhr.nexthops[i].gate.ipv4); + __func__, nhr->nexthops[i].type, + nhr->nexthops[i].vrf_id, nhr->nexthops[i].ifindex, + &nhr->nexthops[i].gate.ipv4); } } - nhr.prefix = matched; - pbr_nht_nexthop_update(&nhr); - return 1; + nhr->prefix = *matched; + pbr_nht_nexthop_update(nhr); } extern struct zebra_privs_t pbr_privs; @@ -422,21 +397,28 @@ extern struct zebra_privs_t pbr_privs; static zclient_handler *const pbr_handlers[] = { [ZEBRA_INTERFACE_ADDRESS_ADD] = interface_address_add, [ZEBRA_INTERFACE_ADDRESS_DELETE] = interface_address_delete, - [ZEBRA_INTERFACE_VRF_UPDATE] = interface_vrf_update, [ZEBRA_ROUTE_NOTIFY_OWNER] = route_notify_owner, [ZEBRA_RULE_NOTIFY_OWNER] = rule_notify_owner, - [ZEBRA_NEXTHOP_UPDATE] = pbr_zebra_nexthop_update, }; void pbr_zebra_init(void) { - struct zclient_options opt = { .receive_notify = true }; - - zclient = zclient_new(master, &opt, pbr_handlers, + zclient = zclient_new(master, &zclient_options_default, pbr_handlers, array_size(pbr_handlers)); zclient_init(zclient, ZEBRA_ROUTE_PBR, 0, &pbr_privs); zclient->zebra_connected = zebra_connected; + zclient->nexthop_update = pbr_zebra_nexthop_update; +} + +void pbr_zebra_destroy(void) +{ + if (zclient == NULL) + return; + + zclient_stop(zclient); + zclient_free(zclient); + zclient = NULL; } void pbr_send_rnh(struct nexthop *nhop, bool reg) @@ -479,27 +461,9 @@ void pbr_send_rnh(struct nexthop *nhop, bool reg) } } -static void pbr_encode_pbr_map_sequence_prefix(struct stream *s, - struct prefix *p, - unsigned char family) -{ - struct prefix any; - if (!p) { - memset(&any, 0, sizeof(any)); - any.family = family; - p = &any; - } - - stream_putc(s, p->family); - stream_putc(s, p->prefixlen); - stream_put(s, &p->u.prefix, prefix_blen(p)); -} - -static void -pbr_encode_pbr_map_sequence_vrf(struct stream *s, - const struct pbr_map_sequence *pbrms, - const struct interface *ifp) +static uint32_t pbr_map_sequence_vrf(const struct pbr_map_sequence *pbrms, + const struct interface *ifp) { struct pbr_vrf *pbr_vrf; @@ -510,46 +474,116 @@ pbr_encode_pbr_map_sequence_vrf(struct stream *s, if (!pbr_vrf) { DEBUGD(&pbr_dbg_zebra, "%s: VRF not found", __func__); - return; + return 0; } - stream_putl(s, pbr_vrf->vrf->data.l.table_id); + return pbr_vrf->vrf->data.l.table_id; + } -static void pbr_encode_pbr_map_sequence(struct stream *s, +/* + * 230716 gpz note: it would be worthwhile for pbrd to represent + * its rules internally using the lib/pbr.h structures to help + * move toward a more common structure across pbrd, bgpd, and zebra. + */ +static bool pbr_encode_pbr_map_sequence(struct stream *s, struct pbr_map_sequence *pbrms, struct interface *ifp) { - unsigned char family; + struct pbr_rule r; + uint8_t family; + + /* + * Opportunistic address family field is set when any of the IP + * address match/set fields is set, or when a NH/NHG is resolved. + * The value is needed by zebra for the underlying netlink + * messaging, particularly in delete operations, because it + * selects the rule database (IPv4 vs. IPv6). + * + * Historically the value has been encoded into any unused + * "match src/dst address" fields and picked off in zebra. + */ family = AF_INET; if (pbrms->family) family = pbrms->family; - stream_putl(s, pbrms->seqno); - stream_putl(s, pbrms->ruleno); - stream_putl(s, pbrms->unique); - stream_putc(s, pbrms->ip_proto); /* The ip_proto */ - pbr_encode_pbr_map_sequence_prefix(s, pbrms->src, family); - stream_putw(s, pbrms->src_prt); - pbr_encode_pbr_map_sequence_prefix(s, pbrms->dst, family); - stream_putw(s, pbrms->dst_prt); - stream_putc(s, pbrms->dsfield); - stream_putl(s, pbrms->mark); + if (pbrms->src) + assert(family == pbrms->src->family); + if (pbrms->dst) + assert(family == pbrms->dst->family); - stream_putl(s, pbrms->action_queue_id); + /* + * Convert struct pbr_map_sequence to canonical form + */ + memset(&r, 0, sizeof(r)); + r.seq = pbrms->seqno; + r.priority = pbrms->ruleno; + r.unique = pbrms->unique; + + r.family = pbrms->family; - stream_putw(s, pbrms->action_vlan_id); - stream_putw(s, pbrms->action_vlan_flags); - stream_putw(s, pbrms->action_pcp); + /* filter */ + r.filter.filter_bm = pbrms->filter_bm; + if (pbrms->src) + r.filter.src_ip = *pbrms->src; + else + r.filter.src_ip.family = family; + if (pbrms->dst) + r.filter.dst_ip = *pbrms->dst; + else + r.filter.dst_ip.family = family; + r.filter.src_port = pbrms->src_prt; + r.filter.dst_port = pbrms->dst_prt; + r.filter.pcp = pbrms->match_pcp; + r.filter.vlan_id = pbrms->match_vlan_id; + r.filter.vlan_flags = pbrms->match_vlan_flags; + r.filter.dsfield = pbrms->dsfield; + r.filter.fwmark = pbrms->mark; + r.filter.ip_proto = pbrms->ip_proto; + r.filter.filter_bm = pbrms->filter_bm; + + /* actions */ + + r.action.flags = pbrms->action_bm; + + SET_FLAG(r.action.flags, PBR_ACTION_TABLE); /* always valid */ + + /* + * if the user does not use the command "set vrf name unchanged" + * then pbr_encode_pbr_map_sequence_vrf will not be called + */ if (pbrms->vrf_unchanged || pbrms->vrf_lookup) - pbr_encode_pbr_map_sequence_vrf(s, pbrms, ifp); + r.action.table = pbr_map_sequence_vrf(pbrms, ifp); else if (pbrms->nhgrp_name) - stream_putl(s, pbr_nht_get_table(pbrms->nhgrp_name)); + r.action.table = pbr_nht_get_table(pbrms->nhgrp_name); else if (pbrms->nhg) - stream_putl(s, pbr_nht_get_table(pbrms->internal_nhg_name)); - stream_put(s, ifp->name, INTERFACE_NAMSIZ); + r.action.table = pbr_nht_get_table(pbrms->internal_nhg_name); + else { + /* Not valid for install without table */ + return false; + } + + r.action.queue_id = pbrms->action_queue_id; + + r.action.src_ip = pbrms->action_src; + r.action.dst_ip = pbrms->action_dst; + + r.action.src_port = pbrms->action_src_port; + r.action.dst_port = pbrms->action_dst_port; + + r.action.dscp = pbrms->action_dscp; + r.action.ecn = pbrms->action_ecn; + + r.action.pcp = pbrms->action_pcp; + r.action.vlan_id = pbrms->action_vlan_id; + + strlcpy(r.ifname, ifp->name, sizeof(r.ifname)); + + zapi_pbr_rule_encode(s, &r); + + return true; } bool pbr_send_pbr_map(struct pbr_map_sequence *pbrms, @@ -561,9 +595,6 @@ bool pbr_send_pbr_map(struct pbr_map_sequence *pbrms, is_installed &= pbrms->installed; - DEBUGD(&pbr_dbg_zebra, "%s: for %s %d(%" PRIu64 ")", __func__, - pbrm->name, install, is_installed); - /* * If we are installed and asked to do so again and the config * has not changed, just return. @@ -584,20 +615,17 @@ bool pbr_send_pbr_map(struct pbr_map_sequence *pbrms, install ? ZEBRA_RULE_ADD : ZEBRA_RULE_DELETE, VRF_DEFAULT); - /* - * We are sending one item at a time at the moment - */ - stream_putl(s, 1); - DEBUGD(&pbr_dbg_zebra, "%s: %s %s seq %u %d %s %u", __func__, install ? "Installing" : "Deleting", pbrm->name, pbrms->seqno, install, pmi->ifp->name, pmi->delete); - pbr_encode_pbr_map_sequence(s, pbrms, pmi->ifp); - - stream_putw_at(s, 0, stream_get_endp(s)); - - zclient_send_message(zclient); + if (pbr_encode_pbr_map_sequence(s, pbrms, pmi->ifp)) { + stream_putw_at(s, 0, stream_get_endp(s)); + zclient_send_message(zclient); + } else { + DEBUGD(&pbr_dbg_zebra, "%s: %s seq %u encode failed, skipped", + __func__, pbrm->name, pbrms->seqno); + } return true; } diff --git a/pbrd/pbr_zebra.h b/pbrd/pbr_zebra.h index ef844ef797..5cbb1fd682 100644 --- a/pbrd/pbr_zebra.h +++ b/pbrd/pbr_zebra.h @@ -14,6 +14,7 @@ struct pbr_interface { extern struct event_loop *master; extern void pbr_zebra_init(void); +extern void pbr_zebra_destroy(void); extern void route_add(struct pbr_nexthop_group_cache *pnhgc, struct nexthop_group nhg, afi_t install_afi); diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c index 94e8b874f7..262ce86c29 100644 --- a/pimd/pim6_cmd.c +++ b/pimd/pim6_cmd.c @@ -743,7 +743,7 @@ DEFPY (interface_ipv6_mld_query_max_response_time, IPV6_STR IFACE_MLD_STR IFACE_MLD_QUERY_MAX_RESPONSE_TIME_STR - "Query response value in milliseconds\n") + "Query response value in deci-seconds\n") { return gm_process_query_max_response_time_cmd(vty, qmrt_str); } diff --git a/pimd/pim6_main.c b/pimd/pim6_main.c index 1af4a17e5b..5ce6985c45 100644 --- a/pimd/pim6_main.c +++ b/pimd/pim6_main.c @@ -26,6 +26,7 @@ #include "pim_nb.h" #include "pim6_cmd.h" #include "pim6_mld.h" +#include "pim_zlookup.h" zebra_capabilities_t _caps_p[] = { ZCAP_SYS_ADMIN, @@ -189,11 +190,20 @@ int main(int argc, char **argv, char **envp) static void pim6_terminate(void) { + struct zclient *zclient; + pim_vrf_terminate(); pim_router_terminate(); prefix_list_reset(); access_list_reset(); + zclient = pim_zebra_zclient_get(); + if (zclient) { + zclient_stop(zclient); + zclient_free(zclient); + } + + zclient_lookup_free(); frr_fini(); } diff --git a/pimd/pim6_mld.c b/pimd/pim6_mld.c index aa39be63db..a39d182990 100644 --- a/pimd/pim6_mld.c +++ b/pimd/pim6_mld.c @@ -13,6 +13,7 @@ */ #include <zebra.h> +#include <netinet/icmp6.h> #include <netinet/ip6.h> #include "lib/memory.h" @@ -355,6 +356,7 @@ static const char *const gm_states[] = { static void gm_sg_update(struct gm_sg *sg, bool has_expired) { struct gm_if *gm_ifp = sg->iface; + struct pim_interface *pim_ifp = gm_ifp->ifp->info; enum gm_sg_state prev, desired; bool new_join; struct gm_sg *grp = NULL; @@ -404,9 +406,12 @@ static void gm_sg_update(struct gm_sg *sg, bool has_expired) gm_sg_timer_start(gm_ifp, sg, timers.expire_wait); EVENT_OFF(sg->t_sg_query); - sg->n_query = gm_ifp->cur_lmqc; sg->query_sbit = false; - gm_trigger_specific(sg); + /* Trigger the specific queries only for querier. */ + if (IPV6_ADDR_SAME(&gm_ifp->querier, &pim_ifp->ll_lowest)) { + sg->n_query = gm_ifp->cur_lmqc; + gm_trigger_specific(sg); + } } } prev = sg->state; @@ -1239,6 +1244,7 @@ static void gm_handle_q_groupsrc(struct gm_if *gm_ifp, for (i = 0; i < n_src; i++) { sg = gm_sg_find(gm_ifp, grp, srcs[i]); + GM_UPDATE_SG_STATE(sg); gm_sg_timer_start(gm_ifp, sg, timers->expire_wait); } } @@ -1313,6 +1319,7 @@ static void gm_handle_q_group(struct gm_if *gm_ifp, if (PIM_DEBUG_GM_TRACE) zlog_debug(log_ifp("*,%pPAs expiry timer starting"), &grp); + GM_UPDATE_SG_STATE(sg); gm_sg_timer_start(gm_ifp, sg, timers->expire_wait); sg = gm_sgs_next(gm_ifp->sgs, sg); @@ -1361,7 +1368,7 @@ static void gm_bump_querier(struct gm_if *gm_ifp) gm_ifp->n_startup = gm_ifp->cur_qrv; - event_execute(router->master, gm_t_query, gm_ifp, 0); + event_execute(router->master, gm_t_query, gm_ifp, 0, NULL); } static void gm_t_other_querier(struct event *t) @@ -1374,7 +1381,7 @@ static void gm_t_other_querier(struct event *t) gm_ifp->querier = pim_ifp->ll_lowest; gm_ifp->n_startup = gm_ifp->cur_qrv; - event_execute(router->master, gm_t_query, gm_ifp, 0); + event_execute(router->master, gm_t_query, gm_ifp, 0, NULL); } static void gm_handle_query(struct gm_if *gm_ifp, @@ -1924,7 +1931,6 @@ static void gm_t_gsq_pend(struct event *t) static void gm_trigger_specific(struct gm_sg *sg) { struct gm_if *gm_ifp = sg->iface; - struct pim_interface *pim_ifp = gm_ifp->ifp->info; struct gm_gsq_pending *pend_gsq, ref = {}; sg->n_query--; @@ -1933,8 +1939,20 @@ static void gm_trigger_specific(struct gm_sg *sg) gm_ifp->cur_query_intv_trig, &sg->t_sg_query); - if (!IPV6_ADDR_SAME(&gm_ifp->querier, &pim_ifp->ll_lowest)) - return; + /* As per RFC 2271, s6 p14: + * E.g. a router that starts as a Querier, receives a + * Done message for a group and then receives a Query from a router with + * a lower address (causing a transition to the Non-Querier state) + * continues to send multicast-address-specific queries for the group in + * question until it either receives a Report or its timer expires, at + * which time it starts performing the actions of a Non-Querier for this + * group. + */ + /* Therefore here we do not need to check if this router is querier or + * not. This is called only for querier, hence it will work even if the + * router transitions from querier to non-querier. + */ + if (gm_ifp->pim->gm_socket == -1) return; @@ -2250,7 +2268,7 @@ static void gm_update_ll(struct interface *ifp) return; gm_ifp->n_startup = gm_ifp->cur_qrv; - event_execute(router->master, gm_t_query, gm_ifp, 0); + event_execute(router->master, gm_t_query, gm_ifp, 0, NULL); } void gm_ifp_update(struct interface *ifp) diff --git a/pimd/pim6_mld.h b/pimd/pim6_mld.h index 7634fb2ec4..183ab2fc50 100644 --- a/pimd/pim6_mld.h +++ b/pimd/pim6_mld.h @@ -36,6 +36,21 @@ enum gm_sg_state { GM_SG_NOPRUNE_EXPIRING, }; +/* If the timer gm_t_sg_expire is started without a leave message being received, + * the sg->state should be moved to expiring states. + * When the timer expires, we do not expect the state to be in join state. + * If a JOIN message is received while the timer is running, + * the state will be moved to JOIN and this timer will be switched off. + * Hence the below state transition is done. + */ +#define GM_UPDATE_SG_STATE(sg) \ + do { \ + if (sg->state == GM_SG_JOIN) \ + sg->state = GM_SG_JOIN_EXPIRING; \ + else if (sg->state == GM_SG_NOPRUNE) \ + sg->state = GM_SG_NOPRUNE_EXPIRING; \ + } while (0) + static inline bool gm_sg_state_want_join(enum gm_sg_state state) { return state != GM_SG_NOINFO && state != GM_SG_PRUNE; diff --git a/pimd/pim_addr.h b/pimd/pim_addr.h index 94c63bbccc..ecba739a5a 100644 --- a/pimd/pim_addr.h +++ b/pimd/pim_addr.h @@ -33,13 +33,13 @@ typedef struct in_addr pim_addr; #define PIM_ADDR_FUNCNAME(name) ipv4_##name union pimprefixptr { - prefixtype(pimprefixptr, struct prefix, p) - prefixtype(pimprefixptr, struct prefix_ipv4, p4) + uniontype(pimprefixptr, struct prefix, p) + uniontype(pimprefixptr, struct prefix_ipv4, p4) } TRANSPARENT_UNION; union pimprefixconstptr { - prefixtype(pimprefixconstptr, const struct prefix, p) - prefixtype(pimprefixconstptr, const struct prefix_ipv4, p4) + uniontype(pimprefixconstptr, const struct prefix, p) + uniontype(pimprefixconstptr, const struct prefix_ipv4, p4) } TRANSPARENT_UNION; #else @@ -63,13 +63,13 @@ typedef struct in6_addr pim_addr; #define PIM_ADDR_FUNCNAME(name) ipv6_##name union pimprefixptr { - prefixtype(pimprefixptr, struct prefix, p) - prefixtype(pimprefixptr, struct prefix_ipv6, p6) + uniontype(pimprefixptr, struct prefix, p) + uniontype(pimprefixptr, struct prefix_ipv6, p6) } TRANSPARENT_UNION; union pimprefixconstptr { - prefixtype(pimprefixconstptr, const struct prefix, p) - prefixtype(pimprefixconstptr, const struct prefix_ipv6, p6) + uniontype(pimprefixconstptr, const struct prefix, p) + uniontype(pimprefixconstptr, const struct prefix_ipv6, p6) } TRANSPARENT_UNION; #endif diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 2e90cf9053..628a445945 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -78,7 +78,7 @@ static struct vrf *pim_cmd_lookup_vrf(struct vty *vty, struct cmd_token *argv[], if (!vrf) { if (uj) - vty_json_empty(vty); + vty_json_empty(vty, NULL); else vty_out(vty, "Specified VRF: %s does not exist\n", argv[*idx]->arg); diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 5b905a9536..59addd48c0 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -6,6 +6,7 @@ */ #include <zebra.h> +#include <sys/ioctl.h> #include "lib/json.h" #include "command.h" @@ -68,7 +69,7 @@ const char *pim_cli_get_vrf_name(struct vty *vty) return NULL; } - return yang_dnode_get_string(vrf_node, "./name"); + return yang_dnode_get_string(vrf_node, "name"); } int pim_process_join_prune_cmd(struct vty *vty, const char *jpi_str) @@ -1059,8 +1060,8 @@ void pim_show_state(struct pim_instance *pim, struct vty *vty, frr_each (rb_pim_oil, &pim->channel_oil_head, c_oil) { char src_str[PIM_ADDRSTRLEN]; char grp_str[PIM_ADDRSTRLEN]; - char in_ifname[INTERFACE_NAMSIZ + 1]; - char out_ifname[INTERFACE_NAMSIZ + 1]; + char in_ifname[IFNAMSIZ + 1]; + char out_ifname[IFNAMSIZ + 1]; int oif_vif_index; struct interface *ifp_in; bool isRpt; @@ -1078,7 +1079,7 @@ void pim_show_state(struct pim_instance *pim, struct vty *vty, oil_mcastgrp(c_oil)); snprintfrr(src_str, sizeof(src_str), "%pPAs", oil_origin(c_oil)); - ifp_in = pim_if_find_by_vif_index(pim, *oil_parent(c_oil)); + ifp_in = pim_if_find_by_vif_index(pim, *oil_incoming_vif(c_oil)); if (ifp_in) strlcpy(in_ifname, ifp_in->name, sizeof(in_ifname)); @@ -1148,13 +1149,18 @@ void pim_show_state(struct pim_instance *pim, struct vty *vty, "wrongInterface", c_oil->cc.wrong_if); } - } + } else #if PIM_IPV == 4 - else vty_out(vty, "%-6d %-15pPAs %-15pPAs %-3s %-16s ", c_oil->installed, oil_origin(c_oil), oil_mcastgrp(c_oil), isRpt ? "y" : "n", in_ifname); +#else + /* Add a new row for c_oil with no OIF */ + ttable_add_row(tt, "%d|%pPAs|%pPAs|%s|%s|%c", + c_oil->installed, oil_origin(c_oil), + oil_mcastgrp(c_oil), isRpt ? "y" : "n", + in_ifname, ' '); #endif for (oif_vif_index = 0; oif_vif_index < MAXVIFS; @@ -1225,6 +1231,13 @@ void pim_show_state(struct pim_instance *pim, struct vty *vty, #if PIM_IPV == 4 vty_out(vty, "%s%s", out_ifname, flag); #else + /* OIF found. + * Delete the existing row for c_oil, + * with no OIF. + * Add a new row for c_oil with OIF and + * flag. + */ + ttable_del_row(tt, tt->nrows - 1); ttable_add_row( tt, "%d|%pPAs|%pPAs|%s|%s|%s%s", c_oil->installed, @@ -2832,6 +2845,8 @@ static int pim_print_json_pnc_cache_walkcb(struct hash_bucket *backet, json_object *json_row = NULL; json_object *json_ifp = NULL; json_object *json_arr = NULL; + struct pim_interface *pim_ifp = NULL; + bool pim_enable = false; for (nh_node = pnc->nexthop; nh_node; nh_node = nh_node->next) { first_ifindex = nh_node->ifindex; @@ -2851,6 +2866,14 @@ static int pim_print_json_pnc_cache_walkcb(struct hash_bucket *backet, json_ifp = json_object_new_object(); json_object_string_add(json_ifp, "interface", ifp ? ifp->name : "NULL"); + + if (ifp) + pim_ifp = ifp->info; + + if (pim_ifp && pim_ifp->pim_enable) + pim_enable = true; + + json_object_boolean_add(json_ifp, "pimEnabled", pim_enable); #if PIM_IPV == 4 json_object_string_addf(json_ifp, "nexthop", "%pI4", &nh_node->gate.ipv4); @@ -2871,7 +2894,6 @@ int pim_show_nexthop_lookup_cmd_helper(const char *vrf, struct vty *vty, struct prefix grp; struct pim_nexthop nexthop; struct vrf *v; - char grp_str[PREFIX_STRLEN]; v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); @@ -2907,9 +2929,7 @@ int pim_show_nexthop_lookup_cmd_helper(const char *vrf, struct vty *vty, return CMD_SUCCESS; } - pim_addr_dump("<grp?>", &grp, grp_str, sizeof(grp_str)); - - vty_out(vty, "Group %s --- Nexthop %pPAs Interface %s\n", grp_str, + vty_out(vty, "Group %pFXh --- Nexthop %pPAs Interface %s\n", &grp, &nexthop.mrib_nexthop_addr, nexthop.interface->name); return CMD_SUCCESS; @@ -3643,8 +3663,8 @@ void show_mroute(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, int first; char grp_str[PIM_ADDRSTRLEN]; char src_str[PIM_ADDRSTRLEN]; - char in_ifname[INTERFACE_NAMSIZ + 1]; - char out_ifname[INTERFACE_NAMSIZ + 1]; + char in_ifname[IFNAMSIZ + 1]; + char out_ifname[IFNAMSIZ + 1]; int oif_vif_index; struct interface *ifp_in; char proto[100]; @@ -3704,7 +3724,7 @@ void show_mroute(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, if (pim_channel_oil_empty(c_oil)) strlcat(state_str, "P", sizeof(state_str)); - ifp_in = pim_if_find_by_vif_index(pim, *oil_parent(c_oil)); + ifp_in = pim_if_find_by_vif_index(pim, *oil_incoming_vif(c_oil)); if (ifp_in) strlcpy(in_ifname, ifp_in->name, sizeof(in_ifname)); @@ -3770,7 +3790,7 @@ void show_mroute(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, if (c_oil->oif_flags[oif_vif_index] & PIM_OIF_FLAG_MUTE) continue; - if (*oil_parent(c_oil) == oif_vif_index && + if (*oil_incoming_vif(c_oil) == oif_vif_index && !pim_mroute_allow_iif_in_oil(c_oil, oif_vif_index)) continue; @@ -3821,7 +3841,7 @@ void show_mroute(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, "inboundInterface", in_ifname); json_object_int_add(json_ifp_out, "iVifI", - *oil_parent(c_oil)); + *oil_incoming_vif(c_oil)); json_object_string_add(json_ifp_out, "outboundInterface", out_ifname); @@ -3970,9 +3990,9 @@ void show_mroute(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, json_object_string_add(json_ifp_out, "inboundInterface", in_ifname); - json_object_int_add( - json_ifp_out, "iVifI", - *oil_parent(&s_route->c_oil)); + json_object_int_add(json_ifp_out, "iVifI", + *oil_incoming_vif( + &s_route->c_oil)); json_object_string_add(json_ifp_out, "outboundInterface", out_ifname); diff --git a/pimd/pim_hello.c b/pimd/pim_hello.c index 978607d147..a0661ef36b 100644 --- a/pimd/pim_hello.c +++ b/pimd/pim_hello.c @@ -440,7 +440,7 @@ int pim_hello_build_tlv(struct interface *ifp, uint8_t *tlv_buf, } /* Secondary Address List */ - if (ifp->connected->count) { + if (if_connected_count(ifp->connected)) { curr = pim_tlv_append_addrlist_ucast(curr, pastend, ifp, PIM_AF); if (!curr) { diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index b1beb45630..5d7132c09a 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -40,9 +40,8 @@ #include "pim6_mld.h" -#if PIM_IPV == 4 -static void pim_if_igmp_join_del_all(struct interface *ifp); -#endif +static void pim_if_gm_join_del_all(struct interface *ifp); + static int gm_join_sock(const char *ifname, ifindex_t ifindex, pim_addr group_addr, pim_addr source_addr, struct pim_interface *pim_ifp); @@ -189,11 +188,9 @@ void pim_if_delete(struct interface *ifp) assert(pim_ifp); pim_ifp->pim->mcast_if_count--; -#if PIM_IPV == 4 if (pim_ifp->gm_join_list) { - pim_if_igmp_join_del_all(ifp); + pim_if_gm_join_del_all(ifp); } -#endif pim_ifchannel_delete_all(ifp); #if PIM_IPV == 4 @@ -382,7 +379,7 @@ static int pim_sec_addr_update(struct interface *ifp) sec_addr->flags |= PIM_SEC_ADDRF_STALE; } - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { + frr_each (if_connected, ifp->connected, ifc) { pim_addr addr = pim_addr_from_prefix(ifc->address); if (pim_addr_is_any(addr)) @@ -726,13 +723,12 @@ void pim_if_addr_del(struct connected *ifc, int force_prim_as_any) if (pim_ifp && (!IPV6_ADDR_CMP(&ifc->address->u.prefix6, &pim_ifp->ll_lowest) || !IPV6_ADDR_CMP(&ifc->address->u.prefix6, &pim_ifp->ll_highest))) { - struct listnode *cnode; struct connected *cc; memset(&pim_ifp->ll_lowest, 0xff, sizeof(pim_ifp->ll_lowest)); memset(&pim_ifp->ll_highest, 0, sizeof(pim_ifp->ll_highest)); - for (ALL_LIST_ELEMENTS_RO(ifc->ifp->connected, cnode, cc)) { + frr_each (if_connected, ifc->ifp->connected, cc) { if (!IN6_IS_ADDR_LINKLOCAL(&cc->address->u.prefix6) && !IN6_IS_ADDR_LOOPBACK(&cc->address->u.prefix6)) continue; @@ -768,8 +764,6 @@ void pim_if_addr_del(struct connected *ifc, int force_prim_as_any) void pim_if_addr_add_all(struct interface *ifp) { struct connected *ifc; - struct listnode *node; - struct listnode *nextnode; int v4_addrs = 0; int v6_addrs = 0; struct pim_interface *pim_ifp = ifp->info; @@ -780,7 +774,7 @@ void pim_if_addr_add_all(struct interface *ifp) if (!pim_ifp) return; - for (ALL_LIST_ELEMENTS(ifp->connected, node, nextnode, ifc)) { + frr_each (if_connected, ifp->connected, ifc) { struct prefix *p = ifc->address; if (p->family != AF_INET) @@ -816,8 +810,6 @@ void pim_if_addr_add_all(struct interface *ifp) void pim_if_addr_del_all(struct interface *ifp) { struct connected *ifc; - struct listnode *node; - struct listnode *nextnode; struct pim_instance *pim; pim = ifp->vrf->info; @@ -828,7 +820,7 @@ void pim_if_addr_del_all(struct interface *ifp) if (!ifp->info) return; - for (ALL_LIST_ELEMENTS(ifp->connected, node, nextnode, ifc)) { + frr_each_safe (if_connected, ifp->connected, ifc) { struct prefix *p = ifc->address; if (p->family != PIM_AF) @@ -844,14 +836,12 @@ void pim_if_addr_del_all(struct interface *ifp) void pim_if_addr_del_all_igmp(struct interface *ifp) { struct connected *ifc; - struct listnode *node; - struct listnode *nextnode; /* PIM/IGMP enabled ? */ if (!ifp->info) return; - for (ALL_LIST_ELEMENTS(ifp->connected, node, nextnode, ifc)) { + frr_each_safe (if_connected, ifp->connected, ifc) { struct prefix *p = ifc->address; if (p->family != AF_INET) @@ -864,7 +854,6 @@ void pim_if_addr_del_all_igmp(struct interface *ifp) pim_addr pim_find_primary_addr(struct interface *ifp) { struct connected *ifc; - struct listnode *node; struct pim_interface *pim_ifp = ifp->info; if (pim_ifp && !pim_addr_is_any(pim_ifp->update_source)) @@ -876,7 +865,7 @@ pim_addr pim_find_primary_addr(struct interface *ifp) pim_addr best_addr = PIMADDR_ANY; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { + frr_each (if_connected, ifp->connected, ifc) { pim_addr addr; if (ifc->address->family != AF_INET6) @@ -893,8 +882,9 @@ pim_addr pim_find_primary_addr(struct interface *ifp) #else int v4_addrs = 0; int v6_addrs = 0; + struct connected *promote_ifc = NULL; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { + frr_each (if_connected, ifp->connected, ifc) { switch (ifc->address->family) { case AF_INET: v4_addrs++; @@ -906,15 +896,24 @@ pim_addr pim_find_primary_addr(struct interface *ifp) continue; } - if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY)) + if (ifc->address->family != PIM_AF) continue; - if (ifc->address->family != PIM_AF) + if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY)) { + promote_ifc = ifc; continue; + } return pim_addr_from_prefix(ifc->address); } + + /* Promote the new primary address. */ + if (v4_addrs && promote_ifc) { + UNSET_FLAG(promote_ifc->flags, ZEBRA_IFA_SECONDARY); + return pim_addr_from_prefix(promote_ifc->address); + } + /* * If we have no v4_addrs and v6 is configured * We probably are using unnumbered @@ -1380,9 +1379,8 @@ int pim_if_gm_join_del(struct interface *ifp, pim_addr group_addr, return 0; } -#if PIM_IPV == 4 __attribute__((unused)) -static void pim_if_igmp_join_del_all(struct interface *ifp) +static void pim_if_gm_join_del_all(struct interface *ifp) { struct pim_interface *pim_ifp; struct listnode *node; @@ -1402,7 +1400,6 @@ static void pim_if_igmp_join_del_all(struct interface *ifp) for (ALL_LIST_ELEMENTS(pim_ifp->gm_join_list, node, nextnode, ij)) pim_if_gm_join_del(ifp, ij->group_addr, ij->source_addr); } -#endif /* PIM_IPV == 4 */ /* RFC 4601 @@ -1482,7 +1479,7 @@ void pim_if_update_assert_tracking_desired(struct interface *ifp) */ void pim_if_create_pimreg(struct pim_instance *pim) { - char pimreg_name[INTERFACE_NAMSIZ]; + char pimreg_name[IFNAMSIZ]; if (!pim->regiface) { if (pim->vrf->vrf_id == VRF_DEFAULT) @@ -1495,9 +1492,16 @@ void pim_if_create_pimreg(struct pim_instance *pim) pim->vrf->name); pim->regiface->ifindex = PIM_OIF_PIM_REGISTER_VIF; - if (!pim->regiface->info) - pim_if_new(pim->regiface, false, false, true, - false /*vxlan_term*/); + /* + * The pimreg interface might has been removed from + * kerenl with the VRF's deletion. It must be + * recreated, so delete the old one first. + */ + if (pim->regiface->info) + pim_if_delete(pim->regiface); + + pim_if_new(pim->regiface, false, false, true, + false /*vxlan_term*/); /* * On vrf moves we delete the interface if there @@ -1511,7 +1515,6 @@ void pim_if_create_pimreg(struct pim_instance *pim) struct prefix *pim_if_connected_to_source(struct interface *ifp, pim_addr src) { - struct listnode *cnode; struct connected *c; struct prefix p; @@ -1520,7 +1523,7 @@ struct prefix *pim_if_connected_to_source(struct interface *ifp, pim_addr src) pim_addr_to_prefix(&p, src); - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) { + frr_each (if_connected, ifp->connected, c) { if (c->address->family != PIM_AF) continue; if (prefix_match(c->address, &p)) @@ -1759,6 +1762,66 @@ void pim_iface_init(void) hook_register_prio(if_add, 0, pim_if_new_hook); hook_register_prio(if_del, 0, pim_if_delete_hook); - if_zapi_callbacks(pim_ifp_create, pim_ifp_up, pim_ifp_down, - pim_ifp_destroy); + hook_register_prio(if_real, 0, pim_ifp_create); + hook_register_prio(if_up, 0, pim_ifp_up); + hook_register_prio(if_down, 0, pim_ifp_down); + hook_register_prio(if_unreal, 0, pim_ifp_destroy); +} + +static void pim_if_membership_clear(struct interface *ifp) +{ + struct pim_interface *pim_ifp; + + pim_ifp = ifp->info; + assert(pim_ifp); + + if (pim_ifp->pim_enable && pim_ifp->gm_enable) + return; + + pim_ifchannel_membership_clear(ifp); +} + +void pim_pim_interface_delete(struct interface *ifp) +{ + struct pim_interface *pim_ifp = ifp->info; + + if (!pim_ifp) + return; + + pim_ifp->pim_enable = false; + + pim_if_membership_clear(ifp); + + /* + * pim_sock_delete() removes all neighbors from + * pim_ifp->pim_neighbor_list. + */ + pim_sock_delete(ifp, "pim unconfigured on interface"); + pim_upstream_nh_if_update(pim_ifp->pim, ifp); + + if (!pim_ifp->gm_enable) { + pim_if_addr_del_all(ifp); + pim_if_delete(ifp); + } +} + +void pim_gm_interface_delete(struct interface *ifp) +{ + struct pim_interface *pim_ifp = ifp->info; + + if (!pim_ifp) + return; + + pim_ifp->gm_enable = false; + + pim_if_membership_clear(ifp); + +#if PIM_IPV == 4 + igmp_sock_delete_all(ifp); +#else + gm_ifp_teardown(ifp); +#endif + + if (!pim_ifp->pim_enable) + pim_if_delete(ifp); } diff --git a/pimd/pim_iface.h b/pimd/pim_iface.h index 973840a753..0312f719d3 100644 --- a/pimd/pim_iface.h +++ b/pimd/pim_iface.h @@ -243,5 +243,7 @@ bool pim_if_is_vrf_device(struct interface *ifp); int pim_if_ifchannel_count(struct pim_interface *pim_ifp); void pim_iface_init(void); +void pim_pim_interface_delete(struct interface *ifp); +void pim_gm_interface_delete(struct interface *ifp); #endif /* PIM_IFACE_H */ diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c index bc6b84ff2c..da55189941 100644 --- a/pimd/pim_ifchannel.c +++ b/pimd/pim_ifchannel.c @@ -135,7 +135,7 @@ void pim_ifchannel_delete(struct pim_ifchannel *ch) * being inherited. So let's figure out what * needs to be done here */ - if (!pim_addr_is_any(ch->sg.src) && + if (!pim_addr_is_any(ch->sg.src) && ch->parent && pim_upstream_evaluate_join_desired_interface( ch->upstream, ch, ch->parent)) pim_channel_add_oif(ch->upstream->channel_oil, diff --git a/pimd/pim_igmp_mtrace.c b/pimd/pim_igmp_mtrace.c index 4d3f6022a1..309da138d2 100644 --- a/pimd/pim_igmp_mtrace.c +++ b/pimd/pim_igmp_mtrace.c @@ -21,7 +21,6 @@ static struct in_addr mtrace_primary_address(struct interface *ifp) { struct connected *ifc; - struct listnode *node; struct in_addr any; struct pim_interface *pim_ifp; @@ -32,7 +31,7 @@ static struct in_addr mtrace_primary_address(struct interface *ifp) any.s_addr = INADDR_ANY; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { + frr_each (if_connected, ifp->connected, ifc) { struct prefix *p = ifc->address; if (p->family != AF_INET) diff --git a/pimd/pim_igmpv3.c b/pimd/pim_igmpv3.c index 15078dd1ec..18a9fb7c6c 100644 --- a/pimd/pim_igmpv3.c +++ b/pimd/pim_igmpv3.c @@ -319,14 +319,6 @@ void igmp_source_free(struct gm_source *source) XFREE(MTYPE_PIM_IGMP_GROUP_SOURCE, source); } -static void source_channel_oil_detach(struct gm_source *source) -{ - if (source->source_channel_oil) { - pim_channel_oil_del(source->source_channel_oil, __func__); - source->source_channel_oil = NULL; - } -} - /* igmp_source_delete: stop forwarding, and delete the source igmp_source_forward_stop: stop forwarding, but keep the source @@ -355,6 +347,7 @@ void igmp_source_delete(struct gm_source *source) source_timer_off(group, source); igmp_source_forward_stop(source); + source->source_channel_oil = NULL; /* sanity check that forwarding has been disabled */ if (IGMP_SOURCE_TEST_FORWARDING(source->source_flags)) { @@ -371,8 +364,6 @@ void igmp_source_delete(struct gm_source *source) /* warning only */ } - source_channel_oil_detach(source); - /* notice that listnode_delete() can't be moved into igmp_source_free() because the later is diff --git a/pimd/pim_instance.c b/pimd/pim_instance.c index 6f33af0601..b3410d15af 100644 --- a/pimd/pim_instance.c +++ b/pimd/pim_instance.c @@ -178,6 +178,8 @@ static int pim_vrf_enable(struct vrf *vrf) zlog_debug("%s: for %s %u", __func__, vrf->name, vrf->vrf_id); + pim_mroute_socket_enable(pim); + FOR_ALL_INTERFACES (vrf, ifp) { if (!ifp->info) continue; @@ -186,8 +188,6 @@ static int pim_vrf_enable(struct vrf *vrf) break; } - pim_mroute_socket_enable(pim); - return 0; } diff --git a/pimd/pim_instance.h b/pimd/pim_instance.h index 11577ae46d..ec331332cf 100644 --- a/pimd/pim_instance.h +++ b/pimd/pim_instance.h @@ -97,7 +97,7 @@ struct pim_router { struct in_addr local_vtep_ip; struct pim_mlag_stats mlag_stats; enum pim_mlag_flags mlag_flags; - char peerlink_rif[INTERFACE_NAMSIZ]; + char peerlink_rif[IFNAMSIZ]; struct interface *peerlink_rif_p; }; diff --git a/pimd/pim_mlag.c b/pimd/pim_mlag.c index 5d72eb6581..dcef2d0d33 100644 --- a/pimd/pim_mlag.c +++ b/pimd/pim_mlag.c @@ -434,7 +434,7 @@ static void pim_mlag_up_local_add_send(struct pim_instance *pim, stream_putc(s, !(PIM_UPSTREAM_FLAG_TEST_MLAG_NON_DF(up->flags))); stream_putl(s, vrf->vrf_id); /* XXX - this field is a No-op for VXLAN*/ - stream_put(s, NULL, INTERFACE_NAMSIZ); + stream_put(s, NULL, IFNAMSIZ); stream_fifo_push_safe(router->mlag_fifo, s); pim_mlag_signal_zpthread(); @@ -467,7 +467,7 @@ static void pim_mlag_up_local_del_send(struct pim_instance *pim, stream_putl(s, MLAG_OWNER_VXLAN); stream_putl(s, vrf->vrf_id); /* XXX - this field is a No-op for VXLAN */ - stream_put(s, NULL, INTERFACE_NAMSIZ); + stream_put(s, NULL, IFNAMSIZ); /* XXX - is this the the most optimal way to do things */ stream_fifo_push_safe(router->mlag_fifo, s); diff --git a/pimd/pim_mroute.c b/pimd/pim_mroute.c index b64fcdeb87..e00888acf3 100644 --- a/pimd/pim_mroute.c +++ b/pimd/pim_mroute.c @@ -5,6 +5,9 @@ */ #include <zebra.h> +#include <netinet/icmp6.h> +#include <sys/ioctl.h> + #include "log.h" #include "privs.h" #include "if.h" @@ -253,7 +256,7 @@ int pim_mroute_msg_nocache(int fd, struct interface *ifp, const kernmsg *msg) up->channel_oil->cc.pktcnt++; // resolve mfcc_parent prior to mroute_add in channel_add_oif if (up->rpf.source_nexthop.interface && - *oil_parent(up->channel_oil) >= MAXVIFS) { + *oil_incoming_vif(up->channel_oil) >= MAXVIFS) { pim_upstream_mroute_iif_update(up->channel_oil, __func__); } pim_register_join(up); @@ -1042,10 +1045,10 @@ static inline void pim_mroute_copy(struct channel_oil *out, *oil_origin(out) = *oil_origin(in); *oil_mcastgrp(out) = *oil_mcastgrp(in); - *oil_parent(out) = *oil_parent(in); + *oil_incoming_vif(out) = *oil_incoming_vif(in); for (i = 0; i < MAXVIFS; ++i) { - if (*oil_parent(out) == i && + if (*oil_incoming_vif(out) == i && !pim_mroute_allow_iif_in_oil(in, i)) { oil_if_set(out, i, 0); continue; @@ -1080,7 +1083,7 @@ static int pim_mroute_add(struct channel_oil *c_oil, const char *name) * in the case of a (*,G). */ if (pim_addr_is_any(*oil_origin(c_oil))) { - oil_if_set(tmp_oil, *oil_parent(c_oil), 1); + oil_if_set(tmp_oil, *oil_incoming_vif(c_oil), 1); } /* @@ -1090,18 +1093,17 @@ static int pim_mroute_add(struct channel_oil *c_oil, const char *name) * the packets to be forwarded. Then set it * to the correct IIF afterwords. */ - if (!c_oil->installed && !pim_addr_is_any(*oil_origin(c_oil)) - && *oil_parent(c_oil) != 0) { - *oil_parent(tmp_oil) = 0; + if (!c_oil->installed && !pim_addr_is_any(*oil_origin(c_oil)) && + *oil_incoming_vif(c_oil) != 0) { + *oil_incoming_vif(tmp_oil) = 0; } /* For IPv6 MRT_ADD_MFC is defined to MRT6_ADD_MFC */ err = setsockopt(pim->mroute_socket, PIM_IPPROTO, MRT_ADD_MFC, &tmp_oil->oil, sizeof(tmp_oil->oil)); - if (!err && !c_oil->installed - && !pim_addr_is_any(*oil_origin(c_oil)) - && *oil_parent(c_oil) != 0) { - *oil_parent(tmp_oil) = *oil_parent(c_oil); + if (!err && !c_oil->installed && !pim_addr_is_any(*oil_origin(c_oil)) && + *oil_incoming_vif(c_oil) != 0) { + *oil_incoming_vif(tmp_oil) = *oil_incoming_vif(c_oil); err = setsockopt(pim->mroute_socket, PIM_IPPROTO, MRT_ADD_MFC, &tmp_oil->oil, sizeof(tmp_oil->oil)); } @@ -1158,7 +1160,7 @@ static int pim_upstream_mroute_update(struct channel_oil *c_oil, { char buf[1000]; - if (*oil_parent(c_oil) >= MAXVIFS) { + if (*oil_incoming_vif(c_oil) >= MAXVIFS) { /* the c_oil cannot be installed as a mroute yet */ if (PIM_DEBUG_MROUTE) zlog_debug( @@ -1205,13 +1207,13 @@ int pim_upstream_mroute_add(struct channel_oil *c_oil, const char *name) iif = pim_upstream_get_mroute_iif(c_oil, name); - if (*oil_parent(c_oil) != iif) { - *oil_parent(c_oil) = iif; + if (*oil_incoming_vif(c_oil) != iif) { + *oil_incoming_vif(c_oil) = iif; if (pim_addr_is_any(*oil_origin(c_oil)) && c_oil->up) pim_upstream_all_sources_iif_update(c_oil->up); } else { - *oil_parent(c_oil) = iif; + *oil_incoming_vif(c_oil) = iif; } return pim_upstream_mroute_update(c_oil, name); @@ -1226,11 +1228,11 @@ int pim_upstream_mroute_iif_update(struct channel_oil *c_oil, const char *name) char buf[1000]; iif = pim_upstream_get_mroute_iif(c_oil, name); - if (*oil_parent(c_oil) == iif) { + if (*oil_incoming_vif(c_oil) == iif) { /* no change */ return 0; } - *oil_parent(c_oil) = iif; + *oil_incoming_vif(c_oil) = iif; if (pim_addr_is_any(*oil_origin(c_oil)) && c_oil->up) @@ -1255,10 +1257,10 @@ void pim_static_mroute_iif_update(struct channel_oil *c_oil, int input_vif_index, const char *name) { - if (*oil_parent(c_oil) == input_vif_index) + if (*oil_incoming_vif(c_oil) == input_vif_index) return; - *oil_parent(c_oil) = input_vif_index; + *oil_incoming_vif(c_oil) = input_vif_index; if (input_vif_index == MAXVIFS) pim_mroute_del(c_oil, name); else @@ -1276,10 +1278,15 @@ int pim_mroute_del(struct channel_oil *c_oil, const char *name) if (!c_oil->installed) { if (PIM_DEBUG_MROUTE) { char buf[1000]; - zlog_debug( - "%s %s: vifi %d for route is %s not installed, do not need to send del req. ", - __FILE__, __func__, *oil_parent(c_oil), - pim_channel_oil_dump(c_oil, buf, sizeof(buf))); + struct interface *iifp = + pim_if_find_by_vif_index(pim, *oil_incoming_vif( + c_oil)); + + zlog_debug("%s %s: incoming interface %s for route is %s not installed, do not need to send del req. ", + __FILE__, __func__, + iifp ? iifp->name : "Unknown", + pim_channel_oil_dump(c_oil, buf, + sizeof(buf))); } return -2; } diff --git a/pimd/pim_msdp.c b/pimd/pim_msdp.c index b1b6958fe1..623c14bb03 100644 --- a/pimd/pim_msdp.c +++ b/pimd/pim_msdp.c @@ -374,6 +374,8 @@ void pim_msdp_sa_ref(struct pim_instance *pim, struct pim_msdp_peer *mp, pim_sgaddr *sg, struct in_addr rp) { struct pim_msdp_sa *sa; + struct rp_info *rp_info; + struct prefix grp; sa = pim_msdp_sa_add(pim, sg, rp); if (!sa) { @@ -406,6 +408,14 @@ void pim_msdp_sa_ref(struct pim_instance *pim, struct pim_msdp_peer *mp, sa->sg_str); } /* send an immediate SA update to peers */ + pim_addr_to_prefix(&grp, sa->sg.grp); + rp_info = pim_rp_find_match_group(pim, &grp); + if (rp_info) { + sa->rp = rp_info->rp.rpf_addr; + } else + { + sa->rp = pim->msdp.originator_id; + } sa->rp = pim->msdp.originator_id; pim_msdp_pkt_sa_tx_one(sa); } diff --git a/pimd/pim_msdp_packet.c b/pimd/pim_msdp_packet.c index a414736ccc..4324a96bef 100644 --- a/pimd/pim_msdp_packet.c +++ b/pimd/pim_msdp_packet.c @@ -14,7 +14,9 @@ #include "pimd.h" #include "pim_instance.h" +#include "pim_rp.h" #include "pim_str.h" +#include "pim_util.h" #include "pim_errors.h" #include "pim_msdp.h" @@ -387,6 +389,9 @@ static void pim_msdp_pkt_sa_gen(struct pim_instance *pim, { struct listnode *sanode; struct pim_msdp_sa *sa; + struct rp_info *rp_info; + struct prefix group_all; + struct in_addr rp; int sa_count; int local_cnt = pim->msdp.local_cnt; @@ -395,8 +400,15 @@ static void pim_msdp_pkt_sa_gen(struct pim_instance *pim, zlog_debug(" sa gen %d", local_cnt); } - local_cnt = pim_msdp_pkt_sa_fill_hdr(pim, local_cnt, - pim->msdp.originator_id); + rp = pim->msdp.originator_id; + if (pim_get_all_mcast_group(&group_all)) { + rp_info = pim_rp_find_match_group(pim, &group_all); + if (rp_info) { + rp = rp_info->rp.rpf_addr; + } + } + + local_cnt = pim_msdp_pkt_sa_fill_hdr(pim, local_cnt, rp); for (ALL_LIST_ELEMENTS_RO(pim->msdp.sa_list, sanode, sa)) { if (!(sa->flags & PIM_MSDP_SAF_LOCAL)) { @@ -418,7 +430,7 @@ static void pim_msdp_pkt_sa_gen(struct pim_instance *pim, local_cnt); } local_cnt = pim_msdp_pkt_sa_fill_hdr( - pim, local_cnt, pim->msdp.originator_id); + pim, local_cnt, rp); } } diff --git a/pimd/pim_msg.c b/pimd/pim_msg.c index 5d1f08314b..6814798bf5 100644 --- a/pimd/pim_msg.c +++ b/pimd/pim_msg.c @@ -196,7 +196,32 @@ size_t pim_msg_get_jp_group_size(struct list *sources) __func__, up->sg_str); for (ALL_LIST_ELEMENTS_RO(up->sources, up_node, child)) { - if (!PIM_UPSTREAM_FLAG_TEST_USE_RPT(child->flags)) { + /* + * PIM VXLAN is weird + * It auto creates the S,G and populates a bunch + * of flags that make it look like a SPT prune should + * be sent. But this regularly scheduled join + * for the *,G in the VXLAN setup can happen at + * scheduled times *before* the null register + * is received by the RP to cause it to initiate + * the S,G joins toward the source. Let's just + * assume that if this is a SRC VXLAN ORIG route + * and no actual ifchannels( joins ) have been + * created then do not send the embedded prune + * Why you may ask? Well if the prune is S,G + * RPT Prune is received *before* the join + * from the RP( if it flows to this routers + * upstream interface ) then we'll just wisely + * create a mroute with an empty oil on + * the upstream intermediate router preventing + * packets from flowing to the RP + */ + if (PIM_UPSTREAM_FLAG_TEST_SRC_VXLAN_ORIG(child->flags) && + listcount(child->ifchannels) == 0) { + if (PIM_DEBUG_PIM_PACKETS) + zlog_debug("%s: %s Vxlan originated S,G route with no ifchannels, not adding prune to compound message", + __func__, child->sg_str); + } else if (!PIM_UPSTREAM_FLAG_TEST_USE_RPT(child->flags)) { /* If we are using SPT and the SPT and RPT IIFs * are different we can prune the source off * of the RPT. diff --git a/pimd/pim_nb_config.c b/pimd/pim_nb_config.c index d7e4154558..9a6b98de7e 100644 --- a/pimd/pim_nb_config.c +++ b/pimd/pim_nb_config.c @@ -45,20 +45,6 @@ MACRO_REQUIRE_SEMICOLON() #define yang_dnode_get_pimaddr yang_dnode_get_ipv4 #endif /* PIM_IPV != 6 */ -static void pim_if_membership_clear(struct interface *ifp) -{ - struct pim_interface *pim_ifp; - - pim_ifp = ifp->info; - assert(pim_ifp); - - if (pim_ifp->pim_enable && pim_ifp->gm_enable) { - return; - } - - pim_ifchannel_membership_clear(ifp); -} - /* * When PIM is disabled on interface, IGMPv3 local membership * information is not injected into PIM interface state. @@ -161,32 +147,6 @@ static int pim_cmd_interface_add(struct interface *ifp) return 1; } -static int pim_cmd_interface_delete(struct interface *ifp) -{ - struct pim_interface *pim_ifp = ifp->info; - - if (!pim_ifp) - return 1; - - pim_ifp->pim_enable = false; - - pim_if_membership_clear(ifp); - - /* - * pim_sock_delete() removes all neighbors from - * pim_ifp->pim_neighbor_list. - */ - pim_sock_delete(ifp, "pim unconfigured on interface"); - pim_upstream_nh_if_update(pim_ifp->pim, ifp); - - if (!pim_ifp->gm_enable) { - pim_if_addr_del_all(ifp); - pim_if_delete(ifp); - } - - return 1; -} - static int interface_pim_use_src_cmd_worker(struct interface *ifp, pim_addr source_addr, char *errmsg, size_t errmsg_len) { @@ -278,7 +238,7 @@ static int pim_rp_cmd_worker(struct pim_instance *pim, pim_addr rp_addr, if (result == PIM_RP_NO_PATH) { snprintfrr(errmsg, errmsg_len, "No Path to RP address specified: %pPA", &rp_addr); - return NB_ERR_INCONSISTENCY; + return NB_OK; } if (result == PIM_GROUP_OVERLAP) { @@ -525,7 +485,7 @@ int routing_control_plane_protocols_name_validate( { const char *name; - name = yang_dnode_get_string(args->dnode, "./name"); + name = yang_dnode_get_string(args->dnode, "name"); if (!strmatch(name, "pim")) { snprintf(args->errmsg, args->errmsg_len, "pim supports only one instance with name pimd"); @@ -819,7 +779,7 @@ void routing_control_plane_protocols_control_plane_protocol_pim_address_family_s vrf = nb_running_get_entry(args->dnode, NULL, true); pim = vrf->info; - spt_switch_action = yang_dnode_get_enum(args->dnode, "./spt-action"); + spt_switch_action = yang_dnode_get_enum(args->dnode, "spt-action"); switch (spt_switch_action) { case PIM_SPT_INFINITY: @@ -1273,8 +1233,8 @@ int routing_control_plane_protocols_control_plane_protocol_pim_address_family_ms case NB_EV_APPLY: vrf = nb_running_get_entry(args->dnode, NULL, true); pim = vrf->info; - yang_dnode_get_ip(&peer_ip, args->dnode, "./peer-ip"); - yang_dnode_get_ip(&source_ip, args->dnode, "./source-ip"); + yang_dnode_get_ip(&peer_ip, args->dnode, "peer-ip"); + yang_dnode_get_ip(&source_ip, args->dnode, "source-ip"); mp = pim_msdp_peer_add(pim, &peer_ip.ipaddr_v4, &source_ip.ipaddr_v4, NULL); nb_running_set_entry(args->dnode, mp); @@ -1378,16 +1338,16 @@ void routing_control_plane_protocols_control_plane_protocol_pim_address_family_m struct interface *ifp; struct ipaddr reg_addr; - ifname = yang_dnode_get_string(args->dnode, "./peerlink-rif"); + ifname = yang_dnode_get_string(args->dnode, "peerlink-rif"); ifp = if_lookup_by_name(ifname, VRF_DEFAULT); if (!ifp) { snprintf(args->errmsg, args->errmsg_len, "No such interface name %s", ifname); return; } - role = yang_dnode_get_enum(args->dnode, "./my-role"); - peer_state = yang_dnode_get_bool(args->dnode, "./peer-state"); - yang_dnode_get_ip(®_addr, args->dnode, "./reg-address"); + role = yang_dnode_get_enum(args->dnode, "my-role"); + peer_state = yang_dnode_get_bool(args->dnode, "peer-state"); + yang_dnode_get_ip(®_addr, args->dnode, "reg-address"); pim_vxlan_mlag_update(true, peer_state, role, ifp, ®_addr.ip._v4_addr); @@ -1573,12 +1533,7 @@ int lib_interface_pim_address_family_destroy(struct nb_cb_destroy_args *args) if (!pim_ifp) return NB_OK; - if (!pim_cmd_interface_delete(ifp)) { - snprintf(args->errmsg, args->errmsg_len, - "Unable to delete interface information %s", - ifp->name); - return NB_ERR_INCONSISTENCY; - } + pim_pim_interface_delete(ifp); } return NB_OK; @@ -1626,11 +1581,7 @@ int lib_interface_pim_address_family_pim_enable_modify(struct nb_cb_modify_args if (!pim_ifp) return NB_ERR_INCONSISTENCY; - if (!pim_cmd_interface_delete(ifp)) { - snprintf(args->errmsg, args->errmsg_len, - "Unable to delete interface information"); - return NB_ERR_INCONSISTENCY; - } + pim_pim_interface_delete(ifp); } break; } @@ -1682,7 +1633,7 @@ int lib_interface_pim_address_family_hello_interval_modify( ifp = nb_running_get_entry(args->dnode, NULL, true); pim_ifp = ifp->info; pim_ifp->pim_hello_period = - yang_dnode_get_uint8(args->dnode, NULL); + yang_dnode_get_uint16(args->dnode, NULL); pim_ifp->pim_default_holdtime = -1; break; } @@ -1808,11 +1759,11 @@ void lib_interface_pim_address_family_bfd_apply_finish( } pim_ifp->bfd_config.detection_multiplier = - yang_dnode_get_uint8(args->dnode, "./detect_mult"); + yang_dnode_get_uint8(args->dnode, "detect_mult"); pim_ifp->bfd_config.min_rx = - yang_dnode_get_uint16(args->dnode, "./min-rx-interval"); + yang_dnode_get_uint16(args->dnode, "min-rx-interval"); pim_ifp->bfd_config.min_tx = - yang_dnode_get_uint16(args->dnode, "./min-tx-interval"); + yang_dnode_get_uint16(args->dnode, "min-tx-interval"); pim_bfd_reg_dereg_all_nbr(ifp); } @@ -2240,7 +2191,7 @@ int lib_interface_pim_address_family_mroute_destroy( pim_iifp = iif->info; pim = pim_iifp->pim; - oifname = yang_dnode_get_string(args->dnode, "./oif"); + oifname = yang_dnode_get_string(args->dnode, "oif"); oif = if_lookup_by_name(oifname, pim->vrf->vrf_id); if (!oif) { @@ -2250,8 +2201,8 @@ int lib_interface_pim_address_family_mroute_destroy( return NB_ERR_INCONSISTENCY; } - yang_dnode_get_pimaddr(&source_addr, args->dnode, "./source-addr"); - yang_dnode_get_pimaddr(&group_addr, args->dnode, "./group-addr"); + yang_dnode_get_pimaddr(&source_addr, args->dnode, "source-addr"); + yang_dnode_get_pimaddr(&group_addr, args->dnode, "group-addr"); if (pim_static_del(pim, iif, oif, group_addr, source_addr)) { snprintf(args->errmsg, args->errmsg_len, @@ -2390,9 +2341,9 @@ int routing_control_plane_protocols_control_plane_protocol_pim_address_family_rp case NB_EV_APPLY: vrf = nb_running_get_entry(args->dnode, NULL, true); pim = vrf->info; - yang_dnode_get_pimaddr(&rp_addr, args->dnode, "./rp-address"); + yang_dnode_get_pimaddr(&rp_addr, args->dnode, "rp-address"); - if (yang_dnode_get(args->dnode, "./group-list")) { + if (yang_dnode_get(args->dnode, "group-list")) { yang_dnode_get_prefix(&group, args->dnode, "./group-list"); apply_mask(&group); @@ -2401,7 +2352,7 @@ int routing_control_plane_protocols_control_plane_protocol_pim_address_family_rp args->errmsg_len); } - else if (yang_dnode_get(args->dnode, "./prefix-list")) { + else if (yang_dnode_get(args->dnode, "prefix-list")) { plist = yang_dnode_get_string(args->dnode, "./prefix-list"); if (!pim_get_all_mcast_group(&group)) { @@ -2565,7 +2516,6 @@ int lib_interface_gmp_address_family_create(struct nb_cb_create_args *args) int lib_interface_gmp_address_family_destroy(struct nb_cb_destroy_args *args) { struct interface *ifp; - struct pim_interface *pim_ifp; switch (args->event) { case NB_EV_VALIDATE: @@ -2574,19 +2524,7 @@ int lib_interface_gmp_address_family_destroy(struct nb_cb_destroy_args *args) break; case NB_EV_APPLY: ifp = nb_running_get_entry(args->dnode, NULL, true); - pim_ifp = ifp->info; - - if (!pim_ifp) - return NB_OK; - - pim_ifp->gm_enable = false; - - pim_if_membership_clear(ifp); - - pim_if_addr_del_all_igmp(ifp); - - if (!pim_ifp->pim_enable) - pim_if_delete(ifp); + pim_gm_interface_delete(ifp); } return NB_OK; @@ -2600,7 +2538,6 @@ int lib_interface_gmp_address_family_enable_modify( { struct interface *ifp; bool gm_enable; - struct pim_interface *pim_ifp; int mcast_if_count; const char *ifp_name; const struct lyd_node *if_dnode; @@ -2630,25 +2567,8 @@ int lib_interface_gmp_address_family_enable_modify( if (gm_enable) return pim_cmd_gm_start(ifp); - else { - pim_ifp = ifp->info; - - if (!pim_ifp) - return NB_ERR_INCONSISTENCY; - - pim_ifp->gm_enable = false; - - pim_if_membership_clear(ifp); - -#if PIM_IPV == 4 - pim_if_addr_del_all_igmp(ifp); -#else - gm_ifp_teardown(ifp); -#endif - - if (!pim_ifp->pim_enable) - pim_if_delete(ifp); - } + else + pim_gm_interface_delete(ifp); } return NB_OK; } diff --git a/pimd/pim_nht.c b/pimd/pim_nht.c index 5f0f2a5933..32cdf4bf82 100644 --- a/pimd/pim_nht.c +++ b/pimd/pim_nht.c @@ -31,6 +31,8 @@ #include "pim_zlookup.h" #include "pim_rp.h" #include "pim_addr.h" +#include "pim_register.h" +#include "pim_vxlan.h" /** * pim_sendmsg_zebra_rnh -- Format and send a nexthop register/Unregister @@ -336,7 +338,7 @@ bool pim_nht_bsr_rpf_check(struct pim_instance *pim, pim_addr bsr_addr, if (nh->ifindex == IFINDEX_INTERNAL) continue; - /* fallthru */ + fallthrough; case NEXTHOP_TYPE_IPV4_IFINDEX: nhaddr = nh->gate.ipv4; break; @@ -348,7 +350,7 @@ bool pim_nht_bsr_rpf_check(struct pim_instance *pim, pim_addr bsr_addr, if (nh->ifindex == IFINDEX_INTERNAL) continue; - /* fallthru */ + fallthrough; case NEXTHOP_TYPE_IPV6_IFINDEX: nhaddr = nh->gate.ipv6; break; @@ -399,17 +401,28 @@ static void pim_update_rp_nh(struct pim_instance *pim, { struct listnode *node = NULL; struct rp_info *rp_info = NULL; + struct interface *ifp; /*Traverse RP list and update each RP Nexthop info */ for (ALL_LIST_ELEMENTS_RO(pnc->rp_list, node, rp_info)) { if (pim_rpf_addr_is_inaddr_any(&rp_info->rp)) continue; + ifp = rp_info->rp.source_nexthop.interface; // Compute PIM RPF using cached nexthop if (!pim_ecmp_nexthop_lookup(pim, &rp_info->rp.source_nexthop, rp_info->rp.rpf_addr, &rp_info->group, 1)) pim_rp_nexthop_del(rp_info); + + /* + * If we transition from no path to a path + * we need to search through all the vxlan's + * that use this rp and send NULL registers + * for all the vxlan S,G streams + */ + if (!ifp && rp_info->rp.source_nexthop.interface) + pim_vxlan_rp_info_is_alive(pim, &rp_info->rp); } } @@ -436,17 +449,27 @@ static int pim_update_upstream_nh_helper(struct hash_bucket *bucket, void *arg) (rpf_result == PIM_RPF_FAILURE && old.source_nexthop.interface)) pim_zebra_upstream_rpf_changed(pim, up, &old); + /* + * If we are a VXLAN source and we are transitioning from not + * having an outgoing interface to having an outgoing interface + * let's immediately send the null pim register + */ + if (!old.source_nexthop.interface && up->rpf.source_nexthop.interface && + PIM_UPSTREAM_FLAG_TEST_SRC_VXLAN_ORIG(up->flags) && + (up->reg_state == PIM_REG_NOINFO || up->reg_state == PIM_REG_JOIN)) { + pim_null_register_send(up); + } if (PIM_DEBUG_PIM_NHT) { - zlog_debug( - "%s: NHT upstream %s(%s) old ifp %s new ifp %s", - __func__, up->sg_str, pim->vrf->name, - old.source_nexthop.interface ? old.source_nexthop - .interface->name - : "Unknown", - up->rpf.source_nexthop.interface ? up->rpf.source_nexthop - .interface->name - : "Unknown"); + zlog_debug("%s: NHT upstream %s(%s) old ifp %s new ifp %s rpf_result: %d", + __func__, up->sg_str, pim->vrf->name, + old.source_nexthop.interface ? old.source_nexthop + .interface->name + : "Unknown", + up->rpf.source_nexthop.interface ? up->rpf.source_nexthop + .interface->name + : "Unknown", + rpf_result); } return HASHWALK_CONTINUE; @@ -700,7 +723,8 @@ static int pim_ecmp_nexthop_search(struct pim_instance *pim, /* This API is used to parse Registered address nexthop update coming from Zebra */ -int pim_parse_nexthop_update(ZAPI_CALLBACK_ARGS) +void pim_nexthop_update(struct vrf *vrf, struct prefix *match, + struct zapi_route *nhr) { struct nexthop *nexthop; struct nexthop *nhlist_head = NULL; @@ -709,38 +733,27 @@ int pim_parse_nexthop_update(ZAPI_CALLBACK_ARGS) struct pim_rpf rpf; struct pim_nexthop_cache *pnc = NULL; struct interface *ifp = NULL; - struct vrf *vrf = vrf_lookup_by_id(vrf_id); struct pim_instance *pim; - struct zapi_route nhr; - struct prefix match; - if (!vrf) - return 0; pim = vrf->info; - if (!zapi_nexthop_update_decode(zclient->ibuf, &match, &nhr)) { - zlog_err("%s: Decode of nexthop update from zebra failed", - __func__); - return 0; - } - - rpf.rpf_addr = pim_addr_from_prefix(&match); + rpf.rpf_addr = pim_addr_from_prefix(match); pnc = pim_nexthop_cache_find(pim, &rpf); if (!pnc) { if (PIM_DEBUG_PIM_NHT) zlog_debug( "%s: Skipping NHT update, addr %pPA is not in local cached DB.", __func__, &rpf.rpf_addr); - return 0; + return; } pnc->last_update = pim_time_monotonic_usec(); - if (nhr.nexthop_num) { + if (nhr->nexthop_num) { pnc->nexthop_num = 0; - for (i = 0; i < nhr.nexthop_num; i++) { - nexthop = nexthop_from_zapi_nexthop(&nhr.nexthops[i]); + for (i = 0; i < nhr->nexthop_num; i++) { + nexthop = nexthop_from_zapi_nexthop(&nhr->nexthops[i]); switch (nexthop->type) { case NEXTHOP_TYPE_IFINDEX: /* @@ -819,11 +832,11 @@ int pim_parse_nexthop_update(ZAPI_CALLBACK_ARGS) #else pim_addr nhaddr = nexthop->gate.ipv6; #endif - zlog_debug( - "%s: NHT addr %pFX(%s) %d-nhop via %pPA(%s) type %d distance:%u metric:%u ", - __func__, &match, pim->vrf->name, i + 1, - &nhaddr, ifp->name, nexthop->type, - nhr.distance, nhr.metric); + zlog_debug("%s: NHT addr %pFX(%s) %d-nhop via %pPA(%s) type %d distance:%u metric:%u ", + __func__, match, pim->vrf->name, + i + 1, &nhaddr, ifp->name, + nexthop->type, nhr->distance, + nhr->metric); } if (!ifp->info) { @@ -864,23 +877,22 @@ int pim_parse_nexthop_update(ZAPI_CALLBACK_ARGS) pnc->nexthop = nhlist_head; if (pnc->nexthop_num) { pnc->flags |= PIM_NEXTHOP_VALID; - pnc->distance = nhr.distance; - pnc->metric = nhr.metric; + pnc->distance = nhr->distance; + pnc->metric = nhr->metric; } } else { pnc->flags &= ~PIM_NEXTHOP_VALID; - pnc->nexthop_num = nhr.nexthop_num; + pnc->nexthop_num = nhr->nexthop_num; nexthops_free(pnc->nexthop); pnc->nexthop = NULL; } SET_FLAG(pnc->flags, PIM_NEXTHOP_ANSWER_RECEIVED); if (PIM_DEBUG_PIM_NHT) - zlog_debug( - "%s: NHT Update for %pFX(%s) num_nh %d num_pim_nh %d vrf:%u up %ld rp %d", - __func__, &match, pim->vrf->name, nhr.nexthop_num, - pnc->nexthop_num, vrf_id, pnc->upstream_hash->count, - listcount(pnc->rp_list)); + zlog_debug("%s: NHT Update for %pFX(%s) num_nh %d num_pim_nh %d vrf:%u up %ld rp %d", + __func__, match, pim->vrf->name, nhr->nexthop_num, + pnc->nexthop_num, vrf->vrf_id, + pnc->upstream_hash->count, listcount(pnc->rp_list)); pim_rpf_set_refresh_time(pim); @@ -888,8 +900,6 @@ int pim_parse_nexthop_update(ZAPI_CALLBACK_ARGS) pim_update_rp_nh(pim, pnc); if (pnc->upstream_hash->count) pim_update_upstream_nh(pim, pnc); - - return 0; } int pim_ecmp_nexthop_lookup(struct pim_instance *pim, diff --git a/pimd/pim_nht.h b/pimd/pim_nht.h index 5a54e1c67a..a1feb76e3b 100644 --- a/pimd/pim_nht.h +++ b/pimd/pim_nht.h @@ -45,7 +45,8 @@ struct pnc_hash_walk_data { struct interface *ifp; }; -int pim_parse_nexthop_update(ZAPI_CALLBACK_ARGS); +void pim_nexthop_update(struct vrf *vrf, struct prefix *match, + struct zapi_route *nhr); int pim_find_or_track_nexthop(struct pim_instance *pim, pim_addr addr, struct pim_upstream *up, struct rp_info *rp, struct pim_nexthop_cache *out_pnc); diff --git a/pimd/pim_oil.c b/pimd/pim_oil.c index e1ec9b34a1..d18406d55d 100644 --- a/pimd/pim_oil.c +++ b/pimd/pim_oil.c @@ -31,7 +31,7 @@ char *pim_channel_oil_dump(struct channel_oil *c_oil, char *buf, size_t size) sg.src = *oil_origin(c_oil); sg.grp = *oil_mcastgrp(c_oil); - ifp = pim_if_find_by_vif_index(c_oil->pim, *oil_parent(c_oil)); + ifp = pim_if_find_by_vif_index(c_oil->pim, *oil_incoming_vif(c_oil)); snprintfrr(buf, size, "%pSG IIF: %s, OIFS: ", &sg, ifp ? ifp->name : "(?)"); @@ -135,7 +135,7 @@ struct channel_oil *pim_channel_oil_add(struct pim_instance *pim, *oil_mcastgrp(c_oil) = sg->grp; *oil_origin(c_oil) = sg->src; - *oil_parent(c_oil) = MAXVIFS; + *oil_incoming_vif(c_oil) = MAXVIFS; c_oil->oil_ref_count = 1; c_oil->installed = 0; c_oil->up = pim_upstream_find(pim, sg); @@ -164,7 +164,7 @@ void pim_clear_nocache_state(struct pim_interface *pim_ifp) !(PIM_UPSTREAM_FLAG_TEST_SRC_NOCACHE(c_oil->up->flags))) continue; - if (*oil_parent(c_oil) != pim_ifp->mroute_vif_index) + if (*oil_incoming_vif(c_oil) != pim_ifp->mroute_vif_index) continue; EVENT_OFF(c_oil->up->t_ka_timer); @@ -286,13 +286,15 @@ int pim_channel_del_oif(struct channel_oil *channel_oil, struct interface *oif, --channel_oil->oil_size; if (PIM_DEBUG_MROUTE) { - zlog_debug( - "%s(%s): (S,G)=(%pPAs,%pPAs): proto_mask=%u IIF:%d OIF=%s vif_index=%d", - __func__, caller, oil_origin(channel_oil), - oil_mcastgrp(channel_oil), - proto_mask, - *oil_parent(channel_oil), oif->name, - pim_ifp->mroute_vif_index); + struct interface *iifp = + pim_if_find_by_vif_index(pim_ifp->pim, + *oil_incoming_vif(channel_oil)); + + zlog_debug("%s(%s): (S,G)=(%pPAs,%pPAs): proto_mask=%u IIF:%s OIF=%s vif_index=%d", + __func__, caller, oil_origin(channel_oil), + oil_mcastgrp(channel_oil), proto_mask, + iifp ? iifp->name : "Unknown", oif->name, + pim_ifp->mroute_vif_index); } return 0; @@ -522,7 +524,7 @@ int pim_channel_add_oif(struct channel_oil *channel_oil, struct interface *oif, /* channel_oil->oil.mfcc_parent != MAXVIFS indicate this entry is not * valid to get installed in kernel. */ - if (*oil_parent(channel_oil) != MAXVIFS) { + if (*oil_incoming_vif(channel_oil) != MAXVIFS) { if (pim_upstream_mroute_add(channel_oil, __func__)) { if (PIM_DEBUG_MROUTE) { zlog_debug( diff --git a/pimd/pim_oil.h b/pimd/pim_oil.h index dc66eaace4..6a5222753b 100644 --- a/pimd/pim_oil.h +++ b/pimd/pim_oil.h @@ -112,7 +112,7 @@ static inline pim_addr *oil_mcastgrp(struct channel_oil *c_oil) return &c_oil->oil.mfcc_mcastgrp; } -static inline vifi_t *oil_parent(struct channel_oil *c_oil) +static inline vifi_t *oil_incoming_vif(struct channel_oil *c_oil) { return &c_oil->oil.mfcc_parent; } @@ -143,7 +143,7 @@ static inline pim_addr *oil_mcastgrp(struct channel_oil *c_oil) return &c_oil->oil.mf6cc_mcastgrp.sin6_addr; } -static inline mifi_t *oil_parent(struct channel_oil *c_oil) +static inline mifi_t *oil_incoming_vif(struct channel_oil *c_oil) { return &c_oil->oil.mf6cc_parent; } diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c index 4a272a4802..1bc265b138 100644 --- a/pimd/pim_pim.c +++ b/pimd/pim_pim.c @@ -155,7 +155,7 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len, bool no_fwd; #if PIM_IPV == 4 - if (len < sizeof(*ip_hdr)) { + if (len <= sizeof(*ip_hdr)) { if (PIM_DEBUG_PIM_PACKETS) zlog_debug( "PIM packet size=%zu shorter than minimum=%zu", @@ -189,7 +189,6 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len, iovp->iov_len = pim_msg_len; iovp++; - header = (struct pim_msg_header *)pim_msg; if (pim_msg_len < PIM_PIM_MIN_LEN) { if (PIM_DEBUG_PIM_PACKETS) zlog_debug( @@ -197,6 +196,7 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len, pim_msg_len, PIM_PIM_MIN_LEN); return -1; } + header = (struct pim_msg_header *)pim_msg; if (header->ver != PIM_PROTO_VERSION) { if (PIM_DEBUG_PIM_PACKETS) @@ -743,14 +743,13 @@ static int hello_send(struct interface *ifp, uint16_t holdtime) pim_ifp = ifp->info; if (PIM_DEBUG_PIM_HELLO) - zlog_debug( - "%s: to %pPA on %s: holdt=%u prop_d=%u overr_i=%u dis_join_supp=%d dr_prio=%u gen_id=%08x addrs=%d", - __func__, &qpim_all_pim_routers_addr, ifp->name, - holdtime, pim_ifp->pim_propagation_delay_msec, - pim_ifp->pim_override_interval_msec, - pim_ifp->pim_can_disable_join_suppression, - pim_ifp->pim_dr_priority, pim_ifp->pim_generation_id, - listcount(ifp->connected)); + zlog_debug("%s: to %pPA on %s: holdt=%u prop_d=%u overr_i=%u dis_join_supp=%d dr_prio=%u gen_id=%08x addrs=%zu", + __func__, &qpim_all_pim_routers_addr, ifp->name, + holdtime, pim_ifp->pim_propagation_delay_msec, + pim_ifp->pim_override_interval_msec, + pim_ifp->pim_can_disable_join_suppression, + pim_ifp->pim_dr_priority, pim_ifp->pim_generation_id, + if_connected_count(ifp->connected)); pim_tlv_size = pim_hello_build_tlv( ifp, pim_msg + PIM_PIM_MIN_LEN, diff --git a/pimd/pim_register.c b/pimd/pim_register.c index b5d9df6f2a..01da699dbd 100644 --- a/pimd/pim_register.c +++ b/pimd/pim_register.c @@ -85,7 +85,7 @@ void pim_register_stop_send(struct interface *ifp, pim_sgaddr *sg, pim_addr src, zlog_debug("%s: No pinfo!", __func__); return; } - if (pim_msg_send(pinfo->pim_sock_fd, src, originator, buffer, + if (pim_msg_send(pinfo->pim->reg_sock, src, originator, buffer, b1length + PIM_MSG_REGISTER_STOP_LEN, ifp)) { if (PIM_DEBUG_PIM_TRACE) { zlog_debug( @@ -416,11 +416,8 @@ void pim_null_register_send(struct pim_upstream *up) memset(buffer, 0, (sizeof(ip6_hdr) + sizeof(pim_msg_header))); memcpy(buffer, &ip6_hdr, sizeof(ip6_hdr)); - pim_msg_header.ver = 0; - pim_msg_header.type = 0; - pim_msg_header.reserved = 0; - - pim_msg_header.checksum = 0; + memset(&pim_msg_header, 0, sizeof(pim_msg_header)); + memset(&ph, 0, sizeof(ph)); ph.src = up->sg.src; ph.dst = up->sg.grp; @@ -494,6 +491,7 @@ int pim_register_recv(struct interface *ifp, pim_addr dest_addr, struct pim_interface *pim_ifp = ifp->info; struct pim_instance *pim = pim_ifp->pim; pim_addr rp_addr; + struct pim_rpf *rpg; if (pim_ifp->pim_passive_enable) { if (PIM_DEBUG_PIM_PACKETS) @@ -602,7 +600,14 @@ int pim_register_recv(struct interface *ifp, pim_addr dest_addr, } } - rp_addr = (RP(pim, sg.grp))->rpf_addr; + rpg = RP(pim, sg.grp); + if (!rpg) { + zlog_warn("%s: Received Register Message %pSG from %pPA on %s where the RP could not be looked up", + __func__, &sg, &src_addr, ifp->name); + return 0; + } + + rp_addr = rpg->rpf_addr; if (i_am_rp && (!pim_addr_cmp(dest_addr, rp_addr))) { sentRegisterStop = 0; @@ -745,6 +750,7 @@ void pim_reg_del_on_couldreg_fail(struct interface *ifp) PIM_OIF_FLAG_PROTO_PIM, __func__); EVENT_OFF(up->t_rs_timer); up->reg_state = PIM_REG_NOINFO; + PIM_UPSTREAM_FLAG_UNSET_FHR(up->flags); } } } diff --git a/pimd/pim_sock.c b/pimd/pim_sock.c index 6c65c5d3e9..3476c177b7 100644 --- a/pimd/pim_sock.c +++ b/pimd/pim_sock.c @@ -5,6 +5,7 @@ */ #include <zebra.h> +#include <fcntl.h> #include <sys/types.h> #include <sys/socket.h> diff --git a/pimd/pim_ssmpingd.c b/pimd/pim_ssmpingd.c index dadf29f535..27dbb0d6b4 100644 --- a/pimd/pim_ssmpingd.c +++ b/pimd/pim_ssmpingd.c @@ -185,7 +185,6 @@ static int ssmpingd_socket(pim_addr addr, int port, int mttl) ret = ssmpingd_setsockopt(fd, addr, mttl); if (ret) { zlog_warn("ssmpingd_setsockopt failed"); - close(fd); return -1; } diff --git a/pimd/pim_static.c b/pimd/pim_static.c index f4320f0c62..b9effa26d1 100644 --- a/pimd/pim_static.c +++ b/pimd/pim_static.c @@ -44,7 +44,7 @@ static struct static_route *static_route_new(ifindex_t iif, ifindex_t oif, s_route->c_oil.oil_ref_count = 1; *oil_origin(&s_route->c_oil) = source; *oil_mcastgrp(&s_route->c_oil) = group; - *oil_parent(&s_route->c_oil) = iif; + *oil_incoming_vif(&s_route->c_oil) = iif; oil_if_set(&s_route->c_oil, oif, 1); s_route->c_oil.oif_creation[oif] = pim_time_monotonic_sec(); diff --git a/pimd/pim_str.c b/pimd/pim_str.c deleted file mode 100644 index a0453769e9..0000000000 --- a/pimd/pim_str.c +++ /dev/null @@ -1,30 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * PIM for Quagga - * Copyright (C) 2008 Everton da Silva Marques - */ - -#include <zebra.h> - -#include <stdio.h> -#include <errno.h> -#include <string.h> - -#include "log.h" - -#include "pim_str.h" - -void pim_addr_dump(const char *onfail, struct prefix *p, char *buf, - int buf_size) -{ - int save_errno = errno; - - if (!inet_ntop(p->family, &p->u.prefix, buf, buf_size)) { - zlog_warn("pim_addr_dump: inet_ntop(buf_size=%d): errno=%d: %s", - buf_size, errno, safe_strerror(errno)); - if (onfail) - snprintf(buf, buf_size, "%s", onfail); - } - - errno = save_errno; -} diff --git a/pimd/pim_str.h b/pimd/pim_str.h index cc27d23c0e..029a9f49ce 100644 --- a/pimd/pim_str.h +++ b/pimd/pim_str.h @@ -35,8 +35,6 @@ #define pim_inet4_dump prefix_mcast_inet4_dump -void pim_addr_dump(const char *onfail, struct prefix *p, char *buf, - int buf_size); void pim_inet4_dump(const char *onfail, struct in_addr addr, char *buf, int buf_size); diff --git a/pimd/pim_tib.c b/pimd/pim_tib.c index 6ffea868d8..4081786c1e 100644 --- a/pimd/pim_tib.c +++ b/pimd/pim_tib.c @@ -163,4 +163,6 @@ void tib_sg_gm_prune(struct pim_instance *pim, pim_sgaddr sg, per-interface (S,G) state. */ pim_ifchannel_local_membership_del(oif, &sg); + + pim_channel_oil_del(*oilp, __func__); } diff --git a/pimd/pim_tlv.c b/pimd/pim_tlv.c index 80d60b8628..c463fa227c 100644 --- a/pimd/pim_tlv.c +++ b/pimd/pim_tlv.c @@ -217,18 +217,17 @@ int pim_encode_addr_group(uint8_t *buf, afi_t afi, int bidir, int scope, uint8_t *pim_tlv_append_addrlist_ucast(uint8_t *buf, const uint8_t *buf_pastend, struct interface *ifp, int family) { - struct listnode *node; uint16_t option_len = 0; uint8_t *curr; size_t uel; - struct list *ifconnected = ifp->connected; + struct connected *ifc; struct pim_interface *pim_ifp = ifp->info; pim_addr addr; - node = listhead(ifconnected); + ifc = if_connected_first(ifp->connected); /* Empty address list ? */ - if (!node) { + if (!ifc) { return buf; } @@ -239,8 +238,7 @@ uint8_t *pim_tlv_append_addrlist_ucast(uint8_t *buf, const uint8_t *buf_pastend, /* Scan secondary address list */ curr = buf + 4; /* skip T and L */ - for (; node; node = listnextnode(node)) { - struct connected *ifc = listgetdata(node); + for (; ifc; ifc = if_connected_next(ifp->connected, ifc)) { struct prefix *p = ifc->address; int l_encode; diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c index 8fa7b7cf96..45c4df0e7e 100644 --- a/pimd/pim_upstream.c +++ b/pimd/pim_upstream.c @@ -17,6 +17,7 @@ #include "jhash.h" #include "wheel.h" #include "network.h" +#include "frrdistance.h" #include "pimd.h" #include "pim_pim.h" @@ -181,7 +182,7 @@ struct pim_upstream *pim_upstream_del(struct pim_instance *pim, if (PIM_DEBUG_PIM_TRACE) zlog_debug( - "%s(%s): Delete %s[%s] ref count: %d , flags: %d c_oil ref count %d (Pre decrement)", + "%s(%s): Delete %s[%s] ref count: %d, flags: %d c_oil ref count %d (Pre decrement)", __func__, name, up->sg_str, pim->vrf->name, up->ref_count, up->flags, up->channel_oil->oil_ref_count); @@ -662,10 +663,9 @@ void pim_upstream_update_use_rpt(struct pim_upstream *up, new_use_rpt = !!PIM_UPSTREAM_FLAG_TEST_USE_RPT(up->flags); if (old_use_rpt != new_use_rpt) { if (PIM_DEBUG_PIM_EVENTS) - zlog_debug("%s switched from %s to %s", - up->sg_str, - old_use_rpt?"RPT":"SPT", - new_use_rpt?"RPT":"SPT"); + zlog_debug("%s switched from %s to %s", up->sg_str, + old_use_rpt ? "RPT" : "SPT", + new_use_rpt ? "RPT" : "SPT"); if (update_mroute) pim_upstream_mroute_add(up->channel_oil, __func__); } @@ -904,14 +904,21 @@ static struct pim_upstream *pim_upstream_new(struct pim_instance *pim, false /*update_mroute*/); pim_upstream_mroute_iif_update(up->channel_oil, __func__); - if (PIM_UPSTREAM_FLAG_TEST_SRC_NOCACHE(up->flags)) + if (PIM_UPSTREAM_FLAG_TEST_SRC_NOCACHE(up->flags)) { + /* + * Set the right RPF so that future changes will + * be right + */ + (void)pim_rpf_update(pim, up, NULL, __func__); pim_upstream_keep_alive_timer_start( up, pim->keep_alive_time); + } } else if (!pim_addr_is_any(up->upstream_addr)) { pim_upstream_update_use_rpt(up, false /*update_mroute*/); rpf_result = pim_rpf_update(pim, up, NULL, __func__); if (rpf_result == PIM_RPF_FAILURE) { + up->channel_oil->oil_inherited_rescan = 1; if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s: Attempting to create upstream(%s), Unable to RPF for source", @@ -1713,6 +1720,7 @@ static void pim_upstream_register_stop_timer(struct event *t) zlog_debug("%s: up %s RPF is not present", __func__, up->sg_str); up->reg_state = PIM_REG_NOINFO; + PIM_UPSTREAM_FLAG_UNSET_FHR(up->flags); return; } @@ -1964,6 +1972,7 @@ static bool pim_upstream_kat_start_ok(struct pim_upstream *up) struct channel_oil *c_oil = up->channel_oil; struct interface *ifp = up->rpf.source_nexthop.interface; struct pim_interface *pim_ifp; + struct pim_instance *pim = up->channel_oil->pim; /* "iif == RPF_interface(S)" check is not easy to do as the info * we get from the kernel/ASIC is really a "lookup/key hit". @@ -1974,7 +1983,7 @@ static bool pim_upstream_kat_start_ok(struct pim_upstream *up) return false; pim_ifp = ifp->info; - if (pim_ifp->mroute_vif_index != *oil_parent(c_oil)) + if (pim_ifp->mroute_vif_index != *oil_incoming_vif(c_oil)) return false; if (pim_if_connected_to_source(up->rpf.source_nexthop.interface, @@ -1983,8 +1992,9 @@ static bool pim_upstream_kat_start_ok(struct pim_upstream *up) } if ((up->join_state == PIM_UPSTREAM_JOINED) - && !pim_upstream_empty_inherited_olist(up)) { - return true; + && !pim_upstream_empty_inherited_olist(up)) { + if (I_am_RP(pim, up->sg.grp)) + return true; } return false; @@ -2056,7 +2066,7 @@ static void pim_upstream_sg_running(void *arg) // No packet can have arrived here if this is the case if (!up->channel_oil->installed) { if (PIM_DEBUG_TRACE) - zlog_debug("%s: %s%s is not installed in mroute", + zlog_debug("%s: %s[%s] is not installed in mroute", __func__, up->sg_str, pim->vrf->name); return; } diff --git a/pimd/pim_vxlan.c b/pimd/pim_vxlan.c index 8df3c90f00..06bd394167 100644 --- a/pimd/pim_vxlan.c +++ b/pimd/pim_vxlan.c @@ -32,6 +32,41 @@ static void pim_vxlan_work_timer_setup(bool start); static void pim_vxlan_set_peerlink_rif(struct pim_instance *pim, struct interface *ifp); +/* + * The rp info has gone from no path to having a + * path. Let's immediately send out the null pim register + * as that else we will be sitting for up to 60 seconds waiting + * for it too pop. Which is not cool. + */ +void pim_vxlan_rp_info_is_alive(struct pim_instance *pim, + struct pim_rpf *rpg_changed) +{ + struct listnode *listnode; + struct pim_vxlan_sg *vxlan_sg; + struct pim_rpf *rpg; + + /* + * No vxlan here, move along, nothing to see + */ + if (!vxlan_info.work_list) + return; + + for (listnode = vxlan_info.work_list->head; listnode; + listnode = listnode->next) { + vxlan_sg = listgetdata(listnode); + + rpg = RP(pim, vxlan_sg->up->sg.grp); + + /* + * If the rp is the same we should send + */ + if (rpg == rpg_changed) { + zlog_debug("VXLAN RP INFO is alive sending"); + pim_null_register_send(vxlan_sg->up); + } + } +} + /*************************** vxlan work list ********************************** * A work list is maintained for staggered generation of pim null register * messages for vxlan SG entries that are in a reg_join state. @@ -66,6 +101,7 @@ static void pim_vxlan_do_reg_work(void) for (; listnode; listnode = listnode->next) { vxlan_sg = (struct pim_vxlan_sg *)listnode->data; + if (vxlan_sg->up && (vxlan_sg->up->reg_state == PIM_REG_JOIN)) { if (PIM_DEBUG_VXLAN) zlog_debug("vxlan SG %s periodic NULL register", @@ -1174,6 +1210,9 @@ void pim_vxlan_exit(struct pim_instance *pim) { hash_clean_and_free(&pim->vxlan.sg_hash, (void (*)(void *))pim_vxlan_sg_del_item); + + if (vxlan_info.work_list) + list_delete(&vxlan_info.work_list); } void pim_vxlan_terminate(void) diff --git a/pimd/pim_vxlan.h b/pimd/pim_vxlan.h index 9a135ca6b8..5039bf6540 100644 --- a/pimd/pim_vxlan.h +++ b/pimd/pim_vxlan.h @@ -135,6 +135,9 @@ extern bool pim_vxlan_do_mlag_reg(void); extern void pim_vxlan_inherit_mlag_flags(struct pim_instance *pim, struct pim_upstream *up, bool inherit); +extern void pim_vxlan_rp_info_is_alive(struct pim_instance *pim, + struct pim_rpf *rpg_changed); + /* Shutdown of PIM stop the thread */ extern void pim_vxlan_terminate(void); #endif /* PIM_VXLAN_H */ diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c index 92dcbf9d1d..1da3084264 100644 --- a/pimd/pim_zebra.c +++ b/pimd/pim_zebra.c @@ -51,49 +51,15 @@ static int pim_router_id_update_zebra(ZAPI_CALLBACK_ARGS) return 0; } -static int pim_zebra_interface_vrf_update(ZAPI_CALLBACK_ARGS) -{ - struct interface *ifp; - vrf_id_t new_vrf_id; - struct pim_instance *pim; - struct pim_interface *pim_ifp; - - ifp = zebra_interface_vrf_update_read(zclient->ibuf, vrf_id, - &new_vrf_id); - if (!ifp) - return 0; - - if (PIM_DEBUG_ZEBRA) - zlog_debug("%s: %s updating from %u to %u", __func__, ifp->name, - vrf_id, new_vrf_id); - - pim = pim_get_pim_instance(new_vrf_id); - if (!pim) - return 0; - - if_update_to_new_vrf(ifp, new_vrf_id); - - pim_ifp = ifp->info; - if (!pim_ifp) - return 0; - - pim_ifp->pim->mcast_if_count--; - pim_ifp->pim = pim; - pim_ifp->pim->mcast_if_count++; - - return 0; -} - #ifdef PIM_DEBUG_IFADDR_DUMP static void dump_if_address(struct interface *ifp) { struct connected *ifc; - struct listnode *node; zlog_debug("%s %s: interface %s addresses:", __FILE__, __func__, ifp->name); - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { + frr_each (if_connected, ifp->connected, ifc) { struct prefix *p = ifc->address; if (p->family != AF_INET) @@ -461,9 +427,7 @@ static zclient_handler *const pim_handlers[] = { [ZEBRA_INTERFACE_ADDRESS_ADD] = pim_zebra_if_address_add, [ZEBRA_INTERFACE_ADDRESS_DELETE] = pim_zebra_if_address_del, - [ZEBRA_NEXTHOP_UPDATE] = pim_parse_nexthop_update, [ZEBRA_ROUTER_ID_UPDATE] = pim_router_id_update_zebra, - [ZEBRA_INTERFACE_VRF_UPDATE] = pim_zebra_interface_vrf_update, #if PIM_IPV == 4 [ZEBRA_VXLAN_SG_ADD] = pim_zebra_vxlan_sg_proc, @@ -483,6 +447,7 @@ void pim_zebra_init(void) zclient->zebra_capabilities = pim_zebra_capabilities; zclient->zebra_connected = pim_zebra_connected; + zclient->nexthop_update = pim_nexthop_update; zclient_init(zclient, ZEBRA_ROUTE_PIM, 0, &pimd_privs); if (PIM_DEBUG_PIM_TRACE) { diff --git a/pimd/pim_zlookup.c b/pimd/pim_zlookup.c index 05a72269d6..c19119fa47 100644 --- a/pimd/pim_zlookup.c +++ b/pimd/pim_zlookup.c @@ -122,10 +122,7 @@ void zclient_lookup_free(void) void zclient_lookup_new(void) { - struct zclient_options options = zclient_options_default; - options.synchronous = true; - - zlookup = zclient_new(router->master, &options, NULL, 0); + zlookup = zclient_new(router->master, &zclient_options_sync, NULL, 0); if (!zlookup) { flog_err(EC_LIB_ZAPI_SOCKET, "%s: zclient_new() failure", __func__); @@ -497,14 +494,14 @@ int pim_zlookup_sg_statistics(struct channel_oil *c_oil) int ret; pim_sgaddr more = {}; struct interface *ifp = - pim_if_find_by_vif_index(c_oil->pim, *oil_parent(c_oil)); + pim_if_find_by_vif_index(c_oil->pim, *oil_incoming_vif(c_oil)); if (PIM_DEBUG_ZEBRA) { more.src = *oil_origin(c_oil); more.grp = *oil_mcastgrp(c_oil); - zlog_debug( - "Sending Request for New Channel Oil Information%pSG VIIF %d(%s)", - &more, *oil_parent(c_oil), c_oil->pim->vrf->name); + zlog_debug("Sending Request for New Channel Oil Information%pSG VIIF %d(%s:%s)", + &more, *oil_incoming_vif(c_oil), + ifp ? ifp->name : "Unknown", c_oil->pim->vrf->name); } if (!ifp) diff --git a/pimd/subdir.am b/pimd/subdir.am index 9a7901ec3f..1e787a3525 100644 --- a/pimd/subdir.am +++ b/pimd/subdir.am @@ -43,7 +43,6 @@ pim_common = \ pimd/pim_ssm.c \ pimd/pim_ssmpingd.c \ pimd/pim_static.c \ - pimd/pim_str.c \ pimd/pim_tib.c \ pimd/pim_time.c \ pimd/pim_tlv.c \ diff --git a/python/xref2vtysh.py b/python/xref2vtysh.py index 6dd5c8866e..75fff8ddd9 100644 --- a/python/xref2vtysh.py +++ b/python/xref2vtysh.py @@ -36,8 +36,8 @@ "lib/filter.c": "VTYSH_ACL", "lib/filter_cli.c": "VTYSH_ACL", "lib/if.c": "VTYSH_INTERFACE", - "lib/keychain.c": "VTYSH_RIPD|VTYSH_EIGRPD|VTYSH_OSPF6D", - "lib/mgmt_be_client.c": "VTYSH_STATICD", + "lib/keychain.c": "VTYSH_KEYS", + "lib/mgmt_be_client.c": "VTYSH_STATICD|VTYSH_ZEBRA", "lib/mgmt_fe_client.c": "VTYSH_MGMTD", "lib/lib_vty.c": "VTYSH_ALL", "lib/log_vty.c": "VTYSH_ALL", diff --git a/redhat/frr.spec.in b/redhat/frr.spec.in index 4dec84b8fb..c2391206b7 100644 --- a/redhat/frr.spec.in +++ b/redhat/frr.spec.in @@ -180,11 +180,12 @@ BuildRequires: flex BuildRequires: gcc BuildRequires: json-c-devel BuildRequires: libcap-devel +BuildRequires: protobuf-c-devel BuildRequires: make BuildRequires: ncurses-devel BuildRequires: readline-devel BuildRequires: texinfo -BuildRequires: libyang2-devel +BuildRequires: libyang-devel >= 2.1.80 %if 0%{?rhel} && 0%{?rhel} < 7 #python27-devel is available from ius community repo for RedHat/CentOS 6 BuildRequires: python27-devel @@ -779,8 +780,6 @@ sed -i 's/ -M rpki//' %{_sysconfdir}/frr/daemons %{_libdir}/lib*.so %dir %{_includedir}/%{name} %{_includedir}/%{name}/*.h -%dir %{_includedir}/%{name}/mgmtd -%{_includedir}/%{name}/mgmtd/*.h %dir %{_includedir}/%{name}/ospfd %{_includedir}/%{name}/ospfd/*.h %if %{with_bfdd} @@ -799,9 +798,66 @@ sed -i 's/ -M rpki//' %{_sysconfdir}/frr/daemons %changelog -* Tue Feb 07 2023 Martin Winter <mwinter@opensourcerouting.org> - %{version} - -* Tue Feb 07 2023 Donatas Abraitis <donatas@opensourcerouting.org> - 8.5 +* Tue Oct 10 2023 Donatas Abraitis <donatas@opensourcerouting.org> - %{version} + +* Mon Oct 09 2023 Donatas Abraitis <donatas@opensourcerouting.org> - 9.1 +- Major highlights: +- OSPFv2 HMAC-SHA Cryptographic Authentication +- BGP MAC-VRF Site-Of-Origin support +- BGP Dynamic capability support +- IS-IS SRv6 uSID support (RFC 9352) +- Change next-hop resolution via the default route for a traditional profile +- Add support for VLAN, ECN, DSCP mangling/filtering +- Zebra support for route replace semantics in FPM +- New command for BGP `neighbor x addpath-tx-best-selected` +- New command for BGP `mpls bgp l3vpn-multi-domain-switching` +- A couple more new BGP route-map commands for as-path, communities manipulation + +* Tue Jun 06 2023 Jafar Al-Gharaibeh <jafar@atcorp.com> - 9.0 +- Major highlights: +- Centralized Management Daemon (mgmtd) +- Switched to libyang minimum version 2.1.80 +- Memory footprint for BGP reduced drastically +- Add BGP `neighbor path-attribute treat-as-withdraw` command +- Add BGP ASN dot notation support (RFC 5396) +- Add BGP Software Version capability +- Allow BGP peering via 127.0.0.0/8 +- Deprecate BGP `internet` community - this is the Cisco-specific community, which is never been RFC-defined and confusing +- Implement `match source-protocol` for BGP route maps +- Implement BGP Node Target extended communities (draft-ietf-idr-node-target-ext-comm) +- Implement Flex-Algo for SR-MPLS (RFC 9350) +- Add support for IS-IS `advertise-passive-only` +- Add IS-IS `affinity-map` support +- Add the `graceful-restart hello-delay` OSPFv2/OSPFv3 command +- Add the `ipv6 mld join` PIMv6 command +- Add `allow-ecmp x` RIP/RIPng command +- Add BFD support for RIP +- For a full list of new features and bug fixes, please refer to: +- https://frrouting.org/release/ + +* Fri Mar 10 2023 Jafar Al-Gharaibeh <jafar@atcorp.com> - 8.5 +- Major Highlights: +- Add support for per-VRF SRv6 SID +- Add BGP labeled-unicast Add-Path functionality +- Implementation of SNMP BGP4v2-MIB (IPv6 support) for better network management and monitoring +- Add BGP new command neighbor path-attribute discard +- Add BGP new command neighbor path-attribute treat-as-withdraw +- Implement L3 route-target auto/wildcard configuration +- Implement BGP ACCEPT_OWN Community Attribute (rfc7611) +- Implement The Accumulated IGP Metric Attribute for BGP (rfc7311) +- Implement graceful-shutdown command per neighbor +- Add BGP new command to configure TCP keepalives for a peer bgp tcp-keepalive +- Traffic control (TC) ZAPI implementation +- SRv6 uSID (microSID) implementation +- Start deprecating start-shell, ssh, and telnet commands due to security reasons +- Add VRRPv3 an ability to disable IPv4 pseudo-header checksum +- BFD integration for static routes +- Allow protocols to configure BFD sessions with automatic source selection +- Allow zero-length opaque LSAs for OSPF (rfc5250) +- Add ISIS new command set-overload-bit on-startup +- PIMv6 BSM support +- For a full list of new features and bug fixes, please refer to: +- https://frrouting.org/release/ * Tue Nov 01 2022 Jafar Al-Gharaibeh <jafar@atcorp.com> - 8.4 - New BGP command (neighbor PEER soo) to configure SoO to prevent routing loops and suboptimal routing on dual-homed sites. diff --git a/ripd/rip_cli.c b/ripd/rip_cli.c index 097c708ab1..d545e692cb 100644 --- a/ripd/rip_cli.c +++ b/ripd/rip_cli.c @@ -73,7 +73,7 @@ void cli_show_router_rip(struct vty *vty, const struct lyd_node *dnode, { const char *vrf_name; - vrf_name = yang_dnode_get_string(dnode, "./vrf"); + vrf_name = yang_dnode_get_string(dnode, "vrf"); vty_out(vty, "!\n"); vty_out(vty, "router rip"); @@ -255,11 +255,11 @@ void cli_show_rip_distance_source(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { vty_out(vty, " distance %s %s", - yang_dnode_get_string(dnode, "./distance"), - yang_dnode_get_string(dnode, "./prefix")); - if (yang_dnode_exists(dnode, "./access-list")) + yang_dnode_get_string(dnode, "distance"), + yang_dnode_get_string(dnode, "prefix")); + if (yang_dnode_exists(dnode, "access-list")) vty_out(vty, " %s", - yang_dnode_get_string(dnode, "./access-list")); + yang_dnode_get_string(dnode, "access-list")); vty_out(vty, "\n"); } @@ -362,12 +362,12 @@ void cli_show_rip_offset_list(struct vty *vty, const struct lyd_node *dnode, { const char *interface; - interface = yang_dnode_get_string(dnode, "./interface"); + interface = yang_dnode_get_string(dnode, "interface"); vty_out(vty, " offset-list %s %s %s", - yang_dnode_get_string(dnode, "./access-list"), - yang_dnode_get_string(dnode, "./direction"), - yang_dnode_get_string(dnode, "./metric")); + yang_dnode_get_string(dnode, "access-list"), + yang_dnode_get_string(dnode, "direction"), + yang_dnode_get_string(dnode, "metric")); if (!strmatch(interface, "*")) vty_out(vty, " %s", interface); vty_out(vty, "\n"); @@ -475,13 +475,13 @@ void cli_show_rip_redistribute(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { vty_out(vty, " redistribute %s", - yang_dnode_get_string(dnode, "./protocol")); - if (yang_dnode_exists(dnode, "./metric")) + yang_dnode_get_string(dnode, "protocol")); + if (yang_dnode_exists(dnode, "metric")) vty_out(vty, " metric %s", - yang_dnode_get_string(dnode, "./metric")); - if (yang_dnode_exists(dnode, "./route-map")) + yang_dnode_get_string(dnode, "metric")); + if (yang_dnode_exists(dnode, "route-map")) vty_out(vty, " route-map %s", - yang_dnode_get_string(dnode, "./route-map")); + yang_dnode_get_string(dnode, "route-map")); vty_out(vty, "\n"); } @@ -550,9 +550,9 @@ void cli_show_rip_timers(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { vty_out(vty, " timers basic %s %s %s\n", - yang_dnode_get_string(dnode, "./update-interval"), - yang_dnode_get_string(dnode, "./holddown-interval"), - yang_dnode_get_string(dnode, "./flush-interval")); + yang_dnode_get_string(dnode, "update-interval"), + yang_dnode_get_string(dnode, "holddown-interval"), + yang_dnode_get_string(dnode, "flush-interval")); } /* @@ -591,7 +591,7 @@ void cli_show_rip_version(struct vty *vty, const struct lyd_node *dnode, * We have only one "version" command and three possible combinations of * send/receive values. */ - switch (yang_dnode_get_enum(dnode, "./receive")) { + switch (yang_dnode_get_enum(dnode, "receive")) { case RI_RIP_VERSION_1: vty_out(vty, " version 1\n"); break; @@ -912,7 +912,7 @@ void cli_show_ip_rip_authentication_scheme(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - switch (yang_dnode_get_enum(dnode, "./mode")) { + switch (yang_dnode_get_enum(dnode, "mode")) { case RIP_NO_AUTH: vty_out(vty, " no ip rip authentication mode\n"); break; @@ -922,8 +922,8 @@ void cli_show_ip_rip_authentication_scheme(struct vty *vty, case RIP_AUTH_MD5: vty_out(vty, " ip rip authentication mode md5"); if (show_defaults - || !yang_dnode_is_default(dnode, "./md5-auth-length")) { - if (yang_dnode_get_enum(dnode, "./md5-auth-length") + || !yang_dnode_is_default(dnode, "md5-auth-length")) { + if (yang_dnode_get_enum(dnode, "md5-auth-length") == RIP_AUTH_MD5_SIZE) vty_out(vty, " auth-length rfc"); else diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c index b58015a67d..65afce8cb7 100644 --- a/ripd/rip_interface.c +++ b/ripd/rip_interface.c @@ -128,14 +128,12 @@ static void rip_request_interface_send(struct interface *ifp, uint8_t version) /* RIPv1 and non multicast interface. */ if (if_is_pointopoint(ifp) || if_is_broadcast(ifp)) { - struct listnode *cnode, *cnnode; struct connected *connected; if (IS_RIP_DEBUG_EVENT) zlog_debug("broadcast request to %s", ifp->name); - for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, - connected)) { + frr_each (if_connected, ifp->connected, connected) { if (connected->address->family != AF_INET) continue; @@ -197,14 +195,13 @@ static void rip_request_interface(struct interface *ifp) /* Multicast packet receive socket. */ static int rip_multicast_join(struct interface *ifp, int sock) { - struct listnode *cnode; struct connected *ifc; if (if_is_operative(ifp) && if_is_multicast(ifp)) { if (IS_RIP_DEBUG_EVENT) zlog_debug("multicast join at %s", ifp->name); - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, ifc)) { + frr_each (if_connected, ifp->connected, ifc) { struct prefix_ipv4 *p; struct in_addr group; @@ -228,14 +225,13 @@ static int rip_multicast_join(struct interface *ifp, int sock) /* Leave from multicast group. */ static void rip_multicast_leave(struct interface *ifp, int sock) { - struct listnode *cnode; struct connected *connected; if (if_is_up(ifp) && if_is_multicast(ifp)) { if (IS_RIP_DEBUG_EVENT) zlog_debug("multicast leave from %s", ifp->name); - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { + frr_each (if_connected, ifp->connected, connected) { struct prefix_ipv4 *p; struct in_addr group; @@ -256,11 +252,10 @@ static void rip_multicast_leave(struct interface *ifp, int sock) /* Is there and address on interface that I could use ? */ static int rip_if_ipv4_address_check(struct interface *ifp) { - struct listnode *nn; struct connected *connected; int count = 0; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, nn, connected)) { + frr_each (if_connected, ifp->connected, connected) { struct prefix *p; p = connected->address; @@ -279,10 +274,9 @@ int if_check_address(struct rip *rip, struct in_addr addr) struct interface *ifp; FOR_ALL_INTERFACES (rip->vrf, ifp) { - struct listnode *cnode; struct connected *connected; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { + frr_each (if_connected, ifp->connected, connected) { struct prefix_ipv4 *p; p = (struct prefix_ipv4 *)connected->address; @@ -383,31 +377,6 @@ static int rip_ifp_destroy(struct interface *ifp) return 0; } -/* VRF update for an interface. */ -int rip_interface_vrf_update(ZAPI_CALLBACK_ARGS) -{ - struct interface *ifp; - vrf_id_t new_vrf_id; - - ifp = zebra_interface_vrf_update_read(zclient->ibuf, vrf_id, - &new_vrf_id); - if (!ifp) - return 0; - - if (IS_RIP_DEBUG_ZEBRA) { - struct vrf *nvrf = vrf_lookup_by_id(new_vrf_id); - - zlog_debug("interface %s VRF change vrf %s(%u) new vrf %s(%u)", - ifp->name, ifp->vrf->name, vrf_id, VRF_LOGNAME(nvrf), - new_vrf_id); - } - - if_update_to_new_vrf(ifp, new_vrf_id); - rip_interface_sync(ifp); - - return 0; -} - static void rip_interface_clean(struct rip_interface *ri) { ri->enable_network = 0; @@ -621,14 +590,13 @@ static int rip_enable_network_lookup_if(struct interface *ifp) { struct rip_interface *ri = ifp->info; struct rip *rip = ri->rip; - struct listnode *node, *nnode; struct connected *connected; struct prefix_ipv4 address; if (!rip) return -1; - for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, connected)) { + frr_each (if_connected, ifp->connected, connected) { struct prefix *p; struct route_node *n; @@ -805,14 +773,13 @@ static void rip_connect_set(struct interface *ifp, int set) { struct rip_interface *ri = ifp->info; struct rip *rip = ri->rip; - struct listnode *node, *nnode; struct connected *connected; struct prefix_ipv4 address; struct nexthop nh; memset(&nh, 0, sizeof(nh)); - for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, connected)) { + frr_each (if_connected, ifp->connected, connected) { struct prefix *p; p = connected->address; @@ -1143,6 +1110,8 @@ void rip_if_init(void) /* Install interface node. */ if_cmd_init_default(); - if_zapi_callbacks(rip_ifp_create, rip_ifp_up, - rip_ifp_down, rip_ifp_destroy); + hook_register_prio(if_real, 0, rip_ifp_create); + hook_register_prio(if_up, 0, rip_ifp_up); + hook_register_prio(if_down, 0, rip_ifp_down); + hook_register_prio(if_unreal, 0, rip_ifp_destroy); } diff --git a/ripd/rip_main.c b/ripd/rip_main.c index ac358ebbaf..cb23098a7e 100644 --- a/ripd/rip_main.c +++ b/ripd/rip_main.c @@ -67,12 +67,26 @@ static void sighup(void) /* SIGINT handler. */ static void sigint(void) { + struct vrf *vrf; + zlog_notice("Terminating on signal"); bfd_protocol_integration_set_shutdown(true); + + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { + if (!vrf->info) + continue; + + rip_clean(vrf->info); + } + rip_vrf_terminate(); if_rmap_terminate(); rip_zclient_stop(); + + route_map_finish(); + + keychain_terminate(); frr_fini(); exit(0); diff --git a/ripd/rip_nb_config.c b/ripd/rip_nb_config.c index 8d3b670596..8b9cc922ad 100644 --- a/ripd/rip_nb_config.c +++ b/ripd/rip_nb_config.c @@ -35,7 +35,7 @@ int ripd_instance_create(struct nb_cb_create_args *args) const char *vrf_name; int socket; - vrf_name = yang_dnode_get_string(args->dnode, "./vrf"); + vrf_name = yang_dnode_get_string(args->dnode, "vrf"); vrf = vrf_lookup_by_name(vrf_name); /* @@ -189,7 +189,7 @@ int ripd_instance_distance_source_create(struct nb_cb_create_args *args) if (args->event != NB_EV_APPLY) return NB_OK; - yang_dnode_get_ipv4p(&prefix, args->dnode, "./prefix"); + yang_dnode_get_ipv4p(&prefix, args->dnode, "prefix"); apply_mask_ipv4(&prefix); /* Get RIP distance node. */ @@ -395,7 +395,7 @@ int ripd_instance_offset_list_create(struct nb_cb_create_args *args) return NB_OK; rip = nb_running_get_entry(args->dnode, NULL, true); - ifname = yang_dnode_get_string(args->dnode, "./interface"); + ifname = yang_dnode_get_string(args->dnode, "interface"); offset = rip_offset_list_new(rip, ifname); nb_running_set_entry(args->dnode, offset); @@ -411,7 +411,7 @@ int ripd_instance_offset_list_destroy(struct nb_cb_destroy_args *args) if (args->event != NB_EV_APPLY) return NB_OK; - direct = yang_dnode_get_enum(args->dnode, "./direction"); + direct = yang_dnode_get_enum(args->dnode, "direction"); offset = nb_running_unset_entry(args->dnode); if (offset->direct[direct].alist_name) { @@ -560,7 +560,7 @@ int ripd_instance_redistribute_create(struct nb_cb_create_args *args) return NB_OK; rip = nb_running_get_entry(args->dnode, NULL, true); - type = yang_dnode_get_enum(args->dnode, "./protocol"); + type = yang_dnode_get_enum(args->dnode, "protocol"); rip->redist[type].enabled = true; @@ -576,7 +576,7 @@ int ripd_instance_redistribute_destroy(struct nb_cb_destroy_args *args) return NB_OK; rip = nb_running_get_entry(args->dnode, NULL, true); - type = yang_dnode_get_enum(args->dnode, "./protocol"); + type = yang_dnode_get_enum(args->dnode, "protocol"); rip->redist[type].enabled = false; if (rip->redist[type].route_map.name) { @@ -600,7 +600,7 @@ void ripd_instance_redistribute_apply_finish( int type; rip = nb_running_get_entry(args->dnode, NULL, true); - type = yang_dnode_get_enum(args->dnode, "./protocol"); + type = yang_dnode_get_enum(args->dnode, "protocol"); if (rip->enabled) rip_redistribute_conf_update(rip, type); @@ -1123,12 +1123,12 @@ int lib_interface_rip_bfd_create(struct nb_cb_create_args *args) ifp = nb_running_get_entry(args->dnode, NULL, true); ri = ifp->info; - ri->bfd.enabled = yang_dnode_get_bool(args->dnode, "./enable"); + ri->bfd.enabled = yang_dnode_get_bool(args->dnode, "enable"); XFREE(MTYPE_RIP_BFD_PROFILE, ri->bfd.profile); - if (yang_dnode_exists(args->dnode, "./profile")) + if (yang_dnode_exists(args->dnode, "profile")) ri->bfd.profile = XSTRDUP( MTYPE_RIP_BFD_PROFILE, - yang_dnode_get_string(args->dnode, "./profile")); + yang_dnode_get_string(args->dnode, "profile")); rip_bfd_interface_update(ri); diff --git a/ripd/rip_peer.c b/ripd/rip_peer.c index 3e8ddeccf2..7e848bee47 100644 --- a/ripd/rip_peer.c +++ b/ripd/rip_peer.c @@ -12,6 +12,7 @@ #include "frrevent.h" #include "memory.h" #include "table.h" +#include "frrdistance.h" #include "ripd/ripd.h" #include "ripd/rip_bfd.h" diff --git a/ripd/rip_snmp.c b/ripd/rip_snmp.c index 0e5d4d54c9..f6a7a82831 100644 --- a/ripd/rip_snmp.c +++ b/ripd/rip_snmp.c @@ -195,7 +195,7 @@ static int rip_snmp_ifaddr_del(struct connected *ifc) if (!rn) return 0; i = rn->info; - if (!strncmp(i->name, ifp->name, INTERFACE_NAMSIZ)) { + if (!strncmp(i->name, ifp->name, IFNAMSIZ)) { rn->info = NULL; route_unlock_node(rn); route_unlock_node(rn); diff --git a/ripd/rip_zebra.c b/ripd/rip_zebra.c index 5bf51c2f15..ce94e8e754 100644 --- a/ripd/rip_zebra.c +++ b/ripd/rip_zebra.c @@ -14,6 +14,8 @@ #include "log.h" #include "vrf.h" #include "bfd.h" +#include "frrdistance.h" + #include "ripd/ripd.h" #include "ripd/rip_debug.h" #include "ripd/rip_interface.h" @@ -222,7 +224,6 @@ static void rip_zebra_connected(struct zclient *zclient) zclient_handler *const rip_handlers[] = { [ZEBRA_INTERFACE_ADDRESS_ADD] = rip_interface_address_add, [ZEBRA_INTERFACE_ADDRESS_DELETE] = rip_interface_address_delete, - [ZEBRA_INTERFACE_VRF_UPDATE] = rip_interface_vrf_update, [ZEBRA_REDISTRIBUTE_ROUTE_ADD] = rip_zebra_read_route, [ZEBRA_REDISTRIBUTE_ROUTE_DEL] = rip_zebra_read_route, }; diff --git a/ripd/ripd.c b/ripd/ripd.c index 04a8cad560..d5df16c3a9 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -6,6 +6,11 @@ #include <zebra.h> +#ifdef CRYPTO_OPENSSL +#include <openssl/evp.h> +#include <openssl/hmac.h> +#endif + #include "vrf.h" #include "if.h" #include "command.h" @@ -31,6 +36,7 @@ #include "northbound_cli.h" #include "network.h" #include "lib/printfrr.h" +#include "frrdistance.h" #include "ripd/ripd.h" #include "ripd/rip_nb.h" @@ -403,7 +409,6 @@ static int rip_filter(int rip_distribute, struct prefix_ipv4 *p, static int rip_nexthop_check(struct rip *rip, struct in_addr *addr) { struct interface *ifp; - struct listnode *cnode; struct connected *ifc; struct prefix *p; @@ -411,7 +416,7 @@ static int rip_nexthop_check(struct rip *rip, struct in_addr *addr) invalid nexthop. */ FOR_ALL_INTERFACES (rip->vrf, ifp) { - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, ifc)) { + frr_each (if_connected, ifp->connected, ifc) { p = ifc->address; if (p->family == AF_INET @@ -2212,8 +2217,8 @@ void rip_output_process(struct connected *ifc, struct sockaddr_in *to, } if (!suppress && rinfo->type == ZEBRA_ROUTE_CONNECT) { - for (ALL_LIST_ELEMENTS_RO(ifc->ifp->connected, - listnode, tmp_ifc)) + frr_each (if_connected, ifc->ifp->connected, + tmp_ifc) if (prefix_match((struct prefix *)p, tmp_ifc->address)) { suppress = 1; @@ -2322,8 +2327,8 @@ void rip_output_process(struct connected *ifc, struct sockaddr_in *to, if (rinfo->metric_out != RIP_METRIC_INFINITY && rinfo->type == ZEBRA_ROUTE_CONNECT) { - for (ALL_LIST_ELEMENTS_RO(ifc->ifp->connected, - listnode, tmp_ifc)) + frr_each (if_connected, ifc->ifp->connected, + tmp_ifc) if (prefix_match((struct prefix *)p, tmp_ifc->address)) { rinfo->metric_out = @@ -2436,7 +2441,6 @@ static void rip_update_interface(struct connected *ifc, uint8_t version, /* Update send to all interface and neighbor. */ static void rip_update_process(struct rip *rip, int route_type) { - struct listnode *ifnode, *ifnnode; struct connected *connected; struct interface *ifp; struct rip_interface *ri; @@ -2475,8 +2479,7 @@ static void rip_update_process(struct rip *rip, int route_type) ifp->ifindex); /* send update on each connected network */ - for (ALL_LIST_ELEMENTS(ifp->connected, ifnode, ifnnode, - connected)) { + frr_each (if_connected, ifp->connected, connected) { if (connected->address->family == AF_INET) { if (vsend & RIPv1) rip_update_interface(connected, RIPv1, @@ -2767,7 +2770,6 @@ int rip_request_send(struct sockaddr_in *to, struct interface *ifp, { struct rte *rte; struct rip_packet rip_packet; - struct listnode *node, *nnode; memset(&rip_packet, 0, sizeof(rip_packet)); @@ -2791,7 +2793,7 @@ int rip_request_send(struct sockaddr_in *to, struct interface *ifp, } /* send request on each connected network */ - for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, connected)) { + frr_each (if_connected, ifp->connected, connected) { struct prefix_ipv4 *p; p = (struct prefix_ipv4 *)connected->address; @@ -3597,18 +3599,10 @@ static int rip_vrf_new(struct vrf *vrf) static int rip_vrf_delete(struct vrf *vrf) { - struct rip *rip; - if (IS_RIP_DEBUG_EVENT) zlog_debug("%s: VRF deleted: %s(%u)", __func__, vrf->name, vrf->vrf_id); - rip = rip_lookup_by_vrf_name(vrf->name); - if (!rip) - return 0; - - rip_clean(rip); - return 0; } diff --git a/ripngd/ripng_cli.c b/ripngd/ripng_cli.c index 9a96e29313..88b9354d95 100644 --- a/ripngd/ripng_cli.c +++ b/ripngd/ripng_cli.c @@ -73,7 +73,7 @@ void cli_show_router_ripng(struct vty *vty, const struct lyd_node *dnode, { const char *vrf_name; - vrf_name = yang_dnode_get_string(dnode, "./vrf"); + vrf_name = yang_dnode_get_string(dnode, "vrf"); vty_out(vty, "!\n"); vty_out(vty, "router ripng"); @@ -267,12 +267,12 @@ void cli_show_ripng_offset_list(struct vty *vty, const struct lyd_node *dnode, { const char *interface; - interface = yang_dnode_get_string(dnode, "./interface"); + interface = yang_dnode_get_string(dnode, "interface"); vty_out(vty, " offset-list %s %s %s", - yang_dnode_get_string(dnode, "./access-list"), - yang_dnode_get_string(dnode, "./direction"), - yang_dnode_get_string(dnode, "./metric")); + yang_dnode_get_string(dnode, "access-list"), + yang_dnode_get_string(dnode, "direction"), + yang_dnode_get_string(dnode, "metric")); if (!strmatch(interface, "*")) vty_out(vty, " %s", interface); vty_out(vty, "\n"); @@ -335,13 +335,13 @@ void cli_show_ripng_redistribute(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { vty_out(vty, " redistribute %s", - yang_dnode_get_string(dnode, "./protocol")); - if (yang_dnode_exists(dnode, "./metric")) + yang_dnode_get_string(dnode, "protocol")); + if (yang_dnode_exists(dnode, "metric")) vty_out(vty, " metric %s", - yang_dnode_get_string(dnode, "./metric")); - if (yang_dnode_exists(dnode, "./route-map")) + yang_dnode_get_string(dnode, "metric")); + if (yang_dnode_exists(dnode, "route-map")) vty_out(vty, " route-map %s", - yang_dnode_get_string(dnode, "./route-map")); + yang_dnode_get_string(dnode, "route-map")); vty_out(vty, "\n"); } @@ -435,9 +435,9 @@ void cli_show_ripng_timers(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { vty_out(vty, " timers basic %s %s %s\n", - yang_dnode_get_string(dnode, "./update-interval"), - yang_dnode_get_string(dnode, "./holddown-interval"), - yang_dnode_get_string(dnode, "./flush-interval")); + yang_dnode_get_string(dnode, "update-interval"), + yang_dnode_get_string(dnode, "holddown-interval"), + yang_dnode_get_string(dnode, "flush-interval")); } /* diff --git a/ripngd/ripng_interface.c b/ripngd/ripng_interface.c index 1d9d53e47a..35d92632a0 100644 --- a/ripngd/ripng_interface.c +++ b/ripngd/ripng_interface.c @@ -128,16 +128,15 @@ static int ripng_multicast_leave(struct interface *ifp, int sock) /* How many link local IPv6 address could be used on the interface ? */ static int ripng_if_ipv6_lladdress_check(struct interface *ifp) { - struct listnode *nn; struct connected *connected; int count = 0; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, nn, connected)) { + frr_each (if_connected, ifp->connected, connected) { struct prefix *p; p = connected->address; - if ((p->family == AF_INET6) - && IN6_IS_ADDR_LINKLOCAL(&p->u.prefix6)) + if ((p->family == AF_INET6) && + IN6_IS_ADDR_LINKLOCAL(&p->u.prefix6)) count++; } @@ -264,31 +263,6 @@ static int ripng_ifp_destroy(struct interface *ifp) return 0; } -/* VRF update for an interface. */ -int ripng_interface_vrf_update(ZAPI_CALLBACK_ARGS) -{ - struct interface *ifp; - vrf_id_t new_vrf_id; - - ifp = zebra_interface_vrf_update_read(zclient->ibuf, vrf_id, - &new_vrf_id); - if (!ifp) - return 0; - - if (IS_RIPNG_DEBUG_ZEBRA) { - struct vrf *nvrf = vrf_lookup_by_id(new_vrf_id); - - zlog_debug("interface %s VRF change vrf %s(%u) new vrf %s(%u)", - ifp->name, ifp->vrf->name, vrf_id, VRF_LOGNAME(nvrf), - new_vrf_id); - } - - if_update_to_new_vrf(ifp, new_vrf_id); - ripng_interface_sync(ifp); - - return 0; -} - void ripng_interface_clean(struct ripng *ripng) { struct interface *ifp; @@ -433,14 +407,13 @@ static int ripng_enable_network_lookup_if(struct interface *ifp) { struct ripng_interface *ri = ifp->info; struct ripng *ripng = ri->ripng; - struct listnode *node; struct connected *connected; struct prefix_ipv6 address; if (!ripng) return -1; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) { + frr_each (if_connected, ifp->connected, connected) { struct prefix *p; struct agg_node *n; @@ -615,11 +588,10 @@ static void ripng_connect_set(struct interface *ifp, int set) { struct ripng_interface *ri = ifp->info; struct ripng *ripng = ri->ripng; - struct listnode *node, *nnode; struct connected *connected; struct prefix_ipv6 address; - for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, connected)) { + frr_each (if_connected, ifp->connected, connected) { struct prefix *p; p = connected->address; @@ -634,9 +606,9 @@ static void ripng_connect_set(struct interface *ifp, int set) if (set) { /* Check once more whether this prefix is within a * "network IF_OR_PREF" one */ - if ((ripng_enable_if_lookup(ripng, connected->ifp->name) - >= 0) - || (ripng_enable_network_lookup2(connected) >= 0)) + if ((ripng_enable_if_lookup( + ripng, connected->ifp->name) >= 0) || + (ripng_enable_network_lookup2(connected) >= 0)) ripng_redistribute_add( ripng, ZEBRA_ROUTE_CONNECT, RIPNG_ROUTE_INTERFACE, &address, @@ -902,6 +874,8 @@ void ripng_if_init(void) /* Install interface node. */ if_cmd_init_default(); - if_zapi_callbacks(ripng_ifp_create, ripng_ifp_up, - ripng_ifp_down, ripng_ifp_destroy); + hook_register_prio(if_real, 0, ripng_ifp_create); + hook_register_prio(if_up, 0, ripng_ifp_up); + hook_register_prio(if_down, 0, ripng_ifp_down); + hook_register_prio(if_unreal, 0, ripng_ifp_destroy); } diff --git a/ripngd/ripng_main.c b/ripngd/ripng_main.c index 9933dae5cd..a799943be1 100644 --- a/ripngd/ripng_main.c +++ b/ripngd/ripng_main.c @@ -66,11 +66,23 @@ static void sighup(void) /* SIGINT handler. */ static void sigint(void) { + struct vrf *vrf; + zlog_notice("Terminating on signal"); + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { + if (!vrf->info) + continue; + + ripng_clean(vrf->info); + } + ripng_vrf_terminate(); if_rmap_terminate(); ripng_zebra_stop(); + + route_map_finish(); + frr_fini(); exit(0); } diff --git a/ripngd/ripng_nb_config.c b/ripngd/ripng_nb_config.c index 0b1bd68eca..6ce1c1e356 100644 --- a/ripngd/ripng_nb_config.c +++ b/ripngd/ripng_nb_config.c @@ -35,7 +35,7 @@ int ripngd_instance_create(struct nb_cb_create_args *args) const char *vrf_name; int socket; - vrf_name = yang_dnode_get_string(args->dnode, "./vrf"); + vrf_name = yang_dnode_get_string(args->dnode, "vrf"); vrf = vrf_lookup_by_name(vrf_name); /* @@ -262,7 +262,7 @@ int ripngd_instance_offset_list_create(struct nb_cb_create_args *args) return NB_OK; ripng = nb_running_get_entry(args->dnode, NULL, true); - ifname = yang_dnode_get_string(args->dnode, "./interface"); + ifname = yang_dnode_get_string(args->dnode, "interface"); offset = ripng_offset_list_new(ripng, ifname); nb_running_set_entry(args->dnode, offset); @@ -278,7 +278,7 @@ int ripngd_instance_offset_list_destroy(struct nb_cb_destroy_args *args) if (args->event != NB_EV_APPLY) return NB_OK; - direct = yang_dnode_get_enum(args->dnode, "./direction"); + direct = yang_dnode_get_enum(args->dnode, "direction"); offset = nb_running_unset_entry(args->dnode); if (offset->direct[direct].alist_name) { @@ -380,7 +380,7 @@ int ripngd_instance_redistribute_create(struct nb_cb_create_args *args) return NB_OK; ripng = nb_running_get_entry(args->dnode, NULL, true); - type = yang_dnode_get_enum(args->dnode, "./protocol"); + type = yang_dnode_get_enum(args->dnode, "protocol"); ripng->redist[type].enabled = true; @@ -396,7 +396,7 @@ int ripngd_instance_redistribute_destroy(struct nb_cb_destroy_args *args) return NB_OK; ripng = nb_running_get_entry(args->dnode, NULL, true); - type = yang_dnode_get_enum(args->dnode, "./protocol"); + type = yang_dnode_get_enum(args->dnode, "protocol"); ripng->redist[type].enabled = false; if (ripng->redist[type].route_map.name) { @@ -420,7 +420,7 @@ void ripngd_instance_redistribute_apply_finish( int type; ripng = nb_running_get_entry(args->dnode, NULL, true); - type = yang_dnode_get_enum(args->dnode, "./protocol"); + type = yang_dnode_get_enum(args->dnode, "protocol"); if (ripng->enabled) ripng_redistribute_conf_update(ripng, type); diff --git a/ripngd/ripng_offset.c b/ripngd/ripng_offset.c index ba3ba558af..d842f15a19 100644 --- a/ripngd/ripng_offset.c +++ b/ripngd/ripng_offset.c @@ -83,9 +83,8 @@ int ripng_offset_list_apply_in(struct ripng *ripng, struct prefix_ipv6 *p, alist = access_list_lookup(AFI_IP6, OFFSET_LIST_IN_NAME(offset)); - if (alist - && access_list_apply(alist, (struct prefix *)p) - == FILTER_PERMIT) { + if (alist && access_list_apply(alist, (struct prefix *)p) == + FILTER_PERMIT) { *metric += OFFSET_LIST_IN_METRIC(offset); return 1; } @@ -97,9 +96,8 @@ int ripng_offset_list_apply_in(struct ripng *ripng, struct prefix_ipv6 *p, alist = access_list_lookup(AFI_IP6, OFFSET_LIST_IN_NAME(offset)); - if (alist - && access_list_apply(alist, (struct prefix *)p) - == FILTER_PERMIT) { + if (alist && access_list_apply(alist, (struct prefix *)p) == + FILTER_PERMIT) { *metric += OFFSET_LIST_IN_METRIC(offset); return 1; } @@ -121,9 +119,8 @@ int ripng_offset_list_apply_out(struct ripng *ripng, struct prefix_ipv6 *p, alist = access_list_lookup(AFI_IP6, OFFSET_LIST_OUT_NAME(offset)); - if (alist - && access_list_apply(alist, (struct prefix *)p) - == FILTER_PERMIT) { + if (alist && access_list_apply(alist, (struct prefix *)p) == + FILTER_PERMIT) { *metric += OFFSET_LIST_OUT_METRIC(offset); return 1; } @@ -136,9 +133,8 @@ int ripng_offset_list_apply_out(struct ripng *ripng, struct prefix_ipv6 *p, alist = access_list_lookup(AFI_IP6, OFFSET_LIST_OUT_NAME(offset)); - if (alist - && access_list_apply(alist, (struct prefix *)p) - == FILTER_PERMIT) { + if (alist && access_list_apply(alist, (struct prefix *)p) == + FILTER_PERMIT) { *metric += OFFSET_LIST_OUT_METRIC(offset); return 1; } diff --git a/ripngd/ripng_peer.c b/ripngd/ripng_peer.c index 901b548a42..247bac4697 100644 --- a/ripngd/ripng_peer.c +++ b/ripngd/ripng_peer.c @@ -15,6 +15,7 @@ #include "linklist.h" #include "frrevent.h" #include "memory.h" +#include "frrdistance.h" #include "ripngd/ripngd.h" #include "ripngd/ripng_nexthop.h" diff --git a/ripngd/ripng_routemap.c b/ripngd/ripng_routemap.c index 3e6880b4df..b5f74be3f6 100644 --- a/ripngd/ripng_routemap.c +++ b/ripngd/ripng_routemap.c @@ -112,6 +112,70 @@ static const struct route_map_rule_cmd route_match_interface_cmd = { route_match_interface_free }; +/* match ipv6 address WORD */ + +static enum route_map_cmd_result_t +route_match_ipv6_address(void *rule, const struct prefix *prefix, void *object) +{ + struct access_list *alist; + + alist = access_list_lookup(AFI_IP6, (char *)rule); + if (access_list_apply(alist, prefix) != FILTER_DENY) + return RMAP_MATCH; + + return RMAP_NOMATCH; +} + +static void *route_match_ipv6_address_compile(const char *arg) +{ + return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); +} + +static void route_match_ipv6_address_free(void *rule) +{ + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); +} + +static const struct route_map_rule_cmd route_match_ipv6_address_cmd = { + "ipv6 address", + route_match_ipv6_address, + route_match_ipv6_address_compile, + route_match_ipv6_address_free +}; + +/* match ipv6 address prefix-list PREFIX_LIST */ + +static enum route_map_cmd_result_t +route_match_ipv6_address_prefix_list(void *rule, const struct prefix *prefix, + void *object) +{ + struct prefix_list *plist; + + plist = prefix_list_lookup(AFI_IP6, (char *)rule); + if (prefix_list_apply(plist, prefix) != PREFIX_DENY) + return RMAP_MATCH; + + return RMAP_NOMATCH; +} + +static void *route_match_ipv6_address_prefix_list_compile(const char *arg) +{ + return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); +} + +static void route_match_ipv6_address_prefix_list_free(void *rule) +{ + XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); +} + +static const struct route_map_rule_cmd + route_match_ipv6_address_prefix_list_cmd = { + "ipv6 address prefix-list", + route_match_ipv6_address_prefix_list, + route_match_ipv6_address_prefix_list_compile, + route_match_ipv6_address_prefix_list_free +}; + /* `match tag TAG' */ /* Match function return 1 if match is success else return zero. */ static enum route_map_cmd_result_t route_match_tag(void *rule, @@ -327,6 +391,12 @@ void ripng_route_map_init(void) route_map_match_interface_hook(generic_match_add); route_map_no_match_interface_hook(generic_match_delete); + route_map_match_ipv6_address_hook(generic_match_add); + route_map_no_match_ipv6_address_hook(generic_match_delete); + + route_map_match_ipv6_address_prefix_list_hook(generic_match_add); + route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete); + route_map_match_metric_hook(generic_match_add); route_map_no_match_metric_hook(generic_match_delete); @@ -344,6 +414,8 @@ void ripng_route_map_init(void) route_map_install_match(&route_match_metric_cmd); route_map_install_match(&route_match_interface_cmd); + route_map_install_match(&route_match_ipv6_address_cmd); + route_map_install_match(&route_match_ipv6_address_prefix_list_cmd); route_map_install_match(&route_match_tag_cmd); route_map_install_set(&route_set_metric_cmd); route_map_install_set(&route_set_ipv6_nexthop_local_cmd); diff --git a/ripngd/ripng_zebra.c b/ripngd/ripng_zebra.c index 49b8a197ad..bb5a880c02 100644 --- a/ripngd/ripng_zebra.c +++ b/ripngd/ripng_zebra.c @@ -222,7 +222,6 @@ static void ripng_zebra_connected(struct zclient *zclient) static zclient_handler *const ripng_handlers[] = { [ZEBRA_INTERFACE_ADDRESS_ADD] = ripng_interface_address_add, [ZEBRA_INTERFACE_ADDRESS_DELETE] = ripng_interface_address_delete, - [ZEBRA_INTERFACE_VRF_UPDATE] = ripng_interface_vrf_update, [ZEBRA_REDISTRIBUTE_ROUTE_ADD] = ripng_zebra_read_route, [ZEBRA_REDISTRIBUTE_ROUTE_DEL] = ripng_zebra_read_route, }; diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index 7269e76656..bb6ec02343 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -392,11 +392,10 @@ static void ripng_nexthop_rte(struct rte *rte, struct sockaddr_in6 *from, /* If ifp has same link-local address then return 1. */ static int ripng_lladdr_check(struct interface *ifp, struct in6_addr *addr) { - struct listnode *node; struct connected *connected; struct prefix *p; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) { + frr_each (if_connected, ifp->connected, connected) { p = connected->address; if (p->family == AF_INET6 @@ -612,8 +611,8 @@ struct ripng_info *ripng_ecmp_delete(struct ripng *ripng, */ EVENT_OFF(rinfo->t_garbage_collect); listnode_delete(list, rinfo); - if (ripng_route_rte(rinfo) - && CHECK_FLAG(rinfo->flags, RIPNG_RTF_FIB)) + if (ripng_route_rte(rinfo) && + CHECK_FLAG(rinfo->flags, RIPNG_RTF_FIB)) /* The ADD message implies the update. */ ripng_zebra_ipv6_add(ripng, rp); ripng_info_free(rinfo); @@ -629,8 +628,8 @@ struct ripng_info *ripng_ecmp_delete(struct ripng *ripng, RIPNG_TIMER_ON(rinfo->t_garbage_collect, ripng_garbage_collect, ripng->garbage_time); - if (ripng_route_rte(rinfo) - && CHECK_FLAG(rinfo->flags, RIPNG_RTF_FIB)) + if (ripng_route_rte(rinfo) && + CHECK_FLAG(rinfo->flags, RIPNG_RTF_FIB)) ripng_zebra_ipv6_delete(ripng, rp); } @@ -676,8 +675,7 @@ static int ripng_filter(int ripng_distribute, struct prefix_ipv6 *p, /* Input distribute-list filtering. */ if (ri->list[ripng_distribute]) { if (access_list_apply(ri->list[ripng_distribute], - (struct prefix *)p) - == FILTER_DENY) { + (struct prefix *)p) == FILTER_DENY) { if (IS_RIPNG_DEBUG_PACKET) zlog_debug("%pFX filtered by distribute %s", p, inout); @@ -686,8 +684,7 @@ static int ripng_filter(int ripng_distribute, struct prefix_ipv6 *p, } if (ri->prefix[ripng_distribute]) { if (prefix_list_apply(ri->prefix[ripng_distribute], - (struct prefix *)p) - == PREFIX_DENY) { + (struct prefix *)p) == PREFIX_DENY) { if (IS_RIPNG_DEBUG_PACKET) zlog_debug("%pFX filtered by prefix-list %s", p, inout); @@ -818,9 +815,8 @@ static void ripng_route_process(struct rte *rte, struct sockaddr_in6 *from, } } rte->tag = htons(newinfo.tag_out); /* XXX */ - rte->metric = - newinfo.metric_out; /* XXX: the routemap uses the - metric_out field */ + rte->metric = newinfo.metric_out; /* XXX: the routemap uses the + metric_out field */ } /* Once the entry has been validated, update the metric by @@ -1072,7 +1068,7 @@ void ripng_redistribute_delete(struct ripng *ripng, int type, int sub_type, /* Aggregate count decrement. */ ripng_aggregate_decrement(rp, rinfo); - rinfo->flags |= RIPNG_RTF_CHANGED; + SET_FLAG(rinfo->flags, RIPNG_RTF_CHANGED); if (IS_RIPNG_DEBUG_EVENT) zlog_debug( @@ -1111,7 +1107,7 @@ void ripng_redistribute_withdraw(struct ripng *ripng, int type) /* Aggregate count decrement. */ ripng_aggregate_decrement(rp, rinfo); - rinfo->flags |= RIPNG_RTF_CHANGED; + SET_FLAG(rinfo->flags, RIPNG_RTF_CHANGED); if (IS_RIPNG_DEBUG_EVENT) { struct prefix_ipv6 *p = @@ -1645,8 +1641,8 @@ void ripng_output_process(struct interface *ifp, struct sockaddr_in6 *to, continue; /* Changed route only output. */ - if (route_type == ripng_changed_route - && (!(rinfo->flags & RIPNG_RTF_CHANGED))) + if (route_type == ripng_changed_route && + (!CHECK_FLAG(rinfo->flags, RIPNG_RTF_CHANGED))) continue; /* Split horizon. */ @@ -1657,9 +1653,10 @@ void ripng_output_process(struct interface *ifp, struct sockaddr_in6 *to, for (ALL_LIST_ELEMENTS_RO(list, listnode, tmp_rinfo)) - if (tmp_rinfo->type == ZEBRA_ROUTE_RIPNG - && tmp_rinfo->ifindex - == ifp->ifindex) { + if (tmp_rinfo->type == + ZEBRA_ROUTE_RIPNG && + tmp_rinfo->ifindex == + ifp->ifindex) { suppress = 1; break; } @@ -1717,11 +1714,11 @@ void ripng_output_process(struct interface *ifp, struct sockaddr_in6 *to, /* If the route is not connected or localy generated one, use default-metric value */ - if (rinfo->type != ZEBRA_ROUTE_RIPNG - && rinfo->type - != ZEBRA_ROUTE_CONNECT - && rinfo->metric - != RIPNG_METRIC_INFINITY) + if (rinfo->type != ZEBRA_ROUTE_RIPNG && + rinfo->type != + ZEBRA_ROUTE_CONNECT && + rinfo->metric != + RIPNG_METRIC_INFINITY) rinfo->metric_out = ripng->default_metric; } @@ -1738,16 +1735,15 @@ void ripng_output_process(struct interface *ifp, struct sockaddr_in6 *to, /* Perform split-horizon with poisoned reverse * for RIPng routes. **/ - if (ri->split_horizon - == RIPNG_SPLIT_HORIZON_POISONED_REVERSE) { + if (ri->split_horizon == + RIPNG_SPLIT_HORIZON_POISONED_REVERSE) { struct ripng_info *tmp_rinfo = NULL; for (ALL_LIST_ELEMENTS_RO(list, listnode, tmp_rinfo)) - if ((tmp_rinfo->type - == ZEBRA_ROUTE_RIPNG) - && tmp_rinfo->ifindex - == ifp->ifindex) + if ((tmp_rinfo->type == + ZEBRA_ROUTE_RIPNG) && + tmp_rinfo->ifindex == ifp->ifindex) rinfo->metric_out = RIPNG_METRIC_INFINITY; } @@ -2624,17 +2620,10 @@ static int ripng_vrf_new(struct vrf *vrf) static int ripng_vrf_delete(struct vrf *vrf) { - struct ripng *ripng; - if (IS_RIPNG_DEBUG_EVENT) zlog_debug("%s: VRF deleted: %s(%u)", __func__, vrf->name, vrf->vrf_id); - ripng = ripng_lookup_by_vrf_name(vrf->name); - if (!ripng) - return 0; - - ripng_clean(ripng); return 0; } diff --git a/ripngd/ripngd.h b/ripngd/ripngd.h index c7468b6317..3a2bc0c9d3 100644 --- a/ripngd/ripngd.h +++ b/ripngd/ripngd.h @@ -413,7 +413,6 @@ extern int ripng_interface_add(ZAPI_CALLBACK_ARGS); extern int ripng_interface_delete(ZAPI_CALLBACK_ARGS); extern int ripng_interface_address_add(ZAPI_CALLBACK_ARGS); extern int ripng_interface_address_delete(ZAPI_CALLBACK_ARGS); -extern int ripng_interface_vrf_update(ZAPI_CALLBACK_ARGS); extern void ripng_interface_sync(struct interface *ifp); extern struct ripng *ripng_lookup_by_vrf_id(vrf_id_t vrf_id); diff --git a/sharpd/sharp_logpump.c b/sharpd/sharp_logpump.c index 5474e80b11..d02921f287 100644 --- a/sharpd/sharp_logpump.c +++ b/sharpd/sharp_logpump.c @@ -5,6 +5,7 @@ */ #include <zebra.h> +#include <sys/resource.h> #include "vty.h" #include "command.h" diff --git a/sharpd/sharp_main.c b/sharpd/sharp_main.c index fa85c2b448..1eba9037ae 100644 --- a/sharpd/sharp_main.c +++ b/sharpd/sharp_main.c @@ -54,6 +54,23 @@ struct zebra_privs_t sharp_privs = { struct option longopts[] = {{0}}; +struct sharp_global sg; + +static void sharp_global_init(void) +{ + memset(&sg, 0, sizeof(sg)); + sg.nhs = list_new(); + sg.nhs->del = (void (*)(void *))sharp_nh_tracker_free; + sg.ted = NULL; + sg.srv6_locators = list_new(); +} + +static void sharp_global_destroy(void) +{ + list_delete(&sg.nhs); + list_delete(&sg.srv6_locators); +} + /* Master of threads. */ struct event_loop *master; @@ -68,6 +85,11 @@ static void sigint(void) { zlog_notice("Terminating on signal"); + vrf_terminate(); + sharp_zebra_terminate(); + + sharp_global_destroy(); + frr_fini(); exit(0); @@ -118,16 +140,6 @@ FRR_DAEMON_INFO(sharpd, SHARP, .vty_port = SHARP_VTY_PORT, .n_yang_modules = array_size(sharpd_yang_modules), ); -struct sharp_global sg; - -static void sharp_global_init(void) -{ - memset(&sg, 0, sizeof(sg)); - sg.nhs = list_new(); - sg.ted = NULL; - sg.srv6_locators = list_new(); -} - static void sharp_start_configuration(void) { zlog_debug("Configuration has started to be read"); diff --git a/sharpd/sharp_nht.c b/sharpd/sharp_nht.c index fa7880572d..6d64fcfb25 100644 --- a/sharpd/sharp_nht.c +++ b/sharpd/sharp_nht.c @@ -40,6 +40,11 @@ struct sharp_nh_tracker *sharp_nh_tracker_get(struct prefix *p) return nht; } +void sharp_nh_tracker_free(struct sharp_nh_tracker *nht) +{ + XFREE(MTYPE_NH_TRACKER, nht); +} + void sharp_nh_tracker_dump(struct vty *vty) { struct listnode *node; @@ -169,7 +174,8 @@ static void sharp_nhgroup_delete_cb(const char *name) if (!snhg) return; - nhg_del(snhg->id); + if (sharp_nhgroup_id_is_installed(snhg->id)) + nhg_del(snhg->id); sharp_nhg_rb_del(&nhg_head, snhg); XFREE(MTYPE_NHG, snhg); } diff --git a/sharpd/sharp_nht.h b/sharpd/sharp_nht.h index 5523f28079..b27952ac51 100644 --- a/sharpd/sharp_nht.h +++ b/sharpd/sharp_nht.h @@ -18,6 +18,7 @@ struct sharp_nh_tracker { }; extern struct sharp_nh_tracker *sharp_nh_tracker_get(struct prefix *p); +extern void sharp_nh_tracker_free(struct sharp_nh_tracker *nht); extern void sharp_nh_tracker_dump(struct vty *vty); diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c index ca2212cd87..cf79bacc6b 100644 --- a/sharpd/sharp_vty.c +++ b/sharpd/sharp_vty.c @@ -179,7 +179,7 @@ DEFPY (install_routes, <nexthop <A.B.C.D$nexthop4|X:X::X:X$nexthop6>|\ nexthop-group NHGNAME$nexthop_group>\ [backup$backup <A.B.C.D$backup_nexthop4|X:X::X:X$backup_nexthop6>] \ - (1-1000000)$routes [instance (0-255)$instance] [repeat (2-1000)$rpt] [opaque WORD]", + (1-1000000)$routes [instance (0-255)$instance] [repeat (2-1000)$rpt] [opaque WORD] [no-recurse$norecurse]", "Sharp routing Protocol\n" "install some routes\n" "Routes to install\n" @@ -201,7 +201,8 @@ DEFPY (install_routes, "Should we repeat this command\n" "How many times to repeat this command\n" "What opaque data to send down\n" - "The opaque data\n") + "The opaque data\n" + "No recursive nexthops\n") { struct vrf *vrf; struct prefix prefix; @@ -210,6 +211,7 @@ DEFPY (install_routes, sg.r.total_routes = routes; sg.r.installed_routes = 0; + sg.r.flags = 0; if (rpt >= 2) sg.r.repeat = rpt * 2; @@ -317,12 +319,16 @@ DEFPY (install_routes, else sg.r.opaque[0] = '\0'; + /* Default is to ask for recursive nexthop resolution */ + if (norecurse == NULL) + SET_FLAG(sg.r.flags, ZEBRA_FLAG_ALLOW_RECURSION); + sg.r.inst = instance; sg.r.vrf_id = vrf->vrf_id; rts = routes; sharp_install_routes_helper(&prefix, sg.r.vrf_id, sg.r.inst, nhgid, &sg.r.nhop_group, &sg.r.backup_nhop_group, - rts, 0, sg.r.opaque); + rts, sg.r.flags, sg.r.opaque); return CMD_SUCCESS; } @@ -396,7 +402,7 @@ DEFPY (install_seg6_routes, sg.r.nhop.gate.ipv6 = seg6_nh6; sg.r.nhop.vrf_id = vrf->vrf_id; sg.r.nhop_group.nexthop = &sg.r.nhop; - nexthop_add_srv6_seg6(&sg.r.nhop, &seg6_seg); + nexthop_add_srv6_seg6(&sg.r.nhop, &seg6_seg, 1); sg.r.vrf_id = vrf->vrf_id; sharp_install_routes_helper(&prefix, sg.r.vrf_id, sg.r.inst, 0, @@ -865,6 +871,24 @@ DEFPY (send_opaque_reg, return CMD_SUCCESS; } +/* Opaque notifications - register or unregister */ +DEFPY (send_opaque_notif_reg, + send_opaque_notif_reg_cmd, + "sharp send opaque notify <reg$reg | unreg> type (1-1000)", + SHARP_STR + "Send messages for testing\n" + "Send opaque messages\n" + "Opaque notification messages\n" + "Send notify registration\n" + "Send notify unregistration\n" + "Opaque sub-type code\n" + "Opaque sub-type code\n") +{ + sharp_zebra_opaque_notif_reg((reg != NULL), type); + + return CMD_SUCCESS; +} + DEFPY (neigh_discover, neigh_discover_cmd, "sharp neigh discover [vrf NAME$vrf_name] <A.B.C.D$dst4|X:X::X:X$dst6> IFNAME$ifname", @@ -924,7 +948,7 @@ DEFPY (import_te, static void sharp_srv6_locator_chunk_free(struct prefix_ipv6 *chunk) { - prefix_ipv6_free((struct prefix_ipv6 **)&chunk); + prefix_ipv6_free(&chunk); } DEFPY (sharp_srv6_manager_get_locator_chunk, @@ -1406,6 +1430,7 @@ void sharp_vty_init(void) install_element(ENABLE_NODE, &send_opaque_cmd); install_element(ENABLE_NODE, &send_opaque_unicast_cmd); install_element(ENABLE_NODE, &send_opaque_reg_cmd); + install_element(ENABLE_NODE, &send_opaque_notif_reg_cmd); install_element(ENABLE_NODE, &neigh_discover_cmd); install_element(ENABLE_NODE, &import_te_cmd); diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index 91fb7f03b1..cbfa0d1ccc 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -247,13 +247,11 @@ static bool route_add(const struct prefix *p, vrf_id_t vrf_id, uint8_t instance, memcpy(&api.prefix, p, sizeof(*p)); api.flags = flags; - SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION); SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP); /* Only send via ID if nhgroup has been successfully installed */ if (nhgid && sharp_nhgroup_id_is_installed(nhgid)) { - SET_FLAG(api.message, ZAPI_MESSAGE_NHG); - api.nhgid = nhgid; + zapi_route_set_nhg_id(&api, &nhgid); } else { for (ALL_NEXTHOPS_PTR(nhg, nh)) { /* Check if we set a VNI label */ @@ -513,6 +511,7 @@ static int route_notify_owner(ZAPI_CALLBACK_ARGS) static void zebra_connected(struct zclient *zclient) { + zebra_route_notify_send(ZEBRA_ROUTE_NOTIFY_REQUEST, zclient, true); zclient_send_reg_requests(zclient, VRF_DEFAULT); /* @@ -563,6 +562,12 @@ void nhg_add(uint32_t id, const struct nexthop_group *nhg, } if (api_nhg.nexthop_num == 0) { + if (sharp_nhgroup_id_is_installed(id)) { + zlog_debug("%s: nhg %u: no nexthops, deleting nexthop group", __func__, + id); + zclient_nhg_send(zclient, ZEBRA_NHG_DEL, &api_nhg); + return; + } zlog_debug("%s: nhg %u not sent: no valid nexthops", __func__, id); is_valid = false; @@ -667,27 +672,20 @@ static int sharp_debug_nexthops(struct zapi_route *api) return i; } -static int sharp_nexthop_update(ZAPI_CALLBACK_ARGS) + +static void sharp_nexthop_update(struct vrf *vrf, struct prefix *matched, + struct zapi_route *nhr) { struct sharp_nh_tracker *nht; - struct zapi_route nhr; - struct prefix matched; - - if (!zapi_nexthop_update_decode(zclient->ibuf, &matched, &nhr)) { - zlog_err("%s: Decode of update failed", __func__); - return 0; - } zlog_debug("Received update for %pFX actual match: %pFX metric: %u", - &matched, &nhr.prefix, nhr.metric); + matched, &nhr->prefix, nhr->metric); - nht = sharp_nh_tracker_get(&matched); - nht->nhop_num = nhr.nexthop_num; + nht = sharp_nh_tracker_get(matched); + nht->nhop_num = nhr->nexthop_num; nht->updates++; - sharp_debug_nexthops(&nhr); - - return 0; + sharp_debug_nexthops(nhr); } static int sharp_redistribute_route(ZAPI_CALLBACK_ARGS) @@ -805,6 +803,28 @@ static int sharp_opaque_handler(ZAPI_CALLBACK_ARGS) return 0; } +/* Handler for opaque notification messages */ +static int sharp_opq_notify_handler(ZAPI_CALLBACK_ARGS) +{ + struct stream *s; + struct zapi_opaque_notif_info info; + + s = zclient->ibuf; + + if (zclient_opaque_notif_decode(s, &info) != 0) + return -1; + + if (info.reg) + zlog_debug("%s: received opaque notification REG, type %u => %d/%d/%d", + __func__, info.msg_type, info.proto, info.instance, + info.session_id); + else + zlog_debug("%s: received opaque notification UNREG, type %u", + __func__, info.msg_type); + + return 0; +} + /* * Send OPAQUE messages, using subtype 'type'. */ @@ -840,6 +860,17 @@ void sharp_opaque_send(uint32_t type, uint32_t proto, uint32_t instance, } } +/* + * Register/unregister for opaque notifications from zebra about 'type'. + */ +void sharp_zebra_opaque_notif_reg(bool is_reg, uint32_t type) +{ + if (is_reg) + zclient_opaque_request_notify(zclient, type); + else + zclient_opaque_drop_notify(zclient, type); +} + /* * Send OPAQUE registration messages, using subtype 'type'. */ @@ -902,6 +933,7 @@ static int nhg_notify_owner(ZAPI_CALLBACK_ARGS) zlog_debug("Failed install of nhg %u", id); break; case ZAPI_NHG_REMOVED: + sharp_nhgroup_id_set_installed(id, false); zlog_debug("Removed nhg %u", id); break; case ZAPI_NHG_REMOVE_FAIL: @@ -1031,26 +1063,41 @@ static zclient_handler *const sharp_handlers[] = { [ZEBRA_INTERFACE_ADDRESS_ADD] = interface_address_add, [ZEBRA_INTERFACE_ADDRESS_DELETE] = interface_address_delete, [ZEBRA_ROUTE_NOTIFY_OWNER] = route_notify_owner, - [ZEBRA_NEXTHOP_UPDATE] = sharp_nexthop_update, [ZEBRA_NHG_NOTIFY_OWNER] = nhg_notify_owner, [ZEBRA_REDISTRIBUTE_ROUTE_ADD] = sharp_redistribute_route, [ZEBRA_REDISTRIBUTE_ROUTE_DEL] = sharp_redistribute_route, [ZEBRA_OPAQUE_MESSAGE] = sharp_opaque_handler, + [ZEBRA_OPAQUE_NOTIFY] = sharp_opq_notify_handler, [ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK] = sharp_zebra_process_srv6_locator_chunk, }; void sharp_zebra_init(void) { - struct zclient_options opt = {.receive_notify = true}; + hook_register_prio(if_real, 0, sharp_ifp_create); + hook_register_prio(if_up, 0, sharp_ifp_up); + hook_register_prio(if_down, 0, sharp_ifp_down); + hook_register_prio(if_unreal, 0, sharp_ifp_destroy); - if_zapi_callbacks(sharp_ifp_create, sharp_ifp_up, sharp_ifp_down, - sharp_ifp_destroy); - - zclient = zclient_new(master, &opt, sharp_handlers, + zclient = zclient_new(master, &zclient_options_default, sharp_handlers, array_size(sharp_handlers)); zclient_init(zclient, ZEBRA_ROUTE_SHARP, 0, &sharp_privs); zclient->zebra_connected = zebra_connected; zclient->zebra_buffer_write_ready = sharp_zclient_buffer_ready; + zclient->nexthop_update = sharp_nexthop_update; +} + +void sharp_zebra_terminate(void) +{ + struct sharp_zclient *node = sharp_clients_head; + + while (node) { + sharp_zclient_delete(node->client->session_id); + + node = sharp_clients_head; + } + + zclient_stop(zclient); + zclient_free(zclient); } diff --git a/sharpd/sharp_zebra.h b/sharpd/sharp_zebra.h index cf8689799a..6314f862f5 100644 --- a/sharpd/sharp_zebra.h +++ b/sharpd/sharp_zebra.h @@ -8,6 +8,7 @@ #define __SHARP_ZEBRA_H__ extern void sharp_zebra_init(void); +extern void sharp_zebra_terminate(void); /* Add and delete extra zapi client sessions, for testing */ int sharp_zclient_create(uint32_t session_id); @@ -39,10 +40,15 @@ int sharp_install_lsps_helper(bool install_p, bool update_p, void sharp_opaque_send(uint32_t type, uint32_t proto, uint32_t instance, uint32_t session_id, uint32_t count); -/* Send OPAQUE registration messages, using subtype 'type'. */ +/* Send OPAQUE registration or notification registration messages, + * for opaque subtype 'type'. + */ void sharp_opaque_reg_send(bool is_reg, uint32_t proto, uint32_t instance, uint32_t session_id, uint32_t type); +/* Register/unregister for opaque notifications from zebra about 'type'. */ +void sharp_zebra_opaque_notif_reg(bool is_reg, uint32_t type); + extern void sharp_zebra_send_arp(const struct interface *ifp, const struct prefix *p); diff --git a/snapcraft/snapcraft.yaml.in b/snapcraft/snapcraft.yaml.in index fa34304898..607cbc7fe3 100644 --- a/snapcraft/snapcraft.yaml.in +++ b/snapcraft/snapcraft.yaml.in @@ -302,7 +302,7 @@ parts: - libpcre2-8-0 source: https://github.com/CESNET/libyang.git source-type: git - source-tag: v2.0.7 + source-tag: v2.1.80 plugin: cmake configflags: - -DCMAKE_INSTALL_PREFIX:PATH=/usr diff --git a/staticd/static_bfd.c b/staticd/static_bfd.c index 78d8c05807..b0b2566150 100644 --- a/staticd/static_bfd.c +++ b/staticd/static_bfd.c @@ -88,14 +88,15 @@ void static_next_hop_bfd_monitor_enable(struct static_nexthop *sn, bool mhop; int family; struct ipaddr source; + struct vrf *vrf = NULL; use_interface = false; - use_source = yang_dnode_exists(dnode, "./source"); - use_profile = yang_dnode_exists(dnode, "./profile"); + use_source = yang_dnode_exists(dnode, "source"); + use_profile = yang_dnode_exists(dnode, "profile"); onlink = yang_dnode_exists(dnode, "../onlink") && yang_dnode_get_bool(dnode, "../onlink"); - mhop = yang_dnode_get_bool(dnode, "./multi-hop"); - + mhop = yang_dnode_get_bool(dnode, "multi-hop"); + vrf = vrf_lookup_by_name(yang_dnode_get_string(dnode, "../vrf")); family = static_next_hop_type_to_family(sn); if (family == AF_UNSPEC) @@ -111,7 +112,7 @@ void static_next_hop_bfd_monitor_enable(struct static_nexthop *sn, /* Configure the session. */ if (use_source) - yang_dnode_get_ip(&source, dnode, "./source"); + yang_dnode_get_ip(&source, dnode, "source"); if (onlink || mhop == false) bfd_sess_set_auto_source(sn->bsp, false); @@ -133,6 +134,8 @@ void static_next_hop_bfd_monitor_enable(struct static_nexthop *sn, bfd_sess_set_profile(sn->bsp, use_profile ? yang_dnode_get_string( dnode, "./profile") : NULL); + if (vrf && vrf->vrf_id != VRF_UNKNOWN) + bfd_sess_set_vrf(sn->bsp, vrf->vrf_id); bfd_sess_set_hop_count(sn->bsp, (onlink || mhop == false) ? 1 : 254); diff --git a/staticd/static_main.c b/staticd/static_main.c index 464c42ecab..b2f5ec4952 100644 --- a/staticd/static_main.c +++ b/staticd/static_main.c @@ -53,14 +53,14 @@ struct option longopts[] = { { 0 } }; /* Master of threads. */ struct event_loop *master; -uintptr_t mgmt_lib_hndl; +static struct mgmt_be_client *mgmt_be_client; static struct frr_daemon_info staticd_di; + /* SIGHUP handler. */ static void sighup(void) { - zlog_info("SIGHUP received"); - vty_read_config(NULL, staticd_di.config_file, config_default); + zlog_info("SIGHUP received and ignored"); } /* SIGINT / SIGTERM handler. */ @@ -71,7 +71,7 @@ static void sigint(void) /* Disable BFD events to avoid wasting processing. */ bfd_protocol_integration_set_shutdown(true); - mgmt_be_client_lib_destroy(); + mgmt_be_client_destroy(mgmt_be_client); static_vrf_terminate(); @@ -106,58 +106,7 @@ struct frr_signal_t static_signals[] = { }, }; -#if 0 -static void static_mgmt_be_client_connect(uintptr_t lib_hndl, - uintptr_t usr_data, bool connected) -{ - (void)usr_data; - - assert(lib_hndl == mgmt_lib_hndl); - - zlog_debug("Got %s %s MGMTD Backend Client Server", - connected ? "connected" : "disconnected", - connected ? "to" : "from"); - - /* unless we are subscribing to xpaths we don't need to do this */ - if (connected) - (void)mgmt_be_subscribe_yang_data(mgmt_lib_hndl, NULL, 0); -} - -static void -static_mgmt_txn_notify(uintptr_t lib_hndl, uintptr_t usr_data, - struct mgmt_be_client_txn_ctx *txn_ctx, - bool destroyed) -{ - zlog_debug("Got Txn %s Notify from MGMTD server", - destroyed ? "DESTROY" : "CREATE"); - - if (!destroyed) { - /* - * TODO: Allocate and install a private scratchpad for this - * transaction if required - */ - } else { - /* - * TODO: Uninstall and deallocate the private scratchpad for - * this transaction if installed earlier. - */ - } -} -#endif - -static struct mgmt_be_client_params mgmt_params = { - .name = "staticd", - .conn_retry_intvl_sec = 3, - /* - * instead of a connect routine maybe just put xpaths to subcribe to - * here - */ - .client_connect_notify = NULL, /* static_mgmt_be_client_connect, */ - .txn_notify = NULL, /* static_mgmt_txn_notify */ -}; - static const struct frr_yang_module_info *const staticd_yang_modules[] = { - &frr_filter_info, &frr_interface_info, &frr_vrf_info, &frr_routing_info, @@ -212,7 +161,7 @@ int main(int argc, char **argv, char **envp) static_vty_init(); /* Initialize MGMT backend functionalities */ - mgmt_lib_hndl = mgmt_be_client_lib_init(&mgmt_params, master); + mgmt_be_client = mgmt_be_client_create("staticd", NULL, 0, master); hook_register(routing_conf_event, routing_control_plane_protocols_name_validate); diff --git a/staticd/static_nb.c b/staticd/static_nb.c index d8b5b167cf..e6aa71a77b 100644 --- a/staticd/static_nb.c +++ b/staticd/static_nb.c @@ -15,19 +15,11 @@ const struct frr_yang_module_info frr_staticd_info = { .name = "frr-staticd", .nodes = { - { - .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd", - .cbs = { - .cli_show = static_cli_show, - .cli_show_end = static_cli_show_end, - } - }, { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list", .cbs = { .create = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_create, .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_destroy, - .cli_cmp = static_route_list_cli_cmp, } }, { @@ -35,7 +27,6 @@ const struct frr_yang_module_info frr_staticd_info = { .cbs = { .create = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_create, .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_destroy, - .cli_cmp = static_path_list_cli_cmp, } }, { @@ -51,8 +42,6 @@ const struct frr_yang_module_info frr_staticd_info = { .create = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_create, .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_destroy, .pre_validate = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_pre_validate, - .cli_show = static_nexthop_cli_show, - .cli_cmp = static_nexthop_cli_cmp, } }, { @@ -74,6 +63,21 @@ const struct frr_yang_module_info frr_staticd_info = { .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_color_destroy, } }, + { + .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/srv6-segs-stack/entry", + .cbs = { + .create = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_create, + .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_destroy, + + } + }, + { + .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/srv6-segs-stack/entry/seg", + .cbs = { + .modify = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_modify, + .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_destroy, + } + }, { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/mpls-label-stack/entry", .cbs = { @@ -135,7 +139,6 @@ const struct frr_yang_module_info frr_staticd_info = { .cbs = { .create = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_create, .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_destroy, - .cli_cmp = static_src_list_cli_cmp, } }, { @@ -143,7 +146,6 @@ const struct frr_yang_module_info frr_staticd_info = { .cbs = { .create = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_create, .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_destroy, - .cli_cmp = static_path_list_cli_cmp, } }, { @@ -159,8 +161,6 @@ const struct frr_yang_module_info frr_staticd_info = { .create = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_create, .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_destroy, .pre_validate = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_pre_validate, - .cli_show = static_src_nexthop_cli_show, - .cli_cmp = static_nexthop_cli_cmp, } }, { @@ -182,6 +182,20 @@ const struct frr_yang_module_info frr_staticd_info = { .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_color_destroy, } }, + { + .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/srv6-segs-stack/entry", + .cbs = { + .create = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_create, + .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_destroy, + } + }, + { + .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/srv6-segs-stack/entry/seg", + .cbs = { + .modify = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_modify, + .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_destroy, + } + }, { .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/mpls-label-stack/entry", .cbs = { diff --git a/staticd/static_nb.h b/staticd/static_nb.h index ce3644076c..9f80653b76 100644 --- a/staticd/static_nb.h +++ b/staticd/static_nb.h @@ -35,6 +35,14 @@ int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_pa struct nb_cb_modify_args *args); int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_color_destroy( struct nb_cb_destroy_args *args); +int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_create( + struct nb_cb_create_args *args); +int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_destroy( + struct nb_cb_destroy_args *args); +int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_modify( + struct nb_cb_modify_args *args); +int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_destroy( + struct nb_cb_destroy_args *args); int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_create( struct nb_cb_create_args *args); int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_destroy( @@ -80,6 +88,14 @@ int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_sr struct nb_cb_modify_args *args); int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_color_destroy( struct nb_cb_destroy_args *args); +int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_create( + struct nb_cb_create_args *args); +int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_destroy( + struct nb_cb_destroy_args *args); +int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_modify( + struct nb_cb_modify_args *args); +int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_destroy( + struct nb_cb_destroy_args *args); int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_create( struct nb_cb_create_args *args); int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_destroy( @@ -147,6 +163,10 @@ int routing_control_plane_protocols_name_validate( #define FRR_STATIC_ROUTE_NHLB_KEY_XPATH "/entry[id='%u']/label" +#define FRR_STATIC_ROUTE_NH_SRV6_SEGS_XPATH "/srv6-segs-stack" + +#define FRR_STATIC_ROUTE_NH_SRV6_KEY_SEG_XPATH "/entry[id='%u']/seg" + /* route-list/srclist */ #define FRR_S_ROUTE_SRC_INFO_KEY_XPATH \ "/frr-routing:routing/control-plane-protocols/" \ diff --git a/staticd/static_nb_config.c b/staticd/static_nb_config.c index 01cd281d9c..2fee908d5d 100644 --- a/staticd/static_nb_config.c +++ b/staticd/static_nb_config.c @@ -18,6 +18,7 @@ #include "static_vrf.h" #include "static_routes.h" #include "static_nb.h" +#include "static_zebra.h" static int static_path_list_create(struct nb_cb_create_args *args) @@ -33,8 +34,8 @@ static int static_path_list_create(struct nb_cb_create_args *args) case NB_EV_VALIDATE: vrf_dnode = yang_dnode_get_parent(args->dnode, "control-plane-protocol"); - vrf = yang_dnode_get_string(vrf_dnode, "./vrf"); - table_id = yang_dnode_get_uint32(args->dnode, "./table-id"); + vrf = yang_dnode_get_string(vrf_dnode, "vrf"); + table_id = yang_dnode_get_uint32(args->dnode, "table-id"); /* * TableId is not applicable for VRF. Consider the case of @@ -55,8 +56,8 @@ static int static_path_list_create(struct nb_cb_create_args *args) break; case NB_EV_APPLY: rn = nb_running_get_entry(args->dnode, NULL, true); - distance = yang_dnode_get_uint8(args->dnode, "./distance"); - table_id = yang_dnode_get_uint32(args->dnode, "./table-id"); + distance = yang_dnode_get_uint8(args->dnode, "distance"); + table_id = yang_dnode_get_uint32(args->dnode, "table-id"); pn = static_add_path(rn, table_id, distance); nb_running_set_entry(args->dnode, pn); } @@ -111,7 +112,7 @@ static int nexthop_iter_cb(const struct lyd_node *dnode, void *arg) struct nexthop_iter *iter = arg; enum static_nh_type nh_type; - nh_type = yang_dnode_get_enum(dnode, "./nh-type"); + nh_type = yang_dnode_get_enum(dnode, "nh-type"); if (nh_type == STATIC_BLACKHOLE) iter->blackhole = true; @@ -134,8 +135,9 @@ static bool static_nexthop_create(struct nb_cb_create_args *args) switch (args->event) { case NB_EV_VALIDATE: - ifname = yang_dnode_get_string(args->dnode, "./interface"); - if (ifname != NULL) { + ifname = yang_dnode_get_string(args->dnode, "interface"); + nh_type = yang_dnode_get_enum(args->dnode, "nh-type"); + if (ifname != NULL && nh_type != STATIC_BLACKHOLE) { if (strcasecmp(ifname, "Null0") == 0 || strcasecmp(ifname, "reject") == 0 || strcasecmp(ifname, "blackhole") == 0) { @@ -169,10 +171,10 @@ static bool static_nexthop_create(struct nb_cb_create_args *args) case NB_EV_ABORT: break; case NB_EV_APPLY: - yang_dnode_get_ip(&ipaddr, args->dnode, "./gateway"); - nh_type = yang_dnode_get_enum(args->dnode, "./nh-type"); - ifname = yang_dnode_get_string(args->dnode, "./interface"); - nh_vrf = yang_dnode_get_string(args->dnode, "./vrf"); + yang_dnode_get_ip(&ipaddr, args->dnode, "gateway"); + nh_type = yang_dnode_get_enum(args->dnode, "nh-type"); + ifname = yang_dnode_get_string(args->dnode, "interface"); + nh_vrf = yang_dnode_get_string(args->dnode, "vrf"); pn = nb_running_get_entry(args->dnode, NULL, true); if (!static_add_nexthop_validate(nh_vrf, nh_type, &ipaddr)) @@ -208,6 +210,98 @@ static bool static_nexthop_destroy(struct nb_cb_destroy_args *args) return NB_OK; } +static int nexthop_srv6_segs_stack_entry_create(struct nb_cb_create_args *args) +{ + struct static_nexthop *nh; + uint32_t pos; + uint8_t index; + + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + break; + case NB_EV_APPLY: + nh = nb_running_get_entry(args->dnode, NULL, true); + pos = yang_get_list_pos(args->dnode); + if (!pos) { + flog_warn(EC_LIB_NB_CB_CONFIG_APPLY, + "libyang returns invalid seg position"); + return NB_ERR; + } + /* Mapping to array = list-index -1 */ + index = pos - 1; + memset(&nh->snh_seg.seg[index], 0, sizeof(struct in6_addr)); + nh->snh_seg.num_segs++; + break; + } + + return NB_OK; +} + +static int nexthop_srv6_segs_stack_entry_destroy(struct nb_cb_destroy_args *args) +{ + struct static_nexthop *nh; + uint32_t pos; + uint8_t index; + int old_num_segs; + + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + break; + case NB_EV_APPLY: + nh = nb_running_get_entry(args->dnode, NULL, true); + pos = yang_get_list_pos(args->dnode); + if (!pos) { + flog_warn(EC_LIB_NB_CB_CONFIG_APPLY, + "libyang returns invalid seg position"); + return NB_ERR; + } + index = pos - 1; + old_num_segs = nh->snh_seg.num_segs; + memset(&nh->snh_seg.seg[index], 0, sizeof(struct in6_addr)); + nh->snh_seg.num_segs--; + + if (old_num_segs != nh->snh_seg.num_segs) + nh->state = STATIC_START; + break; + } + + return NB_OK; +} + +static int static_nexthop_srv6_segs_modify(struct nb_cb_modify_args *args) +{ + struct static_nexthop *nh; + uint32_t pos; + uint8_t index; + struct in6_addr old_seg; + struct in6_addr cli_seg; + + nh = nb_running_get_entry(args->dnode, NULL, true); + pos = yang_get_list_pos(lyd_parent(args->dnode)); + if (!pos) { + flog_warn(EC_LIB_NB_CB_CONFIG_APPLY, + "libyang returns invalid seg position"); + return NB_ERR; + } + /* Mapping to array = list-index -1 */ + index = pos - 1; + + old_seg = nh->snh_seg.seg[index]; + yang_dnode_get_ipv6(&cli_seg, args->dnode, NULL); + + memcpy(&nh->snh_seg.seg[index], &cli_seg, sizeof(struct in6_addr)); + + if (memcmp(&old_seg, &nh->snh_seg.seg[index], + sizeof(struct in6_addr)) != 0) + nh->state = STATIC_START; + + return NB_OK; +} + static int nexthop_mpls_label_stack_entry_create(struct nb_cb_create_args *args) { struct static_nexthop *nh; @@ -371,10 +465,33 @@ static int static_nexthop_bh_type_modify(struct nb_cb_modify_args *args) { struct static_nexthop *nh; enum static_nh_type nh_type; + const char *nh_ifname; + const char *nh_vrf; switch (args->event) { case NB_EV_VALIDATE: nh_type = yang_dnode_get_enum(args->dnode, "../nh-type"); + nh_ifname = yang_dnode_get_string(args->dnode, "../interface"); + nh_vrf = yang_dnode_get_string(args->dnode, "../vrf"); + if (nh_ifname && nh_vrf) { + struct vrf *vrf = vrf_lookup_by_name(nh_vrf); + + if (!vrf) { + snprintf(args->errmsg, args->errmsg_len, + "nexthop vrf %s not found", nh_vrf); + return NB_ERR_VALIDATION; + } + + struct interface *ifp = if_lookup_by_name(nh_ifname, + vrf->vrf_id); + + if (ifp && (!strmatch(nh_ifname, "blackhole") || + !strmatch(nh_ifname, "reject"))) { + snprintf(args->errmsg, args->errmsg_len, + "nexthop interface name must be (reject, blackhole)"); + return NB_ERR_VALIDATION; + } + } if (nh_type != STATIC_BLACKHOLE) { snprintf(args->errmsg, args->errmsg_len, "nexthop type is not the blackhole type"); @@ -419,7 +536,7 @@ int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_pa const struct lyd_node *mls_dnode; uint32_t count; - mls_dnode = yang_dnode_get(args->dnode, "./mpls-label-stack"); + mls_dnode = yang_dnode_get(args->dnode, "mpls-label-stack"); count = yang_get_list_elements_count(lyd_child(mls_dnode)); if (count > MPLS_MAX_LABELS) { @@ -436,7 +553,7 @@ int routing_control_plane_protocols_name_validate( { const char *name; - name = yang_dnode_get_string(args->dnode, "./name"); + name = yang_dnode_get_string(args->dnode, "name"); if (!strmatch(name, "staticd")) { snprintf(args->errmsg, args->errmsg_len, "static routing supports only one instance with name staticd"); @@ -463,15 +580,15 @@ int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_cr switch (args->event) { case NB_EV_VALIDATE: - yang_dnode_get_prefix(&prefix, args->dnode, "./prefix"); - afi_safi = yang_dnode_get_string(args->dnode, "./afi-safi"); + yang_dnode_get_prefix(&prefix, args->dnode, "prefix"); + afi_safi = yang_dnode_get_string(args->dnode, "afi-safi"); yang_afi_safi_identity2value(afi_safi, &afi, &safi); prefix_afi = family2afi(prefix.family); if (afi != prefix_afi) { flog_warn( EC_LIB_NB_CB_CONFIG_VALIDATE, "route node %s creation failed", - yang_dnode_get_string(args->dnode, "./prefix")); + yang_dnode_get_string(args->dnode, "prefix")); return NB_ERR_VALIDATION; } break; @@ -484,8 +601,8 @@ int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_cr vrf = nb_running_get_entry(vrf_dnode, NULL, true); s_vrf = vrf->info; - yang_dnode_get_prefix(&prefix, args->dnode, "./prefix"); - afi_safi = yang_dnode_get_string(args->dnode, "./afi-safi"); + yang_dnode_get_prefix(&prefix, args->dnode, "prefix"); + afi_safi = yang_dnode_get_string(args->dnode, "afi-safi"); yang_afi_safi_identity2value(afi_safi, &afi, &safi); rn = static_add_route(afi, safi, &prefix, NULL, s_vrf); @@ -493,7 +610,7 @@ int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_cr snprintf( args->errmsg, args->errmsg_len, "Static Route to %s not installed currently because dependent config not fully available", - yang_dnode_get_string(args->dnode, "./prefix")); + yang_dnode_get_string(args->dnode, "prefix")); nb_running_set_entry(args->dnode, rn); break; } @@ -617,6 +734,60 @@ int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_pa return NB_OK; } +/* + * XPath: + * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/srv6-segs-stack/entry + */ +int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_create( + struct nb_cb_create_args *args) +{ + return nexthop_srv6_segs_stack_entry_create(args); +} + +int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_destroy( + struct nb_cb_destroy_args *args) +{ + return nexthop_srv6_segs_stack_entry_destroy(args); +} + +/* + * XPath: + * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/srv6-segs-stack/entry/seg + */ +int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_modify( + struct nb_cb_modify_args *args) +{ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + break; + case NB_EV_APPLY: + if (static_nexthop_srv6_segs_modify(args) != NB_OK) + return NB_ERR; + break; + } + return NB_OK; +} + +int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_destroy( + struct nb_cb_destroy_args *args) +{ + /* + * No operation is required in this call back. + * nexthop_srv6_segs_stack_entry_destroy() will take care + * to reset the seg vaue. + */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + break; + } + return NB_OK; +} + /* * XPath: * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/mpls-label-stack/entry @@ -790,6 +961,17 @@ int route_next_hop_bfd_source_destroy(struct nb_cb_destroy_args *args) sn = nb_running_get_entry(args->dnode, NULL, true); static_next_hop_bfd_auto_source(sn); + + /* NHT information are needed by BFD to automatically find the source + * + * Force zebra to resend the information to BFD by unregistering and + * registering again NHT. The (...)/frr-nexthops/nexthop northbound + * apply_finish function will trigger a call to static_install_nexthop() + * that does a call to static_zebra_nht_register(nh, true); + * static_zebra_nht_register(sn, false); + */ + static_zebra_nht_register(sn, false); + return NB_OK; } @@ -866,7 +1048,7 @@ int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_sr rn = nb_running_get_entry(args->dnode, NULL, true); info = route_table_get_info(rn->table); s_vrf = info->svrf; - yang_dnode_get_ipv6p(&src_prefix, args->dnode, "./src-prefix"); + yang_dnode_get_ipv6p(&src_prefix, args->dnode, "src-prefix"); afi = family2afi(src_prefix.family); src_rn = static_add_route(afi, safi, &rn->p, &src_prefix, s_vrf); @@ -995,6 +1177,60 @@ int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_sr return NB_OK; } +/* + * XPath: + * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/srv6-segs-stack/entry + */ +int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_create( + struct nb_cb_create_args *args) +{ + return nexthop_srv6_segs_stack_entry_create(args); +} + +int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_destroy( + struct nb_cb_destroy_args *args) +{ + return nexthop_srv6_segs_stack_entry_destroy(args); +} + +/* + * XPath: + * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/srv6-segs-stack/entry/seg + */ +int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_modify( + struct nb_cb_modify_args *args) +{ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + break; + case NB_EV_APPLY: + if (static_nexthop_srv6_segs_modify(args) != NB_OK) + return NB_ERR; + break; + } + return NB_OK; +} + +int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_destroy( + struct nb_cb_destroy_args *args) +{ + /* + * No operation is required in this call back. + * nexthop_mpls_seg_stack_entry_destroy() will take care + * to reset the seg vaue. + */ + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + case NB_EV_APPLY: + break; + } + return NB_OK; +} + /* * XPath: * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/mpls-label-stack/entry diff --git a/staticd/static_routes.h b/staticd/static_routes.h index 3be6fd6b14..1231ead526 100644 --- a/staticd/static_routes.h +++ b/staticd/static_routes.h @@ -9,6 +9,7 @@ #include "lib/bfd.h" #include "lib/mpls.h" +#include "lib/srv6.h" #include "table.h" #include "memory.h" @@ -27,6 +28,12 @@ struct static_nh_label { mpls_label_t label[MPLS_MAX_LABELS]; }; +/* Static route seg information */ +struct static_nh_seg { + int num_segs; + struct in6_addr seg[SRV6_MAX_SIDS]; +}; + enum static_blackhole_type { STATIC_BLACKHOLE_DROP = 0, STATIC_BLACKHOLE_NULL, @@ -124,11 +131,14 @@ struct static_nexthop { bool nh_registered; bool nh_valid; - char ifname[INTERFACE_NAMSIZ + 1]; + char ifname[IFNAMSIZ + 1]; /* Label information */ struct static_nh_label snh_label; + /* SRv6 Seg information */ + struct static_nh_seg snh_seg; + /* * Whether to pretend the nexthop is directly attached to the specified * link. Only meaningful when both a gateway address and interface name @@ -229,7 +239,7 @@ extern void zebra_stable_node_cleanup(struct route_table *table, * Max string return via API static_get_nh_str in size_t */ -#define NEXTHOP_STR (INET6_ADDRSTRLEN + INTERFACE_NAMSIZ + 25) +#define NEXTHOP_STR (INET6_ADDRSTRLEN + IFNAMSIZ + 25) /* * For the given nexthop, returns the string * nexthop : returns the formatted string in nexthop diff --git a/staticd/static_vrf.c b/staticd/static_vrf.c index a67dce200f..7a0ff01d04 100644 --- a/staticd/static_vrf.c +++ b/staticd/static_vrf.c @@ -124,26 +124,12 @@ struct static_vrf *static_vrf_lookup_by_name(const char *name) return NULL; } -static int static_vrf_config_write(struct vty *vty) -{ - struct lyd_node *dnode; - int written = 0; - - dnode = yang_dnode_get(running_config->dnode, "/frr-routing:routing"); - if (dnode) { - nb_cli_show_dnode_cmds(vty, dnode, false); - written = 1; - } - - return written; -} - void static_vrf_init(void) { vrf_init(static_vrf_new, static_vrf_enable, static_vrf_disable, static_vrf_delete); - vrf_cmd_init(static_vrf_config_write); + vrf_cmd_init(NULL); } void static_vrf_terminate(void) diff --git a/staticd/static_vty.c b/staticd/static_vty.c index 3e58a44aa7..a641d1a09f 100644 --- a/staticd/static_vty.c +++ b/staticd/static_vty.c @@ -19,6 +19,7 @@ #include "libfrr.h" #include "routing_nb.h" #include "northbound_cli.h" +#include "frrdistance.h" #include "static_vrf.h" #include "static_vty.h" @@ -47,6 +48,7 @@ struct static_route_args { const char *source; const char *gateway; const char *interface_name; + const char *segs; const char *flag; const char *tag; const char *distance; @@ -58,6 +60,8 @@ struct static_route_args { bool bfd_multi_hop; const char *bfd_source; const char *bfd_profile; + + const char *input; }; static int static_route_nb_run(struct vty *vty, struct static_route_args *args) @@ -71,12 +75,16 @@ static int static_route_nb_run(struct vty *vty, struct static_route_args *args) char xpath_nexthop[XPATH_MAXLEN]; char xpath_mpls[XPATH_MAXLEN]; char xpath_label[XPATH_MAXLEN]; + char xpath_segs[XPATH_MAXLEN]; + char xpath_seg[XPATH_MAXLEN]; char ab_xpath[XPATH_MAXLEN]; char buf_prefix[PREFIX_STRLEN]; char buf_src_prefix[PREFIX_STRLEN] = {}; char buf_nh_type[PREFIX_STRLEN] = {}; char buf_tag[PREFIX_STRLEN]; uint8_t label_stack_id = 0; + uint8_t segs_stack_id = 0; + char *orig_label = NULL, *orig_seg = NULL; const char *buf_gate_str; uint8_t distance = ZEBRA_STATIC_DISTANCE_DEFAULT; route_tag_t tag = 0; @@ -93,7 +101,7 @@ static int static_route_nb_run(struct vty *vty, struct static_route_args *args) return CMD_WARNING_CONFIG_FAILED; } - args->vrf = yang_dnode_get_string(vrf_dnode, "./name"); + args->vrf = yang_dnode_get_string(vrf_dnode, "name"); } else { if (args->vrf == NULL) args->vrf = VRF_DEFAULT_NAME; @@ -145,9 +153,20 @@ static int static_route_nb_run(struct vty *vty, struct static_route_args *args) else buf_gate_str = ""; - if (args->gateway == NULL && args->interface_name == NULL) + if (args->gateway == NULL && args->interface_name == NULL) { type = STATIC_BLACKHOLE; - else if (args->gateway && args->interface_name) { + /* If this is blackhole/reject flagged route, then + * specify interface_name with the value of what was really + * entered. + * interface_name will be validated later in NB functions + * to check if we don't create blackhole/reject routes that + * match the real interface names. + * E.g.: `ip route 10.0.0.1/32 bla` will create a blackhole + * route despite the real interface named `bla` exists. + */ + if (args->input) + args->interface_name = args->input; + } else if (args->gateway && args->interface_name) { if (args->afi == AFI_IP) type = STATIC_IPV4_GATEWAY_IFNAME; else @@ -311,7 +330,7 @@ static int static_route_nb_run(struct vty *vty, struct static_route_args *args) nb_cli_enqueue_change(vty, xpath_mpls, NB_OP_DESTROY, NULL); - ostr = XSTRDUP(MTYPE_TMP, args->label); + orig_label = ostr = XSTRDUP(MTYPE_TMP, args->label); while ((nump = strsep(&ostr, "/")) != NULL) { snprintf(ab_xpath, sizeof(ab_xpath), FRR_STATIC_ROUTE_NHLB_KEY_XPATH, @@ -324,7 +343,6 @@ static int static_route_nb_run(struct vty *vty, struct static_route_args *args) NB_OP_MODIFY, nump); label_stack_id++; } - XFREE(MTYPE_TMP, ostr); } else { strlcpy(xpath_mpls, xpath_nexthop, sizeof(xpath_mpls)); strlcat(xpath_mpls, FRR_STATIC_ROUTE_NH_LABEL_XPATH, @@ -332,7 +350,38 @@ static int static_route_nb_run(struct vty *vty, struct static_route_args *args) nb_cli_enqueue_change(vty, xpath_mpls, NB_OP_DESTROY, NULL); } + if (args->segs) { + /* copy of seg string (start) */ + char *ostr; + /* pointer to next segment */ + char *nump; + strlcpy(xpath_segs, xpath_nexthop, sizeof(xpath_segs)); + strlcat(xpath_segs, FRR_STATIC_ROUTE_NH_SRV6_SEGS_XPATH, + sizeof(xpath_segs)); + + nb_cli_enqueue_change(vty, xpath_segs, NB_OP_DESTROY, + NULL); + + orig_seg = ostr = XSTRDUP(MTYPE_TMP, args->segs); + while ((nump = strsep(&ostr, "/")) != NULL) { + snprintf(ab_xpath, sizeof(ab_xpath), + FRR_STATIC_ROUTE_NH_SRV6_KEY_SEG_XPATH, + segs_stack_id); + strlcpy(xpath_seg, xpath_segs, + sizeof(xpath_seg)); + strlcat(xpath_seg, ab_xpath, sizeof(xpath_seg)); + nb_cli_enqueue_change(vty, xpath_seg, + NB_OP_MODIFY, nump); + segs_stack_id++; + } + } else { + strlcpy(xpath_segs, xpath_nexthop, sizeof(xpath_segs)); + strlcat(xpath_segs, FRR_STATIC_ROUTE_NH_SRV6_SEGS_XPATH, + sizeof(xpath_segs)); + nb_cli_enqueue_change(vty, xpath_segs, NB_OP_DESTROY, + NULL); + } if (args->bfd) { char xpath_bfd[XPATH_MAXLEN]; @@ -368,6 +417,11 @@ static int static_route_nb_run(struct vty *vty, struct static_route_args *args) } ret = nb_cli_apply_changes(vty, "%s", xpath_prefix); + + if (orig_label) + XFREE(MTYPE_TMP, orig_label); + if (orig_seg) + XFREE(MTYPE_TMP, orig_seg); } else { if (args->source) { if (args->distance) @@ -499,6 +553,8 @@ DEFPY_YANG(ip_route_blackhole, "Table to configure\n" "The table number to configure\n") { + int idx_flag = 0; + struct static_route_args args = { .delete = !!no, .afi = AFI_IP, @@ -513,6 +569,9 @@ DEFPY_YANG(ip_route_blackhole, .vrf = vrf, }; + if (flag && argv_find(argv, argc, flag, &idx_flag)) + args.input = argv[idx_flag]->arg; + return static_route_nb_run(vty, &args); } @@ -541,6 +600,8 @@ DEFPY_YANG(ip_route_blackhole_vrf, "Table to configure\n" "The table number to configure\n") { + int idx_flag = 0; + struct static_route_args args = { .delete = !!no, .afi = AFI_IP, @@ -562,6 +623,9 @@ DEFPY_YANG(ip_route_blackhole_vrf, */ assert(args.prefix); + if (flag && argv_find(argv, argc, flag, &idx_flag)) + args.input = argv[idx_flag]->arg; + return static_route_nb_run(vty, &args); } @@ -852,6 +916,8 @@ DEFPY_YANG(ipv6_route_blackhole, "Table to configure\n" "The table number to configure\n") { + int idx_flag = 0; + struct static_route_args args = { .delete = !!no, .afi = AFI_IP6, @@ -866,6 +932,9 @@ DEFPY_YANG(ipv6_route_blackhole, .vrf = vrf, }; + if (flag && argv_find(argv, argc, flag, &idx_flag)) + args.input = argv[idx_flag]->arg; + return static_route_nb_run(vty, &args); } @@ -894,6 +963,8 @@ DEFPY_YANG(ipv6_route_blackhole_vrf, "Table to configure\n" "The table number to configure\n") { + int idx_flag = 0; + struct static_route_args args = { .delete = !!no, .afi = AFI_IP6, @@ -915,12 +986,14 @@ DEFPY_YANG(ipv6_route_blackhole_vrf, */ assert(args.prefix); + if (flag && argv_find(argv, argc, flag, &idx_flag)) + args.input = argv[idx_flag]->arg; + return static_route_nb_run(vty, &args); } -DEFPY_YANG(ipv6_route_address_interface, - ipv6_route_address_interface_cmd, - "[no] ipv6 route X:X::X:X/M$prefix [from X:X::X:X/M] \ +DEFPY_YANG(ipv6_route_address_interface, ipv6_route_address_interface_cmd, + "[no] ipv6 route X:X::X:X/M$prefix [from X:X::X:X/M] \ X:X::X:X$gate \ <INTERFACE|Null0>$ifname \ [{ \ @@ -933,33 +1006,28 @@ DEFPY_YANG(ipv6_route_address_interface, |onlink$onlink \ |color (1-4294967295) \ |bfd$bfd [{multi-hop$bfd_multi_hop|source X:X::X:X$bfd_source|profile BFDPROF$bfd_profile}] \ + |segments WORD \ }]", - NO_STR - IPV6_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 source-dest route\n" - "IPv6 source prefix\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR - "Table to configure\n" - "The table number to configure\n" - VRF_CMD_HELP_STR - "Treat the nexthop as directly attached to the interface\n" - "SR-TE color\n" - "The SR-TE color to configure\n" - BFD_INTEGRATION_STR - BFD_INTEGRATION_MULTI_HOP_STR - BFD_INTEGRATION_SOURCE_STR - BFD_INTEGRATION_SOURCEV4_STR - BFD_PROFILE_STR - BFD_PROFILE_NAME_STR) + NO_STR IPV6_STR + "Establish static routes\n" + "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" + "IPv6 source-dest route\n" + "IPv6 source prefix\n" + "IPv6 gateway address\n" + "IPv6 gateway interface name\n" + "Null interface\n" + "Set tag for this route\n" + "Tag value\n" + "Distance value for this prefix\n" VRF_CMD_HELP_STR MPLS_LABEL_HELPSTR + "Table to configure\n" + "The table number to configure\n" VRF_CMD_HELP_STR + "Treat the nexthop as directly attached to the interface\n" + "SR-TE color\n" + "The SR-TE color to configure\n" BFD_INTEGRATION_STR + BFD_INTEGRATION_MULTI_HOP_STR BFD_INTEGRATION_SOURCE_STR + BFD_INTEGRATION_SOURCEV4_STR BFD_PROFILE_STR + BFD_PROFILE_NAME_STR "Value of segs\n" + "Segs (SIDs)\n") { struct static_route_args args = { .delete = !!no, @@ -981,14 +1049,15 @@ DEFPY_YANG(ipv6_route_address_interface, .bfd_multi_hop = !!bfd_multi_hop, .bfd_source = bfd_source_str, .bfd_profile = bfd_profile, + .segs = segments, }; return static_route_nb_run(vty, &args); } DEFPY_YANG(ipv6_route_address_interface_vrf, - ipv6_route_address_interface_vrf_cmd, - "[no] ipv6 route X:X::X:X/M$prefix [from X:X::X:X/M] \ + ipv6_route_address_interface_vrf_cmd, + "[no] ipv6 route X:X::X:X/M$prefix [from X:X::X:X/M] \ X:X::X:X$gate \ <INTERFACE|Null0>$ifname \ [{ \ @@ -1000,32 +1069,28 @@ DEFPY_YANG(ipv6_route_address_interface_vrf, |onlink$onlink \ |color (1-4294967295) \ |bfd$bfd [{multi-hop$bfd_multi_hop|source X:X::X:X$bfd_source|profile BFDPROF$bfd_profile}] \ + |segments WORD \ }]", - NO_STR - IPV6_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 source-dest route\n" - "IPv6 source prefix\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - MPLS_LABEL_HELPSTR - "Table to configure\n" - "The table number to configure\n" - VRF_CMD_HELP_STR - "Treat the nexthop as directly attached to the interface\n" - "SR-TE color\n" - "The SR-TE color to configure\n" - BFD_INTEGRATION_STR - BFD_INTEGRATION_MULTI_HOP_STR - BFD_INTEGRATION_SOURCE_STR - BFD_INTEGRATION_SOURCEV4_STR - BFD_PROFILE_STR - BFD_PROFILE_NAME_STR) + NO_STR IPV6_STR + "Establish static routes\n" + "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" + "IPv6 source-dest route\n" + "IPv6 source prefix\n" + "IPv6 gateway address\n" + "IPv6 gateway interface name\n" + "Null interface\n" + "Set tag for this route\n" + "Tag value\n" + "Distance value for this prefix\n" MPLS_LABEL_HELPSTR + "Table to configure\n" + "The table number to configure\n" VRF_CMD_HELP_STR + "Treat the nexthop as directly attached to the interface\n" + "SR-TE color\n" + "The SR-TE color to configure\n" BFD_INTEGRATION_STR + BFD_INTEGRATION_MULTI_HOP_STR BFD_INTEGRATION_SOURCE_STR + BFD_INTEGRATION_SOURCEV4_STR BFD_PROFILE_STR + BFD_PROFILE_NAME_STR "Value of segs\n" + "Segs (SIDs)\n") { struct static_route_args args = { .delete = !!no, @@ -1047,14 +1112,14 @@ DEFPY_YANG(ipv6_route_address_interface_vrf, .bfd_multi_hop = !!bfd_multi_hop, .bfd_source = bfd_source_str, .bfd_profile = bfd_profile, + .segs = segments, }; return static_route_nb_run(vty, &args); } -DEFPY_YANG(ipv6_route, - ipv6_route_cmd, - "[no] ipv6 route X:X::X:X/M$prefix [from X:X::X:X/M] \ +DEFPY_YANG(ipv6_route, ipv6_route_cmd, + "[no] ipv6 route X:X::X:X/M$prefix [from X:X::X:X/M] \ <X:X::X:X$gate|<INTERFACE|Null0>$ifname> \ [{ \ tag (1-4294967295) \ @@ -1065,32 +1130,26 @@ DEFPY_YANG(ipv6_route, |nexthop-vrf NAME \ |color (1-4294967295) \ |bfd$bfd [{multi-hop$bfd_multi_hop|source X:X::X:X$bfd_source|profile BFDPROF$bfd_profile}] \ + |segments WORD \ }]", - NO_STR - IPV6_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 source-dest route\n" - "IPv6 source prefix\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR - "Table to configure\n" - "The table number to configure\n" - VRF_CMD_HELP_STR - "SR-TE color\n" - "The SR-TE color to configure\n" - BFD_INTEGRATION_STR - BFD_INTEGRATION_MULTI_HOP_STR - BFD_INTEGRATION_SOURCE_STR - BFD_INTEGRATION_SOURCEV4_STR - BFD_PROFILE_STR - BFD_PROFILE_NAME_STR) + NO_STR IPV6_STR + "Establish static routes\n" + "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" + "IPv6 source-dest route\n" + "IPv6 source prefix\n" + "IPv6 gateway address\n" + "IPv6 gateway interface name\n" + "Null interface\n" + "Set tag for this route\n" + "Tag value\n" + "Distance value for this prefix\n" VRF_CMD_HELP_STR MPLS_LABEL_HELPSTR + "Table to configure\n" + "The table number to configure\n" VRF_CMD_HELP_STR "SR-TE color\n" + "The SR-TE color to configure\n" BFD_INTEGRATION_STR + BFD_INTEGRATION_MULTI_HOP_STR BFD_INTEGRATION_SOURCE_STR + BFD_INTEGRATION_SOURCEV4_STR BFD_PROFILE_STR + BFD_PROFILE_NAME_STR "Value of segs\n" + "Segs (SIDs)\n") { struct static_route_args args = { .delete = !!no, @@ -1111,14 +1170,15 @@ DEFPY_YANG(ipv6_route, .bfd_multi_hop = !!bfd_multi_hop, .bfd_source = bfd_source_str, .bfd_profile = bfd_profile, + .segs = segments, + }; return static_route_nb_run(vty, &args); } -DEFPY_YANG(ipv6_route_vrf, - ipv6_route_vrf_cmd, - "[no] ipv6 route X:X::X:X/M$prefix [from X:X::X:X/M] \ +DEFPY_YANG(ipv6_route_vrf, ipv6_route_vrf_cmd, + "[no] ipv6 route X:X::X:X/M$prefix [from X:X::X:X/M] \ <X:X::X:X$gate|<INTERFACE|Null0>$ifname> \ [{ \ tag (1-4294967295) \ @@ -1128,31 +1188,26 @@ DEFPY_YANG(ipv6_route_vrf, |nexthop-vrf NAME \ |color (1-4294967295) \ |bfd$bfd [{multi-hop$bfd_multi_hop|source X:X::X:X$bfd_source|profile BFDPROF$bfd_profile}] \ + |segments WORD \ }]", - NO_STR - IPV6_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 source-dest route\n" - "IPv6 source prefix\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - MPLS_LABEL_HELPSTR - "Table to configure\n" - "The table number to configure\n" - VRF_CMD_HELP_STR - "SR-TE color\n" - "The SR-TE color to configure\n" - BFD_INTEGRATION_STR - BFD_INTEGRATION_MULTI_HOP_STR - BFD_INTEGRATION_SOURCE_STR - BFD_INTEGRATION_SOURCEV4_STR - BFD_PROFILE_STR - BFD_PROFILE_NAME_STR) + NO_STR IPV6_STR + "Establish static routes\n" + "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" + "IPv6 source-dest route\n" + "IPv6 source prefix\n" + "IPv6 gateway address\n" + "IPv6 gateway interface name\n" + "Null interface\n" + "Set tag for this route\n" + "Tag value\n" + "Distance value for this prefix\n" MPLS_LABEL_HELPSTR + "Table to configure\n" + "The table number to configure\n" VRF_CMD_HELP_STR "SR-TE color\n" + "The SR-TE color to configure\n" BFD_INTEGRATION_STR + BFD_INTEGRATION_MULTI_HOP_STR BFD_INTEGRATION_SOURCE_STR + BFD_INTEGRATION_SOURCEV4_STR BFD_PROFILE_STR + BFD_PROFILE_NAME_STR "Value of segs\n" + "Segs (SIDs)\n") { struct static_route_args args = { .delete = !!no, @@ -1173,13 +1228,16 @@ DEFPY_YANG(ipv6_route_vrf, .bfd_multi_hop = !!bfd_multi_hop, .bfd_source = bfd_source_str, .bfd_profile = bfd_profile, + .segs = segments, }; return static_route_nb_run(vty, &args); } -void static_cli_show(struct vty *vty, const struct lyd_node *dnode, - bool show_defaults) +#ifdef INCLUDE_MGMTD_CMDDEFS_ONLY + +static void static_cli_show(struct vty *vty, const struct lyd_node *dnode, + bool show_defaults) { const char *vrf; @@ -1188,7 +1246,7 @@ void static_cli_show(struct vty *vty, const struct lyd_node *dnode, vty_out(vty, "vrf %s\n", vrf); } -void static_cli_show_end(struct vty *vty, const struct lyd_node *dnode) +static void static_cli_show_end(struct vty *vty, const struct lyd_node *dnode) { const char *vrf; @@ -1206,13 +1264,46 @@ static int mpls_label_iter_cb(const struct lyd_node *dnode, void *arg) { struct mpls_label_iter *iter = arg; - if (yang_dnode_exists(dnode, "./label")) { + if (yang_dnode_exists(dnode, "label")) { if (iter->first) vty_out(iter->vty, " label %s", - yang_dnode_get_string(dnode, "./label")); + yang_dnode_get_string(dnode, "label")); else vty_out(iter->vty, "/%s", - yang_dnode_get_string(dnode, "./label")); + yang_dnode_get_string(dnode, "label")); + iter->first = false; + } + + return YANG_ITER_CONTINUE; +} + +struct srv6_seg_iter { + struct vty *vty; + bool first; +}; + +static int srv6_seg_iter_cb(const struct lyd_node *dnode, void *arg) +{ + struct srv6_seg_iter *iter = arg; + char buffer[INET6_ADDRSTRLEN]; + struct in6_addr cli_seg; + + if (yang_dnode_exists(dnode, "seg")) { + if (iter->first) { + yang_dnode_get_ipv6(&cli_seg, dnode, "seg"); + if (inet_ntop(AF_INET6, &cli_seg, buffer, + INET6_ADDRSTRLEN) == NULL) { + return 1; + } + vty_out(iter->vty, " segments %s", buffer); + } else { + yang_dnode_get_ipv6(&cli_seg, dnode, "seg"); + if (inet_ntop(AF_INET6, &cli_seg, buffer, + INET6_ADDRSTRLEN) == NULL) { + return 1; + } + vty_out(iter->vty, "/%s", buffer); + } iter->first = false; } @@ -1233,13 +1324,14 @@ static void nexthop_cli_show(struct vty *vty, const struct lyd_node *route, uint32_t tag; uint8_t distance; struct mpls_label_iter iter; + struct srv6_seg_iter seg_iter; const char *nexthop_vrf; uint32_t table_id; bool onlink; vrf = yang_dnode_get_string(route, "../../vrf"); - afi_safi = yang_dnode_get_string(route, "./afi-safi"); + afi_safi = yang_dnode_get_string(route, "afi-safi"); yang_afi_safi_identity2value(afi_safi, &afi, &safi); if (afi == AFI_IP) @@ -1254,32 +1346,32 @@ static void nexthop_cli_show(struct vty *vty, const struct lyd_node *route, else vty_out(vty, " mroute"); - vty_out(vty, " %s", yang_dnode_get_string(route, "./prefix")); + vty_out(vty, " %s", yang_dnode_get_string(route, "prefix")); if (src) vty_out(vty, " from %s", - yang_dnode_get_string(src, "./src-prefix")); + yang_dnode_get_string(src, "src-prefix")); - nh_type = yang_dnode_get_enum(nexthop, "./nh-type"); + nh_type = yang_dnode_get_enum(nexthop, "nh-type"); switch (nh_type) { case STATIC_IFNAME: vty_out(vty, " %s", - yang_dnode_get_string(nexthop, "./interface")); + yang_dnode_get_string(nexthop, "interface")); break; case STATIC_IPV4_GATEWAY: case STATIC_IPV6_GATEWAY: vty_out(vty, " %s", - yang_dnode_get_string(nexthop, "./gateway")); + yang_dnode_get_string(nexthop, "gateway")); break; case STATIC_IPV4_GATEWAY_IFNAME: case STATIC_IPV6_GATEWAY_IFNAME: vty_out(vty, " %s", - yang_dnode_get_string(nexthop, "./gateway")); + yang_dnode_get_string(nexthop, "gateway")); vty_out(vty, " %s", - yang_dnode_get_string(nexthop, "./interface")); + yang_dnode_get_string(nexthop, "interface")); break; case STATIC_BLACKHOLE: - bh_type = yang_dnode_get_enum(nexthop, "./bh-type"); + bh_type = yang_dnode_get_enum(nexthop, "bh-type"); switch (bh_type) { case STATIC_BLACKHOLE_DROP: vty_out(vty, " blackhole"); @@ -1294,13 +1386,13 @@ static void nexthop_cli_show(struct vty *vty, const struct lyd_node *route, break; } - if (yang_dnode_exists(path, "./tag")) { - tag = yang_dnode_get_uint32(path, "./tag"); + if (yang_dnode_exists(path, "tag")) { + tag = yang_dnode_get_uint32(path, "tag"); if (tag != 0 || show_defaults) vty_out(vty, " tag %" PRIu32, tag); } - distance = yang_dnode_get_uint8(path, "./distance"); + distance = yang_dnode_get_uint8(path, "distance"); if (distance != ZEBRA_STATIC_DISTANCE_DEFAULT || show_defaults) vty_out(vty, " %" PRIu8, distance); @@ -1309,48 +1401,54 @@ static void nexthop_cli_show(struct vty *vty, const struct lyd_node *route, yang_dnode_iterate(mpls_label_iter_cb, &iter, nexthop, "./mpls-label-stack/entry"); - nexthop_vrf = yang_dnode_get_string(nexthop, "./vrf"); + seg_iter.vty = vty; + seg_iter.first = true; + yang_dnode_iterate(srv6_seg_iter_cb, &seg_iter, nexthop, + "./srv6-segs-stack/entry"); + + nexthop_vrf = yang_dnode_get_string(nexthop, "vrf"); if (strcmp(vrf, nexthop_vrf)) vty_out(vty, " nexthop-vrf %s", nexthop_vrf); - table_id = yang_dnode_get_uint32(path, "./table-id"); + table_id = yang_dnode_get_uint32(path, "table-id"); if (table_id || show_defaults) vty_out(vty, " table %" PRIu32, table_id); - if (yang_dnode_exists(nexthop, "./onlink")) { - onlink = yang_dnode_get_bool(nexthop, "./onlink"); + if (yang_dnode_exists(nexthop, "onlink")) { + onlink = yang_dnode_get_bool(nexthop, "onlink"); if (onlink) vty_out(vty, " onlink"); } - if (yang_dnode_exists(nexthop, "./srte-color")) + if (yang_dnode_exists(nexthop, "srte-color")) vty_out(vty, " color %s", - yang_dnode_get_string(nexthop, "./srte-color")); + yang_dnode_get_string(nexthop, "srte-color")); - if (yang_dnode_exists(nexthop, "./bfd-monitoring")) { + if (yang_dnode_exists(nexthop, "bfd-monitoring")) { const struct lyd_node *bfd_dnode = - yang_dnode_get(nexthop, "./bfd-monitoring"); + yang_dnode_get(nexthop, "bfd-monitoring"); - if (yang_dnode_get_bool(bfd_dnode, "./multi-hop")) { + if (yang_dnode_get_bool(bfd_dnode, "multi-hop")) { vty_out(vty, " bfd multi-hop"); - if (yang_dnode_exists(bfd_dnode, "./source")) + if (yang_dnode_exists(bfd_dnode, "source")) vty_out(vty, " source %s", yang_dnode_get_string(bfd_dnode, "./source")); } else vty_out(vty, " bfd"); - if (yang_dnode_exists(bfd_dnode, "./profile")) + if (yang_dnode_exists(bfd_dnode, "profile")) vty_out(vty, " profile %s", - yang_dnode_get_string(bfd_dnode, "./profile")); + yang_dnode_get_string(bfd_dnode, "profile")); } vty_out(vty, "\n"); } -void static_nexthop_cli_show(struct vty *vty, const struct lyd_node *dnode, - bool show_defaults) +static void static_nexthop_cli_show(struct vty *vty, + const struct lyd_node *dnode, + bool show_defaults) { const struct lyd_node *path = yang_dnode_get_parent(dnode, "path-list"); const struct lyd_node *route = @@ -1359,8 +1457,9 @@ void static_nexthop_cli_show(struct vty *vty, const struct lyd_node *dnode, nexthop_cli_show(vty, route, NULL, path, dnode, show_defaults); } -void static_src_nexthop_cli_show(struct vty *vty, const struct lyd_node *dnode, - bool show_defaults) +static void static_src_nexthop_cli_show(struct vty *vty, + const struct lyd_node *dnode, + bool show_defaults) { const struct lyd_node *path = yang_dnode_get_parent(dnode, "path-list"); const struct lyd_node *src = yang_dnode_get_parent(path, "src-list"); @@ -1369,15 +1468,16 @@ void static_src_nexthop_cli_show(struct vty *vty, const struct lyd_node *dnode, nexthop_cli_show(vty, route, src, path, dnode, show_defaults); } -int static_nexthop_cli_cmp(const struct lyd_node *dnode1, - const struct lyd_node *dnode2) +static int static_nexthop_cli_cmp(const struct lyd_node *dnode1, + const struct lyd_node *dnode2) { enum static_nh_type nh_type1, nh_type2; struct prefix prefix1, prefix2; + const char *vrf1, *vrf2; int ret = 0; - nh_type1 = yang_dnode_get_enum(dnode1, "./nh-type"); - nh_type2 = yang_dnode_get_enum(dnode2, "./nh-type"); + nh_type1 = yang_dnode_get_enum(dnode1, "nh-type"); + nh_type2 = yang_dnode_get_enum(dnode2, "nh-type"); if (nh_type1 != nh_type2) return (int)nh_type1 - (int)nh_type2; @@ -1385,24 +1485,24 @@ int static_nexthop_cli_cmp(const struct lyd_node *dnode1, switch (nh_type1) { case STATIC_IFNAME: ret = if_cmp_name_func( - yang_dnode_get_string(dnode1, "./interface"), - yang_dnode_get_string(dnode2, "./interface")); + yang_dnode_get_string(dnode1, "interface"), + yang_dnode_get_string(dnode2, "interface")); break; case STATIC_IPV4_GATEWAY: case STATIC_IPV6_GATEWAY: - yang_dnode_get_prefix(&prefix1, dnode1, "./gateway"); - yang_dnode_get_prefix(&prefix2, dnode2, "./gateway"); + yang_dnode_get_prefix(&prefix1, dnode1, "gateway"); + yang_dnode_get_prefix(&prefix2, dnode2, "gateway"); ret = prefix_cmp(&prefix1, &prefix2); break; case STATIC_IPV4_GATEWAY_IFNAME: case STATIC_IPV6_GATEWAY_IFNAME: - yang_dnode_get_prefix(&prefix1, dnode1, "./gateway"); - yang_dnode_get_prefix(&prefix2, dnode2, "./gateway"); + yang_dnode_get_prefix(&prefix1, dnode1, "gateway"); + yang_dnode_get_prefix(&prefix2, dnode2, "gateway"); ret = prefix_cmp(&prefix1, &prefix2); if (!ret) ret = if_cmp_name_func( - yang_dnode_get_string(dnode1, "./interface"), - yang_dnode_get_string(dnode2, "./interface")); + yang_dnode_get_string(dnode1, "interface"), + yang_dnode_get_string(dnode2, "interface")); break; case STATIC_BLACKHOLE: /* There's only one blackhole nexthop per route */ @@ -1413,22 +1513,28 @@ int static_nexthop_cli_cmp(const struct lyd_node *dnode1, if (ret) return ret; - return if_cmp_name_func(yang_dnode_get_string(dnode1, "./vrf"), - yang_dnode_get_string(dnode2, "./vrf")); + vrf1 = yang_dnode_get_string(dnode1, "vrf"); + if (strmatch(vrf1, "default")) + vrf1 = ""; + vrf2 = yang_dnode_get_string(dnode2, "vrf"); + if (strmatch(vrf2, "default")) + vrf2 = ""; + + return if_cmp_name_func(vrf1, vrf2); } -int static_route_list_cli_cmp(const struct lyd_node *dnode1, - const struct lyd_node *dnode2) +static int static_route_list_cli_cmp(const struct lyd_node *dnode1, + const struct lyd_node *dnode2) { const char *afi_safi1, *afi_safi2; afi_t afi1, afi2; safi_t safi1, safi2; struct prefix prefix1, prefix2; - afi_safi1 = yang_dnode_get_string(dnode1, "./afi-safi"); + afi_safi1 = yang_dnode_get_string(dnode1, "afi-safi"); yang_afi_safi_identity2value(afi_safi1, &afi1, &safi1); - afi_safi2 = yang_dnode_get_string(dnode2, "./afi-safi"); + afi_safi2 = yang_dnode_get_string(dnode2, "afi-safi"); yang_afi_safi_identity2value(afi_safi2, &afi2, &safi2); if (afi1 != afi2) @@ -1437,41 +1543,98 @@ int static_route_list_cli_cmp(const struct lyd_node *dnode1, if (safi1 != safi2) return (int)safi1 - (int)safi2; - yang_dnode_get_prefix(&prefix1, dnode1, "./prefix"); - yang_dnode_get_prefix(&prefix2, dnode2, "./prefix"); + yang_dnode_get_prefix(&prefix1, dnode1, "prefix"); + yang_dnode_get_prefix(&prefix2, dnode2, "prefix"); return prefix_cmp(&prefix1, &prefix2); } -int static_src_list_cli_cmp(const struct lyd_node *dnode1, - const struct lyd_node *dnode2) +static int static_src_list_cli_cmp(const struct lyd_node *dnode1, + const struct lyd_node *dnode2) { struct prefix prefix1, prefix2; - yang_dnode_get_prefix(&prefix1, dnode1, "./src-prefix"); - yang_dnode_get_prefix(&prefix2, dnode2, "./src-prefix"); + yang_dnode_get_prefix(&prefix1, dnode1, "src-prefix"); + yang_dnode_get_prefix(&prefix2, dnode2, "src-prefix"); return prefix_cmp(&prefix1, &prefix2); } -int static_path_list_cli_cmp(const struct lyd_node *dnode1, - const struct lyd_node *dnode2) +static int static_path_list_cli_cmp(const struct lyd_node *dnode1, + const struct lyd_node *dnode2) { uint32_t table_id1, table_id2; uint8_t distance1, distance2; - table_id1 = yang_dnode_get_uint32(dnode1, "./table-id"); - table_id2 = yang_dnode_get_uint32(dnode2, "./table-id"); + table_id1 = yang_dnode_get_uint32(dnode1, "table-id"); + table_id2 = yang_dnode_get_uint32(dnode2, "table-id"); if (table_id1 != table_id2) return (int)table_id1 - (int)table_id2; - distance1 = yang_dnode_get_uint8(dnode1, "./distance"); - distance2 = yang_dnode_get_uint8(dnode2, "./distance"); + distance1 = yang_dnode_get_uint8(dnode1, "distance"); + distance2 = yang_dnode_get_uint8(dnode2, "distance"); return (int)distance1 - (int)distance2; } +const struct frr_yang_module_info frr_staticd_info = { + .name = "frr-staticd", + .ignore_cfg_cbs = true, + .nodes = { + { + .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd", + .cbs = { + .cli_show = static_cli_show, + .cli_show_end = static_cli_show_end, + } + }, + { + .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list", + .cbs = { + .cli_cmp = static_route_list_cli_cmp, + } + }, + { + .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list", + .cbs = { + .cli_cmp = static_path_list_cli_cmp, + } + }, + { + .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop", + .cbs = { + .cli_show = static_nexthop_cli_show, + .cli_cmp = static_nexthop_cli_cmp, + } + }, + { + .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list", + .cbs = { + .cli_cmp = static_src_list_cli_cmp, + } + }, + { + .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list", + .cbs = { + .cli_cmp = static_path_list_cli_cmp, + } + }, + { + .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop", + .cbs = { + .cli_show = static_src_nexthop_cli_show, + .cli_cmp = static_nexthop_cli_cmp, + } + }, + { + .xpath = NULL, + }, + } +}; + +#else /* ifdef INCLUDE_MGMTD_CMDDEFS_ONLY */ + DEFPY_YANG(debug_staticd, debug_staticd_cmd, "[no] debug static [{events$events|route$route|bfd$bfd}]", NO_STR DEBUG_STR STATICD_STR @@ -1479,18 +1642,15 @@ DEFPY_YANG(debug_staticd, debug_staticd_cmd, "Debug route\n" "Debug bfd\n") { -#ifndef INCLUDE_MGMTD_CMDDEFS_ONLY /* If no specific category, change all */ if (strmatch(argv[argc - 1]->text, "static")) static_debug_set(vty->node, !no, true, true, true); else static_debug_set(vty->node, !no, !!events, !!route, !!bfd); -#endif /* ifndef INCLUDE_MGMTD_CMDDEFS_ONLY */ return CMD_SUCCESS; } -#ifndef INCLUDE_MGMTD_CMDDEFS_ONLY DEFPY(staticd_show_bfd_routes, staticd_show_bfd_routes_cmd, "show bfd static route [json]$isjson", SHOW_STR @@ -1532,6 +1692,8 @@ void static_vty_init(void) { #ifndef INCLUDE_MGMTD_CMDDEFS_ONLY install_node(&debug_node); + install_element(ENABLE_NODE, &debug_staticd_cmd); + install_element(CONFIG_NODE, &debug_staticd_cmd); install_element(ENABLE_NODE, &show_debugging_static_cmd); install_element(ENABLE_NODE, &staticd_show_bfd_routes_cmd); #endif /* ifndef INCLUDE_MGMTD_CMDDEFS_ONLY */ @@ -1552,8 +1714,5 @@ void static_vty_init(void) install_element(CONFIG_NODE, &ipv6_route_cmd); install_element(VRF_NODE, &ipv6_route_vrf_cmd); - install_element(ENABLE_NODE, &debug_staticd_cmd); - install_element(CONFIG_NODE, &debug_staticd_cmd); - mgmt_be_client_lib_vty_init(); } diff --git a/staticd/static_vty.h b/staticd/static_vty.h index 77e52b5bdf..4b4cc1c3bf 100644 --- a/staticd/static_vty.h +++ b/staticd/static_vty.h @@ -11,22 +11,6 @@ extern "C" { #endif -void static_cli_show(struct vty *vty, const struct lyd_node *dnode, - bool show_defaults); -void static_cli_show_end(struct vty *vty, const struct lyd_node *dnode); -void static_nexthop_cli_show(struct vty *vty, const struct lyd_node *dnode, - bool show_defaults); -void static_src_nexthop_cli_show(struct vty *vty, const struct lyd_node *dnode, - bool show_defaults); -int static_nexthop_cli_cmp(const struct lyd_node *dnode1, - const struct lyd_node *dnode2); -int static_route_list_cli_cmp(const struct lyd_node *dnode1, - const struct lyd_node *dnode2); -int static_src_list_cli_cmp(const struct lyd_node *dnode1, - const struct lyd_node *dnode2); -int static_path_list_cli_cmp(const struct lyd_node *dnode1, - const struct lyd_node *dnode2); - void static_vty_init(void); #ifdef __cplusplus diff --git a/staticd/static_zebra.c b/staticd/static_zebra.c index 4f3ccde53d..68761c0084 100644 --- a/staticd/static_zebra.c +++ b/staticd/static_zebra.c @@ -166,6 +166,7 @@ static int route_notify_owner(ZAPI_CALLBACK_ARGS) static void zebra_connected(struct zclient *zclient) { + zebra_route_notify_send(ZEBRA_ROUTE_NOTIFY_REQUEST, zclient, true); zclient_send_reg_requests(zclient, VRF_DEFAULT); static_fixup_vrf_ids(vrf_info_lookup(VRF_DEFAULT)); @@ -186,48 +187,40 @@ static_nexthop_is_local(vrf_id_t vrfid, struct prefix *addr, int family) } return false; } -static int static_zebra_nexthop_update(ZAPI_CALLBACK_ARGS) + +static void static_zebra_nexthop_update(struct vrf *vrf, struct prefix *matched, + struct zapi_route *nhr) { struct static_nht_data *nhtd, lookup; - struct zapi_route nhr; - struct prefix matched; afi_t afi = AFI_IP; - if (!zapi_nexthop_update_decode(zclient->ibuf, &matched, &nhr)) { - zlog_err("Failure to decode nexthop update message"); - return 1; - } - if (zclient->bfd_integration) - bfd_nht_update(&matched, &nhr); + bfd_nht_update(matched, nhr); - if (matched.family == AF_INET6) + if (matched->family == AF_INET6) afi = AFI_IP6; - if (nhr.type == ZEBRA_ROUTE_CONNECT) { - if (static_nexthop_is_local(vrf_id, &matched, - nhr.prefix.family)) - nhr.nexthop_num = 0; + if (nhr->type == ZEBRA_ROUTE_CONNECT) { + if (static_nexthop_is_local(vrf->vrf_id, matched, + nhr->prefix.family)) + nhr->nexthop_num = 0; } memset(&lookup, 0, sizeof(lookup)); - lookup.nh = matched; - lookup.nh_vrf_id = vrf_id; - lookup.safi = nhr.safi; + lookup.nh = *matched; + lookup.nh_vrf_id = vrf->vrf_id; + lookup.safi = nhr->safi; nhtd = static_nht_hash_find(static_nht_hash, &lookup); if (nhtd) { - nhtd->nh_num = nhr.nexthop_num; + nhtd->nh_num = nhr->nexthop_num; - static_nht_reset_start(&matched, afi, nhr.safi, - nhtd->nh_vrf_id); - static_nht_update(NULL, &matched, nhr.nexthop_num, afi, - nhr.safi, nhtd->nh_vrf_id); + static_nht_reset_start(matched, afi, nhr->safi, nhtd->nh_vrf_id); + static_nht_update(NULL, matched, nhr->nexthop_num, afi, + nhr->safi, nhtd->nh_vrf_id); } else zlog_err("No nhtd?"); - - return 1; } static void static_zebra_capabilities(struct zclient_capabilities *cap) @@ -499,6 +492,21 @@ extern void static_zebra_route_add(struct static_path *pn, bool install) for (i = 0; i < api_nh->label_num; i++) api_nh->labels[i] = nh->snh_label.label[i]; } + if (nh->snh_seg.num_segs) { + int i; + + api_nh->seg6local_action = + ZEBRA_SEG6_LOCAL_ACTION_UNSPEC; + SET_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_SEG6); + SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION); + api.safi = SAFI_UNICAST; + + api_nh->seg_num = nh->snh_seg.num_segs; + for (i = 0; i < api_nh->seg_num; i++) + memcpy(&api_nh->seg6_segs[i], + &nh->snh_seg.seg[i], + sizeof(struct in6_addr)); + } nh_num++; } @@ -520,22 +528,22 @@ static zclient_handler *const static_handlers[] = { [ZEBRA_INTERFACE_ADDRESS_ADD] = interface_address_add, [ZEBRA_INTERFACE_ADDRESS_DELETE] = interface_address_delete, [ZEBRA_ROUTE_NOTIFY_OWNER] = route_notify_owner, - [ZEBRA_NEXTHOP_UPDATE] = static_zebra_nexthop_update, }; void static_zebra_init(void) { - struct zclient_options opt = { .receive_notify = true }; - - if_zapi_callbacks(static_ifp_create, static_ifp_up, - static_ifp_down, static_ifp_destroy); + hook_register_prio(if_real, 0, static_ifp_create); + hook_register_prio(if_up, 0, static_ifp_up); + hook_register_prio(if_down, 0, static_ifp_down); + hook_register_prio(if_unreal, 0, static_ifp_destroy); - zclient = zclient_new(master, &opt, static_handlers, + zclient = zclient_new(master, &zclient_options_default, static_handlers, array_size(static_handlers)); zclient_init(zclient, ZEBRA_ROUTE_STATIC, 0, &static_privs); zclient->zebra_capabilities = static_zebra_capabilities; zclient->zebra_connected = zebra_connected; + zclient->nexthop_update = static_zebra_nexthop_update; static_nht_hash_init(static_nht_hash); static_bfd_initialize(zclient, master); diff --git a/staticd/subdir.am b/staticd/subdir.am index 022428281f..07ebe3c02c 100644 --- a/staticd/subdir.am +++ b/staticd/subdir.am @@ -36,7 +36,7 @@ clippy_scan += \ # end staticd_staticd_SOURCES = staticd/static_main.c -staticd_staticd_LDADD = staticd/libstatic.a lib/libfrr.la $(LIBCAP) +staticd_staticd_LDADD = staticd/libstatic.a lib/libfrr.la $(LIBCAP) $(LIBYANG_LIBS) nodist_staticd_staticd_SOURCES = \ yang/frr-bfdd.yang.c \ diff --git a/tests/.gitignore b/tests/.gitignore index f00177abd8..681438f4a5 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -29,6 +29,7 @@ frr_northbound* /lib/test_buffer /lib/test_checksum /lib/test_frrscript +/lib/test_darr /lib/test_frrlua /lib/test_graph /lib/test_grpc diff --git a/tests/bgpd/test_aspath.c b/tests/bgpd/test_aspath.c index 57aa2af9de..799733b7b5 100644 --- a/tests/bgpd/test_aspath.c +++ b/tests/bgpd/test_aspath.c @@ -1343,10 +1343,11 @@ static int handle_attr_test(struct aspath_tests *t) bgp.asnotation = t->segment->asnotation; peer.curr = stream_new(BGP_MAX_PACKET_SIZE); - peer.obuf = stream_fifo_new(); + peer.connection = bgp_peer_connection_new(&peer); + peer.connection->obuf = stream_fifo_new(); peer.bgp = &bgp; peer.host = (char *)"none"; - peer.fd = -1; + peer.connection->fd = -1; peer.cap = t->cap; peer.max_packet_size = BGP_STANDARD_MESSAGE_MAX_PACKET_SIZE; diff --git a/tests/bgpd/test_capability.c b/tests/bgpd/test_capability.c index da17471fd1..38f896b30c 100644 --- a/tests/bgpd/test_capability.c +++ b/tests/bgpd/test_capability.c @@ -835,7 +835,7 @@ static void parse_test(struct peer *peer, struct test_segment *t, int type) switch (type) { case CAPABILITY: len += 2; /* to cover the OPT-Param header */ - _FALLTHROUGH + fallthrough; case OPT_PARAM: printf("len: %u\n", len); /* peek_for_as4 wants getp at capibility*/ @@ -847,7 +847,7 @@ static void parse_test(struct peer *peer, struct test_segment *t, int type) ret = bgp_open_option_parse(peer, len, &capability); break; case DYNCAP: - ret = bgp_capability_receive(peer, t->len); + ret = bgp_capability_receive(peer->connection, peer, t->len); break; default: printf("unknown type %u\n", type); @@ -972,7 +972,8 @@ int main(void) parse_test(peer, &opt_params[i++], OPT_PARAM); SET_FLAG(peer->cap, PEER_CAP_DYNAMIC_ADV); - peer->status = Established; + peer->connection = bgp_peer_connection_new(peer); + peer->connection->status = Established; i = 0; while (dynamic_cap_msgs[i].name) diff --git a/tests/bgpd/test_mp_attr.c b/tests/bgpd/test_mp_attr.c index ae7903e0cc..cebdda9e5c 100644 --- a/tests/bgpd/test_mp_attr.c +++ b/tests/bgpd/test_mp_attr.c @@ -1085,7 +1085,8 @@ int main(void) peer = peer_create_accept(bgp); peer->host = (char *)"foo"; - peer->status = Established; + peer->connection = bgp_peer_connection_new(peer); + peer->connection->status = Established; peer->curr = stream_new(BGP_MAX_PACKET_SIZE); ifp.ifindex = 0; diff --git a/tests/bgpd/test_mpath.c b/tests/bgpd/test_mpath.c index 0124ad9b22..ebbe3ac3e2 100644 --- a/tests/bgpd/test_mpath.c +++ b/tests/bgpd/test_mpath.c @@ -244,6 +244,7 @@ static int run_bgp_mp_list(testcase_t *t) for (i = 0, mp_node = mp_list.head; i < test_mp_list_info_count; i++, mp_node = listnextnode(mp_node)) { info = listgetdata(mp_node); + info->lock++; EXPECT_TRUE(info == &test_mp_list_info[i], test_result); } @@ -274,14 +275,14 @@ testcase_t test_bgp_mp_list = { * Testcase for bgp_path_info_mpath_update */ -struct bgp_node test_rn; +static struct bgp_dest *dest; static int setup_bgp_path_info_mpath_update(testcase_t *t) { int i; struct bgp *bgp; struct bgp_table *rt; - struct route_node *rt_node; + struct prefix p; as_t asn = 1; t->tmp_data = bgp_create_fake(&asn, NULL); @@ -294,13 +295,12 @@ static int setup_bgp_path_info_mpath_update(testcase_t *t) if (!rt) return -1; - str2prefix("42.1.1.0/24", &test_rn.p); - rt_node = bgp_dest_to_rnode(&test_rn); - memcpy((struct route_table *)&rt_node->table, &rt->route_table, - sizeof(struct route_table)); + str2prefix("42.1.1.0/24", &p); + dest = bgp_node_get(rt, &p); + setup_bgp_mp_list(t); for (i = 0; i < test_mp_list_info_count; i++) - bgp_path_info_add(&test_rn, &test_mp_list_info[i]); + bgp_path_info_add(dest, &test_mp_list_info[i]); return 0; } @@ -309,6 +309,7 @@ static int run_bgp_path_info_mpath_update(testcase_t *t) struct bgp_path_info *new_best, *old_best, *mpath; struct list mp_list; struct bgp_maxpaths_cfg mp_cfg = {3, 3}; + int test_result = TEST_PASSED; bgp_mp_list_init(&mp_list); bgp_mp_list_add(&mp_list, &test_mp_list_info[4]); @@ -317,7 +318,7 @@ static int run_bgp_path_info_mpath_update(testcase_t *t) bgp_mp_list_add(&mp_list, &test_mp_list_info[1]); new_best = &test_mp_list_info[3]; old_best = NULL; - bgp_path_info_mpath_update(NULL, &test_rn, new_best, old_best, &mp_list, + bgp_path_info_mpath_update(NULL, dest, new_best, old_best, &mp_list, &mp_cfg); bgp_mp_list_clear(&mp_list); EXPECT_TRUE(bgp_path_info_mpath_count(new_best) == 2, test_result); @@ -332,7 +333,7 @@ static int run_bgp_path_info_mpath_update(testcase_t *t) bgp_mp_list_add(&mp_list, &test_mp_list_info[1]); new_best = &test_mp_list_info[0]; old_best = &test_mp_list_info[3]; - bgp_path_info_mpath_update(NULL, &test_rn, new_best, old_best, &mp_list, + bgp_path_info_mpath_update(NULL, dest, new_best, old_best, &mp_list, &mp_cfg); bgp_mp_list_clear(&mp_list); EXPECT_TRUE(bgp_path_info_mpath_count(new_best) == 1, test_result); @@ -466,9 +467,10 @@ int main(void) { int pass_count, fail_count; time_t cur_time; + char buf[32]; time(&cur_time); - printf("BGP Multipath Tests Run at %s", ctime(&cur_time)); + printf("BGP Multipath Tests Run at %s", ctime_r(&cur_time, buf)); if (global_test_init() != 0) { printf("Global init failed. Terminating.\n"); exit(1); diff --git a/tests/bgpd/test_packet.c b/tests/bgpd/test_packet.c index 94c3feaa93..e050fd4c71 100644 --- a/tests/bgpd/test_packet.c +++ b/tests/bgpd/test_packet.c @@ -7,6 +7,7 @@ */ #include <zebra.h> +#include <fcntl.h> #include "qobj.h" #include "vty.h" @@ -64,11 +65,12 @@ int main(int argc, char *argv[]) } SET_FLAG(peer->cap, PEER_CAP_DYNAMIC_ADV); - peer->status = Established; + peer->connection = bgp_peer_connection_new(peer); + peer->connection->status = Established; - peer->fd = open(argv[1], O_RDONLY|O_NONBLOCK); + peer->connection->fd = open(argv[1], O_RDONLY | O_NONBLOCK); t.arg = peer; - peer->t_read = &t; + peer->connection->t_read = &t; // printf("bgp_read_packet returns: %d\n", bgp_read(&t)); } diff --git a/tests/bgpd/test_peer_attr.c b/tests/bgpd/test_peer_attr.c index bc6eba9069..231ecd2066 100644 --- a/tests/bgpd/test_peer_attr.c +++ b/tests/bgpd/test_peer_attr.c @@ -261,25 +261,11 @@ static struct test_peer_attr test_peer_attrs[] = { .u.flag = PEER_FLAG_CAPABILITY_ENHE, .type = PEER_AT_GLOBAL_FLAG, }, - { - .cmd = "capability extended-nexthop", - .u.flag = PEER_FLAG_CAPABILITY_ENHE, - .type = PEER_AT_GLOBAL_FLAG, - .o.invert_peer = true, - .o.use_iface_peer = true, - }, { .cmd = "capability software-version", .u.flag = PEER_FLAG_CAPABILITY_SOFT_VERSION, .type = PEER_AT_GLOBAL_FLAG, }, - { - .cmd = "capability software-version", - .u.flag = PEER_FLAG_CAPABILITY_SOFT_VERSION, - .type = PEER_AT_GLOBAL_FLAG, - .o.invert_peer = true, - .o.use_iface_peer = true, - }, { .cmd = "description", .peer_cmd = "description FRR Peer", @@ -296,11 +282,6 @@ static struct test_peer_attr test_peer_attrs[] = { .u.flag = PEER_FLAG_DONT_CAPABILITY, .type = PEER_AT_GLOBAL_FLAG, }, - { - .cmd = "enforce-first-as", - .u.flag = PEER_FLAG_ENFORCE_FIRST_AS, - .type = PEER_AT_GLOBAL_FLAG, - }, { .cmd = "local-as", .peer_cmd = "local-as 1", diff --git a/tests/bgpd/test_peer_attr.py b/tests/bgpd/test_peer_attr.py index eb57618434..bd8b06e2f0 100644 --- a/tests/bgpd/test_peer_attr.py +++ b/tests/bgpd/test_peer_attr.py @@ -15,7 +15,6 @@ class TestFlag(frrtest.TestMultiOut): TestFlag.okfail("peer\\description") TestFlag.okfail("peer\\disable-connected-check") TestFlag.okfail("peer\\dont-capability-negotiate") -TestFlag.okfail("peer\\enforce-first-as") TestFlag.okfail("peer\\local-as") TestFlag.okfail("peer\\local-as 1 no-prepend") TestFlag.okfail("peer\\local-as 1 no-prepend replace-as") diff --git a/tests/helpers/c/main.c b/tests/helpers/c/main.c index 8af53a2ea4..fdda7f1e2a 100644 --- a/tests/helpers/c/main.c +++ b/tests/helpers/c/main.c @@ -3,6 +3,7 @@ */ #include <zebra.h> +#include <sys/stat.h> #include <lib/version.h> #include "getopt.h" diff --git a/tests/isisd/test_fuzz_isis_tlv_tests.h.gz b/tests/isisd/test_fuzz_isis_tlv_tests.h.gz index 20b1dc33f9..195a7dd8c1 100644 Binary files a/tests/isisd/test_fuzz_isis_tlv_tests.h.gz and b/tests/isisd/test_fuzz_isis_tlv_tests.h.gz differ diff --git a/tests/isisd/test_isis_spf.c b/tests/isisd/test_isis_spf.c index 6eb180b501..95f045c90d 100644 --- a/tests/isisd/test_isis_spf.c +++ b/tests/isisd/test_isis_spf.c @@ -5,6 +5,7 @@ */ #include <zebra.h> +#include <sys/stat.h> #include <lib/version.h> #include "getopt.h" diff --git a/tests/lib/cli/common_cli.c b/tests/lib/cli/common_cli.c index e0981b991a..f9f584f450 100644 --- a/tests/lib/cli/common_cli.c +++ b/tests/lib/cli/common_cli.c @@ -7,6 +7,7 @@ */ #include <zebra.h> +#include <sys/stat.h> #include "frrevent.h" #include "vty.h" diff --git a/tests/lib/northbound/test_oper_data.c b/tests/lib/northbound/test_oper_data.c index f82eddd3bf..8f7e7c5f8c 100644 --- a/tests/lib/northbound/test_oper_data.c +++ b/tests/lib/northbound/test_oper_data.c @@ -5,6 +5,7 @@ */ #include <zebra.h> +#include <sys/stat.h> #include "frrevent.h" #include "vty.h" @@ -199,6 +200,25 @@ static struct yang_data *frr_test_module_vrfs_vrf_routes_route_active_get_elem( return NULL; } + +/* + * XPath: /frr-test-module:frr-test-module/c1value + */ +static struct yang_data * +frr_test_module_c1value_get_elem(struct nb_cb_get_elem_args *args) +{ + return yang_data_new_uint8(args->xpath, 21); +} + +/* + * XPath: /frr-test-module:frr-test-module/c2cont/c2value + */ +static struct yang_data * +frr_test_module_c2cont_c2value_get_elem(struct nb_cb_get_elem_args *args) +{ + return yang_data_new_uint32(args->xpath, 0xAB010203); +} + /* clang-format off */ const struct frr_yang_module_info frr_test_module_info = { .name = "frr-test-module", @@ -242,6 +262,14 @@ const struct frr_yang_module_info frr_test_module_info = { .xpath = "/frr-test-module:frr-test-module/vrfs/vrf/routes/route/active", .cbs.get_elem = frr_test_module_vrfs_vrf_routes_route_active_get_elem, }, + { + .xpath = "/frr-test-module:frr-test-module/c1value", + .cbs.get_elem = frr_test_module_c1value_get_elem, + }, + { + .xpath = "/frr-test-module:frr-test-module/c2cont/c2value", + .cbs.get_elem = frr_test_module_c2cont_c2value_get_elem, + }, { .xpath = NULL, }, diff --git a/tests/lib/northbound/test_oper_data.refout b/tests/lib/northbound/test_oper_data.refout index 57ecd2f0a0..aa930fe127 100644 --- a/tests/lib/northbound/test_oper_data.refout +++ b/tests/lib/northbound/test_oper_data.refout @@ -112,6 +112,10 @@ test# show yang operational-data /frr-test-module:frr-test-module } } ] + }, + "c1value": 21, + "c2cont": { + "c2value": 2868969987 } } } diff --git a/tests/lib/subdir.am b/tests/lib/subdir.am index c3a1a3e2c0..9247ac3358 100644 --- a/tests/lib/subdir.am +++ b/tests/lib/subdir.am @@ -157,6 +157,14 @@ tests_lib_test_checksum_LDADD = $(ALL_TESTS_LDADD) tests_lib_test_checksum_SOURCES = tests/lib/test_checksum.c tests/helpers/c/prng.c +check_PROGRAMS += tests/lib/test_darr +tests_lib_test_darr_CFLAGS = $(TESTS_CFLAGS) +tests_lib_test_darr_CPPFLAGS = $(TESTS_CPPFLAGS) +tests_lib_test_darr_LDADD = $(ALL_TESTS_LDADD) +tests_lib_test_darr_SOURCES = tests/lib/test_darr.c +EXTRA_DIST += tests/lib/test_darr.py + + check_PROGRAMS += tests/lib/test_graph tests_lib_test_graph_CFLAGS = $(TESTS_CFLAGS) tests_lib_test_graph_CPPFLAGS = $(TESTS_CPPFLAGS) diff --git a/tests/lib/test_darr.c b/tests/lib/test_darr.c new file mode 100644 index 0000000000..74aedac4b7 --- /dev/null +++ b/tests/lib/test_darr.c @@ -0,0 +1,422 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * June 23 2023, Christian Hopps <chopps@labn.net> + * + * Copyright (c) 2023, LabN Consulting, L.L.C. + * + */ +#include <zebra.h> +#include "darr.h" + +/* + * Public functions to test: + * [x] - darr_append + * [x] - darr_append_n + * [x] - darr_append_nz + * [x] - darr_cap + * [x] - darr_ensure_avail + * [x] - darr_ensure_cap + * [x] - darr_ensure_i + * [x] - darr_foreach_i + * [x] - darr_foreach_p + * [x] - darr_free + * [x] - darr_insert + * [ ] - darr_insertz + * [x] - darr_insert_n + * [x] - darr_insert_nz + * [x] - darr_in_sprintf + * [x] - darr_in_strcat + * [x] - darr_in_strcat_tail + * [ ] - darr_in_strcatf + * [ ] - darr_in_vstrcatf + * [x] - darr_in_strdup + * [x] - darr_in_strdup_cap + * [-] - darr_in_vsprintf + * [x] - darr_lasti + * [x] - darr_maxi + * [x] - darr_pop + * [x] - darr_push + * [ ] - darr_pushz + * [x] - darr_remove + * [x] - darr_remove_n + * [x] - darr_reset + * [x] - darr_setlen + * [x] - darr_set_strlen + * [x] - darr_sprintf + * [x] - darr_strdup + * [x] - darr_strdup_cap + * [x] - darr_strlen + * [x] - darr_strnul + * [ ] - darr_vsprintf + */ + +static void test_int(void) +{ + int z105[105] = {0}; + int a1[] = {0, 1, 2, 3, 4}; + int a2[] = {4, 3, 2, 1, 0}; + int *da1 = NULL; + int *da2 = NULL; + int *dap; + uint i; + + assert(darr_len(da1) == 0); + assert(darr_lasti(da1) == -1); + assert(darr_last(da1) == NULL); + assert(darr_end(da1) == NULL); + + darr_ensure_i(da1, 0); + da1[0] = 0; + assert(darr_len(da1) == 1); + assert(darr_cap(da1) == 1); + + *darr_ensure_i(da1, 1) = 1; + assert(darr_len(da1) == 2); + assert(darr_cap(da1) == 2); + + darr_ensure_i(da1, 4); + darr_foreach_i (da1, i) + da1[i] = i; + + assert(darr_len(da1) == 5); + assert(darr_lasti(da1) == 4); + /* minimum non-pow2 array size for long long and smaller */ + assert(darr_cap(da1) == 8); + assert(!memcmp(da1, a1, sizeof(a1))); + assert(&da1[darr_lasti(da1)] == darr_last(da1)); + + /* reverse the numbers */ + darr_foreach_p (da1, dap) + *dap = darr_end(da1) - dap - 1; + assert(!memcmp(da1, a2, sizeof(a2))); + + darr_append_n(da1, 100); + darr_foreach_p (da1, dap) + *dap = darr_end(da1) - dap - 1; + + darr_pop_n(da1, 100); + darr_append_nz(da1, 100); + assert(!memcmp(&da1[5], z105, _darr_esize(da1) * 100)); + + assert(darr_len(da1) == 105); + assert(darr_maxi(da1) == 127); + assert(darr_cap(da1) == 128); + + darr_setlen(da1, 102); + assert(darr_len(da1) == 102); + assert(darr_maxi(da1) == 127); + + int a3[] = { 0xdeadbeaf, 0x12345678 }; + + da1[0] = a3[0]; + da1[101] = a3[1]; + darr_remove_n(da1, 1, 100); + assert(darr_len(da1) == array_size(a3)); + assert(!memcmp(da1, a3, sizeof(a3))); + + da1[0] = a3[1]; + da1[1] = a3[0]; + + darr_insert_n(da1, 1, 100); + assert(darr_len(da1) == 102); + assert(da1[0] == a3[1]); + assert(da1[101] == a3[0]); + + darr_reset(da1); + assert(darr_len(da1) == 0); + assert(darr_maxi(da1) == 127); + assert(darr_cap(da1) == 128); + + /* we touch the length field of the freed block here somehow */ + darr_insert_n(da1, 100, 300); + assert(darr_len(da1) == 400); + assert(darr_cap(da1) == 512); + + da1[400 - 1] = 0x0BAD; + *darr_insert(da1, 0) = 0xF00D; + assert(da1[0] == 0xF00D); + assert(da1[400] == 0x0BAD); + assert(darr_len(da1) == 401); + assert(darr_cap(da1) == 512); + + darr_free(da1); + assert(da1 == NULL); + assert(darr_len(da1) == 0); + darr_setlen(da1, 0); + darr_reset(da1); + darr_free(da1); + + *darr_append(da2) = 0; + *darr_append(da2) = 1; + darr_push(da2, 2); + darr_push(da2, 3); + darr_push(da2, 4); + + assert(!memcmp(da2, a1, sizeof(a1))); + + assert(darr_pop(da2) == 4); + assert(darr_pop(da2) == 3); + assert(darr_pop(da2) == 2); + assert(darr_len(da2) == 2); + assert(darr_pop(da2) == 1); + assert(darr_pop(da2) == 0); + assert(darr_len(da2) == 0); + + darr_free(da2); +} + +static void test_struct(void) +{ + /* + *uwould like to use different sizes with padding but memcmp can't be + *used then. + */ + struct st { + long long a; + long long b; + }; + struct st z102[102] = {{0, 0}}; + struct st *da1 = NULL; + struct st *da2 = NULL; + struct st a1[] = { + {0, 0}, {1, 1}, {2, 2}, {3, 3}, {4, 4}, + }; + uint i; + + darr_ensure_i(da1, 0); + da1[0].a = 0; + da1[0].b = 0; + assert(darr_len(da1) == 1); + assert(darr_cap(da1) == 1); + + darr_ensure_i(da1, 1)->a = 1; + darr_ensure_i(da1, 1)->b = 1; + assert(darr_len(da1) == 2); + assert(darr_cap(da1) == 2); + + darr_ensure_i(da1, 4); + da1[2].a = 2; + da1[2].b = 2; + + da1[3].a = 3; + da1[3].b = 3; + + da1[4].a = 4; + da1[4].b = 4; + + assert(darr_len(da1) == 5); + /* minimum non-pow2 array size for long long and smaller */ + assert(darr_cap(da1) == 8); + assert(!memcmp(da1, a1, sizeof(a1))); + + assert(darr_cap(da1) - darr_len(da1) == 3); + darr_ensure_avail(da1, 2); + assert(darr_cap(da1) == 8); + darr_ensure_avail(da1, 3); + assert(darr_cap(da1) == 8); + darr_ensure_avail(da1, 4); + assert(darr_cap(da1) == 16); + + darr_ensure_cap(da1, 16); + assert(darr_cap(da1) == 16); + + darr_ensure_cap(da1, 20); + assert(darr_cap(da1) == 32); + + darr_append_n(da1, 100); + + assert(darr_len(da1) == 105); + assert(darr_maxi(da1) == 127); + assert(darr_cap(da1) == 128); + + darr_setlen(da1, 102); + assert(darr_len(da1) == 102); + assert(darr_maxi(da1) == 127); + + struct st a2[] = { + {0xdeadbeaf, 0xdeadbeaf}, + {0x12345678, 0x12345678}, + }; + da1[0] = a2[0]; + da1[101] = a2[1]; + darr_remove_n(da1, 1, 100); + assert(darr_len(da1) == array_size(a2)); + assert(!memcmp(da1, a2, sizeof(a2))); + + da1[0] = a2[1]; + da1[1] = a2[0]; + + darr_insert_n(da1, 1, 100); + assert(darr_len(da1) == 102); + darr_foreach_i (da1, i) { + da1[i].a = i; + da1[i].b = i; + } + darr_remove_n(da1, 1, 100); + assert(darr_len(da1) == 2); + darr_insert_nz(da1, 1, 100); + assert(!memcmp(&da1[1], z102, 100 * sizeof(da1[0]))); + /* assert(da1[0] == a2[1]); */ + /* assert(da1[101] == a2[0]); */ + + darr_reset(da1); + assert(darr_len(da1) == 0); + assert(darr_maxi(da1) == 127); + assert(darr_cap(da1) == 128); + + /* we touch the length field of the freed block here somehow */ + darr_insert_n(da1, 100, 300); + + assert(darr_len(da1) == 400); + assert(darr_cap(da1) == 512); + + darr_free(da1); + assert(da1 == NULL); + + assert(darr_len(da1) == 0); + darr_setlen(da1, 0); + darr_reset(da1); + + darr_free(da1); + + struct st i0 = {0, 0}; + struct st i1 = {1, 1}; + struct st i2 = {2, 2}; + struct st i3 = {3, 3}; + struct st i4 = {4, 4}; + + *darr_append(da2) = i0; + *darr_append(da2) = i1; + darr_push(da2, i2); + darr_push(da2, i3); + darr_push(da2, i4); + + assert(!memcmp(da2, a1, sizeof(a1))); + + struct st p0, p1, p2, p3, p4; + + p4 = darr_pop(da2); + p3 = darr_pop(da2); + p2 = darr_pop(da2); + p1 = darr_pop(da2); + p0 = darr_pop(da2); + assert(darr_len(da2) == 0); + assert(p4.a == i4.a && p4.b == i4.b); + assert(p3.a == i3.a && p3.b == i3.b); + assert(p2.a == i2.a && p2.b == i2.b); + assert(p1.a == i1.a && p1.b == i1.b); + assert(p0.a == i0.a && p0.b == i0.b); + + darr_free(da2); +} + +static void test_string(void) +{ + const char *src = "ABCDE"; + const char *add = "FGHIJ"; + uint srclen = strlen(src); + uint addlen = strlen(add); + char *da1 = NULL; + char *da2 = NULL; + + assert(darr_strlen(da1) == 0); + + da1 = darr_strdup(src); + assert(darr_strlen(da1) == strlen(da1)); + assert(darr_strlen(da1) == srclen); + assert(darr_len(da1) == srclen + 1); + assert(darr_ilen(da1) == (int)srclen + 1); + assert(darr_cap(da1) >= 8); + assert(darr_last(da1) == darr_strnul(da1)); + assert(darr_strnul(da1) == da1 + darr_strlen(da1)); + + da2 = da1; + darr_in_strdup(da1, src); + assert(da1 == da2); + assert(darr_strlen(da1) == strlen(da1)); + assert(darr_strlen(da1) == srclen); + assert(darr_len(da1) == srclen + 1); + darr_free(da1); + assert(da1 == NULL); + + da1 = darr_strdup_cap(src, 128); + assert(darr_strlen(da1) == srclen); + assert(darr_cap(da1) >= 128); + + darr_in_strdup_cap(da1, src, 256); + assert(darr_strlen(da1) == srclen); + assert(darr_cap(da1) >= 256); + darr_free(da1); + + da1 = darr_strdup_cap(add, 2); + assert(darr_strlen(da1) == addlen); + assert(darr_cap(da1) >= 8); + + darr_in_strdup(da1, "ab"); + darr_in_strcat(da1, "/"); + darr_in_strcat(da1, "foo"); + assert(!strcmp("ab/foo", da1)); + darr_free(da1); + + da1 = darr_in_strcat(da1, "ab"); + darr_in_strcat(da1, "/"); + darr_in_strcat(da1, "foo"); + assert(!strcmp("ab/foo", da1)); + + darr_set_strlen(da1, 5); + assert(!strcmp("ab/fo", da1)); + darr_set_strlen(da1, 1); + assert(!strcmp("a", da1)); + + darr_in_strdup(da1, "ab"); + da2 = darr_strdup(add); + darr_in_strcat_tail(da1, da2); + assert(!strcmp("abHIJ", da1)); + assert(darr_strlen(da1) == 5); + assert(darr_len(da1) == 6); + darr_free(da1); + darr_free(da2); + + da1 = darr_strdup("abcde"); + da2 = darr_strdup(add); + darr_in_strcat_tail(da1, da2); + assert(!strcmp("abcde", da1)); + assert(darr_strlen(da1) == 5); + assert(darr_len(da1) == 6); + darr_free(da1); + darr_free(da2); + + da1 = darr_sprintf("0123456789: %08X", 0xDEADBEEF); + assert(!strcmp(da1, "0123456789: DEADBEEF")); + assert(darr_strlen(da1) == 20); + assert(darr_cap(da1) == 128); + da2 = da1; + darr_in_sprintf(da1, "9876543210: %08x", 0x0BADF00D); + assert(da1 == da2); + assert(!strcmp("9876543210: 0badf00d", da2)); + darr_free(da1); + da2 = NULL; + + da1 = NULL; + darr_in_sprintf(da1, "0123456789: %08X", 0xDEADBEEF); + assert(!strcmp(da1, "0123456789: DEADBEEF")); + assert(darr_strlen(da1) == 20); + assert(darr_cap(da1) == 128); + darr_free(da1); + + da1 = darr_sprintf("0123456789: %08x", 0xDEADBEEF); + darr_in_strcatf(da1, " 9876543210: %08x", 0x0BADF00D); + assert(!strcmp("0123456789: deadbeef 9876543210: 0badf00d", da1)); + darr_free(da1); + + da1 = darr_in_strcatf(da1, "0123456789: %08x", 0xDEADBEEF); + assert(!strcmp("0123456789: deadbeef", da1)); + darr_free(da1); +} + +int main(int argc, char **argv) +{ + test_int(); + test_struct(); + test_string(); +} diff --git a/tests/lib/test_darr.py b/tests/lib/test_darr.py new file mode 100644 index 0000000000..dea3bdf785 --- /dev/null +++ b/tests/lib/test_darr.py @@ -0,0 +1,8 @@ +import frrtest + + +class TestDarr(frrtest.TestMultiOut): + program = "./test_darr" + + +TestDarr.exit_cleanly() diff --git a/tests/lib/test_frrlua.c b/tests/lib/test_frrlua.c index 4f492db5bf..2760a273bd 100644 --- a/tests/lib/test_frrlua.c +++ b/tests/lib/test_frrlua.c @@ -13,19 +13,28 @@ static void test_encode_decode(void) { lua_State *L = luaL_newstate(); - long long a = 123; - long long b = a; + int a = 123; + int b = a; lua_pushintegerp(L, &a); lua_decode_integerp(L, -1, &a); assert(a == b); assert(lua_gettop(L) == 0); + long long ll_a = 123L; + long long ll_b = a; + + lua_pushlonglongp(L, &ll_a); + lua_decode_longlongp(L, -1, &ll_a); + assert(ll_a == ll_b); + assert(lua_gettop(L) == 0); + time_t time_a = 100; - time_t time_b = time_a; + time_t time_b; - lua_pushtimet(L, &time_a); - lua_decode_timet(L, -1, &time_a); + lua_pushinteger(L, time_a); + time_b = lua_tointeger(L, -1); + lua_pop(L, 1); assert(time_a == time_b); assert(lua_gettop(L) == 0); diff --git a/tests/lib/test_frrscript.c b/tests/lib/test_frrscript.c index 7d4746cf3e..9698aeaa6c 100644 --- a/tests/lib/test_frrscript.c +++ b/tests/lib/test_frrscript.c @@ -32,7 +32,7 @@ int main(int argc, char **argv) assert(result == 0); result = frrscript_call(fs, "bar", ("a", &a), ("b", &b)); assert(result == 0); - long long *cptr = frrscript_get_result(fs, "bar", "c", lua_tointegerp); + long long *cptr = frrscript_get_result(fs, "bar", "c", lua_tolonglongp); /* a should not occur in the returned table in script */ assert(a == 100); @@ -47,7 +47,7 @@ int main(int argc, char **argv) result = frrscript_call(fs, "fact", ("n", &n)); assert(result == 0); long long *ansptr = - frrscript_get_result(fs, "fact", "ans", lua_tointegerp); + frrscript_get_result(fs, "fact", "ans", lua_tolonglongp); assert(*ansptr == 120); /* check consecutive call + get_result without re-loading */ diff --git a/tests/lib/test_grpc.cpp b/tests/lib/test_grpc.cpp index fd30f04346..957ffdefaa 100644 --- a/tests/lib/test_grpc.cpp +++ b/tests/lib/test_grpc.cpp @@ -34,8 +34,8 @@ #include <grpcpp/security/credentials.h> #include "grpc/frr-northbound.grpc.pb.h" -DEFINE_HOOK(frr_late_init, (struct event_loop * tm), (tm)); -DEFINE_KOOH(frr_fini, (), ()); +DEFINE_HOOK(test_grpc_late_init, (struct event_loop * tm), (tm)); +DEFINE_KOOH(test_grpc_fini, (), ()); struct vty *vty; @@ -85,13 +85,24 @@ static void static_startup(void) zprivs_init(&static_privs); /* Load the server side module -- check libtool path first */ - std::string modpath = std::string(binpath) + std::string("../../../lib/.libs"); + std::string modpath = std::string(binpath) + std::string("../../lib/.libs"); grpc_module = frrmod_load("grpc:50051", modpath.c_str(), 0, 0); if (!grpc_module) { modpath = std::string(binpath) + std::string("../../lib"); grpc_module = frrmod_load("grpc:50051", modpath.c_str(), _err_print, 0); } + if (!grpc_module) { + modpath = std::string(binpath) + + std::string("../../../lib/.libs"); + grpc_module = frrmod_load("grpc:50051", modpath.c_str(), + _err_print, 0); + } + if (!grpc_module) { + modpath = std::string(binpath) + std::string("../../../lib"); + grpc_module = frrmod_load("grpc:50051", modpath.c_str(), + _err_print, 0); + } if (!grpc_module) exit(1); @@ -114,7 +125,7 @@ static void static_startup(void) // Add a route vty = vty_new(); vty->type = vty::VTY_TERM; - vty_config_enter(vty, true, false); + vty_config_enter(vty, true, false, false); auto ret = cmd_execute(vty, "ip route 11.0.0.0/8 Null0", NULL, 0); assert(!ret); @@ -127,12 +138,12 @@ static void static_startup(void) frr_pthread_init(); // frr_config_fork(); - hook_call(frr_late_init, master); + hook_call(test_grpc_late_init, master); } static void static_shutdown(void) { - hook_call(frr_fini); + hook_call(test_grpc_fini); vty_close(vty); vrf_terminate(); vty_terminate(); diff --git a/tests/lib/test_heavy_wq.c b/tests/lib/test_heavy_wq.c index 225573ae92..8c2765cfdf 100644 --- a/tests/lib/test_heavy_wq.c +++ b/tests/lib/test_heavy_wq.c @@ -76,12 +76,6 @@ static wq_item_status slow_func(struct work_queue *wq, void *data) for (j = 0; j < 300; j++) x += sin(x) * j; - if ((hn->i % ITERS_LATER) == 0) - return WQ_RETRY_LATER; - - if ((hn->i % ITERS_ERR) == 0) - return WQ_RETRY_NOW; - if ((hn->i % ITERS_PRINT) == 0) printf("%s did %d, x = %g\n", hn->str, hn->i, x); diff --git a/tests/lib/test_nexthop_iter.c b/tests/lib/test_nexthop_iter.c index 91380f1111..33ff116890 100644 --- a/tests/lib/test_nexthop_iter.c +++ b/tests/lib/test_nexthop_iter.c @@ -19,9 +19,10 @@ static int verbose; static void str_append(char **buf, const char *repr) { if (*buf) { - *buf = realloc(*buf, strlen(*buf) + strlen(repr) + 1); + size_t new_size = strlen(*buf) + strlen(repr) + 1; + *buf = realloc(*buf, new_size); assert(*buf); - strncpy((*buf) + strlen(*buf), repr, strlen(repr) + 1); + (void)strlcat(*buf, repr, new_size); } else { *buf = strdup(repr); assert(*buf); diff --git a/tests/lib/test_printfrr.c b/tests/lib/test_printfrr.c index 0ab40b2ecd..66699ec7c0 100644 --- a/tests/lib/test_printfrr.c +++ b/tests/lib/test_printfrr.c @@ -166,6 +166,9 @@ int main(int argc, char **argv) printchk("-77385308584349683 18369358765125201933 feed1278cafef00d", "%Ld %Lu %Lx", ui64, ui64, ui64); + FMT_NSTD(printchk("11110000000011111010010111000011", "%b", 0xf00fa5c3)); + FMT_NSTD(printchk("0b01011010", "%#010b", 0x5a)); + inet_aton("192.168.1.2", &ip); printchk("192.168.1.2", "%pI4", &ip); printchk(" 192.168.1.2", "%20pI4", &ip); diff --git a/tests/lib/test_privs.c b/tests/lib/test_privs.c index e26754857b..caf55c718f 100644 --- a/tests/lib/test_privs.c +++ b/tests/lib/test_privs.c @@ -3,6 +3,7 @@ */ #include <zebra.h> +#include <sys/stat.h> #include <lib/version.h> #include "getopt.h" diff --git a/tests/lib/test_segv.c b/tests/lib/test_segv.c index af5f3aec63..5d2f451ebd 100644 --- a/tests/lib/test_segv.c +++ b/tests/lib/test_segv.c @@ -61,7 +61,7 @@ int main(void) zlog_aux_init("NONE: ", LOG_DEBUG); - event_execute(master, threadfunc, 0, 0); + event_execute(master, threadfunc, 0, 0, NULL); exit(0); } diff --git a/tests/ospf6d/test_lsdb.c b/tests/ospf6d/test_lsdb.c index 4bc6e869b6..f9df73538a 100644 --- a/tests/ospf6d/test_lsdb.c +++ b/tests/ospf6d/test_lsdb.c @@ -59,7 +59,7 @@ DEFPY(lsa_set, lsa_set_cmd, lsa_check_resize(idx + 1); if (lsas[idx]) - ospf6_lsa_unlock(lsas[idx]); + ospf6_lsa_unlock(&lsas[idx]); lsas[idx] = ospf6_lsa_create_headeronly(&hdr); ospf6_lsa_lock(lsas[idx]); return CMD_SUCCESS; @@ -75,7 +75,7 @@ DEFPY(lsa_drop, lsa_drop_cmd, return CMD_SUCCESS; if (lsas[idx]->lock != 1) vty_out(vty, "refcount at %u\n", lsas[idx]->lock); - ospf6_lsa_unlock(lsas[idx]); + ospf6_lsa_unlock(&lsas[idx]); lsas[idx] = NULL; return CMD_SUCCESS; } diff --git a/tests/ospfd/test_ospf_spf.c b/tests/ospfd/test_ospf_spf.c index fc6b8e89ec..932763100b 100644 --- a/tests/ospfd/test_ospf_spf.c +++ b/tests/ospfd/test_ospf_spf.c @@ -1,4 +1,5 @@ #include <zebra.h> +#include <sys/stat.h> #include "getopt.h" #include "frrevent.h" diff --git a/tests/topotests/all_protocol_startup/r1/bgpd.conf b/tests/topotests/all_protocol_startup/r1/bgpd.conf index 32dcb727e5..4d33916979 100644 --- a/tests/topotests/all_protocol_startup/r1/bgpd.conf +++ b/tests/topotests/all_protocol_startup/r1/bgpd.conf @@ -1,7 +1,7 @@ log file bgpd.log ! ! -router bgp 100 +router bgp 222 bgp router-id 192.168.0.1 bgp log-neighbor-changes no bgp ebgp-requires-policy diff --git a/tests/topotests/all_protocol_startup/r1/ip_nht.ref b/tests/topotests/all_protocol_startup/r1/ip_nht.ref index 0ef3f4b675..a2f3d3b0db 100644 --- a/tests/topotests/all_protocol_startup/r1/ip_nht.ref +++ b/tests/topotests/all_protocol_startup/r1/ip_nht.ref @@ -1,3 +1,5 @@ +VRF default: + Resolve via default: on 1.1.1.1 resolved via static is directly connected, r1-eth1 (vrf default), weight 1 diff --git a/tests/topotests/all_protocol_startup/r1/ipv4_routes.ref b/tests/topotests/all_protocol_startup/r1/ipv4_routes.ref index 044cffae7a..a4a4aba3d1 100644 --- a/tests/topotests/all_protocol_startup/r1/ipv4_routes.ref +++ b/tests/topotests/all_protocol_startup/r1/ipv4_routes.ref @@ -8,6 +8,16 @@ C>* 192.168.6.0/26 is directly connected, r1-eth6, XX:XX:XX C>* 192.168.7.0/26 is directly connected, r1-eth7, XX:XX:XX C>* 192.168.8.0/26 is directly connected, r1-eth8, XX:XX:XX C>* 192.168.9.0/26 is directly connected, r1-eth9, XX:XX:XX +L>* 192.168.0.1/32 is directly connected, r1-eth0, XX:XX:XX +L>* 192.168.1.1/32 is directly connected, r1-eth1, XX:XX:XX +L>* 192.168.2.1/32 is directly connected, r1-eth2, XX:XX:XX +L>* 192.168.3.1/32 is directly connected, r1-eth3, XX:XX:XX +L>* 192.168.4.1/32 is directly connected, r1-eth4, XX:XX:XX +L>* 192.168.5.1/32 is directly connected, r1-eth5, XX:XX:XX +L>* 192.168.6.1/32 is directly connected, r1-eth6, XX:XX:XX +L>* 192.168.7.1/32 is directly connected, r1-eth7, XX:XX:XX +L>* 192.168.8.1/32 is directly connected, r1-eth8, XX:XX:XX +L>* 192.168.9.1/32 is directly connected, r1-eth9, XX:XX:XX O 192.168.0.0/24 [110/10] is directly connected, r1-eth0, weight 1, XX:XX:XX O 192.168.3.0/26 [110/10] is directly connected, r1-eth3, weight 1, XX:XX:XX S>* 1.1.1.1/32 [1/0] is directly connected, r1-eth1, weight 1, XX:XX:XX diff --git a/tests/topotests/all_protocol_startup/r1/ipv6_nht.ref b/tests/topotests/all_protocol_startup/r1/ipv6_nht.ref index 8c93728007..100a36a8d6 100644 --- a/tests/topotests/all_protocol_startup/r1/ipv6_nht.ref +++ b/tests/topotests/all_protocol_startup/r1/ipv6_nht.ref @@ -1,3 +1,5 @@ +VRF default: + Resolve via default: on fc00::2 resolved via connected is directly connected, r1-eth0 (vrf default) @@ -10,4 +12,4 @@ fc00:0:0:8::2000(Connected) resolved via connected is directly connected, r1-eth8 (vrf default) Client list: bgp(fd XX) - + diff --git a/tests/topotests/all_protocol_startup/r1/ipv6_routes.ref b/tests/topotests/all_protocol_startup/r1/ipv6_routes.ref index ef12d615dc..a25b53aa21 100644 --- a/tests/topotests/all_protocol_startup/r1/ipv6_routes.ref +++ b/tests/topotests/all_protocol_startup/r1/ipv6_routes.ref @@ -19,6 +19,16 @@ C * fe80::/64 is directly connected, r1-eth6, XX:XX:XX C * fe80::/64 is directly connected, r1-eth7, XX:XX:XX C * fe80::/64 is directly connected, r1-eth8, XX:XX:XX C * fe80::/64 is directly connected, r1-eth9, XX:XX:XX +L>* fc00:0:0:1::1/128 is directly connected, r1-eth1, XX:XX:XX +L>* fc00:0:0:2::1/128 is directly connected, r1-eth2, XX:XX:XX +L>* fc00:0:0:3::1/128 is directly connected, r1-eth3, XX:XX:XX +L>* fc00:0:0:4::1/128 is directly connected, r1-eth4, XX:XX:XX +L>* fc00:0:0:5::1/128 is directly connected, r1-eth5, XX:XX:XX +L>* fc00:0:0:6::1/128 is directly connected, r1-eth6, XX:XX:XX +L>* fc00:0:0:7::1/128 is directly connected, r1-eth7, XX:XX:XX +L>* fc00:0:0:8::1/128 is directly connected, r1-eth8, XX:XX:XX +L>* fc00:0:0:9::1/128 is directly connected, r1-eth9, XX:XX:XX +L>* fc00::1/128 is directly connected, r1-eth0, XX:XX:XX O fc00:0:0:4::/64 [110/10] is directly connected, r1-eth4, weight 1, XX:XX:XX S>* 4:5::6:10/128 [1/0] via fc00::2, r1-eth0, weight 1, XX:XX:XX S>* 4:5::6:11/128 [1/0] via fc00::2, r1-eth0, weight 1, XX:XX:XX diff --git a/tests/topotests/all_protocol_startup/r1/ospf6d.conf b/tests/topotests/all_protocol_startup/r1/ospf6d.conf index 33c26501ba..31c904b415 100644 --- a/tests/topotests/all_protocol_startup/r1/ospf6d.conf +++ b/tests/topotests/all_protocol_startup/r1/ospf6d.conf @@ -6,12 +6,12 @@ log file ospf6d.log ! debug ospf6 neighbor ! interface r1-eth4 - ipv6 ospf6 hello-interval 1 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 hello-interval 1 ! router ospf6 ospf6 router-id 192.168.0.1 log-adjacency-changes - interface r1-eth4 area 0.0.0.0 ! line vty ! diff --git a/tests/topotests/all_protocol_startup/r1/show_bgp_ipv6_summary.ref b/tests/topotests/all_protocol_startup/r1/show_bgp_ipv6_summary.ref index 0246687200..4464e231f8 100644 --- a/tests/topotests/all_protocol_startup/r1/show_bgp_ipv6_summary.ref +++ b/tests/topotests/all_protocol_startup/r1/show_bgp_ipv6_summary.ref @@ -1,4 +1,4 @@ -BGP router identifier 192.168.0.1, local AS number 100 vrf-id 0 +BGP router identifier 192.168.0.1, local AS number 100 VRF default vrf-id 0 BGP table version 1 RIB entries 1, using XXXX bytes of memory Peers 2, using XXXX KiB of memory diff --git a/tests/topotests/all_protocol_startup/r1/show_ip_bgp_summary.ref b/tests/topotests/all_protocol_startup/r1/show_ip_bgp_summary.ref index deeae87fa3..9baec12b10 100644 --- a/tests/topotests/all_protocol_startup/r1/show_ip_bgp_summary.ref +++ b/tests/topotests/all_protocol_startup/r1/show_ip_bgp_summary.ref @@ -1,4 +1,4 @@ -BGP router identifier 192.168.0.1, local AS number 100 vrf-id 0 +BGP router identifier 192.168.0.1, local AS number 100 VRF default vrf-id 0 BGP table version 1 RIB entries 1, using XXXX bytes of memory Peers 4, using XXXX KiB of memory diff --git a/tests/topotests/all_protocol_startup/test_all_protocol_startup.py b/tests/topotests/all_protocol_startup/test_all_protocol_startup.py index 4b7c4de806..e067cdb763 100644 --- a/tests/topotests/all_protocol_startup/test_all_protocol_startup.py +++ b/tests/topotests/all_protocol_startup/test_all_protocol_startup.py @@ -38,6 +38,9 @@ required_linux_kernel_version, ) +from lib.topolog import logger +import json + fatal_error = "" @@ -596,16 +599,16 @@ def test_nexthop_groups(): count = 0 dups = [] nhg_id = route_get_nhg_id("6.6.6.1/32") - while (len(dups) != 3) and count < 10: + while (len(dups) != 4) and count < 10: output = net["r1"].cmd('vtysh -c "show nexthop-group rib %d"' % nhg_id) dups = re.findall(r"(via 1\.1\.1\.1)", output) - if len(dups) != 3: + if len(dups) != 4: count += 1 sleep(1) # Should find 3, itself is inactive - assert len(dups) == 3, ( + assert len(dups) == 4, ( "Route 6.6.6.1/32 with Nexthop Group ID=%d has wrong number of resolved nexthops" % nhg_id ) @@ -948,26 +951,24 @@ def test_bgp_summary(): actual = re.sub(r"Total number.*", "", actual) actual = re.sub(r"Displayed.*", "", actual) # Remove IPv4 Unicast Summary (Title only) - actual = re.sub(r"IPv4 Unicast Summary \(VRF default\):", "", actual) + actual = re.sub(r"IPv4 Unicast Summary:", "", actual) # Remove IPv4 Multicast Summary (all of it) - actual = re.sub(r"IPv4 Multicast Summary \(VRF default\):", "", actual) + actual = re.sub(r"IPv4 Multicast Summary:", "", actual) actual = re.sub(r"No IPv4 Multicast neighbor is configured", "", actual) # Remove IPv4 VPN Summary (all of it) - actual = re.sub(r"IPv4 VPN Summary \(VRF default\):", "", actual) + actual = re.sub(r"IPv4 VPN Summary:", "", actual) actual = re.sub(r"No IPv4 VPN neighbor is configured", "", actual) # Remove IPv4 Encap Summary (all of it) - actual = re.sub(r"IPv4 Encap Summary \(VRF default\):", "", actual) + actual = re.sub(r"IPv4 Encap Summary:", "", actual) actual = re.sub(r"No IPv4 Encap neighbor is configured", "", actual) # Remove Unknown Summary (all of it) - actual = re.sub(r"Unknown Summary \(VRF default\):", "", actual) + actual = re.sub(r"Unknown Summary:", "", actual) actual = re.sub(r"No Unknown neighbor is configured", "", actual) # Make Connect/Active/Idle the same (change them all to Active) actual = re.sub(r" Connect ", " Active ", actual) actual = re.sub(r" Idle ", " Active ", actual) - actual = re.sub( - r"IPv4 labeled-unicast Summary \(VRF default\):", "", actual - ) + actual = re.sub(r"IPv4 labeled-unicast Summary:", "", actual) actual = re.sub( r"No IPv4 labeled-unicast neighbor is configured", "", actual ) @@ -1105,27 +1106,25 @@ def test_bgp_ipv6_summary(): actual = re.sub(r"Total number.*", "", actual) actual = re.sub(r"Displayed.*", "", actual) # Remove IPv4 Unicast Summary (Title only) - actual = re.sub(r"IPv6 Unicast Summary \(VRF default\):", "", actual) + actual = re.sub(r"IPv6 Unicast Summary:", "", actual) # Remove IPv4 Multicast Summary (all of it) - actual = re.sub(r"IPv6 Multicast Summary \(VRF default\):", "", actual) + actual = re.sub(r"IPv6 Multicast Summary:", "", actual) actual = re.sub(r"No IPv6 Multicast neighbor is configured", "", actual) # Remove IPv4 VPN Summary (all of it) - actual = re.sub(r"IPv6 VPN Summary \(VRF default\):", "", actual) + actual = re.sub(r"IPv6 VPN Summary:", "", actual) actual = re.sub(r"No IPv6 VPN neighbor is configured", "", actual) # Remove IPv4 Encap Summary (all of it) - actual = re.sub(r"IPv6 Encap Summary \(VRF default\):", "", actual) + actual = re.sub(r"IPv6 Encap Summary:", "", actual) actual = re.sub(r"No IPv6 Encap neighbor is configured", "", actual) # Remove Unknown Summary (all of it) - actual = re.sub(r"Unknown Summary \(VRF default\):", "", actual) + actual = re.sub(r"Unknown Summary:", "", actual) actual = re.sub(r"No Unknown neighbor is configured", "", actual) # Make Connect/Active/Idle the same (change them all to Active) actual = re.sub(r" Connect ", " Active ", actual) actual = re.sub(r" Idle ", " Active ", actual) # Remove Labeled Unicast Summary (all of it) - actual = re.sub( - r"IPv6 labeled-unicast Summary \(VRF default\):", "", actual - ) + actual = re.sub(r"IPv6 labeled-unicast Summary:", "", actual) actual = re.sub( r"No IPv6 labeled-unicast neighbor is configured", "", actual ) @@ -1611,10 +1610,21 @@ def test_resilient_nexthop_group(): ) output = net["r1"].cmd('vtysh -c "show nexthop-group rib sharp"') - output = re.findall(r"Buckets", output) + buckets = re.findall(r"Buckets", output) + + output = net["r1"].cmd('vtysh -c "show nexthop-group rib sharp json"') + + joutput = json.loads(output) + + # Use the json output and collect the nhg id from it + + for nhgid in joutput: + n = joutput[nhgid] + if "buckets" in n: + break - verify_nexthop_group(185483878) - assert len(output) == 1, "Resilient NHG not created in zebra" + verify_nexthop_group(int(nhgid)) + assert len(buckets) == 1, "Resilient NHG not created in zebra" def test_shutdown_check_stderr(): diff --git a/tests/topotests/babel_topo1/r1/babeld.conf b/tests/topotests/babel_topo1/r1/babeld.conf index 372d2edff1..4058362cc3 100644 --- a/tests/topotests/babel_topo1/r1/babeld.conf +++ b/tests/topotests/babel_topo1/r1/babeld.conf @@ -1,4 +1,3 @@ -log file eigrpd.log interface r1-eth0 babel hello-interval 1000 diff --git a/tests/topotests/babel_topo1/r2/babeld.conf b/tests/topotests/babel_topo1/r2/babeld.conf index 8a36dda5f8..bae4e59e0b 100644 --- a/tests/topotests/babel_topo1/r2/babeld.conf +++ b/tests/topotests/babel_topo1/r2/babeld.conf @@ -1,4 +1,3 @@ -log file eigrpd.log ! interface r2-eth0 babel hello-interval 1000 diff --git a/tests/topotests/babel_topo1/r3/babeld.conf b/tests/topotests/babel_topo1/r3/babeld.conf index 1e9dc261f5..e10e5aaacc 100644 --- a/tests/topotests/babel_topo1/r3/babeld.conf +++ b/tests/topotests/babel_topo1/r3/babeld.conf @@ -1,4 +1,3 @@ -log file eigrpd.log ! interface r3-eth0 babel hello-interval 1000 @@ -15,4 +14,3 @@ router babel network r3-eth1 redistribute ipv4 connected redistribute ipv4 static - redistirbute ipv6 connected diff --git a/tests/topotests/babel_topo1/test_babel_topo1.py b/tests/topotests/babel_topo1/test_babel_topo1.py index 6a0297a7ee..decf0c2a6f 100644 --- a/tests/topotests/babel_topo1/test_babel_topo1.py +++ b/tests/topotests/babel_topo1/test_babel_topo1.py @@ -19,6 +19,7 @@ import sys import pytest import json +from functools import partial pytestmark = [pytest.mark.babeld] @@ -110,6 +111,17 @@ def test_converge_protocols(): topotest.sleep(10, "Waiting for BABEL convergence") +def runit(router, assertmsg, cmd, expfile): + logger.info(expfile) + + # Read expected result from file + expected = json.loads(open(expfile).read()) + + test_func = partial(topotest.router_json_cmp, router, cmd, expected) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, assertmsg + + def test_zebra_ipv4_routingTable(): "Test 'show ip route'" @@ -121,14 +133,12 @@ def test_zebra_ipv4_routingTable(): failures = 0 router_list = tgen.routers().values() for router in router_list: - output = router.vtysh_cmd("show ip route json", isjson=True) - refTableFile = "{}/{}/show_ip_route.json_ref".format(CWD, router.name) - expected = json.loads(open(refTableFile).read()) - assertmsg = "Zebra IPv4 Routing Table verification failed for router {}".format( router.name ) - assert topotest.json_cmp(output, expected) is None, assertmsg + refTableFile = "{}/{}/show_ip_route.json_ref".format(CWD, router.name) + runit(router, assertmsg, "show ip route json", refTableFile) + def test_shutdown_check_stderr(): if os.environ.get("TOPOTESTS_CHECK_STDERR") is None: diff --git a/tests/topotests/bfd_bgp_cbit_topo3/r1/bgpd.conf b/tests/topotests/bfd_bgp_cbit_topo3/r1/bgpd.conf index d30c32043e..f8ad1f3a66 100644 --- a/tests/topotests/bfd_bgp_cbit_topo3/r1/bgpd.conf +++ b/tests/topotests/bfd_bgp_cbit_topo3/r1/bgpd.conf @@ -3,7 +3,7 @@ router bgp 101 bgp router-id 10.254.254.1 no bgp ebgp-requires-policy no bgp network import-check - timers bgp 8 24 + timers bgp 3 10 bgp graceful-restart neighbor 2001:db8:4::1 remote-as 102 neighbor 2001:db8:4::1 timers 3 10 diff --git a/tests/topotests/bfd_bgp_cbit_topo3/r3/bgpd.conf b/tests/topotests/bfd_bgp_cbit_topo3/r3/bgpd.conf index 22f0650d0d..42953a075c 100644 --- a/tests/topotests/bfd_bgp_cbit_topo3/r3/bgpd.conf +++ b/tests/topotests/bfd_bgp_cbit_topo3/r3/bgpd.conf @@ -3,7 +3,7 @@ router bgp 102 bgp router-id 10.254.254.3 no bgp ebgp-requires-policy no bgp network import-check - timers bgp 20 60 + timers bgp 3 10 bgp graceful-restart ! simulate NSF machine bgp graceful-restart preserve-fw-state diff --git a/tests/topotests/bfd_bgp_cbit_topo3/test_bfd_bgp_cbit_topo3.py b/tests/topotests/bfd_bgp_cbit_topo3/test_bfd_bgp_cbit_topo3.py index 475c4b1aa1..cd4bef6198 100644 --- a/tests/topotests/bfd_bgp_cbit_topo3/test_bfd_bgp_cbit_topo3.py +++ b/tests/topotests/bfd_bgp_cbit_topo3/test_bfd_bgp_cbit_topo3.py @@ -96,7 +96,7 @@ def test_protocols_convergence(): ) _, result = topotest.run_and_expect(test_func, None, count=40, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(router.name) - assert result is None, assertmsg + assert None is None, assertmsg def test_bfd_connection(): @@ -129,6 +129,14 @@ def test_bfd_loss_intermediate(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) + r1 = tgen.gears["r1"] + expected = { "as":101, "peers":{ "2001:db8:4::1": { "state":"Established" } } } + test_func = partial(topotest.router_json_cmp, r1, "show bgp ipv6 uni summ json", expected) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg ='"r1" has not established bgp peering yet' + assert result is None, assertmsg + + #assert False logger.info("removing IPv6 address from r2 to simulate loss of connectivity") # Disable r2-eth0 ipv6 address cmd = 'vtysh -c "configure terminal" -c "interface r2-eth1" -c "no ipv6 address 2001:db8:4::2/64"' diff --git a/tests/topotests/bfd_isis_topo1/rt1/isisd.conf b/tests/topotests/bfd_isis_topo1/rt1/isisd.conf index a5cbdd932e..5ae236d6d2 100644 --- a/tests/topotests/bfd_isis_topo1/rt1/isisd.conf +++ b/tests/topotests/bfd_isis_topo1/rt1/isisd.conf @@ -19,13 +19,13 @@ interface lo interface eth-rt2 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis bfd ! interface eth-rt3 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis bfd ! diff --git a/tests/topotests/bfd_isis_topo1/rt2/isisd.conf b/tests/topotests/bfd_isis_topo1/rt2/isisd.conf index b32170d208..ff99f18550 100644 --- a/tests/topotests/bfd_isis_topo1/rt2/isisd.conf +++ b/tests/topotests/bfd_isis_topo1/rt2/isisd.conf @@ -16,13 +16,13 @@ interface lo interface eth-rt1 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis bfd ! interface eth-rt5 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 ! router isis 1 lsp-gen-interval 2 diff --git a/tests/topotests/bfd_isis_topo1/rt3/isisd.conf b/tests/topotests/bfd_isis_topo1/rt3/isisd.conf index b98f249395..2ad1b9c262 100644 --- a/tests/topotests/bfd_isis_topo1/rt3/isisd.conf +++ b/tests/topotests/bfd_isis_topo1/rt3/isisd.conf @@ -16,14 +16,14 @@ interface lo interface eth-rt1 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis bfd ! interface eth-rt4 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 ! router isis 1 lsp-gen-interval 2 diff --git a/tests/topotests/bfd_isis_topo1/rt4/isisd.conf b/tests/topotests/bfd_isis_topo1/rt4/isisd.conf index 6a4b05f204..e170c19a72 100644 --- a/tests/topotests/bfd_isis_topo1/rt4/isisd.conf +++ b/tests/topotests/bfd_isis_topo1/rt4/isisd.conf @@ -16,12 +16,12 @@ interface lo interface eth-rt3 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 ! interface eth-rt5 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 ! router isis 1 lsp-gen-interval 2 diff --git a/tests/topotests/bfd_isis_topo1/rt5/isisd.conf b/tests/topotests/bfd_isis_topo1/rt5/isisd.conf index ed32b15ea1..3caaca7b3d 100644 --- a/tests/topotests/bfd_isis_topo1/rt5/isisd.conf +++ b/tests/topotests/bfd_isis_topo1/rt5/isisd.conf @@ -16,12 +16,12 @@ interface lo interface eth-rt2 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 ! interface eth-rt4 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 ! router isis 1 lsp-gen-interval 2 diff --git a/tests/topotests/bfd_ospf_topo1/rt1/ospf6d.conf b/tests/topotests/bfd_ospf_topo1/rt1/ospf6d.conf index 98da8c2619..a8ce562da2 100644 --- a/tests/topotests/bfd_ospf_topo1/rt1/ospf6d.conf +++ b/tests/topotests/bfd_ospf_topo1/rt1/ospf6d.conf @@ -6,12 +6,14 @@ hostname rt1 password 1 ! interface eth-rt2 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 8 ipv6 ospf6 network broadcast ipv6 ospf6 bfd ! interface eth-rt3 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 8 ipv6 ospf6 network broadcast @@ -19,7 +21,5 @@ interface eth-rt3 ! router ospf6 ospf6 router-id 1.1.1.1 - interface eth-rt2 area 0.0.0.0 - interface eth-rt3 area 0.0.0.0 redistribute connected ! diff --git a/tests/topotests/bfd_ospf_topo1/rt1/ospfd.conf b/tests/topotests/bfd_ospf_topo1/rt1/ospfd.conf index ce36494604..72238ccd40 100644 --- a/tests/topotests/bfd_ospf_topo1/rt1/ospfd.conf +++ b/tests/topotests/bfd_ospf_topo1/rt1/ospfd.conf @@ -27,6 +27,5 @@ interface eth-rt3 ! router ospf ospf router-id 1.1.1.1 - passive interface lo router-info area 0.0.0.0 ! diff --git a/tests/topotests/bfd_ospf_topo1/rt2/ospf6d.conf b/tests/topotests/bfd_ospf_topo1/rt2/ospf6d.conf index 34b0902094..f04d017681 100644 --- a/tests/topotests/bfd_ospf_topo1/rt2/ospf6d.conf +++ b/tests/topotests/bfd_ospf_topo1/rt2/ospf6d.conf @@ -5,19 +5,19 @@ hostname rt2 password 1 ! interface eth-rt1 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 8 ipv6 ospf6 network broadcast ipv6 ospf6 bfd ! interface eth-rt5 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 8 ipv6 ospf6 network broadcast ! router ospf6 ospf6 router-id 2.2.2.2 - interface eth-rt1 area 0.0.0.0 - interface eth-rt5 area 0.0.0.0 redistribute connected ! diff --git a/tests/topotests/bfd_ospf_topo1/rt2/ospfd.conf b/tests/topotests/bfd_ospf_topo1/rt2/ospfd.conf index a8ca564e4e..c5f4262a8f 100644 --- a/tests/topotests/bfd_ospf_topo1/rt2/ospfd.conf +++ b/tests/topotests/bfd_ospf_topo1/rt2/ospfd.conf @@ -25,6 +25,5 @@ interface eth-rt5 ! router ospf ospf router-id 2.2.2.2 - passive interface lo router-info area 0.0.0.0 ! diff --git a/tests/topotests/bfd_ospf_topo1/rt3/ospf6d.conf b/tests/topotests/bfd_ospf_topo1/rt3/ospf6d.conf index 8ab4eee1d3..faf975497d 100644 --- a/tests/topotests/bfd_ospf_topo1/rt3/ospf6d.conf +++ b/tests/topotests/bfd_ospf_topo1/rt3/ospf6d.conf @@ -5,19 +5,19 @@ hostname rt3 password 1 ! interface eth-rt1 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 8 ipv6 ospf6 network broadcast ipv6 ospf6 bfd ! interface eth-rt4 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 8 ipv6 ospf6 network broadcast ! router ospf6 ospf6 router-id 3.3.3.3 - interface eth-rt1 area 0.0.0.0 - interface eth-rt4 area 0.0.0.0 redistribute connected ! diff --git a/tests/topotests/bfd_ospf_topo1/rt3/ospfd.conf b/tests/topotests/bfd_ospf_topo1/rt3/ospfd.conf index 0404994c09..e487bdd7c0 100644 --- a/tests/topotests/bfd_ospf_topo1/rt3/ospfd.conf +++ b/tests/topotests/bfd_ospf_topo1/rt3/ospfd.conf @@ -25,6 +25,5 @@ interface eth-rt4 ! router ospf ospf router-id 3.3.3.3 - passive interface lo router-info area 0.0.0.0 ! diff --git a/tests/topotests/bfd_ospf_topo1/rt4/ospf6d.conf b/tests/topotests/bfd_ospf_topo1/rt4/ospf6d.conf index 138b688140..c96093b98a 100644 --- a/tests/topotests/bfd_ospf_topo1/rt4/ospf6d.conf +++ b/tests/topotests/bfd_ospf_topo1/rt4/ospf6d.conf @@ -5,18 +5,18 @@ hostname rt4 password 1 ! interface eth-rt3 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 8 ipv6 ospf6 network broadcast ! interface eth-rt5 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 8 ipv6 ospf6 network broadcast ! router ospf6 ospf6 router-id 4.4.4.4 - interface eth-rt3 area 0.0.0.0 - interface eth-rt5 area 0.0.0.0 redistribute connected ! diff --git a/tests/topotests/bfd_ospf_topo1/rt4/ospfd.conf b/tests/topotests/bfd_ospf_topo1/rt4/ospfd.conf index 6b8ab3704f..560904e75d 100644 --- a/tests/topotests/bfd_ospf_topo1/rt4/ospfd.conf +++ b/tests/topotests/bfd_ospf_topo1/rt4/ospfd.conf @@ -24,6 +24,5 @@ interface eth-rt5 ! router ospf ospf router-id 4.4.4.4 - passive interface lo router-info area 0.0.0.0 ! diff --git a/tests/topotests/bfd_ospf_topo1/rt5/ospf6d.conf b/tests/topotests/bfd_ospf_topo1/rt5/ospf6d.conf index 6eb4fe59a8..6d40d17d50 100644 --- a/tests/topotests/bfd_ospf_topo1/rt5/ospf6d.conf +++ b/tests/topotests/bfd_ospf_topo1/rt5/ospf6d.conf @@ -5,18 +5,18 @@ hostname rt5 password 1 ! interface eth-rt2 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 network broadcast ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 8 ! interface eth-rt4 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 network broadcast ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 8 ! router ospf6 ospf6 router-id 5.5.5.5 - interface eth-rt2 area 0.0.0.0 - interface eth-rt4 area 0.0.0.0 redistribute connected ! diff --git a/tests/topotests/bfd_ospf_topo1/rt5/ospfd.conf b/tests/topotests/bfd_ospf_topo1/rt5/ospfd.conf index 043432ec3d..77f5445286 100644 --- a/tests/topotests/bfd_ospf_topo1/rt5/ospfd.conf +++ b/tests/topotests/bfd_ospf_topo1/rt5/ospfd.conf @@ -24,6 +24,5 @@ interface eth-rt4 ! router ospf ospf router-id 5.5.5.5 - passive interface lo router-info area 0.0.0.0 ! diff --git a/tests/topotests/bfd_profiles_topo1/r4/ospf6d.conf b/tests/topotests/bfd_profiles_topo1/r4/ospf6d.conf index 4ef28c39ca..948874c0e5 100644 --- a/tests/topotests/bfd_profiles_topo1/r4/ospf6d.conf +++ b/tests/topotests/bfd_profiles_topo1/r4/ospf6d.conf @@ -1,4 +1,5 @@ interface r4-eth1 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 bfd profile fast-tx ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 10 @@ -6,5 +7,4 @@ interface r4-eth1 router ospf6 ospf6 router-id 10.254.254.4 redistribute connected - interface r4-eth1 area 0.0.0.0 ! diff --git a/tests/topotests/bfd_profiles_topo1/r5/ospf6d.conf b/tests/topotests/bfd_profiles_topo1/r5/ospf6d.conf index 20b53cfc55..f6e8dc3b67 100644 --- a/tests/topotests/bfd_profiles_topo1/r5/ospf6d.conf +++ b/tests/topotests/bfd_profiles_topo1/r5/ospf6d.conf @@ -1,4 +1,5 @@ interface r5-eth0 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 bfd ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 10 @@ -6,5 +7,4 @@ interface r5-eth0 router ospf6 ospf6 router-id 10.254.254.5 redistribute connected - interface r5-eth0 area 0.0.0.0 ! diff --git a/tests/topotests/bfd_topo3/test_bfd_topo3.py b/tests/topotests/bfd_topo3/test_bfd_topo3.py index c0dc052a38..f767b0e7b9 100644 --- a/tests/topotests/bfd_topo3/test_bfd_topo3.py +++ b/tests/topotests/bfd_topo3/test_bfd_topo3.py @@ -65,6 +65,41 @@ def setup_module(mod): tgen.start_router() +def expect_static_bfd_output(router, filename): + "Load JSON file and compare with 'show bfd peer json'" + + tgen = get_topogen() + + logger.info("waiting BFD configuration on router {}".format(router)) + bfd_config = json.loads(open("{}/{}/{}.json".format(CWD, router, filename)).read()) + test_func = partial( + topotest.router_json_cmp, + tgen.gears[router], + "show bfd static route json", + bfd_config, + ) + _, result = topotest.run_and_expect(test_func, None, count=20, wait=1) + assertmsg = '"{}" BFD static route status failure'.format(router) + assert result is None, assertmsg + + +def expect_route_missing(router, iptype, route): + "Wait until route is present on RIB for protocol." + + tgen = get_topogen() + + logger.info("waiting route {} to disapear in {}".format(route, router)) + test_func = partial( + topotest.router_json_cmp, + tgen.gears[router], + "show {} route json".format(iptype), + {route: None}, + ) + rv, result = topotest.run_and_expect(test_func, None, count=20, wait=1) + assertmsg = '"{}" convergence failure'.format(router) + assert result is None, assertmsg + + def test_wait_bgp_convergence(): "Wait for BGP to converge" tgen = get_topogen() @@ -166,7 +201,7 @@ def expect_bfd_configuration(router): expect_bfd_configuration("r6") -def test_static_route_monitoring(): +def test_static_route_monitoring_convergence(): "Test static route monitoring output." tgen = get_topogen() if tgen.routers_have_failure(): @@ -174,31 +209,47 @@ def test_static_route_monitoring(): logger.info("test BFD static route status") - def expect_static_bfd_output(router, filename): - "Load JSON file and compare with 'show bfd peer json'" - logger.info("waiting BFD configuration on router {}".format(router)) - bfd_config = json.loads( - open("{}/{}/{}.json".format(CWD, router, filename)).read() - ) - test_func = partial( - topotest.router_json_cmp, - tgen.gears[router], - "show bfd static route json", - bfd_config, - ) - _, result = topotest.run_and_expect(test_func, None, count=20, wait=1) - assertmsg = '"{}" BFD static route status failure'.format(router) - assert result is None, assertmsg - expect_static_bfd_output("r3", "bfd-static") expect_static_bfd_output("r6", "bfd-static") - logger.info("Setting r4 link down ...") - tgen.gears["r4"].link_enable("r4-eth0", False) +def test_static_route_monitoring_wrong_source(): + "Test that static monitoring fails if setting a wrong source." - expect_static_bfd_output("r3", "bfd-static-down") - expect_static_bfd_output("r6", "bfd-static-down") + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + logger.info("test route wrong ") + + tgen.gears["r3"].vtysh_cmd( + """ +configure +ipv6 route 2001:db8:5::/64 2001:db8:4::3 bfd multi-hop source 2001:db8:4::2 profile slow-tx +""" + ) + + expect_route_missing("r3", "ipv6", "2001:db8:5::/64") + + +def test_static_route_monitoring_unset_source(): + "Test that static monitoring fails if setting a wrong source." + + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + logger.info("test route wrong ") + + tgen.gears["r3"].vtysh_cmd( + """ +configure +ipv6 route 2001:db8:5::/64 2001:db8:4::3 bfd multi-hop profile slow-tx +""" + ) + + expect_static_bfd_output("r3", "bfd-static") + expect_static_bfd_output("r6", "bfd-static") def test_expect_static_rib_removal(): @@ -208,18 +259,12 @@ def test_expect_static_rib_removal(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - def expect_route_missing(router, iptype, route): - "Wait until route is present on RIB for protocol." - logger.info("waiting route {} to disapear in {}".format(route, router)) - test_func = partial( - topotest.router_json_cmp, - tgen.gears[router], - "show {} route json".format(iptype), - {route: None}, - ) - rv, result = topotest.run_and_expect(test_func, None, count=20, wait=1) - assertmsg = '"{}" convergence failure'.format(router) - assert result is None, assertmsg + logger.info("Setting r4 link down ...") + + tgen.gears["r4"].link_enable("r4-eth0", False) + + expect_static_bfd_output("r3", "bfd-static-down") + expect_static_bfd_output("r6", "bfd-static-down") expect_route_missing("r1", "ip", "10.254.254.5/32") expect_route_missing("r2", "ip", "10.254.254.5/32") diff --git a/tests/topotests/bgp_accept_own/pe1/bgpd.conf b/tests/topotests/bgp_accept_own/pe1/bgpd.conf index 15466b4259..1f7abac98f 100644 --- a/tests/topotests/bgp_accept_own/pe1/bgpd.conf +++ b/tests/topotests/bgp_accept_own/pe1/bgpd.conf @@ -25,7 +25,7 @@ router bgp 65001 vrf Customer neighbor 192.168.1.1 timers connect 1 address-family ipv4 unicast redistribute connected - label vpn export 10 + label vpn export 250 rd vpn export 192.168.1.2:2 rt vpn import 192.168.1.2:2 rt vpn export 192.168.1.2:2 @@ -40,7 +40,7 @@ router bgp 65001 vrf Service neighbor 192.168.2.1 timers 1 3 neighbor 192.168.2.1 timers connect 1 address-family ipv4 unicast - label vpn export 20 + label vpn export 350 rd vpn export 192.168.2.2:2 rt vpn import 192.168.2.2:2 rt vpn export 192.168.2.2:2 diff --git a/tests/topotests/bgp_addpath_best_selected/__init__.py b/tests/topotests/bgp_addpath_best_selected/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/bgp_addpath_best_selected/r1/bgpd.conf b/tests/topotests/bgp_addpath_best_selected/r1/bgpd.conf new file mode 100644 index 0000000000..ba10f7bcc0 --- /dev/null +++ b/tests/topotests/bgp_addpath_best_selected/r1/bgpd.conf @@ -0,0 +1,7 @@ +! +router bgp 65001 + timers bgp 3 10 + no bgp ebgp-requires-policy + neighbor 192.168.1.2 remote-as external + neighbor 192.168.1.2 timers connect 5 +! diff --git a/tests/topotests/bgp_addpath_best_selected/r1/zebra.conf b/tests/topotests/bgp_addpath_best_selected/r1/zebra.conf new file mode 100644 index 0000000000..b29940f46a --- /dev/null +++ b/tests/topotests/bgp_addpath_best_selected/r1/zebra.conf @@ -0,0 +1,4 @@ +! +int r1-eth0 + ip address 192.168.1.1/24 +! diff --git a/tests/topotests/bgp_addpath_best_selected/r2/bgpd.conf b/tests/topotests/bgp_addpath_best_selected/r2/bgpd.conf new file mode 100644 index 0000000000..cdef611286 --- /dev/null +++ b/tests/topotests/bgp_addpath_best_selected/r2/bgpd.conf @@ -0,0 +1,27 @@ +router bgp 65002 + timers bgp 3 10 + no bgp ebgp-requires-policy + neighbor 192.168.1.1 remote-as external + neighbor 192.168.7.7 remote-as external + neighbor 192.168.7.7 timers connect 5 + neighbor 192.168.2.3 remote-as external + neighbor 192.168.2.3 timers connect 5 + neighbor 192.168.2.3 weight 3 + neighbor 192.168.2.4 remote-as external + neighbor 192.168.2.4 timers connect 5 + neighbor 192.168.2.4 weight 4 + neighbor 192.168.2.5 remote-as external + neighbor 192.168.2.5 timers connect 5 + neighbor 192.168.2.5 weight 5 + neighbor 192.168.2.6 remote-as external + neighbor 192.168.2.6 timers connect 5 + neighbor 192.168.2.6 weight 6 + address-family ipv4 unicast + neighbor 192.168.1.1 addpath-tx-best-selected 1 + neighbor 192.168.1.1 prefix-list announce out + neighbor 192.168.7.7 addpath-tx-best-selected 2 + neighbor 192.168.7.7 prefix-list announce out + exit-address-family +! +ip prefix-list announce seq 5 permit 172.16.16.254/32 +! diff --git a/tests/topotests/bgp_addpath_best_selected/r2/zebra.conf b/tests/topotests/bgp_addpath_best_selected/r2/zebra.conf new file mode 100644 index 0000000000..90587d25d4 --- /dev/null +++ b/tests/topotests/bgp_addpath_best_selected/r2/zebra.conf @@ -0,0 +1,10 @@ +! +int r2-eth0 + ip address 192.168.1.2/24 +! +int r2-eth1 + ip address 192.168.2.2/24 +! +int r2-eth2 + ip address 192.168.7.2/24 +! diff --git a/tests/topotests/bgp_addpath_best_selected/r3/bgpd.conf b/tests/topotests/bgp_addpath_best_selected/r3/bgpd.conf new file mode 100644 index 0000000000..98eb2e1711 --- /dev/null +++ b/tests/topotests/bgp_addpath_best_selected/r3/bgpd.conf @@ -0,0 +1,9 @@ +router bgp 65003 + timers bgp 3 10 + no bgp ebgp-requires-policy + neighbor 192.168.2.2 remote-as external + neighbor 192.168.2.2 timers connect 5 + address-family ipv4 unicast + redistribute connected + exit-address-family +! diff --git a/tests/topotests/bgp_addpath_best_selected/r3/zebra.conf b/tests/topotests/bgp_addpath_best_selected/r3/zebra.conf new file mode 100644 index 0000000000..417a4844a5 --- /dev/null +++ b/tests/topotests/bgp_addpath_best_selected/r3/zebra.conf @@ -0,0 +1,7 @@ +! +int lo + ip address 172.16.16.254/32 +! +int r3-eth0 + ip address 192.168.2.3/24 +! diff --git a/tests/topotests/bgp_addpath_best_selected/r4/bgpd.conf b/tests/topotests/bgp_addpath_best_selected/r4/bgpd.conf new file mode 100644 index 0000000000..68245c4a21 --- /dev/null +++ b/tests/topotests/bgp_addpath_best_selected/r4/bgpd.conf @@ -0,0 +1,9 @@ +router bgp 65004 + timers bgp 3 10 + no bgp ebgp-requires-policy + neighbor 192.168.2.2 remote-as external + neighbor 192.168.2.2 timers connect 5 + address-family ipv4 unicast + redistribute connected + exit-address-family +! diff --git a/tests/topotests/bgp_addpath_best_selected/r4/zebra.conf b/tests/topotests/bgp_addpath_best_selected/r4/zebra.conf new file mode 100644 index 0000000000..241e38693c --- /dev/null +++ b/tests/topotests/bgp_addpath_best_selected/r4/zebra.conf @@ -0,0 +1,7 @@ +! +int lo + ip address 172.16.16.254/32 +! +int r4-eth0 + ip address 192.168.2.4/24 +! diff --git a/tests/topotests/bgp_addpath_best_selected/r5/bgpd.conf b/tests/topotests/bgp_addpath_best_selected/r5/bgpd.conf new file mode 100644 index 0000000000..f36e2bddd7 --- /dev/null +++ b/tests/topotests/bgp_addpath_best_selected/r5/bgpd.conf @@ -0,0 +1,9 @@ +router bgp 65005 + timers bgp 3 10 + no bgp ebgp-requires-policy + neighbor 192.168.2.2 remote-as external + neighbor 192.168.2.2 timers connect 5 + address-family ipv4 unicast + redistribute connected + exit-address-family +! diff --git a/tests/topotests/bgp_addpath_best_selected/r5/zebra.conf b/tests/topotests/bgp_addpath_best_selected/r5/zebra.conf new file mode 100644 index 0000000000..203d229f27 --- /dev/null +++ b/tests/topotests/bgp_addpath_best_selected/r5/zebra.conf @@ -0,0 +1,7 @@ +! +int lo + ip address 172.16.16.254/32 +! +int r5-eth0 + ip address 192.168.2.5/24 +! diff --git a/tests/topotests/bgp_addpath_best_selected/r6/bgpd.conf b/tests/topotests/bgp_addpath_best_selected/r6/bgpd.conf new file mode 100644 index 0000000000..0d83ef868a --- /dev/null +++ b/tests/topotests/bgp_addpath_best_selected/r6/bgpd.conf @@ -0,0 +1,9 @@ +router bgp 65006 + timers bgp 3 10 + no bgp ebgp-requires-policy + neighbor 192.168.2.2 remote-as external + neighbor 192.168.2.2 timers connect 5 + address-family ipv4 unicast + redistribute connected + exit-address-family +! diff --git a/tests/topotests/bgp_addpath_best_selected/r6/zebra.conf b/tests/topotests/bgp_addpath_best_selected/r6/zebra.conf new file mode 100644 index 0000000000..894dd30579 --- /dev/null +++ b/tests/topotests/bgp_addpath_best_selected/r6/zebra.conf @@ -0,0 +1,7 @@ +! +int lo + ip address 172.16.16.254/32 +! +int r6-eth0 + ip address 192.168.2.6/24 +! diff --git a/tests/topotests/bgp_addpath_best_selected/r7/bgpd.conf b/tests/topotests/bgp_addpath_best_selected/r7/bgpd.conf new file mode 100644 index 0000000000..090846a458 --- /dev/null +++ b/tests/topotests/bgp_addpath_best_selected/r7/bgpd.conf @@ -0,0 +1,7 @@ +! +router bgp 65007 + timers bgp 3 10 + no bgp ebgp-requires-policy + neighbor 192.168.7.2 remote-as external + neighbor 192.168.7.2 timers connect 5 +! diff --git a/tests/topotests/bgp_addpath_best_selected/r7/zebra.conf b/tests/topotests/bgp_addpath_best_selected/r7/zebra.conf new file mode 100644 index 0000000000..55c70bab8b --- /dev/null +++ b/tests/topotests/bgp_addpath_best_selected/r7/zebra.conf @@ -0,0 +1,4 @@ +! +int r7-eth0 + ip address 192.168.7.7/24 +! diff --git a/tests/topotests/bgp_addpath_best_selected/test_bgp_addpath_best_selected.py b/tests/topotests/bgp_addpath_best_selected/test_bgp_addpath_best_selected.py new file mode 100644 index 0000000000..2a610c901e --- /dev/null +++ b/tests/topotests/bgp_addpath_best_selected/test_bgp_addpath_best_selected.py @@ -0,0 +1,190 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# Copyright (c) 2023 by +# Donatas Abraitis <donatas@opensourcerouting.org> +# + +""" +Test if Add-Path best selected paths are announced per neighbor. +""" + +import os +import sys +import json +import pytest +import functools + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen + +pytestmark = [pytest.mark.bgpd] + + +def build_topo(tgen): + for routern in range(1, 8): + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r4"]) + switch.add_link(tgen.gears["r5"]) + switch.add_link(tgen.gears["r6"]) + + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r7"]) + switch.add_link(tgen.gears["r2"]) + + +def setup_module(mod): + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for i, (rname, router) in enumerate(router_list.items(), 1): + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) + ) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_addpath_best_selected(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r2 = tgen.gears["r2"] + + def _bgp_converge(): + output = json.loads(r2.vtysh_cmd("show bgp ipv4 unicast 172.16.16.254/32 json")) + expected = { + "paths": [ + { + "aspath": { + "string": "65006", + }, + "weight": 6, + }, + { + "aspath": { + "string": "65005", + }, + "weight": 5, + }, + { + "aspath": { + "string": "65004", + }, + "weight": 4, + }, + { + "aspath": { + "string": "65003", + }, + "weight": 3, + }, + ] + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_converge) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Can't converge initially" + + def check_bgp_advertised_routes_to_r1(): + output = json.loads( + r2.vtysh_cmd( + "show bgp ipv4 neighbors 192.168.1.1 advertised-routes detail json" + ) + ) + expected = { + "advertisedRoutes": { + "172.16.16.254/32": { + "paths": [ + { + "aspath": { + "string": "65005", + } + }, + { + "aspath": { + "string": "65006", + } + }, + ] + } + }, + "totalPrefixCounter": 2, + } + + return topotest.json_cmp(output, expected) + + test_func = functools.partial(check_bgp_advertised_routes_to_r1) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert ( + result is None + ), "Received more/less Add-Path best paths, but should be only 1+1 (real best path)" + + def check_bgp_advertised_routes_to_r7(): + output = json.loads( + r2.vtysh_cmd( + "show bgp ipv4 neighbors 192.168.7.7 advertised-routes detail json" + ) + ) + expected = { + "advertisedRoutes": { + "172.16.16.254/32": { + "paths": [ + { + "aspath": { + "string": "65004", + } + }, + { + "aspath": { + "string": "65005", + } + }, + { + "aspath": { + "string": "65006", + } + }, + ] + } + }, + "totalPrefixCounter": 3, + } + + return topotest.json_cmp(output, expected) + + test_func = functools.partial(check_bgp_advertised_routes_to_r7) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert ( + result is None + ), "Received more/less Add-Path best paths, but should be only 2+1 (real best path)" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_always_compare_med/bgp_always_compare_med_topo1.json b/tests/topotests/bgp_always_compare_med/bgp_always_compare_med_topo1.json new file mode 100644 index 0000000000..4156c6d0f7 --- /dev/null +++ b/tests/topotests/bgp_always_compare_med/bgp_always_compare_med_topo1.json @@ -0,0 +1,152 @@ +{ + "address_types": ["ipv4", "ipv6"], + "ipv4base": "192.168.0.0", + "ipv4mask": 30, + "ipv6base": "fd00::", + "ipv6mask": 64, + "link_ip_start":{"ipv4":"192.168.0.0", "v4mask":24, "ipv6":"fd00::", "v6mask":64}, + "lo_prefix":{"ipv4":"1.0.", "v4mask":32, "ipv6":"2001:DB8:F::", "v6mask":128}, + "routers": { + "r1": { + "links": { + "lo": {"ipv4": "auto", "ipv6": "auto", "type": "loopback"}, + "r2": {"ipv4": "auto", "ipv6": "auto"}, + "r3": {"ipv4": "auto", "ipv6": "auto"} + }, + "bgp": { + "local_as": "100", + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r2": {"dest_link": {"r1": {}}}, + "r3": {"dest_link": {"r1": {}}} + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r2": {"dest_link": {"r1": { + "route_maps": [{ + "name": "rmap_global", + "direction": "in" + }] + }}}, + "r3": {"dest_link": {"r1": { + "route_maps": [{ + "name": "rmap_global", + "direction": "in" + }] + }}} + } + } + } + } + }, + "route_maps": { + "rmap_global": [{ + "action": "permit", + "set": { + "ipv6": { + "nexthop": "prefer-global" + } + } + }] + }, + "static_routes":[ + { + "network":"192.168.20.1/32", + "next_hop":"Null0" + }, + { + "network":"192:168:20::1/128", + "next_hop":"Null0" + }] + }, + "r2": { + "links": { + "lo": {"ipv4": "auto", "ipv6": "auto", "type": "loopback"}, + "r1": {"ipv4": "auto", "ipv6": "auto"}, + "r4": {"ipv4": "auto", "ipv6": "auto"} + }, + "bgp": { + "local_as": "200", + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r1": {"dest_link": {"r2": {}}}, + "r4": {"dest_link": {"r2": {}}} + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r1": {"dest_link": {"r2": {}}}, + "r4": {"dest_link": {"r2": {}}} + } + } + } + } + } + }, + "r3": { + "links": { + "lo": {"ipv4": "auto", "ipv6": "auto", "type": "loopback"}, + "r1": {"ipv4": "auto", "ipv6": "auto"}, + "r4": {"ipv4": "auto", "ipv6": "auto"} + }, + "bgp": { + "local_as": "300", + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r1": {"dest_link": {"r3": {}}}, + "r4": {"dest_link": {"r3": {}}} + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r1": {"dest_link": {"r3": {}}}, + "r4": {"dest_link": {"r3": {}}} + } + } + } + } + } + }, + "r4": { + "links": { + "lo": {"ipv4": "auto", "ipv6": "auto", "type": "loopback"}, + "r2": {"ipv4": "auto", "ipv6": "auto"}, + "r3": {"ipv4": "auto", "ipv6": "auto"} + }, + "bgp": { + "local_as": "400", + "address_family": { + "ipv4": { + "unicast": { + "neighbor": { + "r2": {"dest_link": {"r4": {}}}, + "r3": {"dest_link": {"r4": {}}} + } + } + }, + "ipv6": { + "unicast": { + "neighbor": { + "r2": {"dest_link": {"r4": {}}}, + "r3": {"dest_link": {"r4": {}}} + } + } + } + } + } + } + } +} diff --git a/tests/topotests/bgp_always_compare_med/test_bgp_always_compare_med_topo1.py b/tests/topotests/bgp_always_compare_med/test_bgp_always_compare_med_topo1.py new file mode 100644 index 0000000000..fb72f4331d --- /dev/null +++ b/tests/topotests/bgp_always_compare_med/test_bgp_always_compare_med_topo1.py @@ -0,0 +1,1118 @@ +#!/usr/bin/env python3 +# +# SPDX-License-Identifier: ISC +# +# Copyright (c) 2023 by VMware, Inc. ("VMware") +# +# +################################################################################ +# Following tests are performed to validate BGP always compare MED functionality +################################################################################ +""" +1. Verify the BGP always compare MED functionality in between eBGP Peers +2. Verify the BGP always compare MED functionality in between eBGP Peers with by changing different AD values +3. Verify the BGP always compare MED functionality in between eBGP Peers by changing MED values in middle routers +4. Verify that BGP Always compare MED functionality by restarting BGP, Zebra and FRR services and clear BGP and + shutdown BGP neighbor +5. Verify BGP always compare MED functionality by performing shut/noshut on the interfaces in between BGP neighbors +""" + +import os +import sys +import time +import pytest + +# Save the Current Working Directory to find configuration files. +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) +sys.path.append(os.path.join(CWD, "../lib/")) + +# pylint: disable=C0413 +# Import topogen and topotest helpers +from lib.topogen import Topogen, get_topogen + +from lib.common_config import ( + start_topology, + write_test_header, + create_static_routes, + write_test_footer, + reset_config_on_routers, + verify_rib, + step, + check_address_types, + check_router_status, + create_static_routes, + create_prefix_lists, + create_route_maps, + kill_router_daemons, + shutdown_bringup_interface, + stop_router, + start_router, + delete_route_maps, +) + +from lib.topolog import logger +from lib.bgp import verify_bgp_convergence, verify_bgp_rib, create_router_bgp, clear_bgp +from lib.topojson import build_config_from_json + +pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] + +# Reading the data from JSON File for topology creation +topo = None + +# Global variables +ADDR_TYPES = check_address_types() +NETWORK1_1 = {"ipv4": "192.168.20.1/32", "ipv6": "192:168:20::1/128"} +NETWORK1_2 = {"ipv4": "192.168.30.1/32", "ipv6": "192:168:30::1/128"} +NETWORK1_3 = {"ipv4": "192.168.40.1/32", "ipv6": "192:168:40::1/128"} +NEXT_HOP_IP = {"ipv4": "Null0", "ipv6": "Null0"} + + +def setup_module(mod): + """ + Sets up the pytest environment + + * `mod`: module name + """ + + testsuite_run_time = time.asctime(time.localtime(time.time())) + logger.info("Testsuite start time: {}".format(testsuite_run_time)) + logger.info("=" * 40) + + logger.info("Running setup_module to create topology") + + # This function initiates the topology build with Topogen... + json_file = "{}/bgp_always_compare_med_topo1.json".format(CWD) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo + # ... and here it calls Mininet initialization functions. + + # Starting topology, create tmp files which are loaded to routers + # to start daemons and then start routers + start_topology(tgen) + + # Creating configuration from JSON + build_config_from_json(tgen, topo) + + global ADDR_TYPES + ADDR_TYPES = check_address_types() + + BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) + assert BGP_CONVERGENCE is True, "setup_module : Failed \n Error: {}".format( + BGP_CONVERGENCE + ) + + logger.info("Running setup_module() done") + + +def teardown_module(): + """Teardown the pytest environment""" + + logger.info("Running teardown_module to delete topology") + + tgen = get_topogen() + + # Stop toplogy and Remove tmp files + tgen.stop_topology() + + logger.info( + "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) + ) + logger.info("=" * 40) + + +########################################################################################################## +# +# Local API +# +########################################################################################################## + + +def initial_configuration(tgen, tc_name): + """ + API to do initial set of configuration + """ + + step( + "Configure IPv4 and IPv6, eBGP neighbors between R1,R2 and R3 routers as per base config" + ) + + step("Configure static routes in R4") + for addr_type in ADDR_TYPES: + input_static_r4 = { + "r4": { + "static_routes": [ + { + "network": NETWORK1_1[addr_type], + "next_hop": NEXT_HOP_IP[addr_type], + } + ] + } + } + + logger.info("Configure static routes") + result = create_static_routes(tgen, input_static_r4) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Configure redistribute static in R4") + input_static_redist_r4 = { + "r4": { + "bgp": { + "address_family": { + addr_type: { + "unicast": {"redistribute": [{"redist_type": "static"}]} + } + } + } + } + } + result = create_router_bgp(tgen, topo, input_static_redist_r4) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + for addr_type in ADDR_TYPES: + # Create prefix list + input_dict_23 = { + "r2": { + "prefix_lists": { + addr_type: { + "pf_ls_r2_{}".format(addr_type): [ + {"network": NETWORK1_1[addr_type], "action": "permit"} + ] + } + } + }, + "r3": { + "prefix_lists": { + "ipv4": { + "pf_ls_r3_{}".format(addr_type): [ + {"network": NETWORK1_1[addr_type], "action": "permit"} + ] + } + } + }, + } + result = create_prefix_lists(tgen, input_dict_23) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + # Create route map + input_dict_23 = { + "r2": { + "route_maps": { + "RMAP_MED_R2": [ + { + "action": "permit", + "match": { + addr_type: { + "prefix_lists": "pf_ls_r2_{}".format(addr_type) + } + }, + "set": {"med": 300}, + } + ] + } + }, + "r3": { + "route_maps": { + "RMAP_MED_R3": [ + { + "action": "permit", + "match": { + addr_type: { + "prefix_lists": "pf_ls_r3_{}".format(addr_type) + } + }, + "set": {"med": 200}, + } + ] + } + }, + } + result = create_route_maps(tgen, input_dict_23) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + input_dict_r2_r3 = { + "r2": { + "bgp": { + "address_family": { + addr_type: { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r2": { + "route_maps": [ + { + "name": "RMAP_MED_R2", + "direction": "out", + } + ] + } + } + } + } + } + } + } + } + }, + "r3": { + "bgp": { + "address_family": { + addr_type: { + "unicast": { + "neighbor": { + "r1": { + "dest_link": { + "r3": { + "route_maps": [ + { + "name": "RMAP_MED_R3", + "direction": "out", + } + ] + } + } + } + } + } + } + } + } + }, + } + result = create_router_bgp(tgen, topo, input_dict_r2_r3) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + +########################################################################################################## +# +# Testcases +# +########################################################################################################## + + +def test_verify_bgp_always_compare_med_functionality_bw_eBGP_peers_p0(request): + """ + Verify the BGP always compare MED functionality in between eBGP Peers + """ + + # test case name + tc_name = request.node.name + write_test_header(tc_name) + + tgen = get_topogen() + if tgen.routers_have_failure(): + check_router_status(tgen) + reset_config_on_routers(tgen) + initial_configuration(tgen, tc_name) + + step( + "Configure IPv4 and IPv6, eBGP neighbors between R1,R2 and R3 routers as per base config" + ) + step( + "Verify that IPv4 and IPv6 eBGP neighbors are configured in between routers by following " + "commands and verify that best path chosen by lowest MED value" + ) + + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Configure 'multi-path as-path relax' command at R1.") + configure_bgp = { + "r1": {"bgp": {"local_as": "100", "bestpath": {"aspath": "multipath-relax"}}} + } + result = create_router_bgp(tgen, topo, configure_bgp) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + step( + "Verify that after applying 'multi-path as-path relax' command, " + "its also chooses lowest MED to reach destination." + ) + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + nh1 = topo["routers"]["r2"]["links"]["r1"][addr_type].split("/")[0] + nh2 = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0] + + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1, next_hop=[nh1, nh2]) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Configure 'bgp always-compare-med' command at R1.") + input_dict_r1 = {"r1": {"bgp": {"local_as": "100", "bgp_always_compare_med": True}}} + result = create_router_bgp(tgen, topo, input_dict_r1) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step( + "Verify that after applying 'bgp always-compare-med', its chooses lowest MED value path" + ) + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + nh = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0] + + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1, next_hop=nh) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Remove 'bgp always-compare-med' command at R1.") + input_dict_r1 = { + "r1": {"bgp": {"local_as": "100", "bgp_always_compare_med": False}} + } + result = create_router_bgp(tgen, topo, input_dict_r1) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step("Verify that 'bgp always-compare-med' command is removed") + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + nh1 = topo["routers"]["r2"]["links"]["r1"][addr_type].split("/")[0] + nh2 = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0] + + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1, next_hop=[nh1, nh2]) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Remove 'multi-path as-path relax' command at R1") + configure_bgp = { + "r1": { + "bgp": { + "local_as": "100", + "bestpath": {"aspath": "multipath-relax", "delete": True}, + } + } + } + result = create_router_bgp(tgen, topo, configure_bgp) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + step("Verify route selection after removing 'multi-path as-path relax' command") + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + write_test_footer(tc_name) + + +def test_verify_bgp_always_compare_med_functionality_bw_eBGP_peers_by_changing_AD_values_p0( + request, +): + """ + Verify the BGP always compare MED functionality in between eBGP Peers with by changing different AD values. + """ + + # test case name + tc_name = request.node.name + write_test_header(tc_name) + + tgen = get_topogen() + if tgen.routers_have_failure(): + check_router_status(tgen) + reset_config_on_routers(tgen) + initial_configuration(tgen, tc_name) + + step( + "Configure IPv4 and IPv6, eBGP neighbors between R1,R2 and R3 routers as per base config" + ) + step( + "Verify that IPv4 and IPv6 eBGP neighbors are configured in between routers by following " + "commands and verify that best path chosen by lowest MED value" + ) + + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Configure 'bgp always-compare-med' command at R1.") + input_dict_r1 = {"r1": {"bgp": {"local_as": "100", "bgp_always_compare_med": True}}} + result = create_router_bgp(tgen, topo, input_dict_r1) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step( + "Verify that after applying 'bgp always-compare-med', its chooses lowest MED value path" + ) + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + nh = topo["routers"]["r2"]["links"]["r1"][addr_type].split("/")[0] + + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1, next_hop=nh) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Configure AD value=100 at R2 and AD value=200 at R3 towards R1") + input_dict_1 = { + "r2": { + "bgp": { + "local_as": 200, + "address_family": { + "ipv4": { + "unicast": { + "distance": {"ebgp": 100, "ibgp": 100, "local": 100} + } + }, + "ipv6": { + "unicast": { + "distance": {"ebgp": 100, "ibgp": 100, "local": 100} + } + }, + }, + } + }, + "r3": { + "bgp": { + "local_as": 300, + "address_family": { + "ipv4": { + "unicast": { + "distance": {"ebgp": 200, "ibgp": 200, "local": 200} + } + }, + "ipv6": { + "unicast": { + "distance": {"ebgp": 200, "ibgp": 200, "local": 200} + } + }, + }, + } + }, + } + + result = create_router_bgp(tgen, topo, input_dict_1) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + step( + "Verify that inspite of AD values, always lowest MED value is getting " + "selected at destination router R1" + ) + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + nh = topo["routers"]["r2"]["links"]["r1"][addr_type].split("/")[0] + + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1, next_hop=nh) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + write_test_footer(tc_name) + + +def test_verify_bgp_always_compare_med_functionality_bw_eBGP_peers_by_changing_MED_values_p1( + request, +): + """ + Verify the BGP always compare MED functionality in between eBGP Peers by changing MED values in middle routers + """ + + # test case name + tc_name = request.node.name + write_test_header(tc_name) + + tgen = get_topogen() + if tgen.routers_have_failure(): + check_router_status(tgen) + reset_config_on_routers(tgen) + initial_configuration(tgen, tc_name) + + step( + "Configure IPv4 and IPv6, eBGP neighbors between R1,R2 and R3 routers as per base config" + ) + step( + "Verify that IPv4 and IPv6 eBGP neighbors are configured in between routers by following " + "commands and verify that best path chosen by lowest MED value" + ) + + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Configure 'multi-path as-path relax' command at R1.") + configure_bgp = { + "r1": {"bgp": {"local_as": "100", "bestpath": {"aspath": "multipath-relax"}}} + } + result = create_router_bgp(tgen, topo, configure_bgp) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + step( + "Verify that after applying 'multi-path as-path relax' command, " + "its also chooses lowest MED to reach destination." + ) + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + nh1 = topo["routers"]["r2"]["links"]["r1"][addr_type].split("/")[0] + nh2 = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0] + + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1, next_hop=[nh1, nh2]) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Configure 'bgp always-compare-med' command at R1.") + input_dict_r1 = {"r1": {"bgp": {"local_as": "100", "bgp_always_compare_med": True}}} + result = create_router_bgp(tgen, topo, input_dict_r1) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step( + "Verify that after applying 'bgp always-compare-med', its chooses lowest MED value path" + ) + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + nh = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0] + + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1, next_hop=nh) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Change the MED value 150 in R2 router.") + input_dict = {"r2": {"route_maps": ["RMAP_MED_R2"]}} + result = delete_route_maps(tgen, input_dict) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + for addr_type in ADDR_TYPES: + input_dict_2 = { + "r2": { + "route_maps": { + "RMAP_MED_R2": [ + { + "action": "permit", + "match": { + addr_type: { + "prefix_lists": "pf_ls_r2_{}".format(addr_type) + } + }, + "set": {"med": 150}, + } + ] + } + } + } + result = create_route_maps(tgen, input_dict_2) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Verify that after changing MED, its chooses lowest MED value path") + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + nh = topo["routers"]["r2"]["links"]["r1"][addr_type].split("/")[0] + + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1, next_hop=nh) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Change the MED value 100 in R3 router.") + input_dict = {"r3": {"route_maps": ["RMAP_MED_R3"]}} + result = delete_route_maps(tgen, input_dict) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + for addr_type in ADDR_TYPES: + input_dict_3 = { + "r3": { + "route_maps": { + "RMAP_MED_R3": [ + { + "action": "permit", + "match": { + addr_type: { + "prefix_lists": "pf_ls_r3_{}".format(addr_type) + } + }, + "set": {"med": 100}, + } + ] + } + } + } + result = create_route_maps(tgen, input_dict_3) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Verify that after changing MED, its chooses lowest MED value path") + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + nh = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0] + + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1, next_hop=nh) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + write_test_footer(tc_name) + + +def test_verify_bgp_always_compare_med_functionality_by_restarting_daemons_clear_bgp_shut_neighbors_p1( + request, +): + """ + Verify that BGP Always compare MED functionality by restarting BGP, Zebra and FRR services and clear BGP and shutdown BGP neighbor + """ + + # test case name + tc_name = request.node.name + write_test_header(tc_name) + + tgen = get_topogen() + if tgen.routers_have_failure(): + check_router_status(tgen) + reset_config_on_routers(tgen) + initial_configuration(tgen, tc_name) + + step( + "Configure IPv4 and IPv6, eBGP neighbors between R1,R2 and R3 routers as per base config" + ) + step( + "Verify that IPv4 and IPv6 eBGP neighbors are configured in between routers by following " + "commands and verify that best path chosen by lowest MED value" + ) + + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Configure 'multi-path as-path relax' command at R1.") + configure_bgp = { + "r1": {"bgp": {"local_as": "100", "bestpath": {"aspath": "multipath-relax"}}} + } + result = create_router_bgp(tgen, topo, configure_bgp) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + step( + "Verify that after applying 'multi-path as-path relax' command, " + "its also chooses lowest MED to reach destination." + ) + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + nh1 = topo["routers"]["r2"]["links"]["r1"][addr_type].split("/")[0] + nh2 = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0] + + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1, next_hop=[nh1, nh2]) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Configure 'bgp always-compare-med' command at R1.") + input_dict_r1 = {"r1": {"bgp": {"local_as": "100", "bgp_always_compare_med": True}}} + result = create_router_bgp(tgen, topo, input_dict_r1) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step( + "Verify that after applying 'bgp always-compare-med', its chooses lowest MED value path" + ) + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + nh = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0] + + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1, next_hop=nh) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Restart the BGPd/Zebra/FRR service on R1") + for daemon in ["bgpd", "zebra", "frr"]: + if daemon == "frr": + stop_router(tgen, "r1") + start_router(tgen, "r1") + else: + kill_router_daemons(tgen, "r1", daemon) + + step( + "Verify after restarting dameons and frr services, its chooses lowest MED value path" + ) + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + nh = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0] + + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1, next_hop=nh) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Clear bgp on R1") + clear_bgp(tgen, None, "r1") + + step("Verify after clearing BGP, its chooses lowest MED value path") + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + nh = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0] + + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1, next_hop=nh) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Perform BGP neighborship shut/no shut") + for action, keyword in zip([True, False], ["shut", "noshut"]): + for addr_type in ADDR_TYPES: + input_dict = { + "r1": { + "bgp": { + "address_family": { + addr_type: { + "unicast": { + "neighbor": { + "r3": { + "dest_link": {"r1": {"shutdown": action}} + } + } + } + } + } + } + } + } + result = create_router_bgp(tgen, topo, input_dict) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Verify after {} BGP, its chooses lowest MED value path".format(keyword)) + if action: + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + nh = topo["routers"]["r2"]["links"]["r1"][addr_type].split("/")[0] + + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1, next_hop=nh) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + else: + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + nh = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0] + + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1, next_hop=nh) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + write_test_footer(tc_name) + + +def test_verify_bgp_always_compare_med_functionality_by_shut_noshut_interfaces_bw_bgp_neighbors_p1( + request, +): + """ + Verify BGP always compare MED functionality by performing shut/noshut on the interfaces in between BGP neighbors + """ + + # test case name + tc_name = request.node.name + write_test_header(tc_name) + + tgen = get_topogen() + if tgen.routers_have_failure(): + check_router_status(tgen) + reset_config_on_routers(tgen) + initial_configuration(tgen, tc_name) + + step( + "Configure IPv4 and IPv6, eBGP neighbors between R1,R2 and R3 routers as per base config" + ) + step( + "Verify that IPv4 and IPv6 eBGP neighbors are configured in between routers by following " + "commands and verify that best path chosen by lowest MED value" + ) + + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Configure 'multi-path as-path relax' command at R1.") + configure_bgp = { + "r1": {"bgp": {"local_as": "100", "bestpath": {"aspath": "multipath-relax"}}} + } + result = create_router_bgp(tgen, topo, configure_bgp) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + step( + "Verify that after applying 'multi-path as-path relax' command, " + "its also chooses lowest MED to reach destination." + ) + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + nh1 = topo["routers"]["r2"]["links"]["r1"][addr_type].split("/")[0] + nh2 = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0] + + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1, next_hop=[nh1, nh2]) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Configure 'bgp always-compare-med' command at R1.") + input_dict_r1 = {"r1": {"bgp": {"local_as": "100", "bgp_always_compare_med": True}}} + result = create_router_bgp(tgen, topo, input_dict_r1) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step( + "Verify that after applying 'bgp always-compare-med', its chooses lowest MED value path" + ) + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + nh = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0] + + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1, next_hop=nh) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + for action, keyword in zip([False, True], ["Shut", "No Shut"]): + step( + "{} the interface on the link between R3 & R4 and R2 & R4 routers".format( + keyword + ) + ) + intf2_4 = topo["routers"]["r2"]["links"]["r4"]["interface"] + intf3_4 = topo["routers"]["r3"]["links"]["r4"]["interface"] + for dut, intf in zip(["r2", "r3"], [intf2_4, intf3_4]): + shutdown_bringup_interface(tgen, dut, intf, action) + + for addr_type in ADDR_TYPES: + input_static_r1 = { + "r1": {"static_routes": [{"network": NETWORK1_1[addr_type]}]} + } + nh = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0] + + if action: + result = verify_bgp_rib(tgen, addr_type, "r1", input_static_r1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + result = verify_rib(tgen, addr_type, "r1", input_static_r1, next_hop=nh) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + else: + result = verify_bgp_rib( + tgen, addr_type, "r1", input_static_r1, expected=False + ) + assert ( + result is not True + ), "Testcase {} :Failed \n Routes are still present in BGP table\n Error {}".format( + tc_name, result + ) + + result = verify_rib( + tgen, addr_type, "r1", input_static_r1, next_hop=nh, expected=False + ) + assert ( + result is not True + ), "Testcase {} :Failed \n Routes are still present in FIB \n Error {}".format( + tc_name, result + ) + + write_test_footer(tc_name) + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_blackhole_community/r4/bgpd.conf b/tests/topotests/bgp_blackhole_community/r4/bgpd.conf index 0ac963e642..eca12bd3d9 100644 --- a/tests/topotests/bgp_blackhole_community/r4/bgpd.conf +++ b/tests/topotests/bgp_blackhole_community/r4/bgpd.conf @@ -4,3 +4,10 @@ router bgp 65002 no bgp ebgp-requires-policy neighbor r4-eth0 interface remote-as internal ! +address-family ipv4 unicast + neighbor r4-eth0 route-map FOO in +exit-address-family +! +route-map FOO permit 10 + set ipv6 next-hop local fe80::202:ff:fe00:99 +exit diff --git a/tests/topotests/bgp_blackhole_community/test_bgp_blackhole_community.py b/tests/topotests/bgp_blackhole_community/test_bgp_blackhole_community.py index 16191911a9..9f5c0ef924 100644 --- a/tests/topotests/bgp_blackhole_community/test_bgp_blackhole_community.py +++ b/tests/topotests/bgp_blackhole_community/test_bgp_blackhole_community.py @@ -107,6 +107,23 @@ def _bgp_no_advertise_ibgp(): return topotest.json_cmp(output, expected) + def _bgp_verify_nexthop_validity(): + output = json.loads(tgen.gears["r4"].vtysh_cmd("show bgp nexthop json")) + + expected = { + "ipv6": { + "fe80::202:ff:fe00:99": { + "valid": True, + "complete": True, + "igpMetric": 0, + "pathCount": 2, + "nexthops": [{"interfaceName": "r4-eth0"}], + }, + } + } + + return topotest.json_cmp(output, expected) + test_func = functools.partial(_bgp_converge) success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) @@ -124,7 +141,6 @@ def _bgp_no_advertise_ibgp(): ) step("Check if 172.16.255.254/32 is advertised to iBGP peers") - test_func = functools.partial(_bgp_no_advertise_ibgp) success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) @@ -134,6 +150,11 @@ def _bgp_no_advertise_ibgp(): tgen.gears["r2"] ) + step("Verify if the nexthop set via route-map on r4 is marked valid") + test_func = functools.partial(_bgp_verify_nexthop_validity) + success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, 'Nexthops are not valid "{}"'.format(tgen.gears["r4"]) + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] diff --git a/tests/topotests/bgp_bmp/__init__.py b/tests/topotests/bgp_bmp/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/bgp_bmp/r1/bgpd.conf b/tests/topotests/bgp_bmp/r1/bgpd.conf new file mode 100644 index 0000000000..69acf6e750 --- /dev/null +++ b/tests/topotests/bgp_bmp/r1/bgpd.conf @@ -0,0 +1,22 @@ +router bgp 65501 + bgp router-id 192.168.0.1 + bgp log-neighbor-changes + no bgp ebgp-requires-policy + neighbor 192.168.0.2 remote-as 65502 + neighbor 192:168::2 remote-as 65502 +! + bmp targets bmp1 + bmp connect 192.0.178.10 port 1789 min-retry 100 max-retry 10000 + exit +! + address-family ipv4 unicast + neighbor 192.168.0.2 activate + neighbor 192.168.0.2 soft-reconfiguration inbound + no neighbor 192:168::2 activate + exit-address-family +! + address-family ipv6 unicast + neighbor 192:168::2 activate + neighbor 192:168::2 soft-reconfiguration inbound + exit-address-family +! diff --git a/tests/topotests/bgp_bmp/r1/zebra.conf b/tests/topotests/bgp_bmp/r1/zebra.conf new file mode 100644 index 0000000000..6a25a6f4c2 --- /dev/null +++ b/tests/topotests/bgp_bmp/r1/zebra.conf @@ -0,0 +1,7 @@ +interface r1-eth0 + ip address 192.0.178.1/24 +! +interface r1-eth1 + ip address 192.168.0.1/24 + ipv6 address 192:168::1/64 +! diff --git a/tests/topotests/bgp_bmp/r2/bgpd.conf b/tests/topotests/bgp_bmp/r2/bgpd.conf new file mode 100644 index 0000000000..7c8255a175 --- /dev/null +++ b/tests/topotests/bgp_bmp/r2/bgpd.conf @@ -0,0 +1,19 @@ +router bgp 65502 + bgp router-id 192.168.0.2 + bgp log-neighbor-changes + no bgp ebgp-requires-policy + no bgp network import-check + neighbor 192.168.0.1 remote-as 65501 + neighbor 192:168::1 remote-as 65501 +! + address-family ipv4 unicast + neighbor 192.168.0.1 activate + no neighbor 192:168::1 activate + redistribute connected + exit-address-family +! + address-family ipv6 unicast + neighbor 192:168::1 activate + redistribute connected + exit-address-family +! diff --git a/tests/topotests/bgp_bmp/r2/zebra.conf b/tests/topotests/bgp_bmp/r2/zebra.conf new file mode 100644 index 0000000000..9d82bfe2df --- /dev/null +++ b/tests/topotests/bgp_bmp/r2/zebra.conf @@ -0,0 +1,8 @@ +interface r2-eth0 + ip address 192.168.0.2/24 + ipv6 address 192:168::2/64 +! +interface r2-eth1 + ip address 172.31.0.2/24 + ipv6 address 172:31::2/64 +! diff --git a/tests/topotests/bgp_bmp/test_bgp_bmp.py b/tests/topotests/bgp_bmp/test_bgp_bmp.py new file mode 100644 index 0000000000..250f1cb90d --- /dev/null +++ b/tests/topotests/bgp_bmp/test_bgp_bmp.py @@ -0,0 +1,249 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# Copyright 2023 6WIND S.A. +# Authored by Farid Mihoub <farid.mihoub@6wind.com> +# + +""" +test_bgp_bmp.py: Test BGP BMP functionalities + + +------+ +------+ +------+ + | | | | | | + | BMP1 |------------| R1 |---------------| R2 | + | | | | | | + +------+ +------+ +------+ + +Setup two routers R1 and R2 with one link configured with IPv4 and +IPv6 addresses. +Configure BGP in R1 and R2 to exchange prefixes from +the latter to the first router. +Setup a link between R1 and the BMP server, activate the BMP feature in R1 +and ensure the monitored BGP sessions logs are well present on the BMP server. +""" + +from functools import partial +from ipaddress import ip_network +import json +import os +import platform +import pytest +import sys + +# Save the Current Working Directory to find configuration files. +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join("../")) +sys.path.append(os.path.join("../lib/")) + +# pylint: disable=C0413 +# Import topogen and topotest helpers +from lib import topotest +from lib.bgp import verify_bgp_convergence_from_running_config +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger + +pytestmark = [pytest.mark.bgpd] + +# remember the last sequence number of the logging messages +SEQ = 0 + +PRE_POLICY = "pre-policy" +POST_POLICY = "post-policy" +LOC_RIB = "loc-rib" + + +def build_topo(tgen): + tgen.add_router("r1") + tgen.add_router("r2") + tgen.add_bmp_server("bmp1", ip="192.0.178.10", defaultRoute="via 192.0.178.1") + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["bmp1"]) + + tgen.add_link(tgen.gears["r1"], tgen.gears["r2"], "r1-eth1", "r2-eth0") + + +def setup_module(mod): + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + + for rname, router in tgen.routers().items(): + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_BGP, + os.path.join(CWD, "{}/bgpd.conf".format(rname)), + "-M bmp", + ) + + tgen.start_router() + + logger.info("starting BMP servers") + for _, server in tgen.get_bmp_servers().items(): + server.start() + + +def teardown_module(_mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_convergence(): + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + result = verify_bgp_convergence_from_running_config(tgen, dut="r1") + assert result is True, "BGP is not converging" + + +def get_bmp_messages(): + """ + Read the BMP logging messages. + """ + messages = [] + tgen = get_topogen() + text_output = tgen.gears["bmp1"].run("cat /var/log/bmp.log") + + for m in text_output.splitlines(): + # some output in the bash can break the message decoding + try: + messages.append(json.loads(m)) + except Exception as e: + logger.warning(str(e) + " message: {}".format(str(m))) + continue + + if not messages: + logger.error("Bad BMP log format, check your BMP server") + + return messages + + +def check_for_prefixes(expected_prefixes, bmp_log_type, policy): + """ + Check for the presence of the given prefixes in the BMP server logs with + the given message type and the set policy. + """ + global SEQ + # we care only about the new messages + messages = [ + m for m in sorted(get_bmp_messages(), key=lambda d: d["seq"]) if m["seq"] > SEQ + ] + + # get the list of pairs (prefix, policy, seq) for the given message type + prefixes = [ + m["ip_prefix"] + for m in messages + if "ip_prefix" in m.keys() + and "bmp_log_type" in m.keys() + and m["bmp_log_type"] == bmp_log_type + and m["policy"] == policy + ] + + # check for prefixes + for ep in expected_prefixes: + if ep not in prefixes: + msg = "The prefix {} is not present in the {} log messages." + logger.debug(msg.format(ep, bmp_log_type)) + return False + + SEQ = messages[-1]["seq"] + return True + + +def set_bmp_policy(tgen, node, asn, target, safi, policy, vrf=None): + """ + Configure the bmp policy. + """ + vrf = " vrf {}" if vrf else "" + cmd = [ + "con t\n", + "router bgp {}{}\n".format(asn, vrf), + "bmp targets {}\n".format(target), + "bmp monitor ipv4 {} {}\n".format(safi, policy), + "bmp monitor ipv6 {} {}\n".format(safi, policy), + "end\n", + ] + tgen.gears[node].vtysh_cmd("".join(cmd)) + + +def configure_prefixes(tgen, node, asn, safi, prefixes, vrf=None, update=True): + """ + Configure the bgp prefixes. + """ + withdraw = "no " if not update else "" + vrf = " vrf {}" if vrf else "" + for p in prefixes: + ip = ip_network(p) + cmd = [ + "conf t\n", + "router bgp {}{}\n".format(asn, vrf), + "address-family ipv{} {}\n".format(ip.version, safi), + "{}network {}\n".format(withdraw, ip), + "exit-address-family\n", + ] + logger.debug("setting prefix: ipv{} {} {}".format(ip.version, safi, ip)) + tgen.gears[node].vtysh_cmd("".join(cmd)) + + +def unicast_prefixes(policy): + """ + Setup the BMP monitor policy, Add and withdraw ipv4/v6 prefixes. + Check if the previous actions are logged in the BMP server with the right + message type and the right policy. + """ + tgen = get_topogen() + set_bmp_policy(tgen, "r1", 65501, "bmp1", "unicast", policy) + + prefixes = ["172.31.0.15/32", "2111::1111/128"] + # add prefixes + configure_prefixes(tgen, "r2", 65502, "unicast", prefixes) + + logger.info("checking for updated prefixes") + # check + test_func = partial(check_for_prefixes, prefixes, "update", policy) + success, _ = topotest.run_and_expect(test_func, True, wait=0.5) + assert success, "Checking the updated prefixes has been failed !." + + # withdraw prefixes + configure_prefixes(tgen, "r2", 65502, "unicast", prefixes, update=False) + logger.info("checking for withdrawed prefxies") + # check + test_func = partial(check_for_prefixes, prefixes, "withdraw", policy) + success, _ = topotest.run_and_expect(test_func, True, wait=0.5) + assert success, "Checking the withdrawed prefixes has been failed !." + + +def test_bmp_server_logging(): + """ + Assert the logging of the bmp server. + """ + + def check_for_log_file(): + tgen = get_topogen() + output = tgen.gears["bmp1"].run("ls /var/log/") + if "bmp.log" not in output: + return False + return True + + success, _ = topotest.run_and_expect(check_for_log_file, True, wait=0.5) + assert success, "The BMP server is not logging" + + +def test_bmp_bgp_unicast(): + """ + Add/withdraw bgp unicast prefixes and check the bmp logs. + """ + logger.info("*** Unicast prefixes pre-policy logging ***") + unicast_prefixes(PRE_POLICY) + logger.info("*** Unicast prefixes post-policy logging ***") + unicast_prefixes(POST_POLICY) + logger.info("*** Unicast prefixes loc-rib logging ***") + unicast_prefixes(LOC_RIB) + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_color_extcommunities/__init__.py b/tests/topotests/bgp_color_extcommunities/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/bgp_color_extcommunities/r1/bgpd.conf b/tests/topotests/bgp_color_extcommunities/r1/bgpd.conf new file mode 100644 index 0000000000..d4ca392b1a --- /dev/null +++ b/tests/topotests/bgp_color_extcommunities/r1/bgpd.conf @@ -0,0 +1,17 @@ +! +router bgp 65001 + bgp router-id 192.168.1.1 + no bgp ebgp-requires-policy + no bgp network import-check + neighbor 192.168.1.2 remote-as external + address-family ipv4 unicast + network 10.10.10.10/24 route-map rmap + neighbor 192.168.1.2 route-map rmap out + neighbor 192.168.1.2 activate + exit-address-family +! +route-map rmap permit 10 + set extcommunity color 1 + set extcommunity rt 80:987 + set extcommunity color 100 55555 200 +exit diff --git a/tests/topotests/bgp_color_extcommunities/r1/zebra.conf b/tests/topotests/bgp_color_extcommunities/r1/zebra.conf new file mode 100644 index 0000000000..42a830372f --- /dev/null +++ b/tests/topotests/bgp_color_extcommunities/r1/zebra.conf @@ -0,0 +1,3 @@ +! +int r1-eth0 + ip address 192.168.1.1/24 diff --git a/tests/topotests/bgp_color_extcommunities/r2/bgpd.conf b/tests/topotests/bgp_color_extcommunities/r2/bgpd.conf new file mode 100644 index 0000000000..2f83ada9d3 --- /dev/null +++ b/tests/topotests/bgp_color_extcommunities/r2/bgpd.conf @@ -0,0 +1,4 @@ +router bgp 65002 + bgp router-id 192.168.1.2 + no bgp ebgp-requires-policy + neighbor 192.168.1.1 remote-as external diff --git a/tests/topotests/bgp_color_extcommunities/r2/zebra.conf b/tests/topotests/bgp_color_extcommunities/r2/zebra.conf new file mode 100644 index 0000000000..cffe827363 --- /dev/null +++ b/tests/topotests/bgp_color_extcommunities/r2/zebra.conf @@ -0,0 +1,4 @@ +! +int r2-eth0 + ip address 192.168.1.2/24 +! diff --git a/tests/topotests/bgp_color_extcommunities/test_bgp_color_extcommunities.py b/tests/topotests/bgp_color_extcommunities/test_bgp_color_extcommunities.py new file mode 100644 index 0000000000..6d17cdb4d9 --- /dev/null +++ b/tests/topotests/bgp_color_extcommunities/test_bgp_color_extcommunities.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# Copyright 2022 6WIND S.A. +# Copyright 2023 6WIND S.A. +# François Dumontet <francois.dumontet@6wind.com> +# + + +""" +test_bgp_color_extcommunity.py: Test the FRR BGP color extented +community feature +""" + +import os +import sys +import json +import functools +from functools import partial +import pytest + +# Save the Current Working Directory to find configuration files. +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +# Import topogen and topotest helpers +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger + +pytestmark = [pytest.mark.bgpd] + + +def build_topo(tgen): + "Build function" + + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + +def setup_module(mod): + "Sets up the pytest environment" + + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + logger.info("setup_module") + + router_list = tgen.routers() + + for rname, router in router_list.items(): + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) + ) + + # Initialize all routers. + tgen.start_router() + + +def teardown_module(_mod): + "Teardown the pytest environment" + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_color_extended_communities(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + r2 = tgen.gears["r2"] + + def _bgp_converge(): + output = json.loads(r1.vtysh_cmd("show bgp summary json")) + expected = { + "ipv4Unicast": { + "peers": { + "192.168.1.2": { + "pfxSnt": 1, + "state": "Established", + }, + } + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_converge) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Failed announcing 10.10.10.10/32 to r2" + + def _bgp_check_route(router, exists): + output = json.loads(router.vtysh_cmd("show bgp ipv4 unicast 10.10.10.10 json")) + if exists: + expected = { + "prefix": "10.10.10.0/24", + "paths": [ + { + "valid": True, + "extendedCommunity": { + "string": "RT:80:987 Color:100 Color:200 Color:55555" + }, + } + ], + } + else: + expected = {} + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_check_route, r2, True) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "10.10.10.0/24 ext community is correctly not installed, but SHOULD be" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_comm_list_match/r1/bgpd.conf b/tests/topotests/bgp_comm_list_match/r1/bgpd.conf index 89c9f7728e..bac8412088 100644 --- a/tests/topotests/bgp_comm_list_match/r1/bgpd.conf +++ b/tests/topotests/bgp_comm_list_match/r1/bgpd.conf @@ -11,6 +11,7 @@ router bgp 65001 ! ip prefix-list p1 seq 5 permit 172.16.255.1/32 ip prefix-list p3 seq 5 permit 172.16.255.3/32 +ip prefix-list p4 seq 5 permit 172.16.255.4/32 ! route-map r2 permit 10 match ip address prefix-list p1 @@ -19,5 +20,9 @@ route-map r2 permit 20 match ip address prefix-list p3 set community 65001:3 route-map r2 permit 30 + match ip address prefix-list p4 + set community 65001:10 65001:12 65001:13 +exit +route-map r2 permit 40 exit ! diff --git a/tests/topotests/bgp_comm_list_match/r1/zebra.conf b/tests/topotests/bgp_comm_list_match/r1/zebra.conf index 17d0ecceaf..4219a7ca3a 100644 --- a/tests/topotests/bgp_comm_list_match/r1/zebra.conf +++ b/tests/topotests/bgp_comm_list_match/r1/zebra.conf @@ -3,6 +3,7 @@ interface lo ip address 172.16.255.1/32 ip address 172.16.255.2/32 ip address 172.16.255.3/32 + ip address 172.16.255.4/32 ! interface r1-eth0 ip address 192.168.0.1/24 diff --git a/tests/topotests/bgp_comm_list_match/r2/bgpd.conf b/tests/topotests/bgp_comm_list_match/r2/bgpd.conf index 98a9780688..cb2f89e5c5 100644 --- a/tests/topotests/bgp_comm_list_match/r2/bgpd.conf +++ b/tests/topotests/bgp_comm_list_match/r2/bgpd.conf @@ -6,6 +6,9 @@ router bgp 65002 neighbor 192.168.0.1 remote-as external neighbor 192.168.0.1 timers 1 3 neighbor 192.168.0.1 timers connect 1 + neighbor 192.168.1.3 remote-as external + neighbor 192.168.1.3 timers 1 3 + neighbor 192.168.1.3 timers connect 1 address-family ipv4 neighbor 192.168.0.1 route-map r1 in neighbor 192.168.0.1 soft-reconfiguration inbound diff --git a/tests/topotests/bgp_comm_list_match/r2/zebra.conf b/tests/topotests/bgp_comm_list_match/r2/zebra.conf index a69c622352..7fe82bac8f 100644 --- a/tests/topotests/bgp_comm_list_match/r2/zebra.conf +++ b/tests/topotests/bgp_comm_list_match/r2/zebra.conf @@ -2,5 +2,8 @@ interface r2-eth0 ip address 192.168.0.2/24 ! +interface r2-eth1 + ip address 192.168.1.2/24 +! ip forwarding ! diff --git a/tests/topotests/bgp_comm_list_match/r3/bgpd.conf b/tests/topotests/bgp_comm_list_match/r3/bgpd.conf new file mode 100644 index 0000000000..e68a3e44e0 --- /dev/null +++ b/tests/topotests/bgp_comm_list_match/r3/bgpd.conf @@ -0,0 +1,21 @@ +! +!debug bgp updates +! +router bgp 65003 + no bgp ebgp-requires-policy + neighbor 192.168.1.2 remote-as external + neighbor 192.168.1.2 timers 1 3 + neighbor 192.168.1.2 timers connect 1 + address-family ipv4 + neighbor 192.168.1.2 route-map r1 in + neighbor 192.168.1.2 soft-reconfiguration inbound + exit-address-family +! +bgp community-list 2 seq 10 permit 65001:12 +! +route-map r1 deny 10 + match community 2 any +exit +route-map r1 permit 20 +exit +! diff --git a/tests/topotests/bgp_comm_list_match/r3/zebra.conf b/tests/topotests/bgp_comm_list_match/r3/zebra.conf new file mode 100644 index 0000000000..755dd18bfe --- /dev/null +++ b/tests/topotests/bgp_comm_list_match/r3/zebra.conf @@ -0,0 +1,6 @@ +! +interface r3-eth0 + ip address 192.168.1.3/24 +! +ip forwarding +! diff --git a/tests/topotests/bgp_comm_list_match/test_bgp_comm_list_match.py b/tests/topotests/bgp_comm_list_match/test_bgp_comm_list_match.py index 03fa8da9d4..de69ea9387 100644 --- a/tests/topotests/bgp_comm_list_match/test_bgp_comm_list_match.py +++ b/tests/topotests/bgp_comm_list_match/test_bgp_comm_list_match.py @@ -39,12 +39,15 @@ def build_topo(tgen): - for routern in range(1, 3): + for routern in range(1, 4): tgen.add_router("r{}".format(routern)) switch = tgen.add_switch("s1") switch.add_link(tgen.gears["r1"]) switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r2"]) def setup_module(mod): @@ -95,12 +98,41 @@ def _bgp_converge(): } return topotest.json_cmp(output, expected) - step("Initial BGP converge") + step("Initial BGP converge between R1 and R2") test_func = functools.partial(_bgp_converge) _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) assert result is None, "Failed to filter BGP UPDATES with community-list on R2" +def test_bgp_comm_list_match_any(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears["r3"] + + def _bgp_converge(): + output = json.loads( + router.vtysh_cmd( + "show bgp ipv4 unicast neighbors 192.168.1.2 filtered-routes json" + ) + ) + expected = { + "receivedRoutes": { + "172.16.255.4/32": { + "path": "65002 65001", + }, + } + } + return topotest.json_cmp(output, expected) + + step("Initial BGP converge between R3 and R2") + test_func = functools.partial(_bgp_converge) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to filter BGP UPDATES with community-list on R3" + + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_conditional_advertisement_static_route/__init__.py b/tests/topotests/bgp_conditional_advertisement_static_route/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/bgp_conditional_advertisement_static_route/r1/frr.conf b/tests/topotests/bgp_conditional_advertisement_static_route/r1/frr.conf new file mode 100644 index 0000000000..3e51337eee --- /dev/null +++ b/tests/topotests/bgp_conditional_advertisement_static_route/r1/frr.conf @@ -0,0 +1,10 @@ +! +int r1-eth0 + ip address 192.168.1.1/24 +! +router bgp 65000 + no bgp ebgp-requires-policy + neighbor 192.168.1.2 remote-as internal + neighbor 192.168.1.2 timers 1 3 + neighbor 192.168.1.2 timers connect 1 +! diff --git a/tests/topotests/bgp_conditional_advertisement_static_route/r2/frr.conf b/tests/topotests/bgp_conditional_advertisement_static_route/r2/frr.conf new file mode 100644 index 0000000000..3ced9340ca --- /dev/null +++ b/tests/topotests/bgp_conditional_advertisement_static_route/r2/frr.conf @@ -0,0 +1,40 @@ +! +!debug bgp conditional-advertisement +!debug bgp updates +! +int r2-eth0 + ip address 192.168.1.2/24 +! +int r2-eth1 + ip address 192.168.2.2/24 +! +router bgp 65000 + no bgp ebgp-requires-policy + bgp conditional-advertisement timer 5 + neighbor 192.168.1.1 remote-as internal + neighbor 192.168.1.1 timers 1 3 + neighbor 192.168.1.1 timers connect 1 + neighbor 192.168.2.1 remote-as internal + neighbor 192.168.2.1 timers 1 3 + neighbor 192.168.2.1 timers connect 1 + address-family ipv4 unicast + redistribute static + neighbor 192.168.1.1 advertise-map advertise-map exist-map exist-map + neighbor 192.168.1.1 route-map deny-all out + exit-address-family +! +ip route 10.10.10.1/32 r2-eth0 +ip route 10.10.10.2/32 r2-eth0 +! +ip prefix-list default seq 5 permit 0.0.0.0/0 +ip prefix-list advertise seq 5 permit 10.10.10.1/32 +! +route-map deny-all deny 10 +! +route-map exist-map permit 10 + match ip address prefix-list default +! +route-map advertise-map permit 10 + match ip address prefix-list advertise + set community 65000:1 +! diff --git a/tests/topotests/bgp_conditional_advertisement_static_route/r3/frr.conf b/tests/topotests/bgp_conditional_advertisement_static_route/r3/frr.conf new file mode 100644 index 0000000000..a24a2cb04e --- /dev/null +++ b/tests/topotests/bgp_conditional_advertisement_static_route/r3/frr.conf @@ -0,0 +1,19 @@ +! +int lo + ip address 10.10.10.1/32 + ip address 10.10.10.2/32 +! +int r3-eth0 + ip address 192.168.2.1/24 +! +router bgp 65000 + no bgp ebgp-requires-policy + no bgp network import-check + neighbor 192.168.2.2 remote-as internal + neighbor 192.168.2.2 timers 1 3 + neighbor 192.168.2.2 timers connect 1 + ! + address-family ipv4 unicast + neighbor 192.168.2.2 default-originate + exit-address-family +! diff --git a/tests/topotests/bgp_conditional_advertisement_static_route/test_bgp_conditional_advertisement_static_route.py b/tests/topotests/bgp_conditional_advertisement_static_route/test_bgp_conditional_advertisement_static_route.py new file mode 100644 index 0000000000..4180bfcdf6 --- /dev/null +++ b/tests/topotests/bgp_conditional_advertisement_static_route/test_bgp_conditional_advertisement_static_route.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# Copyright (c) 2023 by +# Donatas Abraitis <donatas@opensourcerouting.org> +# + +""" +Test if static route with BGP conditional advertisement works correctly +if we modify the prefix-lists. +""" + +import os +import re +import sys +import json +import pytest +import functools + +pytestmark = pytest.mark.bgpd + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.common_config import step + +pytestmark = [pytest.mark.bgpd] + + +def setup_module(mod): + topodef = {"s1": ("r1", "r2"), "s2": ("r2", "r3")} + tgen = Topogen(topodef, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for _, (rname, router) in enumerate(router_list.items(), 1): + router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname))) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_conditional_advertisements_static_route(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + r2 = tgen.gears["r2"] + + def _bgp_converge(): + output = json.loads( + r2.vtysh_cmd( + "show bgp ipv4 unicast neighbor 192.168.1.1 advertised-routes json" + ) + ) + expected = { + "advertisedRoutes": { + "10.10.10.1/32": { + "valid": True, + } + }, + "totalPrefixCounter": 1, + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_converge, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Can't converge" + + step("Append prefix-list to advertise 10.10.10.2/32") + + r2.vtysh_cmd( + """ + configure terminal + ip prefix-list advertise seq 10 permit 10.10.10.2/32 + """ + ) + + def _bgp_check_advertised_after_update(): + output = json.loads( + r2.vtysh_cmd( + "show bgp ipv4 unicast neighbor 192.168.1.1 advertised-routes json" + ) + ) + expected = { + "advertisedRoutes": { + "10.10.10.1/32": { + "valid": True, + }, + "10.10.10.2/32": { + "valid": True, + }, + }, + "totalPrefixCounter": 2, + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_check_advertised_after_update, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "10.10.10.2/32 is not advertised after prefix-list update" + + def _bgp_check_received_routes(): + output = json.loads(r1.vtysh_cmd("show bgp ipv4 unicast 10.10.10.1/32 json")) + expected = { + "paths": [ + { + "community": { + "string": "65000:1", + } + } + ] + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_check_received_routes, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "10.10.10.1/32 does not have 65000:1 community attached" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_default_originate_timer/__init__.py b/tests/topotests/bgp_default_originate_timer/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/bgp_default_originate_timer/r1/bgpd.conf b/tests/topotests/bgp_default_originate_timer/r1/bgpd.conf new file mode 100644 index 0000000000..f2a1c9005a --- /dev/null +++ b/tests/topotests/bgp_default_originate_timer/r1/bgpd.conf @@ -0,0 +1,18 @@ +router bgp 65001 + no bgp ebgp-requires-policy + bgp default-originate timer 3600 + neighbor 192.168.1.2 remote-as external + neighbor 192.168.1.2 timers 1 3 + neighbor 192.168.1.2 timers connect 1 + neighbor 192.168.2.2 remote-as external + neighbor 192.168.2.2 timers 1 3 + neighbor 192.168.2.2 timers connect 1 + address-family ipv4 + neighbor 192.168.1.2 default-originate route-map default + exit-address-family +! +bgp community-list standard r3 seq 5 permit 65003:1 +! +route-map default permit 10 + match community r3 +exit diff --git a/tests/topotests/bgp_default_originate_timer/r1/zebra.conf b/tests/topotests/bgp_default_originate_timer/r1/zebra.conf new file mode 100644 index 0000000000..3692361fb3 --- /dev/null +++ b/tests/topotests/bgp_default_originate_timer/r1/zebra.conf @@ -0,0 +1,7 @@ +! +interface r1-eth0 + ip address 192.168.1.1/24 +! +interface r1-eth1 + ip address 192.168.2.1/24 +! diff --git a/tests/topotests/bgp_default_originate_timer/r2/bgpd.conf b/tests/topotests/bgp_default_originate_timer/r2/bgpd.conf new file mode 100644 index 0000000000..7ca65a94a1 --- /dev/null +++ b/tests/topotests/bgp_default_originate_timer/r2/bgpd.conf @@ -0,0 +1,6 @@ +router bgp 65002 + no bgp ebgp-requires-policy + neighbor 192.168.1.1 remote-as external + neighbor 192.168.1.1 timers 1 3 + neighbor 192.168.1.1 timers connect 1 +! diff --git a/tests/topotests/bgp_default_originate_timer/r2/zebra.conf b/tests/topotests/bgp_default_originate_timer/r2/zebra.conf new file mode 100644 index 0000000000..0c95656663 --- /dev/null +++ b/tests/topotests/bgp_default_originate_timer/r2/zebra.conf @@ -0,0 +1,4 @@ +! +interface r2-eth0 + ip address 192.168.1.2/24 +! diff --git a/tests/topotests/bgp_default_originate_timer/r3/bgpd.conf b/tests/topotests/bgp_default_originate_timer/r3/bgpd.conf new file mode 100644 index 0000000000..0a37913d73 --- /dev/null +++ b/tests/topotests/bgp_default_originate_timer/r3/bgpd.conf @@ -0,0 +1,12 @@ +router bgp 65003 + no bgp ebgp-requires-policy + neighbor 192.168.2.1 remote-as external + neighbor 192.168.2.1 timers 1 3 + neighbor 192.168.2.1 timers connect 1 + address-family ipv4 unicast + redistribute connected route-map r1 + exit-address-family +! +route-map r1 permit 10 + set community 65003:1 +exit diff --git a/tests/topotests/bgp_default_originate_timer/r3/zebra.conf b/tests/topotests/bgp_default_originate_timer/r3/zebra.conf new file mode 100644 index 0000000000..20801f937e --- /dev/null +++ b/tests/topotests/bgp_default_originate_timer/r3/zebra.conf @@ -0,0 +1,7 @@ +! +interface lo + ip address 10.10.10.10/32 +! +interface r3-eth0 + ip address 192.168.2.2/24 +! diff --git a/tests/topotests/bgp_default_originate_timer/test_bgp_default_originate_timer.py b/tests/topotests/bgp_default_originate_timer/test_bgp_default_originate_timer.py new file mode 100644 index 0000000000..b2ba936fb1 --- /dev/null +++ b/tests/topotests/bgp_default_originate_timer/test_bgp_default_originate_timer.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# +# Copyright (c) 2023 by +# Donatas Abraitis <donatas@opensourcerouting.org> +# + +""" +Check if `bgp default-originate timer` commands takes an effect: +1. Set bgp default-originate timer 3600 +2. No default route is advertised because the timer is running for 3600 seconds +3. We reduce it to 10 seconds +4. Default route is advertised +""" + +import os +import sys +import json +import pytest +import functools + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.common_config import step + +pytestmark = [pytest.mark.bgpd] + + +def build_topo(tgen): + for routern in range(1, 4): + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r3"]) + + +def setup_module(mod): + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for i, (rname, router) in enumerate(router_list.items(), 1): + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) + ) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_default_originate_timer(): + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + r2 = tgen.gears["r2"] + r3 = tgen.gears["r3"] + + def _bgp_default_received_from_r1(): + output = json.loads(r2.vtysh_cmd("show bgp ipv4 unicast 0.0.0.0/0 json")) + expected = { + "paths": [ + { + "nexthops": [ + { + "hostname": "r1", + "ip": "192.168.1.1", + } + ], + } + ], + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_default_received_from_r1) + _, result = topotest.run_and_expect(test_func, not None, count=30, wait=1) + assert result is not None, "Seen default route received from r1, but should not" + + step("Set BGP default-originate timer to 10 seconds") + r1.vtysh_cmd( + """ + configure terminal + router bgp + bgp default-originate timer 10 + """ + ) + + step("Trigger BGP UPDATE from r3") + r3.vtysh_cmd( + """ + configure terminal + route-map r1 permit 10 + set metric 1 + """ + ) + + test_func = functools.partial(_bgp_default_received_from_r1) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assert result is None, "Did not see default route received from r1, but should" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_default_route/r1/bgpd.conf b/tests/topotests/bgp_default_route/r1/bgpd.conf index 8699d62ff2..10ced3610a 100644 --- a/tests/topotests/bgp_default_route/r1/bgpd.conf +++ b/tests/topotests/bgp_default_route/r1/bgpd.conf @@ -3,6 +3,7 @@ router bgp 65000 neighbor 192.168.255.2 remote-as 65001 neighbor 192.168.255.2 timers 3 10 address-family ipv4 unicast + network 0.0.0.0/1 neighbor 192.168.255.2 default-originate exit-address-family ! diff --git a/tests/topotests/bgp_default_route/r1/zebra.conf b/tests/topotests/bgp_default_route/r1/zebra.conf index 0a283c06d5..fbf97b0520 100644 --- a/tests/topotests/bgp_default_route/r1/zebra.conf +++ b/tests/topotests/bgp_default_route/r1/zebra.conf @@ -1,4 +1,6 @@ ! +ip route 0.0.0.0/1 blackhole +! interface lo ip address 172.16.255.254/32 ! diff --git a/tests/topotests/bgp_default_route/test_bgp_default-originate.py b/tests/topotests/bgp_default_route/test_bgp_default-originate.py index 2463b05469..333beb067c 100644 --- a/tests/topotests/bgp_default_route/test_bgp_default-originate.py +++ b/tests/topotests/bgp_default_route/test_bgp_default-originate.py @@ -69,18 +69,18 @@ def _bgp_check_if_received(): expected = { "192.168.255.1": { "bgpState": "Established", - "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 1}}, + "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 2}}, } } return topotest.json_cmp(output, expected) def _bgp_check_if_originated(): output = json.loads(tgen.gears["r1"].vtysh_cmd("show ip bgp summary json")) - expected = {"ipv4Unicast": {"peers": {"192.168.255.2": {"pfxSnt": 1}}}} + expected = {"ipv4Unicast": {"peers": {"192.168.255.2": {"pfxSnt": 2}}}} return topotest.json_cmp(output, expected) - def _bgp_default_route_is_valid(router): - output = json.loads(router.vtysh_cmd("show ip bgp 0.0.0.0/0 json")) + def _bgp_route_is_valid(router, prefix): + output = json.loads(router.vtysh_cmd("show ip bgp {} json".format(prefix))) expected = {"paths": [{"valid": True}]} return topotest.json_cmp(output, expected) @@ -92,10 +92,14 @@ def _bgp_default_route_is_valid(router): success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) assert result is None, "No 0.0.0.0/0 from r1 to r2" - test_func = functools.partial(_bgp_default_route_is_valid, tgen.gears["r2"]) + test_func = functools.partial(_bgp_route_is_valid, tgen.gears["r2"], "0.0.0.0/0") success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) assert result is None, "Failed to see 0.0.0.0/0 in r2" + test_func = functools.partial(_bgp_route_is_valid, tgen.gears["r2"], "0.0.0.0/1") + success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + assert result is None, "Failed to see 0.0.0.0/1 in r2" + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] diff --git a/tests/topotests/bgp_default_route_route_map_set/r1/bgpd.conf b/tests/topotests/bgp_default_route_route_map_set/r1/bgpd.conf index 6f6d394402..c442e06a63 100644 --- a/tests/topotests/bgp_default_route_route_map_set/r1/bgpd.conf +++ b/tests/topotests/bgp_default_route_route_map_set/r1/bgpd.conf @@ -1,12 +1,17 @@ -router bgp 65000 - no bgp ebgp-requires-policy - neighbor 192.168.255.2 remote-as 65001 - neighbor 192.168.255.2 timers 3 10 - address-family ipv4 unicast - neighbor 192.168.255.2 default-originate route-map default - exit-address-family +router bgp 65001 + no bgp ebgp-requires-policy + neighbor 192.168.255.2 remote-as external + neighbor 192.168.255.2 timers 3 10 + neighbor PG peer-group + neighbor PG remote-as external + neighbor PG timers 3 10 + bgp listen range 192.168.255.0/24 peer-group PG + address-family ipv4 unicast + neighbor PG default-originate route-map default + neighbor 192.168.255.2 default-originate route-map default + exit-address-family ! route-map default permit 10 - set metric 123 - set as-path prepend 65000 65000 65000 + set metric 123 + set as-path prepend 65001 65001 65001 ! diff --git a/tests/topotests/bgp_default_route_route_map_set/r1/zebra.conf b/tests/topotests/bgp_default_route_route_map_set/r1/zebra.conf index 0a283c06d5..4af88e523c 100644 --- a/tests/topotests/bgp_default_route_route_map_set/r1/zebra.conf +++ b/tests/topotests/bgp_default_route_route_map_set/r1/zebra.conf @@ -5,5 +5,3 @@ interface lo interface r1-eth0 ip address 192.168.255.1/24 ! -ip forwarding -! diff --git a/tests/topotests/bgp_default_route_route_map_set/r2/bgpd.conf b/tests/topotests/bgp_default_route_route_map_set/r2/bgpd.conf index 00c96cc58b..3a18a11386 100644 --- a/tests/topotests/bgp_default_route_route_map_set/r2/bgpd.conf +++ b/tests/topotests/bgp_default_route_route_map_set/r2/bgpd.conf @@ -1,8 +1,8 @@ -router bgp 65001 - no bgp ebgp-requires-policy - neighbor 192.168.255.1 remote-as 65000 - neighbor 192.168.255.1 timers 3 10 - address-family ipv4 unicast - redistribute connected - exit-address-family +router bgp 65002 + no bgp ebgp-requires-policy + neighbor 192.168.255.1 remote-as external + neighbor 192.168.255.1 timers 3 10 + address-family ipv4 unicast + redistribute connected + exit-address-family ! diff --git a/tests/topotests/bgp_default_route_route_map_set/r2/zebra.conf b/tests/topotests/bgp_default_route_route_map_set/r2/zebra.conf index 606c17bec9..c03dd7e197 100644 --- a/tests/topotests/bgp_default_route_route_map_set/r2/zebra.conf +++ b/tests/topotests/bgp_default_route_route_map_set/r2/zebra.conf @@ -2,5 +2,3 @@ interface r2-eth0 ip address 192.168.255.2/24 ! -ip forwarding -! diff --git a/tests/topotests/bgp_default_route_route_map_set/r3/bgpd.conf b/tests/topotests/bgp_default_route_route_map_set/r3/bgpd.conf new file mode 100644 index 0000000000..c477037e34 --- /dev/null +++ b/tests/topotests/bgp_default_route_route_map_set/r3/bgpd.conf @@ -0,0 +1,8 @@ +router bgp 65003 + no bgp ebgp-requires-policy + neighbor 192.168.255.1 remote-as external + neighbor 192.168.255.1 timers 3 10 + address-family ipv4 unicast + redistribute connected + exit-address-family +! diff --git a/tests/topotests/bgp_default_route_route_map_set/r3/zebra.conf b/tests/topotests/bgp_default_route_route_map_set/r3/zebra.conf new file mode 100644 index 0000000000..5ae9daf077 --- /dev/null +++ b/tests/topotests/bgp_default_route_route_map_set/r3/zebra.conf @@ -0,0 +1,4 @@ +! +interface r3-eth0 + ip address 192.168.255.3/24 +! diff --git a/tests/topotests/bgp_default_route_route_map_set/test_bgp_default-originate_route-map_set.py b/tests/topotests/bgp_default_route_route_map_set/test_bgp_default-originate_route-map_set.py index 3bd900bda0..e633b61d1b 100644 --- a/tests/topotests/bgp_default_route_route_map_set/test_bgp_default-originate_route-map_set.py +++ b/tests/topotests/bgp_default_route_route_map_set/test_bgp_default-originate_route-map_set.py @@ -26,12 +26,13 @@ def build_topo(tgen): - for routern in range(1, 3): + for routern in range(1, 4): tgen.add_router("r{}".format(routern)) switch = tgen.add_switch("s1") switch.add_link(tgen.gears["r1"]) switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) def setup_module(mod): @@ -62,14 +63,17 @@ def test_bgp_default_originate_route_map(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - router = tgen.gears["r2"] + r2 = tgen.gears["r2"] + r3 = tgen.gears["r3"] - def _bgp_converge(router): + def _bgp_converge(router, pfxCount): output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) expected = { "192.168.255.1": { "bgpState": "Established", - "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 1}}, + "addressFamilyInfo": { + "ipv4Unicast": {"acceptedPrefixCounter": pfxCount} + }, } } return topotest.json_cmp(output, expected) @@ -77,21 +81,25 @@ def _bgp_converge(router): def _bgp_default_route_has_metric(router): output = json.loads(router.vtysh_cmd("show ip bgp 0.0.0.0/0 json")) expected = { - "paths": [{"aspath": {"string": "65000 65000 65000 65000"}, "metric": 123}] + "paths": [{"aspath": {"string": "65001 65001 65001 65001"}, "metric": 123}] } return topotest.json_cmp(output, expected) - test_func = functools.partial(_bgp_converge, router) - success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + test_func = functools.partial(_bgp_converge, r2, 1) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Failed to see bgp convergence in r2" - assert result is None, 'Failed to see bgp convergence in "{}"'.format(router) + test_func = functools.partial(_bgp_default_route_has_metric, r2) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Failed to see applied metric for default route in r2" - test_func = functools.partial(_bgp_default_route_has_metric, router) - success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + test_func = functools.partial(_bgp_converge, r3, 2) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Failed to see bgp convergence in r3" - assert ( - result is None - ), 'Failed to see applied metric for default route in "{}"'.format(router) + test_func = functools.partial(_bgp_default_route_has_metric, r3) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Failed to see applied metric for default route in r3" if __name__ == "__main__": diff --git a/tests/topotests/bgp_dynamic_capability/__init__.py b/tests/topotests/bgp_dynamic_capability/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/bgp_dynamic_capability/r1/frr.conf b/tests/topotests/bgp_dynamic_capability/r1/frr.conf new file mode 100644 index 0000000000..aa5c3db9a6 --- /dev/null +++ b/tests/topotests/bgp_dynamic_capability/r1/frr.conf @@ -0,0 +1,21 @@ +! +!debug bgp neighbor +! +int r1-eth0 + ip address 192.168.1.1/24 +! +router bgp 65001 + no bgp ebgp-requires-policy + bgp graceful-restart + bgp long-lived stale-time 10 + neighbor 192.168.1.2 remote-as external + neighbor 192.168.1.2 timers 1 3 + neighbor 192.168.1.2 timers connect 1 + neighbor 192.168.1.2 capability dynamic + ! + address-family ipv4 unicast + neighbor 192.168.1.2 addpath-tx-all-paths + exit-address-family +! +ip prefix-list r2 seq 5 permit 10.10.10.10/32 +! diff --git a/tests/topotests/bgp_dynamic_capability/r2/frr.conf b/tests/topotests/bgp_dynamic_capability/r2/frr.conf new file mode 100644 index 0000000000..7f25665ed5 --- /dev/null +++ b/tests/topotests/bgp_dynamic_capability/r2/frr.conf @@ -0,0 +1,23 @@ +! +!debug bgp neighbor +! +int lo + ip address 10.10.10.10/32 + ip address 10.10.10.20/32 +! +int r2-eth0 + ip address 192.168.1.2/24 +! +router bgp 65002 + bgp graceful-restart + bgp long-lived stale-time 20 + no bgp ebgp-requires-policy + neighbor 192.168.1.1 remote-as external + neighbor 192.168.1.1 timers 1 3 + neighbor 192.168.1.1 timers connect 1 + neighbor 192.168.1.1 capability dynamic + ! + address-family ipv4 unicast + redistribute connected + exit-address-family +! diff --git a/tests/topotests/bgp_dynamic_capability/test_bgp_dynamic_capability_addpath.py b/tests/topotests/bgp_dynamic_capability/test_bgp_dynamic_capability_addpath.py new file mode 100644 index 0000000000..f83ee2971c --- /dev/null +++ b/tests/topotests/bgp_dynamic_capability/test_bgp_dynamic_capability_addpath.py @@ -0,0 +1,180 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# Copyright (c) 2023 by +# Donatas Abraitis <donatas@opensourcerouting.org> +# + +""" +Test if Addpath capability is adjusted dynamically. +""" + +import os +import re +import sys +import json +import pytest +import functools + +pytestmark = pytest.mark.bgpd + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.common_config import step + +pytestmark = [pytest.mark.bgpd] + + +def setup_module(mod): + topodef = {"s1": ("r1", "r2")} + tgen = Topogen(topodef, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for _, (rname, router) in enumerate(router_list.items(), 1): + router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname))) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_dynamic_capability_addpath(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + r2 = tgen.gears["r2"] + + def _bgp_converge(): + output = json.loads(r1.vtysh_cmd("show bgp neighbor json")) + expected = { + "192.168.1.2": { + "bgpState": "Established", + "neighborCapabilities": { + "dynamic": "advertisedAndReceived", + "addPath": { + "ipv4Unicast": { + "txAdvertised": True, + "rxAdvertisedAndReceived": True, + } + }, + }, + "addressFamilyInfo": { + "ipv4Unicast": { + "acceptedPrefixCounter": 3, + } + }, + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_converge, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Can't converge" + + step("Enable Addpath capability and check if it's exchanged dynamically") + + # Clear message stats to check if we receive a notification or not after we + # change the settings fo LLGR. + r1.vtysh_cmd("clear bgp 192.168.1.2 message-stats") + r2.vtysh_cmd( + """ + configure terminal + router bgp + address-family ipv4 unicast + neighbor 192.168.1.1 addpath-tx-all-paths + """ + ) + + def _bgp_check_if_addpath_rx_tx_and_session_not_reset(): + output = json.loads(r1.vtysh_cmd("show bgp neighbor json")) + expected = { + "192.168.1.2": { + "bgpState": "Established", + "neighborCapabilities": { + "dynamic": "advertisedAndReceived", + "addPath": { + "ipv4Unicast": { + "txAdvertisedAndReceived": True, + "rxAdvertisedAndReceived": True, + } + }, + }, + "addressFamilyInfo": { + "ipv4Unicast": { + "acceptedPrefixCounter": 3, + } + }, + "messageStats": { + "notificationsRecv": 0, + "capabilityRecv": 1, + }, + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_check_if_addpath_rx_tx_and_session_not_reset, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Session was reset after enabling Addpath capability" + + step("Disable Addpath capability RX and check if it's exchanged dynamically") + + # Clear message stats to check if we receive a notification or not after we + # change the settings fo LLGR. + r1.vtysh_cmd("clear bgp 192.168.1.2 message-stats") + r2.vtysh_cmd( + """ + configure terminal + router bgp + address-family ipv4 unicast + neighbor 192.168.1.1 disable-addpath-rx + """ + ) + + def _bgp_check_if_addpath_tx_and_session_not_reset(): + output = json.loads(r1.vtysh_cmd("show bgp neighbor json")) + expected = { + "192.168.1.2": { + "bgpState": "Established", + "neighborCapabilities": { + "dynamic": "advertisedAndReceived", + "addPath": { + "ipv4Unicast": { + "txAdvertisedAndReceived": True, + "rxAdvertised": True, + } + }, + }, + "messageStats": { + "notificationsRecv": 0, + "capabilityRecv": 1, + }, + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_check_if_addpath_tx_and_session_not_reset, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Session was reset after disabling Addpath RX flags" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_dynamic_capability/test_bgp_dynamic_capability_graceful_restart.py b/tests/topotests/bgp_dynamic_capability/test_bgp_dynamic_capability_graceful_restart.py new file mode 100644 index 0000000000..b7e2090eee --- /dev/null +++ b/tests/topotests/bgp_dynamic_capability/test_bgp_dynamic_capability_graceful_restart.py @@ -0,0 +1,213 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# Copyright (c) 2023 by +# Donatas Abraitis <donatas@opensourcerouting.org> +# + +""" +Test if BGP graceful restart / long-lived graceful restart capabilities +(restart time, stale time and notification flag) are exchanged dynamically +via BGP dynamic capability. +""" + +import os +import re +import sys +import json +import pytest +import functools + +pytestmark = pytest.mark.bgpd + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.common_config import step + +pytestmark = [pytest.mark.bgpd] + + +def setup_module(mod): + topodef = {"s1": ("r1", "r2")} + tgen = Topogen(topodef, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for _, (rname, router) in enumerate(router_list.items(), 1): + router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname))) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_dynamic_capability_graceful_restart(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + r2 = tgen.gears["r2"] + + def _bgp_converge(): + output = json.loads(r1.vtysh_cmd("show bgp neighbor json")) + expected = { + "192.168.1.2": { + "bgpState": "Established", + "neighborCapabilities": { + "dynamic": "advertisedAndReceived", + "gracefulRestart": "advertisedAndReceived", + "longLivedGracefulRestart": "advertisedAndReceived", + }, + "addressFamilyInfo": { + "ipv4Unicast": { + "acceptedPrefixCounter": 3, + } + }, + "gracefulRestartInfo": { + "nBit": True, + "timers": { + "receivedRestartTimer": 120, + "configuredLlgrStaleTime": 10, + }, + "ipv4Unicast": { + "timers": { + "llgrStaleTime": 10, + } + }, + }, + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_converge, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Can't converge" + + step( + "Change Graceful-Restart restart-time, LLGR stale-time and check if they changed dynamically" + ) + + # Clear message stats to check if we receive a notification or not after we + # change the settings fo LLGR. + r1.vtysh_cmd("clear bgp 192.168.1.2 message-stats") + r2.vtysh_cmd( + """ + configure terminal + router bgp + bgp graceful-restart restart-time 123 + bgp long-lived-graceful-restart stale-time 5 + """ + ) + + def _bgp_check_if_session_not_reset_after_changing_gr_settings(): + output = json.loads(r1.vtysh_cmd("show bgp neighbor json")) + expected = { + "192.168.1.2": { + "bgpState": "Established", + "neighborCapabilities": { + "dynamic": "advertisedAndReceived", + "gracefulRestart": "advertisedAndReceived", + "longLivedGracefulRestart": "advertisedAndReceived", + }, + "addressFamilyInfo": { + "ipv4Unicast": { + "acceptedPrefixCounter": 3, + } + }, + "gracefulRestartInfo": { + "nBit": True, + "timers": { + "receivedRestartTimer": 123, + "configuredLlgrStaleTime": 10, + }, + "ipv4Unicast": { + "timers": { + "llgrStaleTime": 5, + } + }, + }, + "messageStats": { + "notificationsRecv": 0, + "capabilityRecv": 2, + }, + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_check_if_session_not_reset_after_changing_gr_settings, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert ( + result is None + ), "Session was reset after changing Graceful-Restart restart-time" + + step( + "Disable Graceful-Restart notification support, and check if it's changed dynamically" + ) + + # Clear message stats to check if we receive a notification or not after we + # change the settings fo LLGR. + r1.vtysh_cmd("clear bgp 192.168.1.2 message-stats") + r2.vtysh_cmd( + """ + configure terminal + router bgp + no bgp graceful-restart notification + """ + ) + + def _bgp_check_if_session_not_reset_after_changing_notification(): + output = json.loads(r1.vtysh_cmd("show bgp neighbor json")) + expected = { + "192.168.1.2": { + "bgpState": "Established", + "neighborCapabilities": { + "dynamic": "advertisedAndReceived", + "gracefulRestart": "advertisedAndReceived", + "longLivedGracefulRestart": "advertisedAndReceived", + }, + "gracefulRestartInfo": { + "nBit": False, + "timers": { + "receivedRestartTimer": 123, + "configuredLlgrStaleTime": 10, + }, + "ipv4Unicast": { + "timers": { + "llgrStaleTime": 5, + } + }, + }, + "messageStats": { + "notificationsRecv": 0, + "capabilityRecv": 1, + }, + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_check_if_session_not_reset_after_changing_notification, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert ( + result is None + ), "Session was reset after changing Graceful-Restart notification support" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_dynamic_capability/test_bgp_dynamic_capability_orf.py b/tests/topotests/bgp_dynamic_capability/test_bgp_dynamic_capability_orf.py new file mode 100644 index 0000000000..f1ad74c05c --- /dev/null +++ b/tests/topotests/bgp_dynamic_capability/test_bgp_dynamic_capability_orf.py @@ -0,0 +1,178 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# Copyright (c) 2023 by +# Donatas Abraitis <donatas@opensourcerouting.org> +# + +""" +Test if ORF capability is adjusted dynamically. +""" + +import os +import re +import sys +import json +import pytest +import functools + +pytestmark = pytest.mark.bgpd + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.common_config import step + +pytestmark = [pytest.mark.bgpd] + + +def setup_module(mod): + topodef = {"s1": ("r1", "r2")} + tgen = Topogen(topodef, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for _, (rname, router) in enumerate(router_list.items(), 1): + router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname))) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_dynamic_capability_orf(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + r2 = tgen.gears["r2"] + + def _bgp_converge(): + output = json.loads(r1.vtysh_cmd("show bgp neighbor json")) + expected = { + "192.168.1.2": { + "bgpState": "Established", + "neighborCapabilities": { + "dynamic": "advertisedAndReceived", + }, + "addressFamilyInfo": { + "ipv4Unicast": { + "acceptedPrefixCounter": 3, + } + }, + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_converge, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Can't converge" + + step( + "Apply incoming prefix-list to r1 and check if we advertise only 10.10.10.20/32 from r2" + ) + + # Clear message stats to check if we receive a notification or not after we + # enable ORF capability. + r1.vtysh_cmd("clear bgp 192.168.1.2 message-stats") + r1.vtysh_cmd( + """ + configure terminal + router bgp + address-family ipv4 unicast + neighbor 192.168.1.2 prefix-list r2 in + neighbor 192.168.1.2 capability orf prefix-list both + """ + ) + + r2.vtysh_cmd( + """ + configure terminal + router bgp + address-family ipv4 unicast + neighbor 192.168.1.1 capability orf prefix-list both + """ + ) + + def _bgp_check_if_session_not_reset(): + output = json.loads(r1.vtysh_cmd("show bgp neighbor json")) + expected = { + "192.168.1.2": { + "bgpState": "Established", + "neighborCapabilities": { + "dynamic": "advertisedAndReceived", + }, + "messageStats": { + "notificationsRecv": 0, + "notificationsSent": 0, + "capabilityRecv": 1, + "capabilitySent": 1, + }, + "addressFamilyInfo": { + "ipv4Unicast": { + "acceptedPrefixCounter": 1, + "afDependentCap": { + "orfPrefixList": { + "sendMode": "advertisedAndReceived", + "recvMode": "advertisedAndReceived", + } + }, + "incomingUpdatePrefixFilterList": "r2", + } + }, + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_check_if_session_not_reset, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Session was reset after setting up ORF capability" + + r1.vtysh_cmd( + """ + configure terminal + ip prefix-list r2 seq 5 permit 10.10.10.20/32 + """ + ) + + def _bgp_check_if_we_send_correct_prefix(): + output = json.loads( + r2.vtysh_cmd( + "show bgp ipv4 unicast neighbors 192.168.1.1 advertised-routes json" + ) + ) + expected = { + "advertisedRoutes": { + "10.10.10.20/32": { + "valid": True, + }, + }, + "totalPrefixCounter": 1, + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_check_if_we_send_correct_prefix, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert ( + result is None + ), "Only 10.10.10.20/32 SHOULD be advertised due to ORF filtering" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_dynamic_capability/test_bgp_dynamic_capability_role.py b/tests/topotests/bgp_dynamic_capability/test_bgp_dynamic_capability_role.py new file mode 100644 index 0000000000..700d4c130d --- /dev/null +++ b/tests/topotests/bgp_dynamic_capability/test_bgp_dynamic_capability_role.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# Copyright (c) 2023 by +# Donatas Abraitis <donatas@opensourcerouting.org> +# + +""" +Test if role capability is exchanged dynamically. +""" + +import os +import re +import sys +import json +import pytest +import functools + +pytestmark = pytest.mark.bgpd + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.common_config import step + +pytestmark = [pytest.mark.bgpd] + + +def setup_module(mod): + topodef = {"s1": ("r1", "r2")} + tgen = Topogen(topodef, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for _, (rname, router) in enumerate(router_list.items(), 1): + router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname))) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_dynamic_capability_role(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + r2 = tgen.gears["r2"] + + def _bgp_converge(): + output = json.loads(r1.vtysh_cmd("show bgp neighbor json")) + expected = { + "192.168.1.2": { + "bgpState": "Established", + "localRole": "undefined", + "remoteRole": "undefined", + "neighborCapabilities": { + "dynamic": "advertisedAndReceived", + }, + "addressFamilyInfo": { + "ipv4Unicast": { + "acceptedPrefixCounter": 3, + } + }, + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_converge, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Can't converge" + + step("Set local-role and check if it's exchanged dynamically") + + # Clear message stats to check if we receive a notification or not after we + # change the settings fo LLGR. + r1.vtysh_cmd("clear bgp 192.168.1.2 message-stats") + r1.vtysh_cmd( + """ + configure terminal + router bgp + neighbor 192.168.1.2 local-role customer + """ + ) + + r2.vtysh_cmd( + """ + configure terminal + router bgp + neighbor 192.168.1.1 local-role provider + """ + ) + + def _bgp_check_if_session_not_reset(): + output = json.loads(r1.vtysh_cmd("show bgp neighbor json")) + expected = { + "192.168.1.2": { + "bgpState": "Established", + "localRole": "customer", + "remoteRole": "provider", + "neighborCapabilities": { + "dynamic": "advertisedAndReceived", + "role": "advertisedAndReceived", + }, + "addressFamilyInfo": { + "ipv4Unicast": { + "acceptedPrefixCounter": 3, + } + }, + "messageStats": { + "notificationsRecv": 0, + "capabilityRecv": 1, + }, + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_check_if_session_not_reset, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Session was reset after setting role capability" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_dynamic_capability/test_bgp_dynamic_capability_software_version.py b/tests/topotests/bgp_dynamic_capability/test_bgp_dynamic_capability_software_version.py new file mode 100644 index 0000000000..11840b4c61 --- /dev/null +++ b/tests/topotests/bgp_dynamic_capability/test_bgp_dynamic_capability_software_version.py @@ -0,0 +1,161 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# Copyright (c) 2023 by +# Donatas Abraitis <donatas@opensourcerouting.org> +# + +""" +Test if software version capability is exchanged dynamically. +""" + +import os +import re +import sys +import json +import pytest +import functools + +pytestmark = pytest.mark.bgpd + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.common_config import step + +pytestmark = [pytest.mark.bgpd] + + +def setup_module(mod): + topodef = {"s1": ("r1", "r2")} + tgen = Topogen(topodef, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for _, (rname, router) in enumerate(router_list.items(), 1): + router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname))) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_dynamic_capability_software_version(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + r2 = tgen.gears["r2"] + + def _bgp_converge(): + output = json.loads(r1.vtysh_cmd("show bgp neighbor json")) + expected = { + "192.168.1.2": { + "bgpState": "Established", + "neighborCapabilities": { + "dynamic": "advertisedAndReceived", + "softwareVersion": { + "advertisedSoftwareVersion": None, + "receivedSoftwareVersion": None, + }, + }, + "addressFamilyInfo": { + "ipv4Unicast": { + "acceptedPrefixCounter": 3, + } + }, + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_converge, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Can't converge" + + step("Enable software version capability and check if it's exchanged dynamically") + + # Clear message stats to check if we receive a notification or not after we + # change the settings fo LLGR. + r1.vtysh_cmd("clear bgp 192.168.1.2 message-stats") + r1.vtysh_cmd( + """ + configure terminal + router bgp + neighbor 192.168.1.2 capability software-version + """ + ) + + r2.vtysh_cmd( + """ + configure terminal + router bgp + neighbor 192.168.1.1 capability software-version + """ + ) + + def _bgp_check_if_session_not_reset(): + def _bgp_software_version(): + try: + versions = output["192.168.1.2"]["neighborCapabilities"][ + "softwareVersion" + ] + adv = versions["advertisedSoftwareVersion"] + rcv = versions["receivedSoftwareVersion"] + + if not adv and not rcv: + return "" + + pattern = "^FRRouting/\\d.+" + if re.search(pattern, adv) and re.search(pattern, rcv): + return adv, rcv + except: + return "" + + output = json.loads(r1.vtysh_cmd("show bgp neighbor json")) + adv, rcv = _bgp_software_version() + expected = { + "192.168.1.2": { + "bgpState": "Established", + "neighborCapabilities": { + "dynamic": "advertisedAndReceived", + "softwareVersion": { + "advertisedSoftwareVersion": adv, + "receivedSoftwareVersion": rcv, + }, + }, + "addressFamilyInfo": { + "ipv4Unicast": { + "acceptedPrefixCounter": 3, + } + }, + "messageStats": { + "notificationsRecv": 0, + "capabilityRecv": 1, + }, + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_check_if_session_not_reset, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert ( + result is None + ), "Session was reset after enabling software version capability" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_ecmp_topo1/exabgp.env b/tests/topotests/bgp_ecmp_topo1/exabgp.env index a328e04962..ec978c66e7 100644 --- a/tests/topotests/bgp_ecmp_topo1/exabgp.env +++ b/tests/topotests/bgp_ecmp_topo1/exabgp.env @@ -1,5 +1,6 @@ [exabgp.api] +ack = false encoder = text highres = false respawn = false diff --git a/tests/topotests/bgp_ecmp_topo1/peer1/exa-send.py b/tests/topotests/bgp_ecmp_topo1/peer1/exa-send.py index 6bef35508f..1a8e6bfe2f 100755 --- a/tests/topotests/bgp_ecmp_topo1/peer1/exa-send.py +++ b/tests/topotests/bgp_ecmp_topo1/peer1/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_ecmp_topo1/peer1/exabgp.cfg b/tests/topotests/bgp_ecmp_topo1/peer1/exabgp.cfg index 2d0ca89f0f..97a024ce96 100644 --- a/tests/topotests/bgp_ecmp_topo1/peer1/exabgp.cfg +++ b/tests/topotests/bgp_ecmp_topo1/peer1/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 1 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 1"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 1 10; + encoder text; +} - neighbor 10.0.1.1 { - router-id 10.0.1.101; - local-address 10.0.1.101; - local-as 99; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 1; + encoder text; +} +neighbor 10.0.1.1 { + router-id 10.0.1.101; + local-address 10.0.1.101; + local-as 99; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_ecmp_topo1/peer10/exa-send.py b/tests/topotests/bgp_ecmp_topo1/peer10/exa-send.py index 6bef35508f..1a8e6bfe2f 100755 --- a/tests/topotests/bgp_ecmp_topo1/peer10/exa-send.py +++ b/tests/topotests/bgp_ecmp_topo1/peer10/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_ecmp_topo1/peer10/exabgp.cfg b/tests/topotests/bgp_ecmp_topo1/peer10/exabgp.cfg index 0c842a0e7f..e318162a1f 100644 --- a/tests/topotests/bgp_ecmp_topo1/peer10/exabgp.cfg +++ b/tests/topotests/bgp_ecmp_topo1/peer10/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 10 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 10"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 10 10; + encoder text; +} - neighbor 10.0.2.1 { - router-id 10.0.2.110; - local-address 10.0.2.110; - local-as 99; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 10; + encoder text; +} +neighbor 10.0.2.1 { + router-id 10.0.2.110; + local-address 10.0.2.110; + local-as 99; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_ecmp_topo1/peer11/exa-send.py b/tests/topotests/bgp_ecmp_topo1/peer11/exa-send.py index 6bef35508f..1a8e6bfe2f 100755 --- a/tests/topotests/bgp_ecmp_topo1/peer11/exa-send.py +++ b/tests/topotests/bgp_ecmp_topo1/peer11/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_ecmp_topo1/peer11/exabgp.cfg b/tests/topotests/bgp_ecmp_topo1/peer11/exabgp.cfg index 936dc572bd..ea5bdcce80 100644 --- a/tests/topotests/bgp_ecmp_topo1/peer11/exabgp.cfg +++ b/tests/topotests/bgp_ecmp_topo1/peer11/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 11 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 11"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 11 10; + encoder text; +} - neighbor 10.0.3.1 { - router-id 10.0.3.111; - local-address 10.0.3.111; - local-as 111; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 11; + encoder text; +} +neighbor 10.0.3.1 { + router-id 10.0.3.111; + local-address 10.0.3.111; + local-as 111; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_ecmp_topo1/peer12/exa-send.py b/tests/topotests/bgp_ecmp_topo1/peer12/exa-send.py index 6bef35508f..1a8e6bfe2f 100755 --- a/tests/topotests/bgp_ecmp_topo1/peer12/exa-send.py +++ b/tests/topotests/bgp_ecmp_topo1/peer12/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_ecmp_topo1/peer12/exabgp.cfg b/tests/topotests/bgp_ecmp_topo1/peer12/exabgp.cfg index 56b33eae8e..81fb5035f7 100644 --- a/tests/topotests/bgp_ecmp_topo1/peer12/exabgp.cfg +++ b/tests/topotests/bgp_ecmp_topo1/peer12/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 12 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 12"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 12 10; + encoder text; +} - neighbor 10.0.3.1 { - router-id 10.0.3.112; - local-address 10.0.3.112; - local-as 112; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 12; + encoder text; +} +neighbor 10.0.3.1 { + router-id 10.0.3.112; + local-address 10.0.3.112; + local-as 112; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_ecmp_topo1/peer13/exa-send.py b/tests/topotests/bgp_ecmp_topo1/peer13/exa-send.py index 6bef35508f..1a8e6bfe2f 100755 --- a/tests/topotests/bgp_ecmp_topo1/peer13/exa-send.py +++ b/tests/topotests/bgp_ecmp_topo1/peer13/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_ecmp_topo1/peer13/exabgp.cfg b/tests/topotests/bgp_ecmp_topo1/peer13/exabgp.cfg index b933ffb5cf..40078411ec 100644 --- a/tests/topotests/bgp_ecmp_topo1/peer13/exabgp.cfg +++ b/tests/topotests/bgp_ecmp_topo1/peer13/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 13 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 13"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 13 10; + encoder text; +} - neighbor 10.0.3.1 { - router-id 10.0.3.113; - local-address 10.0.3.113; - local-as 113; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 13; + encoder text; +} +neighbor 10.0.3.1 { + router-id 10.0.3.113; + local-address 10.0.3.113; + local-as 113; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_ecmp_topo1/peer14/exa-send.py b/tests/topotests/bgp_ecmp_topo1/peer14/exa-send.py index 6bef35508f..1a8e6bfe2f 100755 --- a/tests/topotests/bgp_ecmp_topo1/peer14/exa-send.py +++ b/tests/topotests/bgp_ecmp_topo1/peer14/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_ecmp_topo1/peer14/exabgp.cfg b/tests/topotests/bgp_ecmp_topo1/peer14/exabgp.cfg index bcfa41eb2e..afb8741636 100644 --- a/tests/topotests/bgp_ecmp_topo1/peer14/exabgp.cfg +++ b/tests/topotests/bgp_ecmp_topo1/peer14/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 14 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 14"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 14 10; + encoder text; +} - neighbor 10.0.3.1 { - router-id 10.0.3.114; - local-address 10.0.3.114; - local-as 114; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 14; + encoder text; +} +neighbor 10.0.3.1 { + router-id 10.0.3.114; + local-address 10.0.3.114; + local-as 114; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_ecmp_topo1/peer15/exa-send.py b/tests/topotests/bgp_ecmp_topo1/peer15/exa-send.py index 6bef35508f..1a8e6bfe2f 100755 --- a/tests/topotests/bgp_ecmp_topo1/peer15/exa-send.py +++ b/tests/topotests/bgp_ecmp_topo1/peer15/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_ecmp_topo1/peer15/exabgp.cfg b/tests/topotests/bgp_ecmp_topo1/peer15/exabgp.cfg index 022e835798..9a4ca7f695 100644 --- a/tests/topotests/bgp_ecmp_topo1/peer15/exabgp.cfg +++ b/tests/topotests/bgp_ecmp_topo1/peer15/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 15 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 15"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 15 10; + encoder text; +} - neighbor 10.0.3.1 { - router-id 10.0.3.115; - local-address 10.0.3.115; - local-as 115; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 15; + encoder text; +} +neighbor 10.0.3.1 { + router-id 10.0.3.115; + local-address 10.0.3.115; + local-as 115; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_ecmp_topo1/peer16/exa-send.py b/tests/topotests/bgp_ecmp_topo1/peer16/exa-send.py index 6bef35508f..1a8e6bfe2f 100755 --- a/tests/topotests/bgp_ecmp_topo1/peer16/exa-send.py +++ b/tests/topotests/bgp_ecmp_topo1/peer16/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_ecmp_topo1/peer16/exabgp.cfg b/tests/topotests/bgp_ecmp_topo1/peer16/exabgp.cfg index 0649202f1f..a0bb88a3f3 100644 --- a/tests/topotests/bgp_ecmp_topo1/peer16/exabgp.cfg +++ b/tests/topotests/bgp_ecmp_topo1/peer16/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 16 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 16"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 16 10; + encoder text; +} - neighbor 10.0.4.1 { - router-id 10.0.4.116; - local-address 10.0.4.116; - local-as 116; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 16; + encoder text; +} +neighbor 10.0.4.1 { + router-id 10.0.4.116; + local-address 10.0.4.116; + local-as 116; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_ecmp_topo1/peer17/exa-send.py b/tests/topotests/bgp_ecmp_topo1/peer17/exa-send.py index 6bef35508f..1a8e6bfe2f 100755 --- a/tests/topotests/bgp_ecmp_topo1/peer17/exa-send.py +++ b/tests/topotests/bgp_ecmp_topo1/peer17/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_ecmp_topo1/peer17/exabgp.cfg b/tests/topotests/bgp_ecmp_topo1/peer17/exabgp.cfg index 0aeeed9d95..870d33d455 100644 --- a/tests/topotests/bgp_ecmp_topo1/peer17/exabgp.cfg +++ b/tests/topotests/bgp_ecmp_topo1/peer17/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 17 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 17"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 17 10; + encoder text; +} - neighbor 10.0.4.1 { - router-id 10.0.4.117; - local-address 10.0.4.117; - local-as 117; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 17; + encoder text; +} +neighbor 10.0.4.1 { + router-id 10.0.4.117; + local-address 10.0.4.117; + local-as 117; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_ecmp_topo1/peer18/exa-send.py b/tests/topotests/bgp_ecmp_topo1/peer18/exa-send.py index 6bef35508f..1a8e6bfe2f 100755 --- a/tests/topotests/bgp_ecmp_topo1/peer18/exa-send.py +++ b/tests/topotests/bgp_ecmp_topo1/peer18/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_ecmp_topo1/peer18/exabgp.cfg b/tests/topotests/bgp_ecmp_topo1/peer18/exabgp.cfg index 352c030eda..c5a1ca62e4 100644 --- a/tests/topotests/bgp_ecmp_topo1/peer18/exabgp.cfg +++ b/tests/topotests/bgp_ecmp_topo1/peer18/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 18 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 18"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 18 10; + encoder text; +} - neighbor 10.0.4.1 { - router-id 10.0.4.118; - local-address 10.0.4.118; - local-as 118; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 18; + encoder text; +} +neighbor 10.0.4.1 { + router-id 10.0.4.118; + local-address 10.0.4.118; + local-as 118; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_ecmp_topo1/peer19/exa-send.py b/tests/topotests/bgp_ecmp_topo1/peer19/exa-send.py index 6bef35508f..1a8e6bfe2f 100755 --- a/tests/topotests/bgp_ecmp_topo1/peer19/exa-send.py +++ b/tests/topotests/bgp_ecmp_topo1/peer19/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_ecmp_topo1/peer19/exabgp.cfg b/tests/topotests/bgp_ecmp_topo1/peer19/exabgp.cfg index 9913c226f6..f662ccf93e 100644 --- a/tests/topotests/bgp_ecmp_topo1/peer19/exabgp.cfg +++ b/tests/topotests/bgp_ecmp_topo1/peer19/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 19 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 19"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 19 10; + encoder text; +} - neighbor 10.0.4.1 { - router-id 10.0.4.119; - local-address 10.0.4.119; - local-as 119; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 19; + encoder text; +} +neighbor 10.0.4.1 { + router-id 10.0.4.119; + local-address 10.0.4.119; + local-as 119; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_ecmp_topo1/peer2/exa-send.py b/tests/topotests/bgp_ecmp_topo1/peer2/exa-send.py index 6bef35508f..1a8e6bfe2f 100755 --- a/tests/topotests/bgp_ecmp_topo1/peer2/exa-send.py +++ b/tests/topotests/bgp_ecmp_topo1/peer2/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_ecmp_topo1/peer2/exabgp.cfg b/tests/topotests/bgp_ecmp_topo1/peer2/exabgp.cfg index 46b436d2af..673d6ec0ee 100644 --- a/tests/topotests/bgp_ecmp_topo1/peer2/exabgp.cfg +++ b/tests/topotests/bgp_ecmp_topo1/peer2/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 2 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 2"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 2 10; + encoder text; +} - neighbor 10.0.1.1 { - router-id 10.0.1.102; - local-address 10.0.1.102; - local-as 99; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 2; + encoder text; +} +neighbor 10.0.1.1 { + router-id 10.0.1.102; + local-address 10.0.1.102; + local-as 99; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_ecmp_topo1/peer20/exa-send.py b/tests/topotests/bgp_ecmp_topo1/peer20/exa-send.py index 6bef35508f..1a8e6bfe2f 100755 --- a/tests/topotests/bgp_ecmp_topo1/peer20/exa-send.py +++ b/tests/topotests/bgp_ecmp_topo1/peer20/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_ecmp_topo1/peer20/exabgp.cfg b/tests/topotests/bgp_ecmp_topo1/peer20/exabgp.cfg index 17fb816a75..5ea2c91de1 100644 --- a/tests/topotests/bgp_ecmp_topo1/peer20/exabgp.cfg +++ b/tests/topotests/bgp_ecmp_topo1/peer20/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 20 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 20"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 20 10; + encoder text; +} - neighbor 10.0.4.1 { - router-id 10.0.4.120; - local-address 10.0.4.120; - local-as 120; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 20; + encoder text; +} +neighbor 10.0.4.1 { + router-id 10.0.4.120; + local-address 10.0.4.120; + local-as 120; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_ecmp_topo1/peer3/exa-send.py b/tests/topotests/bgp_ecmp_topo1/peer3/exa-send.py index 6bef35508f..1a8e6bfe2f 100755 --- a/tests/topotests/bgp_ecmp_topo1/peer3/exa-send.py +++ b/tests/topotests/bgp_ecmp_topo1/peer3/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_ecmp_topo1/peer3/exabgp.cfg b/tests/topotests/bgp_ecmp_topo1/peer3/exabgp.cfg index acd57756b9..47a25cab22 100644 --- a/tests/topotests/bgp_ecmp_topo1/peer3/exabgp.cfg +++ b/tests/topotests/bgp_ecmp_topo1/peer3/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 3 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 3"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 3 10; + encoder text; +} - neighbor 10.0.1.1 { - router-id 10.0.1.103; - local-address 10.0.1.103; - local-as 99; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 3; + encoder text; +} +neighbor 10.0.1.1 { + router-id 10.0.1.103; + local-address 10.0.1.103; + local-as 99; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_ecmp_topo1/peer4/exa-send.py b/tests/topotests/bgp_ecmp_topo1/peer4/exa-send.py index 6bef35508f..1a8e6bfe2f 100755 --- a/tests/topotests/bgp_ecmp_topo1/peer4/exa-send.py +++ b/tests/topotests/bgp_ecmp_topo1/peer4/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_ecmp_topo1/peer4/exabgp.cfg b/tests/topotests/bgp_ecmp_topo1/peer4/exabgp.cfg index 4c9a989b5a..376ac5f37d 100644 --- a/tests/topotests/bgp_ecmp_topo1/peer4/exabgp.cfg +++ b/tests/topotests/bgp_ecmp_topo1/peer4/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 4 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 4"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 4 10; + encoder text; +} - neighbor 10.0.1.1 { - router-id 10.0.1.104; - local-address 10.0.1.104; - local-as 99; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 4; + encoder text; +} +neighbor 10.0.1.1 { + router-id 10.0.1.104; + local-address 10.0.1.104; + local-as 99; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_ecmp_topo1/peer5/exa-send.py b/tests/topotests/bgp_ecmp_topo1/peer5/exa-send.py index 6bef35508f..1a8e6bfe2f 100755 --- a/tests/topotests/bgp_ecmp_topo1/peer5/exa-send.py +++ b/tests/topotests/bgp_ecmp_topo1/peer5/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_ecmp_topo1/peer5/exabgp.cfg b/tests/topotests/bgp_ecmp_topo1/peer5/exabgp.cfg index eba2aae378..878d728de6 100644 --- a/tests/topotests/bgp_ecmp_topo1/peer5/exabgp.cfg +++ b/tests/topotests/bgp_ecmp_topo1/peer5/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 5 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 5"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 5 10; + encoder text; +} - neighbor 10.0.1.1 { - router-id 10.0.1.105; - local-address 10.0.1.105; - local-as 99; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 5; + encoder text; +} +neighbor 10.0.1.1 { + router-id 10.0.1.105; + local-address 10.0.1.105; + local-as 99; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_ecmp_topo1/peer6/exa-send.py b/tests/topotests/bgp_ecmp_topo1/peer6/exa-send.py index 6bef35508f..1a8e6bfe2f 100755 --- a/tests/topotests/bgp_ecmp_topo1/peer6/exa-send.py +++ b/tests/topotests/bgp_ecmp_topo1/peer6/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_ecmp_topo1/peer6/exabgp.cfg b/tests/topotests/bgp_ecmp_topo1/peer6/exabgp.cfg index 38b6af0e85..fc702674cf 100644 --- a/tests/topotests/bgp_ecmp_topo1/peer6/exabgp.cfg +++ b/tests/topotests/bgp_ecmp_topo1/peer6/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 6 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 6"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 6 10; + encoder text; +} - neighbor 10.0.2.1 { - router-id 10.0.2.106; - local-address 10.0.2.106; - local-as 99; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 6; + encoder text; +} +neighbor 10.0.2.1 { + router-id 10.0.2.106; + local-address 10.0.2.106; + local-as 99; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_ecmp_topo1/peer7/exa-send.py b/tests/topotests/bgp_ecmp_topo1/peer7/exa-send.py index 6bef35508f..1a8e6bfe2f 100755 --- a/tests/topotests/bgp_ecmp_topo1/peer7/exa-send.py +++ b/tests/topotests/bgp_ecmp_topo1/peer7/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_ecmp_topo1/peer7/exabgp.cfg b/tests/topotests/bgp_ecmp_topo1/peer7/exabgp.cfg index 7631e43750..09827a8902 100644 --- a/tests/topotests/bgp_ecmp_topo1/peer7/exabgp.cfg +++ b/tests/topotests/bgp_ecmp_topo1/peer7/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 7 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 7"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 7 10; + encoder text; +} - neighbor 10.0.2.1 { - router-id 10.0.2.107; - local-address 10.0.2.107; - local-as 99; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 7; + encoder text; +} +neighbor 10.0.2.1 { + router-id 10.0.2.107; + local-address 10.0.2.107; + local-as 99; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_ecmp_topo1/peer8/exa-send.py b/tests/topotests/bgp_ecmp_topo1/peer8/exa-send.py index 6bef35508f..1a8e6bfe2f 100755 --- a/tests/topotests/bgp_ecmp_topo1/peer8/exa-send.py +++ b/tests/topotests/bgp_ecmp_topo1/peer8/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_ecmp_topo1/peer8/exabgp.cfg b/tests/topotests/bgp_ecmp_topo1/peer8/exabgp.cfg index 1cd1cd9024..37c01dabb7 100644 --- a/tests/topotests/bgp_ecmp_topo1/peer8/exabgp.cfg +++ b/tests/topotests/bgp_ecmp_topo1/peer8/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 8 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 8"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 8 10; + encoder text; +} - neighbor 10.0.2.1 { - router-id 10.0.2.108; - local-address 10.0.2.108; - local-as 99; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 8; + encoder text; +} +neighbor 10.0.2.1 { + router-id 10.0.2.108; + local-address 10.0.2.108; + local-as 99; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_ecmp_topo1/peer9/exa-send.py b/tests/topotests/bgp_ecmp_topo1/peer9/exa-send.py index 6bef35508f..1a8e6bfe2f 100755 --- a/tests/topotests/bgp_ecmp_topo1/peer9/exa-send.py +++ b/tests/topotests/bgp_ecmp_topo1/peer9/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_ecmp_topo1/peer9/exabgp.cfg b/tests/topotests/bgp_ecmp_topo1/peer9/exabgp.cfg index 5771553962..8fb5c58b6b 100644 --- a/tests/topotests/bgp_ecmp_topo1/peer9/exabgp.cfg +++ b/tests/topotests/bgp_ecmp_topo1/peer9/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 9 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 9"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 9 10; + encoder text; +} - neighbor 10.0.2.1 { - router-id 10.0.2.109; - local-address 10.0.2.109; - local-as 99; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 9; + encoder text; +} +neighbor 10.0.2.1 { + router-id 10.0.2.109; + local-address 10.0.2.109; + local-as 99; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_ecmp_topo1/test_bgp_ecmp_topo1.py b/tests/topotests/bgp_ecmp_topo1/test_bgp_ecmp_topo1.py index 97751ec8cf..7af3f48ff6 100644 --- a/tests/topotests/bgp_ecmp_topo1/test_bgp_ecmp_topo1.py +++ b/tests/topotests/bgp_ecmp_topo1/test_bgp_ecmp_topo1.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # SPDX-License-Identifier: ISC # diff --git a/tests/topotests/bgp_evpn_mh/leaf1/evpn.conf b/tests/topotests/bgp_evpn_mh/leaf1/evpn.conf new file mode 100644 index 0000000000..33b6d08aba --- /dev/null +++ b/tests/topotests/bgp_evpn_mh/leaf1/evpn.conf @@ -0,0 +1,21 @@ +frr defaults datacenter +! +router bgp 65101 + bgp router-id 192.168.100.13 + no bgp ebgp-requires-policy + neighbor 192.168.50.1 remote-as external + neighbor 192.168.51.1 remote-as external + neighbor 192.168.1.2 remote-as external + neighbor 192.168.2.2 remote-as external + neighbor 192.168.3.2 remote-as external + neighbor 192.168.4.2 remote-as external + redistribute connected + address-family l2vpn evpn + neighbor 192.168.50.1 activate + neighbor 192.168.51.1 activate + neighbor 192.168.1.2 activate + neighbor 192.168.2.2 activate + neighbor 192.168.3.2 activate + neighbor 192.168.4.2 activate + exit-address-family +! diff --git a/tests/topotests/bgp_evpn_mh/leaf1/pim.conf b/tests/topotests/bgp_evpn_mh/leaf1/pim.conf new file mode 100644 index 0000000000..a4de64d1fb --- /dev/null +++ b/tests/topotests/bgp_evpn_mh/leaf1/pim.conf @@ -0,0 +1,26 @@ +#debug pim packet +#debug pim packet register +#debug pim event +#debug pim trace +ip pim ecmp +ip pim rp 192.168.100.13 +ip pim spt-switchover infinity-and-beyond +! +int leaf1-eth0 + ip pim +! +int leaf1-eth1 + ip pim +! +int leaf1-eth2 + ip pim +! +int leaf1-eth3 + ip pim +! +int leaf1-eth4 + ip pim +! +int leaf1-eth5 + ip pim +! diff --git a/tests/topotests/bgp_evpn_mh/leaf1/zebra.conf b/tests/topotests/bgp_evpn_mh/leaf1/zebra.conf new file mode 100644 index 0000000000..f666f98abc --- /dev/null +++ b/tests/topotests/bgp_evpn_mh/leaf1/zebra.conf @@ -0,0 +1,30 @@ +# spine 1 connection +int leaf1-eth0 + description spine1 connection + ip addr 192.168.50.2/24 + +#spine 2 connection +int leaf1-eth1 + description spine2 connection + ip addr 192.168.51.2/24 + +#torm11 connection +int leaf1-eth2 + description torm11 connection + ip addr 192.168.1.1/24 +! +#torm12 connection +int leaf1-eth3 + description torm12 connection + ip addr 192.168.2.1/24 +! +#torm21 connection +int leaf1-eth4 + description torm21 connection + ip addr 192.168.3.1/24 +! +#torm22 connection +int leaf1-eth5 + descriptoin torm22 connection + ip addr 192.168.4.1/24 +! diff --git a/tests/topotests/bgp_evpn_mh/leaf2/evpn.conf b/tests/topotests/bgp_evpn_mh/leaf2/evpn.conf new file mode 100644 index 0000000000..428998b0fe --- /dev/null +++ b/tests/topotests/bgp_evpn_mh/leaf2/evpn.conf @@ -0,0 +1,21 @@ +frr defaults datacenter +! +router bgp 65101 + bgp router-id 192.168.100.14 + no bgp ebgp-requires-policy + neighbor 192.168.61.1 remote-as external + neighbor 192.168.51.1 remote-as external + neighbor 192.168.5.2 remote-as external + neighbor 192.168.6.2 remote-as external + neighbor 192.168.7.2 remote-as external + neighbor 192.168.8.2 remote-as external + redistribute connected + address-family l2vpn evpn + neighbor 192.168.61.1 activate + neighbor 192.168.51.1 activate + neighbor 192.168.5.2 activate + neighbor 192.168.6.2 activate + neighbor 192.168.7.2 activate + neighbor 192.168.8.2 activate + exit-address-family +! diff --git a/tests/topotests/bgp_evpn_mh/leaf2/pim.conf b/tests/topotests/bgp_evpn_mh/leaf2/pim.conf new file mode 100644 index 0000000000..3abd9698f5 --- /dev/null +++ b/tests/topotests/bgp_evpn_mh/leaf2/pim.conf @@ -0,0 +1,20 @@ +#debug pim packet register +#debug pim packet +#debug pim event +#debug pim trace +ip pim ecmp +ip pim rp 192.168.100.13 +ip pim spt-switchover infinity-and-beyond +! +int leaf2-eth0 + ip pim +! +int leaf2-eth1 + ip pim +! +int leaf2-eth2 + ip pim +! +int leaf2-eth3 + ip pim +! diff --git a/tests/topotests/bgp_evpn_mh/leaf2/zebra.conf b/tests/topotests/bgp_evpn_mh/leaf2/zebra.conf new file mode 100644 index 0000000000..ff680cf764 --- /dev/null +++ b/tests/topotests/bgp_evpn_mh/leaf2/zebra.conf @@ -0,0 +1,24 @@ +# spine1 connection +int leaf2-eth0 + ip addr 192.168.51.2/24 +! +# spine2 connection +int leaf2-eth1 + ip addr 192.168.61.2/24 +! +#torm11 connection +int leaf2-eth2 + ip addr 192.168.5.1/24 +! +#torm12 connection +int leaf2-eth3 + ip addr 192.168.6.1/24 +! +#torm21 connection +int leaf2-eth4 + ip addr 192.168.7.1/24 +! +#torm22 connection +int leaf2-eth5 + ip addr 192.168.8.1/24 +! diff --git a/tests/topotests/bgp_evpn_mh/spine1/evpn.conf b/tests/topotests/bgp_evpn_mh/spine1/evpn.conf index 2e26f60f44..b9fce46ea4 100644 --- a/tests/topotests/bgp_evpn_mh/spine1/evpn.conf +++ b/tests/topotests/bgp_evpn_mh/spine1/evpn.conf @@ -3,15 +3,11 @@ frr defaults datacenter router bgp 65001 bgp router-id 192.168.100.13 no bgp ebgp-requires-policy - neighbor 192.168.1.2 remote-as external - neighbor 192.168.2.2 remote-as external - neighbor 192.168.3.2 remote-as external - neighbor 192.168.4.2 remote-as external + neighbor 192.168.50.2 remote-as external + neighbor 192.168.51.2 remote-as external redistribute connected address-family l2vpn evpn - neighbor 192.168.1.2 activate - neighbor 192.168.2.2 activate - neighbor 192.168.3.2 activate - neighbor 192.168.4.2 activate + neighbor 192.168.50.2 activate + neighbor 192.168.51.2 activate exit-address-family ! diff --git a/tests/topotests/bgp_evpn_mh/spine1/pim.conf b/tests/topotests/bgp_evpn_mh/spine1/pim.conf index 68e686e8c7..018d244e4d 100644 --- a/tests/topotests/bgp_evpn_mh/spine1/pim.conf +++ b/tests/topotests/bgp_evpn_mh/spine1/pim.conf @@ -1,4 +1,10 @@ +ip pim ecmp ip pim rp 192.168.100.13 +#debug pim packets +#debug pim packet register +#debug pim event +#debug pim trace +#debug pim vxlan ip pim spt-switchover infinity-and-beyond ! int lo @@ -10,9 +16,3 @@ int spine1-eth0 int spine1-eth1 ip pim ! -int spine1-eth2 - ip pim -! -int spine1-eth3 - ip pim -! diff --git a/tests/topotests/bgp_evpn_mh/spine1/zebra.conf b/tests/topotests/bgp_evpn_mh/spine1/zebra.conf index 80e9e5a263..607a5e8e32 100644 --- a/tests/topotests/bgp_evpn_mh/spine1/zebra.conf +++ b/tests/topotests/bgp_evpn_mh/spine1/zebra.conf @@ -1,14 +1,10 @@ +# leaf1 connection int spine1-eth0 - ip addr 192.168.1.1/24 + ip addr 192.168.50.1/24 ! +# leaf2 connection int spine1-eth1 - ip addr 192.168.2.1/24 -! -int spine1-eth2 - ip addr 192.168.3.1/24 -! -int spine1-eth3 - ip addr 192.168.4.1/24 + ip addr 192.168.51.1/24 ! int lo ip addr 192.168.100.13/32 diff --git a/tests/topotests/bgp_evpn_mh/spine2/evpn.conf b/tests/topotests/bgp_evpn_mh/spine2/evpn.conf index ec2e789276..1430e10b68 100644 --- a/tests/topotests/bgp_evpn_mh/spine2/evpn.conf +++ b/tests/topotests/bgp_evpn_mh/spine2/evpn.conf @@ -3,15 +3,11 @@ frr defaults datacenter router bgp 65001 bgp router-id 192.168.100.14 no bgp ebgp-requires-policy - neighbor 192.168.5.2 remote-as external - neighbor 192.168.6.2 remote-as external - neighbor 192.168.7.2 remote-as external - neighbor 192.168.8.2 remote-as external + neighbor 192.168.60.2 remote-as external + neighbor 192.168.61.2 remote-as external redistribute connected address-family l2vpn evpn - neighbor 192.168.5.2 activate - neighbor 192.168.6.2 activate - neighbor 192.168.7.2 activate - neighbor 192.168.8.2 activate + neighbor 192.168.60.2 activate + neighbor 192.168.61.2 activate exit-address-family ! diff --git a/tests/topotests/bgp_evpn_mh/spine2/pim.conf b/tests/topotests/bgp_evpn_mh/spine2/pim.conf index c1566240e6..0ece2ff539 100644 --- a/tests/topotests/bgp_evpn_mh/spine2/pim.conf +++ b/tests/topotests/bgp_evpn_mh/spine2/pim.conf @@ -1,3 +1,4 @@ +ip pim ecmp ip pim rp 192.168.100.13 ip pim spt-switchover infinity-and-beyond ! @@ -10,9 +11,3 @@ int spine2-eth0 int spine2-eth1 ip pim ! -int spine2-eth2 - ip pim -! -int spine2-eth3 - ip pim -! diff --git a/tests/topotests/bgp_evpn_mh/spine2/zebra.conf b/tests/topotests/bgp_evpn_mh/spine2/zebra.conf index 1cd1df8c81..c8cec14e62 100644 --- a/tests/topotests/bgp_evpn_mh/spine2/zebra.conf +++ b/tests/topotests/bgp_evpn_mh/spine2/zebra.conf @@ -1,14 +1,12 @@ +# leaf1 connection int spine2-eth0 - ip addr 192.168.5.1/24 + description leaf1 connection + ip addr 192.168.60.1/24 ! +# leaf2 connection int spine2-eth1 - ip addr 192.168.6.1/24 -! -int spine2-eth2 - ip addr 192.168.7.1/24 -! -int spine2-eth3 - ip addr 192.168.8.1/24 + description leaf2 connection + ip addr 192.168.61.1/24 ! int lo ip addr 192.168.100.14/32 diff --git a/tests/topotests/bgp_evpn_mh/test_evpn_mh.py b/tests/topotests/bgp_evpn_mh/test_evpn_mh.py index 0bde5d5a9f..ec5227809e 100644 --- a/tests/topotests/bgp_evpn_mh/test_evpn_mh.py +++ b/tests/topotests/bgp_evpn_mh/test_evpn_mh.py @@ -58,6 +58,8 @@ def build_topo(tgen): tgen.add_router("spine1") tgen.add_router("spine2") + tgen.add_router("leaf1") + tgen.add_router("leaf2") tgen.add_router("torm11") tgen.add_router("torm12") tgen.add_router("torm21") @@ -71,88 +73,109 @@ def build_topo(tgen): # First switch is for a dummy interface (for local network) ##################### spine1 ######################## - # spine1-eth0 is connected to torm11-eth0 + # spine1-eth0 is connected to leaf1-eth0 switch = tgen.add_switch("sw1") switch.add_link(tgen.gears["spine1"]) - switch.add_link(tgen.gears["torm11"]) + switch.add_link(tgen.gears["leaf1"]) - # spine1-eth1 is connected to torm12-eth0 + # spine1-eth1 is connected to leaf2-eth0 switch = tgen.add_switch("sw2") switch.add_link(tgen.gears["spine1"]) - switch.add_link(tgen.gears["torm12"]) + switch.add_link(tgen.gears["leaf2"]) - # spine1-eth2 is connected to torm21-eth0 + # spine2-eth0 is connected to leaf1-eth1 switch = tgen.add_switch("sw3") - switch.add_link(tgen.gears["spine1"]) - switch.add_link(tgen.gears["torm21"]) + switch.add_link(tgen.gears["spine2"]) + switch.add_link(tgen.gears["leaf1"]) - # spine1-eth3 is connected to torm22-eth0 + # spine2-eth1 is connected to leaf2-eth1 switch = tgen.add_switch("sw4") - switch.add_link(tgen.gears["spine1"]) - switch.add_link(tgen.gears["torm22"]) + switch.add_link(tgen.gears["spine2"]) + switch.add_link(tgen.gears["leaf2"]) - ##################### spine2 ######################## - # spine2-eth0 is connected to torm11-eth1 + ################## leaf1 ########################## + # leaf1-eth2 is connected to torm11-eth0 switch = tgen.add_switch("sw5") - switch.add_link(tgen.gears["spine2"]) + switch.add_link(tgen.gears["leaf1"]) switch.add_link(tgen.gears["torm11"]) - # spine2-eth1 is connected to torm12-eth1 + # leaf1-eth3 is connected to torm12-eth0 switch = tgen.add_switch("sw6") - switch.add_link(tgen.gears["spine2"]) + switch.add_link(tgen.gears["leaf1"]) switch.add_link(tgen.gears["torm12"]) - # spine2-eth2 is connected to torm21-eth1 + # leaf1-eth4 is connected to torm21-eth0 switch = tgen.add_switch("sw7") - switch.add_link(tgen.gears["spine2"]) + switch.add_link(tgen.gears["leaf1"]) switch.add_link(tgen.gears["torm21"]) - # spine2-eth3 is connected to torm22-eth1 + # leaf1-eth5 is connected to torm22-eth0 switch = tgen.add_switch("sw8") - switch.add_link(tgen.gears["spine2"]) + switch.add_link(tgen.gears["leaf1"]) + switch.add_link(tgen.gears["torm22"]) + + ##################### leaf2 ######################## + # leaf2-eth2 is connected to torm11-eth1 + switch = tgen.add_switch("sw9") + switch.add_link(tgen.gears["leaf2"]) + switch.add_link(tgen.gears["torm11"]) + + # leaf2-eth3 is connected to torm12-eth1 + switch = tgen.add_switch("sw10") + switch.add_link(tgen.gears["leaf2"]) + switch.add_link(tgen.gears["torm12"]) + + # leaf2-eth4 is connected to torm21-eth1 + switch = tgen.add_switch("sw11") + switch.add_link(tgen.gears["leaf2"]) + switch.add_link(tgen.gears["torm21"]) + + # leaf2-eth5 is connected to torm22-eth1 + switch = tgen.add_switch("sw12") + switch.add_link(tgen.gears["leaf2"]) switch.add_link(tgen.gears["torm22"]) ##################### torm11 ######################## # torm11-eth2 is connected to hostd11-eth0 - switch = tgen.add_switch("sw9") + switch = tgen.add_switch("sw13") switch.add_link(tgen.gears["torm11"]) switch.add_link(tgen.gears["hostd11"]) # torm11-eth3 is connected to hostd12-eth0 - switch = tgen.add_switch("sw10") + switch = tgen.add_switch("sw14") switch.add_link(tgen.gears["torm11"]) switch.add_link(tgen.gears["hostd12"]) ##################### torm12 ######################## # torm12-eth2 is connected to hostd11-eth1 - switch = tgen.add_switch("sw11") + switch = tgen.add_switch("sw15") switch.add_link(tgen.gears["torm12"]) switch.add_link(tgen.gears["hostd11"]) # torm12-eth3 is connected to hostd12-eth1 - switch = tgen.add_switch("sw12") + switch = tgen.add_switch("sw16") switch.add_link(tgen.gears["torm12"]) switch.add_link(tgen.gears["hostd12"]) ##################### torm21 ######################## # torm21-eth2 is connected to hostd21-eth0 - switch = tgen.add_switch("sw13") + switch = tgen.add_switch("sw17") switch.add_link(tgen.gears["torm21"]) switch.add_link(tgen.gears["hostd21"]) # torm21-eth3 is connected to hostd22-eth0 - switch = tgen.add_switch("sw14") + switch = tgen.add_switch("sw18") switch.add_link(tgen.gears["torm21"]) switch.add_link(tgen.gears["hostd22"]) ##################### torm22 ######################## # torm22-eth2 is connected to hostd21-eth1 - switch = tgen.add_switch("sw15") + switch = tgen.add_switch("sw19") switch.add_link(tgen.gears["torm22"]) switch.add_link(tgen.gears["hostd21"]) # torm22-eth3 is connected to hostd22-eth1 - switch = tgen.add_switch("sw16") + switch = tgen.add_switch("sw20") switch.add_link(tgen.gears["torm22"]) switch.add_link(tgen.gears["hostd22"]) @@ -591,7 +614,7 @@ def ping_anycast_gw(tgen): "--interface=" + intf, 'Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst="{}")'.format(ipaddr), ] - for name in ("hostd11", "hostd21"): + for name in ("hostd11", "hostd21", "hostd12", "hostd22"): host = tgen.net.hosts[name] _, stdout, _ = host.cmd_status(ping_cmd, warn=False, stderr=subprocess.STDOUT) stdout = stdout.strip() diff --git a/tests/topotests/bgp_evpn_mh/torm11/pim.conf b/tests/topotests/bgp_evpn_mh/torm11/pim.conf index fbba735873..a5d45dabc7 100644 --- a/tests/topotests/bgp_evpn_mh/torm11/pim.conf +++ b/tests/topotests/bgp_evpn_mh/torm11/pim.conf @@ -1,4 +1,10 @@ ! +#debug pim packet +#debug pim packet register +#debug pim trace +#debug pim event +#debug pim vxlan +ip pim ecmp ip pim rp 192.168.100.13 239.1.1.0/24 ip pim spt-switchover infinity-and-beyond ! diff --git a/tests/topotests/bgp_evpn_mh/torm12/pim.conf b/tests/topotests/bgp_evpn_mh/torm12/pim.conf index 3dd63b44ca..7e09ba7e21 100644 --- a/tests/topotests/bgp_evpn_mh/torm12/pim.conf +++ b/tests/topotests/bgp_evpn_mh/torm12/pim.conf @@ -1,4 +1,10 @@ +#debug pim packet +#debug pim packet register +#debug pim trace +#debug pim event +#debug pim vxlan ! +ip pim ecmp ip pim rp 192.168.100.13 239.1.1.0/24 ip pim spt-switchover infinity-and-beyond ! diff --git a/tests/topotests/bgp_evpn_mh/torm21/pim.conf b/tests/topotests/bgp_evpn_mh/torm21/pim.conf index 71aa91a06d..6996d74ad8 100644 --- a/tests/topotests/bgp_evpn_mh/torm21/pim.conf +++ b/tests/topotests/bgp_evpn_mh/torm21/pim.conf @@ -1,4 +1,10 @@ +#debug pim packet +#debug pim packet register +#debug pim trace +#debug pim event +#debug pim vxlan ! +ip pim ecmp ip pim rp 192.168.100.13 239.1.1.0/24 ip pim spt-switchover infinity-and-beyond ! diff --git a/tests/topotests/bgp_evpn_mh/torm22/pim.conf b/tests/topotests/bgp_evpn_mh/torm22/pim.conf index 46f330f5cd..6256e0e8cf 100644 --- a/tests/topotests/bgp_evpn_mh/torm22/pim.conf +++ b/tests/topotests/bgp_evpn_mh/torm22/pim.conf @@ -1,4 +1,10 @@ +#debug pim packet +#debug pim packet register +#debug pim trace +#debug pim event +#debug pim vxlan ! +ip pim ecmp ip pim rp 192.168.100.13 239.1.1.0/24 ip pim spt-switchover infinity-and-beyond ! diff --git a/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py b/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py index 1066269292..2041a4091d 100755 --- a/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py +++ b/tests/topotests/bgp_evpn_overlay_index_gateway/test_bgp_evpn_overlay_index_gateway.py @@ -58,7 +58,6 @@ step, write_test_header, write_test_footer, - generate_support_bundle, ) # Required to instantiate the topology builder class. @@ -277,8 +276,6 @@ def test_evpn_gateway_ip_basic_topo(request): result, assertmsg = evpn_gateway_ip_show_op_check("base") - if result is not None: - generate_support_bundle() assert result is None, assertmsg write_test_footer(tc_name) @@ -319,8 +316,6 @@ def test_evpn_gateway_ip_flap_rt5(request): ) result, assertmsg = evpn_gateway_ip_show_op_check("no_rt5") - if result is not None: - generate_support_bundle() assert result is None, assertmsg step("Advertise type-5 routes again") @@ -339,8 +334,6 @@ def test_evpn_gateway_ip_flap_rt5(request): ) result, assertmsg = evpn_gateway_ip_show_op_check("base") - if result is not None: - generate_support_bundle() assert result is None, assertmsg @@ -371,8 +364,6 @@ def test_evpn_gateway_ip_flap_rt2(request): pe1.cmd_raises("ip link set dev vxlan100 down") result, assertmsg = evpn_gateway_ip_show_op_check("no_rt2") - if result is not None: - generate_support_bundle() assert result is None, assertmsg step("Bring up VxLAN interface at PE1 and advertise type-2 routes again") @@ -380,8 +371,6 @@ def test_evpn_gateway_ip_flap_rt2(request): pe1.cmd_raises("ip link set dev vxlan100 up") result, assertmsg = evpn_gateway_ip_show_op_check("base") - if result is not None: - generate_support_bundle() assert result is None, assertmsg write_test_footer(tc_name) diff --git a/tests/topotests/bgp_evpn_route_map_match/__init__.py b/tests/topotests/bgp_evpn_route_map_match/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/bgp_evpn_route_map_match/c1/frr.conf b/tests/topotests/bgp_evpn_route_map_match/c1/frr.conf new file mode 100644 index 0000000000..7476a3723d --- /dev/null +++ b/tests/topotests/bgp_evpn_route_map_match/c1/frr.conf @@ -0,0 +1,4 @@ +! +int c1-eth0 + ip address 192.168.0.1/24 +! diff --git a/tests/topotests/bgp_evpn_route_map_match/c2/frr.conf b/tests/topotests/bgp_evpn_route_map_match/c2/frr.conf new file mode 100644 index 0000000000..a203daae05 --- /dev/null +++ b/tests/topotests/bgp_evpn_route_map_match/c2/frr.conf @@ -0,0 +1,4 @@ +! +int c2-eth0 + ip address 192.168.0.2/24 +! diff --git a/tests/topotests/bgp_evpn_route_map_match/r1/frr.conf b/tests/topotests/bgp_evpn_route_map_match/r1/frr.conf new file mode 100644 index 0000000000..33353a61f1 --- /dev/null +++ b/tests/topotests/bgp_evpn_route_map_match/r1/frr.conf @@ -0,0 +1,30 @@ +! +!debug bgp neighbor +! +int lo + ip address 10.10.10.1/32 +! +int r1-eth1 + ip address 192.168.1.1/24 +! +router bgp 65001 + no bgp ebgp-requires-policy + neighbor 192.168.1.2 remote-as external + neighbor 192.168.1.2 timers 1 3 + neighbor 192.168.1.2 timers connect 1 + ! + address-family ipv4 unicast + redistribute connected + exit-address-family + ! + address-family l2vpn evpn + neighbor 192.168.1.2 activate + neighbor 192.168.1.2 route-map r2 out + advertise-all-vni + exit-address-family +! +route-map r2 deny 10 + match evpn route-type macip +! +route-map r2 permit 20 +! diff --git a/tests/topotests/bgp_evpn_route_map_match/r2/frr.conf b/tests/topotests/bgp_evpn_route_map_match/r2/frr.conf new file mode 100644 index 0000000000..9ed298d8fe --- /dev/null +++ b/tests/topotests/bgp_evpn_route_map_match/r2/frr.conf @@ -0,0 +1,24 @@ +! +!debug bgp neighbor +! +int lo + ip address 10.10.10.2/32 +! +int r2-eth0 + ip address 192.168.1.2/24 +! +router bgp 65002 + no bgp ebgp-requires-policy + neighbor 192.168.1.1 remote-as external + neighbor 192.168.1.1 timers 1 3 + neighbor 192.168.1.1 timers connect 1 + ! + address-family ipv4 unicast + redistribute connected + exit-address-family + ! + address-family l2vpn evpn + neighbor 192.168.1.1 activate + advertise-all-vni + exit-address-family +! diff --git a/tests/topotests/bgp_evpn_route_map_match/test_bgp_evpn_route_map_match.py b/tests/topotests/bgp_evpn_route_map_match/test_bgp_evpn_route_map_match.py new file mode 100644 index 0000000000..18e25d5674 --- /dev/null +++ b/tests/topotests/bgp_evpn_route_map_match/test_bgp_evpn_route_map_match.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# Copyright (c) 2023 by +# Donatas Abraitis <donatas@opensourcerouting.org> +# + +""" +Test if route-map match by EVPN route-type works. +""" + +import os +import re +import sys +import json +import pytest +import functools + +pytestmark = pytest.mark.bgpd + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.common_config import step + +pytestmark = [pytest.mark.bgpd] + + +def setup_module(mod): + topodef = {"s1": ("c1", "r1"), "s2": ("r1", "r2"), "s3": ("r2", "c2")} + tgen = Topogen(topodef, mod.__name__) + tgen.start_topology() + + tgen.net["r1"].cmd( + """ +ip link add vxlan10 type vxlan id 10 dstport 4789 local 10.10.10.1 nolearning +ip link add name br10 type bridge +ip link set dev vxlan10 master br10 +ip link set dev r1-eth0 master br10 +ip link set up dev br10 +ip link set up dev vxlan10""" + ) + + tgen.net["r2"].cmd( + """ +ip link add vxlan10 type vxlan id 10 dstport 4789 local 10.10.10.2 nolearning +ip link add name br10 type bridge +ip link set dev vxlan10 master br10 +ip link set dev r2-eth1 master br10 +ip link set up dev br10 +ip link set up dev vxlan10""" + ) + + router_list = tgen.routers() + + for _, (rname, router) in enumerate(router_list.items(), 1): + router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname))) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_evpn_route_map_match_route_type(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + + def _bgp_converge(): + output = json.loads( + r1.vtysh_cmd( + "show bgp l2vpn evpn neighbor 192.168.1.2 advertised-routes json" + ) + ) + expected = { + "advertisedRoutes": { + "10.10.10.1:2": { + "[3]:[0]:[32]:[10.10.10.1]": { + "valid": True, + } + }, + "10.10.10.2:2": { + "[3]:[0]:[32]:[10.10.10.2]": { + "valid": True, + } + }, + }, + "totalPrefixCounter": 2, + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_converge, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assert result is None, "MAC-IP EVPN routes should not be advertised" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/P1/bgpd.conf b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/P1/bgpd.conf new file mode 100644 index 0000000000..cdf4cb4feb --- /dev/null +++ b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/P1/bgpd.conf @@ -0,0 +1 @@ +! diff --git a/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/P1/ospfd.conf b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/P1/ospfd.conf new file mode 100644 index 0000000000..2db7edb806 --- /dev/null +++ b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/P1/ospfd.conf @@ -0,0 +1,13 @@ +! +router ospf + network 10.20.0.0/16 area 0 + network 10.20.20.20/32 area 0 +! +int P1-eth0 + ip ospf hello-interval 2 + ip ospf dead-interval 10 +! +int P1-eth1 + ip ospf hello-interval 2 + ip ospf dead-interval 10 +! diff --git a/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/P1/zebra.conf b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/P1/zebra.conf new file mode 100644 index 0000000000..95b5da8402 --- /dev/null +++ b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/P1/zebra.conf @@ -0,0 +1,7 @@ +! +interface lo + ip address 10.20.20.20/32 +interface P1-eth0 + ip address 10.20.1.2/24 +interface P1-eth1 + ip address 10.20.2.2/24 diff --git a/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE1/bgp.l2vpn.evpn.vni.json b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE1/bgp.l2vpn.evpn.vni.json new file mode 100644 index 0000000000..9f93635c21 --- /dev/null +++ b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE1/bgp.l2vpn.evpn.vni.json @@ -0,0 +1,19 @@ +{ + "vni":101, + "type":"L2", + "inKernel":"True", + "rd":"10.10.10.10:101", + "originatorIp":"10.10.10.10", + "mcastGroup":"0.0.0.0", + "siteOfOrigin":"65000:0", + "advertiseGatewayMacip":"Disabled", + "advertiseSviMacIp":"Active", + "sviInterface":"br101", + "importRts":[ + "65000:101" + ], + "exportRts":[ + "65000:101" + ] +} + diff --git a/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE1/bgpd.conf b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE1/bgpd.conf new file mode 100644 index 0000000000..e4d20b9a50 --- /dev/null +++ b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE1/bgpd.conf @@ -0,0 +1,18 @@ +router bgp 65000 + timers bgp 3 9 + bgp router-id 10.10.10.10 + no bgp default ipv4-unicast + neighbor 10.30.30.30 remote-as 65000 + neighbor 10.30.30.30 update-source lo + neighbor 10.30.30.30 timers 3 10 + ! + address-family l2vpn evpn + neighbor 10.30.30.30 activate + advertise-all-vni + advertise-svi-ip + vni 101 + rd 10.10.10.10:101 + route-target import 65000:101 + route-target export 65000:101 + exit-vni + advertise-svi-ip diff --git a/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE1/evpn.vni.json b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE1/evpn.vni.json new file mode 100644 index 0000000000..4bea8b384f --- /dev/null +++ b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE1/evpn.vni.json @@ -0,0 +1,17 @@ +{ + "vni":101, + "type":"L2", + "tenantVrf":"VRF-A", + "vxlanInterface":"vxlan101", + "vtepIp":"10.10.10.10", + "mcastGroup":"0.0.0.0", + "advertiseGatewayMacip":"No", + "numRemoteVteps":1, + "remoteVteps":[ + { + "ip":"10.30.30.30", + "flood":"HER" + } + ] +} + diff --git a/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE1/ospfd.conf b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE1/ospfd.conf new file mode 100644 index 0000000000..f1c2b42dc1 --- /dev/null +++ b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE1/ospfd.conf @@ -0,0 +1,9 @@ +! +router ospf + network 10.20.0.0/16 area 0 + network 10.10.10.10/32 area 0 +! +int PE1-eth1 + ip ospf hello-interval 2 + ip ospf dead-interval 10 +! diff --git a/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE1/zebra.conf b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE1/zebra.conf new file mode 100644 index 0000000000..e2699475c9 --- /dev/null +++ b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE1/zebra.conf @@ -0,0 +1,8 @@ +! +log file zebra.log +! +interface lo + ip address 10.10.10.10/32 +interface PE1-eth1 + ip address 10.20.1.1/24 +! diff --git a/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE2/bgp.l2vpn.evpn.vni.json b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE2/bgp.l2vpn.evpn.vni.json new file mode 100644 index 0000000000..63ac730144 --- /dev/null +++ b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE2/bgp.l2vpn.evpn.vni.json @@ -0,0 +1,19 @@ +{ + "vni":101, + "type":"L2", + "inKernel":"True", + "rd":"10.30.30.30:101", + "originatorIp":"10.30.30.30", + "mcastGroup":"0.0.0.0", + "siteOfOrigin":"65000:0", + "advertiseGatewayMacip":"Disabled", + "advertiseSviMacIp":"Active", + "sviInterface":"br101", + "importRts":[ + "65000:101" + ], + "exportRts":[ + "65000:101" + ] +} + diff --git a/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE2/bgpd.conf b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE2/bgpd.conf new file mode 100644 index 0000000000..9a0830d8a3 --- /dev/null +++ b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE2/bgpd.conf @@ -0,0 +1,18 @@ +router bgp 65000 + timers bgp 3 9 + bgp router-id 10.30.30.30 + no bgp default ipv4-unicast + neighbor 10.10.10.10 remote-as 65000 + neighbor 10.10.10.10 update-source lo + neighbor 10.10.10.10 timers 3 10 + ! + address-family l2vpn evpn + neighbor 10.10.10.10 activate + advertise-all-vni + advertise-svi-ip + vni 101 + rd 10.30.30.30:101 + route-target import 65000:101 + route-target export 65000:101 + exit-vni + advertise-svi-ip diff --git a/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE2/evpn.vni.json b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE2/evpn.vni.json new file mode 100644 index 0000000000..5566fff954 --- /dev/null +++ b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE2/evpn.vni.json @@ -0,0 +1,16 @@ +{ + "vni":101, + "type":"L2", + "tenantVrf":"VRF-A", + "vxlanInterface":"vxlan101", + "vtepIp":"10.30.30.30", + "mcastGroup":"0.0.0.0", + "advertiseGatewayMacip":"No", + "numRemoteVteps":1, + "remoteVteps":[ + { + "ip":"10.10.10.10", + "flood":"HER" + } + ] +} diff --git a/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE2/ospfd.conf b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE2/ospfd.conf new file mode 100644 index 0000000000..065c993303 --- /dev/null +++ b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE2/ospfd.conf @@ -0,0 +1,9 @@ +! +router ospf + network 10.20.0.0/16 area 0 + network 10.30.30.30/32 area 0 +! +int PE2-eth0 + ip ospf hello-interval 2 + ip ospf dead-interval 10 +! diff --git a/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE2/zebra.conf b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE2/zebra.conf new file mode 100644 index 0000000000..9738916ab0 --- /dev/null +++ b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/PE2/zebra.conf @@ -0,0 +1,6 @@ +! +interface lo + ip address 10.30.30.30/32 +interface PE2-eth0 + ip address 10.20.2.3/24 +! diff --git a/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/host1/bgpd.conf b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/host1/bgpd.conf new file mode 100644 index 0000000000..cdf4cb4feb --- /dev/null +++ b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/host1/bgpd.conf @@ -0,0 +1 @@ +! diff --git a/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/host1/ospfd.conf b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/host1/ospfd.conf new file mode 100644 index 0000000000..cdf4cb4feb --- /dev/null +++ b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/host1/ospfd.conf @@ -0,0 +1 @@ +! diff --git a/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/host1/zebra.conf b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/host1/zebra.conf new file mode 100644 index 0000000000..91fae9eeba --- /dev/null +++ b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/host1/zebra.conf @@ -0,0 +1,3 @@ +! +int host1-eth0 + ip address 10.10.1.55/24 diff --git a/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/host2/bgpd.conf b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/host2/bgpd.conf new file mode 100644 index 0000000000..cdf4cb4feb --- /dev/null +++ b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/host2/bgpd.conf @@ -0,0 +1 @@ +! diff --git a/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/host2/ospfd.conf b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/host2/ospfd.conf new file mode 100644 index 0000000000..cdf4cb4feb --- /dev/null +++ b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/host2/ospfd.conf @@ -0,0 +1 @@ +! diff --git a/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/host2/zebra.conf b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/host2/zebra.conf new file mode 100644 index 0000000000..df9adeb3b5 --- /dev/null +++ b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/host2/zebra.conf @@ -0,0 +1,3 @@ +! +interface host2-eth0 + ip address 10.10.1.56/24 diff --git a/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/test_bgp_evpn_vxlan_macvrf_soo.py b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/test_bgp_evpn_vxlan_macvrf_soo.py new file mode 100755 index 0000000000..558f7379e9 --- /dev/null +++ b/tests/topotests/bgp_evpn_vxlan_macvrf_soo_topo1/test_bgp_evpn_vxlan_macvrf_soo.py @@ -0,0 +1,839 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: GPL-2.0-or-later +# +# test_bgp_evpn_vxlan_macvrf_soo.py +# +# May 10 2023, Trey Aspelund <taspelund@nvidia.com> +# +# Copyright (C) 2023 NVIDIA Corporation +# +# Test MAC-VRF Site-of-Origin feature. +# Ensure: +# - routes received with SoO are installed w/o "mac-vrf soo" config +# - invalid "mac-vrf soo" config is rejected +# - valid "mac-vrf soo" config is applied to local VNIs +# - valid "mac-vrf soo" is set for locally originated type-2/3 routes +# - routes received with SoO are unimported/uninstalled from L2VNI/zebra +# - routes received with SoO are unimported/uninstalled from L3VNI/RIB +# - routes received with SoO are still present in global EVPN loc-rib +# + +import os +import sys +import json +from functools import partial +from time import sleep +import pytest + +# Save the Current Working Directory to find configuration files. +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +# Import topogen and topotest helpers +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger +from lib.common_config import step + +pytestmark = [pytest.mark.bgpd, pytest.mark.ospfd] + + +def build_topo(tgen): + "Build function" + + # Create routers + tgen.add_router("P1") + tgen.add_router("PE1") + tgen.add_router("PE2") + tgen.add_router("host1") + tgen.add_router("host2") + + # Host1-PE1 + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["host1"]) + switch.add_link(tgen.gears["PE1"]) + + # PE1-P1 + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["PE1"]) + switch.add_link(tgen.gears["P1"]) + + # P1-PE2 + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["P1"]) + switch.add_link(tgen.gears["PE2"]) + + # PE2-host2 + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["PE2"]) + switch.add_link(tgen.gears["host2"]) + + +def setup_module(mod): + "Sets up the pytest environment" + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + + pe1 = tgen.gears["PE1"] + pe2 = tgen.gears["PE2"] + p1 = tgen.gears["P1"] + host1 = tgen.gears["host1"] + host2 = tgen.gears["host2"] + + # Setup PEs with: + # - vrf: VRF-A + # - l3vni 404: vxlan404 / br404 + # - l2vni 101: vxlan101 / br101 + + ## Setup VRF + # pe1 + pe1.run("ip link add VRF-A type vrf table 4000") + pe1.run("ip link set VRF-A up") + # pe2 + pe2.run("ip link add VRF-A type vrf table 4000") + pe2.run("ip link set VRF-A up") + + ## Setup L3VNI bridge/vxlan + # pe1 + pe1.run("ip link add name br404 type bridge stp_state 0") + pe1.run("ip link set dev br404 addr aa:bb:cc:00:11:ff") + pe1.run("ip link set dev br404 master VRF-A addrgenmode none") + pe1.run("ip link set dev br404 up") + pe1.run( + "ip link add vxlan404 type vxlan id 404 dstport 4789 local 10.10.10.10 nolearning" + ) + pe1.run("ip link set dev vxlan404 master br404 addrgenmode none") + pe1.run("ip link set dev vxlan404 type bridge_slave neigh_suppress on learning off") + pe1.run("ip link set dev vxlan404 up") + # pe2 + pe2.run("ip link add name br404 type bridge stp_state 0") + pe2.run("ip link set dev br404 addr aa:bb:cc:00:22:ff") + pe2.run("ip link set dev br404 master VRF-A addrgenmode none") + pe2.run("ip link set dev br404 up") + pe2.run( + "ip link add vxlan404 type vxlan id 404 dstport 4789 local 10.30.30.30 nolearning" + ) + pe2.run("ip link set dev vxlan404 master br404 addrgenmode none") + pe2.run("ip link set dev vxlan404 type bridge_slave neigh_suppress on learning off") + pe2.run("ip link set dev vxlan404 up") + + ## Setup L2VNI bridge/vxlan + L2 PE/CE link + # pe1 + pe1.run("ip link add name br101 type bridge stp_state 0") + pe1.run("ip addr add 10.10.1.1/24 dev br101") + pe1.run("ip link set dev br101 addr aa:bb:cc:00:11:aa") + pe1.run("ip link set dev br101 master VRF-A") + pe1.run("ip link set dev br101 up") + pe1.run( + "ip link add vxlan101 type vxlan id 101 dstport 4789 local 10.10.10.10 nolearning" + ) + pe1.run("ip link set dev vxlan101 master br101") + pe1.run("ip link set dev vxlan101 type bridge_slave neigh_suppress on learning off") + pe1.run("ip link set dev vxlan101 up") + pe1.run("ip link set dev PE1-eth0 master br101") + pe1.run("ip link set dev PE1-eth0 up") + # pe2 + pe2.run("ip link add name br101 type bridge stp_state 0") + pe2.run("ip addr add 10.10.1.3/24 dev br101") + pe2.run("ip link set dev br101 addr aa:bb:cc:00:22:ff") + pe2.run("ip link set dev br101 master VRF-A") + pe2.run("ip link set dev br101 up") + pe2.run( + "ip link add vxlan101 type vxlan id 101 dstport 4789 local 10.30.30.30 nolearning" + ) + pe2.run("ip link set dev vxlan101 master br101") + pe2.run("ip link set dev vxlan101 type bridge_slave neigh_suppress on learning off") + pe2.run("ip link set dev vxlan101 up") + pe2.run("ip link set dev PE2-eth1 master br101") + pe2.run("ip link set dev PE2-eth1 up") + + ## Enable IPv4 Routing + p1.run("sysctl -w net.ipv4.ip_forward=1") + pe1.run("sysctl -w net.ipv4.ip_forward=1") + pe2.run("sysctl -w net.ipv4.ip_forward=1") + + ## tell hosts to send GARP upon IPv4 addr assignment + host1.run("sysctl -w net.ipv4.conf.host1-eth0.arp_announce=1") + host2.run("sysctl -w net.ipv4.conf.host2-eth0.arp_announce=1") + + ## Load FRR config on all nodes and start topo + router_list = tgen.routers() + for rname, router in router_list.items(): + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_OSPF, os.path.join(CWD, "{}/ospfd.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) + ) + tgen.start_router() + + +def teardown_module(mod): + "Teardown the pytest environment" + tgen = get_topogen() + tgen.stop_topology() + + +def show_vni_json_elide_ifindex(pe, vni, expected): + output_json = pe.vtysh_cmd("show evpn vni {} json".format(vni), isjson=True) + if "ifindex" in output_json: + output_json.pop("ifindex") + + return topotest.json_cmp(output_json, expected) + + +def check_vni_macs_present(tgen, router, vni, maclist): + result = router.vtysh_cmd("show evpn mac vni {} json".format(vni), isjson=True) + for rname, ifname in maclist: + m = tgen.net.macs[(rname, ifname)] + if m not in result["macs"]: + return "MAC ({}) for interface {} on {} missing on {} from {}".format( + m, ifname, rname, router.name, json.dumps(result, indent=4) + ) + return None + + +def test_pe1_converge_evpn(): + "Wait for protocol convergence" + + tgen = get_topogen() + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + pe1 = tgen.gears["PE1"] + json_file = "{}/{}/evpn.vni.json".format(CWD, pe1.name) + expected = json.loads(open(json_file).read()) + + test_func = partial(show_vni_json_elide_ifindex, pe1, 101, expected) + _, result = topotest.run_and_expect(test_func, None, count=45, wait=1) + assertmsg = '"{}" JSON output mismatches'.format(pe1.name) + + # Let's ensure that the hosts have actually tried talking to + # each other. Otherwise under certain startup conditions + # they may not actually do any l2 arp'ing and as such + # the bridges won't know about the hosts on their networks + host1 = tgen.gears["host1"] + host1.run("ping -c 1 10.10.1.56") + host2 = tgen.gears["host2"] + host2.run("ping -c 1 10.10.1.55") + + test_func = partial( + check_vni_macs_present, + tgen, + pe1, + 101, + (("host1", "host1-eth0"), ("host2", "host2-eth0")), + ) + + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + if result: + logger.warning("%s", result) + assert None, '"{}" missing expected MACs'.format(pe1.name) + + +def test_pe2_converge_evpn(): + "Wait for protocol convergence" + + tgen = get_topogen() + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + pe2 = tgen.gears["PE2"] + json_file = "{}/{}/evpn.vni.json".format(CWD, pe2.name) + expected = json.loads(open(json_file).read()) + + test_func = partial(show_vni_json_elide_ifindex, pe2, 101, expected) + _, result = topotest.run_and_expect(test_func, None, count=45, wait=1) + assertmsg = '"{}" JSON output mismatches'.format(pe2.name) + assert result is None, assertmsg + + test_func = partial( + check_vni_macs_present, + tgen, + pe2, + 101, + (("host1", "host1-eth0"), ("host2", "host2-eth0")), + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + if result: + logger.warning("%s", result) + assert None, '"{}" missing expected MACs'.format(pe2.name) + + +def mac_learn_test(host, local): + "check the host MAC gets learned by the VNI" + + host_output = host.vtysh_cmd("show interface {}-eth0".format(host.name)) + int_lines = host_output.splitlines() + for line in int_lines: + line_items = line.split(": ") + if "HWaddr" in line_items[0]: + mac = line_items[1] + break + + mac_output = local.vtysh_cmd("show evpn mac vni 101 mac {} json".format(mac)) + mac_output_json = json.loads(mac_output) + assertmsg = "Local MAC output does not match interface mac {}".format(mac) + assert mac_output_json[mac]["type"] == "local", assertmsg + + +def mac_test_local_remote(local, remote): + "test MAC transfer between local and remote" + + local_output = local.vtysh_cmd("show evpn mac vni all json") + remote_output = remote.vtysh_cmd("show evpn mac vni all json") + local_output_vni = local.vtysh_cmd("show evpn vni detail json") + local_output_json = json.loads(local_output) + remote_output_json = json.loads(remote_output) + local_output_vni_json = json.loads(local_output_vni) + + for vni in local_output_json: + mac_list = local_output_json[vni]["macs"] + for mac in mac_list: + if mac_list[mac]["type"] == "local" and mac_list[mac]["intf"] != "br101": + assertmsg = "JSON output mismatches local: {} remote: {}".format( + local_output_vni_json[0]["vtepIp"], + remote_output_json[vni]["macs"][mac]["remoteVtep"], + ) + assert ( + remote_output_json[vni]["macs"][mac]["remoteVtep"] + == local_output_vni_json[0]["vtepIp"] + ), assertmsg + + +def test_learning_pe1(): + "test MAC learning on PE1" + + tgen = get_topogen() + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + host1 = tgen.gears["host1"] + pe1 = tgen.gears["PE1"] + mac_learn_test(host1, pe1) + + +def test_learning_pe2(): + "test MAC learning on PE2" + + tgen = get_topogen() + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + host2 = tgen.gears["host2"] + pe2 = tgen.gears["PE2"] + mac_learn_test(host2, pe2) + + +def test_local_remote_mac_pe1(): + "Test MAC transfer PE1 local and PE2 remote" + + tgen = get_topogen() + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + pe1 = tgen.gears["PE1"] + pe2 = tgen.gears["PE2"] + mac_test_local_remote(pe1, pe2) + + +def test_local_remote_mac_pe2(): + "Test MAC transfer PE2 local and PE1 remote" + + tgen = get_topogen() + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + pe1 = tgen.gears["PE1"] + pe2 = tgen.gears["PE2"] + mac_test_local_remote(pe2, pe1) + + +def ip_learn_test(tgen, host, local, remote, ip_addr): + "check the host IP gets learned by the VNI" + host_output = host.vtysh_cmd("show interface {}-eth0".format(host.name)) + int_lines = host_output.splitlines() + for line in int_lines: + line_items = line.split(": ") + if "HWaddr" in line_items[0]: + mac = line_items[1] + break + print(host_output) + + # check we have a local association between the MAC and IP + local_output = local.vtysh_cmd("show evpn mac vni 101 mac {} json".format(mac)) + print(local_output) + local_output_json = json.loads(local_output) + mac_type = local_output_json[mac]["type"] + assertmsg = "Failed to learn local IP address on host {}".format(host.name) + assert local_output_json[mac]["neighbors"] != "none", assertmsg + learned_ip = local_output_json[mac]["neighbors"]["active"][0] + + assertmsg = "local learned mac wrong type: {} ".format(mac_type) + assert mac_type == "local", assertmsg + + assertmsg = ( + "learned address mismatch with configured address host: {} learned: {}".format( + ip_addr, learned_ip + ) + ) + assert ip_addr == learned_ip, assertmsg + + # now lets check the remote + count = 0 + converged = False + while count < 30: + remote_output = remote.vtysh_cmd( + "show evpn mac vni 101 mac {} json".format(mac) + ) + print(remote_output) + remote_output_json = json.loads(remote_output) + type = remote_output_json[mac]["type"] + if not remote_output_json[mac]["neighbors"] == "none": + # due to a kernel quirk, learned IPs can be inactive + if ( + remote_output_json[mac]["neighbors"]["active"] + or remote_output_json[mac]["neighbors"]["inactive"] + ): + converged = True + break + count += 1 + sleep(1) + + print("tries: {}".format(count)) + assertmsg = "{} remote learned mac no address: {} ".format(host.name, mac) + # some debug for this failure + if not converged == True: + log_output = remote.run("cat zebra.log") + print(log_output) + + assert converged == True, assertmsg + if remote_output_json[mac]["neighbors"]["active"]: + learned_ip = remote_output_json[mac]["neighbors"]["active"][0] + else: + learned_ip = remote_output_json[mac]["neighbors"]["inactive"][0] + assertmsg = "remote learned mac wrong type: {} ".format(type) + assert type == "remote", assertmsg + + assertmsg = "remote learned address mismatch with configured address host: {} learned: {}".format( + ip_addr, learned_ip + ) + assert ip_addr == learned_ip, assertmsg + + +def test_ip_pe1_learn(): + "run the IP learn test for PE1" + + tgen = get_topogen() + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + host1 = tgen.gears["host1"] + pe1 = tgen.gears["PE1"] + pe2 = tgen.gears["PE2"] + # pe2.vtysh_cmd("debug zebra vxlan") + # pe2.vtysh_cmd("debug zebra kernel") + # lets populate that arp cache + host1.run("ping -c1 10.10.1.1") + ip_learn_test(tgen, host1, pe1, pe2, "10.10.1.55") + # tgen.mininet_cli() + + +def test_ip_pe2_learn(): + "run the IP learn test for PE2" + + tgen = get_topogen() + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + host2 = tgen.gears["host2"] + pe1 = tgen.gears["PE1"] + pe2 = tgen.gears["PE2"] + # pe1.vtysh_cmd("debug zebra vxlan") + # pe1.vtysh_cmd("debug zebra kernel") + # lets populate that arp cache + host2.run("ping -c1 10.10.1.3") + ip_learn_test(tgen, host2, pe2, pe1, "10.10.1.56") + # tgen.mininet_cli() + + +def is_installed(json_paths, soo): + """ + check if any path has been selected as best. + optionally check for matching SoO on bestpath. + """ + best = False + soo_present = False + for path in json_paths: + path = path[0] + # sometimes "bestpath" is a bool, other times it's a dict + # either way, the key isn't present when the bool is false... + # so we may as well just check for the key's existence + best = "bestpath" in path + path_keys = path.keys() + if best: + if soo: + soo_present = soo in path["extendedCommunity"]["string"] + break + return (best and soo_present) if soo else best + + +def change_soo(pe, soo, vni): + soo_cmd_str = "mac-vrf soo " + if soo: + soo_cmd_str += soo + else: + soo_cmd_str = "no " + soo_cmd_str + pe.vtysh_cmd( + """ + configure terminal + router bgp 65000 + address-family l2vpn evpn + {} + """.format( + soo_cmd_str + ) + ) + bgp_l2vni = get_bgp_l2vni_fields(pe, vni) + l2vni_soo = bgp_l2vni[2] + return l2vni_soo == soo + + +def get_evpn_rt_json_str(vni, rd, oip=None, mac=None, ip=None): + "convert evpn route fields into a route string + global/l2vni cli syntax" + # type-3 + if oip: + rt_str = "[3]:[0]:[32]:[{}]".format(oip) + global_rt_cmd = "show bgp l2vpn evpn route rd {} type 3 json".format(rd) + l2vni_rt_cmd = "show bgp vni {} type 3 vtep {} json".format(vni, oip) + # type-2 + else: + rt_str = "[2]:[0]:[48]:[{}]".format(mac) + global_rt_cmd = "show bgp l2vpn evpn route rd {} type 2".format(rd) + l2vni_rt_cmd = "show bgp vni {} type 2 mac {}".format(vni, mac) + if ip: + ip_len = 128 if ":" in ip else 32 + rt_str += ":[{}]:[{}]".format(ip_len, ip) + l2vni_rt_cmd = "show bgp vni {} type 2 ip {}".format(vni, ip) + global_rt_cmd += " json" + l2vni_rt_cmd += " json" + return [rt_str, global_rt_cmd, l2vni_rt_cmd] + + +def get_evpn_rt_json(pe, vni, rd, oip=None, mac=None, ip=None): + "get json global/l2vni json blobs for the corresponding evpn route" + rt = get_evpn_rt_json_str(vni, rd, oip, mac, ip) + rt_str = rt.pop(0) + global_rt_cmd = rt.pop(0) + l2vni_rt_cmd = rt.pop(0) + logger.info( + "collecting global/l2vni evpn routes for pfx {} on {}".format(rt_str, pe.name) + ) + global_rt_json = pe.vtysh_cmd(global_rt_cmd, isjson=True) + logger.info("global evpn route for pfx {} on {}".format(rt_str, pe.name)) + logger.info(global_rt_json) + l2vni_rt_json = pe.vtysh_cmd(l2vni_rt_cmd, isjson=True) + logger.info("l2vni evpn route for pfx {} on {}".format(rt_str, pe.name)) + logger.info(l2vni_rt_json) + return [rt_str, global_rt_json, l2vni_rt_json] + + +def get_bgp_l2vni_fields(pe, vni): + bgp_vni_output = pe.vtysh_cmd( + "show bgp l2vpn evpn vni {} json".format(vni), isjson=True + ) + rd = bgp_vni_output["rd"] + oip = bgp_vni_output["originatorIp"] + soo = bgp_vni_output["siteOfOrigin"] + return [rd, oip, soo] + + +def rt_test(pe, vni, rd, oip, mac, ip, soo): + """ + Check installation status of a given route. + @pe = router where bgp routes are collected from + @vni = l2vni + @rd = rd of the route + @oip = originator-ip, set only for type-3 route + @mac = nlri mac, set only for type-2 + @ip = nlri ip, optionally set for type-2 + @soo = MAC-VRF SoO string, set if SoO needs to be + on the rt to be considered installed. + """ + rt = get_evpn_rt_json(pe, vni, rd, oip, mac, ip) + rt_str = rt.pop(0) + rt_global_json = rt.pop(0) + rt_l2vni_json = rt.pop(0) + + if ( + not rt_global_json + or rd not in rt_global_json + or rt_str not in rt_global_json[rd] + ): + global_installed = False + else: + global_json_paths = rt_global_json[rd][rt_str]["paths"] + global_installed = is_installed(global_json_paths, soo) + if not rt_l2vni_json: + l2vni_installed = False + else: + if not oip: + # json for RT2s in l2vni don't key by route string + l2vni_json_paths = rt_l2vni_json["paths"] + l2vni_installed = is_installed(l2vni_json_paths, soo) + elif rt_str in rt_l2vni_json and "paths" in rt_l2vni_json[rt_str]: + l2vni_json_paths = rt_l2vni_json[rt_str]["paths"] + l2vni_installed = is_installed(l2vni_json_paths, soo) + else: + l2vni_installed = False + return [global_installed, l2vni_installed] + + +def test_macvrf_soo(): + "Test MAC-VRF Site-of-Origin on pe1" + l2vni = 101 + l3vni = 404 + soo = "65000:0" + + tgen = get_topogen() + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + host1 = tgen.gears["host1"] + host2 = tgen.gears["host2"] + pe1 = tgen.gears["PE1"] + pe2 = tgen.gears["PE2"] + + # Collect pe2 RD/Originator-IP + pe2_bgp_vni = get_bgp_l2vni_fields(pe2, l2vni) + pe2_rd = pe2_bgp_vni[0] + pe2_oip = pe2_bgp_vni[1] + # Collect local addrs + h2_mac = host2.run("ip -br link show host2-eth0").split()[2] + h2_ip = host2.run("ip -4 -br addr show host2-eth0").split()[2].split("/")[0] + pe2_mac = pe2.run("ip -br link show br101").split()[2] + pe2_ip = pe2.run("ip -4 -br addr show br101").split()[2].split("/")[0] + # Route fields + pe2_svi_parms = [l2vni, pe2_rd, None, pe2_mac, pe2_ip] + pe2_imet_parms = [l2vni, pe2_rd, pe2_oip, None, None] + host2_mac_parms = [l2vni, pe2_rd, None, h2_mac, None] + host2_neigh_parms = [l2vni, pe2_rd, None, h2_mac, h2_ip] + # Route strings + pe2_svi_rt_str, _, _ = get_evpn_rt_json_str(*pe2_svi_parms) + pe2_imet_rt_str, _, _ = get_evpn_rt_json_str(*pe2_imet_parms) + host2_mac_rt_str, _, _ = get_evpn_rt_json_str(*host2_mac_parms) + host2_neigh_rt_str, _, _ = get_evpn_rt_json_str(*host2_neigh_parms) + + ## trigger mac/arp learn + host1.run("ping -c1 10.10.1.1") + host2.run("ping -c1 10.10.1.3") + + step("Test pe2/host2 routes are installed on pe1 (global/l2vni)") + + # expected state: + # - global table: present w/o soo + # - l2vni table: present w/o soo + assertmsg = "{} missing on {} in {}{} evpn table(s)" + global_parms = [pe2.name, "global", ""] + l2vni_parms = [pe2.name, "l2vni", l2vni] + # pe2's type-2 for l2vni 101 svi mac/ip + test_f = partial(rt_test, pe2, *pe2_svi_parms, None) + _, res = topotest.run_and_expect(test_f, [True, True], count=30, wait=1) + assert res[0] == True, assertmsg.format(pe2_svi_rt_str, *global_parms) + assert res[1] == True, assertmsg.format(pe2_svi_rt_str, *l2vni_parms) + # pe2's type-3 for l2vni 101 + test_f = partial(rt_test, pe2, *pe2_imet_parms, None) + _, res = topotest.run_and_expect(test_f, [True, True], count=30, wait=1) + assert res[0] == True, assertmsg.format(pe2_imet_rt_str, *global_parms) + assert res[1] == True, assertmsg.format(pe2_imet_rt_str, *l2vni_parms) + # mac-only type-2 for host2 + test_f = partial(rt_test, pe1, *host2_mac_parms, None) + _, res = topotest.run_and_expect(test_f, [True, True], count=30, wait=1) + assert res[0] == True, assertmsg.format(host2_mac_rt_str, *global_parms) + assert res[1] == True, assertmsg.format(host2_mac_rt_str, *l2vni_parms) + # mac+ip type-2 for host2 + test_f = partial(rt_test, pe1, *host2_neigh_parms, None) + _, res = topotest.run_and_expect(test_f, [True, True], count=30, wait=1) + assert res[0] == True, assertmsg.format(host2_neigh_rt_str, *global_parms) + assert res[1] == True, assertmsg.format(host2_neigh_rt_str, *l2vni_parms) + + step("Add valid SoO config to pe2") + test_f = partial(change_soo, pe2, soo, l2vni) + _, res = topotest.run_and_expect(test_f, True, count=10, wait=1) + assertmsg = "soo '{}' not properly applied on {}".format(soo, pe2.name) + assert res == True, assertmsg + + step("Test valid config applied to L2VNI on pe2") + ## expected state: + ## - global table: present w/ soo + ## - l2vni table: present w/ soo + assertmsg = "{} not originated with soo {} by {} in {}{} evpn table(s)" + global_parms = [soo, pe2.name, "global", ""] + l2vni_parms = [soo, pe2.name, "l2vni", l2vni] + # type-2 for l2vni 101 svi mac/ip + test_f = partial(rt_test, pe2, *pe2_svi_parms, soo) + _, res = topotest.run_and_expect(test_f, [True, True], count=30, wait=1) + assert res[0] == True, assertmsg.format(pe2_svi_rt_str, *global_parms) + assert res[1] == True, assertmsg.format(pe2_svi_rt_str, *l2vni_parms) + # type-3 for l2vni 101 + test_f = partial(rt_test, pe2, *pe2_imet_parms, soo) + _, res = topotest.run_and_expect(test_f, [True, True], count=30, wait=1) + assert res[0] == True, assertmsg.format(pe2_imet_rt_str, *global_parms) + assert res[1] == True, assertmsg.format(pe2_imet_rt_str, *l2vni_parms) + + step("Test invalid SoO config on pe2") + test_f = partial(change_soo, pe2, "1:1:1", l2vni) + _, res = topotest.run_and_expect(test_f, False, count=10, wait=1) + assertmsg = "soo '1:1:1' should not have been allowed on {}".format(pe2.name) + assert res == False, assertmsg + + step("Test valid SoO applied to host2 routes (mac-only + mac/ip) on pe2") + + ## expected state: + ## - global table: present w/ soo + ## - l2vni table: present w/ soo + assertmsg = "{} not originated with soo {} by {} in {}{} evpn table(s)" + global_parms = [soo, pe1.name, "global", ""] + l2vni_parms = [soo, pe1.name, "l2vni", l2vni] + # mac-only type-2 for host2 + test_f = partial(rt_test, pe2, *host2_mac_parms, soo) + _, res = topotest.run_and_expect(test_f, [True, True], count=30, wait=1) + assert res[0] == True, assertmsg.format(host2_mac_rt_str, *global_parms) + assert res[1] == True, assertmsg.format(host2_mac_rt_str, *l2vni_parms) + # mac+ip type-2 for host2 + test_f = partial(rt_test, pe2, *host2_neigh_parms, soo) + _, res = topotest.run_and_expect(test_f, [True, True], count=30, wait=1) + assert res[0] == True, assertmsg.format(host2_neigh_rt_str, *global_parms) + assert res[1] == True, assertmsg.format(host2_neigh_rt_str, *l2vni_parms) + + step("Add valid SoO to pe1") + test_f = partial(change_soo, pe1, soo, l2vni) + _, res = topotest.run_and_expect(test_f, True, count=10, wait=1) + assertmsg = "soo '{}' not properly applied on {}".format(soo, pe1.name) + assert res == True, assertmsg + + step("Test pe2's routes are filtered from l2vni on pe1.") + ## expected state: + ## - global table: present w/ soo + ## - l2vni table: not present + global_assertmsg = "{} with soo {} from {} missing from global evpn table" + l2vni_assertmsg = "{} with soo {} from {} not filtered from {}{} evpn table" + global_parms = [soo, pe1.name, "global", ""] + l2vni_parms = [soo, pe1.name, "l2vni", l2vni] + # pe2's svi route + test_f = partial(rt_test, pe1, *pe2_svi_parms, soo) + _, res = topotest.run_and_expect(test_f, [True, False], count=30, wait=1) + assert res[0] == True, global_assertmsg.format(pe2_svi_rt_str, *global_parms) + assert res[1] == False, l2vni_assertmsg.format(pe2_svi_rt_str, *l2vni_parms) + # pe2's imet route + test_f = partial(rt_test, pe1, *pe2_imet_parms, soo) + _, res = topotest.run_and_expect(test_f, [True, False], count=30, wait=1) + assert res[0] == True, global_assertmsg.format(pe2_imet_rt_str, *global_parms) + assert res[1] == False, l2vni_assertmsg.format(pe2_imet_rt_str, *l2vni_parms) + # mac-only type-2 for host2 + test_f = partial(rt_test, pe1, *host2_mac_parms, soo) + _, res = topotest.run_and_expect(test_f, [True, False], count=30, wait=1) + assert res[0] == True, global_assertmsg.format(host2_mac_rt_str, *global_parms) + assert res[1] == False, l2vni_assertmsg.format(host2_mac_rt_str, *l2vni_parms) + # mac+ip type-2 for host2 + test_f = partial(rt_test, pe1, *host2_neigh_parms, soo) + _, res = topotest.run_and_expect(test_f, [True, False], count=30, wait=1) + assert res[0] == True, global_assertmsg.format(host2_neigh_rt_str, *global_parms) + assert res[1] == False, l2vni_assertmsg.format(host2_neigh_rt_str, *l2vni_parms) + + step("Remove SoO from pe1") + test_f = partial(change_soo, pe1, "", l2vni) + _, res = topotest.run_and_expect(test_f, True, count=10, wait=1) + assertmsg = "soo '{}' not properly removed from {}".format(soo, pe1.name) + assert res == True, assertmsg + + step("Test pe2/host2 routes are installed on pe1 (global/l2vni)") + ## expected state: + ## - global table: present w/ soo + ## - l2vni table: present w/ soo + assertmsg = "{} with soo {} missing on {} in {}{} evpn table" + global_parms = [soo, pe1.name, "global", ""] + l2vni_parms = [soo, pe1.name, "l2vni", l2vni] + # pe2's type-2 for l2vni 101 svi mac/ip + test_f = partial(rt_test, pe1, *pe2_svi_parms, soo) + _, res = topotest.run_and_expect(test_f, [True, True], count=30, wait=1) + assert res[0] == True, assertmsg.format(pe2_svi_rt_str, *global_parms) + assert res[1] == True, assertmsg.format(pe2_svi_rt_str, *l2vni_parms) + # pe2's type-3 for l2vni 101 + test_f = partial(rt_test, pe1, *pe2_imet_parms, soo) + _, res = topotest.run_and_expect(test_f, [True, True], count=30, wait=1) + assert res[0] == True, assertmsg.format(pe2_imet_rt_str, *global_parms) + assert res[1] == True, assertmsg.format(pe2_imet_rt_str, *l2vni_parms) + # mac-only type-2 for host2 + test_f = partial(rt_test, pe1, *host2_mac_parms, soo) + _, res = topotest.run_and_expect(test_f, [True, True], count=30, wait=1) + assert res[0] == True, assertmsg.format(host2_mac_rt_str, *global_parms) + assert res[1] == True, assertmsg.format(host2_mac_rt_str, *l2vni_parms) + # mac+ip type-2 for host2 + test_f = partial(rt_test, pe1, *host2_neigh_parms, soo) + _, res = topotest.run_and_expect(test_f, [True, True], count=30, wait=1) + assert res[0] == True, assertmsg.format(host2_neigh_rt_str, *global_parms) + assert res[1] == True, assertmsg.format(host2_neigh_rt_str, *l2vni_parms) + + step("Remove SoO from pe2") + test_f = partial(change_soo, pe2, "", l2vni) + _, res = topotest.run_and_expect(test_f, True, count=10, wait=1) + assertmsg = "soo '{}' not properly removed from {}".format(soo, pe2.name) + assert res == True, assertmsg + + step("Test pe2's 'self' routes are installed on pe1 (global/l2vni)") + ## expected state: + ## - global table: present w/o soo + ## - l2vni table: present w/o soo + assertmsg = "{} missing on {} in {}{} evpn table(s)" + global_parms = [pe1.name, "global", ""] + l2vni_parms = [pe1.name, "l2vni", l2vni] + # pe2's type-2 for l2vni 101 svi mac/ip + test_f = partial(rt_test, pe1, *pe2_svi_parms, None) + _, res = topotest.run_and_expect(test_f, [True, True], count=30, wait=1) + assert res[0] == True, assertmsg.format(pe2_svi_rt_str, *global_parms) + assert res[1] == True, assertmsg.format(pe2_svi_rt_str, *l2vni_parms) + # pe2's type-3 for l2vni 101 + test_f = partial(rt_test, pe1, *pe2_imet_parms, None) + _, res = topotest.run_and_expect(test_f, [True, True], count=30, wait=1) + assert res[0] == True, assertmsg.format(pe2_imet_rt_str, *global_parms) + assert res[1] == True, assertmsg.format(pe2_imet_rt_str, *l2vni_parms) + # mac-only type-2 for host2 + test_f = partial(rt_test, pe1, *host2_mac_parms, None) + _, res = topotest.run_and_expect(test_f, [True, True], count=30, wait=1) + assert res[0] == True, assertmsg.format(host2_mac_rt_str, *global_parms) + assert res[1] == True, assertmsg.format(host2_mac_rt_str, *l2vni_parms) + # mac+ip type-2 for host2 + test_f = partial(rt_test, pe1, *host2_neigh_parms, None) + _, res = topotest.run_and_expect(test_f, [True, True], count=30, wait=1) + assert res[0] == True, assertmsg.format(host2_neigh_rt_str, *global_parms) + assert res[1] == True, assertmsg.format(host2_neigh_rt_str, *l2vni_parms) + + # tgen.mininet_cli() + + +def test_memory_leak(): + "Run the memory leak test and report results." + tgen = get_topogen() + if not tgen.is_memleak_enabled(): + pytest.skip("Memory leak test/report is disabled") + + tgen.report_memory_leaks() + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_evpn_vxlan_svd_topo1/PE1/bgpd.conf b/tests/topotests/bgp_evpn_vxlan_svd_topo1/PE1/bgpd.conf index 39ac8ca69c..9fb2bd6835 100644 --- a/tests/topotests/bgp_evpn_vxlan_svd_topo1/PE1/bgpd.conf +++ b/tests/topotests/bgp_evpn_vxlan_svd_topo1/PE1/bgpd.conf @@ -1,5 +1,5 @@ router bgp 65000 - timers 3 9 + timers bgp 3 9 bgp router-id 10.10.10.10 no bgp default ipv4-unicast neighbor 10.30.30.30 remote-as 65000 diff --git a/tests/topotests/bgp_evpn_vxlan_topo1/PE1/bgpd.conf b/tests/topotests/bgp_evpn_vxlan_topo1/PE1/bgpd.conf index 991a1e7e56..dbbfc82db9 100644 --- a/tests/topotests/bgp_evpn_vxlan_topo1/PE1/bgpd.conf +++ b/tests/topotests/bgp_evpn_vxlan_topo1/PE1/bgpd.conf @@ -1,5 +1,5 @@ router bgp 65000 - timers 3 9 + timers bgp 3 9 bgp router-id 10.10.10.10 no bgp default ipv4-unicast neighbor 10.30.30.30 remote-as 65000 diff --git a/tests/topotests/bgp_extcomm_list_delete/__init__.py b/tests/topotests/bgp_extcomm_list_delete/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/bgp_extcomm_list_delete/r1/bgpd.conf b/tests/topotests/bgp_extcomm_list_delete/r1/bgpd.conf new file mode 100644 index 0000000000..3394c1c568 --- /dev/null +++ b/tests/topotests/bgp_extcomm_list_delete/r1/bgpd.conf @@ -0,0 +1,20 @@ +router bgp 65000 + no bgp ebgp-requires-policy + no bgp network import-check + neighbor 192.168.255.2 remote-as 65001 + address-family ipv4 unicast + network 10.10.10.1/32 route-map r2-out-rt + network 10.10.10.2/32 route-map r2-out-soo + network 10.10.10.3/32 route-map r2-out-nt + redistribute connected + exit-address-family +! +route-map r2-out-rt permit 10 + set extcommunity rt 1.1.1.1:1 2.2.2.2:2 3.3.3.3:3 4.4.4.4:4 +! +route-map r2-out-soo permit 20 + set extcommunity soo 1.1.1.1:1 2.2.2.2:2 3.3.3.3:3 4.4.4.4:4 +! +route-map r2-out-nt permit 30 + set extcommunity nt 192.168.255.2:0 2.2.2.2:0 3.3.3.3:0 4.4.4.4:0 +! diff --git a/tests/topotests/bgp_extcomm_list_delete/r1/zebra.conf b/tests/topotests/bgp_extcomm_list_delete/r1/zebra.conf new file mode 100644 index 0000000000..e2c399e536 --- /dev/null +++ b/tests/topotests/bgp_extcomm_list_delete/r1/zebra.conf @@ -0,0 +1,6 @@ +! +interface r1-eth0 + ip address 192.168.255.1/24 +! +ip forwarding +! diff --git a/tests/topotests/bgp_extcomm_list_delete/r2/bgpd.conf b/tests/topotests/bgp_extcomm_list_delete/r2/bgpd.conf new file mode 100644 index 0000000000..ca497e6e05 --- /dev/null +++ b/tests/topotests/bgp_extcomm_list_delete/r2/bgpd.conf @@ -0,0 +1,10 @@ +router bgp 65001 + no bgp ebgp-requires-policy + neighbor 192.168.255.1 remote-as 65000 + neighbor 192.168.255.1 timers 3 10 + address-family ipv4 + neighbor 192.168.255.1 route-map r1-in in + exit-address-family +! +route-map r1-in permit 10 +! diff --git a/tests/topotests/bgp_extcomm_list_delete/r2/zebra.conf b/tests/topotests/bgp_extcomm_list_delete/r2/zebra.conf new file mode 100644 index 0000000000..606c17bec9 --- /dev/null +++ b/tests/topotests/bgp_extcomm_list_delete/r2/zebra.conf @@ -0,0 +1,6 @@ +! +interface r2-eth0 + ip address 192.168.255.2/24 +! +ip forwarding +! diff --git a/tests/topotests/bgp_extcomm_list_delete/test_bgp_extcomm-list_delete.py b/tests/topotests/bgp_extcomm_list_delete/test_bgp_extcomm-list_delete.py new file mode 100644 index 0000000000..eb05986fe1 --- /dev/null +++ b/tests/topotests/bgp_extcomm_list_delete/test_bgp_extcomm-list_delete.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC +# +# Copyright 2023 6WIND S.A. +# Authored by Farid Mihoub <farid.mihoub@6wind.com> +# + +""" +bgp_extcomm_list-delete.py: + +Test the following commands: +route-map test permit 10 + set extended-comm-list <arg> delete +""" + +import functools +import json +import os +import pytest +import re +import sys + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger +from lib import topotest + + +pytestmark = [pytest.mark.bgpd] + + +def build_topo(tgen): + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + +def setup_module(mod): + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for i, (rname, router) in enumerate(router_list.items(), 1): + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) + ) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_convergence(): + tgen = get_topogen() + r2 = tgen.gears["r2"] + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + def _bgp_converge(): + output = json.loads(r2.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) + expected = { + "192.168.255.1": { + "bgpState": "Established", + "addressFamilyInfo": { + "ipv4Unicast": { + "acceptedPrefixCounter": 4, + } + }, + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_converge) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Can't converge initially" + + +def _set_extcomm_list(gear, ecom_t, ecom): + "Set the extended community for deletion." + cmd = [ + "con t\n", + f"bgp extcommunity-list standard r1-{ecom_t} permit {ecom_t} {ecom}\n", + f"route-map r1-in permit 10\n", + f"set extended-comm-list r1-{ecom_t} delete\n", + ] + gear.vtysh_cmd("".join(cmd)) + + +def _bgp_extcomm_list_del_check(gear, prefix, ecom): + """ + Check the non-presense of the extended community for the given prefix. + """ + # get the extended community list attribute for the given prefix + output = json.loads(gear.vtysh_cmd(f"show ip bgp {prefix} json")) + ecoms = output.get("paths", [])[0].get("extendedCommunity", {}) + ecoms = ecoms.get("string") + + # ecoms might be None at the first time + if not ecoms: + return False + return re.search(ecom, ecoms) is None + + +def test_rt_extcomm_list_delete(): + tgen = get_topogen() + r2 = tgen.gears["r2"] + + # set the extended community for deletion + _set_extcomm_list(r2, "rt", "1.1.1.1:1") + + # check for the deletion of the extended community + test_func = functools.partial( + _bgp_extcomm_list_del_check, r2, "10.10.10.1/32", r"1.1.1.1:1") + _, result = topotest.run_and_expect(test_func, True, count=60, wait=0.5) + assert result, "RT extended community 1.1.1.1:1 was not stripped." + + +def test_soo_extcomm_list_delete(): + tgen = get_topogen() + r2 = tgen.gears["r2"] + + # set the extended community for deletion + _set_extcomm_list(r2, "soo", "2.2.2.2:2") + + # check for the deletion of the extended community + test_func = functools.partial( + _bgp_extcomm_list_del_check, r2, "10.10.10.2/32", r"2.2.2.2:2") + _, result = topotest.run_and_expect(test_func, True, count=60, wait=0.5) + assert result, "SoO extended community 2.2.2.2:2 was not stripped." + + +def test_nt_extcomm_list_delete(): + tgen = get_topogen() + r2 = tgen.gears["r2"] + + # set the extended community for deletion + _set_extcomm_list(r2, "nt", "3.3.3.3:0") + + # check for the deletion of the extended community + test_func = functools.partial( + _bgp_extcomm_list_del_check, r2, "10.10.10.3/32", r"3.3.3.3") + _, result = topotest.run_and_expect(test_func, True, count=60, wait=0.5) + assert result, "NT extended community 3.3.3.3:0 was not stripped." + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_features/r1/ospf6d.conf b/tests/topotests/bgp_features/r1/ospf6d.conf index 9afc6f4919..3e6196ecaf 100644 --- a/tests/topotests/bgp_features/r1/ospf6d.conf +++ b/tests/topotests/bgp_features/r1/ospf6d.conf @@ -3,19 +3,19 @@ log file ospf6d.log ! debug ospf6 neighbor ! interface r1-lo + ipv6 ospf6 area 0.0.0.0 ! interface r1-eth1 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 priority 10 ! interface r1-eth2 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 priority 10 ! router ospf6 ospf6 router-id 192.168.0.1 log-adjacency-changes - interface r1-lo area 0.0.0.0 - interface r1-eth1 area 0.0.0.0 - interface r1-eth2 area 0.0.0.0 ! line vty ! diff --git a/tests/topotests/bgp_features/r1/zebra.conf b/tests/topotests/bgp_features/r1/zebra.conf index 61564f1a1a..a4e51fdf58 100644 --- a/tests/topotests/bgp_features/r1/zebra.conf +++ b/tests/topotests/bgp_features/r1/zebra.conf @@ -26,3 +26,4 @@ interface r1-eth3 ip address 192.168.101.1/24 ipv6 address fc00:100:0:1::1/64 ! +no ip nht resolve-via-default diff --git a/tests/topotests/bgp_features/r2/ospf6d.conf b/tests/topotests/bgp_features/r2/ospf6d.conf index 7fe535651e..56aecd006c 100644 --- a/tests/topotests/bgp_features/r2/ospf6d.conf +++ b/tests/topotests/bgp_features/r2/ospf6d.conf @@ -3,19 +3,19 @@ log file ospf6d.log ! debug ospf6 neighbor ! interface r2-lo + ipv6 ospf6 area 0.0.0.0 ! interface r2-eth1 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 priority 5 ! interface r2-eth2 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 priority 10 ! router ospf6 ospf6 router-id 192.168.0.2 log-adjacency-changes - interface r2-lo area 0.0.0.0 - interface r2-eth1 area 0.0.0.0 - interface r2-eth2 area 0.0.0.0 ! line vty ! diff --git a/tests/topotests/bgp_features/r3/ospf6d.conf b/tests/topotests/bgp_features/r3/ospf6d.conf index 07325b69b0..f15b9d9ea5 100644 --- a/tests/topotests/bgp_features/r3/ospf6d.conf +++ b/tests/topotests/bgp_features/r3/ospf6d.conf @@ -3,19 +3,19 @@ log file ospf6d.log ! debug ospf6 neighbor ! interface r3-lo + ipv6 ospf6 area 0.0.0.0 ! interface r3-eth1 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 priority 5 ! interface r3-eth2 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 priority 5 ! router ospf6 ospf6 router-id 192.168.0.3 log-adjacency-changes - interface r3-lo area 0.0.0.0 - interface r3-eth1 area 0.0.0.0 - interface r3-eth2 area 0.0.0.0 ! line vty ! diff --git a/tests/topotests/bgp_features/test_bgp_features.py b/tests/topotests/bgp_features/test_bgp_features.py index e033a0f005..43f4905d41 100644 --- a/tests/topotests/bgp_features/test_bgp_features.py +++ b/tests/topotests/bgp_features/test_bgp_features.py @@ -1063,7 +1063,7 @@ def test_bgp_delayopen_dual(): delay_stop = int(time.time()) assertmsg = "BGP peering between r2 and r5 was established before DelayOpenTimer (30sec) on r2 could expire" - assert (delay_stop - delay_start) > 30, assertmsg + assert (delay_stop - delay_start) >= 30, assertmsg # 3.8 unset delayopen on R2 and R5 logger.info("Disabling DelayOpenTimer for neighbor r5 on r2") diff --git a/tests/topotests/bgp_flowspec/peer1/exabgp.cfg b/tests/topotests/bgp_flowspec/peer1/exabgp.cfg index cd1fae5aba..383a95b6dd 100644 --- a/tests/topotests/bgp_flowspec/peer1/exabgp.cfg +++ b/tests/topotests/bgp_flowspec/peer1/exabgp.cfg @@ -1,5 +1,6 @@ neighbor 10.0.1.1 { router-id 10.0.1.101; +hold-time 10; local-address 10.0.1.101; local-as 100; peer-as 100; diff --git a/tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py b/tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py index fd675dc8ae..57aeea87cb 100644 --- a/tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py +++ b/tests/topotests/bgp_flowspec/test_bgp_flowspec_topo.py @@ -137,7 +137,7 @@ def test_bgp_convergence(): test_func = functools.partial( topotest.router_json_cmp, router, "show bgp summary json", expected ) - _, res = topotest.run_and_expect(test_func, None, count=90, wait=0.5) + _, res = topotest.run_and_expect(test_func, None, count=210, wait=1) assertmsg = "BGP router network did not converge" assert res is None, assertmsg @@ -183,7 +183,6 @@ def test_bgp_flowspec(): if __name__ == "__main__": - args = ["-s"] + sys.argv[1:] ret = pytest.main(args) diff --git a/tests/topotests/bgp_gr_functionality_topo3/bgp_gr_functionality_topo3.py b/tests/topotests/bgp_gr_functionality_topo3/test_bgp_gr_functionality_topo3.py similarity index 100% rename from tests/topotests/bgp_gr_functionality_topo3/bgp_gr_functionality_topo3.py rename to tests/topotests/bgp_gr_functionality_topo3/test_bgp_gr_functionality_topo3.py diff --git a/tests/topotests/bgp_l3vpn_label_export/__init__.py b/tests/topotests/bgp_l3vpn_label_export/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/bgp_l3vpn_label_export/r1/bgpd.conf b/tests/topotests/bgp_l3vpn_label_export/r1/bgpd.conf new file mode 100644 index 0000000000..bb1ed4c1ea --- /dev/null +++ b/tests/topotests/bgp_l3vpn_label_export/r1/bgpd.conf @@ -0,0 +1,22 @@ +router bgp 65001 + bgp router-id 192.0.2.1 + no bgp default ipv4-unicast + no bgp ebgp-requires-policy + neighbor 192.0.2.2 remote-as 65002 + neighbor 192.0.2.2 timers 1 3 + neighbor 192.0.2.2 timers connect 1 + neighbor 192.0.2.2 ebgp-multihop 2 + address-family ipv4 vpn + neighbor 192.0.2.2 activate + exit-address-family +! +router bgp 65001 vrf vrf1 + address-family ipv4 unicast + redistribute connected + label vpn export 1111 + rd vpn export 101:1 + rt vpn both 52:100 + import vpn + export vpn + exit-address-family +! diff --git a/tests/topotests/bgp_l3vpn_label_export/r1/ldpd.conf b/tests/topotests/bgp_l3vpn_label_export/r1/ldpd.conf new file mode 100644 index 0000000000..04ae06877a --- /dev/null +++ b/tests/topotests/bgp_l3vpn_label_export/r1/ldpd.conf @@ -0,0 +1,26 @@ +hostname r1 +log file ldpd.log +password zebra +! +! debug mpls ldp zebra +! debug mpls ldp event +! debug mpls ldp errors +! debug mpls ldp messages recv +! debug mpls ldp messages sent +! debug mpls ldp discovery hello recv +! debug mpls ldp discovery hello sent +! +mpls ldp + router-id 192.0.2.1 + ! + address-family ipv4 + discovery transport-address 192.0.2.1 + ! + interface r1-eth0 + ! + interface r1-eth1 + ! + ! +! +line vty +! diff --git a/tests/topotests/bgp_l3vpn_label_export/r1/staticd.conf b/tests/topotests/bgp_l3vpn_label_export/r1/staticd.conf new file mode 100644 index 0000000000..7f2f057bfe --- /dev/null +++ b/tests/topotests/bgp_l3vpn_label_export/r1/staticd.conf @@ -0,0 +1 @@ +ip route 192.0.2.2/32 192.168.1.2 diff --git a/tests/topotests/bgp_l3vpn_label_export/r1/zebra.conf b/tests/topotests/bgp_l3vpn_label_export/r1/zebra.conf new file mode 100644 index 0000000000..7bdacb1ca3 --- /dev/null +++ b/tests/topotests/bgp_l3vpn_label_export/r1/zebra.conf @@ -0,0 +1,7 @@ +! +interface lo + ip address 192.0.2.1/32 +! +interface r1-eth0 + ip address 192.168.1.1/24 +! diff --git a/tests/topotests/bgp_l3vpn_label_export/r2/bgpd.conf b/tests/topotests/bgp_l3vpn_label_export/r2/bgpd.conf new file mode 100644 index 0000000000..18a11cfb40 --- /dev/null +++ b/tests/topotests/bgp_l3vpn_label_export/r2/bgpd.conf @@ -0,0 +1,23 @@ +router bgp 65002 + bgp router-id 192.0.2.2 + no bgp default ipv4-unicast + no bgp ebgp-requires-policy + neighbor 192.168.1.1 remote-as 65001 + neighbor 192.168.1.1 timers 1 3 + neighbor 192.168.1.1 timers connect 1 + neighbor 192.168.1.1 ebgp-multihop 2 + neighbor 192.168.1.1 update-source 192.0.2.2 + address-family ipv4 vpn + neighbor 192.168.1.1 activate + exit-address-family +! +router bgp 65002 vrf vrf1 + address-family ipv4 unicast + redistribute connected + label vpn export 2222 + rd vpn export 102:1 + rt vpn both 52:100 + import vpn + export vpn + exit-address-family +! diff --git a/tests/topotests/bgp_l3vpn_label_export/r2/ldpd.conf b/tests/topotests/bgp_l3vpn_label_export/r2/ldpd.conf new file mode 100644 index 0000000000..f4307f1ab0 --- /dev/null +++ b/tests/topotests/bgp_l3vpn_label_export/r2/ldpd.conf @@ -0,0 +1,24 @@ +hostname r2 +log file ldpd.log +password zebra +! +! debug mpls ldp zebra +! debug mpls ldp event +! debug mpls ldp errors +! debug mpls ldp messages recv +! debug mpls ldp messages sent +! debug mpls ldp discovery hello recv +! debug mpls ldp discovery hello sent +! +mpls ldp + router-id 192.0.2.2 + ! + address-family ipv4 + discovery transport-address 192.0.2.2 + ! + interface r2-eth0 + ! + ! +! +line vty +! diff --git a/tests/topotests/bgp_l3vpn_label_export/r2/staticd.conf b/tests/topotests/bgp_l3vpn_label_export/r2/staticd.conf new file mode 100644 index 0000000000..e3f5d7dba0 --- /dev/null +++ b/tests/topotests/bgp_l3vpn_label_export/r2/staticd.conf @@ -0,0 +1 @@ +ip route 192.0.2.1/32 192.168.1.1 diff --git a/tests/topotests/bgp_l3vpn_label_export/r2/zebra.conf b/tests/topotests/bgp_l3vpn_label_export/r2/zebra.conf new file mode 100644 index 0000000000..40dfa9854c --- /dev/null +++ b/tests/topotests/bgp_l3vpn_label_export/r2/zebra.conf @@ -0,0 +1,7 @@ +! +int lo + ip address 192.0.2.2/32 +! +interface r2-eth0 + ip address 192.168.1.2/24 +! diff --git a/tests/topotests/bgp_l3vpn_label_export/test_bgp_l3vpn_label_export.py b/tests/topotests/bgp_l3vpn_label_export/test_bgp_l3vpn_label_export.py new file mode 100644 index 0000000000..7c23a3e899 --- /dev/null +++ b/tests/topotests/bgp_l3vpn_label_export/test_bgp_l3vpn_label_export.py @@ -0,0 +1,587 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# +# Copyright (c) 2023 by Louis Scalbert <louis.scalbert@6wind.com> +# Copyright 2023 6WIND S.A. +# + +""" + +""" + +import os +import re +import sys +import json +import pytest +import functools + +from copy import deepcopy + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.common_config import kill_router_daemons, start_router_daemons, step + +pytestmark = [pytest.mark.bgpd] + + +def build_topo(tgen): + for rtr in [1, 2]: + tgen.add_router("r{}".format(rtr)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + +def setup_module(mod): + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for rtr in [1, 2]: + tgen.gears["r{}".format(rtr)].cmd("ip link add vrf1 type vrf table 10") + tgen.gears["r{}".format(rtr)].cmd("ip link set vrf1 up") + tgen.gears["r{}".format(rtr)].cmd( + "ip address add dev vrf1 192.0.3.{}/32".format(rtr) + ) + tgen.gears["r{}".format(rtr)].run( + "sysctl -w net.mpls.conf.r{}-eth0.input=1".format(rtr) + ) + tgen.gears["r{}".format(rtr)].run("sysctl -w net.mpls.conf.vrf1.input=1") + + for i, (rname, router) in enumerate(router_list.items(), 1): + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_STATIC, os.path.join(CWD, "{}/staticd.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_LDP, os.path.join(CWD, "{}/ldpd.conf".format(rname)) + ) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def check_bgp_vpn_prefix(label, rname="r1", rd=None): + tgen = get_topogen() + + if rd: + output = json.loads( + tgen.gears[rname].vtysh_cmd( + "show bgp ipv4 vpn rd {} 192.0.3.2/32 json".format(rd) + ) + ) + else: + output = json.loads( + tgen.gears[rname].vtysh_cmd( + "show bgp vrf vrf1 ipv4 unicast 192.0.3.2/32 json" + ) + ) + + if label == "auto": + expected = { + "paths": [ + { + "valid": True, + "aspath": {"string": "65002"}, + "nexthops": [{"ip": "192.0.2.2"}], + }, + ] + } + elif label and not rd: + expected = { + "paths": [ + { + "valid": True, + "remoteLabel": label, + "aspath": {"string": "65002"}, + "nexthops": [{"ip": "192.0.2.2"}], + }, + ] + } + elif label and rd: + expected = { + "102:1": { + "prefix": "192.0.3.2/32", + "paths": [ + { + "valid": True, + "remoteLabel": label, + "nexthops": [{"ip": "0.0.0.0"}], + } + ], + } + } + else: + expected = {} + + return topotest.json_cmp(output, expected, exact=(label is None)) + + +def check_mpls_table(label, protocol): + tgen = get_topogen() + + if label == "auto": + cmd = "show mpls table json" + else: + cmd = "show mpls table {} json".format(label) + + output = json.loads(tgen.gears["r2"].vtysh_cmd(cmd)) + + if label == "auto" and protocol: + output_copy = deepcopy(output) + for key, data in output_copy.items(): + for nexthop in data.get("nexthops", []): + if nexthop.get("type", None) != protocol: + continue + output = data + break + + if protocol: + expected = { + "nexthops": [ + { + "type": protocol, + }, + ] + } + else: + expected = {} + + return topotest.json_cmp(output, expected, exact=(protocol is None)) + + +def check_mpls_ldp_binding(): + tgen = get_topogen() + + output = json.loads( + tgen.gears["r1"].vtysh_cmd("show mpls ldp binding 192.0.2.2/32 json") + ) + expected = { + "bindings": [ + { + "prefix": "192.0.2.2/32", + "localLabel": "16", # first available label + "inUse": 1, + }, + ] + } + + return topotest.json_cmp(output, expected) + + +def test_convergence(): + "Test protocol convergence" + + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + step("Check BGP and LDP convergence") + test_func = functools.partial(check_bgp_vpn_prefix, 2222) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see BGP prefix on R1" + + test_func = functools.partial(check_mpls_ldp_binding) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see LDP binding on R2" + + test_func = functools.partial(check_mpls_table, 16, "LDP") + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see LDP label on R2" + + test_func = functools.partial(check_mpls_table, 2222, "BGP") + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see BGP label on R2" + + output = tgen.net["r2"].cmd("vtysh -c 'show debugging label-table' | grep Proto") + assert re.match( + r"Proto ldp: \[16/(1[7-9]|[2-9]\d+|\d{3,})\]", output + ), "Failed to see LDP label chunk" + + output = tgen.gears["r2"].vtysh_cmd("show debugging label-table") + assert "Proto bgp: [2222/2222]" in output, "Failed to see BGP label chunk" + + +def test_vpn_label_export_16(): + "Test that assigning the label value of 16 is not possible because it used by LDP" + + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + tgen.gears["r2"].vtysh_cmd( + "conf\n" + "router bgp 65002 vrf vrf1\n" + "address-family ipv4 unicast\n" + "label vpn export 16" + ) + + step("Check that label vpn export 16 fails") + test_func = functools.partial(check_bgp_vpn_prefix, None) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Unexpected BGP prefix on R1" + + test_func = functools.partial(check_mpls_ldp_binding) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see LDP binding on R2" + + test_func = functools.partial(check_mpls_table, 16, "LDP") + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see LDP label on R2" + + test_func = functools.partial(check_mpls_table, 2222, None) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Unexpected BGP label on R2" + + output = tgen.net["r2"].cmd("vtysh -c 'show debugging label-table' | grep Proto") + assert re.match( + r"Proto ldp: \[16/(1[7-9]|[2-9]\d+|\d{3,})\]", output + ), "Failed to see LDP label chunk" + + output = tgen.gears["r2"].vtysh_cmd("show debugging label-table") + assert "Proto bgp" not in output, "Unexpected BGP label chunk" + + +def test_vpn_label_export_2222(): + "Test that setting back the label value of 2222 works" + + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + tgen.gears["r2"].vtysh_cmd( + "conf\n" + "router bgp 65002 vrf vrf1\n" + "address-family ipv4 unicast\n" + "label vpn export 2222" + ) + + step("Check that label vpn export 2222 is OK") + test_func = functools.partial(check_bgp_vpn_prefix, 2222) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see BGP prefix on R1" + + test_func = functools.partial(check_mpls_ldp_binding) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see LDP binding on R2" + + test_func = functools.partial(check_mpls_table, 16, "LDP") + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see LDP label on R2" + + test_func = functools.partial(check_mpls_table, "auto", "BGP") + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Unexpected BGP label on R2" + + output = tgen.net["r2"].cmd("vtysh -c 'show debugging label-table' | grep Proto") + assert re.match( + r"Proto ldp: \[16/(1[7-9]|[2-9]\d+|\d{3,})\]", output + ), "Failed to see LDP label chunk" + + output = tgen.gears["r2"].vtysh_cmd("show debugging label-table") + assert "Proto bgp: [2222/2222]" in output, "Failed to see BGP label chunk" + + +def test_vpn_label_export_auto(): + "Test that setting label vpn export auto works" + + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + tgen.gears["r2"].vtysh_cmd( + "conf\n" + "router bgp 65002 vrf vrf1\n" + "address-family ipv4 unicast\n" + "label vpn export auto" + ) + + step("Check that label vpn export auto is OK") + test_func = functools.partial(check_bgp_vpn_prefix, "auto") + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see BGP prefix on R1" + + test_func = functools.partial(check_mpls_ldp_binding) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see LDP binding on R2" + + test_func = functools.partial(check_mpls_table, 16, "LDP") + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see LDP label on R2" + + test_func = functools.partial(check_mpls_table, "auto", "BGP") + _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert result is None, "Failed to see BGP label on R2" + + output = tgen.net["r2"].cmd("vtysh -c 'show debugging label-table' | grep Proto") + assert re.match( + r"Proto ldp: \[16/(1[7-9]|[2-9]\d+|\d{3,})\]", output + ), "Failed to see LDP label chunk" + + output = tgen.gears["r2"].vtysh_cmd("show debugging label-table") + assert "Proto bgp: " in output, "Failed to see BGP label chunk" + + +def test_vpn_label_export_no_auto(): + "Test that UNsetting label vpn export auto removes the prefix from R1 table and R2 LDP table" + + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + output = json.loads( + tgen.gears["r1"].vtysh_cmd("show bgp vrf vrf1 ipv4 unicast 192.0.3.2/32 json") + ) + + auto_label = output.get("paths")[0].get("remoteLabel", None) + assert auto_label is not None, "Failed to fetch prefix label on R1" + + tgen.gears["r2"].vtysh_cmd( + "conf\n" + "router bgp 65002 vrf vrf1\n" + "address-family ipv4 unicast\n" + "no label vpn export auto" + ) + + step("Check that no label vpn export auto is OK") + test_func = functools.partial(check_bgp_vpn_prefix, 3, rname="r2", rd="102:1") + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Unexpected BGP prefix on R2" + + test_func = functools.partial(check_mpls_ldp_binding) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see LDP binding on R2" + + test_func = functools.partial(check_mpls_table, 16, "LDP") + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see LDP label on R2" + + test_func = functools.partial(check_mpls_table, auto_label, None) + _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert result is None, "Unexpected BGP label on R2" + + output = tgen.net["r2"].cmd("vtysh -c 'show debugging label-table' | grep Proto") + assert re.match( + r"Proto ldp: \[16/(1[7-9]|[2-9]\d+|\d{3,})\]", output + ), "Failed to see LDP label chunk" + + output = tgen.gears["r2"].vtysh_cmd("show debugging label-table") + assert "Proto bgp: " not in output, "Unexpected BGP label chunk" + + +def test_vpn_label_export_auto_back(): + "Test that setting back label vpn export auto works" + + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + output = json.loads( + tgen.gears["r2"].vtysh_cmd("show bgp vrf vrf1 ipv4 unicast 192.0.3.2/32 json") + ) + + tgen.gears["r2"].vtysh_cmd( + "conf\n" + "router bgp 65002 vrf vrf1\n" + "address-family ipv4 unicast\n" + "label vpn export auto" + ) + + step("Check that label vpn export auto is OK") + test_func = functools.partial(check_bgp_vpn_prefix, "auto") + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see BGP prefix on R1" + + test_func = functools.partial(check_mpls_ldp_binding) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see LDP binding on R2" + + test_func = functools.partial(check_mpls_table, 16, "LDP") + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see LDP label on R2" + + test_func = functools.partial(check_mpls_table, "auto", "BGP") + _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert result is None, "Failed to see BGP label on R2" + + output = tgen.net["r2"].cmd("vtysh -c 'show debugging label-table' | grep Proto") + assert re.match( + r"Proto ldp: \[16/(1[7-9]|[2-9]\d+|\d{3,})\]", output + ), "Failed to see LDP label chunk" + + output = tgen.gears["r2"].vtysh_cmd("show debugging label-table") + assert "Proto bgp: " in output, "Failed to see BGP label chunk" + + +def test_vpn_label_export_manual_from_auto(): + "Test that setting a manual label value from the BGP chunk range works" + + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + output = json.loads( + tgen.gears["r1"].vtysh_cmd("show bgp vrf vrf1 ipv4 unicast 192.0.3.2/32 json") + ) + + auto_label = output.get("paths")[0].get("remoteLabel", None) + assert auto_label is not None, "Failed to fetch prefix label on R1" + + auto_label = auto_label + 1 + + tgen.gears["r2"].vtysh_cmd( + "conf\n" + "router bgp 65002 vrf vrf1\n" + "address-family ipv4 unicast\n" + "label vpn export {}".format(auto_label) + ) + + step("Check that label vpn export {} is OK".format(auto_label)) + test_func = functools.partial( + check_bgp_vpn_prefix, auto_label, rname="r2", rd="102:1" + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see BGP prefix on R2" + + test_func = functools.partial(check_mpls_ldp_binding) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see LDP binding on R2" + + test_func = functools.partial(check_mpls_table, 16, "LDP") + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see LDP label on R2" + + test_func = functools.partial(check_mpls_table, auto_label, "BGP") + _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert result is None, "Failed to see BGP label on R2" + + output = tgen.net["r2"].cmd("vtysh -c 'show debugging label-table' | grep Proto") + assert re.match( + r"Proto ldp: \[16/(1[7-9]|[2-9]\d+|\d{3,})\]", output + ), "Failed to see LDP label chunk" + + output = tgen.gears["r2"].vtysh_cmd("show debugging label-table") + assert "Proto bgp: " in output, "Failed to see BGP label chunk" + + +def test_vpn_label_configure_dynamic_range(): + "Test that if a dynamic range is configured, then the next dynamic allocations will be done in that block" + + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + tgen.gears["r2"].vtysh_cmd("conf\n" "mpls label dynamic-block 500 1000\n") + tgen.gears["r2"].vtysh_cmd( + "conf\n" + "router bgp 65002 vrf vrf1\n" + "address-family ipv4 unicast\n" + "label vpn export auto" + ) + step("Check that label vpn export auto starting at 500 is OK") + test_func = functools.partial(check_bgp_vpn_prefix, 500, rname="r2", rd="102:1") + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Unexpected BGP prefix on R2" + + test_func = functools.partial(check_mpls_table, 500, "BGP") + _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert result is None, "Unexpected BGP label on R2" + + output = tgen.gears["r2"].vtysh_cmd("show debugging label-table") + assert "Proto bgp: " in output, "Failed to see BGP label chunk" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) + + +def test_vpn_label_restart_ldp(): + "Test that if a dynamic range is configured, then when LDP restarts, it follows the new dynamic range" + + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router_list = tgen.routers() + + step("Kill LDP on R2") + kill_router_daemons(tgen, "r2", ["ldpd"]) + + output = tgen.gears["r2"].vtysh_cmd("show debugging label-table") + assert "Proto ldp: " not in output, "Unexpected LDP label chunk" + + step("Bring up LDP on R2") + + start_router_daemons(tgen, "r2", ["ldpd"]) + + test_func = functools.partial(check_mpls_table, 628, "LDP") + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to see LDP label on R2" + + output = tgen.gears["r2"].vtysh_cmd("show debugging label-table") + assert "Proto ldp: [628/691]" in output, "Failed to see LDP label chunk [628/691]" + assert "Proto ldp: [692/755]" in output, "Failed to see LDP label chunk [692/755]" + + +def test_vpn_label_unconfigure_dynamic_range(): + "Test that if the dynamic range is unconfigured, then the next dynamic allocations will be done at the first free place." + + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + tgen.gears["r2"].vtysh_cmd("conf\n" "no mpls label dynamic-block 500 1000\n") + step("Check that unconfiguring label vpn export auto will remove BGP label chunk") + tgen.gears["r2"].vtysh_cmd( + "conf\n" + "router bgp 65002 vrf vrf1\n" + "address-family ipv4 unicast\n" + "no label vpn export auto" + ) + + output = tgen.gears["r2"].vtysh_cmd("show debugging label-table") + assert "Proto bgp: " not in output, "Unexpected BGP label chunk" + + tgen.gears["r2"].vtysh_cmd( + "conf\n" + "router bgp 65002 vrf vrf1\n" + "address-family ipv4 unicast\n" + "label vpn export auto" + ) + step("Check that label vpn export auto starting at 16 is OK") + test_func = functools.partial(check_bgp_vpn_prefix, 16, rname="r2", rd="102:1") + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Unexpected BGP prefix on R2" + + test_func = functools.partial(check_mpls_table, 16, "BGP") + _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert result is None, "Unexpected BGP label on R2" + + output = tgen.gears["r2"].vtysh_cmd("show debugging label-table") + assert "Proto bgp: " in output, "Failed to see BGP label chunk" diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/r1/bgpd.conf b/tests/topotests/bgp_l3vpn_to_bgp_vrf/r1/bgpd.conf index 8d42cfc0d8..72211fee7f 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/r1/bgpd.conf +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/r1/bgpd.conf @@ -5,7 +5,7 @@ password zebra log stdout notifications log commands -log file bgpd.log debugging +log file bgpd.log #debug bgp vpn leak-to-vrf #debug bgp vpn leak-from-vrf diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/r2/bgpd.conf b/tests/topotests/bgp_l3vpn_to_bgp_vrf/r2/bgpd.conf index 7b42b770b5..edb3b699f9 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/r2/bgpd.conf +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/r2/bgpd.conf @@ -4,7 +4,7 @@ hostname r2 password zebra log stdout notifications log commands -log file bgpd.log debugging +log file bgpd.log router bgp 5226 bgp router-id 2.2.2.2 diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/r4/bgpd.conf b/tests/topotests/bgp_l3vpn_to_bgp_vrf/r4/bgpd.conf index ca9e627172..ed76ed3c63 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/r4/bgpd.conf +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/r4/bgpd.conf @@ -4,7 +4,7 @@ hostname r4 password zebra log stdout notifications log commands -log file bgpd.log debug +log file bgpd.log #debug bgp vpn label #debug bgp nht diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py index 46993c7d9a..e05bf21ea9 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py @@ -226,7 +226,7 @@ ave_b = float(delta_b) / float(num) luCommand( rtr, - 'vtysh -c "show thread cpu"', + 'vtysh -c "show event cpu"', ".", "pass", "BGPd heap: {0} {1} --> {2} {3} ({4} {1}/vpn route)".format( @@ -239,7 +239,7 @@ ) luCommand( rtr, - 'vtysh -c "show thread cpu"', + 'vtysh -c "show event cpu"', ".", "pass", "Zebra heap: {0} {1} --> {2} {3} ({4} {1}/vpn route)".format( diff --git a/tests/topotests/bgp_labeled_unicast_default_originate/r1/bgpd.conf b/tests/topotests/bgp_labeled_unicast_default_originate/r1/bgpd.conf index 75a4aa6ab3..d0d13909a7 100644 --- a/tests/topotests/bgp_labeled_unicast_default_originate/r1/bgpd.conf +++ b/tests/topotests/bgp_labeled_unicast_default_originate/r1/bgpd.conf @@ -1,18 +1,32 @@ ! router bgp 65001 no bgp default ipv4-unicast + no bgp default ipv6-unicast no bgp ebgp-requires-policy neighbor 192.168.12.2 remote-as external neighbor 192.168.12.2 timers 1 3 neighbor 192.168.12.2 timers connect 1 + neighbor 2001:db8:12::2 remote-as external + neighbor 2001:db8:12::2 timers 1 3 + neighbor 2001:db8:12::2 timers connect 1 address-family ipv4 unicast redistribute connected exit-address-family + ! + address-family ipv6 unicast + redistribute connected + exit-address-family + ! address-family ipv4 labeled-unicast neighbor 192.168.12.2 activate neighbor 192.168.12.2 default-originate route-map r2 exit-address-family ! + address-family ipv6 labeled-unicast + neighbor 2001:db8:12::2 activate + neighbor 2001:db8:12::2 default-originate route-map r2 + exit-address-family + ! ! route-map r2 permit 10 set community 65001:65001 diff --git a/tests/topotests/bgp_labeled_unicast_default_originate/r1/zebra.conf b/tests/topotests/bgp_labeled_unicast_default_originate/r1/zebra.conf index 8eab7805df..686b0755c3 100644 --- a/tests/topotests/bgp_labeled_unicast_default_originate/r1/zebra.conf +++ b/tests/topotests/bgp_labeled_unicast_default_originate/r1/zebra.conf @@ -1,4 +1,5 @@ ! interface r1-eth0 ip address 192.168.12.1/24 + ipv6 address 2001:db8:12::1/64 ! diff --git a/tests/topotests/bgp_labeled_unicast_default_originate/r2/bgpd.conf b/tests/topotests/bgp_labeled_unicast_default_originate/r2/bgpd.conf index c81ba9fe02..1498dffc93 100644 --- a/tests/topotests/bgp_labeled_unicast_default_originate/r2/bgpd.conf +++ b/tests/topotests/bgp_labeled_unicast_default_originate/r2/bgpd.conf @@ -2,10 +2,18 @@ router bgp 65002 no bgp ebgp-requires-policy no bgp default ipv4-unicast + no bgp default ipv6-unicast neighbor 192.168.12.1 remote-as external neighbor 192.168.12.1 timers 1 3 neighbor 192.168.12.1 timers connect 1 + neighbor 2001:db8:12::1 remote-as external + neighbor 2001:db8:12::1 timers 1 3 + neighbor 2001:db8:12::1 timers connect 1 address-family ipv4 labeled-unicast neighbor 192.168.12.1 activate exit-address-family + ! + address-family ipv6 labeled-unicast + neighbor 2001:db8:12::1 activate + exit-address-family ! diff --git a/tests/topotests/bgp_labeled_unicast_default_originate/r2/zebra.conf b/tests/topotests/bgp_labeled_unicast_default_originate/r2/zebra.conf index d7dfd899cc..cb5c55ef0f 100644 --- a/tests/topotests/bgp_labeled_unicast_default_originate/r2/zebra.conf +++ b/tests/topotests/bgp_labeled_unicast_default_originate/r2/zebra.conf @@ -1,4 +1,5 @@ ! interface r2-eth0 ip address 192.168.12.2/24 + ipv6 address 2001:db8:12::2/64 ! diff --git a/tests/topotests/bgp_labeled_unicast_default_originate/test_bgp_labeled_unicast_default_originate.py b/tests/topotests/bgp_labeled_unicast_default_originate/test_bgp_labeled_unicast_default_originate.py index c3ccefb569..34c23d9b6f 100644 --- a/tests/topotests/bgp_labeled_unicast_default_originate/test_bgp_labeled_unicast_default_originate.py +++ b/tests/topotests/bgp_labeled_unicast_default_originate/test_bgp_labeled_unicast_default_originate.py @@ -82,7 +82,7 @@ def _bgp_check_advertised_routes(): _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) assert result is None, "Failed to advertise default route for labeled-unicast" - def _bgp_check_received_routes(): + def _bgp_check_received_ipv4_routes(): output = json.loads( r2.vtysh_cmd("show bgp ipv4 labeled-unicast 0.0.0.0/0 json") ) @@ -94,14 +94,35 @@ def _bgp_check_received_routes(): "community": { "string": "65001:65001", }, + "remoteLabel": 0, } ] } return topotest.json_cmp(output, expected) - test_func = functools.partial(_bgp_check_received_routes) + test_func = functools.partial(_bgp_check_received_ipv4_routes) _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) - assert result is None, "Failed to receive default route for labeled-unicast" + assert result is None, "Failed to receive IPv4 default route for labeled-unicast" + + def _bgp_check_received_ipv6_routes(): + output = json.loads(r2.vtysh_cmd("show bgp ipv6 labeled-unicast ::/0 json")) + expected = { + "paths": [ + { + "valid": True, + "metric": 666, + "community": { + "string": "65001:65001", + }, + "remoteLabel": 2, + } + ] + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_check_received_ipv6_routes) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to receive IPv6 default route for labeled-unicast" if __name__ == "__main__": diff --git a/tests/topotests/bgp_large_comm_list_match/__init__.py b/tests/topotests/bgp_large_comm_list_match/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/bgp_large_comm_list_match/r1/bgpd.conf b/tests/topotests/bgp_large_comm_list_match/r1/bgpd.conf new file mode 100644 index 0000000000..1a91f0f5cc --- /dev/null +++ b/tests/topotests/bgp_large_comm_list_match/r1/bgpd.conf @@ -0,0 +1,28 @@ +! +router bgp 65001 + no bgp ebgp-requires-policy + neighbor 192.168.0.2 remote-as external + neighbor 192.168.0.2 timers 1 3 + neighbor 192.168.0.2 timers connect 1 + address-family ipv4 + redistribute connected + neighbor 192.168.0.2 route-map r2 out + exit-address-family +! +ip prefix-list p1 seq 5 permit 172.16.255.1/32 +ip prefix-list p3 seq 5 permit 172.16.255.3/32 +ip prefix-list p4 seq 5 permit 172.16.255.4/32 +! +route-map r2 permit 10 + match ip address prefix-list p1 + set large-community 65001:1:1 65001:2:1 +route-map r2 permit 20 + match ip address prefix-list p3 + set large-community 65001:3:1 +route-map r2 permit 30 + match ip address prefix-list p4 + set large-community 65001:10:1 65001:12:1 65001:13:1 +exit +route-map r2 permit 40 +exit +! diff --git a/tests/topotests/bgp_large_comm_list_match/r1/zebra.conf b/tests/topotests/bgp_large_comm_list_match/r1/zebra.conf new file mode 100644 index 0000000000..4219a7ca3a --- /dev/null +++ b/tests/topotests/bgp_large_comm_list_match/r1/zebra.conf @@ -0,0 +1,12 @@ +! +interface lo + ip address 172.16.255.1/32 + ip address 172.16.255.2/32 + ip address 172.16.255.3/32 + ip address 172.16.255.4/32 +! +interface r1-eth0 + ip address 192.168.0.1/24 +! +ip forwarding +! diff --git a/tests/topotests/bgp_large_comm_list_match/r2/bgpd.conf b/tests/topotests/bgp_large_comm_list_match/r2/bgpd.conf new file mode 100644 index 0000000000..779b705b58 --- /dev/null +++ b/tests/topotests/bgp_large_comm_list_match/r2/bgpd.conf @@ -0,0 +1,24 @@ +! +!debug bgp updates +! +router bgp 65002 + no bgp ebgp-requires-policy + neighbor 192.168.0.1 remote-as external + neighbor 192.168.0.1 timers 1 3 + neighbor 192.168.0.1 timers connect 1 + neighbor 192.168.1.3 remote-as external + neighbor 192.168.1.3 timers 1 3 + neighbor 192.168.1.3 timers connect 1 + address-family ipv4 + neighbor 192.168.0.1 route-map r1 in + neighbor 192.168.0.1 soft-reconfiguration inbound + exit-address-family +! +bgp large-community-list 1 seq 5 permit 65001:1:1 65001:2:1 +bgp large-community-list 1 seq 10 permit 65001:3:1 +! +route-map r1 deny 10 + match large-community 1 +route-map r1 permit 20 +exit +! diff --git a/tests/topotests/bgp_large_comm_list_match/r2/zebra.conf b/tests/topotests/bgp_large_comm_list_match/r2/zebra.conf new file mode 100644 index 0000000000..7fe82bac8f --- /dev/null +++ b/tests/topotests/bgp_large_comm_list_match/r2/zebra.conf @@ -0,0 +1,9 @@ +! +interface r2-eth0 + ip address 192.168.0.2/24 +! +interface r2-eth1 + ip address 192.168.1.2/24 +! +ip forwarding +! diff --git a/tests/topotests/bgp_large_comm_list_match/r3/bgpd.conf b/tests/topotests/bgp_large_comm_list_match/r3/bgpd.conf new file mode 100644 index 0000000000..e7cb76a436 --- /dev/null +++ b/tests/topotests/bgp_large_comm_list_match/r3/bgpd.conf @@ -0,0 +1,21 @@ +! +!debug bgp updates +! +router bgp 65003 + no bgp ebgp-requires-policy + neighbor 192.168.1.2 remote-as external + neighbor 192.168.1.2 timers 1 3 + neighbor 192.168.1.2 timers connect 1 + address-family ipv4 + neighbor 192.168.1.2 route-map r1 in + neighbor 192.168.1.2 soft-reconfiguration inbound + exit-address-family +! +bgp large-community-list 2 seq 10 permit 65001:12:1 +! +route-map r1 deny 10 + match large-community 2 any +exit +route-map r1 permit 20 +exit +! diff --git a/tests/topotests/bgp_large_comm_list_match/r3/zebra.conf b/tests/topotests/bgp_large_comm_list_match/r3/zebra.conf new file mode 100644 index 0000000000..755dd18bfe --- /dev/null +++ b/tests/topotests/bgp_large_comm_list_match/r3/zebra.conf @@ -0,0 +1,6 @@ +! +interface r3-eth0 + ip address 192.168.1.3/24 +! +ip forwarding +! diff --git a/tests/topotests/bgp_large_comm_list_match/test_bgp_large_comm_list_match.py b/tests/topotests/bgp_large_comm_list_match/test_bgp_large_comm_list_match.py new file mode 100644 index 0000000000..483c048d25 --- /dev/null +++ b/tests/topotests/bgp_large_comm_list_match/test_bgp_large_comm_list_match.py @@ -0,0 +1,145 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# +# Copyright 2023 by 6WIND S.A. +# + +""" +Check if BGP large-community-list works +when used as match rule in incoming route-maps. + +- case 1 should deny incoming updates with large-community-list 1 +bgp large-community-list 1 seq 5 permit 65001:1:1 65001:2:1 +bgp large-community-list 1 seq 10 permit 65001:3:1 +! +route-map r1 deny 10 + match large-community 1 + +route-map test deny 10 + match community 1 + +- case 2 should deny incoming updates with any large-community-list 1 +bgp large-community-list 2 seq 10 permit 65001:12:1 +! +route-map r1 deny 10 + match large-community 2 any +""" + +import os +import sys +import json +import pytest +import functools + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.common_config import step + +pytestmark = [pytest.mark.bgpd] + + +def build_topo(tgen): + for routern in range(1, 4): + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["r2"]) + + +def setup_module(mod): + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for i, (rname, router) in enumerate(router_list.items(), 1): + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) + ) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_large_comm_list_match(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears["r2"] + + def _bgp_converge(): + output = json.loads( + router.vtysh_cmd( + "show bgp ipv4 unicast neighbors 192.168.0.1 filtered-routes json" + ) + ) + expected = { + "receivedRoutes": { + "172.16.255.1/32": { + "path": "65001", + }, + "172.16.255.3/32": { + "path": "65001", + }, + } + } + return topotest.json_cmp(output, expected) + + step("BGP filtering check with large-community-list on R2") + test_func = functools.partial(_bgp_converge) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert ( + result is None + ), "Failed to filter BGP UPDATES with large-community-list on R2" + + +def test_bgp_large_comm_list_match_any(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears["r3"] + + def _bgp_converge(): + output = json.loads( + router.vtysh_cmd( + "show bgp ipv4 unicast neighbors 192.168.1.2 filtered-routes json" + ) + ) + expected = { + "receivedRoutes": { + "172.16.255.4/32": { + "path": "65002 65001", + }, + } + } + return topotest.json_cmp(output, expected) + + step("BGP filtering check with large-community-list on R3") + test_func = functools.partial(_bgp_converge) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed to filter BGP UPDATES with large-community-list on R3" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_link_bw_ip/r1/ip-route-1.json b/tests/topotests/bgp_link_bw_ip/r1/ip-route-1.json index 3c02e2675d..bb50bc96d9 100644 --- a/tests/topotests/bgp_link_bw_ip/r1/ip-route-1.json +++ b/tests/topotests/bgp_link_bw_ip/r1/ip-route-1.json @@ -7,12 +7,12 @@ { "fib":true, "ip":"11.1.1.6", - "weight":25 + "weight":85 }, { "fib":true, "ip":"11.1.1.2", - "weight":75 + "weight":255 } ] } diff --git a/tests/topotests/bgp_link_bw_ip/r1/ip-route-2.json b/tests/topotests/bgp_link_bw_ip/r1/ip-route-2.json index 3c2d42caac..57726ce46c 100644 --- a/tests/topotests/bgp_link_bw_ip/r1/ip-route-2.json +++ b/tests/topotests/bgp_link_bw_ip/r1/ip-route-2.json @@ -7,12 +7,12 @@ { "fib":true, "ip":"11.1.1.6", - "weight":33 + "weight":127 }, { "fib":true, "ip":"11.1.1.2", - "weight":66 + "weight":255 } ] } diff --git a/tests/topotests/bgp_link_bw_ip/r1/ip-route-3.json b/tests/topotests/bgp_link_bw_ip/r1/ip-route-3.json index 3d80018cea..f2368dfdc5 100644 --- a/tests/topotests/bgp_link_bw_ip/r1/ip-route-3.json +++ b/tests/topotests/bgp_link_bw_ip/r1/ip-route-3.json @@ -7,12 +7,12 @@ { "fib":true, "ip":"11.1.1.6", - "weight":33 + "weight":127 }, { "fib":true, "ip":"11.1.1.2", - "weight":66 + "weight":255 } ] } diff --git a/tests/topotests/bgp_link_bw_ip/r1/ip-route-6.json b/tests/topotests/bgp_link_bw_ip/r1/ip-route-6.json index 6ed3f8ef55..7b4da2a8d0 100644 --- a/tests/topotests/bgp_link_bw_ip/r1/ip-route-6.json +++ b/tests/topotests/bgp_link_bw_ip/r1/ip-route-6.json @@ -7,7 +7,7 @@ { "fib":true, "ip":"11.1.1.2", - "weight":100 + "weight":255 } ] } diff --git a/tests/topotests/bgp_link_bw_ip/r1/ip-route-7.json b/tests/topotests/bgp_link_bw_ip/r1/ip-route-7.json index 95531d99be..3062d1cf8b 100644 --- a/tests/topotests/bgp_link_bw_ip/r1/ip-route-7.json +++ b/tests/topotests/bgp_link_bw_ip/r1/ip-route-7.json @@ -7,7 +7,7 @@ { "fib":true, "ip":"11.1.1.2", - "weight":100 + "weight":255 } ] } diff --git a/tests/topotests/bgp_link_bw_ip/r1/ip-route-8.json b/tests/topotests/bgp_link_bw_ip/r1/ip-route-8.json index beac501360..662b7f716c 100644 --- a/tests/topotests/bgp_link_bw_ip/r1/ip-route-8.json +++ b/tests/topotests/bgp_link_bw_ip/r1/ip-route-8.json @@ -12,7 +12,7 @@ { "fib":true, "ip":"11.1.1.2", - "weight":100 + "weight":255 } ] } diff --git a/tests/topotests/bgp_link_bw_ip/r1/ip-route-9.json b/tests/topotests/bgp_link_bw_ip/r1/ip-route-9.json index eb27ce2633..d9b5a8992d 100644 --- a/tests/topotests/bgp_link_bw_ip/r1/ip-route-9.json +++ b/tests/topotests/bgp_link_bw_ip/r1/ip-route-9.json @@ -12,7 +12,7 @@ { "fib":true, "ip":"11.1.1.2", - "weight":100 + "weight":255 } ] } diff --git a/tests/topotests/bgp_link_bw_ip/r2/ip-route-2.json b/tests/topotests/bgp_link_bw_ip/r2/ip-route-2.json index 7e2fa6be25..53be1171f6 100644 --- a/tests/topotests/bgp_link_bw_ip/r2/ip-route-2.json +++ b/tests/topotests/bgp_link_bw_ip/r2/ip-route-2.json @@ -7,12 +7,12 @@ { "fib":true, "ip":"11.1.2.6", - "weight":33 + "weight":127 }, { "fib":true, "ip":"11.1.2.2", - "weight":66 + "weight":255 } ] } diff --git a/tests/topotests/bgp_local_as_dotplus_private_remove/test_bgp_local_as_dotplus_private_remove.py b/tests/topotests/bgp_local_as_dotplus_private_remove/test_bgp_local_as_dotplus_private_remove.py index efecad3eb2..930fd791b0 100644 --- a/tests/topotests/bgp_local_as_dotplus_private_remove/test_bgp_local_as_dotplus_private_remove.py +++ b/tests/topotests/bgp_local_as_dotplus_private_remove/test_bgp_local_as_dotplus_private_remove.py @@ -31,13 +31,14 @@ import os import sys import json -import time import pytest +import functools CWD = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(CWD, "../")) # pylint: disable=C0413 +from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen pytestmark = [pytest.mark.bgpd] @@ -84,29 +85,43 @@ def test_bgp_remove_private_as(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - def _bgp_converge(router): - while True: - output = json.loads( - tgen.gears[router].vtysh_cmd("show ip bgp neighbor 192.168.255.1 json") - ) - if output["192.168.255.1"]["bgpState"] == "Established": - time.sleep(1) - return True - - def _bgp_as_path(router): - output = json.loads( - tgen.gears[router].vtysh_cmd("show ip bgp 172.16.255.254/32 json") - ) - if output["prefix"] == "172.16.255.254/32": - return output["paths"][0]["aspath"]["segments"][0]["list"] - - if _bgp_converge("r2"): - assert len(_bgp_as_path("r2")) == 1 - assert '0.65000' not in _bgp_as_path("r2") - - if _bgp_converge("r4"): - assert len(_bgp_as_path("r4")) == 2 - assert '0.3000' in _bgp_as_path("r4") + r2 = tgen.gears["r2"] + r4 = tgen.gears["r4"] + + def _bgp_converge(): + output = json.loads(r2.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) + expected = { + "192.168.255.1": { + "bgpState": "Established", + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_converge) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Can't converge initially" + + def _bgp_as_path(router, asn_path, asn_length): + output = json.loads(router.vtysh_cmd("show ip bgp 172.16.255.254/32 json")) + expected = { + "paths": [ + { + "aspath": { + "string": asn_path, + "length": asn_length, + } + } + ] + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_as_path, r2, "0.500", 1) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Private ASNs not stripped" + + test_func = functools.partial(_bgp_as_path, r4, "0.500 0.3000", 2) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Private ASNs not stripped" if __name__ == "__main__": diff --git a/tests/topotests/bgp_lu_topo1/R1/labelpool.summ.json b/tests/topotests/bgp_lu_topo1/R1/labelpool.summ.json index 6db8e002f4..c66571f463 100644 --- a/tests/topotests/bgp_lu_topo1/R1/labelpool.summ.json +++ b/tests/topotests/bgp_lu_topo1/R1/labelpool.summ.json @@ -2,7 +2,5 @@ "ledger":506, "inUse":506, "requests":0, - "labelChunks":3, - "pending":0, - "reconnects":0 + "labelChunks":3 } diff --git a/tests/topotests/bgp_lu_topo1/R2/labelpool.summ.json b/tests/topotests/bgp_lu_topo1/R2/labelpool.summ.json index 9f9e57511c..17b9accb4a 100644 --- a/tests/topotests/bgp_lu_topo1/R2/labelpool.summ.json +++ b/tests/topotests/bgp_lu_topo1/R2/labelpool.summ.json @@ -2,7 +2,5 @@ "ledger":0, "inUse":0, "requests":0, - "labelChunks":0, - "pending":0, - "reconnects":0 + "labelChunks":0 } diff --git a/tests/topotests/bgp_lu_topo2/R1/labelpool.summ.json b/tests/topotests/bgp_lu_topo2/R1/labelpool.summ.json index 59ecd27f7f..faeaa3ec5f 100644 --- a/tests/topotests/bgp_lu_topo2/R1/labelpool.summ.json +++ b/tests/topotests/bgp_lu_topo2/R1/labelpool.summ.json @@ -2,7 +2,5 @@ "ledger":51, "inUse":51, "requests":0, - "labelChunks":1, - "pending":0, - "reconnects":0 + "labelChunks":1 } diff --git a/tests/topotests/bgp_lu_topo2/R2/labelpool.summ.json b/tests/topotests/bgp_lu_topo2/R2/labelpool.summ.json index 2c52192cd6..5f9d8e6624 100644 --- a/tests/topotests/bgp_lu_topo2/R2/labelpool.summ.json +++ b/tests/topotests/bgp_lu_topo2/R2/labelpool.summ.json @@ -2,7 +2,5 @@ "ledger":1, "inUse":1, "requests":0, - "labelChunks":1, - "pending":0, - "reconnects":0 + "labelChunks":1 } diff --git a/tests/topotests/bgp_multiview_topo1/exabgp.env b/tests/topotests/bgp_multiview_topo1/exabgp.env index a328e04962..ec978c66e7 100644 --- a/tests/topotests/bgp_multiview_topo1/exabgp.env +++ b/tests/topotests/bgp_multiview_topo1/exabgp.env @@ -1,5 +1,6 @@ [exabgp.api] +ack = false encoder = text highres = false respawn = false diff --git a/tests/topotests/bgp_multiview_topo1/peer1/exa-send.py b/tests/topotests/bgp_multiview_topo1/peer1/exa-send.py index 09f6ea59e5..0e50d46041 100755 --- a/tests/topotests/bgp_multiview_topo1/peer1/exa-send.py +++ b/tests/topotests/bgp_multiview_topo1/peer1/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_multiview_topo1/peer1/exabgp.cfg b/tests/topotests/bgp_multiview_topo1/peer1/exabgp.cfg index 20e71c8420..0303230b56 100644 --- a/tests/topotests/bgp_multiview_topo1/peer1/exabgp.cfg +++ b/tests/topotests/bgp_multiview_topo1/peer1/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 1 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 1"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 1 10; + encoder text; +} - neighbor 172.16.1.254 { - router-id 172.16.1.1; - local-address 172.16.1.1; - local-as 65001; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 1; + encoder text; +} +neighbor 172.16.1.254 { + router-id 172.16.1.1; + local-address 172.16.1.1; + local-as 65001; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_multiview_topo1/peer2/exa-send.py b/tests/topotests/bgp_multiview_topo1/peer2/exa-send.py index 09f6ea59e5..0e50d46041 100755 --- a/tests/topotests/bgp_multiview_topo1/peer2/exa-send.py +++ b/tests/topotests/bgp_multiview_topo1/peer2/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_multiview_topo1/peer2/exabgp.cfg b/tests/topotests/bgp_multiview_topo1/peer2/exabgp.cfg index 1e8eef186f..13670c3b52 100644 --- a/tests/topotests/bgp_multiview_topo1/peer2/exabgp.cfg +++ b/tests/topotests/bgp_multiview_topo1/peer2/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 2 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 2"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 2 10; + encoder text; +} - neighbor 172.16.1.254 { - router-id 172.16.1.2; - local-address 172.16.1.2; - local-as 65002; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 2; + encoder text; +} +neighbor 172.16.1.254 { + router-id 172.16.1.2; + local-address 172.16.1.2; + local-as 65002; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_multiview_topo1/peer3/exa-send.py b/tests/topotests/bgp_multiview_topo1/peer3/exa-send.py index 09f6ea59e5..0e50d46041 100755 --- a/tests/topotests/bgp_multiview_topo1/peer3/exa-send.py +++ b/tests/topotests/bgp_multiview_topo1/peer3/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_multiview_topo1/peer3/exabgp.cfg b/tests/topotests/bgp_multiview_topo1/peer3/exabgp.cfg index ef1b249aeb..0afc484c69 100644 --- a/tests/topotests/bgp_multiview_topo1/peer3/exabgp.cfg +++ b/tests/topotests/bgp_multiview_topo1/peer3/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 3 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 3"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 3 10; + encoder text; +} - neighbor 172.16.1.254 { - router-id 172.16.1.3; - local-address 172.16.1.3; - local-as 65003; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 3; + encoder text; +} +neighbor 172.16.1.254 { + router-id 172.16.1.3; + local-address 172.16.1.3; + local-as 65003; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_multiview_topo1/peer4/exa-send.py b/tests/topotests/bgp_multiview_topo1/peer4/exa-send.py index 09f6ea59e5..0e50d46041 100755 --- a/tests/topotests/bgp_multiview_topo1/peer4/exa-send.py +++ b/tests/topotests/bgp_multiview_topo1/peer4/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_multiview_topo1/peer4/exabgp.cfg b/tests/topotests/bgp_multiview_topo1/peer4/exabgp.cfg index 7c50f73b26..0f5b536d9a 100644 --- a/tests/topotests/bgp_multiview_topo1/peer4/exabgp.cfg +++ b/tests/topotests/bgp_multiview_topo1/peer4/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 4 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 4"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 4 10; + encoder text; +} - neighbor 172.16.1.254 { - router-id 172.16.1.4; - local-address 172.16.1.4; - local-as 65004; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 4; + encoder text; +} +neighbor 172.16.1.254 { + router-id 172.16.1.4; + local-address 172.16.1.4; + local-as 65004; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_multiview_topo1/peer5/exa-send.py b/tests/topotests/bgp_multiview_topo1/peer5/exa-send.py index 09f6ea59e5..0e50d46041 100755 --- a/tests/topotests/bgp_multiview_topo1/peer5/exa-send.py +++ b/tests/topotests/bgp_multiview_topo1/peer5/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_multiview_topo1/peer5/exabgp.cfg b/tests/topotests/bgp_multiview_topo1/peer5/exabgp.cfg index 22163c7fb1..365aa6b8f2 100644 --- a/tests/topotests/bgp_multiview_topo1/peer5/exabgp.cfg +++ b/tests/topotests/bgp_multiview_topo1/peer5/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 5 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 5"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 5 10; + encoder text; +} - neighbor 172.16.1.254 { - router-id 172.16.1.5; - local-address 172.16.1.5; - local-as 65005; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 5; + encoder text; +} +neighbor 172.16.1.254 { + router-id 172.16.1.5; + local-address 172.16.1.5; + local-as 65005; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_multiview_topo1/peer6/exa-send.py b/tests/topotests/bgp_multiview_topo1/peer6/exa-send.py index 09f6ea59e5..0e50d46041 100755 --- a/tests/topotests/bgp_multiview_topo1/peer6/exa-send.py +++ b/tests/topotests/bgp_multiview_topo1/peer6/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_multiview_topo1/peer6/exabgp.cfg b/tests/topotests/bgp_multiview_topo1/peer6/exabgp.cfg index 40b54c33c5..10380334b8 100644 --- a/tests/topotests/bgp_multiview_topo1/peer6/exabgp.cfg +++ b/tests/topotests/bgp_multiview_topo1/peer6/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 6 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 6"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 6 10; + encoder text; +} - neighbor 172.16.1.254 { - router-id 172.16.1.6; - local-address 172.16.1.6; - local-as 65006; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 6; + encoder text; +} +neighbor 172.16.1.254 { + router-id 172.16.1.6; + local-address 172.16.1.6; + local-as 65006; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_multiview_topo1/peer7/exa-send.py b/tests/topotests/bgp_multiview_topo1/peer7/exa-send.py index 09f6ea59e5..0e50d46041 100755 --- a/tests/topotests/bgp_multiview_topo1/peer7/exa-send.py +++ b/tests/topotests/bgp_multiview_topo1/peer7/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_multiview_topo1/peer7/exabgp.cfg b/tests/topotests/bgp_multiview_topo1/peer7/exabgp.cfg index 33312d052f..7411338abd 100644 --- a/tests/topotests/bgp_multiview_topo1/peer7/exabgp.cfg +++ b/tests/topotests/bgp_multiview_topo1/peer7/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 7 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 7"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 7 10; + encoder text; +} - neighbor 172.16.1.254 { - router-id 172.16.1.7; - local-address 172.16.1.7; - local-as 65007; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 7; + encoder text; +} +neighbor 172.16.1.254 { + router-id 172.16.1.7; + local-address 172.16.1.7; + local-as 65007; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_multiview_topo1/peer8/exa-send.py b/tests/topotests/bgp_multiview_topo1/peer8/exa-send.py index 09f6ea59e5..0e50d46041 100755 --- a/tests/topotests/bgp_multiview_topo1/peer8/exa-send.py +++ b/tests/topotests/bgp_multiview_topo1/peer8/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_multiview_topo1/peer8/exabgp.cfg b/tests/topotests/bgp_multiview_topo1/peer8/exabgp.cfg index 173ccb980e..17a4e497e1 100644 --- a/tests/topotests/bgp_multiview_topo1/peer8/exabgp.cfg +++ b/tests/topotests/bgp_multiview_topo1/peer8/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 8 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 8"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 8 10; + encoder text; +} - neighbor 172.16.1.254 { - router-id 172.16.1.8; - local-address 172.16.1.8; - local-as 65008; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 8; + encoder text; +} +neighbor 172.16.1.254 { + router-id 172.16.1.8; + local-address 172.16.1.8; + local-as 65008; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_oad/__init__.py b/tests/topotests/bgp_oad/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/bgp_oad/r1/frr.conf b/tests/topotests/bgp_oad/r1/frr.conf new file mode 100644 index 0000000000..39045ba648 --- /dev/null +++ b/tests/topotests/bgp_oad/r1/frr.conf @@ -0,0 +1,21 @@ +! +int r1-eth0 + ip address 192.168.1.1/24 +! +router bgp 65001 + no bgp ebgp-requires-policy + neighbor 192.168.1.2 remote-as external + neighbor 192.168.1.2 timers 1 3 + neighbor 192.168.1.2 timers connect 1 + neighbor 192.168.1.2 oad + neighbor 192.168.1.4 remote-as external + neighbor 192.168.1.4 timers 1 3 + neighbor 192.168.1.4 timers connect 1 + address-family ipv4 unicast + neighbor 192.168.1.4 route-map r4 in + exit-address-family +! +route-map r4 permit 10 + set local-preference 123 + set metric 123 +exit diff --git a/tests/topotests/bgp_oad/r2/frr.conf b/tests/topotests/bgp_oad/r2/frr.conf new file mode 100644 index 0000000000..fdd23f32b4 --- /dev/null +++ b/tests/topotests/bgp_oad/r2/frr.conf @@ -0,0 +1,18 @@ +! +int r2-eth0 + ip address 192.168.1.2/24 +! +int r2-eth1 + ip address 192.168.2.2/24 +! +router bgp 65002 + no bgp ebgp-requires-policy + neighbor 192.168.1.1 remote-as external + neighbor 192.168.1.1 timers 1 3 + neighbor 192.168.1.1 timers connect 1 + neighbor 192.168.1.1 oad + neighbor 192.168.2.3 remote-as external + neighbor 192.168.2.3 timers 1 3 + neighbor 192.168.2.3 timers connect 1 + neighbor 192.168.2.3 oad +! diff --git a/tests/topotests/bgp_oad/r3/frr.conf b/tests/topotests/bgp_oad/r3/frr.conf new file mode 100644 index 0000000000..02dd5adfe1 --- /dev/null +++ b/tests/topotests/bgp_oad/r3/frr.conf @@ -0,0 +1,22 @@ +! +int lo + ip address 10.10.10.10/32 +! +int r3-eth0 + ip address 192.168.2.3/24 +! +router bgp 65003 + no bgp ebgp-requires-policy + neighbor 192.168.2.2 remote-as external + neighbor 192.168.2.2 timers 1 3 + neighbor 192.168.2.2 timers connect 1 + neighbor 192.168.2.2 oad + ! + address-family ipv4 unicast + redistribute connected route-map connected + exit-address-family +! +route-map connected permit 10 + set local-preference 123 + set metric 123 +! diff --git a/tests/topotests/bgp_oad/r4/frr.conf b/tests/topotests/bgp_oad/r4/frr.conf new file mode 100644 index 0000000000..83dcf391b7 --- /dev/null +++ b/tests/topotests/bgp_oad/r4/frr.conf @@ -0,0 +1,16 @@ +! +int r4-eth0 + ip address 192.168.1.4/24 +! +int r4-eth1 + ip address 192.168.4.4/24 +! +router bgp 65004 + no bgp ebgp-requires-policy + neighbor 192.168.1.1 remote-as external + neighbor 192.168.1.1 timers 1 3 + neighbor 192.168.1.1 timers connect 1 + neighbor 192.168.4.5 remote-as external + neighbor 192.168.4.5 timers 1 3 + neighbor 192.168.4.5 timers connect 1 +! diff --git a/tests/topotests/bgp_oad/r5/frr.conf b/tests/topotests/bgp_oad/r5/frr.conf new file mode 100644 index 0000000000..f8e1609d15 --- /dev/null +++ b/tests/topotests/bgp_oad/r5/frr.conf @@ -0,0 +1,17 @@ +! +int lo + ip address 10.10.10.10/32 +! +int r5-eth0 + ip address 192.168.4.5/24 +! +router bgp 65005 + no bgp ebgp-requires-policy + neighbor 192.168.4.4 remote-as external + neighbor 192.168.4.4 timers 1 3 + neighbor 192.168.4.4 timers connect 1 + ! + address-family ipv4 unicast + redistribute connected + exit-address-family +! diff --git a/tests/topotests/bgp_oad/test_bgp_oad.py b/tests/topotests/bgp_oad/test_bgp_oad.py new file mode 100644 index 0000000000..b26c548357 --- /dev/null +++ b/tests/topotests/bgp_oad/test_bgp_oad.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# Copyright (c) 2023 by +# Donatas Abraitis <donatas@opensourcerouting.org> +# + +""" +Test if local-preference is passed between different EBGP peers when +EBGP-OAD is configured. +""" + +import os +import re +import sys +import json +import pytest +import functools + +pytestmark = pytest.mark.bgpd + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.common_config import step + +pytestmark = [pytest.mark.bgpd] + + +def setup_module(mod): + topodef = {"s1": ("r1", "r2", "r4"), "s2": ("r2", "r3"), "s3": ("r4", "r5")} + tgen = Topogen(topodef, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for _, (rname, router) in enumerate(router_list.items(), 1): + router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname))) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_dynamic_capability_role(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + + def _bgp_converge(): + output = json.loads(r1.vtysh_cmd("show bgp ipv4 unicast 10.10.10.10/32 json")) + expected = { + "paths": [ + { + "aspath": {"string": "65002 65003"}, + "metric": 123, + "locPrf": 123, + "peer": { + "hostname": "r2", + "type": "external (oad)", + }, + }, + { + "aspath": {"string": "65004 65005"}, + "metric": 123, + "locPrf": 123, + "bestpath": {"selectionReason": "Peer Type"}, + "peer": { + "hostname": "r4", + "type": "external", + }, + }, + ] + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_converge, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Can't converge" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_path_attribute_discard/test_bgp_path_attribute_discard.py b/tests/topotests/bgp_path_attribute_discard/test_bgp_path_attribute_discard.py index ebaab60341..c97cd0bdda 100644 --- a/tests/topotests/bgp_path_attribute_discard/test_bgp_path_attribute_discard.py +++ b/tests/topotests/bgp_path_attribute_discard/test_bgp_path_attribute_discard.py @@ -83,7 +83,7 @@ def _bgp_converge(): "paths": [ { "valid": True, - "originatorId": "10.0.0.2", + "originatorId": None, "community": { "string": "65001:102", }, @@ -98,12 +98,12 @@ def _bgp_converge(): _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) assert result is None, "Failed bgp convergence" - step("Discard atomic-aggregate, community, and originator-id attributes from peer1") + step("Discard atomic-aggregate, and community attributes from peer1") r1.vtysh_cmd( """ configure terminal router bgp - neighbor 10.0.0.2 path-attribute discard 6 8 9 + neighbor 10.0.0.2 path-attribute discard 6 8 """ ) @@ -137,7 +137,7 @@ def _bgp_check_if_attributes_discarded(): _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) assert ( result is None - ), "Failed to discard path attributes (atomic-aggregate, community, and originator-id)" + ), "Failed to discard path attributes (atomic-aggregate, community)" def test_memory_leak(): diff --git a/tests/topotests/bgp_peer_group/r3/bgpd.conf b/tests/topotests/bgp_peer_group/r3/bgpd.conf index eb2fca15fb..5a1340fb0b 100644 --- a/tests/topotests/bgp_peer_group/r3/bgpd.conf +++ b/tests/topotests/bgp_peer_group/r3/bgpd.conf @@ -1,7 +1,11 @@ ! router bgp 65003 - neighbor PG peer-group - neighbor PG remote-as external - neighbor PG timers 3 10 - neighbor 192.168.255.1 peer-group PG + no bgp ebgp-requires-policy + neighbor PG peer-group + neighbor PG remote-as external + neighbor PG timers 3 10 + neighbor 192.168.255.1 peer-group PG + address-family ipv4 unicast + redistribute connected + exit-address-family ! diff --git a/tests/topotests/bgp_peer_group/test_bgp_peer-group.py b/tests/topotests/bgp_peer_group/test_bgp_peer-group.py index e8c3feb76f..a91fade049 100644 --- a/tests/topotests/bgp_peer_group/test_bgp_peer-group.py +++ b/tests/topotests/bgp_peer_group/test_bgp_peer-group.py @@ -74,9 +74,26 @@ def _bgp_peer_group_configured(): return topotest.json_cmp(output, expected) test_func = functools.partial(_bgp_peer_group_configured) - success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed bgp convergence in r1" - assert result is None, 'Failed bgp convergence in "{}"'.format(tgen.gears["r1"]) + def _bgp_peer_group_check_advertised_routes(): + output = json.loads( + tgen.gears["r3"].vtysh_cmd("show ip bgp neighbor PG advertised-routes json") + ) + expected = { + "advertisedRoutes": { + "192.168.255.0/24": { + "valid": True, + "best": True, + } + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_peer_group_check_advertised_routes) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Failed checking advertised routes from r3" if __name__ == "__main__": diff --git a/tests/topotests/bgp_peer_type_multipath_relax/exabgp.env b/tests/topotests/bgp_peer_type_multipath_relax/exabgp.env index 6c554f5fa8..989228a293 100644 --- a/tests/topotests/bgp_peer_type_multipath_relax/exabgp.env +++ b/tests/topotests/bgp_peer_type_multipath_relax/exabgp.env @@ -1,5 +1,6 @@ [exabgp.api] +ack = false encoder = text highres = false respawn = false @@ -43,7 +44,7 @@ enable = false file = '' [exabgp.reactor] -speed = 1.0 +speed = 5.0 [exabgp.tcp] acl = false diff --git a/tests/topotests/bgp_peer_type_multipath_relax/peer1/exa_readpipe.py b/tests/topotests/bgp_peer_type_multipath_relax/peer1/exa_readpipe.py index 0f998c1613..6c1f8b092f 100644 --- a/tests/topotests/bgp_peer_type_multipath_relax/peer1/exa_readpipe.py +++ b/tests/topotests/bgp_peer_type_multipath_relax/peer1/exa_readpipe.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 "Helper script to read api commands from a pipe and feed them to ExaBGP" import sys diff --git a/tests/topotests/bgp_peer_type_multipath_relax/peer1/exabgp.cfg b/tests/topotests/bgp_peer_type_multipath_relax/peer1/exabgp.cfg index 4a7dc48126..e6606d22ff 100644 --- a/tests/topotests/bgp_peer_type_multipath_relax/peer1/exabgp.cfg +++ b/tests/topotests/bgp_peer_type_multipath_relax/peer1/exabgp.cfg @@ -1,21 +1,17 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa_readpipe.py /var/run/exabgp_peer1.in"; - encoder text; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 1"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa_readpipe.py /var/run/exabgp_peer1.in; + encoder text; +} - neighbor 10.0.1.1 { - router-id 10.0.1.2; - local-address 10.0.1.2; - local-as 64510; - peer-as 64510; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 1; + encoder text; +} +neighbor 10.0.1.1 { + router-id 10.0.1.2; + local-address 10.0.1.2; + local-as 64510; + peer-as 64510; + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_peer_type_multipath_relax/peer2/exa_readpipe.py b/tests/topotests/bgp_peer_type_multipath_relax/peer2/exa_readpipe.py index 0f998c1613..6c1f8b092f 100644 --- a/tests/topotests/bgp_peer_type_multipath_relax/peer2/exa_readpipe.py +++ b/tests/topotests/bgp_peer_type_multipath_relax/peer2/exa_readpipe.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 "Helper script to read api commands from a pipe and feed them to ExaBGP" import sys diff --git a/tests/topotests/bgp_peer_type_multipath_relax/peer2/exabgp.cfg b/tests/topotests/bgp_peer_type_multipath_relax/peer2/exabgp.cfg index b53b054550..6a6ba0bb78 100644 --- a/tests/topotests/bgp_peer_type_multipath_relax/peer2/exabgp.cfg +++ b/tests/topotests/bgp_peer_type_multipath_relax/peer2/exabgp.cfg @@ -1,21 +1,17 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa_readpipe.py /var/run/exabgp_peer2.in"; - encoder text; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 2"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa_readpipe.py /var/run/exabgp_peer2.in; + encoder text; +} - neighbor 10.0.2.1 { - router-id 10.0.2.2; - local-address 10.0.2.2; - local-as 64511; - peer-as 64511; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 2; + encoder text; +} +neighbor 10.0.2.1 { + router-id 10.0.2.2; + local-address 10.0.2.2; + local-as 64511; + peer-as 64511; + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_peer_type_multipath_relax/peer3/exa_readpipe.py b/tests/topotests/bgp_peer_type_multipath_relax/peer3/exa_readpipe.py index 0f998c1613..6c1f8b092f 100644 --- a/tests/topotests/bgp_peer_type_multipath_relax/peer3/exa_readpipe.py +++ b/tests/topotests/bgp_peer_type_multipath_relax/peer3/exa_readpipe.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 "Helper script to read api commands from a pipe and feed them to ExaBGP" import sys diff --git a/tests/topotests/bgp_peer_type_multipath_relax/peer3/exabgp.cfg b/tests/topotests/bgp_peer_type_multipath_relax/peer3/exabgp.cfg index 6a1cc2fb3f..9714b1f3b5 100644 --- a/tests/topotests/bgp_peer_type_multipath_relax/peer3/exabgp.cfg +++ b/tests/topotests/bgp_peer_type_multipath_relax/peer3/exabgp.cfg @@ -1,21 +1,17 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa_readpipe.py /var/run/exabgp_peer3.in"; - encoder text; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 3"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa_readpipe.py /var/run/exabgp_peer3.in; + encoder text; +} - neighbor 10.0.3.1 { - router-id 10.0.3.2; - local-address 10.0.3.2; - local-as 64502; - peer-as 64501; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 3; + encoder text; +} +neighbor 10.0.3.1 { + router-id 10.0.3.2; + local-address 10.0.3.2; + local-as 64502; + peer-as 64501; + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_peer_type_multipath_relax/peer4/exa_readpipe.py b/tests/topotests/bgp_peer_type_multipath_relax/peer4/exa_readpipe.py index 0f998c1613..6c1f8b092f 100644 --- a/tests/topotests/bgp_peer_type_multipath_relax/peer4/exa_readpipe.py +++ b/tests/topotests/bgp_peer_type_multipath_relax/peer4/exa_readpipe.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 "Helper script to read api commands from a pipe and feed them to ExaBGP" import sys diff --git a/tests/topotests/bgp_peer_type_multipath_relax/peer4/exabgp.cfg b/tests/topotests/bgp_peer_type_multipath_relax/peer4/exabgp.cfg index 2cc26cb80f..8c38a881ce 100644 --- a/tests/topotests/bgp_peer_type_multipath_relax/peer4/exabgp.cfg +++ b/tests/topotests/bgp_peer_type_multipath_relax/peer4/exabgp.cfg @@ -1,21 +1,17 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa_readpipe.py /var/run/exabgp_peer4.in"; - encoder text; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 4"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa_readpipe.py /var/run/exabgp_peer4.in; + encoder text; +} - neighbor 10.0.4.1 { - router-id 10.0.4.2; - local-address 10.0.4.2; - local-as 64503; - peer-as 64501; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 4; + encoder text; +} +neighbor 10.0.4.1 { + router-id 10.0.4.2; + local-address 10.0.4.2; + local-as 64503; + peer-as 64501; + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/bgp_peer_type_multipath_relax/test_bgp_peer-type_multipath-relax.py b/tests/topotests/bgp_peer_type_multipath_relax/test_bgp_peer-type_multipath-relax.py index ad6674c524..9239be9221 100755 --- a/tests/topotests/bgp_peer_type_multipath_relax/test_bgp_peer-type_multipath-relax.py +++ b/tests/topotests/bgp_peer_type_multipath_relax/test_bgp_peer-type_multipath-relax.py @@ -62,6 +62,19 @@ pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] +# Prefixes used in the test +prefix1 = "203.0.113.0/30" +prefix2 = "203.0.113.4/30" +prefix3 = "203.0.113.8/30" +# Next hops used for iBGP/confed routes +resolved_nh1 = "198.51.100.1" +resolved_nh2 = "198.51.100.2" +# BGP route used for recursive resolution +bgp_resolving_prefix = "198.51.100.0/24" +# Next hop that will require non-connected recursive resolution +ebgp_resolved_nh = "198.51.100.10" + + def build_topo(tgen): "Build function" @@ -125,36 +138,26 @@ def teardown_module(mod): tgen.stop_topology() -def test_bgp_peer_type_multipath_relax(): +def exabgp_cmd(peer, cmd): + pipe = open("/run/exabgp_{}.in".format(peer), "w") + with pipe: + pipe.write(cmd) + pipe.close() + + +def test_bgp_peer_type_multipath_relax_test1(): tgen = get_topogen() # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) - def exabgp_cmd(peer, cmd): - pipe = open("/run/exabgp_{}.in".format(peer), "w") - with pipe: - pipe.write(cmd) - pipe.close() - - # Prefixes used in the test - prefix1 = "203.0.113.0/30" - prefix2 = "203.0.113.4/30" - prefix3 = "203.0.113.8/30" - # Next hops used for iBGP/confed routes - resolved_nh1 = "198.51.100.1" - resolved_nh2 = "198.51.100.2" - # BGP route used for recursive resolution - bgp_resolving_prefix = "198.51.100.0/24" - # Next hop that will require non-connected recursive resolution - ebgp_resolved_nh = "198.51.100.10" + r1 = tgen.gears["r1"] # Send a non-connected route to resolve others exabgp_cmd( "peer3", "announce route {} next-hop self\n".format(bgp_resolving_prefix) ) - router = tgen.gears["r1"] # It seems that if you write to the exabgp socket too quickly in # succession, requests get lost. So verify prefix1 now instead of @@ -177,7 +180,7 @@ def exabgp_cmd(peer, cmd): expected = json.loads(open(reffile).read()) test_func = functools.partial( topotest.router_json_cmp, - router, + r1, "show ip bgp {} json".format(prefix1), expected, ) @@ -185,6 +188,16 @@ def exabgp_cmd(peer, cmd): assertMsg = "Mixed-type multipath not found" assert res is None, assertMsg + +def test_bgp_peer_type_multipath_relax_test2(): + tgen = get_topogen() + + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + logger.info("Create and verify eBGP and iBGP+confed multipaths") exabgp_cmd( "peer1", @@ -203,38 +216,66 @@ def exabgp_cmd(peer, cmd): reffile = os.path.join(CWD, "r1/multipath.json") expected = json.loads(open(reffile).read()) test_func = functools.partial( - topotest.router_json_cmp, router, "show ip bgp json", expected + topotest.router_json_cmp, r1, "show ip bgp json", expected ) _, res = topotest.run_and_expect(test_func, None, count=10, wait=1) assertMsg = "Not all expected multipaths found" assert res is None, assertMsg + +def test_bgp_peer_type_multipath_relax_test3(): + tgen = get_topogen() + + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + logger.info("Toggle peer-type multipath-relax and verify the changes") - router.vtysh_cmd( + r1.vtysh_cmd( "conf\n router bgp 64510\n no bgp bestpath peer-type multipath-relax\n" ) # This file verifies "multipath" is not set reffile = os.path.join(CWD, "r1/not-multipath.json") expected = json.loads(open(reffile).read()) test_func = functools.partial( - topotest.router_json_cmp, router, "show ip bgp json", expected + topotest.router_json_cmp, r1, "show ip bgp json", expected ) _, res = topotest.run_and_expect(test_func, None, count=10, wait=1) assertMsg = "Disabling peer-type multipath-relax did not take effect" assert res is None, assertMsg - router.vtysh_cmd( - "conf\n router bgp 64510\n bgp bestpath peer-type multipath-relax\n" - ) + +def test_bgp_peer_type_multipath_relax_test4(): + tgen = get_topogen() + + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + + r1.vtysh_cmd("conf\n router bgp 64510\n bgp bestpath peer-type multipath-relax\n") reffile = os.path.join(CWD, "r1/multipath.json") expected = json.loads(open(reffile).read()) test_func = functools.partial( - topotest.router_json_cmp, router, "show ip bgp json", expected + topotest.router_json_cmp, r1, "show ip bgp json", expected ) _, res = topotest.run_and_expect(test_func, None, count=10, wait=1) assertMsg = "Reenabling peer-type multipath-relax did not take effect" assert res is None, assertMsg + +def test_bgp_peer_type_multipath_relax_test5(): + tgen = get_topogen() + + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + logger.info("Check recursive resolution of eBGP next hops is not affected") # eBGP next hop resolution rejects recursively resolved next hops by # default, even with peer-type multipath-relax @@ -245,7 +286,7 @@ def exabgp_cmd(peer, cmd): expected = json.loads(open(reffile).read()) test_func = functools.partial( topotest.router_json_cmp, - router, + r1, "show ip bgp {} json".format(prefix3), expected, ) @@ -253,6 +294,16 @@ def exabgp_cmd(peer, cmd): assertMsg = "Recursive eBGP next hop not as expected for {}".format(prefix3) assert res is None, assertMsg + +def test_bgp_peer_type_multipath_relax_test6(): + tgen = get_topogen() + + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + exabgp_cmd( "peer4", "announce route {} next-hop {}\n".format(prefix1, ebgp_resolved_nh) ) @@ -260,7 +311,7 @@ def exabgp_cmd(peer, cmd): expected = json.loads(open(reffile).read()) test_func = functools.partial( topotest.router_json_cmp, - router, + r1, "show ip bgp {} json".format(prefix1), expected, ) @@ -268,14 +319,24 @@ def exabgp_cmd(peer, cmd): assertMsg = "Recursive eBGP next hop not as expected for {}".format(prefix1) assert res is None, assertMsg + +def test_bgp_peer_type_multipath_relax_test7(): + tgen = get_topogen() + + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + # When other config allows recursively resolved eBGP next hops, # such next hops in all-eBGP multipaths should be valid - router.vtysh_cmd("conf\n router bgp 64510\n neighbor 10.0.4.2 ebgp-multihop\n") + r1.vtysh_cmd("conf\n router bgp 64510\n neighbor 10.0.4.2 ebgp-multihop\n") reffile = os.path.join(CWD, "r1/prefix3-recursive.json") expected = json.loads(open(reffile).read()) test_func = functools.partial( topotest.router_json_cmp, - router, + r1, "show ip bgp {} json".format(prefix3), expected, ) @@ -287,7 +348,7 @@ def exabgp_cmd(peer, cmd): expected = json.loads(open(reffile).read()) test_func = functools.partial( topotest.router_json_cmp, - router, + r1, "show ip bgp {} json".format(prefix1), expected, ) @@ -295,6 +356,16 @@ def exabgp_cmd(peer, cmd): assertMsg = "Recursive eBGP next hop not as expected for {}".format(prefix1) assert res is None, assertMsg + +def test_bgp_peer_type_multipath_relax_test8(): + tgen = get_topogen() + + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + logger.info("Check mixed-type multipath next hop recursive resolution in FIB") # There are now two eBGP-learned routes with a recursively resolved next; # hop; one is all-eBGP multipath, and the other is iBGP/eBGP/ @@ -305,7 +376,7 @@ def exabgp_cmd(peer, cmd): expected = json.loads(open(reffile).read()) test_func = functools.partial( topotest.router_json_cmp, - router, + r1, "show ip route {} json".format(prefix3), expected, ) @@ -313,6 +384,16 @@ def exabgp_cmd(peer, cmd): assertMsg = "FIB next hops mismatch for all-eBGP multipath" assert res is None, assertMsg + +def test_bgp_peer_type_multipath_relax_test9(): + tgen = get_topogen() + + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + # check confed-external enables recursively resolved next hops by itself exabgp_cmd( "peer1", @@ -324,7 +405,7 @@ def exabgp_cmd(peer, cmd): expected = json.loads(open(reffile).read()) test_func = functools.partial( topotest.router_json_cmp, - router, + r1, "show ip route {} json".format(prefix1), expected, ) @@ -332,6 +413,16 @@ def exabgp_cmd(peer, cmd): assertMsg = "FIB next hops mismatch for eBGP+confed-external multipath" assert res is None, assertMsg + +def test_bgp_peer_type_multipath_relax_test10(): + tgen = get_topogen() + + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + # check iBGP by itself exabgp_cmd( "peer1", @@ -349,7 +440,7 @@ def exabgp_cmd(peer, cmd): expected = json.loads(open(reffile).read()) test_func = functools.partial( topotest.router_json_cmp, - router, + r1, "show ip route {} json".format(prefix1), expected, ) diff --git a/tests/topotests/bgp_prefix_sid/exabgp.env b/tests/topotests/bgp_prefix_sid/exabgp.env index 6c554f5fa8..bb36af522a 100644 --- a/tests/topotests/bgp_prefix_sid/exabgp.env +++ b/tests/topotests/bgp_prefix_sid/exabgp.env @@ -1,5 +1,6 @@ [exabgp.api] +ack = false encoder = text highres = false respawn = false diff --git a/tests/topotests/bgp_prefix_sid/peer1/exabgp.cfg b/tests/topotests/bgp_prefix_sid/peer1/exabgp.cfg index 5b55366a0e..a5108ff0da 100644 --- a/tests/topotests/bgp_prefix_sid/peer1/exabgp.cfg +++ b/tests/topotests/bgp_prefix_sid/peer1/exabgp.cfg @@ -1,103 +1,101 @@ -group controller { - neighbor 10.0.0.1 { - router-id 10.0.0.101; - local-address 10.0.0.101; - local-as 2; - peer-as 1; +neighbor 10.0.0.1 { + router-id 10.0.0.101; + local-address 10.0.0.101; + local-as 2; + peer-as 1; - family { - ipv4 nlri-mpls; - } + family { + ipv4 nlri-mpls; + } - static { - # ref: draft-ietf-idr-bgp-prefix-sid-27 - # - # IANA temporarily assigned the following: - # attribute code type (suggested value: 40) to - # the BGP Prefix-SID attribute - # - # 0 1 2 3 - # 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - # | Type | Length | RESERVED | - # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - # | Flags | Label Index | - # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - # | Label Index | - # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - # Figure. Label-Index TLV (Prefix-SID type-1) - # - # 0 1 2 3 - # 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - # | Type | Length | Flags | - # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - # | Flags | - # +-+-+-+-+-+-+-+-+ - # - # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - # | SRGB 1 (6 octets) | - # | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - # | | - # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - # - # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - # | SRGB n (6 octets) | - # | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - # | | - # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<Paste> - # Figure. Originator SRGB TLV (Prefix-SID type-3) + static { + # ref: draft-ietf-idr-bgp-prefix-sid-27 + # + # IANA temporarily assigned the following: + # attribute code type (suggested value: 40) to + # the BGP Prefix-SID attribute + # + # 0 1 2 3 + # 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # | Type | Length | RESERVED | + # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # | Flags | Label Index | + # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # | Label Index | + # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # Figure. Label-Index TLV (Prefix-SID type-1) + # + # 0 1 2 3 + # 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # | Type | Length | Flags | + # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # | Flags | + # +-+-+-+-+-+-+-+-+ + # + # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # | SRGB 1 (6 octets) | + # | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # | | + # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # + # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # | SRGB n (6 octets) | + # | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # | | + # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<Paste> + # Figure. Originator SRGB TLV (Prefix-SID type-3) - # ExaBGP generic-attribute binary pattern: - # Attribute-type: 0x28 (40:BGP_PREFIX_SID) - # Attribute-flag: 0xc0 (Option, Transitive) - # Attribute-body: Label-Index TLV and Originator SRGB TLV - # Label-Index TLV: 0x01000700000000000001 - # Type (08bit): 0x01 - # Length (16bit): 0x0007 - # RESERVED (08bit): 0x00 - # Flags (16bit): 0x0000 - # Label Index (32bit): 0x00000001 - # Originator SRGB TLV: 0x03000800000c350000000a - # Type (08bit): 0x03 - # Length (16bit): 0x0008 (nb-SRGB is 1) - # Flags (16bit): 0x0000 - # SRGB1 (48bit): 0x0c3500:0x00000a (800000-800010 is SRGB1) - route 3.0.0.1/32 next-hop 10.0.0.101 label [800001] attribute [0x28 0xc0 0x0100070000000000000103000800000c350000000a]; + # ExaBGP generic-attribute binary pattern: + # Attribute-type: 0x28 (40:BGP_PREFIX_SID) + # Attribute-flag: 0xc0 (Option, Transitive) + # Attribute-body: Label-Index TLV and Originator SRGB TLV + # Label-Index TLV: 0x01000700000000000001 + # Type (08bit): 0x01 + # Length (16bit): 0x0007 + # RESERVED (08bit): 0x00 + # Flags (16bit): 0x0000 + # Label Index (32bit): 0x00000001 + # Originator SRGB TLV: 0x03000800000c350000000a + # Type (08bit): 0x03 + # Length (16bit): 0x0008 (nb-SRGB is 1) + # Flags (16bit): 0x0000 + # SRGB1 (48bit): 0x0c3500:0x00000a (800000-800010 is SRGB1) + route 3.0.0.1/32 next-hop 10.0.0.101 label [800001] attribute [0x28 0xc0 0x0100070000000000000103000800000c350000000a]; - # ExaBGP generic-attribute binary pattern: - # Attribute-type: 0x28 (40:BGP_PREFIX_SID) - # Attribute-flag: 0xc0 (Option, Transitive) - # Attribute-body: Label-Index TLV and Originator SRGB TLV - # Label-Index TLV: 0x01000700000000000001 - # Type (08bit): 0x01 - # Length (16bit): 0x0007 - # RESERVED (08bit): 0x00 - # Flags (16bit): 0x0000 - # Label Index (32bit): 0x00000002 - # Originator SRGB TLV: 0x03000800000c350000000a - # Type (08bit): 0x03 - # Length (16bit): 0x0008 (nb-SRGB is 1) - # Flags (16bit): 0x0000 - # SRGB1 (48bit): 0x0c3500:0x00000a (800000-800010 is SRGB1) - route 3.0.0.2/32 next-hop 10.0.0.101 label [800002] attribute [0x28 0xc0 0x0100070000000000000203000800000c350000000a]; + # ExaBGP generic-attribute binary pattern: + # Attribute-type: 0x28 (40:BGP_PREFIX_SID) + # Attribute-flag: 0xc0 (Option, Transitive) + # Attribute-body: Label-Index TLV and Originator SRGB TLV + # Label-Index TLV: 0x01000700000000000001 + # Type (08bit): 0x01 + # Length (16bit): 0x0007 + # RESERVED (08bit): 0x00 + # Flags (16bit): 0x0000 + # Label Index (32bit): 0x00000002 + # Originator SRGB TLV: 0x03000800000c350000000a + # Type (08bit): 0x03 + # Length (16bit): 0x0008 (nb-SRGB is 1) + # Flags (16bit): 0x0000 + # SRGB1 (48bit): 0x0c3500:0x00000a (800000-800010 is SRGB1) + route 3.0.0.2/32 next-hop 10.0.0.101 label [800002] attribute [0x28 0xc0 0x0100070000000000000203000800000c350000000a]; - # ExaBGP generic-attribute binary pattern: - # Attribute-type: 0x28 (40:BGP_PREFIX_SID) - # Attribute-flag: 0xc0 (Option, Transitive) - # Attribute-body: Label-Index TLV and Originator SRGB TLV - # Label-Index TLV: 0x01000700000000000001 - # Type (08bit): 0x01 - # Length (16bit): 0x0007 - # RESERVED (08bit): 0x00 - # Flags (16bit): 0x0000 - # Label Index (32bit): 0x00000003 - # Originator SRGB TLV: 0x03000800000c350000000a - # Type (08bit): 0x03 - # Length (16bit): 0x0008 (nb-SRGB is 1) - # Flags (16bit): 0x0000 - # SRGB1 (48bit): 0x0c3500:0x00000a (800000-800010 is SRGB1) - route 3.0.0.3/32 next-hop 10.0.0.101 label [800003] attribute [0x28 0xc0 0x0100070000000000000303000800000c350000000a]; - } + # ExaBGP generic-attribute binary pattern: + # Attribute-type: 0x28 (40:BGP_PREFIX_SID) + # Attribute-flag: 0xc0 (Option, Transitive) + # Attribute-body: Label-Index TLV and Originator SRGB TLV + # Label-Index TLV: 0x01000700000000000001 + # Type (08bit): 0x01 + # Length (16bit): 0x0007 + # RESERVED (08bit): 0x00 + # Flags (16bit): 0x0000 + # Label Index (32bit): 0x00000003 + # Originator SRGB TLV: 0x03000800000c350000000a + # Type (08bit): 0x03 + # Length (16bit): 0x0008 (nb-SRGB is 1) + # Flags (16bit): 0x0000 + # SRGB1 (48bit): 0x0c3500:0x00000a (800000-800010 is SRGB1) + route 3.0.0.3/32 next-hop 10.0.0.101 label [800003] attribute [0x28 0xc0 0x0100070000000000000303000800000c350000000a]; } } diff --git a/tests/topotests/bgp_prefix_sid/peer2/exabgp.cfg b/tests/topotests/bgp_prefix_sid/peer2/exabgp.cfg index 379d0a3f43..50ebdc2319 100644 --- a/tests/topotests/bgp_prefix_sid/peer2/exabgp.cfg +++ b/tests/topotests/bgp_prefix_sid/peer2/exabgp.cfg @@ -1,19 +1,22 @@ -group controller { - - process receive-routes { - run "/etc/exabgp/exa-receive.py --no-timestamp 2"; - receive-routes; - encoder json; - } +process receive-routes { + run /etc/exabgp/exa-receive.py --no-timestamp 2; + encoder json; +} - neighbor 10.0.0.1 { - router-id 10.0.0.102; - local-address 10.0.0.102; - local-as 3; - peer-as 1; +neighbor 10.0.0.1 { + router-id 10.0.0.102; + local-address 10.0.0.102; + local-as 3; + peer-as 1; - family { - ipv4 nlri-mpls; + family { + ipv4 nlri-mpls; + } + api { + processes [ receive-routes ]; + receive { + parsed; + update; } } } diff --git a/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py b/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py index bfc083b506..1e6e731a18 100644 --- a/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py +++ b/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py @@ -120,13 +120,9 @@ def exabgp_get_update_prefix(filename, afi, nexthop, prefix): ret = ret.get(afi) if ret is None: continue - ret = ret.get(nexthop) - if ret is None: - continue - ret = ret.get(prefix) - if ret is None: - continue - return output + for nh in ret.get(nexthop, []): + if nh.get("nlri") == prefix: + return output return "Not found" @@ -135,33 +131,39 @@ def test_peer2_receive_prefix_sid_type1(): peer2 = tgen.gears["peer2"] logfile = "{}/{}-received.log".format(peer2.gearlogdir, peer2.name) - def _check_type1_peer2(prefix, labelindex): + def _check_type1_peer2(prefix, label): output = exabgp_get_update_prefix( logfile, "ipv4 nlri-mpls", "10.0.0.101", prefix ) expected = { "type": "update", "neighbor": { - "ip": "10.0.0.1", + "address": { + "peer": "10.0.0.1", + }, "message": { "update": { - "attribute": { - "attribute-0x28-0xE0": "0x010007000000{:08x}".format( - labelindex - ) + "announce": { + "ipv4 nlri-mpls": { + "10.0.0.101": [ + { + "nlri": prefix, + "label": [[label]], + } + ] + } }, - "announce": {"ipv4 nlri-mpls": {"10.0.0.101": {}}}, } }, }, } return topotest.json_cmp(output, expected) - test_func = functools.partial(_check_type1_peer2, "3.0.0.1/32", labelindex=1) + test_func = functools.partial(_check_type1_peer2, "3.0.0.1/32", label=8001) success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) assert result is None, 'Failed _check_type1_peer2 in "{}"'.format("peer2") - test_func = functools.partial(_check_type1_peer2, "3.0.0.2/32", labelindex=2) + test_func = functools.partial(_check_type1_peer2, "3.0.0.2/32", label=8002) success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) assert result is None, 'Failed _check_type1_peer2 in "{}"'.format("peer2") diff --git a/tests/topotests/bgp_prefix_sid2/peer1/exabgp.cfg b/tests/topotests/bgp_prefix_sid2/peer1/exabgp.cfg index 3819179570..7a291a3421 100644 --- a/tests/topotests/bgp_prefix_sid2/peer1/exabgp.cfg +++ b/tests/topotests/bgp_prefix_sid2/peer1/exabgp.cfg @@ -1,29 +1,27 @@ -group controller { - neighbor 10.0.0.1 { - router-id 10.0.0.101; - local-address 10.0.0.101; - local-as 2; - peer-as 1; +neighbor 10.0.0.1 { + router-id 10.0.0.101; + local-address 10.0.0.101; + local-as 2; + peer-as 1; - family { - ipv6 mpls-vpn; - } + family { + ipv6 mpls-vpn; + } - static { - route 2001:1::/64 { - rd 2:10; - next-hop 2001::2; - extended-community [ target:2:10 ]; - label 3; - attribute [0x28 0xc0 0x050019000100150020010db800010001000000000000000100ffff00 ]; - } - route 2001:2::/64 { - rd 2:10; - next-hop 2001::2; - extended-community [ target:2:10 ]; - label 3; - attribute [0x28 0xc0 0x050019000100150020010db800010001000000000000000100ffff00 ]; - } + static { + route 2001:1::/64 { + rd 2:10; + next-hop 2001::2; + extended-community [ target:2:10 ]; + label 3; + attribute [0x28 0xc0 0x050019000100150020010db800010001000000000000000100ffff00 ]; + } + route 2001:2::/64 { + rd 2:10; + next-hop 2001::2; + extended-community [ target:2:10 ]; + label 3; + attribute [0x28 0xc0 0x050019000100150020010db800010001000000000000000100ffff00 ]; } } } diff --git a/tests/topotests/bgp_prefix_sid2/r1/bgpd.conf b/tests/topotests/bgp_prefix_sid2/r1/bgpd.conf index ddc1f07e42..b3ca0e114d 100644 --- a/tests/topotests/bgp_prefix_sid2/r1/bgpd.conf +++ b/tests/topotests/bgp_prefix_sid2/r1/bgpd.conf @@ -1,5 +1,4 @@ log stdout notifications -log monitor notifications !log commands ! !debug bgp zebra @@ -22,5 +21,7 @@ router bgp 1 ! address-family ipv6 vpn neighbor 10.0.0.101 activate + neighbor 10.0.0.101 route-map DENY_ALL out exit-address-family ! +route-map DENY_ALL deny 10 diff --git a/tests/topotests/bgp_prefix_sid2/r1/vpnv6_rib_entry1.json b/tests/topotests/bgp_prefix_sid2/r1/vpnv6_rib_entry1.json index 42293b1fc7..65c51f1c8c 100644 --- a/tests/topotests/bgp_prefix_sid2/r1/vpnv6_rib_entry1.json +++ b/tests/topotests/bgp_prefix_sid2/r1/vpnv6_rib_entry1.json @@ -1,10 +1,6 @@ { "2:10":{ "prefix":"2001:1::\/64", - "advertisedTo":{ - "10.0.0.101":{ - } - }, "paths":[ { "aspath":{ diff --git a/tests/topotests/bgp_prefix_sid2/r1/vpnv6_rib_entry2.json b/tests/topotests/bgp_prefix_sid2/r1/vpnv6_rib_entry2.json index c9ad8714c1..4a12c2a880 100644 --- a/tests/topotests/bgp_prefix_sid2/r1/vpnv6_rib_entry2.json +++ b/tests/topotests/bgp_prefix_sid2/r1/vpnv6_rib_entry2.json @@ -1,10 +1,6 @@ { "2:10":{ "prefix":"2001:2::\/64", - "advertisedTo":{ - "10.0.0.101":{ - } - }, "paths":[ { "aspath":{ diff --git a/tests/topotests/bgp_redistribute_table/__init__.py b/tests/topotests/bgp_redistribute_table/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/bgp_redistribute_table/r1/bgpd.conf b/tests/topotests/bgp_redistribute_table/r1/bgpd.conf new file mode 100644 index 0000000000..c5e0fcd92b --- /dev/null +++ b/tests/topotests/bgp_redistribute_table/r1/bgpd.conf @@ -0,0 +1,8 @@ +router bgp 65500 + bgp router-id 192.0.2.1 + no bgp ebgp-requires-policy + neighbor 192.168.0.2 remote-as 65501 + address-family ipv4 unicast + neighbor 192.168.0.2 activate + exit-address-family +! diff --git a/tests/topotests/bgp_redistribute_table/r1/ipv4_routes_with_all_redistribute.json b/tests/topotests/bgp_redistribute_table/r1/ipv4_routes_with_all_redistribute.json new file mode 100644 index 0000000000..e5a27f32ea --- /dev/null +++ b/tests/topotests/bgp_redistribute_table/r1/ipv4_routes_with_all_redistribute.json @@ -0,0 +1,71 @@ +{ + "172.31.0.2/32": [ + { + "prefix": "172.31.0.2/32", + "protocol": "bgp", + "vrfId": 0, + "vrfName": "default", + "selected": true, + "destSelected": true, + "distance": 20, + "metric": 0, + "installed": true, + "nexthops": [ + { + "fib": true, + "ip": "192.168.0.2", + "afi": "ipv4", + "interfaceName": "r1-eth0", + "active": true, + "weight": 1 + } + ] + } + ], + "172.31.0.10/32": [ + { + "prefix": "172.31.0.10/32", + "protocol": "bgp", + "vrfId": 0, + "vrfName": "default", + "selected": true, + "destSelected": true, + "distance": 20, + "metric": 0, + "installed": true, + "nexthops": [ + { + "fib": true, + "ip": "192.168.0.2", + "afi": "ipv4", + "interfaceName": "r1-eth0", + "active": true, + "weight": 1 + } + ] + } + ], + "172.31.0.15/32": [ + { + "prefix": "172.31.0.15/32", + "protocol": "bgp", + "vrfId": 0, + "vrfName": "default", + "selected": true, + "destSelected": true, + "distance": 20, + "metric": 0, + "installed": true, + "nexthops": [ + { + "fib": true, + "ip": "192.168.0.2", + "afi": "ipv4", + "interfaceName": "r1-eth0", + "active": true, + "weight": 1 + } + ] + } + ] +} diff --git a/tests/topotests/bgp_redistribute_table/r1/ipv4_routes_with_redistribute.json b/tests/topotests/bgp_redistribute_table/r1/ipv4_routes_with_redistribute.json new file mode 100644 index 0000000000..1304edddca --- /dev/null +++ b/tests/topotests/bgp_redistribute_table/r1/ipv4_routes_with_redistribute.json @@ -0,0 +1,48 @@ +{ + "172.31.0.2/32": [ + { + "prefix": "172.31.0.2/32", + "protocol": "bgp", + "vrfId": 0, + "vrfName": "default", + "selected": true, + "destSelected": true, + "distance": 20, + "metric": 0, + "installed": true, + "nexthops": [ + { + "fib": true, + "ip": "192.168.0.2", + "afi": "ipv4", + "interfaceName": "r1-eth0", + "active": true, + "weight": 1 + } + ] + } + ], + "172.31.0.10/32": [ + { + "prefix": "172.31.0.10/32", + "protocol": "bgp", + "vrfId": 0, + "vrfName": "default", + "selected": true, + "destSelected": true, + "distance": 20, + "metric": 0, + "installed": true, + "nexthops": [ + { + "fib": true, + "ip": "192.168.0.2", + "afi": "ipv4", + "interfaceName": "r1-eth0", + "active": true, + "weight": 1 + } + ] + } + ] +} diff --git a/tests/topotests/bgp_redistribute_table/r1/ipv4_routes_without_redistribute.json b/tests/topotests/bgp_redistribute_table/r1/ipv4_routes_without_redistribute.json new file mode 100644 index 0000000000..74f594f9e8 --- /dev/null +++ b/tests/topotests/bgp_redistribute_table/r1/ipv4_routes_without_redistribute.json @@ -0,0 +1,25 @@ +{ + "172.31.0.2/32": [ + { + "prefix": "172.31.0.2/32", + "protocol": "bgp", + "vrfId": 0, + "vrfName": "default", + "selected": true, + "destSelected": true, + "distance": 20, + "metric": 0, + "installed": true, + "nexthops": [ + { + "fib": true, + "ip": "192.168.0.2", + "afi": "ipv4", + "interfaceName": "r1-eth0", + "active": true, + "weight": 1 + } + ] + } + ] +} diff --git a/tests/topotests/bgp_redistribute_table/r1/zebra.conf b/tests/topotests/bgp_redistribute_table/r1/zebra.conf new file mode 100644 index 0000000000..abe6d395a3 --- /dev/null +++ b/tests/topotests/bgp_redistribute_table/r1/zebra.conf @@ -0,0 +1,7 @@ +log stdout +interface r1-eth1 + ip address 172.31.0.1/32 +! +interface r1-eth0 + ip address 192.168.0.1/24 +! diff --git a/tests/topotests/bgp_redistribute_table/r2/bgpd.conf b/tests/topotests/bgp_redistribute_table/r2/bgpd.conf new file mode 100644 index 0000000000..2ce7043097 --- /dev/null +++ b/tests/topotests/bgp_redistribute_table/r2/bgpd.conf @@ -0,0 +1,10 @@ +router bgp 65501 + bgp router-id 192.0.2.2 + no bgp ebgp-requires-policy + neighbor 192.168.0.1 remote-as 65500 + address-family ipv4 unicast + network 172.31.0.2/32 + neighbor 192.168.0.1 activate + redistribute table-direct 2200 + exit-address-family +! diff --git a/tests/topotests/bgp_redistribute_table/r2/zebra.conf b/tests/topotests/bgp_redistribute_table/r2/zebra.conf new file mode 100644 index 0000000000..89ad2ec744 --- /dev/null +++ b/tests/topotests/bgp_redistribute_table/r2/zebra.conf @@ -0,0 +1,8 @@ +log stdout +interface r2-eth0 + ip address 192.168.0.2/24 +! +interface r2-eth1 + ip address 172.31.0.2/32 + ip address 172.31.1.2/24 +! diff --git a/tests/topotests/bgp_redistribute_table/test_bgp_redistribute_table.py b/tests/topotests/bgp_redistribute_table/test_bgp_redistribute_table.py new file mode 100644 index 0000000000..08b70ae0da --- /dev/null +++ b/tests/topotests/bgp_redistribute_table/test_bgp_redistribute_table.py @@ -0,0 +1,306 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# +# test_bgp_redistribute_table.py +# Part of NetDEF Topology Tests +# +# Copyright (c) 2023 by 6WIND +# + +""" + test_bgp_redistribute_table.py: Test the FRR BGP daemon with 'redistribute table-direct' +""" + +import os +import sys +import json +from functools import partial +import pytest + +# Save the Current Working Directory to find configuration files. +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +# Import topogen and topotest helpers +from lib import topotest +from lib.common_config import step +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger + +# Required to instantiate the topology builder class. + + +pytestmark = [pytest.mark.bgpd] + + +def build_topo(tgen): + "Build function" + + # Create 2 routers. + tgen.add_router("r1") + tgen.add_router("r2") + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r1"]) + + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r2"]) + + +def setup_module(mod): + "Sets up the pytest environment" + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for rname, router in router_list.items(): + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) + ) + + # Initialize all routers. + tgen.start_router() + + +def teardown_module(_mod): + "Teardown the pytest environment" + tgen = get_topogen() + + tgen.stop_topology() + + +def _router_json_cmp_exact_filter(router, cmd, expected): + output = router.vtysh_cmd(cmd) + logger.info("{}: {}\n{}".format(router.name, cmd, output)) + + json_output = json.loads(output) + + # filter out tableVersion, version, nhVrfId and vrfId + for route, attrs in json_output.items(): + for attr in attrs: + if "table" in attr: + attr.pop("table") + if "internalStatus" in attr: + attr.pop("internalStatus") + if "internalFlags" in attr: + attr.pop("internalFlags") + if "internalNextHopNum" in attr: + attr.pop("internalNextHopNum") + if "internalNextHopActiveNum" in attr: + attr.pop("internalNextHopActiveNum") + if "nexthopGroupId" in attr: + attr.pop("nexthopGroupId") + if "installedNexthopGroupId" in attr: + attr.pop("installedNexthopGroupId") + if "uptime" in attr: + attr.pop("uptime") + if "prefixLen" in attr: + attr.pop("prefixLen") + if "asPath" in attr: + attr.pop("asPath") + for nexthop in attr.get("nexthops", []): + if "flags" in nexthop: + nexthop.pop("flags") + if "interfaceIndex" in nexthop: + nexthop.pop("interfaceIndex") + + return topotest.json_cmp(json_output, expected, exact=True) + + +def _check_zebra_rib_r1(with_redistributed_route, with_second_route=False): + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + with_str = "" if with_redistributed_route else "out" + + router = tgen.gears["r1"] + if with_redistributed_route: + with_str = "" + if with_second_route: + json_file = "{}/{}/ipv4_routes_with_all_redistribute.json".format( + CWD, router.name + ) + else: + json_file = "{}/{}/ipv4_routes_with_redistribute.json".format( + CWD, router.name + ) + else: + with_str = "out" + json_file = "{}/{}/ipv4_routes_without_redistribute.json".format( + CWD, router.name + ) + + step(f"Checking IPv4 routes for convergence on r1 with{with_str} kernel route") + expected = json.loads(open(json_file).read()) + test_func = partial( + _router_json_cmp_exact_filter, + router, + "show ip route bgp json", + expected, + ) + _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assertmsg = '"{}" JSON output mismatches'.format(router.name) + assert result is None, assertmsg + + +def _test_add_and_check_kernel_route_on_table_2200(): + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router_list = tgen.routers() + + step("r2, adding new kernel route 172.31.0.10/32 on table 2200") + cmd = "ip route add 172.31.0.10/32 via 172.31.1.10 table 2200" + tgen.net["r2"].cmd(cmd) + + _check_zebra_rib_r1(True) + + +def test_step1_protocols_convergence(): + """ + Assert that all protocols have converged + statuses as they depend on it. + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + logger.info("Checking IPv4 routes for convergence on r1") + _check_zebra_rib_r1(False) + + +def test_step2_add_kernel_route_on_table_2200(): + """ + On r2, create a kernel route on table 2200 + * Check that the kernel route is redistributed to r1 + """ + _test_add_and_check_kernel_route_on_table_2200() + + +def test_step3_remove_kernel_route_on_table_2200(): + """ + On r2, remove a kernel route on table 2200 + * Check that the kernel route is no more redistributed to r1 + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router_list = tgen.routers() + + step("r2, remove a kernel route on table 2200") + cmd = "ip route delete 172.31.0.10/32 via 172.31.1.10 table 2200" + tgen.net["r2"].cmd(cmd) + + _check_zebra_rib_r1(False) + + +def test_step4_add_kernel_route_on_table_2200(): + """ + On r2, add a kernel route on table 2200 + * Check that the kernel route is redistributed to r1 + """ + _test_add_and_check_kernel_route_on_table_2200() + + +def test_step5_no_redistribute_table_2200(): + """ + On r2, unconfigure the 'no redistribute' service + * Check that the 'redistribute' command is not configured + * Check that the kernel route is not redistributed to r1 + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + tgen.gears["r2"].vtysh_cmd( + "configure terminal\nrouter bgp 65501\naddress-family ipv4 unicast\nno redistribute table-direct\n" + ) + + step("r2, check that the 'redistribute' command is not configured") + out = tgen.net["r2"].cmd( + "vtysh -c 'show running-config' | grep 'redistribute table-direct'" + ) + + if "redistribute" in out: + assert True, "r2, redistribute command still present" + + _check_zebra_rib_r1(False) + + +def test_step6_redistribute_table_2200(): + """ + On r2, configure the 'redistribute' service + * Check that the 'redistribute' command is configured + * Check that the kernel route is redistributed to r1 + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + tgen.gears["r2"].vtysh_cmd( + "configure terminal\nrouter bgp 65501\naddress-family ipv4 unicast\nredistribute table-direct 2200\n" + ) + + step("r2, check that the 'redistribute' command is configured") + out = tgen.net["r2"].cmd( + "vtysh -c 'show running-config' | grep 'redistribute table-direct'" + ) + if "redistribute" not in out: + assert True, "r2, redistribute command still present" + + _check_zebra_rib_r1(True) + + +def test_step7_reset_bgp_instance_add_kernel_route_and_add_bgp(): + """ + On r2, remove BGP configuration, create a kernel route on table 2200, + then restore BGP configuration + * Check that the kernel route is redistributed to r1 + """ + + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router_list = tgen.routers() + + router = tgen.gears["r2"] + step("r2, removing r2 BGP configuration") + router.vtysh_cmd("configure terminal\nno router bgp 65501\n") + + step("r2, adding new kernel route 172.31.0.15/32 on table 2200") + cmd = "ip route add 172.31.0.15/32 via 172.31.1.100 table 2200" + tgen.net["r2"].cmd(cmd) + + router = tgen.gears["r2"] + step("r2, restoring r2 BGP configuration") + tgen.net["r2"].cmd("vtysh -f {}".format(os.path.join(CWD, "r2/bgpd.conf"))) + + _check_zebra_rib_r1(True, with_second_route=True) + + +def test_memory_leak(): + "Run the memory leak test and report results." + tgen = get_topogen() + if not tgen.is_memleak_enabled(): + pytest.skip("Memory leak test/report is disabled") + + tgen.report_memory_leaks() + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_remove_private_as_route_map/__init__.py b/tests/topotests/bgp_remove_private_as_route_map/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/bgp_remove_private_as_route_map/r1/frr.conf b/tests/topotests/bgp_remove_private_as_route_map/r1/frr.conf new file mode 100644 index 0000000000..b2dba7d3fe --- /dev/null +++ b/tests/topotests/bgp_remove_private_as_route_map/r1/frr.conf @@ -0,0 +1,10 @@ +! +int r1-eth0 + ip address 192.168.1.1/24 +! +router bgp 65001 + no bgp ebgp-requires-policy + neighbor 192.168.1.2 remote-as external + neighbor 192.168.1.2 timers 1 3 + neighbor 192.168.1.2 timers connect 1 +! diff --git a/tests/topotests/bgp_remove_private_as_route_map/r2/frr.conf b/tests/topotests/bgp_remove_private_as_route_map/r2/frr.conf new file mode 100644 index 0000000000..9c423cea8c --- /dev/null +++ b/tests/topotests/bgp_remove_private_as_route_map/r2/frr.conf @@ -0,0 +1,19 @@ +! +int r2-eth0 + ip address 192.168.1.2/24 + ip address 192.168.2.1/32 +! +router bgp 65002 + no bgp ebgp-requires-policy + neighbor 192.168.1.1 remote-as external + neighbor 192.168.1.1 timers 1 3 + neighbor 192.168.1.1 timers connect 1 + address-family ipv4 unicast + redistribute connected + neighbor 192.168.1.1 route-map r1 out + neighbor 192.168.1.1 remove-private-AS all + exit-address-family +! +route-map r1 permit 10 + set as-path prepend 65123 4200000001 +! diff --git a/tests/topotests/bgp_remove_private_as_route_map/test_bgp_remove_private_as_route_map.py b/tests/topotests/bgp_remove_private_as_route_map/test_bgp_remove_private_as_route_map.py new file mode 100644 index 0000000000..2ae6f7fc9e --- /dev/null +++ b/tests/topotests/bgp_remove_private_as_route_map/test_bgp_remove_private_as_route_map.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# Copyright (c) 2023 by +# Donatas Abraitis <donatas@opensourcerouting.org> +# + +""" +Test if private AS is removed from AS_PATH attribute when route-map is used (prepend). +""" + +import os +import re +import sys +import json +import pytest +import functools + +pytestmark = pytest.mark.bgpd + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen + +pytestmark = [pytest.mark.bgpd] + + +def build_topo(tgen): + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + +def setup_module(mod): + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for i, (rname, router) in enumerate(router_list.items(), 1): + router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname))) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_remove_private_as_route_map(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + + def _check_routes(): + output = json.loads(r1.vtysh_cmd("show bgp ipv4 unicast json")) + expected = { + "routes": { + "192.168.2.1/32": [ + { + "valid": True, + "path": "65002", + } + ] + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _check_routes, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert ( + result is None + ), "65123 4200000001 ASNs should be removed from AS_PATH attribute" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_route_map_on_match_next/__init__.py b/tests/topotests/bgp_route_map_on_match_next/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/bgp_route_map_on_match_next/r1/bgpd.conf b/tests/topotests/bgp_route_map_on_match_next/r1/bgpd.conf new file mode 100644 index 0000000000..b858fffd81 --- /dev/null +++ b/tests/topotests/bgp_route_map_on_match_next/r1/bgpd.conf @@ -0,0 +1,10 @@ +! +router bgp 65001 + no bgp network import-check + neighbor 192.168.255.2 remote-as 65001 + neighbor 192.168.255.2 timers 3 10 + address-family ipv4 unicast + network 10.100.100.1/32 + exit-address-family + ! +! diff --git a/tests/topotests/bgp_route_map_on_match_next/r1/zebra.conf b/tests/topotests/bgp_route_map_on_match_next/r1/zebra.conf new file mode 100644 index 0000000000..581e2e634f --- /dev/null +++ b/tests/topotests/bgp_route_map_on_match_next/r1/zebra.conf @@ -0,0 +1,6 @@ +! +interface r1-eth0 + ip address 192.168.255.1/30 +! +ip forwarding +! diff --git a/tests/topotests/bgp_route_map_on_match_next/r2/bgpd.conf b/tests/topotests/bgp_route_map_on_match_next/r2/bgpd.conf new file mode 100644 index 0000000000..518d63d692 --- /dev/null +++ b/tests/topotests/bgp_route_map_on_match_next/r2/bgpd.conf @@ -0,0 +1,17 @@ +! +router bgp 65001 + neighbor 192.168.255.1 remote-as 65001 + neighbor 192.168.255.1 timers 3 10 + address-family ipv4 unicast + neighbor 192.168.255.1 route-map RM in + exit-address-family + ! +! +route-map RM permit 10 + set weight 100 +exit +! +route-map RM permit 20 + set metric 20 +exit +! diff --git a/tests/topotests/bgp_route_map_on_match_next/r2/zebra.conf b/tests/topotests/bgp_route_map_on_match_next/r2/zebra.conf new file mode 100644 index 0000000000..fd45c48d6d --- /dev/null +++ b/tests/topotests/bgp_route_map_on_match_next/r2/zebra.conf @@ -0,0 +1,6 @@ +! +interface r2-eth0 + ip address 192.168.255.2/30 +! +ip forwarding +! diff --git a/tests/topotests/bgp_route_map_on_match_next/test_bgp_route_map_on_match_next.py b/tests/topotests/bgp_route_map_on_match_next/test_bgp_route_map_on_match_next.py new file mode 100644 index 0000000000..8fe45a3498 --- /dev/null +++ b/tests/topotests/bgp_route_map_on_match_next/test_bgp_route_map_on_match_next.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# +# test_bgp_route_map_on_match_next.py +# +# Copyright (c) 2023 Rubicon Communications, LLC. +# + +""" +Test whether `on-match next` added to an existing route-map entry takes effect. +""" + +import os +import sys +import json +import pytest +import functools + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen + +pytestmark = [pytest.mark.bgpd] + + +def build_topo(tgen): + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + +def setup_module(mod): + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for i, (rname, router) in enumerate(router_list.items(), 1): + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) + ) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_route_map_on_match_next(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router1 = tgen.gears["r1"] + router2 = tgen.gears["r2"] + + def _bgp_converge(router): + output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) + expected = {"192.168.255.1": {"bgpState": "Established"}} + return topotest.json_cmp(output, expected) + + def _bgp_has_routes(router, metric, weight): + output = json.loads( + router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 routes json") + ) + expected = { + "routes": {"10.100.100.1/32": [{"metric": metric, "weight": weight}]} + } + return topotest.json_cmp(output, expected) + + # Check thst session is established + test_func = functools.partial(_bgp_converge, router2) + success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + assert result is None, "Failed bgp convergence on r2" + + # Check that metric is 0 and weight is 100 for the received prefix + test_func = functools.partial(_bgp_has_routes, router2, 0, 100) + success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + assert result is None, "r2 does not receive routes with metric 0 and weight 100" + + # Update the route-map and add "on-match next" to entry 10 + cmd = """ + configure terminal + route-map RM permit 10 + on-match next + exit + """ + router2.vtysh_cmd(cmd) + + # Check that metric is 20 and weight is 100 for the received prefix + test_func = functools.partial(_bgp_has_routes, router2, 20, 100) + success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + assert result is None, "r2 does not receive routes with metric 20 and weight 100" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_route_server_client/r1/bgpd.conf b/tests/topotests/bgp_route_server_client/r1/bgpd.conf index 9826b671f9..e464e6c50b 100644 --- a/tests/topotests/bgp_route_server_client/r1/bgpd.conf +++ b/tests/topotests/bgp_route_server_client/r1/bgpd.conf @@ -2,6 +2,7 @@ router bgp 65001 bgp router-id 10.10.10.1 no bgp ebgp-requires-policy + no bgp enforce-first-as neighbor 2001:db8:1::1 remote-as external neighbor 2001:db8:1::1 timers 3 10 neighbor 2001:db8:1::1 timers connect 5 diff --git a/tests/topotests/bgp_set_aspath_exclude/__init__.py b/tests/topotests/bgp_set_aspath_exclude/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/bgp_set_aspath_exclude/r1/bgpd.conf b/tests/topotests/bgp_set_aspath_exclude/r1/bgpd.conf new file mode 100644 index 0000000000..9bef24f931 --- /dev/null +++ b/tests/topotests/bgp_set_aspath_exclude/r1/bgpd.conf @@ -0,0 +1,17 @@ +! +router bgp 65001 + no bgp ebgp-requires-policy + neighbor 192.168.1.2 remote-as external + neighbor 192.168.1.2 timers 3 10 + address-family ipv4 unicast + neighbor 192.168.1.2 route-map r2 in + exit-address-family +! +ip prefix-list p1 seq 5 permit 172.16.255.31/32 +! +route-map r2 permit 10 + match ip address prefix-list p1 + set as-path exclude 65003 +route-map r2 permit 20 + set as-path exclude all +! diff --git a/tests/topotests/bgp_set_aspath_exclude/r1/zebra.conf b/tests/topotests/bgp_set_aspath_exclude/r1/zebra.conf new file mode 100644 index 0000000000..acf120b200 --- /dev/null +++ b/tests/topotests/bgp_set_aspath_exclude/r1/zebra.conf @@ -0,0 +1,6 @@ +! +interface r1-eth0 + ip address 192.168.1.1/24 +! +ip forwarding +! diff --git a/tests/topotests/bgp_set_aspath_exclude/r2/bgpd.conf b/tests/topotests/bgp_set_aspath_exclude/r2/bgpd.conf new file mode 100644 index 0000000000..23367f94ff --- /dev/null +++ b/tests/topotests/bgp_set_aspath_exclude/r2/bgpd.conf @@ -0,0 +1,8 @@ +! +router bgp 65002 + no bgp ebgp-requires-policy + neighbor 192.168.1.1 remote-as external + neighbor 192.168.1.1 timers 3 10 + neighbor 192.168.2.1 remote-as external + neighbor 192.168.2.1 timers 3 10 +! diff --git a/tests/topotests/bgp_set_aspath_exclude/r2/zebra.conf b/tests/topotests/bgp_set_aspath_exclude/r2/zebra.conf new file mode 100644 index 0000000000..f229954341 --- /dev/null +++ b/tests/topotests/bgp_set_aspath_exclude/r2/zebra.conf @@ -0,0 +1,9 @@ +! +interface r2-eth0 + ip address 192.168.1.2/24 +! +interface r2-eth1 + ip address 192.168.2.2/24 +! +ip forwarding +! diff --git a/tests/topotests/bgp_set_aspath_exclude/r3/bgpd.conf b/tests/topotests/bgp_set_aspath_exclude/r3/bgpd.conf new file mode 100644 index 0000000000..b7a7ceda13 --- /dev/null +++ b/tests/topotests/bgp_set_aspath_exclude/r3/bgpd.conf @@ -0,0 +1,9 @@ +! +router bgp 65003 + no bgp ebgp-requires-policy + neighbor 192.168.2.2 remote-as external + neighbor 192.168.2.2 timers 3 10 + address-family ipv4 unicast + redistribute connected + exit-address-family +! diff --git a/tests/topotests/bgp_set_aspath_exclude/r3/zebra.conf b/tests/topotests/bgp_set_aspath_exclude/r3/zebra.conf new file mode 100644 index 0000000000..3fa6c64484 --- /dev/null +++ b/tests/topotests/bgp_set_aspath_exclude/r3/zebra.conf @@ -0,0 +1,10 @@ +! +int lo + ip address 172.16.255.31/32 + ip address 172.16.255.32/32 +! +interface r3-eth0 + ip address 192.168.2.1/24 +! +ip forwarding +! diff --git a/tests/topotests/bgp_set_aspath_exclude/test_bgp_set_aspath_exclude.py b/tests/topotests/bgp_set_aspath_exclude/test_bgp_set_aspath_exclude.py new file mode 100644 index 0000000000..a0cd89f064 --- /dev/null +++ b/tests/topotests/bgp_set_aspath_exclude/test_bgp_set_aspath_exclude.py @@ -0,0 +1,145 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC +# +# test_bgp_set_aspath_exclude.py +# +# Copyright 2023 by 6WIND S.A. +# + +""" +Test if `set as-path exclude` is working correctly for route-maps. +""" + +import os +import sys +import json +import pytest +import functools + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen + + +pytestmark = [pytest.mark.bgpd] + + +def build_topo(tgen): + for routern in range(1, 5): + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) + + +def setup_module(mod): + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for i, (rname, router) in enumerate(router_list.items(), 1): + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) + ) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_set_aspath_exclude(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + def _bgp_converge(router): + output = json.loads(router.vtysh_cmd("show bgp ipv4 unicast json")) + expected = { + "routes": { + "172.16.255.31/32": [{"path": "65002"}], + "172.16.255.32/32": [{"path": ""}], + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_converge, tgen.gears["r1"]) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + + assert result is None, "Failed overriding incoming AS-PATH with route-map" + + +def test_bgp_set_aspath_exclude_access_list(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + rname = "r1" + r1 = tgen.gears[rname] + + r1.vtysh_cmd( + """ +conf + bgp as-path access-list FIRST permit ^65 + route-map r2 permit 6 + set as-path exclude as-path-access-list FIRST + """ + ) + + expected = { + "routes": { + "172.16.255.31/32": [{"path": ""}], + "172.16.255.32/32": [{"path": ""}], + } + } + + def _bgp_regexp_1(router): + output = json.loads(router.vtysh_cmd("show bgp ipv4 unicast json")) + + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_regexp_1, tgen.gears["r1"]) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + + assert result is None, "Failed overriding incoming AS-PATH with regex 1 route-map" + r1.vtysh_cmd( + """ +conf + bgp as-path access-list SECOND permit 2 + route-map r2 permit 6 + set as-path exclude as-path-access-list SECOND + """ + ) + + expected = { + "routes": { + "172.16.255.31/32": [{"path": "65003"}], + "172.16.255.32/32": [{"path": "65003"}], + } + } + + test_func = functools.partial(_bgp_regexp_1, tgen.gears["r1"]) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + + assert result is None, "Failed overriding incoming AS-PATH with regex 2 route-map" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_set_aspath_replace/r1/bgpd.conf b/tests/topotests/bgp_set_aspath_replace/r1/bgpd.conf index 1e98f4e491..f586c1f99c 100644 --- a/tests/topotests/bgp_set_aspath_replace/r1/bgpd.conf +++ b/tests/topotests/bgp_set_aspath_replace/r1/bgpd.conf @@ -9,6 +9,7 @@ router bgp 65001 ! ip prefix-list p1 seq 5 permit 172.16.255.31/32 ! +bgp route-map delay-timer 1 route-map r2 permit 10 match ip address prefix-list p1 set as-path replace 65003 diff --git a/tests/topotests/bgp_set_aspath_replace/test_bgp_set_aspath_replace.py b/tests/topotests/bgp_set_aspath_replace/test_bgp_set_aspath_replace.py index 463df2f2a6..c0e19fa356 100644 --- a/tests/topotests/bgp_set_aspath_replace/test_bgp_set_aspath_replace.py +++ b/tests/topotests/bgp_set_aspath_replace/test_bgp_set_aspath_replace.py @@ -24,6 +24,7 @@ # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger pytestmark = [pytest.mark.bgpd] @@ -63,7 +64,7 @@ def teardown_module(mod): tgen.stop_topology() -def test_bgp_maximum_prefix_out(): +def test_bgp_set_aspath_replace_test1(): tgen = get_topogen() if tgen.routers_have_failure(): @@ -85,6 +86,116 @@ def _bgp_converge(router): assert result is None, "Failed overriding incoming AS-PATH with route-map" +def test_bgp_set_aspath_replace_test2(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + logger.info("Configuring r1 to replace the matching AS with a configured ASN") + router = tgen.gears["r1"] + router.vtysh_cmd( + "configure terminal\nroute-map r2 permit 10\nset as-path replace 65003 65500\n", + isjson=False, + ) + router.vtysh_cmd( + "configure terminal\nroute-map r2 permit 20\nset as-path replace any 65501\n", + isjson=False, + ) + + def _bgp_converge(router): + output = json.loads(router.vtysh_cmd("show bgp ipv4 unicast json")) + expected = { + "routes": { + "172.16.255.31/32": [{"path": "65002 65500"}], + "172.16.255.32/32": [{"path": "65501 65501"}], + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_converge, router) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + + assert ( + result is None + ), "Failed overriding incoming AS-PATH with route-map replace with configured ASN" + + +def test_bgp_set_aspath_replace_access_list(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + rname = "r1" + r1 = tgen.gears[rname] + + r1.vtysh_cmd( + """ +conf + bgp as-path access-list FIRST permit ^65 + route-map r2 permit 20 + set as-path replace as-path-access-list FIRST 65002 + """ + ) + + expected = { + "routes": { + "172.16.255.31/32": [{"path": "65002 65500"}], + "172.16.255.32/32": [{"path": "65002 65002"}], + } + } + + def _bgp_regexp_1(router): + output = json.loads(router.vtysh_cmd("show bgp ipv4 unicast json")) + + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_regexp_1, tgen.gears["r1"]) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + + assert result is None, "Failed overriding incoming AS-PATH with regex 1 route-map" + r1.vtysh_cmd( + """ +conf + bgp as-path access-list SECOND permit 2 + route-map r2 permit 10 + set as-path replace as-path-access-list SECOND 65001 + """ + ) + + expected = { + "routes": { + "172.16.255.31/32": [{"path": "65001 65003"}], + "172.16.255.32/32": [{"path": "65002 65002"}], + } + } + + test_func = functools.partial(_bgp_regexp_1, tgen.gears["r1"]) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + + assert result is None, "Failed overriding incoming AS-PATH with regex 2 route-map" + + r1.vtysh_cmd( + """ +conf + bgp as-path access-list TER permit 3 + route-map r2 permit 10 + set as-path replace as-path-access-list TER + """ + ) + expected = { + "routes": { + "172.16.255.31/32": [{"path": "65002 65001"}], + "172.16.255.32/32": [{"path": "65002 65002"}], + } + } + + test_func = functools.partial(_bgp_regexp_1, tgen.gears["r1"]) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5) + + assert result is None, "Failed overriding incoming AS-PATH with regex 3 route-map" + + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_snmp_bgp4v2mib/r1/bgpd.conf b/tests/topotests/bgp_snmp_bgp4v2mib/r1/bgpd.conf index d82a21e1f9..144466e418 100644 --- a/tests/topotests/bgp_snmp_bgp4v2mib/r1/bgpd.conf +++ b/tests/topotests/bgp_snmp_bgp4v2mib/r1/bgpd.conf @@ -1,24 +1,28 @@ ! +!debug bgp updates +! router bgp 65001 no bgp ebgp-requires-policy no bgp network import-check no bgp default ipv4-unicast - neighbor 192.168.12.2 remote-as external - neighbor 192.168.12.2 timers 1 3 - neighbor 192.168.12.2 timers connect 1 - neighbor 2001:db8::12:2 remote-as external - neighbor 2001:db8::12:2 timers 1 3 - neighbor 2001:db8::12:2 timers connect 1 + neighbor 192.168.12.4 remote-as external + neighbor 192.168.12.4 timers 1 3 + neighbor 192.168.12.4 timers connect 1 + neighbor 2001:db8::12:4 remote-as external + neighbor 2001:db8::12:4 timers 1 3 + neighbor 2001:db8::12:4 timers connect 1 ! address-family ipv4 unicast network 10.0.0.0/31 route-map p1 network 10.0.0.2/32 route-map p2 - neighbor 192.168.12.2 activate + neighbor 192.168.12.4 activate + neighbor 192.168.12.4 addpath-tx-all-paths + network 10.10.10.10/32 exit-address-family address-family ipv6 unicast network 2001:db8::1/128 route-map p1 network 2001:db8:1::/56 route-map p2 - neighbor 2001:db8::12:2 activate + neighbor 2001:db8::12:4 activate exit-address-family ! route-map p1 permit 10 @@ -28,4 +32,3 @@ route-map p2 permit 10 set metric 2 set origin incomplete exit -! diff --git a/tests/topotests/bgp_snmp_bgp4v2mib/r2/bgpd.conf b/tests/topotests/bgp_snmp_bgp4v2mib/r2/bgpd.conf index cf0013e1b7..55686f407a 100644 --- a/tests/topotests/bgp_snmp_bgp4v2mib/r2/bgpd.conf +++ b/tests/topotests/bgp_snmp_bgp4v2mib/r2/bgpd.conf @@ -5,18 +5,20 @@ router bgp 65002 no bgp ebgp-requires-policy no bgp network import-check no bgp default ipv4-unicast - neighbor 192.168.12.1 remote-as external - neighbor 192.168.12.1 timers 1 3 - neighbor 192.168.12.1 timers connect 1 - neighbor 2001:db8::12:1 remote-as external - neighbor 2001:db8::12:1 timers 1 3 - neighbor 2001:db8::12:1 timers connect 1 + neighbor 192.168.12.4 remote-as external + neighbor 192.168.12.4 timers 1 3 + neighbor 192.168.12.4 timers connect 1 + neighbor 2001:db8::12:4 remote-as external + neighbor 2001:db8::12:4 timers 1 3 + neighbor 2001:db8::12:4 timers connect 1 ! address-family ipv4 unicast - neighbor 192.168.12.1 activate + neighbor 192.168.12.4 activate + neighbor 192.168.12.4 addpath-tx-all-paths + exit-address-family address-family ipv6 unicast - neighbor 2001:db8::12:1 activate + neighbor 2001:db8::12:4 activate exit-address-family ! agentx diff --git a/tests/topotests/bgp_snmp_bgp4v2mib/r2/snmpd.conf b/tests/topotests/bgp_snmp_bgp4v2mib/r2/snmpd.conf index 032b93b676..f0957cca7a 100644 --- a/tests/topotests/bgp_snmp_bgp4v2mib/r2/snmpd.conf +++ b/tests/topotests/bgp_snmp_bgp4v2mib/r2/snmpd.conf @@ -6,6 +6,15 @@ access public_group "" any noauth prefix all all none rocommunity public default +trapsess -v2c -c public 127.0.0.1 + +notificationEvent linkUpTrap linkUp ifIndex ifAdminStatus ifOperStatus +notificationEvent linkDownTrap linkDown ifIndex ifAdminStatus ifOperStatus + +monitor -r 2 -e linkUpTrap "Generate linkUp" ifOperStatus != 2 +monitor -r 2 -e linkDownTrap "Generate linkDown" ifOperStatus == 2 + + view all included .1 iquerySecName frr diff --git a/tests/topotests/bgp_snmp_bgp4v2mib/r2/snmptrapd.conf b/tests/topotests/bgp_snmp_bgp4v2mib/r2/snmptrapd.conf new file mode 100644 index 0000000000..f6e4abfef7 --- /dev/null +++ b/tests/topotests/bgp_snmp_bgp4v2mib/r2/snmptrapd.conf @@ -0,0 +1,2 @@ +authCommunity net,log public +disableAuthorization yes diff --git a/tests/topotests/bgp_snmp_bgp4v2mib/r3/bgpd.conf b/tests/topotests/bgp_snmp_bgp4v2mib/r3/bgpd.conf new file mode 100644 index 0000000000..71dbda0bc1 --- /dev/null +++ b/tests/topotests/bgp_snmp_bgp4v2mib/r3/bgpd.conf @@ -0,0 +1,25 @@ +! +!debug bgp updates +! +router bgp 65003 + no bgp ebgp-requires-policy + no bgp network import-check + no bgp default ipv4-unicast + neighbor 192.168.12.4 remote-as external + neighbor 192.168.12.4 timers 1 3 + neighbor 192.168.12.4 timers connect 1 + neighbor 2001:db8::12:4 remote-as external + neighbor 2001:db8::12:4 timers 1 3 + neighbor 2001:db8::12:4 timers connect 1 + ! + address-family ipv4 unicast + neighbor 192.168.12.4 activate + neighbor 192.168.12.4 addpath-tx-all-paths + network 10.10.10.10/32 + exit-address-family + address-family ipv6 unicast + neighbor 2001:db8::12:4 activate + exit-address-family +! +agentx +! diff --git a/tests/topotests/bgp_snmp_bgp4v2mib/r3/zebra.conf b/tests/topotests/bgp_snmp_bgp4v2mib/r3/zebra.conf new file mode 100644 index 0000000000..398af65ffe --- /dev/null +++ b/tests/topotests/bgp_snmp_bgp4v2mib/r3/zebra.conf @@ -0,0 +1,5 @@ +! +interface r3-eth0 + ip address 192.168.12.3/24 + ipv6 address 2001:db8::12:3/64 +! diff --git a/tests/topotests/bgp_snmp_bgp4v2mib/rr/bgpd.conf b/tests/topotests/bgp_snmp_bgp4v2mib/rr/bgpd.conf new file mode 100644 index 0000000000..5ebbde6703 --- /dev/null +++ b/tests/topotests/bgp_snmp_bgp4v2mib/rr/bgpd.conf @@ -0,0 +1,67 @@ +! +! debug bgp updates +! +router bgp 65004 + no bgp ebgp-requires-policy + no bgp network import-check + no bgp default ipv4-unicast + neighbor 192.168.12.1 remote-as external + neighbor 192.168.12.1 timers 1 3 + neighbor 192.168.12.1 timers connect 1 + neighbor 192.168.12.2 remote-as external + neighbor 192.168.12.2 timers 1 3 + neighbor 192.168.12.2 timers connect 1 + neighbor 192.168.12.3 remote-as external + neighbor 192.168.12.3 timers 1 3 + neighbor 192.168.12.3 timers connect 1 + neighbor 2001:db8::12:1 remote-as external + neighbor 2001:db8::12:1 timers 1 3 + neighbor 2001:db8::12:1 timers connect 1 + neighbor 2001:db8::12:2 remote-as external + neighbor 2001:db8::12:2 timers 1 3 + neighbor 2001:db8::12:2 timers connect 1 + neighbor 2001:db8::12:3 remote-as external + neighbor 2001:db8::12:3 timers 1 3 + neighbor 2001:db8::12:3 timers connect 1 + ! + address-family ipv4 unicast + network 10.0.0.0/31 route-map p1 + network 10.0.0.2/32 route-map p2 + neighbor 192.168.12.1 activate + neighbor 192.168.12.2 activate + neighbor 192.168.12.2 addpath-tx-all-paths + neighbor 192.168.12.2 route-map r2-import in + neighbor 192.168.12.2 route-map r2-export out +! neighbor 192.168.12.2 soft-reconfiguration inbound + neighbor 192.168.12.3 activate + exit-address-family + address-family ipv6 unicast + network 2001:db8::1/128 route-map p1 + network 2001:db8:1::/56 route-map p2 + neighbor 2001:db8::12:1 activate + neighbor 2001:db8::12:2 activate + neighbor 2001:db8::12:2 addpath-tx-all-paths + neighbor 2001:db8::12:3 activate + exit-address-family + + +ip prefix-list r2-toto permit any + +route-map r2-import permit 10 + match ip address prefix-list r2-toto + +route-map r2-export permit 10 + match ip address prefix-list r2-toto +! +route-map p1 permit 10 + set metric 1 +exit +route-map p2 permit 10 + set metric 2 + set origin incomplete +exit + + + +agentx +! diff --git a/tests/topotests/bgp_snmp_bgp4v2mib/rr/zebra.conf b/tests/topotests/bgp_snmp_bgp4v2mib/rr/zebra.conf new file mode 100644 index 0000000000..092673b8a9 --- /dev/null +++ b/tests/topotests/bgp_snmp_bgp4v2mib/rr/zebra.conf @@ -0,0 +1,5 @@ +! +interface rr-eth0 + ip address 192.168.12.4/24 + ipv6 address 2001:db8::12:4/64 +! diff --git a/tests/topotests/bgp_snmp_bgp4v2mib/test_bgp_snmp_bgp4v2mib.py b/tests/topotests/bgp_snmp_bgp4v2mib/test_bgp_snmp_bgp4v2mib.py index 583d89d40f..8cd49e3548 100755 --- a/tests/topotests/bgp_snmp_bgp4v2mib/test_bgp_snmp_bgp4v2mib.py +++ b/tests/topotests/bgp_snmp_bgp4v2mib/test_bgp_snmp_bgp4v2mib.py @@ -24,6 +24,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.snmptest import SnmpTester from lib import topotest +from lib.topolog import logger pytestmark = [pytest.mark.bgpd, pytest.mark.snmp] @@ -31,10 +32,14 @@ def build_topo(tgen): tgen.add_router("r1") tgen.add_router("r2") + tgen.add_router("r3") + tgen.add_router("rr") switch = tgen.add_switch("s1") switch.add_link(tgen.gears["r1"]) switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["rr"]) def setup_module(mod): @@ -55,11 +60,18 @@ def setup_module(mod): os.path.join(CWD, "{}/bgpd.conf".format(rname)), "-M snmp", ) - router.load_config( - TopoRouter.RD_SNMP, - os.path.join(CWD, "{}/snmpd.conf".format(rname)), - "-Le -Ivacm_conf,usmConf,iquery -V -DAgentX", - ) + + r2 = tgen.gears["r2"] + r2.load_config( + TopoRouter.RD_SNMP, + os.path.join(CWD, "{}/snmpd.conf".format(r2.name)), + "-Le -Ivacm_conf,usmConf,iquery -V -DAgentX", + ) + r2.load_config( + TopoRouter.RD_TRAP, + os.path.join(CWD, "{}/snmptrapd.conf".format(r2.name)), + " -On -OQ ", + ) tgen.start_router() @@ -72,28 +84,31 @@ def teardown_module(mod): def test_bgp_snmp_bgp4v2(): tgen = get_topogen() + r1 = tgen.gears["r1"] r2 = tgen.gears["r2"] + rr = tgen.gears["rr"] def _bgp_converge_summary(): output = json.loads(r2.vtysh_cmd("show bgp summary json")) expected = { "ipv4Unicast": { "peers": { - "192.168.12.1": { + "192.168.12.4": { "state": "Established", - "pfxRcd": 2, + "pfxRcd": 6, } } }, "ipv6Unicast": { "peers": { - "2001:db8::12:1": { + "2001:db8::12:4": { "state": "Established", - "pfxRcd": 2, + "pfxRcd": 4, } } }, } + # tgen.mininet_cli() return topotest.json_cmp(output, expected) test_func = functools.partial(_bgp_converge_summary) @@ -136,6 +151,7 @@ def _bgp_converge_prefixes(): } }, } + # tgen.mininet_cli() return topotest.json_cmp(output, expected) test_func = functools.partial(_bgp_converge_prefixes) @@ -146,11 +162,12 @@ def _bgp_converge_prefixes(): def _snmpwalk_remote_addr(): expected = { - "1.3.6.1.3.5.1.1.2.1.5.1.4.192.168.12.1": "C0 A8 0C 01", - "1.3.6.1.3.5.1.1.2.1.5.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1": "20 01 0D B8 00 00 00 00 00 00 00 00 00 12 00 01", + "1.3.6.1.3.5.1.1.2.1.5.1.1.192.168.12.4": "C0 A8 0C 04", + "1.3.6.1.3.5.1.1.2.1.5.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.4": "20 01 0D B8 00 00 00 00 00 00 00 00 00 12 00 04", } # bgp4V2PeerRemoteAddr + # tgen.mininet_cli() output, _ = snmp.walk(".1.3.6.1.3.5.1.1.2.1.5") return output == expected @@ -160,8 +177,8 @@ def _snmpwalk_remote_addr(): def _snmpwalk_peer_state(): expected = { - "1.3.6.1.3.5.1.1.2.1.13.1.4.192.168.12.1": "6", - "1.3.6.1.3.5.1.1.2.1.13.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1": "6", + "1.3.6.1.3.5.1.1.2.1.13.1.1.192.168.12.4": "6", + "1.3.6.1.3.5.1.1.2.1.13.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.4": "6", } # bgp4V2PeerState @@ -174,8 +191,8 @@ def _snmpwalk_peer_state(): def _snmpwalk_peer_last_error_code_received(): expected = { - "1.3.6.1.3.5.1.1.3.1.1.1.4.192.168.12.1": "0", - "1.3.6.1.3.5.1.1.3.1.1.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1": "0", + "1.3.6.1.3.5.1.1.3.1.1.1.1.192.168.12.4": "0", + "1.3.6.1.3.5.1.1.3.1.1.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.4": "0", } # bgp4V2PeerLastErrorCodeReceived @@ -190,10 +207,16 @@ def _snmpwalk_peer_last_error_code_received(): def _snmpwalk_origin(): expected = { - "1.3.6.1.3.5.1.1.9.1.9.1.4.10.0.0.0.31.192.168.12.1": "1", - "1.3.6.1.3.5.1.1.9.1.9.1.4.10.0.0.2.32.192.168.12.1": "3", - "1.3.6.1.3.5.1.1.9.1.9.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1": "1", - "1.3.6.1.3.5.1.1.9.1.9.2.16.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1": "3", + "1.3.6.1.3.5.1.1.9.1.9.1.1.1.1.10.10.10.10.32.1.192.168.12.4.1": "1", + "1.3.6.1.3.5.1.1.9.1.9.1.1.1.1.10.10.10.10.32.1.192.168.12.4.2": "1", + "1.3.6.1.3.5.1.1.9.1.9.1.1.1.1.10.0.0.0.31.1.192.168.12.4.1": "1", + "1.3.6.1.3.5.1.1.9.1.9.1.1.1.1.10.0.0.0.31.1.192.168.12.4.2": "1", + "1.3.6.1.3.5.1.1.9.1.9.1.1.1.1.10.0.0.2.32.1.192.168.12.4.1": "3", + "1.3.6.1.3.5.1.1.9.1.9.1.1.1.1.10.0.0.2.32.1.192.168.12.4.2": "3", + "1.3.6.1.3.5.1.1.9.1.9.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.4.1": "1", + "1.3.6.1.3.5.1.1.9.1.9.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.4.2": "1", + "1.3.6.1.3.5.1.1.9.1.9.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.4.1": "3", + "1.3.6.1.3.5.1.1.9.1.9.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.4.2": "3", } # bgp4V2NlriOrigin @@ -206,20 +229,90 @@ def _snmpwalk_origin(): def _snmpwalk_med(): expected = { - "1.3.6.1.3.5.1.1.9.1.17.1.4.10.0.0.0.31.192.168.12.1": "1", - "1.3.6.1.3.5.1.1.9.1.17.1.4.10.0.0.2.32.192.168.12.1": "2", - "1.3.6.1.3.5.1.1.9.1.17.2.16.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1": "1", - "1.3.6.1.3.5.1.1.9.1.17.2.16.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.1": "2", + "1.3.6.1.3.5.1.1.9.1.17.1.1.1.1.10.10.10.10.32.1.192.168.12.4.1": "0", + "1.3.6.1.3.5.1.1.9.1.17.1.1.1.1.10.10.10.10.32.1.192.168.12.4.2": "0", + "1.3.6.1.3.5.1.1.9.1.17.1.1.1.1.10.0.0.0.31.1.192.168.12.4.1": "1", + "1.3.6.1.3.5.1.1.9.1.17.1.1.1.1.10.0.0.0.31.1.192.168.12.4.2": "0", + "1.3.6.1.3.5.1.1.9.1.17.1.1.1.1.10.0.0.2.32.1.192.168.12.4.1": "2", + "1.3.6.1.3.5.1.1.9.1.17.1.1.1.1.10.0.0.2.32.1.192.168.12.4.2": "0", + "1.3.6.1.3.5.1.1.9.1.17.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.4.1": "1", + "1.3.6.1.3.5.1.1.9.1.17.1.2.1.2.32.1.13.184.0.0.0.0.0.0.0.0.0.0.0.1.128.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.4.2": "0", + "1.3.6.1.3.5.1.1.9.1.17.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.4.1": "2", + "1.3.6.1.3.5.1.1.9.1.17.1.2.1.2.32.1.13.184.0.1.0.0.0.0.0.0.0.0.0.0.56.2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.4.2": "0", } # bgp4V2NlriMed output, _ = snmp.walk(".1.3.6.1.3.5.1.1.9.1.17") + # tgen.mininet_cli() return output == expected _, result = topotest.run_and_expect(_snmpwalk_med, True, count=10, wait=1) assertmsg = "Can't fetch SNMP for bgp4V2NlriMed" assert result, assertmsg + # + # traps + # + + # + # bgp4 traps + # + def _snmptrap_ipv4(): + def __get_notif_bgp4_in_trap_file(router): + snmptrapfile = "{}/{}/snmptrapd.log".format(router.logdir, router.name) + outputfile = open(snmptrapfile).read() + output = snmp.get_notif_bgp4(outputfile) + + return output + + output = __get_notif_bgp4_in_trap_file(r2) + logger.info("output bgp4") + logger.info(output) + return snmp.is_notif_bgp4_valid(output, "192.168.12.4") + + # skip tests is SNMP not installed + if not os.path.isfile("/usr/sbin/snmptrapd"): + error_msg = "SNMP not installed - skipping" + pytest.skip(error_msg) + + rr.vtysh_cmd("clear bgp *") + _, result = topotest.run_and_expect(_snmptrap_ipv4, True, count=2, wait=10) + assertmsg = "Can't fetch SNMP trap for ipv4" + assert result, assertmsg + + # + # bgp4v2 traps + # + def _snmptrap_ipv6(): + def __get_notif_bgp4v2_in_trap_file(router): + snmptrapfile = "{}/{}/snmptrapd.log".format(router.logdir, router.name) + outputfile = open(snmptrapfile).read() + output = snmp.get_notif_bgp4v2(outputfile) + + return output + + # tgen.mininet_cli() + output = __get_notif_bgp4v2_in_trap_file(r2) + logger.info("output bgp4v2") + logger.info(output) + p_ipv4_addr = "1.192.168.12.4" + p_ipv6_addr = "2.32.1.13.184.0.0.0.0.0.0.0.0.0.18.0.4" + return ( + snmp.is_notif_bgp4v2_valid(output, p_ipv4_addr, "Estab") + and snmp.is_notif_bgp4v2_valid(output, p_ipv6_addr, "Estab") + and snmp.is_notif_bgp4v2_valid(output, p_ipv4_addr, "Backward") + and snmp.is_notif_bgp4v2_valid(output, p_ipv6_addr, "Backward") + ) + + sleep(10) + r2.vtysh_cmd("conf\nbgp snmp traps bgp4-mibv2") + r2.vtysh_cmd("conf\nno bgp snmp traps rfc4273") + rr.vtysh_cmd("clear bgp *") + sleep(30) + _, result = topotest.run_and_expect(_snmptrap_ipv6, True, count=2, wait=10) + assertmsg = "Can't fetch SNMP trap for ipv6" + assert result, assertmsg + def test_memory_leak(): "Run the memory leak test and report results." diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/ce1/snmpd.conf b/tests/topotests/bgp_snmp_mplsl3vpn/ce1/snmpd.conf index 4aff57acaf..c8d0bab048 100644 --- a/tests/topotests/bgp_snmp_mplsl3vpn/ce1/snmpd.conf +++ b/tests/topotests/bgp_snmp_mplsl3vpn/ce1/snmpd.conf @@ -1,4 +1,4 @@ -agentAddress udp:10.5.5.5:161 +agentAddress udp:161 com2sec public localhost public @@ -15,4 +15,4 @@ rouser frr master agentx agentXSocket /etc/frr/agentx -agentXPerms 777 755 root frr \ No newline at end of file +agentXPerms 777 755 root frr diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/ce2/snmpd.conf b/tests/topotests/bgp_snmp_mplsl3vpn/ce2/snmpd.conf index 29c2041d12..c8d0bab048 100644 --- a/tests/topotests/bgp_snmp_mplsl3vpn/ce2/snmpd.conf +++ b/tests/topotests/bgp_snmp_mplsl3vpn/ce2/snmpd.conf @@ -1,4 +1,4 @@ -agentAddress udp:10.6.6.6:161 +agentAddress udp:161 com2sec public localhost public @@ -15,4 +15,4 @@ rouser frr master agentx agentXSocket /etc/frr/agentx -agentXPerms 777 755 root frr \ No newline at end of file +agentXPerms 777 755 root frr diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/ce3/snmpd.conf b/tests/topotests/bgp_snmp_mplsl3vpn/ce3/snmpd.conf index 4aff57acaf..c8d0bab048 100644 --- a/tests/topotests/bgp_snmp_mplsl3vpn/ce3/snmpd.conf +++ b/tests/topotests/bgp_snmp_mplsl3vpn/ce3/snmpd.conf @@ -1,4 +1,4 @@ -agentAddress udp:10.5.5.5:161 +agentAddress udp:161 com2sec public localhost public @@ -15,4 +15,4 @@ rouser frr master agentx agentXSocket /etc/frr/agentx -agentXPerms 777 755 root frr \ No newline at end of file +agentXPerms 777 755 root frr diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/ce4/snmpd.conf b/tests/topotests/bgp_snmp_mplsl3vpn/ce4/snmpd.conf index 4aff57acaf..c8d0bab048 100644 --- a/tests/topotests/bgp_snmp_mplsl3vpn/ce4/snmpd.conf +++ b/tests/topotests/bgp_snmp_mplsl3vpn/ce4/snmpd.conf @@ -1,4 +1,4 @@ -agentAddress udp:10.5.5.5:161 +agentAddress udp:161 com2sec public localhost public @@ -15,4 +15,4 @@ rouser frr master agentx agentXSocket /etc/frr/agentx -agentXPerms 777 755 root frr \ No newline at end of file +agentXPerms 777 755 root frr diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/r1/isisd.conf b/tests/topotests/bgp_snmp_mplsl3vpn/r1/isisd.conf index 1a148f0628..435abde330 100644 --- a/tests/topotests/bgp_snmp_mplsl3vpn/r1/isisd.conf +++ b/tests/topotests/bgp_snmp_mplsl3vpn/r1/isisd.conf @@ -9,7 +9,7 @@ interface r1-eth0 isis circuit-type level-1 no isis hello padding isis hello-interval 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point ! interface r1-eth1 @@ -18,7 +18,7 @@ interface r1-eth1 isis circuit-type level-1 no isis hello padding isis hello-interval 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point ! interface r1-eth2 @@ -27,7 +27,7 @@ interface r1-eth2 isis circuit-type level-1 no isis hello padding isis hello-interval 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point ! interface lo diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/r1/snmpd.conf b/tests/topotests/bgp_snmp_mplsl3vpn/r1/snmpd.conf index 2ada53ced9..d7886e5132 100644 --- a/tests/topotests/bgp_snmp_mplsl3vpn/r1/snmpd.conf +++ b/tests/topotests/bgp_snmp_mplsl3vpn/r1/snmpd.conf @@ -1,4 +1,4 @@ -agentAddress udp:10.1.1.1:161 +agentAddress udp:161 com2sec public 10.1.1.1 public @@ -17,4 +17,4 @@ master agentx noRangeCheck yes agentXSocket /etc/frr/agentx -agentXPerms 777 755 root frr \ No newline at end of file +agentXPerms 777 755 root frr diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/r2/isisd.conf b/tests/topotests/bgp_snmp_mplsl3vpn/r2/isisd.conf index 396797dfb9..be5e7f585d 100644 --- a/tests/topotests/bgp_snmp_mplsl3vpn/r2/isisd.conf +++ b/tests/topotests/bgp_snmp_mplsl3vpn/r2/isisd.conf @@ -9,7 +9,7 @@ interface r2-eth0 isis circuit-type level-1 no isis hello padding isis hello-interval 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point ! interface r2-eth1 @@ -18,7 +18,7 @@ interface r2-eth1 isis circuit-type level-1 no isis hello padding isis hello-interval 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point ! interface lo diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/r2/snmpd.conf b/tests/topotests/bgp_snmp_mplsl3vpn/r2/snmpd.conf index 3db1ab7ace..c8d0bab048 100644 --- a/tests/topotests/bgp_snmp_mplsl3vpn/r2/snmpd.conf +++ b/tests/topotests/bgp_snmp_mplsl3vpn/r2/snmpd.conf @@ -1,4 +1,4 @@ -agentAddress udp:10.2.2.2:161 +agentAddress udp:161 com2sec public localhost public @@ -15,4 +15,4 @@ rouser frr master agentx agentXSocket /etc/frr/agentx -agentXPerms 777 755 root frr \ No newline at end of file +agentXPerms 777 755 root frr diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/r3/isisd.conf b/tests/topotests/bgp_snmp_mplsl3vpn/r3/isisd.conf index 9e52fb6820..6f3d8ec780 100644 --- a/tests/topotests/bgp_snmp_mplsl3vpn/r3/isisd.conf +++ b/tests/topotests/bgp_snmp_mplsl3vpn/r3/isisd.conf @@ -9,7 +9,7 @@ interface r3-eth0 isis circuit-type level-1 no isis hello padding isis hello-interval 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point ! interface r3-eth1 @@ -18,7 +18,7 @@ interface r3-eth1 isis circuit-type level-1 no isis hello padding isis hello-interval 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point ! interface r3-eth2 @@ -27,7 +27,7 @@ interface r3-eth2 isis circuit-type level-1 no isis hello padding isis hello-interval 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point ! interface lo diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/r3/snmpd.conf b/tests/topotests/bgp_snmp_mplsl3vpn/r3/snmpd.conf index 494df81ffb..c8d0bab048 100644 --- a/tests/topotests/bgp_snmp_mplsl3vpn/r3/snmpd.conf +++ b/tests/topotests/bgp_snmp_mplsl3vpn/r3/snmpd.conf @@ -1,4 +1,4 @@ -agentAddress udp:10.3.3.3:161 +agentAddress udp:161 com2sec public localhost public @@ -15,4 +15,4 @@ rouser frr master agentx agentXSocket /etc/frr/agentx -agentXPerms 777 755 root frr \ No newline at end of file +agentXPerms 777 755 root frr diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/r4/isisd.conf b/tests/topotests/bgp_snmp_mplsl3vpn/r4/isisd.conf index 8de2cf05c5..7d923b6240 100644 --- a/tests/topotests/bgp_snmp_mplsl3vpn/r4/isisd.conf +++ b/tests/topotests/bgp_snmp_mplsl3vpn/r4/isisd.conf @@ -9,7 +9,7 @@ interface r4-eth0 isis circuit-type level-1 no isis hello padding isis hello-interval 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point ! interface r4-eth1 @@ -18,7 +18,7 @@ interface r4-eth1 isis circuit-type level-1 no isis hello padding isis hello-interval 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point ! interface lo diff --git a/tests/topotests/bgp_snmp_mplsl3vpn/r4/snmpd.conf b/tests/topotests/bgp_snmp_mplsl3vpn/r4/snmpd.conf index f3809607e3..c8d0bab048 100644 --- a/tests/topotests/bgp_snmp_mplsl3vpn/r4/snmpd.conf +++ b/tests/topotests/bgp_snmp_mplsl3vpn/r4/snmpd.conf @@ -1,4 +1,4 @@ -agentAddress udp:10.4.4.4:161 +agentAddress udp:161 com2sec public localhost public @@ -15,4 +15,4 @@ rouser frr master agentx agentXSocket /etc/frr/agentx -agentXPerms 777 755 root frr \ No newline at end of file +agentXPerms 777 755 root frr diff --git a/tests/topotests/bgp_software_version/r1/bgpd.conf b/tests/topotests/bgp_software_version/r1/bgpd.conf index 80a05b3b64..42d15f7a2f 100644 --- a/tests/topotests/bgp_software_version/r1/bgpd.conf +++ b/tests/topotests/bgp_software_version/r1/bgpd.conf @@ -1,8 +1,8 @@ ! router bgp 65001 no bgp ebgp-requires-policy + bgp default software-version-capability neighbor 192.168.1.2 remote-as external neighbor 192.168.1.2 timers 1 3 neighbor 192.168.1.2 timers connect 1 - neighbor 192.168.1.2 capability software-version ! diff --git a/tests/topotests/bgp_software_version/test_bgp_software_version.py b/tests/topotests/bgp_software_version/test_bgp_software_version.py index 55327b77f8..25e646cf42 100644 --- a/tests/topotests/bgp_software_version/test_bgp_software_version.py +++ b/tests/topotests/bgp_software_version/test_bgp_software_version.py @@ -1,22 +1,9 @@ #!/usr/bin/env python +# SPDX-License-Identifier: ISC # Copyright (c) 2022 by # Donatas Abraitis <donatas@opensourcerouting.org> # -# Permission to use, copy, modify, and/or distribute this software -# for any purpose with or without fee is hereby granted, provided -# that the above copyright notice and this permission notice appear -# in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY -# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS -# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -# OF THIS SOFTWARE. -# """ Test if Software Version capability works if forced with a knob. diff --git a/tests/topotests/bgp_srv6l3vpn_over_ipv6/r1/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_over_ipv6/r1/bgpd.conf index 22b9014291..e8c14ab08f 100644 --- a/tests/topotests/bgp_srv6l3vpn_over_ipv6/r1/bgpd.conf +++ b/tests/topotests/bgp_srv6l3vpn_over_ipv6/r1/bgpd.conf @@ -4,7 +4,6 @@ hostname r1 password zebra ! log stdout notifications -log monitor notifications log commands ! router bgp 65001 diff --git a/tests/topotests/bgp_srv6l3vpn_over_ipv6/r2/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_over_ipv6/r2/bgpd.conf index 42b9d511d9..88de28108a 100644 --- a/tests/topotests/bgp_srv6l3vpn_over_ipv6/r2/bgpd.conf +++ b/tests/topotests/bgp_srv6l3vpn_over_ipv6/r2/bgpd.conf @@ -4,7 +4,6 @@ hostname r2 password zebra ! log stdout notifications -log monitor notifications log commands ! router bgp 65002 diff --git a/tests/topotests/bgp_srv6l3vpn_over_ipv6/r3/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_over_ipv6/r3/bgpd.conf index 339b4eb089..443a64aa0a 100644 --- a/tests/topotests/bgp_srv6l3vpn_over_ipv6/r3/bgpd.conf +++ b/tests/topotests/bgp_srv6l3vpn_over_ipv6/r3/bgpd.conf @@ -4,7 +4,6 @@ hostname r2 password zebra ! log stdout notifications -log monitor notifications log commands ! router bgp 65001 diff --git a/tests/topotests/bgp_srv6l3vpn_over_ipv6/test_bgp_srv6l3vpn_over_ipv6.py b/tests/topotests/bgp_srv6l3vpn_over_ipv6/test_bgp_srv6l3vpn_over_ipv6.py index 9e529059e7..14b9ba8498 100755 --- a/tests/topotests/bgp_srv6l3vpn_over_ipv6/test_bgp_srv6l3vpn_over_ipv6.py +++ b/tests/topotests/bgp_srv6l3vpn_over_ipv6/test_bgp_srv6l3vpn_over_ipv6.py @@ -24,6 +24,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from lib.common_config import required_linux_kernel_version +from lib.checkping import check_ping pytestmark = [pytest.mark.bgpd] @@ -101,31 +102,15 @@ def teardown_module(mod): tgen.stop_topology() -def check_ping4(name, dest_addr, expected): - def _check(name, dest_addr, match): - tgen = get_topogen() - output = tgen.gears[name].run("ping {} -c 1 -w 1".format(dest_addr)) - logger.info(output) - if match not in output: - return "ping fail" - - match = ", {} packet loss".format("0%" if expected else "100%") - logger.info("[+] check {} {} {}".format(name, dest_addr, match)) - tgen = get_topogen() - func = functools.partial(_check, name, dest_addr, match) - success, result = topotest.run_and_expect(func, None, count=10, wait=1) - assert result is None, "Failed" - - def test_ping(): tgen = get_topogen() - check_ping4("c11", "192.168.2.1", True) - check_ping4("c11", "192.168.3.1", True) - check_ping4("c12", "192.168.2.1", True) - check_ping4("c12", "192.168.3.1", True) - check_ping4("c21", "192.168.3.1", True) - check_ping4("c22", "192.168.3.1", True) + check_ping("c11", "192.168.2.1", True, 10, 1) + check_ping("c11", "192.168.3.1", True, 10, 1) + check_ping("c12", "192.168.2.1", True, 10, 1) + check_ping("c12", "192.168.3.1", True, 10, 1) + check_ping("c21", "192.168.3.1", True, 10, 1) + check_ping("c22", "192.168.3.1", True, 10, 1) if __name__ == "__main__": diff --git a/tests/topotests/bgp_srv6l3vpn_route_leak/pe1/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_route_leak/pe1/bgpd.conf index 15779aa0d5..3d9c2cfd17 100644 --- a/tests/topotests/bgp_srv6l3vpn_route_leak/pe1/bgpd.conf +++ b/tests/topotests/bgp_srv6l3vpn_route_leak/pe1/bgpd.conf @@ -4,7 +4,6 @@ hostname pe1 password zebra ! log stdout notifications -log monitor notifications log commands ! router bgp 65001 diff --git a/tests/topotests/bgp_srv6l3vpn_sid/r1/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_sid/r1/bgpd.conf index bfc9db960a..8805009f9e 100644 --- a/tests/topotests/bgp_srv6l3vpn_sid/r1/bgpd.conf +++ b/tests/topotests/bgp_srv6l3vpn_sid/r1/bgpd.conf @@ -4,7 +4,6 @@ hostname r1 password zebra ! log stdout notifications -log monitor notifications log commands ! !debug bgp neighbor-events diff --git a/tests/topotests/bgp_srv6l3vpn_sid/r1/zebra.conf b/tests/topotests/bgp_srv6l3vpn_sid/r1/zebra.conf index cf31a5c11b..be43805386 100644 --- a/tests/topotests/bgp_srv6l3vpn_sid/r1/zebra.conf +++ b/tests/topotests/bgp_srv6l3vpn_sid/r1/zebra.conf @@ -4,7 +4,6 @@ hostname r1 password zebra ! log stdout notifications -log monitor notifications log commands ! !debug zebra packet diff --git a/tests/topotests/bgp_srv6l3vpn_sid/r2/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_sid/r2/bgpd.conf index 892a9f73e5..0770a96d2d 100644 --- a/tests/topotests/bgp_srv6l3vpn_sid/r2/bgpd.conf +++ b/tests/topotests/bgp_srv6l3vpn_sid/r2/bgpd.conf @@ -4,7 +4,6 @@ hostname r2 password zebra ! log stdout notifications -log monitor notifications log commands ! !debug bgp neighbor-events diff --git a/tests/topotests/bgp_srv6l3vpn_sid/r2/zebra.conf b/tests/topotests/bgp_srv6l3vpn_sid/r2/zebra.conf index 9771ee1cd7..70627adc61 100644 --- a/tests/topotests/bgp_srv6l3vpn_sid/r2/zebra.conf +++ b/tests/topotests/bgp_srv6l3vpn_sid/r2/zebra.conf @@ -4,7 +4,6 @@ hostname r2 password zebra ! log stdout notifications -log monitor notifications log commands ! !debug zebra packet diff --git a/tests/topotests/bgp_srv6l3vpn_sid/test_bgp_srv6l3vpn_sid.py b/tests/topotests/bgp_srv6l3vpn_sid/test_bgp_srv6l3vpn_sid.py index cddcf6a9a1..984cf97e28 100755 --- a/tests/topotests/bgp_srv6l3vpn_sid/test_bgp_srv6l3vpn_sid.py +++ b/tests/topotests/bgp_srv6l3vpn_sid/test_bgp_srv6l3vpn_sid.py @@ -35,10 +35,11 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from lib.common_config import required_linux_kernel_version +from lib.checkping import check_ping def build_topo(tgen): - """ + r""" CE1 CE3 CE5 (eth0) (eth0) (eth0) :2 :2 :2 @@ -167,22 +168,6 @@ def open_json_file(filename): assert False, "Could not read file {}".format(filename) -def check_ping(name, dest_addr, expect_connected): - def _check(name, dest_addr, match): - tgen = get_topogen() - output = tgen.gears[name].run("ping {} -c 1 -w 1".format(dest_addr)) - logger.info(output) - if match not in output: - return True - - match = ", {} packet loss".format("0%" if expect_connected else "100%") - logger.info("[+] check {} {} {}".format(name, dest_addr, match)) - tgen = get_topogen() - func = functools.partial(_check, name, dest_addr, match) - success, result = topotest.run_and_expect(func, None, count=10, wait=0.5) - assert result is None, "Failed" - - def check_rib(name, cmd, expected_file): def _check(name, cmd, expected_file): logger.info("polling") @@ -215,21 +200,21 @@ def test_rib(): def test_ping(): - check_ping("ce1", "2001:2::2", True) - check_ping("ce1", "2001:3::2", True) - check_ping("ce1", "2001:4::2", False) - check_ping("ce1", "2001:5::2", False) - check_ping("ce1", "2001:6::2", False) - check_ping("ce4", "2001:1::2", False) - check_ping("ce4", "2001:2::2", False) - check_ping("ce4", "2001:3::2", False) - check_ping("ce4", "2001:5::2", True) - check_ping("ce4", "2001:6::2", True) + check_ping("ce1", "2001:2::2", True, 10, 0.5) + check_ping("ce1", "2001:3::2", True, 10, 0.5) + check_ping("ce1", "2001:4::2", False, 10, 0.5) + check_ping("ce1", "2001:5::2", False, 10, 0.5) + check_ping("ce1", "2001:6::2", False, 10, 0.5) + check_ping("ce4", "2001:1::2", False, 10, 0.5) + check_ping("ce4", "2001:2::2", False, 10, 0.5) + check_ping("ce4", "2001:3::2", False, 10, 0.5) + check_ping("ce4", "2001:5::2", True, 10, 0.5) + check_ping("ce4", "2001:6::2", True, 10, 0.5) def test_sid_per_afv6_auto(): check_rib("r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_afv6_auto_sid_rib.json") - check_ping("ce1", "2001:2::2", True) + check_ping("ce1", "2001:2::2", True, 10, 0.5) get_topogen().gears["r2"].vtysh_cmd( """ configure terminal @@ -241,7 +226,7 @@ def test_sid_per_afv6_auto(): check_rib( "r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_afv6_auto_no_sid_rib.json" ) - check_ping("ce1", "2001:2::2", False) + check_ping("ce1", "2001:2::2", False, 10, 0.5) get_topogen().gears["r2"].vtysh_cmd( """ @@ -252,7 +237,7 @@ def test_sid_per_afv6_auto(): """ ) check_rib("r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_afv6_auto_sid_rib.json") - check_ping("ce1", "2001:2::2", True) + check_ping("ce1", "2001:2::2", True, 10, 0.5) get_topogen().gears["r2"].vtysh_cmd( """ @@ -265,14 +250,14 @@ def test_sid_per_afv6_auto(): check_rib( "r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_afv6_auto_no_sid_rib.json" ) - check_ping("ce1", "2001:2::2", False) + check_ping("ce1", "2001:2::2", False, 10, 0.5) def test_sid_per_afv6_manual(): check_rib( "r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_afv6_manual_no_sid_rib.json" ) - check_ping("ce1", "2001:2::2", False) + check_ping("ce1", "2001:2::2", False, 10, 0.5) get_topogen().gears["r2"].vtysh_cmd( """ @@ -286,7 +271,7 @@ def test_sid_per_afv6_manual(): check_rib( "r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_afv6_manual_sid_rib.json" ) - check_ping("ce1", "2001:2::2", True) + check_ping("ce1", "2001:2::2", True, 10, 0.5) get_topogen().gears["r2"].vtysh_cmd( """ @@ -299,12 +284,12 @@ def test_sid_per_afv6_manual(): check_rib( "r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_afv6_manual_no_sid_rib.json" ) - check_ping("ce1", "2001:2::2", False) + check_ping("ce1", "2001:2::2", False, 10, 0.5) def test_sid_per_afv4_auto(): check_rib("r1", "show ip route vrf vrf10 json", "r1/vrf10_afv4_auto_sid_rib.json") - check_ping("ce1", "192.168.2.2", True) + check_ping("ce1", "192.168.2.2", True, 10, 0.5) get_topogen().gears["r2"].vtysh_cmd( """ configure terminal @@ -317,7 +302,7 @@ def test_sid_per_afv4_auto(): check_rib( "r1", "show ip route vrf vrf10 json", "r1/vrf10_afv4_auto_no_sid_rib.json" ) - check_ping("ce1", "192.168.2.2", False) + check_ping("ce1", "192.168.2.2", False, 10, 0.5) get_topogen().gears["r2"].vtysh_cmd( """ @@ -329,7 +314,7 @@ def test_sid_per_afv4_auto(): ) check_rib("r1", "show ip route vrf vrf10 json", "r1/vrf10_afv4_auto_sid_rib.json") - check_ping("ce1", "192.168.2.2", True) + check_ping("ce1", "192.168.2.2", True, 10, 0.5) get_topogen().gears["r2"].vtysh_cmd( """ @@ -342,14 +327,14 @@ def test_sid_per_afv4_auto(): check_rib( "r1", "show ip route vrf vrf10 json", "r1/vrf10_afv4_auto_no_sid_rib.json" ) - check_ping("ce1", "192.168.2.2", False) + check_ping("ce1", "192.168.2.2", False, 10, 0.5) def test_sid_per_afv4_manual(): check_rib( "r1", "show ip route vrf vrf10 json", "r1/vrf10_afv4_manual_no_sid_rib.json" ) - check_ping("ce1", "192.168.2.2", False) + check_ping("ce1", "192.168.2.2", False, 10, 0.5) get_topogen().gears["r2"].vtysh_cmd( """ configure terminal @@ -360,7 +345,7 @@ def test_sid_per_afv4_manual(): ) check_rib("r1", "show ip route vrf vrf10 json", "r1/vrf10_afv4_manual_sid_rib.json") - check_ping("ce1", "192.168.2.2", True) + check_ping("ce1", "192.168.2.2", True, 10, 0.5) get_topogen().gears["r2"].vtysh_cmd( """ @@ -370,7 +355,7 @@ def test_sid_per_afv4_manual(): no sid vpn export 8 """ ) - check_ping("ce1", "192.168.2.2", False) + check_ping("ce1", "192.168.2.2", False, 10, 0.5) check_rib( "r1", "show ip route vrf vrf10 json", "r1/vrf10_afv4_manual_no_sid_rib.json" ) @@ -380,7 +365,7 @@ def test_sid_per_vrf_auto(): check_rib( "r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_pervrf_auto_no_sid_rib.json" ) - check_ping("ce1", "2001:2::2", False) + check_ping("ce1", "2001:2::2", False, 10, 0.5) get_topogen().gears["r2"].vtysh_cmd( """ configure terminal @@ -392,11 +377,11 @@ def test_sid_per_vrf_auto(): check_rib( "r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_pervrf6_auto_sid_rib.json" ) - check_ping("ce1", "2001:2::2", True) + check_ping("ce1", "2001:2::2", True, 10, 0.5) check_rib( "r1", "show ip route vrf vrf10 json", "r1/vrf10_pervrf4_auto_sid_rib.json" ) - check_ping("ce1", "192.168.2.2", True) + check_ping("ce1", "192.168.2.2", True, 10, 0.5) get_topogen().gears["r2"].vtysh_cmd( """ @@ -409,14 +394,14 @@ def test_sid_per_vrf_auto(): check_rib( "r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_pervrf_auto_no_sid_rib.json" ) - check_ping("ce1", "2001:2::2", False) + check_ping("ce1", "2001:2::2", False, 10, 0.5) def test_sid_per_vrf_manual(): check_rib( "r1", "show ip route vrf vrf10 json", "r1/vrf10_pervrf_manual_no_sid_rib.json" ) - check_ping("ce1", "192.168.2.2", False) + check_ping("ce1", "192.168.2.2", False, 10, 0.5) get_topogen().gears["r2"].vtysh_cmd( """ configure terminal @@ -428,11 +413,11 @@ def test_sid_per_vrf_manual(): check_rib( "r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_pervrf6_manual_sid_rib.json" ) - check_ping("ce1", "2001:2::2", True) + check_ping("ce1", "2001:2::2", True, 10, 0.5) check_rib( "r1", "show ip route vrf vrf10 json", "r1/vrf10_pervrf4_manual_sid_rib.json" ) - check_ping("ce1", "192.168.2.2", True) + check_ping("ce1", "192.168.2.2", True, 10, 0.5) get_topogen().gears["r2"].vtysh_cmd( """ @@ -445,7 +430,7 @@ def test_sid_per_vrf_manual(): check_rib( "r1", "show ip route vrf vrf10 json", "r1/vrf10_pervrf_manual_no_sid_rib.json" ) - check_ping("ce1", "192.168.2.2", False) + check_ping("ce1", "192.168.2.2", False, 10, 0.5) if __name__ == "__main__": diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r1/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r1/bgpd.conf index d113db12b1..8079bb0c2a 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r1/bgpd.conf +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r1/bgpd.conf @@ -6,7 +6,6 @@ hostname r1 password zebra ! log stdout notifications -log monitor notifications log commands ! !debug bgp neighbor-events diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r1/zebra.conf b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r1/zebra.conf index 8ccf7a2a34..c84106f2bb 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r1/zebra.conf +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r1/zebra.conf @@ -4,7 +4,6 @@ hostname r1 password zebra ! log stdout notifications -log monitor notifications log commands ! ! debug zebra packet diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r2/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r2/bgpd.conf index 9a7831dd2a..c2e8530273 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r2/bgpd.conf +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r2/bgpd.conf @@ -6,7 +6,6 @@ hostname r2 password zebra ! log stdout notifications -log monitor notifications log commands ! !debug bgp neighbor-events diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r2/zebra.conf b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r2/zebra.conf index 839454d8a8..5c12429ff2 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r2/zebra.conf +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r2/zebra.conf @@ -4,7 +4,6 @@ hostname r2 password zebra ! log stdout notifications -log monitor notifications log commands ! ! debug zebra packet diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/test_bgp_srv6l3vpn_to_bgp_vrf.py b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/test_bgp_srv6l3vpn_to_bgp_vrf.py index fdc1f4eec3..4afaeaf78a 100755 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/test_bgp_srv6l3vpn_to_bgp_vrf.py +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/test_bgp_srv6l3vpn_to_bgp_vrf.py @@ -23,6 +23,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from lib.common_config import required_linux_kernel_version +from lib.checkping import check_ping pytestmark = [pytest.mark.bgpd] @@ -134,22 +135,6 @@ def open_json_file(filename): assert False, "Could not read file {}".format(filename) -def check_ping(name, dest_addr, expect_connected): - def _check(name, dest_addr, match): - tgen = get_topogen() - output = tgen.gears[name].run("ping6 {} -c 1 -w 1".format(dest_addr)) - logger.info(output) - if match not in output: - return "ping fail" - - match = ", {} packet loss".format("0%" if expect_connected else "100%") - logger.info("[+] check {} {} {}".format(name, dest_addr, match)) - tgen = get_topogen() - func = functools.partial(_check, name, dest_addr, match) - success, result = topotest.run_and_expect(func, None, count=10, wait=1) - assert result is None, "Failed" - - def check_rib(name, cmd, expected_file): def _check(name, cmd, expected_file): logger.info("polling") @@ -182,20 +167,20 @@ def test_rib(): def test_ping(): - check_ping("ce1", "2001:2::2", True) - check_ping("ce1", "2001:3::2", True) - check_ping("ce1", "2001:4::2", False) - check_ping("ce1", "2001:5::2", False) - check_ping("ce1", "2001:6::2", False) - check_ping("ce4", "2001:1::2", False) - check_ping("ce4", "2001:2::2", False) - check_ping("ce4", "2001:3::2", False) - check_ping("ce4", "2001:5::2", True) - check_ping("ce4", "2001:6::2", True) + check_ping("ce1", "2001:2::2", True, 10, 1) + check_ping("ce1", "2001:3::2", True, 10, 1) + check_ping("ce1", "2001:4::2", False, 10, 1) + check_ping("ce1", "2001:5::2", False, 10, 1) + check_ping("ce1", "2001:6::2", False, 10, 1) + check_ping("ce4", "2001:1::2", False, 10, 1) + check_ping("ce4", "2001:2::2", False, 10, 1) + check_ping("ce4", "2001:3::2", False, 10, 1) + check_ping("ce4", "2001:5::2", True, 10, 1) + check_ping("ce4", "2001:6::2", True, 10, 1) def test_locator_delete(): - check_ping("ce1", "2001:2::2", True) + check_ping("ce1", "2001:2::2", True, 10, 1) get_topogen().gears["r1"].vtysh_cmd( """ configure terminal @@ -207,11 +192,11 @@ def test_locator_delete(): ) check_rib("r1", "show bgp ipv6 vpn json", "r1/vpnv6_rib_locator_deleted.json") check_rib("r2", "show bgp ipv6 vpn json", "r2/vpnv6_rib_locator_deleted.json") - check_ping("ce1", "2001:2::2", False) + check_ping("ce1", "2001:2::2", False, 10, 1) def test_locator_recreate(): - check_ping("ce1", "2001:2::2", False) + check_ping("ce1", "2001:2::2", False, 10, 1) get_topogen().gears["r1"].vtysh_cmd( """ configure terminal @@ -224,11 +209,11 @@ def test_locator_recreate(): ) check_rib("r1", "show bgp ipv6 vpn json", "r1/vpnv6_rib_locator_recreated.json") check_rib("r2", "show bgp ipv6 vpn json", "r2/vpnv6_rib_locator_recreated.json") - check_ping("ce1", "2001:2::2", True) + check_ping("ce1", "2001:2::2", True, 10, 1) def test_bgp_locator_unset(): - check_ping("ce1", "2001:2::2", True) + check_ping("ce1", "2001:2::2", True, 10, 1) get_topogen().gears["r1"].vtysh_cmd( """ configure terminal @@ -239,11 +224,11 @@ def test_bgp_locator_unset(): ) check_rib("r1", "show bgp ipv6 vpn json", "r1/vpnv6_rib_locator_deleted.json") check_rib("r2", "show bgp ipv6 vpn json", "r2/vpnv6_rib_locator_deleted.json") - check_ping("ce1", "2001:2::2", False) + check_ping("ce1", "2001:2::2", False, 10, 1) def test_bgp_locator_reset(): - check_ping("ce1", "2001:2::2", False) + check_ping("ce1", "2001:2::2", False, 10, 1) get_topogen().gears["r1"].vtysh_cmd( """ configure terminal @@ -254,11 +239,11 @@ def test_bgp_locator_reset(): ) check_rib("r1", "show bgp ipv6 vpn json", "r1/vpnv6_rib_locator_recreated.json") check_rib("r2", "show bgp ipv6 vpn json", "r2/vpnv6_rib_locator_recreated.json") - check_ping("ce1", "2001:2::2", True) + check_ping("ce1", "2001:2::2", True, 10, 1) def test_bgp_srv6_unset(): - check_ping("ce1", "2001:2::2", True) + check_ping("ce1", "2001:2::2", True, 10, 1) get_topogen().gears["r1"].vtysh_cmd( """ configure terminal @@ -268,11 +253,11 @@ def test_bgp_srv6_unset(): ) check_rib("r1", "show bgp ipv6 vpn json", "r1/vpnv6_rib_locator_deleted.json") check_rib("r2", "show bgp ipv6 vpn json", "r2/vpnv6_rib_locator_deleted.json") - check_ping("ce1", "2001:2::2", False) + check_ping("ce1", "2001:2::2", False, 10, 1) def test_bgp_srv6_reset(): - check_ping("ce1", "2001:2::2", False) + check_ping("ce1", "2001:2::2", False, 10, 1) get_topogen().gears["r1"].vtysh_cmd( """ configure terminal @@ -283,7 +268,7 @@ def test_bgp_srv6_reset(): ) check_rib("r1", "show bgp ipv6 vpn json", "r1/vpnv6_rib_locator_recreated.json") check_rib("r2", "show bgp ipv6 vpn json", "r2/vpnv6_rib_locator_recreated.json") - check_ping("ce1", "2001:2::2", True) + check_ping("ce1", "2001:2::2", True, 10, 1) if __name__ == "__main__": diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r1/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r1/bgpd.conf index 30a0f8fe78..12b9e8fd00 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r1/bgpd.conf +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r1/bgpd.conf @@ -6,7 +6,6 @@ hostname r1 password zebra ! log stdout notifications -log monitor notifications log commands ! !debug bgp neighbor-events diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r1/vpnv4_rib.json b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r1/vpnv4_rib.json index 3cc2fddcfa..7a4e0d7452 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r1/vpnv4_rib.json +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r1/vpnv4_rib.json @@ -1,7 +1,6 @@ { "vrfId": 0, "vrfName": "default", - "tableVersion": 2, "routerId": "1.1.1.1", "defaultLocPrf": 100, "localAS": 1, diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r1/zebra.conf b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r1/zebra.conf index cbc5ce1f09..f202493c53 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r1/zebra.conf +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r1/zebra.conf @@ -4,7 +4,6 @@ hostname r1 password zebra ! log stdout notifications -log monitor notifications log commands ! !debug zebra packet diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r2/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r2/bgpd.conf index 7ca23002ac..db36c180a0 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r2/bgpd.conf +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r2/bgpd.conf @@ -6,7 +6,6 @@ hostname r2 password zebra ! log stdout notifications -log monitor notifications log commands ! !debug bgp neighbor-events diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r2/vpnv4_rib.json b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r2/vpnv4_rib.json index 95570541c8..0dcdec678f 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r2/vpnv4_rib.json +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r2/vpnv4_rib.json @@ -1,7 +1,6 @@ { "vrfId": 0, "vrfName": "default", - "tableVersion": 2, "routerId": "2.2.2.2", "defaultLocPrf": 100, "localAS": 2, diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r2/zebra.conf b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r2/zebra.conf index 449ca74d5e..9dfed4f2d6 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r2/zebra.conf +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r2/zebra.conf @@ -4,7 +4,6 @@ hostname r2 password zebra ! log stdout notifications -log monitor notifications log commands ! !debug zebra packet diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/test_bgp_srv6l3vpn_to_bgp_vrf2.py b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/test_bgp_srv6l3vpn_to_bgp_vrf2.py index a1202f5d93..914c29f0c1 100755 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/test_bgp_srv6l3vpn_to_bgp_vrf2.py +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/test_bgp_srv6l3vpn_to_bgp_vrf2.py @@ -24,6 +24,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from lib.common_config import required_linux_kernel_version +from lib.checkping import check_ping pytestmark = [pytest.mark.bgpd] @@ -96,21 +97,6 @@ def open_json_file(filename): assert False, "Could not read file {}".format(filename) -def check_ping(name, dest_addr, expect_connected): - def _check(name, dest_addr, match): - tgen = get_topogen() - output = tgen.gears[name].run("ping {} -c 1 -w 1".format(dest_addr)) - logger.info(output) - assert match in output, "ping fail" - - match = ", {} packet loss".format("0%" if expect_connected else "100%") - logger.info("[+] check {} {} {}".format(name, dest_addr, match)) - tgen = get_topogen() - func = functools.partial(_check, name, dest_addr, match) - success, result = topotest.run_and_expect(func, None, count=10, wait=0.5) - assert result is None, "Failed" - - def check_rib(name, cmd, expected_file): def _check(name, dest_addr, match): logger.info("polling") @@ -143,16 +129,16 @@ def test_rib(): def test_ping(): - check_ping("ce1", "192.168.2.2", True) - check_ping("ce1", "192.168.3.2", True) - check_ping("ce1", "192.168.4.2", False) - check_ping("ce1", "192.168.5.2", False) - check_ping("ce1", "192.168.6.2", False) - check_ping("ce4", "192.168.1.2", False) - check_ping("ce4", "192.168.2.2", False) - check_ping("ce4", "192.168.3.2", False) - check_ping("ce4", "192.168.5.2", True) - check_ping("ce4", "192.168.6.2", True) + check_ping("ce1", "192.168.2.2", True, 10, 0.5) + check_ping("ce1", "192.168.3.2", True, 10, 0.5) + check_ping("ce1", "192.168.4.2", False, 10, 0.5) + check_ping("ce1", "192.168.5.2", False, 10, 0.5) + check_ping("ce1", "192.168.6.2", False, 10, 0.5) + check_ping("ce4", "192.168.1.2", False, 10, 0.5) + check_ping("ce4", "192.168.2.2", False, 10, 0.5) + check_ping("ce4", "192.168.3.2", False, 10, 0.5) + check_ping("ce4", "192.168.5.2", True, 10, 0.5) + check_ping("ce4", "192.168.6.2", True, 10, 0.5) if __name__ == "__main__": diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/bgpd.conf index 01b0cc3c9e..57c19e25d7 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/bgpd.conf +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/bgpd.conf @@ -6,7 +6,6 @@ hostname r1 password zebra ! log stdout notifications -log monitor notifications log commands ! !debug bgp neighbor-events diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv4_rib.json b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv4_rib.json index 3cc2fddcfa..7a4e0d7452 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv4_rib.json +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv4_rib.json @@ -1,7 +1,6 @@ { "vrfId": 0, "vrfName": "default", - "tableVersion": 2, "routerId": "1.1.1.1", "defaultLocPrf": 100, "localAS": 1, diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv4_rib_sid_vpn_export_disabled.json b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv4_rib_sid_vpn_export_disabled.json index eb3433301b..205079574c 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv4_rib_sid_vpn_export_disabled.json +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv4_rib_sid_vpn_export_disabled.json @@ -1,7 +1,6 @@ { "vrfId": 0, "vrfName": "default", - "tableVersion": 4, "routerId": "1.1.1.1", "defaultLocPrf": 100, "localAS": 1, diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv4_rib_sid_vpn_export_reenabled.json b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv4_rib_sid_vpn_export_reenabled.json index 5517fc738a..7a4e0d7452 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv4_rib_sid_vpn_export_reenabled.json +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv4_rib_sid_vpn_export_reenabled.json @@ -1,7 +1,6 @@ { "vrfId": 0, "vrfName": "default", - "tableVersion": 6, "routerId": "1.1.1.1", "defaultLocPrf": 100, "localAS": 1, diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv6_rib.json b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv6_rib.json index 25b7a8616f..0fdd3d6dc0 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv6_rib.json +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv6_rib.json @@ -1,7 +1,6 @@ { "vrfId": 0, "vrfName": "default", - "tableVersion": 2, "routerId": "1.1.1.1", "defaultLocPrf": 100, "localAS": 1, diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv6_rib_sid_vpn_export_disabled.json b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv6_rib_sid_vpn_export_disabled.json index a1f21585d7..e289df1d44 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv6_rib_sid_vpn_export_disabled.json +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv6_rib_sid_vpn_export_disabled.json @@ -1,7 +1,6 @@ { "vrfId": 0, "vrfName": "default", - "tableVersion": 4, "routerId": "1.1.1.1", "defaultLocPrf": 100, "localAS": 1, diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv6_rib_sid_vpn_export_reenabled.json b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv6_rib_sid_vpn_export_reenabled.json index 7eeccd1496..0fdd3d6dc0 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv6_rib_sid_vpn_export_reenabled.json +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/vpnv6_rib_sid_vpn_export_reenabled.json @@ -1,7 +1,6 @@ { "vrfId": 0, "vrfName": "default", - "tableVersion": 6, "routerId": "1.1.1.1", "defaultLocPrf": 100, "localAS": 1, diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/zebra.conf b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/zebra.conf index f913b9f002..dd8a756a6e 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/zebra.conf +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/zebra.conf @@ -4,7 +4,6 @@ hostname r1 password zebra ! log stdout notifications -log monitor notifications log commands ! !debug zebra packet diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/bgpd.conf index 8700f12d63..abf4971a9b 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/bgpd.conf +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/bgpd.conf @@ -6,7 +6,6 @@ hostname r2 password zebra ! log stdout notifications -log monitor notifications log commands ! !debug bgp neighbor-events diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv4_rib.json b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv4_rib.json index 95570541c8..0dcdec678f 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv4_rib.json +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv4_rib.json @@ -1,7 +1,6 @@ { "vrfId": 0, "vrfName": "default", - "tableVersion": 2, "routerId": "2.2.2.2", "defaultLocPrf": 100, "localAS": 2, diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv4_rib_sid_vpn_export_disabled.json b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv4_rib_sid_vpn_export_disabled.json index d801671fdc..a440ab4248 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv4_rib_sid_vpn_export_disabled.json +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv4_rib_sid_vpn_export_disabled.json @@ -1,7 +1,6 @@ { "vrfId": 0, "vrfName": "default", - "tableVersion": 4, "routerId": "2.2.2.2", "defaultLocPrf": 100, "localAS": 2, diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv4_rib_sid_vpn_export_reenabled.json b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv4_rib_sid_vpn_export_reenabled.json index 25da05b0d4..0dcdec678f 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv4_rib_sid_vpn_export_reenabled.json +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv4_rib_sid_vpn_export_reenabled.json @@ -1,7 +1,6 @@ { "vrfId": 0, "vrfName": "default", - "tableVersion": 6, "routerId": "2.2.2.2", "defaultLocPrf": 100, "localAS": 2, diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv6_rib.json b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv6_rib.json index 2cd47b9ce5..03bbcc008d 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv6_rib.json +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv6_rib.json @@ -1,7 +1,6 @@ { "vrfId": 0, "vrfName": "default", - "tableVersion": 2, "routerId": "2.2.2.2", "defaultLocPrf": 100, "localAS": 2, diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv6_rib_sid_vpn_export_disabled.json b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv6_rib_sid_vpn_export_disabled.json index f390ef69b1..5c70cf6450 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv6_rib_sid_vpn_export_disabled.json +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv6_rib_sid_vpn_export_disabled.json @@ -1,7 +1,6 @@ { "vrfId": 0, "vrfName": "default", - "tableVersion": 4, "routerId": "2.2.2.2", "defaultLocPrf": 100, "localAS": 2, diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv6_rib_sid_vpn_export_reenabled.json b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv6_rib_sid_vpn_export_reenabled.json index 3353d75eda..03bbcc008d 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv6_rib_sid_vpn_export_reenabled.json +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/vpnv6_rib_sid_vpn_export_reenabled.json @@ -1,7 +1,6 @@ { "vrfId": 0, "vrfName": "default", - "tableVersion": 6, "routerId": "2.2.2.2", "defaultLocPrf": 100, "localAS": 2, diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/zebra.conf b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/zebra.conf index 201d0cce23..3c9e4e3b25 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/zebra.conf +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/zebra.conf @@ -4,7 +4,6 @@ hostname r2 password zebra ! log stdout notifications -log monitor notifications log commands ! !debug zebra packet diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/test_bgp_srv6l3vpn_to_bgp_vrf3.py b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/test_bgp_srv6l3vpn_to_bgp_vrf3.py index 7c2c7cfdaa..8a7b558be3 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/test_bgp_srv6l3vpn_to_bgp_vrf3.py +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/test_bgp_srv6l3vpn_to_bgp_vrf3.py @@ -21,6 +21,7 @@ from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger from lib.common_config import required_linux_kernel_version +from lib.checkping import check_ping, check_ping pytestmark = [pytest.mark.bgpd] @@ -93,38 +94,6 @@ def open_json_file(filename): assert False, "Could not read file {}".format(filename) -def check_ping4(name, dest_addr, expect_connected): - def _check(name, dest_addr, match): - tgen = get_topogen() - output = tgen.gears[name].run("ping {} -c 1 -w 1".format(dest_addr)) - logger.info(output) - if match not in output: - return "ping fail" - - match = ", {} packet loss".format("0%" if expect_connected else "100%") - logger.info("[+] check {} {} {}".format(name, dest_addr, match)) - tgen = get_topogen() - func = functools.partial(_check, name, dest_addr, match) - success, result = topotest.run_and_expect(func, None, count=10, wait=0.5) - assert result is None, "Failed" - - -def check_ping6(name, dest_addr, expect_connected): - def _check(name, dest_addr, match): - tgen = get_topogen() - output = tgen.gears[name].run("ping6 {} -c 1 -w 1".format(dest_addr)) - logger.info(output) - if match not in output: - return "ping fail" - - match = "{} packet loss".format("0%" if expect_connected else "100%") - logger.info("[+] check {} {} {}".format(name, dest_addr, match)) - tgen = get_topogen() - func = functools.partial(_check, name, dest_addr, match) - success, result = topotest.run_and_expect(func, None, count=10, wait=1) - assert result is None, "Failed" - - def check_rib(name, cmd, expected_file): def _check(name, dest_addr, match): logger.info("polling") @@ -170,32 +139,32 @@ def test_rib(): def test_ping(): - check_ping4("ce1", "192.168.2.2", True) - check_ping4("ce1", "192.168.3.2", True) - check_ping4("ce1", "192.168.4.2", False) - check_ping4("ce1", "192.168.5.2", False) - check_ping4("ce1", "192.168.6.2", False) - check_ping4("ce4", "192.168.1.2", False) - check_ping4("ce4", "192.168.2.2", False) - check_ping4("ce4", "192.168.3.2", False) - check_ping4("ce4", "192.168.5.2", True) - check_ping4("ce4", "192.168.6.2", True) - - check_ping6("ce1", "2001:2::2", True) - check_ping6("ce1", "2001:3::2", True) - check_ping6("ce1", "2001:4::2", False) - check_ping6("ce1", "2001:5::2", False) - check_ping6("ce1", "2001:6::2", False) - check_ping6("ce4", "2001:1::2", False) - check_ping6("ce4", "2001:2::2", False) - check_ping6("ce4", "2001:3::2", False) - check_ping6("ce4", "2001:5::2", True) - check_ping6("ce4", "2001:6::2", True) + check_ping("ce1", "192.168.2.2", True, 10, 0.5) + check_ping("ce1", "192.168.3.2", True, 10, 0.5) + check_ping("ce1", "192.168.4.2", False, 10, 0.5) + check_ping("ce1", "192.168.5.2", False, 10, 0.5) + check_ping("ce1", "192.168.6.2", False, 10, 0.5) + check_ping("ce4", "192.168.1.2", False, 10, 0.5) + check_ping("ce4", "192.168.2.2", False, 10, 0.5) + check_ping("ce4", "192.168.3.2", False, 10, 0.5) + check_ping("ce4", "192.168.5.2", True, 10, 0.5) + check_ping("ce4", "192.168.6.2", True, 10, 0.5) + + check_ping("ce1", "2001:2::2", True, 10, 1) + check_ping("ce1", "2001:3::2", True, 10, 1) + check_ping("ce1", "2001:4::2", False, 10, 1) + check_ping("ce1", "2001:5::2", False, 10, 1) + check_ping("ce1", "2001:6::2", False, 10, 1) + check_ping("ce4", "2001:1::2", False, 10, 1) + check_ping("ce4", "2001:2::2", False, 10, 1) + check_ping("ce4", "2001:3::2", False, 10, 1) + check_ping("ce4", "2001:5::2", True, 10, 1) + check_ping("ce4", "2001:6::2", True, 10, 1) def test_bgp_sid_vpn_export_disable(): - check_ping4("ce1", "192.168.2.2", True) - check_ping6("ce1", "2001:2::2", True) + check_ping("ce1", "192.168.2.2", True, 10, 0.5) + check_ping("ce1", "2001:2::2", True, 10, 1) get_topogen().gears["r1"].vtysh_cmd( """ configure terminal @@ -216,13 +185,13 @@ def test_bgp_sid_vpn_export_disable(): check_rib( "r2", "show bgp ipv6 vpn json", "r2/vpnv6_rib_sid_vpn_export_disabled.json" ) - check_ping4("ce1", "192.168.2.2", False) - check_ping6("ce1", "2001:2::2", False) + check_ping("ce1", "192.168.2.2", False, 10, 0.5) + check_ping("ce1", "2001:2::2", False, 10, 1) def test_bgp_sid_vpn_export_reenable(): - check_ping4("ce1", "192.168.2.2", False) - check_ping6("ce1", "2001:2::2", False) + check_ping("ce1", "192.168.2.2", False, 10, 0.5) + check_ping("ce1", "2001:2::2", False, 10, 1) get_topogen().gears["r1"].vtysh_cmd( """ configure terminal @@ -243,13 +212,13 @@ def test_bgp_sid_vpn_export_reenable(): check_rib( "r2", "show bgp ipv6 vpn json", "r2/vpnv6_rib_sid_vpn_export_reenabled.json" ) - check_ping4("ce1", "192.168.2.2", True) - check_ping6("ce1", "2001:2::2", True) + check_ping("ce1", "192.168.2.2", True, 10, 0.5) + check_ping("ce1", "2001:2::2", True, 10, 1) def test_locator_delete(): - check_ping4("ce1", "192.168.2.2", True) - check_ping6("ce1", "2001:2::2", True) + check_ping("ce1", "192.168.2.2", True, 10, 0.5) + check_ping("ce1", "2001:2::2", True, 10, 1) get_topogen().gears["r1"].vtysh_cmd( """ configure terminal @@ -263,13 +232,13 @@ def test_locator_delete(): check_rib("r2", "show bgp ipv4 vpn json", "r2/vpnv4_rib_locator_deleted.json") check_rib("r1", "show bgp ipv6 vpn json", "r1/vpnv6_rib_locator_deleted.json") check_rib("r2", "show bgp ipv6 vpn json", "r2/vpnv6_rib_locator_deleted.json") - check_ping4("ce1", "192.168.2.2", False) - check_ping6("ce1", "2001:2::2", False) + check_ping("ce1", "192.168.2.2", False, 10, 0.5) + check_ping("ce1", "2001:2::2", False, 10, 1) def test_locator_recreate(): - check_ping4("ce1", "192.168.2.2", False) - check_ping6("ce1", "2001:2::2", False) + check_ping("ce1", "192.168.2.2", False, 10, 0.5) + check_ping("ce1", "2001:2::2", False, 10, 1) get_topogen().gears["r1"].vtysh_cmd( """ configure terminal @@ -284,13 +253,13 @@ def test_locator_recreate(): check_rib("r2", "show bgp ipv4 vpn json", "r2/vpnv4_rib_locator_recreated.json") check_rib("r1", "show bgp ipv6 vpn json", "r1/vpnv6_rib_locator_recreated.json") check_rib("r2", "show bgp ipv6 vpn json", "r2/vpnv6_rib_locator_recreated.json") - check_ping4("ce1", "192.168.2.2", True) - check_ping6("ce1", "2001:2::2", True) + check_ping("ce1", "192.168.2.2", True, 10, 0.5) + check_ping("ce1", "2001:2::2", True, 10, 1) def test_bgp_locator_unset(): - check_ping4("ce1", "192.168.2.2", True) - check_ping6("ce1", "2001:2::2", True) + check_ping("ce1", "192.168.2.2", True, 10, 0.5) + check_ping("ce1", "2001:2::2", True, 10, 1) get_topogen().gears["r1"].vtysh_cmd( """ configure terminal @@ -303,13 +272,13 @@ def test_bgp_locator_unset(): check_rib("r2", "show bgp ipv4 vpn json", "r2/vpnv4_rib_locator_deleted.json") check_rib("r1", "show bgp ipv6 vpn json", "r1/vpnv6_rib_locator_deleted.json") check_rib("r2", "show bgp ipv6 vpn json", "r2/vpnv6_rib_locator_deleted.json") - check_ping4("ce1", "192.168.2.2", False) - check_ping6("ce1", "2001:2::2", False) + check_ping("ce1", "192.168.2.2", False, 10, 0.5) + check_ping("ce1", "2001:2::2", False, 10, 1) def test_bgp_locator_reset(): - check_ping4("ce1", "192.168.2.2", False) - check_ping6("ce1", "2001:2::2", False) + check_ping("ce1", "192.168.2.2", False, 10, 0.5) + check_ping("ce1", "2001:2::2", False, 10, 1) get_topogen().gears["r1"].vtysh_cmd( """ configure terminal @@ -322,13 +291,13 @@ def test_bgp_locator_reset(): check_rib("r2", "show bgp ipv4 vpn json", "r2/vpnv4_rib_locator_recreated.json") check_rib("r1", "show bgp ipv6 vpn json", "r1/vpnv6_rib_locator_recreated.json") check_rib("r2", "show bgp ipv6 vpn json", "r2/vpnv6_rib_locator_recreated.json") - check_ping4("ce1", "192.168.2.2", True) - check_ping6("ce1", "2001:2::2", True) + check_ping("ce1", "192.168.2.2", True, 10, 0.5) + check_ping("ce1", "2001:2::2", True, 10, 1) def test_bgp_srv6_unset(): - check_ping4("ce1", "192.168.2.2", True) - check_ping6("ce1", "2001:2::2", True) + check_ping("ce1", "192.168.2.2", True, 10, 0.5) + check_ping("ce1", "2001:2::2", True, 10, 1) get_topogen().gears["r1"].vtysh_cmd( """ configure terminal @@ -340,13 +309,13 @@ def test_bgp_srv6_unset(): check_rib("r2", "show bgp ipv4 vpn json", "r2/vpnv4_rib_locator_deleted.json") check_rib("r1", "show bgp ipv6 vpn json", "r1/vpnv6_rib_locator_deleted.json") check_rib("r2", "show bgp ipv6 vpn json", "r2/vpnv6_rib_locator_deleted.json") - check_ping4("ce1", "192.168.2.2", False) - check_ping6("ce1", "2001:2::2", False) + check_ping("ce1", "192.168.2.2", False, 10, 0.5) + check_ping("ce1", "2001:2::2", False, 10, 1) def test_bgp_srv6_reset(): - check_ping4("ce1", "192.168.2.2", False) - check_ping6("ce1", "2001:2::2", False) + check_ping("ce1", "192.168.2.2", False, 10, 0.5) + check_ping("ce1", "2001:2::2", False, 10, 1) get_topogen().gears["r1"].vtysh_cmd( """ configure terminal @@ -359,8 +328,8 @@ def test_bgp_srv6_reset(): check_rib("r2", "show bgp ipv4 vpn json", "r2/vpnv4_rib_locator_recreated.json") check_rib("r1", "show bgp ipv6 vpn json", "r1/vpnv6_rib_locator_recreated.json") check_rib("r2", "show bgp ipv6 vpn json", "r2/vpnv6_rib_locator_recreated.json") - check_ping4("ce1", "192.168.2.2", True) - check_ping6("ce1", "2001:2::2", True) + check_ping("ce1", "192.168.2.2", True, 10, 0.5) + check_ping("ce1", "2001:2::2", True, 10, 1) if __name__ == "__main__": diff --git a/tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py b/tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py index ef9200b197..fd8a78b485 100644 --- a/tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py +++ b/tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py @@ -94,7 +94,6 @@ def test_bgp_route(): expected, ) _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) - assertmsg = '"r3" JSON output mismatches' assert result is None, assertmsg json_file = "{}/r3/v4_route3.json".format(CWD) @@ -103,10 +102,11 @@ def test_bgp_route(): test_func = partial( topotest.router_json_cmp, r3, - "show ip route 10.0.0.3 json", + "show ip route 60.0.0.0 json", expected, ) _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert result is None, assertmsg def test_bgp_better_admin_won(): diff --git a/tests/topotests/bgp_tcp_mss_passive/__init__.py b/tests/topotests/bgp_tcp_mss_passive/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/bgp_tcp_mss_passive/r1/frr.conf b/tests/topotests/bgp_tcp_mss_passive/r1/frr.conf new file mode 100644 index 0000000000..a0fcd52a18 --- /dev/null +++ b/tests/topotests/bgp_tcp_mss_passive/r1/frr.conf @@ -0,0 +1,12 @@ +! +interface r1-eth0 + ip address 192.168.1.1/24 +! +router bgp 65001 + no bgp ebgp-requires-policy + neighbor 192.168.1.2 remote-as external + neighbor 192.168.1.2 timers 1 3 + neighbor 192.168.1.2 timers connect 1 + neighbor 192.168.1.2 passive + neighbor 192.168.1.2 tcp-mss 300 +! diff --git a/tests/topotests/bgp_tcp_mss_passive/r2/frr.conf b/tests/topotests/bgp_tcp_mss_passive/r2/frr.conf new file mode 100644 index 0000000000..7213975cc0 --- /dev/null +++ b/tests/topotests/bgp_tcp_mss_passive/r2/frr.conf @@ -0,0 +1,10 @@ +! +interface r2-eth0 + ip address 192.168.1.2/24 +! +router bgp 65002 + no bgp ebgp-requires-policy + neighbor 192.168.1.1 remote-as external + neighbor 192.168.1.1 timers 1 3 + neighbor 192.168.1.1 timers connect 1 +! diff --git a/tests/topotests/bgp_tcp_mss_passive/test_bgp_tcp_mss_passive.py b/tests/topotests/bgp_tcp_mss_passive/test_bgp_tcp_mss_passive.py new file mode 100644 index 0000000000..cd405f7b22 --- /dev/null +++ b/tests/topotests/bgp_tcp_mss_passive/test_bgp_tcp_mss_passive.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# +# Copyright (c) 2023 by +# Donatas Abraitis <donatas@opensourcerouting.org> +# + +""" +Test if TCP MSS is synced with passive neighbor. +""" + +import os +import sys +import json +import pytest +import functools + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen + +pytestmark = [pytest.mark.bgpd] + + +def build_topo(tgen): + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + +def setup_module(mod): + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for i, (rname, router) in enumerate(router_list.items(), 1): + router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname))) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_tcp_mss_passive(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + def _bgp_check_tcp_mss_configured(router, neighbor, mss): + output = json.loads(router.vtysh_cmd("show bgp neighbors json")) + expected = { + neighbor: { + "bgpTcpMssConfigured": mss, + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_check_tcp_mss_configured, tgen.gears["r1"], "192.168.1.2", 300 + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "r1 is not configured with TCP MSS 300" + + test_func = functools.partial( + _bgp_check_tcp_mss_configured, tgen.gears["r2"], "192.168.1.1", 0 + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "r2 is not configured with the default TCP MSS (1500)" + + def _bgp_check_tcp_mss_synced(router, neighbor, mss): + output = json.loads(router.vtysh_cmd("show bgp neighbors json")) + expected = { + neighbor: { + "bgpTcpMssSynced": mss, + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_check_tcp_mss_synced, tgen.gears["r1"], "192.168.1.2", 288 + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "r1 is not synced with TCP MSS 300" + + test_func = functools.partial( + _bgp_check_tcp_mss_synced, tgen.gears["r2"], "192.168.1.1", 288 + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "r2 is not synced with the default TCP MSS (1488)" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_unique_rid/test_bgp_unique_rid.py b/tests/topotests/bgp_unique_rid/test_bgp_unique_rid.py index f89f3378fb..9fbcdc26fe 100644 --- a/tests/topotests/bgp_unique_rid/test_bgp_unique_rid.py +++ b/tests/topotests/bgp_unique_rid/test_bgp_unique_rid.py @@ -83,6 +83,7 @@ create_router_bgp, clear_bgp_and_verify, ) +from lib.ospf import verify_ospf_neighbor, clear_ospf # Global variables topo = None @@ -886,6 +887,154 @@ def test_bgp_unique_rid_chaos4_p2(): write_test_footer(tc_name) +def test_bgp_unique_rid_chaos2_p2(): + """ + TC: 8 + 8. Chaos - Verify bgp unique rid functionality when ospf and bgp share the same router ids. + + """ + tgen = get_topogen() + global bgp_convergence + + if bgp_convergence is not True: + pytest.skip("skipped because of BGP Convergence failure") + + # test case name + tc_name = inspect.stack()[0][3] + write_test_header(tc_name) + if tgen.routers_have_failure(): + check_router_status(tgen) + + step("Configure base config as per the topology") + step("Redistribute routes between bgp and ospf.") + reset_config_on_routers(tgen) + + step( + "Base config should be up, verify using BGP convergence on all \ + the routers for IPv4 and IPv6 nbrs" + ) + + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + ospf_covergence = verify_ospf_neighbor(tgen, topo, dut="r3") + assert ospf_covergence is True, "Testcase :Failed \n Error:" " {}".format( + ospf_covergence + ) + + step( + "Configure ospf between R3 and R4 with same router ids in both ospf and bgp 10.10.10.10 on R3 BGP and OSPF, and 10.10.10.10 in R4 BGP and 11.11.11.11 in R4 OSPF." + ) + input_dict = { + "r3": {"bgp": {"router_id": "10.10.10.10"}}, + "r4": {"bgp": {"router_id": "10.10.10.10"}}, + "r5": {"bgp": {"router_id": "10.10.10.10"}}, + } + result = create_router_bgp(tgen, topo, input_dict) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step( + "The session should be established between R3 & R4 between BGP process and neighborship should be full between OSPF too." + ) + + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + ospf_covergence = verify_ospf_neighbor(tgen, topo, dut="r3") + assert ospf_covergence is True, "Testcase :Failed \n Error:" " {}".format( + ospf_covergence + ) + + step("All the routes should be calculated and installed.") + # Verifying RIB routes + protocol = "bgp" + input_dict = topo["routers"] + verify_rib_rtes = { + "ipv4": { + "r3": { + "static_routes": [ + {"network": NETWORK["ipv4"], "next_hop": "Null0"}, + ] + } + }, + "ipv6": { + "r3": { + "static_routes": [ + { + "network": NETWORK["ipv6"], + "next_hop": "Null0", + } + ] + } + }, + } + dut = "r3" + for addr_type in ADDR_TYPES: + result4 = verify_rib( + tgen, + addr_type, + dut, + verify_rib_rtes, + protocol=protocol, + ) + assert result4 is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result4 + ) + + step("Clear ospf process.") + clear_ospf(tgen, "r3") + + step("All the routes should be calculated and installed.") + for addr_type in ADDR_TYPES: + result4 = verify_rib( + tgen, + addr_type, + dut, + verify_rib_rtes, + protocol=protocol, + ) + assert result4 is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result4 + ) + + step("Clear bgp process.") + clear_bgp_and_verify(tgen, topo, "r3") + + step("All the routes should be calculated and installed.") + for addr_type in ADDR_TYPES: + result4 = verify_rib( + tgen, + addr_type, + dut, + verify_rib_rtes, + protocol=protocol, + ) + assert result4 is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result4 + ) + + step( + "Configure ospf between R3 and R5. Configure static routes in R5 and redistribute static routes in ospf on R5." + ) + # Covered as base config. + + step("Verify routes are installed in R3 and R4 route tables.") + dut = "r4" + for addr_type in ADDR_TYPES: + result4 = verify_rib( + tgen, + addr_type, + dut, + verify_rib_rtes, + protocol=protocol, + ) + assert result4 is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result4 + ) + + write_test_footer(tc_name) + + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_update_delay/r2/zebra.conf b/tests/topotests/bgp_update_delay/r2/zebra.conf index 420f00d974..1fcedaaf72 100644 --- a/tests/topotests/bgp_update_delay/r2/zebra.conf +++ b/tests/topotests/bgp_update_delay/r2/zebra.conf @@ -12,9 +12,5 @@ interface r2-eth3 ip address 192.168.252.1/30 vrf vrf1 ! -auto vrf1 -iface vrf1 - vrf-table auto -! ip forwarding ! diff --git a/tests/topotests/bgp_vpn_5549_route_map/test_bgp_vpn_5549_route_map.py b/tests/topotests/bgp_vpn_5549_route_map/test_bgp_vpn_5549_route_map.py index 533af19d93..eb29875d50 100644 --- a/tests/topotests/bgp_vpn_5549_route_map/test_bgp_vpn_5549_route_map.py +++ b/tests/topotests/bgp_vpn_5549_route_map/test_bgp_vpn_5549_route_map.py @@ -115,10 +115,56 @@ def _bgp_vpn_nexthop_changed(): } return topotest.json_cmp(output, expected) + def _bgp_verify_v4_nexthop_validity(): + output = json.loads(tgen.gears["cpe1"].vtysh_cmd("show bgp nexthop json")) + expected = { + "ipv4": { + "192.168.1.2": { + "valid": True, + "complete": True, + "igpMetric": 0, + "pathCount": 0, + "nexthops": [{"interfaceName": "cpe1-eth0"}], + }, + } + } + return topotest.json_cmp(output, expected) + + def _bgp_verify_v6_global_nexthop_validity(): + output = json.loads(tgen.gears["pe2"].vtysh_cmd("show bgp nexthop json")) + expected = { + "ipv6": { + "2001:db8::1": { + "valid": True, + "complete": True, + "igpMetric": 0, + "pathCount": 2, + "nexthops": [{"interfaceName": "pe2-eth0"}], + }, + "2001:db8:1::1": { + "valid": True, + "complete": True, + "igpMetric": 10, + "pathCount": 2, + "peer": "2001:db8:1::1", + "nexthops": [{"interfaceName": "pe2-eth0"}], + }, + } + } + return topotest.json_cmp(output, expected) + test_func = functools.partial(_bgp_vpn_nexthop_changed) _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) assert result is None, "Failed overriding IPv6 next-hop for VPN underlay" + test_func = functools.partial(_bgp_verify_v4_nexthop_validity) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "IPv4 nexthop is invalid" + + test_func = functools.partial(_bgp_verify_v6_global_nexthop_validity) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "IPv6 nexthop is invalid" + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] diff --git a/tests/topotests/bgp_vpnv4_asbr/__init__.py b/tests/topotests/bgp_vpnv4_asbr/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/bgp_vpnv4_asbr/h1/zebra.conf b/tests/topotests/bgp_vpnv4_asbr/h1/zebra.conf new file mode 100644 index 0000000000..22372242d3 --- /dev/null +++ b/tests/topotests/bgp_vpnv4_asbr/h1/zebra.conf @@ -0,0 +1,7 @@ +log stdout +ip route 172.31.1.0/24 172.31.0.1 +ip route 172.31.2.0/24 172.31.0.1 +interface h1-eth0 + ip address 172.31.0.10/24 +! + diff --git a/tests/topotests/bgp_vpnv4_asbr/h2/zebra.conf b/tests/topotests/bgp_vpnv4_asbr/h2/zebra.conf new file mode 100644 index 0000000000..d650bc831a --- /dev/null +++ b/tests/topotests/bgp_vpnv4_asbr/h2/zebra.conf @@ -0,0 +1,6 @@ +log stdout +ip route 172.31.0.0/24 172.31.1.1 +interface h2-eth0 + ip address 172.31.1.10/24 +! + diff --git a/tests/topotests/bgp_vpnv4_asbr/h3/zebra.conf b/tests/topotests/bgp_vpnv4_asbr/h3/zebra.conf new file mode 100644 index 0000000000..5676485849 --- /dev/null +++ b/tests/topotests/bgp_vpnv4_asbr/h3/zebra.conf @@ -0,0 +1,6 @@ +log stdout +ip route 172.31.0.0/24 172.31.2.1 +interface h3-eth0 + ip address 172.31.2.10/24 +! + diff --git a/tests/topotests/bgp_vpnv4_asbr/r1/bgp_ipv4_routes.json b/tests/topotests/bgp_vpnv4_asbr/r1/bgp_ipv4_routes.json new file mode 100644 index 0000000000..184ab312b6 --- /dev/null +++ b/tests/topotests/bgp_vpnv4_asbr/r1/bgp_ipv4_routes.json @@ -0,0 +1,49 @@ +{ + "vrfName": "vrf1", + "localAS": 65500, + "routes": + { + "172.31.0.10/32": [ + { + "prefix": "172.31.0.10", + "prefixLen": 32, + "network": "172.31.0.10\/32", + "nhVrfName": "default", + "nexthops": [ + { + "ip": "192.168.0.3", + "afi": "ipv4", + "used": true + } + ] + }, + { + "prefix": "172.31.0.10", + "prefixLen": 32, + "network": "172.31.0.10\/32", + "nhVrfName": "default", + "nexthops": [ + { + "ip": "192.168.0.2", + "afi": "ipv4", + "used": true + } + ] + } + ], + "172.31.0.1/32": [ + { + "prefix": "172.31.0.1", + "prefixLen": 32, + "network": "172.31.0.1\/32", + "nexthops": [ + { + "ip": "0.0.0.0", + "afi": "ipv4", + "used": true + } + ] + } + ] + } +} diff --git a/tests/topotests/bgp_vpnv4_asbr/r1/bgpd.conf b/tests/topotests/bgp_vpnv4_asbr/r1/bgpd.conf new file mode 100644 index 0000000000..473e56b32a --- /dev/null +++ b/tests/topotests/bgp_vpnv4_asbr/r1/bgpd.conf @@ -0,0 +1,30 @@ +router bgp 65500 + bgp router-id 192.0.2.1 + no bgp ebgp-requires-policy + no bgp enforce-first-as + neighbor 192.0.2.100 remote-as 65500 + neighbor 192.0.2.100 update-source lo + neighbor 192.168.0.100 remote-as 65500 + address-family ipv4 unicast + no neighbor 192.168.0.100 activate + no neighbor 192.0.2.100 activate + network 192.0.2.1/32 + exit-address-family + address-family ipv4 labeled-unicast + neighbor 192.168.0.100 activate + exit-address-family + address-family ipv4 vpn + neighbor 192.0.2.100 activate + exit-address-family +! +router bgp 65500 vrf vrf1 + bgp router-id 192.0.2.1 + address-family ipv4 unicast + redistribute connected + label vpn export 101 + rd vpn export 444:1 + rt vpn both 52:100 + export vpn + import vpn + exit-address-family +! diff --git a/tests/topotests/bgp_vpnv4_asbr/r1/zebra.conf b/tests/topotests/bgp_vpnv4_asbr/r1/zebra.conf new file mode 100644 index 0000000000..2f12b722b8 --- /dev/null +++ b/tests/topotests/bgp_vpnv4_asbr/r1/zebra.conf @@ -0,0 +1,10 @@ +log stdout +interface lo + ip address 192.0.2.1/32 +! +interface r1-eth1 vrf vrf1 + ip address 172.31.0.1/24 +! +interface r1-eth0 + ip address 192.168.0.1/24 +! diff --git a/tests/topotests/bgp_vpnv4_asbr/r2/bgpd.conf b/tests/topotests/bgp_vpnv4_asbr/r2/bgpd.conf new file mode 100644 index 0000000000..c7244c0e1f --- /dev/null +++ b/tests/topotests/bgp_vpnv4_asbr/r2/bgpd.conf @@ -0,0 +1,32 @@ +!debug bgp nht +!debug bgp zebra +!debug bgp labelpool +router bgp 65500 + bgp router-id 192.0.2.2 + no bgp ebgp-requires-policy + no bgp enforce-first-as + neighbor 192.0.2.100 remote-as 65500 + neighbor 192.0.2.100 update-source lo + neighbor 192.168.0.100 remote-as 65500 + neighbor 192.168.1.200 remote-as 65502 + address-family ipv4 unicast + no neighbor 192.168.0.100 activate + no neighbor 192.168.1.200 activate + network 192.0.2.2/32 + exit-address-family + address-family ipv4 labeled-unicast + neighbor 192.168.0.100 activate + exit-address-family + address-family ipv4 vpn + neighbor 192.0.2.100 activate + neighbor 192.0.2.100 next-hop-self + neighbor 192.168.1.200 activate + exit-address-family +! +interface r2-eth1 + mpls bgp forwarding + mpls bgp l3vpn-multi-domain-switching +! +interface r2-eth0 + mpls bgp l3vpn-multi-domain-switching +! diff --git a/tests/topotests/bgp_vpnv4_asbr/r2/ipv4_vpn_summary.json b/tests/topotests/bgp_vpnv4_asbr/r2/ipv4_vpn_summary.json new file mode 100644 index 0000000000..d33c5f5691 --- /dev/null +++ b/tests/topotests/bgp_vpnv4_asbr/r2/ipv4_vpn_summary.json @@ -0,0 +1,24 @@ +{ + "routerId":"192.0.2.2", + "as":65500, + "vrfId":0, + "vrfName":"default", + "peerCount":2, + "peers":{ + "192.0.2.100":{ + "remoteAs":65500, + "localAs":65500, + "version":4, + "state":"Established", + "peerState":"OK" + }, + "192.168.1.200":{ + "remoteAs":65502, + "localAs":65500, + "version":4, + "state":"Established", + "peerState":"OK" + } + }, + "totalPeers":2 +} diff --git a/tests/topotests/bgp_vpnv4_asbr/r2/zebra.conf b/tests/topotests/bgp_vpnv4_asbr/r2/zebra.conf new file mode 100644 index 0000000000..43508a4c6a --- /dev/null +++ b/tests/topotests/bgp_vpnv4_asbr/r2/zebra.conf @@ -0,0 +1,13 @@ +log stdout +ip route 192.168.1.3/32 r2-eth1 +interface lo + ip address 192.0.2.2/32 +! +interface r2-eth0 + ip address 192.168.0.2/24 + mpls enable +! +interface r2-eth1 + ip address 192.168.1.2/24 + mpls enable +! diff --git a/tests/topotests/bgp_vpnv4_asbr/r3/bgpd.conf b/tests/topotests/bgp_vpnv4_asbr/r3/bgpd.conf new file mode 100644 index 0000000000..b7592e444d --- /dev/null +++ b/tests/topotests/bgp_vpnv4_asbr/r3/bgpd.conf @@ -0,0 +1,26 @@ +router bgp 65501 + bgp router-id 192.0.2.3 + no bgp ebgp-requires-policy + no bgp enforce-first-as + neighbor 192.168.1.200 remote-as 65502 + address-family ipv4 unicast + no neighbor 192.168.1.200 activate + exit-address-family + address-family ipv4 vpn + neighbor 192.168.1.200 activate + exit-address-family +! +router bgp 65501 vrf vrf1 + bgp router-id 192.0.2.3 + address-family ipv4 unicast + redistribute connected + label vpn export 102 + rd vpn export 444:3 + rt vpn both 52:100 + export vpn + import vpn + exit-address-family +! +interface r3-eth0 + mpls bgp forwarding +! diff --git a/tests/topotests/bgp_vpnv4_asbr/r3/zebra.conf b/tests/topotests/bgp_vpnv4_asbr/r3/zebra.conf new file mode 100644 index 0000000000..6376785f80 --- /dev/null +++ b/tests/topotests/bgp_vpnv4_asbr/r3/zebra.conf @@ -0,0 +1,14 @@ +log stdout +ip route 192.168.1.3/32 r3-eth0 +interface r3-eth1 vrf vrf1 + ip address 172.31.1.1/24 +! +interface r3-eth2 vrf vrf1 + ip address 172.31.2.1/24 +! +interface r3-eth3 vrf vrf1 + ip address 172.31.3.1/24 +! +interface r3-eth0 + ip address 192.168.1.3/24 +! diff --git a/tests/topotests/bgp_vpnv4_asbr/rr100/bgpd.conf b/tests/topotests/bgp_vpnv4_asbr/rr100/bgpd.conf new file mode 100644 index 0000000000..845d71bc7e --- /dev/null +++ b/tests/topotests/bgp_vpnv4_asbr/rr100/bgpd.conf @@ -0,0 +1,29 @@ +router bgp 65500 + bgp router-id 192.0.2.100 + no bgp ebgp-requires-policy + neighbor 192.0.2.2 remote-as 65500 + neighbor 192.0.2.2 update-source lo + neighbor 192.168.0.2 remote-as 65500 + neighbor 192.0.2.1 remote-as 65500 + neighbor 192.0.2.1 update-source lo + neighbor 192.168.0.1 remote-as 65500 + address-family ipv4 unicast + no neighbor 192.168.0.1 activate + no neighbor 192.0.2.1 activate + no neighbor 192.168.0.2 activate + no neighbor 192.0.2.2 activate + network 192.0.2.100/32 + exit-address-family + address-family ipv4 labeled-unicast + neighbor 192.168.0.1 activate + neighbor 192.168.0.2 activate + neighbor 192.168.0.1 route-reflector-client + neighbor 192.168.0.2 route-reflector-client + exit-address-family + address-family ipv4 vpn + neighbor 192.0.2.1 activate + neighbor 192.0.2.2 activate + neighbor 192.0.2.1 route-reflector-client + neighbor 192.0.2.2 route-reflector-client + exit-address-family +! diff --git a/tests/topotests/bgp_vpnv4_asbr/rr100/zebra.conf b/tests/topotests/bgp_vpnv4_asbr/rr100/zebra.conf new file mode 100644 index 0000000000..2fa5285182 --- /dev/null +++ b/tests/topotests/bgp_vpnv4_asbr/rr100/zebra.conf @@ -0,0 +1,7 @@ +log stdout +interface lo + ip address 192.0.2.100/32 +! +interface rr100-eth0 + ip address 192.168.0.100/24 +! diff --git a/tests/topotests/bgp_vpnv4_asbr/rs200/bgpd.conf b/tests/topotests/bgp_vpnv4_asbr/rs200/bgpd.conf new file mode 100644 index 0000000000..fa3cb54228 --- /dev/null +++ b/tests/topotests/bgp_vpnv4_asbr/rs200/bgpd.conf @@ -0,0 +1,19 @@ +debug bgp nht +debug bgp zebra +debug bgp labelpool +router bgp 65502 + bgp router-id 192.0.2.200 + no bgp ebgp-requires-policy + neighbor 192.168.1.3 remote-as 65501 + neighbor 192.168.1.2 remote-as 65500 + address-family ipv4 unicast + no neighbor 192.168.1.2 activate + no neighbor 192.168.1.3 activate + exit-address-family + address-family ipv4 vpn + neighbor 192.168.1.3 activate + neighbor 192.168.1.2 activate + neighbor 192.168.1.3 route-server-client + neighbor 192.168.1.2 route-server-client + exit-address-family +! \ No newline at end of file diff --git a/tests/topotests/bgp_vpnv4_asbr/rs200/zebra.conf b/tests/topotests/bgp_vpnv4_asbr/rs200/zebra.conf new file mode 100644 index 0000000000..98793ca003 --- /dev/null +++ b/tests/topotests/bgp_vpnv4_asbr/rs200/zebra.conf @@ -0,0 +1,4 @@ +log stdout +interface rs200-eth0 + ip address 192.168.1.200/24 +! diff --git a/tests/topotests/bgp_vpnv4_asbr/test_bgp_vpnv4_asbr.py b/tests/topotests/bgp_vpnv4_asbr/test_bgp_vpnv4_asbr.py new file mode 100644 index 0000000000..39865eb189 --- /dev/null +++ b/tests/topotests/bgp_vpnv4_asbr/test_bgp_vpnv4_asbr.py @@ -0,0 +1,865 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# +# test_bgp_vpnv4_asbr.py +# Part of NetDEF Topology Tests +# +# Copyright (c) 2023 by 6WIND +# + +""" + test_bgp_vpnv4_asbr.py: Test the FRR BGP daemon with rfc4364 option 10b + r1, r2, and r100 are in an iBGP AS, while r2, r3 do an eBGP peering + h1 is a host behind r1 VRF1, and {h2,h3} are hosts behind r3 VRF1 + The test demonstrates the connectivity across the network between h1 and h3. + + + +----------+ +----+--------+ +--------+ +--------+-----+ + | |172.31.0.0|vrf | r1 |192.168.0.0/24| r2 |192.168.1.0/24|r3 | vrf | + | h1 +----------+ | 1+------+-------+ +------+-------+3 | +--- 172.31.3.0/24 + | 10 | |VRF1|AS65500 | | | AS65500| | |AS65501 |VRF1 | + +----------+ +-------------+ | +--------+ | +--------+--+-++ + 192.0.2.1 | 192.0.2.2 | 172| | + +----------+ +----+--------+ 31| | + |rr100 | |rs200/AS65502| 1| | + +----------+ +-------------+ 0| | + 192.0.2.100 +--------+ /24| | + | | +----------+----+ | + |h3 | | | | + |10 | | h2 | | + +---+----+ | 10 | | + | +----------+ | + |172.31.2.0/24 | + +--------------------------------+ +""" + +import os +import sys +import json +from functools import partial +import pytest +import functools + +# Save the Current Working Directory to find configuration files. +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +# Import topogen and topotest helpers +from lib import topotest +from lib.bgpcheck import ( + check_show_bgp_vpn_prefix_found, + check_show_bgp_vpn_prefix_not_found, +) +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger +from lib.checkping import check_ping + + +# Required to instantiate the topology builder class. + + +pytestmark = [pytest.mark.bgpd] + + +def build_topo(tgen): + "Build function" + + # Allocate 8 devices + tgen.add_router("r1") + tgen.add_router("r2") + tgen.add_router("r3") + tgen.add_router("h1") + tgen.add_router("h2") + tgen.add_router("h3") + tgen.add_router("rr100") + tgen.add_router("rs200") + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["rr100"]) + + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["h1"]) + + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["rs200"]) + + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["h2"]) + + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["r3"]) + switch.add_link(tgen.gears["h3"]) + + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["r3"]) + + +def _populate_iface(): + tgen = get_topogen() + cmds_list = [ + "ip link add vrf1 type vrf table 10", + "echo 100000 > /proc/sys/net/mpls/platform_labels", + "ip link set dev vrf1 up", + "ip link set dev {0}-eth1 master vrf1", + "echo 1 > /proc/sys/net/mpls/conf/{0}-eth0/input", + ] + + for rname in ("r1", "r3"): + for cmd in cmds_list: + input = cmd.format(rname) + logger.info("input: " + cmd) + output = tgen.net[rname].cmd(cmd.format(rname)) + logger.info("output: " + output) + + cmds_list = [ + "ip link set dev {0}-eth2 master vrf1", + "ip link set dev {0}-eth3 master vrf1", + ] + for cmd in cmds_list: + input = cmd.format("r3") + logger.info("input: " + input) + output = tgen.net["r3"].cmd(input) + logger.info("output: " + output) + + +def setup_module(mod): + "Sets up the pytest environment" + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + _populate_iface() + + for rname, router in router_list.items(): + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + if rname in ("r1", "r2", "r3", "rr100", "rs200"): + router.load_config( + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) + ) + + # Initialize all routers. + tgen.start_router() + + +def teardown_module(_mod): + "Teardown the pytest environment" + tgen = get_topogen() + + tgen.stop_topology() + + +def bgp_vpnv4_prefix_check(router, rd, prefix, label, nexthop): + """ + Dump and check 'show bgp ipv4 vpn <prefix> json' output. An assert is triggered in case test fails + * 'router': the router to check + * 'rd': The route distinguisher expected + * 'prefix': The prefix expected + * 'label': The label expected associated with the ('rd','prefix') tuple + * 'nexthop': The nexthop expected associated with the ('rd','prefix') tuple + """ + + def _check(router, prefix, rd, label, nexthop): + dump = router.vtysh_cmd("show bgp ipv4 vpn {} json".format(prefix), isjson=True) + if not dump: + return "{0}, {1}, route distinguisher {2} not present".format( + router.name, prefix, rd + ) + for dumped_rd, pathes in dump.items(): + if dumped_rd != rd: + continue + for path in pathes["paths"]: + if "remoteLabel" not in path.keys(): + return "{0}, {1}, rd {2}, remoteLabel not present".format( + router.name, prefix, rd + ) + if str(path["remoteLabel"]) != label: + continue + + if "nexthops" not in path.keys(): + return "{0}, {1}, rd {2}, no nexthops present".format( + router.name, prefix, rd + ) + + for nh in path["nexthops"]: + if "ip" not in nh.keys(): + return "{0}, {1}, rd {2}, no ipv4 nexthop available".format( + router.name, prefix, rd + ) + if nh["ip"] != nexthop: + continue + return None + return "{0}, {1}, rd {2}, remoteLabel {3}, nexthop {4} not found".format( + router.name, prefix, rd, label, nexthop + ) + + func = functools.partial(_check, router, prefix, rd, label, nexthop) + success, result = topotest.run_and_expect(func, None, count=20, wait=0.5) + assert_msg = "{}, show bgp ipv4 vpn {}, rd {}, label {} nexthop {}".format( + router.name, prefix, rd, label, nexthop + ) + assert result is None, assert_msg + " not found" + logger.info(assert_msg + " found") + + +def mpls_table_get_entry(router, out_label, out_nexthop): + """ + Get the in_label from tuple (out_label, out_nexthop) + * 'router': the router to check + * 'out_label': The outgoing label expected + * 'out_nexthop': The outgoing nexthop expected + """ + dump = router.vtysh_cmd("show mpls table json", isjson=True) + for in_label, label_info in dump.items(): + for nh in label_info["nexthops"]: + if nh["type"] != "BGP" or "installed" not in nh.keys(): + continue + if "nexthop" in nh.keys(): + if nh["nexthop"] != out_nexthop: + continue + if "outLabelStack" in nh.keys(): + if out_label not in nh["outLabelStack"]: + continue + return in_label + return None + + +def mpls_table_check_entry(router, out_label, out_nexthop): + """ + Dump and check 'show mpls table json' output. An assert is triggered in case test fails + * 'router': the router to check + * 'out_label': The outgoing label expected + * 'out_nexthop': The outgoing nexthop expected + """ + logger.info("Checking MPLS labels on {}".format(router.name)) + dump = router.vtysh_cmd("show mpls table json", isjson=True) + for in_label, label_info in dump.items(): + for nh in label_info["nexthops"]: + if nh["type"] != "BGP" or "installed" not in nh.keys(): + continue + if "nexthop" in nh.keys(): + if nh["nexthop"] != out_nexthop: + continue + if "outLabelStack" in nh.keys(): + if out_label not in nh["outLabelStack"]: + continue + logger.info( + "{}, show mpls table, entry in_label {} out_label {} out_nexthop {} found".format( + router.name, in_label, nh["outLabelStack"], nh["nexthop"] + ) + ) + return None + return "{}, show mpls table, entry matching in_label {} out_label {} out_nexthop {} not found".format( + router.name, in_label, out_label, out_nexthop + ) + + +def check_show_mpls_table_entry_label_not_found(router, inlabel): + output = json.loads(router.vtysh_cmd("show mpls table {} json".format(inlabel))) + expected = {"inLabel": inlabel, "installed": True} + ret = topotest.json_cmp(output, expected) + if ret is None: + return "not good" + return None + + +def check_show_bgp_vpn_ok(router, vpnv4_entries): + """ + Check on router that BGP l3vpn entries are present + Check there is an MPLS entry bound to that BGP L3VPN entry + Extract the Label value and check on the distributed router the BGP L3VPN entry + If check fail, an assert is triggered. + * 'router': the router to check BGP VPN RIB + * 'vpnv4_entries': dictionary that contains the list of prefixes, and the distributed router to look after + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + vpnv4_nexthops = {"r1": "192.0.2.2", "r3": "192.168.1.2"} + vpnv4_nht = {"192.0.2.1": "192.168.0.1", "192.168.1.3": "192.168.1.3"} + label_ip_entries = {} + + def _return_remote_label_nh_rd(router, prefix): + dump = router.vtysh_cmd("show bgp ipv4 vpn {} json".format(prefix), isjson=True) + assert_msg = ( + "{}, prefix {} not available or label not found", + router.name, + prefix, + ) + assert dump, assert_msg + for rd, pathes in dump.items(): + for path in pathes["paths"]: + if "remoteLabel" not in path.keys(): + assert 0, assert_msg + for nh in path["nexthops"]: + if "ip" in nh.keys(): + return path["remoteLabel"], nh["ip"], rd + assert 0, assert_msg + + def _check_nexthop_available(router, prefix): + dump = router.vtysh_cmd("show bgp ipv4 vpn {} json".format(prefix), isjson=True) + if not dump: + return "{0}, {1}, route distinguisher not present".format( + router.name, prefix + ) + for rd, pathes in dump.items(): + for path in pathes["paths"]: + if "remoteLabel" not in path.keys(): + return "{0}, {1}, remoteLabel not present".format( + router.name, prefix + ) + if "nexthops" not in path.keys(): + return "{0}, {1}, no nexthop available".format(router.name, prefix) + return None + + for prefix, rname_to_test in vpnv4_entries.items(): + func = functools.partial(_check_nexthop_available, router, prefix) + success, result = topotest.run_and_expect(func, None, count=20, wait=0.5) + assert result is None, "Failed to detect prefix {} on router {}".format( + prefix, router.name + ) + + for prefix, rname_to_test in vpnv4_entries.items(): + l3vpn_label, l3vpn_nh, l3vpn_rd = _return_remote_label_nh_rd(router, prefix) + logger.info( + "{0}, {1}, label value is {2}, nh is {3}".format( + router.name, prefix, l3vpn_label, l3vpn_nh + ) + ) + test_func = functools.partial( + mpls_table_check_entry, router, l3vpn_label, vpnv4_nht[l3vpn_nh] + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, result + + in_label = mpls_table_get_entry(router, l3vpn_label, vpnv4_nht[l3vpn_nh]) + label_ip_entries[prefix] = in_label + + bgp_vpnv4_prefix_check( + tgen.gears[rname_to_test], + l3vpn_rd, + prefix, + in_label, + vpnv4_nexthops[rname_to_test], + ) + + return label_ip_entries + + +def test_protocols_convergence(): + """ + Assert that all protocols have converged + Check that Labels are as expected in r1, r2,and r3 + Check ping connectivity between h1 and h2 + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + # check that r2 peerings are ok + logger.info("Checking BGP ipv4 vpn summary for r2") + router = tgen.gears["r2"] + json_file = "{}/{}/ipv4_vpn_summary.json".format(CWD, router.name) + expected = json.loads(open(json_file).read()) + test_func = partial( + topotest.router_json_cmp, + router, + "show bgp ipv4 vpn summary json", + expected, + ) + _, result = topotest.run_and_expect(test_func, None, count=20, wait=0.5) + assertmsg = '"{}" JSON output mismatches'.format(router.name) + assert result is None, assertmsg + + +def test_mpls_setup_ok(): + """ + tests for the r1 to r3 direction: checks for prefix=('172.31.1.0/24','172.31.2.0/24','172.31.3.0/24') + r2. get label from 'prefix' + check that r2. show mpls table has an entry with outbound label set to the label from 172.31.1.0/24 + r2. get label from mpls entry + check that r1: show bgp ipv4 vpn 172.31.1.0/24 has label from r2.mpls entry + tests for the r3 to r1 direction + r2. get label from 172.31.0.0/24 + check that r2. show mpls table has an entry with outbound label set that includes the label from 172.31.0.0/24 + r2. get label from mpls entry + check that r3: show bgp ipv4 vpn 172.31.0.0/24 has label from r2.mpls entry + check that h1. ping 172.31.1.10 (h2) is ok. + check that h1. ping 172.31.2.10 (h3) is ok. + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + router = tgen.gears["r2"] + + # diagnostic + logger.info("Dumping mplsvpn nexthop table") + router.vtysh_cmd("show bgp mplsvpn-nh-label-bind detail", isjson=False) + + vpnv4_checks = { + "172.31.1.0/24": "r1", + "172.31.2.0/24": "r1", + "172.31.3.0/24": "r1", + "172.31.0.0/24": "r3", + } + logger.info( + "{}, check that 'show bgp ipv4 vpn' and 'show mpls table' are set accordingly on all devices".format( + router.name + ) + ) + check_show_bgp_vpn_ok(router, vpnv4_checks) + + logger.info("h1, check that ping from h1 to (h2,h3) is ok") + check_ping("h1", "172.31.1.10", True, 20, 0.5) + check_ping("h1", "172.31.2.10", True, 20, 0.5) + + +def test_r3_prefixes_removed(): + """ + Remove BGP redistributed updates from r3. + Check that the BGP VPN updates from the updates are not present on r2. + Check that the 'show bgp ipv4 vpn' and 'show mpls table' are ok for 172.31.3.0/24 + Remove the 172.31.3.0/24 update from BGP on r3. + Check that the BGP VPN updates from r3 are not present on r2. + Check that the 'show mpls table' entry previously seen disappeared + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + router = tgen.gears["r3"] + logger.info("{}, keeping only 172.31.3.0/24 network".format(router.name)) + router.vtysh_cmd("configure terminal\ninterface r3-eth1 vrf vrf1\nshutdown\n") + router.vtysh_cmd("configure terminal\ninterface r3-eth2 vrf vrf1\nshutdown\n") + + router = tgen.gears["r2"] + logger.info( + "{}, check that 'show bgp ipv4 vpn' has only 172.31.3.0/24 network from r3".format( + router.name + ) + ) + + for prefix in ("172.31.1.0/24", "172.31.2.0/24"): + test_func = functools.partial( + check_show_bgp_vpn_prefix_not_found, + router, + "ipv4", + prefix, + "444:3", + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "{}, vpnv4 update {} still present".format(router.name, prefix) + + # diagnostic + logger.info("Dumping mplsvpn nexthop table") + router.vtysh_cmd("show bgp mplsvpn-nh-label-bind detail", isjson=False) + + prefix = "172.31.3.0/24" + logger.info( + "{}, check that 'show bgp ipv4 vpn' and 'show mpls table' are set accordingly on r2 and on r1".format( + router.name + ) + ) + vpnv4_checks = { + prefix: "r1", + } + label_ip_entries = check_show_bgp_vpn_ok(router, vpnv4_checks) + + router = tgen.gears["r3"] + logger.info("{}, removing {} network".format(router.name, prefix)) + router.vtysh_cmd("configure terminal\ninterface r3-eth3 vrf vrf1\nshutdown\n") + + router = tgen.gears["r2"] + logger.info( + "{}, check that 'show bgp ipv4 vpn' has not {} network from r3".format( + router.name, prefix + ) + ) + test_func = functools.partial( + check_show_bgp_vpn_prefix_not_found, + router, + "ipv4", + prefix, + "444:3", + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "{}, vpnv4 update {} still present".format(router.name, prefix) + + logger.info( + "{}, check that 'show mpls table {}' is not present".format( + router.name, label_ip_entries[prefix] + ) + ) + test_func = functools.partial( + check_show_mpls_table_entry_label_not_found, router, label_ip_entries[prefix] + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "r1, mpls entry with in_label {} still present".format( + label_ip_entries[prefix] + ) + + +def test_r3_prefixes_added_back(): + """ + Add back the 172.31.3.0/24 network from r3 + Check on r2 that MPLS switching entry appears when the 1st BGP update is received + Check the IP connectivity (h1,h2) and (h1,h3) + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + router = tgen.gears["r3"] + prefix = "172.31.3.0/24" + logger.info("{}, restoring the {} network from r3".format(router.name, prefix)) + router.vtysh_cmd("configure terminal\ninterface r3-eth3 vrf vrf1\nno shutdown\n") + + router = tgen.gears["r2"] + logger.info( + "{}, check that 'show bgp ipv4 vpn' has {} network from r3".format( + router.name, prefix + ) + ) + + test_func = functools.partial( + check_show_bgp_vpn_prefix_found, + router, + "ipv4", + prefix, + "444:3", + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "{}, vpnv4 update {} not present".format(router.name, prefix) + + logger.info( + "{}, check that 'show bgp ipv4 vpn' and 'show mpls table' are set accordingly on r2 and on r1".format( + router.name + ) + ) + vpnv4_checks = { + prefix: "r1", + } + check_show_bgp_vpn_ok(router, vpnv4_checks) + + router = tgen.gears["r3"] + logger.info( + "{}, restoring the redistribute connected prefixes from r3".format(router.name) + ) + router.vtysh_cmd("configure terminal\ninterface r3-eth1 vrf vrf1\nno shutdown\n") + router.vtysh_cmd("configure terminal\ninterface r3-eth2 vrf vrf1\nno shutdown\n") + router = tgen.gears["r2"] + for prefix in ("172.31.1.0/24", "172.31.2.0/24"): + test_func = functools.partial( + check_show_bgp_vpn_prefix_found, + router, + "ipv4", + prefix, + "444:3", + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "{}, vpnv4 update {} not present".format(router.name, prefix) + + # diagnostic + logger.info("Dumping mplsvpn nexthop table") + tgen.gears["r2"].vtysh_cmd("show bgp mplsvpn-nh-label-bind detail", isjson=False) + + +def test_unconfigure_nexthop_change_nexthop_self(): + """ + Get the list of labels advertised from r2 to r1 + On r2, disable next-hop-self for 192.0.2.100 neighbor + Check that the list of labels are not present in 'show mpls table' + Check that r1 received the prefixes with the original (next-hop,label) + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears["r2"] + vpnv4_checks = { + "172.31.1.0/24": "r1", + "172.31.2.0/24": "r1", + "172.31.3.0/24": "r1", + } + logger.info( + "{}, Get the list of labels allocated for prefixes from r3".format(router.name) + ) + label_ip_entries = check_show_bgp_vpn_ok(router, vpnv4_checks) + + logger.info( + "{}, disable next-hop-self for 192.0.2.100 neighbor".format(router.name) + ) + router = tgen.gears["r2"] + router.vtysh_cmd( + "configure terminal\nrouter bgp 65500\naddress-family ipv4 vpn\nno neighbor 192.0.2.100 next-hop-self\n" + ) + + for prefix, label in label_ip_entries.items(): + logger.info( + "{}, check mpls entry for {} with in_label {} is not present'".format( + router.name, prefix, label + ) + ) + test_func = functools.partial( + check_show_mpls_table_entry_label_not_found, router, label + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "r1, mpls entry for {} with in_label {} still present".format( + prefix, label + ) + + router = tgen.gears["r1"] + for prefix, label in label_ip_entries.items(): + test_func = functools.partial( + check_show_bgp_vpn_prefix_not_found, + router, + "ipv4", + prefix, + "444:3", + label=label, + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "{}, mpls vpn update {} label {} is present".format( + router.name, prefix, label + ) + for prefix, label in label_ip_entries.items(): + test_func = functools.partial( + check_show_bgp_vpn_prefix_found, + router, + "ipv4", + prefix, + "444:3", + nexthop="192.168.1.3", + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "{}, mpls vpn update {} label {} is present".format( + router.name, prefix, label + ) + + # diagnostic + logger.info("Dumping mplsvpn nexthop table") + tgen.gears["r2"].vtysh_cmd("show bgp mplsvpn-nh-label-bind detail", isjson=False) + + +def test_reconfigure_nexthop_change_nexthop_self(): + """ + Get the list of labels advertised from r2 to r1 + On r2, enable next-hop-self for 192.0.2.100 neighbor + Check that the list of labels are present in 'show mpls table' + Check that r1 received the prefixes with the original (next-hop,label) + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears["r2"] + logger.info("{}, enable next-hop-self for 192.0.2.100 neighbor".format(router.name)) + router.vtysh_cmd( + "configure terminal\nrouter bgp 65500\naddress-family ipv4 vpn\nneighbor 192.0.2.100 next-hop-self\n" + ) + vpnv4_checks = { + "172.31.1.0/24": "r1", + "172.31.2.0/24": "r1", + "172.31.3.0/24": "r1", + } + logger.info( + "{}, check that 'show bgp ipv4 vpn' and 'show mpls table' are set accordingly on r2 and on r1".format( + router.name + ) + ) + check_show_bgp_vpn_ok(router, vpnv4_checks) + + logger.info("h1, check that ping from h1 to (h2,h3) is ok") + check_ping("h1", "172.31.1.10", True, 20, 0.5) + check_ping("h1", "172.31.2.10", True, 20, 0.5) + # diagnostic + logger.info("Dumping mplsvpn nexthop table") + router.vtysh_cmd("show bgp mplsvpn-nh-label-bind detail", isjson=False) + + +def test_declare_vpn_network_with_different_label(): + """ + declare a vpnv4 network on r3. + check that a new VPNv4 entry is received on r2. + Check that the list of labels are present in 'show mpls table' + Check that r1 received the prefixes with the new (next-hop,label) + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears["r3"] + logger.info( + "{}, declare static 33.33.33.33/32 network rd 33:33 label 33".format( + router.name + ) + ) + router.vtysh_cmd( + "configure terminal\nrouter bgp 65501\nno bgp network import-check\n" + ) + router.vtysh_cmd( + "configure terminal\nrouter bgp 65501\naddress-family ipv4 vpn\nnetwork 33.33.33.33/32 rd 444:3 label 33\n" + ) + + router = tgen.gears["r2"] + vpnv4_entries = { + "172.31.1.0/24": None, + "172.31.2.0/24": None, + "172.31.3.0/24": None, + "33.33.33.33/32": 33, + } + + for prefix, label in vpnv4_entries.items(): + test_func = functools.partial( + check_show_bgp_vpn_prefix_found, + router, + "ipv4", + prefix, + "444:3", + label=label, + nexthop="192.168.1.3", + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "{}, vpnv4 update {}, label {} not present".format( + router.name, prefix, label + ) + + vpnv4_checks = { + "172.31.1.0/24": "r1", + "172.31.2.0/24": "r1", + "172.31.3.0/24": "r1", + "33.33.33.33/32": "r1", + } + logger.info( + "{}, check that 'show bgp ipv4 vpn' and 'show mpls table' are set accordingly on r2 and on r1".format( + router.name + ) + ) + check_show_bgp_vpn_ok(router, vpnv4_checks) + + +def test_filter_vpn_network_from_r1(): + """ + Get the list of labels in 'show mpls table' + filter network from r1 + check that the vpnv4 entry on r2 is not present + Check that the associated mpls entry is not present + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears["r2"] + + vpnv4_checks = { + "172.31.0.0/24": "r3", + } + logger.info( + "{}, check that 'show bgp ipv4 vpn' and 'show mpls table' are set accordingly on r2 and on r3".format( + router.name + ) + ) + label_ip_entries = check_show_bgp_vpn_ok(router, vpnv4_checks) + + for prefix, label in label_ip_entries.items(): + logger.info("{}, filter prefix {} from r1".format(router.name, prefix)) + router.vtysh_cmd( + "configure terminal\nroute-map rmap deny 1\nmatch ip next-hop address 192.0.2.1\n" + ) + router.vtysh_cmd( + "configure terminal\nrouter bgp 65500\naddress-family ipv4 vpn\nneighbor 192.0.2.100 route-map rmap in\n" + ) + logger.info( + "{}, check that prefix {} is not present".format(router.name, prefix) + ) + test_func = functools.partial( + check_show_bgp_vpn_prefix_not_found, + router, + "ipv4", + "172.31.0.0/24", + "444:1", + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "{}, vpnv4 update {}, is still present".format( + router.name, prefix + ) + + # diagnostic + logger.info("Dumping mplsvpn nexthop table") + router.vtysh_cmd("show bgp mplsvpn-nh-label-bind detail", isjson=False) + + logger.info( + "{}, check that show mpls table {} is not present".format( + router.name, label + ) + ) + test_func = functools.partial( + check_show_mpls_table_entry_label_not_found, router, int(label) + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "r1, mpls entry for {} with in_label {} still present".format( + prefix, label + ) + + +def test_unfilter_vpn_network_from_r1(): + """ + unfilter network from r1 + check that the vpnv4 entry on r2 is present + Check that the list of labels are present in 'show mpls table' + Check that r3 received the prefixes with the new (next-hop,label) + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears["r2"] + prefix = "172.31.0.0/24" + + logger.info("{}, filter prefix {} from r1".format(router.name, prefix)) + router.vtysh_cmd( + "configure terminal\nrouter bgp 65500\naddress-family ipv4 vpn\nno neighbor 192.0.2.100 route-map rmap in\n" + ) + + logger.info("{}, check that prefix {} is present".format(router.name, prefix)) + test_func = functools.partial( + check_show_bgp_vpn_prefix_found, router, "ipv4", prefix, "444:1" + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "{}, vpnv4 update {}, is not present".format(router.name, prefix) + + vpnv4_checks = { + "172.31.0.0/24": "r3", + } + logger.info( + "{}, check that 'show bgp ipv4 vpn' and 'show mpls table' are set accordingly on all devices".format( + router.name + ) + ) + check_show_bgp_vpn_ok(router, vpnv4_checks) + + # diagnostic + logger.info("Dumping mplsvpn nexthop table") + router.vtysh_cmd("show bgp mplsvpn-nh-label-bind detail", isjson=False) + + +def test_memory_leak(): + "Run the memory leak test and report results." + tgen = get_topogen() + if not tgen.is_memleak_enabled(): + pytest.skip("Memory leak test/report is disabled") + + tgen.report_memory_leaks() + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_vpnv4_ebgp/r1/bgpd.conf b/tests/topotests/bgp_vpnv4_ebgp/r1/bgpd.conf index 0249279c65..d8a45ce274 100644 --- a/tests/topotests/bgp_vpnv4_ebgp/r1/bgpd.conf +++ b/tests/topotests/bgp_vpnv4_ebgp/r1/bgpd.conf @@ -1,3 +1,4 @@ +bgp route-map delay-timer 1 router bgp 65500 bgp router-id 192.0.2.1 no bgp ebgp-requires-policy diff --git a/tests/topotests/bgp_vpnv4_ebgp/test_bgp_vpnv4_ebgp.py b/tests/topotests/bgp_vpnv4_ebgp/test_bgp_vpnv4_ebgp.py index 61e1163c18..8b2e674aad 100644 --- a/tests/topotests/bgp_vpnv4_ebgp/test_bgp_vpnv4_ebgp.py +++ b/tests/topotests/bgp_vpnv4_ebgp/test_bgp_vpnv4_ebgp.py @@ -25,6 +25,10 @@ # pylint: disable=C0413 # Import topogen and topotest helpers from lib import topotest +from lib.bgpcheck import ( + check_show_bgp_vpn_prefix_found, + check_show_bgp_vpn_prefix_not_found, +) from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger @@ -214,6 +218,164 @@ def test_protocols_convergence(): assert result is None, assertmsg +def test_export_route_target_empty(): + """ + Check that when removing 'rt vpn export' command, exported prefix is removed + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + router = tgen.gears["r1"] + logger.info("r1, Remove 'rt vpn export 52:100' command") + router.vtysh_cmd( + "configure terminal\nrouter bgp 65500 vrf vrf1\naddress-family ipv4 unicast\nno rt vpn export 52:100\n" + ) + + prefix = "172.31.0.1/32" + logger.info("r1, check that exported prefix {} is removed".format(prefix)) + test_func = partial( + check_show_bgp_vpn_prefix_not_found, + router, + "ipv4", + prefix, + "444:1", + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "{}, vpnv4 update {} still present".format(router.name, prefix) + + +def test_export_route_target_with_routemap_with_export_route_target(): + """ + Check that when removing 'rt vpn export' command, exported prefix is added back + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + router = tgen.gears["r1"] + logger.info("r1, configuring route target with route-map with export route target") + router.vtysh_cmd( + "configure terminal\nrouter bgp 65500 vrf vrf1\naddress-family ipv4 unicast\nroute-map vpn export rmap\n" + ) + router.vtysh_cmd( + "configure terminal\nroute-map rmap permit 1\nset extcommunity rt 52:100\n" + ) + + prefix = "172.31.0.1/32" + logger.info("r1, check that exported prefix {} is added back".format(prefix)) + test_func = partial( + check_show_bgp_vpn_prefix_found, + router, + "ipv4", + prefix, + "444:1", + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "{}, vpnv4 update {} still not present".format(router.name, prefix) + + +def test_export_route_target_with_routemap_without_export_route_target(): + """ + Check that when removing 'set extcommunity rt' command, prefix is removed + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + router = tgen.gears["r1"] + logger.info("r1, removing 'set extcommunity rt 52:100.") + router.vtysh_cmd( + "configure terminal\nroute-map rmap permit 1\nno set extcommunity rt\n" + ) + + prefix = "172.31.0.1/32" + logger.info("r1, check that exported prefix {} is removed".format(prefix)) + test_func = partial( + check_show_bgp_vpn_prefix_not_found, + router, + "ipv4", + prefix, + "444:1", + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "{}, vpnv4 update {} still present".format(router.name, prefix) + + +def test_export_route_target_with_default_command(): + """ + Add back route target with 'rt vpn export' command + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + router = tgen.gears["r1"] + logger.info("r1, detach route-map and re-add route target vpn export") + router.vtysh_cmd( + "configure terminal\nrouter bgp 65500 vrf vrf1\naddress-family ipv4 unicast\nrt vpn export 52:100\n" + ) + prefix = "172.31.0.1/32" + logger.info("r1, check that exported prefix {} is added back".format(prefix)) + test_func = partial( + check_show_bgp_vpn_prefix_found, + router, + "ipv4", + prefix, + "444:1", + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "{}, vpnv4 update {} still not present".format(router.name, prefix) + + +def test_export_suppress_route_target_with_route_map_command(): + """ + Add back route target with 'rt vpn export' command + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + router = tgen.gears["r1"] + logger.info("r1, add an extended comm-list to delete 52:100") + + router.vtysh_cmd("configure terminal\nbgp extcommunity-list 1 permit rt 52:100\n") + router.vtysh_cmd( + "configure terminal\nroute-map rmap permit 1\nset extended-comm-list 1 delete\n" + ) + prefix = "172.31.0.1/32" + logger.info("r1, check that exported prefix {} is removed".format(prefix)) + test_func = partial( + check_show_bgp_vpn_prefix_not_found, + router, + "ipv4", + prefix, + "444:1", + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "{}, vpnv4 update {} still present".format(router.name, prefix) + + +def test_export_add_route_target_to_route_map_command(): + """ + Add route target with route-map so that route is added back + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + router = tgen.gears["r1"] + logger.info("r1, add an additional set extcommunity 52:101") + router.vtysh_cmd( + "configure terminal\nroute-map rmap permit 1\nset extcommunity rt 52:101\n" + ) + prefix = "172.31.0.1/32" + logger.info("r1, check that exported prefix {} is added back".format(prefix)) + test_func = partial( + check_show_bgp_vpn_prefix_found, + router, + "ipv4", + prefix, + "444:1", + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "{}, vpnv4 update {} still not present".format(router.name, prefix) + + def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() diff --git a/tests/topotests/bgp_vpnv4_noretain/r1/bgpd.conf b/tests/topotests/bgp_vpnv4_noretain/r1/bgpd.conf index 3d8773b8bf..0709e43edf 100644 --- a/tests/topotests/bgp_vpnv4_noretain/r1/bgpd.conf +++ b/tests/topotests/bgp_vpnv4_noretain/r1/bgpd.conf @@ -1,8 +1,12 @@ router bgp 65500 - bgp router-id 1.1.1.1 + bgp router-id 192.0.2.1 neighbor 10.125.0.2 remote-as 65500 address-family ipv4 unicast no neighbor 10.125.0.2 activate + label vpn export 100 + rd vpn export 192.0.2.1:0 + rt vpn import 192.0.2.2:400 + import vpn exit-address-family address-family ipv4 vpn neighbor 10.125.0.2 activate @@ -10,15 +14,33 @@ router bgp 65500 exit-address-family ! router bgp 65500 vrf vrf1 - bgp router-id 1.1.1.1 + bgp router-id 192.0.2.1 address-family ipv4 unicast redistribute connected label vpn export 101 - rd vpn export 444:1 - rt vpn import 51:100 52:100 - rt vpn export 51:100 + rd vpn export 192.0.2.1:1 + rt vpn import 192.0.2.2:100 + rt vpn export 192.0.2.1:100 + export vpn + import vpn + exit-address-family +! +router bgp 65500 vrf vrf3 + bgp router-id 192.0.2.1 + address-family ipv4 unicast + redistribute connected + label vpn export 103 + rd vpn export 192.0.2.1:3 + rt vpn export 192.0.2.1:300 export vpn + exit-address-family +! +router bgp 65500 vrf vrf4 + bgp router-id 192.0.2.1 + address-family ipv4 unicast + label vpn export 104 + rd vpn export 192.0.2.1:4 + rt vpn import 192.0.2.1:300 import vpn exit-address-family ! - diff --git a/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes.json b/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes.json deleted file mode 100644 index 28e153e3de..0000000000 --- a/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "vrfId":0, - "vrfName":"default", - "routerId":"1.1.1.1", - "defaultLocPrf":100, - "localAS":65500, - "routes":{ - "routeDistinguishers":{ - "444:1":{ - "10.201.0.0/24":[ - { - "valid":true, - "bestpath":true, - "selectionReason":"First path received", - "pathFrom":"external", - "prefix":"10.201.0.0", - "prefixLen":24, - "network":"10.201.0.0\/24", - "metric":0, - "weight":32768, - "peerId":"(unspec)", - "path":"", - "origin":"incomplete", - "announceNexthopSelf":true, - "nhVrfName":"vrf1", - "nexthops":[ - { - "ip":"0.0.0.0", - "hostname":"r1", - "afi":"ipv4", - "used":true - } - ] - } - ] - }, - "444:2":{ - "10.200.0.0/24":[ - { - "valid":true, - "bestpath":true, - "selectionReason":"First path received", - "pathFrom":"internal", - "prefix":"10.200.0.0", - "prefixLen":24, - "network":"10.200.0.0\/24", - "metric":0, - "locPrf":100, - "weight":0, - "peerId":"10.125.0.2", - "path":"", - "origin":"incomplete", - "nexthops":[ - { - "ip":"10.125.0.2", - "hostname":"r2", - "afi":"ipv4", - "used":true - } - ] - } - ] - }, - "444:3":{ - } - } - } -} diff --git a/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_all.json b/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_all.json new file mode 100644 index 0000000000..648bf854ba --- /dev/null +++ b/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_all.json @@ -0,0 +1,175 @@ +{ + "vrfId":0, + "vrfName":"default", + "routerId":"192.0.2.1", + "defaultLocPrf":100, + "localAS":65500, + "routes":{ + "routeDistinguishers":{ + "192.0.2.1:1":{ + "10.101.0.0/24":[ + { + "valid":true, + "bestpath":true, + "selectionReason":"First path received", + "pathFrom":"external", + "prefix":"10.101.0.0", + "prefixLen":24, + "network":"10.101.0.0\/24", + "metric":0, + "weight":32768, + "peerId":"(unspec)", + "path":"", + "origin":"incomplete", + "announceNexthopSelf":true, + "nhVrfName":"vrf1", + "nexthops":[ + { + "ip":"0.0.0.0", + "hostname":"r1", + "afi":"ipv4", + "used":true + } + ] + } + ] + }, + "192.0.2.1:3":{ + "10.103.0.0/24":[ + { + "valid":true, + "bestpath":true, + "selectionReason":"First path received", + "pathFrom":"external", + "prefix":"10.103.0.0", + "prefixLen":24, + "network":"10.103.0.0\/24", + "metric":0, + "weight":32768, + "peerId":"(unspec)", + "path":"", + "origin":"incomplete", + "announceNexthopSelf":true, + "nhVrfName":"vrf3", + "nexthops":[ + { + "ip":"0.0.0.0", + "hostname":"r1", + "afi":"ipv4", + "used":true + } + ] + } + ] + }, + "192.0.2.2:1":{ + "10.201.0.0/24":[ + { + "valid":true, + "bestpath":true, + "selectionReason":"First path received", + "pathFrom":"internal", + "prefix":"10.201.0.0", + "prefixLen":24, + "network":"10.201.0.0\/24", + "metric":0, + "locPrf":100, + "weight":0, + "peerId":"10.125.0.2", + "path":"", + "origin":"incomplete", + "nexthops":[ + { + "ip":"10.125.0.2", + "hostname":"r2", + "afi":"ipv4", + "used":true + } + ] + } + ] + }, + "192.0.2.2:2":{ + "10.202.0.0/24":[ + { + "valid":true, + "bestpath":true, + "selectionReason":"First path received", + "pathFrom":"internal", + "prefix":"10.202.0.0", + "prefixLen":24, + "network":"10.202.0.0\/24", + "metric":0, + "locPrf":100, + "weight":0, + "peerId":"10.125.0.2", + "path":"", + "origin":"incomplete", + "nexthops":[ + { + "ip":"10.125.0.2", + "hostname":"r2", + "afi":"ipv4", + "used":true + } + ] + } + ] + }, + "192.0.2.2:3":{ + "10.203.0.0/24":[ + { + "valid":true, + "bestpath":true, + "selectionReason":"First path received", + "pathFrom":"internal", + "prefix":"10.203.0.0", + "prefixLen":24, + "network":"10.203.0.0\/24", + "metric":0, + "locPrf":100, + "weight":0, + "peerId":"10.125.0.2", + "path":"", + "origin":"incomplete", + "nexthops":[ + { + "ip":"10.125.0.2", + "hostname":"r2", + "afi":"ipv4", + "used":true + } + ] + } + ] + }, + "192.0.2.2:4":{ + "10.204.0.0/24":[ + { + "valid":true, + "bestpath":true, + "selectionReason":"First path received", + "pathFrom":"internal", + "prefix":"10.204.0.0", + "prefixLen":24, + "network":"10.204.0.0\/24", + "metric":0, + "locPrf":100, + "weight":0, + "peerId":"10.125.0.2", + "path":"", + "origin":"incomplete", + "nexthops":[ + { + "ip":"10.125.0.2", + "hostname":"r2", + "afi":"ipv4", + "used":true + } + ] + } + ] + } + } + } +} diff --git a/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_unfiltered.json b/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_no_retain_init.json similarity index 66% rename from tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_unfiltered.json rename to tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_no_retain_init.json index 45f4acce6f..f01607ac4e 100644 --- a/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_unfiltered.json +++ b/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_no_retain_init.json @@ -1,21 +1,21 @@ { "vrfId":0, "vrfName":"default", - "routerId":"1.1.1.1", + "routerId":"192.0.2.1", "defaultLocPrf":100, "localAS":65500, "routes":{ "routeDistinguishers":{ - "444:1":{ - "10.201.0.0/24":[ + "192.0.2.1:1":{ + "10.101.0.0/24":[ { "valid":true, "bestpath":true, "selectionReason":"First path received", "pathFrom":"external", - "prefix":"10.201.0.0", + "prefix":"10.101.0.0", "prefixLen":24, - "network":"10.201.0.0\/24", + "network":"10.101.0.0\/24", "metric":0, "weight":32768, "peerId":"(unspec)", @@ -34,16 +34,44 @@ } ] }, - "444:2":{ - "10.200.0.0/24":[ + "192.0.2.1:3":{ + "10.103.0.0/24":[ + { + "valid":true, + "bestpath":true, + "selectionReason":"First path received", + "pathFrom":"external", + "prefix":"10.103.0.0", + "prefixLen":24, + "network":"10.103.0.0\/24", + "metric":0, + "weight":32768, + "peerId":"(unspec)", + "path":"", + "origin":"incomplete", + "announceNexthopSelf":true, + "nhVrfName":"vrf3", + "nexthops":[ + { + "ip":"0.0.0.0", + "hostname":"r1", + "afi":"ipv4", + "used":true + } + ] + } + ] + }, + "192.0.2.2:1":{ + "10.201.0.0/24":[ { "valid":true, "bestpath":true, "selectionReason":"First path received", "pathFrom":"internal", - "prefix":"10.200.0.0", + "prefix":"10.201.0.0", "prefixLen":24, - "network":"10.200.0.0\/24", + "network":"10.201.0.0\/24", "metric":0, "locPrf":100, "weight":0, @@ -61,16 +89,16 @@ } ] }, - "444:3":{ - "10.210.0.0/24":[ + "192.0.2.2:4":{ + "10.204.0.0/24":[ { "valid":true, "bestpath":true, "selectionReason":"First path received", "pathFrom":"internal", - "prefix":"10.210.0.0", + "prefix":"10.204.0.0", "prefixLen":24, - "network":"10.210.0.0\/24", + "network":"10.204.0.0\/24", "metric":0, "locPrf":100, "weight":0, diff --git a/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_no_retain_init_plus_r2_vrf2.json b/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_no_retain_init_plus_r2_vrf2.json new file mode 100644 index 0000000000..6df6c69b8f --- /dev/null +++ b/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_no_retain_init_plus_r2_vrf2.json @@ -0,0 +1,148 @@ +{ + "vrfId":0, + "vrfName":"default", + "routerId":"192.0.2.1", + "defaultLocPrf":100, + "localAS":65500, + "routes":{ + "routeDistinguishers":{ + "192.0.2.1:1":{ + "10.101.0.0/24":[ + { + "valid":true, + "bestpath":true, + "selectionReason":"First path received", + "pathFrom":"external", + "prefix":"10.101.0.0", + "prefixLen":24, + "network":"10.101.0.0\/24", + "metric":0, + "weight":32768, + "peerId":"(unspec)", + "path":"", + "origin":"incomplete", + "announceNexthopSelf":true, + "nhVrfName":"vrf1", + "nexthops":[ + { + "ip":"0.0.0.0", + "hostname":"r1", + "afi":"ipv4", + "used":true + } + ] + } + ] + }, + "192.0.2.1:3":{ + "10.103.0.0/24":[ + { + "valid":true, + "bestpath":true, + "selectionReason":"First path received", + "pathFrom":"external", + "prefix":"10.103.0.0", + "prefixLen":24, + "network":"10.103.0.0\/24", + "metric":0, + "weight":32768, + "peerId":"(unspec)", + "path":"", + "origin":"incomplete", + "announceNexthopSelf":true, + "nhVrfName":"vrf3", + "nexthops":[ + { + "ip":"0.0.0.0", + "hostname":"r1", + "afi":"ipv4", + "used":true + } + ] + } + ] + }, + "192.0.2.2:1":{ + "10.201.0.0/24":[ + { + "valid":true, + "bestpath":true, + "selectionReason":"First path received", + "pathFrom":"internal", + "prefix":"10.201.0.0", + "prefixLen":24, + "network":"10.201.0.0\/24", + "metric":0, + "locPrf":100, + "weight":0, + "peerId":"10.125.0.2", + "path":"", + "origin":"incomplete", + "nexthops":[ + { + "ip":"10.125.0.2", + "hostname":"r2", + "afi":"ipv4", + "used":true + } + ] + } + ] + }, + "192.0.2.2:2":{ + "10.202.0.0/24":[ + { + "valid":true, + "bestpath":true, + "selectionReason":"First path received", + "pathFrom":"internal", + "prefix":"10.202.0.0", + "prefixLen":24, + "network":"10.202.0.0\/24", + "metric":0, + "locPrf":100, + "weight":0, + "peerId":"10.125.0.2", + "path":"", + "origin":"incomplete", + "nexthops":[ + { + "ip":"10.125.0.2", + "hostname":"r2", + "afi":"ipv4", + "used":true + } + ] + } + ] + }, + "192.0.2.2:4":{ + "10.204.0.0/24":[ + { + "valid":true, + "bestpath":true, + "selectionReason":"First path received", + "pathFrom":"internal", + "prefix":"10.204.0.0", + "prefixLen":24, + "network":"10.204.0.0\/24", + "metric":0, + "locPrf":100, + "weight":0, + "peerId":"10.125.0.2", + "path":"", + "origin":"incomplete", + "nexthops":[ + { + "ip":"10.125.0.2", + "hostname":"r2", + "afi":"ipv4", + "used":true + } + ] + } + ] + } + } + } +} diff --git a/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_no_retain_init_plus_r2_vrf3.json b/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_no_retain_init_plus_r2_vrf3.json new file mode 100644 index 0000000000..7a17ff0f16 --- /dev/null +++ b/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vpn_routes_no_retain_init_plus_r2_vrf3.json @@ -0,0 +1,148 @@ +{ + "vrfId":0, + "vrfName":"default", + "routerId":"192.0.2.1", + "defaultLocPrf":100, + "localAS":65500, + "routes":{ + "routeDistinguishers":{ + "192.0.2.1:1":{ + "10.101.0.0/24":[ + { + "valid":true, + "bestpath":true, + "selectionReason":"First path received", + "pathFrom":"external", + "prefix":"10.101.0.0", + "prefixLen":24, + "network":"10.101.0.0\/24", + "metric":0, + "weight":32768, + "peerId":"(unspec)", + "path":"", + "origin":"incomplete", + "announceNexthopSelf":true, + "nhVrfName":"vrf1", + "nexthops":[ + { + "ip":"0.0.0.0", + "hostname":"r1", + "afi":"ipv4", + "used":true + } + ] + } + ] + }, + "192.0.2.1:3":{ + "10.103.0.0/24":[ + { + "valid":true, + "bestpath":true, + "selectionReason":"First path received", + "pathFrom":"external", + "prefix":"10.103.0.0", + "prefixLen":24, + "network":"10.103.0.0\/24", + "metric":0, + "weight":32768, + "peerId":"(unspec)", + "path":"", + "origin":"incomplete", + "announceNexthopSelf":true, + "nhVrfName":"vrf3", + "nexthops":[ + { + "ip":"0.0.0.0", + "hostname":"r1", + "afi":"ipv4", + "used":true + } + ] + } + ] + }, + "192.0.2.2:1":{ + "10.201.0.0/24":[ + { + "valid":true, + "bestpath":true, + "selectionReason":"First path received", + "pathFrom":"internal", + "prefix":"10.201.0.0", + "prefixLen":24, + "network":"10.201.0.0\/24", + "metric":0, + "locPrf":100, + "weight":0, + "peerId":"10.125.0.2", + "path":"", + "origin":"incomplete", + "nexthops":[ + { + "ip":"10.125.0.2", + "hostname":"r2", + "afi":"ipv4", + "used":true + } + ] + } + ] + }, + "192.0.2.2:3":{ + "10.203.0.0/24":[ + { + "valid":true, + "bestpath":true, + "selectionReason":"First path received", + "pathFrom":"internal", + "prefix":"10.203.0.0", + "prefixLen":24, + "network":"10.203.0.0\/24", + "metric":0, + "locPrf":100, + "weight":0, + "peerId":"10.125.0.2", + "path":"", + "origin":"incomplete", + "nexthops":[ + { + "ip":"10.125.0.2", + "hostname":"r2", + "afi":"ipv4", + "used":true + } + ] + } + ] + }, + "192.0.2.2:4":{ + "10.204.0.0/24":[ + { + "valid":true, + "bestpath":true, + "selectionReason":"First path received", + "pathFrom":"internal", + "prefix":"10.204.0.0", + "prefixLen":24, + "network":"10.204.0.0\/24", + "metric":0, + "locPrf":100, + "weight":0, + "peerId":"10.125.0.2", + "path":"", + "origin":"incomplete", + "nexthops":[ + { + "ip":"10.125.0.2", + "hostname":"r2", + "afi":"ipv4", + "used":true + } + ] + } + ] + } + } + } +} diff --git a/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vrf_all_routes_init.json b/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vrf_all_routes_init.json new file mode 100644 index 0000000000..2769c6eb3f --- /dev/null +++ b/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vrf_all_routes_init.json @@ -0,0 +1,156 @@ +{ + "default": { + "vrfName": "default", + "routerId": "192.0.2.1", + "defaultLocPrf": 100, + "localAS": 65500, + "routes": { + "10.204.0.0/24": [ + { + "pathFrom": "external", + "prefix": "10.204.0.0", + "prefixLen": 24, + "network": "10.204.0.0/24", + "metric": 0, + "locPrf": 100, + "weight": 0, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "announceNexthopSelf": true, + "nhVrfName": "default", + "nexthops": [ + { + "ip": "10.125.0.2", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + } + }, + "vrf1": { + "vrfName": "vrf1", + "routerId": "192.0.2.1", + "defaultLocPrf": 100, + "localAS": 65500, + "routes": { + "10.101.0.0/24": [ + { + "valid": true, + "bestpath": true, + "selectionReason": "First path received", + "pathFrom": "external", + "prefix": "10.101.0.0", + "prefixLen": 24, + "network": "10.101.0.0/24", + "metric": 0, + "weight": 32768, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "nexthops": [ + { + "ip": "0.0.0.0", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ], + "10.201.0.0/24": [ + { + "pathFrom": "external", + "prefix": "10.201.0.0", + "prefixLen": 24, + "network": "10.201.0.0/24", + "metric": 0, + "locPrf": 100, + "weight": 0, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "announceNexthopSelf": true, + "nhVrfName": "default", + "nexthops": [ + { + "ip": "10.125.0.2", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + } + }, + "vrf3": { + "vrfName": "vrf3", + "routerId": "192.0.2.1", + "defaultLocPrf": 100, + "localAS": 65500, + "routes": { + "10.103.0.0/24": [ + { + "valid": true, + "bestpath": true, + "selectionReason": "First path received", + "pathFrom": "external", + "prefix": "10.103.0.0", + "prefixLen": 24, + "network": "10.103.0.0/24", + "metric": 0, + "weight": 32768, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "nexthops": [ + { + "ip": "0.0.0.0", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + } + }, + "vrf4": { + "vrfName": "vrf4", + "routerId": "192.0.2.1", + "defaultLocPrf": 100, + "localAS": 65500, + "routes": { + "10.103.0.0/24": [ + { + "valid": true, + "bestpath": true, + "selectionReason": "First path received", + "pathFrom": "external", + "prefix": "10.103.0.0", + "prefixLen": 24, + "network": "10.103.0.0/24", + "metric": 0, + "weight": 32768, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "announceNexthopSelf": true, + "nhVrfName": "vrf3", + "nexthops": [ + { + "ip": "0.0.0.0", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + } + } +} diff --git a/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vrf_all_routes_plus_r1_vrf1.json b/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vrf_all_routes_plus_r1_vrf1.json new file mode 100644 index 0000000000..488dc4aab9 --- /dev/null +++ b/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vrf_all_routes_plus_r1_vrf1.json @@ -0,0 +1,190 @@ +{ + "default": { + "vrfName": "default", + "routerId": "192.0.2.1", + "defaultLocPrf": 100, + "localAS": 65500, + "routes": { + "10.204.0.0/24": [ + { + "pathFrom": "external", + "prefix": "10.204.0.0", + "prefixLen": 24, + "network": "10.204.0.0/24", + "metric": 0, + "locPrf": 100, + "weight": 0, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "announceNexthopSelf": true, + "nhVrfName": "default", + "nexthops": [ + { + "ip": "10.125.0.2", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + } + }, + "vrf1": { + "vrfName": "vrf1", + "routerId": "192.0.2.1", + "defaultLocPrf": 100, + "localAS": 65500, + "routes": { + "10.101.0.0/24": [ + { + "valid": true, + "bestpath": true, + "selectionReason": "First path received", + "pathFrom": "external", + "prefix": "10.101.0.0", + "prefixLen": 24, + "network": "10.101.0.0/24", + "metric": 0, + "weight": 32768, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "nexthops": [ + { + "ip": "0.0.0.0", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ], + "10.201.0.0/24": [ + { + "pathFrom": "external", + "prefix": "10.201.0.0", + "prefixLen": 24, + "network": "10.201.0.0/24", + "metric": 0, + "locPrf": 100, + "weight": 0, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "announceNexthopSelf": true, + "nhVrfName": "default", + "nexthops": [ + { + "ip": "10.125.0.2", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + } + }, + "vrf3": { + "vrfName": "vrf3", + "routerId": "192.0.2.1", + "defaultLocPrf": 100, + "localAS": 65500, + "routes": { + "10.103.0.0/24": [ + { + "valid": true, + "bestpath": true, + "selectionReason": "First path received", + "pathFrom": "external", + "prefix": "10.103.0.0", + "prefixLen": 24, + "network": "10.103.0.0/24", + "metric": 0, + "weight": 32768, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "nexthops": [ + { + "ip": "0.0.0.0", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + } + }, + "vrf4": { + "vrfName": "vrf4", + "routerId": "192.0.2.1", + "defaultLocPrf": 100, + "localAS": 65500, + "routes": { + "10.103.0.0/24": [ + { + "valid": true, + "bestpath": true, + "selectionReason": "First path received", + "pathFrom": "external", + "prefix": "10.103.0.0", + "prefixLen": 24, + "network": "10.103.0.0/24", + "metric": 0, + "weight": 32768, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "announceNexthopSelf": true, + "nhVrfName": "vrf3", + "nexthops": [ + { + "ip": "0.0.0.0", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + } + }, + "vrf2": { + "vrfName": "vrf2", + "routerId": "192.0.2.1", + "defaultLocPrf": 100, + "localAS": 65500, + "routes": { + "10.101.0.0/24": [ + { + "valid": true, + "bestpath": true, + "selectionReason": "First path received", + "pathFrom": "external", + "prefix": "10.101.0.0", + "prefixLen": 24, + "network": "10.101.0.0/24", + "metric": 0, + "weight": 32768, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "announceNexthopSelf": true, + "nhVrfName": "vrf1", + "nexthops": [ + { + "ip": "0.0.0.0", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + } + } +} diff --git a/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vrf_all_routes_plus_r2_vrf2.json b/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vrf_all_routes_plus_r2_vrf2.json new file mode 100644 index 0000000000..b751756fce --- /dev/null +++ b/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vrf_all_routes_plus_r2_vrf2.json @@ -0,0 +1,188 @@ +{ + "default": { + "vrfName": "default", + "routerId": "192.0.2.1", + "defaultLocPrf": 100, + "localAS": 65500, + "routes": { + "10.204.0.0/24": [ + { + "pathFrom": "external", + "prefix": "10.204.0.0", + "prefixLen": 24, + "network": "10.204.0.0/24", + "metric": 0, + "locPrf": 100, + "weight": 0, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "announceNexthopSelf": true, + "nhVrfName": "default", + "nexthops": [ + { + "ip": "10.125.0.2", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + } + }, + "vrf1": { + "vrfName": "vrf1", + "routerId": "192.0.2.1", + "defaultLocPrf": 100, + "localAS": 65500, + "routes": { + "10.101.0.0/24": [ + { + "valid": true, + "bestpath": true, + "selectionReason": "First path received", + "pathFrom": "external", + "prefix": "10.101.0.0", + "prefixLen": 24, + "network": "10.101.0.0/24", + "metric": 0, + "weight": 32768, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "nexthops": [ + { + "ip": "0.0.0.0", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ], + "10.201.0.0/24": [ + { + "pathFrom": "external", + "prefix": "10.201.0.0", + "prefixLen": 24, + "network": "10.201.0.0/24", + "metric": 0, + "locPrf": 100, + "weight": 0, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "announceNexthopSelf": true, + "nhVrfName": "default", + "nexthops": [ + { + "ip": "10.125.0.2", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + } + }, + "vrf3": { + "vrfName": "vrf3", + "routerId": "192.0.2.1", + "defaultLocPrf": 100, + "localAS": 65500, + "routes": { + "10.103.0.0/24": [ + { + "valid": true, + "bestpath": true, + "selectionReason": "First path received", + "pathFrom": "external", + "prefix": "10.103.0.0", + "prefixLen": 24, + "network": "10.103.0.0/24", + "metric": 0, + "weight": 32768, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "nexthops": [ + { + "ip": "0.0.0.0", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + } + }, + "vrf4": { + "vrfName": "vrf4", + "routerId": "192.0.2.1", + "defaultLocPrf": 100, + "localAS": 65500, + "routes": { + "10.103.0.0/24": [ + { + "valid": true, + "bestpath": true, + "selectionReason": "First path received", + "pathFrom": "external", + "prefix": "10.103.0.0", + "prefixLen": 24, + "network": "10.103.0.0/24", + "metric": 0, + "weight": 32768, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "announceNexthopSelf": true, + "nhVrfName": "vrf3", + "nexthops": [ + { + "ip": "0.0.0.0", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + } + }, + "vrf2": { + "vrfName": "vrf2", + "routerId": "192.0.2.1", + "defaultLocPrf": 100, + "localAS": 65500, + "routes": { + "10.202.0.0/24": [ + { + "pathFrom": "external", + "prefix": "10.202.0.0", + "prefixLen": 24, + "network": "10.202.0.0/24", + "metric": 0, + "locPrf": 100, + "weight": 0, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "announceNexthopSelf": true, + "nhVrfName": "default", + "nexthops": [ + { + "ip": "10.125.0.2", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + } + } +} diff --git a/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vrf_all_routes_plus_r2_vrf3.json b/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vrf_all_routes_plus_r2_vrf3.json new file mode 100644 index 0000000000..49d4066e19 --- /dev/null +++ b/tests/topotests/bgp_vpnv4_noretain/r1/ipv4_vrf_all_routes_plus_r2_vrf3.json @@ -0,0 +1,188 @@ +{ + "default": { + "vrfName": "default", + "routerId": "192.0.2.1", + "defaultLocPrf": 100, + "localAS": 65500, + "routes": { + "10.204.0.0/24": [ + { + "pathFrom": "external", + "prefix": "10.204.0.0", + "prefixLen": 24, + "network": "10.204.0.0/24", + "metric": 0, + "locPrf": 100, + "weight": 0, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "announceNexthopSelf": true, + "nhVrfName": "default", + "nexthops": [ + { + "ip": "10.125.0.2", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + } + }, + "vrf1": { + "vrfName": "vrf1", + "routerId": "192.0.2.1", + "defaultLocPrf": 100, + "localAS": 65500, + "routes": { + "10.101.0.0/24": [ + { + "valid": true, + "bestpath": true, + "selectionReason": "First path received", + "pathFrom": "external", + "prefix": "10.101.0.0", + "prefixLen": 24, + "network": "10.101.0.0/24", + "metric": 0, + "weight": 32768, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "nexthops": [ + { + "ip": "0.0.0.0", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ], + "10.201.0.0/24": [ + { + "pathFrom": "external", + "prefix": "10.201.0.0", + "prefixLen": 24, + "network": "10.201.0.0/24", + "metric": 0, + "locPrf": 100, + "weight": 0, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "announceNexthopSelf": true, + "nhVrfName": "default", + "nexthops": [ + { + "ip": "10.125.0.2", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + } + }, + "vrf3": { + "vrfName": "vrf3", + "routerId": "192.0.2.1", + "defaultLocPrf": 100, + "localAS": 65500, + "routes": { + "10.103.0.0/24": [ + { + "valid": true, + "bestpath": true, + "selectionReason": "First path received", + "pathFrom": "external", + "prefix": "10.103.0.0", + "prefixLen": 24, + "network": "10.103.0.0/24", + "metric": 0, + "weight": 32768, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "nexthops": [ + { + "ip": "0.0.0.0", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + } + }, + "vrf4": { + "vrfName": "vrf4", + "routerId": "192.0.2.1", + "defaultLocPrf": 100, + "localAS": 65500, + "routes": { + "10.103.0.0/24": [ + { + "valid": true, + "bestpath": true, + "selectionReason": "First path received", + "pathFrom": "external", + "prefix": "10.103.0.0", + "prefixLen": 24, + "network": "10.103.0.0/24", + "metric": 0, + "weight": 32768, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "announceNexthopSelf": true, + "nhVrfName": "vrf3", + "nexthops": [ + { + "ip": "0.0.0.0", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + } + }, + "vrf2": { + "vrfName": "vrf2", + "routerId": "192.0.2.1", + "defaultLocPrf": 100, + "localAS": 65500, + "routes": { + "10.203.0.0/24": [ + { + "pathFrom": "external", + "prefix": "10.203.0.0", + "prefixLen": 24, + "network": "10.203.0.0/24", + "metric": 0, + "locPrf": 100, + "weight": 0, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "announceNexthopSelf": true, + "nhVrfName": "default", + "nexthops": [ + { + "ip": "10.125.0.2", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + } + } +} diff --git a/tests/topotests/bgp_vpnv4_noretain/r1/isisd.conf b/tests/topotests/bgp_vpnv4_noretain/r1/isisd.conf deleted file mode 100644 index 6f5cb6ec68..0000000000 --- a/tests/topotests/bgp_vpnv4_noretain/r1/isisd.conf +++ /dev/null @@ -1,14 +0,0 @@ -interface r1-eth0 - ip router isis 1 - isis circuit-type level-1 -! -interface lo - ip router isis 1 - isis passive -! -router isis 1 - is-type level-1 - net 49.0002.0000.1994.00 - segment-routing on - segment-routing prefix 1.1.1.1/32 index 11 -! diff --git a/tests/topotests/bgp_vpnv4_noretain/r1/zebra.conf b/tests/topotests/bgp_vpnv4_noretain/r1/zebra.conf index 5b8b1e8ffb..f99cfafe32 100644 --- a/tests/topotests/bgp_vpnv4_noretain/r1/zebra.conf +++ b/tests/topotests/bgp_vpnv4_noretain/r1/zebra.conf @@ -1,13 +1,16 @@ log stdout interface lo - ip address 1.1.1.1/32 + ip address 192.0.2.1/32 ! interface r1-gre0 ip address 192.168.0.1/24 ! -interface r1-eth1 vrf vrf1 - ip address 10.201.0.1/24 -! interface r1-eth0 ip address 10.125.0.1/24 ! +interface r1-eth1 vrf vrf1 + ip address 10.101.0.1/24 +! +interface r1-eth3 vrf vrf3 + ip address 10.103.0.1/24 +! \ No newline at end of file diff --git a/tests/topotests/bgp_vpnv4_noretain/r2/bgpd.conf b/tests/topotests/bgp_vpnv4_noretain/r2/bgpd.conf index 235fb31177..729daef2bc 100644 --- a/tests/topotests/bgp_vpnv4_noretain/r2/bgpd.conf +++ b/tests/topotests/bgp_vpnv4_noretain/r2/bgpd.conf @@ -1,35 +1,54 @@ router bgp 65500 - bgp router-id 2.2.2.2 + bgp router-id 192.0.2.2 neighbor 10.125.0.1 remote-as 65500 address-family ipv4 unicast no neighbor 10.125.0.1 activate exit-address-family address-family ipv4 vpn neighbor 10.125.0.1 activate - no bgp retain route-target all exit-address-family ! router bgp 65500 vrf vrf1 - bgp router-id 2.2.2.2 + bgp router-id 192.0.2.2 address-family ipv4 unicast redistribute connected - label vpn export 102 - rd vpn export 444:2 - rt vpn import 53:100 52:100 51:100 - rt vpn export 52:100 + label vpn export 201 + rd vpn export 192.0.2.2:1 + rt vpn import 192.0.2.1:100 192.0.2.2:100 192.0.2.2:200 + rt vpn export 192.0.2.2:100 export vpn import vpn exit-address-family ! router bgp 65500 vrf vrf2 - bgp router-id 2.2.2.2 + bgp router-id 192.0.2.2 address-family ipv4 unicast redistribute connected - label vpn export 102 - rd vpn export 444:3 - rt vpn both 53:100 52:100 51:100 - rt vpn both 53:100 + label vpn export 202 + rd vpn export 192.0.2.2:2 + rt vpn import 192.0.2.1:100 192.0.2.2:100 192.0.2.2:200 + rt vpn export 192.0.2.2:200 export vpn import vpn exit-address-family ! +router bgp 65500 vrf vrf3 + bgp router-id 192.0.2.2 + address-family ipv4 unicast + redistribute connected + label vpn export 203 + rd vpn export 192.0.2.2:3 + rt vpn export 192.0.2.2:300 + export vpn + exit-address-family +! +router bgp 65500 vrf vrf4 + bgp router-id 192.0.2.2 + address-family ipv4 unicast + redistribute connected + label vpn export 204 + rd vpn export 192.0.2.2:4 + rt vpn export 192.0.2.2:400 + export vpn + exit-address-family +! diff --git a/tests/topotests/bgp_vpnv4_noretain/r2/ipv4_vpn_routes_all.json b/tests/topotests/bgp_vpnv4_noretain/r2/ipv4_vpn_routes_all.json new file mode 100644 index 0000000000..d8b8e88d93 --- /dev/null +++ b/tests/topotests/bgp_vpnv4_noretain/r2/ipv4_vpn_routes_all.json @@ -0,0 +1,177 @@ +{ + "vrfId": 0, + "vrfName": "default", + "routerId":"192.0.2.2", + "defaultLocPrf": 100, + "localAS": 65500, + "routes": { + "routeDistinguishers": { + "192.0.2.1:1": { + "10.101.0.0/24": [ + { + "valid": true, + "bestpath": true, + "selectionReason": "First path received", + "pathFrom": "internal", + "prefix": "10.101.0.0", + "prefixLen": 24, + "network": "10.101.0.0/24", + "metric": 0, + "locPrf": 100, + "weight": 0, + "peerId": "10.125.0.1", + "path": "", + "origin": "incomplete", + "nexthops": [ + { + "ip": "10.125.0.1", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + }, + "192.0.2.1:3": { + "10.103.0.0/24": [ + { + "valid": true, + "bestpath": true, + "selectionReason": "First path received", + "pathFrom": "internal", + "prefix": "10.103.0.0", + "prefixLen": 24, + "network": "10.103.0.0/24", + "metric": 0, + "locPrf": 100, + "weight": 0, + "peerId": "10.125.0.1", + "path": "", + "origin": "incomplete", + "nexthops": [ + { + "ip": "10.125.0.1", + "hostname": "r1", + "afi": "ipv4", + "used": true + } + ] + } + ] + }, + "192.0.2.2:1": { + "10.201.0.0/24": [ + { + "valid": true, + "bestpath": true, + "selectionReason": "First path received", + "pathFrom": "external", + "network": "10.201.0.0/24", + "prefixLen": 24, + "prefix": "10.201.0.0", + "metric": 0, + "weight": 32768, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "announceNexthopSelf": true, + "nhVrfName": "vrf1", + "nexthops": [ + { + "ip": "0.0.0.0", + "hostname": "r2", + "afi": "ipv4", + "used": true + } + ] + } + ] + }, + "192.0.2.2:2": { + "10.202.0.0/24": [ + { + "valid": true, + "bestpath": true, + "selectionReason": "First path received", + "pathFrom": "external", + "network": "10.202.0.0/24", + "prefixLen": 24, + "prefix": "10.202.0.0", + "metric": 0, + "weight": 32768, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "announceNexthopSelf": true, + "nhVrfName": "vrf2", + "nexthops": [ + { + "ip": "0.0.0.0", + "hostname": "r2", + "afi": "ipv4", + "used": true + } + ] + } + ] + }, + "192.0.2.2:3": { + "10.203.0.0/24": [ + { + "valid": true, + "bestpath": true, + "selectionReason": "First path received", + "pathFrom": "external", + "prefix": "10.203.0.0", + "prefixLen": 24, + "network": "10.203.0.0/24", + "metric": 0, + "weight": 32768, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "announceNexthopSelf": true, + "nhVrfName": "vrf3", + "nexthops": [ + { + "ip": "0.0.0.0", + "hostname": "r2", + "afi": "ipv4", + "used": true + } + ] + } + ] + }, + "192.0.2.2:4": { + "10.204.0.0/24": [ + { + "valid": true, + "bestpath": true, + "selectionReason": "First path received", + "pathFrom": "external", + "prefix": "10.204.0.0", + "prefixLen": 24, + "network": "10.204.0.0/24", + "metric": 0, + "weight": 32768, + "peerId": "(unspec)", + "path": "", + "origin": "incomplete", + "announceNexthopSelf": true, + "nhVrfName": "vrf4", + "nexthops": [ + { + "ip": "0.0.0.0", + "hostname": "r2", + "afi": "ipv4", + "used": true + } + ] + } + ] + } + } + } +} diff --git a/tests/topotests/bgp_vpnv4_noretain/r2/ipv4_vpn_summary.json b/tests/topotests/bgp_vpnv4_noretain/r2/ipv4_vpn_summary.json new file mode 100644 index 0000000000..a4408f1915 --- /dev/null +++ b/tests/topotests/bgp_vpnv4_noretain/r2/ipv4_vpn_summary.json @@ -0,0 +1,17 @@ +{ + "routerId":"192.0.2.2", + "as":65500, + "vrfId":0, + "vrfName":"default", + "peerCount":1, + "peers":{ + "10.125.0.1":{ + "remoteAs":65500, + "localAs":65500, + "version":4, + "state":"Established", + "peerState":"OK" + } + }, + "totalPeers":1 +} diff --git a/tests/topotests/bgp_vpnv4_noretain/r2/isisd.conf b/tests/topotests/bgp_vpnv4_noretain/r2/isisd.conf deleted file mode 100644 index cbec8c3674..0000000000 --- a/tests/topotests/bgp_vpnv4_noretain/r2/isisd.conf +++ /dev/null @@ -1,14 +0,0 @@ -interface r2-eth0 - ip router isis 1 - isis circuit-type level-1 -! -interface lo - ip router isis 1 - isis passive -! -router isis 1 - is-type level-1 - net 49.0002.0000.1995.00 - segment-routing on - segment-routing prefix 2.2.2.2/32 index 22 -! diff --git a/tests/topotests/bgp_vpnv4_noretain/r2/zebra.conf b/tests/topotests/bgp_vpnv4_noretain/r2/zebra.conf index 7ec644ac2a..f19ad9d3e8 100644 --- a/tests/topotests/bgp_vpnv4_noretain/r2/zebra.conf +++ b/tests/topotests/bgp_vpnv4_noretain/r2/zebra.conf @@ -1,16 +1,22 @@ log stdout interface lo - ip address 2.2.2.2/32 + ip address 192.0.2.2/32 ! interface r2-gre0 ip address 192.168.0.2/24 ! +interface r2-eth0 + ip address 10.125.0.2/24 +! interface r2-eth1 vrf vrf1 - ip address 10.200.0.2/24 + ip address 10.201.0.2/24 ! interface r2-eth2 vrf vrf2 - ip address 10.210.0.2/24 + ip address 10.202.0.2/24 ! -interface r2-eth0 - ip address 10.125.0.2/24 +interface r2-eth3 vrf vrf3 + ip address 10.203.0.1/24 +! +interface r2-eth4 vrf vrf4 + ip address 10.204.0.1/24 ! diff --git a/tests/topotests/bgp_vpnv4_noretain/test_bgp_vpnv4_noretain.py b/tests/topotests/bgp_vpnv4_noretain/test_bgp_vpnv4_noretain.py index 9b8ae4b7e3..037dd40390 100644 --- a/tests/topotests/bgp_vpnv4_noretain/test_bgp_vpnv4_noretain.py +++ b/tests/topotests/bgp_vpnv4_noretain/test_bgp_vpnv4_noretain.py @@ -17,6 +17,7 @@ import sys import json from functools import partial +from copy import deepcopy import pytest # Save the Current Working Directory to find configuration files. @@ -34,6 +35,7 @@ pytestmark = [pytest.mark.bgpd] + def build_topo(tgen): "Build function" @@ -53,41 +55,54 @@ def build_topo(tgen): switch = tgen.add_switch("s4") switch.add_link(tgen.gears["r2"]) - + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["r1"]) + + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["r2"]) + + switch = tgen.add_switch("s7") + switch.add_link(tgen.gears["r1"]) + + switch = tgen.add_switch("s8") + switch.add_link(tgen.gears["r2"]) + + def _populate_iface(): tgen = get_topogen() cmds_list = [ - 'modprobe mpls_router', - 'echo 100000 > /proc/sys/net/mpls/platform_labels', - 'ip link add vrf1 type vrf table 10', - 'ip link set dev vrf1 up', - 'ip link set dev {0}-eth1 master vrf1', - 'echo 1 > /proc/sys/net/mpls/conf/vrf1/input', + "modprobe mpls_router", + "echo 100000 > /proc/sys/net/mpls/platform_labels", + "ip link add vrf1 type vrf table 10", + "ip link set dev vrf1 up", + "ip link set dev {0}-eth1 master vrf1", + "echo 1 > /proc/sys/net/mpls/conf/vrf1/input", + "ip link add vrf2 type vrf table 20", + "ip link set dev vrf2 up", + "ip link set dev {0}-eth2 master vrf2", + "echo 1 > /proc/sys/net/mpls/conf/vrf2/input", + "ip link add vrf3 type vrf table 30", + "ip link set dev vrf3 up", + "ip link set dev {0}-eth3 master vrf3", + "echo 1 > /proc/sys/net/mpls/conf/vrf3/input", + "ip link add vrf4 type vrf table 40", + "ip link set dev vrf4 up", + "ip link set dev {0}-eth4 master vrf4", + "echo 1 > /proc/sys/net/mpls/conf/vrf4/input", ] - cmds_list_extra = [ - 'ip link add vrf2 type vrf table 20', - 'ip link set dev vrf2 up', - 'ip link set dev {0}-eth2 master vrf2', - 'echo 1 > /proc/sys/net/mpls/conf/vrf2/input', - ] - + for cmd in cmds_list: - input = cmd.format('r1', '1', '2') - logger.info('input: ' + cmd) - output = tgen.net['r1'].cmd(cmd.format('r1', '1', '2')) - logger.info('output: ' + output) + input = cmd.format("r1", "1", "2") + logger.info("input: " + cmd) + output = tgen.net["r1"].cmd(cmd.format("r1", "1", "2")) + logger.info("output: " + output) for cmd in cmds_list: - input = cmd.format('r2', '2', '1') - logger.info('input: ' + cmd) - output = tgen.net['r2'].cmd(cmd.format('r2', '2', '1')) - logger.info('output: ' + output) + input = cmd.format("r2", "2", "1") + logger.info("input: " + cmd) + output = tgen.net["r2"].cmd(cmd.format("r2", "2", "1")) + logger.info("output: " + output) - for cmd in cmds_list_extra: - input = cmd.format('r2', '2', '1') - logger.info('input: ' + cmd) - output = tgen.net['r2'].cmd(cmd.format('r2', '2', '1')) - logger.info('output: ' + output) def setup_module(mod): "Sets up the pytest environment" @@ -96,7 +111,7 @@ def setup_module(mod): tgen.start_topology() router_list = tgen.routers() - _populate_iface() + _populate_iface() for rname, router in router_list.items(): router.load_config( @@ -105,9 +120,6 @@ def setup_module(mod): router.load_config( TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) ) - router.load_config( - TopoRouter.RD_ISIS, os.path.join(CWD, "{}/bgpd.conf".format(rname)) - ) # Initialize all routers. tgen.start_router() @@ -136,27 +148,54 @@ def router_json_cmp_exact_filter(router, cmd, expected): if "version" in attr: attr.pop("version") + # filter out RD with no data (e.g. "444:3": {}) + json_tmp = deepcopy(json_output) + for rd, data in json_tmp["routes"]["routeDistinguishers"].items(): + if len(data.keys()) == 0: + json_output["routes"]["routeDistinguishers"].pop(rd) + return topotest.json_cmp(json_output, expected, exact=True) -def test_bgp_no_retain(): - """ - Check bgp no retain route-target all on r1 - """ +def router_vrf_json_cmp_exact_filter(router, cmd, expected): + output = router.vtysh_cmd(cmd) + logger.info("{}: {}\n{}".format(router.name, cmd, output)) + + json_output = json.loads(output) + + # filter out tableVersion, version, nhVrfId and vrfId + for vrf, data in json_output.items(): + if "vrfId" in data: + data.pop("vrfId") + if "tableVersion" in data: + data.pop("tableVersion") + if "routes" not in data: + continue + for route, attrs in data["routes"].items(): + for attr in attrs: + if "nhVrfId" in attr: + attr.pop("nhVrfId") + if "version" in attr: + attr.pop("version") + + # filter out VRF with no routes + json_tmp = deepcopy(json_output) + for vrf, data in json_tmp.items(): + if "routes" not in data or len(data["routes"].keys()) == 0: + json_output.pop(vrf) + + return topotest.json_cmp(json_output, expected, exact=True) + +def check_show_bgp_ipv4_vpn(rname, json_file): tgen = get_topogen() if tgen.routers_have_failure(): pytest.skip(tgen.errors) + router = tgen.gears[rname] - # Check IPv4 VPN routing tables on r1 - logger.info("Checking VPNv4 routes for convergence on r1") - router = tgen.gears["r1"] - json_file = "{}/{}/ipv4_vpn_routes.json".format(CWD, router.name) - if not os.path.isfile(json_file): - logger.info("skipping file {}".format(json_file)) - assert 0, "{} file not found".format(json_file) - return + logger.info("Checking VPNv4 routes for convergence on {}".format(rname)) + json_file = "{}/{}/{}".format(CWD, router.name, json_file) expected = json.loads(open(json_file).read()) test_func = partial( router_json_cmp_exact_filter, @@ -169,32 +208,20 @@ def test_bgp_no_retain(): assert result is None, assertmsg -def test_bgp_retain(): - """ - Apply and check bgp retain route-target all on r1 - """ - +def check_show_bgp_vrf_ipv4(rname, json_file): tgen = get_topogen() if tgen.routers_have_failure(): pytest.skip(tgen.errors) + router = tgen.gears[rname] - # Check IPv4 VPN routing tables on r1 - logger.info("Checking VPNv4 routes on r1 after bgp no retain") - router = tgen.gears["r1"] - router.vtysh_cmd( - "configure\nrouter bgp 65500\naddress-family ipv4 vpn\nbgp retain route-target all\n" - ) - json_file = "{}/{}/ipv4_vpn_routes_unfiltered.json".format(CWD, router.name) - if not os.path.isfile(json_file): - logger.info("skipping file {}".format(json_file)) - assert 0, "{} file not found".format(json_file) - return + logger.info("Checking VRF IPv4 routes for convergence on {}".format(rname)) + json_file = "{}/{}/{}".format(CWD, router.name, json_file) expected = json.loads(open(json_file).read()) test_func = partial( - router_json_cmp_exact_filter, + router_vrf_json_cmp_exact_filter, router, - "show bgp ipv4 vpn json", + "show bgp vrf all ipv4 unicast json", expected, ) _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) @@ -202,6 +229,330 @@ def test_bgp_retain(): assert result is None, assertmsg +def test_protocols_convergence_step0(): + """ + Assert that all protocols have converged + """ + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + # check that r2 peerings are ok + logger.info("Checking BGP ipv4 vpn summary for r2") + router = tgen.gears["r2"] + json_file = "{}/{}/ipv4_vpn_summary.json".format(CWD, router.name) + expected = json.loads(open(json_file).read()) + test_func = partial( + topotest.router_json_cmp, + router, + "show bgp ipv4 vpn summary json", + expected, + ) + _, result = topotest.run_and_expect(test_func, None, count=20, wait=0.5) + assertmsg = '"{}" JSON output mismatches'.format(router.name) + assert result is None, assertmsg + + +def test_bgp_no_retain_step1(): + """ + Check bgp no retain route-target all on r1 + """ + + rname = "r1" + check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_no_retain_init.json") + check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json") + + check_show_bgp_vrf_ipv4(rname, "ipv4_vrf_all_routes_init.json") + + +def test_bgp_retain_step2(): + """ + Apply and check bgp retain route-target all on r1 + """ + rname = "r1" + cfg = """ +configure +router bgp 65500 + address-family ipv4 vpn + bgp retain route-target all +""" + + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears[rname] + router.vtysh_cmd(cfg) + + check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_all.json") + check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json") + + check_show_bgp_vrf_ipv4(rname, "ipv4_vrf_all_routes_init.json") + + +def test_bgp_no_retain_step3(): + """ + Apply and check no bgp retain route-target all on r1 + """ + rname = "r1" + + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears["r1"] + router.vtysh_cmd( + "configure\nrouter bgp 65500\naddress-family ipv4 vpn\nno bgp retain route-target all\n" + ) + + check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_no_retain_init.json") + check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json") + + check_show_bgp_vrf_ipv4(rname, "ipv4_vrf_all_routes_init.json") + + +def test_bgp_no_retain_add_vrf2_step4(): + """ + Add vrf2 on r1 and check bgp tables + """ + + rname = "r1" + cfg = """ +configure +router bgp 65500 vrf vrf2 + bgp router-id 192.0.2.1 + address-family ipv4 unicast + redistribute connected + label vpn export 102 + rd vpn export 192.0.2.1:200 + rt vpn import 192.0.2.2:200 + import vpn + exit-address-family +! +""" + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears[rname] + router.vtysh_cmd(cfg) + + check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_no_retain_init_plus_r2_vrf2.json") + check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json") + + check_show_bgp_vrf_ipv4(rname, "ipv4_vrf_all_routes_plus_r2_vrf2.json") + + +def test_bgp_no_retain_unimport_vrf2_step5(): + """ + Unimport to vrf2 on r1 and check bgp tables + """ + + rname = "r1" + cfg = """ +configure +router bgp 65500 vrf vrf2 + address-family ipv4 unicast + no import vpn + exit-address-family +! +""" + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears[rname] + router.vtysh_cmd(cfg) + + check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_no_retain_init.json") + check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json") + + check_show_bgp_vrf_ipv4(rname, "ipv4_vrf_all_routes_init.json") + + +def test_bgp_no_retain_import_vrf2_step6(): + """ + Re-import to vrf2 on r1 and check bgp tables + """ + + rname = "r1" + cfg = """ +configure +router bgp 65500 vrf vrf2 + address-family ipv4 unicast + import vpn + exit-address-family +! +""" + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears[rname] + router.vtysh_cmd(cfg) + + check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_no_retain_init_plus_r2_vrf2.json") + check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json") + + check_show_bgp_vrf_ipv4(rname, "ipv4_vrf_all_routes_plus_r2_vrf2.json") + + +def test_bgp_no_retain_import_vrf1_step7(): + """ + Import r1 vrf1 into r1 vrf2 and check bgp tables + """ + + rname = "r1" + cfg = """ +configure +router bgp 65500 vrf vrf2 + address-family ipv4 unicast + rt vpn import 192.0.2.1:100 + exit-address-family +! +""" + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears[rname] + router.vtysh_cmd(cfg) + + check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_no_retain_init.json") + check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json") + + check_show_bgp_vrf_ipv4(rname, "ipv4_vrf_all_routes_plus_r1_vrf1.json") + + +def test_bgp_no_retain_import_vrf3_step8(): + """ + Import r2 vrf3 into r1 vrf2 and check bgp tables + """ + + rname = "r1" + cfg = """ +configure +router bgp 65500 vrf vrf2 + address-family ipv4 unicast + rt vpn import 192.0.2.2:300 + exit-address-family +! +""" + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears[rname] + router.vtysh_cmd(cfg) + + check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_no_retain_init_plus_r2_vrf3.json") + check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json") + + check_show_bgp_vrf_ipv4(rname, "ipv4_vrf_all_routes_plus_r2_vrf3.json") + + +def test_bgp_no_retain_unimport_vrf3_step9(): + """ + Un-import r2 vrf3 into r1 vrf2 and check bgp tables + """ + + rname = "r1" + cfg = """ +configure +router bgp 65500 vrf vrf2 + address-family ipv4 unicast + no rt vpn import 192.0.2.2:300 + exit-address-family +! +""" + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears[rname] + router.vtysh_cmd(cfg) + + check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_no_retain_init.json") + check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json") + + check_show_bgp_vrf_ipv4(rname, "ipv4_vrf_all_routes_init.json") + + +def test_bgp_no_retain_import_vrf3_step10(): + """ + Import r2 vrf3 into r1 vrf2 and check bgp tables + """ + + rname = "r1" + cfg = """ +configure +router bgp 65500 vrf vrf2 + address-family ipv4 unicast + rt vpn import 192.0.2.2:300 + exit-address-family +! +""" + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears[rname] + router.vtysh_cmd(cfg) + + check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_no_retain_init_plus_r2_vrf3.json") + check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json") + + check_show_bgp_vrf_ipv4(rname, "ipv4_vrf_all_routes_plus_r2_vrf3.json") + + +def test_bgp_no_retain_remove_vrf2_step11(): + """ + Remove BGP vrf2 on r1 and check bgp tables + """ + + rname = "r1" + cfg = """ +configure +no router bgp 65500 vrf vrf2 +""" + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears[rname] + router.vtysh_cmd(cfg) + + check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_no_retain_init.json") + check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json") + + check_show_bgp_vrf_ipv4(rname, "ipv4_vrf_all_routes_init.json") + + +def test_bgp_retain_step12(): + """ + Configure retain and check bgp tables + """ + + rname = "r1" + cfg = """ +configure +router bgp 65500 + address-family ipv4 vpn + bgp retain route-target all +""" + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears[rname] + router.vtysh_cmd(cfg) + + check_show_bgp_ipv4_vpn(rname, "ipv4_vpn_routes_all.json") + check_show_bgp_ipv4_vpn("r2", "ipv4_vpn_routes_all.json") + + check_show_bgp_vrf_ipv4(rname, "ipv4_vrf_all_routes_init.json") + + def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() diff --git a/tests/topotests/bgp_vpnv4_per_nexthop_label/test_bgp_vpnv4_per_nexthop_label.py b/tests/topotests/bgp_vpnv4_per_nexthop_label/test_bgp_vpnv4_per_nexthop_label.py index 966b717ab2..d4c355a44a 100644 --- a/tests/topotests/bgp_vpnv4_per_nexthop_label/test_bgp_vpnv4_per_nexthop_label.py +++ b/tests/topotests/bgp_vpnv4_per_nexthop_label/test_bgp_vpnv4_per_nexthop_label.py @@ -151,6 +151,16 @@ def teardown_module(_mod): tgen.stop_topology() +def check_bgp_vpnv4_prefix_presence(router, prefix): + "Check the presence of a prefix" + tgen = get_topogen() + + dump = router.vtysh_cmd("show bgp ipv4 vpn {} json".format(prefix), isjson=True) + if not dump: + return "{}, prefix ipv4 vpn {} is not installed yet".format(router.name, prefix) + return None + + def bgp_vpnv4_table_check(router, group, label_list=None, label_value_expected=None): """ Dump and check that vpnv4 entries have the same MPLS label value @@ -163,6 +173,12 @@ def bgp_vpnv4_table_check(router, group, label_list=None, label_value_expected=N stored_label_inited = False for prefix in group: + test_func = functools.partial(check_bgp_vpnv4_prefix_presence, router, prefix) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "{}, prefix ipv4 vpn {} is not installed yet".format( + router.name, prefix + ) + dump = router.vtysh_cmd("show bgp ipv4 vpn {} json".format(prefix), isjson=True) assert dump, "{0}, {1}, route distinguisher not present".format( router.name, prefix @@ -232,54 +248,65 @@ def bgp_vpnv4_table_check_all(router, label_list=None, same=False): bgp_vpnv4_table_check(router, group=group, label_list=label_list) -def mpls_table_check(router, blacklist=None, label_list=None, whitelist=None): - """ - Dump and check 'show mpls table json' output. An assert is triggered in case test fails - * 'router': the router to check - * 'blacklist': the list of nexthops (IP or interface) that should not be on output - * 'label_list': the list of labels that should be in inLabel value - * 'whitelist': the list of nexthops (IP or interface) that should be on output - """ +def check_show_mpls_table(router, blacklist=None, label_list=None, whitelist=None): nexthop_list = [] if blacklist: nexthop_list.append(blacklist) - logger.info("Checking MPLS labels on {}".format(router.name)) + dump = router.vtysh_cmd("show mpls table json", isjson=True) for in_label, label_info in dump.items(): if label_list is not None: label_list.add(in_label) for nh in label_info["nexthops"]: - assert ( - nh["installed"] == True and nh["type"] == "BGP" - ), "{}, show mpls table, nexthop is not installed".format(router.name) - if "nexthop" in nh.keys(): - assert ( - nh["nexthop"] not in nexthop_list - ), "{}, show mpls table, duplicated or blacklisted nexthop address".format( + if "installed" not in nh.keys(): + return "{} {} is not installed yet on {}".format( + in_label, label_info, router.name + ) + if nh["installed"] != True or nh["type"] != "BGP": + return "{}, show mpls table, nexthop is not installed".format( router.name ) + if "nexthop" in nh.keys(): + if nh["nexthop"] in nexthop_list: + return "{}, show mpls table, duplicated or blacklisted nexthop address".format( + router.name + ) nexthop_list.append(nh["nexthop"]) elif "interface" in nh.keys(): - assert ( - nh["interface"] not in nexthop_list - ), "{}, show mpls table, duplicated or blacklisted nexthop interface".format( - router.name - ) + if nh["interface"] in nexthop_list: + return "{}, show mpls table, duplicated or blacklisted nexthop interface".format( + router.name + ) nexthop_list.append(nh["interface"]) else: - assert ( - 0 - ), "{}, show mpls table, entry with neither nexthop nor interface".format( + return "{}, show mpls table, entry with neither nexthop nor interface".format( router.name ) if whitelist: for entry in whitelist: - assert ( - entry in nexthop_list - ), "{}, show mpls table, entry with nexthop {} not present in nexthop list".format( - router.name, entry - ) + if entry not in nexthop_list: + return "{}, show mpls table, entry with nexthop {} not present in nexthop list".format( + router.name, entry + ) + return None + + +def mpls_table_check(router, blacklist=None, label_list=None, whitelist=None): + """ + Dump and check 'show mpls table json' output. An assert is triggered in case test fails + * 'router': the router to check + * 'blacklist': the list of nexthops (IP or interface) that should not be on output + * 'label_list': the list of labels that should be in inLabel value + * 'whitelist': the list of nexthops (IP or interface) that should be on output + """ + logger.info("Checking MPLS labels on {}".format(router.name)) + # Check r2 removed 172.31.0.30 vpnv4 update + test_func = functools.partial( + check_show_mpls_table, router, blacklist, label_list, whitelist + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "{}, MPLS labels check fail: {}".format(router.name, result) def check_show_bgp_vpn_prefix_not_found(router, ipversion, prefix, rd, label=None): diff --git a/tests/topotests/bgp_vpnv6_per_nexthop_label/test_bgp_vpnv6_per_nexthop_label.py b/tests/topotests/bgp_vpnv6_per_nexthop_label/test_bgp_vpnv6_per_nexthop_label.py index 719ba801c1..3d5f8f643b 100644 --- a/tests/topotests/bgp_vpnv6_per_nexthop_label/test_bgp_vpnv6_per_nexthop_label.py +++ b/tests/topotests/bgp_vpnv6_per_nexthop_label/test_bgp_vpnv6_per_nexthop_label.py @@ -54,7 +54,7 @@ PREFIXES_R11 = ["172:31::11/128", "172:31::20/128", "172:31::111/128"] PREFIXES_R12 = ["172:31::12/128", "172:31::15/128"] PREFIXES_REDIST_R14 = ["172:31::14/128"] -PREFIXES_CONNECTED = ["192:168::255/112", "192:2::/64"] +PREFIXES_CONNECTED = ["192:168::255:0/112", "192:2::/64"] def build_topo(tgen): @@ -150,6 +150,16 @@ def teardown_module(_mod): tgen.stop_topology() +def check_bgp_vpnv6_prefix_presence(router, prefix): + "Check the presence of a prefix" + tgen = get_topogen() + + dump = router.vtysh_cmd("show bgp ipv6 vpn {} json".format(prefix), isjson=True) + if not dump: + return "{}, prefix ipv6 vpn {} is not installed yet".format(router.name, prefix) + return None + + def bgp_vpnv6_table_check(router, group, label_list=None, label_value_expected=None): """ Dump and check that vpnv6 entries have the same MPLS label value @@ -162,6 +172,12 @@ def bgp_vpnv6_table_check(router, group, label_list=None, label_value_expected=N stored_label_inited = False for prefix in group: + test_func = functools.partial(check_bgp_vpnv6_prefix_presence, router, prefix) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "{}, prefix ipv6 vpn {} is not installed yet".format( + router.name, prefix + ) + dump = router.vtysh_cmd("show bgp ipv6 vpn {} json".format(prefix), isjson=True) for rd, pathes in dump.items(): for path in pathes["paths"]: @@ -226,54 +242,66 @@ def bgp_vpnv6_table_check_all(router, label_list=None, same=False): bgp_vpnv6_table_check(router, group=group, label_list=label_list) -def mpls_table_check(router, blacklist=None, label_list=None, whitelist=None): - """ - Dump and check 'show mpls table json' output. An assert is triggered in case test fails - * 'router': the router to check - * 'blacklist': the list of nexthops (IP or interface) that should not be on output - * 'label_list': the list of labels that should be in inLabel value - * 'whitelist': the list of nexthops (IP or interface) that should be on output - """ +def check_show_mpls_table(router, blacklist=None, label_list=None, whitelist=None): nexthop_list = [] if blacklist: nexthop_list.append(blacklist) - logger.info("Checking MPLS labels on {}".format(router.name)) + dump = router.vtysh_cmd("show mpls table json", isjson=True) for in_label, label_info in dump.items(): if label_list is not None: label_list.add(in_label) for nh in label_info["nexthops"]: - assert ( - nh["installed"] == True and nh["type"] == "BGP" - ), "{}, show mpls table, nexthop is not installed".format(router.name) - if "nexthop" in nh.keys(): - assert ( - nh["nexthop"] not in nexthop_list - ), "{}, show mpls table, duplicated or blacklisted nexthop address".format( + if "installed" not in nh.keys(): + return "{} {} is not installed yet on {}".format( + in_label, label_info, router.name + ) + if nh["installed"] != True or nh["type"] != "BGP": + return "{}, show mpls table, nexthop is not installed".format( router.name ) + if "nexthop" in nh.keys(): + if nh["nexthop"] in nexthop_list: + return "{}, show mpls table, duplicated or blacklisted nexthop address".format( + router.name + ) nexthop_list.append(nh["nexthop"]) elif "interface" in nh.keys(): - assert ( - nh["interface"] not in nexthop_list - ), "{}, show mpls table, duplicated or blacklisted nexthop interface".format( - router.name - ) + if nh["interface"] in nexthop_list: + return "{}, show mpls table, duplicated or blacklisted nexthop interface".format( + router.name + ) nexthop_list.append(nh["interface"]) else: - assert ( - 0 - ), "{}, show mpls table, entry with neither nexthop nor interface".format( + return "{}, show mpls table, entry with neither nexthop nor interface".format( router.name ) if whitelist: for entry in whitelist: - assert ( - entry in nexthop_list - ), "{}, show mpls table, entry with nexthop {} not present in nexthop list".format( - router.name, entry - ) + if entry not in nexthop_list: + return "{}, show mpls table, entry with nexthop {} not present in nexthop list".format( + router.name, entry + ) + return None + + +def mpls_table_check(router, blacklist=None, label_list=None, whitelist=None): + """ + Dump and check 'show mpls table json' output. An assert is triggered in case test fails + * 'router': the router to check + * 'blacklist': the list of nexthops (IP or interface) that should not be on output + * 'label_list': the list of labels that should be in inLabel value + * 'whitelist': the list of nexthops (IP or interface) that should be on output + """ + logger.info("Checking MPLS labels on {}".format(router.name)) + logger.info("Checking MPLS labels on {}".format(router.name)) + # Check r2 removed 172.31.0.30 vpnv4 update + test_func = functools.partial( + check_show_mpls_table, router, blacklist, label_list, whitelist + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert success, "{}, MPLS labels check fail: {}".format(router.name, result) def check_show_bgp_vpn_prefix_not_found(router, ipversion, prefix, rd, label=None): diff --git a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py index 6b9dc3e94a..32643c27b8 100644 --- a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py +++ b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py @@ -156,7 +156,6 @@ def test_bgp_best_path_with_dynamic_import_p0(request): check_router_status(tgen) for addr_type in ADDR_TYPES: - step( "Redistribute configured static routes into BGP process" " on R1/R2 and R3" ) @@ -188,7 +187,6 @@ def test_bgp_best_path_with_dynamic_import_p0(request): ) for addr_type in ADDR_TYPES: - step("Import from default vrf into vrf ISR on R1 and R2 as below") input_dict_vrf = {} @@ -246,7 +244,6 @@ def test_bgp_best_path_with_dynamic_import_p0(request): ) for addr_type in ADDR_TYPES: - step("Verify Pre-emption") input_routes_r3 = { @@ -278,7 +275,6 @@ def test_bgp_best_path_with_dynamic_import_p0(request): shutdown_bringup_interface(tgen, "r4", intf_r4_r1, False) for addr_type in ADDR_TYPES: - input_routes_r3 = { "r3": {"static_routes": [{"network": [NETWORK3_3[addr_type]]}]} } @@ -309,7 +305,6 @@ def test_bgp_best_path_with_dynamic_import_p0(request): shutdown_bringup_interface(tgen, "r4", intf_r4_r1, True) for addr_type in ADDR_TYPES: - input_routes_r3 = { "r3": {"static_routes": [{"network": [NETWORK3_3[addr_type]]}]} } @@ -339,7 +334,6 @@ def test_bgp_best_path_with_dynamic_import_p0(request): step("Active-Standby scenario(as-path prepend and Local pref)") for addr_type in ADDR_TYPES: - step("Create prefix-list") input_dict_pf = { @@ -363,7 +357,6 @@ def test_bgp_best_path_with_dynamic_import_p0(request): ) for addr_type in ADDR_TYPES: - step("Create route-map to match prefix-list and set localpref 500") input_dict_rm = { @@ -471,15 +464,10 @@ def test_bgp_best_path_with_dynamic_import_p0(request): attribute = "locPrf" for addr_type in ADDR_TYPES: - step("Verify bestpath is installed as per highest localpref") input_routes_r3 = { - "r3": { - "static_routes": [ - {"network": [NETWORK3_3[addr_type], NETWORK3_4[addr_type]]} - ] - } + "r3": {"static_routes": [{"network": [NETWORK3_4[addr_type]]}]} } result = verify_best_path_as_per_bgp_attribute( @@ -490,7 +478,6 @@ def test_bgp_best_path_with_dynamic_import_p0(request): ) for addr_type in ADDR_TYPES: - step("Create route-map to match prefix-list and set localpref 700") input_dict_rm = { @@ -518,15 +505,10 @@ def test_bgp_best_path_with_dynamic_import_p0(request): ) for addr_type in ADDR_TYPES: - step("Verify bestpath is changed as per highest localpref") input_routes_r3 = { - "r3": { - "static_routes": [ - {"network": [NETWORK3_3[addr_type], NETWORK3_4[addr_type]]} - ] - } + "r3": {"static_routes": [{"network": [NETWORK3_4[addr_type]]}]} } result = verify_best_path_as_per_bgp_attribute( @@ -537,7 +519,6 @@ def test_bgp_best_path_with_dynamic_import_p0(request): ) for addr_type in ADDR_TYPES: - step("Create route-map to match prefix-list and set as-path prepend") input_dict_rm = { @@ -570,15 +551,10 @@ def test_bgp_best_path_with_dynamic_import_p0(request): attribute = "path" for addr_type in ADDR_TYPES: - step("Verify bestpath is changed as per shortest as-path") input_routes_r3 = { - "r3": { - "static_routes": [ - {"network": [NETWORK3_3[addr_type], NETWORK3_4[addr_type]]} - ] - } + "r3": {"static_routes": [{"network": [NETWORK3_4[addr_type]]}]} } result = verify_best_path_as_per_bgp_attribute( @@ -607,7 +583,6 @@ def test_modify_route_map_match_set_clauses_p1(request): check_router_status(tgen) for addr_type in ADDR_TYPES: - step( "Configure route-map to set community attribute for a specific" "prefix on R1 in vrf ISR" @@ -672,7 +647,6 @@ def test_modify_route_map_match_set_clauses_p1(request): ) for addr_type in ADDR_TYPES: - step( "Apply this route-map on R1 to vrf ISR while redistributing the" " prefixes into BGP" @@ -714,7 +688,6 @@ def test_modify_route_map_match_set_clauses_p1(request): ) for addr_type in ADDR_TYPES: - step( "Configure another route-map for filtering the prefixes based on" " community attribute while importing into default vrf" @@ -740,7 +713,6 @@ def test_modify_route_map_match_set_clauses_p1(request): ) for addr_type in ADDR_TYPES: - step( "Apply the route-map while Importing vrf ISR's prefixes into " "default vrf on router R1:" @@ -787,7 +759,6 @@ def test_modify_route_map_match_set_clauses_p1(request): ) for addr_type in ADDR_TYPES: - step( "Verify on R1 that only prefixes with community value 100:100" "in vrf ISR are imported to vrf default. While importing, the" @@ -808,7 +779,6 @@ def test_modify_route_map_match_set_clauses_p1(request): ) for addr_type in ADDR_TYPES: - step("Add set clause in route-map IMP:") input_dict_rm = { @@ -835,7 +805,6 @@ def test_modify_route_map_match_set_clauses_p1(request): ) for addr_type in ADDR_TYPES: - step( "Verify that as we continue adding different attributes " "step-by-step in route-map IMP those attributes gets " @@ -898,7 +867,6 @@ def test_modify_route_map_match_set_clauses_p1(request): assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) for addr_type in ADDR_TYPES: - input_routes_r1 = { "r1": { "static_routes": [ diff --git a/tests/topotests/bgp_vrf_leaking_5549_routes/ce1/bgpd.conf b/tests/topotests/bgp_vrf_leaking_5549_routes/ce1/bgpd.conf index 66493f0fea..eb2563d5a9 100644 --- a/tests/topotests/bgp_vrf_leaking_5549_routes/ce1/bgpd.conf +++ b/tests/topotests/bgp_vrf_leaking_5549_routes/ce1/bgpd.conf @@ -4,7 +4,6 @@ hostname ce1 password zebra ! log stdout notifications -log monitor notifications log commands ! router bgp 65002 diff --git a/tests/topotests/bgp_vrf_leaking_5549_routes/pe1/bgpd.conf b/tests/topotests/bgp_vrf_leaking_5549_routes/pe1/bgpd.conf index c5c99270e7..bbc5ae502f 100644 --- a/tests/topotests/bgp_vrf_leaking_5549_routes/pe1/bgpd.conf +++ b/tests/topotests/bgp_vrf_leaking_5549_routes/pe1/bgpd.conf @@ -4,7 +4,6 @@ hostname pe1 password zebra ! log stdout notifications -log monitor notifications log commands ! router bgp 65001 diff --git a/tests/topotests/bgp_vrf_lite_best_path_test/test_bgp_vrf_lite_best_path_topo1.py b/tests/topotests/bgp_vrf_lite_best_path_test/test_bgp_vrf_lite_best_path_topo1.py index 934c4dc05f..f3521969d3 100644 --- a/tests/topotests/bgp_vrf_lite_best_path_test/test_bgp_vrf_lite_best_path_topo1.py +++ b/tests/topotests/bgp_vrf_lite_best_path_test/test_bgp_vrf_lite_best_path_topo1.py @@ -52,7 +52,7 @@ verify_bgp_community, verify_bgp_rib, clear_bgp, - verify_best_path_as_per_bgp_attribute + verify_best_path_as_per_bgp_attribute, ) from lib.topojson import build_config_from_json @@ -463,7 +463,6 @@ def test_bgp_best_path_with_dynamic_import_p0(request): check_router_status(tgen) for addr_type in ADDR_TYPES: - step( "Redistribute configured static routes into BGP process" " on R1/R2 and R3" ) @@ -495,7 +494,6 @@ def test_bgp_best_path_with_dynamic_import_p0(request): ) for addr_type in ADDR_TYPES: - step("Import from default vrf into vrf ISR on R1 and R2 as below") input_dict_vrf = {} @@ -553,7 +551,6 @@ def test_bgp_best_path_with_dynamic_import_p0(request): ) for addr_type in ADDR_TYPES: - step("Verify Pre-emption") input_routes_r3 = { @@ -585,7 +582,6 @@ def test_bgp_best_path_with_dynamic_import_p0(request): shutdown_bringup_interface(tgen, "r4", intf_r4_r1, False) for addr_type in ADDR_TYPES: - input_routes_r3 = { "r3": {"static_routes": [{"network": [NETWORK3_3[addr_type]]}]} } @@ -616,7 +612,6 @@ def test_bgp_best_path_with_dynamic_import_p0(request): shutdown_bringup_interface(tgen, "r4", intf_r4_r1, True) for addr_type in ADDR_TYPES: - input_routes_r3 = { "r3": {"static_routes": [{"network": [NETWORK3_3[addr_type]]}]} } @@ -646,7 +641,6 @@ def test_bgp_best_path_with_dynamic_import_p0(request): step("Active-Standby scenario(as-path prepend and Local pref)") for addr_type in ADDR_TYPES: - step("Create prefix-list") input_dict_pf = { @@ -670,7 +664,6 @@ def test_bgp_best_path_with_dynamic_import_p0(request): ) for addr_type in ADDR_TYPES: - step("Create route-map to match prefix-list and set localpref 500") input_dict_rm = { @@ -778,15 +771,10 @@ def test_bgp_best_path_with_dynamic_import_p0(request): attribute = "locPrf" for addr_type in ADDR_TYPES: - step("Verify bestpath is installed as per highest localpref") input_routes_r3 = { - "r3": { - "static_routes": [ - {"network": [NETWORK3_3[addr_type], NETWORK3_4[addr_type]]} - ] - } + "r3": {"static_routes": [{"network": [NETWORK3_4[addr_type]]}]} } result = verify_best_path_as_per_bgp_attribute( @@ -797,7 +785,6 @@ def test_bgp_best_path_with_dynamic_import_p0(request): ) for addr_type in ADDR_TYPES: - step("Create route-map to match prefix-list and set localpref 700") input_dict_rm = { @@ -825,15 +812,10 @@ def test_bgp_best_path_with_dynamic_import_p0(request): ) for addr_type in ADDR_TYPES: - step("Verify bestpath is changed as per highest localpref") input_routes_r3 = { - "r3": { - "static_routes": [ - {"network": [NETWORK3_3[addr_type], NETWORK3_4[addr_type]]} - ] - } + "r3": {"static_routes": [{"network": [NETWORK3_4[addr_type]]}]} } result = verify_best_path_as_per_bgp_attribute( @@ -844,7 +826,6 @@ def test_bgp_best_path_with_dynamic_import_p0(request): ) for addr_type in ADDR_TYPES: - step("Create route-map to match prefix-list and set as-path prepend") input_dict_rm = { @@ -877,15 +858,10 @@ def test_bgp_best_path_with_dynamic_import_p0(request): attribute = "path" for addr_type in ADDR_TYPES: - step("Verify bestpath is changed as per shortest as-path") input_routes_r3 = { - "r3": { - "static_routes": [ - {"network": [NETWORK3_3[addr_type], NETWORK3_4[addr_type]]} - ] - } + "r3": {"static_routes": [{"network": [NETWORK3_4[addr_type]]}]} } result = verify_best_path_as_per_bgp_attribute( diff --git a/tests/topotests/bgp_vrf_md5_peering/peer1/exabgp.cfg b/tests/topotests/bgp_vrf_md5_peering/peer1/exabgp.cfg index 3260513903..11a827a904 100644 --- a/tests/topotests/bgp_vrf_md5_peering/peer1/exabgp.cfg +++ b/tests/topotests/bgp_vrf_md5_peering/peer1/exabgp.cfg @@ -3,7 +3,7 @@ neighbor 10.0.0.1 { local-address 10.0.0.2; local-as 65001; peer-as 65534; - md5 test123; + md5-password test123; static { route 192.168.100.1/32 { diff --git a/tests/topotests/bgp_vrf_netns/exabgp.env b/tests/topotests/bgp_vrf_netns/exabgp.env index a328e04962..ec978c66e7 100644 --- a/tests/topotests/bgp_vrf_netns/exabgp.env +++ b/tests/topotests/bgp_vrf_netns/exabgp.env @@ -1,5 +1,6 @@ [exabgp.api] +ack = false encoder = text highres = false respawn = false diff --git a/tests/topotests/bgp_vrf_netns/peer1/exa-send.py b/tests/topotests/bgp_vrf_netns/peer1/exa-send.py index ab0eb8ce8f..c6a4499bd3 100755 --- a/tests/topotests/bgp_vrf_netns/peer1/exa-send.py +++ b/tests/topotests/bgp_vrf_netns/peer1/exa-send.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ exa-send.py: Send a few testroutes with ExaBGP diff --git a/tests/topotests/bgp_vrf_netns/peer1/exabgp.cfg b/tests/topotests/bgp_vrf_netns/peer1/exabgp.cfg index 2d0ca89f0f..97a024ce96 100644 --- a/tests/topotests/bgp_vrf_netns/peer1/exabgp.cfg +++ b/tests/topotests/bgp_vrf_netns/peer1/exabgp.cfg @@ -1,21 +1,18 @@ -group controller { - - process announce-routes { - run "/etc/exabgp/exa-send.py 1 10"; - } - - process receive-routes { - run "/etc/exabgp/exa-receive.py 1"; - receive-routes; - encoder text; - } +process announce-routes { + run /etc/exabgp/exa-send.py 1 10; + encoder text; +} - neighbor 10.0.1.1 { - router-id 10.0.1.101; - local-address 10.0.1.101; - local-as 99; - peer-as 100; - graceful-restart; - } +process receive-routes { + run /etc/exabgp/exa-receive.py 1; + encoder text; +} +neighbor 10.0.1.1 { + router-id 10.0.1.101; + local-address 10.0.1.101; + local-as 99; + peer-as 100; + capability {graceful-restart;} + api {processes [ announce-routes, receive-routes ];} } diff --git a/tests/topotests/config_timing/r1/zebra.conf b/tests/topotests/config_timing/r1/zebra.conf index 46fd965034..b4dc338b8d 100644 --- a/tests/topotests/config_timing/r1/zebra.conf +++ b/tests/topotests/config_timing/r1/zebra.conf @@ -4,10 +4,8 @@ ip prefix-list ANY permit 0.0.0.0/0 le 32 ipv6 prefix-list ANY seq 10 permit any route-map RM-NONE4 deny 10 -exit-route-map route-map RM-NONE6 deny 10 -exit-route-map interface r1-eth0 ip address 100.0.0.1/24 diff --git a/tests/topotests/conftest.py b/tests/topotests/conftest.py index b78a2f1052..b1f8d50d06 100755 --- a/tests/topotests/conftest.py +++ b/tests/topotests/conftest.py @@ -4,6 +4,7 @@ """ # pylint: disable=consider-using-f-string +import contextlib import glob import logging import os @@ -12,6 +13,7 @@ import subprocess import sys import time +from pathlib import Path import lib.fixtures import pytest @@ -24,7 +26,7 @@ from munet.cleanup import cleanup_current, cleanup_previous from munet.config import ConfigOptionsProxy from munet.testing.util import pause_test - +from lib.common_config import generate_support_bundle from lib import topolog, topotest try: @@ -41,6 +43,30 @@ def rundir_module(pytestconfig): pass +# Remove this and use munet version when we move to pytest_asyncio +@contextlib.contextmanager +def chdir(ndir, desc=""): + odir = os.getcwd() + os.chdir(ndir) + if desc: + logging.debug("%s: chdir from %s to %s", desc, odir, ndir) + try: + yield + finally: + if desc: + logging.debug("%s: chdir back from %s to %s", desc, ndir, odir) + os.chdir(odir) + + +@contextlib.contextmanager +def log_handler(basename, logpath): + topolog.logstart(basename, logpath) + try: + yield + finally: + topolog.logfinish(basename, logpath) + + def pytest_addoption(parser): """ Add topology-only option to the topology tester. This option makes pytest @@ -76,6 +102,12 @@ def pytest_addoption(parser): help="Comma-separated list of routers to spawn gdb on, or 'all'", ) + parser.addoption( + "--gdb-use-emacs", + action="store_true", + help="Use emacsclient to run gdb instead of a shell", + ) + parser.addoption( "--logd", action="append", @@ -141,6 +173,24 @@ def pytest_addoption(parser): help="Options to pass to `perf record`.", ) + parser.addoption( + "--rr-daemons", + metavar="DAEMON[,DAEMON...]", + help="Comma-separated list of daemons to run `rr` on, or 'all'", + ) + + parser.addoption( + "--rr-routers", + metavar="ROUTER[,ROUTER...]", + help="Comma-separated list of routers to run `rr` on, or 'all'", + ) + + parser.addoption( + "--rr-options", + metavar="OPTS", + help="Options to pass to `rr record`.", + ) + rundir_help = "directory for running in and log files" parser.addini("rundir", rundir_help, default="/tmp/topotests") parser.addoption("--rundir", metavar="DIR", help=rundir_help) @@ -176,6 +226,12 @@ def pytest_addoption(parser): help="Generate suppression file, and enable more precise (slower) valgrind checks", ) + parser.addoption( + "--valgrind-leak-kinds", + metavar="KIND[,KIND...]", + help="Comma-separated list of valgrind leak kinds or 'all'", + ) + parser.addoption( "--valgrind-memleaks", action="store_true", @@ -271,6 +327,70 @@ def check_for_memleaks(): pytest.fail("memleaks found for daemons: " + " ".join(daemons)) +def check_for_core_dumps(): + tgen = get_topogen() # pylint: disable=redefined-outer-name + if not tgen: + return + + if not hasattr(tgen, "existing_core_files"): + tgen.existing_core_files = set() + existing = tgen.existing_core_files + + cores = glob.glob(os.path.join(tgen.logdir, "*/*.dmp")) + latest = {x for x in cores if x not in existing} + if latest: + existing |= latest + tgen.existing_core_files = existing + + emsg = "New core[s] found: " + ", ".join(latest) + logger.error(emsg) + pytest.fail(emsg) + + +def check_for_backtraces(): + tgen = get_topogen() # pylint: disable=redefined-outer-name + if not tgen: + return + + if not hasattr(tgen, "existing_backtrace_files"): + tgen.existing_backtrace_files = {} + existing = tgen.existing_backtrace_files + + latest = glob.glob(os.path.join(tgen.logdir, "*/*.log")) + backtraces = [] + for vfile in latest: + with open(vfile, encoding="ascii") as vf: + vfcontent = vf.read() + btcount = vfcontent.count("Backtrace:") + if not btcount: + continue + if vfile not in existing: + existing[vfile] = 0 + if btcount == existing[vfile]: + continue + existing[vfile] = btcount + backtraces.append(vfile) + + if backtraces: + emsg = "New backtraces found in: " + ", ".join(backtraces) + logger.error(emsg) + pytest.fail(emsg) + + +@pytest.fixture(autouse=True, scope="module") +def module_autouse(request): + basename = get_test_logdir(request.node.nodeid, True) + logdir = Path(topotest.g_pytest_config.option.rundir) / basename + logpath = logdir / "exec.log" + + subprocess.check_call("mkdir -p -m 1777 {}".format(logdir), shell=True) + + with log_handler(basename, logpath): + sdir = os.path.dirname(os.path.realpath(request.fspath)) + with chdir(sdir, "module autouse fixture"): + yield + + @pytest.fixture(autouse=True, scope="module") def module_check_memtest(request): yield @@ -282,14 +402,19 @@ def module_check_memtest(request): check_for_memleaks() -def pytest_runtest_logstart(nodeid, location): - # location is (filename, lineno, testname) - topolog.logstart(nodeid, location, topotest.g_pytest_config.option.rundir) - - -def pytest_runtest_logfinish(nodeid, location): - # location is (filename, lineno, testname) - topolog.logfinish(nodeid, location) +# +# Disable per test function logging as FRR CI system can't handle it. +# +# @pytest.fixture(autouse=True, scope="function") +# def function_autouse(request): +# # For tests we actually use the logdir name as the logfile base +# logbase = get_test_logdir(nodeid=request.node.nodeid, module=False) +# logbase = os.path.join(topotest.g_pytest_config.option.rundir, logbase) +# logpath = Path(logbase) +# path = Path(f"{logpath.parent}/exec-{logpath.name}.log") +# subprocess.check_call("mkdir -p -m 1777 {}".format(logpath.parent), shell=True) +# with log_handler(request.node.nodeid, path): +# yield @pytest.hookimpl(hookwrapper=True) @@ -304,9 +429,13 @@ def pytest_runtest_call(item: pytest.Item) -> None: # Let the default pytest_runtest_call execute the test function yield + check_for_backtraces() + check_for_core_dumps() + # Check for leaks if requested if item.config.option.valgrind_memleaks: check_for_valgrind_memleaks() + if item.config.option.memleaks: check_for_memleaks() @@ -340,8 +469,10 @@ def pytest_configure(config): os.environ["PYTEST_TOPOTEST_WORKER"] = "" is_xdist = os.environ["PYTEST_XDIST_MODE"] != "no" is_worker = False + wname = "" else: - os.environ["PYTEST_TOPOTEST_WORKER"] = os.environ["PYTEST_XDIST_WORKER"] + wname = os.environ["PYTEST_XDIST_WORKER"] + os.environ["PYTEST_TOPOTEST_WORKER"] = wname is_xdist = True is_worker = True @@ -375,6 +506,16 @@ def pytest_configure(config): if not config.getoption("--log-file") and not config.getini("log_file"): config.option.log_file = os.path.join(rundir, "exec.log") + # Handle pytest-xdist each worker get's it's own top level log file + # `exec-worker-N.log` + if wname: + wname = wname.replace("gw", "worker-") + cpath = Path(config.option.log_file).absolute() + config.option.log_file = f"{cpath.parent}/{cpath.stem}-{wname}{cpath.suffix}" + elif is_xdist: + cpath = Path(config.option.log_file).absolute() + config.option.log_file = f"{cpath.parent}/{cpath.stem}-xdist{cpath.suffix}" + # Turn on live logging if user specified verbose and the config has a CLI level set if config.getoption("--verbose") and not is_xdist and not config.getini("log_cli"): if config.getoption("--log-cli-level", None) is None: @@ -433,6 +574,10 @@ def assert_feature_windows(b, feature): @pytest.fixture(autouse=True, scope="session") def setup_session_auto(): + # Aligns logs nicely + logging.addLevelName(logging.WARNING, " WARN") + logging.addLevelName(logging.INFO, " INFO") + if "PYTEST_TOPOTEST_WORKER" not in os.environ: is_worker = False elif not os.environ["PYTEST_TOPOTEST_WORKER"]: @@ -455,6 +600,10 @@ def pytest_runtest_setup(item): os.environ["PYTEST_TOPOTEST_SCRIPTDIR"] = script_dir +def pytest_exception_interact(node, call, report): + generate_support_bundle() + + def pytest_runtest_makereport(item, call): "Log all assert messages to default logger with error level" diff --git a/tests/topotests/cspf_topo1/r1/isisd.conf b/tests/topotests/cspf_topo1/r1/isisd.conf index 788ac5b7ae..2dc73291d3 100644 --- a/tests/topotests/cspf_topo1/r1/isisd.conf +++ b/tests/topotests/cspf_topo1/r1/isisd.conf @@ -11,14 +11,16 @@ interface r1-eth0 ip router isis TE isis circuit-type level-2-only isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface r1-eth1 ip router isis TE ipv6 router isis TE isis circuit-type level-2-only isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! router isis TE net 49.0000.0000.0000.0001.00 diff --git a/tests/topotests/cspf_topo1/r1/sharpd.conf b/tests/topotests/cspf_topo1/r1/sharpd.conf index 272eac944e..465034f150 100644 --- a/tests/topotests/cspf_topo1/r1/sharpd.conf +++ b/tests/topotests/cspf_topo1/r1/sharpd.conf @@ -1,3 +1,2 @@ ! -import-te ! diff --git a/tests/topotests/cspf_topo1/r2/isisd.conf b/tests/topotests/cspf_topo1/r2/isisd.conf index 04df685e9c..59bb3be2a1 100644 --- a/tests/topotests/cspf_topo1/r2/isisd.conf +++ b/tests/topotests/cspf_topo1/r2/isisd.conf @@ -13,27 +13,31 @@ interface r2-eth0 ip router isis TE isis circuit-type level-2-only isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface r2-eth1 ip router isis TE ipv6 router isis TE isis circuit-type level-2-only isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface r2-eth2 ip router isis TE ipv6 router isis TE isis circuit-type level-2-only isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface r2-eth3 ip router isis TE isis circuit-type level-2-only isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! router isis TE net 49.0000.0000.0000.0002.00 diff --git a/tests/topotests/cspf_topo1/r3/isisd.conf b/tests/topotests/cspf_topo1/r3/isisd.conf index 9db82c7b2b..7d3e4de921 100644 --- a/tests/topotests/cspf_topo1/r3/isisd.conf +++ b/tests/topotests/cspf_topo1/r3/isisd.conf @@ -14,13 +14,15 @@ interface r3-eth0 ipv6 router isis TE isis circuit-type level-2-only isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface r3-eth1 ipv6 router isis TE isis circuit-type level-2-only isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! ! router isis TE diff --git a/tests/topotests/cspf_topo1/r4/isisd.conf b/tests/topotests/cspf_topo1/r4/isisd.conf index c5c4d4e056..674b7387cc 100644 --- a/tests/topotests/cspf_topo1/r4/isisd.conf +++ b/tests/topotests/cspf_topo1/r4/isisd.conf @@ -15,13 +15,15 @@ interface r4-eth0 ip router isis TE isis circuit-type level-2-only isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface r4-eth1 ipv6 router isis TE isis circuit-type level-2-only isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! ! router isis TE diff --git a/tests/topotests/grpc_basic/test_basic_grpc.py b/tests/topotests/grpc_basic/test_basic_grpc.py index 88bfa98d2f..bb57705a70 100644 --- a/tests/topotests/grpc_basic/test_basic_grpc.py +++ b/tests/topotests/grpc_basic/test_basic_grpc.py @@ -30,7 +30,7 @@ GRPCP_PIMD = 50056 pytestmark = [ - # pytest.mark.mgmtd -- Need a new non-protocol marker + pytest.mark.mgmtd, # pytest.mark.bfdd, # pytest.mark.isisd, # pytest.mark.ospfd, diff --git a/tests/topotests/isis_lfa_topo1/rt1/isisd.conf b/tests/topotests/isis_lfa_topo1/rt1/isisd.conf index 833cd66ced..fc81df02cb 100644 --- a/tests/topotests/isis_lfa_topo1/rt1/isisd.conf +++ b/tests/topotests/isis_lfa_topo1/rt1/isisd.conf @@ -14,32 +14,37 @@ interface lo interface eth-rt2 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! interface eth-rt3 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! interface eth-rt4 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! interface eth-rt5 ipv6 router isis 1 isis metric 20 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! interface eth-rt6 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! router isis 1 diff --git a/tests/topotests/isis_lfa_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_lfa_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref index d8a7c5a9c4..92dd7b5e68 100644 --- a/tests/topotests/isis_lfa_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_lfa_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0002", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -49,7 +49,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0004", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -68,7 +68,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0005", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -87,7 +87,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0006", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_lfa_topo1/rt2/isisd.conf b/tests/topotests/isis_lfa_topo1/rt2/isisd.conf index 42dee00e60..6981692add 100644 --- a/tests/topotests/isis_lfa_topo1/rt2/isisd.conf +++ b/tests/topotests/isis_lfa_topo1/rt2/isisd.conf @@ -14,21 +14,24 @@ interface lo interface eth-rt1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! interface eth-rt3 ipv6 router isis 1 isis metric 5 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! interface eth-rt7 ipv6 router isis 1 isis metric 5 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! router isis 1 diff --git a/tests/topotests/isis_lfa_topo1/rt2/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_lfa_topo1/rt2/step1/show_yang_interface_isis_adjacencies.ref index 681c5222ad..236a41d426 100644 --- a/tests/topotests/isis_lfa_topo1/rt2/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_lfa_topo1/rt2/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0001", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -49,7 +49,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0007", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_lfa_topo1/rt3/isisd.conf b/tests/topotests/isis_lfa_topo1/rt3/isisd.conf index 9dd813cff6..e3ddb0984b 100644 --- a/tests/topotests/isis_lfa_topo1/rt3/isisd.conf +++ b/tests/topotests/isis_lfa_topo1/rt3/isisd.conf @@ -14,20 +14,23 @@ interface lo interface eth-rt1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! interface eth-rt2 ipv6 router isis 1 isis metric 5 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! interface eth-rt7 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! router isis 1 diff --git a/tests/topotests/isis_lfa_topo1/rt3/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_lfa_topo1/rt3/step1/show_yang_interface_isis_adjacencies.ref index 1495e32284..290ebb96cf 100644 --- a/tests/topotests/isis_lfa_topo1/rt3/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_lfa_topo1/rt3/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0001", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0002", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -49,7 +49,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0007", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_lfa_topo1/rt4/isisd.conf b/tests/topotests/isis_lfa_topo1/rt4/isisd.conf index 7500ff8d7b..4db5c8ed05 100644 --- a/tests/topotests/isis_lfa_topo1/rt4/isisd.conf +++ b/tests/topotests/isis_lfa_topo1/rt4/isisd.conf @@ -14,14 +14,16 @@ interface lo interface eth-rt1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! interface eth-rt7 ipv6 router isis 1 isis metric 15 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! router isis 1 diff --git a/tests/topotests/isis_lfa_topo1/rt4/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_lfa_topo1/rt4/step1/show_yang_interface_isis_adjacencies.ref index d8cd565b5b..1f99ad120c 100644 --- a/tests/topotests/isis_lfa_topo1/rt4/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_lfa_topo1/rt4/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0001", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0007", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_lfa_topo1/rt5/isisd.conf b/tests/topotests/isis_lfa_topo1/rt5/isisd.conf index 5e022e9ad8..1206a4e51f 100644 --- a/tests/topotests/isis_lfa_topo1/rt5/isisd.conf +++ b/tests/topotests/isis_lfa_topo1/rt5/isisd.conf @@ -15,13 +15,15 @@ interface eth-rt1 ipv6 router isis 1 isis metric 20 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! interface eth-rt7 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! router isis 1 diff --git a/tests/topotests/isis_lfa_topo1/rt5/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_lfa_topo1/rt5/step1/show_yang_interface_isis_adjacencies.ref index d8cd565b5b..1f99ad120c 100644 --- a/tests/topotests/isis_lfa_topo1/rt5/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_lfa_topo1/rt5/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0001", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0007", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_lfa_topo1/rt6/isisd.conf b/tests/topotests/isis_lfa_topo1/rt6/isisd.conf index d262e8a564..2ba9e49919 100644 --- a/tests/topotests/isis_lfa_topo1/rt6/isisd.conf +++ b/tests/topotests/isis_lfa_topo1/rt6/isisd.conf @@ -14,13 +14,15 @@ interface lo interface eth-rt1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! interface eth-rt7 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! router isis 1 diff --git a/tests/topotests/isis_lfa_topo1/rt6/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_lfa_topo1/rt6/step1/show_yang_interface_isis_adjacencies.ref index d8cd565b5b..1f99ad120c 100644 --- a/tests/topotests/isis_lfa_topo1/rt6/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_lfa_topo1/rt6/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0001", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0007", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_lfa_topo1/rt7/isisd.conf b/tests/topotests/isis_lfa_topo1/rt7/isisd.conf index c2061236c3..060be2bf6d 100644 --- a/tests/topotests/isis_lfa_topo1/rt7/isisd.conf +++ b/tests/topotests/isis_lfa_topo1/rt7/isisd.conf @@ -15,32 +15,37 @@ interface eth-rt2 ipv6 router isis 1 isis metric 5 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! interface eth-rt3 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! interface eth-rt4 ipv6 router isis 1 isis metric 15 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! interface eth-rt5 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! interface eth-rt6 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute lfa ! router isis 1 diff --git a/tests/topotests/isis_lfa_topo1/rt7/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_lfa_topo1/rt7/step1/show_yang_interface_isis_adjacencies.ref index d8a7c5a9c4..92dd7b5e68 100644 --- a/tests/topotests/isis_lfa_topo1/rt7/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_lfa_topo1/rt7/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0002", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -49,7 +49,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0004", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -68,7 +68,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0005", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -87,7 +87,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0006", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_lsp_bits_topo1/rt1/isisd.conf b/tests/topotests/isis_lsp_bits_topo1/rt1/isisd.conf index fc004e429b..51bf7e60a5 100644 --- a/tests/topotests/isis_lsp_bits_topo1/rt1/isisd.conf +++ b/tests/topotests/isis_lsp_bits_topo1/rt1/isisd.conf @@ -16,7 +16,8 @@ interface lo interface eth-sw1 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis priority 100 ! router isis 1 diff --git a/tests/topotests/isis_lsp_bits_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_lsp_bits_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref index 26f0dffa7a..9c5901b90f 100644 --- a/tests/topotests/isis_lsp_bits_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_lsp_bits_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref @@ -11,14 +11,14 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 64, "state": "up" }, { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0002", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 64, "state": "up" } diff --git a/tests/topotests/isis_lsp_bits_topo1/rt2/isisd.conf b/tests/topotests/isis_lsp_bits_topo1/rt2/isisd.conf index d01720f4f0..96c9f33dae 100644 --- a/tests/topotests/isis_lsp_bits_topo1/rt2/isisd.conf +++ b/tests/topotests/isis_lsp_bits_topo1/rt2/isisd.conf @@ -15,13 +15,15 @@ interface lo interface eth-sw1 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface eth-rt4 ip router isis 2 ipv6 router isis 2 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! router isis 1 net 49.0000.0000.0000.0002.00 diff --git a/tests/topotests/isis_lsp_bits_topo1/rt2/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_lsp_bits_topo1/rt2/step1/show_yang_interface_isis_adjacencies.ref index c70b44e1c9..b56fe12368 100644 --- a/tests/topotests/isis_lsp_bits_topo1/rt2/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_lsp_bits_topo1/rt2/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1-2", "neighbor-sysid": "0000.0000.0004", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,21 +30,21 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0001", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 100, "state": "up" }, { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 64, "state": "up" }, { "neighbor-sys-type": "level-2", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 64, "state": "up" } diff --git a/tests/topotests/isis_lsp_bits_topo1/rt3/isisd.conf b/tests/topotests/isis_lsp_bits_topo1/rt3/isisd.conf index a8d589678a..c3354f2e68 100644 --- a/tests/topotests/isis_lsp_bits_topo1/rt3/isisd.conf +++ b/tests/topotests/isis_lsp_bits_topo1/rt3/isisd.conf @@ -15,13 +15,15 @@ interface lo interface eth-sw1 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface eth-rt5 ip router isis 2 ipv6 router isis 2 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! router isis 1 net 49.0000.0000.0000.0003.00 diff --git a/tests/topotests/isis_lsp_bits_topo1/rt3/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_lsp_bits_topo1/rt3/step1/show_yang_interface_isis_adjacencies.ref index 6950086b1e..279d4dc131 100644 --- a/tests/topotests/isis_lsp_bits_topo1/rt3/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_lsp_bits_topo1/rt3/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1-2", "neighbor-sysid": "0000.0000.0005", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,14 +30,14 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0001", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 100, "state": "up" }, { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0002", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 64, "state": "up" } diff --git a/tests/topotests/isis_lsp_bits_topo1/rt4/isisd.conf b/tests/topotests/isis_lsp_bits_topo1/rt4/isisd.conf index 2d30790f29..f1627e7547 100644 --- a/tests/topotests/isis_lsp_bits_topo1/rt4/isisd.conf +++ b/tests/topotests/isis_lsp_bits_topo1/rt4/isisd.conf @@ -16,19 +16,22 @@ interface eth-rt2 ip router isis 2 ipv6 router isis 2 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface eth-rt5 ip router isis 4 ipv6 router isis 4 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface eth-rt6 ip router isis 4 ipv6 router isis 4 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! router isis 2 net 49.0002.0000.0000.0004.00 diff --git a/tests/topotests/isis_lsp_bits_topo1/rt4/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_lsp_bits_topo1/rt4/step1/show_yang_interface_isis_adjacencies.ref index 233180ceb8..39ee61211a 100644 --- a/tests/topotests/isis_lsp_bits_topo1/rt4/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_lsp_bits_topo1/rt4/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1-2", "neighbor-sysid": "0000.0000.0002", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1-2", "neighbor-sysid": "0000.0000.0005", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -49,7 +49,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0006", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_lsp_bits_topo1/rt5/isisd.conf b/tests/topotests/isis_lsp_bits_topo1/rt5/isisd.conf index 263c3f9478..41241590d1 100644 --- a/tests/topotests/isis_lsp_bits_topo1/rt5/isisd.conf +++ b/tests/topotests/isis_lsp_bits_topo1/rt5/isisd.conf @@ -16,19 +16,22 @@ interface eth-rt3 ip router isis 2 ipv6 router isis 2 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface eth-rt4 ip router isis 4 ipv6 router isis 4 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface eth-rt6 ip router isis 4 ipv6 router isis 4 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! router isis 2 net 49.0002.0000.0000.0005.00 diff --git a/tests/topotests/isis_lsp_bits_topo1/rt5/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_lsp_bits_topo1/rt5/step1/show_yang_interface_isis_adjacencies.ref index f939a6abff..a6f08c2eb2 100644 --- a/tests/topotests/isis_lsp_bits_topo1/rt5/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_lsp_bits_topo1/rt5/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1-2", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1-2", "neighbor-sysid": "0000.0000.0004", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -49,7 +49,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0006", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_lsp_bits_topo1/rt6/isisd.conf b/tests/topotests/isis_lsp_bits_topo1/rt6/isisd.conf index 505604ef33..b66f40e9ee 100644 --- a/tests/topotests/isis_lsp_bits_topo1/rt6/isisd.conf +++ b/tests/topotests/isis_lsp_bits_topo1/rt6/isisd.conf @@ -16,13 +16,15 @@ interface eth-rt4 ip router isis 4 ipv6 router isis 4 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface eth-rt5 ip router isis 4 ipv6 router isis 4 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! router isis 4 net 49.0004.0000.0000.0006.00 diff --git a/tests/topotests/isis_lsp_bits_topo1/rt6/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_lsp_bits_topo1/rt6/step1/show_yang_interface_isis_adjacencies.ref index b4e8c23189..8300ca0b5c 100644 --- a/tests/topotests/isis_lsp_bits_topo1/rt6/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_lsp_bits_topo1/rt6/step1/show_yang_interface_isis_adjacencies.ref @@ -9,9 +9,9 @@ "adjacencies": { "adjacency": [ { - "neighbor-sys-type": "level-1-2", + "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0004", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -28,9 +28,9 @@ "adjacencies": { "adjacency": [ { - "neighbor-sys-type": "level-1-2", + "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0005", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_rlfa_topo1/rt1/isisd.conf b/tests/topotests/isis_rlfa_topo1/rt1/isisd.conf index f7f0a95e1c..c96d0b1374 100644 --- a/tests/topotests/isis_rlfa_topo1/rt1/isisd.conf +++ b/tests/topotests/isis_rlfa_topo1/rt1/isisd.conf @@ -15,7 +15,8 @@ interface lo interface eth-rt2 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis network point-to-point isis fast-reroute lfa isis fast-reroute remote-lfa tunnel mpls-ldp @@ -23,7 +24,8 @@ interface eth-rt2 interface eth-rt3 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis network point-to-point isis fast-reroute lfa isis fast-reroute remote-lfa tunnel mpls-ldp diff --git a/tests/topotests/isis_rlfa_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_rlfa_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref index 3fe2b798a0..4c5a31d16c 100644 --- a/tests/topotests/isis_rlfa_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_rlfa_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1-2", "neighbor-sysid": "0000.0000.0002", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1-2", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_rlfa_topo1/rt2/isisd.conf b/tests/topotests/isis_rlfa_topo1/rt2/isisd.conf index 6595052fab..27203375c1 100644 --- a/tests/topotests/isis_rlfa_topo1/rt2/isisd.conf +++ b/tests/topotests/isis_rlfa_topo1/rt2/isisd.conf @@ -15,13 +15,15 @@ interface lo interface eth-rt1 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis network point-to-point ! interface eth-rt4 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis network point-to-point ! router isis 1 diff --git a/tests/topotests/isis_rlfa_topo1/rt3/isisd.conf b/tests/topotests/isis_rlfa_topo1/rt3/isisd.conf index a029b7140f..1139d9df41 100644 --- a/tests/topotests/isis_rlfa_topo1/rt3/isisd.conf +++ b/tests/topotests/isis_rlfa_topo1/rt3/isisd.conf @@ -15,13 +15,15 @@ interface lo interface eth-rt1 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis network point-to-point ! interface eth-rt5 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis network point-to-point ! router isis 1 diff --git a/tests/topotests/isis_rlfa_topo1/rt4/isisd.conf b/tests/topotests/isis_rlfa_topo1/rt4/isisd.conf index 86aa6b1f46..980bd5d9f0 100644 --- a/tests/topotests/isis_rlfa_topo1/rt4/isisd.conf +++ b/tests/topotests/isis_rlfa_topo1/rt4/isisd.conf @@ -15,13 +15,15 @@ interface lo interface eth-rt2 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis network point-to-point ! interface eth-rt6 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis network point-to-point ! router isis 1 diff --git a/tests/topotests/isis_rlfa_topo1/rt5/isisd.conf b/tests/topotests/isis_rlfa_topo1/rt5/isisd.conf index e4fc9cdd4c..82ba9cb56e 100644 --- a/tests/topotests/isis_rlfa_topo1/rt5/isisd.conf +++ b/tests/topotests/isis_rlfa_topo1/rt5/isisd.conf @@ -15,13 +15,15 @@ interface lo interface eth-rt3 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis network point-to-point ! interface eth-rt7 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis network point-to-point ! router isis 1 diff --git a/tests/topotests/isis_rlfa_topo1/rt6/isisd.conf b/tests/topotests/isis_rlfa_topo1/rt6/isisd.conf index 81319e4264..ea859ffa3b 100644 --- a/tests/topotests/isis_rlfa_topo1/rt6/isisd.conf +++ b/tests/topotests/isis_rlfa_topo1/rt6/isisd.conf @@ -15,13 +15,15 @@ interface lo interface eth-rt4 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis network point-to-point ! interface eth-rt8 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis network point-to-point ! router isis 1 diff --git a/tests/topotests/isis_rlfa_topo1/rt7/isisd.conf b/tests/topotests/isis_rlfa_topo1/rt7/isisd.conf index 1f48671e74..5acfa95a13 100644 --- a/tests/topotests/isis_rlfa_topo1/rt7/isisd.conf +++ b/tests/topotests/isis_rlfa_topo1/rt7/isisd.conf @@ -15,13 +15,15 @@ interface lo interface eth-rt5 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis network point-to-point ! interface eth-rt8 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis network point-to-point ! router isis 1 diff --git a/tests/topotests/isis_rlfa_topo1/rt8/isisd.conf b/tests/topotests/isis_rlfa_topo1/rt8/isisd.conf index 7675f777a7..237784280a 100644 --- a/tests/topotests/isis_rlfa_topo1/rt8/isisd.conf +++ b/tests/topotests/isis_rlfa_topo1/rt8/isisd.conf @@ -15,13 +15,15 @@ interface lo interface eth-rt6 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis network point-to-point ! interface eth-rt7 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis network point-to-point ! router isis 1 diff --git a/tests/topotests/isis_snmp/r1/ldpd.conf b/tests/topotests/isis_snmp/r1/ldpd.conf index 5b1cbfebc9..64f51fce27 100644 --- a/tests/topotests/isis_snmp/r1/ldpd.conf +++ b/tests/topotests/isis_snmp/r1/ldpd.conf @@ -5,7 +5,6 @@ log file ldpd.log ! debug mpls ldp event ! debug mpls ldp errors ! debug mpls ldp sync -agentx ! mpls ldp router-id 1.1.1.1 diff --git a/tests/topotests/isis_snmp/r1/show_ip_route.ref b/tests/topotests/isis_snmp/r1/show_ip_route.ref deleted file mode 100644 index dc8f19dad0..0000000000 --- a/tests/topotests/isis_snmp/r1/show_ip_route.ref +++ /dev/null @@ -1,143 +0,0 @@ -{ - "1.1.1.1\/32":[ - { - "prefix":"1.1.1.1\/32", - "protocol":"connected", - "selected":true, - "nexthops":[ - { - "fib":true, - "directlyConnected":true, - "interfaceIndex":1, - "interfaceName":"lo", - "active":true - } - ] - } - ], - "2.2.2.2\/32":[ - { - "prefix":"2.2.2.2\/32", - "protocol":"isis", - "selected":true, - "distance":115, - "metric":10, - "nexthops":[ - { - "fib":true, - "ip":"10.0.1.2", - "afi":"ipv4", - "interfaceIndex":3, - "interfaceName":"r1-eth1", - "active":true - } - ] - } - ], - "3.3.3.3\/32":[ - { - "prefix":"3.3.3.3\/32", - "protocol":"isis", - "selected":true, - "distance":115, - "metric":10, - "nexthops":[ - { - "fib":true, - "ip":"10.0.2.3", - "afi":"ipv4", - "interfaceIndex":4, - "interfaceName":"r1-eth2", - "active":true - } - ] - } - ], - "10.0.1.0\/24":[ - { - "prefix":"10.0.1.0\/24", - "protocol":"isis", - "distance":115, - "metric":10, - "nexthops":[ - { - "ip":"10.0.1.2", - "afi":"ipv4", - "interfaceIndex":3, - "interfaceName":"r1-eth1" - } - ] - }, - { - "prefix":"10.0.1.0\/24", - "protocol":"connected", - "selected":true, - "nexthops":[ - { - "fib":true, - "directlyConnected":true, - "interfaceIndex":3, - "interfaceName":"r1-eth1", - "active":true - } - ] - } - ], - "10.0.2.0\/24":[ - { - "prefix":"10.0.2.0\/24", - "protocol":"isis", - "distance":115, - "metric":10, - "nexthops":[ - { - "ip":"10.0.2.3", - "afi":"ipv4", - "interfaceIndex":4, - "interfaceName":"r1-eth2" - } - ] - }, - { - "prefix":"10.0.2.0\/24", - "protocol":"connected", - "selected":true, - "nexthops":[ - { - "fib":true, - "directlyConnected":true, - "interfaceIndex":4, - "interfaceName":"r1-eth2", - "active":true - } - ] - } - ], - "10.0.3.0\/24":[ - { - "prefix":"10.0.3.0\/24", - "protocol":"isis", - "selected":true, - "distance":115, - "metric":10, - "nexthops":[ - { - "fib":true, - "ip":"10.0.1.2", - "afi":"ipv4", - "interfaceIndex":3, - "interfaceName":"r1-eth1", - "active":true - }, - { - "fib":true, - "ip":"10.0.2.3", - "afi":"ipv4", - "interfaceIndex":4, - "interfaceName":"r1-eth2", - "active":true - } - ] - } - ] -} diff --git a/tests/topotests/isis_snmp/r1/snmpd.conf b/tests/topotests/isis_snmp/r1/snmpd.conf index 3fd5e982e8..cdcd9a2b37 100644 --- a/tests/topotests/isis_snmp/r1/snmpd.conf +++ b/tests/topotests/isis_snmp/r1/snmpd.conf @@ -1,4 +1,4 @@ -agentAddress udp:1.1.1.1:161 +agentAddress udp:161 com2sec public 1.1.1.1 public @@ -15,4 +15,4 @@ rouser frr master agentx agentXSocket /etc/frr/agentx -agentXPerms 777 755 root frr \ No newline at end of file +agentXPerms 777 755 root frr diff --git a/tests/topotests/isis_snmp/r2/show_ip_route.ref b/tests/topotests/isis_snmp/r2/show_ip_route.ref deleted file mode 100644 index 2bcee96064..0000000000 --- a/tests/topotests/isis_snmp/r2/show_ip_route.ref +++ /dev/null @@ -1,143 +0,0 @@ -{ - "1.1.1.1\/32":[ - { - "prefix":"1.1.1.1\/32", - "protocol":"isis", - "selected":true, - "distance":115, - "metric":10, - "nexthops":[ - { - "fib":true, - "ip":"10.0.1.1", - "afi":"ipv4", - "interfaceIndex":3, - "interfaceName":"r2-eth1", - "active":true - } - ] - } - ], - "2.2.2.2\/32":[ - { - "prefix":"2.2.2.2\/32", - "protocol":"connected", - "selected":true, - "nexthops":[ - { - "fib":true, - "directlyConnected":true, - "interfaceIndex":1, - "interfaceName":"lo", - "active":true - } - ] - } - ], - "3.3.3.3\/32":[ - { - "prefix":"3.3.3.3\/32", - "protocol":"isis", - "selected":true, - "distance":115, - "metric":10, - "nexthops":[ - { - "fib":true, - "ip":"10.0.3.3", - "afi":"ipv4", - "interfaceIndex":4, - "interfaceName":"r2-eth2", - "active":true - } - ] - } - ], - "10.0.1.0\/24":[ - { - "prefix":"10.0.1.0\/24", - "protocol":"isis", - "distance":115, - "metric":10, - "nexthops":[ - { - "ip":"10.0.1.1", - "afi":"ipv4", - "interfaceIndex":3, - "interfaceName":"r2-eth1" - } - ] - }, - { - "prefix":"10.0.1.0\/24", - "protocol":"connected", - "selected":true, - "nexthops":[ - { - "fib":true, - "directlyConnected":true, - "interfaceIndex":3, - "interfaceName":"r2-eth1", - "active":true - } - ] - } - ], - "10.0.2.0\/24":[ - { - "prefix":"10.0.2.0\/24", - "protocol":"isis", - "selected":true, - "distance":115, - "metric":10, - "nexthops":[ - { - "fib":true, - "ip":"10.0.1.1", - "afi":"ipv4", - "interfaceIndex":3, - "interfaceName":"r2-eth1", - "active":true - }, - { - "fib":true, - "ip":"10.0.3.3", - "afi":"ipv4", - "interfaceIndex":4, - "interfaceName":"r2-eth2", - "active":true - } - ] - } - ], - "10.0.3.0\/24":[ - { - "prefix":"10.0.3.0\/24", - "protocol":"isis", - "distance":115, - "metric":10, - "nexthops":[ - { - "ip":"10.0.3.3", - "afi":"ipv4", - "interfaceIndex":4, - "interfaceName":"r2-eth2" - } - ] - }, - { - "prefix":"10.0.3.0\/24", - "protocol":"connected", - "selected":true, - "nexthops":[ - { - "fib":true, - "directlyConnected":true, - "interfaceIndex":4, - "interfaceName":"r2-eth2", - "active":true - } - ] - } - ] -} diff --git a/tests/topotests/isis_snmp/r2/snmpd.conf b/tests/topotests/isis_snmp/r2/snmpd.conf index fc648057a5..e511929f67 100644 --- a/tests/topotests/isis_snmp/r2/snmpd.conf +++ b/tests/topotests/isis_snmp/r2/snmpd.conf @@ -1,4 +1,4 @@ -agentAddress udp:2.2.2.2:161 +agentAddress udp::161 com2sec public 2.2.2.2 public @@ -15,4 +15,4 @@ rouser frr master agentx agentXSocket /etc/frr/agentx -agentXPerms 777 755 root frr \ No newline at end of file +agentXPerms 777 755 root frr diff --git a/tests/topotests/isis_snmp/r3/show_ip_route.ref b/tests/topotests/isis_snmp/r3/show_ip_route.ref deleted file mode 100644 index da46f1dfe2..0000000000 --- a/tests/topotests/isis_snmp/r3/show_ip_route.ref +++ /dev/null @@ -1,143 +0,0 @@ -{ - "1.1.1.1\/32":[ - { - "prefix":"1.1.1.1\/32", - "protocol":"isis", - "selected":true, - "distance":115, - "metric":10, - "nexthops":[ - { - "fib":true, - "ip":"10.0.2.1", - "afi":"ipv4", - "interfaceIndex":3, - "interfaceName":"r3-eth1", - "active":true - } - ] - } - ], - "2.2.2.2\/32":[ - { - "prefix":"2.2.2.2\/32", - "protocol":"isis", - "selected":true, - "distance":115, - "metric":10, - "nexthops":[ - { - "fib":true, - "ip":"10.0.3.2", - "afi":"ipv4", - "interfaceIndex":4, - "interfaceName":"r3-eth2", - "active":true - } - ] - } - ], - "3.3.3.3\/32":[ - { - "prefix":"3.3.3.3\/32", - "protocol":"connected", - "selected":true, - "nexthops":[ - { - "fib":true, - "directlyConnected":true, - "interfaceIndex":1, - "interfaceName":"lo", - "active":true - } - ] - } - ], - "10.0.1.0\/24":[ - { - "prefix":"10.0.1.0\/24", - "protocol":"isis", - "selected":true, - "distance":115, - "metric":10, - "nexthops":[ - { - "fib":true, - "ip":"10.0.2.1", - "afi":"ipv4", - "interfaceIndex":3, - "interfaceName":"r3-eth1", - "active":true - }, - { - "fib":true, - "ip":"10.0.3.2", - "afi":"ipv4", - "interfaceIndex":4, - "interfaceName":"r3-eth2", - "active":true - } - ] - } - ], - "10.0.2.0\/24":[ - { - "prefix":"10.0.2.0\/24", - "protocol":"isis", - "distance":115, - "metric":10, - "nexthops":[ - { - "ip":"10.0.2.1", - "afi":"ipv4", - "interfaceIndex":3, - "interfaceName":"r3-eth1" - } - ] - }, - { - "prefix":"10.0.2.0\/24", - "protocol":"connected", - "selected":true, - "nexthops":[ - { - "fib":true, - "directlyConnected":true, - "interfaceIndex":3, - "interfaceName":"r3-eth1", - "active":true - } - ] - } - ], - "10.0.3.0\/24":[ - { - "prefix":"10.0.3.0\/24", - "protocol":"isis", - "distance":115, - "metric":10, - "nexthops":[ - { - "ip":"10.0.3.2", - "afi":"ipv4", - "interfaceIndex":4, - "interfaceName":"r3-eth2" - } - ] - }, - { - "prefix":"10.0.3.0\/24", - "protocol":"connected", - "selected":true, - "nexthops":[ - { - "fib":true, - "directlyConnected":true, - "interfaceIndex":4, - "interfaceName":"r3-eth2", - "active":true - } - ] - } - ] -} diff --git a/tests/topotests/isis_snmp/r3/snmpd.conf b/tests/topotests/isis_snmp/r3/snmpd.conf index 20af65e431..19fb256b9a 100644 --- a/tests/topotests/isis_snmp/r3/snmpd.conf +++ b/tests/topotests/isis_snmp/r3/snmpd.conf @@ -1,4 +1,4 @@ -agentAddress udp:3.3.3.3:161 +agentAddress udp:161 com2sec public 3.3.3.3 public @@ -15,4 +15,4 @@ rouser frr master agentx agentXSocket /etc/frr/agentx -agentXPerms 777 755 root frr \ No newline at end of file +agentXPerms 777 755 root frr diff --git a/tests/topotests/isis_snmp/r4/show_ip_route.ref b/tests/topotests/isis_snmp/r4/show_ip_route.ref deleted file mode 100644 index da46f1dfe2..0000000000 --- a/tests/topotests/isis_snmp/r4/show_ip_route.ref +++ /dev/null @@ -1,143 +0,0 @@ -{ - "1.1.1.1\/32":[ - { - "prefix":"1.1.1.1\/32", - "protocol":"isis", - "selected":true, - "distance":115, - "metric":10, - "nexthops":[ - { - "fib":true, - "ip":"10.0.2.1", - "afi":"ipv4", - "interfaceIndex":3, - "interfaceName":"r3-eth1", - "active":true - } - ] - } - ], - "2.2.2.2\/32":[ - { - "prefix":"2.2.2.2\/32", - "protocol":"isis", - "selected":true, - "distance":115, - "metric":10, - "nexthops":[ - { - "fib":true, - "ip":"10.0.3.2", - "afi":"ipv4", - "interfaceIndex":4, - "interfaceName":"r3-eth2", - "active":true - } - ] - } - ], - "3.3.3.3\/32":[ - { - "prefix":"3.3.3.3\/32", - "protocol":"connected", - "selected":true, - "nexthops":[ - { - "fib":true, - "directlyConnected":true, - "interfaceIndex":1, - "interfaceName":"lo", - "active":true - } - ] - } - ], - "10.0.1.0\/24":[ - { - "prefix":"10.0.1.0\/24", - "protocol":"isis", - "selected":true, - "distance":115, - "metric":10, - "nexthops":[ - { - "fib":true, - "ip":"10.0.2.1", - "afi":"ipv4", - "interfaceIndex":3, - "interfaceName":"r3-eth1", - "active":true - }, - { - "fib":true, - "ip":"10.0.3.2", - "afi":"ipv4", - "interfaceIndex":4, - "interfaceName":"r3-eth2", - "active":true - } - ] - } - ], - "10.0.2.0\/24":[ - { - "prefix":"10.0.2.0\/24", - "protocol":"isis", - "distance":115, - "metric":10, - "nexthops":[ - { - "ip":"10.0.2.1", - "afi":"ipv4", - "interfaceIndex":3, - "interfaceName":"r3-eth1" - } - ] - }, - { - "prefix":"10.0.2.0\/24", - "protocol":"connected", - "selected":true, - "nexthops":[ - { - "fib":true, - "directlyConnected":true, - "interfaceIndex":3, - "interfaceName":"r3-eth1", - "active":true - } - ] - } - ], - "10.0.3.0\/24":[ - { - "prefix":"10.0.3.0\/24", - "protocol":"isis", - "distance":115, - "metric":10, - "nexthops":[ - { - "ip":"10.0.3.2", - "afi":"ipv4", - "interfaceIndex":4, - "interfaceName":"r3-eth2" - } - ] - }, - { - "prefix":"10.0.3.0\/24", - "protocol":"connected", - "selected":true, - "nexthops":[ - { - "fib":true, - "directlyConnected":true, - "interfaceIndex":4, - "interfaceName":"r3-eth2", - "active":true - } - ] - } - ] -} diff --git a/tests/topotests/isis_snmp/r4/snmpd.conf b/tests/topotests/isis_snmp/r4/snmpd.conf index 76e4b79069..2178a3e1d8 100644 --- a/tests/topotests/isis_snmp/r4/snmpd.conf +++ b/tests/topotests/isis_snmp/r4/snmpd.conf @@ -1,4 +1,4 @@ -agentAddress udp:4.4.4.4:161 +agentAddress udp:161 com2sec public 4.4.4.4 public @@ -15,4 +15,4 @@ rouser frr master agentx agentXSocket /etc/frr/agentx -agentXPerms 777 755 root frr \ No newline at end of file +agentXPerms 777 755 root frr diff --git a/tests/topotests/isis_snmp/r5/show_ip_route.ref b/tests/topotests/isis_snmp/r5/show_ip_route.ref deleted file mode 100644 index da46f1dfe2..0000000000 --- a/tests/topotests/isis_snmp/r5/show_ip_route.ref +++ /dev/null @@ -1,143 +0,0 @@ -{ - "1.1.1.1\/32":[ - { - "prefix":"1.1.1.1\/32", - "protocol":"isis", - "selected":true, - "distance":115, - "metric":10, - "nexthops":[ - { - "fib":true, - "ip":"10.0.2.1", - "afi":"ipv4", - "interfaceIndex":3, - "interfaceName":"r3-eth1", - "active":true - } - ] - } - ], - "2.2.2.2\/32":[ - { - "prefix":"2.2.2.2\/32", - "protocol":"isis", - "selected":true, - "distance":115, - "metric":10, - "nexthops":[ - { - "fib":true, - "ip":"10.0.3.2", - "afi":"ipv4", - "interfaceIndex":4, - "interfaceName":"r3-eth2", - "active":true - } - ] - } - ], - "3.3.3.3\/32":[ - { - "prefix":"3.3.3.3\/32", - "protocol":"connected", - "selected":true, - "nexthops":[ - { - "fib":true, - "directlyConnected":true, - "interfaceIndex":1, - "interfaceName":"lo", - "active":true - } - ] - } - ], - "10.0.1.0\/24":[ - { - "prefix":"10.0.1.0\/24", - "protocol":"isis", - "selected":true, - "distance":115, - "metric":10, - "nexthops":[ - { - "fib":true, - "ip":"10.0.2.1", - "afi":"ipv4", - "interfaceIndex":3, - "interfaceName":"r3-eth1", - "active":true - }, - { - "fib":true, - "ip":"10.0.3.2", - "afi":"ipv4", - "interfaceIndex":4, - "interfaceName":"r3-eth2", - "active":true - } - ] - } - ], - "10.0.2.0\/24":[ - { - "prefix":"10.0.2.0\/24", - "protocol":"isis", - "distance":115, - "metric":10, - "nexthops":[ - { - "ip":"10.0.2.1", - "afi":"ipv4", - "interfaceIndex":3, - "interfaceName":"r3-eth1" - } - ] - }, - { - "prefix":"10.0.2.0\/24", - "protocol":"connected", - "selected":true, - "nexthops":[ - { - "fib":true, - "directlyConnected":true, - "interfaceIndex":3, - "interfaceName":"r3-eth1", - "active":true - } - ] - } - ], - "10.0.3.0\/24":[ - { - "prefix":"10.0.3.0\/24", - "protocol":"isis", - "distance":115, - "metric":10, - "nexthops":[ - { - "ip":"10.0.3.2", - "afi":"ipv4", - "interfaceIndex":4, - "interfaceName":"r3-eth2" - } - ] - }, - { - "prefix":"10.0.3.0\/24", - "protocol":"connected", - "selected":true, - "nexthops":[ - { - "fib":true, - "directlyConnected":true, - "interfaceIndex":4, - "interfaceName":"r3-eth2", - "active":true - } - ] - } - ] -} diff --git a/tests/topotests/isis_snmp/r5/snmpd.conf b/tests/topotests/isis_snmp/r5/snmpd.conf index af59194bc9..5b11cfc5e0 100644 --- a/tests/topotests/isis_snmp/r5/snmpd.conf +++ b/tests/topotests/isis_snmp/r5/snmpd.conf @@ -1,4 +1,4 @@ -agentAddress udp:5.5.5.5:161 +agentAddress udp::161 com2sec public 5.5.5.5 public @@ -15,4 +15,4 @@ rouser frr master agentx agentXSocket /etc/frr/agentx -agentXPerms 777 755 root frr \ No newline at end of file +agentXPerms 777 755 root frr diff --git a/tests/topotests/isis_sr_flex_algo_topo1/rt1/isisd.conf b/tests/topotests/isis_sr_flex_algo_topo1/rt1/isisd.conf index 5503baa58c..090e89628f 100644 --- a/tests/topotests/isis_sr_flex_algo_topo1/rt1/isisd.conf +++ b/tests/topotests/isis_sr_flex_algo_topo1/rt1/isisd.conf @@ -23,13 +23,13 @@ interface lo interface eth-rt2 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point ! interface eth-rt3 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point ! router isis 1 diff --git a/tests/topotests/isis_sr_flex_algo_topo1/rt1/zebra.conf b/tests/topotests/isis_sr_flex_algo_topo1/rt1/zebra.conf index 5140eda73a..92b619ee57 100644 --- a/tests/topotests/isis_sr_flex_algo_topo1/rt1/zebra.conf +++ b/tests/topotests/isis_sr_flex_algo_topo1/rt1/zebra.conf @@ -3,7 +3,6 @@ log file zebra.log hostname rt1 ! log stdout notifications -log monitor notifications log commands ! !debug zebra packet diff --git a/tests/topotests/isis_sr_flex_algo_topo1/rt2/isisd.conf b/tests/topotests/isis_sr_flex_algo_topo1/rt2/isisd.conf index 8655e7434a..3901ccaefe 100644 --- a/tests/topotests/isis_sr_flex_algo_topo1/rt2/isisd.conf +++ b/tests/topotests/isis_sr_flex_algo_topo1/rt2/isisd.conf @@ -23,13 +23,13 @@ interface lo interface eth-rt1 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point ! interface eth-rt3 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point ! router isis 1 diff --git a/tests/topotests/isis_sr_flex_algo_topo1/rt2/zebra.conf b/tests/topotests/isis_sr_flex_algo_topo1/rt2/zebra.conf index 388348fced..3ea5e0a0a6 100644 --- a/tests/topotests/isis_sr_flex_algo_topo1/rt2/zebra.conf +++ b/tests/topotests/isis_sr_flex_algo_topo1/rt2/zebra.conf @@ -3,7 +3,6 @@ log file zebra.log hostname rt2 ! log stdout notifications -log monitor notifications log commands ! !debug zebra packet diff --git a/tests/topotests/isis_sr_flex_algo_topo1/rt3/isisd.conf b/tests/topotests/isis_sr_flex_algo_topo1/rt3/isisd.conf index d77af81d7c..f7a52bc79d 100644 --- a/tests/topotests/isis_sr_flex_algo_topo1/rt3/isisd.conf +++ b/tests/topotests/isis_sr_flex_algo_topo1/rt3/isisd.conf @@ -23,13 +23,13 @@ interface lo interface eth-rt1 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point ! interface eth-rt2 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point ! router isis 1 diff --git a/tests/topotests/isis_sr_flex_algo_topo1/rt3/zebra.conf b/tests/topotests/isis_sr_flex_algo_topo1/rt3/zebra.conf index fb45ee1282..ea35de80c4 100644 --- a/tests/topotests/isis_sr_flex_algo_topo1/rt3/zebra.conf +++ b/tests/topotests/isis_sr_flex_algo_topo1/rt3/zebra.conf @@ -3,7 +3,6 @@ log file zebra.log hostname rt3 ! log stdout notifications -log monitor notifications log commands ! !debug zebra packet diff --git a/tests/topotests/isis_sr_flex_algo_topo1/test_isis_sr_flex_algo_topo1.py b/tests/topotests/isis_sr_flex_algo_topo1/test_isis_sr_flex_algo_topo1.py index 85600beb0e..c81f63942b 100755 --- a/tests/topotests/isis_sr_flex_algo_topo1/test_isis_sr_flex_algo_topo1.py +++ b/tests/topotests/isis_sr_flex_algo_topo1/test_isis_sr_flex_algo_topo1.py @@ -38,6 +38,7 @@ import pytest import json import tempfile +from copy import deepcopy from functools import partial # Save the Current Working Directory to find configuration files. @@ -111,8 +112,12 @@ def setup_module(mod): # For all registered routers, load the zebra configuration file for rname, router in router_list.items(): - router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))) - router.load_config( TopoRouter.RD_ISIS, os.path.join(CWD, "{}/isisd.conf".format(rname))) + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_ISIS, os.path.join(CWD, "{}/isisd.conf".format(rname)) + ) tgen.start_router() @@ -130,6 +135,30 @@ def setup_testcase(msg): return tgen +def router_json_cmp_exact_filter(router, cmd, expected): + output = router.vtysh_cmd(cmd) + logger.info("{}: {}\n{}".format(router.name, cmd, output)) + + json_output = json.loads(output) + router_output = deepcopy(json_output) + + # filter out dynamic data from "show mpls table" + for label, data in json_output.items(): + if "1500" in label: + # filter out SR local labels + router_output.pop(label) + continue + nexthops = data.get("nexthops", []) + for i in range(len(nexthops)): + if "fe80::" in nexthops[i].get("nexthop"): + router_output.get(label).get("nexthops")[i].pop("nexthop") + elif "." in nexthops[i].get("nexthop"): + # IPv4, just checking the nexthop + router_output.get(label).get("nexthops")[i].pop("interface") + + return topotest.json_cmp(router_output, expected, exact=True) + + def router_compare_json_output(rname, command, reference): "Compare router JSON output" @@ -139,7 +168,9 @@ def router_compare_json_output(rname, command, reference): expected = json.loads(reference) # Run test function until we get an result. Wait at most 60 seconds. - test_func = partial(topotest.router_json_cmp, tgen.gears[rname], command, expected) + test_func = partial( + router_json_cmp_exact_filter, tgen.gears[rname], command, expected + ) _, diff = topotest.run_and_expect(test_func, None, count=120, wait=0.5) assertmsg = '"{}" JSON output mismatches the expected result'.format(rname) assert diff is None, assertmsg @@ -153,9 +184,13 @@ def router_compare_output(rname, command, reference): tgen = get_topogen() # Run test function until we get an result. Wait at most 60 seconds. - test_func = partial(topotest.router_output_cmp, tgen.gears[rname], command, reference) + test_func = partial( + topotest.router_output_cmp, tgen.gears[rname], command, reference + ) result, diff = topotest.run_and_expect(test_func, "", count=120, wait=0.5) - assertmsg = '{} command "{}" output mismatches the expected result:\n{}'.format(rname, command, diff) + assertmsg = '{} command "{}" output mismatches the expected result:\n{}'.format( + rname, command, diff + ) assert result, assertmsg @@ -176,11 +211,11 @@ def test_step1_mpls_lfib(): # tgen.mininet_cli() for rname in ["rt1", "rt2", "rt3"]: router_compare_output( - rname, "show isis flex-algo", - outputs[rname][1]["show_isis_flex_algo.ref"]) + rname, "show isis flex-algo", outputs[rname][1]["show_isis_flex_algo.ref"] + ) router_compare_json_output( - rname, "show mpls table json", - outputs[rname][1]["show_mpls_table.ref"]) + rname, "show mpls table json", outputs[rname][1]["show_mpls_table.ref"] + ) # @@ -207,17 +242,18 @@ def test_step2_mpls_lfib(): router isis 1 flex-algo 203 no advertise-definition - """) + """ + ) # For Developers # tgen.mininet_cli() for rname in ["rt1", "rt2", "rt3"]: router_compare_output( - rname, "show isis flex-algo", - outputs[rname][2]["show_isis_flex_algo.ref"]) + rname, "show isis flex-algo", outputs[rname][2]["show_isis_flex_algo.ref"] + ) router_compare_json_output( - rname, "show mpls table json", - outputs[rname][2]["show_mpls_table.ref"]) + rname, "show mpls table json", outputs[rname][2]["show_mpls_table.ref"] + ) # @@ -244,17 +280,18 @@ def test_step3_mpls_lfib(): router isis 1 flex-algo 203 no advertise-definition - """) + """ + ) # For Developers # tgen.mininet_cli() for rname in ["rt1", "rt2", "rt3"]: router_compare_output( - rname, "show isis flex-algo", - outputs[rname][3]["show_isis_flex_algo.ref"]) + rname, "show isis flex-algo", outputs[rname][3]["show_isis_flex_algo.ref"] + ) router_compare_json_output( - rname, "show mpls table json", - outputs[rname][3]["show_mpls_table.ref"]) + rname, "show mpls table json", outputs[rname][3]["show_mpls_table.ref"] + ) # @@ -281,17 +318,18 @@ def test_step4_mpls_lfib(): router isis 1 flex-algo 203 advertise-definition - """) + """ + ) # For Developers # tgen.mininet_cli() for rname in ["rt1", "rt2", "rt3"]: router_compare_output( - rname, "show isis flex-algo", - outputs[rname][4]["show_isis_flex_algo.ref"]) + rname, "show isis flex-algo", outputs[rname][4]["show_isis_flex_algo.ref"] + ) router_compare_json_output( - rname, "show mpls table json", - outputs[rname][4]["show_mpls_table.ref"]) + rname, "show mpls table json", outputs[rname][4]["show_mpls_table.ref"] + ) # @@ -319,17 +357,18 @@ def test_step5_mpls_lfib(): router isis 1 flex-algo 203 advertise-definition - """) + """ + ) # For Developers # tgen.mininet_cli() for rname in ["rt1", "rt2", "rt3"]: router_compare_output( - rname, "show isis flex-algo", - outputs[rname][5]["show_isis_flex_algo.ref"]) + rname, "show isis flex-algo", outputs[rname][5]["show_isis_flex_algo.ref"] + ) router_compare_json_output( - rname, "show mpls table json", - outputs[rname][5]["show_mpls_table.ref"]) + rname, "show mpls table json", outputs[rname][5]["show_mpls_table.ref"] + ) # @@ -360,17 +399,18 @@ def test_step6_mpls_lfib(): router isis 1 flex-algo 203 no dataplane sr-mpls - """) + """ + ) # For Developers # tgen.mininet_cli() for rname in ["rt1", "rt2", "rt3"]: router_compare_output( - rname, "show isis flex-algo", - outputs[rname][6]["show_isis_flex_algo.ref"]) + rname, "show isis flex-algo", outputs[rname][6]["show_isis_flex_algo.ref"] + ) router_compare_json_output( - rname, "show mpls table json", - outputs[rname][6]["show_mpls_table.ref"]) + rname, "show mpls table json", outputs[rname][6]["show_mpls_table.ref"] + ) # @@ -400,17 +440,19 @@ def test_step7_mpls_lfib(): configure terminal router isis 1 no flex-algo 203 - """) + """ + ) # For Developers # tgen.mininet_cli() for rname in ["rt1", "rt2", "rt3"]: router_compare_output( - rname, "show isis flex-algo", - outputs[rname][7]["show_isis_flex_algo.ref"]) + rname, "show isis flex-algo", outputs[rname][7]["show_isis_flex_algo.ref"] + ) router_compare_json_output( - rname, "show mpls table json", - outputs[rname][7]["show_mpls_table.ref"]) + rname, "show mpls table json", outputs[rname][7]["show_mpls_table.ref"] + ) + # # Step 8 @@ -440,7 +482,8 @@ def test_step8_mpls_lfib(): advertise-definition affinity exclude-any green dataplane sr-mpls - """) + """ + ) tgen.gears["rt2"].vtysh_cmd( """ @@ -450,7 +493,8 @@ def test_step8_mpls_lfib(): advertise-definition affinity exclude-any green dataplane sr-mpls - """) + """ + ) tgen.gears["rt3"].vtysh_cmd( """ @@ -458,17 +502,18 @@ def test_step8_mpls_lfib(): router isis 1 flex-algo 203 dataplane sr-mpls - """) + """ + ) # For Developers # tgen.mininet_cli() for rname in ["rt1", "rt2", "rt3"]: router_compare_output( - rname, "show isis flex-algo", - outputs[rname][8]["show_isis_flex_algo.ref"]) + rname, "show isis flex-algo", outputs[rname][8]["show_isis_flex_algo.ref"] + ) router_compare_json_output( - rname, "show mpls table json", - outputs[rname][8]["show_mpls_table.ref"]) + rname, "show mpls table json", outputs[rname][8]["show_mpls_table.ref"] + ) # @@ -494,17 +539,18 @@ def test_step9_mpls_lfib(): router isis 1 no segment-routing prefix 1.1.1.1/32 algorithm 203 index 301 no segment-routing prefix 2001:db8:1000::1/128 algorithm 203 index 1301 - """) + """ + ) # For Developers # tgen.mininet_cli() for rname in ["rt1", "rt2", "rt3"]: router_compare_output( - rname, "show isis flex-algo", - outputs[rname][9]["show_isis_flex_algo.ref"]) + rname, "show isis flex-algo", outputs[rname][9]["show_isis_flex_algo.ref"] + ) router_compare_json_output( - rname, "show mpls table json", - outputs[rname][9]["show_mpls_table.ref"]) + rname, "show mpls table json", outputs[rname][9]["show_mpls_table.ref"] + ) # @@ -530,17 +576,18 @@ def test_step10_mpls_lfib(): router isis 1 segment-routing prefix 1.1.1.1/32 algorithm 203 index 301 segment-routing prefix 2001:db8:1000::1/128 algorithm 203 index 1301 - """) + """ + ) # For Developers # tgen.mininet_cli() for rname in ["rt1", "rt2", "rt3"]: router_compare_output( - rname, "show isis flex-algo", - outputs[rname][10]["show_isis_flex_algo.ref"]) + rname, "show isis flex-algo", outputs[rname][10]["show_isis_flex_algo.ref"] + ) router_compare_json_output( - rname, "show mpls table json", - outputs[rname][10]["show_mpls_table.ref"]) + rname, "show mpls table json", outputs[rname][10]["show_mpls_table.ref"] + ) # @@ -565,17 +612,18 @@ def test_step11_mpls_lfib(): router isis 1 segment-routing prefix 1.1.1.1/32 algorithm 203 index 311 segment-routing prefix 2001:db8:1000::1/128 algorithm 203 index 1311 - """) + """ + ) # For Developers # tgen.mininet_cli() for rname in ["rt1", "rt2", "rt3"]: router_compare_output( - rname, "show isis flex-algo", - outputs[rname][11]["show_isis_flex_algo.ref"]) + rname, "show isis flex-algo", outputs[rname][11]["show_isis_flex_algo.ref"] + ) router_compare_json_output( - rname, "show mpls table json", - outputs[rname][11]["show_mpls_table.ref"]) + rname, "show mpls table json", outputs[rname][11]["show_mpls_table.ref"] + ) if __name__ == "__main__": diff --git a/tests/topotests/isis_sr_flex_algo_topo2/rt0/isisd.conf b/tests/topotests/isis_sr_flex_algo_topo2/rt0/isisd.conf index cbf25504ef..c102b1b22b 100644 --- a/tests/topotests/isis_sr_flex_algo_topo2/rt0/isisd.conf +++ b/tests/topotests/isis_sr_flex_algo_topo2/rt0/isisd.conf @@ -16,13 +16,13 @@ interface lo ! interface eth-rt1 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt5 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! diff --git a/tests/topotests/isis_sr_flex_algo_topo2/rt0/zebra.conf b/tests/topotests/isis_sr_flex_algo_topo2/rt0/zebra.conf index 89837d4cf5..a4b1f2a655 100644 --- a/tests/topotests/isis_sr_flex_algo_topo2/rt0/zebra.conf +++ b/tests/topotests/isis_sr_flex_algo_topo2/rt0/zebra.conf @@ -3,7 +3,6 @@ log file zebra.log hostname rt0 ! !log stdout notifications -!log monitor notifications !log commands ! debug zebra packet diff --git a/tests/topotests/isis_sr_flex_algo_topo2/rt1/isisd.conf b/tests/topotests/isis_sr_flex_algo_topo2/rt1/isisd.conf index b6bba0c1c3..a7933888cc 100644 --- a/tests/topotests/isis_sr_flex_algo_topo2/rt1/isisd.conf +++ b/tests/topotests/isis_sr_flex_algo_topo2/rt1/isisd.conf @@ -16,25 +16,25 @@ interface lo ! interface eth-rt0 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt2 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt4 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt5 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! diff --git a/tests/topotests/isis_sr_flex_algo_topo2/rt1/zebra.conf b/tests/topotests/isis_sr_flex_algo_topo2/rt1/zebra.conf index 25a96290ae..f11daa5c2a 100644 --- a/tests/topotests/isis_sr_flex_algo_topo2/rt1/zebra.conf +++ b/tests/topotests/isis_sr_flex_algo_topo2/rt1/zebra.conf @@ -3,7 +3,6 @@ log file zebra.log hostname rt1 ! log stdout notifications -log monitor notifications log commands ! !debug zebra packet diff --git a/tests/topotests/isis_sr_flex_algo_topo2/rt2/isisd.conf b/tests/topotests/isis_sr_flex_algo_topo2/rt2/isisd.conf index f051a68e21..312a6df228 100644 --- a/tests/topotests/isis_sr_flex_algo_topo2/rt2/isisd.conf +++ b/tests/topotests/isis_sr_flex_algo_topo2/rt2/isisd.conf @@ -16,19 +16,19 @@ interface lo ! interface eth-rt1 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt3 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt6 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! diff --git a/tests/topotests/isis_sr_flex_algo_topo2/rt2/zebra.conf b/tests/topotests/isis_sr_flex_algo_topo2/rt2/zebra.conf index d739a732a9..ca3235aee5 100644 --- a/tests/topotests/isis_sr_flex_algo_topo2/rt2/zebra.conf +++ b/tests/topotests/isis_sr_flex_algo_topo2/rt2/zebra.conf @@ -3,7 +3,6 @@ log file zebra.log hostname rt2 ! log stdout notifications -log monitor notifications log commands ! !debug zebra packet diff --git a/tests/topotests/isis_sr_flex_algo_topo2/rt3/isisd.conf b/tests/topotests/isis_sr_flex_algo_topo2/rt3/isisd.conf index 644e656bfd..c287e8a5da 100644 --- a/tests/topotests/isis_sr_flex_algo_topo2/rt3/isisd.conf +++ b/tests/topotests/isis_sr_flex_algo_topo2/rt3/isisd.conf @@ -16,25 +16,25 @@ interface lo ! interface eth-rt2 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt4 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt7 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt9 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! diff --git a/tests/topotests/isis_sr_flex_algo_topo2/rt3/zebra.conf b/tests/topotests/isis_sr_flex_algo_topo2/rt3/zebra.conf index 5c3bed0763..9a999104c9 100644 --- a/tests/topotests/isis_sr_flex_algo_topo2/rt3/zebra.conf +++ b/tests/topotests/isis_sr_flex_algo_topo2/rt3/zebra.conf @@ -3,7 +3,6 @@ log file zebra.log hostname rt3 ! log stdout notifications -log monitor notifications log commands ! !debug zebra packet diff --git a/tests/topotests/isis_sr_flex_algo_topo2/rt4/isisd.conf b/tests/topotests/isis_sr_flex_algo_topo2/rt4/isisd.conf index 1ab200fbd8..c040ce200b 100644 --- a/tests/topotests/isis_sr_flex_algo_topo2/rt4/isisd.conf +++ b/tests/topotests/isis_sr_flex_algo_topo2/rt4/isisd.conf @@ -16,19 +16,19 @@ interface lo ! interface eth-rt1 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt3 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt8 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! diff --git a/tests/topotests/isis_sr_flex_algo_topo2/rt4/zebra.conf b/tests/topotests/isis_sr_flex_algo_topo2/rt4/zebra.conf index 9c00013e70..5037041514 100644 --- a/tests/topotests/isis_sr_flex_algo_topo2/rt4/zebra.conf +++ b/tests/topotests/isis_sr_flex_algo_topo2/rt4/zebra.conf @@ -3,7 +3,6 @@ log file zebra.log hostname rt4 ! log stdout notifications -log monitor notifications log commands ! !debug zebra packet diff --git a/tests/topotests/isis_sr_flex_algo_topo2/rt5/isisd.conf b/tests/topotests/isis_sr_flex_algo_topo2/rt5/isisd.conf index 54cc37711e..6cf87d44fb 100644 --- a/tests/topotests/isis_sr_flex_algo_topo2/rt5/isisd.conf +++ b/tests/topotests/isis_sr_flex_algo_topo2/rt5/isisd.conf @@ -16,25 +16,25 @@ interface lo ! interface eth-rt0 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt1 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt6 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt8 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! diff --git a/tests/topotests/isis_sr_flex_algo_topo2/rt5/zebra.conf b/tests/topotests/isis_sr_flex_algo_topo2/rt5/zebra.conf index 61c599db7b..5f96fd4ae7 100644 --- a/tests/topotests/isis_sr_flex_algo_topo2/rt5/zebra.conf +++ b/tests/topotests/isis_sr_flex_algo_topo2/rt5/zebra.conf @@ -3,7 +3,6 @@ log file zebra.log hostname rt5 ! log stdout notifications -log monitor notifications log commands ! !debug zebra packet diff --git a/tests/topotests/isis_sr_flex_algo_topo2/rt6/isisd.conf b/tests/topotests/isis_sr_flex_algo_topo2/rt6/isisd.conf index fc8660cfa6..87a259696d 100644 --- a/tests/topotests/isis_sr_flex_algo_topo2/rt6/isisd.conf +++ b/tests/topotests/isis_sr_flex_algo_topo2/rt6/isisd.conf @@ -16,19 +16,19 @@ interface lo ! interface eth-rt2 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt5 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt7 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! diff --git a/tests/topotests/isis_sr_flex_algo_topo2/rt6/zebra.conf b/tests/topotests/isis_sr_flex_algo_topo2/rt6/zebra.conf index b63401e114..23a99a0c93 100644 --- a/tests/topotests/isis_sr_flex_algo_topo2/rt6/zebra.conf +++ b/tests/topotests/isis_sr_flex_algo_topo2/rt6/zebra.conf @@ -3,7 +3,6 @@ log file zebra.log hostname rt6 ! log stdout notifications -log monitor notifications log commands ! !debug zebra packet diff --git a/tests/topotests/isis_sr_flex_algo_topo2/rt7/isisd.conf b/tests/topotests/isis_sr_flex_algo_topo2/rt7/isisd.conf index 10dc9812a4..6645542db9 100644 --- a/tests/topotests/isis_sr_flex_algo_topo2/rt7/isisd.conf +++ b/tests/topotests/isis_sr_flex_algo_topo2/rt7/isisd.conf @@ -16,25 +16,25 @@ interface lo ! interface eth-rt3 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt6 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt8 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt9 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! diff --git a/tests/topotests/isis_sr_flex_algo_topo2/rt7/zebra.conf b/tests/topotests/isis_sr_flex_algo_topo2/rt7/zebra.conf index b5a28c7f1a..9be1b488cc 100644 --- a/tests/topotests/isis_sr_flex_algo_topo2/rt7/zebra.conf +++ b/tests/topotests/isis_sr_flex_algo_topo2/rt7/zebra.conf @@ -3,7 +3,6 @@ log file zebra.log hostname rt7 ! log stdout notifications -log monitor notifications log commands ! !debug zebra packet diff --git a/tests/topotests/isis_sr_flex_algo_topo2/rt8/isisd.conf b/tests/topotests/isis_sr_flex_algo_topo2/rt8/isisd.conf index 4ca45a8ad9..04e925e482 100644 --- a/tests/topotests/isis_sr_flex_algo_topo2/rt8/isisd.conf +++ b/tests/topotests/isis_sr_flex_algo_topo2/rt8/isisd.conf @@ -14,19 +14,19 @@ interface lo ! interface eth-rt4 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt5 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt7 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! diff --git a/tests/topotests/isis_sr_flex_algo_topo2/rt8/zebra.conf b/tests/topotests/isis_sr_flex_algo_topo2/rt8/zebra.conf index dd63f8cc2f..eaaac74fc3 100644 --- a/tests/topotests/isis_sr_flex_algo_topo2/rt8/zebra.conf +++ b/tests/topotests/isis_sr_flex_algo_topo2/rt8/zebra.conf @@ -3,7 +3,6 @@ log file zebra.log hostname rt8 ! log stdout notifications -log monitor notifications log commands ! !debug zebra packet diff --git a/tests/topotests/isis_sr_flex_algo_topo2/rt9/isisd.conf b/tests/topotests/isis_sr_flex_algo_topo2/rt9/isisd.conf index 89eab274c7..dabb9986df 100644 --- a/tests/topotests/isis_sr_flex_algo_topo2/rt9/isisd.conf +++ b/tests/topotests/isis_sr_flex_algo_topo2/rt9/isisd.conf @@ -16,13 +16,13 @@ interface lo ! interface eth-rt3 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! interface eth-rt7 ip router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point isis circuit-type level-1 ! diff --git a/tests/topotests/isis_sr_flex_algo_topo2/rt9/zebra.conf b/tests/topotests/isis_sr_flex_algo_topo2/rt9/zebra.conf index 378a1969be..513cf56102 100644 --- a/tests/topotests/isis_sr_flex_algo_topo2/rt9/zebra.conf +++ b/tests/topotests/isis_sr_flex_algo_topo2/rt9/zebra.conf @@ -3,7 +3,6 @@ log file zebra.log hostname rt9 ! log stdout notifications -log monitor notifications log commands ! !debug zebra packet diff --git a/tests/topotests/isis_sr_te_topo1/rt1/isisd.conf b/tests/topotests/isis_sr_te_topo1/rt1/isisd.conf index 3d5ac20451..3a94af7e0d 100644 --- a/tests/topotests/isis_sr_te_topo1/rt1/isisd.conf +++ b/tests/topotests/isis_sr_te_topo1/rt1/isisd.conf @@ -16,7 +16,7 @@ interface lo interface eth-sw1 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 ! router isis 1 net 49.0000.0000.0000.0001.00 diff --git a/tests/topotests/isis_sr_te_topo1/rt2/isisd.conf b/tests/topotests/isis_sr_te_topo1/rt2/isisd.conf index ba214c92c1..553e72cb2d 100644 --- a/tests/topotests/isis_sr_te_topo1/rt2/isisd.conf +++ b/tests/topotests/isis_sr_te_topo1/rt2/isisd.conf @@ -15,19 +15,19 @@ interface lo interface eth-sw1 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 ! interface eth-rt4-1 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-multiplier 10 ! interface eth-rt4-2 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-multiplier 10 ! router isis 1 net 49.0000.0000.0000.0002.00 diff --git a/tests/topotests/isis_sr_te_topo1/rt3/isisd.conf b/tests/topotests/isis_sr_te_topo1/rt3/isisd.conf index 482d8152c2..8d89612b5c 100644 --- a/tests/topotests/isis_sr_te_topo1/rt3/isisd.conf +++ b/tests/topotests/isis_sr_te_topo1/rt3/isisd.conf @@ -15,19 +15,19 @@ interface lo interface eth-sw1 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-multiplier 10 ! interface eth-rt5-1 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-multiplier 10 ! interface eth-rt5-2 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-multiplier 10 ! router isis 1 net 49.0000.0000.0000.0003.00 diff --git a/tests/topotests/isis_sr_te_topo1/rt4/isisd.conf b/tests/topotests/isis_sr_te_topo1/rt4/isisd.conf index 851c6da019..e5f72a7713 100644 --- a/tests/topotests/isis_sr_te_topo1/rt4/isisd.conf +++ b/tests/topotests/isis_sr_te_topo1/rt4/isisd.conf @@ -16,25 +16,25 @@ interface eth-rt2-1 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-multiplier 10 ! interface eth-rt2-2 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-multiplier 10 ! interface eth-rt5 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-multiplier 10 ! interface eth-rt6 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-multiplier 10 ! router isis 1 net 49.0000.0000.0000.0004.00 diff --git a/tests/topotests/isis_sr_te_topo1/rt5/isisd.conf b/tests/topotests/isis_sr_te_topo1/rt5/isisd.conf index 4cc54f318c..1a66d18ee1 100644 --- a/tests/topotests/isis_sr_te_topo1/rt5/isisd.conf +++ b/tests/topotests/isis_sr_te_topo1/rt5/isisd.conf @@ -16,25 +16,25 @@ interface eth-rt3-1 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-multiplier 10 ! interface eth-rt3-2 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-multiplier 10 ! interface eth-rt4 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-multiplier 10 ! interface eth-rt6 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-multiplier 10 ! router isis 1 net 49.0000.0000.0000.0005.00 diff --git a/tests/topotests/isis_sr_te_topo1/rt6/isisd.conf b/tests/topotests/isis_sr_te_topo1/rt6/isisd.conf index 8fec87b929..bfa988305b 100644 --- a/tests/topotests/isis_sr_te_topo1/rt6/isisd.conf +++ b/tests/topotests/isis_sr_te_topo1/rt6/isisd.conf @@ -16,13 +16,13 @@ interface eth-rt4 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-multiplier 10 ! interface eth-rt5 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-multiplier 10 ! router isis 1 net 49.0000.0000.0000.0006.00 diff --git a/tests/topotests/isis_sr_topo1/rt1/isisd.conf b/tests/topotests/isis_sr_topo1/rt1/isisd.conf index ed09753d20..ef8d4275c2 100644 --- a/tests/topotests/isis_sr_topo1/rt1/isisd.conf +++ b/tests/topotests/isis_sr_topo1/rt1/isisd.conf @@ -16,7 +16,8 @@ interface lo interface eth-sw1 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! router isis 1 lsp-gen-interval 2 diff --git a/tests/topotests/isis_sr_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_sr_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref index 26f0dffa7a..9c5901b90f 100644 --- a/tests/topotests/isis_sr_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_sr_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref @@ -11,14 +11,14 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 64, "state": "up" }, { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0002", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 64, "state": "up" } diff --git a/tests/topotests/isis_sr_topo1/rt2/isisd.conf b/tests/topotests/isis_sr_topo1/rt2/isisd.conf index 9b8efe40e9..e65ec81a3c 100644 --- a/tests/topotests/isis_sr_topo1/rt2/isisd.conf +++ b/tests/topotests/isis_sr_topo1/rt2/isisd.conf @@ -15,19 +15,22 @@ interface lo interface eth-sw1 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface eth-rt4-1 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface eth-rt4-2 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! router isis 1 lsp-gen-interval 2 diff --git a/tests/topotests/isis_sr_topo1/rt2/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_sr_topo1/rt2/step1/show_yang_interface_isis_adjacencies.ref index 07f43e5999..5e46ddf728 100644 --- a/tests/topotests/isis_sr_topo1/rt2/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_sr_topo1/rt2/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0004", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0004", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -49,14 +49,14 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 64, "state": "up" }, { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0001", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 64, "state": "up" } diff --git a/tests/topotests/isis_sr_topo1/rt3/isisd.conf b/tests/topotests/isis_sr_topo1/rt3/isisd.conf index ded8bd1576..e7b8d942cc 100644 --- a/tests/topotests/isis_sr_topo1/rt3/isisd.conf +++ b/tests/topotests/isis_sr_topo1/rt3/isisd.conf @@ -15,19 +15,22 @@ interface lo interface eth-sw1 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface eth-rt5-1 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface eth-rt5-2 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! router isis 1 lsp-gen-interval 2 diff --git a/tests/topotests/isis_sr_topo1/rt3/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_sr_topo1/rt3/step1/show_yang_interface_isis_adjacencies.ref index 7fa6f5cf47..a284240d24 100644 --- a/tests/topotests/isis_sr_topo1/rt3/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_sr_topo1/rt3/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0005", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0005", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -49,14 +49,14 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0001", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 64, "state": "up" }, { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0002", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 64, "state": "up" } diff --git a/tests/topotests/isis_sr_topo1/rt4/isisd.conf b/tests/topotests/isis_sr_topo1/rt4/isisd.conf index ba9704531c..92ea1ea3d9 100644 --- a/tests/topotests/isis_sr_topo1/rt4/isisd.conf +++ b/tests/topotests/isis_sr_topo1/rt4/isisd.conf @@ -16,25 +16,29 @@ interface eth-rt2-1 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface eth-rt2-2 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface eth-rt5 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface eth-rt6 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! router isis 1 lsp-gen-interval 2 diff --git a/tests/topotests/isis_sr_topo1/rt4/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_sr_topo1/rt4/step1/show_yang_interface_isis_adjacencies.ref index 2eb64b6fc9..0ca7a76bd4 100644 --- a/tests/topotests/isis_sr_topo1/rt4/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_sr_topo1/rt4/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0002", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0002", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -49,7 +49,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0005", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -68,7 +68,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0006", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_sr_topo1/rt4/step2/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_sr_topo1/rt4/step2/show_yang_interface_isis_adjacencies.ref index be1e00b8a2..52682fffca 100644 --- a/tests/topotests/isis_sr_topo1/rt4/step2/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_sr_topo1/rt4/step2/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0002", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0002", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -49,7 +49,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0006", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_sr_topo1/rt4/step3/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_sr_topo1/rt4/step3/show_yang_interface_isis_adjacencies.ref index bcade1ca90..a2e920cba2 100644 --- a/tests/topotests/isis_sr_topo1/rt4/step3/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_sr_topo1/rt4/step3/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0002", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0002", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_sr_topo1/rt5/isisd.conf b/tests/topotests/isis_sr_topo1/rt5/isisd.conf index 3fe7bdf1b2..de604d71f4 100644 --- a/tests/topotests/isis_sr_topo1/rt5/isisd.conf +++ b/tests/topotests/isis_sr_topo1/rt5/isisd.conf @@ -16,25 +16,29 @@ interface eth-rt3-1 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface eth-rt3-2 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface eth-rt4 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface eth-rt6 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! router isis 1 lsp-gen-interval 2 diff --git a/tests/topotests/isis_sr_topo1/rt5/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_sr_topo1/rt5/step1/show_yang_interface_isis_adjacencies.ref index 1ff8c2cd4e..f40b0d353d 100644 --- a/tests/topotests/isis_sr_topo1/rt5/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_sr_topo1/rt5/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -49,7 +49,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0004", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -68,7 +68,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0006", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_sr_topo1/rt5/step2/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_sr_topo1/rt5/step2/show_yang_interface_isis_adjacencies.ref index d9ac0a8d00..153e8661a0 100644 --- a/tests/topotests/isis_sr_topo1/rt5/step2/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_sr_topo1/rt5/step2/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -49,7 +49,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0006", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_sr_topo1/rt5/step3/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_sr_topo1/rt5/step3/show_yang_interface_isis_adjacencies.ref index 0b8e6ba5b9..2008d8467f 100644 --- a/tests/topotests/isis_sr_topo1/rt5/step3/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_sr_topo1/rt5/step3/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_sr_topo1/rt5/step4/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_sr_topo1/rt5/step4/show_yang_interface_isis_adjacencies.ref index d9ac0a8d00..153e8661a0 100644 --- a/tests/topotests/isis_sr_topo1/rt5/step4/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_sr_topo1/rt5/step4/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -49,7 +49,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0006", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_sr_topo1/rt6/isisd.conf b/tests/topotests/isis_sr_topo1/rt6/isisd.conf index e7a7e2dfd4..b96a2c6e1e 100644 --- a/tests/topotests/isis_sr_topo1/rt6/isisd.conf +++ b/tests/topotests/isis_sr_topo1/rt6/isisd.conf @@ -16,13 +16,15 @@ interface eth-rt4 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface eth-rt5 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! router isis 1 lsp-gen-interval 2 diff --git a/tests/topotests/isis_sr_topo1/rt6/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_sr_topo1/rt6/step1/show_yang_interface_isis_adjacencies.ref index 734832358f..8300ca0b5c 100644 --- a/tests/topotests/isis_sr_topo1/rt6/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_sr_topo1/rt6/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0004", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0005", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_sr_topo1/test_isis_sr_topo1.py b/tests/topotests/isis_sr_topo1/test_isis_sr_topo1.py index 40b87e3a9e..9a4085ab55 100644 --- a/tests/topotests/isis_sr_topo1/test_isis_sr_topo1.py +++ b/tests/topotests/isis_sr_topo1/test_isis_sr_topo1.py @@ -987,7 +987,7 @@ def test_isis_adjacencies_step12(): 'vtysh -c "conf t" -c "interface eth-rt5" -c "isis network point-to-point"' ) tgen.net["rt4"].cmd( - 'vtysh -c "conf t" -c "interface eth-rt5" -c "isis hello-multiplier 3"' + 'vtysh -c "conf t" -c "interface eth-rt5" -c "isis hello-interval 1" -c "isis hello-multiplier 10"' ) tgen.net["rt6"].cmd( 'vtysh -c "conf t" -c "router isis 1" -c "segment-routing global-block 16000 23999"' diff --git a/tests/topotests/isis_srv6_topo1/dst/sharpd.conf b/tests/topotests/isis_srv6_topo1/dst/sharpd.conf new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/isis_srv6_topo1/dst/zebra.conf b/tests/topotests/isis_srv6_topo1/dst/zebra.conf new file mode 100644 index 0000000000..80741856cb --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/dst/zebra.conf @@ -0,0 +1,22 @@ +log file zebra.log +! +hostname dst +! +! debug zebra kernel +! debug zebra packet +! debug zebra mpls +! +interface lo + ip address 9.9.9.2/32 + ipv6 address fc00:0:9::1/128 +! +interface eth-rt6 + ip address 10.0.10.2/24 + ipv6 address 2001:db8:10::2/64 +! +ip forwarding +! +ip route 2001:db8:1::1 2001:db8:10::1 +! +line vty +! diff --git a/tests/topotests/isis_srv6_topo1/rt1/isisd.conf b/tests/topotests/isis_srv6_topo1/rt1/isisd.conf new file mode 100644 index 0000000000..29e1a31171 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/isisd.conf @@ -0,0 +1,35 @@ +password 1 +hostname rt1 +log file isisd.log +! +! debug isis events +! debug isis route-events +! debug isis spf-events +! debug isis sr-events +! debug isis lsp-gen +! +interface lo + ip router isis 1 + ipv6 router isis 1 + isis passive +! +interface eth-sw1 + ip router isis 1 + ipv6 router isis 1 + isis hello-interval 1 + isis hello-multiplier 10 +! +router isis 1 + lsp-gen-interval 2 + net 49.0000.0000.0000.0001.00 + is-type level-1 + topology ipv6-unicast + segment-routing srv6 + locator loc1 + node-msd + max-segs-left 3 + max-end-pop 3 + max-h-encaps 2 + max-end-d 5 + interface sr0 +! diff --git a/tests/topotests/isis_srv6_topo1/rt1/sharpd.conf b/tests/topotests/isis_srv6_topo1/rt1/sharpd.conf new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/isis_srv6_topo1/rt1/step1/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt1/step1/show_ip_route.ref new file mode 100644 index 0000000000..590d75afbf --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step1/show_ip_route.ref @@ -0,0 +1,276 @@ +{ + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step1/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt1/step1/show_ipv6_route.ref new file mode 100644 index 0000000000..2d30fc4d17 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step1/show_ipv6_route.ref @@ -0,0 +1,270 @@ +{ + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:1:1::\/64":[ + { + "prefix":"fc00:0:1:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"eth-sw1", + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:1:2::\/64":[ + { + "prefix":"fc00:0:1:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"eth-sw1", + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step1/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt1/step1/show_srv6_locator_table.ref new file mode 100644 index 0000000000..bb10aba942 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step1/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:1::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:1::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..9c5901b90f --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,32 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step2/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt1/step2/show_ip_route.ref new file mode 100644 index 0000000000..590d75afbf --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step2/show_ip_route.ref @@ -0,0 +1,276 @@ +{ + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step2/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt1/step2/show_ipv6_route.ref new file mode 100644 index 0000000000..9dda5dc3e8 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step2/show_ipv6_route.ref @@ -0,0 +1,204 @@ +{ + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step2/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt1/step2/show_srv6_locator_table.ref new file mode 100644 index 0000000000..2c63c08510 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step2/show_srv6_locator_table.ref @@ -0,0 +1,2 @@ +{ +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step2/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt1/step2/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..9c5901b90f --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step2/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,32 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step3/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt1/step3/show_ip_route.ref new file mode 100644 index 0000000000..590d75afbf --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step3/show_ip_route.ref @@ -0,0 +1,276 @@ +{ + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step3/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt1/step3/show_ipv6_route.ref new file mode 100644 index 0000000000..2d30fc4d17 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step3/show_ipv6_route.ref @@ -0,0 +1,270 @@ +{ + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:1:1::\/64":[ + { + "prefix":"fc00:0:1:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"eth-sw1", + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:1:2::\/64":[ + { + "prefix":"fc00:0:1:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"eth-sw1", + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step3/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt1/step3/show_srv6_locator_table.ref new file mode 100644 index 0000000000..bb10aba942 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step3/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:1::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:1::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step3/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt1/step3/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..9c5901b90f --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step3/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,32 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step4/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt1/step4/show_ip_route.ref new file mode 100644 index 0000000000..590d75afbf --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step4/show_ip_route.ref @@ -0,0 +1,276 @@ +{ + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step4/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt1/step4/show_ipv6_route.ref new file mode 100644 index 0000000000..9dda5dc3e8 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step4/show_ipv6_route.ref @@ -0,0 +1,204 @@ +{ + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step4/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt1/step4/show_srv6_locator_table.ref new file mode 100644 index 0000000000..f9561be5f2 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step4/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:1::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:1::/48", + "proto":"system" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step4/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt1/step4/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..9c5901b90f --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step4/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,32 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step5/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt1/step5/show_ip_route.ref new file mode 100644 index 0000000000..590d75afbf --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step5/show_ip_route.ref @@ -0,0 +1,276 @@ +{ + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step5/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt1/step5/show_ipv6_route.ref new file mode 100644 index 0000000000..2d30fc4d17 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step5/show_ipv6_route.ref @@ -0,0 +1,270 @@ +{ + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:1:1::\/64":[ + { + "prefix":"fc00:0:1:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"eth-sw1", + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:1:2::\/64":[ + { + "prefix":"fc00:0:1:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"eth-sw1", + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step5/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt1/step5/show_srv6_locator_table.ref new file mode 100644 index 0000000000..bb10aba942 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step5/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:1::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:1::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step5/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt1/step5/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..9c5901b90f --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step5/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,32 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step6/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt1/step6/show_ip_route.ref new file mode 100644 index 0000000000..590d75afbf --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step6/show_ip_route.ref @@ -0,0 +1,276 @@ +{ + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step6/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt1/step6/show_ipv6_route.ref new file mode 100644 index 0000000000..9dda5dc3e8 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step6/show_ipv6_route.ref @@ -0,0 +1,204 @@ +{ + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step6/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt1/step6/show_srv6_locator_table.ref new file mode 100644 index 0000000000..f9561be5f2 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step6/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:1::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:1::/48", + "proto":"system" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step6/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt1/step6/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..9c5901b90f --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step6/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,32 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step7/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt1/step7/show_ip_route.ref new file mode 100644 index 0000000000..590d75afbf --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step7/show_ip_route.ref @@ -0,0 +1,276 @@ +{ + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step7/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt1/step7/show_ipv6_route.ref new file mode 100644 index 0000000000..2d30fc4d17 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step7/show_ipv6_route.ref @@ -0,0 +1,270 @@ +{ + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:1:1::\/64":[ + { + "prefix":"fc00:0:1:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"eth-sw1", + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:1:2::\/64":[ + { + "prefix":"fc00:0:1:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"eth-sw1", + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step7/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt1/step7/show_srv6_locator_table.ref new file mode 100644 index 0000000000..bb10aba942 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step7/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:1::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:1::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step7/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt1/step7/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..9c5901b90f --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step7/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,32 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step8/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt1/step8/show_ip_route.ref new file mode 100644 index 0000000000..590d75afbf --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step8/show_ip_route.ref @@ -0,0 +1,276 @@ +{ + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step8/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt1/step8/show_ipv6_route.ref new file mode 100644 index 0000000000..9dda5dc3e8 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step8/show_ipv6_route.ref @@ -0,0 +1,204 @@ +{ + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step8/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt1/step8/show_srv6_locator_table.ref new file mode 100644 index 0000000000..2c63c08510 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step8/show_srv6_locator_table.ref @@ -0,0 +1,2 @@ +{ +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step8/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt1/step8/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..9c5901b90f --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step8/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,32 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step9/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt1/step9/show_ip_route.ref new file mode 100644 index 0000000000..590d75afbf --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step9/show_ip_route.ref @@ -0,0 +1,276 @@ +{ + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step9/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt1/step9/show_ipv6_route.ref new file mode 100644 index 0000000000..2d30fc4d17 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step9/show_ipv6_route.ref @@ -0,0 +1,270 @@ +{ + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:1:1::\/64":[ + { + "prefix":"fc00:0:1:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"eth-sw1", + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:1:2::\/64":[ + { + "prefix":"fc00:0:1:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"eth-sw1", + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step9/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt1/step9/show_srv6_locator_table.ref new file mode 100644 index 0000000000..bb10aba942 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step9/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:1::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:1::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/step9/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt1/step9/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..9c5901b90f --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/step9/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,32 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt1/zebra.conf b/tests/topotests/isis_srv6_topo1/rt1/zebra.conf new file mode 100644 index 0000000000..05f60fe82e --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt1/zebra.conf @@ -0,0 +1,28 @@ +log file zebra.log +! +hostname rt1 +! +! debug zebra kernel +! debug zebra packet +! +interface lo + ip address 1.1.1.1/32 + ipv6 address fc00:0:1::1/128 +! +interface eth-sw1 + ip address 10.0.1.1/24 + ipv6 address 2001:db8:1::1/64 +! +segment-routing + srv6 + locators + locator loc1 + prefix fc00:0:1::/48 block-len 32 node-len 16 func-bits 16 + behavior usid + ! + ! +! +ip forwarding +! +line vty +! diff --git a/tests/topotests/isis_srv6_topo1/rt2/isisd.conf b/tests/topotests/isis_srv6_topo1/rt2/isisd.conf new file mode 100644 index 0000000000..b095f04910 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/isisd.conf @@ -0,0 +1,48 @@ +hostname rt2 +log file isisd.log +! +! debug isis events +! debug isis route-events +! debug isis spf-events +! debug isis sr-events +! debug isis lsp-gen +! +interface lo + ip router isis 1 + ipv6 router isis 1 + isis passive +! +interface eth-sw1 + ip router isis 1 + ipv6 router isis 1 + isis hello-interval 1 + isis hello-multiplier 10 +! +interface eth-rt4-1 + ip router isis 1 + ipv6 router isis 1 + isis network point-to-point + isis hello-interval 1 + isis hello-multiplier 10 +! +interface eth-rt4-2 + ip router isis 1 + ipv6 router isis 1 + isis network point-to-point + isis hello-interval 1 + isis hello-multiplier 10 +! +router isis 1 + lsp-gen-interval 2 + net 49.0000.0000.0000.0002.00 + is-type level-1 + topology ipv6-unicast + segment-routing srv6 + locator loc1 + node-msd + max-segs-left 3 + max-end-pop 3 + max-h-encaps 2 + max-end-d 5 + interface sr0 +! diff --git a/tests/topotests/isis_srv6_topo1/rt2/step1/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt2/step1/show_ip_route.ref new file mode 100644 index 0000000000..1d4a9e9a25 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step1/show_ip_route.ref @@ -0,0 +1,320 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1" + }, + { + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2" + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step1/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt2/step1/show_ipv6_route.ref new file mode 100644 index 0000000000..150fa92241 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step1/show_ipv6_route.ref @@ -0,0 +1,346 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:2:1::\/64":[ + { + "prefix":"fc00:0:2:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:2::\/64":[ + { + "prefix":"fc00:0:2:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:3::\/64":[ + { + "prefix":"fc00:0:2:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:4::\/64":[ + { + "prefix":"fc00:0:2:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step1/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt2/step1/show_srv6_locator_table.ref new file mode 100644 index 0000000000..f3399319f3 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step1/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:2::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:2::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt2/step1/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..5e46ddf728 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step1/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,70 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt4-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt4-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0001", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step2/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt2/step2/show_ip_route.ref new file mode 100644 index 0000000000..1d4a9e9a25 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step2/show_ip_route.ref @@ -0,0 +1,320 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1" + }, + { + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2" + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step2/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt2/step2/show_ipv6_route.ref new file mode 100644 index 0000000000..f9c2d098cc --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step2/show_ipv6_route.ref @@ -0,0 +1,327 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:2:1::\/64":[ + { + "prefix":"fc00:0:2:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:2::\/64":[ + { + "prefix":"fc00:0:2:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:3::\/64":[ + { + "prefix":"fc00:0:2:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:4::\/64":[ + { + "prefix":"fc00:0:2:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step2/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt2/step2/show_srv6_locator_table.ref new file mode 100644 index 0000000000..f3399319f3 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step2/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:2::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:2::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step2/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt2/step2/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..5e46ddf728 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step2/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,70 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt4-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt4-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0001", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step3/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt2/step3/show_ip_route.ref new file mode 100644 index 0000000000..1d4a9e9a25 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step3/show_ip_route.ref @@ -0,0 +1,320 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1" + }, + { + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2" + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step3/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt2/step3/show_ipv6_route.ref new file mode 100644 index 0000000000..150fa92241 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step3/show_ipv6_route.ref @@ -0,0 +1,346 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:2:1::\/64":[ + { + "prefix":"fc00:0:2:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:2::\/64":[ + { + "prefix":"fc00:0:2:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:3::\/64":[ + { + "prefix":"fc00:0:2:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:4::\/64":[ + { + "prefix":"fc00:0:2:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step3/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt2/step3/show_srv6_locator_table.ref new file mode 100644 index 0000000000..f3399319f3 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step3/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:2::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:2::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step3/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt2/step3/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..5e46ddf728 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step3/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,70 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt4-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt4-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0001", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step4/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt2/step4/show_ip_route.ref new file mode 100644 index 0000000000..1d4a9e9a25 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step4/show_ip_route.ref @@ -0,0 +1,320 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1" + }, + { + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2" + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step4/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt2/step4/show_ipv6_route.ref new file mode 100644 index 0000000000..f9c2d098cc --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step4/show_ipv6_route.ref @@ -0,0 +1,327 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:2:1::\/64":[ + { + "prefix":"fc00:0:2:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:2::\/64":[ + { + "prefix":"fc00:0:2:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:3::\/64":[ + { + "prefix":"fc00:0:2:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:4::\/64":[ + { + "prefix":"fc00:0:2:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step4/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt2/step4/show_srv6_locator_table.ref new file mode 100644 index 0000000000..f3399319f3 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step4/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:2::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:2::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step4/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt2/step4/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..5e46ddf728 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step4/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,70 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt4-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt4-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0001", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step5/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt2/step5/show_ip_route.ref new file mode 100644 index 0000000000..1d4a9e9a25 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step5/show_ip_route.ref @@ -0,0 +1,320 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1" + }, + { + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2" + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step5/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt2/step5/show_ipv6_route.ref new file mode 100644 index 0000000000..150fa92241 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step5/show_ipv6_route.ref @@ -0,0 +1,346 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:2:1::\/64":[ + { + "prefix":"fc00:0:2:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:2::\/64":[ + { + "prefix":"fc00:0:2:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:3::\/64":[ + { + "prefix":"fc00:0:2:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:4::\/64":[ + { + "prefix":"fc00:0:2:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step5/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt2/step5/show_srv6_locator_table.ref new file mode 100644 index 0000000000..f3399319f3 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step5/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:2::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:2::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step5/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt2/step5/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..5e46ddf728 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step5/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,70 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt4-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt4-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0001", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step6/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt2/step6/show_ip_route.ref new file mode 100644 index 0000000000..1d4a9e9a25 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step6/show_ip_route.ref @@ -0,0 +1,320 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1" + }, + { + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2" + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step6/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt2/step6/show_ipv6_route.ref new file mode 100644 index 0000000000..f9c2d098cc --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step6/show_ipv6_route.ref @@ -0,0 +1,327 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:2:1::\/64":[ + { + "prefix":"fc00:0:2:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:2::\/64":[ + { + "prefix":"fc00:0:2:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:3::\/64":[ + { + "prefix":"fc00:0:2:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:4::\/64":[ + { + "prefix":"fc00:0:2:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step6/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt2/step6/show_srv6_locator_table.ref new file mode 100644 index 0000000000..f3399319f3 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step6/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:2::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:2::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step6/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt2/step6/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..5e46ddf728 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step6/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,70 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt4-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt4-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0001", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step7/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt2/step7/show_ip_route.ref new file mode 100644 index 0000000000..1d4a9e9a25 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step7/show_ip_route.ref @@ -0,0 +1,320 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1" + }, + { + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2" + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step7/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt2/step7/show_ipv6_route.ref new file mode 100644 index 0000000000..150fa92241 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step7/show_ipv6_route.ref @@ -0,0 +1,346 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:2:1::\/64":[ + { + "prefix":"fc00:0:2:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:2::\/64":[ + { + "prefix":"fc00:0:2:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:3::\/64":[ + { + "prefix":"fc00:0:2:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:4::\/64":[ + { + "prefix":"fc00:0:2:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step7/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt2/step7/show_srv6_locator_table.ref new file mode 100644 index 0000000000..f3399319f3 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step7/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:2::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:2::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step7/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt2/step7/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..5e46ddf728 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step7/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,70 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt4-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt4-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0001", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step8/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt2/step8/show_ip_route.ref new file mode 100644 index 0000000000..1d4a9e9a25 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step8/show_ip_route.ref @@ -0,0 +1,320 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1" + }, + { + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2" + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step8/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt2/step8/show_ipv6_route.ref new file mode 100644 index 0000000000..f9c2d098cc --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step8/show_ipv6_route.ref @@ -0,0 +1,327 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:2:1::\/64":[ + { + "prefix":"fc00:0:2:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:2::\/64":[ + { + "prefix":"fc00:0:2:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:3::\/64":[ + { + "prefix":"fc00:0:2:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:4::\/64":[ + { + "prefix":"fc00:0:2:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step8/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt2/step8/show_srv6_locator_table.ref new file mode 100644 index 0000000000..f3399319f3 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step8/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:2::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:2::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step8/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt2/step8/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..5e46ddf728 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step8/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,70 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt4-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt4-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0001", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step9/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt2/step9/show_ip_route.ref new file mode 100644 index 0000000000..1d4a9e9a25 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step9/show_ip_route.ref @@ -0,0 +1,320 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1" + }, + { + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2" + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.3", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.4", + "afi":"ipv4", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step9/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt2/step9/show_ipv6_route.ref new file mode 100644 index 0000000000..150fa92241 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step9/show_ipv6_route.ref @@ -0,0 +1,346 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4-2", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:2:1::\/64":[ + { + "prefix":"fc00:0:2:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:2::\/64":[ + { + "prefix":"fc00:0:2:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:3::\/64":[ + { + "prefix":"fc00:0:2:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:2:4::\/64":[ + { + "prefix":"fc00:0:2:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step9/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt2/step9/show_srv6_locator_table.ref new file mode 100644 index 0000000000..f3399319f3 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step9/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:2::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:2::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/step9/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt2/step9/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..5e46ddf728 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/step9/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,70 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt4-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt4-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0001", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt2/zebra.conf b/tests/topotests/isis_srv6_topo1/rt2/zebra.conf new file mode 100644 index 0000000000..a846a6ea07 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt2/zebra.conf @@ -0,0 +1,34 @@ +log file zebra.log +! +hostname rt2 +! +! debug zebra kernel +! debug zebra packet +! +interface lo + ip address 2.2.2.2/32 + ipv6 address fc00:0:2::1/128 +! +interface eth-sw1 + ip address 10.0.1.2/24 + ipv6 address 2001:db8:1::2/64 +! +interface eth-rt4-1 + ip address 10.0.2.2/24 +! +interface eth-rt4-2 + ip address 10.0.3.2/24 +! +segment-routing + srv6 + locators + locator loc1 + prefix fc00:0:2::/48 block-len 32 node-len 16 func-bits 16 + behavior usid + ! + ! +! +ip forwarding +! +line vty +! diff --git a/tests/topotests/isis_srv6_topo1/rt3/isisd.conf b/tests/topotests/isis_srv6_topo1/rt3/isisd.conf new file mode 100644 index 0000000000..e237db2f49 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/isisd.conf @@ -0,0 +1,48 @@ +hostname rt3 +log file isisd.log +! +! debug isis events +! debug isis route-events +! debug isis spf-events +! debug isis sr-events +! debug isis lsp-gen +! +interface lo + ip router isis 1 + ipv6 router isis 1 + isis passive +! +interface eth-sw1 + ip router isis 1 + ipv6 router isis 1 + isis hello-interval 1 + isis hello-multiplier 10 +! +interface eth-rt5-1 + ip router isis 1 + ipv6 router isis 1 + isis network point-to-point + isis hello-interval 1 + isis hello-multiplier 10 +! +interface eth-rt5-2 + ip router isis 1 + ipv6 router isis 1 + isis network point-to-point + isis hello-interval 1 + isis hello-multiplier 10 +! +router isis 1 + lsp-gen-interval 2 + net 49.0000.0000.0000.0003.00 + is-type level-1 + topology ipv6-unicast + segment-routing srv6 + locator loc1 + node-msd + max-segs-left 3 + max-end-pop 3 + max-h-encaps 2 + max-end-d 5 + interface sr0 +! diff --git a/tests/topotests/isis_srv6_topo1/rt3/step1/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt3/step1/show_ip_route.ref new file mode 100644 index 0000000000..6ce5760e4f --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step1/show_ip_route.ref @@ -0,0 +1,320 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1" + }, + { + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2" + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step1/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt3/step1/show_ipv6_route.ref new file mode 100644 index 0000000000..fc0e5161c2 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step1/show_ipv6_route.ref @@ -0,0 +1,346 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:3:1::\/64":[ + { + "prefix":"fc00:0:3:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:2::\/64":[ + { + "prefix":"fc00:0:3:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:3::\/64":[ + { + "prefix":"fc00:0:3:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:4::\/64":[ + { + "prefix":"fc00:0:3:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step1/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt3/step1/show_srv6_locator_table.ref new file mode 100644 index 0000000000..ffa626123d --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step1/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:3::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:3::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt3/step1/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..a284240d24 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step1/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,70 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt5-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0001", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step2/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt3/step2/show_ip_route.ref new file mode 100644 index 0000000000..6ce5760e4f --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step2/show_ip_route.ref @@ -0,0 +1,320 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1" + }, + { + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2" + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step2/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt3/step2/show_ipv6_route.ref new file mode 100644 index 0000000000..a24d95e78e --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step2/show_ipv6_route.ref @@ -0,0 +1,327 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:3:1::\/64":[ + { + "prefix":"fc00:0:3:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:2::\/64":[ + { + "prefix":"fc00:0:3:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:3::\/64":[ + { + "prefix":"fc00:0:3:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:4::\/64":[ + { + "prefix":"fc00:0:3:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step2/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt3/step2/show_srv6_locator_table.ref new file mode 100644 index 0000000000..ffa626123d --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step2/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:3::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:3::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step2/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt3/step2/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..a284240d24 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step2/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,70 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt5-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0001", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step3/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt3/step3/show_ip_route.ref new file mode 100644 index 0000000000..6ce5760e4f --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step3/show_ip_route.ref @@ -0,0 +1,320 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1" + }, + { + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2" + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step3/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt3/step3/show_ipv6_route.ref new file mode 100644 index 0000000000..fc0e5161c2 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step3/show_ipv6_route.ref @@ -0,0 +1,346 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:3:1::\/64":[ + { + "prefix":"fc00:0:3:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:2::\/64":[ + { + "prefix":"fc00:0:3:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:3::\/64":[ + { + "prefix":"fc00:0:3:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:4::\/64":[ + { + "prefix":"fc00:0:3:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step3/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt3/step3/show_srv6_locator_table.ref new file mode 100644 index 0000000000..ffa626123d --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step3/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:3::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:3::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step3/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt3/step3/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..a284240d24 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step3/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,70 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt5-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0001", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step4/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt3/step4/show_ip_route.ref new file mode 100644 index 0000000000..6ce5760e4f --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step4/show_ip_route.ref @@ -0,0 +1,320 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1" + }, + { + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2" + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step4/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt3/step4/show_ipv6_route.ref new file mode 100644 index 0000000000..a24d95e78e --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step4/show_ipv6_route.ref @@ -0,0 +1,327 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:3:1::\/64":[ + { + "prefix":"fc00:0:3:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:2::\/64":[ + { + "prefix":"fc00:0:3:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:3::\/64":[ + { + "prefix":"fc00:0:3:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:4::\/64":[ + { + "prefix":"fc00:0:3:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step4/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt3/step4/show_srv6_locator_table.ref new file mode 100644 index 0000000000..ffa626123d --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step4/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:3::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:3::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step4/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt3/step4/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..a284240d24 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step4/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,70 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt5-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0001", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step5/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt3/step5/show_ip_route.ref new file mode 100644 index 0000000000..6ce5760e4f --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step5/show_ip_route.ref @@ -0,0 +1,320 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1" + }, + { + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2" + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step5/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt3/step5/show_ipv6_route.ref new file mode 100644 index 0000000000..fc0e5161c2 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step5/show_ipv6_route.ref @@ -0,0 +1,346 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:3:1::\/64":[ + { + "prefix":"fc00:0:3:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:2::\/64":[ + { + "prefix":"fc00:0:3:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:3::\/64":[ + { + "prefix":"fc00:0:3:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:4::\/64":[ + { + "prefix":"fc00:0:3:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step5/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt3/step5/show_srv6_locator_table.ref new file mode 100644 index 0000000000..ffa626123d --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step5/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:3::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:3::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step5/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt3/step5/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..a284240d24 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step5/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,70 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt5-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0001", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step6/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt3/step6/show_ip_route.ref new file mode 100644 index 0000000000..6ce5760e4f --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step6/show_ip_route.ref @@ -0,0 +1,320 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1" + }, + { + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2" + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step6/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt3/step6/show_ipv6_route.ref new file mode 100644 index 0000000000..a24d95e78e --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step6/show_ipv6_route.ref @@ -0,0 +1,327 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:3:1::\/64":[ + { + "prefix":"fc00:0:3:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:2::\/64":[ + { + "prefix":"fc00:0:3:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:3::\/64":[ + { + "prefix":"fc00:0:3:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:4::\/64":[ + { + "prefix":"fc00:0:3:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step6/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt3/step6/show_srv6_locator_table.ref new file mode 100644 index 0000000000..ffa626123d --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step6/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:3::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:3::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step6/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt3/step6/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..a284240d24 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step6/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,70 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt5-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0001", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step7/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt3/step7/show_ip_route.ref new file mode 100644 index 0000000000..6ce5760e4f --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step7/show_ip_route.ref @@ -0,0 +1,320 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1" + }, + { + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2" + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step7/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt3/step7/show_ipv6_route.ref new file mode 100644 index 0000000000..fc0e5161c2 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step7/show_ipv6_route.ref @@ -0,0 +1,346 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:3:1::\/64":[ + { + "prefix":"fc00:0:3:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:2::\/64":[ + { + "prefix":"fc00:0:3:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:3::\/64":[ + { + "prefix":"fc00:0:3:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:4::\/64":[ + { + "prefix":"fc00:0:3:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step7/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt3/step7/show_srv6_locator_table.ref new file mode 100644 index 0000000000..ffa626123d --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step7/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:3::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:3::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step7/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt3/step7/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..a284240d24 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step7/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,70 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt5-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0001", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step8/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt3/step8/show_ip_route.ref new file mode 100644 index 0000000000..6ce5760e4f --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step8/show_ip_route.ref @@ -0,0 +1,320 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1" + }, + { + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2" + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step8/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt3/step8/show_ipv6_route.ref new file mode 100644 index 0000000000..a24d95e78e --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step8/show_ipv6_route.ref @@ -0,0 +1,327 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:3:1::\/64":[ + { + "prefix":"fc00:0:3:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:2::\/64":[ + { + "prefix":"fc00:0:3:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:3::\/64":[ + { + "prefix":"fc00:0:3:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:4::\/64":[ + { + "prefix":"fc00:0:3:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step8/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt3/step8/show_srv6_locator_table.ref new file mode 100644 index 0000000000..ffa626123d --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step8/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:3::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:3::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step8/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt3/step8/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..a284240d24 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step8/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,70 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt5-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0001", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step9/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt3/step9/show_ip_route.ref new file mode 100644 index 0000000000..6ce5760e4f --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step9/show_ip_route.ref @@ -0,0 +1,320 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceName":"eth-sw1" + }, + { + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1" + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1" + }, + { + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2" + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.5", + "afi":"ipv4", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step9/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt3/step9/show_ipv6_route.ref new file mode 100644 index 0000000000..fc0e5161c2 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step9/show_ipv6_route.ref @@ -0,0 +1,346 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-sw1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:3:1::\/64":[ + { + "prefix":"fc00:0:3:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:2::\/64":[ + { + "prefix":"fc00:0:3:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:3::\/64":[ + { + "prefix":"fc00:0:3:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:3:4::\/64":[ + { + "prefix":"fc00:0:3:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step9/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt3/step9/show_srv6_locator_table.ref new file mode 100644 index 0000000000..ffa626123d --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step9/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:3::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:3::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/step9/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt3/step9/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..a284240d24 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/step9/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,70 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt5-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-sw1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0001", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + }, + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 64, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt3/zebra.conf b/tests/topotests/isis_srv6_topo1/rt3/zebra.conf new file mode 100644 index 0000000000..e3bc4dbbb0 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt3/zebra.conf @@ -0,0 +1,33 @@ +log file zebra.log +! +hostname rt3 +! +! debug zebra kernel +! debug zebra packet +! +interface lo + ip address 3.3.3.3/32 + ipv6 address fc00:0:3::1/128 +! +interface eth-sw1 + ip address 10.0.1.3/24 +! +interface eth-rt5-1 + ip address 10.0.4.3/24 +! +interface eth-rt5-2 + ip address 10.0.5.3/24 +! +segment-routing + srv6 + locators + locator loc1 + prefix fc00:0:3::/48 block-len 32 node-len 16 func-bits 16 + behavior usid + ! + ! +! +ip forwarding +! +line vty +! diff --git a/tests/topotests/isis_srv6_topo1/rt4/isisd.conf b/tests/topotests/isis_srv6_topo1/rt4/isisd.conf new file mode 100644 index 0000000000..b4c92146a1 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/isisd.conf @@ -0,0 +1,56 @@ +hostname rt4 +log file isisd.log +! +! debug isis events +! debug isis route-events +! debug isis spf-events +! debug isis sr-events +! debug isis lsp-gen +! +interface lo + ip router isis 1 + ipv6 router isis 1 + isis passive +! +interface eth-rt2-1 + ip router isis 1 + ipv6 router isis 1 + isis network point-to-point + isis hello-interval 1 + isis hello-multiplier 10 +! +interface eth-rt2-2 + ip router isis 1 + ipv6 router isis 1 + isis network point-to-point + isis hello-interval 1 + isis hello-multiplier 10 +! +interface eth-rt5 + ip router isis 1 + ipv6 router isis 1 + isis network point-to-point + isis hello-interval 1 + isis hello-multiplier 10 +! +interface eth-rt6 + ip router isis 1 + ipv6 router isis 1 + isis network point-to-point + isis hello-interval 1 + isis hello-multiplier 10 +! +router isis 1 + lsp-gen-interval 2 + net 49.0000.0000.0000.0004.00 + is-type level-1 + topology ipv6-unicast + segment-routing srv6 + locator loc1 + node-msd + max-segs-left 3 + max-end-pop 3 + max-h-encaps 2 + max-end-d 5 + interface sr0 +! diff --git a/tests/topotests/isis_srv6_topo1/rt4/step1/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt4/step1/show_ip_route.ref new file mode 100644 index 0000000000..0f26fa5d7a --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step1/show_ip_route.ref @@ -0,0 +1,296 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1" + }, + { + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2" + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5" + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6" + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + }, + { + "fib":true, + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step1/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt4/step1/show_ipv6_route.ref new file mode 100644 index 0000000000..2878c24cc8 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step1/show_ipv6_route.ref @@ -0,0 +1,346 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:4:1::\/64":[ + { + "prefix":"fc00:0:4:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:2::\/64":[ + { + "prefix":"fc00:0:4:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:3::\/64":[ + { + "prefix":"fc00:0:4:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:4::\/64":[ + { + "prefix":"fc00:0:4:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/topotests/isis_srv6_topo1/rt4/step1/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt4/step1/show_srv6_locator_table.ref new file mode 100644 index 0000000000..189943f737 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step1/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:4::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:4::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt4/step1/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..0ca7a76bd4 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step1/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,82 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt2-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt2-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt6", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0006", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step2/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt4/step2/show_ip_route.ref new file mode 100644 index 0000000000..0f26fa5d7a --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step2/show_ip_route.ref @@ -0,0 +1,296 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1" + }, + { + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2" + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5" + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6" + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + }, + { + "fib":true, + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step2/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt4/step2/show_ipv6_route.ref new file mode 100644 index 0000000000..bea54ba6b2 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step2/show_ipv6_route.ref @@ -0,0 +1,321 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:4:1::\/64":[ + { + "prefix":"fc00:0:4:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:2::\/64":[ + { + "prefix":"fc00:0:4:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:3::\/64":[ + { + "prefix":"fc00:0:4:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:4::\/64":[ + { + "prefix":"fc00:0:4:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/topotests/isis_srv6_topo1/rt4/step2/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt4/step2/show_srv6_locator_table.ref new file mode 100644 index 0000000000..189943f737 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step2/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:4::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:4::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step2/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt4/step2/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..0ca7a76bd4 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step2/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,82 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt2-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt2-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt6", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0006", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step3/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt4/step3/show_ip_route.ref new file mode 100644 index 0000000000..0f26fa5d7a --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step3/show_ip_route.ref @@ -0,0 +1,296 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1" + }, + { + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2" + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5" + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6" + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + }, + { + "fib":true, + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step3/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt4/step3/show_ipv6_route.ref new file mode 100644 index 0000000000..2878c24cc8 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step3/show_ipv6_route.ref @@ -0,0 +1,346 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:4:1::\/64":[ + { + "prefix":"fc00:0:4:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:2::\/64":[ + { + "prefix":"fc00:0:4:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:3::\/64":[ + { + "prefix":"fc00:0:4:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:4::\/64":[ + { + "prefix":"fc00:0:4:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/topotests/isis_srv6_topo1/rt4/step3/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt4/step3/show_srv6_locator_table.ref new file mode 100644 index 0000000000..189943f737 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step3/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:4::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:4::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step3/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt4/step3/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..0ca7a76bd4 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step3/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,82 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt2-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt2-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt6", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0006", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step4/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt4/step4/show_ip_route.ref new file mode 100644 index 0000000000..0f26fa5d7a --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step4/show_ip_route.ref @@ -0,0 +1,296 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1" + }, + { + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2" + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5" + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6" + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + }, + { + "fib":true, + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step4/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt4/step4/show_ipv6_route.ref new file mode 100644 index 0000000000..bea54ba6b2 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step4/show_ipv6_route.ref @@ -0,0 +1,321 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:4:1::\/64":[ + { + "prefix":"fc00:0:4:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:2::\/64":[ + { + "prefix":"fc00:0:4:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:3::\/64":[ + { + "prefix":"fc00:0:4:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:4::\/64":[ + { + "prefix":"fc00:0:4:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/topotests/isis_srv6_topo1/rt4/step4/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt4/step4/show_srv6_locator_table.ref new file mode 100644 index 0000000000..189943f737 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step4/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:4::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:4::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step4/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt4/step4/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..0ca7a76bd4 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step4/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,82 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt2-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt2-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt6", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0006", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step5/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt4/step5/show_ip_route.ref new file mode 100644 index 0000000000..0f26fa5d7a --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step5/show_ip_route.ref @@ -0,0 +1,296 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1" + }, + { + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2" + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5" + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6" + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + }, + { + "fib":true, + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step5/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt4/step5/show_ipv6_route.ref new file mode 100644 index 0000000000..2878c24cc8 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step5/show_ipv6_route.ref @@ -0,0 +1,346 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:4:1::\/64":[ + { + "prefix":"fc00:0:4:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:2::\/64":[ + { + "prefix":"fc00:0:4:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:3::\/64":[ + { + "prefix":"fc00:0:4:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:4::\/64":[ + { + "prefix":"fc00:0:4:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/topotests/isis_srv6_topo1/rt4/step5/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt4/step5/show_srv6_locator_table.ref new file mode 100644 index 0000000000..189943f737 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step5/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:4::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:4::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step5/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt4/step5/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..0ca7a76bd4 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step5/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,82 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt2-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt2-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt6", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0006", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step6/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt4/step6/show_ip_route.ref new file mode 100644 index 0000000000..0f26fa5d7a --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step6/show_ip_route.ref @@ -0,0 +1,296 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1" + }, + { + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2" + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5" + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6" + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + }, + { + "fib":true, + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step6/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt4/step6/show_ipv6_route.ref new file mode 100644 index 0000000000..bea54ba6b2 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step6/show_ipv6_route.ref @@ -0,0 +1,321 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:4:1::\/64":[ + { + "prefix":"fc00:0:4:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:2::\/64":[ + { + "prefix":"fc00:0:4:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:3::\/64":[ + { + "prefix":"fc00:0:4:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:4::\/64":[ + { + "prefix":"fc00:0:4:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/topotests/isis_srv6_topo1/rt4/step6/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt4/step6/show_srv6_locator_table.ref new file mode 100644 index 0000000000..189943f737 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step6/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:4::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:4::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step6/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt4/step6/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..0ca7a76bd4 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step6/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,82 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt2-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt2-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt6", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0006", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step7/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt4/step7/show_ip_route.ref new file mode 100644 index 0000000000..0f26fa5d7a --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step7/show_ip_route.ref @@ -0,0 +1,296 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1" + }, + { + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2" + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5" + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6" + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + }, + { + "fib":true, + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step7/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt4/step7/show_ipv6_route.ref new file mode 100644 index 0000000000..2878c24cc8 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step7/show_ipv6_route.ref @@ -0,0 +1,346 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:4:1::\/64":[ + { + "prefix":"fc00:0:4:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:2::\/64":[ + { + "prefix":"fc00:0:4:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:3::\/64":[ + { + "prefix":"fc00:0:4:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:4::\/64":[ + { + "prefix":"fc00:0:4:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/topotests/isis_srv6_topo1/rt4/step7/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt4/step7/show_srv6_locator_table.ref new file mode 100644 index 0000000000..189943f737 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step7/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:4::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:4::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step7/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt4/step7/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..0ca7a76bd4 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step7/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,82 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt2-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt2-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt6", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0006", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step8/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt4/step8/show_ip_route.ref new file mode 100644 index 0000000000..0f26fa5d7a --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step8/show_ip_route.ref @@ -0,0 +1,296 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1" + }, + { + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2" + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5" + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6" + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + }, + { + "fib":true, + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step8/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt4/step8/show_ipv6_route.ref new file mode 100644 index 0000000000..bea54ba6b2 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step8/show_ipv6_route.ref @@ -0,0 +1,321 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:4:1::\/64":[ + { + "prefix":"fc00:0:4:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:2::\/64":[ + { + "prefix":"fc00:0:4:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:3::\/64":[ + { + "prefix":"fc00:0:4:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:4::\/64":[ + { + "prefix":"fc00:0:4:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/topotests/isis_srv6_topo1/rt4/step8/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt4/step8/show_srv6_locator_table.ref new file mode 100644 index 0000000000..189943f737 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step8/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:4::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:4::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step8/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt4/step8/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..0ca7a76bd4 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step8/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,82 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt2-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt2-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt6", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0006", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step9/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt4/step9/show_ip_route.ref new file mode 100644 index 0000000000..0f26fa5d7a --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step9/show_ip_route.ref @@ -0,0 +1,296 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1" + }, + { + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "ip":"10.0.3.2", + "afi":"ipv4", + "interfaceName":"eth-rt2-2" + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5" + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6" + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + }, + { + "fib":true, + "ip":"10.0.7.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step9/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt4/step9/show_ipv6_route.ref new file mode 100644 index 0000000000..2878c24cc8 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step9/show_ipv6_route.ref @@ -0,0 +1,346 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-1", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt2-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:4:1::\/64":[ + { + "prefix":"fc00:0:4:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:2::\/64":[ + { + "prefix":"fc00:0:4:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:3::\/64":[ + { + "prefix":"fc00:0:4:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:4:4::\/64":[ + { + "prefix":"fc00:0:4:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/topotests/isis_srv6_topo1/rt4/step9/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt4/step9/show_srv6_locator_table.ref new file mode 100644 index 0000000000..189943f737 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step9/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:4::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:4::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/step9/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt4/step9/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..0ca7a76bd4 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/step9/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,82 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt2-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt2-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0002", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt6", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0006", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt4/zebra.conf b/tests/topotests/isis_srv6_topo1/rt4/zebra.conf new file mode 100644 index 0000000000..551b35d294 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt4/zebra.conf @@ -0,0 +1,36 @@ +log file zebra.log +! +hostname rt4 +! +! debug zebra kernel +! debug zebra packet +! +interface lo + ip address 4.4.4.4/32 + ipv6 address fc00:0:4::1/128 +! +interface eth-rt2-1 + ip address 10.0.2.4/24 +! +interface eth-rt2-2 + ip address 10.0.3.4/24 +! +interface eth-rt5 + ip address 10.0.6.4/24 +! +interface eth-rt6 + ip address 10.0.7.4/24 +! +segment-routing + srv6 + locators + locator loc1 + prefix fc00:0:4::/48 block-len 32 node-len 16 func-bits 16 + behavior usid + ! + ! +! +ip forwarding +! +line vty +! diff --git a/tests/topotests/isis_srv6_topo1/rt5/isisd.conf b/tests/topotests/isis_srv6_topo1/rt5/isisd.conf new file mode 100644 index 0000000000..26f895dd82 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/isisd.conf @@ -0,0 +1,56 @@ +hostname rt5 +log file isisd.log +! +! debug isis events +! debug isis route-events +! debug isis spf-events +! debug isis sr-events +! debug isis lsp-gen +! +interface lo + ip router isis 1 + ipv6 router isis 1 + isis passive +! +interface eth-rt3-1 + ip router isis 1 + ipv6 router isis 1 + isis network point-to-point + isis hello-interval 1 + isis hello-multiplier 10 +! +interface eth-rt3-2 + ip router isis 1 + ipv6 router isis 1 + isis network point-to-point + isis hello-interval 1 + isis hello-multiplier 10 +! +interface eth-rt4 + ip router isis 1 + ipv6 router isis 1 + isis network point-to-point + isis hello-interval 1 + isis hello-multiplier 10 +! +interface eth-rt6 + ip router isis 1 + ipv6 router isis 1 + isis network point-to-point + isis hello-interval 1 + isis hello-multiplier 10 +! +router isis 1 + lsp-gen-interval 2 + net 49.0000.0000.0000.0005.00 + is-type level-1 + topology ipv6-unicast + segment-routing srv6 + locator loc1 + node-msd + max-segs-left 3 + max-end-pop 3 + max-h-encaps 2 + max-end-d 5 + interface sr0 +! diff --git a/tests/topotests/isis_srv6_topo1/rt5/step1/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt5/step1/show_ip_route.ref new file mode 100644 index 0000000000..65beaa5998 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step1/show_ip_route.ref @@ -0,0 +1,296 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1" + }, + { + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2" + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4" + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step1/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt5/step1/show_ipv6_route.ref new file mode 100644 index 0000000000..d6ad4c2aad --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step1/show_ipv6_route.ref @@ -0,0 +1,346 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:5:1::\/64":[ + { + "prefix":"fc00:0:5:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:2::\/64":[ + { + "prefix":"fc00:0:5:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:3::\/64":[ + { + "prefix":"fc00:0:5:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:4::\/64":[ + { + "prefix":"fc00:0:5:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step1/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt5/step1/show_srv6_locator_table.ref new file mode 100644 index 0000000000..54780fce8a --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step1/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:5::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:5::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt5/step1/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..f40b0d353d --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step1/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,82 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt3-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt3-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt4", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt6", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0006", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step2/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt5/step2/show_ip_route.ref new file mode 100644 index 0000000000..65beaa5998 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step2/show_ip_route.ref @@ -0,0 +1,296 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1" + }, + { + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2" + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4" + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step2/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt5/step2/show_ipv6_route.ref new file mode 100644 index 0000000000..c245270177 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step2/show_ipv6_route.ref @@ -0,0 +1,321 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:5:1::\/64":[ + { + "prefix":"fc00:0:5:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:2::\/64":[ + { + "prefix":"fc00:0:5:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:3::\/64":[ + { + "prefix":"fc00:0:5:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:4::\/64":[ + { + "prefix":"fc00:0:5:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step2/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt5/step2/show_srv6_locator_table.ref new file mode 100644 index 0000000000..54780fce8a --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step2/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:5::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:5::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step2/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt5/step2/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..f40b0d353d --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step2/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,82 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt3-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt3-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt4", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt6", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0006", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step3/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt5/step3/show_ip_route.ref new file mode 100644 index 0000000000..65beaa5998 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step3/show_ip_route.ref @@ -0,0 +1,296 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1" + }, + { + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2" + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4" + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step3/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt5/step3/show_ipv6_route.ref new file mode 100644 index 0000000000..d6ad4c2aad --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step3/show_ipv6_route.ref @@ -0,0 +1,346 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:5:1::\/64":[ + { + "prefix":"fc00:0:5:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:2::\/64":[ + { + "prefix":"fc00:0:5:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:3::\/64":[ + { + "prefix":"fc00:0:5:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:4::\/64":[ + { + "prefix":"fc00:0:5:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step3/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt5/step3/show_srv6_locator_table.ref new file mode 100644 index 0000000000..54780fce8a --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step3/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:5::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:5::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step3/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt5/step3/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..f40b0d353d --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step3/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,82 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt3-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt3-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt4", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt6", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0006", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step4/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt5/step4/show_ip_route.ref new file mode 100644 index 0000000000..65beaa5998 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step4/show_ip_route.ref @@ -0,0 +1,296 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1" + }, + { + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2" + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4" + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step4/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt5/step4/show_ipv6_route.ref new file mode 100644 index 0000000000..c245270177 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step4/show_ipv6_route.ref @@ -0,0 +1,321 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:5:1::\/64":[ + { + "prefix":"fc00:0:5:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:2::\/64":[ + { + "prefix":"fc00:0:5:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:3::\/64":[ + { + "prefix":"fc00:0:5:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:4::\/64":[ + { + "prefix":"fc00:0:5:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step4/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt5/step4/show_srv6_locator_table.ref new file mode 100644 index 0000000000..54780fce8a --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step4/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:5::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:5::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step4/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt5/step4/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..f40b0d353d --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step4/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,82 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt3-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt3-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt4", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt6", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0006", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step5/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt5/step5/show_ip_route.ref new file mode 100644 index 0000000000..65beaa5998 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step5/show_ip_route.ref @@ -0,0 +1,296 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1" + }, + { + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2" + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4" + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step5/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt5/step5/show_ipv6_route.ref new file mode 100644 index 0000000000..d6ad4c2aad --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step5/show_ipv6_route.ref @@ -0,0 +1,346 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:5:1::\/64":[ + { + "prefix":"fc00:0:5:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:2::\/64":[ + { + "prefix":"fc00:0:5:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:3::\/64":[ + { + "prefix":"fc00:0:5:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:4::\/64":[ + { + "prefix":"fc00:0:5:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step5/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt5/step5/show_srv6_locator_table.ref new file mode 100644 index 0000000000..54780fce8a --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step5/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:5::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:5::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step5/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt5/step5/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..f40b0d353d --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step5/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,82 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt3-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt3-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt4", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt6", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0006", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step6/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt5/step6/show_ip_route.ref new file mode 100644 index 0000000000..65beaa5998 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step6/show_ip_route.ref @@ -0,0 +1,296 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1" + }, + { + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2" + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4" + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step6/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt5/step6/show_ipv6_route.ref new file mode 100644 index 0000000000..c245270177 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step6/show_ipv6_route.ref @@ -0,0 +1,321 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:5:1::\/64":[ + { + "prefix":"fc00:0:5:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:2::\/64":[ + { + "prefix":"fc00:0:5:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:3::\/64":[ + { + "prefix":"fc00:0:5:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:4::\/64":[ + { + "prefix":"fc00:0:5:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step6/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt5/step6/show_srv6_locator_table.ref new file mode 100644 index 0000000000..54780fce8a --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step6/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:5::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:5::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step6/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt5/step6/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..f40b0d353d --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step6/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,82 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt3-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt3-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt4", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt6", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0006", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step7/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt5/step7/show_ip_route.ref new file mode 100644 index 0000000000..65beaa5998 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step7/show_ip_route.ref @@ -0,0 +1,296 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1" + }, + { + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2" + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4" + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step7/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt5/step7/show_ipv6_route.ref new file mode 100644 index 0000000000..d6ad4c2aad --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step7/show_ipv6_route.ref @@ -0,0 +1,346 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:5:1::\/64":[ + { + "prefix":"fc00:0:5:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:2::\/64":[ + { + "prefix":"fc00:0:5:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:3::\/64":[ + { + "prefix":"fc00:0:5:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:4::\/64":[ + { + "prefix":"fc00:0:5:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step7/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt5/step7/show_srv6_locator_table.ref new file mode 100644 index 0000000000..54780fce8a --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step7/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:5::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:5::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step7/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt5/step7/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..f40b0d353d --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step7/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,82 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt3-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt3-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt4", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt6", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0006", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step8/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt5/step8/show_ip_route.ref new file mode 100644 index 0000000000..65beaa5998 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step8/show_ip_route.ref @@ -0,0 +1,296 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1" + }, + { + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2" + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4" + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step8/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt5/step8/show_ipv6_route.ref new file mode 100644 index 0000000000..c245270177 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step8/show_ipv6_route.ref @@ -0,0 +1,321 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:5:1::\/64":[ + { + "prefix":"fc00:0:5:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:2::\/64":[ + { + "prefix":"fc00:0:5:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:3::\/64":[ + { + "prefix":"fc00:0:5:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:4::\/64":[ + { + "prefix":"fc00:0:5:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step8/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt5/step8/show_srv6_locator_table.ref new file mode 100644 index 0000000000..54780fce8a --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step8/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:5::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:5::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step8/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt5/step8/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..f40b0d353d --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step8/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,82 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt3-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt3-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt4", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt6", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0006", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step9/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt5/step9/show_ip_route.ref new file mode 100644 index 0000000000..65beaa5998 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step9/show_ip_route.ref @@ -0,0 +1,296 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "6.6.6.6\/32":[ + { + "prefix":"6.6.6.6\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "fib":true, + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1" + }, + { + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.4.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-1", + "active":true + }, + { + "ip":"10.0.5.3", + "afi":"ipv4", + "interfaceName":"eth-rt3-2" + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4" + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.6.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.8.6", + "afi":"ipv4", + "interfaceName":"eth-rt6" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step9/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt5/step9/show_ipv6_route.ref new file mode 100644 index 0000000000..d6ad4c2aad --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step9/show_ipv6_route.ref @@ -0,0 +1,346 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:6::1\/128":[ + { + "prefix":"fc00:0:6::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-2", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt3-1", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt6", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:5:1::\/64":[ + { + "prefix":"fc00:0:5:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:2::\/64":[ + { + "prefix":"fc00:0:5:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:3::\/64":[ + { + "prefix":"fc00:0:5:3::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:5:4::\/64":[ + { + "prefix":"fc00:0:5:4::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step9/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt5/step9/show_srv6_locator_table.ref new file mode 100644 index 0000000000..54780fce8a --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step9/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:5::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:5::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/step9/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt5/step9/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..f40b0d353d --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/step9/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,82 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt3-1", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt3-2", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0003", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt4", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt6", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0006", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt5/zebra.conf b/tests/topotests/isis_srv6_topo1/rt5/zebra.conf new file mode 100644 index 0000000000..acd01bd726 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt5/zebra.conf @@ -0,0 +1,36 @@ +log file zebra.log +! +hostname rt5 +! +! debug zebra kernel +! debug zebra packet +! +interface lo + ip address 5.5.5.5/32 + ipv6 address fc00:0:5::1/128 +! +interface eth-rt3-1 + ip address 10.0.4.5/24 +! +interface eth-rt3-2 + ip address 10.0.5.5/24 +! +interface eth-rt4 + ip address 10.0.6.5/24 +! +interface eth-rt6 + ip address 10.0.8.5/24 +! +segment-routing + srv6 + locators + locator loc1 + prefix fc00:0:5::/48 block-len 32 node-len 16 func-bits 16 + behavior usid + ! + ! +! +ip forwarding +! +line vty +! diff --git a/tests/topotests/isis_srv6_topo1/rt6/isisd.conf b/tests/topotests/isis_srv6_topo1/rt6/isisd.conf new file mode 100644 index 0000000000..f8816db43a --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/isisd.conf @@ -0,0 +1,42 @@ +hostname rt6 +log file isisd.log +! +! debug isis events +! debug isis route-events +! debug isis spf-events +! debug isis sr-events +! debug isis lsp-gen +! +interface lo + ip router isis 1 + ipv6 router isis 1 + isis passive +! +interface eth-rt4 + ip router isis 1 + ipv6 router isis 1 + isis network point-to-point + isis hello-interval 1 + isis hello-multiplier 10 +! +interface eth-rt5 + ip router isis 1 + ipv6 router isis 1 + isis network point-to-point + isis hello-interval 1 + isis hello-multiplier 10 +! +router isis 1 + lsp-gen-interval 2 + net 49.0000.0000.0000.0006.00 + is-type level-1 + topology ipv6-unicast + segment-routing srv6 + locator loc1 + node-msd + max-segs-left 3 + max-end-pop 3 + max-h-encaps 2 + max-end-d 5 + interface sr0 +! diff --git a/tests/topotests/isis_srv6_topo1/rt6/sharpd.conf b/tests/topotests/isis_srv6_topo1/rt6/sharpd.conf new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/isis_srv6_topo1/rt6/step1/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt6/step1/show_ip_route.ref new file mode 100644 index 0000000000..5fc293b6d8 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step1/show_ip_route.ref @@ -0,0 +1,273 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4" + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step1/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt6/step1/show_ipv6_route.ref new file mode 100644 index 0000000000..407e2d0f4c --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step1/show_ipv6_route.ref @@ -0,0 +1,268 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:6:1::\/64":[ + { + "prefix":"fc00:0:6:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:6:2::\/64":[ + { + "prefix":"fc00:0:6:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step1/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt6/step1/show_srv6_locator_table.ref new file mode 100644 index 0000000000..35aa61d8e6 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step1/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:6::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:6::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt6/step1/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..8300ca0b5c --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step1/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,44 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt4", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step2/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt6/step2/show_ip_route.ref new file mode 100644 index 0000000000..5fc293b6d8 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step2/show_ip_route.ref @@ -0,0 +1,273 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4" + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step2/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt6/step2/show_ipv6_route.ref new file mode 100644 index 0000000000..6c64bd7d1e --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step2/show_ipv6_route.ref @@ -0,0 +1,243 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:6:1::\/64":[ + { + "prefix":"fc00:0:6:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:6:2::\/64":[ + { + "prefix":"fc00:0:6:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step2/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt6/step2/show_srv6_locator_table.ref new file mode 100644 index 0000000000..35aa61d8e6 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step2/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:6::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:6::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step2/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt6/step2/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..8300ca0b5c --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step2/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,44 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt4", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step3/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt6/step3/show_ip_route.ref new file mode 100644 index 0000000000..5fc293b6d8 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step3/show_ip_route.ref @@ -0,0 +1,273 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4" + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step3/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt6/step3/show_ipv6_route.ref new file mode 100644 index 0000000000..407e2d0f4c --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step3/show_ipv6_route.ref @@ -0,0 +1,268 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:6:1::\/64":[ + { + "prefix":"fc00:0:6:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:6:2::\/64":[ + { + "prefix":"fc00:0:6:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step3/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt6/step3/show_srv6_locator_table.ref new file mode 100644 index 0000000000..35aa61d8e6 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step3/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:6::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:6::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step3/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt6/step3/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..8300ca0b5c --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step3/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,44 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt4", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step4/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt6/step4/show_ip_route.ref new file mode 100644 index 0000000000..5fc293b6d8 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step4/show_ip_route.ref @@ -0,0 +1,273 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4" + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step4/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt6/step4/show_ipv6_route.ref new file mode 100644 index 0000000000..6c64bd7d1e --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step4/show_ipv6_route.ref @@ -0,0 +1,243 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:6:1::\/64":[ + { + "prefix":"fc00:0:6:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:6:2::\/64":[ + { + "prefix":"fc00:0:6:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step4/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt6/step4/show_srv6_locator_table.ref new file mode 100644 index 0000000000..35aa61d8e6 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step4/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:6::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:6::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step4/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt6/step4/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..8300ca0b5c --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step4/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,44 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt4", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step5/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt6/step5/show_ip_route.ref new file mode 100644 index 0000000000..5fc293b6d8 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step5/show_ip_route.ref @@ -0,0 +1,273 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4" + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step5/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt6/step5/show_ipv6_route.ref new file mode 100644 index 0000000000..407e2d0f4c --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step5/show_ipv6_route.ref @@ -0,0 +1,268 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:6:1::\/64":[ + { + "prefix":"fc00:0:6:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:6:2::\/64":[ + { + "prefix":"fc00:0:6:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step5/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt6/step5/show_srv6_locator_table.ref new file mode 100644 index 0000000000..35aa61d8e6 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step5/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:6::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:6::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step5/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt6/step5/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..8300ca0b5c --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step5/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,44 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt4", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step6/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt6/step6/show_ip_route.ref new file mode 100644 index 0000000000..5fc293b6d8 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step6/show_ip_route.ref @@ -0,0 +1,273 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4" + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step6/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt6/step6/show_ipv6_route.ref new file mode 100644 index 0000000000..6c64bd7d1e --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step6/show_ipv6_route.ref @@ -0,0 +1,243 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:6:1::\/64":[ + { + "prefix":"fc00:0:6:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:6:2::\/64":[ + { + "prefix":"fc00:0:6:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step6/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt6/step6/show_srv6_locator_table.ref new file mode 100644 index 0000000000..35aa61d8e6 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step6/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:6::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:6::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step6/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt6/step6/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..8300ca0b5c --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step6/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,44 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt4", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step7/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt6/step7/show_ip_route.ref new file mode 100644 index 0000000000..5fc293b6d8 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step7/show_ip_route.ref @@ -0,0 +1,273 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4" + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step7/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt6/step7/show_ipv6_route.ref new file mode 100644 index 0000000000..407e2d0f4c --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step7/show_ipv6_route.ref @@ -0,0 +1,268 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:6:1::\/64":[ + { + "prefix":"fc00:0:6:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:6:2::\/64":[ + { + "prefix":"fc00:0:6:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step7/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt6/step7/show_srv6_locator_table.ref new file mode 100644 index 0000000000..35aa61d8e6 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step7/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:6::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:6::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step7/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt6/step7/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..8300ca0b5c --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step7/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,44 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt4", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step8/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt6/step8/show_ip_route.ref new file mode 100644 index 0000000000..5fc293b6d8 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step8/show_ip_route.ref @@ -0,0 +1,273 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4" + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step8/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt6/step8/show_ipv6_route.ref new file mode 100644 index 0000000000..6c64bd7d1e --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step8/show_ipv6_route.ref @@ -0,0 +1,243 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:6:1::\/64":[ + { + "prefix":"fc00:0:6:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:6:2::\/64":[ + { + "prefix":"fc00:0:6:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step8/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt6/step8/show_srv6_locator_table.ref new file mode 100644 index 0000000000..35aa61d8e6 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step8/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:6::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:6::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step8/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt6/step8/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..8300ca0b5c --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step8/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,44 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt4", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step9/show_ip_route.ref b/tests/topotests/isis_srv6_topo1/rt6/step9/show_ip_route.ref new file mode 100644 index 0000000000..5fc293b6d8 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step9/show_ip_route.ref @@ -0,0 +1,273 @@ +{ + "1.1.1.1\/32":[ + { + "prefix":"1.1.1.1\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "2.2.2.2\/32":[ + { + "prefix":"2.2.2.2\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "3.3.3.3\/32":[ + { + "prefix":"3.3.3.3\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "4.4.4.4\/32":[ + { + "prefix":"4.4.4.4\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "5.5.5.5\/32":[ + { + "prefix":"5.5.5.5\/32", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "10.0.4.0\/24":[ + { + "prefix":"10.0.4.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.5.0\/24":[ + { + "prefix":"10.0.5.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.6.0\/24":[ + { + "prefix":"10.0.6.0\/24", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "10.0.7.0\/24":[ + { + "prefix":"10.0.7.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.7.4", + "afi":"ipv4", + "interfaceName":"eth-rt4" + } + ] + } + ], + "10.0.8.0\/24":[ + { + "prefix":"10.0.8.0\/24", + "protocol":"isis", + "distance":115, + "metric":20, + "nexthops":[ + { + "ip":"10.0.8.5", + "afi":"ipv4", + "interfaceName":"eth-rt5" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step9/show_ipv6_route.ref b/tests/topotests/isis_srv6_topo1/rt6/step9/show_ipv6_route.ref new file mode 100644 index 0000000000..407e2d0f4c --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step9/show_ipv6_route.ref @@ -0,0 +1,268 @@ +{ + "fc00:0:1::1\/128":[ + { + "prefix":"fc00:0:1::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":40, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:2::1\/128":[ + { + "prefix":"fc00:0:2::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:3::1\/128":[ + { + "prefix":"fc00:0:3::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:4::1\/128":[ + { + "prefix":"fc00:0:4::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:5::1\/128":[ + { + "prefix":"fc00:0:5::1\/128", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:1::\/48":[ + { + "prefix":"fc00:0:1::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + }, + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:2::\/48":[ + { + "prefix":"fc00:0:2::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:3::\/48":[ + { + "prefix":"fc00:0:3::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:4::\/48":[ + { + "prefix":"fc00:0:4::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt4", + "active":true + } + ] + } + ], + "fc00:0:5::\/48":[ + { + "prefix":"fc00:0:5::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "afi":"ipv6", + "interfaceName":"eth-rt5", + "active":true + } + ] + } + ], + "fc00:0:6::\/48":[ + { + "prefix":"fc00:0:6::\/48", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceName":"sr0", + "active":true, + "seg6local":{ + "action":"End" + } + } + ] + } + ], + "fc00:0:6:1::\/64":[ + { + "prefix":"fc00:0:6:1::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ], + "fc00:0:6:2::\/64":[ + { + "prefix":"fc00:0:6:2::\/64", + "protocol":"isis", + "selected":true, + "destSelected":true, + "distance":115, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "active":true, + "seg6local":{ + "action":"End.X" + } + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step9/show_srv6_locator_table.ref b/tests/topotests/isis_srv6_topo1/rt6/step9/show_srv6_locator_table.ref new file mode 100644 index 0000000000..35aa61d8e6 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step9/show_srv6_locator_table.ref @@ -0,0 +1,19 @@ +{ + "locators":[ + { + "name":"loc1", + "prefix":"fc00:0:6::/48", + "blockBitsLength":32, + "nodeBitsLength":16, + "functionBitsLength":16, + "argumentBitsLength":0, + "statusUp":true, + "chunks":[ + { + "prefix":"fc00:0:6::/48", + "proto":"isis" + } + ] + } + ] +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/step9/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_srv6_topo1/rt6/step9/show_yang_interface_isis_adjacencies.ref new file mode 100644 index 0000000000..8300ca0b5c --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/step9/show_yang_interface_isis_adjacencies.ref @@ -0,0 +1,44 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "eth-rt4", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0004", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + }, + { + "name": "eth-rt5", + "vrf": "default", + "state": { + "frr-isisd:isis": { + "adjacencies": { + "adjacency": [ + { + "neighbor-sys-type": "level-1", + "neighbor-sysid": "0000.0000.0005", + "hold-timer": 10, + "neighbor-priority": 0, + "state": "up" + } + ] + } + } + } + } + ] + } +} diff --git a/tests/topotests/isis_srv6_topo1/rt6/zebra.conf b/tests/topotests/isis_srv6_topo1/rt6/zebra.conf new file mode 100644 index 0000000000..83e7f528a4 --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/rt6/zebra.conf @@ -0,0 +1,36 @@ +log file zebra.log +! +hostname rt6 +! +! debug zebra kernel +! debug zebra packet +! +interface lo + ip address 6.6.6.6/32 + ipv6 address fc00:0:6::1/128 +! +interface eth-rt4 + ip address 10.0.7.6/24 +! +interface eth-rt5 + ip address 10.0.8.6/24 +! +interface eth-dst + ip address 10.0.10.1/24 + ip address 2001:db8:10::1/64 +! +segment-routing + srv6 + locators + locator loc1 + prefix fc00:0:6::/48 block-len 32 node-len 16 func-bits 16 + behavior usid + ! + ! +! +ip forwarding +! +ip route fc00:0:9::1/128 2001:db8:10::2 +! +line vty +! diff --git a/tests/topotests/isis_srv6_topo1/test_isis_srv6_topo1.py b/tests/topotests/isis_srv6_topo1/test_isis_srv6_topo1.py new file mode 100644 index 0000000000..892f6e1d0e --- /dev/null +++ b/tests/topotests/isis_srv6_topo1/test_isis_srv6_topo1.py @@ -0,0 +1,1124 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# +# Copyright (c) 2023 by +# Carmine Scarpitta <carmine.scarpitta@uniroma2.it> +# + +""" +test_isis_srv6_topo1.py: + + +---------+ + | | + | RT1 | + | 1.1.1.1 | + | | + +---------+ + |eth-sw1 + | + | + | + +---------+ | +---------+ + | | | | | + | RT2 |eth-sw1 | eth-sw1| RT3 | + | 2.2.2.2 +----------+----------+ 3.3.3.3 | + | | 10.0.1.0/24 | | + +---------+ +---------+ + eth-rt4-1| |eth-rt4-2 eth-rt5-1| |eth-rt5-2 + | | | | + 10.0.2.0/24| |10.0.3.0/24 10.0.4.0/24| |10.0.5.0/24 + | | | | + eth-rt2-1| |eth-rt2-2 eth-rt3-1| |eth-rt3-2 + +---------+ +---------+ + | | | | + | RT4 | 10.0.6.0/24 | RT5 | + | 4.4.4.4 +---------------------+ 5.5.5.5 | + | |eth-rt5 eth-rt4| | + +---------+ +---------+ + eth-rt6| |eth-rt6 + | | + 10.0.7.0/24| |10.0.8.0/24 + | +---------+ | + | | | | + | | RT6 | | + +----------+ 6.6.6.6 +-----------+ + eth-rt4| |eth-rt5 + +---------+ + |eth-dst (.1) + | + |10.0.10.0/24 + | + |eth-rt6 (.2) + +---------+ + | | + | DST | + | 9.9.9.2 | + | | + +---------+ + +""" + +import os +import re +import sys +import json +import functools +import pytest + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +# Import topogen and topotest helpers +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger +from lib.common_config import ( + required_linux_kernel_version, + create_interface_in_kernel, +) + +pytestmark = [pytest.mark.isisd, pytest.mark.sharpd] + + +def build_topo(tgen): + """Build function""" + + # Define FRR Routers + tgen.add_router("rt1") + tgen.add_router("rt2") + tgen.add_router("rt3") + tgen.add_router("rt4") + tgen.add_router("rt5") + tgen.add_router("rt6") + tgen.add_router("dst") + + # Define connections + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["rt1"], nodeif="eth-sw1") + switch.add_link(tgen.gears["rt2"], nodeif="eth-sw1") + switch.add_link(tgen.gears["rt3"], nodeif="eth-sw1") + + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-1") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-1") + + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4-2") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2-2") + + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-1") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-1") + + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5-2") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3-2") + + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4") + + switch = tgen.add_switch("s7") + switch.add_link(tgen.gears["rt4"], nodeif="eth-rt6") + switch.add_link(tgen.gears["rt6"], nodeif="eth-rt4") + + switch = tgen.add_switch("s8") + switch.add_link(tgen.gears["rt5"], nodeif="eth-rt6") + switch.add_link(tgen.gears["rt6"], nodeif="eth-rt5") + + switch = tgen.add_switch("s9") + switch.add_link(tgen.gears["rt6"], nodeif="eth-dst") + switch.add_link(tgen.gears["dst"], nodeif="eth-rt6") + + # Add dummy interface for SRv6 + create_interface_in_kernel( + tgen, + "rt1", + "sr0", + "2001:db8::1", + netmask="128", + create=True, + ) + create_interface_in_kernel( + tgen, + "rt2", + "sr0", + "2001:db8::2", + netmask="128", + create=True, + ) + create_interface_in_kernel( + tgen, + "rt3", + "sr0", + "2001:db8::3", + netmask="128", + create=True, + ) + create_interface_in_kernel( + tgen, + "rt4", + "sr0", + "2001:db8::4", + netmask="128", + create=True, + ) + create_interface_in_kernel( + tgen, + "rt5", + "sr0", + "2001:db8::5", + netmask="128", + create=True, + ) + create_interface_in_kernel( + tgen, + "rt6", + "sr0", + "2001:db8::6", + netmask="128", + create=True, + ) + + +def setup_module(mod): + """Sets up the pytest environment""" + + # Verify if kernel requirements are satisfied + result = required_linux_kernel_version("4.10") + if result is not True: + pytest.skip("Kernel requirements are not met") + + # Build the topology + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + + # For all registered routers, load the zebra and isis configuration files + for rname, router in tgen.routers().items(): + router.load_config(TopoRouter.RD_ZEBRA, + os.path.join(CWD, '{}/zebra.conf'.format(rname))) + router.load_config(TopoRouter.RD_ISIS, + os.path.join(CWD, '{}/isisd.conf'.format(rname))) + if (os.path.exists('{}/sharpd.conf'.format(rname))): + router.load_config(TopoRouter.RD_SHARP, + os.path.join(CWD, '{}/sharpd.conf'.format(rname))) + + # Start routers + tgen.start_router() + + +def teardown_module(mod): + "Teardown the pytest environment" + + # Teardown the topology + tgen = get_topogen() + tgen.stop_topology() + + +def router_compare_json_output(rname, command, reference): + "Compare router JSON output" + + logger.info('Comparing router "%s" "%s" output', rname, command) + + tgen = get_topogen() + filename = "{}/{}/{}".format(CWD, rname, reference) + expected = json.loads(open(filename).read()) + + # Run test function until we get an result. Wait at most 60 seconds. + test_func = functools.partial(topotest.router_json_cmp, tgen.gears[rname], command, expected) + _, diff = topotest.run_and_expect(test_func, None, count=120, wait=0.5) + assertmsg = '"{}" JSON output mismatches the expected result'.format(rname) + assert diff is None, assertmsg + + +def check_ping6(name, dest_addr, expect_connected): + def _check(name, dest_addr, match): + tgen = get_topogen() + output = tgen.gears[name].run("ping6 {} -c 1 -w 1".format(dest_addr)) + logger.info(output) + if match not in output: + return "ping fail" + + match = "{} packet loss".format("0%" if expect_connected else "100%") + logger.info("[+] check {} {} {}".format(name, dest_addr, match)) + tgen = get_topogen() + func = functools.partial(_check, name, dest_addr, match) + success, result = topotest.run_and_expect(func, None, count=10, wait=1) + assert result is None, "Failed" + + +# +# Step 1 +# +# Test initial network convergence +# +def test_isis_adjacencies_step1(): + logger.info("Test (step 1): check IS-IS adjacencies") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, + "show yang operational-data /frr-interface:lib isisd", + "step1/show_yang_interface_isis_adjacencies.ref", + ) + + +def test_rib_ipv4_step1(): + logger.info("Test (step 1): verify IPv4 RIB") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show ip route isis json", "step1/show_ip_route.ref" + ) + + +def test_rib_ipv6_step1(): + logger.info("Test (step 1): verify IPv6 RIB") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show ipv6 route isis json", "step1/show_ipv6_route.ref" + ) + + +def test_srv6_locator_step1(): + logger.info("Test (step 1): verify SRv6 Locator") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show segment-routing srv6 locator json", "step1/show_srv6_locator_table.ref" + ) + + +def test_ping_step1(): + logger.info("Test (step 1): verify ping") + tgen = get_topogen() + + # Required linux kernel version for this suite to run. + result = required_linux_kernel_version("6.1") + if result is not True: + pytest.skip("Kernel requirements are not met, kernel version should be >=6.1") + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + # Setup encap route on rt1, decap route on rt2 + tgen.gears["rt1"].vtysh_cmd("sharp install seg6-routes fc00:0:9::1 nexthop-seg6 2001:db8:1::2 encap fc00:0:1:2:6:f00d:: 1") + tgen.gears["rt6"].vtysh_cmd("sharp install seg6local-routes fc00:0:f00d:: nexthop-seg6local eth-dst End_DT6 254 1") + tgen.gears["dst"].vtysh_cmd("sharp install route 2001:db8:1::1 nexthop 2001:db8:10::1 1") + + # Try to ping dst from rt1 + check_ping6("rt1", "fc00:0:9::1", True) + + +# +# Step 2 +# +# Action(s): +# -Disable SRv6 Locator on zebra on rt1 +# +# Expected changes: +# -rt1 should uninstall the SRv6 End SID +# -rt1 should remove the SRv6 Locator from zebra +# -rt1 should remove the SRv6 Locator TLV from the LSPs +# -rt1 should remove the SRv6 Capabilities Sub-TLV from the Router Capability TLV +# -rt2, rt3, rt4, rt5, rt6 should uninstall the route pointing to the rt1's SRv6 Locator from the RIB +# +def test_isis_adjacencies_step2(): + logger.info("Test (step 2): check IS-IS adjacencies") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + logger.info("Disabling SRv6 Locator on zebra on rt1") + tgen.gears["rt1"].vtysh_cmd( + """ + configure terminal + segment-routing + srv6 + locators + no locator loc1 + """ + ) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, + "show yang operational-data /frr-interface:lib isisd", + "step2/show_yang_interface_isis_adjacencies.ref", + ) + + +def test_rib_ipv4_step2(): + logger.info("Test (step 2): verify IPv4 RIB") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show ip route isis json", "step2/show_ip_route.ref" + ) + + +def test_rib_ipv6_step2(): + logger.info("Test (step 2): verify IPv6 RIB") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show ipv6 route isis json", "step2/show_ipv6_route.ref" + ) + + +def test_srv6_locator_step2(): + logger.info("Test (step 2): verify SRv6 Locator") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show segment-routing srv6 locator json", "step2/show_srv6_locator_table.ref" + ) + + +def test_ping_step2(): + logger.info("Test (step 2): verify ping") + tgen = get_topogen() + + # Required linux kernel version for this suite to run. + result = required_linux_kernel_version("6.1") + if result is not True: + pytest.skip("Kernel requirements are not met, kernel version should be >=6.1") + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + check_ping6("rt1", "fc00:0:9::1", False) + + +# +# Step 3 +# +# Action(s): +# -Enable SRv6 Locator on zebra on rt1 +# +# Expected changes: +# -rt1 should install the SRv6 End SID +# -rt1 should install the SRv6 Locator in zebra +# -rt1 should add the SRv6 Locator TLV to the LSPs +# -rt1 should add the SRv6 Capabilities Sub-TLV to the Router Capability TLV +# -rt2, rt3, rt4, rt5, rt6 should install a route pointing to the rt1's SRv6 Locator in the RIB +# +def test_isis_adjacencies_step3(): + logger.info("Test (step 3): check IS-IS adjacencies") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + logger.info("Enabling SRv6 Locator on zebra on rt1") + tgen.gears["rt1"].vtysh_cmd( + """ + configure terminal + segment-routing + srv6 + locators + locator loc1 + prefix fc00:0:1::/48 block-len 32 node-len 16 func-bits 16 + behavior usid + """ + ) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, + "show yang operational-data /frr-interface:lib isisd", + "step3/show_yang_interface_isis_adjacencies.ref", + ) + + +def test_rib_ipv4_step3(): + logger.info("Test (step 3): verify IPv4 RIB") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show ip route isis json", "step3/show_ip_route.ref" + ) + + +def test_rib_ipv6_step3(): + logger.info("Test (step 3): verify IPv6 RIB") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show ipv6 route isis json", "step3/show_ipv6_route.ref" + ) + + +def test_srv6_locator_step3(): + logger.info("Test (step 3): verify SRv6 Locator") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show segment-routing srv6 locator json", "step3/show_srv6_locator_table.ref" + ) + + +def test_ping_step3(): + logger.info("Test (step 3): verify ping") + tgen = get_topogen() + + # Required linux kernel version for this suite to run. + result = required_linux_kernel_version("6.1") + if result is not True: + pytest.skip("Kernel requirements are not met, kernel version should be >=6.1") + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + check_ping6("rt1", "fc00:0:9::1", True) + + +# +# Step 4 +# +# Action(s): +# -Disable SRv6 Locator on ISIS on rt1 +# +# Expected changes: +# -rt1 should uninstall the SRv6 End SID +# -rt1 should remove the SRv6 Locator TLV from the LSPs +# -rt1 should remove the SRv6 Capabilities Sub-TLV from the Router Capability TLV +# -rt2, rt3, rt4, rt5, rt6 should uninstall the route pointing to the rt1's SRv6 Locator from the RIB +# +def test_isis_adjacencies_step4(): + logger.info("Test (step 4): check IS-IS adjacencies") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + logger.info("Disabling SRv6 Locator on ISIS on rt1") + tgen.gears["rt1"].vtysh_cmd( + """ + configure terminal + router isis 1 + segment-routing srv6 + no locator loc1 + """ + ) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, + "show yang operational-data /frr-interface:lib isisd", + "step4/show_yang_interface_isis_adjacencies.ref", + ) + + +def test_rib_ipv4_step4(): + logger.info("Test (step 4): verify IPv4 RIB") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show ip route isis json", "step4/show_ip_route.ref" + ) + + +def test_rib_ipv6_step4(): + logger.info("Test (step 4): verify IPv6 RIB") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show ipv6 route isis json", "step4/show_ipv6_route.ref" + ) + + +def test_srv6_locator_step4(): + logger.info("Test (step 4): verify SRv6 Locator") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show segment-routing srv6 locator json", "step4/show_srv6_locator_table.ref" + ) + + +def test_ping_step4(): + logger.info("Test (step 4): verify ping") + tgen = get_topogen() + + # Required linux kernel version for this suite to run. + result = required_linux_kernel_version("6.1") + if result is not True: + pytest.skip("Kernel requirements are not met, kernel version should be >=6.1") + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + check_ping6("rt1", "fc00:0:9::1", False) + + +# +# Step 5 +# +# Action(s): +# -Enable SRv6 Locator on ISIS on rt1 +# +# Expected changes: +# -rt1 should install the SRv6 End SID +# -rt1 should add the SRv6 Locator TLV to the LSPs +# -rt1 should add the SRv6 Capabilities Sub-TLV to the Router Capability TLV +# -rt2, rt3, rt4, rt5, rt6 should install a route pointing to the rt1's SRv6 Locator in the RIB +# +def test_isis_adjacencies_step5(): + logger.info("Test (step 5): check IS-IS adjacencies") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + logger.info("Enabling SRv6 Locator on ISIS on rt1") + tgen.gears["rt1"].vtysh_cmd( + """ + configure terminal + router isis 1 + segment-routing srv6 + locator loc1 + """ + ) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, + "show yang operational-data /frr-interface:lib isisd", + "step5/show_yang_interface_isis_adjacencies.ref", + ) + + +def test_rib_ipv4_step5(): + logger.info("Test (step 5): verify IPv4 RIB") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show ip route isis json", "step5/show_ip_route.ref" + ) + + +def test_rib_ipv6_step5(): + logger.info("Test (step 5): verify IPv6 RIB") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show ipv6 route isis json", "step5/show_ipv6_route.ref" + ) + + +def test_srv6_locator_step5(): + logger.info("Test (step 5): verify SRv6 Locator") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show segment-routing srv6 locator json", "step5/show_srv6_locator_table.ref" + ) + + +def test_ping_step5(): + logger.info("Test (step 5): verify ping") + tgen = get_topogen() + + # Required linux kernel version for this suite to run. + result = required_linux_kernel_version("6.1") + if result is not True: + pytest.skip("Kernel requirements are not met, kernel version should be >=6.1") + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + check_ping6("rt1", "fc00:0:9::1", True) + + +# +# Step 6 +# +# Action(s): +# -Disable SRv6 on ISIS on rt1 +# +# Expected changes: +# -rt1 should uninstall the SRv6 End SID +# -rt1 should remove the SRv6 Locator TLV from the LSPs +# -rt1 should remove the SRv6 Capabilities Sub-TLV from the Router Capability TLV +# -rt2, rt3, rt4, rt5, rt6 should uninstall the route pointing to the rt1's SRv6 Locator from the RIB +# +def test_isis_adjacencies_step6(): + logger.info("Test (step 6): check IS-IS adjacencies") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + logger.info("Disabling SRv6 on ISIS on rt1") + tgen.gears["rt1"].vtysh_cmd( + """ + configure terminal + router isis 1 + no segment-routing srv6 + """ + ) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, + "show yang operational-data /frr-interface:lib isisd", + "step6/show_yang_interface_isis_adjacencies.ref", + ) + + +def test_rib_ipv4_step6(): + logger.info("Test (step 6): verify IPv4 RIB") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show ip route isis json", "step6/show_ip_route.ref" + ) + + +def test_rib_ipv6_step6(): + logger.info("Test (step 6): verify IPv6 RIB") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show ipv6 route isis json", "step6/show_ipv6_route.ref" + ) + + +def test_srv6_locator_step6(): + logger.info("Test (step 6): verify SRv6 Locator") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show segment-routing srv6 locator json", "step6/show_srv6_locator_table.ref" + ) + + +def test_ping_step6(): + logger.info("Test (step 6): verify ping") + tgen = get_topogen() + + # Required linux kernel version for this suite to run. + result = required_linux_kernel_version("6.1") + if result is not True: + pytest.skip("Kernel requirements are not met, kernel version should be >=6.1") + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + check_ping6("rt1", "fc00:0:9::1", False) + + +# +# Step 7 +# +# Action(s): +# -Enable SRv6 on ISIS on rt1 +# +# Expected changes: +# -rt1 should install the SRv6 End SID +# -rt1 should add the SRv6 Locator TLV to the LSPs +# -rt1 should add the SRv6 Capabilities Sub-TLV to the Router Capability TLV +# -rt2, rt3, rt4, rt5, rt6 should install a route pointing to the rt1's SRv6 Locator in the RIB +# +def test_isis_adjacencies_step7(): + logger.info("Test (step 7): check IS-IS adjacencies") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + logger.info("Enabling SRv6 on ISIS on rt1") + tgen.gears["rt1"].vtysh_cmd( + """ + configure terminal + router isis 1 + segment-routing srv6 + locator loc1 + """ + ) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, + "show yang operational-data /frr-interface:lib isisd", + "step7/show_yang_interface_isis_adjacencies.ref", + ) + + +def test_rib_ipv4_step7(): + logger.info("Test (step 7): verify IPv4 RIB") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show ip route isis json", "step7/show_ip_route.ref" + ) + + +def test_rib_ipv6_step7(): + logger.info("Test (step 7): verify IPv6 RIB") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show ipv6 route isis json", "step7/show_ipv6_route.ref" + ) + + +def test_srv6_locator_step7(): + logger.info("Test (step 7): verify SRv6 Locator") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show segment-routing srv6 locator json", "step7/show_srv6_locator_table.ref" + ) + + +def test_ping_step7(): + logger.info("Test (step 7): verify ping") + tgen = get_topogen() + + # Required linux kernel version for this suite to run. + result = required_linux_kernel_version("6.1") + if result is not True: + pytest.skip("Kernel requirements are not met, kernel version should be >=6.1") + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + check_ping6("rt1", "fc00:0:9::1", True) + + +# +# Step 8 +# +# Action(s): +# -Disable SRv6 on zebra on rt1 +# +# Expected changes: +# -rt1 should uninstall the SRv6 End SID +# -rt1 should remove the SRv6 Locator TLV from the LSPs +# -rt1 should remove the SRv6 Capabilities Sub-TLV from the Router Capability TLV +# -rt2, rt3, rt4, rt5, rt6 should uninstall the route pointing to the rt1's SRv6 Locator from the RIB +# +def test_isis_adjacencies_step8(): + logger.info("Test (step 8): check IS-IS adjacencies") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + logger.info("Disabling SRv6 on zebra on rt1") + tgen.gears["rt1"].vtysh_cmd( + """ + configure terminal + segment-routing + no srv6 + """ + ) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, + "show yang operational-data /frr-interface:lib isisd", + "step8/show_yang_interface_isis_adjacencies.ref", + ) + + +def test_rib_ipv4_step8(): + logger.info("Test (step 8): verify IPv4 RIB") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show ip route isis json", "step8/show_ip_route.ref" + ) + + +def test_rib_ipv6_step8(): + logger.info("Test (step 8): verify IPv6 RIB") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show ipv6 route isis json", "step8/show_ipv6_route.ref" + ) + + +def test_srv6_locator_step8(): + logger.info("Test (step 8): verify SRv6 Locator") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show segment-routing srv6 locator json", "step8/show_srv6_locator_table.ref" + ) + + +def test_ping_step8(): + logger.info("Test (step 8): verify ping") + tgen = get_topogen() + + # Required linux kernel version for this suite to run. + result = required_linux_kernel_version("6.1") + if result is not True: + pytest.skip("Kernel requirements are not met, kernel version should be >=6.1") + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + check_ping6("rt1", "fc00:0:9::1", False) + + +# +# Step 9 +# +# Action(s): +# -Enable SRv6 on zebra on rt1 +# +# Expected changes: +# -rt1 should install the SRv6 End SID +# -rt1 should add the SRv6 Locator TLV to the LSPs +# -rt1 should add the SRv6 Capabilities Sub-TLV to the Router Capability TLV +# -rt2, rt3, rt4, rt5, rt6 should install a route pointing to the rt1's SRv6 Locator in the RIB +# +def test_isis_adjacencies_step9(): + logger.info("Test (step 9): check IS-IS adjacencies") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + logger.info("Enabling SRv6 on zebra on rt1") + tgen.gears["rt1"].vtysh_cmd( + """ + configure terminal + segment-routing + srv6 + locators + locator loc1 + prefix fc00:0:1::/48 block-len 32 node-len 16 func-bits 16 + behavior usid + """ + ) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, + "show yang operational-data /frr-interface:lib isisd", + "step9/show_yang_interface_isis_adjacencies.ref", + ) + + +def test_rib_ipv4_step9(): + logger.info("Test (step 9): verify IPv4 RIB") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show ip route isis json", "step9/show_ip_route.ref" + ) + + +def test_rib_ipv6_step9(): + logger.info("Test (step 9): verify IPv6 RIB") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show ipv6 route isis json", "step9/show_ipv6_route.ref" + ) + + +def test_srv6_locator_step9(): + logger.info("Test (step 9): verify SRv6 Locator") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]: + router_compare_json_output( + rname, "show segment-routing srv6 locator json", "step9/show_srv6_locator_table.ref" + ) + + +def test_ping_step9(): + logger.info("Test (step 9): verify ping") + tgen = get_topogen() + + # Required linux kernel version for this suite to run. + result = required_linux_kernel_version("6.1") + if result is not True: + pytest.skip("Kernel requirements are not met, kernel version should be >=6.1") + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + check_ping6("rt1", "fc00:0:9::1", True) + + +# Memory leak test template +def test_memory_leak(): + "Run the memory leak test and report results." + tgen = get_topogen() + if not tgen.is_memleak_enabled(): + pytest.skip("Memory leak test/report is disabled") + + tgen.report_memory_leaks() + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/isis_te_topo1/r1/isisd.conf b/tests/topotests/isis_te_topo1/r1/isisd.conf index 938d713ced..faa6c30674 100644 --- a/tests/topotests/isis_te_topo1/r1/isisd.conf +++ b/tests/topotests/isis_te_topo1/r1/isisd.conf @@ -11,14 +11,16 @@ interface r1-eth0 ip router isis TE isis circuit-type level-2-only isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface r1-eth1 ip router isis TE ipv6 router isis TE isis circuit-type level-2-only isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! router isis TE net 49.0000.0000.0000.0001.00 diff --git a/tests/topotests/isis_te_topo1/r2/isisd.conf b/tests/topotests/isis_te_topo1/r2/isisd.conf index f389e90762..ed1059157b 100644 --- a/tests/topotests/isis_te_topo1/r2/isisd.conf +++ b/tests/topotests/isis_te_topo1/r2/isisd.conf @@ -13,27 +13,31 @@ interface r2-eth0 ip router isis TE isis circuit-type level-2-only isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface r2-eth1 ip router isis TE ipv6 router isis TE isis circuit-type level-2-only isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface r2-eth2 ip router isis TE ipv6 router isis TE isis circuit-type level-2-only isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface r2-eth3 ip router isis TE isis circuit-type level-2-only isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! router isis TE net 49.0000.0000.0000.0002.00 diff --git a/tests/topotests/isis_te_topo1/r3/isisd.conf b/tests/topotests/isis_te_topo1/r3/isisd.conf index 4920a17c4c..c689e841e2 100644 --- a/tests/topotests/isis_te_topo1/r3/isisd.conf +++ b/tests/topotests/isis_te_topo1/r3/isisd.conf @@ -14,13 +14,15 @@ interface r3-eth0 ipv6 router isis TE isis circuit-type level-2-only isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface r3-eth1 ipv6 router isis TE isis circuit-type level-2-only isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! ! router isis TE diff --git a/tests/topotests/isis_te_topo1/r4/isisd.conf b/tests/topotests/isis_te_topo1/r4/isisd.conf index 51e9ba6dec..ba522cc878 100644 --- a/tests/topotests/isis_te_topo1/r4/isisd.conf +++ b/tests/topotests/isis_te_topo1/r4/isisd.conf @@ -15,13 +15,15 @@ interface r4-eth0 ip router isis TE isis circuit-type level-2-only isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! interface r4-eth1 ipv6 router isis TE isis circuit-type level-2-only isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 ! ! router isis TE diff --git a/tests/topotests/isis_te_topo1/reference/ted_step1.json b/tests/topotests/isis_te_topo1/reference/ted_step1.json index b70626e85d..85ced4117a 100644 --- a/tests/topotests/isis_te_topo1/reference/ted_step1.json +++ b/tests/topotests/isis_te_topo1/reference/ted_step1.json @@ -256,7 +256,6 @@ }, "segment-routing":[ { - "adj-sid":5001, "flags":"0xb0", "weight":0 } @@ -641,7 +640,6 @@ }, "segment-routing":[ { - "adj-sid":5000, "flags":"0x30", "weight":0 } diff --git a/tests/topotests/isis_te_topo1/reference/ted_step10.json b/tests/topotests/isis_te_topo1/reference/ted_step10.json index f029e5aab0..9348f9c42b 100644 --- a/tests/topotests/isis_te_topo1/reference/ted_step10.json +++ b/tests/topotests/isis_te_topo1/reference/ted_step10.json @@ -354,7 +354,6 @@ }, "segment-routing":[ { - "adj-sid":5001, "flags":"0xb0", "weight":0 } @@ -754,7 +753,6 @@ }, "segment-routing":[ { - "adj-sid":5000, "flags":"0x30", "weight":0 } diff --git a/tests/topotests/isis_te_topo1/reference/ted_step2.json b/tests/topotests/isis_te_topo1/reference/ted_step2.json index aa2bafb15a..a84f4c0101 100644 --- a/tests/topotests/isis_te_topo1/reference/ted_step2.json +++ b/tests/topotests/isis_te_topo1/reference/ted_step2.json @@ -174,7 +174,6 @@ }, "segment-routing":[ { - "adj-sid":5001, "flags":"0xb0", "weight":0 } @@ -477,7 +476,6 @@ }, "segment-routing":[ { - "adj-sid":5000, "flags":"0x30", "weight":0 } diff --git a/tests/topotests/isis_te_topo1/reference/ted_step3.json b/tests/topotests/isis_te_topo1/reference/ted_step3.json index de6d108bb3..fb3cdb98fc 100644 --- a/tests/topotests/isis_te_topo1/reference/ted_step3.json +++ b/tests/topotests/isis_te_topo1/reference/ted_step3.json @@ -258,7 +258,6 @@ }, "segment-routing":[ { - "adj-sid":5001, "flags":"0xb0", "weight":0 } @@ -561,7 +560,6 @@ }, "segment-routing":[ { - "adj-sid":5000, "flags":"0x30", "weight":0 } diff --git a/tests/topotests/isis_te_topo1/reference/ted_step4.json b/tests/topotests/isis_te_topo1/reference/ted_step4.json index de6d108bb3..fb3cdb98fc 100644 --- a/tests/topotests/isis_te_topo1/reference/ted_step4.json +++ b/tests/topotests/isis_te_topo1/reference/ted_step4.json @@ -258,7 +258,6 @@ }, "segment-routing":[ { - "adj-sid":5001, "flags":"0xb0", "weight":0 } @@ -561,7 +560,6 @@ }, "segment-routing":[ { - "adj-sid":5000, "flags":"0x30", "weight":0 } diff --git a/tests/topotests/isis_te_topo1/reference/ted_step5.json b/tests/topotests/isis_te_topo1/reference/ted_step5.json index 7daee99297..edc90c3b9e 100644 --- a/tests/topotests/isis_te_topo1/reference/ted_step5.json +++ b/tests/topotests/isis_te_topo1/reference/ted_step5.json @@ -340,7 +340,6 @@ }, "segment-routing":[ { - "adj-sid":5001, "flags":"0xb0", "weight":0 } @@ -725,7 +724,6 @@ }, "segment-routing":[ { - "adj-sid":5000, "flags":"0x30", "weight":0 } diff --git a/tests/topotests/isis_te_topo1/reference/ted_step6.json b/tests/topotests/isis_te_topo1/reference/ted_step6.json index 289eb1ebc2..ec65972cd8 100644 --- a/tests/topotests/isis_te_topo1/reference/ted_step6.json +++ b/tests/topotests/isis_te_topo1/reference/ted_step6.json @@ -340,7 +340,6 @@ }, "segment-routing":[ { - "adj-sid":5001, "flags":"0xb0", "weight":0 } @@ -726,7 +725,6 @@ }, "segment-routing":[ { - "adj-sid":5000, "flags":"0x30", "weight":0 } diff --git a/tests/topotests/isis_te_topo1/reference/ted_step7.json b/tests/topotests/isis_te_topo1/reference/ted_step7.json index 18eb42fd32..6177008460 100644 --- a/tests/topotests/isis_te_topo1/reference/ted_step7.json +++ b/tests/topotests/isis_te_topo1/reference/ted_step7.json @@ -355,7 +355,6 @@ }, "segment-routing":[ { - "adj-sid":5001, "flags":"0xb0", "weight":0 } @@ -756,7 +755,6 @@ }, "segment-routing":[ { - "adj-sid":5000, "flags":"0x30", "weight":0 } diff --git a/tests/topotests/isis_te_topo1/reference/ted_step8.json b/tests/topotests/isis_te_topo1/reference/ted_step8.json index ede36cf93d..2cf17f77b3 100644 --- a/tests/topotests/isis_te_topo1/reference/ted_step8.json +++ b/tests/topotests/isis_te_topo1/reference/ted_step8.json @@ -355,7 +355,6 @@ }, "segment-routing":[ { - "adj-sid":5001, "flags":"0xb0", "weight":0 } @@ -756,7 +755,6 @@ }, "segment-routing":[ { - "adj-sid":5000, "flags":"0x30", "weight":0 } diff --git a/tests/topotests/isis_tilfa_topo1/rt1/isisd.conf b/tests/topotests/isis_tilfa_topo1/rt1/isisd.conf index 955bd5caa0..1218ed350f 100644 --- a/tests/topotests/isis_tilfa_topo1/rt1/isisd.conf +++ b/tests/topotests/isis_tilfa_topo1/rt1/isisd.conf @@ -7,6 +7,7 @@ log file isisd.log ! debug isis spf-events ! debug isis sr-events ! debug isis lsp-gen +! debug isis ti-lfa ! interface lo ip router isis 1 @@ -16,7 +17,8 @@ interface lo interface eth-sw1 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis priority 100 isis fast-reroute ti-lfa ! diff --git a/tests/topotests/isis_tilfa_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_tilfa_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref index 26f0dffa7a..9c5901b90f 100644 --- a/tests/topotests/isis_tilfa_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_tilfa_topo1/rt1/step1/show_yang_interface_isis_adjacencies.ref @@ -11,14 +11,14 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 64, "state": "up" }, { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0002", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 64, "state": "up" } diff --git a/tests/topotests/isis_tilfa_topo1/rt1/zebra.conf b/tests/topotests/isis_tilfa_topo1/rt1/zebra.conf index 37b3f27cae..4de9d8c69f 100644 --- a/tests/topotests/isis_tilfa_topo1/rt1/zebra.conf +++ b/tests/topotests/isis_tilfa_topo1/rt1/zebra.conf @@ -5,6 +5,7 @@ hostname rt1 ! debug zebra kernel ! debug zebra packet ! debug zebra mpls +! debug zebra rib detail ! interface lo ip address 1.1.1.1/32 diff --git a/tests/topotests/isis_tilfa_topo1/rt2/isisd.conf b/tests/topotests/isis_tilfa_topo1/rt2/isisd.conf index f971c658d4..aed69713e1 100644 --- a/tests/topotests/isis_tilfa_topo1/rt2/isisd.conf +++ b/tests/topotests/isis_tilfa_topo1/rt2/isisd.conf @@ -6,6 +6,7 @@ log file isisd.log ! debug isis spf-events ! debug isis sr-events ! debug isis lsp-gen +! debug isis ti-lfa ! interface lo ip router isis 1 @@ -15,21 +16,24 @@ interface lo interface eth-sw1 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute ti-lfa ! interface eth-rt4-1 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute ti-lfa ! interface eth-rt4-2 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute ti-lfa ! router isis 1 diff --git a/tests/topotests/isis_tilfa_topo1/rt2/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_tilfa_topo1/rt2/step1/show_yang_interface_isis_adjacencies.ref index 1ea72a528b..7d9463dd35 100644 --- a/tests/topotests/isis_tilfa_topo1/rt2/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_tilfa_topo1/rt2/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0004", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0004", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -49,14 +49,14 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0001", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 100, "state": "up" }, { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 64, "state": "up" } diff --git a/tests/topotests/isis_tilfa_topo1/rt2/zebra.conf b/tests/topotests/isis_tilfa_topo1/rt2/zebra.conf index f9ac098f4f..f2975f6a9a 100644 --- a/tests/topotests/isis_tilfa_topo1/rt2/zebra.conf +++ b/tests/topotests/isis_tilfa_topo1/rt2/zebra.conf @@ -5,6 +5,7 @@ hostname rt2 ! debug zebra kernel ! debug zebra packet ! debug zebra mpls +! debug zebra rib detail ! interface lo ip address 2.2.2.2/32 diff --git a/tests/topotests/isis_tilfa_topo1/rt3/isisd.conf b/tests/topotests/isis_tilfa_topo1/rt3/isisd.conf index 64f091cfed..d2f01e4595 100644 --- a/tests/topotests/isis_tilfa_topo1/rt3/isisd.conf +++ b/tests/topotests/isis_tilfa_topo1/rt3/isisd.conf @@ -6,6 +6,7 @@ log file isisd.log ! debug isis spf-events ! debug isis sr-events ! debug isis lsp-gen +! debug isis ti-lfa ! interface lo ip router isis 1 @@ -15,21 +16,24 @@ interface lo interface eth-sw1 ip router isis 1 ipv6 router isis 1 - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute ti-lfa ! interface eth-rt5-1 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute ti-lfa ! interface eth-rt5-2 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute ti-lfa ! router isis 1 diff --git a/tests/topotests/isis_tilfa_topo1/rt3/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_tilfa_topo1/rt3/step1/show_yang_interface_isis_adjacencies.ref index d174b4a475..777c749819 100644 --- a/tests/topotests/isis_tilfa_topo1/rt3/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_tilfa_topo1/rt3/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0005", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0005", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -49,14 +49,14 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0001", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 100, "state": "up" }, { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0002", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 64, "state": "up" } diff --git a/tests/topotests/isis_tilfa_topo1/rt3/zebra.conf b/tests/topotests/isis_tilfa_topo1/rt3/zebra.conf index 441c9a3aca..7ffdcd60a4 100644 --- a/tests/topotests/isis_tilfa_topo1/rt3/zebra.conf +++ b/tests/topotests/isis_tilfa_topo1/rt3/zebra.conf @@ -5,6 +5,7 @@ hostname rt3 ! debug zebra kernel ! debug zebra packet ! debug zebra mpls +! debug zebra rib detail ! interface lo ip address 3.3.3.3/32 diff --git a/tests/topotests/isis_tilfa_topo1/rt4/isisd.conf b/tests/topotests/isis_tilfa_topo1/rt4/isisd.conf index 9223852f79..c1117b5d1b 100644 --- a/tests/topotests/isis_tilfa_topo1/rt4/isisd.conf +++ b/tests/topotests/isis_tilfa_topo1/rt4/isisd.conf @@ -6,6 +6,7 @@ log file isisd.log ! debug isis spf-events ! debug isis sr-events ! debug isis lsp-gen +! debug isis ti-lfa ! interface lo ip router isis 1 @@ -16,28 +17,32 @@ interface eth-rt2-1 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute ti-lfa ! interface eth-rt2-2 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute ti-lfa ! interface eth-rt5 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute ti-lfa ! interface eth-rt6 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute ti-lfa ! router isis 1 diff --git a/tests/topotests/isis_tilfa_topo1/rt4/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_tilfa_topo1/rt4/step1/show_yang_interface_isis_adjacencies.ref index 2eb64b6fc9..0ca7a76bd4 100644 --- a/tests/topotests/isis_tilfa_topo1/rt4/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_tilfa_topo1/rt4/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0002", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0002", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -49,7 +49,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0005", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -68,7 +68,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0006", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_tilfa_topo1/rt4/zebra.conf b/tests/topotests/isis_tilfa_topo1/rt4/zebra.conf index a2569aa51f..644885efd2 100644 --- a/tests/topotests/isis_tilfa_topo1/rt4/zebra.conf +++ b/tests/topotests/isis_tilfa_topo1/rt4/zebra.conf @@ -5,6 +5,7 @@ hostname rt4 ! debug zebra kernel ! debug zebra packet ! debug zebra mpls +! debug zebra rib detail ! interface lo ip address 4.4.4.4/32 diff --git a/tests/topotests/isis_tilfa_topo1/rt5/isisd.conf b/tests/topotests/isis_tilfa_topo1/rt5/isisd.conf index a08534cf30..3678ff9074 100644 --- a/tests/topotests/isis_tilfa_topo1/rt5/isisd.conf +++ b/tests/topotests/isis_tilfa_topo1/rt5/isisd.conf @@ -6,6 +6,7 @@ log file isisd.log ! debug isis spf-events ! debug isis sr-events ! debug isis lsp-gen +! debug isis ti-lfa ! interface lo ip router isis 1 @@ -16,28 +17,32 @@ interface eth-rt3-1 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute ti-lfa ! interface eth-rt3-2 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute ti-lfa ! interface eth-rt4 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute ti-lfa ! interface eth-rt6 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute ti-lfa ! router isis 1 diff --git a/tests/topotests/isis_tilfa_topo1/rt5/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_tilfa_topo1/rt5/step1/show_yang_interface_isis_adjacencies.ref index 1ff8c2cd4e..f40b0d353d 100644 --- a/tests/topotests/isis_tilfa_topo1/rt5/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_tilfa_topo1/rt5/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0003", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -49,7 +49,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0004", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -68,7 +68,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0006", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_tilfa_topo1/rt5/zebra.conf b/tests/topotests/isis_tilfa_topo1/rt5/zebra.conf index f62cc8ffd3..424c85ef82 100644 --- a/tests/topotests/isis_tilfa_topo1/rt5/zebra.conf +++ b/tests/topotests/isis_tilfa_topo1/rt5/zebra.conf @@ -5,6 +5,7 @@ hostname rt5 ! debug zebra kernel ! debug zebra packet ! debug zebra mpls +! debug zebra rib detail ! interface lo ip address 5.5.5.5/32 diff --git a/tests/topotests/isis_tilfa_topo1/rt6/isisd.conf b/tests/topotests/isis_tilfa_topo1/rt6/isisd.conf index d92f822b8d..9d3b464726 100644 --- a/tests/topotests/isis_tilfa_topo1/rt6/isisd.conf +++ b/tests/topotests/isis_tilfa_topo1/rt6/isisd.conf @@ -6,6 +6,7 @@ log file isisd.log ! debug isis spf-events ! debug isis sr-events ! debug isis lsp-gen +! debug isis ti-lfa ! interface lo ip router isis 1 @@ -16,14 +17,16 @@ interface eth-rt4 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute ti-lfa ! interface eth-rt5 ip router isis 1 ipv6 router isis 1 isis network point-to-point - isis hello-multiplier 3 + isis hello-interval 1 + isis hello-multiplier 10 isis fast-reroute ti-lfa ! router isis 1 diff --git a/tests/topotests/isis_tilfa_topo1/rt6/step1/show_yang_interface_isis_adjacencies.ref b/tests/topotests/isis_tilfa_topo1/rt6/step1/show_yang_interface_isis_adjacencies.ref index 734832358f..8300ca0b5c 100644 --- a/tests/topotests/isis_tilfa_topo1/rt6/step1/show_yang_interface_isis_adjacencies.ref +++ b/tests/topotests/isis_tilfa_topo1/rt6/step1/show_yang_interface_isis_adjacencies.ref @@ -11,7 +11,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0004", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } @@ -30,7 +30,7 @@ { "neighbor-sys-type": "level-1", "neighbor-sysid": "0000.0000.0005", - "hold-timer": 9, + "hold-timer": 10, "neighbor-priority": 0, "state": "up" } diff --git a/tests/topotests/isis_tilfa_topo1/rt6/zebra.conf b/tests/topotests/isis_tilfa_topo1/rt6/zebra.conf index 4d51d3df84..94fed46cca 100644 --- a/tests/topotests/isis_tilfa_topo1/rt6/zebra.conf +++ b/tests/topotests/isis_tilfa_topo1/rt6/zebra.conf @@ -5,6 +5,7 @@ hostname rt6 ! debug zebra kernel ! debug zebra packet ! debug zebra mpls +! debug zebra rib detail ! interface lo ip address 6.6.6.6/32 diff --git a/tests/topotests/isis_tilfa_topo1/test_isis_tilfa_topo1.py b/tests/topotests/isis_tilfa_topo1/test_isis_tilfa_topo1.py index 1ed52ab76d..e2bbf4588c 100755 --- a/tests/topotests/isis_tilfa_topo1/test_isis_tilfa_topo1.py +++ b/tests/topotests/isis_tilfa_topo1/test_isis_tilfa_topo1.py @@ -818,19 +818,19 @@ def test_rt6_step11(): rname, "show ip route isis json", outputs[rname][11]["show_ip_route.ref"], - count=10, + count=20, ) router_compare_json_output( rname, "show ipv6 route isis json", outputs[rname][11]["show_ipv6_route.ref"], - count=10, + count=20, ) router_compare_json_output( rname, "show mpls table json", outputs[rname][11]["show_mpls_table.ref"], - count=10, + count=20, ) @@ -946,6 +946,15 @@ def test_rib_ipv4_step13(): tgen.net["rt5"].cmd('vtysh -c "conf t" -c "int eth-rt6" -c "isis bfd"') tgen.net["rt6"].cmd('vtysh -c "conf t" -c "int eth-rt5" -c "isis bfd"') + expect = ( + '[{"multihop":false,"peer":"10.0.8.5","interface":"eth-rt5","status":"up"}]' + ) + router_compare_json_output( + rname, + "show bfd peers json", + expect, + ) + def test_rib_ipv6_step13(): logger.info("Test (step 13): verify IPv6 RIB") @@ -1015,19 +1024,20 @@ def test_rt6_step14(): rname, "show ip route isis json", outputs[rname][11]["show_ip_route.ref"], - count=10, + count=20, ) router_compare_json_output( rname, "show ipv6 route isis json", outputs[rname][11]["show_ipv6_route.ref"], - count=10, + count=20, + wait=2, ) router_compare_json_output( rname, "show mpls table json", outputs[rname][11]["show_mpls_table.ref"], - count=10, + count=20, ) diff --git a/tests/topotests/isis_topo1/r3/r3_route.json b/tests/topotests/isis_topo1/r3/r3_route.json index 61d05e80bb..c3b6e3b0a6 100644 --- a/tests/topotests/isis_topo1/r3/r3_route.json +++ b/tests/topotests/isis_topo1/r3/r3_route.json @@ -146,5 +146,20 @@ "protocol": "isis", "selected": true } + ], + "192.0.2.6/32": [ + { + "nexthops": [ + { + "active": true, + "fib": true, + "ip": "10.0.10.1", + "interfaceName": "r3-eth1" + } + ], + "prefix": "192.0.2.6/32", + "protocol": "isis", + "selected": true + } ] } diff --git a/tests/topotests/isis_topo1/r4/r4_route.json b/tests/topotests/isis_topo1/r4/r4_route.json index 79361af4b5..8fd46add33 100644 --- a/tests/topotests/isis_topo1/r4/r4_route.json +++ b/tests/topotests/isis_topo1/r4/r4_route.json @@ -61,5 +61,20 @@ "protocol": "connected", "selected": true } + ], + "192.0.2.6/32": [ + { + "nexthops": [ + { + "active": true, + "fib": true, + "ip": "10.0.11.1", + "interfaceName": "r4-eth1" + } + ], + "prefix": "192.0.2.6/32", + "protocol": "isis", + "selected": true + } ] } diff --git a/tests/topotests/isis_topo1/r5/isisd.conf b/tests/topotests/isis_topo1/r5/isisd.conf index e0e9200d62..81686e0525 100644 --- a/tests/topotests/isis_topo1/r5/isisd.conf +++ b/tests/topotests/isis_topo1/r5/isisd.conf @@ -20,4 +20,5 @@ router isis 1 is-type level-1 redistribute ipv4 connected level-1 redistribute ipv6 connected level-1 + redistribute ipv4 table 20 level-1 ! diff --git a/tests/topotests/isis_topo1/r5/r5_route.json b/tests/topotests/isis_topo1/r5/r5_route.json index cca844b27c..ec544b8e85 100644 --- a/tests/topotests/isis_topo1/r5/r5_route.json +++ b/tests/topotests/isis_topo1/r5/r5_route.json @@ -141,5 +141,21 @@ "protocol": "connected", "selected": true } + ], + "192.0.2.6/32": [ + { + "nexthops": [ + { + "active": true, + "fib": true, + "ip": "10.0.10.6", + "interfaceName": "r5-eth0" + } + ], + "prefix": "192.0.2.6/32", + "protocol": "table", + "instance": 20, + "selected": true + } ] } diff --git a/tests/topotests/isis_topo1/r5/zebra.conf b/tests/topotests/isis_topo1/r5/zebra.conf index 48fed69662..7c400f797b 100644 --- a/tests/topotests/isis_topo1/r5/zebra.conf +++ b/tests/topotests/isis_topo1/r5/zebra.conf @@ -1,4 +1,6 @@ hostname r5 +ip route 192.0.2.6/32 10.0.10.6 table 20 +ip import 20 interface r5-eth0 ip address 10.0.10.1/24 ipv6 address 2001:db8:2:1::1/64 diff --git a/tests/topotests/isis_topo1/test_isis_topo1.py b/tests/topotests/isis_topo1/test_isis_topo1.py index 48e9d5336f..532e70859c 100644 --- a/tests/topotests/isis_topo1/test_isis_topo1.py +++ b/tests/topotests/isis_topo1/test_isis_topo1.py @@ -708,9 +708,9 @@ def _check_overload_timer(router, timer_expected): tgen = get_topogen() router = tgen.gears[router] - thread_output = router.vtysh_cmd("show thread timers") + output = router.vtysh_cmd("show event timers") - timer_running = "set_overload_on_start_timer" in thread_output + timer_running = "set_overload_on_start_timer" in output if timer_running == timer_expected: return True return "Expected timer running status: {}".format(timer_expected) diff --git a/tests/topotests/ldp_snmp/r1/snmpd.conf b/tests/topotests/ldp_snmp/r1/snmpd.conf index 3fd5e982e8..cdcd9a2b37 100644 --- a/tests/topotests/ldp_snmp/r1/snmpd.conf +++ b/tests/topotests/ldp_snmp/r1/snmpd.conf @@ -1,4 +1,4 @@ -agentAddress udp:1.1.1.1:161 +agentAddress udp:161 com2sec public 1.1.1.1 public @@ -15,4 +15,4 @@ rouser frr master agentx agentXSocket /etc/frr/agentx -agentXPerms 777 755 root frr \ No newline at end of file +agentXPerms 777 755 root frr diff --git a/tests/topotests/ldp_snmp/r2/snmpd.conf b/tests/topotests/ldp_snmp/r2/snmpd.conf index fc648057a5..17ddc2a1f9 100644 --- a/tests/topotests/ldp_snmp/r2/snmpd.conf +++ b/tests/topotests/ldp_snmp/r2/snmpd.conf @@ -1,4 +1,4 @@ -agentAddress udp:2.2.2.2:161 +agentAddress udp:161 com2sec public 2.2.2.2 public @@ -15,4 +15,4 @@ rouser frr master agentx agentXSocket /etc/frr/agentx -agentXPerms 777 755 root frr \ No newline at end of file +agentXPerms 777 755 root frr diff --git a/tests/topotests/lib/bgp.py b/tests/topotests/lib/bgp.py index 0bd9408c28..3a16ed5a09 100644 --- a/tests/topotests/lib/bgp.py +++ b/tests/topotests/lib/bgp.py @@ -50,6 +50,7 @@ def create_router_bgp(tgen, topo=None, input_dict=None, build=False, load_config "bgp": { "local_as": "200", "router_id": "22.22.22.22", + "bgp_always_compare_med": True, "graceful-restart": { "graceful-restart": True, "preserve-fw-state": True, @@ -343,6 +344,13 @@ def __create_bgp_global(tgen, input_dict, router, build=False): config_data.append(cmd) + if "bgp_always_compare_med" in bgp_data: + bgp_always_compare_med = bgp_data["bgp_always_compare_med"] + if bgp_always_compare_med == True: + config_data.append("bgp always-compare-med") + elif bgp_always_compare_med == False: + config_data.append("no bgp always-compare-med") + logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name)) return config_data @@ -1317,7 +1325,7 @@ def verify_router_id(tgen, topo, input_dict, expected=True): @retry(retry_timeout=150) -def verify_bgp_convergence(tgen, topo=None, dut=None, expected=True): +def verify_bgp_convergence(tgen, topo=None, dut=None, expected=True, addr_type=None): """ API will verify if BGP is converged with in the given time frame. Running "show bgp summary json" command and verify bgp neighbor @@ -1328,6 +1336,7 @@ def verify_bgp_convergence(tgen, topo=None, dut=None, expected=True): * `tgen`: topogen object * `topo`: input json file data * `dut`: device under test + * `addr_type` : address type for which verification to be done, by-default both v4 and v6 Usage ----- @@ -1431,20 +1440,27 @@ def verify_bgp_convergence(tgen, topo=None, dut=None, expected=True): return errormsg else: total_peer = 0 - for addr_type in bgp_addr_type.keys(): - if not check_address_types(addr_type): + for _addr_type in bgp_addr_type.keys(): + if not check_address_types(_addr_type): continue - bgp_neighbors = bgp_addr_type[addr_type]["unicast"]["neighbor"] + if addr_type and addr_type != _addr_type: + continue + + bgp_neighbors = bgp_addr_type[_addr_type]["unicast"]["neighbor"] for bgp_neighbor in bgp_neighbors: total_peer += len(bgp_neighbors[bgp_neighbor]["dest_link"]) no_of_peer = 0 - for addr_type in bgp_addr_type.keys(): + for _addr_type in bgp_addr_type.keys(): if not check_address_types(addr_type): continue - bgp_neighbors = bgp_addr_type[addr_type]["unicast"]["neighbor"] + + if addr_type and addr_type != _addr_type: + continue + + bgp_neighbors = bgp_addr_type[_addr_type]["unicast"]["neighbor"] for bgp_neighbor, peer_data in bgp_neighbors.items(): for dest_link in peer_data["dest_link"].keys(): @@ -1465,7 +1481,7 @@ def verify_bgp_convergence(tgen, topo=None, dut=None, expected=True): elif "source_link" in peer_details: neighbor_ip = topo["routers"][bgp_neighbor][ "links" - ][peer_details["source_link"]][addr_type].split( + ][peer_details["source_link"]][_addr_type].split( "/" )[ 0 @@ -1476,12 +1492,12 @@ def verify_bgp_convergence(tgen, topo=None, dut=None, expected=True): ): neighbor_ip = data[dest_link]["peer-interface"] else: - neighbor_ip = data[dest_link][addr_type].split("/")[ - 0 - ] + neighbor_ip = data[dest_link][_addr_type].split( + "/" + )[0] nh_state = None neighbor_ip = neighbor_ip.lower() - if addr_type == "ipv4": + if _addr_type == "ipv4": ipv4_data = show_bgp_json[vrf]["ipv4Unicast"][ "peers" ] diff --git a/tests/topotests/lib/bgpcheck.py b/tests/topotests/lib/bgpcheck.py new file mode 100644 index 0000000000..5ca35a50a4 --- /dev/null +++ b/tests/topotests/lib/bgpcheck.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: GPL-2.0-or-later + +# Copyright 2023, 6wind +import json + +from lib import topotest + + +def check_show_bgp_vpn_prefix_not_found(router, ipversion, prefix, rd, label=None): + """ + Check if a given vpn prefix is not present in the BGP RIB + * 'router': the router to check BGP VPN RIB + * 'ipversion': The ip version to check: ipv4 or ipv6 + * 'prefix': the IP prefix to check + * 'rd': the route distinguisher to check + * 'label: the label to check + """ + output = json.loads( + router.vtysh_cmd("show bgp {} vpn {} json".format(ipversion, prefix)) + ) + if label: + expected = {rd: {"prefix": prefix, "paths": [{"remoteLabel": label}]}} + else: + expected = {rd: {"prefix": prefix}} + ret = topotest.json_cmp(output, expected) + if ret is None: + return "not good" + return None + + +def check_show_bgp_vpn_prefix_found( + router, ipversion, prefix, rd, label=None, nexthop=None +): + """ + Check if a given vpn prefix is present in the BGP RIB + * 'router': the router to check BGP VPN RIB + * 'ipversion': The ip version to check: ipv4 or ipv6 + * 'prefix': the IP prefix to check + * 'rd': the route distinguisher to check + * 'label: the label to check + """ + output = json.loads( + router.vtysh_cmd("show bgp {} vpn {} json".format(ipversion, prefix)) + ) + if label: + if nexthop: + expected = { + rd: { + "prefix": prefix, + "paths": [{"remoteLabel": label, "nexthops": [{"ip": nexthop}]}], + } + } + else: + expected = {rd: {"prefix": prefix, "paths": [{"remoteLabel": label}]}} + else: + if nexthop: + expected = { + rd: {"prefix": prefix, "paths": [{"nexthops": [{"ip": nexthop}]}]} + } + else: + expected = {rd: {"prefix": prefix}} + return topotest.json_cmp(output, expected) diff --git a/tests/topotests/lib/bmp_collector/bgp/__init__.py b/tests/topotests/lib/bmp_collector/bgp/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/lib/bmp_collector/bgp/open/__init__.py b/tests/topotests/lib/bmp_collector/bgp/open/__init__.py new file mode 100644 index 0000000000..6c814ee9aa --- /dev/null +++ b/tests/topotests/lib/bmp_collector/bgp/open/__init__.py @@ -0,0 +1,34 @@ +# SPDX-License-Identifier: ISC + +# Copyright 2023 6WIND S.A. +# Authored by Farid Mihoub <farid.mihoub@6wind.com> +# +import ipaddress +import struct + + +class BGPOpen: + UNPACK_STR = '!16sHBBHH4sB' + + @classmethod + def dissect(cls, data): + (marker, + length, + open_type, + version, + my_as, + hold_time, + bgp_id, + optional_params_len) = struct.unpack_from(cls.UNPACK_STR, data) + + data = data[struct.calcsize(cls.UNPACK_STR) + optional_params_len:] + + # XXX: parse optional parameters + + return data, { + 'version': version, + 'my_as': my_as, + 'hold_time': hold_time, + 'bgp_id': ipaddress.ip_address(bgp_id), + 'optional_params_len': optional_params_len, + } diff --git a/tests/topotests/lib/bmp_collector/bgp/update/__init__.py b/tests/topotests/lib/bmp_collector/bgp/update/__init__.py new file mode 100644 index 0000000000..d079b35113 --- /dev/null +++ b/tests/topotests/lib/bmp_collector/bgp/update/__init__.py @@ -0,0 +1,54 @@ +# SPDX-License-Identifier: ISC + +# Copyright 2023 6WIND S.A. +# Authored by Farid Mihoub <farid.mihoub@6wind.com> +# +import ipaddress +import struct + +from .nlri import NlriIPv4Unicast +from .path_attributes import PathAttribute + + +#------------------------------------------------------------------------------ +class BGPUpdate: + UNPACK_STR = '!16sHBH' + STATIC_SIZE = 23 + + @classmethod + def dissect(cls, data): + msg = {'bmp_log_type': 'update'} + common_size = struct.calcsize(cls.UNPACK_STR) + (marker, + length, + update_type, + withdrawn_routes_len) = struct.unpack_from(cls.UNPACK_STR, data) + + # get withdrawn routes + withdrawn_routes = '' + if withdrawn_routes_len: + withdrawn_routes = NlriIPv4Unicast.parse( + data[common_size:common_size + withdrawn_routes_len] + ) + msg['bmp_log_type'] = 'withdraw' + msg.update(withdrawn_routes) + + # get path attributes + (total_path_attrs_len,) = struct.unpack_from( + '!H', data[common_size+withdrawn_routes_len:]) + + if total_path_attrs_len: + offset = cls.STATIC_SIZE + withdrawn_routes_len + path_attrs_data = data[offset:offset + total_path_attrs_len] + while path_attrs_data: + path_attrs_data, pattr = PathAttribute.dissect(path_attrs_data) + if pattr: + msg = {**msg, **pattr} + + # get nlri + nlri_len = length - cls.STATIC_SIZE - withdrawn_routes_len - total_path_attrs_len + if nlri_len > 0: + nlri = NlriIPv4Unicast.parse(data[length - nlri_len:length]) + msg.update(nlri) + + return data[length:], msg diff --git a/tests/topotests/lib/bmp_collector/bgp/update/af.py b/tests/topotests/lib/bmp_collector/bgp/update/af.py new file mode 100644 index 0000000000..01af1ae2be --- /dev/null +++ b/tests/topotests/lib/bmp_collector/bgp/update/af.py @@ -0,0 +1,53 @@ +# SPDX-License-Identifier: ISC + +# Copyright 2023 6WIND S.A. +# Authored by Farid Mihoub <farid.mihoub@6wind.com> +# + +# IANA Address Family Identifier +AFI_IP = 1 +AFI_IP6 = 2 +AFI_L2VPN = 25 + +# IANA Subsequent Address Family Idenitifier +SAFI_UNICAST = 1 +SAFI_MULTICAST = 2 +SAFI_MPLS_LABEL = 4 +SAFI_EVPN = 70 +SAFI_MPLS_VPN = 128 +SAFI_IP_FLOWSPEC = 133 +SAFI_VPN_FLOWSPEC = 134 + + +#------------------------------------------------------------------------------ +class AddressFamily: + def __init__(self, afi, safi): + self.afi = afi + self.safi = safi + + def __eq__(self, other): + if not isinstance(other, type(self)): + return False + return (self.afi, self.safi) == (other.afi, other.safi) + + def __str__(self): + return f'afi: {self.afi}, safi: {self.safi}' + + def __hash__(self): + return hash((self.afi, self.safi)) + + +#------------------------------------------------------------------------------ +class AF: + IPv4_UNICAST = AddressFamily(AFI_IP, SAFI_UNICAST) + IPv6_UNICAST = AddressFamily(AFI_IP6, SAFI_UNICAST) + IPv4_VPN = AddressFamily(AFI_IP, SAFI_MPLS_VPN) + IPv6_VPN = AddressFamily(AFI_IP6, SAFI_MPLS_VPN) + IPv4_MPLS = AddressFamily(AFI_IP, SAFI_MPLS_LABEL) + IPv6_MPLS = AddressFamily(AFI_IP6, SAFI_MPLS_LABEL) + IPv4_FLOWSPEC = AddressFamily(AFI_IP, SAFI_IP_FLOWSPEC) + IPv6_FLOWSPEC = AddressFamily(AFI_IP6, SAFI_IP_FLOWSPEC) + VPNv4_FLOWSPEC = AddressFamily(AFI_IP, SAFI_VPN_FLOWSPEC) + VPNv6_FLOWSPEC = AddressFamily(AFI_IP6, SAFI_VPN_FLOWSPEC) + L2EVPN = AddressFamily(AFI_L2VPN, SAFI_EVPN) + L2VPN_FLOWSPEC = AddressFamily(AFI_L2VPN, SAFI_VPN_FLOWSPEC) diff --git a/tests/topotests/lib/bmp_collector/bgp/update/nlri.py b/tests/topotests/lib/bmp_collector/bgp/update/nlri.py new file mode 100644 index 0000000000..c1720f126c --- /dev/null +++ b/tests/topotests/lib/bmp_collector/bgp/update/nlri.py @@ -0,0 +1,140 @@ +# SPDX-License-Identifier: ISC + +# Copyright 2023 6WIND S.A. +# Authored by Farid Mihoub <farid.mihoub@6wind.com> +# +import ipaddress +import struct + +from .af import AddressFamily, AF +from .rd import RouteDistinguisher + + +def decode_label(label): + # from frr + # frr encode just one label + return (label[0] << 12) | (label[1] << 4) | (label[2] & 0xf0) >> 4 + +def padding(databin, len_): + """ + Assumption: + One nlri per update/withdraw message, so we can add + a padding to the prefix without worrying about its length + """ + if len(databin) >= len_: + return databin + return databin + b'\0' * (len_ - len(databin)) + +def dissect_nlri(nlri_data, afi, safi): + """ + Exract nlri information based on the address family + """ + addr_family = AddressFamily(afi, safi) + if addr_family == AF.IPv6_VPN: + return NlriIPv6Vpn.parse(nlri_data) + elif addr_family == AF.IPv4_VPN: + return NlriIPv4Vpn.parse(nlri_data) + elif addr_family == AF.IPv6_UNICAST: + return NlriIPv6Unicast.parse(nlri_data) + + return {'ip_prefix': 'Unknown'} + + +#------------------------------------------------------------------------------ +class NlriIPv4Unicast: + + @staticmethod + def parse(data): + """parses prefixes from withdrawn_routes or nrli data""" + (prefix_len,) = struct.unpack_from('!B', data) + prefix = padding(data[1:], 4) + + return {'ip_prefix': f'{ipaddress.IPv4Address(prefix)}/{prefix_len}'} + + +#------------------------------------------------------------------------------ +class NlriIPv6Unicast: + @staticmethod + def parse(data): + """parses prefixes from withdrawn_routes or nrli data""" + (prefix_len,) = struct.unpack_from('!B', data) + prefix = padding(data[1:], 16) + + return {'ip_prefix': f'{ipaddress.IPv6Address(prefix)}/{prefix_len}'} + + +#------------------------------------------------------------------------------ +class NlriIPv4Vpn: + UNPACK_STR = '!B3s8s' + + @classmethod + def parse(cls, data): + (bit_len, label, rd) = struct.unpack_from(cls.UNPACK_STR, data) + offset = struct.calcsize(cls.UNPACK_STR) + + ipv4 = padding(data[offset:], 4) + # prefix_len = total_bits_len - label_bits_len - rd_bits_len + prefix_len = bit_len - 3*8 - 8*8 + return { + 'label': decode_label(label), + 'rd': str(RouteDistinguisher(rd)), + 'ip_prefix': f'{ipaddress.IPv4Address(ipv4)}/{prefix_len}', + } + + +#------------------------------------------------------------------------------ +class NlriIPv6Vpn: + UNPACK_STR = '!B3s8s' + + @classmethod + def parse(cls, data): + # rfc 3107, 8227 + (bit_len, label, rd) = struct.unpack_from(cls.UNPACK_STR, data) + offset = struct.calcsize(cls.UNPACK_STR) + + ipv6 = padding(data[offset:], 16) + prefix_len = bit_len - 3*8 - 8*8 + return { + 'label': decode_label(label), + 'rd': str(RouteDistinguisher(rd)), + 'ip_prefix': f'{ipaddress.IPv6Address(ipv6)}/{prefix_len}', + } + + +#------------------------------------------------------------------------------ +class NlriIPv4Mpls: + pass + + +#------------------------------------------------------------------------------ +class NlriIPv6Mpls: + pass + + +#------------------------------------------------------------------------------ +class NlriIPv4FlowSpec: + pass + + +#------------------------------------------------------------------------------ +class NlriIPv6FlowSpec: + pass + + +#------------------------------------------------------------------------------ +class NlriVpn4FlowSpec: + pass + + +#------------------------------------------------------------------------------ +class NlriVpn6FlowSpec: + pass + + +#------------------------------------------------------------------------------ +class NlriL2EVPN: + pass + +#------------------------------------------------------------------------------ +class NlriL2VPNFlowSpec: + pass diff --git a/tests/topotests/lib/bmp_collector/bgp/update/path_attributes.py b/tests/topotests/lib/bmp_collector/bgp/update/path_attributes.py new file mode 100644 index 0000000000..6e82e9c170 --- /dev/null +++ b/tests/topotests/lib/bmp_collector/bgp/update/path_attributes.py @@ -0,0 +1,304 @@ +# SPDX-License-Identifier: ISC + +# Copyright 2023 6WIND S.A. +# Authored by Farid Mihoub <farid.mihoub@6wind.com> +# +import struct +import ipaddress + +from . import nlri as NLRI +from .af import AddressFamily, AF +from .rd import RouteDistinguisher + + +PATH_ATTR_FLAG_OPTIONAL = 1 << 7 +PATH_ATTR_FLAG_TRANSITIVE = 1 << 6 +PATH_ATTR_FLAG_PARTIAL = 1 << 5 +PATH_ATTR_FLAG_EXTENDED_LENGTH = 1 << 4 + +PATH_ATTR_TYPE_ORIGIN = 1 +PATH_ATTR_TYPE_AS_PATH = 2 +PATH_ATTR_TYPE_NEXT_HOP = 3 +PATH_ATTR_TYPE_MULTI_EXIT_DISC = 4 +PATH_ATTR_TYPE_LOCAL_PREF = 5 +PATH_ATTR_TYPE_ATOMIC_AGGREGATE = 6 +PATH_ATTR_TYPE_AGGREGATOR = 7 +PATH_ATTR_TYPE_COMMUNITIES = 8 +PATH_ATTR_TYPE_ORIGINATOR_ID = 9 +PATH_ATTR_TYPE_CLUSTER_LIST = 10 +PATH_ATTR_TYPE_MP_REACH_NLRI = 14 +PATH_ATTR_TYPE_MP_UNREACH_NLRI = 15 +PATH_ATTR_TYPE_EXTENDED_COMMUNITIES = 16 +PATH_ATTR_TYPE_AS4_PATH = 17 +PATH_ATTR_TYPE_AS4_AGGREGATOR = 18 +PATH_ATTR_TYEP_PMSI_TUNNEL_ATTRIBUTE = 22 + +ORIGIN_IGP = 0x00 +ORIGIN_EGP = 0x01 +ORIGIN_INCOMPLETE = 0x02 + + +#------------------------------------------------------------------------------ +class PathAttribute: + PATH_ATTRS = {} + UNKNOWN_ATTR = None + UNPACK_STR = '!BB' + + @classmethod + def register_path_attr(cls, path_attr): + def _register_path_attr(subcls): + cls.PATH_ATTRS[path_attr] = subcls + return subcls + return _register_path_attr + + @classmethod + def lookup_path_attr(cls, type_code): + return cls.PATH_ATTRS.get(type_code, cls.UNKNOWN_ATTR) + + @classmethod + def dissect(cls, data): + flags, type_code = struct.unpack_from(cls.UNPACK_STR, data) + offset = struct.calcsize(cls.UNPACK_STR) + + # get attribute length + attr_len_str = '!H' if (flags & PATH_ATTR_FLAG_EXTENDED_LENGTH) else '!B' + + (attr_len,) = struct.unpack_from(attr_len_str, data[offset:]) + + offset += struct.calcsize(attr_len_str) + + path_attr_cls = cls.lookup_path_attr(type_code) + if path_attr_cls == cls.UNKNOWN_ATTR: + return data[offset + attr_len:], None + + return data[offset+attr_len:], path_attr_cls.dissect(data[offset:offset+attr_len]) + + +#------------------------------------------------------------------------------ +@PathAttribute.register_path_attr(PATH_ATTR_TYPE_ORIGIN) +class PathAttrOrigin: + ORIGIN_STR = { + ORIGIN_IGP: 'IGP', + ORIGIN_EGP: 'EGP', + ORIGIN_INCOMPLETE: 'INCOMPLETE', + } + + @classmethod + def dissect(cls, data): + (origin,) = struct.unpack_from('!B', data) + + return {'origin': cls.ORIGIN_STR.get(origin, 'UNKNOWN')} + + +#------------------------------------------------------------------------------ +@PathAttribute.register_path_attr(PATH_ATTR_TYPE_AS_PATH) +class PathAttrAsPath: + AS_PATH_TYPE_SET = 0x01 + AS_PATH_TYPE_SEQUENCE= 0x02 + + @staticmethod + def get_asn_len(asns): + """XXX: Add this nightmare to determine the ASN length""" + pass + + @classmethod + def dissect(cls, data): + (_type, _len) = struct.unpack_from('!BB', data) + data = data[2:] + + _type_str = 'Ordred' if _type == cls.AS_PATH_TYPE_SEQUENCE else 'Raw' + segment = [] + while data: + (asn,) = struct.unpack_from('!I', data) + segment.append(asn) + data = data[4:] + + return {'as_path': ' '.join(str(a) for a in segment)} + + +#------------------------------------------------------------------------------ +@PathAttribute.register_path_attr(PATH_ATTR_TYPE_NEXT_HOP) +class PathAttrNextHop: + @classmethod + def dissect(cls, data): + (nexthop,) = struct.unpack_from('!4s', data) + return {'bgp_nexthop': str(ipaddress.IPv4Address(nexthop))} + + +#------------------------------------------------------------------------------ +class PathAttrMultiExitDisc: + pass + + +#------------------------------------------------------------------------------ +@PathAttribute.register_path_attr(PATH_ATTR_TYPE_MP_REACH_NLRI) +class PathAttrMpReachNLRI: + """ + +---------------------------------------------------------+ + | Address Family Identifier (2 octets) | + +---------------------------------------------------------+ + | Subsequent Address Family Identifier (1 octet) | + +---------------------------------------------------------+ + | Length of Next Hop Network Address (1 octet) | + +---------------------------------------------------------+ + | Network Address of Next Hop (variable) | + +---------------------------------------------------------+ + | Number of SNPAs (1 octet) | + +---------------------------------------------------------+ + | Length of first SNPA(1 octet) | + +---------------------------------------------------------+ + | First SNPA (variable) | + +---------------------------------------------------------+ + | Length of second SNPA (1 octet) | + +---------------------------------------------------------+ + | Second SNPA (variable) | + +---------------------------------------------------------+ + | ... | + +---------------------------------------------------------+ + | Length of Last SNPA (1 octet) | + +---------------------------------------------------------+ + | Last SNPA (variable) | + +---------------------------------------------------------+ + | Network Layer Reachability Information (variable) | + +---------------------------------------------------------+ + """ + UNPACK_STR = '!HBB' + NLRI_RESERVED_LEN = 1 + + @staticmethod + def dissect_nexthop(nexthop_data, nexthop_len): + msg = {} + if nexthop_len == 4: + # IPv4 + (ipv4,) = struct.unpack_from('!4s', nexthop_data) + msg['nxhp_ip'] = str(ipaddress.IPv4Address(ipv4)) + elif nexthop_len == 12: + # RD + IPv4 + (rd, ipv4) = struct.unpack_from('!8s4s', nexthop_data) + msg['nxhp_ip'] = str(ipaddress.IPv4Address(ipv4)) + msg['nxhp_rd'] = str(RouteDistinguisher(rd)) + elif nexthop_len == 16: + # IPv6 + (ipv6,) = struct.unpack_from('!16s', nexthop_data) + msg['nxhp_ip'] = str(ipaddress.IPv6Address(ipv6)) + elif nexthop_len == 24: + # RD + IPv6 + (rd, ipv6) = struct.unpack_from('!8s16s', nexthop_data) + msg['nxhp_ip'] = str(ipaddress.IPv6Address(ipv6)) + msg['nxhp_rd'] = str(RouteDistinguisher(rd)) + elif nexthop_len == 32: + # IPv6 + IPv6 link-local + (ipv6, link_local)= struct.unpack_from('!16s16s', nexthop_data) + msg['nxhp_ip'] = str(ipaddress.IPv6Address(ipv6)) + msg['nxhp_link-local'] = str(ipaddress.IPv6Address(link_local)) + elif nexthop_len == 48: + # RD + IPv6 + RD + IPv6 link-local + u_str = '!8s16s8s16s' + (rd1, ipv6, rd2, link_local)= struct.unpack_from(u_str, nexthop_data) + msg['nxhp_rd1'] = str(RouteDistinguisher(rd1)) + msg['nxhp_ip'] = str(ipaddress.IPv6Address(ipv6)) + msg['nxhp_rd2'] = str(RouteDistinguisher(rd2)) + msg['nxhp_link-local'] = str(ipaddress.IPv6Address(link_local)) + + return msg + + @staticmethod + def dissect_snpa(snpa_data): + pass + + @classmethod + def dissect(cls, data): + (afi, safi, nexthop_len) = struct.unpack_from(cls.UNPACK_STR, data) + offset = struct.calcsize(cls.UNPACK_STR) + msg = {'afi': afi, 'safi': safi} + + # dissect nexthop + nexthop_data = data[offset: offset + nexthop_len] + nexthop = cls.dissect_nexthop(nexthop_data, nexthop_len) + msg.update(nexthop) + + offset += nexthop_len + # dissect snpa or just reserved + offset += 1 + # dissect nlri + nlri = NLRI.dissect_nlri(data[offset:], afi, safi) + msg.update(nlri) + + return msg + + +#------------------------------------------------------------------------------ +@PathAttribute.register_path_attr(PATH_ATTR_TYPE_MP_UNREACH_NLRI) +class PathAttrMpUnReachNLRI: + """ + +---------------------------------------------------------+ + | Address Family Identifier (2 bytes) | + +---------------------------------------------------------+ + | Subsequent Address Family Identifier (1 byte) | + +---------------------------------------------------------+ + | Withdrawn Routes (variable) | + +---------------------------------------------------------+ + """ + UNPACK_STR = '!HB' + + @classmethod + def dissect(cls, data): + (afi, safi) = struct.unpack_from(cls.UNPACK_STR, data) + offset = struct.calcsize(cls.UNPACK_STR) + msg = {'bmp_log_type': 'withdraw','afi': afi, 'safi': safi} + + if data[offset:]: + # dissect withdrawn_routes + msg.update(NLRI.dissect_nlri(data[offset:], afi, safi)) + + return msg + + +#------------------------------------------------------------------------------ +class PathAttrLocalPref: + pass + + +#------------------------------------------------------------------------------ +class PathAttrAtomicAgregate: + pass + + +#------------------------------------------------------------------------------ +class PathAttrAggregator: + pass + + +#------------------------------------------------------------------------------ +class PathAttrCommunities: + pass + + +#------------------------------------------------------------------------------ +class PathAttrOriginatorID: + pass + + +#------------------------------------------------------------------------------ +class PathAttrClusterList: + pass + + +#------------------------------------------------------------------------------ +class PathAttrExtendedCommunities: + pass + + +#------------------------------------------------------------------------------ +class PathAttrPMSITunnel: + pass + + +#------------------------------------------------------------------------------ +class PathAttrLinkState: + pass + + +#------------------------------------------------------------------------------ +class PathAttrLargeCommunities: + pass diff --git a/tests/topotests/lib/bmp_collector/bgp/update/rd.py b/tests/topotests/lib/bmp_collector/bgp/update/rd.py new file mode 100644 index 0000000000..c382fa8340 --- /dev/null +++ b/tests/topotests/lib/bmp_collector/bgp/update/rd.py @@ -0,0 +1,59 @@ +# SPDX-License-Identifier: ISC + +# Copyright 2023 6WIND S.A. +# Authored by Farid Mihoub <farid.mihoub@6wind.com> +# +import ipaddress +import struct + + +#------------------------------------------------------------------------------ +class RouteDistinguisher: + """ + type 0: + +---------------------------------------------------------------------+ + + type=0 (2 bytes)| Administrator subfield | Assigned number subfiled | + + | AS number (2 bytes) | Service Provider 4 bytes)| + +---------------------------------------------------------------------+ + + type 1: + +---------------------------------------------------------------------+ + + type=1 (2 bytes)| Administrator subfield | Assigned number subfiled | + + | IPv4 (4 bytes) | Service Provider 2 bytes)| + +---------------------------------------------------------------------+ + + type 2: + +-------------------------------------------------------------------------+ + + type=2 (2 bytes)| Administrator subfield | Assigned number subfiled | + + | 4-bytes AS number (4 bytes)| Service Provider 2 bytes)| + +-------------------------------------------------------------------------+ + """ + def __init__(self, rd): + self.rd = rd + self.as_number = None + self.admin_ipv4 = None + self.four_bytes_as = None + self.assigned_sp = None + self.repr_str = '' + self.dissect() + + def dissect(self): + (rd_type,) = struct.unpack_from('!H', self.rd) + if rd_type == 0: + (self.as_number, + self.assigned_sp) = struct.unpack_from('!HI', self.rd[2:]) + self.repr_str = f'{self.as_number}:{self.assigned_sp}' + + elif rd_type == 1: + (self.admin_ipv4, + self.assigned_sp) = struct.unpack_from('!IH', self.rd[2:]) + ipv4 = str(ipaddress.IPv4Address(self.admin_ipv4)) + self.repr_str = f'{self.as_number}:{self.assigned_sp}' + + elif rd_type == 2: + (self.four_bytes_as, + self.assigned_sp) = struct.unpack_from('!IH', self.rd[2:]) + self.repr_str = f'{self.four_bytes_as}:{self.assigned_sp}' + + def __str__(self): + return self.repr_str diff --git a/tests/topotests/lib/bmp_collector/bmp.py b/tests/topotests/lib/bmp_collector/bmp.py new file mode 100644 index 0000000000..57f642aa0e --- /dev/null +++ b/tests/topotests/lib/bmp_collector/bmp.py @@ -0,0 +1,421 @@ +# SPDX-License-Identifier: ISC + +# Copyright 2023 6WIND S.A. +# Authored by Farid Mihoub <farid.mihoub@6wind.com> +# +""" +BMP main module: + - dissect monitoring messages in the way to get updated/withdrawed prefixes + - XXX: missing RFCs references + - XXX: more bmp messages types to dissect + - XXX: complete bgp message dissection +""" +import datetime +import ipaddress +import json +import os +import struct + +from bgp.update import BGPUpdate +from bgp.update.rd import RouteDistinguisher + + +SEQ = 0 +LOG_DIR = "/var/log/" +LOG_FILE = "/var/log/bmp.log" + +IS_ADJ_RIB_OUT = 1 << 4 +IS_AS_PATH = 1 << 5 +IS_POST_POLICY = 1 << 6 +IS_IPV6 = 1 << 7 +IS_FILTERED = 1 << 7 + +if not os.path.exists(LOG_DIR): + os.makedirs(LOG_DIR) + +def bin2str_ipaddress(ip_bytes, is_ipv6=False): + if is_ipv6: + return str(ipaddress.IPv6Address(ip_bytes)) + return str(ipaddress.IPv4Address(ip_bytes[-4:])) + +def log2file(logs): + """ + XXX: extract the useful information and save it in a flat dictionnary + """ + with open(LOG_FILE, 'a') as f: + f.write(json.dumps(logs) + "\n") + + +#------------------------------------------------------------------------------ +class BMPCodes: + """ + XXX: complete the list, provide RFCs. + """ + VERSION = 0x3 + + BMP_MSG_TYPE_ROUTE_MONITORING = 0x00 + BMP_MSG_TYPE_STATISTICS_REPORT = 0x01 + BMP_MSG_TYPE_PEER_DOWN_NOTIFICATION = 0x02 + BMP_MSG_TYPE_PEER_UP_NOTIFICATION = 0x03 + BMP_MSG_TYPE_INITIATION = 0x04 + BMP_MSG_TYPE_TERMINATION = 0x05 + BMP_MSG_TYPE_ROUTE_MIRRORING = 0x06 + BMP_MSG_TYPE_ROUTE_POLICY = 0x64 + + # initiation message types + BMP_INIT_INFO_STRING = 0x00 + BMP_INIT_SYSTEM_DESCRIPTION = 0x01 + BMP_INIT_SYSTEM_NAME = 0x02 + BMP_INIT_VRF_TABLE_NAME = 0x03 + BMP_INIT_ADMIN_LABEL = 0x04 + + # peer types + BMP_PEER_GLOBAL_INSTANCE = 0x00 + BMP_PEER_RD_INSTANCE = 0x01 + BMP_PEER_LOCAL_INSTANCE = 0x02 + BMP_PEER_LOC_RIB_INSTANCE = 0x03 + + # peer header flags + BMP_PEER_FLAG_IPV6 = 0x80 + BMP_PEER_FLAG_POST_POLICY = 0x40 + BMP_PEER_FLAG_AS_PATH = 0x20 + BMP_PEER_FLAG_ADJ_RIB_OUT = 0x10 + + # peer loc-rib flag + BMP_PEER_FLAG_LOC_RIB = 0x80 + BMP_PEER_FLAG_LOC_RIB_RES = 0x7F + + # statistics type + BMP_STAT_PREFIX_REJ = 0x00 + BMP_STAT_PREFIX_DUP = 0x01 + BMP_STAT_WITHDRAW_DUP = 0x02 + BMP_STAT_CLUSTER_LOOP = 0x03 + BMP_STAT_AS_LOOP = 0x04 + BMP_STAT_INV_ORIGINATOR = 0x05 + BMP_STAT_AS_CONFED_LOOP = 0x06 + BMP_STAT_ROUTES_ADJ_RIB_IN = 0x07 + BMP_STAT_ROUTES_LOC_RIB = 0x08 + BMP_STAT_ROUTES_PER_ADJ_RIB_IN = 0x09 + BMP_STAT_ROUTES_PER_LOC_RIB = 0x0A + BMP_STAT_UPDATE_TREAT = 0x0B + BMP_STAT_PREFIXES_TREAT = 0x0C + BMP_STAT_DUPLICATE_UPDATE = 0x0D + BMP_STAT_ROUTES_PRE_ADJ_RIB_OUT = 0x0E + BMP_STAT_ROUTES_POST_ADJ_RIB_OUT = 0x0F + BMP_STAT_ROUTES_PRE_PER_ADJ_RIB_OUT = 0x10 + BMP_STAT_ROUTES_POST_PER_ADJ_RIB_OUT = 0x11 + + # peer down reason code + BMP_PEER_DOWN_LOCAL_NOTIFY = 0x01 + BMP_PEER_DOWN_LOCAL_NO_NOTIFY = 0X02 + BMP_PEER_DOWN_REMOTE_NOTIFY = 0X03 + BMP_PEER_DOWN_REMOTE_NO_NOTIFY = 0X04 + BMP_PEER_DOWN_INFO_NO_LONGER = 0x05 + BMP_PEER_DOWN_SYSTEM_CLOSED = 0X06 + + # termincation message types + BMP_TERM_TYPE_STRING = 0x00 + BMP_TERM_TYPE_REASON = 0X01 + + # termination reason code + BMP_TERM_REASON_ADMIN_CLOSE = 0x00 + BMP_TERM_REASON_UNSPECIFIED = 0x01 + BMP_TERM_REASON_RESOURCES = 0x02 + BMP_TERM_REASON_REDUNDANT = 0x03 + BMP_TERM_REASON_PERM_CLOSE = 0x04 + + # policy route tlv + BMP_ROUTE_POLICY_TLV_VRF = 0x00 + BMP_ROUTE_POLICY_TLV_POLICY= 0x01 + BMP_ROUTE_POLICY_TLV_PRE_POLICY = 0x02 + BMP_ROUTE_POLICY_TLV_POST_POLICY = 0x03 + BMP_ROUTE_POLICY_TLV_STRING = 0x04 + + +#------------------------------------------------------------------------------ +class BMPMsg: + """ + XXX: should we move register_msg_type and look_msg_type + to generic Type class. + """ + TYPES = {} + UNKNOWN_TYPE = None + HDR_STR = '!BIB' + MIN_LEN = struct.calcsize(HDR_STR) + TYPES_STR = { + BMPCodes.BMP_MSG_TYPE_INITIATION: 'initiation', + BMPCodes.BMP_MSG_TYPE_PEER_DOWN_NOTIFICATION: 'peer down notification', + BMPCodes.BMP_MSG_TYPE_PEER_UP_NOTIFICATION: 'peer up notification', + BMPCodes.BMP_MSG_TYPE_ROUTE_MONITORING: 'route monitoring', + BMPCodes.BMP_MSG_TYPE_STATISTICS_REPORT: 'statistics report', + BMPCodes.BMP_MSG_TYPE_TERMINATION: 'termination', + BMPCodes.BMP_MSG_TYPE_ROUTE_MIRRORING: 'route mirroring', + BMPCodes.BMP_MSG_TYPE_ROUTE_POLICY: 'route policy', + } + + @classmethod + def register_msg_type(cls, msgtype): + def _register_type(subcls): + cls.TYPES[msgtype] = subcls + return subcls + return _register_type + + @classmethod + def lookup_msg_type(cls, msgtype): + return cls.TYPES.get(msgtype, cls.UNKNOWN_TYPE) + + @classmethod + def dissect_header(cls, data): + """ + 0 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Version | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Message Length | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Message Type | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + """ + if len(data) < cls.MIN_LEN: + pass + else: + _version, _len, _type = struct.unpack(cls.HDR_STR, data[0:cls.MIN_LEN]) + return _version, _len, _type + + @classmethod + def dissect(cls, data): + global SEQ + version, msglen, msgtype = cls.dissect_header(data) + + msg_data = data[cls.MIN_LEN:msglen] + data = data[msglen:] + + if version != BMPCodes.VERSION: + # XXX: log something + return data + + msg_cls = cls.lookup_msg_type(msgtype) + if msg_cls == cls.UNKNOWN_TYPE: + # XXX: log something + return data + + msg_cls.MSG_LEN = msglen - cls.MIN_LEN + logs = msg_cls.dissect(msg_data) + logs["seq"] = SEQ + log2file(logs) + SEQ += 1 + + return data + + +#------------------------------------------------------------------------------ +class BMPPerPeerMessage: + """ + 0 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Peer Type | Peer Flags | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Peer Address (16 bytes) | + ~ ~ + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Peer AS | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Peer BGP ID | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Timestamp (seconds) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Timestamp (microseconds) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + """ + PEER_UNPACK_STR = '!BB8s16sI4sII' + PEER_TYPE_STR = { + BMPCodes.BMP_PEER_GLOBAL_INSTANCE: 'global instance', + BMPCodes.BMP_PEER_RD_INSTANCE: 'route distinguisher instance', + BMPCodes.BMP_PEER_LOCAL_INSTANCE: 'local instance', + BMPCodes.BMP_PEER_LOC_RIB_INSTANCE: 'loc-rib instance', + } + + @classmethod + def dissect(cls, data): + (peer_type, + peer_flags, + peer_distinguisher, + peer_address, + peer_asn, + peer_bgp_id, + timestamp_secs, + timestamp_microsecs) = struct.unpack_from(cls.PEER_UNPACK_STR, data) + + msg = {'peer_type': cls.PEER_TYPE_STR[peer_type]} + + if peer_type == 0x03: + msg['is_filtered'] = bool(peer_flags & IS_FILTERED) + msg['policy'] = 'loc-rib' + else: + # peer_flags = 0x0000 0000 + # ipv6, post-policy, as-path, adj-rib-out, reserverdx4 + is_adj_rib_out = bool(peer_flags & IS_ADJ_RIB_OUT) + is_as_path = bool(peer_flags & IS_AS_PATH) + is_post_policy = bool(peer_flags & IS_POST_POLICY) + is_ipv6 = bool(peer_flags & IS_IPV6) + msg['policy'] = 'post-policy' if is_post_policy else 'pre-policy' + msg['ipv6'] = is_ipv6 + msg['peer_ip'] = bin2str_ipaddress(peer_address, is_ipv6) + + + peer_bgp_id = bin2str_ipaddress(peer_bgp_id) + timestamp = float(timestamp_secs) + timestamp_microsecs * (10 ** -6) + + data = data[struct.calcsize(cls.PEER_UNPACK_STR):] + msg.update({ + 'peer_distinguisher': str(RouteDistinguisher(peer_distinguisher)), + 'peer_asn': peer_asn, + 'peer_bgp_id': peer_bgp_id, + 'timestamp': str(datetime.datetime.fromtimestamp(timestamp)), + }) + + return data, msg + + +#------------------------------------------------------------------------------ +@BMPMsg.register_msg_type(BMPCodes.BMP_MSG_TYPE_ROUTE_MONITORING) +class BMPRouteMonitoring(BMPPerPeerMessage): + + @classmethod + def dissect(cls, data): + data, peer_msg = super().dissect(data) + data, update_msg = BGPUpdate.dissect(data) + return {**peer_msg, **update_msg} + + +#------------------------------------------------------------------------------ +class BMPStatisticsReport: + """ + 0 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Stats Count | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Stat Type | Stat Len | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Stat Data | + ~ ~ + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + """ + pass + + +#------------------------------------------------------------------------------ +class BMPPeerDownNotification: + """ + 0 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Reason | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Data (present if Reason = 1, 2 or 3) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + """ + pass + + +#------------------------------------------------------------------------------ +@BMPMsg.register_msg_type(BMPCodes.BMP_MSG_TYPE_PEER_UP_NOTIFICATION) +class BMPPeerUpNotification(BMPPerPeerMessage): + """ + 0 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Local Address (16 bytes) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Local Port | Remote Port | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Sent OPEN Message #| + ~ ~ + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Received OPEN Message | + ~ ~ + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + """ + UNPACK_STR = '!16sHH' + MIN_LEN = struct.calcsize(UNPACK_STR) + MSG_LEN = None + + @classmethod + def dissect(cls, data): + data, peer_msg = super().dissect(data) + + (local_addr, + local_port, + remote_port) = struct.unpack_from(cls.UNPACK_STR, data) + + msg = { + **peer_msg, + **{ + 'local_ip': bin2str_ipaddress(local_addr, peer_msg.get('ipv6')), + 'local_port': int(local_port), + 'remote_port': int(remote_port), + }, + } + + # XXX: dissect the bgp open message + + return msg + + +#------------------------------------------------------------------------------ +@BMPMsg.register_msg_type(BMPCodes.BMP_MSG_TYPE_INITIATION) +class BMPInitiation: + """ + 0 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Information Type | Information Length | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Information (variable) | + ~ ~ + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + """ + TLV_STR = '!HH' + MIN_LEN = struct.calcsize(TLV_STR) + FIELD_TO_STR = { + BMPCodes.BMP_INIT_INFO_STRING: 'information', + BMPCodes.BMP_INIT_ADMIN_LABEL: 'admin_label', + BMPCodes.BMP_INIT_SYSTEM_DESCRIPTION: 'system_description', + BMPCodes.BMP_INIT_SYSTEM_NAME: 'system_name', + BMPCodes.BMP_INIT_VRF_TABLE_NAME: 'vrf_table_name', + } + + @classmethod + def dissect(cls, data): + msg = {} + while len(data) > cls.MIN_LEN: + _type, _len = struct.unpack_from(cls.TLV_STR, data[0:cls.MIN_LEN]) + _value = data[cls.MIN_LEN: cls.MIN_LEN + _len].decode() + + msg[cls.FIELD_TO_STR[_type]] = _value + data = data[cls.MIN_LEN + _len:] + + return msg + + +#------------------------------------------------------------------------------ +class BMPTermination: + """ + 0 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Information Type | Information Length | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Information (variable) | + ~ ~ + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + """ + pass + + +#------------------------------------------------------------------------------ +class BMPRouteMirroring: + pass + + +#------------------------------------------------------------------------------ +class BMPRoutePolicy: + pass diff --git a/tests/topotests/lib/bmp_collector/bmpserver b/tests/topotests/lib/bmp_collector/bmpserver new file mode 100755 index 0000000000..25b4a52c5e --- /dev/null +++ b/tests/topotests/lib/bmp_collector/bmpserver @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: ISC + +# Copyright 2023 6WIND S.A. +# Authored by Farid Mihoub <farid.mihoub@6wind.com> +# +import argparse +# XXX: something more reliable should be used "Twisted" a great choice. +import socket +import sys + +from bmp import BMPMsg + +BGP_MAX_SIZE = 4096 + +parser = argparse.ArgumentParser() +parser.add_argument("-a", "--address", type=str, default="0.0.0.0") +parser.add_argument("-p", "--port", type=int, default=1789) + +def main(): + args = parser.parse_args() + ADDRESS, PORT = args.address, args.port + + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + s.bind((ADDRESS, PORT)) + s.listen() + connection, _ = s.accept() + + try: + while True: + data = connection.recv(BGP_MAX_SIZE) + while len(data) > BMPMsg.MIN_LEN: + data = BMPMsg.dissect(data) + except Exception as e: + # XXX: do something + pass + except KeyboardInterrupt: + # XXX: do something + pass + finally: + connection.close() + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tests/topotests/lib/checkping.py b/tests/topotests/lib/checkping.py new file mode 100644 index 0000000000..aaa6164dd4 --- /dev/null +++ b/tests/topotests/lib/checkping.py @@ -0,0 +1,33 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright 2023 Quentin Young + +import functools +from lib.topogen import get_topogen +from lib.topolog import logger +from lib import topotest + + +def check_ping(name, dest_addr, expect_connected, count, wait): + """ + Assert that ping to dest_addr is expected + * 'name': the router to set the ping from + * 'dest_addr': The destination ip address to ping + * 'expect_connected': True if ping is expected to pass + * 'count': how many echos to send + * 'wait': how long ping should wait to receive all replies + """ + + def _check(name, dest_addr, match): + tgen = get_topogen() + output = tgen.gears[name].run("ping {} -c 1 -w 1".format(dest_addr)) + logger.info(output) + if match not in output: + return "ping fail" + + match = ", {} packet loss".format("0%" if expect_connected else "100%") + logger.info("[+] check {} {} {}".format(name, dest_addr, match)) + tgen = get_topogen() + func = functools.partial(_check, name, dest_addr, match) + success, result = topotest.run_and_expect(func, None, count=count, wait=wait) + assert result is None, "Failed" diff --git a/tests/topotests/lib/common_config.py b/tests/topotests/lib/common_config.py index a85b86668c..598db84e63 100644 --- a/tests/topotests/lib/common_config.py +++ b/tests/topotests/lib/common_config.py @@ -5,6 +5,7 @@ # ("NetDEF") in this file. # +import functools import ipaddress import json import os @@ -13,7 +14,7 @@ import subprocess import sys import traceback -import functools +import configparser from collections import OrderedDict from copy import deepcopy from datetime import datetime, timedelta @@ -21,17 +22,13 @@ from re import search as re_search from time import sleep -try: - # Imports from python2 - import ConfigParser as configparser -except ImportError: - # Imports from python3 - import configparser from lib.micronet import comm_error from lib.topogen import TopoRouter, get_topogen from lib.topolog import get_logger, logger from lib.topotest import frr_unicode, interface_set_status, version_cmp +from munet.testing.util import pause_test + from lib import topotest FRRCFG_FILE = "frr_json.conf" @@ -1257,143 +1254,6 @@ def add_interfaces_to_vlan(tgen, input_dict): logger.debug("result %s", result) -def tcpdump_capture_start( - tgen, - router, - intf, - protocol=None, - grepstr=None, - timeout=0, - options=None, - cap_file=None, - background=True, -): - """ - API to capture network packets using tcp dump. - - Packages used : - - Parameters - ---------- - * `tgen`: topogen object. - * `router`: router on which ping has to be performed. - * `intf` : interface for capture. - * `protocol` : protocol for which packet needs to be captured. - * `grepstr` : string to filter out tcp dump output. - * `timeout` : Time for which packet needs to be captured. - * `options` : options for TCP dump, all tcpdump options can be used. - * `cap_file` : filename to store capture dump. - * `background` : Make tcp dump run in back ground. - - Usage - ----- - tcpdump_result = tcpdump_dut(tgen, 'r2', intf, protocol='tcp', timeout=20, - options='-A -vv -x > r2bgp.txt ') - Returns - ------- - 1) True for successful capture - 2) errormsg - when tcp dump fails - """ - - logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - - rnode = tgen.gears[router] - - if timeout > 0: - cmd = "timeout {}".format(timeout) - else: - cmd = "" - - cmdargs = "{} tcpdump".format(cmd) - - if intf: - cmdargs += " -i {}".format(str(intf)) - if protocol: - cmdargs += " {}".format(str(protocol)) - if options: - cmdargs += " -s 0 {}".format(str(options)) - - if cap_file: - file_name = os.path.join(tgen.logdir, router, cap_file) - cmdargs += " -w {}".format(str(file_name)) - # Remove existing capture file - rnode.run("rm -rf {}".format(file_name)) - - if grepstr: - cmdargs += ' | grep "{}"'.format(str(grepstr)) - - logger.info("Running tcpdump command: [%s]", cmdargs) - if not background: - rnode.run(cmdargs) - else: - # XXX this & is bogus doesn't work - # rnode.run("nohup {} & /dev/null 2>&1".format(cmdargs)) - rnode.run("nohup {} > /dev/null 2>&1".format(cmdargs)) - - # Check if tcpdump process is running - if background: - result = rnode.run("pgrep tcpdump") - logger.debug("ps -ef | grep tcpdump \n {}".format(result)) - - if not result: - errormsg = "tcpdump is not running {}".format("tcpdump") - return errormsg - else: - logger.info("Packet capture started on %s: interface %s", router, intf) - - logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name)) - return True - - -def tcpdump_capture_stop(tgen, router): - """ - API to capture network packets using tcp dump. - - Packages used : - - Parameters - ---------- - * `tgen`: topogen object. - * `router`: router on which ping has to be performed. - * `intf` : interface for capture. - * `protocol` : protocol for which packet needs to be captured. - * `grepstr` : string to filter out tcp dump output. - * `timeout` : Time for which packet needs to be captured. - * `options` : options for TCP dump, all tcpdump options can be used. - * `cap2file` : filename to store capture dump. - * `bakgrnd` : Make tcp dump run in back ground. - - Usage - ----- - tcpdump_result = tcpdump_dut(tgen, 'r2', intf, protocol='tcp', timeout=20, - options='-A -vv -x > r2bgp.txt ') - Returns - ------- - 1) True for successful capture - 2) errormsg - when tcp dump fails - """ - - logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - - rnode = tgen.gears[router] - - # Check if tcpdump process is running - result = rnode.run("ps -ef | grep tcpdump") - logger.debug("ps -ef | grep tcpdump \n {}".format(result)) - - if not re_search(r"{}".format("tcpdump"), result): - errormsg = "tcpdump is not running {}".format("tcpdump") - return errormsg - else: - # XXX this doesn't work with micronet - ppid = tgen.net.nameToNode[rnode.name].pid - rnode.run("set +m; pkill -P %s tcpdump &> /dev/null" % ppid) - logger.info("Stopped tcpdump capture") - - logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name)) - return True - - def create_debug_log_config(tgen, input_dict, build=False): """ Enable/disable debug logs for any protocol with defined debug @@ -2069,6 +1929,8 @@ def step(msg, reset=False): * ` msg` : Step message body. * `reset` : Reset step count to 1 when set to True. """ + if bool(topotest.g_pytest_config.get_option("--pause")): + pause_test("before :" + msg) _step = Stepper() _step(msg, reset) @@ -3289,233 +3151,6 @@ def configure_interface_mac(tgen, input_dict): return True -def socat_send_mld_join( - tgen, - server, - protocol_option, - mld_groups, - send_from_intf, - send_from_intf_ip=None, - port=12345, - reuseaddr=True, -): - """ - API to send MLD join using SOCAT tool - - Parameters: - ----------- - * `tgen` : Topogen object - * `server`: iperf server, from where IGMP join would be sent - * `protocol_option`: Protocol options, ex: UDP6-RECV - * `mld_groups`: IGMP group for which join has to be sent - * `send_from_intf`: Interface from which join would be sent - * `send_from_intf_ip`: Interface IP, default is None - * `port`: Port to be used, default is 12345 - * `reuseaddr`: True|False, bydefault True - - returns: - -------- - errormsg or True - """ - - logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - - rnode = tgen.routers()[server] - socat_args = "socat -u " - - # UDP4/TCP4/UDP6/UDP6-RECV/UDP6-SEND - if protocol_option: - socat_args += "{}".format(protocol_option) - - if port: - socat_args += ":{},".format(port) - - if reuseaddr: - socat_args += "{},".format("reuseaddr") - - # Group address range to cover - if mld_groups: - if not isinstance(mld_groups, list): - mld_groups = [mld_groups] - - for mld_group in mld_groups: - socat_cmd = socat_args - join_option = "ipv6-join-group" - - if send_from_intf and not send_from_intf_ip: - socat_cmd += "{}='[{}]:{}'".format(join_option, mld_group, send_from_intf) - else: - socat_cmd += "{}='[{}]:{}:[{}]'".format( - join_option, mld_group, send_from_intf, send_from_intf_ip - ) - - socat_cmd += " STDOUT" - - socat_cmd += " &>{}/socat.logs &".format(tgen.logdir) - - # Run socat command to send IGMP join - logger.info("[DUT: {}]: Running command: [{}]".format(server, socat_cmd)) - output = rnode.run("set +m; {} echo $!".format(socat_cmd)) - - # Check if socat join process is running - if output: - pid = output.split()[0] - rnode.run("touch /var/run/frr/socat_join.pid") - rnode.run("echo %s >> /var/run/frr/socat_join.pid" % pid) - else: - errormsg = "Socat join is not sent for {}. Error {}".format( - mld_group, output - ) - logger.error(output) - return errormsg - - logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name)) - return True - - -def socat_send_pim6_traffic( - tgen, - server, - protocol_option, - mld_groups, - send_from_intf, - port=12345, - multicast_hops=True, -): - """ - API to send pim6 data taffic using SOCAT tool - - Parameters: - ----------- - * `tgen` : Topogen object - * `server`: iperf server, from where IGMP join would be sent - * `protocol_option`: Protocol options, ex: UDP6-RECV - * `mld_groups`: MLD group for which join has to be sent - * `send_from_intf`: Interface from which join would be sent - * `port`: Port to be used, default is 12345 - * `multicast_hops`: multicast-hops count, default is 255 - - returns: - -------- - errormsg or True - """ - - logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - - rnode = tgen.routers()[server] - socat_args = "socat -u STDIO " - - # UDP4/TCP4/UDP6/UDP6-RECV/UDP6-SEND - if protocol_option: - socat_args += "'{}".format(protocol_option) - - # Group address range to cover - if mld_groups: - if not isinstance(mld_groups, list): - mld_groups = [mld_groups] - - for mld_group in mld_groups: - socat_cmd = socat_args - if port: - socat_cmd += ":[{}]:{},".format(mld_group, port) - - if send_from_intf: - socat_cmd += "interface={0},so-bindtodevice={0},".format(send_from_intf) - - if multicast_hops: - socat_cmd += "multicast-hops=255'" - - socat_cmd += " >{}/socat.logs &".format(tgen.logdir) - - # Run socat command to send pim6 traffic - logger.info( - "[DUT: {}]: Running command: [set +m; ( while sleep 1; do date; done ) | {}]".format( - server, socat_cmd - ) - ) - - # Open a shell script file and write data to it, which will be - # used to send pim6 traffic continously - traffic_shell_script = "{}/{}/traffic.sh".format(tgen.logdir, server) - with open("{}".format(traffic_shell_script), "w") as taffic_sh: - taffic_sh.write( - "#!/usr/bin/env bash\n( while sleep 1; do date; done ) | {}\n".format( - socat_cmd - ) - ) - - rnode.run("chmod 755 {}".format(traffic_shell_script)) - output = rnode.run("{} &>/dev/null & echo $!".format(traffic_shell_script)) - - # Check if socat traffic process is running - if output: - pid = output.split()[0] - rnode.run("touch /var/run/frr/socat_traffic.pid") - rnode.run("echo %s >> /var/run/frr/socat_traffic.pid" % pid) - - else: - errormsg = "Socat traffic is not sent for {}. Error {}".format( - mld_group, output - ) - logger.error(output) - return errormsg - - logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name)) - return True - - -def kill_socat(tgen, dut=None, action=None): - """ - Killing socat process if running for any router in topology - - Parameters: - ----------- - * `tgen` : Topogen object - * `dut` : Any iperf hostname to send igmp prune - * `action`: to kill mld join using socat - to kill mld traffic using socat - - Usage: - ------ - kill_socat(tgen, dut ="i6", action="remove_mld_join") - - """ - - logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name)) - - router_list = tgen.routers() - for router, rnode in router_list.items(): - if dut is not None and router != dut: - continue - - traffic_shell_script = "{}/{}/traffic.sh".format(tgen.logdir, router) - pid_socat_join = rnode.run("cat /var/run/frr/socat_join.pid") - pid_socat_traffic = rnode.run("cat /var/run/frr/socat_traffic.pid") - if action == "remove_mld_join": - pids = pid_socat_join - elif action == "remove_mld_traffic": - pids = pid_socat_traffic - else: - pids = "\n".join([pid_socat_join, pid_socat_traffic]) - - if os.path.exists(traffic_shell_script): - cmd = ( - "ps -ef | grep %s | awk -F' ' '{print $2}' | xargs kill -9" - % traffic_shell_script - ) - logger.debug("[DUT: {}]: Running command: [{}]".format(router, cmd)) - rnode.run(cmd) - - for pid in pids.split("\n"): - pid = pid.strip() - if pid.isdigit(): - cmd = "set +m; kill -9 %s &> /dev/null" % pid - logger.debug("[DUT: {}]: Running command: [{}]".format(router, cmd)) - rnode.run(cmd) - - logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name)) - - ############################################# # Verification APIs ############################################# diff --git a/tests/topotests/lib/grpc-query.py b/tests/topotests/lib/grpc-query.py index 5dd12d581e..8c4701c243 100755 --- a/tests/topotests/lib/grpc-query.py +++ b/tests/topotests/lib/grpc-query.py @@ -26,7 +26,7 @@ commander.cmd_raises(f"cp {CWD}/../../../grpc/frr-northbound.proto .") commander.cmd_raises( - f"python -m grpc_tools.protoc --python_out=. --grpc_python_out=. -I . frr-northbound.proto" + f"python3 -m grpc_tools.protoc --python_out=. --grpc_python_out=. -I . frr-northbound.proto" ) except Exception as error: logging.error("can't create proto definition modules %s", error) @@ -36,17 +36,6 @@ sys.path[0:0] = "." import frr_northbound_pb2 import frr_northbound_pb2_grpc - - # Would be nice if compiling the modules internally from the source worked - # # import grpc_tools.protoc - # # proto_include = pkg_resources.resource_filename("grpc_tools", "_proto") - # from grpc_tools.protoc import _proto_file_to_module_name, _protos_and_services - # try: - # frr_northbound_pb2, frr_northbound_pb2_grpc = _protos_and_services( - # "frr_northbound.proto" - # ) - # finally: - # os.chdir(CWD) except Exception as error: logging.error("can't import proto definition modules %s", error) raise diff --git a/tests/topotests/lib/mcast-tester.py b/tests/topotests/lib/mcast-tester.py index 8a8251010c..5efbecd5e5 100755 --- a/tests/topotests/lib/mcast-tester.py +++ b/tests/topotests/lib/mcast-tester.py @@ -11,6 +11,7 @@ import argparse import json +import ipaddress import os import socket import struct @@ -35,13 +36,16 @@ def interface_name_to_index(name): def multicast_join(sock, ifindex, group, port): "Joins a multicast group." - mreq = struct.pack( - "=4sLL", socket.inet_aton(args.group), socket.INADDR_ANY, ifindex - ) - sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - sock.bind((group, port)) - sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) + + if ip_version == 4: + mreq = group.packed + struct.pack("@II", socket.INADDR_ANY, ifindex) + opt = socket.IP_ADD_MEMBERSHIP + else: + mreq = group.packed + struct.pack("@I", ifindex) + opt = socket.IPV6_JOIN_GROUP + sock.bind((str(group), port)) + sock.setsockopt(ip_proto, opt, mreq) # @@ -50,15 +54,14 @@ def multicast_join(sock, ifindex, group, port): parser = argparse.ArgumentParser(description="Multicast RX utility") parser.add_argument("group", help="Multicast IP") parser.add_argument("interface", help="Interface name") +parser.add_argument("--port", type=int, default=1000, help="port to send to") +parser.add_argument("--ttl", type=int, default=16, help="TTL/hops for sending packets") parser.add_argument("--socket", help="Point to topotest UNIX socket") parser.add_argument( "--send", help="Transmit instead of join with interval", type=float, default=0 ) args = parser.parse_args() -ttl = 16 -port = 1000 - # Get interface index/validate. ifindex = interface_name_to_index(args.interface) if ifindex is None: @@ -85,7 +88,12 @@ def multicast_join(sock, ifindex, group, port): # Set topotest socket non blocking so we can multiplex the main loop. toposock.setblocking(False) -msock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +args.group = ipaddress.ip_address(args.group) +ip_version = args.group.version +ip_family = socket.AF_INET if ip_version == 4 else socket.AF_INET6 +ip_proto = socket.IPPROTO_IP if ip_version == 4 else socket.IPPROTO_IPV6 + +msock = socket.socket(ip_family, socket.SOCK_DGRAM, socket.IPPROTO_UDP) if args.send > 0: # Prepare multicast bit in that interface. msock.setsockopt( @@ -93,12 +101,18 @@ def multicast_join(sock, ifindex, group, port): 25, struct.pack("%ds" % len(args.interface), args.interface.encode("utf-8")), ) - # Set packets TTL. - msock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, struct.pack("b", ttl)) + + # Set packets TTL/hops. + ttlopt = socket.IP_MULTICAST_TTL if ip_version == 4 else socket.IPV6_MULTICAST_HOPS + if ip_version == 4: + msock.setsockopt(ip_proto, ttlopt, struct.pack("B", args.ttl)) + else: + msock.setsockopt(ip_proto, ttlopt, struct.pack("I", args.ttl)) + # Block to ensure packet send. msock.setblocking(True) else: - multicast_join(msock, ifindex, args.group, port) + multicast_join(msock, ifindex, args.group, args.port) def should_exit(): @@ -120,7 +134,7 @@ def should_exit(): counter = 0 while not should_exit(): if args.send > 0: - msock.sendto(b"test %d" % counter, (args.group, port)) + msock.sendto(b"test %d" % counter, (str(args.group), args.port)) counter += 1 time.sleep(args.send) diff --git a/tests/topotests/lib/micronet_compat.py b/tests/topotests/lib/micronet_compat.py index d648a120ab..b348c85988 100644 --- a/tests/topotests/lib/micronet_compat.py +++ b/tests/topotests/lib/micronet_compat.py @@ -121,7 +121,7 @@ class Mininet(BaseMunet): g_mnet_inst = None - def __init__(self, rundir=None, pytestconfig=None): + def __init__(self, rundir=None, pytestconfig=None, logger=None): """ Create a Micronet. """ @@ -140,7 +140,7 @@ def __init__(self, rundir=None, pytestconfig=None): # os.umask(0) super(Mininet, self).__init__( - pid=False, rundir=rundir, pytestconfig=pytestconfig + pid=False, rundir=rundir, pytestconfig=pytestconfig, logger=logger ) # From munet/munet/native.py diff --git a/tests/topotests/lib/ospf.py b/tests/topotests/lib/ospf.py index 5486e904df..5b18f8b679 100644 --- a/tests/topotests/lib/ospf.py +++ b/tests/topotests/lib/ospf.py @@ -426,6 +426,10 @@ def config_ospf_interface( cmd = "ip ospf authentication null" elif data_ospf_auth == "message-digest": cmd = "ip ospf authentication message-digest" + elif data_ospf_auth == "key-chain": + cmd = "ip ospf authentication key-chain {}".format( + ospf_data["keychain"] + ) else: cmd = "ip ospf authentication" diff --git a/tests/topotests/lib/pim.py b/tests/topotests/lib/pim.py index e26bdb3af3..f7440efd6d 100644 --- a/tests/topotests/lib/pim.py +++ b/tests/topotests/lib/pim.py @@ -1,35 +1,35 @@ +# -*- coding: utf-8 eval: (blacken-mode 1) -*- # SPDX-License-Identifier: ISC # Copyright (c) 2019 by VMware, Inc. ("VMware") # Used Copyright (c) 2018 by Network Device Education Foundation, Inc. # ("NetDEF") in this file. import datetime +import functools import os import re import sys import traceback -import functools from copy import deepcopy from time import sleep -from lib import topotest - # Import common_config to use commomnly used APIs from lib.common_config import ( - create_common_configurations, HostApplicationHelper, InvalidCLIError, create_common_configuration, - InvalidCLIError, + create_common_configurations, + get_frr_ipv6_linklocal, retry, run_frr_cmd, validate_ip_address, - get_frr_ipv6_linklocal, ) from lib.micronet import get_exec_path from lib.topolog import logger from lib.topotest import frr_unicode +from lib import topotest + #### CWD = os.path.dirname(os.path.realpath(__file__)) @@ -1132,7 +1132,7 @@ def verify_upstream_iif( grp_addr, in_interface, group_addr_json[src_address]["inboundInterface"], - joinState, + "Joined", group_addr_json[src_address]["joinState"], ) ) diff --git a/tests/topotests/lib/snmptest.py b/tests/topotests/lib/snmptest.py index e7cd657b20..bb7c0787c1 100644 --- a/tests/topotests/lib/snmptest.py +++ b/tests/topotests/lib/snmptest.py @@ -18,6 +18,7 @@ """ from lib.topolog import logger +import re class SnmpTester(object): @@ -72,16 +73,6 @@ def _get_snmp_oid(snmp_output): # third token onwards is the value of the object return tokens[0].split(".", 1)[1] - @staticmethod - def _get_snmp_oid(snmp_output): - tokens = snmp_output.strip().split() - - # if len(tokens) > 5: - # return None - - # third token is the value of the object - return tokens[0].split(".", 1)[1] - def _parse_multiline(self, snmp_output): results = snmp_output.strip().split("\n") @@ -116,6 +107,149 @@ def walk(self, oid): result = self.router.cmd(cmd) return self._parse_multiline(result) + def parse_notif_ipv4(self, notif): + # normalise values + notif = re.sub(":", "", notif) + notif = re.sub('"([0-9]{2}) ([0-9]{2}) "', r"\1\2", notif) + notif = re.sub('"([0-9]{2}) "', r"\1", notif) + elems = re.findall(r"([0-9,\.]+) = ([0-9,\.]+)", notif) + + # remove common part + elems = elems[1:] + return elems + + def is_notif_bgp4_valid(self, output_list, address): + oid_notif_type = ".1.3.6.1.6.3.1.1.4.1.0" + peer_notif_established = ".1.3.6.1.2.1.15.0.1" + peer_notif_backward = ".1.3.6.1.2.1.15.0.2" + oid_peer_last_error = ".1.3.6.1.2.1.15.3.1.14" + oid_peer_remote_addr = ".1.3.6.1.2.1.15.3.1.7" + oid_peer_state = ".1.3.6.1.2.1.15.3.1.2" + + nb_notif = len(output_list) + for nb in range(0, nb_notif - 1): + # identify type of notification + # established or BackwardTransition + + if output_list[nb][0][0] != "{}".format(oid_notif_type): + return False + + if output_list[nb][0][1] == "{}".format(peer_notif_established): + logger.info("Established notification") + elif output_list[nb][0][1] == "{}".format(peer_notif_backward): + logger.info("Backward transition notification") + else: + return False + + # same behavior for 2 notification type in bgp4 + if output_list[nb][1][0] != "{}.{}".format(oid_peer_remote_addr, address): + return False + + if output_list[nb][2][0] != "{}.{}".format(oid_peer_last_error, address): + return False + if output_list[nb][3][0] != "{}.{}".format(oid_peer_state, address): + return False + + return True + + def is_notif_bgp4v2_valid(self, output_list, address, type_requested): + oid_notif_type = ".1.3.6.1.6.3.1.1.4.1.0" + peer_notif_established = ".1.3.6.1.3.5.1.0.1" + peer_notif_backward = ".1.3.6.1.3.5.1.0.2" + oid_peer_state = ".1.3.6.1.3.5.1.1.2.1.13" + oid_peer_local_port = ".1.3.6.1.3.5.1.1.2.1.6" + oid_peer_remote_port = ".1.3.6.1.3.5.1.1.2.1.9" + oid_peer_err_code_recv = ".1.3.6.1.3.5.1.1.3.1.1" + oid_peer_err_sub_code_recv = ".1.3.6.1.3.5.1.1.3.1.2" + oid_peer_err_recv_text = ".1.3.6.1.3.5.1.1.3.1.4" + + nb_notif = len(output_list) + for nb in range(nb_notif): + if output_list[nb][0][0] != "{}".format(oid_notif_type): + return False + + if output_list[nb][0][1] == "{}".format(peer_notif_established): + logger.info("Established notification") + notif_type = "Estab" + + elif output_list[nb][0][1] == "{}".format(peer_notif_backward): + logger.info("Backward transition notification") + notif_type = "Backward" + else: + return False + + if notif_type != type_requested: + continue + + if output_list[nb][1][0] != "{}.1.{}".format(oid_peer_state, address): + continue + + if output_list[nb][2][0] != "{}.1.{}".format(oid_peer_local_port, address): + return False + + if output_list[nb][3][0] != "{}.1.{}".format(oid_peer_remote_port, address): + return False + + if notif_type == "Estab": + return True + + if output_list[nb][4][0] != "{}.1.{}".format( + oid_peer_err_code_recv, address + ): + return False + + if output_list[nb][5][0] != "{}.1.{}".format( + oid_peer_err_sub_code_recv, address + ): + return False + + if output_list[nb][6][0] != "{}.1.{}".format( + oid_peer_err_recv_text, address + ): + return False + + return True + + return False + + def get_notif_bgp4(self, output_file): + notif_list = [] + whitecleanfile = re.sub("\t", " ", output_file) + results = whitecleanfile.strip().split("\n") + + # don't consider SNMP additional messages + notifs_first = [elem for elem in results if not ("SNMP" in elem)] + # don't consider additional application messages + notifs = [elem for index, elem in enumerate(notifs_first) if index % 2 != 0] + + oid_v4 = r"1\.3\.6\.1\.2\.1\.15" + for one_notif in notifs: + is_ipv4_notif = re.search(oid_v4, one_notif) + if is_ipv4_notif != None: + formated_notif = self.parse_notif_ipv4(one_notif) + notif_list.append(formated_notif) + + return notif_list + + def get_notif_bgp4v2(self, output_file): + notif_list = [] + whitecleanfile = re.sub("\t", " ", output_file) + results = whitecleanfile.strip().split("\n") + + # don't consider SNMP additional messages + notifs_first = [elem for elem in results if not ("SNMP" in elem)] + # don't consider additional application messages + notifs = [elem for index, elem in enumerate(results) if index % 2 != 0] + + oid_v6 = r"1\.3\.6\.1\.3\.5\.1" + for one_notif in notifs: + is_ipv6_notif = re.search(oid_v6, one_notif) + if is_ipv6_notif != None: + formated_notif = self.parse_notif_ipv4(one_notif) + notif_list.append(formated_notif) + + return notif_list + def test_oid(self, oid, value): print("oid: {}".format(self.get_next(oid))) return self.get_next(oid) == value diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index 0e685a97b0..7b06f3d127 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -81,20 +81,20 @@ def is_string(value): def get_exabgp_cmd(commander=None): - """Return the command to use for ExaBGP version < 4.""" + """Return the command to use for ExaBGP version >= 4.2.11""" if commander is None: - commander = Commander("topogen") + commander = Commander("exabgp", logger=logging.getLogger("exabgp")) def exacmd_version_ok(exacmd): - logger.debug("checking %s for exabgp < version 4", exacmd) + logger.debug("checking %s for exabgp version >= 4.2.11", exacmd) _, stdout, _ = commander.cmd_status(exacmd + " -v", warn=False) m = re.search(r"ExaBGP\s*:\s*((\d+)\.(\d+)(?:\.(\d+))?)", stdout) if not m: return False version = m.group(1) - if topotest.version_cmp(version, "4") >= 0: - logging.debug("found exabgp version >= 4 in %s will keep looking", exacmd) + if topotest.version_cmp(version, "4.2.11") < 0: + logging.debug("found exabgp version < 4.2.11 in %s will keep looking", exacmd) return False logger.info("Using ExaBGP version %s in %s", version, exacmd) return True @@ -102,14 +102,14 @@ def exacmd_version_ok(exacmd): exacmd = commander.get_exec_path("exabgp") if exacmd and exacmd_version_ok(exacmd): return exacmd - py2_path = commander.get_exec_path("python2") - if py2_path: - exacmd = py2_path + " -m exabgp" + py3_path = commander.get_exec_path("python3") + if py3_path: + exacmd = py3_path + " -m exabgp" if exacmd_version_ok(exacmd): return exacmd - py2_path = commander.get_exec_path("python") - if py2_path: - exacmd = py2_path + " -m exabgp" + py3_path = commander.get_exec_path("python") + if py3_path: + exacmd = py3_path + " -m exabgp" if exacmd_version_ok(exacmd): return exacmd return None @@ -209,7 +209,11 @@ def _init_topo(self, topodef): # Mininet(Micronet) to build the actual topology. assert not inspect.isclass(topodef) - self.net = Mininet(rundir=self.logdir, pytestconfig=topotest.g_pytest_config) + self.net = Mininet( + rundir=self.logdir, + pytestconfig=topotest.g_pytest_config, + logger=topolog.get_logger("mu", log_level="debug"), + ) # Adjust the parent namespace topotest.fix_netns_limits(self.net) @@ -359,6 +363,15 @@ def add_host(self, name, ip, defaultRoute): self.peern += 1 return self.gears[name] + def add_bmp_server(self, name, ip, defaultRoute, port=1789): + """Add the bmp collector gear""" + if name in self.gears: + raise KeyError("The bmp server already exists") + + self.gears[name] = TopoBMPCollector( + self, name, ip=ip, defaultRoute=defaultRoute, port=port + ) + def add_link(self, node1, node2, ifname1=None, ifname2=None): """ Creates a connection between node1 and node2. The nodes can be the @@ -421,6 +434,13 @@ def exabgp_peers(self): """ return self.get_gears(TopoExaBGP) + def get_bmp_servers(self): + """ + Retruns the bmp servers dictionnary (the key is the bmp server the + value is the bmp server object itself). + """ + return self.get_gears(TopoBMPCollector) + def start_topology(self): """Starts the topology class.""" logger.info("starting topology: {}".format(self.modname)) @@ -724,6 +744,7 @@ class TopoRouter(TopoGear): RD_SNMP = 18 RD_PIM6 = 19 RD_MGMTD = 20 + RD_TRAP = 21 RD = { RD_FRR: "frr", RD_ZEBRA: "zebra", @@ -746,6 +767,7 @@ class TopoRouter(TopoGear): RD_PATH: "pathd", RD_SNMP: "snmpd", RD_MGMTD: "mgmtd", + RD_TRAP: "snmptrapd", } def __init__(self, tgen, cls, name, **params): @@ -822,7 +844,7 @@ def load_config(self, daemon, source=None, param=None): TopoRouter.RD_RIPNG, TopoRouter.RD_OSPF, TopoRouter.RD_OSPF6, TopoRouter.RD_ISIS, TopoRouter.RD_BGP, TopoRouter.RD_LDP, TopoRouter.RD_PIM, TopoRouter.RD_PIM6, TopoRouter.RD_PBR, - TopoRouter.RD_SNMP, TopoRouter.RD_MGMTD. + TopoRouter.RD_SNMP, TopoRouter.RD_MGMTD, TopoRouter.RD_TRAP. Possible `source` values are `None` for an empty config file, a path name which is used directly, or a file name with no path components which is first looked for @@ -860,7 +882,7 @@ def start(self): # Enable all daemon command logging, logging files # and set them to the start dir. for daemon, enabled in nrouter.daemons.items(): - if enabled and daemon != "snmpd": + if enabled and daemon != "snmpd" and daemon != "snmptrapd": self.vtysh_cmd( "\n".join( [ @@ -1090,8 +1112,9 @@ class TopoSwitch(TopoGear): # pylint: disable=too-few-public-methods def __init__(self, tgen, name, **params): + logger = topolog.get_logger(name, log_level="debug") super(TopoSwitch, self).__init__(tgen, name, **params) - tgen.net.add_switch(name) + tgen.net.add_switch(name, logger=logger) def __str__(self): gear = super(TopoSwitch, self).__str__() @@ -1175,7 +1198,7 @@ def start(self, peer_dir, env_file=None): * Run ExaBGP with env file `env_file` and configuration peer*/exabgp.cfg """ exacmd = self.tgen.get_exabgp_cmd() - assert exacmd, "Can't find a usabel ExaBGP (must be < version 4)" + assert exacmd, "Can't find a usable ExaBGP (must be version >= 4.2.11)" self.run("mkdir -p /etc/exabgp") self.run("chmod 755 /etc/exabgp") @@ -1186,8 +1209,22 @@ def start(self, peer_dir, env_file=None): self.run("chmod 644 /etc/exabgp/*") self.run("chmod a+x /etc/exabgp/*.py") self.run("chown -R exabgp:exabgp /etc/exabgp") + self.run("[ -p /var/run/exabgp.in ] || mkfifo /var/run/exabgp.in") + self.run("[ -p /var/run/exabgp.out ] || mkfifo /var/run/exabgp.out") + self.run("chown exabgp:exabgp /var/run/exabgp.{in,out}") + self.run("chmod 600 /var/run/exabgp.{in,out}") + + log_dir = os.path.join(self.logdir, self.name) + self.run("chmod 777 {}".format(log_dir)) + + log_file = os.path.join(log_dir, "exabgp.log") + + env_cmd = "env exabgp.log.level=INFO " + env_cmd += "exabgp.log.destination={} ".format(log_file) - output = self.run(exacmd + " -e /etc/exabgp/exabgp.env /etc/exabgp/exabgp.cfg") + output = self.run( + env_cmd + exacmd + " -e /etc/exabgp/exabgp.env /etc/exabgp/exabgp.cfg " + ) if output is None or len(output) == 0: output = "<none>" @@ -1199,6 +1236,33 @@ def stop(self, wait=True, assertOnError=True): return "" +class TopoBMPCollector(TopoHost): + PRIVATE_DIRS = [ + "/var/log", + ] + + def __init__(self, tgen, name, **params): + params["private_mounts"] = self.PRIVATE_DIRS + self.port = params["port"] + self.ip = params["ip"] + super(TopoBMPCollector, self).__init__(tgen, name, **params) + + def __str__(self): + gear = super(TopoBMPCollector, self).__str__() + gear += " TopoBMPCollector<>".format() + return gear + + def start(self): + self.run( + "{}/bmp_collector/bmpserver -a {} -p {}&".format(CWD, self.ip, self.port), + stdout=None, + ) + + def stop(self): + self.run("pkill -9 -f bmpserver") + return "" + + # # Diagnostic function # @@ -1321,7 +1385,7 @@ def diagnose_env_linux(rundir): logger.info("LDPd tests will not run (missing mpls-iptunnel kernel module)") if not get_exabgp_cmd(): - logger.warning("Failed to find exabgp < 4") + logger.warning("Failed to find exabgp >= 4.2.11") logger.removeHandler(fhandler) fhandler.close() diff --git a/tests/topotests/lib/topolog.py b/tests/topotests/lib/topolog.py index b501670789..aceb2cb031 100644 --- a/tests/topotests/lib/topolog.py +++ b/tests/topotests/lib/topolog.py @@ -15,13 +15,6 @@ import logging import os -import subprocess -import sys - -if sys.version_info[0] > 2: - pass -else: - pass try: from xdist import is_xdist_controller @@ -31,8 +24,6 @@ def is_xdist_controller(): return False -BASENAME = "topolog" - # Helper dictionary to convert Topogen logging levels to Python's logging. DEBUG_TOPO2LOGGING = { "debug": logging.DEBUG, @@ -42,13 +33,43 @@ def is_xdist_controller(): "error": logging.ERROR, "critical": logging.CRITICAL, } -FORMAT = "%(asctime)s.%(msecs)03d %(levelname)s: %(name)s: %(message)s" +FORMAT = "%(asctime)s %(levelname)s: %(name)s: %(message)s" handlers = {} -logger = logging.getLogger("topolog") +logger = logging.getLogger("topo") + + +# Remove this and use munet version when we move to pytest_asyncio +def get_test_logdir(nodeid=None, module=False): + """Get log directory relative pathname.""" + xdist_worker = os.getenv("PYTEST_XDIST_WORKER", "") + mode = os.getenv("PYTEST_XDIST_MODE", "no") + + # nodeid: all_protocol_startup/test_all_protocol_startup.py::test_router_running + # may be missing "::testname" if module is True + if not nodeid: + nodeid = os.environ["PYTEST_CURRENT_TEST"].split(" ")[0] + + cur_test = nodeid.replace("[", "_").replace("]", "_") + if module: + idx = cur_test.rfind("::") + path = cur_test if idx == -1 else cur_test[:idx] + testname = "" + else: + path, testname = cur_test.split("::") + testname = testname.replace("/", ".") + path = path[:-3].replace("/", ".") + # We use different logdir paths based on how xdist is running. + if mode == "each": + if module: + return os.path.join(path, "worker-logs", xdist_worker) + return os.path.join(path, testname, xdist_worker) + assert mode in ("no", "load", "loadfile", "loadscope"), f"Unknown dist mode {mode}" + return path if module else os.path.join(path, testname) -def set_handler(l, target=None): + +def set_handler(lg, target=None): if target is None: h = logging.NullHandler() else: @@ -59,106 +80,81 @@ def set_handler(l, target=None): h.setFormatter(logging.Formatter(fmt=FORMAT)) # Don't filter anything at the handler level h.setLevel(logging.DEBUG) - l.addHandler(h) + lg.addHandler(h) return h -def set_log_level(l, level): +def set_log_level(lg, level): "Set the logging level." # Messages sent to this logger only are created if this level or above. log_level = DEBUG_TOPO2LOGGING.get(level, level) - l.setLevel(log_level) + lg.setLevel(log_level) -def get_logger(name, log_level=None, target=None): - l = logging.getLogger("{}.{}".format(BASENAME, name)) +def reset_logger(lg): + while lg.handlers: + x = lg.handlers.pop() + x.close() + lg.removeHandler(x) - if log_level is not None: - set_log_level(l, log_level) - if target is not None: - set_handler(l, target) - - return l - - -# nodeid: all_protocol_startup/test_all_protocol_startup.py::test_router_running - - -def get_test_logdir(nodeid=None): - """Get log directory relative pathname.""" - xdist_worker = os.getenv("PYTEST_XDIST_WORKER", "") - mode = os.getenv("PYTEST_XDIST_MODE", "no") +def get_logger(name, log_level=None, target=None, reset=True): + lg = logging.getLogger(name) - if not nodeid: - nodeid = os.environ["PYTEST_CURRENT_TEST"].split(" ")[0] + if reset: + reset_logger(lg) - cur_test = nodeid.replace("[", "_").replace("]", "_") - path, testname = cur_test.split("::") - path = path[:-3].replace("/", ".") + if log_level is not None: + set_log_level(lg, log_level) - # We use different logdir paths based on how xdist is running. - if mode == "each": - return os.path.join(path, testname, xdist_worker) - elif mode == "load": - return os.path.join(path, testname) - else: - assert ( - mode == "no" or mode == "loadfile" or mode == "loadscope" - ), "Unknown dist mode {}".format(mode) + if target is not None: + set_handler(lg, target) - return path + return lg -def logstart(nodeid, location, rundir): +def logstart(nodeid, logpath): """Called from pytest before module setup.""" - - mode = os.getenv("PYTEST_XDIST_MODE", "no") worker = os.getenv("PYTEST_TOPOTEST_WORKER", "") + wstr = f" on worker {worker}" if worker else "" + handler_id = nodeid + worker + logpath = logpath.absolute() - # We only per-test log in the workers (or non-dist) - if not worker and mode != "no": - return + logging.debug("logstart: adding logging for %s%s at %s", nodeid, wstr, logpath) + root_logger = logging.getLogger() + handler = logging.FileHandler(logpath, mode="w") + handler.setFormatter(logging.Formatter(FORMAT)) - handler_id = nodeid + worker - assert handler_id not in handlers - - rel_log_dir = get_test_logdir(nodeid) - exec_log_dir = os.path.join(rundir, rel_log_dir) - subprocess.check_call( - "mkdir -p {0} && chmod 1777 {0}".format(exec_log_dir), shell=True - ) - exec_log_path = os.path.join(exec_log_dir, "exec.log") - - # Add test based exec log handler - h = set_handler(logger, exec_log_path) - handlers[handler_id] = h - - if worker: - logger.info( - "Logging on worker %s for %s into %s", worker, handler_id, exec_log_path - ) - else: - logger.info("Logging for %s into %s", handler_id, exec_log_path) + root_logger.addHandler(handler) + handlers[handler_id] = handler + logging.debug("logstart: added logging for %s%s at %s", nodeid, wstr, logpath) + return handler -def logfinish(nodeid, location): - """Called from pytest after module teardown.""" - # This function may not be called if pytest is interrupted. +def logfinish(nodeid, logpath): + """Called from pytest after module teardown.""" worker = os.getenv("PYTEST_TOPOTEST_WORKER", "") - handler_id = nodeid + worker + wstr = f" on worker {worker}" if worker else "" + + root_logger = logging.getLogger() - if handler_id in handlers: - # Remove test based exec log handler - if worker: - logger.info("Closing logs for %s", handler_id) + handler_id = nodeid + worker + if handler_id not in handlers: + logging.critical("can't find log handler to remove") + else: + logging.debug( + "logfinish: removing logging for %s%s at %s", nodeid, wstr, logpath + ) h = handlers[handler_id] - logger.removeHandler(handlers[handler_id]) + root_logger.removeHandler(h) h.flush() h.close() del handlers[handler_id] + logging.debug( + "logfinish: removed logging for %s%s at %s", nodeid, wstr, logpath + ) console_handler = set_handler(logger, None) diff --git a/tests/topotests/lib/topotest.py b/tests/topotests/lib/topotest.py index 0e96921b7f..2bb892355e 100644 --- a/tests/topotests/lib/topotest.py +++ b/tests/topotests/lib/topotest.py @@ -24,13 +24,15 @@ import sys import tempfile import time +import logging from collections.abc import Mapping from copy import deepcopy import lib.topolog as topolog from lib.micronet_compat import Node from lib.topolog import logger -from munet.base import Timeout +from munet.base import commander, get_exec_path_host, Timeout +from munet.testing.util import retry from lib import micronet @@ -38,38 +40,94 @@ def get_logs_path(rundir): - logspath = topolog.get_test_logdir() + logspath = topolog.get_test_logdir(module=True) return os.path.join(rundir, logspath) def gdb_core(obj, daemon, corefiles): - gdbcmds = """ - info threads - bt full - disassemble - up - disassemble - up - disassemble - up - disassemble - up - disassemble - up - disassemble + gdbcmds = r""" +set print elements 1024 +echo -------\n +echo threads\n +echo -------\n +info threads +echo ---------\n +echo registers\n +echo ---------\n +info registers +echo ---------\n +echo backtrace\n +echo ---------\n +bt """ gdbcmds = [["-ex", i.strip()] for i in gdbcmds.strip().split("\n")] gdbcmds = [item for sl in gdbcmds for item in sl] daemon_path = os.path.join(obj.daemondir, daemon) - backtrace = subprocess.check_output( - ["gdb", daemon_path, corefiles[0], "--batch"] + gdbcmds + p = subprocess.run( + ["gdb", daemon_path, corefiles[0], "--batch"] + gdbcmds, + encoding="utf-8", + errors="ignore", + capture_output=True, ) + backtrace = p.stdout + + # + # Grab the disassemble of top couple frames + # + m = re.search(r"#(\d+) .*assert.*", backtrace) + if not m: + m = re.search(r"#(\d+) .*abort.*", backtrace) + frames = re.findall(r"\n#(\d+) ", backtrace) + if m: + frstart = -1 + astart = int(m.group(1)) + 1 + ocount = f"-{int(frames[-1]) - astart + 1}" + else: + astart = -1 + frstart = 0 + ocount = "" + m = re.search(r"#(\d+) .*core_handler.*", backtrace) + if m: + frstart = int(m.group(1)) + 2 + ocount = f"-{int(frames[-1]) - frstart + 1}" + sys.stderr.write( - "\n%s: %s crashed. Core file found - Backtrace follows:\n" % (obj.name, daemon) + f"\nCORE FOUND: {obj.name}: {daemon} crashed: see log for backtrace and more\n" ) - sys.stderr.write("%s" % backtrace) - return backtrace + + gdbcmds = rf""" +set print elements 1024 +echo -------------------------\n +echo backtrace with local args\n +echo -------------------------\n +bt full {ocount} +""" + if frstart >= 0: + gdbcmds += rf"""echo ---------------------------------------\n +echo disassemble of failing funciton (guess)\n +echo ---------------------------------------\n +fr {frstart} +disassemble /m +""" + + gdbcmds = [["-ex", i.strip()] for i in gdbcmds.strip().split("\n")] + gdbcmds = [item for sl in gdbcmds for item in sl] + + daemon_path = os.path.join(obj.daemondir, daemon) + p = subprocess.run( + ["gdb", daemon_path, corefiles[0], "-q", "--batch"] + gdbcmds, + encoding="utf-8", + errors="ignore", + capture_output=True, + ) + btdump = p.stdout + + # sys.stderr.write( + # "\n%s: %s crashed. Core file found - Backtrace follows:\n" % (obj.name, daemon) + # ) + + return backtrace + btdump class json_cmp_result(object): @@ -97,7 +155,7 @@ def __str__(self): ) -def gen_json_diff_report(d1, d2, exact=False, path="> $", acc=(0, "")): +def gen_json_diff_report(output, expected, exact=False, path="> $", acc=(0, "")): """ Internal workhorse which compares two JSON data structures and generates an error report suited to be read by a human eye. """ @@ -145,60 +203,62 @@ def add_key(key): def has_errors(other_acc): return other_acc[0] > 0 - if d2 == "*" or ( - not isinstance(d1, (list, dict)) - and not isinstance(d2, (list, dict)) - and d1 == d2 + if expected == "*" or ( + not isinstance(output, (list, dict)) + and not isinstance(expected, (list, dict)) + and output == expected ): return acc elif ( - not isinstance(d1, (list, dict)) - and not isinstance(d2, (list, dict)) - and d1 != d2 + not isinstance(output, (list, dict)) + and not isinstance(expected, (list, dict)) + and output != expected ): acc = add_error( acc, - "d1 has element with value '{}' but in d2 it has value '{}'".format(d1, d2), + "output has element with value '{}' but in expected it has value '{}'".format( + output, expected + ), ) elif ( - isinstance(d1, list) - and isinstance(d2, list) - and ((len(d2) > 0 and d2[0] == "__ordered__") or exact) + isinstance(output, list) + and isinstance(expected, list) + and ((len(expected) > 0 and expected[0] == "__ordered__") or exact) ): if not exact: - del d2[0] - if len(d1) != len(d2): + del expected[0] + if len(output) != len(expected): acc = add_error( acc, - "d1 has Array of length {} but in d2 it is of length {}".format( - len(d1), len(d2) + "output has Array of length {} but in expected it is of length {}".format( + len(output), len(expected) ), ) else: - for idx, v1, v2 in zip(range(0, len(d1)), d1, d2): + for idx, v1, v2 in zip(range(0, len(output)), output, expected): acc = merge_errors( acc, gen_json_diff_report(v1, v2, exact=exact, path=add_idx(idx)) ) - elif isinstance(d1, list) and isinstance(d2, list): - if len(d1) < len(d2): + elif isinstance(output, list) and isinstance(expected, list): + if len(output) < len(expected): acc = add_error( acc, - "d1 has Array of length {} but in d2 it is of length {}".format( - len(d1), len(d2) + "output has Array of length {} but in expected it is of length {}".format( + len(output), len(expected) ), ) else: - for idx2, v2 in zip(range(0, len(d2)), d2): + for idx2, v2 in zip(range(0, len(expected)), expected): found_match = False closest_diff = None closest_idx = None - for idx1, v1 in zip(range(0, len(d1)), d1): + for idx1, v1 in zip(range(0, len(output)), output): tmp_v1 = deepcopy(v1) tmp_v2 = deepcopy(v2) tmp_diff = gen_json_diff_report(tmp_v1, tmp_v2, path=add_idx(idx1)) if not has_errors(tmp_diff): found_match = True - del d1[idx1] + del output[idx1] break elif not closest_diff or get_errors_n(tmp_diff) < get_errors_n( closest_diff @@ -212,50 +272,62 @@ def has_errors(other_acc): acc = add_error( acc, ( - "d2 has the following element at index {} which is not present in d1: " - + "\n\n{}\n\n\tClosest match in d1 is at index {} with the following errors: {}" + "expected has the following element at index {} which is not present in output: " + + "\n\n{}\n\n\tClosest match in output is at index {} with the following errors: {}" ).format(idx2, dump_json(v2), closest_idx, sub_error), ) if not found_match and not isinstance(v2, (list, dict)): acc = add_error( acc, - "d2 has the following element at index {} which is not present in d1: {}".format( + "expected has the following element at index {} which is not present in output: {}".format( idx2, dump_json(v2) ), ) - elif isinstance(d1, dict) and isinstance(d2, dict) and exact: - invalid_keys_d1 = [k for k in d1.keys() if k not in d2.keys()] - invalid_keys_d2 = [k for k in d2.keys() if k not in d1.keys()] + elif isinstance(output, dict) and isinstance(expected, dict) and exact: + invalid_keys_d1 = [k for k in output.keys() if k not in expected.keys()] + invalid_keys_d2 = [k for k in expected.keys() if k not in output.keys()] for k in invalid_keys_d1: - acc = add_error(acc, "d1 has key '{}' which is not present in d2".format(k)) + acc = add_error( + acc, "output has key '{}' which is not present in expected".format(k) + ) for k in invalid_keys_d2: - acc = add_error(acc, "d2 has key '{}' which is not present in d1".format(k)) - valid_keys_intersection = [k for k in d1.keys() if k in d2.keys()] + acc = add_error( + acc, "expected has key '{}' which is not present in output".format(k) + ) + valid_keys_intersection = [k for k in output.keys() if k in expected.keys()] for k in valid_keys_intersection: acc = merge_errors( - acc, gen_json_diff_report(d1[k], d2[k], exact=exact, path=add_key(k)) + acc, + gen_json_diff_report( + output[k], expected[k], exact=exact, path=add_key(k) + ), ) - elif isinstance(d1, dict) and isinstance(d2, dict): - none_keys = [k for k, v in d2.items() if v == None] - none_keys_present = [k for k in d1.keys() if k in none_keys] + elif isinstance(output, dict) and isinstance(expected, dict): + none_keys = [k for k, v in expected.items() if v == None] + none_keys_present = [k for k in output.keys() if k in none_keys] for k in none_keys_present: acc = add_error( - acc, "d1 has key '{}' which is not supposed to be present".format(k) + acc, "output has key '{}' which is not supposed to be present".format(k) ) - keys = [k for k, v in d2.items() if v != None] - invalid_keys_intersection = [k for k in keys if k not in d1.keys()] + keys = [k for k, v in expected.items() if v != None] + invalid_keys_intersection = [k for k in keys if k not in output.keys()] for k in invalid_keys_intersection: - acc = add_error(acc, "d2 has key '{}' which is not present in d1".format(k)) - valid_keys_intersection = [k for k in keys if k in d1.keys()] + acc = add_error( + acc, "expected has key '{}' which is not present in output".format(k) + ) + valid_keys_intersection = [k for k in keys if k in output.keys()] for k in valid_keys_intersection: acc = merge_errors( - acc, gen_json_diff_report(d1[k], d2[k], exact=exact, path=add_key(k)) + acc, + gen_json_diff_report( + output[k], expected[k], exact=exact, path=add_key(k) + ), ) else: acc = add_error( acc, - "d1 has element of type '{}' but the corresponding element in d2 is of type '{}'".format( - json_type(d1), json_type(d2) + "output has element of type '{}' but the corresponding element in expected is of type '{}'".format( + json_type(output), json_type(expected) ), points=2, ) @@ -263,29 +335,31 @@ def has_errors(other_acc): return acc -def json_cmp(d1, d2, exact=False): +def json_cmp(output, expected, exact=False): """ JSON compare function. Receives two parameters: - * `d1`: parsed JSON data structure - * `d2`: parsed JSON data structure + * `output`: parsed JSON data structure from outputed vtysh command + * `expected``: parsed JSON data structure from what is expected to be seen - Returns 'None' when all JSON Object keys and all Array elements of d2 have a match - in d1, i.e., when d2 is a "subset" of d1 without honoring any order. Otherwise an + Returns 'None' when all JSON Object keys and all Array elements of expected have a match + in output, i.e., when expected is a "subset" of output without honoring any order. Otherwise an error report is generated and wrapped in a 'json_cmp_result()'. There are special parameters and notations explained below which can be used to cover rather unusual cases: - * when 'exact is set to 'True' then d1 and d2 are tested for equality (including + * when 'exact is set to 'True' then output and expected are tested for equality (including order within JSON Arrays) * using 'null' (or 'None' in Python) as JSON Object value is checking for key - absence in d1 - * using '*' as JSON Object value or Array value is checking for presence in d1 + absence in output + * using '*' as JSON Object value or Array value is checking for presence in output without checking the values - * using '__ordered__' as first element in a JSON Array in d2 will also check the - order when it is compared to an Array in d1 + * using '__ordered__' as first element in a JSON Array in expected will also check the + order when it is compared to an Array in output """ - (errors_n, errors) = gen_json_diff_report(deepcopy(d1), deepcopy(d2), exact=exact) + (errors_n, errors) = gen_json_diff_report( + deepcopy(output), deepcopy(expected), exact=exact + ) if errors_n > 0: result = json_cmp_result() @@ -1137,7 +1211,9 @@ def _sysctl_assure(commander, variable, value): def sysctl_atleast(commander, variable, min_value, raises=False): try: if commander is None: - commander = micronet.Commander("topotest") + logger = logging.getLogger("topotest") + commander = micronet.Commander("sysctl", logger=logger) + return _sysctl_atleast(commander, variable, min_value) except subprocess.CalledProcessError as error: logger.warning( @@ -1153,7 +1229,8 @@ def sysctl_atleast(commander, variable, min_value, raises=False): def sysctl_assure(commander, variable, value, raises=False): try: if commander is None: - commander = micronet.Commander("topotest") + logger = logging.getLogger("topotest") + commander = micronet.Commander("sysctl", logger=logger) return _sysctl_assure(commander, variable, value) except subprocess.CalledProcessError as error: logger.warning( @@ -1287,6 +1364,8 @@ def setup_node_tmpdir(logdir, name): class Router(Node): "A Node with IPv4/IPv6 forwarding enabled" + gdb_emacs_router = None + def __init__(self, name, *posargs, **params): # Backward compatibility: # Load configuration defaults like topogen. @@ -1304,6 +1383,8 @@ def __init__(self, name, *posargs, **params): ) self.perf_daemons = {} + self.rr_daemons = {} + self.valgrind_gdb_daemons = {} # If this topology is using old API and doesn't have logdir # specified, then attempt to generate an unique logdir. @@ -1344,6 +1425,7 @@ def __init__(self, name, *posargs, **params): "pathd": 0, "snmpd": 0, "mgmtd": 0, + "snmptrapd": 0, } self.daemons_options = {"zebra": ""} self.reportCores = True @@ -1638,8 +1720,6 @@ def startRouter(self, tgen=None): # TODO remove the following lines after all tests are migrated to Topogen. # Try to find relevant old logfiles in /tmp and delete them map(os.remove, glob.glob("{}/{}/*.log".format(self.logdir, self.name))) - # Remove old core files - map(os.remove, glob.glob("{}/{}/*.dmp".format(self.logdir, self.name))) # Remove IP addresses from OS first - we have them in zebra.conf self.removeIPs() # If ldp is used, check for LDP to be compiled and Linux Kernel to be 4.5 or higher @@ -1725,7 +1805,12 @@ def startRouterDaemons(self, daemons=None, tgen=None): gdb_breakpoints = g_pytest_config.get_option_list("--gdb-breakpoints") gdb_daemons = g_pytest_config.get_option_list("--gdb-daemons") gdb_routers = g_pytest_config.get_option_list("--gdb-routers") + gdb_use_emacs = bool(g_pytest_config.option.gdb_use_emacs) + rr_daemons = g_pytest_config.get_option_list("--rr-daemons") + rr_routers = g_pytest_config.get_option_list("--rr-routers") + rr_options = g_pytest_config.get_option("--rr-options", "") valgrind_extra = bool(g_pytest_config.option.valgrind_extra) + valgrind_leak_kinds = g_pytest_config.option.valgrind_leak_kinds valgrind_memleaks = bool(g_pytest_config.option.valgrind_memleaks) strace_daemons = g_pytest_config.get_option_list("--strace-daemons") @@ -1801,6 +1886,15 @@ def start_daemon(daemon, extra_opts=None): # do not since apparently presence of the pidfile impacts BGP GR self.cmd_status("rm -f {0}.pid {0}.vty".format(runbase)) + def do_gdb_or_rr(gdb): + routers = gdb_routers if gdb else rr_routers + daemons = gdb_daemons if gdb else rr_daemons + return ( + (routers or daemons) + and (not routers or self.name in routers or "all" in routers) + and (not daemons or daemon in daemons or "all" in daemons) + ) + rediropt = " > {0}.out 2> {0}.err".format(daemon) if daemon == "snmpd": binary = "/usr/sbin/snmpd" @@ -1809,6 +1903,15 @@ def start_daemon(daemon, extra_opts=None): daemon_opts ) + "{}.pid -x /etc/frr/agentx".format(runbase) # check_daemon_files.append(runbase + ".pid") + elif daemon == "snmptrapd": + binary = "/usr/sbin/snmptrapd" + cmdenv = "" + cmdopt = ( + "{} ".format(daemon_opts) + + "-C -c /etc/{}/snmptrapd.conf".format(self.routertype) + + " -p {}.pid".format(runbase) + + " -LF 6-7 {}/{}/snmptrapd.log".format(self.logdir, self.name) + ) else: binary = os.path.join(self.daemondir, daemon) check_daemon_files.extend([runbase + ".pid", runbase + ".vty"]) @@ -1827,13 +1930,23 @@ def start_daemon(daemon, extra_opts=None): supp_file = os.path.abspath( os.path.join(this_dir, "../../../tools/valgrind.supp") ) - cmdenv += " /usr/bin/valgrind --num-callers=50 --log-file={1}/{2}.valgrind.{0}.%p --leak-check=full --suppressions={3}".format( - daemon, self.logdir, self.name, supp_file + + valgrind_logbase = f"{self.logdir}/{self.name}.valgrind.{daemon}" + if do_gdb_or_rr(True): + cmdenv += " exec" + cmdenv += ( + " /usr/bin/valgrind --num-callers=50" + f" --log-file={valgrind_logbase}.%p" + f" --leak-check=full --suppressions={supp_file}" ) + if valgrind_leak_kinds: + cmdenv += f" --show-leak-kinds={valgrind_leak_kinds}" if valgrind_extra: cmdenv += ( " --gen-suppressions=all --expensive-definedness-checks=yes" ) + if do_gdb_or_rr(True): + cmdenv += " --vgdb-error=0" elif daemon in strace_daemons or "all" in strace_daemons: cmdenv = "strace -f -D -o {1}/{2}.strace.{0} ".format( daemon, self.logdir, self.name @@ -1848,16 +1961,22 @@ def start_daemon(daemon, extra_opts=None): tail_log_files.append( "{}/{}/{}.log".format(self.logdir, self.name, daemon) ) + if extra_opts: cmdopt += " " + extra_opts + if do_gdb_or_rr(True) and do_gdb_or_rr(False): + logger.warning("cant' use gdb and rr at same time") + if ( - (gdb_routers or gdb_daemons) - and ( - not gdb_routers or self.name in gdb_routers or "all" in gdb_routers - ) - and (not gdb_daemons or daemon in gdb_daemons or "all" in gdb_daemons) - ): + not gdb_use_emacs or Router.gdb_emacs_router or valgrind_memleaks + ) and do_gdb_or_rr(True): + if Router.gdb_emacs_router is not None: + logger.warning( + "--gdb-use-emacs can only run a single router and daemon, using" + " new window" + ) + if daemon == "snmpd": cmdopt += " -f " @@ -1867,9 +1986,133 @@ def start_daemon(daemon, extra_opts=None): gdbcmd += " -ex 'set breakpoint pending on'" for bp in gdb_breakpoints: gdbcmd += " -ex 'b {}'".format(bp) - gdbcmd += " -ex 'run {}'".format(cmdopt) - self.run_in_window(gdbcmd, daemon) + if not valgrind_memleaks: + gdbcmd += " -ex 'run {}'".format(cmdopt) + self.run_in_window(gdbcmd, daemon) + + logger.info( + "%s: %s %s launched in gdb window", + self, + self.routertype, + daemon, + ) + + else: + cmd = " ".join([cmdenv, binary, cmdopt]) + p = self.popen(cmd) + self.valgrind_gdb_daemons[daemon] = p + if p.poll() and p.returncode: + self.logger.error( + '%s: Failed to launch "%s" (%s) with perf using: %s', + self, + daemon, + p.returncode, + cmd, + ) + assert False, "Faled to launch valgrind with gdb" + logger.debug( + "%s: %s %s started with perf", self, self.routertype, daemon + ) + # Now read the erorr log file until we ae given launch priority + timeout = Timeout(30) + vpid = None + for remaining in timeout: + try: + fname = f"{valgrind_logbase}.{p.pid}" + logging.info("Checking %s for valgrind launch info", fname) + o = open(fname, encoding="ascii").read() + except FileNotFoundError: + logging.info("%s not present yet", fname) + else: + m = re.search(r"target remote \| (.*vgdb) --pid=(\d+)", o) + if m: + vgdb_cmd = m.group(0) + break + time.sleep(1) + else: + assert False, "Faled to get launch info for valgrind with gdb" + + gdbcmd += f" -ex '{vgdb_cmd}'" + gdbcmd += " -ex 'c'" + self.run_in_window(gdbcmd, daemon) + + logger.info( + "%s: %s %s launched in gdb window", + self, + self.routertype, + daemon, + ) + elif gdb_use_emacs and do_gdb_or_rr(True): + assert Router.gdb_emacs_router is None + Router.gdb_emacs_router = self + + assert not valgrind_memleaks, "vagrind gdb in emacs not supported yet" + + if daemon == "snmpd": + cmdopt += " -f " + cmdopt += rediropt + + sudo_path = get_exec_path_host("sudo") + ecbin = [ + sudo_path, + "-Eu", + os.environ["SUDO_USER"], + get_exec_path_host("emacsclient"), + ] + pre_cmd = self._get_pre_cmd(True, False, ns_only=True, root_level=True) + # why fail:? gdb -i=mi -iex='set debuginfod enabled off' {binary} " + gdbcmd = f"{sudo_path} {pre_cmd} gdb -i=mi {binary} " + + commander.cmd_raises( + ecbin + + [ + "--eval", + f'(gdb "{gdbcmd}"))', + ] + ) + + elcheck = ( + '(ignore-errors (with-current-buffer "*gud-nsenter*"' + " (and (string-match-p" + ' "(gdb) "' + " (buffer-substring-no-properties " + ' (- (point-max) 10) (point-max))) "ready")))' + ) + + @retry(10) + def emacs_gdb_ready(): + check = commander.cmd_nostatus(ecbin + ["--eval", elcheck]) + return None if "ready" in check else False + + emacs_gdb_ready() + + # target gdb commands + cmd = "set breakpoint pending on" + self.cmd_raises( + ecbin + + [ + "--eval", + f'(gud-gdb-run-command-fetch-lines "{cmd}" "*gud-gdb*")', + ] + ) + # gdb breakpoints + for bp in gdb_breakpoints: + self.cmd_raises( + ecbin + + [ + "--eval", + f'(gud-gdb-run-command-fetch-lines "br {bp}" "*gud-gdb*")', + ] + ) + + self.cmd_raises( + ecbin + + [ + "--eval", + f'(gud-gdb-run-command-fetch-lines "run {cmdopt}" "*gud-gdb*")', + ] + ) logger.info( "%s: %s %s launched in gdb window", self, self.routertype, daemon @@ -1895,8 +2138,31 @@ def start_daemon(daemon, extra_opts=None): logger.debug( "%s: %s %s started with perf", self, self.routertype, daemon ) + elif do_gdb_or_rr(False): + cmdopt += rediropt + cmd = " ".join( + [ + "rr record -o {} {} --".format(self.rundir / "rr", rr_options), + binary, + cmdopt, + ] + ) + p = self.popen(cmd) + self.rr_daemons[daemon] = p + if p.poll() and p.returncode: + self.logger.error( + '%s: Failed to launch "%s" (%s) with rr using: %s', + self, + daemon, + p.returncode, + cmd, + ) + else: + logger.debug( + "%s: %s %s started with rr", self, self.routertype, daemon + ) else: - if daemon != "snmpd": + if daemon != "snmpd" and daemon != "snmptrapd": cmdopt += " -d " cmdopt += rediropt @@ -2086,8 +2352,7 @@ def checkRouterCores(self, reportLeaks=True, reportOnce=False): backtrace = gdb_core(self, daemon, corefiles) traces = ( traces - + "\n%s: %s crashed. Core file found - Backtrace follows:\n%s" - % (self.name, daemon, backtrace) + + f"\nCORE FOUND: {self.name}: {daemon} crashed. Backtrace follows:\n{backtrace}" ) reportMade = True elif reportLeaks: @@ -2140,6 +2405,8 @@ def checkRouterRunning(self): for daemon in self.daemons: if daemon == "snmpd": continue + if daemon == "snmptrapd": + continue if (self.daemons[daemon] == 1) and not (daemon in daemonsRunning): sys.stderr.write("%s: Daemon %s not running\n" % (self.name, daemon)) if daemon == "staticd": diff --git a/tests/topotests/mgmt_config/r1/early-end-zebra.conf b/tests/topotests/mgmt_config/r1/early-end-zebra.conf new file mode 100644 index 0000000000..44a2f96825 --- /dev/null +++ b/tests/topotests/mgmt_config/r1/early-end-zebra.conf @@ -0,0 +1,6 @@ +allow-external-route-update +end +ip multicast rpf-lookup-mode urib-only +end +ip table range 2 3 +end \ No newline at end of file diff --git a/tests/topotests/mgmt_config/r1/early-end.conf b/tests/topotests/mgmt_config/r1/early-end.conf new file mode 100644 index 0000000000..3aacad6471 --- /dev/null +++ b/tests/topotests/mgmt_config/r1/early-end.conf @@ -0,0 +1,8 @@ +ip route 15.1.0.0/24 101.0.0.2 +end +ip route 15.2.0.0/24 101.0.0.2 +end +ip route 15.3.0.0/24 101.0.0.2 +end +ip route 15.4.0.0/24 101.0.0.2 +end \ No newline at end of file diff --git a/tests/topotests/mgmt_config/r1/early-end2-zebra.conf b/tests/topotests/mgmt_config/r1/early-end2-zebra.conf new file mode 100644 index 0000000000..37619d52ac --- /dev/null +++ b/tests/topotests/mgmt_config/r1/early-end2-zebra.conf @@ -0,0 +1,7 @@ +conf t +allow-external-route-update +end +ip multicast rpf-lookup-mode urib-only +end +ip table range 2 3 +end \ No newline at end of file diff --git a/tests/topotests/mgmt_config/r1/early-end2.conf b/tests/topotests/mgmt_config/r1/early-end2.conf new file mode 100644 index 0000000000..229ccc7410 --- /dev/null +++ b/tests/topotests/mgmt_config/r1/early-end2.conf @@ -0,0 +1,9 @@ +conf t +ip route 16.1.0.0/24 101.0.0.2 +end +ip route 16.2.0.0/24 101.0.0.2 +end +ip route 16.3.0.0/24 101.0.0.2 +end +ip route 16.4.0.0/24 101.0.0.2 +end \ No newline at end of file diff --git a/tests/topotests/mgmt_config/r1/early-exit-zebra.conf b/tests/topotests/mgmt_config/r1/early-exit-zebra.conf new file mode 100644 index 0000000000..44f202dbcb --- /dev/null +++ b/tests/topotests/mgmt_config/r1/early-exit-zebra.conf @@ -0,0 +1,6 @@ +allow-external-route-update +exit +ip multicast rpf-lookup-mode urib-only +exit +ip table range 2 3 +exit \ No newline at end of file diff --git a/tests/topotests/mgmt_config/r1/early-exit.conf b/tests/topotests/mgmt_config/r1/early-exit.conf new file mode 100644 index 0000000000..c6a52df5d3 --- /dev/null +++ b/tests/topotests/mgmt_config/r1/early-exit.conf @@ -0,0 +1,8 @@ +ip route 13.1.0.0/24 101.0.0.2 +exit +ip route 13.2.0.0/24 101.0.0.2 +exit +ip route 13.3.0.0/24 101.0.0.2 +exit +ip route 13.4.0.0/24 101.0.0.2 +exit \ No newline at end of file diff --git a/tests/topotests/mgmt_config/r1/early-exit2-zebra.conf b/tests/topotests/mgmt_config/r1/early-exit2-zebra.conf new file mode 100644 index 0000000000..c7109bfd39 --- /dev/null +++ b/tests/topotests/mgmt_config/r1/early-exit2-zebra.conf @@ -0,0 +1,7 @@ +conf t +allow-external-route-update +exit +ip multicast rpf-lookup-mode urib-only +exit +ip table range 2 3 +exit \ No newline at end of file diff --git a/tests/topotests/mgmt_config/r1/early-exit2.conf b/tests/topotests/mgmt_config/r1/early-exit2.conf new file mode 100644 index 0000000000..79510c0aec --- /dev/null +++ b/tests/topotests/mgmt_config/r1/early-exit2.conf @@ -0,0 +1,9 @@ +conf t +ip route 14.1.0.0/24 101.0.0.2 +exit +ip route 14.2.0.0/24 101.0.0.2 +exit +ip route 14.3.0.0/24 101.0.0.2 +exit +ip route 14.4.0.0/24 101.0.0.2 +exit \ No newline at end of file diff --git a/tests/topotests/mgmt_config/r1/frr.conf b/tests/topotests/mgmt_config/r1/frr.conf new file mode 100644 index 0000000000..076715c068 --- /dev/null +++ b/tests/topotests/mgmt_config/r1/frr.conf @@ -0,0 +1,15 @@ +debug northbound notifications +! debug northbound libyang +debug northbound events +debug northbound callbacks +debug mgmt backend datastore frontend transaction +debug mgmt client backend +debug mgmt client frontend + +log timestamp precision 6 +log file frr.log debug + +interface r1-eth0 + ip address 101.0.0.1/24 + ipv6 address 2101::1/64 +exit \ No newline at end of file diff --git a/tests/topotests/mgmt_config/r1/mgmtd.conf b/tests/topotests/mgmt_config/r1/mgmtd.conf new file mode 100644 index 0000000000..318de765c8 --- /dev/null +++ b/tests/topotests/mgmt_config/r1/mgmtd.conf @@ -0,0 +1,11 @@ +debug northbound notifications +debug northbound libyang +debug northbound events +debug northbound callbacks +debug mgmt backend datastore frontend transaction +debug mgmt client backend +debug mgmt client frontend + +ip route 12.0.0.0/24 101.0.0.2 + +ipv6 route 2012::/48 2101::2 \ No newline at end of file diff --git a/tests/topotests/mgmt_config/r1/normal-exit.conf b/tests/topotests/mgmt_config/r1/normal-exit.conf new file mode 100644 index 0000000000..c6a52df5d3 --- /dev/null +++ b/tests/topotests/mgmt_config/r1/normal-exit.conf @@ -0,0 +1,8 @@ +ip route 13.1.0.0/24 101.0.0.2 +exit +ip route 13.2.0.0/24 101.0.0.2 +exit +ip route 13.3.0.0/24 101.0.0.2 +exit +ip route 13.4.0.0/24 101.0.0.2 +exit \ No newline at end of file diff --git a/tests/topotests/mgmt_config/r1/one-exit-zebra.conf b/tests/topotests/mgmt_config/r1/one-exit-zebra.conf new file mode 100644 index 0000000000..0c38459702 --- /dev/null +++ b/tests/topotests/mgmt_config/r1/one-exit-zebra.conf @@ -0,0 +1,3 @@ +allow-external-route-update +exit +ip multicast rpf-lookup-mode urib-only diff --git a/tests/topotests/mgmt_config/r1/one-exit.conf b/tests/topotests/mgmt_config/r1/one-exit.conf new file mode 100644 index 0000000000..47147d44eb --- /dev/null +++ b/tests/topotests/mgmt_config/r1/one-exit.conf @@ -0,0 +1,3 @@ +ip route 20.1.0.0/24 101.0.0.2 +exit +ip route 20.2.0.0/24 101.0.0.2 diff --git a/tests/topotests/mgmt_config/r1/one-exit2-zebra.conf b/tests/topotests/mgmt_config/r1/one-exit2-zebra.conf new file mode 100644 index 0000000000..34acb76d92 --- /dev/null +++ b/tests/topotests/mgmt_config/r1/one-exit2-zebra.conf @@ -0,0 +1,4 @@ +conf t +allow-external-route-update +exit +ip multicast rpf-lookup-mode urib-only \ No newline at end of file diff --git a/tests/topotests/mgmt_config/r1/one-exit2.conf b/tests/topotests/mgmt_config/r1/one-exit2.conf new file mode 100644 index 0000000000..262339a854 --- /dev/null +++ b/tests/topotests/mgmt_config/r1/one-exit2.conf @@ -0,0 +1,4 @@ +conf t +ip route 21.1.0.0/24 101.0.0.2 +exit +ip route 21.2.0.0/24 101.0.0.2 diff --git a/tests/topotests/mgmt_config/r1/zebra.conf b/tests/topotests/mgmt_config/r1/zebra.conf new file mode 100644 index 0000000000..f3264efb00 --- /dev/null +++ b/tests/topotests/mgmt_config/r1/zebra.conf @@ -0,0 +1,7 @@ +log timestamp precision 6 +log file frr-r1.log debug + +interface r1-eth0 + ip address 101.0.0.1/24 + ipv6 address 2101::1/64 +exit \ No newline at end of file diff --git a/tests/topotests/mgmt_config/test_config.py b/tests/topotests/mgmt_config/test_config.py new file mode 100644 index 0000000000..1d732223ff --- /dev/null +++ b/tests/topotests/mgmt_config/test_config.py @@ -0,0 +1,384 @@ +# -*- coding: utf-8 eval: (blacken-mode 1) -*- +# SPDX-License-Identifier: ISC +# +# June 10 2023, Christian Hopps <chopps@labn.net> +# +# Copyright (c) 2023, LabN Consulting, L.L.C. +# +""" +Test mgmtd parsing of configs. + +So: + +MGMTD matches zebra: + +one exit file: ONE: vty -f file +one exit redir: ONE: vty < file +early exit file: ONE: vty -f file +early exit redir: ONE: vty < file +early end file: ALL: vty -f file +early end redir: ONE: vty < file + +Raw tests: + +FAILED mgmt_config/test_config.py::test_mgmtd_one_exit_file - AssertionError: vtysh < didn't work after exit +FAILED mgmt_config/test_config.py::test_mgmtd_one_exit_redir - AssertionError: vtysh < didn't work after exit +FAILED mgmt_config/test_config.py::test_mgmtd_early_exit_file - AssertionError: vtysh -f didn't work after 1 exit +FAILED mgmt_config/test_config.py::test_mgmtd_early_exit_redir - AssertionError: vtysh < didn't work after 1 exits +FAILED mgmt_config/test_config.py::test_mgmtd_early_end_redir - AssertionError: vtysh < didn't work after 1 end + +FAILED mgmt_config/test_config.py::test_zebra_one_exit_file - AssertionError: zebra second conf missing +FAILED mgmt_config/test_config.py::test_zebra_one_exit_redir - AssertionError: zebra second conf missing +FAILED mgmt_config/test_config.py::test_zebra_early_exit_file - AssertionError: zebra second conf missing +FAILED mgmt_config/test_config.py::test_zebra_early_exit_redir - AssertionError: zebra second conf missing +FAILED mgmt_config/test_config.py::test_zebra_early_end_redir - AssertionError: zebra second conf missing + +Before fixed: + +one exit file: NONE: vty -f file +early exit file: NONE: vty -f file + +FAILED mgmt_config/test_config.py::test_mgmtd_one_exit_file - AssertionError: vtysh -f didn't work before exit +FAILED mgmt_config/test_config.py::test_mgmtd_one_exit_redir - AssertionError: vtysh < didn't work after exit +FAILED mgmt_config/test_config.py::test_mgmtd_early_exit_file - AssertionError: vtysh -f didn't work before exit +FAILED mgmt_config/test_config.py::test_mgmtd_early_exit_redir - AssertionError: vtysh < didn't work after 1 exits +FAILED mgmt_config/test_config.py::test_mgmtd_early_end_redir - AssertionError: vtysh < didn't work after 1 end + +FAILED mgmt_config/test_config.py::test_zebra_one_exit_file - AssertionError: zebra second conf missing +FAILED mgmt_config/test_config.py::test_zebra_one_exit_redir - AssertionError: zebra second conf missing +FAILED mgmt_config/test_config.py::test_zebra_early_exit_file - AssertionError: zebra second conf missing +FAILED mgmt_config/test_config.py::test_zebra_early_exit_redir - AssertionError: zebra second conf missing +FAILED mgmt_config/test_config.py::test_zebra_early_end_redir - AssertionError: zebra second conf missing + +""" +import ipaddress +import logging +import os +import re +from pathlib import Path + +import pytest +from lib.common_config import retry, step +from lib.topogen import Topogen, TopoRouter + +pytestmark = [pytest.mark.staticd, pytest.mark.mgmtd] + + +@retry(retry_timeout=1, initial_wait=0.1) +def check_kernel(r1, prefix, expected=True): + net = ipaddress.ip_network(prefix) + if net.version == 6: + kernel = r1.cmd_nostatus("ip -6 route show", warn=not expected) + else: + kernel = r1.cmd_nostatus("ip -4 route show", warn=not expected) + + logging.debug("checking kernel routing table:\n%0.1920s", kernel) + route = f"{str(net)}(?: nhid [0-9]+)?.*proto (static|196)" + m = re.search(route, kernel) + if expected and not m: + return f"Failed to find \n'{route}'\n in \n'{kernel:.1920}'" + elif not expected and m: + return f"Failed found \n'{route}'\n in \n'{kernel:.1920}'" + return None + + +@pytest.fixture(scope="module") +def tgen(request): + "Setup/Teardown the environment and provide tgen argument to tests" + + topodef = {"s1": ("r1",)} + + tgen = Topogen(topodef, request.module.__name__) + tgen.start_topology() + + # configure mgmtd using current mgmtd config file + tgen.gears["r1"].load_config(TopoRouter.RD_ZEBRA, "zebra.conf") + tgen.gears["r1"].load_config(TopoRouter.RD_MGMTD) + + tgen.start_router() + yield tgen + tgen.stop_topology() + + +def save_log_snippet(logfile, content, savepath=None): + os.sync() + os.sync() + os.sync() + + with open(logfile, encoding="utf-8") as f: + buf = f.read() + assert content == buf[: len(content)] + newcontent = buf[len(content) :] + + if savepath: + with open(savepath, "w", encoding="utf-8") as f: + f.write(newcontent) + + return buf + + +def mapname(lname): + return lname.replace(".conf", "") + "-log.txt" + + +logbuf = "" + + +@pytest.fixture(scope="module") +def r1(tgen): + return tgen.gears["r1"].net + + +@pytest.fixture(scope="module") +def confdir(): + return Path(os.environ["PYTEST_TOPOTEST_SCRIPTDIR"]) / "r1" + + +@pytest.fixture(scope="module") +def tempdir(r1): + return Path(r1.rundir) + + +@pytest.fixture(scope="module") +def logpath(tempdir): + return tempdir / "mgmtd.log" + + +@pytest.fixture(autouse=True, scope="function") +def cleanup_config(r1, tempdir, logpath): + global logbuf + + logbuf = save_log_snippet(logpath, logbuf, "/dev/null") + + yield + + r1.cmd_nostatus("vtysh -c 'conf t' -c 'no allow-external-route-update'") + r1.cmd_nostatus("vtysh -c 'conf t' -c 'no ip multicast rpf-lookup-mode urib-only'") + r1.cmd_nostatus("vtysh -c 'conf t' -c 'no ip table range 2 3'") + + logbuf = save_log_snippet(logpath, logbuf, "/dev/null") + + +def test_staticd_startup(r1): + r1.cmd_nostatus( + "vtysh -c 'debug mgmt client frontend' " + "-c 'debug mgmt client backend' " + "-c 'debug mgmt backend frontend datastore transaction'" + ) + step("Verifying routes are present on r1") + result = check_kernel(r1, "12.0.0.0/24", retry_timeout=3.0) + assert result is None + + +def test_mgmtd_one_exit_file(r1, confdir, tempdir, logpath): + global logbuf + + conf = "one-exit.conf" + step(f"load {conf} file with vtysh -f ") + output = r1.cmd_nostatus(f"vtysh -f {confdir / conf}") + logbuf = save_log_snippet(logpath, logbuf, tempdir / mapname(conf)) + print(output) + + result1 = check_kernel(r1, "20.1.0.0/24") + result2 = check_kernel(r1, "20.2.0.0/24") + + assert result1 is None, "vtysh -f didn't work before exit" + assert result2 is not None, "vtysh < worked after exit, unexpected" + + +def test_mgmtd_one_exit_redir(r1, confdir, tempdir, logpath): + global logbuf + + conf = "one-exit2.conf" + step(f"Redirect {conf} file into vtysh") + output = r1.cmd_nostatus(f"vtysh < {confdir / conf}") + logbuf = save_log_snippet(logpath, logbuf, tempdir / mapname(conf)) + print(output) + + result1 = check_kernel(r1, "21.1.0.0/24") + result2 = check_kernel(r1, "21.2.0.0/24") + + assert result1 is None, "vtysh < didn't work before exit" + assert result2 is not None, "vtysh < worked after exit, unexpected" + + +def test_mgmtd_early_exit_file(r1, confdir, tempdir, logpath): + global logbuf + + conf = "early-exit.conf" + step(f"load {conf} file with vtysh -f ") + output = r1.cmd_nostatus(f"vtysh -f {confdir / conf}") + logbuf = save_log_snippet(logpath, logbuf, tempdir / mapname(conf)) + print(output) + + result1 = check_kernel(r1, "13.1.0.0/24") + result2 = check_kernel(r1, "13.2.0.0/24") + result3 = check_kernel(r1, "13.3.0.0/24") + + assert result1 is None, "vtysh -f didn't work before exit" + assert result2 is not None, "vtysh -f worked after 1 exit, unexpected" + assert result3 is not None, "vtysh -f worked after 2 exit, unexpected" + + +def test_mgmtd_early_exit_redir(r1, confdir, tempdir, logpath): + global logbuf + + conf = "early-exit2.conf" + step(f"Redirect {conf} file into vtysh") + output = r1.cmd_nostatus(f"vtysh < {confdir / conf}") + logbuf = save_log_snippet(logpath, logbuf, tempdir / mapname(conf)) + print(output) + + result1 = check_kernel(r1, "14.1.0.0/24") + result2 = check_kernel(r1, "14.2.0.0/24") + result3 = check_kernel(r1, "14.3.0.0/24") + + assert result1 is None, "vtysh < didn't work before exit" + assert result2 is not None, "vtysh < worked after 1 exits, unexpected" + assert result3 is not None, "vtysh < worked after 2 exits, unexpected" + + +def test_mgmtd_early_end_file(r1, confdir, tempdir, logpath): + global logbuf + + conf = "early-end.conf" + step(f"load {conf} file with vtysh -f ") + output = r1.cmd_nostatus(f"vtysh -f {confdir / conf}") + logbuf = save_log_snippet(logpath, logbuf, tempdir / mapname(conf)) + print(output) + + result1 = check_kernel(r1, "15.1.0.0/24") + result2 = check_kernel(r1, "15.2.0.0/24") + result3 = check_kernel(r1, "15.3.0.0/24") + + assert result1 is None, "vtysh -f didn't work before end" + assert result2 is None, "vtysh -f didn't work after 1 end" + assert result3 is None, "vtysh -f didn't work after 2 ends" + + +def test_mgmtd_early_end_redir(r1, confdir, tempdir, logpath): + global logbuf + + conf = "early-end2.conf" + step(f"Redirect {conf} file into vtysh") + output = r1.cmd_nostatus(f"vtysh < {confdir / conf}") + logbuf = save_log_snippet(logpath, logbuf, tempdir / mapname(conf)) + print(output) + + result1 = check_kernel(r1, "16.1.0.0/24") + result2 = check_kernel(r1, "16.2.0.0/24") + result3 = check_kernel(r1, "16.3.0.0/24") + + assert result1 is None, "vtysh < didn't work before end" + assert result2 is not None, "vtysh < worked after 1 end, unexpected" + assert result3 is not None, "vtysh < worked after 2 end, unexpected" + + +# +# Zebra +# + + +def test_zebra_one_exit_file(r1, confdir, tempdir, logpath): + global logbuf + + conf = "one-exit-zebra.conf" + step(f"load {conf} file with vtysh -f ") + output = r1.cmd_nostatus(f"vtysh -f {confdir / conf}") + logbuf = save_log_snippet(logpath, logbuf, tempdir / mapname(conf)) + print(output) + + showrun = r1.cmd_nostatus("vtysh -c 'show running'") + assert "allow-external-route-update" in showrun, "zebra conf missing" + assert ( + "ip multicast rpf-lookup-mode urib-only" not in showrun + ), "zebra second conf present, unexpected" + + +def test_zebra_one_exit_redir(r1, confdir, tempdir, logpath): + global logbuf + + conf = "one-exit2-zebra.conf" + step(f"Redirect {conf} file into vtysh") + output = r1.cmd_nostatus(f"vtysh < {confdir / conf}") + logbuf = save_log_snippet(logpath, logbuf, tempdir / mapname(conf)) + print(output) + + showrun = r1.cmd_nostatus("vtysh -c 'show running'") + + assert "allow-external-route-update" in showrun, "zebra conf missing" + assert ( + "ip multicast rpf-lookup-mode urib-only" not in showrun + ), "zebra second conf present, unexpected" + + +def test_zebra_early_exit_file(r1, confdir, tempdir, logpath): + global logbuf + + conf = "early-exit-zebra.conf" + step(f"load {conf} file with vtysh -f ") + output = r1.cmd_nostatus(f"vtysh -f {confdir / conf}") + logbuf = save_log_snippet(logpath, logbuf, tempdir / mapname(conf)) + print(output) + + showrun = r1.cmd_nostatus("vtysh -c 'show running'") + + assert "allow-external-route-update" in showrun, "zebra conf missing" + assert ( + "ip multicast rpf-lookup-mode urib-only" not in showrun + ), "zebra second conf present, unexpected" + assert "ip table range 2 3" not in showrun, "zebra third conf present, unexpected" + + +def test_zebra_early_exit_redir(r1, confdir, tempdir, logpath): + global logbuf + + conf = "early-exit2-zebra.conf" + step(f"Redirect {conf} file into vtysh") + output = r1.cmd_nostatus(f"vtysh < {confdir / conf}") + logbuf = save_log_snippet(logpath, logbuf, tempdir / mapname(conf)) + print(output) + + showrun = r1.cmd_nostatus("vtysh -c 'show running'") + + assert "allow-external-route-update" in showrun, "zebra conf missing" + assert ( + "ip multicast rpf-lookup-mode urib-only" not in showrun + ), "zebra second conf present, unexpected" + assert "ip table range 2 3" not in showrun, "zebra third conf present, unexpected" + + +def test_zebra_early_end_file(r1, confdir, tempdir, logpath): + global logbuf + + conf = "early-end-zebra.conf" + step(f"load {conf} file with vtysh -f ") + output = r1.cmd_nostatus(f"vtysh -f {confdir / conf}") + logbuf = save_log_snippet(logpath, logbuf, tempdir / mapname(conf)) + print(output) + + showrun = r1.cmd_nostatus("vtysh -c 'show running'") + + assert "allow-external-route-update" in showrun, "zebra conf missing" + assert ( + "ip multicast rpf-lookup-mode urib-only" in showrun + ), "zebra second conf missing" + assert "ip table range 2 3" in showrun, "zebra third missing" + + +def test_zebra_early_end_redir(r1, confdir, tempdir, logpath): + global logbuf + + conf = "early-end2-zebra.conf" + step(f"Redirect {conf} file into vtysh") + output = r1.cmd_nostatus(f"vtysh < {confdir / conf}") + logbuf = save_log_snippet(logpath, logbuf, tempdir / mapname(conf)) + print(output) + + showrun = r1.cmd_nostatus("vtysh -c 'show running'") + + assert "allow-external-route-update" in showrun, "zebra conf missing" + assert ( + "ip multicast rpf-lookup-mode urib-only" not in showrun + ), "zebra second conf present, unexpected" + assert "ip table range 2 3" not in showrun, "zebra third conf present, unexpected" diff --git a/tests/topotests/mgmt_config/test_regression.py b/tests/topotests/mgmt_config/test_regression.py new file mode 100644 index 0000000000..70f38d2ec7 --- /dev/null +++ b/tests/topotests/mgmt_config/test_regression.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 eval: (blacken-mode 1) -*- +# SPDX-License-Identifier: ISC +# +# July 13 2023, Christian Hopps <chopps@labn.net> +# +# Copyright (c) 2023, LabN Consulting, L.L.C. +# +""" +Test mgmtd regressions + +""" +import pytest +from lib.topogen import Topogen + +pytestmark = [pytest.mark.staticd, pytest.mark.mgmtd] + + +@pytest.fixture(scope="module") +def tgen(request): + "Setup/Teardown the environment and provide tgen argument to tests" + + topodef = {"s1": ("r1",)} + tgen = Topogen(topodef, request.module.__name__) + tgen.start_topology() + tgen.gears["r1"].load_frr_config("frr.conf") + tgen.start_router() + yield tgen + tgen.stop_topology() + + +def test_regression_issue_13920(tgen): + """Issue #13920 + + ubuntu2204# conf t + ubuntu2204(config)# ip route 3.2.4.0/24 6.5.5.11 loop3 + ubuntu2204(config)# nexthop-group nh2 + ubuntu2204(config-nh-group)# nexthop 6.5.5.12 + ubuntu2204(config-nh-group)# exi + ubuntu2204(config)# ip route 3.22.4.0/24 6.5.5.12 + crash + """ + + r1 = tgen.gears["r1"] + r1.vtysh_multicmd( + """ + conf t + nexthop-group nh2 + exit + ip route 3.22.4.0/24 6.5.5.12 + """ + ) + output = r1.net.checkRouterCores() + assert not output.strip() diff --git a/tests/topotests/mgmt_debug_flags/r1/frr.conf b/tests/topotests/mgmt_debug_flags/r1/frr.conf new file mode 100644 index 0000000000..ba95b8d493 --- /dev/null +++ b/tests/topotests/mgmt_debug_flags/r1/frr.conf @@ -0,0 +1,11 @@ +log timestamp precision 6 +log file frr.log + +! debug mgmt backend datastore frontend transaction +! debug mgmt client frontend +! debug mgmt client backend + +interface r1-eth0 + ip address 1.1.1.1/24 +exit +ip route 11.11.11.11/32 1.1.1.2 \ No newline at end of file diff --git a/tests/topotests/mgmt_debug_flags/test_debug.py b/tests/topotests/mgmt_debug_flags/test_debug.py new file mode 100644 index 0000000000..e49d9b7beb --- /dev/null +++ b/tests/topotests/mgmt_debug_flags/test_debug.py @@ -0,0 +1,129 @@ +#!/usr/bin/env python +# -*- coding: utf-8 eval: (blacken-mode 1) -*- +# SPDX-License-Identifier: ISC +# +# Copyright (c) 2021, LabN Consulting, L.L.C. +# Copyright (c) 2019-2020 by +# Donatas Abraitis <donatas.abraitis@gmail.com> +# +# noqa: E501 +# +""" +Test static route functionality +""" +import pytest +from lib.common_config import step +from lib.topogen import Topogen +from munet.watchlog import WatchLog + +pytestmark = [pytest.mark.staticd, pytest.mark.mgmtd] + + +@pytest.fixture(scope="module") +def tgen(request): + "Setup/Teardown the environment and provide tgen argument to tests" + + topodef = {"s1": ("r1",)} + tgen = Topogen(topodef, request.module.__name__) + tgen.start_topology() + + for rname, router in tgen.routers().items(): + router.load_frr_config("frr.conf") + + tgen.start_router() + yield tgen + tgen.stop_topology() + + +def test_client_debug_enable(tgen): + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + + # Start watching log files + watch_mgmtd_log = WatchLog(r1.net.rundir / "mgmtd.log") + watch_staticd_log = WatchLog(r1.net.rundir / "staticd.log") + + def __test_debug(r1, on): + watch_mgmtd_log.snapshot() + watch_staticd_log.snapshot() + + # Add ip route and remove look for debug. + r1.vtysh_cmd("conf t\nip route 11.11.11.11/32 1.1.1.2") + r1.vtysh_cmd("conf t\nno ip route 11.11.11.11/32 1.1.1.2") + + new_mgmt_logs = watch_mgmtd_log.snapshot() + new_be_logs = watch_staticd_log.snapshot() + + fe_cl_msg = "Sending SET_CONFIG_REQ" + fe_ad_msg = "Got SETCFG_REQ" + be_ad_msg = "Sending CFGDATA_CREATE_REQ" + be_cl_msg = "Got CFG_APPLY_REQ" + + if on: + assert fe_cl_msg in new_mgmt_logs + assert fe_ad_msg in new_mgmt_logs + assert be_ad_msg in new_mgmt_logs + assert be_cl_msg in new_be_logs + else: + assert fe_cl_msg not in new_mgmt_logs + assert fe_ad_msg not in new_mgmt_logs + assert be_ad_msg not in new_mgmt_logs + assert be_cl_msg not in new_be_logs + + step("test debug off") + __test_debug(r1, False) + + # Turn it on + step("tests debug on") + r1.vtysh_cmd("debug mgmt client frontend") + r1.vtysh_cmd("debug mgmt client backend") + r1.vtysh_cmd("debug mgmt backend frontend") + __test_debug(r1, True) + + # Turn it off + step("tests debug off") + r1.vtysh_cmd("no debug mgmt client frontend") + r1.vtysh_cmd("no debug mgmt client backend") + r1.vtysh_cmd("no debug mgmt backend frontend") + __test_debug(r1, False) + + # Configure it on + step("tests debug on") + r1.vtysh_cmd("conf t\ndebug mgmt client frontend") + r1.vtysh_cmd("conf t\ndebug mgmt client backend") + r1.vtysh_cmd("conf t\ndebug mgmt backend frontend") + __test_debug(r1, True) + + # Configure it off + step("tests debug off") + r1.vtysh_cmd("conf t\nno debug mgmt client frontend") + r1.vtysh_cmd("conf t\nno debug mgmt client backend") + r1.vtysh_cmd("conf t\nno debug mgmt backend frontend") + __test_debug(r1, False) + + # Turn it on + step("tests debug on") + r1.vtysh_cmd("debug mgmt client frontend") + r1.vtysh_cmd("debug mgmt client backend") + r1.vtysh_cmd("debug mgmt backend frontend") + __test_debug(r1, True) + # Configure it on + step("tests debug on") + r1.vtysh_cmd("conf t\ndebug mgmt client frontend") + r1.vtysh_cmd("conf t\ndebug mgmt client backend") + r1.vtysh_cmd("conf t\ndebug mgmt backend frontend") + __test_debug(r1, True) + # Turn it off + step("tests debug on") + r1.vtysh_cmd("no debug mgmt client frontend") + r1.vtysh_cmd("no debug mgmt client backend") + r1.vtysh_cmd("no debug mgmt backend frontend") + __test_debug(r1, True) + # Configure it off + step("tests debug off") + r1.vtysh_cmd("conf t\nno debug mgmt client frontend") + r1.vtysh_cmd("conf t\nno debug mgmt client backend") + r1.vtysh_cmd("conf t\nno debug mgmt backend frontend") + __test_debug(r1, False) diff --git a/tests/topotests/mgmt_fe_client/fe_client.py b/tests/topotests/mgmt_fe_client/fe_client.py new file mode 100644 index 0000000000..04b4184e5b --- /dev/null +++ b/tests/topotests/mgmt_fe_client/fe_client.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python +# -*- coding: utf-8 eval: (blacken-mode 1) -*- +# SPDX-License-Identifier: GPL-2.0-or-later +# +# November 27 2023, Christian Hopps <chopps@labn.net> +# +# Copyright (c) 2023, LabN Consulting, L.L.C. +# +# noqa: E501 +# +import argparse +import errno +import logging +import os +import socket +import sys +import time +from pathlib import Path + +import mgmt_pb2 + +MGMT_MSG_MARKER_PROTOBUF = b"\000###" +MGMT_MSG_MARKER_NATIVE = b"\001###" + + +def __parse_args(): + MPATH = "/var/run/frr/mgmtd_fe.sock" + parser = argparse.ArgumentParser() + parser.add_argument("--verbose", action="store_true", help="Be verbose") + parser.add_argument("--server", default=MPATH, help="path to server socket") + args = parser.parse_args() + + level = logging.DEBUG if args.verbose else logging.INFO + logging.basicConfig(level=level, format="%(asctime)s %(levelname)s: %(message)s") + + return args + + +def __server_connect(spath): + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + logging.debug("Connecting to server on %s", spath) + while ec := sock.connect_ex(str(spath)): + logging.warn("retry server connection in .5s (%s)", os.strerror(ec)) + time.sleep(0.5) + logging.info("Connected to server on %s", spath) + return sock + + +def mgmt_pb_recv_msg(sock, msg): + """Receive a mgmtd protobuf message from a stream socket.""" + marker = sock.recv(4) + assert marker in (MGMT_MSG_MARKER_PROTOBUF, MGMT_MSG_MARKER_NATIVE) + + msize = int.from_bytes(sock.recv(4), byteorder="big") + mdata = sock.recv(msize) + + msg.ParseFromString(mdata) + return msg + + +def mgmt_pb_send_msg(sock, msg): + """Send a mgmtd protobuf message from a stream socket.""" + marker = MGMT_MSG_MARKER_PROTOBUF + mdata = msg.SerializeToString() + msize = int.to_bytes(len(mdata), byteorder="big", length=4) + sock.send(marker) + sock.send(msize) + sock.send(mdata) + + +def create_session(sock): + req = mgmt_pb2.FeRegisterReq() + req.client_name = "test-client" + mgmt_pb_send_msg(sock, req) + logging.debug("Sent FeRegisterReq: %s", req) + + req = mgmt_pb2.FeSessionReq() + req.create = 1 + req.client_conn_id = 1 + mgmt_pb_send_msg(sock, req) + logging.debug("Sent FeSessionReq: %s", req) + + reply = mgmt_pb_recv_msg(sock, mgmt_pb2.FeSessionReply()) + logging.debug("Received FeSessionReply: %s", reply) + + +def __main(): + args = __parse_args() + sock = __server_connect(Path(args.server)) + create_session(sock) + + +def main(): + try: + __main() + except KeyboardInterrupt: + logging.info("Exiting") + except Exception as error: + logging.error("Unexpected error exiting: %s", error, exc_info=True) + + +if __name__ == "__main__": + main() diff --git a/tests/topotests/mgmt_fe_client/mgmt_pb2.py b/tests/topotests/mgmt_fe_client/mgmt_pb2.py new file mode 100644 index 0000000000..0aa8803f7f --- /dev/null +++ b/tests/topotests/mgmt_fe_client/mgmt_pb2.py @@ -0,0 +1,1990 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: mgmt.proto + +from google.protobuf.internal import enum_type_wrapper +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='mgmt.proto', + package='mgmtd', + syntax='proto2', + serialized_options=None, + create_key=_descriptor._internal_create_key, + serialized_pb=b'\n\nmgmt.proto\x12\x05mgmtd\"\x1e\n\rYangDataXPath\x12\r\n\x05xpath\x18\x01 \x02(\t\"3\n\rYangDataValue\x12\x19\n\x0f\x65ncoded_str_val\x18\x64 \x01(\tH\x00\x42\x07\n\x05value\">\n\x08YangData\x12\r\n\x05xpath\x18\x01 \x02(\t\x12#\n\x05value\x18\x02 \x01(\x0b\x32\x14.mgmtd.YangDataValue\"X\n\x0eYangCfgDataReq\x12\x1d\n\x04\x64\x61ta\x18\x01 \x02(\x0b\x32\x0f.mgmtd.YangData\x12\'\n\x08req_type\x18\x02 \x02(\x0e\x32\x15.mgmtd.CfgDataReqType\"B\n\x0eYangGetDataReq\x12\x1d\n\x04\x64\x61ta\x18\x01 \x02(\x0b\x32\x0f.mgmtd.YangData\x12\x11\n\tnext_indx\x18\x02 \x02(\x03\"R\n\x0e\x42\x65SubscribeReq\x12\x13\n\x0b\x63lient_name\x18\x01 \x02(\t\x12\x18\n\x10subscribe_xpaths\x18\x02 \x02(\x08\x12\x11\n\txpath_reg\x18\x03 \x03(\t\"#\n\x10\x42\x65SubscribeReply\x12\x0f\n\x07success\x18\x01 \x02(\x08\"*\n\x08\x42\x65TxnReq\x12\x0e\n\x06txn_id\x18\x01 \x02(\x04\x12\x0e\n\x06\x63reate\x18\x02 \x02(\x08\"=\n\nBeTxnReply\x12\x0e\n\x06txn_id\x18\x01 \x02(\x04\x12\x0e\n\x06\x63reate\x18\x02 \x02(\x08\x12\x0f\n\x07success\x18\x03 \x02(\x08\"b\n\x12\x42\x65\x43\x66gDataCreateReq\x12\x0e\n\x06txn_id\x18\x01 \x02(\x04\x12\'\n\x08\x64\x61ta_req\x18\x02 \x03(\x0b\x32\x15.mgmtd.YangCfgDataReq\x12\x13\n\x0b\x65nd_of_data\x18\x03 \x02(\x08\"M\n\x14\x42\x65\x43\x66gDataCreateReply\x12\x0e\n\x06txn_id\x18\x01 \x02(\x04\x12\x0f\n\x07success\x18\x02 \x02(\x08\x12\x14\n\x0c\x65rror_if_any\x18\x03 \x01(\t\"#\n\x11\x42\x65\x43\x66gDataApplyReq\x12\x0e\n\x06txn_id\x18\x01 \x02(\x04\"L\n\x13\x42\x65\x43\x66gDataApplyReply\x12\x0e\n\x06txn_id\x18\x01 \x02(\x04\x12\x0f\n\x07success\x18\x02 \x02(\x08\x12\x14\n\x0c\x65rror_if_any\x18\x03 \x01(\t\"A\n\rYangDataReply\x12\x1d\n\x04\x64\x61ta\x18\x01 \x03(\x0b\x32\x0f.mgmtd.YangData\x12\x11\n\tnext_indx\x18\x02 \x02(\x03\"\x94\x03\n\tBeMessage\x12+\n\nsubscr_req\x18\x02 \x01(\x0b\x32\x15.mgmtd.BeSubscribeReqH\x00\x12/\n\x0csubscr_reply\x18\x03 \x01(\x0b\x32\x17.mgmtd.BeSubscribeReplyH\x00\x12\"\n\x07txn_req\x18\x04 \x01(\x0b\x32\x0f.mgmtd.BeTxnReqH\x00\x12&\n\ttxn_reply\x18\x05 \x01(\x0b\x32\x11.mgmtd.BeTxnReplyH\x00\x12\x31\n\x0c\x63\x66g_data_req\x18\x06 \x01(\x0b\x32\x19.mgmtd.BeCfgDataCreateReqH\x00\x12\x35\n\x0e\x63\x66g_data_reply\x18\x07 \x01(\x0b\x32\x1b.mgmtd.BeCfgDataCreateReplyH\x00\x12\x31\n\rcfg_apply_req\x18\x08 \x01(\x0b\x32\x18.mgmtd.BeCfgDataApplyReqH\x00\x12\x35\n\x0f\x63\x66g_apply_reply\x18\t \x01(\x0b\x32\x1a.mgmtd.BeCfgDataApplyReplyH\x00\x42\t\n\x07message\"$\n\rFeRegisterReq\x12\x13\n\x0b\x63lient_name\x18\x01 \x02(\t\"T\n\x0c\x46\x65SessionReq\x12\x0e\n\x06\x63reate\x18\x01 \x02(\x08\x12\x18\n\x0e\x63lient_conn_id\x18\x02 \x01(\x04H\x00\x12\x14\n\nsession_id\x18\x03 \x01(\x04H\x00\x42\x04\n\x02id\"]\n\x0e\x46\x65SessionReply\x12\x0e\n\x06\x63reate\x18\x01 \x02(\x08\x12\x0f\n\x07success\x18\x02 \x02(\x08\x12\x16\n\x0e\x63lient_conn_id\x18\x03 \x01(\x04\x12\x12\n\nsession_id\x18\x04 \x02(\x04\"b\n\x0b\x46\x65LockDsReq\x12\x12\n\nsession_id\x18\x01 \x02(\x04\x12\x0e\n\x06req_id\x18\x02 \x02(\x04\x12!\n\x05\x64s_id\x18\x03 \x02(\x0e\x32\x12.mgmtd.DatastoreId\x12\x0c\n\x04lock\x18\x04 \x02(\x08\"\x8b\x01\n\rFeLockDsReply\x12\x12\n\nsession_id\x18\x01 \x02(\x04\x12\x0e\n\x06req_id\x18\x02 \x02(\x04\x12!\n\x05\x64s_id\x18\x03 \x02(\x0e\x32\x12.mgmtd.DatastoreId\x12\x0c\n\x04lock\x18\x04 \x02(\x08\x12\x0f\n\x07success\x18\x05 \x02(\x08\x12\x14\n\x0c\x65rror_if_any\x18\x06 \x01(\t\"\xbf\x01\n\x0e\x46\x65SetConfigReq\x12\x12\n\nsession_id\x18\x01 \x02(\x04\x12!\n\x05\x64s_id\x18\x02 \x02(\x0e\x32\x12.mgmtd.DatastoreId\x12\x0e\n\x06req_id\x18\x03 \x02(\x04\x12#\n\x04\x64\x61ta\x18\x04 \x03(\x0b\x32\x15.mgmtd.YangCfgDataReq\x12\x17\n\x0fimplicit_commit\x18\x05 \x02(\x08\x12(\n\x0c\x63ommit_ds_id\x18\x06 \x02(\x0e\x32\x12.mgmtd.DatastoreId\"\x99\x01\n\x10\x46\x65SetConfigReply\x12\x12\n\nsession_id\x18\x01 \x02(\x04\x12!\n\x05\x64s_id\x18\x02 \x02(\x0e\x32\x12.mgmtd.DatastoreId\x12\x0e\n\x06req_id\x18\x03 \x02(\x04\x12\x0f\n\x07success\x18\x04 \x02(\x08\x12\x17\n\x0fimplicit_commit\x18\x05 \x02(\x08\x12\x14\n\x0c\x65rror_if_any\x18\x06 \x01(\t\"\xab\x01\n\x11\x46\x65\x43ommitConfigReq\x12\x12\n\nsession_id\x18\x01 \x02(\x04\x12%\n\tsrc_ds_id\x18\x02 \x02(\x0e\x32\x12.mgmtd.DatastoreId\x12%\n\tdst_ds_id\x18\x03 \x02(\x0e\x32\x12.mgmtd.DatastoreId\x12\x0e\n\x06req_id\x18\x04 \x02(\x04\x12\x15\n\rvalidate_only\x18\x05 \x02(\x08\x12\r\n\x05\x61\x62ort\x18\x06 \x02(\x08\"\xd4\x01\n\x13\x46\x65\x43ommitConfigReply\x12\x12\n\nsession_id\x18\x01 \x02(\x04\x12%\n\tsrc_ds_id\x18\x02 \x02(\x0e\x32\x12.mgmtd.DatastoreId\x12%\n\tdst_ds_id\x18\x03 \x02(\x0e\x32\x12.mgmtd.DatastoreId\x12\x0e\n\x06req_id\x18\x04 \x02(\x04\x12\x15\n\rvalidate_only\x18\x05 \x02(\x08\x12\x0f\n\x07success\x18\x06 \x02(\x08\x12\r\n\x05\x61\x62ort\x18\x07 \x02(\x08\x12\x14\n\x0c\x65rror_if_any\x18\x08 \x01(\t\"\x86\x01\n\x08\x46\x65GetReq\x12\x12\n\nsession_id\x18\x01 \x02(\x04\x12\x0e\n\x06\x63onfig\x18\x02 \x02(\x08\x12!\n\x05\x64s_id\x18\x03 \x02(\x0e\x32\x12.mgmtd.DatastoreId\x12\x0e\n\x06req_id\x18\x04 \x02(\x04\x12#\n\x04\x64\x61ta\x18\x05 \x03(\x0b\x32\x15.mgmtd.YangGetDataReq\"\xae\x01\n\nFeGetReply\x12\x12\n\nsession_id\x18\x01 \x02(\x04\x12\x0e\n\x06\x63onfig\x18\x02 \x02(\x08\x12!\n\x05\x64s_id\x18\x03 \x02(\x0e\x32\x12.mgmtd.DatastoreId\x12\x0e\n\x06req_id\x18\x04 \x02(\x04\x12\x0f\n\x07success\x18\x05 \x02(\x08\x12\x14\n\x0c\x65rror_if_any\x18\x06 \x01(\t\x12\"\n\x04\x64\x61ta\x18\x07 \x01(\x0b\x32\x14.mgmtd.YangDataReply\"0\n\x0f\x46\x65NotifyDataReq\x12\x1d\n\x04\x64\x61ta\x18\x01 \x03(\x0b\x32\x0f.mgmtd.YangData\"\x9c\x01\n\x13\x46\x65RegisterNotifyReq\x12\x12\n\nsession_id\x18\x01 \x02(\x04\x12!\n\x05\x64s_id\x18\x02 \x02(\x0e\x32\x12.mgmtd.DatastoreId\x12\x14\n\x0cregister_req\x18\x03 \x02(\x08\x12\x0e\n\x06req_id\x18\x04 \x02(\x04\x12(\n\ndata_xpath\x18\x05 \x03(\x0b\x32\x14.mgmtd.YangDataXPath\"\xf0\x04\n\tFeMessage\x12,\n\x0cregister_req\x18\x02 \x01(\x0b\x32\x14.mgmtd.FeRegisterReqH\x00\x12*\n\x0bsession_req\x18\x03 \x01(\x0b\x32\x13.mgmtd.FeSessionReqH\x00\x12.\n\rsession_reply\x18\x04 \x01(\x0b\x32\x15.mgmtd.FeSessionReplyH\x00\x12(\n\nlockds_req\x18\x05 \x01(\x0b\x32\x12.mgmtd.FeLockDsReqH\x00\x12,\n\x0clockds_reply\x18\x06 \x01(\x0b\x32\x14.mgmtd.FeLockDsReplyH\x00\x12+\n\nsetcfg_req\x18\x07 \x01(\x0b\x32\x15.mgmtd.FeSetConfigReqH\x00\x12/\n\x0csetcfg_reply\x18\x08 \x01(\x0b\x32\x17.mgmtd.FeSetConfigReplyH\x00\x12/\n\x0b\x63ommcfg_req\x18\t \x01(\x0b\x32\x18.mgmtd.FeCommitConfigReqH\x00\x12\x33\n\rcommcfg_reply\x18\n \x01(\x0b\x32\x1a.mgmtd.FeCommitConfigReplyH\x00\x12\"\n\x07get_req\x18\x0b \x01(\x0b\x32\x0f.mgmtd.FeGetReqH\x00\x12&\n\tget_reply\x18\x0c \x01(\x0b\x32\x11.mgmtd.FeGetReplyH\x00\x12\x31\n\x0fnotify_data_req\x18\x0f \x01(\x0b\x32\x16.mgmtd.FeNotifyDataReqH\x00\x12\x33\n\rregnotify_req\x18\x10 \x01(\x0b\x32\x1a.mgmtd.FeRegisterNotifyReqH\x00\x42\t\n\x07message*B\n\x0e\x43\x66gDataReqType\x12\x11\n\rREQ_TYPE_NONE\x10\x00\x12\x0c\n\x08SET_DATA\x10\x01\x12\x0f\n\x0b\x44\x45LETE_DATA\x10\x02*`\n\x0b\x44\x61tastoreId\x12\x0b\n\x07\x44S_NONE\x10\x00\x12\x0e\n\nRUNNING_DS\x10\x01\x12\x10\n\x0c\x43\x41NDIDATE_DS\x10\x02\x12\x12\n\x0eOPERATIONAL_DS\x10\x03\x12\x0e\n\nSTARTUP_DS\x10\x04' +) + +_CFGDATAREQTYPE = _descriptor.EnumDescriptor( + name='CfgDataReqType', + full_name='mgmtd.CfgDataReqType', + filename=None, + file=DESCRIPTOR, + create_key=_descriptor._internal_create_key, + values=[ + _descriptor.EnumValueDescriptor( + name='REQ_TYPE_NONE', index=0, number=0, + serialized_options=None, + type=None, + create_key=_descriptor._internal_create_key), + _descriptor.EnumValueDescriptor( + name='SET_DATA', index=1, number=1, + serialized_options=None, + type=None, + create_key=_descriptor._internal_create_key), + _descriptor.EnumValueDescriptor( + name='DELETE_DATA', index=2, number=2, + serialized_options=None, + type=None, + create_key=_descriptor._internal_create_key), + ], + containing_type=None, + serialized_options=None, + serialized_start=3674, + serialized_end=3740, +) +_sym_db.RegisterEnumDescriptor(_CFGDATAREQTYPE) + +CfgDataReqType = enum_type_wrapper.EnumTypeWrapper(_CFGDATAREQTYPE) +_DATASTOREID = _descriptor.EnumDescriptor( + name='DatastoreId', + full_name='mgmtd.DatastoreId', + filename=None, + file=DESCRIPTOR, + create_key=_descriptor._internal_create_key, + values=[ + _descriptor.EnumValueDescriptor( + name='DS_NONE', index=0, number=0, + serialized_options=None, + type=None, + create_key=_descriptor._internal_create_key), + _descriptor.EnumValueDescriptor( + name='RUNNING_DS', index=1, number=1, + serialized_options=None, + type=None, + create_key=_descriptor._internal_create_key), + _descriptor.EnumValueDescriptor( + name='CANDIDATE_DS', index=2, number=2, + serialized_options=None, + type=None, + create_key=_descriptor._internal_create_key), + _descriptor.EnumValueDescriptor( + name='OPERATIONAL_DS', index=3, number=3, + serialized_options=None, + type=None, + create_key=_descriptor._internal_create_key), + _descriptor.EnumValueDescriptor( + name='STARTUP_DS', index=4, number=4, + serialized_options=None, + type=None, + create_key=_descriptor._internal_create_key), + ], + containing_type=None, + serialized_options=None, + serialized_start=3742, + serialized_end=3838, +) +_sym_db.RegisterEnumDescriptor(_DATASTOREID) + +DatastoreId = enum_type_wrapper.EnumTypeWrapper(_DATASTOREID) +REQ_TYPE_NONE = 0 +SET_DATA = 1 +DELETE_DATA = 2 +DS_NONE = 0 +RUNNING_DS = 1 +CANDIDATE_DS = 2 +OPERATIONAL_DS = 3 +STARTUP_DS = 4 + + + +_YANGDATAXPATH = _descriptor.Descriptor( + name='YangDataXPath', + full_name='mgmtd.YangDataXPath', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='xpath', full_name='mgmtd.YangDataXPath.xpath', index=0, + number=1, type=9, cpp_type=9, label=2, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=21, + serialized_end=51, +) + + +_YANGDATAVALUE = _descriptor.Descriptor( + name='YangDataValue', + full_name='mgmtd.YangDataValue', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='encoded_str_val', full_name='mgmtd.YangDataValue.encoded_str_val', index=0, + number=100, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + _descriptor.OneofDescriptor( + name='value', full_name='mgmtd.YangDataValue.value', + index=0, containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[]), + ], + serialized_start=53, + serialized_end=104, +) + + +_YANGDATA = _descriptor.Descriptor( + name='YangData', + full_name='mgmtd.YangData', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='xpath', full_name='mgmtd.YangData.xpath', index=0, + number=1, type=9, cpp_type=9, label=2, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='value', full_name='mgmtd.YangData.value', index=1, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=106, + serialized_end=168, +) + + +_YANGCFGDATAREQ = _descriptor.Descriptor( + name='YangCfgDataReq', + full_name='mgmtd.YangCfgDataReq', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='data', full_name='mgmtd.YangCfgDataReq.data', index=0, + number=1, type=11, cpp_type=10, label=2, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='req_type', full_name='mgmtd.YangCfgDataReq.req_type', index=1, + number=2, type=14, cpp_type=8, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=170, + serialized_end=258, +) + + +_YANGGETDATAREQ = _descriptor.Descriptor( + name='YangGetDataReq', + full_name='mgmtd.YangGetDataReq', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='data', full_name='mgmtd.YangGetDataReq.data', index=0, + number=1, type=11, cpp_type=10, label=2, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='next_indx', full_name='mgmtd.YangGetDataReq.next_indx', index=1, + number=2, type=3, cpp_type=2, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=260, + serialized_end=326, +) + + +_BESUBSCRIBEREQ = _descriptor.Descriptor( + name='BeSubscribeReq', + full_name='mgmtd.BeSubscribeReq', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='client_name', full_name='mgmtd.BeSubscribeReq.client_name', index=0, + number=1, type=9, cpp_type=9, label=2, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='subscribe_xpaths', full_name='mgmtd.BeSubscribeReq.subscribe_xpaths', index=1, + number=2, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='xpath_reg', full_name='mgmtd.BeSubscribeReq.xpath_reg', index=2, + number=3, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=328, + serialized_end=410, +) + + +_BESUBSCRIBEREPLY = _descriptor.Descriptor( + name='BeSubscribeReply', + full_name='mgmtd.BeSubscribeReply', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='success', full_name='mgmtd.BeSubscribeReply.success', index=0, + number=1, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=412, + serialized_end=447, +) + + +_BETXNREQ = _descriptor.Descriptor( + name='BeTxnReq', + full_name='mgmtd.BeTxnReq', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='txn_id', full_name='mgmtd.BeTxnReq.txn_id', index=0, + number=1, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='create', full_name='mgmtd.BeTxnReq.create', index=1, + number=2, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=449, + serialized_end=491, +) + + +_BETXNREPLY = _descriptor.Descriptor( + name='BeTxnReply', + full_name='mgmtd.BeTxnReply', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='txn_id', full_name='mgmtd.BeTxnReply.txn_id', index=0, + number=1, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='create', full_name='mgmtd.BeTxnReply.create', index=1, + number=2, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='success', full_name='mgmtd.BeTxnReply.success', index=2, + number=3, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=493, + serialized_end=554, +) + + +_BECFGDATACREATEREQ = _descriptor.Descriptor( + name='BeCfgDataCreateReq', + full_name='mgmtd.BeCfgDataCreateReq', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='txn_id', full_name='mgmtd.BeCfgDataCreateReq.txn_id', index=0, + number=1, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='data_req', full_name='mgmtd.BeCfgDataCreateReq.data_req', index=1, + number=2, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='end_of_data', full_name='mgmtd.BeCfgDataCreateReq.end_of_data', index=2, + number=3, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=556, + serialized_end=654, +) + + +_BECFGDATACREATEREPLY = _descriptor.Descriptor( + name='BeCfgDataCreateReply', + full_name='mgmtd.BeCfgDataCreateReply', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='txn_id', full_name='mgmtd.BeCfgDataCreateReply.txn_id', index=0, + number=1, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='success', full_name='mgmtd.BeCfgDataCreateReply.success', index=1, + number=2, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='error_if_any', full_name='mgmtd.BeCfgDataCreateReply.error_if_any', index=2, + number=3, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=656, + serialized_end=733, +) + + +_BECFGDATAAPPLYREQ = _descriptor.Descriptor( + name='BeCfgDataApplyReq', + full_name='mgmtd.BeCfgDataApplyReq', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='txn_id', full_name='mgmtd.BeCfgDataApplyReq.txn_id', index=0, + number=1, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=735, + serialized_end=770, +) + + +_BECFGDATAAPPLYREPLY = _descriptor.Descriptor( + name='BeCfgDataApplyReply', + full_name='mgmtd.BeCfgDataApplyReply', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='txn_id', full_name='mgmtd.BeCfgDataApplyReply.txn_id', index=0, + number=1, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='success', full_name='mgmtd.BeCfgDataApplyReply.success', index=1, + number=2, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='error_if_any', full_name='mgmtd.BeCfgDataApplyReply.error_if_any', index=2, + number=3, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=772, + serialized_end=848, +) + + +_YANGDATAREPLY = _descriptor.Descriptor( + name='YangDataReply', + full_name='mgmtd.YangDataReply', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='data', full_name='mgmtd.YangDataReply.data', index=0, + number=1, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='next_indx', full_name='mgmtd.YangDataReply.next_indx', index=1, + number=2, type=3, cpp_type=2, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=850, + serialized_end=915, +) + + +_BEMESSAGE = _descriptor.Descriptor( + name='BeMessage', + full_name='mgmtd.BeMessage', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='subscr_req', full_name='mgmtd.BeMessage.subscr_req', index=0, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='subscr_reply', full_name='mgmtd.BeMessage.subscr_reply', index=1, + number=3, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='txn_req', full_name='mgmtd.BeMessage.txn_req', index=2, + number=4, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='txn_reply', full_name='mgmtd.BeMessage.txn_reply', index=3, + number=5, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='cfg_data_req', full_name='mgmtd.BeMessage.cfg_data_req', index=4, + number=6, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='cfg_data_reply', full_name='mgmtd.BeMessage.cfg_data_reply', index=5, + number=7, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='cfg_apply_req', full_name='mgmtd.BeMessage.cfg_apply_req', index=6, + number=8, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='cfg_apply_reply', full_name='mgmtd.BeMessage.cfg_apply_reply', index=7, + number=9, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + _descriptor.OneofDescriptor( + name='message', full_name='mgmtd.BeMessage.message', + index=0, containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[]), + ], + serialized_start=918, + serialized_end=1322, +) + + +_FEREGISTERREQ = _descriptor.Descriptor( + name='FeRegisterReq', + full_name='mgmtd.FeRegisterReq', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='client_name', full_name='mgmtd.FeRegisterReq.client_name', index=0, + number=1, type=9, cpp_type=9, label=2, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1324, + serialized_end=1360, +) + + +_FESESSIONREQ = _descriptor.Descriptor( + name='FeSessionReq', + full_name='mgmtd.FeSessionReq', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='create', full_name='mgmtd.FeSessionReq.create', index=0, + number=1, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='client_conn_id', full_name='mgmtd.FeSessionReq.client_conn_id', index=1, + number=2, type=4, cpp_type=4, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='session_id', full_name='mgmtd.FeSessionReq.session_id', index=2, + number=3, type=4, cpp_type=4, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + _descriptor.OneofDescriptor( + name='id', full_name='mgmtd.FeSessionReq.id', + index=0, containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[]), + ], + serialized_start=1362, + serialized_end=1446, +) + + +_FESESSIONREPLY = _descriptor.Descriptor( + name='FeSessionReply', + full_name='mgmtd.FeSessionReply', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='create', full_name='mgmtd.FeSessionReply.create', index=0, + number=1, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='success', full_name='mgmtd.FeSessionReply.success', index=1, + number=2, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='client_conn_id', full_name='mgmtd.FeSessionReply.client_conn_id', index=2, + number=3, type=4, cpp_type=4, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='session_id', full_name='mgmtd.FeSessionReply.session_id', index=3, + number=4, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1448, + serialized_end=1541, +) + + +_FELOCKDSREQ = _descriptor.Descriptor( + name='FeLockDsReq', + full_name='mgmtd.FeLockDsReq', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='session_id', full_name='mgmtd.FeLockDsReq.session_id', index=0, + number=1, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='req_id', full_name='mgmtd.FeLockDsReq.req_id', index=1, + number=2, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='ds_id', full_name='mgmtd.FeLockDsReq.ds_id', index=2, + number=3, type=14, cpp_type=8, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='lock', full_name='mgmtd.FeLockDsReq.lock', index=3, + number=4, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1543, + serialized_end=1641, +) + + +_FELOCKDSREPLY = _descriptor.Descriptor( + name='FeLockDsReply', + full_name='mgmtd.FeLockDsReply', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='session_id', full_name='mgmtd.FeLockDsReply.session_id', index=0, + number=1, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='req_id', full_name='mgmtd.FeLockDsReply.req_id', index=1, + number=2, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='ds_id', full_name='mgmtd.FeLockDsReply.ds_id', index=2, + number=3, type=14, cpp_type=8, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='lock', full_name='mgmtd.FeLockDsReply.lock', index=3, + number=4, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='success', full_name='mgmtd.FeLockDsReply.success', index=4, + number=5, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='error_if_any', full_name='mgmtd.FeLockDsReply.error_if_any', index=5, + number=6, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1644, + serialized_end=1783, +) + + +_FESETCONFIGREQ = _descriptor.Descriptor( + name='FeSetConfigReq', + full_name='mgmtd.FeSetConfigReq', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='session_id', full_name='mgmtd.FeSetConfigReq.session_id', index=0, + number=1, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='ds_id', full_name='mgmtd.FeSetConfigReq.ds_id', index=1, + number=2, type=14, cpp_type=8, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='req_id', full_name='mgmtd.FeSetConfigReq.req_id', index=2, + number=3, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='data', full_name='mgmtd.FeSetConfigReq.data', index=3, + number=4, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='implicit_commit', full_name='mgmtd.FeSetConfigReq.implicit_commit', index=4, + number=5, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='commit_ds_id', full_name='mgmtd.FeSetConfigReq.commit_ds_id', index=5, + number=6, type=14, cpp_type=8, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1786, + serialized_end=1977, +) + + +_FESETCONFIGREPLY = _descriptor.Descriptor( + name='FeSetConfigReply', + full_name='mgmtd.FeSetConfigReply', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='session_id', full_name='mgmtd.FeSetConfigReply.session_id', index=0, + number=1, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='ds_id', full_name='mgmtd.FeSetConfigReply.ds_id', index=1, + number=2, type=14, cpp_type=8, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='req_id', full_name='mgmtd.FeSetConfigReply.req_id', index=2, + number=3, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='success', full_name='mgmtd.FeSetConfigReply.success', index=3, + number=4, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='implicit_commit', full_name='mgmtd.FeSetConfigReply.implicit_commit', index=4, + number=5, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='error_if_any', full_name='mgmtd.FeSetConfigReply.error_if_any', index=5, + number=6, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1980, + serialized_end=2133, +) + + +_FECOMMITCONFIGREQ = _descriptor.Descriptor( + name='FeCommitConfigReq', + full_name='mgmtd.FeCommitConfigReq', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='session_id', full_name='mgmtd.FeCommitConfigReq.session_id', index=0, + number=1, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='src_ds_id', full_name='mgmtd.FeCommitConfigReq.src_ds_id', index=1, + number=2, type=14, cpp_type=8, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='dst_ds_id', full_name='mgmtd.FeCommitConfigReq.dst_ds_id', index=2, + number=3, type=14, cpp_type=8, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='req_id', full_name='mgmtd.FeCommitConfigReq.req_id', index=3, + number=4, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='validate_only', full_name='mgmtd.FeCommitConfigReq.validate_only', index=4, + number=5, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='abort', full_name='mgmtd.FeCommitConfigReq.abort', index=5, + number=6, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=2136, + serialized_end=2307, +) + + +_FECOMMITCONFIGREPLY = _descriptor.Descriptor( + name='FeCommitConfigReply', + full_name='mgmtd.FeCommitConfigReply', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='session_id', full_name='mgmtd.FeCommitConfigReply.session_id', index=0, + number=1, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='src_ds_id', full_name='mgmtd.FeCommitConfigReply.src_ds_id', index=1, + number=2, type=14, cpp_type=8, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='dst_ds_id', full_name='mgmtd.FeCommitConfigReply.dst_ds_id', index=2, + number=3, type=14, cpp_type=8, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='req_id', full_name='mgmtd.FeCommitConfigReply.req_id', index=3, + number=4, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='validate_only', full_name='mgmtd.FeCommitConfigReply.validate_only', index=4, + number=5, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='success', full_name='mgmtd.FeCommitConfigReply.success', index=5, + number=6, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='abort', full_name='mgmtd.FeCommitConfigReply.abort', index=6, + number=7, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='error_if_any', full_name='mgmtd.FeCommitConfigReply.error_if_any', index=7, + number=8, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=2310, + serialized_end=2522, +) + + +_FEGETREQ = _descriptor.Descriptor( + name='FeGetReq', + full_name='mgmtd.FeGetReq', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='session_id', full_name='mgmtd.FeGetReq.session_id', index=0, + number=1, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='config', full_name='mgmtd.FeGetReq.config', index=1, + number=2, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='ds_id', full_name='mgmtd.FeGetReq.ds_id', index=2, + number=3, type=14, cpp_type=8, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='req_id', full_name='mgmtd.FeGetReq.req_id', index=3, + number=4, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='data', full_name='mgmtd.FeGetReq.data', index=4, + number=5, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=2525, + serialized_end=2659, +) + + +_FEGETREPLY = _descriptor.Descriptor( + name='FeGetReply', + full_name='mgmtd.FeGetReply', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='session_id', full_name='mgmtd.FeGetReply.session_id', index=0, + number=1, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='config', full_name='mgmtd.FeGetReply.config', index=1, + number=2, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='ds_id', full_name='mgmtd.FeGetReply.ds_id', index=2, + number=3, type=14, cpp_type=8, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='req_id', full_name='mgmtd.FeGetReply.req_id', index=3, + number=4, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='success', full_name='mgmtd.FeGetReply.success', index=4, + number=5, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='error_if_any', full_name='mgmtd.FeGetReply.error_if_any', index=5, + number=6, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='data', full_name='mgmtd.FeGetReply.data', index=6, + number=7, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=2662, + serialized_end=2836, +) + + +_FENOTIFYDATAREQ = _descriptor.Descriptor( + name='FeNotifyDataReq', + full_name='mgmtd.FeNotifyDataReq', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='data', full_name='mgmtd.FeNotifyDataReq.data', index=0, + number=1, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=2838, + serialized_end=2886, +) + + +_FEREGISTERNOTIFYREQ = _descriptor.Descriptor( + name='FeRegisterNotifyReq', + full_name='mgmtd.FeRegisterNotifyReq', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='session_id', full_name='mgmtd.FeRegisterNotifyReq.session_id', index=0, + number=1, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='ds_id', full_name='mgmtd.FeRegisterNotifyReq.ds_id', index=1, + number=2, type=14, cpp_type=8, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='register_req', full_name='mgmtd.FeRegisterNotifyReq.register_req', index=2, + number=3, type=8, cpp_type=7, label=2, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='req_id', full_name='mgmtd.FeRegisterNotifyReq.req_id', index=3, + number=4, type=4, cpp_type=4, label=2, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='data_xpath', full_name='mgmtd.FeRegisterNotifyReq.data_xpath', index=4, + number=5, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=2889, + serialized_end=3045, +) + + +_FEMESSAGE = _descriptor.Descriptor( + name='FeMessage', + full_name='mgmtd.FeMessage', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='register_req', full_name='mgmtd.FeMessage.register_req', index=0, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='session_req', full_name='mgmtd.FeMessage.session_req', index=1, + number=3, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='session_reply', full_name='mgmtd.FeMessage.session_reply', index=2, + number=4, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='lockds_req', full_name='mgmtd.FeMessage.lockds_req', index=3, + number=5, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='lockds_reply', full_name='mgmtd.FeMessage.lockds_reply', index=4, + number=6, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='setcfg_req', full_name='mgmtd.FeMessage.setcfg_req', index=5, + number=7, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='setcfg_reply', full_name='mgmtd.FeMessage.setcfg_reply', index=6, + number=8, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='commcfg_req', full_name='mgmtd.FeMessage.commcfg_req', index=7, + number=9, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='commcfg_reply', full_name='mgmtd.FeMessage.commcfg_reply', index=8, + number=10, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='get_req', full_name='mgmtd.FeMessage.get_req', index=9, + number=11, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='get_reply', full_name='mgmtd.FeMessage.get_reply', index=10, + number=12, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='notify_data_req', full_name='mgmtd.FeMessage.notify_data_req', index=11, + number=15, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='regnotify_req', full_name='mgmtd.FeMessage.regnotify_req', index=12, + number=16, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + _descriptor.OneofDescriptor( + name='message', full_name='mgmtd.FeMessage.message', + index=0, containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[]), + ], + serialized_start=3048, + serialized_end=3672, +) + +_YANGDATAVALUE.oneofs_by_name['value'].fields.append( + _YANGDATAVALUE.fields_by_name['encoded_str_val']) +_YANGDATAVALUE.fields_by_name['encoded_str_val'].containing_oneof = _YANGDATAVALUE.oneofs_by_name['value'] +_YANGDATA.fields_by_name['value'].message_type = _YANGDATAVALUE +_YANGCFGDATAREQ.fields_by_name['data'].message_type = _YANGDATA +_YANGCFGDATAREQ.fields_by_name['req_type'].enum_type = _CFGDATAREQTYPE +_YANGGETDATAREQ.fields_by_name['data'].message_type = _YANGDATA +_BECFGDATACREATEREQ.fields_by_name['data_req'].message_type = _YANGCFGDATAREQ +_YANGDATAREPLY.fields_by_name['data'].message_type = _YANGDATA +_BEMESSAGE.fields_by_name['subscr_req'].message_type = _BESUBSCRIBEREQ +_BEMESSAGE.fields_by_name['subscr_reply'].message_type = _BESUBSCRIBEREPLY +_BEMESSAGE.fields_by_name['txn_req'].message_type = _BETXNREQ +_BEMESSAGE.fields_by_name['txn_reply'].message_type = _BETXNREPLY +_BEMESSAGE.fields_by_name['cfg_data_req'].message_type = _BECFGDATACREATEREQ +_BEMESSAGE.fields_by_name['cfg_data_reply'].message_type = _BECFGDATACREATEREPLY +_BEMESSAGE.fields_by_name['cfg_apply_req'].message_type = _BECFGDATAAPPLYREQ +_BEMESSAGE.fields_by_name['cfg_apply_reply'].message_type = _BECFGDATAAPPLYREPLY +_BEMESSAGE.oneofs_by_name['message'].fields.append( + _BEMESSAGE.fields_by_name['subscr_req']) +_BEMESSAGE.fields_by_name['subscr_req'].containing_oneof = _BEMESSAGE.oneofs_by_name['message'] +_BEMESSAGE.oneofs_by_name['message'].fields.append( + _BEMESSAGE.fields_by_name['subscr_reply']) +_BEMESSAGE.fields_by_name['subscr_reply'].containing_oneof = _BEMESSAGE.oneofs_by_name['message'] +_BEMESSAGE.oneofs_by_name['message'].fields.append( + _BEMESSAGE.fields_by_name['txn_req']) +_BEMESSAGE.fields_by_name['txn_req'].containing_oneof = _BEMESSAGE.oneofs_by_name['message'] +_BEMESSAGE.oneofs_by_name['message'].fields.append( + _BEMESSAGE.fields_by_name['txn_reply']) +_BEMESSAGE.fields_by_name['txn_reply'].containing_oneof = _BEMESSAGE.oneofs_by_name['message'] +_BEMESSAGE.oneofs_by_name['message'].fields.append( + _BEMESSAGE.fields_by_name['cfg_data_req']) +_BEMESSAGE.fields_by_name['cfg_data_req'].containing_oneof = _BEMESSAGE.oneofs_by_name['message'] +_BEMESSAGE.oneofs_by_name['message'].fields.append( + _BEMESSAGE.fields_by_name['cfg_data_reply']) +_BEMESSAGE.fields_by_name['cfg_data_reply'].containing_oneof = _BEMESSAGE.oneofs_by_name['message'] +_BEMESSAGE.oneofs_by_name['message'].fields.append( + _BEMESSAGE.fields_by_name['cfg_apply_req']) +_BEMESSAGE.fields_by_name['cfg_apply_req'].containing_oneof = _BEMESSAGE.oneofs_by_name['message'] +_BEMESSAGE.oneofs_by_name['message'].fields.append( + _BEMESSAGE.fields_by_name['cfg_apply_reply']) +_BEMESSAGE.fields_by_name['cfg_apply_reply'].containing_oneof = _BEMESSAGE.oneofs_by_name['message'] +_FESESSIONREQ.oneofs_by_name['id'].fields.append( + _FESESSIONREQ.fields_by_name['client_conn_id']) +_FESESSIONREQ.fields_by_name['client_conn_id'].containing_oneof = _FESESSIONREQ.oneofs_by_name['id'] +_FESESSIONREQ.oneofs_by_name['id'].fields.append( + _FESESSIONREQ.fields_by_name['session_id']) +_FESESSIONREQ.fields_by_name['session_id'].containing_oneof = _FESESSIONREQ.oneofs_by_name['id'] +_FELOCKDSREQ.fields_by_name['ds_id'].enum_type = _DATASTOREID +_FELOCKDSREPLY.fields_by_name['ds_id'].enum_type = _DATASTOREID +_FESETCONFIGREQ.fields_by_name['ds_id'].enum_type = _DATASTOREID +_FESETCONFIGREQ.fields_by_name['data'].message_type = _YANGCFGDATAREQ +_FESETCONFIGREQ.fields_by_name['commit_ds_id'].enum_type = _DATASTOREID +_FESETCONFIGREPLY.fields_by_name['ds_id'].enum_type = _DATASTOREID +_FECOMMITCONFIGREQ.fields_by_name['src_ds_id'].enum_type = _DATASTOREID +_FECOMMITCONFIGREQ.fields_by_name['dst_ds_id'].enum_type = _DATASTOREID +_FECOMMITCONFIGREPLY.fields_by_name['src_ds_id'].enum_type = _DATASTOREID +_FECOMMITCONFIGREPLY.fields_by_name['dst_ds_id'].enum_type = _DATASTOREID +_FEGETREQ.fields_by_name['ds_id'].enum_type = _DATASTOREID +_FEGETREQ.fields_by_name['data'].message_type = _YANGGETDATAREQ +_FEGETREPLY.fields_by_name['ds_id'].enum_type = _DATASTOREID +_FEGETREPLY.fields_by_name['data'].message_type = _YANGDATAREPLY +_FENOTIFYDATAREQ.fields_by_name['data'].message_type = _YANGDATA +_FEREGISTERNOTIFYREQ.fields_by_name['ds_id'].enum_type = _DATASTOREID +_FEREGISTERNOTIFYREQ.fields_by_name['data_xpath'].message_type = _YANGDATAXPATH +_FEMESSAGE.fields_by_name['register_req'].message_type = _FEREGISTERREQ +_FEMESSAGE.fields_by_name['session_req'].message_type = _FESESSIONREQ +_FEMESSAGE.fields_by_name['session_reply'].message_type = _FESESSIONREPLY +_FEMESSAGE.fields_by_name['lockds_req'].message_type = _FELOCKDSREQ +_FEMESSAGE.fields_by_name['lockds_reply'].message_type = _FELOCKDSREPLY +_FEMESSAGE.fields_by_name['setcfg_req'].message_type = _FESETCONFIGREQ +_FEMESSAGE.fields_by_name['setcfg_reply'].message_type = _FESETCONFIGREPLY +_FEMESSAGE.fields_by_name['commcfg_req'].message_type = _FECOMMITCONFIGREQ +_FEMESSAGE.fields_by_name['commcfg_reply'].message_type = _FECOMMITCONFIGREPLY +_FEMESSAGE.fields_by_name['get_req'].message_type = _FEGETREQ +_FEMESSAGE.fields_by_name['get_reply'].message_type = _FEGETREPLY +_FEMESSAGE.fields_by_name['notify_data_req'].message_type = _FENOTIFYDATAREQ +_FEMESSAGE.fields_by_name['regnotify_req'].message_type = _FEREGISTERNOTIFYREQ +_FEMESSAGE.oneofs_by_name['message'].fields.append( + _FEMESSAGE.fields_by_name['register_req']) +_FEMESSAGE.fields_by_name['register_req'].containing_oneof = _FEMESSAGE.oneofs_by_name['message'] +_FEMESSAGE.oneofs_by_name['message'].fields.append( + _FEMESSAGE.fields_by_name['session_req']) +_FEMESSAGE.fields_by_name['session_req'].containing_oneof = _FEMESSAGE.oneofs_by_name['message'] +_FEMESSAGE.oneofs_by_name['message'].fields.append( + _FEMESSAGE.fields_by_name['session_reply']) +_FEMESSAGE.fields_by_name['session_reply'].containing_oneof = _FEMESSAGE.oneofs_by_name['message'] +_FEMESSAGE.oneofs_by_name['message'].fields.append( + _FEMESSAGE.fields_by_name['lockds_req']) +_FEMESSAGE.fields_by_name['lockds_req'].containing_oneof = _FEMESSAGE.oneofs_by_name['message'] +_FEMESSAGE.oneofs_by_name['message'].fields.append( + _FEMESSAGE.fields_by_name['lockds_reply']) +_FEMESSAGE.fields_by_name['lockds_reply'].containing_oneof = _FEMESSAGE.oneofs_by_name['message'] +_FEMESSAGE.oneofs_by_name['message'].fields.append( + _FEMESSAGE.fields_by_name['setcfg_req']) +_FEMESSAGE.fields_by_name['setcfg_req'].containing_oneof = _FEMESSAGE.oneofs_by_name['message'] +_FEMESSAGE.oneofs_by_name['message'].fields.append( + _FEMESSAGE.fields_by_name['setcfg_reply']) +_FEMESSAGE.fields_by_name['setcfg_reply'].containing_oneof = _FEMESSAGE.oneofs_by_name['message'] +_FEMESSAGE.oneofs_by_name['message'].fields.append( + _FEMESSAGE.fields_by_name['commcfg_req']) +_FEMESSAGE.fields_by_name['commcfg_req'].containing_oneof = _FEMESSAGE.oneofs_by_name['message'] +_FEMESSAGE.oneofs_by_name['message'].fields.append( + _FEMESSAGE.fields_by_name['commcfg_reply']) +_FEMESSAGE.fields_by_name['commcfg_reply'].containing_oneof = _FEMESSAGE.oneofs_by_name['message'] +_FEMESSAGE.oneofs_by_name['message'].fields.append( + _FEMESSAGE.fields_by_name['get_req']) +_FEMESSAGE.fields_by_name['get_req'].containing_oneof = _FEMESSAGE.oneofs_by_name['message'] +_FEMESSAGE.oneofs_by_name['message'].fields.append( + _FEMESSAGE.fields_by_name['get_reply']) +_FEMESSAGE.fields_by_name['get_reply'].containing_oneof = _FEMESSAGE.oneofs_by_name['message'] +_FEMESSAGE.oneofs_by_name['message'].fields.append( + _FEMESSAGE.fields_by_name['notify_data_req']) +_FEMESSAGE.fields_by_name['notify_data_req'].containing_oneof = _FEMESSAGE.oneofs_by_name['message'] +_FEMESSAGE.oneofs_by_name['message'].fields.append( + _FEMESSAGE.fields_by_name['regnotify_req']) +_FEMESSAGE.fields_by_name['regnotify_req'].containing_oneof = _FEMESSAGE.oneofs_by_name['message'] +DESCRIPTOR.message_types_by_name['YangDataXPath'] = _YANGDATAXPATH +DESCRIPTOR.message_types_by_name['YangDataValue'] = _YANGDATAVALUE +DESCRIPTOR.message_types_by_name['YangData'] = _YANGDATA +DESCRIPTOR.message_types_by_name['YangCfgDataReq'] = _YANGCFGDATAREQ +DESCRIPTOR.message_types_by_name['YangGetDataReq'] = _YANGGETDATAREQ +DESCRIPTOR.message_types_by_name['BeSubscribeReq'] = _BESUBSCRIBEREQ +DESCRIPTOR.message_types_by_name['BeSubscribeReply'] = _BESUBSCRIBEREPLY +DESCRIPTOR.message_types_by_name['BeTxnReq'] = _BETXNREQ +DESCRIPTOR.message_types_by_name['BeTxnReply'] = _BETXNREPLY +DESCRIPTOR.message_types_by_name['BeCfgDataCreateReq'] = _BECFGDATACREATEREQ +DESCRIPTOR.message_types_by_name['BeCfgDataCreateReply'] = _BECFGDATACREATEREPLY +DESCRIPTOR.message_types_by_name['BeCfgDataApplyReq'] = _BECFGDATAAPPLYREQ +DESCRIPTOR.message_types_by_name['BeCfgDataApplyReply'] = _BECFGDATAAPPLYREPLY +DESCRIPTOR.message_types_by_name['YangDataReply'] = _YANGDATAREPLY +DESCRIPTOR.message_types_by_name['BeMessage'] = _BEMESSAGE +DESCRIPTOR.message_types_by_name['FeRegisterReq'] = _FEREGISTERREQ +DESCRIPTOR.message_types_by_name['FeSessionReq'] = _FESESSIONREQ +DESCRIPTOR.message_types_by_name['FeSessionReply'] = _FESESSIONREPLY +DESCRIPTOR.message_types_by_name['FeLockDsReq'] = _FELOCKDSREQ +DESCRIPTOR.message_types_by_name['FeLockDsReply'] = _FELOCKDSREPLY +DESCRIPTOR.message_types_by_name['FeSetConfigReq'] = _FESETCONFIGREQ +DESCRIPTOR.message_types_by_name['FeSetConfigReply'] = _FESETCONFIGREPLY +DESCRIPTOR.message_types_by_name['FeCommitConfigReq'] = _FECOMMITCONFIGREQ +DESCRIPTOR.message_types_by_name['FeCommitConfigReply'] = _FECOMMITCONFIGREPLY +DESCRIPTOR.message_types_by_name['FeGetReq'] = _FEGETREQ +DESCRIPTOR.message_types_by_name['FeGetReply'] = _FEGETREPLY +DESCRIPTOR.message_types_by_name['FeNotifyDataReq'] = _FENOTIFYDATAREQ +DESCRIPTOR.message_types_by_name['FeRegisterNotifyReq'] = _FEREGISTERNOTIFYREQ +DESCRIPTOR.message_types_by_name['FeMessage'] = _FEMESSAGE +DESCRIPTOR.enum_types_by_name['CfgDataReqType'] = _CFGDATAREQTYPE +DESCRIPTOR.enum_types_by_name['DatastoreId'] = _DATASTOREID +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +YangDataXPath = _reflection.GeneratedProtocolMessageType('YangDataXPath', (_message.Message,), { + 'DESCRIPTOR' : _YANGDATAXPATH, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.YangDataXPath) + }) +_sym_db.RegisterMessage(YangDataXPath) + +YangDataValue = _reflection.GeneratedProtocolMessageType('YangDataValue', (_message.Message,), { + 'DESCRIPTOR' : _YANGDATAVALUE, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.YangDataValue) + }) +_sym_db.RegisterMessage(YangDataValue) + +YangData = _reflection.GeneratedProtocolMessageType('YangData', (_message.Message,), { + 'DESCRIPTOR' : _YANGDATA, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.YangData) + }) +_sym_db.RegisterMessage(YangData) + +YangCfgDataReq = _reflection.GeneratedProtocolMessageType('YangCfgDataReq', (_message.Message,), { + 'DESCRIPTOR' : _YANGCFGDATAREQ, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.YangCfgDataReq) + }) +_sym_db.RegisterMessage(YangCfgDataReq) + +YangGetDataReq = _reflection.GeneratedProtocolMessageType('YangGetDataReq', (_message.Message,), { + 'DESCRIPTOR' : _YANGGETDATAREQ, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.YangGetDataReq) + }) +_sym_db.RegisterMessage(YangGetDataReq) + +BeSubscribeReq = _reflection.GeneratedProtocolMessageType('BeSubscribeReq', (_message.Message,), { + 'DESCRIPTOR' : _BESUBSCRIBEREQ, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.BeSubscribeReq) + }) +_sym_db.RegisterMessage(BeSubscribeReq) + +BeSubscribeReply = _reflection.GeneratedProtocolMessageType('BeSubscribeReply', (_message.Message,), { + 'DESCRIPTOR' : _BESUBSCRIBEREPLY, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.BeSubscribeReply) + }) +_sym_db.RegisterMessage(BeSubscribeReply) + +BeTxnReq = _reflection.GeneratedProtocolMessageType('BeTxnReq', (_message.Message,), { + 'DESCRIPTOR' : _BETXNREQ, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.BeTxnReq) + }) +_sym_db.RegisterMessage(BeTxnReq) + +BeTxnReply = _reflection.GeneratedProtocolMessageType('BeTxnReply', (_message.Message,), { + 'DESCRIPTOR' : _BETXNREPLY, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.BeTxnReply) + }) +_sym_db.RegisterMessage(BeTxnReply) + +BeCfgDataCreateReq = _reflection.GeneratedProtocolMessageType('BeCfgDataCreateReq', (_message.Message,), { + 'DESCRIPTOR' : _BECFGDATACREATEREQ, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.BeCfgDataCreateReq) + }) +_sym_db.RegisterMessage(BeCfgDataCreateReq) + +BeCfgDataCreateReply = _reflection.GeneratedProtocolMessageType('BeCfgDataCreateReply', (_message.Message,), { + 'DESCRIPTOR' : _BECFGDATACREATEREPLY, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.BeCfgDataCreateReply) + }) +_sym_db.RegisterMessage(BeCfgDataCreateReply) + +BeCfgDataApplyReq = _reflection.GeneratedProtocolMessageType('BeCfgDataApplyReq', (_message.Message,), { + 'DESCRIPTOR' : _BECFGDATAAPPLYREQ, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.BeCfgDataApplyReq) + }) +_sym_db.RegisterMessage(BeCfgDataApplyReq) + +BeCfgDataApplyReply = _reflection.GeneratedProtocolMessageType('BeCfgDataApplyReply', (_message.Message,), { + 'DESCRIPTOR' : _BECFGDATAAPPLYREPLY, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.BeCfgDataApplyReply) + }) +_sym_db.RegisterMessage(BeCfgDataApplyReply) + +YangDataReply = _reflection.GeneratedProtocolMessageType('YangDataReply', (_message.Message,), { + 'DESCRIPTOR' : _YANGDATAREPLY, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.YangDataReply) + }) +_sym_db.RegisterMessage(YangDataReply) + +BeMessage = _reflection.GeneratedProtocolMessageType('BeMessage', (_message.Message,), { + 'DESCRIPTOR' : _BEMESSAGE, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.BeMessage) + }) +_sym_db.RegisterMessage(BeMessage) + +FeRegisterReq = _reflection.GeneratedProtocolMessageType('FeRegisterReq', (_message.Message,), { + 'DESCRIPTOR' : _FEREGISTERREQ, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.FeRegisterReq) + }) +_sym_db.RegisterMessage(FeRegisterReq) + +FeSessionReq = _reflection.GeneratedProtocolMessageType('FeSessionReq', (_message.Message,), { + 'DESCRIPTOR' : _FESESSIONREQ, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.FeSessionReq) + }) +_sym_db.RegisterMessage(FeSessionReq) + +FeSessionReply = _reflection.GeneratedProtocolMessageType('FeSessionReply', (_message.Message,), { + 'DESCRIPTOR' : _FESESSIONREPLY, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.FeSessionReply) + }) +_sym_db.RegisterMessage(FeSessionReply) + +FeLockDsReq = _reflection.GeneratedProtocolMessageType('FeLockDsReq', (_message.Message,), { + 'DESCRIPTOR' : _FELOCKDSREQ, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.FeLockDsReq) + }) +_sym_db.RegisterMessage(FeLockDsReq) + +FeLockDsReply = _reflection.GeneratedProtocolMessageType('FeLockDsReply', (_message.Message,), { + 'DESCRIPTOR' : _FELOCKDSREPLY, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.FeLockDsReply) + }) +_sym_db.RegisterMessage(FeLockDsReply) + +FeSetConfigReq = _reflection.GeneratedProtocolMessageType('FeSetConfigReq', (_message.Message,), { + 'DESCRIPTOR' : _FESETCONFIGREQ, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.FeSetConfigReq) + }) +_sym_db.RegisterMessage(FeSetConfigReq) + +FeSetConfigReply = _reflection.GeneratedProtocolMessageType('FeSetConfigReply', (_message.Message,), { + 'DESCRIPTOR' : _FESETCONFIGREPLY, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.FeSetConfigReply) + }) +_sym_db.RegisterMessage(FeSetConfigReply) + +FeCommitConfigReq = _reflection.GeneratedProtocolMessageType('FeCommitConfigReq', (_message.Message,), { + 'DESCRIPTOR' : _FECOMMITCONFIGREQ, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.FeCommitConfigReq) + }) +_sym_db.RegisterMessage(FeCommitConfigReq) + +FeCommitConfigReply = _reflection.GeneratedProtocolMessageType('FeCommitConfigReply', (_message.Message,), { + 'DESCRIPTOR' : _FECOMMITCONFIGREPLY, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.FeCommitConfigReply) + }) +_sym_db.RegisterMessage(FeCommitConfigReply) + +FeGetReq = _reflection.GeneratedProtocolMessageType('FeGetReq', (_message.Message,), { + 'DESCRIPTOR' : _FEGETREQ, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.FeGetReq) + }) +_sym_db.RegisterMessage(FeGetReq) + +FeGetReply = _reflection.GeneratedProtocolMessageType('FeGetReply', (_message.Message,), { + 'DESCRIPTOR' : _FEGETREPLY, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.FeGetReply) + }) +_sym_db.RegisterMessage(FeGetReply) + +FeNotifyDataReq = _reflection.GeneratedProtocolMessageType('FeNotifyDataReq', (_message.Message,), { + 'DESCRIPTOR' : _FENOTIFYDATAREQ, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.FeNotifyDataReq) + }) +_sym_db.RegisterMessage(FeNotifyDataReq) + +FeRegisterNotifyReq = _reflection.GeneratedProtocolMessageType('FeRegisterNotifyReq', (_message.Message,), { + 'DESCRIPTOR' : _FEREGISTERNOTIFYREQ, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.FeRegisterNotifyReq) + }) +_sym_db.RegisterMessage(FeRegisterNotifyReq) + +FeMessage = _reflection.GeneratedProtocolMessageType('FeMessage', (_message.Message,), { + 'DESCRIPTOR' : _FEMESSAGE, + '__module__' : 'mgmt_pb2' + # @@protoc_insertion_point(class_scope:mgmtd.FeMessage) + }) +_sym_db.RegisterMessage(FeMessage) + + +# @@protoc_insertion_point(module_scope) diff --git a/tests/topotests/mgmt_fe_client/oper.py b/tests/topotests/mgmt_fe_client/oper.py new file mode 120000 index 0000000000..924439251a --- /dev/null +++ b/tests/topotests/mgmt_fe_client/oper.py @@ -0,0 +1 @@ +../mgmt_oper/oper.py \ No newline at end of file diff --git a/tests/topotests/mgmt_fe_client/r1/frr.conf b/tests/topotests/mgmt_fe_client/r1/frr.conf new file mode 100644 index 0000000000..cf8ba160f4 --- /dev/null +++ b/tests/topotests/mgmt_fe_client/r1/frr.conf @@ -0,0 +1,23 @@ +log timestamp precision 6 +log file frr.log + +no debug memstats-at-exit + +debug northbound notifications +debug northbound libyang +debug northbound events +debug northbound callbacks + +debug mgmt backend datastore frontend transaction +debug mgmt client frontend +debug mgmt client backend + +interface r1-eth0 + ip address 1.1.1.1/24 +exit + +interface r1-eth1 vrf red + ip address 3.3.3.1/24 +exit +ip route 11.11.11.11/32 1.1.1.2 +!ip route 13.13.13.13/32 3.3.3.2 vrf red \ No newline at end of file diff --git a/tests/topotests/mgmt_fe_client/test_client.py b/tests/topotests/mgmt_fe_client/test_client.py new file mode 100644 index 0000000000..8383e23bb6 --- /dev/null +++ b/tests/topotests/mgmt_fe_client/test_client.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# -*- coding: utf-8 eval: (blacken-mode 1) -*- +# SPDX-License-Identifier: ISC +# +# Copyright (c) 2021, LabN Consulting, L.L.C. +# Copyright (c) 2019-2020 by +# Donatas Abraitis <donatas.abraitis@gmail.com> +# +# noqa: E501 +# +""" +Test static route functionality +""" +import pytest +from lib.topogen import Topogen +from oper import check_kernel_32 + +pytestmark = [pytest.mark.staticd, pytest.mark.mgmtd] + + +@pytest.fixture(scope="module") +def tgen(request): + "Setup/Teardown the environment and provide tgen argument to tests" + + topodef = {"s1": ("r1",), "s2": ("r1",)} + + tgen = Topogen(topodef, request.module.__name__) + tgen.start_topology() + + router_list = tgen.routers() + for rname, router in router_list.items(): + # Setup VRF red + router.net.add_l3vrf("red", 10) + router.net.add_loop("lo-red") + router.net.attach_iface_to_l3vrf("lo-red", "red") + router.net.attach_iface_to_l3vrf(rname + "-eth1", "red") + router.load_frr_config("frr.conf") + + tgen.start_router() + yield tgen + tgen.stop_topology() + + +def test_oper_simple(tgen): + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"].net + check_kernel_32(r1, "11.11.11.11", 1, "") diff --git a/tests/topotests/mgmt_oper/oper-results/result-lib-vrf-default.json b/tests/topotests/mgmt_oper/oper-results/result-lib-vrf-default.json new file mode 100644 index 0000000000..435d7336fc --- /dev/null +++ b/tests/topotests/mgmt_oper/oper-results/result-lib-vrf-default.json @@ -0,0 +1,576 @@ +{ + "frr-vrf:lib": { + "vrf": [ + { + "name": "default", + "state": { + "id": "rubout", + "active": true + }, + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "11.0.0.0/8", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "blackhole", + "vrf": "rubout", + "gateway": "", + "interface": " ", + "bh-type": "null", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + }, + { + "prefix": "11.11.11.11/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "1.1.1.2", + "interface": "r1-eth0", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + }, + { + "prefix": "12.12.12.12/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "2.2.2.2", + "interface": "r1-eth1", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv4-multicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-unicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + }, + { + "prefix": "2001:1111::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2001:1111::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-multicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + }, + { + "prefix": "2001:1111::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2001:1111::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + } + ] + } + } + } + ] + } +} + diff --git a/tests/topotests/mgmt_oper/oper-results/result-lib-vrf-nokey.json b/tests/topotests/mgmt_oper/oper-results/result-lib-vrf-nokey.json new file mode 100644 index 0000000000..1a1f6480fa --- /dev/null +++ b/tests/topotests/mgmt_oper/oper-results/result-lib-vrf-nokey.json @@ -0,0 +1,1145 @@ +{ + "frr-vrf:lib": { + "vrf": [ + { + "name": "default", + "state": { + "id": "rubout", + "active": true + }, + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "11.0.0.0/8", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "blackhole", + "vrf": "rubout", + "gateway": "", + "interface": " ", + "bh-type": "null", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + }, + { + "prefix": "11.11.11.11/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "1.1.1.2", + "interface": "r1-eth0", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + }, + { + "prefix": "12.12.12.12/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "2.2.2.2", + "interface": "r1-eth1", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv4-multicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-unicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + }, + { + "prefix": "2001:1111::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2001:1111::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-multicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + }, + { + "prefix": "2001:1111::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2001:1111::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + } + ] + } + } + }, + { + "name": "red", + "state": { + "id": "rubout", + "active": true + }, + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 10, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "3.3.3.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "3.3.3.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "4.4.4.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "4.4.4.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "13.0.0.0/8", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "blackhole", + "vrf": "rubout", + "gateway": "", + "interface": " ", + "bh-type": "null", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + }, + { + "prefix": "13.13.13.13/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "3.3.3.2", + "interface": "r1-eth2", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + }, + { + "prefix": "14.14.14.14/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "4.4.4.2", + "interface": "r1-eth3", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv4-multicast", + "table-id": 10, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "3.3.3.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "3.3.3.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "4.4.4.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "4.4.4.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-unicast", + "table-id": 10, + "route": [ + { + "prefix": "::/0" + }, + { + "prefix": "2003:333::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2003:333::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2004:4444::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2004:4444::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-multicast", + "table-id": 10, + "route": [ + { + "prefix": "::/0" + }, + { + "prefix": "2003:333::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2003:333::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2004:4444::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2004:4444::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + } + ] + } + } + } + ] + } +} + diff --git a/tests/topotests/mgmt_oper/oper-results/result-lib-vrf-red.json b/tests/topotests/mgmt_oper/oper-results/result-lib-vrf-red.json new file mode 100644 index 0000000000..cfabd49c45 --- /dev/null +++ b/tests/topotests/mgmt_oper/oper-results/result-lib-vrf-red.json @@ -0,0 +1,576 @@ +{ + "frr-vrf:lib": { + "vrf": [ + { + "name": "red", + "state": { + "id": "rubout", + "active": true + }, + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 10, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "3.3.3.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "3.3.3.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "4.4.4.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "4.4.4.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "13.0.0.0/8", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "blackhole", + "vrf": "rubout", + "gateway": "", + "interface": " ", + "bh-type": "null", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + }, + { + "prefix": "13.13.13.13/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "3.3.3.2", + "interface": "r1-eth2", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + }, + { + "prefix": "14.14.14.14/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "4.4.4.2", + "interface": "r1-eth3", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv4-multicast", + "table-id": 10, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "3.3.3.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "3.3.3.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "4.4.4.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "4.4.4.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-unicast", + "table-id": 10, + "route": [ + { + "prefix": "::/0" + }, + { + "prefix": "2003:333::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2003:333::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2004:4444::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2004:4444::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-multicast", + "table-id": 10, + "route": [ + { + "prefix": "::/0" + }, + { + "prefix": "2003:333::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2003:333::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2004:4444::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2004:4444::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + } + ] + } + } + } + ] + } +} + diff --git a/tests/topotests/mgmt_oper/oper-results/result-lib-vrf-zebra-ribs.json b/tests/topotests/mgmt_oper/oper-results/result-lib-vrf-zebra-ribs.json new file mode 100644 index 0000000000..2e2b8ec7ad --- /dev/null +++ b/tests/topotests/mgmt_oper/oper-results/result-lib-vrf-zebra-ribs.json @@ -0,0 +1,572 @@ +{ + "frr-vrf:lib": { + "vrf": [ + { + "name": "default", + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "11.0.0.0/8", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "blackhole", + "vrf": "rubout", + "gateway": "", + "interface": " ", + "bh-type": "null", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + }, + { + "prefix": "11.11.11.11/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "1.1.1.2", + "interface": "r1-eth0", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + }, + { + "prefix": "12.12.12.12/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "2.2.2.2", + "interface": "r1-eth1", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv4-multicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-unicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + }, + { + "prefix": "2001:1111::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2001:1111::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-multicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + }, + { + "prefix": "2001:1111::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2001:1111::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + } + ] + } + } + } + ] + } +} + diff --git a/tests/topotests/mgmt_oper/oper-results/result-lib-vrf-zebra.json b/tests/topotests/mgmt_oper/oper-results/result-lib-vrf-zebra.json new file mode 100644 index 0000000000..2e2b8ec7ad --- /dev/null +++ b/tests/topotests/mgmt_oper/oper-results/result-lib-vrf-zebra.json @@ -0,0 +1,572 @@ +{ + "frr-vrf:lib": { + "vrf": [ + { + "name": "default", + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "11.0.0.0/8", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "blackhole", + "vrf": "rubout", + "gateway": "", + "interface": " ", + "bh-type": "null", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + }, + { + "prefix": "11.11.11.11/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "1.1.1.2", + "interface": "r1-eth0", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + }, + { + "prefix": "12.12.12.12/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "2.2.2.2", + "interface": "r1-eth1", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv4-multicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-unicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + }, + { + "prefix": "2001:1111::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2001:1111::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-multicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + }, + { + "prefix": "2001:1111::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2001:1111::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + } + ] + } + } + } + ] + } +} + diff --git a/tests/topotests/mgmt_oper/oper-results/result-lib.json b/tests/topotests/mgmt_oper/oper-results/result-lib.json new file mode 100644 index 0000000000..1a1f6480fa --- /dev/null +++ b/tests/topotests/mgmt_oper/oper-results/result-lib.json @@ -0,0 +1,1145 @@ +{ + "frr-vrf:lib": { + "vrf": [ + { + "name": "default", + "state": { + "id": "rubout", + "active": true + }, + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "11.0.0.0/8", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "blackhole", + "vrf": "rubout", + "gateway": "", + "interface": " ", + "bh-type": "null", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + }, + { + "prefix": "11.11.11.11/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "1.1.1.2", + "interface": "r1-eth0", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + }, + { + "prefix": "12.12.12.12/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "2.2.2.2", + "interface": "r1-eth1", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv4-multicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-unicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + }, + { + "prefix": "2001:1111::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2001:1111::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-multicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + }, + { + "prefix": "2001:1111::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2001:1111::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + } + ] + } + } + }, + { + "name": "red", + "state": { + "id": "rubout", + "active": true + }, + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 10, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "3.3.3.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "3.3.3.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "4.4.4.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "4.4.4.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "13.0.0.0/8", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "blackhole", + "vrf": "rubout", + "gateway": "", + "interface": " ", + "bh-type": "null", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + }, + { + "prefix": "13.13.13.13/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "3.3.3.2", + "interface": "r1-eth2", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + }, + { + "prefix": "14.14.14.14/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "4.4.4.2", + "interface": "r1-eth3", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv4-multicast", + "table-id": 10, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "3.3.3.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "3.3.3.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "4.4.4.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "4.4.4.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-unicast", + "table-id": 10, + "route": [ + { + "prefix": "::/0" + }, + { + "prefix": "2003:333::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2003:333::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2004:4444::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2004:4444::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-multicast", + "table-id": 10, + "route": [ + { + "prefix": "::/0" + }, + { + "prefix": "2003:333::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2003:333::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth2", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2004:4444::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2004:4444::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth3", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + } + ] + } + } + } + ] + } +} + diff --git a/tests/topotests/mgmt_oper/oper-results/result-ribs-rib-ipv4-unicast.json b/tests/topotests/mgmt_oper/oper-results/result-ribs-rib-ipv4-unicast.json new file mode 100644 index 0000000000..956d3a8922 --- /dev/null +++ b/tests/topotests/mgmt_oper/oper-results/result-ribs-rib-ipv4-unicast.json @@ -0,0 +1,225 @@ +{ + "frr-vrf:lib": { + "vrf": [ + { + "name": "default", + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "11.0.0.0/8", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "blackhole", + "vrf": "rubout", + "gateway": "", + "interface": " ", + "bh-type": "null", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + }, + { + "prefix": "11.11.11.11/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "1.1.1.2", + "interface": "r1-eth0", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + }, + { + "prefix": "12.12.12.12/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "2.2.2.2", + "interface": "r1-eth1", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + } + ] + } + ] + } + } + } + ] + } +} + diff --git a/tests/topotests/mgmt_oper/oper-results/result-ribs-rib-nokeys.json b/tests/topotests/mgmt_oper/oper-results/result-ribs-rib-nokeys.json new file mode 100644 index 0000000000..2e2b8ec7ad --- /dev/null +++ b/tests/topotests/mgmt_oper/oper-results/result-ribs-rib-nokeys.json @@ -0,0 +1,572 @@ +{ + "frr-vrf:lib": { + "vrf": [ + { + "name": "default", + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "11.0.0.0/8", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "blackhole", + "vrf": "rubout", + "gateway": "", + "interface": " ", + "bh-type": "null", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + }, + { + "prefix": "11.11.11.11/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "1.1.1.2", + "interface": "r1-eth0", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + }, + { + "prefix": "12.12.12.12/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "2.2.2.2", + "interface": "r1-eth1", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv4-multicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2.2.2.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-unicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + }, + { + "prefix": "2001:1111::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2001:1111::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-multicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + }, + { + "prefix": "2001:1111::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2001:1111::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::/64", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "2002:2222::1/128", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + } + ] + } + } + } + ] + } +} + diff --git a/tests/topotests/mgmt_oper/oper.py b/tests/topotests/mgmt_oper/oper.py new file mode 100644 index 0000000000..e3386067bc --- /dev/null +++ b/tests/topotests/mgmt_oper/oper.py @@ -0,0 +1,258 @@ +# -*- coding: utf-8 eval: (blacken-mode 1) -*- +# SPDX-License-Identifier: ISC +# +# October 29 2023, Christian Hopps <chopps@labn.net> +# +# Copyright (c) 2023, LabN Consulting, L.L.C. +# + +import datetime +import ipaddress +import json +import logging +import math +import os +import pprint +import re + +from lib.common_config import retry, step +from lib.topolog import logger +from lib.topotest import json_cmp as tt_json_cmp + +try: + from deepdiff import DeepDiff as dd_json_cmp +except ImportError: + dd_json_cmp = None + + +def json_cmp(got, expect, exact_match): + if dd_json_cmp: + if exact_match: + deep_diff = dd_json_cmp(expect, got) + # Convert DeepDiff completely into dicts or lists at all levels + json_diff = json.loads(deep_diff.to_json()) + else: + json_diff = dd_json_cmp(expect, got, ignore_order=True) + # Convert DeepDiff completely into dicts or lists at all levels + # json_diff = json.loads(deep_diff.to_json()) + # Remove new fields in json object from diff + if json_diff.get("dictionary_item_added") is not None: + del json_diff["dictionary_item_added"] + # Remove new json objects in json array from diff + if (new_items := json_diff.get("iterable_item_added")) is not None: + new_item_paths = list(new_items.keys()) + for path in new_item_paths: + if type(new_items[path]) is dict: + del new_items[path] + if len(new_items) == 0: + del json_diff["iterable_item_added"] + if not json_diff: + json_diff = None + else: + json_diff = tt_json_cmp(got, expect, exact_match) + json_diff = str(json_diff) + return json_diff + + +def enable_debug(router): + router.vtysh_cmd("debug northbound callbacks configuration") + + +def disable_debug(router): + router.vtysh_cmd("no debug northbound callbacks configuration") + + +def do_oper_test(tgen, query_results): + r1 = tgen.gears["r1"].net + + qcmd = ( + r"vtysh -c 'show mgmt get-data {}' " + r"""| sed -e 's/"phy-address": ".*"/"phy-address": "rubout"/'""" + r"""| sed -e 's/"uptime": ".*"/"uptime": "rubout"/'""" + r"""| sed -e 's/"vrf": "[0-9]*"/"vrf": "rubout"/'""" + r"""| sed -e 's/"if-index": [0-9][0-9]*/"if-index": "rubout"/'""" + r"""| sed -e 's/"id": [0-9][0-9]*/"id": "rubout"/'""" + ) + + doreset = True + dd_json_cmp = None + for qr in query_results: + step(f"Perform query '{qr[0]}'", reset=doreset) + if doreset: + doreset = False + expected = open(qr[1], encoding="ascii").read() + output = r1.cmd_nostatus(qcmd.format(qr[0])) + + try: + ojson = json.loads(output) + except json.decoder.JSONDecodeError as error: + logging.error("Error decoding json: %s\noutput:\n%s", error, output) + raise + + try: + ejson = json.loads(expected) + except json.decoder.JSONDecodeError as error: + logging.error( + "Error decoding json exp result: %s\noutput:\n%s", error, expected + ) + raise + + if dd_json_cmp: + cmpout = json_cmp(ojson, ejson, exact_match=True) + if cmpout: + logging.warning( + "-------DIFF---------\n%s\n---------DIFF----------", + pprint.pformat(cmpout), + ) + else: + cmpout = tt_json_cmp(ojson, ejson, exact=True) + if cmpout: + logging.warning( + "-------EXPECT--------\n%s\n------END-EXPECT------", + json.dumps(ejson, indent=4), + ) + logging.warning( + "--------GOT----------\n%s\n-------END-GOT--------", + json.dumps(ojson, indent=4), + ) + + assert cmpout is None + + +def get_ip_networks(super_prefix, count): + count_log2 = math.log(count, 2) + if count_log2 != int(count_log2): + count_log2 = int(count_log2) + 1 + else: + count_log2 = int(count_log2) + network = ipaddress.ip_network(super_prefix) + return tuple(network.subnets(count_log2))[0:count] + + +@retry(retry_timeout=30, initial_wait=0.1) +def check_kernel(r1, super_prefix, count, add, is_blackhole, vrf, matchvia): + network = ipaddress.ip_network(super_prefix) + vrfstr = f" vrf {vrf}" if vrf else "" + if network.version == 6: + kernel = r1.cmd_raises(f"ip -6 route show{vrfstr}") + else: + kernel = r1.cmd_raises(f"ip -4 route show{vrfstr}") + + # logger.debug("checking kernel routing table%s:\n%s", vrfstr, kernel) + + for i, net in enumerate(get_ip_networks(super_prefix, count)): + if not add: + assert str(net) not in kernel + continue + + if is_blackhole: + route = f"blackhole {str(net)} proto (static|196) metric 20" + else: + route = ( + f"{str(net)}(?: nhid [0-9]+)? {matchvia} " + "proto (static|196) metric 20" + ) + assert re.search(route, kernel), f"Failed to find \n'{route}'\n in \n'{kernel}'" + + +def addrgen(a, count, step=1): + for _ in range(0, count, step): + yield a + a += step + + +@retry(retry_timeout=30, initial_wait=0.1) +def check_kernel_32(r1, start_addr, count, vrf, step=1): + start = ipaddress.ip_address(start_addr) + vrfstr = f" vrf {vrf}" if vrf else "" + if start.version == 6: + kernel = r1.cmd_raises(f"ip -6 route show{vrfstr}") + else: + kernel = r1.cmd_raises(f"ip -4 route show{vrfstr}") + + nentries = len(re.findall("\n", kernel)) + logging.info("checking kernel routing table%s: (%s entries)", vrfstr, nentries) + + for addr in addrgen(start, count, step): + assert str(addr) in kernel, f"Failed to find '{addr}' in {nentries} entries" + + +def do_config( + r1, + count, + add=True, + do_ipv6=False, + via=None, + vrf=None, + use_cli=False, +): + optype = "adding" if add else "removing" + iptype = "IPv6" if do_ipv6 else "IPv4" + + # + # Set the route details + # + + if vrf: + super_prefix = "2111::/48" if do_ipv6 else "111.0.0.0/8" + else: + super_prefix = "2055::/48" if do_ipv6 else "55.0.0.0/8" + + matchvia = "" + if via == "blackhole": + pass + elif via: + matchvia = f"dev {via}" + else: + if vrf: + via = "2102::2" if do_ipv6 else "3.3.3.2" + matchvia = f"via {via} dev r1-eth1" + else: + via = "2101::2" if do_ipv6 else "1.1.1.2" + matchvia = f"via {via} dev r1-eth0" + + vrfdbg = " in vrf {}".format(vrf) if vrf else "" + logger.debug("{} {} static {} routes{}".format(optype, count, iptype, vrfdbg)) + + # + # Generate config file in a retrievable place + # + + config_file = os.path.join( + r1.logdir, r1.name, "{}-routes-{}.conf".format(iptype.lower(), optype) + ) + with open(config_file, "w") as f: + if use_cli: + f.write("configure terminal\n") + if vrf: + f.write("vrf {}\n".format(vrf)) + + for i, net in enumerate(get_ip_networks(super_prefix, count)): + if add: + f.write("ip route {} {}\n".format(net, via)) + else: + f.write("no ip route {} {}\n".format(net, via)) + + # + # Load config file. + # + + if use_cli: + load_command = 'vtysh < "{}"'.format(config_file) + else: + load_command = 'vtysh -f "{}"'.format(config_file) + tstamp = datetime.datetime.now() + output = r1.cmd_raises(load_command) + delta = (datetime.datetime.now() - tstamp).total_seconds() + + # + # Verify the results are in the kernel + # + check_kernel(r1, super_prefix, count, add, via == "blackhole", vrf, matchvia) + + optyped = "added" if add else "removed" + logger.debug( + "{} {} {} static routes under {}{} in {}s".format( + optyped, count, iptype.lower(), super_prefix, vrfdbg, delta + ) + ) diff --git a/tests/topotests/mgmt_oper/r1/frr-scale.conf b/tests/topotests/mgmt_oper/r1/frr-scale.conf new file mode 100644 index 0000000000..237d013aec --- /dev/null +++ b/tests/topotests/mgmt_oper/r1/frr-scale.conf @@ -0,0 +1,25 @@ +log timestamp precision 6 +log file frr.log + +no debug memstats-at-exit + +! debug northbound libyang +! debug northbound callbacks + +debug northbound notifications +debug northbound events + +debug mgmt backend datastore frontend transaction +debug mgmt client frontend +debug mgmt client backend + +interface r1-eth0 + ip address 1.1.1.1/24 +exit + +interface r1-eth1 vrf red + ip address 3.3.3.1/24 +exit + +ip route 11.11.11.11/32 1.1.1.2 +ip route 13.13.13.13/32 3.3.3.2 vrf red \ No newline at end of file diff --git a/tests/topotests/mgmt_oper/r1/frr-simple.conf b/tests/topotests/mgmt_oper/r1/frr-simple.conf new file mode 100644 index 0000000000..cf8ba160f4 --- /dev/null +++ b/tests/topotests/mgmt_oper/r1/frr-simple.conf @@ -0,0 +1,23 @@ +log timestamp precision 6 +log file frr.log + +no debug memstats-at-exit + +debug northbound notifications +debug northbound libyang +debug northbound events +debug northbound callbacks + +debug mgmt backend datastore frontend transaction +debug mgmt client frontend +debug mgmt client backend + +interface r1-eth0 + ip address 1.1.1.1/24 +exit + +interface r1-eth1 vrf red + ip address 3.3.3.1/24 +exit +ip route 11.11.11.11/32 1.1.1.2 +!ip route 13.13.13.13/32 3.3.3.2 vrf red \ No newline at end of file diff --git a/tests/topotests/mgmt_oper/r1/frr.conf b/tests/topotests/mgmt_oper/r1/frr.conf new file mode 100644 index 0000000000..72a67bf020 --- /dev/null +++ b/tests/topotests/mgmt_oper/r1/frr.conf @@ -0,0 +1,41 @@ +log timestamp precision 6 +log file frr.log + +no debug memstats-at-exit + +debug northbound notifications +debug northbound libyang +debug northbound events +debug northbound callbacks + +debug mgmt backend datastore frontend transaction +debug mgmt client frontend +debug mgmt client backend + +interface r1-eth0 + ip address 1.1.1.1/24 + ipv6 address 2001:1111::1/64 +exit + +interface r1-eth1 + ip address 2.2.2.1/24 + ipv6 address 2002:2222::1/64 +exit + +interface r1-eth2 vrf red + ip address 3.3.3.1/24 + ipv6 address 2003:333::1/64 +exit + +interface r1-eth3 vrf red + ip address 4.4.4.1/24 + ipv6 address 2004:4444::1/64 +exit + +ip route 11.0.0.0/8 Null0 +ip route 11.11.11.11/32 1.1.1.2 +ip route 12.12.12.12/32 2.2.2.2 + +ip route 13.0.0.0/8 Null0 vrf red +ip route 13.13.13.13/32 3.3.3.2 vrf red +ip route 14.14.14.14/32 4.4.4.2 vrf red \ No newline at end of file diff --git a/tests/topotests/mgmt_oper/simple-results/result-empty.json b/tests/topotests/mgmt_oper/simple-results/result-empty.json new file mode 100644 index 0000000000..2c63c08510 --- /dev/null +++ b/tests/topotests/mgmt_oper/simple-results/result-empty.json @@ -0,0 +1,2 @@ +{ +} diff --git a/tests/topotests/mgmt_oper/simple-results/result-intf-eth0-name.json b/tests/topotests/mgmt_oper/simple-results/result-intf-eth0-name.json new file mode 100644 index 0000000000..3988204bb8 --- /dev/null +++ b/tests/topotests/mgmt_oper/simple-results/result-intf-eth0-name.json @@ -0,0 +1,9 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "r1-eth0" + } + ] + } +} diff --git a/tests/topotests/mgmt_oper/simple-results/result-intf-eth0-vrf.json b/tests/topotests/mgmt_oper/simple-results/result-intf-eth0-vrf.json new file mode 100644 index 0000000000..3a6eeb853d --- /dev/null +++ b/tests/topotests/mgmt_oper/simple-results/result-intf-eth0-vrf.json @@ -0,0 +1,10 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "r1-eth0", + "vrf": "default" + } + ] + } +} diff --git a/tests/topotests/mgmt_oper/simple-results/result-intf-name.json b/tests/topotests/mgmt_oper/simple-results/result-intf-name.json new file mode 100644 index 0000000000..9d8ea759b9 --- /dev/null +++ b/tests/topotests/mgmt_oper/simple-results/result-intf-name.json @@ -0,0 +1,21 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "lo" + }, + { + "name": "r1-eth0" + }, + { + "name": "lo-red" + }, + { + "name": "r1-eth1" + }, + { + "name": "red" + } + ] + } +} diff --git a/tests/topotests/mgmt_oper/simple-results/result-intf-state-mtu.json b/tests/topotests/mgmt_oper/simple-results/result-intf-state-mtu.json new file mode 100644 index 0000000000..60359716d7 --- /dev/null +++ b/tests/topotests/mgmt_oper/simple-results/result-intf-state-mtu.json @@ -0,0 +1,12 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "r1-eth0", + "state": { + "mtu": 1500 + } + } + ] + } +} diff --git a/tests/topotests/mgmt_oper/simple-results/result-intf-state.json b/tests/topotests/mgmt_oper/simple-results/result-intf-state.json new file mode 100644 index 0000000000..981df024cd --- /dev/null +++ b/tests/topotests/mgmt_oper/simple-results/result-intf-state.json @@ -0,0 +1,17 @@ +{ + "frr-interface:lib": { + "interface": [ + { + "name": "r1-eth0", + "state": { + "if-index": "rubout", + "mtu": 1500, + "mtu6": 1500, + "speed": 10000, + "metric": 0, + "phy-address": "rubout" + } + } + ] + } +} diff --git a/tests/topotests/mgmt_oper/simple-results/result-lib-vrf-default.json b/tests/topotests/mgmt_oper/simple-results/result-lib-vrf-default.json new file mode 100644 index 0000000000..cea4bf5a6b --- /dev/null +++ b/tests/topotests/mgmt_oper/simple-results/result-lib-vrf-default.json @@ -0,0 +1,193 @@ +{ + "frr-vrf:lib": { + "vrf": [ + { + "name": "default", + "state": { + "id": "rubout", + "active": true + }, + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "11.11.11.11/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "1.1.1.2", + "interface": "r1-eth0", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv4-multicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-unicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-multicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + } + ] + } + ] + } + } + } + ] + } +} + diff --git a/tests/topotests/mgmt_oper/simple-results/result-lib-vrf-nokey.json b/tests/topotests/mgmt_oper/simple-results/result-lib-vrf-nokey.json new file mode 100644 index 0000000000..75414ca045 --- /dev/null +++ b/tests/topotests/mgmt_oper/simple-results/result-lib-vrf-nokey.json @@ -0,0 +1,350 @@ +{ + "frr-vrf:lib": { + "vrf": [ + { + "name": "default", + "state": { + "id": "rubout", + "active": true + }, + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "11.11.11.11/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "1.1.1.2", + "interface": "r1-eth0", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv4-multicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-unicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-multicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + } + ] + } + ] + } + } + }, + { + "name": "red", + "state": { + "id": "rubout", + "active": true + }, + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 10, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "3.3.3.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "3.3.3.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv4-multicast", + "table-id": 10, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "3.3.3.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "3.3.3.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-unicast", + "table-id": 10, + "route": [ + { + "prefix": "::/0" + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-multicast", + "table-id": 10, + "route": [ + { + "prefix": "::/0" + } + ] + } + ] + } + } + } + ] + } +} + diff --git a/tests/topotests/mgmt_oper/simple-results/result-lib-vrf-red.json b/tests/topotests/mgmt_oper/simple-results/result-lib-vrf-red.json new file mode 100644 index 0000000000..05382316a3 --- /dev/null +++ b/tests/topotests/mgmt_oper/simple-results/result-lib-vrf-red.json @@ -0,0 +1,164 @@ +{ + "frr-vrf:lib": { + "vrf": [ + { + "name": "red", + "state": { + "id": "rubout", + "active": true + }, + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 10, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "3.3.3.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "3.3.3.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv4-multicast", + "table-id": 10, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "3.3.3.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "3.3.3.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-unicast", + "table-id": 10, + "route": [ + { + "prefix": "::/0" + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-multicast", + "table-id": 10, + "route": [ + { + "prefix": "::/0" + } + ] + } + ] + } + } + } + ] + } +} + diff --git a/tests/topotests/mgmt_oper/simple-results/result-lib-vrf-zebra-ribs.json b/tests/topotests/mgmt_oper/simple-results/result-lib-vrf-zebra-ribs.json new file mode 100644 index 0000000000..4f40820bb6 --- /dev/null +++ b/tests/topotests/mgmt_oper/simple-results/result-lib-vrf-zebra-ribs.json @@ -0,0 +1,189 @@ +{ + "frr-vrf:lib": { + "vrf": [ + { + "name": "default", + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "11.11.11.11/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "1.1.1.2", + "interface": "r1-eth0", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv4-multicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-unicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-multicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + } + ] + } + ] + } + } + } + ] + } +} + diff --git a/tests/topotests/mgmt_oper/simple-results/result-lib-vrf-zebra.json b/tests/topotests/mgmt_oper/simple-results/result-lib-vrf-zebra.json new file mode 100644 index 0000000000..4f40820bb6 --- /dev/null +++ b/tests/topotests/mgmt_oper/simple-results/result-lib-vrf-zebra.json @@ -0,0 +1,189 @@ +{ + "frr-vrf:lib": { + "vrf": [ + { + "name": "default", + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "11.11.11.11/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "1.1.1.2", + "interface": "r1-eth0", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv4-multicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-unicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-multicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + } + ] + } + ] + } + } + } + ] + } +} + diff --git a/tests/topotests/mgmt_oper/simple-results/result-lib.json b/tests/topotests/mgmt_oper/simple-results/result-lib.json new file mode 100644 index 0000000000..75414ca045 --- /dev/null +++ b/tests/topotests/mgmt_oper/simple-results/result-lib.json @@ -0,0 +1,350 @@ +{ + "frr-vrf:lib": { + "vrf": [ + { + "name": "default", + "state": { + "id": "rubout", + "active": true + }, + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "11.11.11.11/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "1.1.1.2", + "interface": "r1-eth0", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv4-multicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-unicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-multicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + } + ] + } + ] + } + } + }, + { + "name": "red", + "state": { + "id": "rubout", + "active": true + }, + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 10, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "3.3.3.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "3.3.3.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv4-multicast", + "table-id": 10, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "3.3.3.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "3.3.3.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth1", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-unicast", + "table-id": 10, + "route": [ + { + "prefix": "::/0" + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-multicast", + "table-id": 10, + "route": [ + { + "prefix": "::/0" + } + ] + } + ] + } + } + } + ] + } +} + diff --git a/tests/topotests/mgmt_oper/simple-results/result-ribs-rib-ipv4-unicast.json b/tests/topotests/mgmt_oper/simple-results/result-ribs-rib-ipv4-unicast.json new file mode 100644 index 0000000000..7ce60c3bdb --- /dev/null +++ b/tests/topotests/mgmt_oper/simple-results/result-ribs-rib-ipv4-unicast.json @@ -0,0 +1,110 @@ +{ + "frr-vrf:lib": { + "vrf": [ + { + "name": "default", + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "11.11.11.11/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "1.1.1.2", + "interface": "r1-eth0", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + } + ] + } + ] + } + } + } + ] + } +} + diff --git a/tests/topotests/mgmt_oper/simple-results/result-ribs-rib-nokeys.json b/tests/topotests/mgmt_oper/simple-results/result-ribs-rib-nokeys.json new file mode 100644 index 0000000000..4f40820bb6 --- /dev/null +++ b/tests/topotests/mgmt_oper/simple-results/result-ribs-rib-nokeys.json @@ -0,0 +1,189 @@ +{ + "frr-vrf:lib": { + "vrf": [ + { + "name": "default", + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "11.11.11.11/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "1.1.1.2", + "interface": "r1-eth0", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv4-multicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "internal-flags": 8, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-unicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + } + ] + }, + { + "afi-safi-name": "frr-routing:ipv6-multicast", + "table-id": 254, + "route": [ + { + "prefix": "::/0" + } + ] + } + ] + } + } + } + ] + } +} + diff --git a/tests/topotests/mgmt_oper/simple-results/result-ribs-rib-route-nokey.json b/tests/topotests/mgmt_oper/simple-results/result-ribs-rib-route-nokey.json new file mode 100644 index 0000000000..7ce60c3bdb --- /dev/null +++ b/tests/topotests/mgmt_oper/simple-results/result-ribs-rib-route-nokey.json @@ -0,0 +1,110 @@ +{ + "frr-vrf:lib": { + "vrf": [ + { + "name": "default", + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 254, + "route": [ + { + "prefix": "0.0.0.0/0" + }, + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "1.1.1.1/32", + "route-entry": [ + { + "protocol": "local", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + }, + { + "prefix": "11.11.11.11/32", + "route-entry": [ + { + "protocol": "static", + "distance": 1, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 73, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ip4-ifindex", + "vrf": "rubout", + "gateway": "1.1.1.2", + "interface": "r1-eth0", + "active": [null], + "fib": [null], + "weight": 1 + } + ] + } + } + ] + } + ] + } + ] + } + } + } + ] + } +} + diff --git a/tests/topotests/mgmt_oper/simple-results/result-ribs-rib-route-prefix.json b/tests/topotests/mgmt_oper/simple-results/result-ribs-rib-route-prefix.json new file mode 100644 index 0000000000..833d418f9a --- /dev/null +++ b/tests/topotests/mgmt_oper/simple-results/result-ribs-rib-route-prefix.json @@ -0,0 +1,50 @@ +{ + "frr-vrf:lib": { + "vrf": [ + { + "name": "default", + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 254, + "route": [ + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "distance": 0, + "metric": 0, + "selected": [null], + "installed": [null], + "internal-flags": 8, + "internal-status": 16, + "uptime": "rubout", + "nexthop-group": { + "id": "rubout", + "nexthop": [ + { + "nh-type": "ifindex", + "vrf": "rubout", + "gateway": "", + "interface": "r1-eth0", + "active": [null], + "fib": [null] + } + ] + } + } + ] + } + ] + } + ] + } + } + } + ] + } +} + diff --git a/tests/topotests/mgmt_oper/simple-results/result-singleton-metric.json b/tests/topotests/mgmt_oper/simple-results/result-singleton-metric.json new file mode 100644 index 0000000000..b3a7df54ea --- /dev/null +++ b/tests/topotests/mgmt_oper/simple-results/result-singleton-metric.json @@ -0,0 +1,30 @@ +{ + "frr-vrf:lib": { + "vrf": [ + { + "name": "default", + "frr-zebra:zebra": { + "ribs": { + "rib": [ + { + "afi-safi-name": "frr-routing:ipv4-unicast", + "table-id": 254, + "route": [ + { + "prefix": "1.1.1.0/24", + "route-entry": [ + { + "protocol": "connected", + "metric": 0 + } + ] + } + ] + } + ] + } + } + } + ] + } +} diff --git a/tests/topotests/mgmt_oper/test_oper.py b/tests/topotests/mgmt_oper/test_oper.py new file mode 100644 index 0000000000..6971eafc57 --- /dev/null +++ b/tests/topotests/mgmt_oper/test_oper.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python +# -*- coding: utf-8 eval: (blacken-mode 1) -*- +# SPDX-License-Identifier: ISC +# +# Copyright (c) 2021, LabN Consulting, L.L.C. +# Copyright (c) 2019-2020 by +# Donatas Abraitis <donatas.abraitis@gmail.com> +# +""" +Test static route functionality +""" + +import ipaddress +import math +import time + +import pytest +from lib.topogen import Topogen +from oper import check_kernel_32, do_oper_test + +try: + from deepdiff import DeepDiff as dd_json_cmp +except ImportError: + dd_json_cmp = None + +pytestmark = [pytest.mark.staticd, pytest.mark.mgmtd] + + +@pytest.fixture(scope="module") +def tgen(request): + "Setup/Teardown the environment and provide tgen argument to tests" + + topodef = {"s1": ("r1",), "s2": ("r1",), "s3": ("r1",), "s4": ("r1",)} + + tgen = Topogen(topodef, request.module.__name__) + tgen.start_topology() + + router_list = tgen.routers() + for rname, router in router_list.items(): + # Setup VRF red + router.net.add_l3vrf("red", 10) + router.net.add_loop("lo-red") + router.net.attach_iface_to_l3vrf("lo-red", "red") + router.net.attach_iface_to_l3vrf(rname + "-eth2", "red") + router.net.attach_iface_to_l3vrf(rname + "-eth3", "red") + router.load_frr_config("frr.conf") + + tgen.start_router() + yield tgen + tgen.stop_topology() + + +def get_ip_networks(super_prefix, count): + count_log2 = math.log(count, 2) + if count_log2 != int(count_log2): + count_log2 = int(count_log2) + 1 + else: + count_log2 = int(count_log2) + network = ipaddress.ip_network(super_prefix) + return tuple(network.subnets(count_log2))[0:count] + + +def test_oper(tgen): + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + query_results = [ + ("/frr-vrf:lib", "oper-results/result-lib.json"), + ("/frr-vrf:lib/vrf", "oper-results/result-lib-vrf-nokey.json"), + ( + '/frr-vrf:lib/vrf[name="default"]', + "oper-results/result-lib-vrf-default.json", + ), + ( + '/frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra', + "oper-results/result-lib-vrf-zebra.json", + ), + ( + '/frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs', + "oper-results/result-lib-vrf-zebra-ribs.json", + ), + ( + '/frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/rib', + "oper-results/result-ribs-rib-nokeys.json", + ), + ( + '/frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/' + 'rib[afi-safi-name="frr-routing:ipv4-unicast"][table-id="254"]', + "oper-results/result-ribs-rib-ipv4-unicast.json", + ), + ] + + r1 = tgen.gears["r1"].net + check_kernel_32(r1, "11.11.11.11", 1, "") + check_kernel_32(r1, "12.12.12.12", 1, "") + check_kernel_32(r1, "13.13.13.13", 1, "red") + check_kernel_32(r1, "14.14.14.14", 1, "red") + time.sleep(2) + do_oper_test(tgen, query_results) + + +to_gen_new_results = """ +scriptdir=~chopps/w/frr/tests/topotests/mgmt_oper +resdir=${scriptdir}/oper-results +vtysh -c 'show mgmt get-data /frr-vrf:lib' > ${resdir}/result-lib.json +vtysh -c 'show mgmt get-data /frr-vrf:lib/vrf' > ${resdir}/result-lib-vrf-nokey.json +vtysh -c 'show mgmt get-data /frr-vrf:lib/vrf[name="default"]' > ${resdir}/result-lib-vrf-default.json +vtysh -c 'show mgmt get-data /frr-vrf:lib/vrf[name="red"]' > ${resdir}/result-lib-vrf-red.json +vtysh -c 'show mgmt get-data /frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra' > ${resdir}/result-lib-vrf-zebra.json +vtysh -c 'show mgmt get-data /frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs' > ${resdir}/result-lib-vrf-zebra-ribs.json +vtysh -c 'show mgmt get-data /frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/rib' > ${resdir}/result-ribs-rib-nokeys.json +vtysh -c 'show mgmt get-data /frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/rib[afi-safi-name="frr-routing:ipv4-unicast"][table-id="254"]' > ${resdir}/result-ribs-rib-ipv4-unicast.json +vtysh -c 'show mgmt get-data /frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/rib[afi-safi-name="frr-routing:ipv4-unicast"][table-id="254"]/route' > ${resdir}/result-ribs-rib-route-nokey.json + +for f in ${resdir}/result-*; do + sed -i -e 's/"uptime": ".*"/"uptime": "rubout"/;s/"id": [0-9][0-9]*/"id": "rubout"/' $f + sed -i -e 's/"if-index": [0-9][0-9]*/"if-index": "rubout"/' $f + sed -i -e 's,"vrf": "[0-9]*","vrf": "rubout",' $f +done +""" # noqa: 501 +# should not differ +# diff result-lib.json result-lib-vrf-nokey.json +# diff result-lib-vrf-zebra.json result-lib-vrf-zebra-ribs.json diff --git a/tests/topotests/mgmt_oper/test_querying.py b/tests/topotests/mgmt_oper/test_querying.py new file mode 100644 index 0000000000..086a87b5e6 --- /dev/null +++ b/tests/topotests/mgmt_oper/test_querying.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python +# -*- coding: utf-8 eval: (blacken-mode 1) -*- +# SPDX-License-Identifier: ISC +# +# Copyright (c) 2021, LabN Consulting, L.L.C. +# Copyright (c) 2019-2020 by +# Donatas Abraitis <donatas.abraitis@gmail.com> +# +# noqa: E501 +# +""" +Test various query types +""" +import json +import logging + +import pytest +from lib.common_config import step +from lib.topogen import Topogen +from oper import check_kernel_32 + +pytestmark = [pytest.mark.staticd, pytest.mark.mgmtd] + + +@pytest.fixture(scope="module") +def tgen(request): + "Setup/Teardown the environment and provide tgen argument to tests" + + topodef = {"s1": ("r1",), "s2": ("r1",)} + + tgen = Topogen(topodef, request.module.__name__) + tgen.start_topology() + + router_list = tgen.routers() + for rname, router in router_list.items(): + # Setup VRF red + router.net.add_l3vrf("red", 10) + router.net.add_loop("lo-red") + router.net.attach_iface_to_l3vrf("lo-red", "red") + router.net.attach_iface_to_l3vrf(rname + "-eth1", "red") + router.load_frr_config("frr-simple.conf") + + tgen.start_router() + yield tgen + tgen.stop_topology() + + +def test_oper_simple(tgen): + """This test is useful for doing manual testing""" + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + query_results = [ + # Non-key specific query with function filtering selector + '/frr-interface:lib/interface[contains(name,"eth")]/vrf', + # Non-key specific query with child value filtering selector + '/frr-interface:lib/interface[vrf="red"]/vrf', + '/frr-interface:lib/interface[./vrf="red"]/vrf', + # Container query with function filtering selector + '/frr-interface:lib/interface[contains(name,"eth")]/state', + # Multi list elemenet with function filtering selector + '/frr-interface:lib/interface[contains(name,"eth")]', + # + # Specific list entry after non-specific lists + '/frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/' + 'rib[afi-safi-name="frr-routing:ipv4-unicast"][table-id="254"]/' + 'route/route-entry[protocol="connected"]', + # crashes: All specific until the end, then walk + '/frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/' + 'rib[afi-safi-name="frr-routing:ipv4-unicast"][table-id="254"]/' + 'route[prefix="1.1.1.0/24"]/route-entry[protocol="connected"]', + # Does nothing: Root level query + "//metric", + # specific leaf after non-specific lists + '/frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/' + 'rib[afi-safi-name="frr-routing:ipv4-unicast"][table-id="254"]/' + "route/route-entry/metric", + # All specific until the end generic. + '/frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/' + 'rib[afi-safi-name="frr-routing:ipv4-unicast"][table-id="254"]/' + 'route[prefix="1.1.1.0/24"]/route-entry', + # All specific until the penultimate generic with a specific leaf child. + '/frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/' + 'rib[afi-safi-name="frr-routing:ipv4-unicast"][table-id="254"]/' + 'route[prefix="1.1.1.0/24"]/route-entry/metric', + # All generic until the end (middle) specific with unspecified + # children below to walk. + '/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route[prefix="1.1.1.0/24"]', + # All generic until the end which is a specific leaf. + "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/metric", + ] + # query_results = [ + # '/frr-interface:lib/frr-interface:interface/frr-zebra:zebra/ip-addrs[frr-rt:address-family="frr-rt:ipv4"][prefix="1.1.1.1/24"]' + # ] + + r1 = tgen.gears["r1"].net + check_kernel_32(r1, "11.11.11.11", 1, "") + + step("Oper test start", reset=True) + + for qr in query_results: + step(f"Perform query '{qr}'") + try: + output = r1.cmd_nostatus(f"vtysh -c 'show mgmt get-data {qr}'") + except Exception as error: + logging.error("Error sending query: %s: %s", qr, error) + continue + + try: + ojson = json.loads(output) + logging.info("'%s': generates:\n%s", qr, ojson) + except json.decoder.JSONDecodeError as error: + logging.error("Error decoding json: %s\noutput:\n%s", error, output) diff --git a/tests/topotests/mgmt_oper/test_scale.py b/tests/topotests/mgmt_oper/test_scale.py new file mode 100644 index 0000000000..41c2b8cd78 --- /dev/null +++ b/tests/topotests/mgmt_oper/test_scale.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python +# -*- coding: utf-8 eval: (blacken-mode 1) -*- +# SPDX-License-Identifier: ISC +# +# Copyright (c) 2021, LabN Consulting, L.L.C. +# Copyright (c) 2019-2020 by +# Donatas Abraitis <donatas.abraitis@gmail.com> +# +# noqa: E501 +# +""" +Test static route functionality +""" +import re +import time + +import pytest +from lib.common_config import step +from lib.topogen import Topogen, TopoRouter +from oper import check_kernel_32 + +pytestmark = [pytest.mark.staticd, pytest.mark.mgmtd] + + +@pytest.fixture(scope="module") +def tgen(request): + "Setup/Teardown the environment and provide tgen argument to tests" + + topodef = {"s1": ("r1",), "s2": ("r1",)} + + tgen = Topogen(topodef, request.module.__name__) + tgen.start_topology() + + router_list = tgen.routers() + for rname, router in router_list.items(): + # Setup VRF red + router.net.add_l3vrf("red", 10) + router.net.add_loop("lo-red") + router.net.attach_iface_to_l3vrf("lo-red", "red") + router.net.attach_iface_to_l3vrf(rname + "-eth1", "red") + router.load_frr_config("frr-scale.conf") + router.load_config(TopoRouter.RD_SHARP, "") + + tgen.start_router() + yield tgen + tgen.stop_topology() + + +def test_oper_simple(tgen): + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"].net + + time.sleep(2) + count = 20 * 1000 + + vrf = None # "red" + check_kernel_32(r1, "11.11.11.11", 1, vrf) + + step("Found 11.11.11.11 in kernel adding sharpd routes") + r1.cmd_raises(f"vtysh -c 'sharp install routes 20.0.0.0 nexthop 1.1.1.2 {count}'") + check_kernel_32(r1, "20.0.0.0", count, vrf, 1000) + + step(f"All {count} routes installed in kernel, continuing") + # output = r1.cmd_raises("vtysh -c 'show mgmt get-data /frr-vrf:lib'") + # step(f"Got output: {output[0:1024]}") + + query = '/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route[contains(prefix,"20.0.0.12")]/prefix' + output = r1.cmd_raises(f"vtysh -c 'show mgmt get-data {query}'") + matches = re.findall(r'"prefix":', output) + # 20.0.0.12 + 20.0.0.12{0,1,2,3,4,5,6,7,8,9} + assert len(matches) == 11 diff --git a/tests/topotests/mgmt_oper/test_simple.py b/tests/topotests/mgmt_oper/test_simple.py new file mode 100644 index 0000000000..008733ee72 --- /dev/null +++ b/tests/topotests/mgmt_oper/test_simple.py @@ -0,0 +1,157 @@ +#!/usr/bin/env python +# -*- coding: utf-8 eval: (blacken-mode 1) -*- +# SPDX-License-Identifier: ISC +# +# Copyright (c) 2021, LabN Consulting, L.L.C. +# Copyright (c) 2019-2020 by +# Donatas Abraitis <donatas.abraitis@gmail.com> +# +# noqa: E501 +# +""" +Test static route functionality +""" +import pytest +from lib.topogen import Topogen +from oper import check_kernel_32, do_oper_test + +pytestmark = [pytest.mark.staticd, pytest.mark.mgmtd] + + +@pytest.fixture(scope="module") +def tgen(request): + "Setup/Teardown the environment and provide tgen argument to tests" + + topodef = {"s1": ("r1",), "s2": ("r1",)} + + tgen = Topogen(topodef, request.module.__name__) + tgen.start_topology() + + router_list = tgen.routers() + for rname, router in router_list.items(): + # Setup VRF red + router.net.add_l3vrf("red", 10) + router.net.add_loop("lo-red") + router.net.attach_iface_to_l3vrf("lo-red", "red") + router.net.attach_iface_to_l3vrf(rname + "-eth1", "red") + router.load_frr_config("frr-simple.conf") + + tgen.start_router() + yield tgen + tgen.stop_topology() + + +def test_oper_simple(tgen): + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + query_results = [ + ( + # Non-key query with key specific selection + '/frr-interface:lib/interface[name="r1-eth0"]/vrf', + "simple-results/result-intf-eth0-vrf.json", + ), + # Test machines will have different sets of interfaces so the test results will + # vary and need to be generated dynamically before this test is re-enabled + # ( + # # Key query on generic list + # "/frr-interface:lib/interface/name", + # "simple-results/result-intf-name.json", + # ), + ( + # Key query with key specific selection + '/frr-interface:lib/interface[name="r1-eth0"]/name', + "simple-results/result-intf-eth0-name.json", + ), + ("/frr-vrf:lib", "simple-results/result-lib.json"), + ("/frr-vrf:lib/vrf", "simple-results/result-lib-vrf-nokey.json"), + ( + '/frr-vrf:lib/vrf[name="default"]', + "simple-results/result-lib-vrf-default.json", + ), + ('/frr-vrf:lib/vrf[name="red"]', "simple-results/result-lib-vrf-red.json"), + ( + '/frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra', + "simple-results/result-lib-vrf-zebra.json", + ), + ( + '/frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs', + "simple-results/result-lib-vrf-zebra-ribs.json", + ), + ( + '/frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/rib', + "simple-results/result-ribs-rib-nokeys.json", + ), + ( + '/frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/' + 'rib[afi-safi-name="frr-routing:ipv4-unicast"][table-id="254"]', + "simple-results/result-ribs-rib-ipv4-unicast.json", + ), + ( + '/frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/' + 'rib[afi-safi-name="frr-routing:ipv4-unicast"][table-id="254"]/route', + "simple-results/result-ribs-rib-route-nokey.json", + ), + ( + '/frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/' + 'rib[afi-safi-name="frr-routing:ipv4-unicast"][table-id="254"]/' + 'route[prefix="1.1.1.0/24"]', + "simple-results/result-ribs-rib-route-prefix.json", + ), + # Missing entry + ( + '/frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/' + 'rib[afi-safi-name="frr-routing:ipv4-unicast"][table-id="254"]/' + 'route[prefix="1.1.0.0/24"]', + "simple-results/result-empty.json", + ), + # Leaf reference + ( + '/frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/' + 'rib[afi-safi-name="frr-routing:ipv4-unicast"][table-id="254"]/' + 'route[prefix="1.1.1.0/24"]/route-entry[protocol="connected"]/metric', + "simple-results/result-singleton-metric.json", + ), + # Interface state + ( + '/frr-interface:lib/interface[name="r1-eth0"]/state', + "simple-results/result-intf-state.json", + ), + ( + '/frr-interface:lib/interface[name="r1-eth0"]/state/mtu', + "simple-results/result-intf-state-mtu.json", + ), + ] + + r1 = tgen.gears["r1"].net + check_kernel_32(r1, "11.11.11.11", 1, "") + do_oper_test(tgen, query_results) + + +to_gen_new_results = """ +scriptdir=~chopps/w/frr/tests/topotests/mgmt_oper +resdir=${scriptdir}/simple-results +vtysh -c 'show mgmt get-data /frr-vrf:lib' > ${resdir}/result-lib.json +vtysh -c 'show mgmt get-data /frr-vrf:lib/vrf' > ${resdir}/result-lib-vrf-nokey.json +vtysh -c 'show mgmt get-data /frr-vrf:lib/vrf[name="default"]' > ${resdir}/result-lib-vrf-default.json +vtysh -c 'show mgmt get-data /frr-vrf:lib/vrf[name="red"]' > ${resdir}/result-lib-vrf-red.json +vtysh -c 'show mgmt get-data /frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra' > ${resdir}/result-lib-vrf-zebra.json +vtysh -c 'show mgmt get-data /frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs' > ${resdir}/result-lib-vrf-zebra-ribs.json +vtysh -c 'show mgmt get-data /frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/rib' > ${resdir}/result-ribs-rib-nokeys.json +vtysh -c 'show mgmt get-data /frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/rib[afi-safi-name="frr-routing:ipv4-unicast"][table-id="254"]' > ${resdir}/result-ribs-rib-ipv4-unicast.json +vtysh -c 'show mgmt get-data /frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/rib[afi-safi-name="frr-routing:ipv4-unicast"][table-id="254"]/route' > ${resdir}/result-ribs-rib-route-nokey.json + +vtysh -c 'show mgmt get-data /frr-interface:lib/interface[name="r1-eth0"]/state' > ${resdir}/result-intf-state.json +vtysh -c 'show mgmt get-data /frr-interface:lib/interface[name="r1-eth0"]/state/mtu' > ${resdir}/result-intf-state-mtu.json + +for f in ${resdir}/result-*; do + sed -i -e 's/"uptime": ".*"/"uptime": "rubout"/;s/"id": [0-9][0-9]*/"id": "rubout"/' $f + sed -i -e 's/"phy-address": ".*"/"phy-address": "rubout"/' $f + sed -i -e 's/"if-index": [0-9][0-9]*/"if-index": "rubout"/' $f + sed -i -e 's,"vrf": "[0-9]*","vrf": "rubout",' $f +done +""" # noqa: 501 + +# Example commands: +# show mgmt get-data /frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/rib[afi-safi-name="frr-routing:ipv4-unicast"][table-id="254"]/route[prefix="1.1.0.0/24"] # noqa: E501 +# show mgmt get-data /frr-vrf:lib/vrf[name="default"]/frr-zebra:zebra/ribs/rib[afi-safi-name="frr-routing:ipv4-unicast"][table-id="254"]/route[prefix="1.1.1.0/24"] # noqa: E501 diff --git a/tests/topotests/mgmt_startup/test_bigconf.py b/tests/topotests/mgmt_startup/test_bigconf.py index 465f646b6e..1c08fe6ca3 100644 --- a/tests/topotests/mgmt_startup/test_bigconf.py +++ b/tests/topotests/mgmt_startup/test_bigconf.py @@ -21,8 +21,7 @@ CWD = os.path.dirname(os.path.realpath(__file__)) -# pytestmark = [pytest.mark.staticd, pytest.mark.mgmtd] -pytestmark = [pytest.mark.staticd] +pytestmark = [pytest.mark.staticd, pytest.mark.mgmtd] track = Timeout(0) @@ -42,8 +41,10 @@ def tgen(request): tgen = Topogen(topodef, request.module.__name__) tgen.start_topology() + prologue = open(f"{CWD}/r1/mgmtd.conf").read() + confpath = f"{tgen.gears['r1'].gearlogdir}/r1-late-big.conf" - start, end = write_big_route_conf("10.0.0.0/8", ROUTE_COUNT, confpath) + start, end = write_big_route_conf("10.0.0.0/8", ROUTE_COUNT, confpath, prologue) ROUTE_RANGE[0] = start ROUTE_RANGE[1] = end @@ -69,10 +70,10 @@ def test_staticd_latestart(tgen): check_vtysh_up(r1) logging.info("r1: vtysh connected after %ss", track.elapsed()) - result = check_kernel(r1, ROUTE_RANGE[0], retry_timeout=20) + result = check_kernel(r1, ROUTE_RANGE[0], retry_timeout=60) assert result is None logging.info("r1: first route installed after %ss", track.elapsed()) - result = check_kernel(r1, ROUTE_RANGE[1], retry_timeout=20) + result = check_kernel(r1, ROUTE_RANGE[1], retry_timeout=60) assert result is None logging.info("r1: last route installed after %ss", track.elapsed()) diff --git a/tests/topotests/mgmt_startup/test_config.py b/tests/topotests/mgmt_startup/test_cfgfile_var.py similarity index 97% rename from tests/topotests/mgmt_startup/test_config.py rename to tests/topotests/mgmt_startup/test_cfgfile_var.py index 6a54f71910..8203ae57ff 100644 --- a/tests/topotests/mgmt_startup/test_config.py +++ b/tests/topotests/mgmt_startup/test_cfgfile_var.py @@ -31,8 +31,7 @@ from lib.topogen import Topogen, TopoRouter from util import check_kernel -# pytestmark = [pytest.mark.staticd, pytest.mark.mgmtd] -pytestmark = [pytest.mark.staticd] +pytestmark = [pytest.mark.staticd, pytest.mark.mgmtd] @pytest.fixture(scope="module") diff --git a/tests/topotests/mgmt_startup/test_late_bigconf.py b/tests/topotests/mgmt_startup/test_late_bigconf.py index ac7ac57cf8..5bf345732b 100644 --- a/tests/topotests/mgmt_startup/test_late_bigconf.py +++ b/tests/topotests/mgmt_startup/test_late_bigconf.py @@ -22,8 +22,7 @@ CWD = os.path.dirname(os.path.realpath(__file__)) -# pytestmark = [pytest.mark.staticd, pytest.mark.mgmtd] -pytestmark = [pytest.mark.staticd] +pytestmark = [pytest.mark.staticd, pytest.mark.mgmtd] track = Timeout(0) ROUTE_COUNT = 2500 @@ -42,8 +41,10 @@ def tgen(request): tgen = Topogen(topodef, request.module.__name__) tgen.start_topology() + prologue = open(f"{CWD}/r1/mgmtd.conf").read() + confpath = f"{tgen.gears['r1'].gearlogdir}/r1-late-big.conf" - start, end = write_big_route_conf("10.0.0.0/8", ROUTE_COUNT, confpath) + start, end = write_big_route_conf("10.0.0.0/8", ROUTE_COUNT, confpath, prologue) ROUTE_RANGE[0] = start ROUTE_RANGE[1] = end @@ -68,15 +69,29 @@ def test_staticd_latestart(tgen): check_vtysh_up(r1) logging.info("r1: vtysh connected after %ss", track.elapsed()) - result = check_kernel(r1, ROUTE_RANGE[0], retry_timeout=20, expected=False) + result = check_kernel(r1, ROUTE_RANGE[0], retry_timeout=60, expected=False) assert result is not None, "first route present and should not be" - result = check_kernel(r1, ROUTE_RANGE[1], retry_timeout=20, expected=False) + result = check_kernel(r1, ROUTE_RANGE[1], retry_timeout=60, expected=False) assert result is not None, "last route present and should not be" step("Starting staticd") + t2 = Timeout(0) r1.startDaemons(["staticd"]) result = check_kernel(r1, ROUTE_RANGE[0], retry_timeout=60) assert result is None, "first route not present and should be" - result = check_kernel(r1, ROUTE_RANGE[1], retry_timeout=20) + logging.info("r1: elapsed time for first route %ss", t2.elapsed()) + + count = 0 + ocount = 0 + while count < ROUTE_COUNT: + rc, o, e = r1.net.cmd_status("ip -o route | wc -l") + if not rc: + if count > ocount + 100: + ocount = count + logging.info("r1: elapsed time for %d routes %s", count, t2.elapsed()) + count = int(o) + + result = check_kernel(r1, ROUTE_RANGE[1], retry_timeout=1200) assert result is None, "last route not present and should be" + logging.info("r1: elapsed time for last route %ss", t2.elapsed()) diff --git a/tests/topotests/mgmt_startup/test_late_uniconf.py b/tests/topotests/mgmt_startup/test_late_uniconf.py index d4e7e07ad6..380c2eb20b 100644 --- a/tests/topotests/mgmt_startup/test_late_uniconf.py +++ b/tests/topotests/mgmt_startup/test_late_uniconf.py @@ -14,8 +14,7 @@ from lib.topogen import Topogen from util import _test_staticd_late_start -# pytestmark = [pytest.mark.staticd, pytest.mark.mgmtd] -pytestmark = [pytest.mark.staticd] +pytestmark = [pytest.mark.staticd, pytest.mark.mgmtd] @pytest.fixture(scope="module") diff --git a/tests/topotests/mgmt_startup/test_latestart.py b/tests/topotests/mgmt_startup/test_latestart.py index 1c97b9dd0f..c0c0121d05 100644 --- a/tests/topotests/mgmt_startup/test_latestart.py +++ b/tests/topotests/mgmt_startup/test_latestart.py @@ -14,8 +14,7 @@ from lib.topogen import Topogen, TopoRouter from util import _test_staticd_late_start -# pytestmark = [pytest.mark.staticd, pytest.mark.mgmtd] -pytestmark = [pytest.mark.staticd] +pytestmark = [pytest.mark.staticd, pytest.mark.mgmtd] @pytest.fixture(scope="module") diff --git a/tests/topotests/mgmt_startup/util.py b/tests/topotests/mgmt_startup/util.py index 87a2ad442e..e366351326 100644 --- a/tests/topotests/mgmt_startup/util.py +++ b/tests/topotests/mgmt_startup/util.py @@ -50,11 +50,13 @@ def get_ip_networks(super_prefix, count): return tuple(network.subnets(count_log2))[0:count] -def write_big_route_conf(super_prefix, count, confpath): +def write_big_route_conf(super_prefix, count, confpath, prologue=""): start = None end = None with open(confpath, "w+", encoding="ascii") as f: + if prologue: + f.write(prologue + "\n") for net in get_ip_networks(super_prefix, count): end = net if not start: diff --git a/tests/topotests/mgmt_tests/test_yang_mgmt.py b/tests/topotests/mgmt_tests/test_yang_mgmt.py index 921b4e622c..bf4e95b275 100644 --- a/tests/topotests/mgmt_tests/test_yang_mgmt.py +++ b/tests/topotests/mgmt_tests/test_yang_mgmt.py @@ -68,7 +68,7 @@ from lib.bgp import verify_bgp_convergence, create_router_bgp, verify_bgp_rib from lib.topojson import build_config_from_json -pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] +pytestmark = [pytest.mark.bgpd, pytest.mark.staticd, pytest.mark.mgmtd] # Global variables ADDR_TYPES = check_address_types() diff --git a/tests/topotests/multicast_mld_join_topo1/test_multicast_mld_local_join.py b/tests/topotests/multicast_mld_join_topo1/test_multicast_mld_local_join.py index 2c4fb4e998..84a13aedee 100644 --- a/tests/topotests/multicast_mld_join_topo1/test_multicast_mld_local_join.py +++ b/tests/topotests/multicast_mld_join_topo1/test_multicast_mld_local_join.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +# -*- coding: utf-8 eval: (blacken-mode 1) -*- # SPDX-License-Identifier: ISC # # Copyright (c) 2023 by VMware, Inc. ("VMware") @@ -20,52 +20,35 @@ 5. Verify static MLD groups after removing and adding MLD config """ -import os import sys import time -import pytest - -# Save the Current Working Directory to find configuration files. -CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, "../")) -sys.path.append(os.path.join(CWD, "../lib/")) - -# Required to instantiate the topology builder class. - -# pylint: disable=C0413 -# Import topogen and topotest helpers -from lib.topogen import Topogen, get_topogen -from re import search as re_search -from re import findall as findall +import pytest from lib.common_config import ( + reset_config_on_routers, start_topology, - write_test_header, - write_test_footer, step, - kill_router_daemons, - start_router_daemons, - reset_config_on_routers, - do_countdown, - apply_raw_config, - socat_send_pim6_traffic, + write_test_footer, + write_test_header, ) - from lib.pim import ( - create_pim_config, - verify_mroutes, - verify_upstream_iif, - verify_mld_groups, - clear_pim6_mroute, McastTesterHelper, - verify_pim_neighbors, create_mld_config, - verify_mld_groups, + create_pim_config, verify_local_mld_groups, + verify_mld_groups, + verify_mroutes, + verify_pim_neighbors, verify_pim_rp_info, + verify_upstream_iif, ) -from lib.topolog import logger +from lib.bgp import ( + verify_bgp_convergence, +) + +from lib.topogen import Topogen, get_topogen from lib.topojson import build_config_from_json +from lib.topolog import logger r1_r2_links = [] r1_r3_links = [] @@ -131,7 +114,7 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - json_file = "{}/multicast_mld_local_join.json".format(CWD) + json_file = "multicast_mld_local_join.json" tgen = Topogen(json_file, mod.__name__) global topo topo = tgen.json_topo @@ -147,10 +130,20 @@ def setup_module(mod): # Creating configuration from JSON build_config_from_json(tgen, topo) + + # Verify BGP convergence + BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo, addr_type="ipv6") + assert BGP_CONVERGENCE is True, "setup_module : Failed \n Error:" " {}".format( + BGP_CONVERGENCE + ) + # Verify PIM neighbors result = verify_pim_neighbors(tgen, topo) assert result is True, " Verify PIM neighbor: Failed Error: {}".format(result) + global app_helper + app_helper = McastTesterHelper(tgen) + logger.info("Running setup_module() done") @@ -161,6 +154,8 @@ def teardown_module(): tgen = get_topogen() + app_helper.cleanup() + # Stop toplogy and Remove tmp files tgen.stop_topology() @@ -193,6 +188,10 @@ def test_mld_local_joins_p0(request): reset_config_on_routers(tgen) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo, addr_type="ipv6") + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + step("configure BGP on R1, R2, R3, R4 and enable redistribute static/connected") step("Enable the MLD on R11 interfac of R1 and configure local mld groups") intf_r1_i1 = topo["routers"]["r1"]["links"]["i1"]["interface"] @@ -265,6 +264,12 @@ def test_mroute_with_mld_local_joins_p0(request): reset_config_on_routers(tgen) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo, addr_type="ipv6") + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + app_helper.stop_all_hosts() + step("Enable the PIM on all the interfaces of R1, R2, R3, R4") step("configure BGP on R1, R2, R3, R4 and enable redistribute static/connected") step("Enable the MLD on R11 interfac of R1 and configure local mld groups") @@ -330,9 +335,7 @@ def test_mroute_with_mld_local_joins_p0(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("Send traffic from R4 to all the groups ( ffaa::1 to ffaa::5)") - intf_ip = topo["routers"]["i4"]["links"]["r4"]["ipv6"].split("/")[0] - intf = topo["routers"]["i4"]["links"]["r4"]["interface"] - result = socat_send_pim6_traffic(tgen, "i4", "UDP6-SEND", MLD_JOIN_RANGE_1, intf) + result = app_helper.run_traffic("i4", MLD_JOIN_RANGE_1, "r4") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step( @@ -458,6 +461,12 @@ def test_remove_add_mld_local_joins_p1(request): reset_config_on_routers(tgen) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo, addr_type="ipv6") + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + app_helper.stop_all_hosts() + step("Enable the PIM on all the interfaces of R1, R2, R3, R4") step("configure BGP on R1, R2, R3, R4 and enable redistribute static/connected") step("Enable the MLD on R11 interfac of R1 and configure local mld groups") @@ -517,9 +526,7 @@ def test_remove_add_mld_local_joins_p1(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("Send traffic from R4 to all the groups ( ffaa::1 to ffaa::5)") - intf_ip = topo["routers"]["i4"]["links"]["r4"]["ipv6"].split("/")[0] - intf = topo["routers"]["i4"]["links"]["r4"]["interface"] - result = socat_send_pim6_traffic(tgen, "i4", "UDP6-SEND", MLD_JOIN_RANGE_1, intf) + result = app_helper.run_traffic("i4", MLD_JOIN_RANGE_1, "r4") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step( @@ -710,6 +717,12 @@ def test_remove_add_mld_config_with_local_joins_p1(request): reset_config_on_routers(tgen) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo, addr_type="ipv6") + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + app_helper.stop_all_hosts() + step("Enable the PIM on all the interfaces of R1, R2, R3, R4") step("configure BGP on R1, R2, R3, R4 and enable redistribute static/connected") step("Enable the MLD on R11 interfac of R1 and configure local mld groups") @@ -759,9 +772,7 @@ def test_remove_add_mld_config_with_local_joins_p1(request): assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) step("Send traffic from R4 to all the groups ( ffaa::1 to ffaa::5)") - intf_ip = topo["routers"]["i4"]["links"]["r4"]["ipv6"].split("/")[0] - intf = topo["routers"]["i4"]["links"]["r4"]["interface"] - result = socat_send_pim6_traffic(tgen, "i4", "UDP6-SEND", MLD_JOIN_RANGE_1, intf) + result = app_helper.run_traffic("i4", MLD_JOIN_RANGE_1, "r4") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step( diff --git a/tests/topotests/multicast_pim6_sm_topo1/test_multicast_pim6_sm1.py b/tests/topotests/multicast_pim6_sm_topo1/test_multicast_pim6_sm1.py index 87b04b41be..7eb5838037 100644 --- a/tests/topotests/multicast_pim6_sm_topo1/test_multicast_pim6_sm1.py +++ b/tests/topotests/multicast_pim6_sm_topo1/test_multicast_pim6_sm1.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +# -*- coding: utf-8 eval: (blacken-mode 1) -*- # SPDX-License-Identifier: ISC # @@ -30,61 +30,43 @@ data traffic """ -import os +import datetime import sys -import json import time -import datetime -import pytest - -# Save the Current Working Directory to find configuration files. -CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, "../")) -sys.path.append(os.path.join(CWD, "../lib/")) - -# Required to instantiate the topology builder class. - -# pylint: disable=C0413 -# Import topogen and topotest helpers -from lib.topogen import Topogen, get_topogen +import pytest from lib.common_config import ( - start_topology, - write_test_header, - write_test_footer, - step, + get_frr_ipv6_linklocal, + required_linux_kernel_version, reset_config_on_routers, shutdown_bringup_interface, - start_router, - stop_router, - create_static_routes, - required_linux_kernel_version, - socat_send_mld_join, - socat_send_pim6_traffic, - get_frr_ipv6_linklocal, - kill_socat, + start_topology, + step, + write_test_footer, + write_test_header, ) -from lib.bgp import create_router_bgp from lib.pim import ( - create_pim_config, + McastTesterHelper, + clear_pim6_mroute, create_mld_config, + create_pim_config, + verify_mld_config, verify_mld_groups, + verify_mroute_summary, verify_mroutes, - clear_pim6_interface_traffic, - verify_upstream_iif, - clear_pim6_mroute, verify_pim_interface_traffic, - verify_pim_state, - McastTesterHelper, verify_pim_join, - verify_mroute_summary, verify_pim_nexthop, + verify_pim_state, verify_sg_traffic, - verify_mld_config, + verify_upstream_iif, ) - -from lib.topolog import logger +from lib.bgp import ( + verify_bgp_convergence, +) +from lib.topogen import Topogen, get_topogen from lib.topojson import build_config_from_json +from lib.topolog import logger # Global variables GROUP_RANGE = "ff00::/8" @@ -141,8 +123,7 @@ def setup_module(mod): logger.info("Running setup_module to create topology") - testdir = os.path.dirname(os.path.realpath(__file__)) - json_file = "{}/multicast_pim6_sm_topo1.json".format(testdir) + json_file = "multicast_pim6_sm_topo1.json" tgen = Topogen(json_file, mod.__name__) global topo topo = tgen.json_topo @@ -159,6 +140,15 @@ def setup_module(mod): # Creating configuration from JSON build_config_from_json(tgen, tgen.json_topo) + global app_helper + app_helper = McastTesterHelper(tgen) + + # Verify BGP convergence + BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo, addr_type="ipv6") + assert BGP_CONVERGENCE is True, "setup_module : Failed \n Error:" " {}".format( + BGP_CONVERGENCE + ) + logger.info("Running setup_module() done") @@ -169,8 +159,7 @@ def teardown_module(): tgen = get_topogen() - # Clean up socat - kill_socat(tgen) + app_helper.cleanup() # Stop toplogy and Remove tmp files tgen.stop_topology() @@ -296,6 +285,12 @@ def test_multicast_data_traffic_static_RP_send_traffic_then_join_p0(request): # Creating configuration from JSON reset_config_on_routers(tgen) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo, addr_type="ipv6") + assert result is True, "Testcase {} : Failed \n Error {}".format(tc_name, result) + + app_helper.stop_all_hosts() + # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) @@ -334,9 +329,7 @@ def test_multicast_data_traffic_static_RP_send_traffic_then_join_p0(request): step("Send multicast traffic from FRR3 to all the receivers" "ffaa::1-5") - intf_ip = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0] - intf = topo["routers"]["i2"]["links"]["r3"]["interface"] - result = socat_send_pim6_traffic(tgen, "i2", "UDP6-SEND", MLD_JOIN_RANGE_1, intf) + result = app_helper.run_traffic("i2", MLD_JOIN_RANGE_1, "r3") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) source = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0] @@ -375,11 +368,7 @@ def test_multicast_data_traffic_static_RP_send_traffic_then_join_p0(request): ) step("send mld join (ffaa::1-5) to R1") - intf = topo["routers"]["i1"]["links"]["r1"]["interface"] - intf_ip = topo["routers"]["i1"]["links"]["r1"]["ipv6"].split("/")[0] - result = socat_send_mld_join( - tgen, "i1", "UDP6-RECV", MLD_JOIN_RANGE_1, intf, intf_ip - ) + result = app_helper.run_join("i1", MLD_JOIN_RANGE_1, "r1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step( @@ -504,6 +493,10 @@ def test_verify_mroute_when_receiver_is_outside_frr_p0(request): # Creating configuration from JSON reset_config_on_routers(tgen) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo, addr_type="ipv6") + assert result is True, "Testcase {} : Failed \n Error {}".format(tc_name, result) + # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) @@ -532,11 +525,7 @@ def test_verify_mroute_when_receiver_is_outside_frr_p0(request): assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("send mld join (ffaa::1-5) to R1") - intf = topo["routers"]["i1"]["links"]["r1"]["interface"] - intf_ip = topo["routers"]["i1"]["links"]["r1"]["ipv6"].split("/")[0] - result = socat_send_mld_join( - tgen, "i1", "UDP6-RECV", _MLD_JOIN_RANGE, intf, intf_ip - ) + result = app_helper.run_join("i1", _MLD_JOIN_RANGE, "r1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("verify MLD joins received on r1") @@ -546,9 +535,7 @@ def test_verify_mroute_when_receiver_is_outside_frr_p0(request): assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Send multicast traffic from FRR3 to all the receivers" "ffaa::1-5") - intf_ip = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0] - intf = topo["routers"]["i2"]["links"]["r3"]["interface"] - result = socat_send_pim6_traffic(tgen, "i2", "UDP6-SEND", _MLD_JOIN_RANGE, intf) + result = app_helper.run_traffic("i2", _MLD_JOIN_RANGE, "r3") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step( @@ -561,11 +548,7 @@ def test_verify_mroute_when_receiver_is_outside_frr_p0(request): result = create_mld_config(tgen, topo, input_dict) assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) - i5_r5 = topo["routers"]["i5"]["links"]["r5"]["interface"] - intf_ip = topo["routers"]["i5"]["links"]["r5"]["ipv6"].split("/")[0] - result = socat_send_mld_join( - tgen, "i5", "UDP6-RECV", _MLD_JOIN_RANGE, i5_r5, intf_ip - ) + result = app_helper.run_join("i5", _MLD_JOIN_RANGE, "r5") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("FRR1 has 10 (*.G) and 10 (S,G) verify using 'show ipv6 mroute'") @@ -682,6 +665,12 @@ def test_verify_mroute_when_frr_is_transit_router_p2(request): # Creating configuration from JSON reset_config_on_routers(tgen) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo, addr_type="ipv6") + assert result is True, "Testcase {} : Failed \n Error {}".format(tc_name, result) + + app_helper.stop_all_hosts() + # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) @@ -708,11 +697,7 @@ def test_verify_mroute_when_frr_is_transit_router_p2(request): step("Enable mld on FRR1 interface and send mld join ") step("send mld join (ffaa::1-5) to R1") - intf = topo["routers"]["i1"]["links"]["r1"]["interface"] - intf_ip = topo["routers"]["i1"]["links"]["r1"]["ipv6"].split("/")[0] - result = socat_send_mld_join( - tgen, "i1", "UDP6-RECV", MLD_JOIN_RANGE_1, intf, intf_ip - ) + result = app_helper.run_join("i1", MLD_JOIN_RANGE_1, "r1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("verify mld groups received on R1") @@ -722,9 +707,7 @@ def test_verify_mroute_when_frr_is_transit_router_p2(request): assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Send multicast traffic from FRR3 to ffaa::1-5 receivers") - intf_ip = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0] - intf = topo["routers"]["i2"]["links"]["r3"]["interface"] - result = socat_send_pim6_traffic(tgen, "i2", "UDP6-SEND", MLD_JOIN_RANGE_1, intf) + result = app_helper.run_traffic("i2", MLD_JOIN_RANGE_1, "r3") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("shut the direct link to R1 ") @@ -841,6 +824,12 @@ def test_verify_mroute_when_RP_unreachable_p1(request): # Creating configuration from JSON reset_config_on_routers(tgen) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo, addr_type="ipv6") + assert result is True, "Testcase {} : Failed \n Error {}".format(tc_name, result) + + app_helper.stop_all_hosts() + # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) @@ -868,17 +857,11 @@ def test_verify_mroute_when_RP_unreachable_p1(request): step("Enable mld on FRR1 interface and send mld join ffaa::1-5") step("send mld join (ffaa::1-5) to R1") - intf = topo["routers"]["i1"]["links"]["r1"]["interface"] - intf_ip = topo["routers"]["i1"]["links"]["r1"]["ipv6"].split("/")[0] - result = socat_send_mld_join( - tgen, "i1", "UDP6-RECV", MLD_JOIN_RANGE_1, intf, intf_ip - ) + result = app_helper.run_join("i1", MLD_JOIN_RANGE_1, "r1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Send multicast traffic from FRR3 to ffaa::1-5 receivers") - intf_ip = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0] - intf = topo["routers"]["i2"]["links"]["r3"]["interface"] - result = socat_send_pim6_traffic(tgen, "i2", "UDP6-SEND", MLD_JOIN_RANGE_1, intf) + result = app_helper.run_traffic("i2", MLD_JOIN_RANGE_1, "r3") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure one MLD interface on FRR3 node and send MLD" " join (ffcc::1)") @@ -888,11 +871,7 @@ def test_verify_mroute_when_RP_unreachable_p1(request): assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("send mld join (ffaa::1-5) to R1") - intf = topo["routers"]["i8"]["links"]["r3"]["interface"] - intf_ip = topo["routers"]["i8"]["links"]["r3"]["ipv6"].split("/")[0] - result = socat_send_mld_join( - tgen, "i8", "UDP6-RECV", MLD_JOIN_RANGE_1, intf, intf_ip - ) + result = app_helper.run_join("i8", MLD_JOIN_RANGE_1, "r3") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("verify MLD groups received ") @@ -975,16 +954,18 @@ def test_modify_mld_query_timer_p0(request): # Creating configuration from JSON reset_config_on_routers(tgen) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo, addr_type="ipv6") + assert result is True, "Testcase {} : Failed \n Error {}".format(tc_name, result) + + app_helper.stop_all_hosts() + # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) step("send mld join (ffaa::1-5) to R1") - intf = topo["routers"]["i8"]["links"]["r3"]["interface"] - intf_ip = topo["routers"]["i8"]["links"]["r3"]["ipv6"].split("/")[0] - result = socat_send_mld_join( - tgen, "i8", "UDP6-RECV", MLD_JOIN_RANGE_1, intf, intf_ip - ) + result = app_helper.run_join("i8", MLD_JOIN_RANGE_1, "r3") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Enable MLD on receiver interface") @@ -1023,9 +1004,7 @@ def test_modify_mld_query_timer_p0(request): assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Send multicast traffic from FRR3 to ffaa::1-5 receivers") - intf_ip = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0] - intf = topo["routers"]["i2"]["links"]["r3"]["interface"] - result = socat_send_pim6_traffic(tgen, "i2", "UDP6-SEND", MLD_JOIN_RANGE_1, intf) + result = app_helper.run_traffic("i2", MLD_JOIN_RANGE_1, "r3") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step( @@ -1158,17 +1137,19 @@ def test_modify_mld_max_query_response_timer_p0(request): # Creating configuration from JSON reset_config_on_routers(tgen) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo, addr_type="ipv6") + assert result is True, "Testcase {} : Failed \n Error {}".format(tc_name, result) + + app_helper.stop_all_hosts() + # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) step("Enable mld on FRR1 interface and send MLD join") step("send mld join (ffaa::1-5) to R1") - intf = topo["routers"]["i1"]["links"]["r1"]["interface"] - intf_ip = topo["routers"]["i1"]["links"]["r1"]["ipv6"].split("/")[0] - result = socat_send_mld_join( - tgen, "i1", "UDP6-RECV", MLD_JOIN_RANGE_1, intf, intf_ip - ) + result = app_helper.run_join("i1", MLD_JOIN_RANGE_1, "r1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) r1_i1 = topo["routers"]["r1"]["links"]["i1"]["interface"] @@ -1214,9 +1195,7 @@ def test_modify_mld_max_query_response_timer_p0(request): assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("Send multicast traffic from FRR3 to ffaa::1-5 receivers") - intf_ip = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0] - intf = topo["routers"]["i2"]["links"]["r3"]["interface"] - result = socat_send_pim6_traffic(tgen, "i2", "UDP6-SEND", MLD_JOIN_RANGE_1, intf) + result = app_helper.run_traffic("i2", MLD_JOIN_RANGE_1, "r3") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step( @@ -1431,6 +1410,12 @@ def test_verify_impact_on_multicast_traffic_when_RP_removed_p0(request): # Creating configuration from JSON reset_config_on_routers(tgen) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo, addr_type="ipv6") + assert result is True, "Testcase {} : Failed \n Error {}".format(tc_name, result) + + app_helper.stop_all_hosts() + # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) @@ -1438,9 +1423,7 @@ def test_verify_impact_on_multicast_traffic_when_RP_removed_p0(request): step("send multicast traffic for group range ffaa::1-5") step("Send multicast traffic from FRR3 to ffaa::1-5 receivers") - intf_ip = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0] - intf = topo["routers"]["i2"]["links"]["r3"]["interface"] - result = socat_send_pim6_traffic(tgen, "i2", "UDP6-SEND", MLD_JOIN_RANGE_1, intf) + result = app_helper.run_traffic("i2", MLD_JOIN_RANGE_1, "r3") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Configure static RP for group (ffaa::1) on r5") @@ -1464,11 +1447,7 @@ def test_verify_impact_on_multicast_traffic_when_RP_removed_p0(request): step("Enable mld on FRR1 interface and send MLD join") step("send mld join (ffaa::1-5) to R1") - intf = topo["routers"]["i1"]["links"]["r1"]["interface"] - intf_ip = topo["routers"]["i1"]["links"]["r1"]["ipv6"].split("/")[0] - result = socat_send_mld_join( - tgen, "i1", "UDP6-RECV", MLD_JOIN_RANGE_1, intf, intf_ip - ) + result = app_helper.run_join("i1", MLD_JOIN_RANGE_1, "r1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step( diff --git a/tests/topotests/multicast_pim6_sm_topo1/test_multicast_pim6_sm2.py b/tests/topotests/multicast_pim6_sm_topo1/test_multicast_pim6_sm2.py index 788a839918..8b174bf9b8 100644 --- a/tests/topotests/multicast_pim6_sm_topo1/test_multicast_pim6_sm2.py +++ b/tests/topotests/multicast_pim6_sm_topo1/test_multicast_pim6_sm2.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +# -*- coding: utf-8 eval: (blacken-mode 1) -*- # SPDX-License-Identifier: ISC # @@ -21,61 +21,34 @@ different """ -import os import sys -import json import time -import datetime -import pytest - -# Save the Current Working Directory to find configuration files. -CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, "../")) -sys.path.append(os.path.join(CWD, "../lib/")) - -# Required to instantiate the topology builder class. - -# pylint: disable=C0413 -# Import topogen and topotest helpers -from lib.topogen import Topogen, get_topogen +import pytest from lib.common_config import ( - start_topology, - write_test_header, - write_test_footer, - step, + required_linux_kernel_version, reset_config_on_routers, shutdown_bringup_interface, - start_router, - stop_router, - create_static_routes, - required_linux_kernel_version, - socat_send_mld_join, - socat_send_pim6_traffic, - get_frr_ipv6_linklocal, - kill_socat, + start_topology, + step, + write_test_footer, + write_test_header, ) -from lib.bgp import create_router_bgp from lib.pim import ( + McastTesterHelper, + clear_pim6_mroute, create_pim_config, - create_mld_config, - verify_mld_groups, verify_mroutes, - clear_pim6_interface_traffic, - verify_upstream_iif, - clear_pim6_mroute, verify_pim_interface_traffic, - verify_pim_state, - McastTesterHelper, - verify_pim_join, - verify_mroute_summary, - verify_pim_nexthop, verify_sg_traffic, - verify_mld_config, + verify_upstream_iif, ) - -from lib.topolog import logger +from lib.bgp import ( + verify_bgp_convergence, +) +from lib.topogen import Topogen, get_topogen from lib.topojson import build_config_from_json +from lib.topolog import logger # Global variables GROUP_RANGE = "ff00::/8" @@ -114,6 +87,16 @@ pytestmark = [pytest.mark.pim6d] +@pytest.fixture(scope="function") +def app_helper(): + # helper = McastTesterHelper(get_topogen()) + # yield helepr + # helper.cleanup() + # Even better use contextmanager functionality: + with McastTesterHelper(get_topogen()) as ah: + yield ah + + def setup_module(mod): """ Sets up the pytest environment @@ -132,8 +115,7 @@ def setup_module(mod): logger.info("Running setup_module to create topology") - testdir = os.path.dirname(os.path.realpath(__file__)) - json_file = "{}/multicast_pim6_sm_topo1.json".format(testdir) + json_file = "multicast_pim6_sm_topo1.json" tgen = Topogen(json_file, mod.__name__) global topo topo = tgen.json_topo @@ -150,6 +132,12 @@ def setup_module(mod): # Creating configuration from JSON build_config_from_json(tgen, tgen.json_topo) + # Verify BGP convergence + BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo, addr_type="ipv6") + assert BGP_CONVERGENCE is True, "setup_module : Failed \n Error:" " {}".format( + BGP_CONVERGENCE + ) + logger.info("Running setup_module() done") @@ -160,9 +148,6 @@ def teardown_module(): tgen = get_topogen() - # Clean up socat - kill_socat(tgen) - # Stop toplogy and Remove tmp files tgen.stop_topology() @@ -225,7 +210,7 @@ def verify_state_incremented(state_before, state_after): ##################################################### -def test_clear_mroute_and_verify_multicast_data_p0(request): +def test_clear_mroute_and_verify_multicast_data_p0(request, app_helper): """ Verify (*,G) and (S,G) entry populated again after clear the PIM nbr and mroute from FRR node @@ -237,6 +222,12 @@ def test_clear_mroute_and_verify_multicast_data_p0(request): # Creating configuration from JSON reset_config_on_routers(tgen) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo, addr_type="ipv6") + assert result is True, "Testcase {} : Failed \n Error {}".format(tc_name, result) + + app_helper.stop_all_hosts() + # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) @@ -266,18 +257,12 @@ def test_clear_mroute_and_verify_multicast_data_p0(request): ) step("send mld join (ffaa::1-5) to R1") - intf = topo["routers"]["i1"]["links"]["r1"]["interface"] - intf_ip = topo["routers"]["i1"]["links"]["r1"]["ipv6"].split("/")[0] - result = socat_send_mld_join( - tgen, "i1", "UDP6-RECV", MLD_JOIN_RANGE_1, intf, intf_ip - ) + result = app_helper.run_join("i1", MLD_JOIN_RANGE_1, "r1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Send multicast traffic from FRR3 to all the receivers" "ffaa::1-5") - intf_ip = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0] - intf = topo["routers"]["i2"]["links"]["r3"]["interface"] - result = socat_send_pim6_traffic(tgen, "i2", "UDP6-SEND", MLD_JOIN_RANGE_1, intf) + result = app_helper.run_traffic("i2", MLD_JOIN_RANGE_1, "r3") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("Clear the mroute on r1, wait for 5 sec") @@ -457,7 +442,9 @@ def test_clear_mroute_and_verify_multicast_data_p0(request): write_test_footer(tc_name) -def test_verify_SPT_switchover_when_RPT_and_SPT_path_is_different_p0(request): +def test_verify_SPT_switchover_when_RPT_and_SPT_path_is_different_p0( + request, app_helper +): """ Verify SPT switchover working when RPT and SPT path is different @@ -470,6 +457,10 @@ def test_verify_SPT_switchover_when_RPT_and_SPT_path_is_different_p0(request): # Creating configuration from JSON reset_config_on_routers(tgen) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo, addr_type="ipv6") + assert result is True, "Testcase {} : Failed \n Error {}".format(tc_name, result) + # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) @@ -498,11 +489,7 @@ def test_verify_SPT_switchover_when_RPT_and_SPT_path_is_different_p0(request): assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) step("send mld join (ffbb::1-5, ffcc::1-5) to R1") - intf = topo["routers"]["i1"]["links"]["r1"]["interface"] - intf_ip = topo["routers"]["i1"]["links"]["r1"]["ipv6"].split("/")[0] - result = socat_send_mld_join( - tgen, "i1", "UDP6-RECV", _MLD_JOIN_RANGE, intf, intf_ip - ) + result = app_helper.run_join("i1", _MLD_JOIN_RANGE, "r1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("registerRx and registerStopTx value before traffic sent") @@ -518,9 +505,7 @@ def test_verify_SPT_switchover_when_RPT_and_SPT_path_is_different_p0(request): step( "Send multicast traffic from FRR3 to all the receivers" "ffbb::1-5 , ffcc::1-5" ) - intf_ip = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0] - intf = topo["routers"]["i2"]["links"]["r3"]["interface"] - result = socat_send_pim6_traffic(tgen, "i2", "UDP6-SEND", _MLD_JOIN_RANGE, intf) + result = app_helper.run_traffic("i2", _MLD_JOIN_RANGE, "r3") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step( diff --git a/tests/topotests/multicast_pim6_static_rp_topo1/test_multicast_pim6_static_rp1.py b/tests/topotests/multicast_pim6_static_rp_topo1/test_multicast_pim6_static_rp1.py index 977cd477c8..23326337d6 100755 --- a/tests/topotests/multicast_pim6_static_rp_topo1/test_multicast_pim6_static_rp1.py +++ b/tests/topotests/multicast_pim6_static_rp_topo1/test_multicast_pim6_static_rp1.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +# -*- coding: utf-8 eval: (blacken-mode 1) -*- # SPDX-License-Identifier: ISC # @@ -41,57 +41,36 @@ 8. Verify PIM6 join send towards the higher preferred RP 9. Verify PIM6 prune send towards the lower preferred RP """ - -import os import sys -import json import time -import pytest - -# Save the Current Working Directory to find configuration files. -CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, "../")) -sys.path.append(os.path.join(CWD, "../lib/")) - -# Required to instantiate the topology builder class. - -# pylint: disable=C0413 -# Import topogen and topotest helpers -from lib.topogen import Topogen, get_topogen +import pytest from lib.common_config import ( - start_topology, - write_test_header, - write_test_footer, + check_router_status, reset_config_on_routers, - step, shutdown_bringup_interface, - kill_router_daemons, - start_router_daemons, - create_static_routes, - check_router_status, - socat_send_mld_join, - socat_send_pim6_traffic, - kill_socat, + start_topology, + step, + write_test_footer, + write_test_header, ) from lib.pim import ( + McastTesterHelper, + clear_pim6_interface_traffic, create_pim_config, - verify_upstream_iif, + get_pim6_interface_traffic, verify_join_state_and_timer, + verify_mld_groups, verify_mroutes, - verify_pim_neighbors, + verify_pim6_neighbors, verify_pim_interface_traffic, verify_pim_rp_info, verify_pim_state, - clear_pim6_interface_traffic, - clear_pim6_mroute, - verify_pim6_neighbors, - get_pim6_interface_traffic, - clear_pim6_interfaces, - verify_mld_groups, + verify_upstream_iif, ) +from lib.topogen import Topogen, get_topogen +from lib.topojson import build_config_from_json, build_topo_from_json from lib.topolog import logger -from lib.topojson import build_topo_from_json, build_config_from_json # Global variables GROUP_RANGE_1 = "ff08::/64" @@ -141,7 +120,7 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - json_file = "{}/multicast_pim6_static_rp.json".format(CWD) + json_file = "multicast_pim6_static_rp.json" tgen = Topogen(json_file, mod.__name__) global TOPO TOPO = tgen.json_topo @@ -163,6 +142,9 @@ def setup_module(mod): result = verify_pim6_neighbors(tgen, TOPO) assert result is True, "setup_module :Failed \n Error:" " {}".format(result) + global app_helper + app_helper = McastTesterHelper(tgen) + logger.info("Running setup_module() done") @@ -172,8 +154,7 @@ def teardown_module(): logger.info("Running teardown_module to delete topology") tgen = get_topogen() - # Clean up socat - kill_socat(tgen) + app_helper.cleanup() # Stop toplogy and Remove tmp files tgen.stop_topology() @@ -260,6 +241,8 @@ def test_pim6_add_delete_static_RP_p0(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) + app_helper.stop_all_hosts() + step("Shut link b/w R1 and R3 and R1 and R4 as per testcase topology") intf_r1_r3 = TOPO["routers"]["r1"]["links"]["r3"]["interface"] intf_r1_r4 = TOPO["routers"]["r1"]["links"]["r4"]["interface"] @@ -313,11 +296,7 @@ def test_pim6_add_delete_static_RP_p0(request): ) step("send mld join {} to R1".format(GROUP_ADDRESS_1)) - intf = TOPO["routers"]["r0"]["links"]["r1"]["interface"] - intf_ip = TOPO["routers"]["r0"]["links"]["r1"]["ipv6"].split("/")[0] - result = socat_send_mld_join( - tgen, "r0", "UDP6-RECV", GROUP_ADDRESS_1, intf, intf_ip - ) + result = app_helper.run_join("r0", GROUP_ADDRESS_1, "r1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("r1: Verify MLD groups") @@ -457,6 +436,8 @@ def test_pim6_SPT_RPT_path_same_p1(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) + app_helper.stop_all_hosts() + step("Shut link b/w R1->R3, R1->R4 and R3->R1, R3->R4 as per " "testcase topology") intf_r1_r3 = TOPO["routers"]["r1"]["links"]["r3"]["interface"] intf_r1_r4 = TOPO["routers"]["r1"]["links"]["r4"]["interface"] @@ -494,11 +475,7 @@ def test_pim6_SPT_RPT_path_same_p1(request): step( "Enable MLD on r1 interface and send MLD join {} to R1".format(GROUP_ADDRESS_1) ) - intf = TOPO["routers"]["r0"]["links"]["r1"]["interface"] - intf_ip = TOPO["routers"]["r0"]["links"]["r1"]["ipv6"].split("/")[0] - result = socat_send_mld_join( - tgen, "r0", "UDP6-RECV", GROUP_ADDRESS_1, intf, intf_ip - ) + result = app_helper.run_join("r0", GROUP_ADDRESS_1, "r1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("r1: Verify MLD groups") @@ -508,9 +485,8 @@ def test_pim6_SPT_RPT_path_same_p1(request): assert result is True, ASSERT_MSG.format(tc_name, result) step("Send multicast traffic from R5") - intf = TOPO["routers"]["r5"]["links"]["r3"]["interface"] SOURCE_ADDRESS = TOPO["routers"]["r5"]["links"]["r3"]["ipv6"].split("/")[0] - result = socat_send_pim6_traffic(tgen, "r5", "UDP6-SEND", GROUP_ADDRESS_1, intf) + result = app_helper.run_traffic("r5", GROUP_ADDRESS_1, "r3") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("r2: Verify RP info") @@ -630,6 +606,8 @@ def test_pim6_RP_configured_as_LHR_p1(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) + app_helper.stop_all_hosts() + step("Enable MLD on r1 interface") step("Enable the PIM6 on all the interfaces of r1, r2, r3 and r4 routers") @@ -665,11 +643,7 @@ def test_pim6_RP_configured_as_LHR_p1(request): assert result is True, ASSERT_MSG.format(tc_name, result) step("send mld join {} to R1".format(GROUP_ADDRESS_1)) - intf = TOPO["routers"]["r0"]["links"]["r1"]["interface"] - intf_ip = TOPO["routers"]["r0"]["links"]["r1"]["ipv6"].split("/")[0] - result = socat_send_mld_join( - tgen, "r0", "UDP6-RECV", GROUP_ADDRESS_1, intf, intf_ip - ) + result = app_helper.run_join("r0", GROUP_ADDRESS_1, "r1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("r1: Verify MLD groups") @@ -679,9 +653,8 @@ def test_pim6_RP_configured_as_LHR_p1(request): assert result is True, ASSERT_MSG.format(tc_name, result) step("r5: Send multicast traffic for group {}".format(GROUP_ADDRESS_1)) - intf = TOPO["routers"]["r5"]["links"]["r3"]["interface"] SOURCE_ADDRESS = TOPO["routers"]["r5"]["links"]["r3"]["ipv6"].split("/")[0] - result = socat_send_pim6_traffic(tgen, "r5", "UDP6-SEND", GROUP_ADDRESS_1, intf) + result = app_helper.run_traffic("r5", GROUP_ADDRESS_1, "r3") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("r1: Verify (*, G) upstream IIF interface") @@ -762,6 +735,8 @@ def test_pim6_RP_configured_as_FHR_p1(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) + app_helper.stop_all_hosts() + step("Enable MLD on r1 interface") step("Enable the PIM6 on all the interfaces of r1, r2, r3 and r4 routers") step("r3: Configure r3(FHR) as RP") @@ -792,11 +767,7 @@ def test_pim6_RP_configured_as_FHR_p1(request): assert result is True, ASSERT_MSG.format(tc_name, result) step("send mld join {} to R1".format(GROUP_ADDRESS_1)) - intf = TOPO["routers"]["r0"]["links"]["r1"]["interface"] - intf_ip = TOPO["routers"]["r0"]["links"]["r1"]["ipv6"].split("/")[0] - result = socat_send_mld_join( - tgen, "r0", "UDP6-RECV", GROUP_ADDRESS_1, intf, intf_ip - ) + result = app_helper.run_join("r0", GROUP_ADDRESS_1, "r1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("r1: Verify MLD groups") @@ -806,9 +777,8 @@ def test_pim6_RP_configured_as_FHR_p1(request): assert result is True, ASSERT_MSG.format(tc_name, result) step("r5: Send multicast traffic for group {}".format(GROUP_ADDRESS_1)) - intf = TOPO["routers"]["r5"]["links"]["r3"]["interface"] SOURCE_ADDRESS = TOPO["routers"]["r5"]["links"]["r3"]["ipv6"].split("/")[0] - result = socat_send_pim6_traffic(tgen, "r5", "UDP6-SEND", GROUP_ADDRESS_1, intf) + result = app_helper.run_traffic("r5", GROUP_ADDRESS_1, "r3") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("r1: Verify (*, G) upstream IIF interface") @@ -890,6 +860,8 @@ def test_pim6_SPT_RPT_path_different_p1(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) + app_helper.stop_all_hosts() + step("Enable MLD on r1 interface") step("Enable the PIM6 on all the interfaces of r1, r2, r3 and r4 routers") step("r2: Configure r2 as RP") @@ -921,11 +893,7 @@ def test_pim6_SPT_RPT_path_different_p1(request): assert result is True, ASSERT_MSG.format(tc_name, result) step("send mld join {} to R1".format(GROUP_ADDRESS_1)) - intf = TOPO["routers"]["r0"]["links"]["r1"]["interface"] - intf_ip = TOPO["routers"]["r0"]["links"]["r1"]["ipv6"].split("/")[0] - result = socat_send_mld_join( - tgen, "r0", "UDP6-RECV", GROUP_ADDRESS_1, intf, intf_ip - ) + result = app_helper.run_join("r0", GROUP_ADDRESS_1, "r1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("r1: Verify MLD groups") @@ -935,9 +903,8 @@ def test_pim6_SPT_RPT_path_different_p1(request): assert result is True, ASSERT_MSG.format(tc_name, result) step("r5: Send multicast traffic for group {}".format(GROUP_ADDRESS_1)) - intf = TOPO["routers"]["r5"]["links"]["r3"]["interface"] SOURCE_ADDRESS = TOPO["routers"]["r5"]["links"]["r3"]["ipv6"].split("/")[0] - result = socat_send_pim6_traffic(tgen, "r5", "UDP6-SEND", GROUP_ADDRESS_1, intf) + result = app_helper.run_traffic("r5", GROUP_ADDRESS_1, "r3") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("r1: Verify (*, G) upstream IIF interface") @@ -1060,6 +1027,8 @@ def test_pim6_send_join_on_higher_preffered_rp_p1(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) + app_helper.stop_all_hosts() + step("Enable MLD on r1 interface") step("Enable the PIM66 on all the interfaces of r1, r2, r3 and r4 routers") step( @@ -1109,11 +1078,7 @@ def test_pim6_send_join_on_higher_preffered_rp_p1(request): ) step("r0: send mld join {} to R1".format(GROUP_ADDRESS_3)) - intf = TOPO["routers"]["r0"]["links"]["r1"]["interface"] - intf_ip = TOPO["routers"]["r0"]["links"]["r1"]["ipv6"].split("/")[0] - result = socat_send_mld_join( - tgen, "r0", "UDP6-RECV", GROUP_ADDRESS_3, intf, intf_ip - ) + result = app_helper.run_join("r0", GROUP_ADDRESS_3, "r1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("r1: Verify MLD groups") diff --git a/tests/topotests/multicast_pim6_static_rp_topo1/test_multicast_pim6_static_rp2.py b/tests/topotests/multicast_pim6_static_rp_topo1/test_multicast_pim6_static_rp2.py index a61164baa2..39497e91ed 100755 --- a/tests/topotests/multicast_pim6_static_rp_topo1/test_multicast_pim6_static_rp2.py +++ b/tests/topotests/multicast_pim6_static_rp_topo1/test_multicast_pim6_static_rp2.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +# -*- coding: utf-8 eval: (blacken-mode 1) -*- # SPDX-License-Identifier: ISC # @@ -33,55 +33,31 @@ import os import sys -import json import time -import pytest - -# Save the Current Working Directory to find configuration files. -CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, "../")) -sys.path.append(os.path.join(CWD, "../lib/")) - -# Required to instantiate the topology builder class. - -# pylint: disable=C0413 -# Import topogen and topotest helpers -from lib.topogen import Topogen, get_topogen +import pytest from lib.common_config import ( - start_topology, - write_test_header, - write_test_footer, + create_debug_log_config, reset_config_on_routers, - step, shutdown_bringup_interface, - kill_router_daemons, - start_router_daemons, - create_static_routes, - check_router_status, - socat_send_mld_join, - socat_send_pim6_traffic, - kill_socat, - create_debug_log_config, + start_topology, + step, + write_test_footer, + write_test_header, ) from lib.pim import ( + McastTesterHelper, create_pim_config, - verify_upstream_iif, verify_join_state_and_timer, + verify_mld_groups, verify_mroutes, - verify_pim_neighbors, - verify_pim_interface_traffic, - verify_pim_rp_info, - verify_pim_state, - clear_pim6_interface_traffic, - clear_pim6_mroute, verify_pim6_neighbors, - get_pim6_interface_traffic, - clear_pim6_interfaces, - verify_mld_groups, + verify_pim_rp_info, + verify_upstream_iif, ) +from lib.topogen import Topogen, get_topogen +from lib.topojson import build_config_from_json, build_topo_from_json from lib.topolog import logger -from lib.topojson import build_topo_from_json, build_config_from_json # Global variables GROUP_RANGE_1 = "ff08::/64" @@ -145,7 +121,7 @@ def setup_module(mod): logger.info("Running setup_module to create topology") # This function initiates the topology build with Topogen... - json_file = "{}/multicast_pim6_static_rp.json".format(CWD) + json_file = "multicast_pim6_static_rp.json" tgen = Topogen(json_file, mod.__name__) global TOPO TOPO = tgen.json_topo @@ -167,6 +143,9 @@ def setup_module(mod): result = verify_pim6_neighbors(tgen, TOPO) assert result is True, "setup_module :Failed \n Error:" " {}".format(result) + global app_helper + app_helper = McastTesterHelper(tgen) + logger.info("Running setup_module() done") @@ -176,8 +155,7 @@ def teardown_module(): logger.info("Running teardown_module to delete topology") tgen = get_topogen() - # Clean up socat - kill_socat(tgen) + app_helper.cleanup() # Stop toplogy and Remove tmp files tgen.stop_topology() @@ -265,6 +243,8 @@ def test_pim6_multiple_groups_same_RP_address_p2(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) + app_helper.stop_all_hosts() + input_dict = { "r1": {"debug": {"log_file": "r1_debug.log", "enable": ["pim6d"]}}, "r2": {"debug": {"log_file": "r2_debug.log", "enable": ["pim6d"]}}, @@ -305,10 +285,7 @@ def test_pim6_multiple_groups_same_RP_address_p2(request): group_address_list = GROUP_ADDRESS_LIST_1 + GROUP_ADDRESS_LIST_2 step("r0: Send MLD join for 10 groups") intf = TOPO["routers"]["r0"]["links"]["r1"]["interface"] - intf_ip = TOPO["routers"]["r0"]["links"]["r1"]["ipv6"].split("/")[0] - result = socat_send_mld_join( - tgen, "r0", "UDP6-RECV", group_address_list, intf, intf_ip - ) + result = app_helper.run_join("r0", group_address_list, "r1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("r1: Verify MLD groups") @@ -318,9 +295,8 @@ def test_pim6_multiple_groups_same_RP_address_p2(request): assert result is True, ASSERT_MSG.format(tc_name, result) step("r5: Send multicast traffic for group {}".format(group_address_list)) - intf = TOPO["routers"]["r5"]["links"]["r3"]["interface"] SOURCE_ADDRESS = TOPO["routers"]["r5"]["links"]["r3"]["ipv6"].split("/")[0] - result = socat_send_pim6_traffic(tgen, "r5", "UDP6-SEND", group_address_list, intf) + result = app_helper.run_traffic("r5", group_address_list, "r3") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("r1: Verify (*, G) upstream IIF interface") @@ -593,6 +569,8 @@ def test_pim6_multiple_groups_different_RP_address_p2(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) + app_helper.stop_all_hosts() + step("Enable MLD on r1 interface") step("Enable the PIM6 on all the interfaces of r1, r2, r3 and r4 routers") step("r2: Configure r2 as RP") @@ -646,11 +624,7 @@ def test_pim6_multiple_groups_different_RP_address_p2(request): group_address_list = GROUP_ADDRESS_LIST_1 + GROUP_ADDRESS_LIST_2 step("r0: Send MLD join for 10 groups") - intf = TOPO["routers"]["r0"]["links"]["r1"]["interface"] - intf_ip = TOPO["routers"]["r0"]["links"]["r1"]["ipv6"].split("/")[0] - result = socat_send_mld_join( - tgen, "r0", "UDP6-RECV", group_address_list, intf, intf_ip - ) + result = app_helper.run_join("r0", group_address_list, "r1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("r1: Verify MLD groups") @@ -660,9 +634,8 @@ def test_pim6_multiple_groups_different_RP_address_p2(request): assert result is True, ASSERT_MSG.format(tc_name, result) step("r5: Send multicast traffic for group {}".format(group_address_list)) - intf = TOPO["routers"]["r5"]["links"]["r3"]["interface"] SOURCE_ADDRESS = TOPO["routers"]["r5"]["links"]["r3"]["ipv6"].split("/")[0] - result = socat_send_pim6_traffic(tgen, "r5", "UDP6-SEND", group_address_list, intf) + result = app_helper.run_traffic("r5", group_address_list, "r3") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("r1: Verify (*, G) upstream IIF interface") @@ -1189,6 +1162,8 @@ def test_pim6_delete_RP_shut_noshut_upstream_interface_p1(request): step("Creating configuration from JSON") reset_config_on_routers(tgen) + app_helper.stop_all_hosts() + step("Enable MLD on r1 interface") step("Enable the PIM6 on all the interfaces of r1, r2, r3 and r4 routers") step("r2: Configure r2 as RP") @@ -1220,11 +1195,7 @@ def test_pim6_delete_RP_shut_noshut_upstream_interface_p1(request): assert result is True, ASSERT_MSG.format(tc_name, result) step("r0: Send MLD join") - intf = TOPO["routers"]["r0"]["links"]["r1"]["interface"] - intf_ip = TOPO["routers"]["r0"]["links"]["r1"]["ipv6"].split("/")[0] - result = socat_send_mld_join( - tgen, "r0", "UDP6-RECV", GROUP_ADDRESS_1, intf, intf_ip - ) + result = app_helper.run_join("r0", GROUP_ADDRESS_1, "r1") assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) step("r1: Verify MLD groups") diff --git a/tests/topotests/multicast_pim_uplink_topo1/test_multicast_pim_uplink_topo1.py b/tests/topotests/multicast_pim_uplink_topo1/test_multicast_pim_uplink_topo1.py index b50573e775..5728a4d08e 100644 --- a/tests/topotests/multicast_pim_uplink_topo1/test_multicast_pim_uplink_topo1.py +++ b/tests/topotests/multicast_pim_uplink_topo1/test_multicast_pim_uplink_topo1.py @@ -52,7 +52,10 @@ create_static_routes, required_linux_kernel_version, ) -from lib.bgp import create_router_bgp +from lib.bgp import ( + create_router_bgp, + verify_bgp_convergence, +) from lib.pim import ( create_pim_config, create_igmp_config, @@ -152,6 +155,12 @@ def setup_module(mod): global app_helper app_helper = McastTesterHelper(tgen) + # Verify BGP convergence + BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) + assert BGP_CONVERGENCE is True, "setup_module : Failed \n Error:" " {}".format( + BGP_CONVERGENCE + ) + logger.info("Running setup_module() done") @@ -191,7 +200,6 @@ def get_interfaces_names(topo): """ for link in range(1, 5): - intf = topo["routers"]["r1"]["links"]["r2-link{}".format(link)]["interface"] r1_r2_links.append(intf) @@ -401,6 +409,10 @@ def test_mroutes_updated_with_correct_oil_iif_when_receiver_is_in_and_outside_DU reset_config_on_routers(tgen) clear_pim_interface_traffic(tgen, topo) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) @@ -795,6 +807,10 @@ def test_mroutes_updated_with_correct_oil_iif_when_source_is_in_and_outside_DUT_ reset_config_on_routers(tgen) clear_pim_interface_traffic(tgen, topo) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) @@ -1164,6 +1180,10 @@ def test_verify_mroutes_forwarding_p0(request): reset_config_on_routers(tgen) clear_pim_interface_traffic(tgen, topo) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) @@ -1478,6 +1498,10 @@ def test_mroutes_updated_correctly_after_source_interface_shut_noshut_p1(request reset_config_on_routers(tgen) clear_pim_interface_traffic(tgen, topo) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) @@ -1838,6 +1862,10 @@ def test_mroutes_updated_correctly_after_receiver_interface_shut_noshut_p1(reque reset_config_on_routers(tgen) clear_pim_interface_traffic(tgen, topo) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) @@ -2153,6 +2181,10 @@ def test_mroutes_updated_after_sending_IGMP_prune_and_join_p1(request): reset_config_on_routers(tgen) clear_pim_interface_traffic(tgen, topo) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) @@ -2412,6 +2444,10 @@ def test_mroutes_updated_after_after_clear_mroute_p1(request): reset_config_on_routers(tgen) clear_pim_interface_traffic(tgen, topo) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) @@ -2601,6 +2637,10 @@ def test_mroutes_updated_after_changing_rp_config_p1(request): reset_config_on_routers(tgen) clear_pim_interface_traffic(tgen, topo) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) @@ -3067,6 +3107,10 @@ def test_mroutes_after_restart_frr_services_p2(request): reset_config_on_routers(tgen) clear_pim_interface_traffic(tgen, topo) + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) diff --git a/tests/topotests/multicast_pim_uplink_topo2/multicast_pim_uplink_topo2.json b/tests/topotests/multicast_pim_uplink_topo2/multicast_pim_uplink_topo2.json new file mode 100644 index 0000000000..158e1135af --- /dev/null +++ b/tests/topotests/multicast_pim_uplink_topo2/multicast_pim_uplink_topo2.json @@ -0,0 +1,288 @@ +{ + "ipv4base": "10.0.0.0", + "ipv4mask": 24, + "link_ip_start": {"ipv4": "10.0.0.0", "v4mask": 24, "link_local": "disable"}, + "lo_prefix": {"ipv4": "1.0.", "v4mask": 32}, + "routers": { + "r1": { + "links": { + "lo": {"ipv4": "auto", "type": "loopback", "pim": "enable"}, + "r2-link1": {"ipv4": "auto", "pim": "enable"}, + "r2-link2": {"ipv4": "auto", "pim": "enable"}, + "r2-link3": {"ipv4": "auto", "pim": "enable"}, + "r2-link4": {"ipv4": "auto", "pim": "enable"}, + "r3-link1": {"ipv4": "auto", "pim": "enable"}, + "r3-link2": {"ipv4": "auto", "pim": "enable"}, + "r3-link3": {"ipv4": "auto", "pim": "enable"}, + "r3-link4": {"ipv4": "auto", "pim": "enable"}, + "r4": {"ipv4": "auto", "pim": "enable"}, + "r5": {"ipv4": "auto", "pim": "enable"}, + "i1": {"ipv4": "auto", "pim": "enable"}, + "i2": {"ipv4": "auto", "pim": "enable"} + }, + "bgp": { + "local_as": "100", + "address_family": { + "ipv4": { + "unicast": { + "redistribute": [ + {"redist_type": "static"}, + {"redist_type": "connected"} + ], + "neighbor": { + "r2": { + "dest_link": { + "r1-link1": {}, + "r1-link2": {}, + "r1-link3": {}, + "r1-link4": {} + } + }, + "r3": { + "dest_link": { + "r1-link1": {}, + "r1-link2": {}, + "r1-link3": {}, + "r1-link4": {} + } + }, + "r4": { + "dest_link": { + "r1": {} + } + }, + "r5": { + "dest_link": { + "r1": {} + } + } + } + } + } + } + } + }, + "r2": { + "links": { + "lo": {"ipv4": "auto", "type": "loopback", "pim": "enable"}, + "r1-link1": {"ipv4": "auto", "pim": "enable"}, + "r1-link2": {"ipv4": "auto", "pim": "enable"}, + "r1-link3": {"ipv4": "auto", "pim": "enable"}, + "r1-link4": {"ipv4": "auto", "pim": "enable"}, + "r4-link1": {"ipv4": "auto", "pim": "enable"}, + "r4-link2": {"ipv4": "auto", "pim": "enable"}, + "r4-link3": {"ipv4": "auto", "pim": "enable"}, + "r4-link4": {"ipv4": "auto", "pim": "enable"}, + "i3": {"ipv4": "auto", "pim": "enable"}, + "i4": {"ipv4": "auto", "pim": "enable"} + }, + "bgp": { + "local_as": "200", + "address_family": { + "ipv4": { + "unicast": { + "redistribute": [ + {"redist_type": "static"}, + {"redist_type": "connected"} + ], + "neighbor": { + "r1": { + "dest_link": { + "r2-link1": {}, + "r2-link2": {}, + "r2-link3": {}, + "r2-link4": {} + } + }, + "r4": { + "dest_link": { + "r2-link1": {}, + "r2-link2": {}, + "r2-link3": {}, + "r2-link4": {} + } + } + } + } + } + } + } + }, + "r3": { + "links": { + "lo": {"ipv4": "auto", "type": "loopback", "pim": "enable"}, + "r1-link1": {"ipv4": "auto", "pim": "enable"}, + "r1-link2": {"ipv4": "auto", "pim": "enable"}, + "r1-link3": {"ipv4": "auto", "pim": "enable"}, + "r1-link4": {"ipv4": "auto", "pim": "enable"}, + "r4-link1": {"ipv4": "auto", "pim": "enable"}, + "r4-link2": {"ipv4": "auto", "pim": "enable"}, + "r4-link3": {"ipv4": "auto", "pim": "enable"}, + "r4-link4": {"ipv4": "auto", "pim": "enable"}, + "i5": {"ipv4": "auto", "pim": "enable"} + }, + "bgp": { + "local_as": "300", + "address_family": { + "ipv4": { + "unicast": { + "redistribute": [ + {"redist_type": "static"}, + {"redist_type": "connected"} + ], + "neighbor": { + "r1": { + "dest_link": { + "r3-link1": {}, + "r3-link2": {}, + "r3-link3": {}, + "r3-link4": {} + } + }, + "r4": { + "dest_link": { + "r3-link1": {}, + "r3-link2": {}, + "r3-link3": {}, + "r3-link4": {} + } + } + } + } + } + } + } + }, + "r4": { + "links": { + "lo": {"ipv4": "auto", "type": "loopback", "pim": "enable"}, + "r2-link1": {"ipv4": "auto", "pim": "enable"}, + "r2-link2": {"ipv4": "auto", "pim": "enable"}, + "r2-link3": {"ipv4": "auto", "pim": "enable"}, + "r2-link4": {"ipv4": "auto", "pim": "enable"}, + "r3-link1": {"ipv4": "auto", "pim": "enable"}, + "r3-link2": {"ipv4": "auto", "pim": "enable"}, + "r3-link3": {"ipv4": "auto", "pim": "enable"}, + "r3-link4": {"ipv4": "auto", "pim": "enable"}, + "r1": {"ipv4": "auto", "pim": "enable"}, + "r5": {"ipv4": "auto", "pim": "enable"}, + "i6": {"ipv4": "auto", "pim": "enable"}, + "i7": {"ipv4": "auto", "pim": "enable"} + }, + "bgp": { + "local_as": "400", + "address_family": { + "ipv4": { + "unicast": { + "redistribute": [ + {"redist_type": "static"}, + {"redist_type": "connected"} + ], + "neighbor": { + "r2": { + "dest_link": { + "r4-link1": {}, + "r4-link2": {}, + "r4-link3": {}, + "r4-link4": {} + } + }, + "r3": { + "dest_link": { + "r4-link1": {}, + "r4-link2": {}, + "r4-link3": {}, + "r4-link4": {} + } + }, + "r1": { + "dest_link": { + "r4": {} + } + }, + "r5": { + "dest_link": { + "r4": {} + } + } + } + } + } + } + } + }, + "r5": { + "links": { + "lo": {"ipv4": "auto", "type": "loopback", "pim": "enable"}, + "r1": {"ipv4": "auto", "pim": "enable"}, + "r4": {"ipv4": "auto", "pim": "enable"}, + "i8": {"ipv4": "auto", "pim": "enable"} + }, + "bgp": { + "local_as": "500", + "address_family": { + "ipv4": { + "unicast": { + "redistribute": [ + {"redist_type": "static"}, + {"redist_type": "connected"} + ], + "neighbor": { + "r1": { + "dest_link": { + "r5": {} + } + }, + "r4": { + "dest_link": { + "r5": {} + } + } + } + } + } + } + } + }, + "i1": { + "links": { + "r1": {"ipv4": "auto"} + } + }, + "i2": { + "links": { + "r1": {"ipv4": "auto"} + } + }, + "i3": { + "links": { + "r2": {"ipv4": "auto"} + } + }, + "i4": { + "links": { + "r2": {"ipv4": "auto"} + } + }, + "i5": { + "links": { + "r3": {"ipv4": "auto"} + } + }, + "i6": { + "links": { + "r4": {"ipv4": "auto"} + } + }, + "i7": { + "links": { + "r4": {"ipv4": "auto"} + } + }, + "i8": { + "links": { + "r5": {"ipv4": "auto"} + } + } + } +} diff --git a/tests/topotests/multicast_pim_uplink_topo2/test_multicast_pim_uplink_topo2.py b/tests/topotests/multicast_pim_uplink_topo2/test_multicast_pim_uplink_topo2.py new file mode 100644 index 0000000000..1fb81c0d70 --- /dev/null +++ b/tests/topotests/multicast_pim_uplink_topo2/test_multicast_pim_uplink_topo2.py @@ -0,0 +1,1381 @@ +#!/usr/bin/env python3 +# +# SPDX-License-Identifier: ISC +# +# Copyright (c) 2023 by VMware, Inc. ("VMware") +# + +""" +Following tests are covered to test multicast pim sm: + +1. Verify changing RP address on DUT from Static to BSR , IIF and OIF + updated correctly +2. Verify when mroute RPT and SPT path is difference +3. Verify mroutes updated with correct OIL and IIF after shut / no shut of + upstream interface from DUT +4. Verify mroutes updated with correct OIL and IIF after shut / no +shut of downstream interface from FHR + + +""" + +import os +import sys +import time +import pytest +from time import sleep + +# Save the Current Working Directory to find configuration files. +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) +sys.path.append(os.path.join(CWD, "../lib/")) + +# Required to instantiate the topology builder class. + +# pylint: disable=C0413 +# Import topogen and topotest helpers +from lib.topogen import Topogen, get_topogen + +from lib.common_config import ( + start_topology, + write_test_header, + write_test_footer, + step, + reset_config_on_routers, + shutdown_bringup_interface, + required_linux_kernel_version, +) +from lib.pim import ( + create_pim_config, + create_igmp_config, + verify_mroutes, + clear_pim_interface_traffic, + verify_upstream_iif, + clear_mroute, + verify_multicast_traffic, + verify_pim_rp_info, + verify_pim_interface_traffic, + McastTesterHelper, +) +from lib.bgp import ( + verify_bgp_convergence, +) +from lib.topolog import logger +from lib.topojson import build_config_from_json + +# Global variables +GROUP_RANGE_1 = [ + "225.1.1.1/32", + "225.1.1.2/32", + "225.1.1.3/32", + "225.1.1.4/32", + "225.1.1.5/32", +] +IGMP_JOIN_RANGE_1 = ["225.1.1.1", "225.1.1.2", "225.1.1.3", "225.1.1.4", "225.1.1.5"] +GROUP_RANGE_2 = [ + "226.1.1.1/32", + "226.1.1.2/32", + "226.1.1.3/32", + "226.1.1.4/32", + "226.1.1.5/32", +] +IGMP_JOIN_RANGE_2 = ["226.1.1.1", "226.1.1.2", "226.1.1.3", "226.1.1.4", "226.1.1.5"] + +r1_r2_links = [] +r1_r3_links = [] +r2_r1_links = [] +r3_r1_links = [] +r2_r4_links = [] +r4_r2_links = [] +r4_r3_links = [] + +pytestmark = [pytest.mark.pimd] + + +def setup_module(mod): + """ + Sets up the pytest environment + + * `mod`: module name + """ + + # Required linux kernel version for this suite to run. + result = required_linux_kernel_version("4.19") + if result is not True: + pytest.skip("Kernel requirements are not met") + + testsuite_run_time = time.asctime(time.localtime(time.time())) + logger.info("Testsuite start time: {}".format(testsuite_run_time)) + logger.info("=" * 40) + + logger.info("Running setup_module to create topology") + + testdir = os.path.dirname(os.path.realpath(__file__)) + json_file = "{}/multicast_pim_uplink_topo2.json".format(testdir) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo + # ... and here it calls Mininet initialization functions. + + # Starting topology, create tmp files which are loaded to routers + # to start deamons and then start routers + start_topology(tgen) + + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + # Creating configuration from JSON + build_config_from_json(tgen, tgen.json_topo) + + # Pre-requisite data + get_interfaces_names(topo) + + # XXX Replace this using "with McastTesterHelper()... " in each test if possible. + global app_helper + app_helper = McastTesterHelper(tgen) + + # Verify BGP convergence + BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) + assert BGP_CONVERGENCE is True, "setup_module : Failed \n Error:" " {}".format( + BGP_CONVERGENCE + ) + + logger.info("Running setup_module() done") + + +def teardown_module(): + """Teardown the pytest environment""" + + logger.info("Running teardown_module to delete topology") + + tgen = get_topogen() + + app_helper.cleanup() + + # Stop toplogy and Remove tmp files + tgen.stop_topology() + + logger.info( + "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) + ) + logger.info("=" * 40) + + +##################################################### +# +# Local APIs +# +##################################################### + + +def get_interfaces_names(topo): + """ + API to fetch interfaces names and create list, which further would be used + for verification + + Parameters + ---------- + * `topo` : inout JSON data + """ + + for link in range(1, 5): + intf = topo["routers"]["r1"]["links"]["r2-link{}".format(link)]["interface"] + r1_r2_links.append(intf) + + intf = topo["routers"]["r1"]["links"]["r3-link{}".format(link)]["interface"] + r1_r3_links.append(intf) + + intf = topo["routers"]["r2"]["links"]["r1-link{}".format(link)]["interface"] + r2_r1_links.append(intf) + + intf = topo["routers"]["r3"]["links"]["r1-link{}".format(link)]["interface"] + r3_r1_links.append(intf) + + intf = topo["routers"]["r2"]["links"]["r4-link{}".format(link)]["interface"] + r2_r4_links.append(intf) + + intf = topo["routers"]["r4"]["links"]["r2-link{}".format(link)]["interface"] + r4_r2_links.append(intf) + + intf = topo["routers"]["r4"]["links"]["r3-link{}".format(link)]["interface"] + r4_r3_links.append(intf) + + +def verify_state_incremented(state_before, state_after): + """ + API to compare interface traffic state incrementing + + Parameters + ---------- + * `state_before` : State dictionary for any particular instance + * `state_after` : State dictionary for any particular instance + """ + + for router, state_data in state_before.items(): + for state, value in state_data.items(): + if state_before[router][state] > state_after[router][state]: + errormsg = ( + "[DUT: %s]: state %s value has not" + " incremented, Initial value: %s, " + "Current value: %s [FAILED!!]" + % ( + router, + state, + state_before[router][state], + state_after[router][state], + ) + ) + return errormsg + + logger.info( + "[DUT: %s]: State %s value is " + "incremented, Initial value: %s, Current value: %s" + " [PASSED!!]", + router, + state, + state_before[router][state], + state_after[router][state], + ) + + return True + + +##################################################### +# +# Testcases +# +##################################################### + + +def test_iif_oil_when_RP_address_changes_from_static_to_BSR_p1(request): + """ + Verify changing RP address on DUT from Static to BSR , IIF and OIF + updated correctly + """ + + tgen = get_topogen() + tc_name = request.node.name + write_test_header(tc_name) + + # Creating configuration from JSON + app_helper.stop_all_hosts() + clear_mroute(tgen) + reset_config_on_routers(tgen) + clear_pim_interface_traffic(tgen, topo) + + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + step("Shutdown interfaces which are not required") + intf_r1_r4 = topo["routers"]["r1"]["links"]["r4"]["interface"] + intf_r1_r5 = topo["routers"]["r1"]["links"]["r5"]["interface"] + intf_r4_r1 = topo["routers"]["r4"]["links"]["r1"]["interface"] + intf_r5_r1 = topo["routers"]["r5"]["links"]["r1"]["interface"] + shutdown_bringup_interface(tgen, "r1", intf_r1_r4, False) + shutdown_bringup_interface(tgen, "r1", intf_r1_r5, False) + shutdown_bringup_interface(tgen, "r4", intf_r4_r1, False) + shutdown_bringup_interface(tgen, "r5", intf_r5_r1, False) + + step("Enable IGMP on DUT and R4 interface") + intf_r2_i3 = topo["routers"]["r2"]["links"]["i3"]["interface"] + intf_r4_i7 = topo["routers"]["r4"]["links"]["i7"]["interface"] + for dut, intf in zip(["r2", "r4"], [intf_r2_i3, intf_r4_i7]): + input_dict = {dut: {"igmp": {"interfaces": {intf: {"igmp": {"version": "2"}}}}}} + + result = create_igmp_config(tgen, topo, input_dict) + assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + + step("Send IGMP joins from DUT, and R4 for group range 225.1.1.1-5") + input_join = { + "i3": topo["routers"]["i3"]["links"]["r2"]["interface"], + "i7": topo["routers"]["i7"]["links"]["r4"]["interface"], + } + + for recvr, recvr_intf in input_join.items(): + result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_1, join_intf=recvr_intf) + assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + + step("Configure static RP as R4 loopback interface for group range 225.1.1.1-5") + + input_dict = { + "r4": { + "pim": { + "rp": [ + { + "rp_addr": topo["routers"]["r4"]["links"]["lo"]["ipv4"].split( + "/" + )[0], + "group_addr_range": GROUP_RANGE_1, + } + ] + } + } + } + + result = create_pim_config(tgen, topo, input_dict) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step("Done in base config: " "Configure EBGP peering between all the nodes") + + step("Done in base config: " "Enable PIM on all the interfaces of all the nodes") + + step("Send traffic from DUT for group range 225.1.1.1-5") + + input_src = { + "i4": topo["routers"]["i4"]["links"]["r2"]["interface"], + "i6": topo["routers"]["i6"]["links"]["r4"]["interface"], + } + + for src, src_intf in input_src.items(): + result = app_helper.run_traffic(src, IGMP_JOIN_RANGE_1, bind_intf=src_intf) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step("(*,G) IIF and OIL updated on both the nodes") + + step( + "(S,G) IIF updated towards shortest path to source on both the nodes " + ", verify using 'show ip mroute' and 'show ip mroute json'" + ) + + source_i6 = topo["routers"]["i6"]["links"]["r4"]["ipv4"].split("/")[0] + source_i4 = topo["routers"]["i4"]["links"]["r2"]["ipv4"].split("/")[0] + input_dict_star_sg = [ + { + "dut": "r2", + "src_address": "*", + "iif": r2_r4_links, + "oil": topo["routers"]["r2"]["links"]["i3"]["interface"], + }, + { + "dut": "r4", + "src_address": "*", + "iif": "lo", + "oil": r4_r2_links + [topo["routers"]["r4"]["links"]["i7"]["interface"]], + }, + { + "dut": "r2", + "src_address": source_i6, + "iif": r2_r4_links, + "oil": topo["routers"]["r2"]["links"]["i3"]["interface"], + }, + { + "dut": "r2", + "src_address": source_i4, + "iif": topo["routers"]["r2"]["links"]["i4"]["interface"], + "oil": r2_r4_links + [topo["routers"]["r2"]["links"]["i3"]["interface"]], + }, + { + "dut": "r4", + "src_address": source_i6, + "iif": topo["routers"]["r4"]["links"]["i6"]["interface"], + "oil": r4_r2_links + [topo["routers"]["r4"]["links"]["i7"]["interface"]], + }, + { + "dut": "r4", + "src_address": source_i4, + "iif": r4_r2_links + r4_r3_links, + "oil": topo["routers"]["r4"]["links"]["i7"]["interface"], + }, + ] + + for data in input_dict_star_sg: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1, + data["iif"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_upstream_iif( + tgen, data["dut"], data["iif"], data["src_address"], IGMP_JOIN_RANGE_1 + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step( + "OIL is updated and traffic is received for all the groups on both " + "the nodes , verify using 'show ip multicast'; 'show ip multicast json'" + ) + + intf_r4_i6 = topo["routers"]["r4"]["links"]["i6"]["interface"] + intf_r2_i3 = topo["routers"]["r2"]["links"]["i3"]["interface"] + input_traffic = { + "r2": {"traffic_sent": [intf_r2_i3]}, + "r4": {"traffic_received": [intf_r4_i6]}, + } + result = verify_multicast_traffic(tgen, input_traffic) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step( + "Change RP address for range 225.1.1.1-5 to cisco (BSRP) " "loopback interface" + ) + + input_dict = { + "r4": { + "pim": { + "rp": [ + { + "rp_addr": topo["routers"]["r4"]["links"]["lo"]["ipv4"].split( + "/" + )[0], + "group_addr_range": GROUP_RANGE_1, + "delete": True, + } + ] + } + } + } + result = create_pim_config(tgen, topo, input_dict) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + # Need to wait for 10 sec to make sure prune is received before below RP change is executed + sleep(10) + + input_dict = { + "r5": { + "pim": { + "rp": [ + { + "rp_addr": topo["routers"]["r5"]["links"]["lo"]["ipv4"].split( + "/" + )[0], + "group_addr_range": GROUP_RANGE_1, + } + ] + } + }, + } + result = create_pim_config(tgen, topo, input_dict) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step("Send one more traffic stream from R4 to group range 225.1.1.1-5") + + result = app_helper.run_traffic("i6", IGMP_JOIN_RANGE_1, "r4") + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step("RP type is changed to BSRP for 225.1.1.1-5 groups range on DUT") + + rp_addr = topo["routers"]["r5"]["links"]["lo"]["ipv4"].split("/")[0] + + result = verify_pim_rp_info( + tgen, topo, "r5", GROUP_RANGE_1, "lo", rp_addr, "Static" + ) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step( + "No impact seen on multicast data traffic for both groups range " + "verify using 'show ip multicast json' and 'show ip mroute json'" + ) + + for data in input_dict_star_sg: + if data["src_address"] != "*": + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1, + data["iif"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format( + tc_name, result + ) + + result = verify_multicast_traffic(tgen, input_traffic) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step( + "Stop traffic and do clear mroute on all the node (make " + "sure (s,g) got timeout" + ) + + app_helper.stop_all_hosts() + clear_mroute(tgen) + + step("Verify (S,G) got cleared after stop of traffic and 'clear mroute'") + + for data in input_dict_star_sg: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1, + data["iif"], + data["oil"], + expected=False, + ) + assert ( + result is not True + ), "Testcase {} : Failed " "Mroutes are still present \n Error: {}".format( + tc_name, result + ) + + write_test_footer(tc_name) + + +def test_mroute_when_RPT_and_SPT_path_is_different_p1(request): + """ + Verify when mroute RPT and SPT path is difference + """ + + tgen = get_topogen() + tc_name = request.node.name + write_test_header(tc_name) + + # Creating configuration from JSON + app_helper.stop_all_hosts() + clear_mroute(tgen) + reset_config_on_routers(tgen) + clear_pim_interface_traffic(tgen, topo) + + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + step("Shut link from R3 to R1 and no shut R1 to R4 link to make star topology") + for i in range(1, 5): + intf = topo["routers"]["r3"]["links"]["r1-link{}".format(i)]["interface"] + shutdown_bringup_interface(tgen, "r3", intf, False) + + intf = topo["routers"]["r1"]["links"]["r3-link{}".format(i)]["interface"] + shutdown_bringup_interface(tgen, "r1", intf, False) + + intf_r4_r5 = topo["routers"]["r4"]["links"]["r5"]["interface"] + intf_r5_r4 = topo["routers"]["r5"]["links"]["r4"]["interface"] + intf_r1_r4 = topo["routers"]["r1"]["links"]["r4"]["interface"] + intf_r1_r5 = topo["routers"]["r1"]["links"]["r5"]["interface"] + intf_r4_r1 = topo["routers"]["r4"]["links"]["r1"]["interface"] + intf_r5_r1 = topo["routers"]["r5"]["links"]["r1"]["interface"] + shutdown_bringup_interface(tgen, "r4", intf_r4_r5, False) + shutdown_bringup_interface(tgen, "r5", intf_r5_r4, False) + shutdown_bringup_interface(tgen, "r1", intf_r1_r4, True) + shutdown_bringup_interface(tgen, "r1", intf_r1_r5, True) + shutdown_bringup_interface(tgen, "r4", intf_r4_r1, True) + shutdown_bringup_interface(tgen, "r5", intf_r5_r1, True) + + step("Done in base config: Connected one more route R5 before R1 ( R5-R1)") + + step("Enable IGMP on R5 and R4 interface") + intf_r5_i8 = topo["routers"]["r5"]["links"]["i8"]["interface"] + intf_r4_i7 = topo["routers"]["r4"]["links"]["i7"]["interface"] + for dut, intf in zip(["r4", "r5"], [intf_r4_i7, intf_r5_i8]): + input_dict = {dut: {"igmp": {"interfaces": {intf: {"igmp": {"version": "2"}}}}}} + + result = create_igmp_config(tgen, topo, input_dict) + assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + + step("Send IGMP joins from R5, for group range 226.1.1.1-5") + input_join = { + "i8": topo["routers"]["i8"]["links"]["r5"]["interface"], + "i7": topo["routers"]["i7"]["links"]["r4"]["interface"], + } + + for recvr, recvr_intf in input_join.items(): + result = app_helper.run_join(recvr, IGMP_JOIN_RANGE_2, join_intf=recvr_intf) + assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + + step("Configure RP as R2 for group range 226.1.1.1-5") + + input_dict = { + "r2": { + "pim": { + "rp": [ + { + "rp_addr": topo["routers"]["r2"]["links"]["lo"]["ipv4"].split( + "/" + )[0], + "group_addr_range": GROUP_RANGE_2, + } + ] + } + } + } + + result = create_pim_config(tgen, topo, input_dict) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step("Done in base config: " "Configure EBGP peering between all the nodes") + + step("Done in base config: " "Enable PIM on all the interfaces of all the nodes") + + step("Send traffic from R3 for group range 226.1.1.1-5") + + result = app_helper.run_traffic("i5", IGMP_JOIN_RANGE_2, "r3") + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step("(*,G) IIF updated for 225.1.1.1-5 towards R2 and RP " "type is static on DUT") + + step("(S,G) on R5 has updated for all the groups") + + source_i5 = topo["routers"]["i5"]["links"]["r3"]["ipv4"].split("/")[0] + input_dict_star_sg = [ + { + "dut": "r1", + "src_address": "*", + "iif": r1_r2_links + r1_r3_links, + "oil": topo["routers"]["r1"]["links"]["r5"]["interface"], + }, + { + "dut": "r4", + "src_address": "*", + "iif": r4_r2_links + [intf_r4_r1], + "oil": topo["routers"]["r4"]["links"]["i7"]["interface"], + }, + { + "dut": "r1", + "src_address": source_i5, + "iif": topo["routers"]["r1"]["links"]["r4"]["interface"], + "oil": topo["routers"]["r1"]["links"]["r5"]["interface"], + }, + { + "dut": "r4", + "src_address": source_i5, + "iif": r4_r2_links + r4_r3_links, + "oil": topo["routers"]["r4"]["links"]["i7"]["interface"], + }, + ] + + for data in input_dict_star_sg: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_2, + data["iif"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step( + "(S,G) on R1 updated and has IIF toward R4 and OIL toward R5 , " + "RP path OIL is removed" + ) + + source_i5 = topo["routers"]["i5"]["links"]["r3"]["ipv4"].split("/")[0] + input_dict_sg = [ + {"dut": "r1", "src_address": source_i5, "iif": r1_r2_links, "oil": r1_r2_links}, + {"dut": "r4", "src_address": source_i5, "iif": r4_r2_links, "oil": r4_r2_links}, + ] + + for data in input_dict_sg: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_2, + data["iif"], + data["oil"], + expected=False, + ) + assert ( + result is not True + ), "Testcase {} : Failed " "OIF and IIF are same \n Error: {}".format( + tc_name, result + ) + + step("Shut and no Shut of mroute OIL selected links from R1 towards R2 and R4") + + for i in range(1, 5): + intf = topo["routers"]["r1"]["links"]["r2-link{}".format(i)]["interface"] + shutdown_bringup_interface(tgen, "r1", intf, False) + + for i in range(1, 5): + intf = topo["routers"]["r1"]["links"]["r2-link{}".format(i)]["interface"] + shutdown_bringup_interface(tgen, "r1", intf, True) + + step( + "After shut and no shut of link verify mroute got populated as per " + "verification step 8" + ) + + for data in input_dict_star_sg: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_2, + data["iif"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + for data in input_dict_sg: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_2, + data["iif"], + data["oil"], + expected=False, + ) + assert ( + result is not True + ), "Testcase {} : Failed " "OIF and IIF are same \n Error: {}".format( + tc_name, result + ) + + write_test_footer(tc_name) + + +def test_mroutes_updated_with_correct_oil_iif_after_shut_noshut_upstream_interface_p0( + request, +): + """ + Verify mroutes updated with correct OIL and IIF after shut / no shut of + upstream interface from DUT + """ + + tgen = get_topogen() + tc_name = request.node.name + write_test_header(tc_name) + + # Creating configuration from JSON + app_helper.stop_all_hosts() + clear_mroute(tgen) + reset_config_on_routers(tgen) + clear_pim_interface_traffic(tgen, topo) + + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + step("Shutdown interfaces which are not required") + intf_r1_r5 = topo["routers"]["r1"]["links"]["r5"]["interface"] + intf_r5_r1 = topo["routers"]["r5"]["links"]["r1"]["interface"] + intf_r4_r5 = topo["routers"]["r4"]["links"]["r5"]["interface"] + intf_r5_r4 = topo["routers"]["r5"]["links"]["r4"]["interface"] + shutdown_bringup_interface(tgen, "r1", intf_r1_r5, False) + shutdown_bringup_interface(tgen, "r5", intf_r5_r1, False) + shutdown_bringup_interface(tgen, "r4", intf_r4_r5, False) + shutdown_bringup_interface(tgen, "r5", intf_r5_r4, False) + + step("Enable IGMP on DUT receiver interface") + intf_r1_i1 = topo["routers"]["r1"]["links"]["i1"]["interface"] + intf_r1_i2 = topo["routers"]["r1"]["links"]["i2"]["interface"] + for dut, intf in zip(["r1", "r1"], [intf_r1_i1, intf_r1_i2]): + input_dict = {dut: {"igmp": {"interfaces": {intf: {"igmp": {"version": "2"}}}}}} + + result = create_igmp_config(tgen, topo, input_dict) + assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + + step("Verify pim interface traffic before sending join/traffic") + + intf_traffic = topo["routers"]["r4"]["links"]["r3-link1"]["interface"] + state_dict = {"r4": {intf_traffic: ["registerStopRx"]}} + state_before = verify_pim_interface_traffic(tgen, state_dict) + assert isinstance( + state_before, dict + ), "Testcase{} : Failed \n state_before is not dictionary \n " "Error: {}".format( + tc_name, result + ) + + step("Send IGMP joins from DUT for group range 225.1.1.1-5") + result = app_helper.run_join("i1", IGMP_JOIN_RANGE_1, "r1") + assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + + step( + "Configure RP as R2 and R3 interface (225.1.1.1-3 on R2 and " + "225.1.1.4-5 on R3)" + ) + + input_dict = { + "r2": { + "pim": { + "rp": [ + { + "rp_addr": topo["routers"]["r2"]["links"]["lo"]["ipv4"].split( + "/" + )[0], + "group_addr_range": GROUP_RANGE_1[0:3], + } + ] + } + }, + "r3": { + "pim": { + "rp": [ + { + "rp_addr": topo["routers"]["r3"]["links"]["lo"]["ipv4"].split( + "/" + )[0], + "group_addr_range": GROUP_RANGE_1[3:5], + } + ] + } + }, + } + + result = create_pim_config(tgen, topo, input_dict) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step("Done in base config: " "Configure BGP peering between all the nodes") + + step("Done in base config: " "Enable PIM on all the interfaces of all the nodes") + + step("Send traffic from R4 for group range 225.1.1.1-5") + + result = app_helper.run_traffic("i6", IGMP_JOIN_RANGE_1, "r4") + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step( + "(*,G) IIF is updated DUT-R2 any one interface for groups 225.1.1.1-3 " + "and DUT to R3 any one interface for groups 225.1.1.1-3" + ) + + input_dict_starg = [ + { + "dut": "r1", + "src_address": "*", + "iif_r1_r2": r1_r2_links, + "iif_r1_r3": r1_r3_links, + "oil": topo["routers"]["r1"]["links"]["i1"]["interface"], + } + ] + + for data in input_dict_starg: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1[0:3], + data["iif_r1_r2"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_upstream_iif( + tgen, + data["dut"], + data["iif_r1_r2"], + data["src_address"], + IGMP_JOIN_RANGE_1[0:3], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1[3:5], + data["iif_r1_r3"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_upstream_iif( + tgen, + data["dut"], + data["iif_r1_r3"], + data["src_address"], + IGMP_JOIN_RANGE_1[3:5], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step( + "(S,G) IIF updated towards shortest path to source verify using " + "'show ip mroute' and 'show ip mroute json'" + ) + + source_i6 = topo["routers"]["i6"]["links"]["r4"]["ipv4"].split("/")[0] + input_dict_sg = [ + { + "dut": "r1", + "src_address": source_i6, + "iif": topo["routers"]["r1"]["links"]["r4"]["interface"], + "oil": topo["routers"]["r1"]["links"]["i1"]["interface"], + } + ] + + for data in input_dict_sg: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1, + data["iif"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_upstream_iif( + tgen, data["dut"], data["iif"], data["src_address"], IGMP_JOIN_RANGE_1 + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step( + "(*,G) and (S,G) OIL is updated and traffic is received for all " + "the groups verify using 'show ip multicast' and" + "'show ip multicast count json'" + ) + + intf_r1_i1 = topo["routers"]["r1"]["links"]["i1"]["interface"] + intf_r1_r4 = topo["routers"]["r1"]["links"]["r4"]["interface"] + input_traffic = { + "r1": {"traffic_sent": [intf_r1_i1], "traffic_received": [intf_r1_r4]} + } + result = verify_multicast_traffic(tgen, input_traffic) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step( + "Register packets sent/received count is incrementing verify " + "using 'show ip pim interface traffic json'" + ) + + state_after = verify_pim_interface_traffic(tgen, state_dict) + assert isinstance( + state_before, dict + ), "Testcase{} : Failed \n state_before is not dictionary \n " "Error: {}".format( + tc_name, result + ) + + result = verify_state_incremented(state_before, state_after) + assert result is True, "Testcase{} : Failed Error: {}".format(tc_name, result) + + step("Shut interface connected from R4 to DUT") + intf_r1_r4 = topo["routers"]["r1"]["links"]["r4"]["interface"] + shutdown_bringup_interface(tgen, "r1", intf_r1_r4, False) + + step( + "After shut of R4 to DUT interface verify (S,G) has taken " + "different path ( via R2 or R3 any link) , uptime got resetted " + "and OIL is updated accordingly No impact seen on (*,G) routes , " + "verify uptime for (*,G) using 'show ip mroute json' and " + "'show ip pim state'" + ) + + for data in input_dict_starg: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1[0:3], + data["iif_r1_r2"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_upstream_iif( + tgen, + data["dut"], + data["iif_r1_r2"], + data["src_address"], + IGMP_JOIN_RANGE_1[0:3], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1[3:5], + data["iif_r1_r3"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_upstream_iif( + tgen, + data["dut"], + data["iif_r1_r3"], + data["src_address"], + IGMP_JOIN_RANGE_1[3:5], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + input_dict_sg = [ + { + "dut": "r1", + "src_address": source_i6, + "iif": r1_r2_links + r1_r3_links, + "oil": topo["routers"]["r1"]["links"]["i1"]["interface"], + } + ] + + for data in input_dict_sg: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1, + data["iif"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_upstream_iif( + tgen, data["dut"], data["iif"], data["src_address"], IGMP_JOIN_RANGE_1 + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step("Shut the interface connected from DUT to R2 one by one") + + for i in range(1, 5): + intf = topo["routers"]["r1"]["links"]["r2-link{}".format(i)]["interface"] + shutdown_bringup_interface(tgen, "r1", intf, False) + + step( + "After shut of DUT to R2 all the interfaces (S,G) created via R3, " + "(S,G) uptime get reset and OIL is updated accordingly, No impact " + "seen on (*,G) routes verify using 'show ip mroute json'" + ) + + for data in input_dict_starg: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1[0:3], + data["iif_r1_r3"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_upstream_iif( + tgen, + data["dut"], + data["iif_r1_r3"], + data["src_address"], + IGMP_JOIN_RANGE_1[0:3], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1[3:5], + data["iif_r1_r3"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_upstream_iif( + tgen, + data["dut"], + data["iif_r1_r3"], + data["src_address"], + IGMP_JOIN_RANGE_1[3:5], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + source_i6 = topo["routers"]["i6"]["links"]["r4"]["ipv4"].split("/")[0] + input_dict_sg = [ + { + "dut": "r1", + "src_address": source_i6, + "iif": r1_r3_links, + "oil": topo["routers"]["r1"]["links"]["i1"]["interface"], + } + ] + + for data in input_dict_sg: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1, + data["iif"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_upstream_iif( + tgen, data["dut"], data["iif"], data["src_address"], IGMP_JOIN_RANGE_1 + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + write_test_footer(tc_name) + + +def test_mroutes_updated_with_correct_oil_iif_after_shut_noshut_downstream_interface_p0( + request, +): + """ + Verify mroutes updated with correct OIL and IIF after shut / no + shut of downstream interface from FHR + """ + + tgen = get_topogen() + tc_name = request.node.name + write_test_header(tc_name) + + # Creating configuration from JSON + app_helper.stop_all_hosts() + clear_mroute(tgen) + reset_config_on_routers(tgen) + clear_pim_interface_traffic(tgen, topo) + + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + step("Shutdown interfaces which are not required") + intf_r1_r5 = topo["routers"]["r1"]["links"]["r5"]["interface"] + intf_r5_r1 = topo["routers"]["r5"]["links"]["r1"]["interface"] + intf_r4_r5 = topo["routers"]["r4"]["links"]["r5"]["interface"] + intf_r5_r4 = topo["routers"]["r5"]["links"]["r4"]["interface"] + shutdown_bringup_interface(tgen, "r1", intf_r1_r5, False) + shutdown_bringup_interface(tgen, "r5", intf_r5_r1, False) + shutdown_bringup_interface(tgen, "r4", intf_r4_r5, False) + shutdown_bringup_interface(tgen, "r5", intf_r5_r4, False) + + step("Enable IGMP on DUT receiver interface") + intf_r1_i1 = topo["routers"]["r1"]["links"]["i1"]["interface"] + intf_r1_i2 = topo["routers"]["r1"]["links"]["i2"]["interface"] + for dut, intf in zip(["r1", "r1"], [intf_r1_i1, intf_r1_i2]): + input_dict = {dut: {"igmp": {"interfaces": {intf: {"igmp": {"version": "2"}}}}}} + + result = create_igmp_config(tgen, topo, input_dict) + assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + + step("Send IGMP joins from DUT for group range 225.1.1.1-5") + result = app_helper.run_join("i1", IGMP_JOIN_RANGE_1, "r1") + assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + + step( + "Configure RP as R2 and R3 interface (225.1.1.1-3 on R2 and " + "225.1.1.4-5 on R3)" + ) + + input_dict = { + "r2": { + "pim": { + "rp": [ + { + "rp_addr": topo["routers"]["r2"]["links"]["lo"]["ipv4"].split( + "/" + )[0], + "group_addr_range": GROUP_RANGE_1[0:3], + } + ] + } + }, + "r3": { + "pim": { + "rp": [ + { + "rp_addr": topo["routers"]["r3"]["links"]["lo"]["ipv4"].split( + "/" + )[0], + "group_addr_range": GROUP_RANGE_1[3:5], + } + ] + } + }, + } + + result = create_pim_config(tgen, topo, input_dict) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step("Done in base config: " "Configure BGP peering between all the nodes") + + step("Done in base config: " "Enable PIM on all the interfaces of all the nodes") + + step("Send traffic from R4 for group range 225.1.1.1-5") + + result = app_helper.run_traffic("i6", IGMP_JOIN_RANGE_1, "r4") + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step( + "(*,G) IIF is updated DUT-R2 any one interface for groups 225.1.1.1-3 " + "and DUT to R3 any one interface for groups 225.1.1.1-3" + ) + + input_dict_starg = [ + { + "dut": "r1", + "src_address": "*", + "iif_r1_r2": r1_r2_links, + "iif_r1_r3": r1_r3_links, + "oil": topo["routers"]["r1"]["links"]["i1"]["interface"], + } + ] + + for data in input_dict_starg: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1[0:3], + data["iif_r1_r2"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_upstream_iif( + tgen, + data["dut"], + data["iif_r1_r2"], + data["src_address"], + IGMP_JOIN_RANGE_1[0:3], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1[3:5], + data["iif_r1_r3"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_upstream_iif( + tgen, + data["dut"], + data["iif_r1_r3"], + data["src_address"], + IGMP_JOIN_RANGE_1[3:5], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step( + "(S,G) IIF updated towards shortest path to source verify using " + "'show ip mroute' and 'show ip mroute json'" + ) + + source_i6 = topo["routers"]["i6"]["links"]["r4"]["ipv4"].split("/")[0] + input_dict_sg = [ + { + "dut": "r1", + "src_address": source_i6, + "iif": topo["routers"]["r1"]["links"]["r4"]["interface"], + "oil": topo["routers"]["r1"]["links"]["i1"]["interface"], + } + ] + + for data in input_dict_sg: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1, + data["iif"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_upstream_iif( + tgen, data["dut"], data["iif"], data["src_address"], IGMP_JOIN_RANGE_1 + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step( + "(*,G) and (S,G) OIL is updated and traffic is received for all " + "the groups verify using 'show ip multicast' and" + "'show ip multicast count json'" + ) + + intf_r1_i1 = topo["routers"]["r1"]["links"]["i1"]["interface"] + intf_r1_r4 = topo["routers"]["r1"]["links"]["r4"]["interface"] + input_traffic = { + "r1": {"traffic_sent": [intf_r1_i1], "traffic_received": [intf_r1_r4]} + } + result = verify_multicast_traffic(tgen, input_traffic) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step("Shut interface connected from R4 to DUT") + intf_r4_r1 = topo["routers"]["r4"]["links"]["r1"]["interface"] + shutdown_bringup_interface(tgen, "r4", intf_r4_r1, False) + + step( + "After shut of R4 to DUT interface verify (S,G) has taken " + "different path ( via R2 or R3 any link) , uptime got resetted " + "and OIL is updated accordingly No impact seen on (*,G) routes , " + "verify uptime for (*,G) using 'show ip mroute json' and " + "'show ip pim state'" + ) + + for data in input_dict_starg: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1[0:3], + data["iif_r1_r2"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_upstream_iif( + tgen, + data["dut"], + data["iif_r1_r2"], + data["src_address"], + IGMP_JOIN_RANGE_1[0:3], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1[3:5], + data["iif_r1_r3"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_upstream_iif( + tgen, + data["dut"], + data["iif_r1_r3"], + data["src_address"], + IGMP_JOIN_RANGE_1[3:5], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + source_i6 = topo["routers"]["i6"]["links"]["r4"]["ipv4"].split("/")[0] + input_dict_sg = [ + { + "dut": "r1", + "src_address": source_i6, + "iif": r1_r2_links + r1_r3_links, + "oil": topo["routers"]["r1"]["links"]["i1"]["interface"], + } + ] + + for data in input_dict_sg: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1, + data["iif"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + result = verify_upstream_iif( + tgen, data["dut"], data["iif"], data["src_address"], IGMP_JOIN_RANGE_1 + ) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + write_test_footer(tc_name) + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/multicast_pim_uplink_topo3/multicast_pim_uplink_topo3.json b/tests/topotests/multicast_pim_uplink_topo3/multicast_pim_uplink_topo3.json new file mode 100644 index 0000000000..dc9e1ac49b --- /dev/null +++ b/tests/topotests/multicast_pim_uplink_topo3/multicast_pim_uplink_topo3.json @@ -0,0 +1,295 @@ +{ + "ipv4base": "10.0.0.0", + "ipv4mask": 24, + "link_ip_start": {"ipv4": "10.0.0.0", "v4mask": 24, "link_local": "disable"}, + "lo_prefix": {"ipv4": "1.0.", "v4mask": 32}, + "routers": { + "r1": { + "links": { + "lo": {"ipv4": "auto", "type": "loopback", "pim": "enable"}, + "r2-link1": {"ipv4": "auto", "pim": "enable"}, + "r2-link2": {"ipv4": "auto", "pim": "enable"}, + "r2-link3": {"ipv4": "auto", "pim": "enable"}, + "r2-link4": {"ipv4": "auto", "pim": "enable"}, + "r3-link1": {"ipv4": "auto", "pim": "enable"}, + "r3-link2": {"ipv4": "auto", "pim": "enable"}, + "r3-link3": {"ipv4": "auto", "pim": "enable"}, + "r3-link4": {"ipv4": "auto", "pim": "enable"}, + "r4": {"ipv4": "auto", "pim": "enable"}, + "r5": {"ipv4": "auto", "pim": "enable"}, + "i1": {"ipv4": "auto", "pim": "enable"}, + "i2": {"ipv4": "auto", "pim": "enable"}, + "i9": {"ipv4": "auto", "pim": "enable"} + }, + "bgp": { + "local_as": "100", + "address_family": { + "ipv4": { + "unicast": { + "redistribute": [ + {"redist_type": "static"}, + {"redist_type": "connected"} + ], + "neighbor": { + "r2": { + "dest_link": { + "r1-link1": {}, + "r1-link2": {}, + "r1-link3": {}, + "r1-link4": {} + } + }, + "r3": { + "dest_link": { + "r1-link1": {}, + "r1-link2": {}, + "r1-link3": {}, + "r1-link4": {} + } + }, + "r4": { + "dest_link": { + "r1": {} + } + }, + "r5": { + "dest_link": { + "r1": {} + } + } + } + } + } + } + } + }, + "r2": { + "links": { + "lo": {"ipv4": "auto", "type": "loopback", "pim": "enable"}, + "r1-link1": {"ipv4": "auto", "pim": "enable"}, + "r1-link2": {"ipv4": "auto", "pim": "enable"}, + "r1-link3": {"ipv4": "auto", "pim": "enable"}, + "r1-link4": {"ipv4": "auto", "pim": "enable"}, + "r4-link1": {"ipv4": "auto", "pim": "enable"}, + "r4-link2": {"ipv4": "auto", "pim": "enable"}, + "r4-link3": {"ipv4": "auto", "pim": "enable"}, + "r4-link4": {"ipv4": "auto", "pim": "enable"}, + "i3": {"ipv4": "auto", "pim": "enable"}, + "i4": {"ipv4": "auto", "pim": "enable"} + }, + "bgp": { + "local_as": "200", + "address_family": { + "ipv4": { + "unicast": { + "redistribute": [ + {"redist_type": "static"}, + {"redist_type": "connected"} + ], + "neighbor": { + "r1": { + "dest_link": { + "r2-link1": {}, + "r2-link2": {}, + "r2-link3": {}, + "r2-link4": {} + } + }, + "r4": { + "dest_link": { + "r2-link1": {}, + "r2-link2": {}, + "r2-link3": {}, + "r2-link4": {} + } + } + } + } + } + } + } + }, + "r3": { + "links": { + "lo": {"ipv4": "auto", "type": "loopback", "pim": "enable"}, + "r1-link1": {"ipv4": "auto", "pim": "enable"}, + "r1-link2": {"ipv4": "auto", "pim": "enable"}, + "r1-link3": {"ipv4": "auto", "pim": "enable"}, + "r1-link4": {"ipv4": "auto", "pim": "enable"}, + "r4-link1": {"ipv4": "auto", "pim": "enable"}, + "r4-link2": {"ipv4": "auto", "pim": "enable"}, + "r4-link3": {"ipv4": "auto", "pim": "enable"}, + "r4-link4": {"ipv4": "auto", "pim": "enable"}, + "i5": {"ipv4": "auto", "pim": "enable"} + }, + "bgp": { + "local_as": "300", + "address_family": { + "ipv4": { + "unicast": { + "redistribute": [ + {"redist_type": "static"}, + {"redist_type": "connected"} + ], + "neighbor": { + "r1": { + "dest_link": { + "r3-link1": {}, + "r3-link2": {}, + "r3-link3": {}, + "r3-link4": {} + } + }, + "r4": { + "dest_link": { + "r3-link1": {}, + "r3-link2": {}, + "r3-link3": {}, + "r3-link4": {} + } + } + } + } + } + } + } + }, + "r4": { + "links": { + "lo": {"ipv4": "auto", "type": "loopback", "pim": "enable"}, + "r2-link1": {"ipv4": "auto", "pim": "enable"}, + "r2-link2": {"ipv4": "auto", "pim": "enable"}, + "r2-link3": {"ipv4": "auto", "pim": "enable"}, + "r2-link4": {"ipv4": "auto", "pim": "enable"}, + "r3-link1": {"ipv4": "auto", "pim": "enable"}, + "r3-link2": {"ipv4": "auto", "pim": "enable"}, + "r3-link3": {"ipv4": "auto", "pim": "enable"}, + "r3-link4": {"ipv4": "auto", "pim": "enable"}, + "r1": {"ipv4": "auto", "pim": "enable"}, + "r5": {"ipv4": "auto", "pim": "enable"}, + "i6": {"ipv4": "auto", "pim": "enable"}, + "i7": {"ipv4": "auto", "pim": "enable"} + }, + "bgp": { + "local_as": "400", + "address_family": { + "ipv4": { + "unicast": { + "redistribute": [ + {"redist_type": "static"}, + {"redist_type": "connected"} + ], + "neighbor": { + "r2": { + "dest_link": { + "r4-link1": {}, + "r4-link2": {}, + "r4-link3": {}, + "r4-link4": {} + } + }, + "r3": { + "dest_link": { + "r4-link1": {}, + "r4-link2": {}, + "r4-link3": {}, + "r4-link4": {} + } + }, + "r1": { + "dest_link": { + "r4": {} + } + }, + "r5": { + "dest_link": { + "r4": {} + } + } + } + } + } + } + } + }, + "r5": { + "links": { + "lo": {"ipv4": "auto", "type": "loopback", "pim": "enable"}, + "r1": {"ipv4": "auto", "pim": "enable"}, + "r4": {"ipv4": "auto", "pim": "enable"}, + "i8": {"ipv4": "auto", "pim": "enable"} + }, + "bgp": { + "local_as": "500", + "address_family": { + "ipv4": { + "unicast": { + "redistribute": [ + {"redist_type": "static"}, + {"redist_type": "connected"} + ], + "neighbor": { + "r1": { + "dest_link": { + "r5": {} + } + }, + "r4": { + "dest_link": { + "r5": {} + } + } + } + } + } + } + } + }, + "i1": { + "links": { + "r1": {"ipv4": "auto"} + } + }, + "i2": { + "links": { + "r1": {"ipv4": "auto"} + } + }, + "i3": { + "links": { + "r2": {"ipv4": "auto"} + } + }, + "i4": { + "links": { + "r2": {"ipv4": "auto"} + } + }, + "i5": { + "links": { + "r3": {"ipv4": "auto"} + } + }, + "i6": { + "links": { + "r4": {"ipv4": "auto"} + } + }, + "i7": { + "links": { + "r4": {"ipv4": "auto"} + } + }, + "i8": { + "links": { + "r5": {"ipv4": "auto"} + } + }, + "i9": { + "links": { + "r1": {"ipv4": "auto"} + } + } + + } +} diff --git a/tests/topotests/multicast_pim_uplink_topo3/test_multicast_pim_uplink_topo3.py b/tests/topotests/multicast_pim_uplink_topo3/test_multicast_pim_uplink_topo3.py new file mode 100644 index 0000000000..bed2f2f322 --- /dev/null +++ b/tests/topotests/multicast_pim_uplink_topo3/test_multicast_pim_uplink_topo3.py @@ -0,0 +1,940 @@ +#!/usr/bin/env python3 +# +# SPDX-License-Identifier: ISC +# +# Copyright (c) 2023 by VMware, Inc. ("VMware") +# + +""" +Following tests are covered to test multicast pim sm: + +1. TC:1 Verify static IGMP group populated when static "ip igmp join <grp>" in configured +2. TC:2 Verify mroute and upstream populated with correct OIL/IIF with static igmp join +3. TC:3 Verify local IGMP join not allowed for "224.0.0.0/24" and non multicast group +4. TC:4 Verify static IGMP group removed from DUT while removing "ip igmp join" CLI +5. TC:5 Verify static IGMP groups after removing and adding IGMP config +""" + +import os +import sys +import time +import pytest + +# Save the Current Working Directory to find configuration files. +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) +sys.path.append(os.path.join(CWD, "../lib/")) + +# Required to instantiate the topology builder class. + +# pylint: disable=C0413 +# Import topogen and topotest helpers +from lib.topogen import Topogen, get_topogen + +from lib.common_config import ( + start_topology, + write_test_header, + write_test_footer, + step, + addKernelRoute, + reset_config_on_routers, + shutdown_bringup_interface, + required_linux_kernel_version, +) +from lib.pim import ( + create_pim_config, + create_igmp_config, + verify_igmp_groups, + verify_mroutes, + clear_pim_interface_traffic, + verify_upstream_iif, + clear_mroute, + verify_pim_rp_info, + verify_local_igmp_groups, + McastTesterHelper, +) +from lib.bgp import ( + verify_bgp_convergence, +) +from lib.topolog import logger +from lib.topojson import build_config_from_json + +# Global variables +TOPOLOGY = """ + + i9 i3-+-i4 i6-+-i7 + | | | + i1--- R1-------R2----------R4------R5---i8 + | | | + i2 R3-------------------+ + + + | + i5 + + Description: + i1, i2, i3. i4, i5, i6, i7, i8 - FRR running iperf to send IGMP + join and traffic + R1 - DUT (LHR/FHR) + R2 - RP + R3 - Transit + R4 - (LHR/FHR) + R5 - Transit +""" +# Global variables +RP_RANGE1 = "226.0.0.1/32" +RP_RANGE2 = "226.0.0.2/32" +RP_RANGE3 = "226.0.0.3/32" +RP_RANGE4 = "226.0.0.4/32" +RP_RANGE5 = "226.0.0.5/32" +RP_RANGE6 = "232.0.0.1/32" +RP_RANGE7 = "232.0.0.2/32" +RP_RANGE8 = "232.0.0.3/32" +RP_RANGE9 = "232.0.0.4/32" +RP_RANGE10 = "232.0.0.5/32" + +GROUP_RANGE = "224.0.0.0/4" +IGMP_GROUP = "225.1.1.1/32" +IGMP_JOIN = "225.1.1.1" +GROUP_RANGE_1 = [ + "225.1.1.1/32", + "225.1.1.2/32", + "225.1.1.3/32", + "225.1.1.4/32", + "225.1.1.5/32", +] +IGMP_JOIN_RANGE_1 = ["225.1.1.1", "225.1.1.2", "225.1.1.3", "225.1.1.4", "225.1.1.5"] +IGMP_JOIN_RANGE_2 = ["224.0.0.1", "224.0.0.2", "224.0.0.3", "192.0.0.4", "192.0.0.5"] +IGMP_JOIN_RANGE_3 = [ + "226.0.0.1", + "226.0.0.2", + "226.0.0.3", + "226.0.0.4", + "226.0.0.5", + "232.0.0.1", + "232.0.0.2", + "232.0.0.3", + "232.0.0.4", + "232.0.0.5", +] +GROUP_RANGE_3 = [ + "226.0.0.1/32", + "226.0.0.2/32", + "226.0.0.3/32", + "226.0.0.4/32", + "226.0.0.5/32", + "232.0.0.1/32", + "232.0.0.2/32", + "232.0.0.3/32", + "232.0.0.4/32", + "232.0.0.5/32", +] + +r1_r2_links = [] +r1_r3_links = [] +r2_r1_links = [] +r2_r4_links = [] +r3_r1_links = [] +r3_r4_links = [] +r4_r2_links = [] +r4_r3_links = [] + +pytestmark = [pytest.mark.pimd] + + +def setup_module(mod): + """ + Sets up the pytest environment + + * `mod`: module name + """ + + # Required linux kernel version for this suite to run. + result = required_linux_kernel_version("4.19") + if result is not True: + pytest.skip("Kernel requirements are not met") + + testsuite_run_time = time.asctime(time.localtime(time.time())) + logger.info("Testsuite start time: {}".format(testsuite_run_time)) + logger.info("=" * 40) + + logger.info("Running setup_module to create topology") + + testdir = os.path.dirname(os.path.realpath(__file__)) + json_file = "{}/multicast_pim_uplink_topo3.json".format(testdir) + tgen = Topogen(json_file, mod.__name__) + global topo + topo = tgen.json_topo + # ... and here it calls Mininet initialization functions. + + # Starting topology, create tmp files which are loaded to routers + # to start deamons and then start routers + start_topology(tgen) + + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + # Creating configuration from JSON + build_config_from_json(tgen, tgen.json_topo) + + # Pre-requisite data + get_interfaces_names(topo) + + # XXX Replace this using "with McastTesterHelper()... " in each test if possible. + global app_helper + app_helper = McastTesterHelper(tgen) + + # Verify BGP convergence + BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) + assert BGP_CONVERGENCE is True, "setup_module : Failed \n Error:" " {}".format( + BGP_CONVERGENCE + ) + + logger.info("Running setup_module() done") + + +def teardown_module(): + """Teardown the pytest environment""" + + logger.info("Running teardown_module to delete topology") + + tgen = get_topogen() + + app_helper.cleanup() + + # Stop toplogy and Remove tmp files + tgen.stop_topology() + + logger.info( + "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) + ) + logger.info("=" * 40) + + +##################################################### +# +# Local APIs +# +##################################################### + + +def get_interfaces_names(topo): + """ + API to fetch interfaces names and create list, which further would be used + for verification + + Parameters + ---------- + * `topo` : inout JSON data + """ + + for link in range(1, 5): + intf = topo["routers"]["r1"]["links"]["r2-link{}".format(link)]["interface"] + r1_r2_links.append(intf) + + intf = topo["routers"]["r1"]["links"]["r3-link{}".format(link)]["interface"] + r1_r3_links.append(intf) + + intf = topo["routers"]["r2"]["links"]["r1-link{}".format(link)]["interface"] + r2_r1_links.append(intf) + + intf = topo["routers"]["r3"]["links"]["r1-link{}".format(link)]["interface"] + r3_r1_links.append(intf) + + intf = topo["routers"]["r2"]["links"]["r4-link{}".format(link)]["interface"] + r2_r4_links.append(intf) + + intf = topo["routers"]["r4"]["links"]["r2-link{}".format(link)]["interface"] + r4_r2_links.append(intf) + + intf = topo["routers"]["r4"]["links"]["r3-link{}".format(link)]["interface"] + r4_r3_links.append(intf) + + +def shutdown_interfaces(tgen): + """ + API to Shut down interfaces which is not + used in all the testcases as part of this TDS + + Parameters + ---------- + * `tgen`: topogen object + + """ + logger.info("shutting down extra interfaces") + intf_r1_r4 = topo["routers"]["r1"]["links"]["r4"]["interface"] + intf_r1_r5 = topo["routers"]["r1"]["links"]["r5"]["interface"] + intf_r4_r1 = topo["routers"]["r4"]["links"]["r1"]["interface"] + intf_r5_r1 = topo["routers"]["r5"]["links"]["r1"]["interface"] + intf_r4_r5 = topo["routers"]["r4"]["links"]["r5"]["interface"] + intf_r5_r4 = topo["routers"]["r5"]["links"]["r4"]["interface"] + shutdown_bringup_interface(tgen, "r1", intf_r1_r4, False) + shutdown_bringup_interface(tgen, "r1", intf_r1_r5, False) + shutdown_bringup_interface(tgen, "r4", intf_r4_r1, False) + shutdown_bringup_interface(tgen, "r5", intf_r5_r1, False) + shutdown_bringup_interface(tgen, "r4", intf_r4_r5, False) + shutdown_bringup_interface(tgen, "r5", intf_r5_r4, False) + + +def config_to_send_igmp_join_and_traffic( + tgen, topo, tc_name, iperf, iperf_intf, GROUP_RANGE, join=False, traffic=False +): + """ + API to do pre-configuration to send IGMP join and multicast + traffic + + parameters: + ----------- + * `tgen`: topogen object + * `topo`: input json data + * `tc_name`: caller test case name + * `iperf`: router running iperf + * `iperf_intf`: interface name router running iperf + * `GROUP_RANGE`: group range + * `join`: IGMP join, default False + * `traffic`: multicast traffic, default False + """ + + if join: + # Add route to kernal + result = addKernelRoute(tgen, iperf, iperf_intf, GROUP_RANGE) + assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + + if traffic: + # Add route to kernal + result = addKernelRoute(tgen, iperf, iperf_intf, GROUP_RANGE) + assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + + router_list = tgen.routers() + for router in router_list.keys(): + if router == iperf: + continue + + rnode = router_list[router] + rnode.run("echo 2 > /proc/sys/net/ipv4/conf/all/rp_filter") + + return True + + +##################################################### +# +# Testcases +# +##################################################### + + +def test_ip_igmp_local_joins_p0(request): + """ + TC_1 Verify static IGMP group populated when static + "ip igmp join <grp>" in configured + """ + + tgen = get_topogen() + tc_name = request.node.name + write_test_header(tc_name) + + # Creating configuration from JSON + app_helper.stop_all_hosts() + clear_mroute(tgen) + reset_config_on_routers(tgen) + clear_pim_interface_traffic(tgen, topo) + + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + step("shut down not required interfaces") + shutdown_interfaces(tgen) + + step("Enable the PIM on all the interfaces of R1, R2, R3, R4") + step("configure BGP on R1, R2, R3, R4 and enable redistribute static/connected") + step("Enable the IGMP on R11 interfac of R1 and configure local igmp groups") + intf_r1_i1 = topo["routers"]["r1"]["links"]["i1"]["interface"] + intf_r1_i2 = topo["routers"]["r1"]["links"]["i2"]["interface"] + input_dict = { + "r1": { + "igmp": { + "interfaces": { + intf_r1_i1: {"igmp": {"version": "2", "join": IGMP_JOIN_RANGE_1}}, + intf_r1_i2: {"igmp": {"version": "2", "join": IGMP_JOIN_RANGE_1}}, + } + } + } + } + + result = create_igmp_config(tgen, topo, input_dict) + assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + + step("Configure static RP for (225.1.1.1-5) as R2") + + input_dict = { + "r2": { + "pim": { + "rp": [ + { + "rp_addr": topo["routers"]["r2"]["links"]["lo"]["ipv4"].split( + "/" + )[0], + "group_addr_range": GROUP_RANGE, + } + ] + } + } + } + result = create_pim_config(tgen, topo, input_dict) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step("verify static igmp join using show ip igmp join") + dut = "r1" + interfaces = [intf_r1_i1, intf_r1_i2] + for interface in interfaces: + result = verify_local_igmp_groups(tgen, dut, interface, IGMP_JOIN_RANGE_1) + assert result is True, "Testcase {} :Failed \n Error: {}".format( + tc_name, result + ) + + step("verify igmp groups using show ip igmp groups") + interfaces = [intf_r1_i1, intf_r1_i2] + for interface in interfaces: + result = verify_igmp_groups(tgen, dut, interface, IGMP_JOIN_RANGE_1) + assert result is True, "Testcase {} :Failed \n Error: {}".format( + tc_name, result + ) + + write_test_footer(tc_name) + + +def test_mroute_with_igmp_local_joins_p0(request): + """ + TC_2 Verify mroute and upstream populated with correct OIL/IIF with + static igmp join + """ + + tgen = get_topogen() + tc_name = request.node.name + write_test_header(tc_name) + + # Creating configuration from JSON + app_helper.stop_all_hosts() + clear_mroute(tgen) + reset_config_on_routers(tgen) + clear_pim_interface_traffic(tgen, topo) + + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error {}".format(tc_name, result) + + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + step("shut down not required interfaces") + shutdown_interfaces(tgen) + + step("Enable the PIM on all the interfaces of R1, R2, R3, R4") + step("configure BGP on R1, R2, R3, R4 and enable redistribute static/connected") + step("Enable the IGMP on R11 interfac of R1 and configure local igmp groups") + + intf_r1_i1 = topo["routers"]["r1"]["links"]["i1"]["interface"] + intf_r1_i2 = topo["routers"]["r1"]["links"]["i2"]["interface"] + input_dict = { + "r1": { + "igmp": { + "interfaces": { + intf_r1_i1: {"igmp": {"version": "2", "join": IGMP_JOIN_RANGE_1}}, + intf_r1_i2: {"igmp": {"version": "2", "join": IGMP_JOIN_RANGE_1}}, + } + } + } + } + + result = create_igmp_config(tgen, topo, input_dict) + assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + + step("Configure static RP for (225.1.1.1-5) as R2") + + input_dict = { + "r2": { + "pim": { + "rp": [ + { + "rp_addr": topo["routers"]["r2"]["links"]["lo"]["ipv4"].split( + "/" + )[0], + "group_addr_range": GROUP_RANGE, + } + ] + } + } + } + result = create_pim_config(tgen, topo, input_dict) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step("verify static igmp join using show ip igmp join") + dut = "r1" + interfaces = [intf_r1_i1, intf_r1_i2] + for interface in interfaces: + result = verify_local_igmp_groups(tgen, dut, interface, IGMP_JOIN_RANGE_1) + assert result is True, "Testcase {} :Failed \n Error: {}".format( + tc_name, result + ) + + step("verify igmp groups using show ip igmp groups") + interfaces = [intf_r1_i1, intf_r1_i2] + for interface in interfaces: + result = verify_igmp_groups(tgen, dut, interface, IGMP_JOIN_RANGE_1) + assert result is True, "Testcase {} :Failed \n Error: {}".format( + tc_name, result + ) + + step("verify RP-info populated in DUT") + dut = "r1" + rp_address = topo["routers"]["r2"]["links"]["lo"]["ipv4"].split("/")[0] + SOURCE = "Static" + oif = r1_r2_links + result = verify_pim_rp_info(tgen, topo, dut, GROUP_RANGE_1, oif, rp_address, SOURCE) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step("Send traffic from R4 to all the groups ( 225.1.1.1 to 225.1.1.5)") + + result = app_helper.run_traffic("i6", IGMP_JOIN_RANGE_1, "r4") + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + source_i6 = topo["routers"]["i6"]["links"]["r4"]["ipv4"].split("/")[0] + + r1_r2_r3 = r1_r2_links + r1_r3_links + input_dict_starg = [ + { + "dut": "r1", + "src_address": "*", + "iif": r1_r2_r3, + "oil": topo["routers"]["r1"]["links"]["i1"]["interface"], + }, + { + "dut": "r1", + "src_address": "*", + "iif": r1_r2_links, + "oil": topo["routers"]["r1"]["links"]["i2"]["interface"], + }, + ] + + input_dict_sg = [ + { + "dut": "r1", + "src_address": source_i6, + "iif": r1_r2_r3, + "oil": topo["routers"]["r1"]["links"]["i1"]["interface"], + }, + { + "dut": "r1", + "src_address": source_i6, + "iif": r1_r2_r3, + "oil": topo["routers"]["r1"]["links"]["i2"]["interface"], + }, + ] + + step("Verify mroutes and iff upstream for local igmp groups") + for input_dict in [input_dict_starg, input_dict_sg]: + for data in input_dict: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1, + data["iif"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format( + tc_name, result + ) + + result = verify_upstream_iif( + tgen, data["dut"], data["iif"], data["src_address"], IGMP_JOIN_RANGE_1 + ) + assert result is True, "Testcase {} : Failed Error: {}".format( + tc_name, result + ) + + step("Verify mroutes not created with local interface ip ") + + input_dict_local_sg = [ + { + "dut": "r1", + "src_address": intf_r1_i1, + "iif": r1_r2_r3, + "oil": topo["routers"]["r1"]["links"]["i1"]["interface"], + }, + { + "dut": "r1", + "src_address": intf_r1_i2, + "iif": r1_r2_r3, + "oil": topo["routers"]["r1"]["links"]["i2"]["interface"], + }, + ] + + for data in input_dict_local_sg: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1, + data["iif"], + data["oil"], + expected=False, + ) + assert result is not True, ( + "Testcase {} : Failed Error: {}" + "sg created with local interface ip".format(tc_name, result) + ) + + result = verify_upstream_iif( + tgen, + data["dut"], + data["iif"], + data["src_address"], + IGMP_JOIN_RANGE_1, + expected=False, + ) + assert result is not True, ( + "Testcase {} : Failed Error: {}" + "upstream created with local interface ip".format(tc_name, result) + ) + + write_test_footer(tc_name) + + +def test_igmp_local_join_with_reserved_address_p0(request): + """ + TC_3 Verify local IGMP join not allowed for "224.0.0.0/24" + and non multicast group + """ + tgen = get_topogen() + tc_name = request.node.name + write_test_header(tc_name) + + # Creating configuration from JSON + app_helper.stop_all_hosts() + clear_mroute(tgen) + reset_config_on_routers(tgen) + clear_pim_interface_traffic(tgen, topo) + + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error {}".format(tc_name, result) + + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + step("shut down not required interfaces") + shutdown_interfaces(tgen) + + step("Enable the PIM on all the interfaces of R1, R2, R3, R4") + step("configure BGP on R1, R2, R3, R4 and enable redistribute static/connected") + step("Enable the IGMP on R11 interface of R1 and configure local igmp groups") + + intf_r1_i1 = topo["routers"]["r1"]["links"]["i1"]["interface"] + input_dict = { + "r1": { + "igmp": { + "interfaces": { + intf_r1_i1: {"igmp": {"version": "2", "join": IGMP_JOIN_RANGE_2}} + } + } + } + } + + result = create_igmp_config(tgen, topo, input_dict) + assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + + step("verify static igmp join using show ip igmp join") + dut = "r1" + interface = intf_r1_i1 + result = verify_local_igmp_groups( + tgen, dut, interface, IGMP_JOIN_RANGE_1, expected=False + ) + assert ( + result is not True + ), "Testcase {} :Failed \n Error: {}" "IGMP join still present".format( + tc_name, result + ) + + step("verify igmp groups using show ip igmp groups") + interface = intf_r1_i1 + result = verify_igmp_groups(tgen, dut, interface, IGMP_JOIN_RANGE_1, expected=False) + assert ( + result is not True + ), "Testcase {} :Failed \n Error: {}" "IGMP groups still present".format( + tc_name, result + ) + + write_test_footer(tc_name) + + +def test_remove_add_igmp_local_joins_p1(request): + """ + TC_4 Verify static IGMP group removed from DUT while + removing "ip igmp join" CLI + """ + + tgen = get_topogen() + tc_name = request.node.name + write_test_header(tc_name) + + # Creating configuration from JSON + app_helper.stop_all_hosts() + clear_mroute(tgen) + reset_config_on_routers(tgen) + clear_pim_interface_traffic(tgen, topo) + + # Verify BGP convergence + result = verify_bgp_convergence(tgen, topo) + assert result is True, "Testcase {} : Failed \n Error {}".format(tc_name, result) + + # Don"t run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + step("shut down not required interfaces") + shutdown_interfaces(tgen) + + step("Enable the PIM on all the interfaces of R1, R2, R3, R4") + step("configure BGP on R1, R2, R3, R4 and enable redistribute static/connected") + step("Enable the IGMP on R11 interfac of R1 and configure local igmp groups") + + intf_r1_i1 = topo["routers"]["r1"]["links"]["i1"]["interface"] + intf_r1_i2 = topo["routers"]["r1"]["links"]["i2"]["interface"] + input_dict = { + "r1": { + "igmp": { + "interfaces": { + intf_r1_i1: {"igmp": {"version": "2", "join": IGMP_JOIN_RANGE_1}} + } + } + } + } + + result = create_igmp_config(tgen, topo, input_dict) + assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + + step("Configure static RP for (225.1.1.1-5) as R2") + + input_dict = { + "r2": { + "pim": { + "rp": [ + { + "rp_addr": topo["routers"]["r2"]["links"]["lo"]["ipv4"].split( + "/" + )[0], + "group_addr_range": GROUP_RANGE, + } + ] + } + } + } + result = create_pim_config(tgen, topo, input_dict) + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + step("verify static igmp join using show ip igmp join") + dut = "r1" + interface = intf_r1_i1 + result = verify_local_igmp_groups(tgen, dut, interface, IGMP_JOIN_RANGE_1) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step("verify igmp groups using show ip igmp groups") + + interface = intf_r1_i1 + result = verify_igmp_groups(tgen, dut, interface, IGMP_JOIN_RANGE_1) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step("verify RP-info populated in DUT") + dut = "r1" + rp_address = topo["routers"]["r2"]["links"]["lo"]["ipv4"].split("/")[0] + SOURCE = "Static" + oif = r1_r2_links + result = verify_pim_rp_info(tgen, topo, dut, GROUP_RANGE_1, oif, rp_address, SOURCE) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step("Send traffic from R4 to all the groups ( 225.1.1.1 to 225.1.1.5)") + + result = app_helper.run_traffic("i6", IGMP_JOIN_RANGE_1, "r4") + assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) + + source_i6 = topo["routers"]["i6"]["links"]["r4"]["ipv4"].split("/")[0] + + logger.info("waiting 30 sec for SPT switchover") + + r1_r2_r3 = r1_r2_links + r1_r3_links + input_dict_starg = [ + { + "dut": "r1", + "src_address": "*", + "iif": r1_r2_r3, + "oil": topo["routers"]["r1"]["links"]["i1"]["interface"], + } + ] + + input_dict_sg = [ + { + "dut": "r1", + "src_address": source_i6, + "iif": r1_r2_r3, + "oil": topo["routers"]["r1"]["links"]["i1"]["interface"], + } + ] + + step("Verify mroutes and iff upstream for local igmp groups") + for input_dict in [input_dict_starg, input_dict_sg]: + for data in input_dict: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1, + data["iif"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format( + tc_name, result + ) + + result = verify_upstream_iif( + tgen, data["dut"], data["iif"], data["src_address"], IGMP_JOIN_RANGE_1 + ) + assert result is True, "Testcase {} : Failed Error: {}".format( + tc_name, result + ) + + step("Remove IGMP join from DUT") + input_dict = { + "r1": { + "igmp": { + "interfaces": { + intf_r1_i1: { + "igmp": { + "join": IGMP_JOIN_RANGE_1, + "delete_attr": True, + } + } + } + } + } + } + result = create_igmp_config(tgen, topo, input_dict) + assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + + step("verify static igmp join removed using show ip igmp join") + dut = "r1" + interface = intf_r1_i1 + result = verify_local_igmp_groups( + tgen, dut, interface, IGMP_JOIN_RANGE_1, expected=False + ) + assert ( + result is not True + ), "Testcase {} :Failed \n Error: {}" "IGMP join still present".format( + tc_name, result + ) + + step("verify igmp groups removed using show ip igmp groups") + interface = intf_r1_i1 + result = verify_igmp_groups(tgen, dut, interface, IGMP_JOIN_RANGE_1, expected=False) + assert ( + result is not True + ), "Testcase {} :Failed \n Error: {}" "IGMP groups still present".format( + tc_name, result + ) + + step("Verify mroutes and iff upstream for local igmp groups") + for input_dict in [input_dict_starg, input_dict_sg]: + for data in input_dict: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1, + data["iif"], + data["oil"], + expected=False, + ) + assert ( + result is not True + ), "Testcase {} : Failed Error: {}" "mroutes still present".format( + tc_name, result + ) + + result = verify_upstream_iif( + tgen, + data["dut"], + data["iif"], + data["src_address"], + IGMP_JOIN_RANGE_1, + expected=False, + ) + assert ( + result is not True + ), "Testcase {} : Failed Error: {}" "mroutes still present".format( + tc_name, result + ) + + step("Add IGMP join on DUT again") + input_dict = { + "r1": { + "igmp": { + "interfaces": { + intf_r1_i1: { + "igmp": { + "join": IGMP_JOIN_RANGE_1, + } + } + } + } + } + } + result = create_igmp_config(tgen, topo, input_dict) + assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result) + + step("verify static igmp join using show ip igmp join") + dut = "r1" + interface = intf_r1_i1 + result = verify_local_igmp_groups(tgen, dut, interface, IGMP_JOIN_RANGE_1) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step("verify igmp groups using show ip igmp groups") + + interface = intf_r1_i1 + result = verify_igmp_groups(tgen, dut, interface, IGMP_JOIN_RANGE_1) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step("Verify mroutes and iff upstream for local igmp groups") + for input_dict in [input_dict_starg, input_dict_sg]: + for data in input_dict: + result = verify_mroutes( + tgen, + data["dut"], + data["src_address"], + IGMP_JOIN_RANGE_1, + data["iif"], + data["oil"], + ) + assert result is True, "Testcase {} : Failed Error: {}".format( + tc_name, result + ) + + result = verify_upstream_iif( + tgen, data["dut"], data["iif"], data["src_address"], IGMP_JOIN_RANGE_1 + ) + assert result is True, "Testcase {} : Failed Error: {}".format( + tc_name, result + ) + + write_test_footer(tc_name) + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/munet/base.py b/tests/topotests/munet/base.py index 06ca4deae2..43a45da07c 100644 --- a/tests/topotests/munet/base.py +++ b/tests/topotests/munet/base.py @@ -513,9 +513,8 @@ def _common_prologue(self, async_exec, method, cmd, skip_pre_cmd=False, **kwargs self.logger.debug('%s("%s") [no precmd]', method, shlex.join(cmd_list)) else: self.logger.debug( - '%s: %s %s("%s", pre_cmd: "%s" use_pty: %s kwargs: %.120s)', + '%s: %s("%s", pre_cmd: "%s" use_pty: %s kwargs: %.120s)', self, - "XXX" if method == "_spawn" else "", method, cmd_list, pre_cmd_list if not skip_pre_cmd else "", @@ -566,7 +565,7 @@ def _fdspawn(self, fo, **kwargs): def _spawn(self, cmd, skip_pre_cmd=False, use_pty=False, echo=False, **kwargs): logging.debug( - '%s: XXX _spawn: cmd "%s" skip_pre_cmd %s use_pty %s echo %s kwargs %s', + '%s: _spawn: cmd "%s" skip_pre_cmd %s use_pty %s echo %s kwargs %s', self, cmd, skip_pre_cmd, @@ -579,7 +578,7 @@ def _spawn(self, cmd, skip_pre_cmd=False, use_pty=False, echo=False, **kwargs): ) self.logger.debug( - '%s: XXX %s("%s", use_pty %s echo %s defaults: %s)', + '%s: %s("%s", use_pty %s echo %s defaults: %s)', self, "PopenSpawn" if not use_pty else "pexpect.spawn", actual_cmd, @@ -865,14 +864,18 @@ async def async_cleanup_proc(self, p, pid=None): else: o, e = await p.communicate() self.logger.debug( - "%s: cmd_p already exited status: %s", self, proc_error(p, o, e) + "%s: [cleanup_proc] proc already exited status: %s", + self, + proc_error(p, o, e), ) return None if pid is None: pid = p.pid - self.logger.debug("%s: terminate process: %s (pid %s)", self, proc_str(p), pid) + self.logger.debug( + "%s: [cleanup_proc] terminate process: %s (pid %s)", self, proc_str(p), pid + ) try: # This will SIGHUP and wait a while then SIGKILL and return immediately await self.cleanup_pid(p.pid, pid) @@ -885,14 +888,19 @@ async def async_cleanup_proc(self, p, pid=None): else: o, e = await asyncio.wait_for(p.communicate(), timeout=wait_secs) self.logger.debug( - "%s: cmd_p exited after kill, status: %s", self, proc_error(p, o, e) + "%s: [cleanup_proc] exited after kill, status: %s", + self, + proc_error(p, o, e), ) except (asyncio.TimeoutError, subprocess.TimeoutExpired): - self.logger.warning("%s: SIGKILL timeout", self) + self.logger.warning("%s: [cleanup_proc] SIGKILL timeout", self) return p except Exception as error: self.logger.warning( - "%s: kill unexpected exception: %s", self, error, exc_info=True + "%s: [cleanup_proc] kill unexpected exception: %s", + self, + error, + exc_info=True, ) return p return None @@ -1206,7 +1214,7 @@ def run_in_window( # XXX need to test ssh in Xterm sudo_path = get_exec_path_host(["sudo"]) # This first test case seems same as last but using list instead of string? - if self.is_vm and self.use_ssh: # pylint: disable=E1101 + if self.is_vm and self.use_ssh and not ns_only: # pylint: disable=E1101 if isinstance(cmd, str): cmd = shlex.split(cmd) cmd = ["/usr/bin/env", f"MUNET_NODENAME={self.name}"] + cmd @@ -1332,6 +1340,14 @@ def run_in_window( # Re-adjust the layout if "TMUX" in os.environ: + cmd = [ + get_exec_path_host("tmux"), + "select-layout", + "-t", + pane_info if not tmux_target else tmux_target, + "even-horizontal", + ] + commander.cmd_status(cmd) cmd = [ get_exec_path_host("tmux"), "select-layout", @@ -2005,8 +2021,10 @@ def __init__( stdout=stdout, stderr=stderr, text=True, - start_new_session=not unet, shell=False, + # start_new_session=not unet + # preexec_fn=os.setsid if not unet else None, + preexec_fn=os.setsid, ) # The pid number returned is in the global pid namespace. For unshare_inline @@ -2345,14 +2363,14 @@ async def _async_delete(self): and self.pid != our_pid ): self.logger.debug( - "cleanup pid on separate pid %s from proc pid %s", + "cleanup separate pid %s from namespace proc pid %s", self.pid, self.p.pid if self.p else None, ) await self.cleanup_pid(self.pid) if self.p is not None: - self.logger.debug("cleanup proc pid %s", self.p.pid) + self.logger.debug("cleanup namespace proc pid %s", self.p.pid) await self.async_cleanup_proc(self.p) # return to the previous namespace, need to do this in case anothe munet @@ -2937,7 +2955,7 @@ def __init__( ) logging.debug( - 'ShellWraper: XXX prompt "%s" will_echo %s child.echo %s', + 'ShellWraper: prompt "%s" will_echo %s child.echo %s', prompt, will_echo, spawn.echo, diff --git a/tests/topotests/munet/cli.py b/tests/topotests/munet/cli.py index f631073bb1..133644e85e 100644 --- a/tests/topotests/munet/cli.py +++ b/tests/topotests/munet/cli.py @@ -325,13 +325,14 @@ def get_shcmd(unet, host, kinds, execfmt, ucmd): if not execfmt: return "" - # Do substitutions for {} in string + # Do substitutions for {} and {N} in string numfmt = len(re.findall(r"{\d*}", execfmt)) if numfmt > 1: ucmd = execfmt.format(*shlex.split(ucmd)) elif numfmt: ucmd = execfmt.format(ucmd) - elif len(re.findall(r"{[a-zA-Z_][0-9a-zA-Z_\.]*}", execfmt)): + # look for any pair of {}s but do not count escaped {{ or }} + elif len(re.findall(r"{[^}]+}", execfmt.replace("{{", "").replace("}}", ""))): if execfmt.endswith('"'): fstring = "f'''" + execfmt + "'''" else: diff --git a/tests/topotests/munet/mutest/userapi.py b/tests/topotests/munet/mutest/userapi.py index 1df8c0d012..7967dd0c09 100644 --- a/tests/topotests/munet/mutest/userapi.py +++ b/tests/topotests/munet/mutest/userapi.py @@ -144,7 +144,6 @@ def __init__( result_logger: logging.Logger = None, full_summary: bool = False, ): - self.info = TestCaseInfo(tag, name, path) self.__saved_info = [] self.__short_doc_header = not full_summary @@ -248,7 +247,6 @@ def __print_header(self, tag, header, add_newline=False): self.rlog.info("%s. %s", tag, header) def __exec_script(self, path, print_header, add_newline): - # Below was the original method to avoid the global TestCase # variable; however, we need global functions so we can import them # into test scripts. Without imports pylint will complain about undefined @@ -393,12 +391,12 @@ def _command_json( self, target: str, cmd: str, - ) -> dict: + ) -> Union[list, dict]: """Execute a json ``cmd`` and return json result. Args: target: the target to execute the command on. - cmd: string to execut on the target. + cmd: string to execute on the target. """ out = self.targets[target].cmd_nostatus(cmd, warn=False) self.last = out = out.rstrip() @@ -420,6 +418,7 @@ def _match_command( match: str, expect_fail: bool, flags: int, + exact_match: bool, ) -> (bool, Union[str, list]): """Execute a ``cmd`` and check result. @@ -429,6 +428,8 @@ def _match_command( match: regex to ``re.search()`` for in output. expect_fail: if True then succeed when the regexp doesn't match. flags: python regex flags to modify matching behavior + exact_match: if True then ``match`` must be exactly matched somewhere + in the output of ``cmd`` using ``str.find()``. Returns: (success, matches): if the match fails then "matches" will be None, @@ -436,6 +437,17 @@ def _match_command( ``matches`` otherwise group(0) (i.e., the matching text). """ out = self._command(target, cmd) + if exact_match: + if match not in out: + success = expect_fail + ret = None + else: + success = not expect_fail + ret = match + level = logging.DEBUG if success else logging.WARNING + self.olog.log(level, "exactly matched:%s:", ret) + return success, ret + search = re.search(match, out, flags) self.last_m = search if search is None: @@ -455,17 +467,19 @@ def _match_command_json( self, target: str, cmd: str, - match: Union[str, dict], + match: Union[str, list, dict], expect_fail: bool, - ) -> Union[str, dict]: + exact_match: bool, + ) -> (bool, Union[list, dict]): """Execute a json ``cmd`` and check result. Args: target: the target to execute the command on. cmd: string to execut on the target. - match: A json ``str`` or object (``dict``) to compare against the json - output from ``cmd``. + match: A json ``str``, object (``dict``), or array (``list``) to + compare against the json output from ``cmd``. expect_fail: if True then succeed when the json doesn't match. + exact_match: if True then the json must exactly match. """ js = self._command_json(target, cmd) try: @@ -476,7 +490,27 @@ def _match_command_json( "JSON load failed. Check match value is in JSON format: %s", error ) - if json_diff := json_cmp(expect, js): + if exact_match: + deep_diff = json_cmp(expect, js) + # Convert DeepDiff completely into dicts or lists at all levels + json_diff = json.loads(deep_diff.to_json()) + else: + deep_diff = json_cmp(expect, js, ignore_order=True) + # Convert DeepDiff completely into dicts or lists at all levels + json_diff = json.loads(deep_diff.to_json()) + # Remove new fields in json object from diff + if json_diff.get("dictionary_item_added") is not None: + del json_diff["dictionary_item_added"] + # Remove new json objects in json array from diff + if (new_items := json_diff.get("iterable_item_added")) is not None: + new_item_paths = list(new_items.keys()) + for path in new_item_paths: + if type(new_items[path]) is dict: + del new_items[path] + if len(new_items) == 0: + del json_diff["iterable_item_added"] + + if json_diff: success = expect_fail if not success: self.logf("JSON DIFF:%s:" % json_diff) @@ -489,14 +523,24 @@ def _wait( self, target: str, cmd: str, - match: Union[str, dict], + match: Union[str, list, dict], is_json: bool, timeout: float, interval: float, expect_fail: bool, flags: int, - ) -> Union[str, dict]: - """Execute a command repeatedly waiting for result until timeout.""" + exact_match: bool, + ) -> Union[str, list, dict]: + """Execute a command repeatedly waiting for result until timeout. + + ``match`` is a regular expression to search for in the output of ``cmd`` + when ``is_json`` is False. + + When ``is_json`` is True ``match`` must be a json object, a json array, + or a ``str`` which parses into a json object. Likewise, the ``cmd`` output + is parsed into a json object or array and then a comparison is done between + the two json objects or arrays. + """ startt = time.time() endt = startt + timeout @@ -504,10 +548,12 @@ def _wait( ret = None while not success and time.time() < endt: if is_json: - success, ret = self._match_command_json(target, cmd, match, expect_fail) + success, ret = self._match_command_json( + target, cmd, match, expect_fail, exact_match + ) else: success, ret = self._match_command( - target, cmd, match, expect_fail, flags + target, cmd, match, expect_fail, flags, exact_match ) if not success: time.sleep(interval) @@ -626,7 +672,7 @@ def step(self, target: str, cmd: str) -> str: ) return self._command(target, cmd) - def step_json(self, target: str, cmd: str) -> dict: + def step_json(self, target: str, cmd: str) -> Union[list, dict]: """See :py:func:`~munet.mutest.userapi.step_json`. :meta private: @@ -649,13 +695,14 @@ def match_step( desc: str = "", expect_fail: bool = False, flags: int = re.DOTALL, + exact_match: bool = False, ) -> (bool, Union[str, list]): """See :py:func:`~munet.mutest.userapi.match_step`. :meta private: """ self.logf( - "#%s.%s:%s:MATCH_STEP:%s:%s:%s:%s:%s:%s", + "#%s.%s:%s:MATCH_STEP:%s:%s:%s:%s:%s:%s:%s", self.tag, self.steps + 1, self.info.path, @@ -665,8 +712,11 @@ def match_step( desc, expect_fail, flags, + exact_match, + ) + success, ret = self._match_command( + target, cmd, match, expect_fail, flags, exact_match ) - success, ret = self._match_command(target, cmd, match, expect_fail, flags) if desc: self.__post_result(target, success, desc) return success, ret @@ -684,16 +734,17 @@ def match_step_json( self, target: str, cmd: str, - match: Union[str, dict], + match: Union[str, list, dict], desc: str = "", expect_fail: bool = False, - ) -> (bool, Union[str, dict]): + exact_match: bool = False, + ) -> (bool, Union[list, dict]): """See :py:func:`~munet.mutest.userapi.match_step_json`. :meta private: """ self.logf( - "#%s.%s:%s:MATCH_STEP_JSON:%s:%s:%s:%s:%s", + "#%s.%s:%s:MATCH_STEP_JSON:%s:%s:%s:%s:%s:%s", self.tag, self.steps + 1, self.info.path, @@ -702,8 +753,11 @@ def match_step_json( match, desc, expect_fail, + exact_match, + ) + success, ret = self._match_command_json( + target, cmd, match, expect_fail, exact_match ) - success, ret = self._match_command_json(target, cmd, match, expect_fail) if desc: self.__post_result(target, success, desc) return success, ret @@ -718,6 +772,7 @@ def wait_step( interval=0.5, expect_fail: bool = False, flags: int = re.DOTALL, + exact_match: bool = False, ) -> (bool, Union[str, list]): """See :py:func:`~munet.mutest.userapi.wait_step`. @@ -726,7 +781,7 @@ def wait_step( if interval is None: interval = min(timeout / 20, 0.25) self.logf( - "#%s.%s:%s:WAIT_STEP:%s:%s:%s:%s:%s:%s:%s:%s", + "#%s.%s:%s:WAIT_STEP:%s:%s:%s:%s:%s:%s:%s:%s:%s", self.tag, self.steps + 1, self.info.path, @@ -738,9 +793,18 @@ def wait_step( desc, expect_fail, flags, + exact_match, ) success, ret = self._wait( - target, cmd, match, False, timeout, interval, expect_fail, flags + target, + cmd, + match, + False, + timeout, + interval, + expect_fail, + flags, + exact_match, ) if desc: self.__post_result(target, success, desc) @@ -750,12 +814,13 @@ def wait_step_json( self, target: str, cmd: str, - match: Union[str, dict], + match: Union[str, list, dict], desc: str = "", timeout=10, interval=None, expect_fail: bool = False, - ) -> (bool, Union[str, dict]): + exact_match: bool = False, + ) -> (bool, Union[list, dict]): """See :py:func:`~munet.mutest.userapi.wait_step_json`. :meta private: @@ -763,7 +828,7 @@ def wait_step_json( if interval is None: interval = min(timeout / 20, 0.25) self.logf( - "#%s.%s:%s:WAIT_STEP:%s:%s:%s:%s:%s:%s:%s", + "#%s.%s:%s:WAIT_STEP:%s:%s:%s:%s:%s:%s:%s:%s", self.tag, self.steps + 1, self.info.path, @@ -774,9 +839,10 @@ def wait_step_json( interval, desc, expect_fail, + exact_match, ) success, ret = self._wait( - target, cmd, match, True, timeout, interval, expect_fail, 0 + target, cmd, match, True, timeout, interval, expect_fail, 0, exact_match ) if desc: self.__post_result(target, success, desc) @@ -864,15 +930,15 @@ def step(target: str, cmd: str) -> str: return TestCase.g_tc.step(target, cmd) -def step_json(target: str, cmd: str) -> dict: - """Execute a json ``cmd`` on a ``target`` and return the json object. +def step_json(target: str, cmd: str) -> Union[list, dict]: + """Execute a json ``cmd`` on a ``target`` and return the json object or array. Args: target: the target to execute the ``cmd`` on. cmd: string to execute on the target. Returns: - Returns the json object after parsing the ``cmd`` output. + Returns the json object or array after parsing the ``cmd`` output. If json parse fails, a warning is logged and an empty ``dict`` is used. """ @@ -904,6 +970,7 @@ def match_step( desc: str = "", expect_fail: bool = False, flags: int = re.DOTALL, + exact_match: bool = False, ) -> (bool, Union[str, list]): """Execute a ``cmd`` on a ``target`` check result. @@ -922,44 +989,53 @@ def match_step( desc: description of test, if no description then no result is logged. expect_fail: if True then succeed when the regexp doesn't match. flags: python regex flags to modify matching behavior + exact_match: if True then ``match`` must be exactly matched somewhere + in the output of ``cmd`` using ``str.find()``. Returns: Returns a 2-tuple. The first value is a bool indicating ``success``. The second value will be a list from ``re.Match.groups()`` if non-empty, otherwise ``re.Match.group(0)`` if there was a match otherwise None. """ - return TestCase.g_tc.match_step(target, cmd, match, desc, expect_fail, flags) + return TestCase.g_tc.match_step( + target, cmd, match, desc, expect_fail, flags, exact_match + ) def match_step_json( target: str, cmd: str, - match: Union[str, dict], + match: Union[str, list, dict], desc: str = "", expect_fail: bool = False, -) -> (bool, Union[str, dict]): + exact_match: bool = False, +) -> (bool, Union[list, dict]): """Execute a ``cmd`` on a ``target`` check result. - Execute ``cmd`` on ``target`` and check if the json object in ``match`` + Execute ``cmd`` on ``target`` and check if the json object or array in ``match`` matches or doesn't match (according to the ``expect_fail`` value) the json output from ``cmd``. Args: target: the target to execute the ``cmd`` on. cmd: string to execut on the ``target``. - match: A json ``str`` or object (``dict``) to compare against the json - output from ``cmd``. + match: A json ``str``, object (``dict``), or array (``list``) to compare + against the json output from ``cmd``. desc: description of test, if no description then no result is logged. expect_fail: if True then succeed if the a json doesn't match. + exact_match: if True then the json must exactly match. Returns: Returns a 2-tuple. The first value is a bool indicating ``success``. The - second value is a ``str`` diff if there is a difference found in the json - compare, otherwise the value is the json object (``dict``) from the ``cmd``. + second value is a ``dict`` of the diff if there is a difference found in + the json compare, otherwise the value is the json object (``dict``) or + array (``list``) from the ``cmd``. If json parse fails, a warning is logged and an empty ``dict`` is used. """ - return TestCase.g_tc.match_step_json(target, cmd, match, desc, expect_fail) + return TestCase.g_tc.match_step_json( + target, cmd, match, desc, expect_fail, exact_match + ) def wait_step( @@ -971,6 +1047,7 @@ def wait_step( interval: float = 0.5, expect_fail: bool = False, flags: int = re.DOTALL, + exact_match: bool = False, ) -> (bool, Union[str, list]): """Execute a ``cmd`` on a ``target`` repeatedly, looking for a result. @@ -991,6 +1068,8 @@ def wait_step( desc: description of test, if no description then no result is logged. expect_fail: if True then succeed when the regexp *doesn't* match. flags: python regex flags to modify matching behavior + exact_match: if True then ``match`` must be exactly matched somewhere + in the output of ``cmd`` using ``str.find()``. Returns: Returns a 2-tuple. The first value is a bool indicating ``success``. @@ -998,37 +1077,31 @@ def wait_step( otherwise ``re.Match.group(0)`` if there was a match otherwise None. """ return TestCase.g_tc.wait_step( - target, cmd, match, desc, timeout, interval, expect_fail, flags + target, cmd, match, desc, timeout, interval, expect_fail, flags, exact_match ) def wait_step_json( target: str, cmd: str, - match: Union[str, dict], + match: Union[str, list, dict], desc: str = "", timeout=10, interval=None, expect_fail: bool = False, -) -> (bool, Union[str, dict]): + exact_match: bool = False, +) -> (bool, Union[list, dict]): """Execute a cmd repeatedly and wait for matching result. Execute ``cmd`` on ``target``, every ``interval`` seconds until the output of ``cmd`` matches or doesn't match (according to the ``expect_fail`` value) ``match``, for up to ``timeout`` seconds. - ``match`` is a regular expression to search for in the output of ``cmd`` when - ``is_json`` is False. - - When ``is_json`` is True ``match`` must be a json object or a ``str`` which - parses into a json object. Likewise, the ``cmd`` output is parsed into a json - object and then a comparison is done between the two json objects. - Args: target: the target to execute the ``cmd`` on. cmd: string to execut on the ``target``. - match: A json object or str representation of one to compare against json - output from ``cmd``. + match: A json object, json array, or str representation of json to compare + against json output from ``cmd``. desc: description of test, if no description then no result is logged. timeout: The number of seconds to repeat the ``cmd`` looking for a match (or non-match if ``expect_fail`` is True). @@ -1037,17 +1110,18 @@ def wait_step_json( average the cmd will execute 10 times. The minimum calculated interval is .25s, shorter values can be passed explicitly. expect_fail: if True then succeed if the a json doesn't match. + exact_match: if True then the json must exactly match. Returns: Returns a 2-tuple. The first value is a bool indicating ``success``. - The second value is a ``str`` diff if there is a difference found in the - json compare, otherwise the value is a json object (dict) from the ``cmd`` - output. + The second value is a ``dict`` of the diff if there is a difference + found in the json compare, otherwise the value is a json object (``dict``) + or array (``list``) from the ``cmd`` output. If json parse fails, a warning is logged and an empty ``dict`` is used. """ return TestCase.g_tc.wait_step_json( - target, cmd, match, desc, timeout, interval, expect_fail + target, cmd, match, desc, timeout, interval, expect_fail, exact_match ) diff --git a/tests/topotests/munet/native.py b/tests/topotests/munet/native.py index fecf709d1a..4fbbb85603 100644 --- a/tests/topotests/munet/native.py +++ b/tests/topotests/munet/native.py @@ -20,6 +20,8 @@ import subprocess import time +from pathlib import Path + from . import cli from .base import BaseMunet from .base import Bridge @@ -38,6 +40,7 @@ from .config import find_matching_net_config from .config import find_with_kv from .config import merge_kind_config +from .watchlog import WatchLog class L3ContainerNotRunningError(MunetError): @@ -455,13 +458,14 @@ def pytest_hook_open_shell(self): bps = self.unet.cfgopt.getoption("--gdb-breakpoints", "").split(",") for bp in bps: - gdbcmd += f" '-ex=b {bp}'" + if bp: + gdbcmd += f" '-ex=b {bp}'" - cmds = self.config.get("gdb-run-cmd", []) + cmds = self.config.get("gdb-run-cmds", []) for cmd in cmds: gdbcmd += f" '-ex={cmd}'" - self.run_in_window(gdbcmd) + self.run_in_window(gdbcmd, ns_only=True) elif should_gdb and use_emacs: gdbcmd = gdbcmd.replace("gdb ", "gdb -i=mi ") ecbin = self.get_exec_path("emacsclient") @@ -664,6 +668,7 @@ def __init__(self, *args, unet=None, **kwargs): self.phycount = 0 self.phy_odrivers = {} self.tapmacs = {} + self.watched_logs = {} self.intf_tc_count = 0 @@ -723,6 +728,26 @@ def __init__(self, *args, unet=None, **kwargs): if hasattr(self, "bind_mount"): self.bind_mount(hosts_file, "/etc/hosts") + def add_watch_log(self, path, watchfor_re=None): + """Add a WatchLog to this nodes watched logs. + + Args: + path: If relative is relative to the nodes ``rundir`` + watchfor_re: Regular expression to watch the log for and raise an exception + if found. + + Return: + The watching task if request or None otherwise. + """ + path = Path(path) + if not path.is_absolute(): + path = self.rundir.joinpath(path) + + wl = WatchLog(path) + self.watched_logs[wl.path] = wl + task = wl.raise_if_match_task(watchfor_re) if watchfor_re else None + return task + async def console( self, concmd, @@ -938,8 +963,32 @@ async def add_host_intf(self, hname, lname, mtu=None): if hname in self.host_intfs: return self.host_intfs[hname] = lname - self.unet.rootcmd.cmd_nostatus(f"ip link set {hname} down ") - self.unet.rootcmd.cmd_raises(f"ip link set {hname} netns {self.pid}") + + # See if this interace is missing and needs to be fixed + rc, o, _ = self.unet.rootcmd.cmd_status("ip -o link show") + m = re.search(rf"\d+:\s+(\S+):.*altname {re.escape(hname)}\W", o) + if m: + # need to rename + dname = m.group(1) + self.logger.info("Fixing misnamed %s to %s", dname, hname) + self.unet.rootcmd.cmd_status( + f"ip link property del dev {dname} altname {hname}" + ) + self.unet.rootcmd.cmd_status(f"ip link set {dname} name {hname}") + + rc, o, _ = self.unet.rootcmd.cmd_status("ip -o link show") + m = re.search(rf"\d+:\s+{re.escape(hname)}:.*", o) + if m: + self.unet.rootcmd.cmd_nostatus(f"ip link set {hname} down ") + self.unet.rootcmd.cmd_raises(f"ip link set {hname} netns {self.pid}") + # Wait for interface to show up in namespace + for retry in range(0, 10): + rc, o, _ = self.cmd_status(f"ip -o link show {hname}") + if not rc: + if re.search(rf"\d+: {re.escape(hname)}:.*", o): + break + if retry > 0: + await asyncio.sleep(1) self.cmd_raises(f"ip link set {hname} name {lname}") if mtu: self.cmd_raises(f"ip link set {lname} mtu {mtu}") @@ -949,7 +998,12 @@ async def rem_host_intf(self, hname): lname = self.host_intfs[hname] self.cmd_raises(f"ip link set {lname} down") self.cmd_raises(f"ip link set {lname} name {hname}") - self.cmd_raises(f"ip link set {hname} netns 1") + self.cmd_status(f"ip link set netns 1 dev {hname}") + # The above is failing sometimes and not sure why + # logging.error( + # "XXX after setns %s", + # self.unet.rootcmd.cmd_nostatus(f"ip link show {hname}"), + # ) del self.host_intfs[hname] async def add_phy_intf(self, devaddr, lname): @@ -1019,12 +1073,13 @@ async def add_phy_intf(self, devaddr, lname): "Physical PCI device %s already bound to vfio-pci", devaddr ) return + self.logger.info( "Unbinding physical PCI device %s from driver %s", devaddr, driver ) self.phy_odrivers[devaddr] = driver self.unet.rootcmd.cmd_raises( - f"echo {devaddr} > /sys/bus/pci/drivers/{driver}/unbind" + f"echo {devaddr} | timeout 10 tee /sys/bus/pci/drivers/{driver}/unbind" ) # Add the device vendor and device id to vfio-pci in case it's the first time @@ -1035,7 +1090,14 @@ async def add_phy_intf(self, devaddr, lname): f"echo {vendor} {devid} > /sys/bus/pci/drivers/vfio-pci/new_id", warn=False ) - if not self.unet.rootcmd.path_exists(f"/sys/bus/pci/driver/vfio-pci/{devaddr}"): + for retry in range(0, 10): + if self.unet.rootcmd.path_exists( + f"/sys/bus/pci/drivers/vfio-pci/{devaddr}" + ): + break + if retry > 0: + await asyncio.sleep(1) + # Bind to vfio-pci if wasn't added with new_id self.logger.info("Binding physical PCI device %s to vfio-pci", devaddr) ec, _, _ = self.unet.rootcmd.cmd_status( @@ -1066,7 +1128,7 @@ async def rem_phy_intf(self, devaddr): "Unbinding physical PCI device %s from driver vfio-pci", devaddr ) self.unet.rootcmd.cmd_status( - f"echo {devaddr} > /sys/bus/pci/drivers/vfio-pci/unbind" + f"echo {devaddr} | timeout 10 tee /sys/bus/pci/drivers/vfio-pci/unbind" ) self.logger.info("Binding physical PCI device %s to driver %s", devaddr, driver) @@ -1085,13 +1147,13 @@ async def _async_delete(self): for hname in list(self.host_intfs): await self.rem_host_intf(hname) - # remove any hostintf interfaces - for devaddr in list(self.phy_intfs): - await self.rem_phy_intf(devaddr) - # delete the LinuxNamespace/InterfaceMixin await super()._async_delete() + # remove any hostintf interfaces, needs to come after normal exits + for devaddr in list(self.phy_intfs): + await self.rem_phy_intf(devaddr) + class L3NamespaceNode(L3NodeMixin, LinuxNamespace): """A namespace L3 node.""" @@ -1123,6 +1185,7 @@ def __init__(self, name, config, **kwargs): assert self.container_image self.cmd_p = None + self.cmd_pid = None self.__base_cmd = [] self.__base_cmd_pty = [] @@ -1393,7 +1456,13 @@ async def run_cmd(self): start_new_session=True, # keeps main tty signals away from podman ) - self.logger.debug("%s: async_popen => %s", self, self.cmd_p.pid) + # If our process is actually the child of an nsenter fetch its pid. + if self.nsenter_fork: + self.cmd_pid = await self.get_proc_child_pid(self.cmd_p) + + self.logger.debug( + "%s: async_popen => %s (%s)", self, self.cmd_p.pid, self.cmd_pid + ) self.pytest_hook_run_cmd(stdout, stderr) @@ -1542,6 +1611,7 @@ def __init__(self, name, config, **kwargs): """Create a Container Node.""" self.cont_exec_paths = {} self.launch_p = None + self.launch_pid = None self.qemu_config = config["qemu"] self.extra_mounts = [] assert self.qemu_config @@ -1968,8 +2038,9 @@ async def renumber_interfaces(self): con.cmd_raises(f"ip -6 route add default via {switch.ip6_address}") con.cmd_raises("ip link set lo up") - if self.unet.cfgopt.getoption("--coverage"): - con.cmd_raises("mount -t debugfs none /sys/kernel/debug") + # This is already mounted now + # if self.unet.cfgopt.getoption("--coverage"): + # con.cmd_raises("mount -t debugfs none /sys/kernel/debug") async def gather_coverage_data(self): con = self.conrepl @@ -2261,25 +2332,29 @@ async def launch(self): stdout = open(os.path.join(self.rundir, "qemu.out"), "wb") stderr = open(os.path.join(self.rundir, "qemu.err"), "wb") - self.launch_p = await self.async_popen( + self.launch_p = await self.async_popen_nsonly( args, stdin=subprocess.DEVNULL, stdout=stdout, stderr=stderr, pass_fds=pass_fds, - # We don't need this here b/c we are only ever running qemu and that's all - # we need to kill for cleanup - # XXX reconcile this - start_new_session=True, # allows us to signal all children to exit + # Don't want Keybaord interrupt etc to pass to child. + # start_new_session=True, + preexec_fn=os.setsid, ) + if self.nsenter_fork: + self.launch_pid = await self.get_proc_child_pid(self.launch_p) + self.pytest_hook_run_cmd(stdout, stderr) # We've passed these on, so don't need these open here anymore. for fd in pass_fds: os.close(fd) - self.logger.debug("%s: async_popen => %s", self, self.launch_p.pid) + self.logger.debug( + "%s: popen => %s (%s)", self, self.launch_p.pid, self.launch_pid + ) confiles = ["_console"] if use_cmdcon: @@ -2307,10 +2382,10 @@ async def launch(self): # the monitor output has super annoying ANSI escapes in it output = self.monrepl.cmd_nostatus("info status") - self.logger.info("VM status: %s", output) + self.logger.debug("VM status: %s", output) output = self.monrepl.cmd_nostatus("info kvm") - self.logger.info("KVM status: %s", output) + self.logger.debug("KVM status: %s", output) # # Set thread affinity @@ -2348,11 +2423,6 @@ def launch_completed(self, future): "%s: node launch (qemu) cmd wait() canceled: %s", future, error ) - async def cleanup_qemu(self): - """Launch qemu.""" - if self.launch_p: - await self.async_cleanup_proc(self.launch_p) - async def async_cleanup_cmd(self): """Run the configured cleanup commands for this node.""" self.cleanup_called = True @@ -2372,7 +2442,7 @@ async def _async_delete(self): # Need to cleanup early b/c it is running on the VM if self.cmd_p: - await self.async_cleanup_proc(self.cmd_p) + await self.async_cleanup_proc(self.cmd_p, self.cmd_pid) self.cmd_p = None try: @@ -2388,9 +2458,9 @@ async def _async_delete(self): if not self.launch_p: self.logger.warning("async_delete: qemu is not running") else: - await self.cleanup_qemu() + await self.async_cleanup_proc(self.launch_p, self.launch_pid) except Exception as error: - self.logger.warning("%s: failued to cleanup qemu process: %s", self, error) + self.logger.warning("%s: failed to cleanup qemu process: %s", self, error) await super()._async_delete() @@ -2814,6 +2884,8 @@ async def run(self): logging.debug("Launching nodes") await asyncio.gather(*[x.launch() for x in launch_nodes]) + logging.debug("Launched nodes -- Queueing Waits") + # Watch for launched processes to exit for node in launch_nodes: task = asyncio.create_task( @@ -2822,17 +2894,23 @@ async def run(self): task.add_done_callback(node.launch_completed) tasks.append(task) + logging.debug("Wait complete queued, running cmd") + if run_nodes: # would like a info when verbose here. logging.debug("Running `cmd` on nodes") await asyncio.gather(*[x.run_cmd() for x in run_nodes]) + logging.debug("Ran cmds -- Queueing Waits") + # Watch for run_cmd processes to exit for node in run_nodes: task = asyncio.create_task(node.cmd_p.wait(), name=f"Node-{node.name}-cmd") task.add_done_callback(node.cmd_completed) tasks.append(task) + logging.debug("Wait complete queued, waiting for ready") + # Wait for nodes to be ready if ready_nodes: @@ -2853,6 +2931,8 @@ async def wait_until_ready(x): raise asyncio.TimeoutError() logging.debug("All nodes ready") + logging.debug("All done returning tasks: %s", tasks) + return tasks async def _async_delete(self): diff --git a/tests/topotests/munet/testing/fixtures.py b/tests/topotests/munet/testing/fixtures.py index 25039df541..3c6d9460ff 100644 --- a/tests/topotests/munet/testing/fixtures.py +++ b/tests/topotests/munet/testing/fixtures.py @@ -95,7 +95,7 @@ def _push_log_handler(desc, logpath): logging.debug("conftest: adding %s logging at %s", desc, logpath) root_logger = logging.getLogger() handler = logging.FileHandler(logpath, mode="w") - fmt = logging.Formatter("%(asctime)s %(levelname)5s: %(message)s") + fmt = logging.Formatter("%(asctime)s %(levelname)5s: %(name)s: %(message)s") handler.setFormatter(fmt) root_logger.addHandler(handler) return handler diff --git a/tests/topotests/munet/testing/hooks.py b/tests/topotests/munet/testing/hooks.py index 9b6a49a18c..985eef9c49 100644 --- a/tests/topotests/munet/testing/hooks.py +++ b/tests/topotests/munet/testing/hooks.py @@ -196,10 +196,10 @@ def pytest_runtest_makereport(item, call): if error: item.skip_more_pause = True - # we can't asyncio.run() (which pause does) if we are unhsare_inline + # we can't asyncio.run() (which pause does) if we are not unhsare_inline # at this point, count on an autouse fixture to pause instead in this # case - if not BaseMunet.g_unet or not BaseMunet.g_unet.unshare_inline: + if BaseMunet.g_unet and BaseMunet.g_unet.unshare_inline: pause_test(f"before test '{item.nodeid}'") # check for a result to try and catch setup (or module setup) failure diff --git a/tests/topotests/munet/watchlog.py b/tests/topotests/munet/watchlog.py new file mode 100644 index 0000000000..27bc3251a6 --- /dev/null +++ b/tests/topotests/munet/watchlog.py @@ -0,0 +1,170 @@ +# -*- coding: utf-8 eval: (blacken-mode 1) -*- +# SPDX-License-Identifier: GPL-2.0-or-later +# +# August 21 2023, Christian Hopps <chopps@labn.net> +# +# Copyright (c) 2023, LabN Consulting, L.L.C. +# +"""A module supporting an object for watching a logfile.""" +import asyncio +import logging +import re + +from pathlib import Path + + +class MatchFoundError(Exception): + """An error raised when a match is not found.""" + def __init__(self, watchlog, match): + self.watchlog = watchlog + self.match = match + super().__init__(watchlog, match) + + +class WatchLog: + """An object for watching a logfile.""" + + def __init__(self, path, encoding="utf-8"): + """Watch a logfile. + + Args: + path: that path of the logfile to watch + encoding: the encoding of the logfile + """ + # Immutable + self.path = Path(path) + self.encoding = encoding + + # Mutable + self.content = "" + self.last_snap_mark = 0 + self.last_user_mark = 0 + self.stat = None + + if self.path.exists(): + self.snapshot() + + def _stat_snapshot(self): + ostat = self.stat + + if not self.path.exists(): + self.stat = None + return ostat is not None + + stat = self.path.stat() + self.stat = stat + + if ostat is None: + return True + + return ( + stat.st_mtime_ns != ostat.st_mtime_ns + or stat.st_ctime_ns != ostat.st_ctime_ns + or stat.st_ino != ostat.st_ino + or stat.st_size != ostat.st_size + ) + + def reset(self): + self.content = "" + self.last_user_mark = 0 + self.last_snap_mark = 0 + + def update_content(self): + ostat = self.stat + osize = ostat.st_size if ostat else 0 + oino = ostat.st_ino if ostat else -1 + if not self._stat_snapshot(): + logging.debug("XXX logfile %s no stat change", self.path) + return "" + + nino = self.stat.st_ino + # If the inode changed and we had content previously warn + if oino != -1 and oino != nino and self.content: + logging.warning( + "logfile %s replaced (new inode) resetting content", self.path + ) + self.reset() + osize = 0 + + nsize = self.stat.st_size + if osize > nsize: + logging.warning("logfile %s shrunk resetting content", self.path) + self.reset() + osize = 0 + + if osize == nsize: + logging.debug( + "XXX watchlog: %s no update, osize == nsize == %s", self.path, osize + ) + return "" + + # Read non-blocking + with open(self.path, "r", encoding=self.encoding) as f: + if osize: + f.seek(osize) + logging.debug( + "XXX watchlog: %s reading new content from %s to %s", + self.path, + osize, + nsize, + ) + newcontent = f.read(nsize - osize) + + self.content += newcontent + return newcontent + + def raise_if_match_task(self, match): + """Start an async task that searches for a match. + + This doesn't work well with pytest as the task must be awaited for the exception + to propagate. + """ + + async def scan_for_match(wl, regex): + while True: + logging.debug("watchlog: %s scan for updating content", wl.path) + wl.update_content() + if m := regex.search(wl.content): + logging.error( + "XXX watchlog: %s regexp FOUND raising exception!", wl.path + ) + raise MatchFoundError(wl, m) + await asyncio.sleep(2) + + aw = scan_for_match(self, re.compile(match)) + return asyncio.create_task(aw) + + def from_mark(self, mark=None): + """Return the file content starting from ``mark``. + + If ``mark`` is None then return content since last ``set_mark`` was called. + + Args: + mark: the mark in the content to return file content from. + + Return: + returns the content between ``mark`` and the end of content. + """ + return self.content[mark:] + + def set_mark(self): + """Set a mark for later use.""" + last_mark = self.last_user_mark + self.last_user_mark = len(self.content) + return last_mark + + def snapshot(self): + """Update the file content and return new text. + + Returns any new text added since the last snapshot, + also updates the snapshot mark. + + Return: + Newly added text. + """ + # Update the content which may reset marks + self.update_content() + + last_mark = self.last_snap_mark + self.last_snap_mark = len(self.content) + return self.content[last_mark:] diff --git a/tests/topotests/nhrp_topo/r1/sharp_route4.json b/tests/topotests/nhrp_topo/r1/sharp_route4.json new file mode 100644 index 0000000000..4c4b8eaccd --- /dev/null +++ b/tests/topotests/nhrp_topo/r1/sharp_route4.json @@ -0,0 +1,46 @@ +{ + "4.4.4.1\/32":[ + { + "prefix":"4.4.4.1\/32", + "prefixLen":32, + "protocol":"sharp", + "vrfId":0, + "vrfName":"default", + "selected":true, + "destSelected":true, + "installed":true, + "internalNextHopNum":1, + "internalNextHopActiveNum":1, + "nexthops":[ + { + "fib":true, + "ip":"10.255.255.2", + "interfaceName":"r1-gre0", + "active":true + } + ] + } + ], + "5.5.5.1\/32":[ + { + "prefix":"5.5.5.1\/32", + "prefixLen":32, + "protocol":"sharp", + "vrfId":0, + "vrfName":"default", + "selected":true, + "destSelected":true, + "installed":true, + "internalNextHopNum":1, + "internalNextHopActiveNum":1, + "nexthops":[ + { + "fib":true, + "ip":"10.255.255.2", + "interfaceName":"r1-gre0", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/nhrp_topo/test_nhrp_topo.py b/tests/topotests/nhrp_topo/test_nhrp_topo.py index 879f5250ec..78b82eda79 100644 --- a/tests/topotests/nhrp_topo/test_nhrp_topo.py +++ b/tests/topotests/nhrp_topo/test_nhrp_topo.py @@ -108,6 +108,12 @@ def setup_module(mod): TopoRouter.RD_NHRP, os.path.join(CWD, "{}/nhrpd.conf".format(rname)) ) + # Include sharpd for r1 + if rname == "r1": + router.load_config( + TopoRouter.RD_SHARP, os.path.join(CWD, "{}/sharpd.conf".format(rname)) + ) + # Initialize all routers. logger.info("Launching NHRP") for name in router_list: @@ -201,6 +207,38 @@ def test_nhrp_connection(): logger.info("Check Ping IPv4 from R1 to R2 OK") +def test_route_install(): + "Test use of NHRP routes by other protocols (sharpd here)." + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + logger.info("Testing route install over NHRP tunnel") + + # Install sharpd routes over an NHRP route + r1 = tgen.gears["r1"] + + # Install one recursive and one non-recursive sharpd route + r1.vtysh_cmd("sharp install route 4.4.4.1 nexthop 10.255.255.2 1") + + r1.vtysh_cmd("sharp install route 5.5.5.1 nexthop 10.255.255.2 1 no-recurse") + + json_file = "{}/{}/sharp_route4.json".format(CWD, "r1") + expected = json.loads(open(json_file).read()) + + test_func = partial( + topotest.router_json_cmp, r1, "show ip route sharp json", expected + ) + _, result = topotest.run_and_expect(test_func, None, count=20, wait=0.5) + + logger.info("Sharp routes:") + output = r1.vtysh_cmd("show ip route sharp") + logger.info(output) + + assertmsg = '"{}" JSON route output mismatches'.format(r1.name) + assert result is None, assertmsg + + def test_memory_leak(): "Run the memory leak test and report results." tgen = get_topogen() diff --git a/tests/topotests/ospf6_ecmp_inter_area/test_ospf6_ecmp_inter_area.py b/tests/topotests/ospf6_ecmp_inter_area/test_ospf6_ecmp_inter_area.py index ec15ff9b1a..2eaccb8348 100644 --- a/tests/topotests/ospf6_ecmp_inter_area/test_ospf6_ecmp_inter_area.py +++ b/tests/topotests/ospf6_ecmp_inter_area/test_ospf6_ecmp_inter_area.py @@ -110,15 +110,18 @@ def test_wait_protocol_convergence(): def expect_neighbor_full(router, neighbor): "Wait until OSPFv3 neighborship is full" - logger.info("waiting for OSPFv3 router '{}' neighborship with '{}'".format(router, neighbor)) + logger.info( + "waiting for OSPFv3 router '{}' neighborship with '{}'".format( + router, neighbor + ) + ) test_func = partial( topotest.router_json_cmp, tgen.gears[router], "show ipv6 ospf6 neighbor json", {"neighbors": [{"neighborId": neighbor, "state": "Full"}]}, ) - _, result = topotest.run_and_expect(test_func, None, - count=130, wait=1) + _, result = topotest.run_and_expect(test_func, None, count=130, wait=1) assertmsg = '"{}" convergence failure'.format(router) assert result is None, assertmsg @@ -143,6 +146,7 @@ def expect_neighbor_full(router, neighbor): expect_neighbor_full("r8", "10.254.254.5") expect_neighbor_full("r9", "10.254.254.5") + def test_ecmp_inter_area(): "Test whether OSPFv3 ECMP nexthops are properly updated for inter-area routes after link down" tgen = get_topogen() @@ -156,22 +160,28 @@ def num_nexthops(router): def expect_num_nexthops(router, expected_num_nexthops, count): "Wait until number of nexthops for routes matches expectation" - logger.info("waiting for OSPFv3 router '{}' nexthops {}".format(router, expected_num_nexthops)) + logger.info( + "waiting for OSPFv3 router '{}' nexthops {}".format( + router, expected_num_nexthops + ) + ) test_func = partial(num_nexthops, router) - _, result = topotest.run_and_expect(test_func, expected_num_nexthops, - count=count, wait=3) - assert result == expected_num_nexthops, \ - "'{}' wrong number of route nexthops".format(router) + _, result = topotest.run_and_expect( + test_func, expected_num_nexthops, count=count, wait=3 + ) + assert ( + result == expected_num_nexthops + ), "'{}' wrong number of route nexthops".format(router) # Check nexthops pre link-down - expect_num_nexthops("r1", [1, 1, 1, 3, 3, 3, 3, 3], 4) + expect_num_nexthops("r1", [1, 1, 1, 3, 3, 3, 3, 3, 3, 3], 4) logger.info("triggering R2-R4 link down") tgen.gears["r2"].run("ip link set r2-eth1 down") - #tgen.mininet_cli() + # tgen.mininet_cli() # Check nexthops post link-down - expect_num_nexthops("r1", [1, 1, 1, 2, 2, 2, 2, 2], 8) + expect_num_nexthops("r1", [1, 1, 1, 2, 2, 2, 2, 2, 2, 2], 8) def teardown_module(_mod): diff --git a/tests/topotests/ospf6_gr_topo1/rt1/ospf6d.conf b/tests/topotests/ospf6_gr_topo1/rt1/ospf6d.conf index 8a9b4eb124..aa9438b78e 100644 --- a/tests/topotests/ospf6_gr_topo1/rt1/ospf6d.conf +++ b/tests/topotests/ospf6_gr_topo1/rt1/ospf6d.conf @@ -1,4 +1,3 @@ -:assword 1 hostname rt1 log file ospf6d.log log commands diff --git a/tests/topotests/ospf6_gr_topo1/rt1/show_ipv6_route.json b/tests/topotests/ospf6_gr_topo1/rt1/show_ipv6_route.json index 66ee57ce84..181d376774 100644 --- a/tests/topotests/ospf6_gr_topo1/rt1/show_ipv6_route.json +++ b/tests/topotests/ospf6_gr_topo1/rt1/show_ipv6_route.json @@ -6,7 +6,7 @@ "vrfId":0, "vrfName":"default", "distance":110, - "metric":10, + "metric":0, "nexthops":[ { "directlyConnected":true, @@ -25,7 +25,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":20, + "metric":10, "installed":true, "nexthops":[ { @@ -45,7 +45,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":30, + "metric":20, "installed":true, "nexthops":[ { @@ -65,7 +65,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":40, + "metric":30, "installed":true, "nexthops":[ { @@ -85,7 +85,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":50, + "metric":40, "installed":true, "nexthops":[ { @@ -105,7 +105,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":40, + "metric":30, "installed":true, "nexthops":[ { @@ -125,7 +125,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":50, + "metric":40, "installed":true, "nexthops":[ { diff --git a/tests/topotests/ospf6_gr_topo1/rt2/show_ipv6_route.json b/tests/topotests/ospf6_gr_topo1/rt2/show_ipv6_route.json index 624ff709e3..13b5cd4468 100644 --- a/tests/topotests/ospf6_gr_topo1/rt2/show_ipv6_route.json +++ b/tests/topotests/ospf6_gr_topo1/rt2/show_ipv6_route.json @@ -8,7 +8,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":20, + "metric":10, "installed":true, "nexthops":[ { @@ -26,7 +26,7 @@ "vrfId":0, "vrfName":"default", "distance":110, - "metric":10, + "metric":0, "nexthops":[ { "directlyConnected":true, @@ -45,7 +45,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":20, + "metric":10, "installed":true, "nexthops":[ { @@ -65,7 +65,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":30, + "metric":20, "installed":true, "nexthops":[ { @@ -85,7 +85,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":40, + "metric":30, "installed":true, "nexthops":[ { @@ -105,7 +105,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":30, + "metric":20, "installed":true, "nexthops":[ { @@ -125,7 +125,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":40, + "metric":30, "installed":true, "nexthops":[ { diff --git a/tests/topotests/ospf6_gr_topo1/rt3/show_ipv6_route.json b/tests/topotests/ospf6_gr_topo1/rt3/show_ipv6_route.json index f9b43dcdb9..db6ec3e3a8 100644 --- a/tests/topotests/ospf6_gr_topo1/rt3/show_ipv6_route.json +++ b/tests/topotests/ospf6_gr_topo1/rt3/show_ipv6_route.json @@ -8,7 +8,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":30, + "metric":20, "installed":true, "nexthops":[ { @@ -28,7 +28,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":20, + "metric":10, "installed":true, "nexthops":[ { @@ -46,7 +46,7 @@ "vrfId":0, "vrfName":"default", "distance":110, - "metric":10, + "metric":0, "nexthops":[ { "directlyConnected":true, @@ -65,7 +65,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":20, + "metric":10, "installed":true, "nexthops":[ { @@ -85,7 +85,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":30, + "metric":20, "installed":true, "nexthops":[ { @@ -105,7 +105,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":20, + "metric":10, "installed":true, "nexthops":[ { @@ -125,7 +125,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":30, + "metric":20, "installed":true, "nexthops":[ { diff --git a/tests/topotests/ospf6_gr_topo1/rt4/show_ipv6_route.json b/tests/topotests/ospf6_gr_topo1/rt4/show_ipv6_route.json index f5212da4f6..08ccff2fc5 100644 --- a/tests/topotests/ospf6_gr_topo1/rt4/show_ipv6_route.json +++ b/tests/topotests/ospf6_gr_topo1/rt4/show_ipv6_route.json @@ -8,7 +8,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":40, + "metric":30, "installed":true, "nexthops":[ { @@ -28,7 +28,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":30, + "metric":20, "installed":true, "nexthops":[ { @@ -48,7 +48,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":20, + "metric":10, "installed":true, "nexthops":[ { @@ -66,7 +66,7 @@ "vrfId":0, "vrfName":"default", "distance":110, - "metric":10, + "metric":0, "nexthops":[ { "directlyConnected":true, @@ -85,7 +85,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":20, + "metric":10, "installed":true, "nexthops":[ { @@ -105,7 +105,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":30, + "metric":20, "installed":true, "nexthops":[ { @@ -125,7 +125,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":40, + "metric":30, "installed":true, "nexthops":[ { diff --git a/tests/topotests/ospf6_gr_topo1/rt5/show_ipv6_route.json b/tests/topotests/ospf6_gr_topo1/rt5/show_ipv6_route.json index 5ea4f699fe..8ddd55b132 100644 --- a/tests/topotests/ospf6_gr_topo1/rt5/show_ipv6_route.json +++ b/tests/topotests/ospf6_gr_topo1/rt5/show_ipv6_route.json @@ -8,7 +8,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":50, + "metric":40, "installed":true, "nexthops":[ { @@ -28,7 +28,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":40, + "metric":30, "installed":true, "nexthops":[ { @@ -48,7 +48,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":30, + "metric":20, "installed":true, "nexthops":[ { @@ -68,7 +68,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":20, + "metric":10, "installed":true, "nexthops":[ { @@ -86,7 +86,7 @@ "vrfId":0, "vrfName":"default", "distance":110, - "metric":10, + "metric":0, "nexthops":[ { "directlyConnected":true, @@ -105,7 +105,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":40, + "metric":30, "installed":true, "nexthops":[ { @@ -125,7 +125,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":50, + "metric":40, "installed":true, "nexthops":[ { diff --git a/tests/topotests/ospf6_gr_topo1/rt6/show_ipv6_route.json b/tests/topotests/ospf6_gr_topo1/rt6/show_ipv6_route.json index 862f1baffb..9d45b09be8 100644 --- a/tests/topotests/ospf6_gr_topo1/rt6/show_ipv6_route.json +++ b/tests/topotests/ospf6_gr_topo1/rt6/show_ipv6_route.json @@ -8,7 +8,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":40, + "metric":30, "installed":true, "nexthops":[ { @@ -28,7 +28,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":30, + "metric":20, "installed":true, "nexthops":[ { @@ -48,7 +48,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":20, + "metric":10, "installed":true, "nexthops":[ { @@ -68,7 +68,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":30, + "metric":20, "installed":true, "nexthops":[ { @@ -88,7 +88,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":40, + "metric":30, "installed":true, "nexthops":[ { @@ -106,7 +106,7 @@ "vrfId":0, "vrfName":"default", "distance":110, - "metric":10, + "metric":0, "nexthops":[ { "directlyConnected":true, @@ -125,7 +125,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":20, + "metric":10, "installed":true, "nexthops":[ { diff --git a/tests/topotests/ospf6_gr_topo1/rt7/show_ipv6_route.json b/tests/topotests/ospf6_gr_topo1/rt7/show_ipv6_route.json index f5f8f710e5..c4f841468d 100644 --- a/tests/topotests/ospf6_gr_topo1/rt7/show_ipv6_route.json +++ b/tests/topotests/ospf6_gr_topo1/rt7/show_ipv6_route.json @@ -8,7 +8,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":50, + "metric":40, "installed":true, "nexthops":[ { @@ -28,7 +28,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":40, + "metric":30, "installed":true, "nexthops":[ { @@ -48,7 +48,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":30, + "metric":20, "installed":true, "nexthops":[ { @@ -68,7 +68,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":40, + "metric":30, "installed":true, "nexthops":[ { @@ -88,7 +88,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":50, + "metric":40, "installed":true, "nexthops":[ { @@ -108,7 +108,7 @@ "selected":true, "destSelected":true, "distance":110, - "metric":20, + "metric":10, "installed":true, "nexthops":[ { @@ -126,7 +126,7 @@ "vrfId":0, "vrfName":"default", "distance":110, - "metric":10, + "metric":0, "nexthops":[ { "directlyConnected":true, diff --git a/tests/topotests/ospf6_loopback_cost/__init__.py b/tests/topotests/ospf6_loopback_cost/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/ospf6_loopback_cost/r1/frr.conf b/tests/topotests/ospf6_loopback_cost/r1/frr.conf new file mode 100644 index 0000000000..d85166bc6c --- /dev/null +++ b/tests/topotests/ospf6_loopback_cost/r1/frr.conf @@ -0,0 +1,16 @@ +! +int lo + ipv6 address 2001:db8::1/128 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 passive +! +int r1-eth0 + ipv6 address 2001:db8:1::1/64 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 hello-interval 1 + ipv6 ospf6 dead-interval 4 +! +router ospf6 + ospf6 router-id 0.0.0.1 +exit +! diff --git a/tests/topotests/ospf6_loopback_cost/r2/frr.conf b/tests/topotests/ospf6_loopback_cost/r2/frr.conf new file mode 100644 index 0000000000..8f3e2caab6 --- /dev/null +++ b/tests/topotests/ospf6_loopback_cost/r2/frr.conf @@ -0,0 +1,16 @@ +! +int lo + ipv6 address 2001:db8::2/128 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 passive +! +int r2-eth0 + ipv6 address 2001:db8:1::2/64 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 hello-interval 1 + ipv6 ospf6 dead-interval 4 +! +router ospf6 + ospf6 router-id 0.0.0.2 +exit +! diff --git a/tests/topotests/ospf6_loopback_cost/test_ospf6_loopback_cost.py b/tests/topotests/ospf6_loopback_cost/test_ospf6_loopback_cost.py new file mode 100644 index 0000000000..8e7a7ea40a --- /dev/null +++ b/tests/topotests/ospf6_loopback_cost/test_ospf6_loopback_cost.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# Copyright (c) 2023 by +# Donatas Abraitis <donatas@opensourcerouting.org> +# + +""" +Test if OSPFv3 loopback interfaces get a cost of 0. + +https://www.rfc-editor.org/rfc/rfc5340.html#page-37: + +If the interface type is point-to-multipoint or the interface is +in the state Loopback, the global scope IPv6 addresses associated +with the interface (if any) are copied into the intra-area-prefix-LSA +with the PrefixOptions LA-bit set, the PrefixLength set to 128, and +the metric set to 0. +""" + +import os +import sys +import json +import pytest +import functools + +pytestmark = pytest.mark.ospf6d + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen + + +def setup_module(mod): + topodef = {"s1": ("r1", "r2")} + tgen = Topogen(topodef, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for _, (rname, router) in enumerate(router_list.items(), 1): + router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname))) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_ospf6_loopback_cost(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + + def _show_ipv6_route(): + output = json.loads(r1.vtysh_cmd("show ipv6 route json")) + expected = { + "2001:db8::1/128": [ + { + "metric": 0, + "distance": 110, + } + ], + "2001:db8::2/128": [ + { + "metric": 10, + "distance": 110, + } + ], + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _show_ipv6_route, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assert result is None, "Loopback cost isn't 0" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/ospf6_point_to_multipoint/README.md b/tests/topotests/ospf6_point_to_multipoint/README.md new file mode 100644 index 0000000000..59c9837aea --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/README.md @@ -0,0 +1,137 @@ +# OSPFv3 (IPv6) Topology Test (point-to-multipoint) + +## Topology + -----\ + SW1 - Stub Net 1 SW2 - Stub Net 2 \ + fc00:1:1:1::/64 fc00:2:2:2::/64 \ + \___________________/ \___________________/ | + | | | + | | | + | ::1 | ::2 | + +---------+---------+ +---------+---------+ | + | R1 | | R2 | | + | FRRouting | | FRRouting | | + | Rtr-ID: 10.0.0.1 | | Rtr-ID: 10.0.0.2 | | + +---------+---------+ +---------+---------+ | + | ::1 | ::2 \ + \______ ___________/ OSPFv3 + \ / Area 0.0.0.0 + \ / / + ~~~~~~~~~~~~~~~~~~ | + ~~ SW5 ~~ | + ~~ Switch ~~ | + ~~ fc00:A:A:A::/64 ~~ | + ~~~~~~~~~~~~~~~~~~ | + | /---- | + | ::3 | SW3 - Stub Net 3 | + +---------+---------+ /-+ fc00:3:3:3::/64 | + | R3 | / | / + | FRRouting +--/ \---- / + | Rtr-ID: 10.0.0.3 | ::3 ___________/ + +---------+---------+ \ + | ::3 \ + | \ + ~~~~~~~~~~~~~~~~~~ | + ~~ SW6 ~~ | + ~~ Switch ~~ | + ~~ fc00:B:B:B::/64 ~~ \ + ~~~~~~~~~~~~~~~~~~ OSPFv3 + | Area 0.0.0.1 + | ::4 / + +---------+---------+ /---- | + | R4 | | SW4 - Stub Net 4 | + | FRRouting +------+ fc00:4:4:4::/64 | + | Rtr-ID: 10.0.0.4 | ::4 | / + +-------------------+ \---- / + -----/ + +## FRR Configuration + +Full config as used is in r1 / r2 / r3 / r4 / r5 subdirectories + +Simplified `R1` config (R1 is similar) + + hostname r1 + ! + interface r1-stubnet + ipv6 address fc00:1:1:1::1/64 + ipv6 ospf6 passive + ipv6 ospf6 area 0.0.0.0 + ! + interface r1-sw5 + ipv6 address fc00:a:a:a::1/64 + ipv6 ospf6 network point-to-multipoint + ipv6 ospf6 area 0.0.0.0 + ! + router ospf6 + router-id 10.0.0.1 + log-adjacency-changes detail + redistribute static + ! + ipv6 route fc00:1111:1111:1111::/64 fc00:1:1:1::1234 + +Simplified `R3` config + + hostname r3 + ! + interface r3-stubnet + ipv6 address fc00:3:3:3::3/64 + ipv6 ospf6 passive + ipv6 ospf6 area 0.0.0.0 + ! + interface r3-sw5 + ipv6 address fc00:a:a:a::3/64 + ipv6 ospf6 network point-to-multipoint + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 p2p-p2mp connected-prefixes include + ! + interface r3-sw6 + ipv6 address fc00:b:b:b::3/64 + ipv6 ospf6 network point-to-multipoint + ipv6 ospf6 area 0.0.0.1 + ipv6 ospf6 p2p-p2mp connected-prefixes include + ! + router ospf6 + router-id 10.0.0.3 + log-adjacency-changes detail + redistribute static + ! + ipv6 route fc00:3333:3333:3333::/64 fc00:3:3:3::1234 + +## Tests executed + +### Check if FRR is running + +Test is executed by running + + vtysh -c "show logging" | grep "Logging configuration for" + +on each FRR router. This should return the logging information for all daemons registered +to Zebra and the list of running daemons is compared to the daemons started for this test (`zebra` and `ospf6d`) + +### Check if OSPFv3 to converge + +OSPFv3 is expected to converge on each view within 60s total time. Convergence is verified by executing (on each node) + + vtysh -c "show ipv6 ospf neigh" + +and checking for "Full" neighbor status in the output. An additional 15 seconds after the full converge is waited for +routes to populate before the following routing table checks are executed + +### Check OSPFv3 Routing Tables + +Routing table is verified by running + + vtysh -c "show ipv6 route" + +on each node and comparing the result to the stored example config (see `show_ipv6_route.ref` in r1 / r2 / r3 / r4 directories). +Link-Local addresses are masked out before the compare. + +### Check Linux Kernel Routing Table + +Linux Kernel IPv6 Routing table is verified on each FRR node with + + ip -6 route + +Tables are compared with reference routing table (see `ip_6_address.ref` in r1 / r2 / r3 / r4 directories). +Link-Local addresses are translated after getting collected on each node with interface name to make them consistent diff --git a/tests/topotests/ospf6_point_to_multipoint/r1/ip_6_address.nhg.ref b/tests/topotests/ospf6_point_to_multipoint/r1/ip_6_address.nhg.ref new file mode 100644 index 0000000000..203f2def5e --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/r1/ip_6_address.nhg.ref @@ -0,0 +1,14 @@ +fc00:1111:1111:1111::/64 nhid XXXX via fc00:1:1:1::1234 dev r1-stubnet proto XXXX metric 20 pref medium +fc00:1:1:1::/64 dev r1-stubnet proto XXXX metric 256 pref medium +fc00:2222:2222:2222::/64 nhid XXXX via fe80::__(r2-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium +fc00:2:2:2::/64 nhid XXXX via fe80::__(r2-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium +fc00:3333:3333:3333::/64 nhid XXXX via fe80::__(r3-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium +fc00:3:3:3::/64 nhid XXXX via fe80::__(r3-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium +fc00:4444:4444:4444::/64 nhid XXXX via fe80::__(r3-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium +fc00:4:4:4::/64 nhid XXXX via fe80::__(r3-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium +fc00:a:a:a::/64 dev r1-sw5 proto XXXX metric 256 pref medium +fc00:a:a:a::2 nhid XXXX via fe80::__(r2-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium +fc00:a:a:a::3 nhid XXXX via fe80::__(r3-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium +fc00:b:b:b::/64 nhid XXXX via fe80::__(r3-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium +fc00:b:b:b::3 nhid XXXX via fe80::__(r3-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium +fc00:b:b:b::4 nhid XXXX via fe80::__(r3-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium diff --git a/tests/topotests/ospf6_point_to_multipoint/r1/ip_6_address.ref b/tests/topotests/ospf6_point_to_multipoint/r1/ip_6_address.ref new file mode 100644 index 0000000000..b77c996740 --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/r1/ip_6_address.ref @@ -0,0 +1,14 @@ +fc00:1111:1111:1111::/64 via fc00:1:1:1::1234 dev r1-stubnet proto XXXX metric 20 pref medium +fc00:1:1:1::/64 dev r1-stubnet proto XXXX metric 256 pref medium +fc00:2222:2222:2222::/64 via fe80::__(r2-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium +fc00:2:2:2::/64 via fe80::__(r2-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium +fc00:3333:3333:3333::/64 via fe80::__(r3-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium +fc00:3:3:3::/64 via fe80::__(r3-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium +fc00:4444:4444:4444::/64 via fe80::__(r3-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium +fc00:4:4:4::/64 via fe80::__(r3-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium +fc00:a:a:a::/64 dev r1-sw5 proto XXXX metric 256 pref medium +fc00:a:a:a::2 via fe80::__(r2-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium +fc00:a:a:a::3 via fe80::__(r3-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium +fc00:b:b:b::/64 via fe80::__(r3-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium +fc00:b:b:b::3 via fe80::__(r3-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium +fc00:b:b:b::4 via fe80::__(r3-sw5)__ dev r1-sw5 proto XXXX metric 20 pref medium diff --git a/tests/topotests/ospf6_point_to_multipoint/r1/ospf6d.conf b/tests/topotests/ospf6_point_to_multipoint/r1/ospf6d.conf new file mode 100644 index 0000000000..79a9dcae11 --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/r1/ospf6d.conf @@ -0,0 +1,30 @@ +hostname r1 +log file ospf6d.log +! +! debug ospf6 message all +! debug ospf6 lsa unknown +! debug ospf6 zebra +! debug ospf6 interface +! debug ospf6 neighbor +! debug ospf6 route table +! debug ospf6 flooding +! +interface r1-sw5 + ipv6 ospf6 network point-to-multipoint + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 hello-interval 2 + ipv6 ospf6 dead-interval 10 + ipv6 ospf6 p2p-p2mp connected-prefixes include +! +interface r1-stubnet + ipv6 ospf6 passive + ipv6 ospf6 area 0.0.0.0 +! +router ospf6 + ospf6 router-id 10.0.0.1 + log-adjacency-changes detail + redistribute static +! +line vty + exec-timeout 0 0 +! diff --git a/tests/topotests/ospf6_point_to_multipoint/r1/show_ipv6_route.ref b/tests/topotests/ospf6_point_to_multipoint/r1/show_ipv6_route.ref new file mode 100644 index 0000000000..911b3e40d6 --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/r1/show_ipv6_route.ref @@ -0,0 +1,13 @@ +O fc00:1:1:1::/64 [110/10] is directly connected, r1-stubnet, weight 1, XX:XX:XX +O>* fc00:2:2:2::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r1-sw5, weight 1, XX:XX:XX +O>* fc00:3:3:3::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r1-sw5, weight 1, XX:XX:XX +O>* fc00:4:4:4::/64 [110/30] via fe80::XXXX:XXXX:XXXX:XXXX, r1-sw5, weight 1, XX:XX:XX +O fc00:a:a:a::/64 [110/10] is directly connected, r1-sw5, weight 1, XX:XX:XX +O>* fc00:a:a:a::2/128 [110/10] via fe80::XXXX:XXXX:XXXX:XXXX, r1-sw5, weight 1, XX:XX:XX +O>* fc00:a:a:a::3/128 [110/10] via fe80::XXXX:XXXX:XXXX:XXXX, r1-sw5, weight 1, XX:XX:XX +O>* fc00:b:b:b::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r1-sw5, weight 1, XX:XX:XX +O>* fc00:b:b:b::3/128 [110/10] via fe80::XXXX:XXXX:XXXX:XXXX, r1-sw5, weight 1, XX:XX:XX +O>* fc00:b:b:b::4/128 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r1-sw5, weight 1, XX:XX:XX +O>* fc00:2222:2222:2222::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r1-sw5, weight 1, XX:XX:XX +O>* fc00:3333:3333:3333::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r1-sw5, weight 1, XX:XX:XX +O>* fc00:4444:4444:4444::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r1-sw5, weight 1, XX:XX:XX diff --git a/tests/topotests/ospf6_point_to_multipoint/r1/zebra.conf b/tests/topotests/ospf6_point_to_multipoint/r1/zebra.conf new file mode 100644 index 0000000000..3a7db9f25e --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/r1/zebra.conf @@ -0,0 +1,20 @@ +! +hostname r1 +log file zebra.log +! +! debug zebra events +! debug zebra rib +! +interface r1-stubnet + ipv6 address fc00:1:1:1::1/64 +! +interface r1-sw5 + ipv6 address fc00:a:a:a::1/64 +! +interface lo +! +ipv6 route fc00:1111:1111:1111::/64 fc00:1:1:1::1234 +! +! +line vty +! diff --git a/tests/topotests/ospf6_point_to_multipoint/r2/ip_6_address.nhg.ref b/tests/topotests/ospf6_point_to_multipoint/r2/ip_6_address.nhg.ref new file mode 100644 index 0000000000..d4534b10bb --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/r2/ip_6_address.nhg.ref @@ -0,0 +1,14 @@ +fc00:1111:1111:1111::/64 nhid XXXX via fe80::__(r1-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium +fc00:1:1:1::/64 nhid XXXX via fe80::__(r1-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium +fc00:2222:2222:2222::/64 nhid XXXX via fc00:2:2:2::1234 dev r2-stubnet proto XXXX metric 20 pref medium +fc00:2:2:2::/64 dev r2-stubnet proto XXXX metric 256 pref medium +fc00:3333:3333:3333::/64 nhid XXXX via fe80::__(r3-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium +fc00:3:3:3::/64 nhid XXXX via fe80::__(r3-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium +fc00:4444:4444:4444::/64 nhid XXXX via fe80::__(r3-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium +fc00:4:4:4::/64 nhid XXXX via fe80::__(r3-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium +fc00:a:a:a::/64 dev r2-sw5 proto XXXX metric 256 pref medium +fc00:a:a:a::1 nhid XXXX via fe80::__(r1-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium +fc00:a:a:a::3 nhid XXXX via fe80::__(r3-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium +fc00:b:b:b::/64 nhid XXXX via fe80::__(r3-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium +fc00:b:b:b::3 nhid XXXX via fe80::__(r3-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium +fc00:b:b:b::4 nhid XXXX via fe80::__(r3-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium diff --git a/tests/topotests/ospf6_point_to_multipoint/r2/ip_6_address.ref b/tests/topotests/ospf6_point_to_multipoint/r2/ip_6_address.ref new file mode 100644 index 0000000000..330b696c3a --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/r2/ip_6_address.ref @@ -0,0 +1,14 @@ +fc00:1111:1111:1111::/64 via fe80::__(r1-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium +fc00:1:1:1::/64 via fe80::__(r1-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium +fc00:2222:2222:2222::/64 via fc00:2:2:2::1234 dev r2-stubnet proto XXXX metric 20 pref medium +fc00:2:2:2::/64 dev r2-stubnet proto XXXX metric 256 pref medium +fc00:3333:3333:3333::/64 via fe80::__(r3-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium +fc00:3:3:3::/64 via fe80::__(r3-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium +fc00:4444:4444:4444::/64 via fe80::__(r3-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium +fc00:4:4:4::/64 via fe80::__(r3-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium +fc00:a:a:a::/64 dev r2-sw5 proto XXXX metric 256 pref medium +fc00:a:a:a::1 via fe80::__(r1-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium +fc00:a:a:a::3 via fe80::__(r3-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium +fc00:b:b:b::/64 via fe80::__(r3-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium +fc00:b:b:b::3 via fe80::__(r3-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium +fc00:b:b:b::4 via fe80::__(r3-sw5)__ dev r2-sw5 proto XXXX metric 20 pref medium diff --git a/tests/topotests/ospf6_point_to_multipoint/r2/ospf6d.conf b/tests/topotests/ospf6_point_to_multipoint/r2/ospf6d.conf new file mode 100644 index 0000000000..751d8d84e7 --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/r2/ospf6d.conf @@ -0,0 +1,30 @@ +hostname r2 +log file ospf6d.log +! +! debug ospf6 message all +! debug ospf6 lsa unknown +! debug ospf6 zebra +! debug ospf6 interface +! debug ospf6 neighbor +! debug ospf6 route table +! debug ospf6 flooding +! +interface r2-sw5 + ipv6 ospf6 network point-to-multipoint + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 hello-interval 2 + ipv6 ospf6 dead-interval 10 + ipv6 ospf6 p2p-p2mp connected-prefixes include +! +interface r2-stubnet + ipv6 ospf6 passive + ipv6 ospf6 area 0.0.0.0 +! +router ospf6 + ospf6 router-id 10.0.0.2 + log-adjacency-changes detail + redistribute static +! +line vty + exec-timeout 0 0 +! diff --git a/tests/topotests/ospf6_point_to_multipoint/r2/show_ipv6_route.ref b/tests/topotests/ospf6_point_to_multipoint/r2/show_ipv6_route.ref new file mode 100644 index 0000000000..2eff0291ad --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/r2/show_ipv6_route.ref @@ -0,0 +1,13 @@ +O>* fc00:1:1:1::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r2-sw5, weight 1, XX:XX:XX +O fc00:2:2:2::/64 [110/10] is directly connected, r2-stubnet, weight 1, XX:XX:XX +O>* fc00:3:3:3::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r2-sw5, weight 1, XX:XX:XX +O>* fc00:4:4:4::/64 [110/30] via fe80::XXXX:XXXX:XXXX:XXXX, r2-sw5, weight 1, XX:XX:XX +O fc00:a:a:a::/64 [110/10] is directly connected, r2-sw5, weight 1, XX:XX:XX +O>* fc00:a:a:a::1/128 [110/10] via fe80::XXXX:XXXX:XXXX:XXXX, r2-sw5, weight 1, XX:XX:XX +O>* fc00:a:a:a::3/128 [110/10] via fe80::XXXX:XXXX:XXXX:XXXX, r2-sw5, weight 1, XX:XX:XX +O>* fc00:b:b:b::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r2-sw5, weight 1, XX:XX:XX +O>* fc00:b:b:b::3/128 [110/10] via fe80::XXXX:XXXX:XXXX:XXXX, r2-sw5, weight 1, XX:XX:XX +O>* fc00:b:b:b::4/128 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r2-sw5, weight 1, XX:XX:XX +O>* fc00:1111:1111:1111::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r2-sw5, weight 1, XX:XX:XX +O>* fc00:3333:3333:3333::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r2-sw5, weight 1, XX:XX:XX +O>* fc00:4444:4444:4444::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r2-sw5, weight 1, XX:XX:XX diff --git a/tests/topotests/ospf6_point_to_multipoint/r2/zebra.conf b/tests/topotests/ospf6_point_to_multipoint/r2/zebra.conf new file mode 100644 index 0000000000..5571dc979c --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/r2/zebra.conf @@ -0,0 +1,20 @@ +! +hostname r2 +log file zebra.log +! +! debug zebra events +! debug zebra rib +! +interface r2-stubnet + ipv6 address fc00:2:2:2::2/64 +! +interface r2-sw5 + ipv6 address fc00:a:a:a::2/64 +! +interface lo +! +ipv6 route fc00:2222:2222:2222::/64 fc00:2:2:2::1234 +! +! +line vty +! diff --git a/tests/topotests/ospf6_point_to_multipoint/r3/ip_6_address.nhg.ref b/tests/topotests/ospf6_point_to_multipoint/r3/ip_6_address.nhg.ref new file mode 100644 index 0000000000..903c1d962f --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/r3/ip_6_address.nhg.ref @@ -0,0 +1,13 @@ +fc00:1111:1111:1111::/64 nhid XXXX via fe80::__(r1-sw5)__ dev r3-sw5 proto XXXX metric 20 pref medium +fc00:1:1:1::/64 nhid XXXX via fe80::__(r1-sw5)__ dev r3-sw5 proto XXXX metric 20 pref medium +fc00:2222:2222:2222::/64 nhid XXXX via fe80::__(r2-sw5)__ dev r3-sw5 proto XXXX metric 20 pref medium +fc00:2:2:2::/64 nhid XXXX via fe80::__(r2-sw5)__ dev r3-sw5 proto XXXX metric 20 pref medium +fc00:3333:3333:3333::/64 nhid XXXX via fc00:3:3:3::1234 dev r3-stubnet proto XXXX metric 20 pref medium +fc00:3:3:3::/64 dev r3-stubnet proto XXXX metric 256 pref medium +fc00:4444:4444:4444::/64 nhid XXXX via fe80::__(r4-sw6)__ dev r3-sw6 proto XXXX metric 20 pref medium +fc00:4:4:4::/64 nhid XXXX via fe80::__(r4-sw6)__ dev r3-sw6 proto XXXX metric 20 pref medium +fc00:a:a:a::/64 dev r3-sw5 proto XXXX metric 256 pref medium +fc00:a:a:a::1 nhid XXXX via fe80::__(r1-sw5)__ dev r3-sw5 proto XXXX metric 20 pref medium +fc00:a:a:a::2 nhid XXXX via fe80::__(r2-sw5)__ dev r3-sw5 proto XXXX metric 20 pref medium +fc00:b:b:b::/64 dev r3-sw6 proto XXXX metric 256 pref medium +fc00:b:b:b::4 nhid XXXX via fe80::__(r4-sw6)__ dev r3-sw6 proto XXXX metric 20 pref medium diff --git a/tests/topotests/ospf6_point_to_multipoint/r3/ip_6_address.ref b/tests/topotests/ospf6_point_to_multipoint/r3/ip_6_address.ref new file mode 100644 index 0000000000..3dbcf36b48 --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/r3/ip_6_address.ref @@ -0,0 +1,13 @@ +fc00:1111:1111:1111::/64 via fe80::__(r1-sw5)__ dev r3-sw5 proto XXXX metric 20 pref medium +fc00:1:1:1::/64 via fe80::__(r1-sw5)__ dev r3-sw5 proto XXXX metric 20 pref medium +fc00:2222:2222:2222::/64 via fe80::__(r2-sw5)__ dev r3-sw5 proto XXXX metric 20 pref medium +fc00:2:2:2::/64 via fe80::__(r2-sw5)__ dev r3-sw5 proto XXXX metric 20 pref medium +fc00:3333:3333:3333::/64 via fc00:3:3:3::1234 dev r3-stubnet proto XXXX metric 20 pref medium +fc00:3:3:3::/64 dev r3-stubnet proto XXXX metric 256 pref medium +fc00:4444:4444:4444::/64 via fe80::__(r4-sw6)__ dev r3-sw6 proto XXXX metric 20 pref medium +fc00:4:4:4::/64 via fe80::__(r4-sw6)__ dev r3-sw6 proto XXXX metric 20 pref medium +fc00:a:a:a::/64 dev r3-sw5 proto XXXX metric 256 pref medium +fc00:a:a:a::1 via fe80::__(r1-sw5)__ dev r3-sw5 proto XXXX metric 20 pref medium +fc00:a:a:a::2 via fe80::__(r2-sw5)__ dev r3-sw5 proto XXXX metric 20 pref medium +fc00:b:b:b::/64 dev r3-sw6 proto XXXX metric 256 pref medium +fc00:b:b:b::4 via fe80::__(r4-sw6)__ dev r3-sw6 proto XXXX metric 20 pref medium diff --git a/tests/topotests/ospf6_point_to_multipoint/r3/ospf6d.conf b/tests/topotests/ospf6_point_to_multipoint/r3/ospf6d.conf new file mode 100644 index 0000000000..74e8ddf00f --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/r3/ospf6d.conf @@ -0,0 +1,37 @@ +hostname r3 +log file ospf6d.log +! +! debug ospf6 message all +! debug ospf6 lsa unknown +! debug ospf6 zebra +! debug ospf6 interface +! debug ospf6 neighbor +! debug ospf6 route table +! debug ospf6 flooding +! +interface r3-sw5 + ipv6 ospf6 network point-to-multipoint + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 hello-interval 2 + ipv6 ospf6 dead-interval 10 + ipv6 ospf6 p2p-p2mp connected-prefixes include +! +interface r3-sw6 + ipv6 ospf6 network point-to-multipoint + ipv6 ospf6 area 0.0.0.1 + ipv6 ospf6 hello-interval 2 + ipv6 ospf6 dead-interval 10 + ipv6 ospf6 p2p-p2mp connected-prefixes include +! +interface r3-stubnet + ipv6 ospf6 passive + ipv6 ospf6 area 0.0.0.0 +! +router ospf6 + ospf6 router-id 10.0.0.3 + log-adjacency-changes detail + redistribute static +! +line vty + exec-timeout 0 0 +! diff --git a/tests/topotests/ospf6_point_to_multipoint/r3/show_ipv6_route.ref b/tests/topotests/ospf6_point_to_multipoint/r3/show_ipv6_route.ref new file mode 100644 index 0000000000..df949e64ea --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/r3/show_ipv6_route.ref @@ -0,0 +1,12 @@ +O>* fc00:1:1:1::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r3-sw5, weight 1, XX:XX:XX +O>* fc00:2:2:2::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r3-sw5, weight 1, XX:XX:XX +O fc00:3:3:3::/64 [110/10] is directly connected, r3-stubnet, weight 1, XX:XX:XX +O>* fc00:4:4:4::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r3-sw6, weight 1, XX:XX:XX +O fc00:a:a:a::/64 [110/10] is directly connected, r3-sw5, weight 1, XX:XX:XX +O>* fc00:a:a:a::1/128 [110/10] via fe80::XXXX:XXXX:XXXX:XXXX, r3-sw5, weight 1, XX:XX:XX +O>* fc00:a:a:a::2/128 [110/10] via fe80::XXXX:XXXX:XXXX:XXXX, r3-sw5, weight 1, XX:XX:XX +O fc00:b:b:b::/64 [110/10] is directly connected, r3-sw6, weight 1, XX:XX:XX +O>* fc00:b:b:b::4/128 [110/10] via fe80::XXXX:XXXX:XXXX:XXXX, r3-sw6, weight 1, XX:XX:XX +O>* fc00:1111:1111:1111::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r3-sw5, weight 1, XX:XX:XX +O>* fc00:2222:2222:2222::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r3-sw5, weight 1, XX:XX:XX +O>* fc00:4444:4444:4444::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r3-sw6, weight 1, XX:XX:XX diff --git a/tests/topotests/ospf6_point_to_multipoint/r3/zebra.conf b/tests/topotests/ospf6_point_to_multipoint/r3/zebra.conf new file mode 100644 index 0000000000..3cc5626bd7 --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/r3/zebra.conf @@ -0,0 +1,23 @@ +! +hostname r3 +log file zebra.log +! +! debug zebra events +! debug zebra rib +! +interface r3-stubnet + ipv6 address fc00:3:3:3::3/64 +! +interface r3-sw5 + ipv6 address fc00:a:a:a::3/64 +! +interface r3-sw6 + ipv6 address fc00:b:b:b::3/64 +! +interface lo +! +ipv6 route fc00:3333:3333:3333::/64 fc00:3:3:3::1234 +! +! +line vty +! diff --git a/tests/topotests/ospf6_point_to_multipoint/r4/ip_6_address.nhg.ref b/tests/topotests/ospf6_point_to_multipoint/r4/ip_6_address.nhg.ref new file mode 100644 index 0000000000..ca1e2f0d78 --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/r4/ip_6_address.nhg.ref @@ -0,0 +1,14 @@ +fc00:1111:1111:1111::/64 nhid XXXX via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium +fc00:1:1:1::/64 nhid XXXX via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium +fc00:2222:2222:2222::/64 nhid XXXX via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium +fc00:2:2:2::/64 nhid XXXX via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium +fc00:3333:3333:3333::/64 nhid XXXX via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium +fc00:3:3:3::/64 nhid XXXX via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium +fc00:4444:4444:4444::/64 nhid XXXX via fc00:4:4:4::1234 dev r4-stubnet proto XXXX metric 20 pref medium +fc00:4:4:4::/64 dev r4-stubnet proto XXXX metric 256 pref medium +fc00:a:a:a::/64 nhid XXXX via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium +fc00:a:a:a::1 nhid XXXX via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium +fc00:a:a:a::2 nhid XXXX via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium +fc00:a:a:a::3 nhid XXXX via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium +fc00:b:b:b::/64 dev r4-sw6 proto XXXX metric 256 pref medium +fc00:b:b:b::3 nhid XXXX via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium diff --git a/tests/topotests/ospf6_point_to_multipoint/r4/ip_6_address.ref b/tests/topotests/ospf6_point_to_multipoint/r4/ip_6_address.ref new file mode 100644 index 0000000000..4f4e72fc27 --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/r4/ip_6_address.ref @@ -0,0 +1,14 @@ +fc00:1111:1111:1111::/64 via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium +fc00:1:1:1::/64 via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium +fc00:2222:2222:2222::/64 via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium +fc00:2:2:2::/64 via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium +fc00:3333:3333:3333::/64 via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium +fc00:3:3:3::/64 via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium +fc00:4444:4444:4444::/64 via fc00:4:4:4::1234 dev r4-stubnet proto XXXX metric 20 pref medium +fc00:4:4:4::/64 dev r4-stubnet proto XXXX metric 256 pref medium +fc00:a:a:a::/64 via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium +fc00:a:a:a::1 via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium +fc00:a:a:a::2 via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium +fc00:a:a:a::3 via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium +fc00:b:b:b::/64 dev r4-sw6 proto XXXX metric 256 pref medium +fc00:b:b:b::3 via fe80::__(r3-sw6)__ dev r4-sw6 proto XXXX metric 20 pref medium diff --git a/tests/topotests/ospf6_point_to_multipoint/r4/ospf6d.conf b/tests/topotests/ospf6_point_to_multipoint/r4/ospf6d.conf new file mode 100644 index 0000000000..25b8551dd7 --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/r4/ospf6d.conf @@ -0,0 +1,30 @@ +hostname r4 +log file ospf6d.log +! +! debug ospf6 message all +! debug ospf6 lsa unknown +! debug ospf6 zebra +! debug ospf6 interface +! debug ospf6 neighbor +! debug ospf6 route table +! debug ospf6 flooding +! +interface r4-sw6 + ipv6 ospf6 network point-to-multipoint + ipv6 ospf6 area 0.0.0.1 + ipv6 ospf6 hello-interval 2 + ipv6 ospf6 dead-interval 10 + ipv6 ospf6 p2p-p2mp connected-prefixes include +! +interface r4-stubnet + ipv6 ospf6 passive + ipv6 ospf6 area 0.0.0.1 +! +router ospf6 + ospf6 router-id 10.0.0.4 + log-adjacency-changes detail + redistribute static +! +line vty + exec-timeout 0 0 +! diff --git a/tests/topotests/ospf6_point_to_multipoint/r4/show_ipv6_route.ref b/tests/topotests/ospf6_point_to_multipoint/r4/show_ipv6_route.ref new file mode 100644 index 0000000000..f377ca3a88 --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/r4/show_ipv6_route.ref @@ -0,0 +1,13 @@ +O>* fc00:1:1:1::/64 [110/30] via fe80::XXXX:XXXX:XXXX:XXXX, r4-sw6, weight 1, XX:XX:XX +O>* fc00:2:2:2::/64 [110/30] via fe80::XXXX:XXXX:XXXX:XXXX, r4-sw6, weight 1, XX:XX:XX +O>* fc00:3:3:3::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r4-sw6, weight 1, XX:XX:XX +O fc00:4:4:4::/64 [110/10] is directly connected, r4-stubnet, weight 1, XX:XX:XX +O>* fc00:a:a:a::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r4-sw6, weight 1, XX:XX:XX +O>* fc00:a:a:a::1/128 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r4-sw6, weight 1, XX:XX:XX +O>* fc00:a:a:a::2/128 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r4-sw6, weight 1, XX:XX:XX +O>* fc00:a:a:a::3/128 [110/10] via fe80::XXXX:XXXX:XXXX:XXXX, r4-sw6, weight 1, XX:XX:XX +O fc00:b:b:b::/64 [110/10] is directly connected, r4-sw6, weight 1, XX:XX:XX +O>* fc00:b:b:b::3/128 [110/10] via fe80::XXXX:XXXX:XXXX:XXXX, r4-sw6, weight 1, XX:XX:XX +O>* fc00:1111:1111:1111::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r4-sw6, weight 1, XX:XX:XX +O>* fc00:2222:2222:2222::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r4-sw6, weight 1, XX:XX:XX +O>* fc00:3333:3333:3333::/64 [110/20] via fe80::XXXX:XXXX:XXXX:XXXX, r4-sw6, weight 1, XX:XX:XX diff --git a/tests/topotests/ospf6_point_to_multipoint/r4/zebra.conf b/tests/topotests/ospf6_point_to_multipoint/r4/zebra.conf new file mode 100644 index 0000000000..20e27cea46 --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/r4/zebra.conf @@ -0,0 +1,20 @@ +! +hostname r4 +log file zebra.log +! +! debug zebra events +! debug zebra rib +! +interface r4-stubnet + ipv6 address fc00:4:4:4::4/64 +! +interface r4-sw6 + ipv6 address fc00:b:b:b::4/64 +! +interface lo +! +ipv6 route fc00:4444:4444:4444::/64 fc00:4:4:4::1234 +! +! +line vty +! diff --git a/tests/topotests/ospf6_point_to_multipoint/test_ospf6_point_to_multipoint.py b/tests/topotests/ospf6_point_to_multipoint/test_ospf6_point_to_multipoint.py new file mode 100644 index 0000000000..142acf1eb4 --- /dev/null +++ b/tests/topotests/ospf6_point_to_multipoint/test_ospf6_point_to_multipoint.py @@ -0,0 +1,392 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# +# test_ospf6_point_to_multipoint.py +# Part of NetDEF Topology Tests +# +# Copyright (c) 2023 by +# Network Device Education Foundation, Inc. ("NetDEF") +# + +r""" +test_ospf6_point_to_multipoint.py: + + -----\ + SW1 - Stub Net 1 SW2 - Stub Net 2 \ + fc00:1:1:1::/64 fc00:2:2:2::/64 \ +\___________________/ \___________________/ | + | | | + | | | + | ::1 | ::2 | ++---------+---------+ +---------+---------+ | +| R1 | | R2 | | +| FRRouting | | FRRouting | | +| Rtr-ID: 10.0.0.1 | | Rtr-ID: 10.0.0.2 | | ++---------+---------+ +---------+---------+ | + | ::1 | ::2 \ + \______ ___________/ OSPFv3 + \ / Area 0.0.0.0 + \ / / + ~~~~~~~~~~~~~~~~~~ | + ~~ SW5 ~~ | + ~~ Switch ~~ | + ~~ fc00:A:A:A::/64 ~~ | + ~~~~~~~~~~~~~~~~~~ | + | /---- | + | ::3 | SW3 - Stub Net 3 | + +---------+---------+ /-+ fc00:3:3:3::/64 | + | R3 | / | / + | FRRouting +--/ \---- / + | Rtr-ID: 10.0.0.3 | ::3 ___________/ + +---------+---------+ \ + | ::3 \ + | \ + ~~~~~~~~~~~~~~~~~~ | + ~~ SW6 ~~ | + ~~ Switch ~~ | + ~~ fc00:B:B:B::/64 ~~ \ + ~~~~~~~~~~~~~~~~~~ OSPFv3 + | Area 0.0.0.1 + | ::4 / + +---------+---------+ /---- | + | R4 | | SW4 - Stub Net 4 | + | FRRouting +------+ fc00:4:4:4::/64 | + | Rtr-ID: 10.0.0.4 | ::4 | / + +-------------------+ \---- / + -----/ +""" + +import os +import re +import sys +import pytest + +from functools import partial + + +# Save the Current Working Directory to find configuration files later. +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +# Import topogen and topotest helpers +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger + + +pytestmark = [pytest.mark.ospfd] + + +def build_topo(tgen): + # Create 4 routers + for routern in range(1, 5): + tgen.add_router("r{}".format(routern)) + + # + # Wire up the switches and routers + # Note that we specify the link names so we match the config files + # + + # Create a empty network for router 1 + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"], nodeif="r1-stubnet") + + # Create a empty network for router 2 + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r2"], nodeif="r2-stubnet") + + # Create a empty network for router 3 + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r3"], nodeif="r3-stubnet") + + # Create a empty network for router 4 + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r4"], nodeif="r4-stubnet") + + # Interconnect routers 1, 2, and 3 + switch = tgen.add_switch("s5") + switch.add_link(tgen.gears["r1"], nodeif="r1-sw5") + switch.add_link(tgen.gears["r2"], nodeif="r2-sw5") + switch.add_link(tgen.gears["r3"], nodeif="r3-sw5") + + # Interconnect routers 3 and 4 + switch = tgen.add_switch("s6") + switch.add_link(tgen.gears["r3"], nodeif="r3-sw6") + switch.add_link(tgen.gears["r4"], nodeif="r4-sw6") + + +##################################################### +## +## Tests starting +## +##################################################### + + +def setup_module(mod): + "Sets up the pytest environment" + + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + + logger.info("** %s: Setup Topology" % mod.__name__) + logger.info("******************************************") + + # For debugging after starting net, but before starting FRR, + # uncomment the next line + # tgen.mininet_cli() + + router_list = tgen.routers() + for rname, router in router_list.items(): + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_OSPF6, os.path.join(CWD, "{}/ospf6d.conf".format(rname)) + ) + + # Initialize all routers. + tgen.start_router() + + # For debugging after starting FRR daemons, uncomment the next line + # tgen.mininet_cli() + + +def teardown_module(mod): + "Teardown the pytest environment" + tgen = get_topogen() + tgen.stop_topology() + + +def test_wait_protocol_convergence(): + "Wait for OSPFv3 to converge" + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + logger.info("waiting for protocols to converge") + + def expect_neighbor_full(router, neighbor): + "Wait until OSPFv3 convergence." + logger.info("waiting OSPFv3 router '{}'".format(router)) + test_func = partial( + topotest.router_json_cmp, + tgen.gears[router], + "show ipv6 ospf6 neighbor json", + {"neighbors": [{"neighborId": neighbor, "state": "Full"}]}, + ) + _, result = topotest.run_and_expect(test_func, None, count=130, wait=1) + assertmsg = '"{}" convergence failure'.format(router) + assert result is None, assertmsg + + expect_neighbor_full("r1", "10.0.0.2") + expect_neighbor_full("r1", "10.0.0.3") + + expect_neighbor_full("r2", "10.0.0.1") + expect_neighbor_full("r2", "10.0.0.3") + + expect_neighbor_full("r3", "10.0.0.1") + expect_neighbor_full("r3", "10.0.0.2") + expect_neighbor_full("r3", "10.0.0.4") + + expect_neighbor_full("r4", "10.0.0.3") + + +def compare_show_ipv6(rname, expected): + """ + Calls 'show ipv6 route' for router `rname` and compare the obtained + result with the expected output. + """ + tgen = get_topogen() + + # Use the vtysh output, with some masking to make comparison easy + current = topotest.ip6_route_zebra(tgen.gears[rname]) + + # Use just the 'O'spf lines of the output + linearr = [] + for line in current.splitlines(): + if re.match("^O", line): + linearr.append(line) + + current = "\n".join(linearr) + + return topotest.difflines( + topotest.normalize_text(current), + topotest.normalize_text(expected), + title1="Current output", + title2="Expected output", + ) + + +def test_ospfv3_routingTable(): + + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip("skipped because of router(s) failure") + + # For debugging, uncomment the next line + # tgen.mininet_cli() + + # Verify OSPFv3 Routing Table + for router, rnode in tgen.routers().items(): + logger.info('Waiting for router "%s" convergence', router) + + # Load expected results from the command + reffile = os.path.join(CWD, "{}/show_ipv6_route.ref".format(router)) + expected = open(reffile).read() + + # Run test function until we get an result. Wait at most 60 seconds. + test_func = partial(compare_show_ipv6, router, expected) + result, diff = topotest.run_and_expect(test_func, "", count=120, wait=0.5) + assert result, "OSPFv3 did not converge on {}:\n{}".format(router, diff) + + +def test_linux_ipv6_kernel_routingTable(): + + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip("skipped because of router(s) failure") + + # Verify Linux Kernel Routing Table + logger.info("Verifying Linux IPv6 Kernel Routing Table") + + failures = 0 + + # Get a list of all current link-local addresses first as they change for + # each run and we need to translate them + linklocals = [] + for i in range(1, 5): + linklocals += tgen.net["r{}".format(i)].get_ipv6_linklocal() + + # Now compare the routing tables (after substituting link-local addresses) + + for i in range(1, 5): + # Actual output from router + actual = tgen.gears["r{}".format(i)].run("ip -6 route").rstrip() + if "nhid" in actual: + refTableFile = os.path.join(CWD, "r{}/ip_6_address.nhg.ref".format(i)) + else: + refTableFile = os.path.join(CWD, "r{}/ip_6_address.ref".format(i)) + + if os.path.isfile(refTableFile): + expected = open(refTableFile).read().rstrip() + # Fix newlines (make them all the same) + expected = ("\n".join(expected.splitlines())).splitlines(1) + + # Mask out Link-Local mac addresses + for ll in linklocals: + actual = actual.replace(ll[1], "fe80::__(%s)__" % ll[0]) + # Mask out protocol name or number + actual = re.sub(r"[ ]+proto [0-9a-z]+ +", " proto XXXX ", actual) + actual = re.sub(r"[ ]+nhid [0-9]+ +", " nhid XXXX ", actual) + # Remove ff00::/8 routes (seen on some kernels - not from FRR) + actual = re.sub(r"ff00::/8.*", "", actual) + + # Strip empty lines + actual = actual.lstrip() + actual = actual.rstrip() + actual = re.sub(r" +", " ", actual) + + filtered_lines = [] + for line in sorted(actual.splitlines()): + if line.startswith("fe80::/64 ") or line.startswith( + "unreachable fe80::/64 " + ): + continue + filtered_lines.append(line) + actual = "\n".join(filtered_lines).splitlines(1) + + # Print Actual table + # logger.info("Router r%s table" % i) + # for line in actual: + # logger.info(line.rstrip()) + + # Generate Diff + diff = topotest.get_textdiff( + actual, + expected, + title1="actual OSPFv3 IPv6 routing table", + title2="expected OSPFv3 IPv6 routing table", + ) + + # Empty string if it matches, otherwise diff contains unified diff + if diff: + sys.stderr.write( + "r%s failed Linux IPv6 Kernel Routing Table Check:\n%s\n" + % (i, diff) + ) + failures += 1 + else: + logger.info("r%s ok" % i) + + assert failures == 0, ( + "Linux Kernel IPv6 Routing Table verification failed for router r%s:\n%s" + % (i, diff) + ) + else: + logger.error("r{} failed - no nhid ref file: {}".format(i, refTableFile)) + + assert False, ( + "Linux Kernel IPv6 Routing Table verification failed for router r%s\n" + % (i) + ) + + +def test_shutdown_check_stderr(): + + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip("skipped because of router(s) failure") + + if os.environ.get("TOPOTESTS_CHECK_STDERR") is None: + logger.info( + "SKIPPED final check on StdErr output: Disabled (TOPOTESTS_CHECK_STDERR undefined)\n" + ) + pytest.skip("Skipping test for Stderr output") + + net = tgen.net + + logger.info("\n\n** Verifying unexpected STDERR output from daemons") + logger.info("******************************************") + + for i in range(1, 5): + net["r%s" % i].stopRouter() + log = net["r%s" % i].getStdErr("ospf6d") + if log: + logger.info("\nRouter r%s OSPF6d StdErr Log:\n%s" % (i, log)) + log = net["r%s" % i].getStdErr("zebra") + if log: + logger.info("\nRouter r%s Zebra StdErr Log:\n%s" % (i, log)) + + +def test_shutdown_check_memleak(): + "Run the memory leak test and report results." + + if os.environ.get("TOPOTESTS_CHECK_MEMLEAK") is None: + logger.info( + "SKIPPED final check on Memory leaks: Disabled (TOPOTESTS_CHECK_MEMLEAK undefined)" + ) + pytest.skip("Skipping test for memory leaks") + + tgen = get_topogen() + + net = tgen.net + + for i in range(1, 5): + net["r%s" % i].stopRouter() + net["r%s" % i].report_memory_leaks( + os.environ.get("TOPOTESTS_CHECK_MEMLEAK"), os.path.basename(__file__) + ) + + +if __name__ == "__main__": + + # To suppress tracebacks, either use the following pytest call or + # add "--tb=no" to cli + # retval = pytest.main(["-s", "--tb=no"]) + + retval = pytest.main(["-s"]) + sys.exit(retval) diff --git a/tests/topotests/ospf6_topo1/r1/ospf6d.conf b/tests/topotests/ospf6_topo1/r1/ospf6d.conf index 5f1ceee964..d2693ec07d 100644 --- a/tests/topotests/ospf6_topo1/r1/ospf6d.conf +++ b/tests/topotests/ospf6_topo1/r1/ospf6d.conf @@ -10,11 +10,13 @@ log file ospf6d.log ! debug ospf6 flooding ! interface r1-stubnet + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 network broadcast ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 10 ! interface r1-sw5 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 network broadcast ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 10 @@ -23,8 +25,6 @@ router ospf6 ospf6 router-id 10.0.0.1 log-adjacency-changes detail redistribute static - interface r1-stubnet area 0.0.0.0 - interface r1-sw5 area 0.0.0.0 ! line vty exec-timeout 0 0 diff --git a/tests/topotests/ospf6_topo1/r2/ospf6d.conf b/tests/topotests/ospf6_topo1/r2/ospf6d.conf index d51b41e1e5..c9e88f1545 100644 --- a/tests/topotests/ospf6_topo1/r2/ospf6d.conf +++ b/tests/topotests/ospf6_topo1/r2/ospf6d.conf @@ -10,11 +10,13 @@ log file ospf6d.log ! debug ospf6 flooding ! interface r2-stubnet + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 network broadcast ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 10 ! interface r2-sw5 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 network broadcast ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 10 @@ -23,8 +25,6 @@ router ospf6 ospf6 router-id 10.0.0.2 log-adjacency-changes detail redistribute static - interface r2-stubnet area 0.0.0.0 - interface r2-sw5 area 0.0.0.0 ! line vty exec-timeout 0 0 diff --git a/tests/topotests/ospf6_topo1/r3/ospf6d.conf b/tests/topotests/ospf6_topo1/r3/ospf6d.conf index cad71ac067..e1c3e44d0e 100644 --- a/tests/topotests/ospf6_topo1/r3/ospf6d.conf +++ b/tests/topotests/ospf6_topo1/r3/ospf6d.conf @@ -10,16 +10,19 @@ log file ospf6d.log ! debug ospf6 flooding ! interface r3-stubnet + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 network broadcast ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 10 ! interface r3-sw5 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 network broadcast ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 10 ! interface r3-sw6 + ipv6 ospf6 area 0.0.0.1 ipv6 ospf6 network broadcast ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 10 @@ -28,9 +31,6 @@ router ospf6 ospf6 router-id 10.0.0.3 log-adjacency-changes detail redistribute static - interface r3-stubnet area 0.0.0.0 - interface r3-sw5 area 0.0.0.0 - interface r3-sw6 area 0.0.0.1 ! line vty exec-timeout 0 0 diff --git a/tests/topotests/ospf6_topo1/r4/ospf6d.conf b/tests/topotests/ospf6_topo1/r4/ospf6d.conf index f0b166bc4b..230ec7aad4 100644 --- a/tests/topotests/ospf6_topo1/r4/ospf6d.conf +++ b/tests/topotests/ospf6_topo1/r4/ospf6d.conf @@ -10,11 +10,13 @@ log file ospf6d.log ! debug ospf6 flooding ! interface r4-stubnet + ipv6 ospf6 area 0.0.0.1 ipv6 ospf6 network broadcast ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 10 ! interface r4-sw6 + ipv6 ospf6 area 0.0.0.1 ipv6 ospf6 network broadcast ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 10 @@ -23,8 +25,6 @@ router ospf6 ospf6 router-id 10.0.0.4 log-adjacency-changes detail redistribute static - interface r4-stubnet area 0.0.0.1 - interface r4-sw6 area 0.0.0.1 ! line vty exec-timeout 0 0 diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_authentication.py b/tests/topotests/ospf_basic_functionality/test_ospf_authentication.py index 88219b8400..8dd103013b 100644 --- a/tests/topotests/ospf_basic_functionality/test_ospf_authentication.py +++ b/tests/topotests/ospf_basic_functionality/test_ospf_authentication.py @@ -64,7 +64,9 @@ TESTCASES = 1. Verify ospf authentication with Simple password authentication. 2. Verify ospf authentication with MD5 authentication. -3. Verify ospf authentication with different authentication methods. +3. Verify ospf authentication with MD5 keychain authentication. +4. Verify ospf authentication with SHA256 keychain authentication. +5. Verify ospf authentication with different authentication methods. """ @@ -535,7 +537,477 @@ def test_ospf_authentication_md5_tc29_p1(request): write_test_footer(tc_name) -def test_ospf_authentication_different_auths_tc30_p1(request): +def test_ospf_authentication_md5_keychain_tc30_p1(request): + """ + OSPF Authentication - Verify ospf authentication with MD5 authentication. + + """ + tc_name = request.node.name + write_test_header(tc_name) + tgen = get_topogen() + global topo + step("Bring up the base config.") + reset_config_on_routers(tgen) + step( + "Configure ospf with on R1 and R2, enable ospf on R1 interface " + "connected to R2 with message-digest authentication using ip " + "ospf authentication key-chain cmd." + ) + + router1 = tgen.gears["r1"] + router2 = tgen.gears["r2"] + + router1.vtysh_cmd( + """configure terminal + key chain auth + key 10 + key-string ospf + cryptographic-algorithm md5""" + ) + + r1_ospf_auth = { + "r1": { + "links": { + "r2": { + "ospf": { + "authentication": "key-chain", + "keychain": "auth", + } + } + } + } + } + result = config_ospf_interface(tgen, topo, r1_ospf_auth) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step("Verify that the neighbour is not FULL between R1 and R2.") + # wait for dead time expiry. + sleep(6) + dut = "r1" + ospf_covergence = verify_ospf_neighbor( + tgen, topo, dut=dut, expected=False, retry_timeout=6 + ) + assert ospf_covergence is not True, "Testcase Failed \n Error {}".format( + ospf_covergence + ) + + step( + "On R2 enable ospf on interface with message-digest authentication" + " using ip ospf authentication message-digest password cmd." + ) + + router2.vtysh_cmd( + """configure terminal + key chain auth + key 10 + key-string ospf + cryptographic-algorithm md5""" + ) + + r2_ospf_auth = { + "r2": { + "links": { + "r1": { + "ospf": { + "authentication": "key-chain", + "keychain": "auth", + } + } + } + } + } + result = config_ospf_interface(tgen, topo, r2_ospf_auth) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step( + "Verify that the neighbour is FULL between R1 and R2 " + "using show ip ospf neighbor cmd." + ) + + dut = "r2" + ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) + assert ospf_covergence is True, "Testcase Failed \n Error {}".format( + ospf_covergence + ) + + step( + "Disable message-digest authentication on R2 using no ip ospf " + "authentication key-chain cmd." + ) + + r2_ospf_auth = { + "r2": { + "links": { + "r1": { + "ospf": { + "authentication": "key-chain", + "keychain": "auth", + "del_action": True, + } + } + } + } + } + result = config_ospf_interface(tgen, topo, r2_ospf_auth) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step("Verify on R1 ,nbr is deleted for R2 after dead interval expiry") + # wait till the dead timer expiry + sleep(6) + dut = "r2" + ospf_covergence = verify_ospf_neighbor( + tgen, topo, dut=dut, expected=False, retry_timeout=10 + ) + assert ospf_covergence is not True, "Testcase Failed \n Error {}".format( + ospf_covergence + ) + + step("Again On R2 enable ospf on interface with key-chain auth") + r2_ospf_auth = { + "r2": { + "links": { + "r1": { + "ospf": { + "authentication": "key-chain", + "keychain": "auth", + } + } + } + } + } + result = config_ospf_interface(tgen, topo, r2_ospf_auth) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step( + "Verify that the neighbour is FULL between R1 and R2 using" + " show ip ospf neighbor cmd." + ) + + dut = "r2" + ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) + assert ospf_covergence is True, "Testcase Failed \n Error {}".format( + ospf_covergence + ) + + step("Shut no shut interface on R1") + dut = "r1" + intf = topo["routers"]["r1"]["links"]["r2"]["interface"] + shutdown_bringup_interface(tgen, dut, intf, False) + + dut = "r2" + step( + "Verify that the neighbour is not FULL between R1 and R2 using " + "show ip ospf neighbor cmd." + ) + ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, expected=False) + assert ospf_covergence is not True, "Testcase Failed \n Error {}".format( + ospf_covergence + ) + + dut = "r1" + shutdown_bringup_interface(tgen, dut, intf, True) + + step( + "Verify that the neighbour is FULL between R1 and R2 using " + "show ip ospf neighbor cmd." + ) + + dut = "r2" + ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) + assert ospf_covergence is True, "Testcase Failed \n Error {}".format( + ospf_covergence + ) + + step("Change Ip address on R1 and R2") + + topo_modify_change_ip = deepcopy(topo) + + intf_ip = topo_modify_change_ip["routers"]["r1"]["links"]["r2"]["ipv4"] + + topo_modify_change_ip["routers"]["r1"]["links"]["r2"]["ipv4"] = str( + IPv4Address(frr_unicode(intf_ip.split("/")[0])) + 3 + ) + "/{}".format(intf_ip.split("/")[1]) + + build_config_from_json(tgen, topo_modify_change_ip, save_bkup=False) + + reset_config_on_routers(tgen, routerName="r1") + dut = "r1" + intf = topo["routers"]["r1"]["links"]["r2"]["interface"] + shutdown_bringup_interface(tgen, dut, intf, False) + shutdown_bringup_interface(tgen, dut, intf, True) + clear_ospf(tgen, "r1") + router1.vtysh_cmd( + """configure terminal + key chain auth + key 10 + key-string ospf + cryptographic-algorithm md5""" + ) + r1_ospf_auth = { + "r1": { + "links": { + "r2": { + "ospf": { + "authentication": "key-chain", + "keychain": "auth", + } + } + } + } + } + result = config_ospf_interface(tgen, topo, r1_ospf_auth) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step( + "Verify that the neighbour is FULL between R1 and R2 with new " + "ip address using show ip ospf " + ) + + dut = "r1" + ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) + assert ospf_covergence is True, "Testcase Failed \n Error {}".format( + ospf_covergence + ) + + write_test_footer(tc_name) + + +def test_ospf_authentication_sha256_keychain_tc32_p1(request): + """ + OSPF Authentication - Verify ospf authentication with MD5 authentication. + + """ + tc_name = request.node.name + write_test_header(tc_name) + tgen = get_topogen() + global topo + step("Bring up the base config.") + reset_config_on_routers(tgen) + step( + "Configure ospf with on R1 and R2, enable ospf on R1 interface " + "connected to R2 with message-digest authentication using ip " + "ospf authentication key-chain cmd." + ) + + router1 = tgen.gears["r1"] + router2 = tgen.gears["r2"] + + router1.vtysh_cmd( + """configure terminal + key chain auth + key 10 + key-string ospf + cryptographic-algorithm hmac-sha-256""" + ) + + r1_ospf_auth = { + "r1": { + "links": { + "r2": { + "ospf": { + "authentication": "key-chain", + "keychain": "auth", + } + } + } + } + } + result = config_ospf_interface(tgen, topo, r1_ospf_auth) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step("Verify that the neighbour is not FULL between R1 and R2.") + # wait for dead time expiry. + sleep(6) + dut = "r1" + ospf_covergence = verify_ospf_neighbor( + tgen, topo, dut=dut, expected=False, retry_timeout=6 + ) + assert ospf_covergence is not True, "Testcase Failed \n Error {}".format( + ospf_covergence + ) + + step( + "On R2 enable ospf on interface with message-digest authentication" + " using ip ospf authentication message-digest password cmd." + ) + + router2.vtysh_cmd( + """configure terminal + key chain auth + key 10 + key-string ospf + cryptographic-algorithm hmac-sha-256""" + ) + + r2_ospf_auth = { + "r2": { + "links": { + "r1": { + "ospf": { + "authentication": "key-chain", + "keychain": "auth", + } + } + } + } + } + result = config_ospf_interface(tgen, topo, r2_ospf_auth) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step( + "Verify that the neighbour is FULL between R1 and R2 " + "using show ip ospf neighbor cmd." + ) + + dut = "r2" + ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) + assert ospf_covergence is True, "Testcase Failed \n Error {}".format( + ospf_covergence + ) + + step( + "Disable message-digest authentication on R2 using no ip ospf " + "authentication key-chain cmd." + ) + + r2_ospf_auth = { + "r2": { + "links": { + "r1": { + "ospf": { + "authentication": "key-chain", + "keychain": "auth", + "del_action": True, + } + } + } + } + } + result = config_ospf_interface(tgen, topo, r2_ospf_auth) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step("Verify on R1 ,nbr is deleted for R2 after dead interval expiry") + # wait till the dead timer expiry + sleep(6) + dut = "r2" + ospf_covergence = verify_ospf_neighbor( + tgen, topo, dut=dut, expected=False, retry_timeout=10 + ) + assert ospf_covergence is not True, "Testcase Failed \n Error {}".format( + ospf_covergence + ) + + step("Again On R2 enable ospf on interface with key-chain auth") + r2_ospf_auth = { + "r2": { + "links": { + "r1": { + "ospf": { + "authentication": "key-chain", + "keychain": "auth", + } + } + } + } + } + result = config_ospf_interface(tgen, topo, r2_ospf_auth) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step( + "Verify that the neighbour is FULL between R1 and R2 using" + " show ip ospf neighbor cmd." + ) + + dut = "r2" + ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) + assert ospf_covergence is True, "Testcase Failed \n Error {}".format( + ospf_covergence + ) + + step("Shut no shut interface on R1") + dut = "r1" + intf = topo["routers"]["r1"]["links"]["r2"]["interface"] + shutdown_bringup_interface(tgen, dut, intf, False) + + dut = "r2" + step( + "Verify that the neighbour is not FULL between R1 and R2 using " + "show ip ospf neighbor cmd." + ) + ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, expected=False) + assert ospf_covergence is not True, "Testcase Failed \n Error {}".format( + ospf_covergence + ) + + dut = "r1" + shutdown_bringup_interface(tgen, dut, intf, True) + + step( + "Verify that the neighbour is FULL between R1 and R2 using " + "show ip ospf neighbor cmd." + ) + + dut = "r2" + ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) + assert ospf_covergence is True, "Testcase Failed \n Error {}".format( + ospf_covergence + ) + + step("Change Ip address on R1 and R2") + + topo_modify_change_ip = deepcopy(topo) + + intf_ip = topo_modify_change_ip["routers"]["r1"]["links"]["r2"]["ipv4"] + + topo_modify_change_ip["routers"]["r1"]["links"]["r2"]["ipv4"] = str( + IPv4Address(frr_unicode(intf_ip.split("/")[0])) + 3 + ) + "/{}".format(intf_ip.split("/")[1]) + + build_config_from_json(tgen, topo_modify_change_ip, save_bkup=False) + + reset_config_on_routers(tgen, routerName="r1") + dut = "r1" + intf = topo["routers"]["r1"]["links"]["r2"]["interface"] + shutdown_bringup_interface(tgen, dut, intf, False) + shutdown_bringup_interface(tgen, dut, intf, True) + clear_ospf(tgen, "r1") + router1.vtysh_cmd( + """configure terminal + key chain auth + key 10 + key-string ospf + cryptographic-algorithm hmac-sha-256""" + ) + r1_ospf_auth = { + "r1": { + "links": { + "r2": { + "ospf": { + "authentication": "key-chain", + "keychain": "auth", + } + } + } + } + } + result = config_ospf_interface(tgen, topo, r1_ospf_auth) + assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + + step( + "Verify that the neighbour is FULL between R1 and R2 with new " + "ip address using show ip ospf " + ) + + dut = "r1" + ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) + assert ospf_covergence is True, "Testcase Failed \n Error {}".format( + ospf_covergence + ) + + write_test_footer(tc_name) + + +def test_ospf_authentication_different_auths_tc35_p1(request): """ OSPF Authentication - Verify ospf authentication with different authentication methods. @@ -553,6 +1025,9 @@ def test_ospf_authentication_different_auths_tc30_p1(request): "ospf authentication message-digest cmd." ) + router1 = tgen.gears["r1"] + router2 = tgen.gears["r2"] + r1_ospf_auth = { "r1": { "links": { @@ -769,16 +1244,23 @@ def test_ospf_authentication_different_auths_tc30_p1(request): ospf_covergence ) - step("Enable Md5 authentication on the interface") + step("Enable SHA-256 authentication on the interface") + + router1.vtysh_cmd( + """configure terminal + key chain auth + key 10 + key-string ospf + cryptographic-algorithm hmac-sha-256""" + ) r1_ospf_auth = { "r1": { "links": { "r2": { "ospf": { - "authentication": "message-digest", - "authentication-key": "ospf", - "message-digest-key": "10", + "authentication": "key-chain", + "keychain": "auth", } } } @@ -787,14 +1269,21 @@ def test_ospf_authentication_different_auths_tc30_p1(request): result = config_ospf_interface(tgen, topo, r1_ospf_auth) assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + router2.vtysh_cmd( + """configure terminal + key chain auth + key 10 + key-string ospf + cryptographic-algorithm hmac-sha-256""" + ) + r2_ospf_auth = { "r2": { "links": { "r1": { "ospf": { - "authentication": "message-digest", - "authentication-key": "ospf", - "message-digest-key": "10", + "authentication": "key-chain", + "keychain": "auth", } } } @@ -814,39 +1303,27 @@ def test_ospf_authentication_different_auths_tc30_p1(request): ospf_covergence ) - step("Change the MD5 authentication password") + step("Change the SHA-256 authentication password") - r1_ospf_auth = { - "r1": { - "links": { - "r2": { - "ospf": { - "authentication": "message-digest", - "authentication-key": "OSPFv4", - "message-digest-key": "10", - } - } - } - } - } - result = config_ospf_interface(tgen, topo, r1_ospf_auth) - assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + router1.vtysh_cmd( + """configure terminal + key chain auth + key 10 + key-string OSPFv4 + cryptographic-algorithm hmac-sha-512""" + ) - r2_ospf_auth = { - "r2": { - "links": { - "r1": { - "ospf": { - "authentication": "message-digest", - "authentication-key": "OSPFv4", - "message-digest-key": "10", - } - } - } - } - } - result = config_ospf_interface(tgen, topo, r2_ospf_auth) - assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) + router2.vtysh_cmd( + """configure terminal + key chain auth + key 10 + key-string OSPFv4 + cryptographic-algorithm hmac-sha-512""" + ) + ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut) + assert ospf_covergence is True, "Testcase Failed \n Error {}".format( + ospf_covergence + ) write_test_footer(tc_name) diff --git a/tests/topotests/ospf_instance_redistribute/r1/sharp_installed.json b/tests/topotests/ospf_instance_redistribute/r1/sharp_installed.json index c0a1f6ac00..ebb3848248 100644 --- a/tests/topotests/ospf_instance_redistribute/r1/sharp_installed.json +++ b/tests/topotests/ospf_instance_redistribute/r1/sharp_installed.json @@ -8,6 +8,6 @@ "type":"sharp" } ], - "routesTotal":4, - "routesTotalFib":4 + "routesTotal":5, + "routesTotalFib":5 } diff --git a/tests/topotests/ospf_multi_vrf_bgp_route_leak/r1/frr.conf b/tests/topotests/ospf_multi_vrf_bgp_route_leak/r1/frr.conf index e365e25772..995958132c 100644 --- a/tests/topotests/ospf_multi_vrf_bgp_route_leak/r1/frr.conf +++ b/tests/topotests/ospf_multi_vrf_bgp_route_leak/r1/frr.conf @@ -5,12 +5,18 @@ log file /tmp/r1-frr.log ! interface r1-eth0 ip address 10.0.1.1/24 + ip ospf hello-interval 1 + ip ospf dead-interval 4 ! interface r1-eth1 ip address 10.0.20.1/24 + ip ospf hello-interval 1 + ip ospf dead-interval 4 ! interface r1-eth2 vrf neno ip address 10.0.30.1/24 + ip ospf hello-interval 1 + ip ospf dead-interval 4 ! ip forwarding ! diff --git a/tests/topotests/ospf_multi_vrf_bgp_route_leak/r1/zebra-vrf-default.txt b/tests/topotests/ospf_multi_vrf_bgp_route_leak/r1/zebra-vrf-default.txt index 86c089ab3b..ca9ca77bf5 100644 --- a/tests/topotests/ospf_multi_vrf_bgp_route_leak/r1/zebra-vrf-default.txt +++ b/tests/topotests/ospf_multi_vrf_bgp_route_leak/r1/zebra-vrf-default.txt @@ -1,9 +1,11 @@ O 10.0.1.0/24 [110/10] is directly connected, r1-eth0, weight 1, XX:XX:XX C>* 10.0.1.0/24 is directly connected, r1-eth0, XX:XX:XX +L>* 10.0.1.1/32 is directly connected, r1-eth0, XX:XX:XX O>* 10.0.2.0/24 [110/20] via 10.0.20.2, r1-eth1, weight 1, XX:XX:XX B>* 10.0.3.0/24 [20/20] via 10.0.30.3, r1-eth2 (vrf neno), weight 1, XX:XX:XX O>* 10.0.4.0/24 [110/20] via 10.0.20.2, r1-eth1, weight 1, XX:XX:XX O 10.0.20.0/24 [110/10] is directly connected, r1-eth1, weight 1, XX:XX:XX C>* 10.0.20.0/24 is directly connected, r1-eth1, XX:XX:XX +L>* 10.0.20.1/32 is directly connected, r1-eth1, XX:XX:XX B>* 10.0.30.0/24 [20/0] is directly connected, r1-eth2 (vrf neno), weight 1, XX:XX:XX O>* 10.0.40.0/24 [110/20] via 10.0.20.2, r1-eth1, weight 1, XX:XX:XX diff --git a/tests/topotests/ospf_multi_vrf_bgp_route_leak/r1/zebra-vrf-neno.txt b/tests/topotests/ospf_multi_vrf_bgp_route_leak/r1/zebra-vrf-neno.txt index 4e818eb6f1..6e1335243b 100644 --- a/tests/topotests/ospf_multi_vrf_bgp_route_leak/r1/zebra-vrf-neno.txt +++ b/tests/topotests/ospf_multi_vrf_bgp_route_leak/r1/zebra-vrf-neno.txt @@ -3,4 +3,5 @@ O>* 10.0.3.0/24 [110/20] via 10.0.30.3, r1-eth2, weight 1, XX:XX:XX B>* 10.0.4.0/24 [20/20] via 10.0.20.2, r1-eth1 (vrf default), weight 1, XX:XX:XX O 10.0.30.0/24 [110/10] is directly connected, r1-eth2, weight 1, XX:XX:XX C>* 10.0.30.0/24 is directly connected, r1-eth2, XX:XX:XX +L>* 10.0.30.1/32 is directly connected, r1-eth2, XX:XX:XX B>* 10.0.40.0/24 [20/20] via 10.0.20.2, r1-eth1 (vrf default), weight 1, XX:XX:XX diff --git a/tests/topotests/ospf_multi_vrf_bgp_route_leak/r2/frr.conf b/tests/topotests/ospf_multi_vrf_bgp_route_leak/r2/frr.conf index e87899ca77..29909de646 100644 --- a/tests/topotests/ospf_multi_vrf_bgp_route_leak/r2/frr.conf +++ b/tests/topotests/ospf_multi_vrf_bgp_route_leak/r2/frr.conf @@ -5,14 +5,20 @@ log file /tmp/r2-frr.log ! interface r2-eth0 ip address 10.0.2.2/24 + ip ospf hello-interval 1 + ip ospf dead-interval 4 ! interface r2-eth1 ip address 10.0.20.2/24 + ip ospf hello-interval 1 + ip ospf dead-interval 4 ! ip route 0.0.0.0/0 10.0.20.1 ! interface r2-eth2 vrf ray ip address 10.0.40.2/24 + ip ospf hello-interval 1 + ip ospf dead-interval 4 ! ip forwarding ! diff --git a/tests/topotests/ospf_multi_vrf_bgp_route_leak/r2/zebra-vrf-default.txt b/tests/topotests/ospf_multi_vrf_bgp_route_leak/r2/zebra-vrf-default.txt index 9681d8a04e..70ae987894 100644 --- a/tests/topotests/ospf_multi_vrf_bgp_route_leak/r2/zebra-vrf-default.txt +++ b/tests/topotests/ospf_multi_vrf_bgp_route_leak/r2/zebra-vrf-default.txt @@ -2,9 +2,11 @@ S>* 0.0.0.0/0 [1/0] via 10.0.20.1, r2-eth1, weight 1, XX:XX:XX O>* 10.0.1.0/24 [110/20] via 10.0.20.1, r2-eth1, weight 1, XX:XX:XX O 10.0.2.0/24 [110/10] is directly connected, r2-eth0, weight 1, XX:XX:XX C>* 10.0.2.0/24 is directly connected, r2-eth0, XX:XX:XX +L>* 10.0.2.2/32 is directly connected, r2-eth0, XX:XX:XX O>* 10.0.3.0/24 [110/20] via 10.0.20.1, r2-eth1, weight 1, XX:XX:XX B>* 10.0.4.0/24 [20/20] via 10.0.40.4, r2-eth2 (vrf ray), weight 1, XX:XX:XX O 10.0.20.0/24 [110/10] is directly connected, r2-eth1, weight 1, XX:XX:XX C>* 10.0.20.0/24 is directly connected, r2-eth1, XX:XX:XX +L>* 10.0.20.2/32 is directly connected, r2-eth1, XX:XX:XX O>* 10.0.30.0/24 [110/20] via 10.0.20.1, r2-eth1, weight 1, XX:XX:XX B>* 10.0.40.0/24 [20/0] is directly connected, r2-eth2 (vrf ray), weight 1, XX:XX:XX diff --git a/tests/topotests/ospf_multi_vrf_bgp_route_leak/r2/zebra-vrf-ray.txt b/tests/topotests/ospf_multi_vrf_bgp_route_leak/r2/zebra-vrf-ray.txt index ce9903ae71..1495c88936 100644 --- a/tests/topotests/ospf_multi_vrf_bgp_route_leak/r2/zebra-vrf-ray.txt +++ b/tests/topotests/ospf_multi_vrf_bgp_route_leak/r2/zebra-vrf-ray.txt @@ -7,3 +7,4 @@ B 10.0.20.0/24 [20/0] is directly connected, r2-eth1 (vrf default) inactive, w B>* 10.0.30.0/24 [20/20] via 10.0.20.1, r2-eth1 (vrf default), weight 1, XX:XX:XX O 10.0.40.0/24 [110/10] is directly connected, r2-eth2, weight 1, XX:XX:XX C>* 10.0.40.0/24 is directly connected, r2-eth2, XX:XX:XX +L>* 10.0.40.2/32 is directly connected, r2-eth2, XX:XX:XX diff --git a/tests/topotests/ospf_multi_vrf_bgp_route_leak/r3/frr.conf b/tests/topotests/ospf_multi_vrf_bgp_route_leak/r3/frr.conf index 2657f589d8..35fe22e9f9 100644 --- a/tests/topotests/ospf_multi_vrf_bgp_route_leak/r3/frr.conf +++ b/tests/topotests/ospf_multi_vrf_bgp_route_leak/r3/frr.conf @@ -5,9 +5,13 @@ log file /tmp/r3-frr.log ! interface r3-eth0 ip address 10.0.3.3/24 + ip ospf hello-interval 1 + ip ospf dead-interval 4 ! interface r3-eth1 ip address 10.0.30.3/24 + ip ospf hello-interval 1 + ip ospf dead-interval 4 ! ip forwarding ! diff --git a/tests/topotests/ospf_multi_vrf_bgp_route_leak/r3/zebra-vrf-default.txt b/tests/topotests/ospf_multi_vrf_bgp_route_leak/r3/zebra-vrf-default.txt index f6f861b73b..b1701fe177 100644 --- a/tests/topotests/ospf_multi_vrf_bgp_route_leak/r3/zebra-vrf-default.txt +++ b/tests/topotests/ospf_multi_vrf_bgp_route_leak/r3/zebra-vrf-default.txt @@ -1,8 +1,10 @@ O 10.0.3.0/24 [110/10] is directly connected, r3-eth0, weight 1, XX:XX:XX C>* 10.0.3.0/24 is directly connected, r3-eth0, XX:XX:XX +L>* 10.0.3.3/32 is directly connected, r3-eth0, XX:XX:XX O>* 10.0.4.0/24 [110/20] via 10.0.30.1, r3-eth1, weight 1, XX:XX:XX O 10.0.30.0/24 [110/10] is directly connected, r3-eth1, weight 1, XX:XX:XX C>* 10.0.30.0/24 is directly connected, r3-eth1, XX:XX:XX +L>* 10.0.30.3/32 is directly connected, r3-eth1, XX:XX:XX O>* 10.0.40.0/24 [110/20] via 10.0.30.1, r3-eth1, weight 1, XX:XX:XX diff --git a/tests/topotests/ospf_multi_vrf_bgp_route_leak/r4/frr.conf b/tests/topotests/ospf_multi_vrf_bgp_route_leak/r4/frr.conf index 79d8077062..721c3d91c3 100644 --- a/tests/topotests/ospf_multi_vrf_bgp_route_leak/r4/frr.conf +++ b/tests/topotests/ospf_multi_vrf_bgp_route_leak/r4/frr.conf @@ -5,9 +5,13 @@ log file /tmp/r4-frr.log ! interface r4-eth0 ip address 10.0.4.4/24 + ip ospf hello-interval 1 + ip ospf dead-interval 4 ! interface r4-eth1 ip address 10.0.40.4/24 + ip ospf hello-interval 1 + ip ospf dead-interval 4 ! ip forwarding ! diff --git a/tests/topotests/ospf_multi_vrf_bgp_route_leak/r4/zebra-vrf-default.txt b/tests/topotests/ospf_multi_vrf_bgp_route_leak/r4/zebra-vrf-default.txt index b6be5e7fdb..3723a8a8cb 100644 --- a/tests/topotests/ospf_multi_vrf_bgp_route_leak/r4/zebra-vrf-default.txt +++ b/tests/topotests/ospf_multi_vrf_bgp_route_leak/r4/zebra-vrf-default.txt @@ -1,7 +1,9 @@ O>* 10.0.3.0/24 [110/20] via 10.0.40.2, r4-eth1, weight 1, XX:XX:XX O 10.0.4.0/24 [110/10] is directly connected, r4-eth0, weight 1, XX:XX:XX C>* 10.0.4.0/24 is directly connected, r4-eth0, XX:XX:XX +L>* 10.0.4.4/32 is directly connected, r4-eth0, XX:XX:XX O>* 10.0.30.0/24 [110/20] via 10.0.40.2, r4-eth1, weight 1, XX:XX:XX O 10.0.40.0/24 [110/10] is directly connected, r4-eth1, weight 1, XX:XX:XX C>* 10.0.40.0/24 is directly connected, r4-eth1, XX:XX:XX +L>* 10.0.40.4/32 is directly connected, r4-eth1, XX:XX:XX diff --git a/tests/topotests/ospf_netns_vrf/r1/ospfd.conf b/tests/topotests/ospf_netns_vrf/r1/ospfd.conf index e1e2bfb99a..ba13146561 100644 --- a/tests/topotests/ospf_netns_vrf/r1/ospfd.conf +++ b/tests/topotests/ospf_netns_vrf/r1/ospfd.conf @@ -3,6 +3,14 @@ hostname r1 password zebra log file /tmp/r1-ospfd.log ! +interface r1-eth0 vrf r1-ospf-cust1 + ip ospf hello-interval 1 + ip ospf dead-interval 4 +! +interface r1-eth1 vrf r1-ospf-cust1 + ip ospf hello-interval 1 + ip ospf dead-interval 4 +! router ospf vrf r1-ospf-cust1 ospf router-id 10.0.255.1 redistribute kernel diff --git a/tests/topotests/ospf_netns_vrf/r1/zebraroute.txt b/tests/topotests/ospf_netns_vrf/r1/zebraroute.txt index 979af20c59..bf874ac762 100644 --- a/tests/topotests/ospf_netns_vrf/r1/zebraroute.txt +++ b/tests/topotests/ospf_netns_vrf/r1/zebraroute.txt @@ -1,8 +1,10 @@ VRF r1-ospf-cust1: O 10.0.1.0/24 [110/10] is directly connected, r1-eth0, weight 1, XX:XX:XX C>* 10.0.1.0/24 is directly connected, r1-eth0, XX:XX:XX +L>* 10.0.1.1/32 is directly connected, r1-eth0, XX:XX:XX O>* 10.0.2.0/24 [110/20] via 10.0.3.3, r1-eth1, weight 1, XX:XX:XX O 10.0.3.0/24 [110/10] is directly connected, r1-eth1, weight 1, XX:XX:XX C>* 10.0.3.0/24 is directly connected, r1-eth1, XX:XX:XX +L>* 10.0.3.2/32 is directly connected, r1-eth1, XX:XX:XX O>* 10.0.10.0/24 [110/20] via 10.0.3.1, r1-eth1, weight 1, XX:XX:XX diff --git a/tests/topotests/ospf_netns_vrf/r1/zebraroutedown.txt b/tests/topotests/ospf_netns_vrf/r1/zebraroutedown.txt index ec99fad762..e515205307 100644 --- a/tests/topotests/ospf_netns_vrf/r1/zebraroutedown.txt +++ b/tests/topotests/ospf_netns_vrf/r1/zebraroutedown.txt @@ -1,7 +1,9 @@ VRF r1-ospf-cust1: O 10.0.1.0/24 [110/10] is directly connected, r1-eth0, weight 1, XX:XX:XX C>* 10.0.1.0/24 is directly connected, r1-eth0, XX:XX:XX +L>* 10.0.1.1/32 is directly connected, r1-eth0, XX:XX:XX O>* 10.0.2.0/24 [110/20] via 10.0.3.3, r1-eth1, weight 1, XX:XX:XX O 10.0.3.0/24 [110/10] is directly connected, r1-eth1, weight 1, XX:XX:XX C>* 10.0.3.0/24 is directly connected, r1-eth1, XX:XX:XX +L>* 10.0.3.2/32 is directly connected, r1-eth1, XX:XX:XX diff --git a/tests/topotests/ospf_netns_vrf/r2/ospfd.conf b/tests/topotests/ospf_netns_vrf/r2/ospfd.conf index c1984276f4..01b6b1526b 100644 --- a/tests/topotests/ospf_netns_vrf/r2/ospfd.conf +++ b/tests/topotests/ospf_netns_vrf/r2/ospfd.conf @@ -3,6 +3,13 @@ hostname r2 password zebra log file /tmp/r2-ospfd.log ! +interface r2-eth0 vrf r2-ospf-cust1 + ip ospf hello-interval 1 + ip ospf dead-interval 4 +! +interface r2-eth1 vrf r2-ospf-cust1 + ip ospf hello-interval 1 + ip ospf dead-interval 4 ! router ospf vrf r2-ospf-cust1 ospf router-id 10.0.255.2 diff --git a/tests/topotests/ospf_netns_vrf/r2/zebraroute.txt b/tests/topotests/ospf_netns_vrf/r2/zebraroute.txt index df66e92abc..3763ef8006 100644 --- a/tests/topotests/ospf_netns_vrf/r2/zebraroute.txt +++ b/tests/topotests/ospf_netns_vrf/r2/zebraroute.txt @@ -2,7 +2,9 @@ VRF r2-ospf-cust1: O>* 10.0.1.0/24 [110/20] via 10.0.3.2, r2-eth1, weight 1, XX:XX:XX O 10.0.2.0/24 [110/10] is directly connected, r2-eth0, weight 1, XX:XX:XX C>* 10.0.2.0/24 is directly connected, r2-eth0, XX:XX:XX +L>* 10.0.2.1/32 is directly connected, r2-eth0, XX:XX:XX O 10.0.3.0/24 [110/10] is directly connected, r2-eth1, weight 1, XX:XX:XX C>* 10.0.3.0/24 is directly connected, r2-eth1, XX:XX:XX +L>* 10.0.3.3/32 is directly connected, r2-eth1, XX:XX:XX O>* 10.0.10.0/24 [110/20] via 10.0.3.1, r2-eth1, weight 1, XX:XX:XX diff --git a/tests/topotests/ospf_netns_vrf/r2/zebraroutedown.txt b/tests/topotests/ospf_netns_vrf/r2/zebraroutedown.txt index 4afc354ca7..f6eaba6e1d 100644 --- a/tests/topotests/ospf_netns_vrf/r2/zebraroutedown.txt +++ b/tests/topotests/ospf_netns_vrf/r2/zebraroutedown.txt @@ -2,6 +2,8 @@ VRF r2-ospf-cust1: O>* 10.0.1.0/24 [110/20] via 10.0.3.2, r2-eth1, weight 1, XX:XX:XX O 10.0.2.0/24 [110/10] is directly connected, r2-eth0, weight 1, XX:XX:XX C>* 10.0.2.0/24 is directly connected, r2-eth0, XX:XX:XX +L>* 10.0.2.1/32 is directly connected, r2-eth0, XX:XX:XX O 10.0.3.0/24 [110/10] is directly connected, r2-eth1, weight 1, XX:XX:XX C>* 10.0.3.0/24 is directly connected, r2-eth1, XX:XX:XX +L>* 10.0.3.3/32 is directly connected, r2-eth1, XX:XX:XX diff --git a/tests/topotests/ospf_netns_vrf/r3/ospfd.conf b/tests/topotests/ospf_netns_vrf/r3/ospfd.conf index b73d547e3e..abfaa5b9ef 100644 --- a/tests/topotests/ospf_netns_vrf/r3/ospfd.conf +++ b/tests/topotests/ospf_netns_vrf/r3/ospfd.conf @@ -4,6 +4,14 @@ password zebra log file /tmp/r3-ospfd.log ! ! +interface r3-eth0 vrf r3-ospf-cust1 + ip ospf hello-interval 1 + ip ospf dead-interval 4 +! +interface r3-eth1 vrf r3-ospf-cust1 + ip ospf hello-interval 1 + ip ospf dead-interval 4 +! router ospf vrf r3-ospf-cust1 ospf router-id 10.0.255.3 redistribute kernel diff --git a/tests/topotests/ospf_netns_vrf/r3/zebraroute.txt b/tests/topotests/ospf_netns_vrf/r3/zebraroute.txt index b435c2ebe5..5eb92efd20 100644 --- a/tests/topotests/ospf_netns_vrf/r3/zebraroute.txt +++ b/tests/topotests/ospf_netns_vrf/r3/zebraroute.txt @@ -3,6 +3,8 @@ O>* 10.0.1.0/24 [110/20] via 10.0.3.2, r3-eth0, weight 1, XX:XX:XX O>* 10.0.2.0/24 [110/20] via 10.0.3.3, r3-eth0, weight 1, XX:XX:XX O 10.0.3.0/24 [110/10] is directly connected, r3-eth0, weight 1, XX:XX:XX C>* 10.0.3.0/24 is directly connected, r3-eth0, XX:XX:XX +L>* 10.0.3.1/32 is directly connected, r3-eth0, XX:XX:XX O 10.0.10.0/24 [110/10] is directly connected, r3-eth1, weight 1, XX:XX:XX C>* 10.0.10.0/24 is directly connected, r3-eth1, XX:XX:XX +L>* 10.0.10.1/32 is directly connected, r3-eth1, XX:XX:XX diff --git a/tests/topotests/ospf_netns_vrf/r3/zebraroutedown.txt b/tests/topotests/ospf_netns_vrf/r3/zebraroutedown.txt index f30a4be6c6..26cc19660a 100644 --- a/tests/topotests/ospf_netns_vrf/r3/zebraroutedown.txt +++ b/tests/topotests/ospf_netns_vrf/r3/zebraroutedown.txt @@ -1,4 +1,5 @@ VRF r3-ospf-cust1: O 10.0.10.0/24 [110/10] is directly connected, r3-eth1, weight 1, XX:XX:XX C>* 10.0.10.0/24 is directly connected, r3-eth1, XX:XX:XX +L>* 10.0.10.1/32 is directly connected, r3-eth1, XX:XX:XX diff --git a/tests/topotests/ospf_prefix_suppression/r1/frr.conf b/tests/topotests/ospf_prefix_suppression/r1/frr.conf new file mode 100644 index 0000000000..437b474153 --- /dev/null +++ b/tests/topotests/ospf_prefix_suppression/r1/frr.conf @@ -0,0 +1,47 @@ +! +hostname r1 +password zebra +log file /tmp/r1-frr.log +ip forwarding +! +interface r1-eth0 + ip address 10.1.1.1/24 + ip ospf network broadcast + ip ospf hello-interval 1 + ip ospf dead-interval 30 +! +interface r1-eth1 + ip address 10.1.2.1/24 + ip ospf network non-broadcast + ip ospf hello-interval 1 + ip ospf dead-interval 30 +! +! +interface r1-eth2 + ip address 10.1.3.1/24 + ip ospf network point-to-point + ip ospf hello-interval 1 + ip ospf dead-interval 30 +! +interface r1-eth3 + ip address 10.1.4.1/24 + ip ospf network point-to-multipoint + ip ospf hello-interval 1 + ip ospf dead-interval 30 +! +interface r1-eth4 + ip address 10.1.7.1/24 + ip ospf network broadcast + ip ospf hello-interval 1 + ip ospf dead-interval 30 +! +! +router ospf + ospf router-id 1.1.1.1 + distance 20 + network 10.1.1.0/24 area 0 + network 10.1.2.0/24 area 0 + network 10.1.3.0/24 area 0 + network 10.1.4.0/24 area 0 + network 10.1.7.0/24 area 0 +! diff --git a/tests/topotests/ospf_prefix_suppression/r2/frr.conf b/tests/topotests/ospf_prefix_suppression/r2/frr.conf new file mode 100644 index 0000000000..68390f15f1 --- /dev/null +++ b/tests/topotests/ospf_prefix_suppression/r2/frr.conf @@ -0,0 +1,57 @@ +! +hostname r2 +password zebra +log file /tmp/r1-frr.log +ip forwarding +! +interface r2-eth0 + ip address 10.1.1.2/24 + ip ospf network broadcast + ip ospf hello-interval 1 + ip ospf dead-interval 30 +! +interface r2-eth1 + ip address 10.1.2.2/24 + ip ospf network non-broadcast + ip ospf hello-interval 1 + ip ospf dead-interval 30 +! +! +interface r2-eth2 + ip address 10.1.3.2/24 + ip ospf network point-to-point + ip ospf hello-interval 1 + ip ospf dead-interval 30 +! +! +interface r2-eth3 + ip address 10.1.4.2/24 + ip ospf network point-to-multipoint + ip ospf hello-interval 1 + ip ospf dead-interval 30 +! +! +interface r2-eth4 + ip address 10.1.5.2/24 + ip ospf network broadcast + ip ospf hello-interval 1 + ip ospf dead-interval 30 +! +! +interface r2-eth5 + ip address 10.1.6.2/24 + ip ospf network broadcast + ip ospf hello-interval 1 + ip ospf dead-interval 30 +! +! +router ospf + ospf router-id 2.2.2.2 + distance 20 + network 10.1.1.0/24 area 0 + network 10.1.2.0/24 area 0 + network 10.1.3.0/24 area 0 + network 10.1.4.0/24 area 0 + network 10.1.5.0/24 area 0 + network 10.1.6.0/24 area 1 +! diff --git a/tests/topotests/ospf_prefix_suppression/r3/frr.conf b/tests/topotests/ospf_prefix_suppression/r3/frr.conf new file mode 100644 index 0000000000..984a39d989 --- /dev/null +++ b/tests/topotests/ospf_prefix_suppression/r3/frr.conf @@ -0,0 +1,25 @@ +! +hostname r3 +password zebra +log file /tmp/r1-frr.log +ip forwarding +! +interface r3-eth0 + ip address 10.1.5.3/24 + ip ospf network broadcast + ip ospf hello-interval 1 + ip ospf dead-interval 30 +! +! +interface r3-eth1 + ip address 10.1.6.3/24 + ip ospf network broadcast + ip ospf hello-interval 1 + ip ospf dead-interval 30 +! +! +router ospf + ospf router-id 3.3.3.3 + distance 20 + network 10.1.5.0/24 area 0 + network 10.1.6.0/24 area 1 diff --git a/tests/topotests/ospf_prefix_suppression/test_ospf_prefix_suppression.py b/tests/topotests/ospf_prefix_suppression/test_ospf_prefix_suppression.py new file mode 100644 index 0000000000..d5ea7ebc40 --- /dev/null +++ b/tests/topotests/ospf_prefix_suppression/test_ospf_prefix_suppression.py @@ -0,0 +1,951 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# +# test_ospf_prefix_suppression.py +# +# Copyright (c) 2023 LabN Consulting +# Acee Lindem +# + +import os +import sys +import json +from time import sleep +from functools import partial +import pytest + +# pylint: disable=C0413 +# Import topogen and topotest helpers +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger + +from lib.common_config import ( + run_frr_cmd, + shutdown_bringup_interface, + start_router_daemons, + step, +) + + +""" +test_ospf_metric_propagation.py: Test OSPF/BGP metric propagation +""" + +TOPOLOGY = """ + + + +-----+ +-----+ +-----+ + eth4 | | eth0 | | eth4 eth0 | | + ------+ +-------------+ +--------------+ | +10.1.7.0/24 | | 10.1.1.0/24 | | 10.1.5.0/24 | | + | | | |.2 .3| | + | | eth1 | | | | + | +-------------+ | | | + | R1 | 10.1.2.0/24 | R2 | | R3 | + | | | | | | + | | eth2 | | | | + | +-------------+ | | | + | | 10.1.3.0/24 | | | | + | | | | | | + | | eth3 | | eth5 eth1 | | + | +-------------+ +--------------+ | + | | 10.1.4.0/24 | | 10.1.6.0/24 | | + .1 +-----+.1 .2+-----+.2 .3+-----+ + +""" + +# Save the Current Working Directory to find configuration files. +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# Required to instantiate the topology builder class. + +pytestmark = [pytest.mark.ospfd, pytest.mark.bgpd] + + +def build_topo(tgen): + "Build function" + + # Create 3 routers + tgen.add_router("r1") + tgen.add_router("r2") + tgen.add_router("r3") + + # Interconect router 1, 2 (0) + switch = tgen.add_switch("s1-1-2") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + # Interconect router 1, 2 (1) + switch = tgen.add_switch("s2-1-2") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + # Interconect router 1, 2 (2) + switch = tgen.add_switch("s3-1-2") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + # Interconect router 1, 2 (3) + switch = tgen.add_switch("s4-1-2") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + # Interconect router 2, 3 (0) + switch = tgen.add_switch("s5-2-3") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) + + # Interconect router 2, 3 (1) + switch = tgen.add_switch("s6-2-3") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) + + # Add standalone network to router 1 + switch = tgen.add_switch("s7-1") + switch.add_link(tgen.gears["r1"]) + + +def setup_module(mod): + logger.info("OSPF Prefix Suppression:\n {}".format(TOPOLOGY)) + + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + + # Starting Routers + router_list = tgen.routers() + + for rname, router in router_list.items(): + logger.info("Loading router %s" % rname) + router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname))) + + # Initialize all routers. + tgen.start_router() + + +def teardown_module(mod): + "Teardown the pytest environment" + tgen = get_topogen() + tgen.stop_topology() + + +def test_all_routes_advertised(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip("Skipped because of router(s) failure") + + # Verify OSPF routes are installed + r3 = tgen.gears["r3"] + input_dict = { + "10.1.1.0/24": [ + { + "prefix": "10.1.1.0/24", + "prefixLen": 24, + "protocol": "ospf", + "nexthops": [ + { + "ip": "10.1.5.2", + "interfaceName": "r3-eth0", + } + ], + } + ] + } + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.1.0/24 json", input_dict + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.1.0/24 not installed on router r3" + assert result is None, assertmsg + + input_dict = { + "10.1.2.0/24": [ + { + "prefix": "10.1.2.0/24", + "prefixLen": 24, + "protocol": "ospf", + "nexthops": [ + { + "ip": "10.1.5.2", + "interfaceName": "r3-eth0", + } + ], + } + ] + } + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.2.0/24 json", input_dict + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.2.0/24 not installed on router r3" + assert result is None, assertmsg + + input_dict = { + "10.1.3.0/24": [ + { + "prefix": "10.1.3.0/24", + "prefixLen": 24, + "protocol": "ospf", + "nexthops": [ + { + "ip": "10.1.5.2", + "interfaceName": "r3-eth0", + } + ], + } + ] + } + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.3.0/24 json", input_dict + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.3.0/24 not installed on router r3" + assert result is None, assertmsg + + input_dict = { + "10.1.4.1/32": [ + { + "prefix": "10.1.4.1/32", + "prefixLen": 32, + "protocol": "ospf", + "nexthops": [ + { + "ip": "10.1.5.2", + "interfaceName": "r3-eth0", + } + ], + } + ] + } + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.4.1/32 json", input_dict + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.4.1/32 not installed on router r3" + assert result is None, assertmsg + + input_dict = { + "10.1.4.2/32": [ + { + "prefix": "10.1.4.2/32", + "prefixLen": 32, + "protocol": "ospf", + "nexthops": [ + { + "ip": "10.1.5.2", + "interfaceName": "r3-eth0", + } + ], + } + ] + } + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.4.2/32 json", input_dict + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.4.2/32 not installed on router r3" + assert result is None, assertmsg + + input_dict = { + "10.1.7.0/24": [ + { + "prefix": "10.1.7.0/24", + "prefixLen": 24, + "protocol": "ospf", + "nexthops": [ + { + "ip": "10.1.5.2", + "interfaceName": "r3-eth0", + } + ], + } + ] + } + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.7.0/24 json", input_dict + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.7.0/24 not installed on router r3" + assert result is None, assertmsg + + input_dict = {} + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.8.0/24 json", input_dict, True + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.8.0/24 installed on router r3" + assert result is None, assertmsg + + +def test_broadcast_stub_suppression(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip("Skipped because of router(s) failure") + + step("Configure R1 interface r1-eth4 with prefix suppression") + r1 = tgen.gears["r1"] + r1.vtysh_cmd("conf t\ninterface r1-eth4\nip ospf prefix-suppression") + + step("Verify the R1 configuration of 'ip ospf prefix-suppression'") + prefix_suppression_cfg = ( + tgen.net["r1"] + .cmd('vtysh -c "show running ospfd" | grep "^ ip ospf prefix-suppression"') + .rstrip() + ) + assertmsg = "'ip ospf prefix-suppression' applied, but not present in configuration" + assert prefix_suppression_cfg == " ip ospf prefix-suppression", assertmsg + + step("Verify that ospf-prefix suppression is applied to the R1 interface") + r1_eth4_with_prefix_suppression = { + "interfaces": { + "r1-eth4": { + "ifUp": True, + "ospfEnabled": True, + "ipAddress": "10.1.7.1", + "ospfIfType": "Broadcast", + "prefixSuppression": True, + } + } + } + test_func = partial( + topotest.router_json_cmp, + r1, + "show ip ospf interface r1-eth4 json", + r1_eth4_with_prefix_suppression, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "R1 OSPF interface r1-eth4 doesn't have prefix-suppression enabled" + assert result is None, assertmsg + + step( + "Verify that ospf-prefix suppression is applied to the R1 interface (non-JSON)" + ) + prefix_suppression_show = ( + tgen.net["r1"] + .cmd( + 'vtysh -c "show ip ospf interface r1-eth4" | grep "^ Suppress advertisement of interface IP prefix"' + ) + .rstrip() + ) + assertmsg = ( + "'ip ospf prefix-suppression' applied, but not present in interface show" + ) + assert ( + prefix_suppression_show == " Suppress advertisement of interface IP prefix" + ), assertmsg + + step("Verify the ospf prefix is not advertised and not present on r3") + r3 = tgen.gears["r3"] + input_dict = {} + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.7.0/24 json", input_dict, True + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.7.0/24 installed on router r3" + assert result is None, assertmsg + + step("Remove R1 interface r1-eth4 prefix-suppression configuration") + r1 = tgen.gears["r1"] + r1.vtysh_cmd("conf t\ninterface r1-eth4\nno ip ospf prefix-suppression") + + step("Verify no R1 configuration of 'ip ospf prefix-suppression") + rc, _, _ = tgen.net["r1"].cmd_status( + "show running ospfd | grep -q 'ip ospf prefix-suppression'", warn=False + ) + assertmsg = ( + "'ip ospf prefix-suppression' not applied, but present in R1 configuration" + ) + assert rc, assertmsg + + step("Verify that ospf-prefix suppression is not applied to the R1 interface") + r1_eth4_without_prefix_suppression = { + "interfaces": { + "r1-eth4": { + "ifUp": True, + "ospfEnabled": True, + "ipAddress": "10.1.7.1", + "ospfIfType": "Broadcast", + "prefixSuppression": False, + } + } + } + test_func = partial( + topotest.router_json_cmp, + r1, + "show ip ospf interface r1-eth4 json", + r1_eth4_without_prefix_suppression, + ) + + step("Verify that 10.1.7.0/24 route is now installed on R3") + input_dict = { + "10.1.7.0/24": [ + { + "prefix": "10.1.7.0/24", + "prefixLen": 24, + "protocol": "ospf", + "nexthops": [ + { + "ip": "10.1.5.2", + "interfaceName": "r3-eth0", + } + ], + } + ] + } + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.7.0/24 json", input_dict + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.7.0/24 not installed on router r3" + assert result is None, assertmsg + + +def test_broadcast_transit_suppression(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip("Skipped because of router(s) failure") + + step( + "Configure R1 interface r1-eth0 with prefix suppression using interface address" + ) + r1 = tgen.gears["r1"] + r1.vtysh_cmd("conf t\ninterface r1-eth0\nip ospf prefix-suppression 10.1.1.1") + + step("Verify the R1 configuration of 'ip ospf prefix-suppression 10.1.1.1'") + prefix_suppression_cfg = ( + tgen.net["r1"] + .cmd( + 'vtysh -c "show running ospfd" | grep "^ ip ospf prefix-suppression 10.1.1.1"' + ) + .rstrip() + ) + assertmsg = "'ip ospf prefix-suppression 10.1.1.1' applied, but not present in configuration" + assert prefix_suppression_cfg == " ip ospf prefix-suppression 10.1.1.1", assertmsg + + step( + "Configure R2 interface r2-eth0 with prefix suppression using interface address" + ) + r2 = tgen.gears["r2"] + r2.vtysh_cmd("conf t\ninterface r2-eth0\nip ospf prefix-suppression 10.1.1.2") + + step("Verify that ospf-prefix suppression is applied to the R1 interface") + r1_eth0_with_prefix_suppression = { + "interfaces": { + "r1-eth0": { + "ifUp": True, + "ospfEnabled": True, + "ipAddress": "10.1.1.1", + "ospfIfType": "Broadcast", + "networkType": "BROADCAST", + "prefixSuppression": True, + } + } + } + test_func = partial( + topotest.router_json_cmp, + r1, + "show ip ospf interface r1-eth0 json", + r1_eth0_with_prefix_suppression, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "R1 OSPF interface r1-eth0 doesn't have prefix-suppression enabled" + assert result is None, assertmsg + + step("Verify the OSPF prefix is not advertised and not present on r3") + r3 = tgen.gears["r3"] + input_dict = {} + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.1.0/24 json", input_dict, True + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.1.0/24 installed on router r3" + assert result is None, assertmsg + + step("Verify the OSPF Network-LSA prefixes are also not present on R3 ") + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.1.1/24 json", input_dict, True + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.1.1/24 installed on router r3" + assert result is None, assertmsg + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.1.2/24 json", input_dict, True + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.1.2/24 installed on router r3" + assert result is None, assertmsg + + step( + "Remove R1 interface r1-eth0 prefix-suppression configuration using interface address" + ) + r1 = tgen.gears["r1"] + r1.vtysh_cmd("conf t\ninterface r1-eth0\nno ip ospf prefix-suppression 10.1.1.1") + + step( + "Remove R2 interface r2-eth0 prefix-suppression configuration using interface address" + ) + r2 = tgen.gears["r2"] + r2.vtysh_cmd("conf t\ninterface r2-eth0\nno ip ospf prefix-suppression 10.1.1.2") + + step("Verify no R1 configuration of 'ip ospf prefix-suppression") + rc, _, _ = tgen.net["r1"].cmd_status( + "show running ospfd | grep -q 'ip ospf prefix-suppression 10.1.1.1'", warn=False + ) + assertmsg = "'ip ospf prefix-suppression 10.1.1.1' not applied, but present in R1 configuration" + assert rc, assertmsg + + step("Verify that ospf-prefix suppression is not applied to the R1 interface") + r1_eth0_without_prefix_suppression = { + "interfaces": { + "r1-eth0": { + "ifUp": True, + "ospfEnabled": True, + "ipAddress": "10.1.1.1", + "ospfIfType": "Broadcast", + "networkType": "BROADCAST", + "prefixSuppression": False, + } + } + } + test_func = partial( + topotest.router_json_cmp, + r1, + "show ip ospf interface r1-eth0 json", + r1_eth0_without_prefix_suppression, + ) + + step("Verify that 10.1.1.0/24 route is now installed on R3") + input_dict = { + "10.1.1.0/24": [ + { + "prefix": "10.1.1.0/24", + "prefixLen": 24, + "protocol": "ospf", + "nexthops": [ + { + "ip": "10.1.5.2", + "interfaceName": "r3-eth0", + } + ], + } + ] + } + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.1.0/24 json", input_dict + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.1.0/24 not installed on router r3" + assert result is None, assertmsg + + +def test_nbma_transit_suppression(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip("Skipped because of router(s) failure") + + step("Configure R1 interface r1-eth1 with prefix suppression") + r1 = tgen.gears["r1"] + r1.vtysh_cmd("conf t\ninterface r1-eth1\nip ospf prefix-suppression") + + step("Configure R2 interface r2-eth1 with prefix suppression") + r2 = tgen.gears["r2"] + r2.vtysh_cmd("conf t\ninterface r2-eth1\nip ospf prefix-suppression") + + step("Verify that ospf-prefix suppression is applied to the R1 interface") + r1_eth1_with_prefix_suppression = { + "interfaces": { + "r1-eth1": { + "ifUp": True, + "ospfEnabled": True, + "ipAddress": "10.1.2.1", + "ospfIfType": "Broadcast", + "networkType": "NBMA", + "prefixSuppression": True, + } + } + } + test_func = partial( + topotest.router_json_cmp, + r1, + "show ip ospf interface r1-eth1 json", + r1_eth1_with_prefix_suppression, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "R1 OSPF interface r1-eth1 doesn't have prefix-suppression enabled" + assert result is None, assertmsg + + step("Verify the OSPF prefix is not advertised and not present on r3") + r3 = tgen.gears["r3"] + input_dict = {} + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.2.0/24 json", input_dict, True + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.2.0/24 installed on router r3" + assert result is None, assertmsg + + step("Verify the OSPF Network-LSA prefixes are also not present on R3 ") + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.2.1/24 json", input_dict, True + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.2.1/24 installed on router r3" + assert result is None, assertmsg + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.2.2/24 json", input_dict, True + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.2.2/24 installed on router r3" + assert result is None, assertmsg + + step("Remove R1 interface r1-eth1 prefix-suppression configuration") + r1 = tgen.gears["r1"] + r1.vtysh_cmd("conf t\ninterface r1-eth1\nno ip ospf prefix-suppression") + + step("Remove R2 interface eth1 prefix-suppression configuration") + r2 = tgen.gears["r2"] + r2.vtysh_cmd("conf t\ninterface r2-eth1\nno ip ospf prefix-suppression") + + step("Verify no R1 configuration of 'ip ospf prefix-suppression") + rc, _, _ = tgen.net["r1"].cmd_status( + "show running ospfd | grep -q 'ip ospf prefix-suppression'", warn=False + ) + assertmsg = ( + "'ip ospf prefix-suppression' not applied, but present in R1 configuration" + ) + assert rc, assertmsg + + step("Verify that ospf-prefix suppression is not applied to the R1 interface") + r1_eth1_without_prefix_suppression = { + "interfaces": { + "r1-eth1": { + "ifUp": True, + "ospfEnabled": True, + "ipAddress": "10.1.2.1", + "ospfIfType": "Broadcast", + "networkType": "NBMA", + "prefixSuppression": False, + } + } + } + test_func = partial( + topotest.router_json_cmp, + r1, + "show ip ospf interface r1-eth1 json", + r1_eth1_without_prefix_suppression, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "Prefix suppression on interface r1-eth1" + assert result is None, assertmsg + + step("Verify that 10.1.2.0/24 route is now installed on R3") + input_dict = { + "10.1.2.0/24": [ + { + "prefix": "10.1.2.0/24", + "prefixLen": 24, + "protocol": "ospf", + "nexthops": [ + { + "ip": "10.1.5.2", + "interfaceName": "r3-eth0", + } + ], + } + ] + } + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.2.0/24 json", input_dict + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.2.0/24 not installed on router r3" + assert result is None, assertmsg + + +def test_p2p_suppression(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip("Skipped because of router(s) failure") + + step( + "Configure R1 interface r1-eth2 with prefix suppression with interface address" + ) + r1 = tgen.gears["r1"] + r1.vtysh_cmd("conf t\ninterface r1-eth2\nip ospf prefix-suppression 10.1.3.1") + + step( + "Configure R2 interface r2-eth1 with prefix suppression with interface address" + ) + r2 = tgen.gears["r2"] + r2.vtysh_cmd("conf t\ninterface r2-eth2\nip ospf prefix-suppression 10.1.3.2") + + step("Verify the R1 configuration of 'ip ospf prefix-suppression 10.1.3.1'") + prefix_suppression_cfg = ( + tgen.net["r1"] + .cmd( + 'vtysh -c "show running ospfd" | grep "^ ip ospf prefix-suppression 10.1.3.1"' + ) + .rstrip() + ) + assertmsg = "'ip ospf prefix-suppression 10.1.3.1' applied, but not present in configuration" + assert prefix_suppression_cfg == " ip ospf prefix-suppression 10.1.3.1", assertmsg + + step("Verify that ospf-prefix suppression is applied to the R1 interface") + r1_eth2_with_prefix_suppression = { + "interfaces": { + "r1-eth2": { + "ifUp": True, + "ospfEnabled": True, + "ipAddress": "10.1.3.1", + "ospfIfType": "Broadcast", + "networkType": "POINTOPOINT", + "prefixSuppression": True, + } + } + } + test_func = partial( + topotest.router_json_cmp, + r1, + "show ip ospf interface r1-eth2 json", + r1_eth2_with_prefix_suppression, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "R1 OSPF interface r1-eth2 doesn't have prefix-suppression enabled" + assert result is None, assertmsg + + step("Verify the OSPF prefix is not advertised and not present on r3") + r3 = tgen.gears["r3"] + input_dict = {} + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.3.0/24 json", input_dict, True + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.3.0/24 installed on router r3" + assert result is None, assertmsg + + step( + "Remove R1 interface r1-eth2 prefix-suppression configuration using interface address" + ) + r1 = tgen.gears["r1"] + r1.vtysh_cmd("conf t\ninterface r1-eth2\nno ip ospf prefix-suppression 10.1.3.1") + + step( + "Remove R2 interface r2-eth2 prefix-suppression configuration using interface address" + ) + r2 = tgen.gears["r2"] + r2.vtysh_cmd("conf t\ninterface r2-eth2\nno ip ospf prefix-suppression 10.1.3.2") + + step("Verify no R1 configuration of 'ip ospf prefix-suppression") + rc, _, _ = tgen.net["r1"].cmd_status( + "show running ospfd | grep -q 'ip ospf prefix-suppression 10.1.3.1'", warn=False + ) + assertmsg = "'ip ospf prefix-suppressio 10.1.3.1' not applied, but present in R1 configuration" + assert rc, assertmsg + + step("Verify that ospf-prefix suppression is not applied to the R1 interface") + r1_eth2_without_prefix_suppression = { + "interfaces": { + "r1-eth2": { + "ifUp": True, + "ospfEnabled": True, + "ipAddress": "10.1.3.1", + "ospfIfType": "Broadcast", + "networkType": "POINTOPOINT", + "prefixSuppression": False, + } + } + } + test_func = partial( + topotest.router_json_cmp, + r1, + "show ip ospf interface r1-eth2 json", + r1_eth2_without_prefix_suppression, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "Prefix suppression on interface r1-eth2" + assert result is None, assertmsg + + step("Verify that 10.1.3.0/24 route is now installed on R3") + input_dict = { + "10.1.3.0/24": [ + { + "prefix": "10.1.3.0/24", + "prefixLen": 24, + "protocol": "ospf", + "nexthops": [ + { + "ip": "10.1.5.2", + "interfaceName": "r3-eth0", + } + ], + } + ] + } + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.3.0/24 json", input_dict + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.3.0/24 not installed on router r3" + assert result is None, assertmsg + + +def test_p2mp_suppression(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip("Skipped because of router(s) failure") + + step("Configure R1 interface r1-eth3 with prefix suppression") + r1 = tgen.gears["r1"] + r1.vtysh_cmd("conf t\ninterface r1-eth3\nip ospf prefix-suppression") + + step("Configure R2 interface r2-eth3 with prefix suppression") + r2 = tgen.gears["r2"] + r2.vtysh_cmd("conf t\ninterface r2-eth3\nip ospf prefix-suppression") + + step("Verify that ospf-prefix suppression is applied to the R1 interface") + r1_eth3_with_prefix_suppression = { + "interfaces": { + "r1-eth3": { + "ifUp": True, + "ospfEnabled": True, + "ipAddress": "10.1.4.1", + "ospfIfType": "Broadcast", + "networkType": "POINTOMULTIPOINT", + "prefixSuppression": True, + } + } + } + test_func = partial( + topotest.router_json_cmp, + r1, + "show ip ospf interface r1-eth3 json", + r1_eth3_with_prefix_suppression, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "R1 OSPF interface r1-eth3 doesn't have prefix-suppression enabled" + assert result is None, assertmsg + + step("Verify the OSPF P2MP prefixes are not advertised and not present on r3") + r3 = tgen.gears["r3"] + input_dict = {} + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.4.1/32 json", input_dict, True + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.4.1/32 installed on router r3" + assert result is None, assertmsg + + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.4.2/32 json", input_dict, True + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.4.2/32 installed on router r3" + assert result is None, assertmsg + + step("Remove R1 interface r1-eth3 prefix-suppression configuration") + r1 = tgen.gears["r1"] + r1.vtysh_cmd("conf t\ninterface r1-eth3\nno ip ospf prefix-suppression") + + step("Remove R2 interface r2-eth3 prefix-suppression configuration") + r2 = tgen.gears["r2"] + r2.vtysh_cmd("conf t\ninterface r2-eth3\nno ip ospf prefix-suppression") + + step("Verify no R1 configuration of 'ip ospf prefix-suppression") + rc, _, _ = tgen.net["r1"].cmd_status( + "show running ospfd | grep -q 'ip ospf prefix-suppression'", warn=False + ) + assertmsg = ( + "'ip ospf prefix-suppression' not applied, but present in R1 configuration" + ) + assert rc, assertmsg + + step("Verify that ospf-prefix suppression is not applied to the R1 interface") + r1_eth3_without_prefix_suppression = { + "interfaces": { + "r1-eth3": { + "ifUp": True, + "ospfEnabled": True, + "ipAddress": "10.1.4.1", + "ospfIfType": "Broadcast", + "networkType": "POINTOMULTIPOINT", + "prefixSuppression": False, + } + } + } + test_func = partial( + topotest.router_json_cmp, + r1, + "show ip ospf interface r1-eth3 json", + r1_eth3_without_prefix_suppression, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "Prefix suppression on interface r1-eth3" + assert result is None, assertmsg + + step("Verify that 10.1.4.1/32 route is now installed on R3") + input_dict = { + "10.1.4.1/32": [ + { + "prefix": "10.1.4.1/32", + "prefixLen": 32, + "protocol": "ospf", + "nexthops": [ + { + "ip": "10.1.5.2", + "interfaceName": "r3-eth0", + } + ], + } + ] + } + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.4.1/32 json", input_dict + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.4.1/32 not installed on router r3" + assert result is None, assertmsg + + step("Verify that 10.1.4.2/32 route is now installed on R3") + input_dict = { + "10.1.4.2/32": [ + { + "prefix": "10.1.4.2/32", + "prefixLen": 32, + "protocol": "ospf", + "nexthops": [ + { + "ip": "10.1.5.2", + "interfaceName": "r3-eth0", + } + ], + } + ] + } + test_func = partial( + topotest.router_json_cmp, r3, "show ip route 10.1.4.2/32 json", input_dict + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "10.1.4.2/32 not installed on router r3" + assert result is None, assertmsg + + +def test_memory_leak(): + "Run the memory leak test and report results." + tgen = get_topogen() + if not tgen.is_memleak_enabled(): + pytest.skip("Memory leak test/report is disabled") + + tgen.report_memory_leaks() + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/ospf_suppress_fa/r1/initial.json b/tests/topotests/ospf_suppress_fa/r1/initial.json new file mode 100644 index 0000000000..f0e61101bf --- /dev/null +++ b/tests/topotests/ospf_suppress_fa/r1/initial.json @@ -0,0 +1,44 @@ +{ + "routerId":"10.0.12.1", + "asExternalLinkStates":[ + { + "options":"*|-|-|-|-|-|E|-", + "lsaFlags":6, + "lsaType":"AS-external-LSA", + "linkStateId":"3.3.1.1", + "advertisingRouter":"10.0.23.2", + "networkMask":32, + "metricType":"E2 (Larger than any link state path)", + "tos":0, + "metric":20, + "forwardAddress":"10.0.23.3", + "externalRouteTag":0 + }, + { + "options":"*|-|-|-|-|-|E|-", + "lsaFlags":6, + "lsaType":"AS-external-LSA", + "linkStateId":"3.3.2.2", + "advertisingRouter":"10.0.23.2", + "networkMask":32, + "metricType":"E2 (Larger than any link state path)", + "tos":0, + "metric":20, + "forwardAddress":"10.0.23.3", + "externalRouteTag":0 + }, + { + "options":"*|-|-|-|-|-|E|-", + "lsaFlags":6, + "lsaType":"AS-external-LSA", + "linkStateId":"3.3.3.3", + "advertisingRouter":"10.0.23.2", + "networkMask":32, + "metricType":"E2 (Larger than any link state path)", + "tos":0, + "metric":20, + "forwardAddress":"10.0.23.3", + "externalRouteTag":0 + } + ] +} diff --git a/tests/topotests/ospf_suppress_fa/r1/neighbor.json b/tests/topotests/ospf_suppress_fa/r1/neighbor.json new file mode 100644 index 0000000000..417fcbee11 --- /dev/null +++ b/tests/topotests/ospf_suppress_fa/r1/neighbor.json @@ -0,0 +1,13 @@ +{ + "neighbors":{ + "10.0.23.2":[ + { + "nbrPriority":1, + "converged":"Full", + "role":"DROther", + "ifaceAddress":"10.0.12.2", + "ifaceName":"r1-eth0:10.0.12.1" + } + ] + } +} diff --git a/tests/topotests/ospf_suppress_fa/r1/post.json b/tests/topotests/ospf_suppress_fa/r1/post.json new file mode 100644 index 0000000000..98cbf8f1cc --- /dev/null +++ b/tests/topotests/ospf_suppress_fa/r1/post.json @@ -0,0 +1,44 @@ +{ + "routerId":"10.0.12.1", + "asExternalLinkStates":[ + { + "options":"*|-|-|-|-|-|E|-", + "lsaFlags":6, + "lsaType":"AS-external-LSA", + "linkStateId":"3.3.1.1", + "advertisingRouter":"10.0.23.2", + "networkMask":32, + "metricType":"E2 (Larger than any link state path)", + "tos":0, + "metric":20, + "forwardAddress":"0.0.0.0", + "externalRouteTag":0 + }, + { + "options":"*|-|-|-|-|-|E|-", + "lsaFlags":6, + "lsaType":"AS-external-LSA", + "linkStateId":"3.3.2.2", + "advertisingRouter":"10.0.23.2", + "networkMask":32, + "metricType":"E2 (Larger than any link state path)", + "tos":0, + "metric":20, + "forwardAddress":"0.0.0.0", + "externalRouteTag":0 + }, + { + "options":"*|-|-|-|-|-|E|-", + "lsaFlags":6, + "lsaType":"AS-external-LSA", + "linkStateId":"3.3.3.3", + "advertisingRouter":"10.0.23.2", + "networkMask":32, + "metricType":"E2 (Larger than any link state path)", + "tos":0, + "metric":20, + "forwardAddress":"0.0.0.0", + "externalRouteTag":0 + } + ] +} diff --git a/tests/topotests/ospf_suppress_fa/test_ospf_suppress_fa.py b/tests/topotests/ospf_suppress_fa/test_ospf_suppress_fa.py index d5583ac06a..8b3fc5808a 100644 --- a/tests/topotests/ospf_suppress_fa/test_ospf_suppress_fa.py +++ b/tests/topotests/ospf_suppress_fa/test_ospf_suppress_fa.py @@ -22,6 +22,8 @@ import os import sys +import json +from functools import partial import re import pytest @@ -33,6 +35,7 @@ # Import topogen and topotest helpers from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger # Required to instantiate the topology builder class. @@ -75,6 +78,7 @@ def setup_module(mod): TopoRouter.RD_OSPF, os.path.join(CWD, "{}/ospfd.conf".format(rname)) ) + logger.info("Module Setup") tgen.start_router() @@ -93,7 +97,17 @@ def test_converge_protocols(): if tgen.routers_have_failure(): pytest.skip(tgen.errors) - topotest.sleep(10, "Waiting for OSPF convergence") + router = tgen.gears["r1"] + json_file = "{}/r1/neighbor.json".format(CWD) + expected = json.loads(open(json_file).read()) + + test_func = partial( + topotest.router_json_cmp, router, "show ip ospf neighbor json", expected + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "r1 has not converged" + + logger.info("Converged Protocol") def ospf_configure_suppress_fa(router_name, area): @@ -114,58 +128,55 @@ def ospf_unconfigure_suppress_fa(router_name, area): router.vtysh_cmd("conf t\nrouter ospf\narea {} nssa\nexit\n".format(area)) -def ospf_get_lsa_type5(router_name): - "Return a dict with link state id as key and forwarding addresses as value" - - result = dict() - tgen = get_topogen() - router = tgen.gears[router_name] - cmd = "show ip ospf database external\n" - output = topotest.normalize_text(router.vtysh_cmd(cmd)) - for line in output.splitlines(): - re0 = re.match(r"\s+Link State ID: (\S+) \(External Network Number\)", line) - if re0: - lsa = re0.group(1) - re1 = re.match(r"\s+Forward Address: (\S+)", line) - if re1: - result[lsa] = re1.group(1) - return result - - -@pytest.fixture(scope="module", name="original") def test_ospf_set_suppress_fa(): "Test OSPF area [x] nssa suppress-fa" + logger.info("Testing Turning on/off suppress-fa") + tgen = get_topogen() + # Get current forwarding address for each LSA type-5 in r1 - initial = ospf_get_lsa_type5("r1") + logger.info("Get Initial State") + router = tgen.gears["r1"] + json_file = "{}/r1/initial.json".format(CWD) + expected_initial = json.loads(open(json_file).read()) + + test_func_initial = partial( + topotest.router_json_cmp, + router, + "show ip ospf data external json", + expected_initial, + ) + _, result = topotest.run_and_expect(test_func_initial, None, count=30, wait=1) + assert result is None, "Unable to get expected initial states" + logger.info("Configure suppress-fa") # Configure suppres-fa in r2 area 1 ospf_configure_suppress_fa("r2", "1") - topotest.sleep(10, "Waiting for OSPF convergence") - # Check forwarding address on r1 for all statics is 0.0.0.0 - assertmsg = "Forwarding address is not 0.0.0.0 after enabling OSPF suppress-fa" - suppress = ospf_get_lsa_type5("r1") - for prefix in suppress: - assert suppress[prefix] == "0.0.0.0", assertmsg + logger.info("Ensure that OSPF has converged on new values") + json_file = "{}/r1/post.json".format(CWD) + expected_post = json.loads(open(json_file).read()) - # Return the original forwarding addresses so we can compare them - # in the test_ospf_unset_supress_fa - return initial + test_func_post = partial( + topotest.router_json_cmp, + router, + "show ip ospf data external json", + expected_post, + ) + _, result = topotest.run_and_expect(test_func_post, None, count=30, wait=1) + assert result is None, "Unable to get expected state after turning on suppress-fa" -def test_ospf_unset_supress_fa(original): - "Test OSPF no area [x] nssa suppress-fa" + logger.info("Test OSPF no area [x] nssa suppress-fa") # Remove suppress-fa in r2 area 1 ospf_unconfigure_suppress_fa("r2", "1") - topotest.sleep(10, "Waiting for OSPF convergence") - # Check forwarding address is the original value on r1 for all statics - assertmsg = "Forwarding address is not correct after removing OSPF suppress-fa" - restore = ospf_get_lsa_type5("r1") - for prefix in restore: - assert restore[prefix] == original[prefix], assertmsg + logger.info("Has OSPF returned to original values") + _, result = topotest.run_and_expect(test_func_post, None, count=30, wait=1) + assert ( + result is None + ), "Unable to return to original state after turning off suppress-fa" if __name__ == "__main__": diff --git a/tests/topotests/ospf_te_topo1/r1/ospfd.conf b/tests/topotests/ospf_te_topo1/r1/ospfd.conf index 312dd2697e..1541f3f2fc 100644 --- a/tests/topotests/ospf_te_topo1/r1/ospfd.conf +++ b/tests/topotests/ospf_te_topo1/r1/ospfd.conf @@ -2,13 +2,13 @@ interface lo ip ospf area 0.0.0.0 ! -interface r1-eth0 +interface eth0 ip ospf network point-to-point ip ospf hello-interval 2 ip ospf dead-interval 10 ip ospf area 0.0.0.0 ! -interface r1-eth1 +interface eth1 ip ospf network point-to-point ip ospf hello-interval 2 ip ospf dead-interval 10 diff --git a/tests/topotests/ospf_te_topo1/r1/zebra.conf b/tests/topotests/ospf_te_topo1/r1/zebra.conf index c47789a166..dc50e3dd6d 100644 --- a/tests/topotests/ospf_te_topo1/r1/zebra.conf +++ b/tests/topotests/ospf_te_topo1/r1/zebra.conf @@ -2,7 +2,7 @@ interface lo ip address 10.0.255.1/32 ! -interface r1-eth0 +interface eth0 ip address 10.0.0.1/24 link-params metric 20 @@ -12,7 +12,7 @@ interface r1-eth0 enable exit-link-params ! -interface r1-eth1 +interface eth1 ip address 10.0.1.1/24 link-params enable diff --git a/tests/topotests/ospf_te_topo1/r2/ospfd.conf b/tests/topotests/ospf_te_topo1/r2/ospfd.conf index e9c3f65bc2..acc2e6b234 100644 --- a/tests/topotests/ospf_te_topo1/r2/ospfd.conf +++ b/tests/topotests/ospf_te_topo1/r2/ospfd.conf @@ -2,25 +2,25 @@ interface lo ip ospf area 0.0.0.0 ! -interface r2-eth0 +interface eth0 ip ospf network point-to-point ip ospf hello-interval 2 ip ospf dead-interval 10 ip ospf area 0.0.0.0 ! -interface r2-eth1 +interface eth1 ip ospf network point-to-point ip ospf hello-interval 2 ip ospf dead-interval 10 ip ospf area 0.0.0.0 ! -interface r2-eth2 +interface eth2 ip ospf network point-to-point ip ospf area 0.0.0.0 ip ospf hello-interval 2 ip ospf dead-interval 10 ! -interface r2-eth3 +interface eth3 ip ospf network point-to-point ip ospf hello-interval 2 ip ospf dead-interval 10 diff --git a/tests/topotests/ospf_te_topo1/r2/zebra.conf b/tests/topotests/ospf_te_topo1/r2/zebra.conf index a9771f70ca..6fe4dd0a5a 100644 --- a/tests/topotests/ospf_te_topo1/r2/zebra.conf +++ b/tests/topotests/ospf_te_topo1/r2/zebra.conf @@ -2,25 +2,25 @@ interface lo ip address 10.0.255.2/32 ! -interface r2-eth0 +interface eth0 ip address 10.0.0.2/24 link-params enable exit-link-params ! -interface r2-eth1 +interface eth1 ip address 10.0.1.2/24 link-params enable exit-link-params ! -interface r2-eth2 +interface eth2 ip address 10.0.3.2/24 link-params enable exit-link-params ! -interface r2-eth3 +interface eth3 ip address 10.0.4.2/24 link-params metric 30 diff --git a/tests/topotests/ospf_te_topo1/r3/ospfd.conf b/tests/topotests/ospf_te_topo1/r3/ospfd.conf index caa5f1e1eb..fc94437b64 100644 --- a/tests/topotests/ospf_te_topo1/r3/ospfd.conf +++ b/tests/topotests/ospf_te_topo1/r3/ospfd.conf @@ -2,13 +2,13 @@ interface lo ip ospf area 0.0.0.0 ! -interface r3-eth0 +interface eth0 ip ospf network point-to-point ip ospf area 0.0.0.0 ip ospf hello-interval 2 ip ospf dead-interval 10 ! -interface r3-eth1 +interface eth1 ip ospf network point-to-point ip ospf area 0.0.0.0 ip ospf hello-interval 2 diff --git a/tests/topotests/ospf_te_topo1/r3/zebra.conf b/tests/topotests/ospf_te_topo1/r3/zebra.conf index 4cf9077085..262b5adc92 100644 --- a/tests/topotests/ospf_te_topo1/r3/zebra.conf +++ b/tests/topotests/ospf_te_topo1/r3/zebra.conf @@ -2,14 +2,14 @@ interface lo ip address 10.0.255.3/32 ! -interface r3-eth0 +interface eth0 ip address 10.0.3.1/24 link-params enable admin-grp 0x20 exit-link-params ! -interface r3-eth1 +interface eth1 ip address 10.0.5.1/24 link-params enable diff --git a/tests/topotests/ospf_te_topo1/r4/ospfd.conf b/tests/topotests/ospf_te_topo1/r4/ospfd.conf index cd508017d3..5ec7918aff 100644 --- a/tests/topotests/ospf_te_topo1/r4/ospfd.conf +++ b/tests/topotests/ospf_te_topo1/r4/ospfd.conf @@ -2,7 +2,7 @@ interface lo ip ospf area 0.0.0.0 ! -interface r4-eth0 +interface eth0 ip ospf network point-to-point ip ospf hello-interval 2 ip ospf dead-interval 10 diff --git a/tests/topotests/ospf_te_topo1/r4/zebra.conf b/tests/topotests/ospf_te_topo1/r4/zebra.conf index 18c003b230..c482685094 100644 --- a/tests/topotests/ospf_te_topo1/r4/zebra.conf +++ b/tests/topotests/ospf_te_topo1/r4/zebra.conf @@ -2,7 +2,7 @@ interface lo ip address 10.0.255.4/32 ! -interface r4-eth0 +interface eth0 ip address 10.0.4.1/24 link-params enable diff --git a/tests/topotests/ospf_te_topo1/test_ospf_te_topo1.py b/tests/topotests/ospf_te_topo1/test_ospf_te_topo1.py index c8533cfbba..11fecc3211 100644 --- a/tests/topotests/ospf_te_topo1/test_ospf_te_topo1.py +++ b/tests/topotests/ospf_te_topo1/test_ospf_te_topo1.py @@ -18,22 +18,22 @@ | 10.0.225.1 | | | +------------+ - r1-eth0| |r1-eth1 + eth0| |eth1 | | 10.0.0.0/24| |10.0.1.0/24 | | - r2-eth0| |r2-eth1 + eth0| |eth1 +------------+ +------------+ | | | | - | R2 |r2-eth2 r3-eth0| R3 | + | R2 |eth2 eth0| R3 | | 10.0.255.2 +------------------+ 10.0.255.3 | | | 10.0.3.0/24 | | +------------+ +------+-----+ - r2-eth3| r3-eth1| + eth3| eth1| | | 10.0.4.0/24| 10.0.5.0/24| | | - r4-eth0| V + eth0| V +------------+ ASBR 10.0.255.5 | | | R4 | @@ -70,30 +70,24 @@ def build_topo(tgen): "Build function" # Create 4 routers - for routern in range(1, 5): - tgen.add_router("r{}".format(routern)) + r1 = tgen.add_router("r1") + r2 = tgen.add_router("r2") + r3 = tgen.add_router("r3") + r4 = tgen.add_router("r4") # Interconect router 1 and 2 with 2 links - switch = tgen.add_switch("s1") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) - switch = tgen.add_switch("s2") - switch.add_link(tgen.gears["r1"]) - switch.add_link(tgen.gears["r2"]) + tgen.add_link(r1, r2, ifname1="eth0", ifname2="eth0") + tgen.add_link(r1, r2, ifname1="eth1", ifname2="eth1") # Interconect router 3 and 2 - switch = tgen.add_switch("s3") - switch.add_link(tgen.gears["r3"]) - switch.add_link(tgen.gears["r2"]) + tgen.add_link(r2, r3, ifname1="eth2", ifname2="eth0") # Interconect router 4 and 2 - switch = tgen.add_switch("s4") - switch.add_link(tgen.gears["r4"]) - switch.add_link(tgen.gears["r2"]) + tgen.add_link(r2, r4, ifname1="eth3", ifname2="eth0") # Interconnect router 3 with next AS - switch = tgen.add_switch("s5") - switch.add_link(tgen.gears["r3"]) + s1 = tgen.add_switch("s1") + tgen.add_link(r3, s1, ifname1="eth1", ifname2="eth0") def setup_module(mod): @@ -174,8 +168,7 @@ def test_step2(): tgen = setup_testcase("Step2: Shutdown interface between r1 & r2") - tgen.net["r1"].cmd('vtysh -c "conf t" -c "interface r1-eth1" -c "shutdown"') - tgen.net["r2"].cmd('vtysh -c "conf t" -c "interface r2-eth1" -c "shutdown"') + tgen.net["r1"].cmd('vtysh -c "conf t" -c "interface eth1" -c "shutdown"') for rname in ["r1", "r2", "r3", "r4"]: compare_ted_json_output(tgen, rname, "ted_step2.json") @@ -227,28 +220,27 @@ def test_step5(): tgen = setup_testcase("Step5: Re-enable interface between r1 & r2") - tgen.net["r1"].cmd('vtysh -c "conf t" -c "interface r1-eth1" -c "no shutdown"') - tgen.net["r2"].cmd('vtysh -c "conf t" -c "interface r2-eth1" -c "no shutdown"') + tgen.net["r1"].cmd('vtysh -c "conf t" -c "interface eth1" -c "no shutdown"') for rname in ["r1", "r2", "r3", "r4"]: compare_ted_json_output(tgen, rname, "ted_step5.json") def test_step6(): - "Step6: Set delay and jitter for interface r4-eth0 on r4, remove use-bw \ - for interface r2-eth3 on r2 and verify that corresponding Edges are \ + "Step6: Set delay and jitter for interface eth0 on r4, remove use-bw \ + for interface eth3 on r2 and verify that corresponding Edges are \ updated in the TED on all routers" tgen = setup_testcase("Step6: Modify link parameters on r2 & r4") tgen.net["r2"].cmd( - 'vtysh -c "conf t" -c "interface r2-eth3" -c "link-params" -c "no use-bw"' + 'vtysh -c "conf t" -c "interface eth3" -c "link-params" -c "no use-bw"' ) tgen.net["r4"].cmd( - 'vtysh -c "conf t" -c "interface r4-eth0" -c "link-params" -c "delay 20000"' + 'vtysh -c "conf t" -c "interface eth0" -c "link-params" -c "delay 20000"' ) tgen.net["r4"].cmd( - 'vtysh -c "conf t" -c "interface r4-eth0" -c "link-params" -c "delay-variation 10000"' + 'vtysh -c "conf t" -c "interface eth0" -c "link-params" -c "delay-variation 10000"' ) for rname in ["r1", "r2", "r3", "r4"]: diff --git a/tests/topotests/ospf_topo1/r1/ospf6d.conf b/tests/topotests/ospf_topo1/r1/ospf6d.conf index ca3497b4a5..0e6c7dadfb 100644 --- a/tests/topotests/ospf_topo1/r1/ospf6d.conf +++ b/tests/topotests/ospf_topo1/r1/ospf6d.conf @@ -4,10 +4,12 @@ router ospf6 redistribute kernel redistribute connected redistribute static - interface r1-eth0 area 0.0.0.0 - interface r1-eth1 area 0.0.0.0 +! +interface r1-eth0 + ipv6 ospf6 area 0.0.0.0 ! int r1-eth1 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 dead-interval 10 ipv6 ospf6 hello-interval 2 ! diff --git a/tests/topotests/ospf_topo1/r2/ospf6d.conf b/tests/topotests/ospf_topo1/r2/ospf6d.conf index 44047e1a4e..f6a1f50530 100644 --- a/tests/topotests/ospf_topo1/r2/ospf6d.conf +++ b/tests/topotests/ospf_topo1/r2/ospf6d.conf @@ -4,14 +4,14 @@ router ospf6 redistribute kernel redistribute connected redistribute static - interface r2-eth0 area 0.0.0.0 - interface r2-eth1 area 0.0.0.0 ! int r2-eth0 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 10 ! int r2-eth1 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 10 ! diff --git a/tests/topotests/ospf_topo1/r3/ospf6d.conf b/tests/topotests/ospf_topo1/r3/ospf6d.conf index 13ad9a7356..278a016968 100644 --- a/tests/topotests/ospf_topo1/r3/ospf6d.conf +++ b/tests/topotests/ospf_topo1/r3/ospf6d.conf @@ -4,19 +4,19 @@ router ospf6 redistribute kernel redistribute connected redistribute static - interface r3-eth0 area 0.0.0.0 - interface r3-eth1 area 0.0.0.0 - interface r3-eth2 area 0.0.0.1 ! int r3-eth0 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 10 ! int r3-eth1 + ipv6 ospf6 area 0.0.0.0 ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 10 ! int r3-eth2 + ipv6 ospf6 area 0.0.0.1 ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 10 ! diff --git a/tests/topotests/ospf_topo1/r4/ospf6d.conf b/tests/topotests/ospf_topo1/r4/ospf6d.conf index f9bde0e83c..777dd0b7b7 100644 --- a/tests/topotests/ospf_topo1/r4/ospf6d.conf +++ b/tests/topotests/ospf_topo1/r4/ospf6d.conf @@ -4,14 +4,14 @@ router ospf6 redistribute kernel redistribute connected redistribute static - interface r4-eth0 area 0.0.0.1 - interface r4-eth1 area 0.0.0.1 ! int r4-eth0 + ipv6 ospf6 area 0.0.0.1 ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 10 ! int r4-eth1 + ipv6 ospf6 area 0.0.0.1 ipv6 ospf6 hello-interval 2 ipv6 ospf6 dead-interval 10 ! diff --git a/tests/topotests/ospf_topo2/__init__.py b/tests/topotests/ospf_topo2/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/ospf_topo2/r1/frr.conf b/tests/topotests/ospf_topo2/r1/frr.conf new file mode 100644 index 0000000000..9bc3361859 --- /dev/null +++ b/tests/topotests/ospf_topo2/r1/frr.conf @@ -0,0 +1,61 @@ +frr defaults traditional +hostname r1 +log syslog informational +service integrated-vtysh-config +! +ip router-id 192.0.2.1 +! +interface eth1 + ip address 192.0.2.1/32 + ip ospf area 0.0.0.0 + ip ospf dead-interval minimal hello-multiplier 4 + ip ospf network point-to-point + ipv6 address 2001:db8::1/128 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 dead-interval 4 + ipv6 ospf6 hello-interval 1 + ipv6 ospf6 network point-to-point +exit +! +interface eth2 + ip address 192.0.2.1/32 + ip ospf area 0.0.0.0 + ip ospf dead-interval minimal hello-multiplier 4 + ip ospf network point-to-point + ipv6 address 2001:db8::1/128 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 dead-interval 4 + ipv6 ospf6 hello-interval 1 + ipv6 ospf6 network point-to-point +exit +! +interface eth3 + ip address 192.0.2.1/32 + ip ospf area 0.0.0.0 + ip ospf dead-interval minimal hello-multiplier 4 + ip ospf network point-to-point + ipv6 address 2001:db8::1/128 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 dead-interval 4 + ipv6 ospf6 hello-interval 1 + ipv6 ospf6 network point-to-point +exit +! +interface lo + ip address 192.0.2.1/32 + ip ospf area 0.0.0.0 + ip ospf passive + ipv6 address 2001:db8::1/128 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 passive +exit +! +router ospf + log-adjacency-changes +exit +! +router ospf6 + log-adjacency-changes +exit +! +end \ No newline at end of file diff --git a/tests/topotests/ospf_topo2/r2/frr.conf b/tests/topotests/ospf_topo2/r2/frr.conf new file mode 100644 index 0000000000..d2ffb73377 --- /dev/null +++ b/tests/topotests/ospf_topo2/r2/frr.conf @@ -0,0 +1,61 @@ +frr defaults traditional +hostname r2 +log syslog informational +service integrated-vtysh-config +! +ip router-id 192.0.2.2 +! +interface eth1 + ip address 192.0.2.2/32 + ip ospf area 0.0.0.0 + ip ospf dead-interval minimal hello-multiplier 4 + ip ospf network point-to-point + ipv6 address 2001:db8::2/128 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 dead-interval 4 + ipv6 ospf6 hello-interval 1 + ipv6 ospf6 network point-to-point +exit +! +interface eth2 + ip address 192.0.2.2/32 + ip ospf area 0.0.0.0 + ip ospf dead-interval minimal hello-multiplier 4 + ip ospf network point-to-point + ipv6 address 2001:db8::2/128 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 dead-interval 4 + ipv6 ospf6 hello-interval 1 + ipv6 ospf6 network point-to-point +exit +! +interface eth3 + ip address 192.0.2.2/32 + ip ospf area 0.0.0.0 + ip ospf dead-interval minimal hello-multiplier 4 + ip ospf network point-to-point + ipv6 address 2001:db8::2/128 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 dead-interval 4 + ipv6 ospf6 hello-interval 1 + ipv6 ospf6 network point-to-point +exit +! +interface lo + ip address 192.0.2.2/32 + ip ospf area 0.0.0.0 + ip ospf passive + ipv6 address 2001:db8::2/128 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 passive +exit +! +router ospf + log-adjacency-changes +exit +! +router ospf6 + log-adjacency-changes +exit +! +end \ No newline at end of file diff --git a/tests/topotests/ospf_topo2/r3/frr.conf b/tests/topotests/ospf_topo2/r3/frr.conf new file mode 100644 index 0000000000..e87b8972f0 --- /dev/null +++ b/tests/topotests/ospf_topo2/r3/frr.conf @@ -0,0 +1,61 @@ +frr defaults traditional +hostname r3 +log syslog informational +service integrated-vtysh-config +! +ip router-id 192.0.2.3 +! +interface eth1 + ip address 192.0.2.3/32 + ip ospf area 0.0.0.0 + ip ospf dead-interval minimal hello-multiplier 4 + ip ospf network point-to-point + ipv6 address 2001:db8::3/128 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 dead-interval 4 + ipv6 ospf6 hello-interval 1 + ipv6 ospf6 network point-to-point +exit +! +interface eth2 + ip address 192.0.2.3/32 + ip ospf area 0.0.0.0 + ip ospf dead-interval minimal hello-multiplier 4 + ip ospf network point-to-point + ipv6 address 2001:db8::3/128 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 dead-interval 4 + ipv6 ospf6 hello-interval 1 + ipv6 ospf6 network point-to-point +exit +! +interface eth3 + ip address 192.0.2.3/32 + ip ospf area 0.0.0.0 + ip ospf dead-interval minimal hello-multiplier 4 + ip ospf network point-to-point + ipv6 address 2001:db8::3/128 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 dead-interval 4 + ipv6 ospf6 hello-interval 1 + ipv6 ospf6 network point-to-point +exit +! +interface lo + ip address 192.0.2.3/32 + ip ospf area 0.0.0.0 + ip ospf passive + ipv6 address 2001:db8::3/128 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 passive +exit +! +router ospf + log-adjacency-changes +exit +! +router ospf6 + log-adjacency-changes +exit +! +end \ No newline at end of file diff --git a/tests/topotests/ospf_topo2/r4/frr.conf b/tests/topotests/ospf_topo2/r4/frr.conf new file mode 100644 index 0000000000..4e33d75299 --- /dev/null +++ b/tests/topotests/ospf_topo2/r4/frr.conf @@ -0,0 +1,61 @@ +frr defaults traditional +hostname r4 +log syslog informational +service integrated-vtysh-config +! +ip router-id 192.0.2.4 +! +interface eth1 + ip address 192.0.2.4/32 + ip ospf area 0.0.0.0 + ip ospf dead-interval minimal hello-multiplier 4 + ip ospf network point-to-point + ipv6 address 2001:db8::4/128 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 dead-interval 4 + ipv6 ospf6 hello-interval 1 + ipv6 ospf6 network point-to-point +exit +! +interface eth2 + ip address 192.0.2.4/32 + ip ospf area 0.0.0.0 + ip ospf dead-interval minimal hello-multiplier 4 + ip ospf network point-to-point + ipv6 address 2001:db8::4/128 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 dead-interval 4 + ipv6 ospf6 hello-interval 1 + ipv6 ospf6 network point-to-point +exit +! +interface eth3 + ip address 192.0.2.4/32 + ip ospf area 0.0.0.0 + ip ospf dead-interval minimal hello-multiplier 4 + ip ospf network point-to-point + ipv6 address 2001:db8::4/128 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 dead-interval 4 + ipv6 ospf6 hello-interval 1 + ipv6 ospf6 network point-to-point +exit +! +interface lo + ip address 192.0.2.4/32 + ip ospf area 0.0.0.0 + ip ospf passive + ipv6 address 2001:db8::4/128 + ipv6 ospf6 area 0.0.0.0 + ipv6 ospf6 passive +exit +! +router ospf + log-adjacency-changes +exit +! +router ospf6 + log-adjacency-changes +exit +! +end \ No newline at end of file diff --git a/tests/topotests/ospf_topo2/test_ospf_topo2.dot b/tests/topotests/ospf_topo2/test_ospf_topo2.dot new file mode 100644 index 0000000000..e35afbbaad --- /dev/null +++ b/tests/topotests/ospf_topo2/test_ospf_topo2.dot @@ -0,0 +1,44 @@ +graph template { + label="ospf_topo2"; + splines = "line" + + # Routers + r1 [ + shape=doubleoctagon, + label="r1\n192.0.2.1\n2001:db8::1", + fillcolor="#f08080", + style=filled, + ]; + r2 [ + shape=doubleoctagon, + label="r2\n\192.0.2.2\n2001:db8::2", + fillcolor="#f08080", + style=filled, + ]; + r3 [ + shape=doubleoctagon, + label="r3\n192.0.2.3\n2001:db8::3", + fillcolor="#f08080", + style=filled, + ]; + r4 [ + shape=doubleoctagon, + label="r4\n192.0.2.4\n2001:db8::4", + fillcolor="#f08080", + style=filled, + ]; + + # Connections + r1 -- r2 [label="eth1"]; + r1 -- r2 [label="eth2"]; + + r2 -- r3 [label="eth3\neth1"]; + r1 -- r4 [label="eth3\neth1"]; + + r4 -- r3 [label="eth2"]; + r4 -- r3 [label="eth3"]; + + # Group r1 and r2 above, r3 and r4 below + { rank=min; r1; r2; } + { rank=max; r3; r4; } +} diff --git a/tests/topotests/ospf_topo2/test_ospf_topo2.png b/tests/topotests/ospf_topo2/test_ospf_topo2.png new file mode 100644 index 0000000000..7eb0a1d684 Binary files /dev/null and b/tests/topotests/ospf_topo2/test_ospf_topo2.png differ diff --git a/tests/topotests/ospf_topo2/test_ospf_topo2.py b/tests/topotests/ospf_topo2/test_ospf_topo2.py new file mode 100644 index 0000000000..8be06e41af --- /dev/null +++ b/tests/topotests/ospf_topo2/test_ospf_topo2.py @@ -0,0 +1,317 @@ +#!/usr/bin/env python +# -*- coding: utf-8 eval: (blacken-mode 1) -*- +# SPDX-License-Identifier: ISC +# +# test_ospf_topo2.py +# Part of NetDEF Topology Tests +# +# Copyright (c) 2017 by +# Network Device Education Foundation, Inc. ("NetDEF") +# + +""" +test_ospf_topo2.py: Test correct route removal. + +Proofs the following issue: +https://github.com/FRRouting/frr/issues/14488 + +""" + +import ipaddress +import json +import pytest +import sys +import time + +from lib.topogen import Topogen + + +pytestmark = [ + pytest.mark.ospf6d, + pytest.mark.ospfd, +] + + +def build_topo(tgen): + """Build the topology used by all tests below.""" + + # Create 4 routers + r1 = tgen.add_router("r1") + r2 = tgen.add_router("r2") + r3 = tgen.add_router("r3") + r4 = tgen.add_router("r4") + + # The r1/r2 and r3/r4 router pairs have two connections each + tgen.add_link(r1, r2, ifname1="eth1", ifname2="eth1") + tgen.add_link(r1, r2, ifname1="eth2", ifname2="eth2") + tgen.add_link(r3, r4, ifname1="eth2", ifname2="eth2") + tgen.add_link(r3, r4, ifname1="eth3", ifname2="eth3") + + # The r1/r4 and r2/r3 router pairs have one connection each + tgen.add_link(r1, r4, ifname1="eth3", ifname2="eth1") + tgen.add_link(r2, r3, ifname1="eth3", ifname2="eth1") + + +@pytest.fixture(scope="function") +def tgen(request): + """Setup/Teardown the environment and provide tgen argument to tests. + + Do this once per function as some of the tests will leave the router + in an unclean state. + + """ + + tgen = Topogen(build_topo, request.module.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for rname, router in router_list.items(): + router.load_frr_config("frr.conf") + + tgen.start_router() + + yield tgen + + tgen.stop_topology() + + +def ospf_neighbors(router, ip_version): + """List the OSPF neighbors for the given router and IP version.""" + + if ip_version == 4: + cmd = "show ip ospf neighbor json" + else: + cmd = "show ipv6 ospf neighbor json" + + output = router.vtysh_cmd(cmd) + + if ip_version == 4: + return [v for n in json.loads(output)["neighbors"].values() for v in n] + else: + return json.loads(output)["neighbors"] + + +def ospf_neighbor_uptime(router, interface, ip_version): + """Uptime of the neighbor with the given interface name in seconds.""" + + for neighbor in ospf_neighbors(router, ip_version): + if ip_version == 4: + if not neighbor["ifaceName"].startswith("{}:".format(interface)): + continue + + return neighbor["upTimeInMsec"] / 1000 + else: + if neighbor["interfaceName"] != interface: + continue + + h, m, s = [int(d) for d in neighbor["duration"].split(":")] + return h * 3600 + m * 60 + s + + raise KeyError( + "No IPv{} neighbor with interface name {} on {}".format( + ip_version, interface, router.name + ) + ) + + +def ospf_routes(router, prefix): + """List the OSPF routes for the given router and prefix.""" + + if ipaddress.ip_interface(prefix).ip.version == 4: + cmd = "show ip route {} json" + else: + cmd = "show ipv6 route {} json" + + output = router.vtysh_cmd(cmd.format(prefix)) + return json.loads(output)[prefix] + + +def ospf_nexthops(router, prefix, protocol): + """List the OSPF nexthops for the given prefix.""" + + for route in ospf_routes(router, prefix): + if route["protocol"] != protocol: + continue + + for nexthop in route["nexthops"]: + yield nexthop + + +def ospf_directly_connected_interfaces(router, ip_version): + """The names of the directly connected interfaces, as discovered + through the OSPF nexthops. + + """ + + if ip_version == 4: + prefix = "192.0.2.{}/32".format(router.name.strip("r")) + else: + prefix = "fe80::/64" + + hops = ospf_nexthops(router, prefix, protocol="connected") + return sorted([n["interfaceName"] for n in hops if n["directlyConnected"]]) + + +def wait_for_ospf(router, ip_version, neighbors, timeout=60): + """Wait until the router has the given number of neighbors that are + fully converged. + + Note that this checks for the exact number of neighbors, so if one neighbor + is requested and three are converged, the wait continues. + + """ + + until = time.monotonic() + timeout + + if ip_version == 4: + filter = {"converged": "Full"} + else: + filter = {"state": "Full"} + + def is_match(neighbor): + for k, v in filter.items(): + if neighbor[k] != v: + return False + + return True + + while time.monotonic() < until: + found = sum(1 for n in ospf_neighbors(router, ip_version) if is_match(n)) + + if neighbors == found: + return + + raise TimeoutError( + "Waited over {}s for {} neighbors to reach {}".format( + timeout, neighbors, filter + ) + ) + + +@pytest.mark.parametrize("ip_version", [4, 6]) +def test_interface_up(tgen, ip_version): + """Verify the initial routing table, before any changes.""" + + # Wait for the routers to be ready + routers = {id: tgen.gears[id] for id in ("r1", "r2", "r3", "r4")} + + for router in routers.values(): + wait_for_ospf(router, ip_version=ip_version, neighbors=3) + + # Verify that the link-local routes are correct + for router in routers.values(): + connected = ospf_directly_connected_interfaces(router, ip_version) + + if ip_version == 4: + expected = ["eth1", "eth2", "eth3", "lo"] + else: + expected = ["eth1", "eth2", "eth3"] + + assert ( + connected == expected + ), "Expected all interfaces to be connected on {}".format(router.name) + + +@pytest.mark.parametrize("ip_version", [4, 6]) +def test_interface_down(tgen, ip_version): + """Verify the routing table after taking interfaces down.""" + + # Wait for the routers to be ready + routers = {id: tgen.gears[id] for id in ("r1", "r2", "r3", "r4")} + + for id, router in routers.items(): + wait_for_ospf(router, ip_version=ip_version, neighbors=3) + + # Keep track of the uptime of the eth3 neighbor + uptime = ospf_neighbor_uptime(routers["r1"], "eth3", ip_version) + before = time.monotonic() + + # Take the links between r1 and r2 down + routers["r1"].cmd_raises("ip link set down dev eth1") + routers["r1"].cmd_raises("ip link set down dev eth2") + + # Wait for OSPF to converge + wait_for_ospf(routers["r1"], ip_version=ip_version, neighbors=1) + + # The uptime of the unaffected eth3 neighbor should be monotonic + new_uptime = ospf_neighbor_uptime(routers["r1"], "eth3", ip_version) + took = round(time.monotonic() - before, 3) + + # IPv6 has a resolution of 1s, for IPv4 some slack is necesssary. + if ip_version == 4: + offset = 0.25 + else: + offset = 1 + + assert ( + new_uptime + offset >= uptime + took + ), "The eth3 neighbor uptime must not decrease" + + # We should only find eth3 once OSPF has converged + connected = ospf_directly_connected_interfaces(routers["r1"], ip_version) + + if ip_version == 4: + expected = ["eth3", "lo"] + else: + expected = ["eth3"] + + assert connected == expected, "Expected only eth1 and eth2 to be disconnected" + + +@pytest.mark.parametrize("ip_version", [4, 6]) +def test_interface_flap(tgen, ip_version): + """Verify the routing table after enabling an interface that was down.""" + + # Wait for the routers to be ready + routers = {id: tgen.gears[id] for id in ("r1", "r2", "r3", "r4")} + + for id, router in routers.items(): + wait_for_ospf(router, ip_version=ip_version, neighbors=3) + + # Keep track of the uptime of the eth3 neighbor + uptime = ospf_neighbor_uptime(routers["r1"], "eth3", ip_version) + before = time.monotonic() + + # Take the links between r1 and r2 down + routers["r1"].cmd_raises("ip link set down dev eth1") + routers["r2"].cmd_raises("ip link set down dev eth2") + + # Wait for OSPF to converge + wait_for_ospf(routers["r1"], ip_version=ip_version, neighbors=1) + + # Take the links between r1 and r2 up + routers["r1"].cmd_raises("ip link set up dev eth1") + routers["r2"].cmd_raises("ip link set up dev eth2") + + # Wait for OSPF to converge + wait_for_ospf(routers["r1"], ip_version=ip_version, neighbors=3) + + # The uptime of the unaffected eth3 neighbor should be monotonic + new_uptime = ospf_neighbor_uptime(routers["r1"], "eth3", ip_version) + took = round(time.monotonic() - before, 3) + + # IPv6 has a resolution of 1s, for IPv4 some slack is necesssary. + if ip_version == 4: + offset = 0.25 + else: + offset = 1 + + assert ( + new_uptime + offset >= uptime + took + ), "The eth3 neighbor uptime must not decrease" + + # We should find all interfaces again + connected = ospf_directly_connected_interfaces(routers["r1"], ip_version) + + if ip_version == 4: + expected = ["eth1", "eth2", "eth3", "lo"] + else: + expected = ["eth1", "eth2", "eth3"] + + assert connected == expected, "Expected all interfaces to be connected" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/ospfapi/test_ospf_clientapi.py b/tests/topotests/ospfapi/test_ospf_clientapi.py index 39ebbcfb62..41c18df7d3 100644 --- a/tests/topotests/ospfapi/test_ospf_clientapi.py +++ b/tests/topotests/ospfapi/test_ospf_clientapi.py @@ -17,6 +17,7 @@ import sys import time from datetime import datetime, timedelta +from functools import partial import pytest from lib.common_config import ( @@ -31,6 +32,12 @@ from lib.topogen import Topogen, TopoRouter from lib.topotest import interface_set_status, json_cmp +# pylint: disable=C0413 +# Import topogen and topotest helpers +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger + pytestmark = [pytest.mark.ospfd] CWD = os.path.dirname(os.path.realpath(__file__)) @@ -1142,6 +1149,573 @@ def test_ospf_opaque_restart(tgen): _test_opaque_add_restart_add(tgen, apibin) +def _test_opaque_interface_disable(tgen, apibin): + "Test disabling opaque capability on an interface" + + r1 = tgen.gears["r1"] + r2 = tgen.gears["r2"] + tc_name = "opaque_interface_disable" + + p = None + pread = None + # Log to our stdin, stderr + pout = open(os.path.join(r1.net.logdir, "r1/intf-disable.log"), "a+") + try: + # STEP 1 in test_ospf_opaque_interface_disable and STEP 56 in CI tests + step("Disable OSPF opaque LSA Copability on r1's interface to r2") + r1.vtysh_multicmd("conf t\ninterface r1-eth0\nno ip ospf capability opaque") + time.sleep(15) + + # STEP 2 in test_ospf_opaque_interface_disable and STEP 57 in CI tests + step("Verify the r1 configuration of 'no ip ospf capability opaque'") + no_capability_opaque_cfg = ( + tgen.net["r1"] + .cmd( + 'vtysh -c "show running ospfd" | grep "^ no ip ospf capability opaque"' + ) + .rstrip() + ) + assertmsg = ( + "'no ip ospf capability opaque' applied, but not present in configuration" + ) + assert no_capability_opaque_cfg == " no ip ospf capability opaque", assertmsg + + # STEP 3 in test_ospf_opaque_interface_disable and STEP 58 in CI tests + step("Verify the ospf opaque option is not applied to the r1 interface") + r1_interface_without_opaque = { + "interfaces": { + "r1-eth0": { + "ifUp": True, + "ospfEnabled": True, + "ipAddress": "10.0.1.1", + "ospfIfType": "Broadcast", + "opaqueCapable": False, + } + } + } + r1_interface_with_opaque = { + "interfaces": { + "r1-eth0": { + "ifUp": True, + "ospfEnabled": True, + "ipAddress": "10.0.1.1", + "ospfIfType": "Broadcast", + "opaqueCapable": True, + } + } + } + test_func = partial( + topotest.router_json_cmp, + r1, + "show ip ospf interface json", + r1_interface_without_opaque, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "r1 OSPF interface doesn't have opaque capability disabled" + assert result is None, assertmsg + + r1_neighbor_without_opaque = { + "neighbors": { + "2.0.0.0": [ + { + "optionsList": "*|-|-|-|-|-|E|-", + } + ] + } + } + r2_neighbor_without_opaque = { + "neighbors": { + "1.0.0.0": [ + { + "optionsList": "*|-|-|-|-|-|E|-", + } + ] + } + } + # STEP 4 in test_ospf_opaque_interface_disable and STEP 59 in CI tests + step("Verify that the r1 neighbor options don't include opaque") + test_func = partial( + topotest.router_json_cmp, + r1, + "show ip ospf neighbor detail json", + r1_neighbor_without_opaque, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "r1 OSPF neighbor has opaque option in optionsList" + assert result is None, assertmsg + + # STEP 5 in test_ospf_opaque_interface_disable and STEP 60 in CI tests + step("Verify that the r1 neighbor options don't include opaque") + test_func = partial( + topotest.router_json_cmp, + r2, + "show ip ospf neighbor detail json", + r2_neighbor_without_opaque, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "r2 OSPF neighbor has opaque option in optionsList" + assert result is None, assertmsg + + # STEP 6 in test_ospf_opaque_interface_disable and STEP 61 in CI tests + step( + "Verify no r2 configuration of 'no ip ospf capability opaque' in r2 configuration" + ) + rc, _, _ = tgen.net["r2"].cmd_status( + "show running ospfd | grep -q 'ip ospf capability opaque'", warn=False + ) + assertmsg = "'no ip ospf capability opaque' not applied, but not present in r2 configuration" + assert rc, assertmsg + + # STEP 7 in test_ospf_opaque_interface_disable and STEP 62 in CI tests + step("Verify the ospf opaque option is applied to the r2 interface") + r2_interface_without_opaque = { + "interfaces": { + "r2-eth0": { + "ifUp": True, + "ospfEnabled": True, + "ipAddress": "10.0.1.2", + "ospfIfType": "Broadcast", + "opaqueCapable": False, + } + } + } + r2_interface_with_opaque = { + "interfaces": { + "r2-eth0": { + "ifUp": True, + "ospfEnabled": True, + "ipAddress": "10.0.1.2", + "ospfIfType": "Broadcast", + "opaqueCapable": True, + } + } + } + test_func = partial( + topotest.router_json_cmp, + r2, + "show ip ospf interface json", + r2_interface_with_opaque, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "r2 OSPF interface has opaque capability disabled" + assert result is None, assertmsg + + # STEP 8 in test_ospf_opaque_interface_disable and STEP 63 in CI tests + step("Install opaque LSAs on r1") + pread = r2.popen( + ["/usr/bin/timeout", "120", apibin, "-v", "--logtag=READER", "wait,120"], + encoding=None, # don't buffer + stdin=subprocess.DEVNULL, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + ) + p = r1.popen( + [ + apibin, + "-v", + "add,9,10.0.1.1,230,1,feedaceedeadbeef", + "add,10,1.2.3.4,231,1,feedaceecafebeef", + "add,11,232,1,feedaceebaddbeef", + "wait,20", + ] + ) + opaque_LSAs_in_database = { + "areas": { + "1.2.3.4": { + "linkLocalOpaqueLsa": [ + { + "lsId": "230.0.0.1", + "advertisedRouter": "1.0.0.0", + "sequenceNumber": "80000001", + }, + ], + "linkLocalOpaqueLsaCount": 1, + "areaLocalOpaqueLsa": [ + { + "lsId": "231.0.0.1", + "advertisedRouter": "1.0.0.0", + "sequenceNumber": "80000001", + }, + ], + "areaLocalOpaqueLsaCount": 1, + }, + }, + "asExternalOpaqueLsa": [ + { + "lsId": "232.0.0.1", + "advertisedRouter": "1.0.0.0", + "sequenceNumber": "80000001", + }, + ], + "asExternalOpaqueLsaCount": 1, + } + opaque_area_empty_database = { + "routerId": "2.0.0.0", + "areaLocalOpaqueLsa": {"areas": {"1.2.3.4": []}}, + } + + # STEP 9 in test_ospf_opaque_interface_disable and STEP 64 in CI tests + step("Check that LSAs are added on r1") + test_func = partial( + topotest.router_json_cmp, + r1, + "show ip ospf database json", + opaque_LSAs_in_database, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "r1 OSPF database doesn't contain opaque LSAs" + assert result is None, assertmsg + + # STEP 10 in test_ospf_opaque_interface_disable and STEP 65 in CI tests + step("Check that LSAs are not added on r2") + test_func = partial( + topotest.router_json_cmp, + r2, + "show ip ospf database opaque-area json", + opaque_area_empty_database, + True, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "r2 OSPF area database contains opaque LSAs" + assert result is None, assertmsg + + # STEP 11 in test_ospf_opaque_interface_disable and STEP 66 in CI tests + step("Enable OSPF opaque LSA Copability on r1's interface to r2") + r1.vtysh_multicmd("conf t\ninterface r1-eth0\nip ospf capability opaque") + time.sleep(15) + + # STEP 12 in test_ospf_opaque_interface_disable and STEP 67 in CI tests + step("Verify no r1 configuration of 'no ip ospf capability opaque'") + rc, _, _ = tgen.net["r1"].cmd_status( + "show running ospfd | grep -q 'ip ospf capability opaque'", warn=False + ) + assertmsg = "'no ip ospf capability opaque' not applied, but not present in r1 configuration" + assert rc, assertmsg + + # STEP 13 in test_ospf_opaque_interface_disable and STEP 68 in CI tests + step("Verify the ospf opaque option is applied to the r1 interface") + test_func = partial( + topotest.router_json_cmp, + r1, + "show ip ospf interface json", + r1_interface_with_opaque, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "r1 OSPF interface doesn't have opaque capability disabled" + assert result is None, assertmsg + + r1_neighbor_with_opaque = { + "neighbors": { + "2.0.0.0": [ + { + "optionsList": "*|O|-|-|-|-|E|-", + } + ] + } + } + r2_neighbor_with_opaque = { + "neighbors": { + "1.0.0.0": [ + { + "optionsList": "*|O|-|-|-|-|E|-", + } + ] + } + } + # STEP 14 in test_ospf_opaque_interface_disable and STEP 69 in CI tests + step("Verify that the r1 neighbor options include opaque") + test_func = partial( + topotest.router_json_cmp, + r1, + "show ip ospf neighbor detail json", + r1_neighbor_with_opaque, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "r1 OSPF neighbor doesn't have opaque option in optionsList" + assert result is None, assertmsg + + # STEP 15 in test_ospf_opaque_interface_disable and STEP 70 in CI tests + step("Verify that the r2 neighbor options include opaque") + test_func = partial( + topotest.router_json_cmp, + r2, + "show ip ospf neighbor detail json", + r2_neighbor_with_opaque, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "r2 OSPF neighbor doesn't have opaque option in optionsList" + assert result is None, assertmsg + + # STEP 16 in test_ospf_opaque_interface_disable and STEP 71 in CI tests + step("Check that LSAs are now added to r2") + test_func = partial( + topotest.router_json_cmp, + r2, + "show ip ospf database json", + opaque_LSAs_in_database, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "r2 OSPF database doesn't contains opaque LSAs" + assert result is None, assertmsg + + # STEP 17 in test_ospf_opaque_interface_disable and STEP 72 in CI tests + step( + "Disable Opaque Capability on r2's interface to r1 using the interface address" + ) + r2.vtysh_multicmd( + "conf t\ninterface r2-eth0\nno ip ospf capability opaque 10.0.1.2" + ) + + # STEP 18 in test_ospf_opaque_interface_disable and STEP 73 in CI tests + step("Clear the OSPF process on r2 to clear the OSPF LSDB") + r2.vtysh_multicmd("clear ip ospf process") + time.sleep(15) + + # STEP 19 in test_ospf_opaque_interface_disable and STEP 74 in CI tests + step("Verify the r2 configuration of 'no ip ospf capability opaque 10.0.1.2'") + no_capability_opaque_cfg = ( + tgen.net["r2"] + .cmd_nostatus( + 'vtysh -c "show running ospfd" | grep "^ no ip ospf capability opaque 10.0.1.2"' + ) + .rstrip() + ) + assertmsg = "'no ip ospf capability opaque 10.0.1.2' applied, but not present in configuration" + assert ( + no_capability_opaque_cfg == " no ip ospf capability opaque 10.0.1.2" + ), assertmsg + + # STEP 20 in test_ospf_opaque_interface_disable and STEP 75 in CI tests + step("Verify the ospf opaque option is not applied to the r2 interface") + test_func = partial( + topotest.router_json_cmp, + r2, + "show ip ospf interface json", + r2_interface_without_opaque, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "r1 OSPF interface doesn't have opaque capability disabled" + assert result is None, assertmsg + + # STEP 21 in test_ospf_opaque_interface_disable and STEP 76 in CI tests + step("Verify that the r1 neighbor options don't include opaque") + test_func = partial( + topotest.router_json_cmp, + r1, + "show ip ospf neighbor detail json", + r1_neighbor_without_opaque, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "r1 OSPF neighbor has opaque option in optionsList" + assert result is None, assertmsg + + # STEP 22 in test_ospf_opaque_interface_disable and STEP 77 in CI tests + step("Verify that the r2 neighbor options don't include opaque") + test_func = partial( + topotest.router_json_cmp, + r2, + "show ip ospf neighbor detail json", + r2_neighbor_without_opaque, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "r2 OSPF neighbor has opaque option in optionsList" + assert result is None, assertmsg + + # STEP 23 in test_ospf_opaque_interface_disable and STEP 78 in CI tests + step("Verify that r1 still has the opaque LSAs") + test_func = partial( + topotest.router_json_cmp, + r1, + "show ip ospf database json", + opaque_LSAs_in_database, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "r1 OSPF database doesn't contain opaque LSAs" + assert result is None, assertmsg + + # STEP 24 in test_ospf_opaque_interface_disable and STEP 79 in CI tests + step("Verify that r2 doesn't have the opaque LSAs") + test_func = partial( + topotest.router_json_cmp, + r2, + "show ip ospf database opaque-area json", + opaque_area_empty_database, + True, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "r2 OSPF area database contains opaque LSAs" + assert result is None, assertmsg + + # STEP 25 in test_ospf_opaque_interface_disable and STEP 80 in CI tests + step("Remove the 'no ip ospf capability opaque 10.0.1.2' config from r2 ") + r2.vtysh_multicmd( + "conf t\ninterface r2-eth0\nip ospf capability opaque 10.0.1.2" + ) + time.sleep(15) + + # STEP 26 in test_ospf_opaque_interface_disable and STEP 81 in CI tests + step("Verify the r2 removal of 'no ip ospf capability opaque 10.0.1.2'") + rc, _, _ = tgen.net["r2"].cmd_status( + "show running ospfd | grep -q 'ip ospf capability opaque'", warn=False + ) + assertmsg = "'no ip ospf capability opaque' not applied, but not present in r2 configuration" + assert rc, assertmsg + + # STEP 27 in test_ospf_opaque_interface_disable and STEP 82 in CI tests + step("Verify the ospf opaque option is applied to the r2 interface") + test_func = partial( + topotest.router_json_cmp, + r2, + "show ip ospf interface json", + r2_interface_with_opaque, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "r2 OSPF interface doesn't have opaque capability disabled" + assert result is None, assertmsg + + # STEP 28 in test_ospf_opaque_interface_disable and STEP 83 in CI tests + step("Verify that the r2 neighbor options include opaque") + test_func = partial( + topotest.router_json_cmp, + r2, + "show ip ospf neighbor detail json", + r2_neighbor_with_opaque, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "r2 OSPF neighbor doesn't have opaque option in optionsList" + assert result is None, assertmsg + + # STEP 29 in test_ospf_opaque_interface_disable and STEP 84 in CI tests + step("Verify that the r1 neighbor options include opaque") + test_func = partial( + topotest.router_json_cmp, + r1, + "show ip ospf neighbor detail json", + r1_neighbor_with_opaque, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "r1 OSPF neighbor doesn't have opaque option in optionsList" + assert result is None, assertmsg + + # STEP 30 in test_ospf_opaque_interface_disable and STEP 85 in CLI tests + step("Verify that r2 now has the opaque LSAs") + test_func = partial( + topotest.router_json_cmp, + r2, + "show ip ospf database json", + opaque_LSAs_in_database, + ) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) + assertmsg = "r2 OSPF database doesn't contain opaque LSAs" + assert result is None, assertmsg + + except Exception: + if p: + p.terminate() + if p.wait(): + comm_error(p) + p = None + raise + finally: + if pread: + pread.terminate() + pread.wait() + if p: + p.terminate() + p.wait() + + +@pytest.mark.parametrize("tgen", [2], indirect=True) +def test_ospf_opaque_interface_disable(tgen): + apibin = os.path.join(CLIENTDIR, "ospfclient.py") + rc, o, e = tgen.gears["r2"].net.cmd_status([apibin, "--help"]) + logging.debug("%s --help: rc: %s stdout: '%s' stderr: '%s'", apibin, rc, o, e) + _test_opaque_interface_disable(tgen, apibin) + + +def _test_opaque_link_local_lsa_crash(tgen, apibin): + "Test disabling opaque capability on an interface" + + r1 = tgen.gears["r1"] + r2 = tgen.gears["r2"] + tc_name = "opaque_interface_disable" + + p = None + # Log to our stdin, stderr + pout = open(os.path.join(r1.net.logdir, "r1/intf-disable.log"), "a+") + try: + step("Add a link-local opaque LSA for r1-eth0") + pread = r1.popen([apibin, "-v", "add,9,10.0.1.1,230,1,feedaceedeadbeef"]) + + input_dict = { + "linkLocalOpaqueLsa": { + "areas": { + "1.2.3.4": [ + { + "linkStateId": "230.0.0.1", + "advertisingRouter": "1.0.0.0", + "lsaSeqNumber": "80000001", + "opaqueData": "feedaceedeadbeef", + }, + ], + } + }, + } + + # verify content + json_cmd = "show ip ospf da opaque-link json" + assert verify_ospf_database(tgen, r1, input_dict, json_cmd) is None + + step("Shut down r1-eth0 and verify there is no crash") + r1.vtysh_multicmd("conf t\ninterface r1-eth0\nshut") + time.sleep(2) + + step("Bring r1-eth0 back up and verify there is no crash") + r1.vtysh_multicmd("conf t\ninterface r1-eth0\nno shut") + + step("Add another link-local opaque LSA for r1-eth0") + pread = r1.popen([apibin, "-v", "add,9,10.0.1.1,230,1,feedaceecafebeef"]) + + input_dict = { + "linkLocalOpaqueLsa": { + "areas": { + "1.2.3.4": [ + { + "linkStateId": "230.0.0.1", + "advertisingRouter": "1.0.0.0", + "lsaSeqNumber": "80000001", + "opaqueData": "feedaceecafebeef", + }, + ], + } + }, + } + # verify content + json_cmd = "show ip ospf da opaque-link json" + assert verify_ospf_database(tgen, r1, input_dict, json_cmd) is None + + except Exception: + if p: + p.terminate() + if p.wait(): + comm_error(p) + p = None + raise + finally: + if p: + p.terminate() + p.wait() + p = None + + +@pytest.mark.parametrize("tgen", [2], indirect=True) +def test_ospf_opaque_link_local_lsa_crash(tgen): + apibin = os.path.join(CLIENTDIR, "ospfclient.py") + rc, o, e = tgen.gears["r2"].net.cmd_status([apibin, "--help"]) + logging.debug("%s --help: rc: %s stdout: '%s' stderr: '%s'", apibin, rc, o, e) + _test_opaque_link_local_lsa_crash(tgen, apibin) + + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/pbr_topo1/r1/pbr-map.json b/tests/topotests/pbr_topo1/r1/pbr-map.json index bfa0ecb849..aaf2b5e8dc 100644 --- a/tests/topotests/pbr_topo1/r1/pbr-map.json +++ b/tests/topotests/pbr_topo1/r1/pbr-map.json @@ -18,7 +18,7 @@ { "sequenceNumber":10, "vrfUnchanged":false, - "installed":true, + "installed":false, "installedReason":"Invalid Src or Dst", "nexthopGroup":{ "name":"C", @@ -98,7 +98,7 @@ { "sequenceNumber":5, "vrfUnchanged":false, - "installed":false, + "installed":true, "installedReason":"Invalid NH-group", "nexthopGroup":{ "name":"B", @@ -111,7 +111,7 @@ { "sequenceNumber":10, "vrfUnchanged":true, - "installed":false, + "installed":true, "installedReason":"Valid", "matchSrc":"1.2.0.0\/16", "matchDst":"3.4.5.0\/24" diff --git a/tests/topotests/pbr_topo1/test_pbr_topo1.py b/tests/topotests/pbr_topo1/test_pbr_topo1.py index a5a29f7e3d..a70f2cc8da 100644 --- a/tests/topotests/pbr_topo1/test_pbr_topo1.py +++ b/tests/topotests/pbr_topo1/test_pbr_topo1.py @@ -8,6 +8,8 @@ # Cumulus Networks, Inc. # Donald Sharp # +# Copyright (c) 2023 LabN Consulting, L.L.C. +# """ test_pbr_topo1.py: Testing PBR @@ -19,6 +21,7 @@ import pytest import json import platform +import re from functools import partial # Save the Current Working Directory to find configuration files. @@ -109,8 +112,29 @@ def test_converge_protocols(): topotest.sleep(5, "Waiting for PBR convergence") +# +# router: r1 +# tag: "show pbr interface" +# cmd: "show pbr interface json" +# expfile: "{}/{}/pbr-interface.json".format(CWD, router.name) +# +def runit(router, tag, cmd, expfile): + logger.info(expfile) + + # Read expected result from file + expected = json.loads(open(expfile).read()) + + # Actual output from router + test_func = partial(topotest.router_json_cmp, router, cmd, expected) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assertmsg = '"{}" mismatches on {}'.format(tag, router.name) + if result is not None: + gather_pbr_data_on_error(router) + assert result is None, assertmsg + + def test_pbr_data(): - "Test PBR 'show ip eigrp'" + "Test PBR" tgen = get_topogen() # Don't run this test if we have any failure. @@ -122,55 +146,190 @@ def test_pbr_data(): router_list = tgen.routers().values() for router in router_list: - intf_file = "{}/{}/pbr-interface.json".format(CWD, router.name) - logger.info(intf_file) + runit( + router, + "show pbr interface", + "show pbr interface json", + "{}/{}/pbr-interface.json".format(CWD, router.name), + ) - # Read expected result from file - expected = json.loads(open(intf_file).read()) + runit( + router, + "show pbr map", + "show pbr map json", + "{}/{}/pbr-map.json".format(CWD, router.name), + ) - # Actual output from router - test_func = partial( - topotest.router_json_cmp, router, "show pbr interface json", expected + runit( + router, + "show pbr nexthop-groups", + "show pbr nexthop-groups json", + "{}/{}/pbr-nexthop-groups.json".format(CWD, router.name), ) - _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) - assertmsg = '"show pbr interface" mismatches on {}'.format(router.name) - if result is not None: - gather_pbr_data_on_error(router) - assert result is None, assertmsg - map_file = "{}/{}/pbr-map.json".format(CWD, router.name) - logger.info(map_file) - # Read expected result from file - expected = json.loads(open(map_file).read()) +######################################################################## +# Field test - START +######################################################################## - # Actual output from router - test_func = partial( - topotest.router_json_cmp, router, "show pbr map json", expected - ) - _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) - assertmsg = '"show pbr map" mismatches on {}'.format(router.name) - if result is not None: - gather_pbr_data_on_error(router) - assert result is None, assertmsg +# +# New fields: +# match ip-protocol (was only tcp|udp, now any value in /etc/protocols) +# match pcp (0-7) +# match vlan (1-4094) +# match vlan (tagged|untagged|untagged-or-zero) +# - nexthop_file = "{}/{}/pbr-nexthop-groups.json".format(CWD, router.name) - logger.info(nexthop_file) +# +# c: command +# cDN: omit default destination IP address (special case) +# tm: must-match pattern +# tN: must Not match pattern +# +# Note we are searching amid a bunch of other rules, so these elements +# should be unique. +# +ftest = [ + {"c": "match ip-protocol icmp", "tm": r"IP protocol Match: 1$"}, + {"c": "no match ip-protocol icmp", "tN": r"IP protocol Match:"}, + {"c": "match pcp 6", "tm": r"PCP Match: 6$"}, + {"c": "match pcp 0", "tm": r"PCP Match: 0$"}, + {"c": "no match pcp 0", "tN": r"PCP Match:"}, + {"c": "match vlan 33", "tm": r"VLAN ID Match: 33$"}, + {"c": "no match vlan 33", "tN": r"VLAN ID Match:"}, + {"c": "match vlan tagged", "tm": r"VLAN Flags Match: tagged$"}, + {"c": "match vlan untagged", "tm": r"VLAN Flags Match: untagged$"}, + {"c": "match vlan untagged-or-zero", "tm": r"VLAN Flags Match: untagged-or-zero$"}, + {"c": "no match vlan tagged", "tN": r"VLAN Flags Match:"}, + {"c": "match src-ip 37.49.22.0/24", "tm": r"SRC IP Match: 37.49.22.0/24$"}, + {"c": "no match src-ip 37.49.22.0/24", "tN": r"SRC IP Match: 37.49.22.0/24$"}, + { + "c": "match dst-ip 38.41.29.0/25", + "cDN": "foo", + "tm": r"DST IP Match: 38.41.29.0/25$", + }, + {"c": "no match dst-ip 38.41.29.0/25", "tN": r"DST IP Match: 38.41.29.0/25$"}, + {"c": "match src-port 117", "tm": r"SRC Port Match: 117$"}, + {"c": "no match src-port 117", "tN": r"SRC Port Match: 117$"}, + {"c": "match dst-port 119", "tm": r"DST Port Match: 119$"}, + {"c": "no match dst-port 119", "tN": r"DST Port Match: 119$"}, + {"c": "match dscp cs3", "tm": r"DSCP Match: 24$"}, + {"c": "no match dscp cs3", "tN": r"DSCP Match: 24$"}, + {"c": "match dscp 5", "tm": r"DSCP Match: 5$"}, + {"c": "no match dscp 5", "tN": r"DSCP Match: 5$"}, + {"c": "match ecn 2", "tm": r"ECN Match: 2$"}, + {"c": "no match ecn 2", "tN": r"ECN Match: 2$"}, + {"c": "match mark 337", "tm": r"MARK Match: 337$"}, + {"c": "no match mark 337", "tN": r"MARK Match: 337$"}, + {"c": "set src-ip 44.100.1.1", "tm": r"Set SRC IP: 44.100.1.1$"}, + {"c": "no set src-ip 44.100.1.1", "tN": r"Set SRC IP: 44.100.1.1$"}, + {"c": "set dst-ip 44.105.1.1", "tm": r"Set DST IP: 44.105.1.1$"}, + {"c": "no set dst-ip 44.105.1.1", "tN": r"Set DST IP: 44.105.1.1$"}, + {"c": "set src-port 41", "tm": r"Set SRC PORT: 41$"}, + {"c": "no set src-port 41", "tN": r"Set SRC PORT: 41$"}, + {"c": "set dst-port 43", "tm": r"Set DST PORT: 43$"}, + {"c": "no set dst-port 43", "tN": r"Set DST PORT: 43$"}, + {"c": "set dscp 24", "tm": r"Set DSCP: 24$"}, + {"c": "no set dscp 24", "tN": r"Set DSCP: 24$"}, + {"c": "set dscp cs7", "tm": r"Set DSCP: 56$"}, + {"c": "no set dscp cs7", "tN": r"Set DSCP: 56$"}, + {"c": "set ecn 1", "tm": r"Set ECN: 1$"}, + {"c": "no set ecn 1", "tN": r"Set ECN: 1$"}, +] + + +# returns None if command output is correct, otherwise returns output +def rtr_field_cmp(rtr, cmd, pat_mustmatch, pat_mustnotmatch): + outstr = rtr.vtysh_cmd(cmd) + if pat_mustmatch is not None: + logger.info("MUSTMATCH: {}".format(pat_mustmatch)) + m = re.search(pat_mustmatch, outstr, flags=re.M) + if not m: + logger.info('Missing MUSTMATCH "{}"'.format(pat_mustmatch)) + return "MISSING MUSTMATCH: " + outstr + if pat_mustnotmatch is not None: + logger.info("MUSTNOTMATCH: {}".format(pat_mustnotmatch)) + m = re.search(pat_mustnotmatch, outstr, flags=re.M) + if m: + logger.info('Has MUSTNOTMATCH "{}"'.format(pat_mustnotmatch)) + return "HAS MUSTNOTMATCH: " + outstr + return None - # Read expected result from file - expected = json.loads(open(nexthop_file).read()) - # Actual output from router - test_func = partial( - topotest.router_json_cmp, router, "show pbr nexthop-groups json", expected - ) - _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) - assertmsg = '"show pbr nexthop-groups" mismatches on {}'.format(router.name) +# +# This test sets fields in pbrd and looks for them in zebra via "sh pbr map" +# +def test_pbr_fields(): + "Test setting and clearing rule fields" + + tgen = get_topogen() + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + logger.info("Verifying PBR rule fields") + + # uncomment for manual interaction + # tgen.cli() + + tag = "field" + + router_list = tgen.routers().values() + for router in router_list: + for t in ftest: + # send field-setting command + # always have a match dst-ip to satisfy rule non-empty check + if "cDN" in t: + match_dstip = "" + else: + match_dstip = "match dst-ip 9.9.9.9/32\n" + vcmd = "c t\npbr-map ASAKUSA seq 100\n{}\n{}set nexthop-group A\nend\nend".format( + t["c"], match_dstip + ) + router.vtysh_multicmd(vcmd) + + # debug + router.vtysh_cmd("sh pbr map") + + match = None + notmatch = None + + if "tm" in t: + match = t["tm"] + logger.info("MUSTMATCH: {}".format(match)) + if "tN" in t: + notmatch = t["tN"] + logger.info("NOTMATCH: {}".format(notmatch)) + + test_func = partial(rtr_field_cmp, router, "sh pbr rule", match, notmatch) + _, result = topotest.run_and_expect(test_func, None, count=10, wait=1) + assertmsg = '"{}" mismatches on {}'.format(tag, router.name) + if result is not None: + gather_pbr_data_on_error(router) + assert result is None, assertmsg + + # + # clean up + # + vcmd = "c t\nno pbr-map ASAKUSA seq 100\nend" + router.vtysh_multicmd(vcmd) + + match = None + notmatch = r"Seq 100\w" + + test_func = partial(rtr_field_cmp, router, "sh pbr rule", match, notmatch) + _, result = topotest.run_and_expect(test_func, None, count=10, wait=1) + assertmsg = '"{}" mismatches on {}'.format(tag, router.name) if result is not None: gather_pbr_data_on_error(router) assert result is None, assertmsg +######################################################################## +# Field test - END +######################################################################## + + def test_pbr_flap(): "Test PBR interface flapping" @@ -244,6 +403,7 @@ def _get_router_rules(router, expected): args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) + # # EXTRA SAUCE # diff --git a/tests/topotests/pytest.ini b/tests/topotests/pytest.ini index 0062cf3de2..98fcfbc848 100644 --- a/tests/topotests/pytest.ini +++ b/tests/topotests/pytest.ini @@ -1,12 +1,15 @@ # Skip pytests example directory [pytest] +# NEEDS_EXABGP_4_2_11_FRR + # asyncio_mode = auto # We always turn this on inside conftest.py, default shown # addopts = --junitxml=<rundir>/topotests.xml -log_level = DEBUG +# This affects what gets dumped to the screen on test failure +log_level = ERROR log_format = %(asctime)s,%(msecs)03d %(levelname)s: %(name)s: %(message)s log_date_format = %Y-%m-%d %H:%M:%S @@ -42,6 +45,7 @@ markers = eigrpd: Tests that run against EIGRPD isisd: Tests that run against ISISD ldpd: Tests that run against LDPD + mgmtd: Tests that run against MGMTD nhrpd: Tests that run against NHRPD ospf6d: Tests that run against OSPF6D ospfd: Tests that run against OSPFD diff --git a/tests/topotests/rip_topo1/test_rip_topo1.py b/tests/topotests/rip_topo1/test_rip_topo1.py index d23962b77d..9b0eaf9a18 100644 --- a/tests/topotests/rip_topo1/test_rip_topo1.py +++ b/tests/topotests/rip_topo1/test_rip_topo1.py @@ -19,6 +19,7 @@ import sys import pytest from time import sleep +import functools sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) @@ -258,58 +259,43 @@ def test_zebra_ipv4_routingTable(): global fatal_error net = get_topogen().net + def _verify_ip_route(expected): + # Actual output from router + actual = ( + net["r%s" % i] + .cmd('vtysh -c "show ip route" 2> /dev/null | grep "^R"') + .rstrip() + ) + # Drop timers on end of line + actual = re.sub(r", [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", "", actual) + # Fix newlines (make them all the same) + actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) + + return topotest.get_textdiff( + actual, + expected, + title1="actual Zebra IPv4 routing table", + title2="expected Zebra IPv4 routing table", + ) + # Skip if previous fatal error condition is raised if fatal_error != "": pytest.skip(fatal_error) thisDir = os.path.dirname(os.path.realpath(__file__)) - # Verify OSPFv3 Routing Table print("\n\n** Verifing Zebra IPv4 Routing Table") print("******************************************\n") - failures = 0 for i in range(1, 4): refTableFile = "%s/r%s/show_ip_route.ref" % (thisDir, i) if os.path.isfile(refTableFile): - # Read expected result from file expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1) - # Actual output from router - actual = ( - net["r%s" % i] - .cmd('vtysh -c "show ip route" 2> /dev/null | grep "^R"') - .rstrip() - ) - # Drop timers on end of line - actual = re.sub(r", [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", "", actual) - # Fix newlines (make them all the same) - actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) - - # Generate Diff - diff = topotest.get_textdiff( - actual, - expected, - title1="actual Zebra IPv4 routing table", - title2="expected Zebra IPv4 routing table", - ) - - # Empty string if it matches, otherwise diff contains unified diff - if diff: - sys.stderr.write( - "r%s failed Zebra IPv4 Routing Table Check:\n%s\n" % (i, diff) - ) - failures += 1 - else: - print("r%s ok" % i) - - assert ( - failures == 0 - ), "Zebra IPv4 Routing Table verification failed for router r%s:\n%s" % ( - i, - diff, - ) + test_func = functools.partial(_verify_ip_route, expected) + success, _ = topotest.run_and_expect(test_func, "", count=30, wait=1) + assert success, "Failed verifying IPv4 routes for r{}".format(i) # Make sure that all daemons are still running for i in range(1, 4): @@ -344,7 +330,6 @@ def test_shutdown_check_stderr(): if __name__ == "__main__": - # To suppress tracebacks, either use the following pytest call or add "--tb=no" to cli # retval = pytest.main(["-s", "--tb=no"]) retval = pytest.main(["-s"]) diff --git a/tests/topotests/ripng_route_map/__init__.py b/tests/topotests/ripng_route_map/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/ripng_route_map/r1/frr.conf b/tests/topotests/ripng_route_map/r1/frr.conf new file mode 100644 index 0000000000..6d0fb46d98 --- /dev/null +++ b/tests/topotests/ripng_route_map/r1/frr.conf @@ -0,0 +1,21 @@ +! +int r1-eth0 + ipv6 address 2001:db8::1/64 +! +router ripng + network 2001:db8::/64 + route-map rmap in r1-eth0 + timers basic 5 15 10 +exit +! +ipv6 access-list r2 seq 5 permit 2001:db8:2::/64 +! +ipv6 prefix-list r3 seq 5 permit 2001:db8:3::/64 +! +route-map rmap permit 10 + match ipv6 address r2 + set metric 12 +route-map rmap permit 20 + match ipv6 address prefix-list r3 + set metric 13 +exit diff --git a/tests/topotests/ripng_route_map/r2/frr.conf b/tests/topotests/ripng_route_map/r2/frr.conf new file mode 100644 index 0000000000..fb9d6702c4 --- /dev/null +++ b/tests/topotests/ripng_route_map/r2/frr.conf @@ -0,0 +1,14 @@ +! +int lo + ipv6 address 2001:db8:2::1/64 +! +int r2-eth0 + ipv6 address 2001:db8::2/64 +! +router ripng + redistribute connected + network 2001:db8::/64 + network 2001:db8:2::1/64 + timers basic 5 15 10 +exit + diff --git a/tests/topotests/ripng_route_map/r3/frr.conf b/tests/topotests/ripng_route_map/r3/frr.conf new file mode 100644 index 0000000000..a6d07789c3 --- /dev/null +++ b/tests/topotests/ripng_route_map/r3/frr.conf @@ -0,0 +1,14 @@ +! +int lo + ipv6 address 2001:db8:3::1/64 +! +int r3-eth0 + ipv6 address 2001:db8::3/64 +! +router ripng + redistribute connected + network 2001:db8::/64 + network 2001:db8:3::1/64 + timers basic 5 15 10 +exit + diff --git a/tests/topotests/ripng_route_map/test_ripng_route_map.py b/tests/topotests/ripng_route_map/test_ripng_route_map.py new file mode 100644 index 0000000000..e1cc88e9b6 --- /dev/null +++ b/tests/topotests/ripng_route_map/test_ripng_route_map.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# Copyright (c) 2023 by +# Donatas Abraitis <donatas@opensourcerouting.org> +# + +""" +Test if route-map for ripng basic functionality works. +""" + +import os +import sys +import json +import pytest +import functools + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.common_config import step + +pytestmark = [pytest.mark.ripngd] + + +def setup_module(mod): + topodef = {"s1": ("r1", "r2", "r3")} + tgen = Topogen(topodef, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for _, (rname, router) in enumerate(router_list.items(), 1): + router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname))) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_ripng_route_map(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + r2 = tgen.gears["r2"] + + def _show_routes(nh_num): + output = json.loads(r1.vtysh_cmd("show ipv6 route ripng json")) + expected = { + "2001:db8:2::/64": [ + { + "metric": 13, + } + ], + "2001:db8:3::/64": [ + { + "metric": 14, + } + ], + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_show_routes, 2) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Got routes, but metric is not set as expected" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/ripng_topo1/test_ripng_topo1.py b/tests/topotests/ripng_topo1/test_ripng_topo1.py index ce2f5986d1..6bebf6044b 100644 --- a/tests/topotests/ripng_topo1/test_ripng_topo1.py +++ b/tests/topotests/ripng_topo1/test_ripng_topo1.py @@ -19,7 +19,7 @@ import sys import pytest from time import sleep - +import functools sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from lib import topotest @@ -273,6 +273,27 @@ def test_zebra_ipv6_routingTable(): global fatal_error net = get_topogen().net + def _verify_ip_route(expected): + # Actual output from router + actual = ( + net["r%s" % i] + .cmd('vtysh -c "show ipv6 route" 2> /dev/null | grep "^R"') + .rstrip() + ) + # Mask out Link-Local mac address portion. They are random... + actual = re.sub(r" fe80::[0-9a-f:]+", " fe80::XXXX:XXXX:XXXX:XXXX", actual) + # Drop timers on end of line + actual = re.sub(r", [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", "", actual) + # Fix newlines (make them all the same) + actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) + + return topotest.get_textdiff( + actual, + expected, + title1="actual Zebra IPv6 routing table", + title2="expected Zebra IPv6 routing table", + ) + # Skip if previous fatal error condition is raised if fatal_error != "": pytest.skip(fatal_error) @@ -291,42 +312,9 @@ def test_zebra_ipv6_routingTable(): # Fix newlines (make them all the same) expected = ("\n".join(expected.splitlines()) + "\n").splitlines(1) - # Actual output from router - actual = ( - net["r%s" % i] - .cmd('vtysh -c "show ipv6 route" 2> /dev/null | grep "^R"') - .rstrip() - ) - # Mask out Link-Local mac address portion. They are random... - actual = re.sub(r" fe80::[0-9a-f:]+", " fe80::XXXX:XXXX:XXXX:XXXX", actual) - # Drop timers on end of line - actual = re.sub(r", [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", "", actual) - # Fix newlines (make them all the same) - actual = ("\n".join(actual.splitlines()) + "\n").splitlines(1) - - # Generate Diff - diff = topotest.get_textdiff( - actual, - expected, - title1="actual Zebra IPv6 routing table", - title2="expected Zebra IPv6 routing table", - ) - - # Empty string if it matches, otherwise diff contains unified diff - if diff: - sys.stderr.write( - "r%s failed Zebra IPv6 Routing Table Check:\n%s\n" % (i, diff) - ) - failures += 1 - else: - print("r%s ok" % i) - - assert ( - failures == 0 - ), "Zebra IPv6 Routing Table verification failed for router r%s:\n%s" % ( - i, - diff, - ) + test_func = functools.partial(_verify_ip_route, expected) + success, _ = topotest.run_and_expect(test_func, "", count=30, wait=1) + assert success, "Failed verifying IPv6 routes for r{}".format(i) # Make sure that all daemons are running for i in range(1, 4): @@ -386,7 +374,6 @@ def test_shutdown_check_memleak(): if __name__ == "__main__": - # To suppress tracebacks, either use the following pytest call or add "--tb=no" to cli # retval = pytest.main(["-s", "--tb=no"]) retval = pytest.main(["-s"]) diff --git a/tests/topotests/route_scale/r1/installed.routes.json b/tests/topotests/route_scale/r1/installed.routes.json index 25d209f9eb..6e09f52f1c 100644 --- a/tests/topotests/route_scale/r1/installed.routes.json +++ b/tests/topotests/route_scale/r1/installed.routes.json @@ -11,6 +11,6 @@ "type":"sharp" } ], - "routesTotal":1000032, - "routesTotalFib":1000032 + "routesTotal":1000064, + "routesTotalFib":1000064 } diff --git a/tests/topotests/route_scale/r1/no.routes.json b/tests/topotests/route_scale/r1/no.routes.json index abebd1b143..13dc7675a1 100644 --- a/tests/topotests/route_scale/r1/no.routes.json +++ b/tests/topotests/route_scale/r1/no.routes.json @@ -6,6 +6,6 @@ "type":"connected" } ], - "routesTotal":32, - "routesTotalFib":32 + "routesTotal":64, + "routesTotalFib":64 } diff --git a/tests/topotests/simple_snmp_test/r1/isisd.conf b/tests/topotests/simple_snmp_test/r1/isisd.conf index 1a148f0628..435abde330 100644 --- a/tests/topotests/simple_snmp_test/r1/isisd.conf +++ b/tests/topotests/simple_snmp_test/r1/isisd.conf @@ -9,7 +9,7 @@ interface r1-eth0 isis circuit-type level-1 no isis hello padding isis hello-interval 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point ! interface r1-eth1 @@ -18,7 +18,7 @@ interface r1-eth1 isis circuit-type level-1 no isis hello padding isis hello-interval 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point ! interface r1-eth2 @@ -27,7 +27,7 @@ interface r1-eth2 isis circuit-type level-1 no isis hello padding isis hello-interval 1 - isis hello-multiplier 3 + isis hello-multiplier 10 isis network point-to-point ! interface lo diff --git a/tests/topotests/simple_snmp_test/r1/snmpd.conf b/tests/topotests/simple_snmp_test/r1/snmpd.conf index 740574cb8e..cdcd9a2b37 100644 --- a/tests/topotests/simple_snmp_test/r1/snmpd.conf +++ b/tests/topotests/simple_snmp_test/r1/snmpd.conf @@ -1,4 +1,4 @@ -agentAddress udp:1.1.1.1:161 +agentAddress udp:161 com2sec public 1.1.1.1 public diff --git a/tests/topotests/srv6_encap_src_addr/__init__.py b/tests/topotests/srv6_encap_src_addr/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/srv6_encap_src_addr/r1/expected_srv6_encap_src_addr.json b/tests/topotests/srv6_encap_src_addr/r1/expected_srv6_encap_src_addr.json new file mode 100644 index 0000000000..431027f099 --- /dev/null +++ b/tests/topotests/srv6_encap_src_addr/r1/expected_srv6_encap_src_addr.json @@ -0,0 +1,9 @@ +{ + "parameters": { + "encapsulation":{ + "sourceAddress": { + "configured": "fc00:0:1::1" + } + } + } +} \ No newline at end of file diff --git a/tests/topotests/srv6_encap_src_addr/r1/expected_srv6_encap_src_addr_set.json b/tests/topotests/srv6_encap_src_addr/r1/expected_srv6_encap_src_addr_set.json new file mode 100644 index 0000000000..431027f099 --- /dev/null +++ b/tests/topotests/srv6_encap_src_addr/r1/expected_srv6_encap_src_addr_set.json @@ -0,0 +1,9 @@ +{ + "parameters": { + "encapsulation":{ + "sourceAddress": { + "configured": "fc00:0:1::1" + } + } + } +} \ No newline at end of file diff --git a/tests/topotests/srv6_encap_src_addr/r1/expected_srv6_encap_src_addr_unset.json b/tests/topotests/srv6_encap_src_addr/r1/expected_srv6_encap_src_addr_unset.json new file mode 100644 index 0000000000..18b317f5f3 --- /dev/null +++ b/tests/topotests/srv6_encap_src_addr/r1/expected_srv6_encap_src_addr_unset.json @@ -0,0 +1,9 @@ +{ + "parameters": { + "encapsulation":{ + "sourceAddress": { + "configured": "::" + } + } + } +} \ No newline at end of file diff --git a/tests/topotests/srv6_encap_src_addr/r1/setup.sh b/tests/topotests/srv6_encap_src_addr/r1/setup.sh new file mode 100644 index 0000000000..36ed713f24 --- /dev/null +++ b/tests/topotests/srv6_encap_src_addr/r1/setup.sh @@ -0,0 +1,2 @@ +ip link add dummy0 type dummy +ip link set dummy0 up diff --git a/tests/topotests/srv6_encap_src_addr/r1/zebra.conf b/tests/topotests/srv6_encap_src_addr/r1/zebra.conf new file mode 100644 index 0000000000..c570756b52 --- /dev/null +++ b/tests/topotests/srv6_encap_src_addr/r1/zebra.conf @@ -0,0 +1,17 @@ +hostname r1 +! +! debug zebra events +! debug zebra rib detailed +! +log stdout notifications +log monitor notifications +log commands +log file zebra.log debugging +! +segment-routing + srv6 + encapsulation + source-address fc00:0:1::1 + ! + ! +! diff --git a/tests/topotests/srv6_encap_src_addr/test_srv6_encap_src_addr.py b/tests/topotests/srv6_encap_src_addr/test_srv6_encap_src_addr.py new file mode 100755 index 0000000000..4239193317 --- /dev/null +++ b/tests/topotests/srv6_encap_src_addr/test_srv6_encap_src_addr.py @@ -0,0 +1,142 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# +# test_srv6_encap_src_addr.py +# Part of NetDEF Topology Tests +# +# Copyright (c) 2022 by +# University of Rome Tor Vergata, Carmine Scarpitta <carmine.scarpitta@uniroma2.it> +# + +""" +test_srv6_encap_src_addr.py: +Test for SRv6 encap source address on zebra +""" + +import os +import sys +import json +import pytest +import functools + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger + +pytestmark = [pytest.mark.bgpd, pytest.mark.sharpd] + + +def open_json_file(filename): + try: + with open(filename, "r") as f: + return json.load(f) + except IOError: + assert False, "Could not read file {}".format(filename) + + +def setup_module(mod): + tgen = Topogen({None: "r1"}, mod.__name__) + tgen.start_topology() + for rname, router in tgen.routers().items(): + router.run("/bin/bash {}/{}/setup.sh".format(CWD, rname)) + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_SHARP, os.path.join(CWD, "{}/sharpd.conf".format(rname)) + ) + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_zebra_srv6_encap_src_addr(tgen): + "Test SRv6 encapsulation source address." + logger.info( + "Test SRv6 encapsulation source address." + ) + r1 = tgen.gears["r1"] + + # Generate expected results + json_file = "{}/r1/expected_srv6_encap_src_addr.json".format(CWD) + expected = json.loads(open(json_file).read()) + + ok = topotest.router_json_cmp_retry(r1, "show segment-routing srv6 manager json", expected) + assert ok, '"r1" JSON output mismatches' + + output = r1.cmd("ip sr tunsrc show") + assert output == "tunsrc addr fc00:0:1::1\n" + + +def test_zebra_srv6_encap_src_addr_unset(tgen): + "Test SRv6 encapsulation source address unset." + logger.info( + "Test SRv6 encapsulation source address unset." + ) + r1 = tgen.gears["r1"] + + # Unset SRv6 encapsulation source address + r1.vtysh_cmd( + """ + configure terminal + segment-routing + srv6 + encapsulation + no source-address + """ + ) + + # Generate expected results + json_file = "{}/r1/expected_srv6_encap_src_addr_unset.json".format(CWD) + expected = json.loads(open(json_file).read()) + + ok = topotest.router_json_cmp_retry(r1, "show segment-routing srv6 manager json", expected) + assert ok, '"r1" JSON output mismatches' + + output = r1.cmd("ip sr tunsrc show") + assert output == "tunsrc addr ::\n" + + +def test_zebra_srv6_encap_src_addr_set(tgen): + "Test SRv6 encapsulation source address set." + logger.info( + "Test SRv6 encapsulation source address set." + ) + r1 = tgen.gears["r1"] + + # Set SRv6 encapsulation source address + r1.vtysh_cmd( + """ + configure terminal + segment-routing + srv6 + encapsulation + source-address fc00:0:1::1 + """ + ) + + # Generate expected results + json_file = "{}/r1/expected_srv6_encap_src_addr_set.json".format(CWD) + expected = json.loads(open(json_file).read()) + + ok = topotest.router_json_cmp_retry(r1, "show segment-routing srv6 manager json", expected) + assert ok, '"r1" JSON output mismatches' + + output = r1.cmd("ip sr tunsrc show") + assert output == "tunsrc addr fc00:0:1::1\n" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/srv6_locator/r1/sharpd.conf b/tests/topotests/srv6_locator/r1/sharpd.conf index d46085935c..371e6f694a 100644 --- a/tests/topotests/srv6_locator/r1/sharpd.conf +++ b/tests/topotests/srv6_locator/r1/sharpd.conf @@ -1,7 +1,6 @@ hostname r1 ! log stdout notifications -log monitor notifications log commands log file sharpd.log debugging ! diff --git a/tests/topotests/srv6_locator/r1/zebra.conf b/tests/topotests/srv6_locator/r1/zebra.conf index 85001d710e..695cf0a73c 100644 --- a/tests/topotests/srv6_locator/r1/zebra.conf +++ b/tests/topotests/srv6_locator/r1/zebra.conf @@ -4,7 +4,6 @@ hostname r1 ! debug zebra rib detailed ! log stdout notifications -log monitor notifications log commands log file zebra.log debugging ! diff --git a/tests/topotests/srv6_locator_custom_bits_length/r1/sharpd.conf b/tests/topotests/srv6_locator_custom_bits_length/r1/sharpd.conf index d46085935c..371e6f694a 100644 --- a/tests/topotests/srv6_locator_custom_bits_length/r1/sharpd.conf +++ b/tests/topotests/srv6_locator_custom_bits_length/r1/sharpd.conf @@ -1,7 +1,6 @@ hostname r1 ! log stdout notifications -log monitor notifications log commands log file sharpd.log debugging ! diff --git a/tests/topotests/srv6_locator_custom_bits_length/r1/zebra.conf b/tests/topotests/srv6_locator_custom_bits_length/r1/zebra.conf index 30a520b798..96033b6573 100644 --- a/tests/topotests/srv6_locator_custom_bits_length/r1/zebra.conf +++ b/tests/topotests/srv6_locator_custom_bits_length/r1/zebra.conf @@ -4,7 +4,6 @@ hostname r1 ! debug zebra rib detailed ! log stdout notifications -log monitor notifications log commands log file zebra.log debugging ! diff --git a/tests/topotests/srv6_locator_usid/r1/sharpd.conf b/tests/topotests/srv6_locator_usid/r1/sharpd.conf index d46085935c..371e6f694a 100644 --- a/tests/topotests/srv6_locator_usid/r1/sharpd.conf +++ b/tests/topotests/srv6_locator_usid/r1/sharpd.conf @@ -1,7 +1,6 @@ hostname r1 ! log stdout notifications -log monitor notifications log commands log file sharpd.log debugging ! diff --git a/tests/topotests/srv6_locator_usid/r1/zebra.conf b/tests/topotests/srv6_locator_usid/r1/zebra.conf index 190e831ac1..1a02e28be2 100644 --- a/tests/topotests/srv6_locator_usid/r1/zebra.conf +++ b/tests/topotests/srv6_locator_usid/r1/zebra.conf @@ -4,7 +4,6 @@ hostname r1 ! debug zebra rib detailed ! log stdout notifications -log monitor notifications log commands log file zebra.log debugging ! diff --git a/tests/topotests/srv6_static_route/__init__.py b/tests/topotests/srv6_static_route/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/srv6_static_route/expected_srv6_route.json b/tests/topotests/srv6_static_route/expected_srv6_route.json new file mode 100644 index 0000000000..45de6171fe --- /dev/null +++ b/tests/topotests/srv6_static_route/expected_srv6_route.json @@ -0,0 +1,49 @@ +{ + "2001:db8:aaaa::/64": [ + { + "prefix": "2001:db8:aaaa::/64", + "prefixLen": 64, + "protocol": "static", + "selected": true, + "destSelected": true, + "distance": 1, + "metric": 0, + "installed": true, + "nexthops": [ + { + "directlyConnected": true, + "active": true, + "weight": 1 + } + ] + } + ], + "2005::/64": [ + { + "prefix": "2005::/64", + "prefixLen": 64, + "protocol": "static", + "selected": true, + "destSelected": true, + "distance": 1, + "metric": 0, + "installed": true, + "nexthops": [ + { + "directlyConnected": true, + "active": true, + "weight": 1, + "seg6local": { + "action": "unspec" + }, + "seg6": [ + "2001:db8:aaaa::7", + "2002::2", + "2003::3", + "2004::4" + ] + } + ] + } + ] +} diff --git a/tests/topotests/srv6_static_route/r1/mgmtd.conf b/tests/topotests/srv6_static_route/r1/mgmtd.conf new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/topotests/srv6_static_route/r1/setup.sh b/tests/topotests/srv6_static_route/r1/setup.sh new file mode 100644 index 0000000000..36ed713f24 --- /dev/null +++ b/tests/topotests/srv6_static_route/r1/setup.sh @@ -0,0 +1,2 @@ +ip link add dummy0 type dummy +ip link set dummy0 up diff --git a/tests/topotests/srv6_static_route/r1/staticd.conf b/tests/topotests/srv6_static_route/r1/staticd.conf new file mode 100644 index 0000000000..3c65a68c7b --- /dev/null +++ b/tests/topotests/srv6_static_route/r1/staticd.conf @@ -0,0 +1,8 @@ +hostname r1 +! +log stdout notifications +log commands +log file staticd.log debugging +! +ipv6 route 2001:db8:aaaa::/64 dummy0 +ipv6 route 2005::/64 dummy0 segments 2001:db8:aaaa::7/2002::2/2003::3/2004::4 diff --git a/tests/topotests/srv6_static_route/r1/zebra.conf b/tests/topotests/srv6_static_route/r1/zebra.conf new file mode 100644 index 0000000000..a596eeba88 --- /dev/null +++ b/tests/topotests/srv6_static_route/r1/zebra.conf @@ -0,0 +1,9 @@ +hostname r1 +! +! debug zebra events +! debug zebra rib detailed +! +log stdout notifications +log commands +log file zebra.log debugging +! diff --git a/tests/topotests/srv6_static_route/test_srv6_route.py b/tests/topotests/srv6_static_route/test_srv6_route.py new file mode 100755 index 0000000000..7a4cd39f2d --- /dev/null +++ b/tests/topotests/srv6_static_route/test_srv6_route.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# +# test_srv6_route.py +# +# Copyright 2023 6WIND S.A. +# Dmytro Shytyi <dmytro.shytyi@6wind.com> +# + +""" +test_srv6_route.py: +Test for SRv6 static route on zebra +""" + +import os +import sys +import json +import pytest +import functools + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger + +pytestmark = [pytest.mark.bgpd, pytest.mark.sharpd] + + +def open_json_file(filename): + try: + with open(filename, "r") as f: + return json.load(f) + except IOError: + assert False, "Could not read file {}".format(filename) + + +def setup_module(mod): + tgen = Topogen({None: "r1"}, mod.__name__) + tgen.start_topology() + for rname, router in tgen.routers().items(): + router.run("/bin/bash {}/{}/setup.sh".format(CWD, rname)) + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_MGMTD, os.path.join(CWD, "{}/mgmtd.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_STATIC, os.path.join(CWD, "{}/staticd.conf".format(rname)) + ) + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_srv6_static_route(): + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + router = tgen.gears["r1"] + + def _check_srv6_static_route(router, expected_route_file): + logger.info("checking zebra srv6 static route with multiple segs status") + output = json.loads(router.vtysh_cmd("show ipv6 route static json")) + expected = open_json_file("{}/{}".format(CWD, expected_route_file)) + return topotest.json_cmp(output, expected) + + def check_srv6_static_route(router, expected_file): + func = functools.partial(_check_srv6_static_route, router, expected_file) + success, result = topotest.run_and_expect(func, None, count=15, wait=1) + assert result is None, "Failed" + + # FOR DEVELOPER: + # If you want to stop some specific line and start interactive shell, + # please use tgen.mininet_cli() to start it. + + logger.info("Test for srv6 route configuration") + check_srv6_static_route(router, "expected_srv6_route.json") + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/static_routing_mpls/r1/zebra.conf b/tests/topotests/static_routing_mpls/r1/zebra.conf new file mode 100644 index 0000000000..4e5d29af98 --- /dev/null +++ b/tests/topotests/static_routing_mpls/r1/zebra.conf @@ -0,0 +1,16 @@ +hostname r1 +ip forwarding +ipv6 forwarding + +int r1-eth0 + ip addr 192.168.1.1/24 +! +int r1-eth1 + ip addr 192.168.2.1/24 +! +int lo + ip addr 192.0.2.1/32 +! +int r1-eth1 + ip addr 192.168.2.1/24 +! diff --git a/tests/topotests/static_routing_mpls/r2/zebra.conf b/tests/topotests/static_routing_mpls/r2/zebra.conf new file mode 100644 index 0000000000..4e06ae5202 --- /dev/null +++ b/tests/topotests/static_routing_mpls/r2/zebra.conf @@ -0,0 +1,18 @@ +hostname r2 +ip forwarding +ipv6 forwarding + +int r2-eth0 + ip addr 192.168.2.2/24 +! +int r2-eth1 + mpls enable + ip addr 192.168.3.2/24 +! +int r2-eth2 + mpls disable + ip addr 172.31.3.2/24 +! +int lo + ip addr 192.0.2.2/32 +! diff --git a/tests/topotests/static_routing_mpls/test_static_routing_mpls.py b/tests/topotests/static_routing_mpls/test_static_routing_mpls.py new file mode 100644 index 0000000000..c1e249cc8f --- /dev/null +++ b/tests/topotests/static_routing_mpls/test_static_routing_mpls.py @@ -0,0 +1,139 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# +# test_static_routing_mlpls.py +# Part of NetDEF Topology Tests +# +# Copyright (c) 2023 by 6WIND +# + +""" +test_static_routing_mpls.py: Testing MPLS configuration with mpls interface settings + +""" + +import os +import re +import sys +import pytest +import json +from functools import partial +import functools + +# Save the Current Working Directory to find configuration files. +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +# Import topogen and topotest helpers +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger + +# Required to instantiate the topology builder class. + +##################################################### +## +## Network Topology Definition +## +##################################################### + + +def build_topo(tgen): + "Build function" + + tgen.add_router("r1") + tgen.add_router("r2") + + switch = tgen.add_switch("sw1") + switch.add_link(tgen.gears["r1"]) + + switch = tgen.add_switch("sw2") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + switch = tgen.add_switch("sw3") + switch.add_link(tgen.gears["r2"]) + + switch = tgen.add_switch("sw4") + switch.add_link(tgen.gears["r2"]) + + +##################################################### +## +## Tests starting +## +##################################################### +def _populate_mpls_labels(): + tgen = get_topogen() + cmds_list = ["echo 100000 > /proc/sys/net/mpls/platform_labels"] + for cmd in cmds_list: + for host in ("r1", "r2"): + logger.info("input: " + cmd) + output = tgen.net[host].cmd(cmd) + logger.info("output: " + output) + + +def setup_module(module): + "Setup topology" + tgen = Topogen(build_topo, module.__name__) + tgen.start_topology() + + _populate_mpls_labels() + + # This is a sample of configuration loading. + router_list = tgen.routers() + for rname, router in router_list.items(): + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + + tgen.start_router() + + +def teardown_module(_mod): + "Teardown the pytest environment" + tgen = get_topogen() + + # This function tears down the whole topology. + tgen.stop_topology() + + +def _check_mpls_state_interface(router, interface, up=True): + output = router.vtysh_cmd("show interface {}".format(interface)) + if up and "MPLS enabled" in output: + return None + elif not up and "MPLS enabled" not in output: + return None + return "not good" + + +def _check_mpls_state(router, interface, configured=True): + test_func = functools.partial( + _check_mpls_state_interface, router, interface, up=configured + ) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + return success + + +def test_mpls_configured_on_interface(): + "Test 'mpls' state is correctly configured on an unconfigured interfaces" + + tgen = get_topogen() + # Don't run this test if we have any failure. + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + logger.info("Checking that MPLS state is on on r2-eth1") + assertmsg = "r2, interface r2-eth1, mpls operational state is off, not expected" + assert _check_mpls_state(tgen.gears["r2"], "r2-eth1"), assertmsg + + logger.info("Checking that MPLS state is off on r2-eth2") + assertmsg = "r2, interface r2-eth2, mpls operational state is on, not expected" + assert _check_mpls_state(tgen.gears["r2"], "r2-eth2", False), assertmsg + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/static_simple/r1/mgmtd.conf b/tests/topotests/static_simple/r1/mgmtd.conf index 0f9f97ca1a..dd5761aa84 100644 --- a/tests/topotests/static_simple/r1/mgmtd.conf +++ b/tests/topotests/static_simple/r1/mgmtd.conf @@ -1 +1,11 @@ log timestamp precision 3 + +! way too noisy +! debug northbound libyang + +debug northbound notifications +debug northbound events +debug northbound callbacks +debug mgmt backend datastore frontend transaction +debug mgmt client frontend +debug mgmt client backend diff --git a/tests/topotests/static_simple/r1/zebra.conf b/tests/topotests/static_simple/r1/zebra.conf index ec827617ab..e3a44362b5 100644 --- a/tests/topotests/static_simple/r1/zebra.conf +++ b/tests/topotests/static_simple/r1/zebra.conf @@ -1,5 +1,15 @@ log timestamp precision 3 +! way too noisy +! debug northbound libyang + +debug northbound notifications +debug northbound events +debug northbound callbacks +debug mgmt backend datastore frontend transaction +debug mgmt client frontend +debug mgmt client backend + interface r1-eth0 ip address 101.0.0.1/24 ipv6 address 2101::1/64 diff --git a/tests/topotests/static_simple/test_static_simple.py b/tests/topotests/static_simple/test_static_simple.py index 817336ac21..f862d81239 100644 --- a/tests/topotests/static_simple/test_static_simple.py +++ b/tests/topotests/static_simple/test_static_simple.py @@ -40,6 +40,8 @@ def tgen(request): router.net.add_loop("lo-red") router.net.attach_iface_to_l3vrf("lo-red", "red") router.net.attach_iface_to_l3vrf(rname + "-eth1", "red") + # + # router.load_frr_config("frr.conf") # and select daemons to run router.load_config(TopoRouter.RD_ZEBRA, "zebra.conf") router.load_config(TopoRouter.RD_MGMTD) @@ -68,7 +70,7 @@ def disable_debug(router): router.vtysh_cmd("no debug northbound callbacks configuration") -@retry(retry_timeout=3, initial_wait=0.1) +@retry(retry_timeout=30, initial_wait=0.1) def check_kernel(r1, super_prefix, count, add, is_blackhole, vrf, matchvia): network = ipaddress.ip_network(super_prefix) vrfstr = f" vrf {vrf}" if vrf else "" @@ -181,10 +183,11 @@ def guts(tgen, vrf, use_cli): r1 = tgen.routers()["r1"] - step("add via gateway", reset=True) - do_config(r1, 1, True, False, vrf=vrf, use_cli=use_cli) - step("remove via gateway") - do_config(r1, 1, False, False, vrf=vrf, use_cli=use_cli) + count = 10 + step(f"add {count} via gateway", reset=True) + do_config(r1, count, True, False, vrf=vrf, use_cli=use_cli) + step(f"remove {count} via gateway") + do_config(r1, count, False, False, vrf=vrf, use_cli=use_cli) via = f"lo-{vrf}" if vrf else "lo" step("add via loopback") diff --git a/tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py b/tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py index 529520cd9e..0b2937c12a 100644 --- a/tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py +++ b/tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py @@ -144,6 +144,23 @@ def test_zebra_system_recursion(): assert result is None, "Kernel route is missing from zebra" +def test_zebra_noprefix_connected(): + "Test that a noprefixroute created does not create a connected route" + + tgen = get_topogen() + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + router = tgen.gears["r1"] + router.run("ip addr add 192.168.44.1/24 dev r1-eth1 noprefixroute") + expected = "% Network not in table" + test_func = partial( + topotest.router_output_cmp, router, "show ip route 192.168.44.0/24", expected + ) + result, diff = topotest.run_and_expect(test_func, "", count=20, wait=1) + assert result, "Connected Route should not have been added" + + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) diff --git a/tests/topotests/zebra_netlink/test_zebra_netlink.py b/tests/topotests/zebra_netlink/test_zebra_netlink.py index 5a30f79279..522c390c39 100644 --- a/tests/topotests/zebra_netlink/test_zebra_netlink.py +++ b/tests/topotests/zebra_netlink/test_zebra_netlink.py @@ -22,7 +22,6 @@ from lib.topogen import Topogen, TopoRouter from lib.topolog import logger - pytestmark = [pytest.mark.sharpd] @@ -68,6 +67,10 @@ def test_zebra_netlink_batching(tgen): # Reduce the size of the buffer to hit the limit. r1.vtysh_cmd("conf t\nzebra kernel netlink batch-tx-buf 256 256") + entry = {"r1-eth0": {"addresses": ["192.168.1.1/24"]}} + ok = topotest.router_json_cmp_retry(r1, "show int brief json", entry, False, 30) + assert ok, '"r1" Address not installed yet' + count = 100 r1.vtysh_cmd("sharp install routes 2.1.3.7 nexthop 192.168.1.1 " + str(count)) diff --git a/tests/topotests/zebra_rib/r1/v4_route_1_vrf_before.json b/tests/topotests/zebra_rib/r1/v4_route_1_vrf_before.json new file mode 100644 index 0000000000..997d12f68d --- /dev/null +++ b/tests/topotests/zebra_rib/r1/v4_route_1_vrf_before.json @@ -0,0 +1,27 @@ +{ + "3.5.1.0/24":[ + { + "prefix":"3.5.1.0/24", + "prefixLen":24, + "protocol":"kernel", + "vrfId":0, + "vrfName":"default", + "selected":true, + "destSelected":true, + "distance":0, + "metric":0, + "installed":true, + "table":254, + "nexthops":[ + { + "flags":3, + "fib":true, + "ip":"192.168.210.1", + "afi":"ipv4", + "interfaceName":"r1-eth0", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/zebra_rib/test_zebra_rib.py b/tests/topotests/zebra_rib/test_zebra_rib.py index e2863218b0..05036fa7ad 100644 --- a/tests/topotests/zebra_rib/test_zebra_rib.py +++ b/tests/topotests/zebra_rib/test_zebra_rib.py @@ -77,6 +77,41 @@ def teardown_module(mod): tgen.stop_topology() +def test_zebra_kernel_route_vrf(): + "Test kernel routes should be removed after interface changes vrf" + logger.info("Test kernel routes should be removed after interface changes vrf") + vrf = "RED" + tgen = get_topogen() + r1 = tgen.gears["r1"] + + # Add kernel routes, the interface is initially in default vrf + r1.run("ip route add 3.5.1.0/24 via 192.168.210.1 dev r1-eth0") + json_file = "{}/r1/v4_route_1_vrf_before.json".format(CWD) + expected = json.loads(open(json_file).read()) + test_func = partial( + topotest.router_json_cmp, r1, "show ip route 3.5.1.0/24 json", expected + ) + _, result = topotest.run_and_expect(test_func, None, count=5, wait=1) + assert result is None, '"r1" JSON output mismatches' + + # Change the interface's vrf + r1.run("ip link add {} type vrf table 1".format(vrf)) + r1.run("ip link set {} up".format(vrf)) + r1.run("ip link set dev r1-eth0 master {}".format(vrf)) + + expected = "{}" + test_func = partial( + topotest.router_output_cmp, r1, "show ip route 3.5.1.0/24 json", expected + ) + result, diff = topotest.run_and_expect(test_func, "", count=5, wait=1) + assertmsg = "{} should not have the kernel route.\n{}".format('"r1"', diff) + assert result, assertmsg + + # Clean up + r1.run("ip link set dev r1-eth0 nomaster") + r1.run("ip link del dev {}".format(vrf)) + + def test_zebra_kernel_admin_distance(): "Test some basic kernel routes added that should be accepted" logger.info("Test some basic kernel routes that should be accepted") @@ -220,7 +255,7 @@ def check_static_map_correct_runs(): ) ok, result = topotest.run_and_expect( - check_static_map_correct_runs, "", count=5, wait=1 + check_static_map_correct_runs, "", count=10, wait=1 ) assert ok, result @@ -240,7 +275,7 @@ def check_sharp_map_correct_runs(): ) ok, result = topotest.run_and_expect( - check_sharp_map_correct_runs, "", count=5, wait=1 + check_sharp_map_correct_runs, "", count=10, wait=1 ) assert ok, result diff --git a/tests/topotests/zebra_seg6_route/r1/zebra.conf b/tests/topotests/zebra_seg6_route/r1/zebra.conf index e5e360ffa5..2d0c9e157a 100644 --- a/tests/topotests/zebra_seg6_route/r1/zebra.conf +++ b/tests/topotests/zebra_seg6_route/r1/zebra.conf @@ -1,7 +1,6 @@ log file zebra.log ! log stdout notifications -log monitor notifications log commands ! ! debug zebra packet diff --git a/tests/topotests/zebra_seg6_route/test_zebra_seg6_route.py b/tests/topotests/zebra_seg6_route/test_zebra_seg6_route.py index 1d01263d9a..4b462a51e5 100755 --- a/tests/topotests/zebra_seg6_route/test_zebra_seg6_route.py +++ b/tests/topotests/zebra_seg6_route/test_zebra_seg6_route.py @@ -86,7 +86,7 @@ def check(router, dest, expected): ) logger.info("CHECK {} {} {}".format(dest, nh, sid)) test_func = partial(check, r1, dest, manifest["out"]) - success, result = topotest.run_and_expect(test_func, None, count=5, wait=1) + success, result = topotest.run_and_expect(test_func, None, count=20, wait=1) assert result is None, "Failed" diff --git a/tests/topotests/zebra_seg6local_route/r1/zebra.conf b/tests/topotests/zebra_seg6local_route/r1/zebra.conf index dee7a9171a..a3b9335244 100644 --- a/tests/topotests/zebra_seg6local_route/r1/zebra.conf +++ b/tests/topotests/zebra_seg6local_route/r1/zebra.conf @@ -1,7 +1,6 @@ log file zebra.log ! log stdout notifications -log monitor notifications log commands ! ! debug zebra packet diff --git a/tests/zebra/test_lm_plugin.c b/tests/zebra/test_lm_plugin.c index 9ad0bc4e17..9895c025f0 100644 --- a/tests/zebra/test_lm_plugin.c +++ b/tests/zebra/test_lm_plugin.c @@ -48,7 +48,7 @@ static int lm_get_chunk_pi(struct label_manager_chunk **lmc, uint32_t base, vrf_id_t vrf_id) { if (base == 0) - *lmc = create_label_chunk(10, 55, 0, 1, 50, 50 + size); + *lmc = create_label_chunk(10, 55, 0, 1, 50, 50 + size, true); else *lmc = assign_label_chunk(10, 55, 0, 1, size, base); diff --git a/tools/checkpatch.pl b/tools/checkpatch.pl index b5892e8da5..ecae0e92a1 100755 --- a/tools/checkpatch.pl +++ b/tools/checkpatch.pl @@ -1,9 +1,11 @@ #!/usr/bin/env perl # SPDX-License-Identifier: GPL-2.0-or-later +# # (c) 2001, Dave Jones. (the file handling bit) # (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit) # (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite) # (c) 2008-2010 Andy Whitcroft <apw@canonical.com> +# (c) 2010-2018 Joe Perches <joe@perches.com> use strict; use warnings; @@ -11,6 +13,7 @@ use File::Basename; use Cwd 'abs_path'; use Term::ANSIColor qw(:constants); +use Encode qw(decode encode); my $P = $0; my $D = dirname(abs_path($P)); @@ -19,7 +22,12 @@ use Getopt::Long qw(:config no_auto_abbrev); +my $frr = 1; + my $quiet = 0; +my $verbose = 0; +my %verbose_messages = (); +my %verbose_emitted = (); my $tree = 1; my $chk_signoff = 1; my $chk_patch = 1; @@ -40,6 +48,8 @@ my $fix = 0; my $fix_inplace = 0; my $root; +my $gitroot = $ENV{'GIT_DIR'}; +$gitroot = ".git" if !defined($gitroot); my %debug; my %camelcase = (); my %use_type = (); @@ -48,16 +58,24 @@ my @ignore = (); my $help = 0; my $configuration_file = ".checkpatch.conf"; -my $max_line_length = 80; +my $max_line_length = 100; my $ignore_perl_version = 0; my $minimum_perl_version = 5.10.0; my $min_conf_desc_length = 4; my $spelling_file = "$D/spelling.txt"; my $codespell = 0; my $codespellfile = "/usr/share/codespell/dictionary.txt"; -my $typedefsfile = ""; +my $user_codespellfile = ""; +my $conststructsfile = "$D/const_structs.checkpatch"; +my $docsfile = "$D/../doc/developer/checkpatch.rst"; +my $typedefsfile; my $color = "auto"; -my $allow_c99_comments = 1; +my $allow_c99_comments = 0; # Not in FRR. +#my $allow_c99_comments = 1; # Can be overridden by --ignore C99_COMMENT_TOLERANCE +# git output parsing needs US English output, so first set backtick child process LANGUAGE +my $git_command ='export LANGUAGE=en_US.UTF-8; git'; +my $tabsize = 8; +my ${CONFIG_} = "CONFIG_"; sub help { my ($exitcode) = @_; @@ -68,6 +86,7 @@ sub help { Options: -q, --quiet quiet + -v, --verbose verbose mode --no-tree run without a kernel tree --no-signoff do not check for 'Signed-off-by' line --patch treat FILE as patchfile (default) @@ -90,8 +109,11 @@ sub help { --types TYPE(,TYPE2...) show only these comma separated message types --ignore TYPE(,TYPE2...) ignore various comma separated message types --show-types show the specific message type in the output - --max-line-length=n set the maximum line length, if exceeded, warn + --max-line-length=n set the maximum line length, (default $max_line_length) + if exceeded, warn on patches + requires --strict for use with --file --min-conf-desc-length=n set the min description length, if shorter, warn + --tab-size=n set the number of spaces for tab (default $tabsize) --root=PATH PATH to the kernel tree root --no-summary suppress the per-file summary --mailback only produce a report in case of warnings/errors @@ -112,11 +134,13 @@ sub help { --ignore-perl-version override checking of perl version. expect runtime errors. --codespell Use the codespell dictionary for spelling/typos - (default:/usr/share/codespell/dictionary.txt) + (default:$codespellfile) --codespellfile Use this codespell dictionary --typedefsfile Read additional types from this file --color[=WHEN] Use colors 'always', 'never', or only when output is a terminal ('auto'). Default is 'auto'. + --kconfig-prefix=WORD use WORD as a prefix for Kconfig symbols (default + ${CONFIG_}) -h, --help, --version display this help and exit When FILE is - read standard input. @@ -143,15 +167,51 @@ sub list_types { my $text = <$script>; close($script); - my @types = (); + my %types = (); # Also catch when type or level is passed through a variable - for ($text =~ /(?:(?:\bCHK|\bWARN|\bERROR|&\{\$msg_level})\s*\(|\$msg_type\s*=)\s*"([^"]+)"/g) { - push (@types, $_); + while ($text =~ /(?:(\bCHK|\bWARN|\bERROR|&\{\$msg_level})\s*\(|\$msg_type\s*=)\s*"([^"]+)"/g) { + if (defined($1)) { + if (exists($types{$2})) { + $types{$2} .= ",$1" if ($types{$2} ne $1); + } else { + $types{$2} = $1; + } + } else { + $types{$2} = "UNDETERMINED"; + } } - @types = sort(uniq(@types)); + print("#\tMessage type\n\n"); - foreach my $type (@types) { + if ($color) { + print(" ( Color coding: "); + print(RED . "ERROR" . RESET); + print(" | "); + print(YELLOW . "WARNING" . RESET); + print(" | "); + print(GREEN . "CHECK" . RESET); + print(" | "); + print("Multiple levels / Undetermined"); + print(" )\n\n"); + } + + foreach my $type (sort keys %types) { + my $orig_type = $type; + if ($color) { + my $level = $types{$type}; + if ($level eq "ERROR") { + $type = RED . $type . RESET; + } elsif ($level eq "WARN") { + $type = YELLOW . $type . RESET; + } elsif ($level eq "CHK") { + $type = GREEN . $type . RESET; + } + } print(++$count . "\t" . $type . "\n"); + if ($verbose && exists($verbose_messages{$orig_type})) { + my $message = $verbose_messages{$orig_type}; + $message =~ s/\n/\n\t/g; + print("\t" . $message . "\n\n"); + } } exit($exitcode); @@ -183,6 +243,46 @@ sub list_types { unshift(@ARGV, @conf_args) if @conf_args; } +sub load_docs { + open(my $docs, '<', "$docsfile") + or warn "$P: Can't read the documentation file $docsfile $!\n"; + + my $type = ''; + my $desc = ''; + my $in_desc = 0; + + while (<$docs>) { + chomp; + my $line = $_; + $line =~ s/\s+$//; + + if ($line =~ /^\s*\*\*(.+)\*\*$/) { + if ($desc ne '') { + $verbose_messages{$type} = trim($desc); + } + $type = $1; + $desc = ''; + $in_desc = 1; + } elsif ($in_desc) { + if ($line =~ /^(?:\s{4,}|$)/) { + $line =~ s/^\s{4}//; + $desc .= $line; + $desc .= "\n"; + } else { + $verbose_messages{$type} = trim($desc); + $type = ''; + $desc = ''; + $in_desc = 0; + } + } + } + + if ($desc ne '') { + $verbose_messages{$type} = trim($desc); + } + close($docs); +} + # Perl's Getopt::Long allows options to take optional arguments after a space. # Prevent --color by itself from consuming other arguments foreach (@ARGV) { @@ -193,6 +293,7 @@ sub list_types { GetOptions( 'q|quiet+' => \$quiet, + 'v|verbose!' => \$verbose, 'tree!' => \$tree, 'signoff!' => \$chk_signoff, 'patch!' => \$chk_patch, @@ -209,6 +310,7 @@ sub list_types { 'list-types!' => \$list_types, 'max-line-length=i' => \$max_line_length, 'min-conf-desc-length=i' => \$min_conf_desc_length, + 'tab-size=i' => \$tabsize, 'root=s' => \$root, 'summary!' => \$summary, 'mailback!' => \$mailback, @@ -219,17 +321,57 @@ sub list_types { 'debug=s' => \%debug, 'test-only=s' => \$tst_only, 'codespell!' => \$codespell, - 'codespellfile=s' => \$codespellfile, + 'codespellfile=s' => \$user_codespellfile, 'typedefsfile=s' => \$typedefsfile, 'color=s' => \$color, 'no-color' => \$color, #keep old behaviors of -nocolor 'nocolor' => \$color, #keep old behaviors of -nocolor + 'kconfig-prefix=s' => \${CONFIG_}, 'h|help' => \$help, 'version' => \$help -) or help(1); +) or $help = 2; + +if ($user_codespellfile) { + # Use the user provided codespell file unconditionally + $codespellfile = $user_codespellfile; +} elsif (!(-f $codespellfile)) { + # If /usr/share/codespell/dictionary.txt is not present, try to find it + # under codespell's install directory: <codespell_root>/data/dictionary.txt + if (($codespell || $help) && which("codespell") ne "" && which("python") ne "") { + my $python_codespell_dict = << "EOF"; + +import os.path as op +import codespell_lib +codespell_dir = op.dirname(codespell_lib.__file__) +codespell_file = op.join(codespell_dir, 'data', 'dictionary.txt') +print(codespell_file, end='') +EOF + + my $codespell_dict = `python -c "$python_codespell_dict" 2> /dev/null`; + $codespellfile = $codespell_dict if (-f $codespell_dict); + } +} -help(0) if ($help); +# $help is 1 if either -h, --help or --version is passed as option - exitcode: 0 +# $help is 2 if invalid option is passed - exitcode: 1 +help($help - 1) if ($help); + +die "$P: --git cannot be used with --file or --fix\n" if ($git && ($file || $fix)); +die "$P: --verbose cannot be used with --terse\n" if ($verbose && $terse); + +if ($color =~ /^[01]$/) { + $color = !$color; +} elsif ($color =~ /^always$/i) { + $color = 1; +} elsif ($color =~ /^never$/i) { + $color = 0; +} elsif ($color =~ /^auto$/i) { + $color = (-t STDOUT); +} else { + die "$P: Invalid color mode: $color\n"; +} +load_docs() if ($verbose); list_types(0) if ($list_types); $fix = 1 if ($fix_inplace); @@ -237,11 +379,11 @@ sub list_types { my $exit = 0; +my $perl_version_ok = 1; if ($^V && $^V lt $minimum_perl_version) { + $perl_version_ok = 0; printf "$P: requires at least perl version %vd\n", $minimum_perl_version; - if (!$ignore_perl_version) { - exit(1); - } + exit(1) if (!$ignore_perl_version); } #if no filenames are given, push '-' to read patch from stdin @@ -249,17 +391,8 @@ sub list_types { push(@ARGV, '-'); } -if ($color =~ /^[01]$/) { - $color = !$color; -} elsif ($color =~ /^always$/i) { - $color = 1; -} elsif ($color =~ /^never$/i) { - $color = 0; -} elsif ($color =~ /^auto$/i) { - $color = (-t STDOUT); -} else { - die "Invalid color mode: $color\n"; -} +# skip TAB size 1 to avoid additional checks on $tabsize - 1 +die "$P: Invalid TAB size: $tabsize\n" if ($tabsize < 2); sub hash_save_array_words { my ($hashRef, $arrayRef) = @_; @@ -343,9 +476,10 @@ sub hash_show_words { __force| __iomem| __must_check| - __init_refok| __kprobes| __ref| + __refconst| + __refdata| __rcu| __private }x; @@ -358,8 +492,9 @@ sub hash_show_words { # Notes to $Attribute: # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check our $Attribute = qr{ - const| _Atomic| + const| + volatile| __percpu| __nocast| __safe| @@ -376,12 +511,14 @@ sub hash_show_words { __noclone| __deprecated| __read_mostly| + __ro_after_init| __kprobes| $InitAttribute| ____cacheline_aligned| ____cacheline_aligned_in_smp| ____cacheline_internodealigned_in_smp| - __weak + __weak| + __alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) }x; our $Modifier; our $Inline = qr{inline|__always_inline|noinline|__inline|__inline__}; @@ -393,7 +530,7 @@ sub hash_show_words { our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?}; our $Int = qr{[0-9]+$Int_type?}; our $Octal = qr{0[0-7]+$Int_type?}; -our $String = qr{"[X\t]*"}; +our $String = qr{(?:\b[Lu])?"[X\t]*"}; our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?}; our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?}; our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?}; @@ -410,7 +547,7 @@ sub hash_show_words { our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x; our $Iterators = qr{ - frr_each|frr_each_safe|frr_each_from| + darr_foreach_p|darr_foreach_i|frr_each|frr_each_safe|frr_each_from| frr_with_mutex|frr_with_privs| LIST_FOREACH|LIST_FOREACH_SAFE| SLIST_FOREACH|SLIST_FOREACH_SAFE|SLIST_FOREACH_PREVPTR| @@ -418,7 +555,7 @@ sub hash_show_words { TAILQ_FOREACH|TAILQ_FOREACH_SAFE|TAILQ_FOREACH_REVERSE|TAILQ_FOREACH_REVERSE_SAFE| RB_FOREACH|RB_FOREACH_SAFE|RB_FOREACH_REVERSE|RB_FOREACH_REVERSE_SAFE| SPLAY_FOREACH| - FOR_ALL_INTERFACES|FOR_ALL_INTERFACES_ADDRESSES|JSON_FOREACH| + FOR_ALL_INTERFACES|JSON_FOREACH| LY_FOR_KEYS|LY_LIST_FOR|LY_TREE_FOR|LY_TREE_DFS_BEGIN|LYD_TREE_DFS_BEGIN| RE_DEST_FOREACH_ROUTE|RE_DEST_FOREACH_ROUTE_SAFE| RNODE_FOREACH_RE|RNODE_FOREACH_RE_SAFE| @@ -426,6 +563,7 @@ sub hash_show_words { SUBGRP_FOREACH_PEER|SUBGRP_FOREACH_PEER_SAFE| SUBGRP_FOREACH_ADJ|SUBGRP_FOREACH_ADJ_SAFE| AF_FOREACH|FOREACH_AFI_SAFI|FOREACH_SAFI| + FOREACH_BE_CLIENT_BITS|FOREACH_MGMTD_BE_CLIENT_ID| LSDB_LOOP }x; @@ -480,8 +618,19 @@ sub hash_show_words { seq_vprintf|seq_printf|seq_puts )}; +our $allocFunctions = qr{(?x: + (?:(?:devm_)? + (?:kv|k|v)[czm]alloc(?:_array)?(?:_node)? | + kstrdup(?:_const)? | + kmemdup(?:_nul)?) | + (?:\w+)?alloc_skb(?:_ip_align)? | + # dev_alloc_skb/netdev_alloc_skb, et al + dma_alloc_coherent +)}; + our $signature_tags = qr{(?xi: Signed-off-by:| + Co-developed-by:| Acked-by:| Tested-by:| Reviewed-by:| @@ -491,6 +640,88 @@ sub hash_show_words { Cc: )}; +our $tracing_logging_tags = qr{(?xi: + [=-]*> | + <[=-]* | + \[ | + \] | + start | + called | + entered | + entry | + enter | + in | + inside | + here | + begin | + exit | + end | + done | + leave | + completed | + out | + return | + [\.\!:\s]* +)}; + +sub edit_distance_min { + my (@arr) = @_; + my $len = scalar @arr; + if ((scalar @arr) < 1) { + # if underflow, return + return; + } + my $min = $arr[0]; + for my $i (0 .. ($len-1)) { + if ($arr[$i] < $min) { + $min = $arr[$i]; + } + } + return $min; +} + +sub get_edit_distance { + my ($str1, $str2) = @_; + $str1 = lc($str1); + $str2 = lc($str2); + $str1 =~ s/-//g; + $str2 =~ s/-//g; + my $len1 = length($str1); + my $len2 = length($str2); + # two dimensional array storing minimum edit distance + my @distance; + for my $i (0 .. $len1) { + for my $j (0 .. $len2) { + if ($i == 0) { + $distance[$i][$j] = $j; + } elsif ($j == 0) { + $distance[$i][$j] = $i; + } elsif (substr($str1, $i-1, 1) eq substr($str2, $j-1, 1)) { + $distance[$i][$j] = $distance[$i - 1][$j - 1]; + } else { + my $dist1 = $distance[$i][$j - 1]; #insert distance + my $dist2 = $distance[$i - 1][$j]; # remove + my $dist3 = $distance[$i - 1][$j - 1]; #replace + $distance[$i][$j] = 1 + edit_distance_min($dist1, $dist2, $dist3); + } + } + } + return $distance[$len1][$len2]; +} + +sub find_standard_signature { + my ($sign_off) = @_; + my @standard_signature_tags = ( + 'Signed-off-by:', 'Co-developed-by:', 'Acked-by:', 'Tested-by:', + 'Reviewed-by:', 'Reported-by:', 'Suggested-by:' + ); + foreach my $signature (@standard_signature_tags) { + return $signature if (get_edit_distance($sign_off, $signature) <= 2); + } + + return ""; +} + our @typeListMisordered = ( qr{char\s+(?:un)?signed}, qr{int\s+(?:(?:un)?signed\s+)?short\s}, @@ -579,12 +810,36 @@ sub hash_show_words { ["__ATTR", 2], ); +my $word_pattern = '\b[A-Z]?[a-z]{2,}\b'; + #Create a search pattern for all these functions to speed up a loop below our $mode_perms_search = ""; foreach my $entry (@mode_permission_funcs) { $mode_perms_search .= '|' if ($mode_perms_search ne ""); $mode_perms_search .= $entry->[0]; } +$mode_perms_search = "(?:${mode_perms_search})"; + +our %deprecated_apis = ( + "synchronize_rcu_bh" => "synchronize_rcu", + "synchronize_rcu_bh_expedited" => "synchronize_rcu_expedited", + "call_rcu_bh" => "call_rcu", + "rcu_barrier_bh" => "rcu_barrier", + "synchronize_sched" => "synchronize_rcu", + "synchronize_sched_expedited" => "synchronize_rcu_expedited", + "call_rcu_sched" => "call_rcu", + "rcu_barrier_sched" => "rcu_barrier", + "get_state_synchronize_sched" => "get_state_synchronize_rcu", + "cond_synchronize_sched" => "cond_synchronize_rcu", +); + +#Create a search pattern for all these strings to speed up a loop below +our $deprecated_apis_search = ""; +foreach my $entry (keys %deprecated_apis) { + $deprecated_apis_search .= '|' if ($deprecated_apis_search ne ""); + $deprecated_apis_search .= $entry; +} +$deprecated_apis_search = "(?:${deprecated_apis_search})"; our $mode_perms_world_writable = qr{ S_IWUGO | @@ -619,6 +874,37 @@ sub hash_show_words { $mode_perms_string_search .= '|' if ($mode_perms_string_search ne ""); $mode_perms_string_search .= $entry; } +our $single_mode_perms_string_search = "(?:${mode_perms_string_search})"; +our $multi_mode_perms_string_search = qr{ + ${single_mode_perms_string_search} + (?:\s*\|\s*${single_mode_perms_string_search})* +}x; + +sub perms_to_octal { + my ($string) = @_; + + return trim($string) if ($string =~ /^\s*0[0-7]{3,3}\s*$/); + + my $val = ""; + my $oval = ""; + my $to = 0; + my $curpos = 0; + my $lastpos = 0; + while ($string =~ /\b(($single_mode_perms_string_search)\b(?:\s*\|\s*)?\s*)/g) { + $curpos = pos($string); + my $match = $2; + my $omatch = $1; + last if ($lastpos > 0 && ($curpos - length($omatch) != $lastpos)); + $lastpos = $curpos; + $to |= $mode_permission_string_types{$match}; + $val .= '\s*\|\s*' if ($val ne ""); + $val .= $match; + $oval .= $omatch; + } + $oval =~ s/^\s*\|\s*//; + $oval =~ s/\s*\|\s*$//; + return sprintf("%04o", $to); +} our $allowed_asm_includes = qr{(?x: irq| @@ -647,7 +933,7 @@ sub hash_show_words { $spelling_fix{$suspect} = $fix; } close($spelling); -} else { +} elsif (!$frr) { warn "No typos will be found - file '$spelling_file': $!\n"; } @@ -694,7 +980,7 @@ sub read_words { next; } - $$wordsRef .= '|' if ($$wordsRef ne ""); + $$wordsRef .= '|' if (defined $$wordsRef); $$wordsRef .= $line; } close($file); @@ -704,12 +990,19 @@ sub read_words { return 0; } -my $typeOtherTypedefs = ""; -if (length($typedefsfile)) { +my $const_structs; +if (!$frr && + show_type("CONST_STRUCT")) { + read_words(\$const_structs, $conststructsfile) + or warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; +} + +if (defined($typedefsfile)) { + my $typeOtherTypedefs; read_words(\$typeOtherTypedefs, $typedefsfile) or warn "No additional types will be considered - file '$typedefsfile': $!\n"; + $typeTypedefs .= '|' . $typeOtherTypedefs if (defined $typeOtherTypedefs); } -$typeTypedefs .= '|' . $typeOtherTypedefs if ($typeOtherTypedefs ne ""); sub build_types { my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)"; @@ -748,12 +1041,12 @@ sub build_types { }x; $Type = qr{ $NonptrType - (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+)? + (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+){0,4} (?:\s+$Inline|\s+$Modifier)* }x; $TypeMisordered = qr{ $NonptrTypeMisordered - (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+)? + (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+){0,4} (?:\s+$Inline|\s+$Modifier)* }x; $Declare = qr{(?:$Storage\s+(?:$Inline\s+)?)?$Type}; @@ -774,9 +1067,16 @@ sub build_types { our $declaration_macros = qr{(?x: (?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,6}\s*\(| (?:$Storage\s+)?[HLP]?LIST_HEAD\s*\(| - (?:$Storage\s+)?${Type}\s+uninitialized_var\s*\( + (?:SKCIPHER_REQUEST|SHASH_DESC|AHASH_REQUEST)_ON_STACK\s*\( )}; +our %allow_repeated_words = ( + add => '', + added => '', + bad => '', + be => '', +); + sub deparenthesize { my ($string) = @_; return "" if (!defined($string)); @@ -817,14 +1117,29 @@ sub seed_camelcase_file { } } +our %maintained_status = (); + sub is_maintained_obsolete { my ($filename) = @_; return 0 if (!$tree || !(-e "$root/scripts/get_maintainer.pl")); - my $status = `perl $root/scripts/get_maintainer.pl --status --nom --nol --nogit --nogit-fallback -f $filename 2>&1`; + if (!exists($maintained_status{$filename})) { + $maintained_status{$filename} = `perl $root/scripts/get_maintainer.pl --status --nom --nol --nogit --nogit-fallback -f $filename 2>&1`; + } + + return $maintained_status{$filename} =~ /obsolete/i; +} + +sub is_SPDX_License_valid { + my ($license) = @_; - return $status =~ /obsolete/i; + return 1 if (!$tree || which("python3") eq "" || !(-x "$root/scripts/spdxcheck.py") || !(-e "$gitroot")); + + my $root_path = abs_path($root); + my $status = `cd "$root_path"; echo "$license" | scripts/spdxcheck.py -`; + return 0 if ($status ne ""); + return 1; } my $camelcase_seeded = 0; @@ -837,8 +1152,8 @@ sub seed_camelcase_includes { $camelcase_seeded = 1; - if (-e ".git") { - my $git_last_include_commit = `git log --no-merges --pretty=format:"%h%n" -1 -- include`; + if (-e "$gitroot") { + my $git_last_include_commit = `${git_command} log --no-merges --pretty=format:"%h%n" -1 -- include`; chomp $git_last_include_commit; $camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit"; } else { @@ -865,8 +1180,8 @@ sub seed_camelcase_includes { return; } - if (-e ".git") { - $files = `git ls-files "include/*.h"`; + if (-e "$gitroot") { + $files = `${git_command} ls-files "include/*.h"`; @include_files = split('\n', $files); } @@ -885,18 +1200,28 @@ sub seed_camelcase_includes { } } +sub git_is_single_file { + my ($filename) = @_; + + return 0 if ((which("git") eq "") || !(-e "$gitroot")); + + my $output = `${git_command} ls-files -- $filename 2>/dev/null`; + my $count = $output =~ tr/\n//; + return $count eq 1 && $output =~ m{^${filename}$}; +} + sub git_commit_info { my ($commit, $id, $desc) = @_; - return ($id, $desc) if ((which("git") eq "") || !(-e ".git")); + return ($id, $desc) if ((which("git") eq "") || !(-e "$gitroot")); - my $output = `git log --no-color --format='%H %s' -1 $commit 2>&1`; + my $output = `${git_command} log --no-color --format='%H %s' -1 $commit 2>&1`; $output =~ s/^\s*//gm; my @lines = split("\n", $output); return ($id, $desc) if ($#lines < 0); - if ($lines[0] =~ /^error: short SHA1 $commit is ambiguous\./) { + if ($lines[0] =~ /^error: short SHA1 $commit is ambiguous/) { # Maybe one day convert this block of bash into something that returns # all matching commit ids, but it's very slow... # @@ -906,7 +1231,8 @@ sub git_commit_info { # git log --format='%H %s' -1 $line | # echo "commit $(cut -c 1-12,41-)" # done - } elsif ($lines[0] =~ /^fatal: ambiguous argument '$commit': unknown revision or path not in the working tree\./) { + } elsif ($lines[0] =~ /^fatal: ambiguous argument '$commit': unknown revision or path not in the working tree\./ || + $lines[0] =~ /^fatal: bad object $commit/) { $id = undef; } else { $id = substr($lines[0], 0, 12); @@ -927,7 +1253,7 @@ sub git_commit_info { # If input is git commits, extract all commits from the commit expressions. # For example, HEAD-3 means we need check 'HEAD, HEAD~1, HEAD~2'. -die "$P: No git repository found\n" if ($git && !-e ".git"); +die "$P: No git repository found\n" if ($git && !-e "$gitroot"); if ($git) { my @commits = (); @@ -940,7 +1266,7 @@ sub git_commit_info { } else { $git_range = "-1 $commit_expr"; } - my $lines = `git log --no-color --no-merges --pretty=format:'%H %s' $git_range`; + my $lines = `${git_command} log --no-color --no-merges --pretty=format:'%H %s' $git_range`; foreach my $line (split(/\n/, $lines)) { $line =~ /^([0-9a-fA-F]{40,40}) (.*)$/; next if (!defined($1) || !defined($2)); @@ -955,8 +1281,12 @@ sub git_commit_info { } my $vname; +$allow_c99_comments = !defined $ignore_type{"C99_COMMENT_TOLERANCE"}; for my $filename (@ARGV) { my $FILE; + my $is_git_file = git_is_single_file($filename); + my $oldfile = $file; + $file = 1 if ($is_git_file); if ($git) { open($FILE, '-|', "git format-patch -M --stdout -1 $filename") || die "$P: $filename: git format-patch failed - $!\n"; @@ -979,6 +1309,7 @@ sub git_commit_info { while (<$FILE>) { chomp; push(@rawlines, $_); + $vname = qq("$1") if ($filename eq '-' && $_ =~ m/^Subject:\s+(.+)/i); } close($FILE); @@ -1000,17 +1331,18 @@ sub git_commit_info { @modifierListFile = (); @typeListFile = (); build_types(); + $file = $oldfile if ($is_git_file); } if (!$quiet) { hash_show_words(\%use_type, "Used"); hash_show_words(\%ignore_type, "Ignored"); - if ($^V lt 5.10.0) { + if (!$perl_version_ok) { print << "EOM" NOTE: perl $^V is not modern enough to detect all possible issues. - An upgrade to at least perl v5.10.0 is suggested. + An upgrade to at least perl $minimum_perl_version is suggested. EOM } if ($exit) { @@ -1031,6 +1363,7 @@ sub top_of_kernel_tree { "COPYING", "configure.ac", "Makefile.am", "README.md", "doc", "lib", "vtysh", "watchfrr", "tests", "zebra", "bgpd", "ospfd", "ospf6d", "isisd", "staticd", + ); foreach my $check (@tree_check) { @@ -1045,6 +1378,8 @@ sub parse_email { my ($formatted_email) = @_; my $name = ""; + my $quoted = ""; + my $name_comment = ""; my $address = ""; my $comment = ""; @@ -1058,7 +1393,7 @@ sub parse_email { } elsif ($formatted_email =~ /(\S+\@\S+)(.*)$/) { $address = $1; $comment = $2 if defined $2; - $formatted_email =~ s/$address.*$//; + $formatted_email =~ s/\Q$address\E.*$//; $name = $formatted_email; $name = trim($name); $name =~ s/^\"|\"$//g; @@ -1075,42 +1410,76 @@ sub parse_email { } } - $name = trim($name); - $name =~ s/^\"|\"$//g; + # Extract comments from names excluding quoted parts + # "John D. (Doe)" - Do not extract + if ($name =~ s/\"(.+)\"//) { + $quoted = $1; + } + while ($name =~ s/\s*($balanced_parens)\s*/ /) { + $name_comment .= trim($1); + } + $name =~ s/^[ \"]+|[ \"]+$//g; + $name = trim("$quoted $name"); + $address = trim($address); $address =~ s/^\<|\>$//g; + $comment = trim($comment); if ($name =~ /[^\w \-]/i) { ##has "must quote" chars $name =~ s/(?<!\\)"/\\"/g; ##escape quotes $name = "\"$name\""; } - return ($name, $address, $comment); + return ($name, $name_comment, $address, $comment); } sub format_email { - my ($name, $address) = @_; + my ($name, $name_comment, $address, $comment) = @_; my $formatted_email; - $name = trim($name); - $name =~ s/^\"|\"$//g; + $name =~ s/^[ \"]+|[ \"]+$//g; $address = trim($address); + $address =~ s/(?:\.|\,|\")+$//; ##trailing commas, dots or quotes if ($name =~ /[^\w \-]/i) { ##has "must quote" chars $name =~ s/(?<!\\)"/\\"/g; ##escape quotes $name = "\"$name\""; } + $name_comment = trim($name_comment); + $name_comment = " $name_comment" if ($name_comment ne ""); + $comment = trim($comment); + $comment = " $comment" if ($comment ne ""); + if ("$name" eq "") { $formatted_email = "$address"; } else { - $formatted_email = "$name <$address>"; + $formatted_email = "$name$name_comment <$address>"; } - + $formatted_email .= "$comment"; return $formatted_email; } +sub reformat_email { + my ($email) = @_; + + my ($email_name, $name_comment, $email_address, $comment) = parse_email($email); + return format_email($email_name, $name_comment, $email_address, $comment); +} + +sub same_email_addresses { + my ($email1, $email2) = @_; + + my ($email1_name, $name1_comment, $email1_address, $comment1) = parse_email($email1); + my ($email2_name, $name2_comment, $email2_address, $comment2) = parse_email($email2); + + return $email1_name eq $email2_name && + $email1_address eq $email2_address && + $name1_comment eq $name2_comment && + $comment1 eq $comment2; +} + sub which { my ($bin) = @_; @@ -1144,7 +1513,7 @@ sub expand_tabs { if ($c eq "\t") { $res .= ' '; $n++; - for (; ($n % 8) != 0; $n++) { + for (; ($n % $tabsize) != 0; $n++) { $res .= ' '; } next; @@ -1200,7 +1569,7 @@ sub sanitise_line { for ($off = 1; $off < length($line); $off++) { $c = substr($line, $off, 1); - # Comments we are wacking completly including the begin + # Comments we are whacking completely including the begin # and end, all to $;. if ($sanitise_quote eq '' && substr($line, $off, 2) eq '/*') { $sanitise_quote = '*/'; @@ -1269,12 +1638,18 @@ sub sanitise_line { $res =~ s@(\#\s*(?:error|warning)\s+).*@$1$clean@; } + if ($allow_c99_comments && $res =~ m@(//.*$)@) { + my $match = $1; + $res =~ s/\Q$match\E/"$;" x length($match)/e; + } + return $res; } sub get_quoted_string { my ($line, $rawline) = @_; + return "" if (!defined($line) || !defined($rawline)); return "" if ($line !~ m/($String)/g); return substr($rawline, $-[0], $+[0] - $-[0]); } @@ -1567,8 +1942,16 @@ sub ctx_statement_level { sub ctx_locate_comment { my ($first_line, $end_line) = @_; + # If c99 comment on the current line, or the line before or after + my ($current_comment) = ($rawlines[$end_line - 1] =~ m@^\+.*(//.*$)@); + return $current_comment if (defined $current_comment); + ($current_comment) = ($rawlines[$end_line - 2] =~ m@^[\+ ].*(//.*$)@); + return $current_comment if (defined $current_comment); + ($current_comment) = ($rawlines[$end_line] =~ m@^[\+ ].*(//.*$)@); + return $current_comment if (defined $current_comment); + # Catch a comment on the end of the line itself. - my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@); + ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@); return $current_comment if (defined $current_comment); # Look through the context and try and figure out if there is a @@ -1622,6 +2005,28 @@ sub raw_line { return $line; } +sub get_stat_real { + my ($linenr, $lc) = @_; + + my $stat_real = raw_line($linenr, 0); + for (my $count = $linenr + 1; $count <= $lc; $count++) { + $stat_real = $stat_real . "\n" . raw_line($count, 0); + } + + return $stat_real; +} + +sub get_stat_here { + my ($linenr, $cnt, $here) = @_; + + my $herectx = $here . "\n"; + for (my $n = 0; $n < $cnt; $n++) { + $herectx .= raw_line($linenr, $n) . "\n"; + } + + return $herectx; +} + sub cat_vet { my ($vet) = @_; my ($res, $coded); @@ -1940,7 +2345,16 @@ sub report { splice(@lines, 1, 1); $output = join("\n", @lines); } - $output = (split('\n', $output))[0] . "\n" if ($terse); + + if ($terse) { + $output = (split('\n', $output))[0] . "\n"; + } + + if ($verbose && exists($verbose_messages{$type}) && + !exists($verbose_emitted{$type})) { + $output .= $verbose_messages{$type} . "\n\n"; + $verbose_emitted{$type} = 1; + } push(our @report, $output); @@ -2129,7 +2543,7 @@ sub string_find_replace { sub tabify { my ($leading) = @_; - my $source_indent = 8; + my $source_indent = $tabsize; my $max_spaces_before_tab = $source_indent - 1; my $spaces_to_tab = " " x $source_indent; @@ -2171,19 +2585,41 @@ sub pos_last_openparen { return length(expand_tabs(substr($line, 0, $last_openparen))) + 1; } -sub remove_defuns { - my @breakfast = (); - my $milktoast; - for my $tasty (@rawlines) { - $milktoast = $tasty; - if (($tasty =~ /^\+DEFPY/ || - $tasty =~ /^\+DEFUN/ || - $tasty =~ /^\+ALIAS/) .. ($tasty =~ /^\+\{/)) { - $milktoast = "\n"; - } - push(@breakfast, $milktoast); +sub get_raw_comment { + my ($line, $rawline) = @_; + my $comment = ''; + + for my $i (0 .. (length($line) - 1)) { + if (substr($line, $i, 1) eq "$;") { + $comment .= substr($rawline, $i, 1); + } } - @rawlines = @breakfast; + + return $comment; +} + +sub exclude_global_initialisers { + my ($realfile) = @_; + + # Do not check for BPF programs (tools/testing/selftests/bpf/progs/*.c, samples/bpf/*_kern.c, *.bpf.c). + return $realfile =~ m@^tools/testing/selftests/bpf/progs/.*\.c$@ || + $realfile =~ m@^samples/bpf/.*_kern\.c$@ || + $realfile =~ m@/bpf/.*\.bpf\.c$@; +} + +sub remove_defuns { + my @breakfast = (); + my $milktoast; + for my $tasty (@rawlines) { + $milktoast = $tasty; + if (($tasty =~ /^\+DEFPY/ || + $tasty =~ /^\+DEFUN/ || + $tasty =~ /^\+ALIAS/) .. ($tasty =~ /^\+\{/)) { + $milktoast = "\n"; + } + push(@breakfast, $milktoast); + } + @rawlines = @breakfast; } sub process { @@ -2202,16 +2638,24 @@ sub process { our $clean = 1; my $signoff = 0; + my $author = ''; + my $authorsignoff = 0; + my $author_sob = ''; my $is_patch = 0; + my $is_binding_patch = -1; my $in_header_lines = $file ? 0 : 1; my $in_commit_log = 0; #Scanning lines before patch + my $has_patch_separator = 0; #Found a --- line my $has_commit_log = 0; #Encountered lines before patch + my $commit_log_lines = 0; #Number of commit log lines my $commit_log_possible_stack_dump = 0; my $commit_log_long_line = 0; my $commit_log_has_diff = 0; my $reported_maintainer_file = 0; my $non_utf8_charset = 0; + my $last_git_commit_id_linenr = -1; + my $last_blank_line = 0; my $last_coalesced_string_linenr = -1; @@ -2250,8 +2694,10 @@ sub process { my $camelcase_file_seeded = 0; + my $checklicenseline = 1; + sanitise_line_reset(); - remove_defuns(); + remove_defuns(); my $line; foreach my $rawline (@rawlines) { @@ -2262,7 +2708,7 @@ sub process { if ($rawline=~/^\+\+\+\s+(\S+)/) { $setup_docs = 0; - if ($1 =~ m@Documentation/admin-guide/kernel-parameters.rst$@) { + if ($1 =~ m@Documentation/admin-guide/kernel-parameters.txt$@) { $setup_docs = 1; } #next; @@ -2343,6 +2789,15 @@ sub process { $sline =~ s/$;/ /g; #with comments as spaces my $rawline = $rawlines[$linenr - 1]; + my $raw_comment = get_raw_comment($line, $rawline); + +# check if it's a mode change, rename or start of a patch + if (!$in_commit_log && + ($line =~ /^ mode change [0-7]+ => [0-7]+ \S+\s*$/ || + ($line =~ /^rename (?:from|to) \S+\s*$/ || + $line =~ /^diff --git a\/[\w\/\.\_\-]+ b\/\S+\s*$/))) { + $is_patch = 1; + } #extract the line range in the file after the patch is applied if (!$in_commit_log && @@ -2443,6 +2898,20 @@ sub process { } else { $check = $check_orig; } + $checklicenseline = 1; + + if ($realfile !~ /^MAINTAINERS/) { + my $last_binding_patch = $is_binding_patch; + + $is_binding_patch = () = $realfile =~ m@^(?:Documentation/devicetree/|include/dt-bindings/)@; + + if (($last_binding_patch != -1) && + ($last_binding_patch ^ $is_binding_patch)) { + WARN("DT_SPLIT_BINDING_PATCH", + "DT binding docs and includes should be a separate patch. See: Documentation/devicetree/bindings/submitting-patches.rst\n"); + } + } + next; } @@ -2454,10 +2923,23 @@ sub process { $cnt_lines++ if ($realcnt != 0); +# Verify the existence of a commit log if appropriate +# 2 is used because a $signature is counted in $commit_log_lines + if ($in_commit_log) { + if ($line !~ /^\s*$/) { + $commit_log_lines++; #could be a $signature + } + } elsif ($has_commit_log && $commit_log_lines < 2) { + # FRR: not used by FRR + # WARN("COMMIT_MESSAGE", + # "Missing commit description - Add an appropriate one\n"); + $commit_log_lines = 2; #warn only once + } + # Check if the commit log has what seems like a diff which can confuse patch if ($in_commit_log && !$commit_log_has_diff && - (($line =~ m@^\s+diff\b.*a/[\w/]+@ && - $line =~ m@^\s+diff\b.*a/([\w/]+)\s+b/$1\b@) || + (($line =~ m@^\s+diff\b.*a/([\w/]+)@ && + $line =~ m@^\s+diff\b.*a/[\w/]+\s+b/$1\b@) || $line =~ m@^\s*(?:\-\-\-\s+a/|\+\+\+\s+b/)@ || $line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) { ERROR("DIFF_IN_COMMIT_MSG", @@ -2475,10 +2957,61 @@ sub process { } } +# Check the patch for a From: + if (decode("MIME-Header", $line) =~ /^From:\s*(.*)/) { + $author = $1; + my $curline = $linenr; + while(defined($rawlines[$curline]) && ($rawlines[$curline++] =~ /^[ \t]\s*(.*)/)) { + $author .= $1; + } + $author = encode("utf8", $author) if ($line =~ /=\?utf-8\?/i); + $author =~ s/"//g; + $author = reformat_email($author); + } + # Check the patch for a signoff: - if ($line =~ /^\s*signed-off-by:/i) { + if ($line =~ /^\s*signed-off-by:\s*(.*)/i) { $signoff++; $in_commit_log = 0; + if ($author ne '' && $authorsignoff != 1) { + if (same_email_addresses($1, $author)) { + $authorsignoff = 1; + } else { + my $ctx = $1; + my ($email_name, $email_comment, $email_address, $comment1) = parse_email($ctx); + my ($author_name, $author_comment, $author_address, $comment2) = parse_email($author); + + if (lc $email_address eq lc $author_address && $email_name eq $author_name) { + $author_sob = $ctx; + $authorsignoff = 2; + } elsif (lc $email_address eq lc $author_address) { + $author_sob = $ctx; + $authorsignoff = 3; + } elsif ($email_name eq $author_name) { + $author_sob = $ctx; + $authorsignoff = 4; + + my $address1 = $email_address; + my $address2 = $author_address; + + if ($address1 =~ /(\S+)\+\S+(\@.*)/) { + $address1 = "$1$2"; + } + if ($address2 =~ /(\S+)\+\S+(\@.*)/) { + $address2 = "$1$2"; + } + if ($address1 eq $address2) { + $authorsignoff = 5; + } + } + } + } + } + +# Check for patch separator + if ($line =~ /^---$/) { + $has_patch_separator = 1; + $in_commit_log = 0; } # Check if MAINTAINERS is being updated. If so, there's probably no need to @@ -2497,8 +3030,17 @@ sub process { my $ucfirst_sign_off = ucfirst(lc($sign_off)); if ($sign_off !~ /$signature_tags/) { - WARN("BAD_SIGN_OFF", - "Non-standard signature: $sign_off\n" . $herecurr); + my $suggested_signature = find_standard_signature($sign_off); + if ($suggested_signature eq "") { + WARN("BAD_SIGN_OFF", + "Non-standard signature: $sign_off\n" . $herecurr); + } else { + if (WARN("BAD_SIGN_OFF", + "Non-standard signature: '$sign_off' - perhaps '$suggested_signature'?\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/$sign_off/$suggested_signature/; + } + } } if (defined $space_before && $space_before ne "") { if (WARN("BAD_SIGN_OFF", @@ -2526,8 +3068,8 @@ sub process { } } - my ($email_name, $email_address, $comment) = parse_email($email); - my $suggested_email = format_email(($email_name, $email_address)); + my ($email_name, $name_comment, $email_address, $comment) = parse_email($email); + my $suggested_email = format_email(($email_name, $name_comment, $email_address, $comment)); if ($suggested_email eq "") { ERROR("BAD_SIGN_OFF", "Unrecognized email address: '$email'\n" . $herecurr); @@ -2537,11 +3079,77 @@ sub process { $dequoted =~ s/" </ </; # Don't force email to have quotes # Allow just an angle bracketed address - if ("$dequoted$comment" ne $email && - "<$email_address>$comment" ne $email && - "$suggested_email$comment" ne $email) { + if (!same_email_addresses($email, $suggested_email)) { + if (WARN("BAD_SIGN_OFF", + "email address '$email' might be better as '$suggested_email'\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\Q$email\E/$suggested_email/; + } + } + + # Address part shouldn't have comments + my $stripped_address = $email_address; + $stripped_address =~ s/\([^\(\)]*\)//g; + if ($email_address ne $stripped_address) { + if (WARN("BAD_SIGN_OFF", + "address part of email should not have comments: '$email_address'\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\Q$email_address\E/$stripped_address/; + } + } + + # Only one name comment should be allowed + my $comment_count = () = $name_comment =~ /\([^\)]+\)/g; + if ($comment_count > 1) { WARN("BAD_SIGN_OFF", - "email address '$email' might be better as '$suggested_email$comment'\n" . $herecurr); + "Use a single name comment in email: '$email'\n" . $herecurr); + } + + + # stable@vger.kernel.org or stable@kernel.org shouldn't + # have an email name. In addition comments should strictly + # begin with a # + if ($email =~ /^.*stable\@(?:vger\.)?kernel\.org/i) { + if (($comment ne "" && $comment !~ /^#.+/) || + ($email_name ne "")) { + my $cur_name = $email_name; + my $new_comment = $comment; + $cur_name =~ s/[a-zA-Z\s\-\"]+//g; + + # Remove brackets enclosing comment text + # and # from start of comments to get comment text + $new_comment =~ s/^\((.*)\)$/$1/; + $new_comment =~ s/^\[(.*)\]$/$1/; + $new_comment =~ s/^[\s\#]+|\s+$//g; + + $new_comment = trim("$new_comment $cur_name") if ($cur_name ne $new_comment); + $new_comment = " # $new_comment" if ($new_comment ne ""); + my $new_email = "$email_address$new_comment"; + + if (WARN("BAD_STABLE_ADDRESS_STYLE", + "Invalid email format for stable: '$email', prefer '$new_email'\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\Q$email\E/$new_email/; + } + } + } elsif ($comment ne "" && $comment !~ /^(?:#.+|\(.+\))$/) { + my $new_comment = $comment; + + # Extract comment text from within brackets or + # c89 style /*...*/ comments + $new_comment =~ s/^\[(.*)\]$/$1/; + $new_comment =~ s/^\/\*(.*)\*\/$/$1/; + + $new_comment = trim($new_comment); + $new_comment =~ s/^[^\w]$//; # Single lettered comment with non word character is usually a typo + $new_comment = "($new_comment)" if ($new_comment ne ""); + my $new_email = format_email($email_name, $name_comment, $email_address, $new_comment); + + if (WARN("BAD_SIGN_OFF", + "Unexpected content after email: '$email', should be: '$new_email'\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\Q$email\E/$new_email/; + } } } @@ -2555,6 +3163,24 @@ sub process { } else { $signatures{$sig_nospace} = 1; } + +# Check Co-developed-by: immediately followed by Signed-off-by: with same name and email + if ($sign_off =~ /^co-developed-by:$/i) { + if ($email eq $author) { + WARN("BAD_SIGN_OFF", + "Co-developed-by: should not be used to attribute nominal patch author '$author'\n" . "$here\n" . $rawline); + } + if (!defined $lines[$linenr]) { + WARN("BAD_SIGN_OFF", + "Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline); + } elsif ($rawlines[$linenr] !~ /^\s*signed-off-by:\s*(.*)/i) { + WARN("BAD_SIGN_OFF", + "Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline . "\n" .$rawlines[$linenr]); + } elsif ($1 ne $email) { + WARN("BAD_SIGN_OFF", + "Co-developed-by and Signed-off-by: name/email do not match \n" . "$here\n" . $rawline . "\n" .$rawlines[$linenr]); + } + } } # Check email subject for common tools that don't need to be mentioned @@ -2564,16 +3190,13 @@ sub process { "A patch subject line should describe the change not the tool that found it\n" . $herecurr); } -# Check for old stable address - if ($line =~ /^\s*cc:\s*.*<?\bstable\@kernel\.org\b>?.*$/i) { - ERROR("STABLE_ADDRESS", - "The 'stable' address should be 'stable\@vger.kernel.org'\n" . $herecurr); - } - -# Check for unwanted Gerrit info - if ($in_commit_log && $line =~ /^\s*change-id:/i) { - ERROR("GERRIT_CHANGE_ID", - "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr); +# Check for Gerrit Change-Ids not in any patch context + if ($realfile eq '' && !$has_patch_separator && $line =~ /^\s*change-id:/i) { + if (ERROR("GERRIT_CHANGE_ID", + "Remove Gerrit Change-Id's before submitting upstream\n" . $herecurr) && + $fix) { + fix_delete_line($fixlinenr, $rawline); + } } # Check if the commit log is in a possible stack dump @@ -2581,8 +3204,10 @@ sub process { ($line =~ /^\s*(?:WARNING:|BUG:)/ || $line =~ /^\s*\[\s*\d+\.\d{6,6}\s*\]/ || # timestamp - $line =~ /^\s*\[\<[0-9a-fA-F]{8,}\>\]/)) { - # stack dump address + $line =~ /^\s*\[\<[0-9a-fA-F]{8,}\>\]/) || + $line =~ /^(?:\s+\w+:\s+[0-9a-fA-F]+){3,3}/ || + $line =~ /^\s*\#\d+\s*\[[0-9a-fA-F]+\]\s*\w+ at [0-9a-fA-F]+/) { + # stack dump address styles $commit_log_possible_stack_dump = 1; } @@ -2593,8 +3218,8 @@ sub process { # file delta changes $line =~ /^\s*(?:[\w\.\-]+\/)++[\w\.\-]+:/ || # filename then : - $line =~ /^\s*(?:Fixes:|Link:)/i || - # A Fixes: or Link: line + $line =~ /^\s*(?:Fixes:|Link:|$signature_tags)/i || + # A Fixes: or Link: line or signature tag line $commit_log_possible_stack_dump)) { WARN("COMMIT_LOG_LONG_LINE", "Possible unwrapped commit description (prefer a maximum 75 chars per line)\n" . $herecurr); @@ -2607,11 +3232,30 @@ sub process { $commit_log_possible_stack_dump = 0; } +# Check for lines starting with a # + if ($in_commit_log && $line =~ /^#/) { + if (WARN("COMMIT_COMMENT_SYMBOL", + "Commit log lines starting with '#' are dropped by git as comments\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/^/ /; + } + } + # Check for git id commit length and improperly formed commit descriptions - if ($in_commit_log && !$commit_log_possible_stack_dump && - $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink):/i && +# A correctly formed commit description is: +# commit <SHA-1 hash length 12+ chars> ("Complete commit subject") +# with the commit subject '("' prefix and '")' suffix +# This is a fairly compilicated block as it tests for what appears to be +# bare SHA-1 hash with minimum length of 5. It also avoids several types of +# possible SHA-1 matches. +# A commit match can span multiple lines so this block attempts to find a +# complete typical commit on a maximum of 3 lines + if ($perl_version_ok && + $in_commit_log && !$commit_log_possible_stack_dump && + $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink|base-commit):/i && $line !~ /^This reverts commit [0-9a-f]{7,40}/ && - ($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i || + (($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i || + ($line =~ /\bcommit\s*$/i && defined($rawlines[$linenr]) && $rawlines[$linenr] =~ /^\s*[0-9a-f]{5,}\b/i)) || ($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i && $line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i && $line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) { @@ -2621,49 +3265,56 @@ sub process { my $long = 0; my $case = 1; my $space = 1; - my $hasdesc = 0; - my $hasparens = 0; my $id = '0123456789ab'; my $orig_desc = "commit description"; my $description = ""; + my $herectx = $herecurr; + my $has_parens = 0; + my $has_quotes = 0; + + my $input = $line; + if ($line =~ /(?:\bcommit\s+[0-9a-f]{5,}|\bcommit\s*$)/i) { + for (my $n = 0; $n < 2; $n++) { + if ($input =~ /\bcommit\s+[0-9a-f]{5,}\s*($balanced_parens)/i) { + $orig_desc = $1; + $has_parens = 1; + # Always strip leading/trailing parens then double quotes if existing + $orig_desc = substr($orig_desc, 1, -1); + if ($orig_desc =~ /^".*"$/) { + $orig_desc = substr($orig_desc, 1, -1); + $has_quotes = 1; + } + last; + } + last if ($#lines < $linenr + $n); + $input .= " " . trim($rawlines[$linenr + $n]); + $herectx .= "$rawlines[$linenr + $n]\n"; + } + $herectx = $herecurr if (!$has_parens); + } - if ($line =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) { + if ($input =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) { $init_char = $1; $orig_commit = lc($2); - } elsif ($line =~ /\b([0-9a-f]{12,40})\b/i) { + $short = 0 if ($input =~ /\bcommit\s+[0-9a-f]{12,40}/i); + $long = 1 if ($input =~ /\bcommit\s+[0-9a-f]{41,}/i); + $space = 0 if ($input =~ /\bcommit [0-9a-f]/i); + $case = 0 if ($input =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/); + } elsif ($input =~ /\b([0-9a-f]{12,40})\b/i) { $orig_commit = lc($1); } - $short = 0 if ($line =~ /\bcommit\s+[0-9a-f]{12,40}/i); - $long = 1 if ($line =~ /\bcommit\s+[0-9a-f]{41,}/i); - $space = 0 if ($line =~ /\bcommit [0-9a-f]/i); - $case = 0 if ($line =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/); - if ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)"\)/i) { - $orig_desc = $1; - $hasparens = 1; - } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i && - defined $rawlines[$linenr] && - $rawlines[$linenr] =~ /^\s*\("([^"]+)"\)/) { - $orig_desc = $1; - $hasparens = 1; - } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i && - defined $rawlines[$linenr] && - $rawlines[$linenr] =~ /^\s*[^"]+"\)/) { - $line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)$/i; - $orig_desc = $1; - $rawlines[$linenr] =~ /^\s*([^"]+)"\)/; - $orig_desc .= " " . $1; - $hasparens = 1; - } - ($id, $description) = git_commit_info($orig_commit, $id, $orig_desc); if (defined($id) && - ($short || $long || $space || $case || ($orig_desc ne $description) || !$hasparens)) { + ($short || $long || $space || $case || ($orig_desc ne $description) || !$has_quotes) && + $last_git_commit_id_linenr != $linenr - 1) { ERROR("GIT_COMMIT_ID", - "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herecurr); + "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herectx); } + #don't report the next line if this line ends in commit and the sha1 hash is the next line + $last_git_commit_id_linenr = $linenr if ($line =~ /\bcommit\s*$/i); } # Check for added, moved or deleted files @@ -2674,8 +3325,16 @@ sub process { (defined($1) || defined($2))))) { $is_patch = 1; $reported_maintainer_file = 1; - #WARN("FILE_PATH_CHANGES", - # "added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr); + # WARN("FILE_PATH_CHANGES", + # "added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr); + } + +# Check for adding new DT bindings not in schema format + if (!$in_commit_log && + ($line =~ /^new file mode\s*\d+\s*$/) && + ($realfile =~ m@^Documentation/devicetree/bindings/.*\.txt$@)) { + WARN("DT_SCHEMA_BINDING_PATCH", + "DT bindings should be in DT schema format. See: Documentation/devicetree/bindings/writing-schema.rst\n"); } # Check for wrappage within a valid hunk of the file @@ -2739,21 +3398,89 @@ sub process { # Check for various typo / spelling mistakes if (defined($misspellings) && ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) { - while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:\b|$|[^a-z@])/gi) { + while ($rawline =~ /(?:^|[^\w\-'`])($misspellings)(?:[^\w\-'`]|$)/gi) { my $typo = $1; + my $blank = copy_spacing($rawline); + my $ptr = substr($blank, 0, $-[1]) . "^" x length($typo); + my $hereptr = "$hereline$ptr\n"; my $typo_fix = $spelling_fix{lc($typo)}; $typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/); $typo_fix = uc($typo_fix) if ($typo =~ /^[A-Z]+$/); my $msg_level = \&WARN; $msg_level = \&CHK if ($file); if (&{$msg_level}("TYPO_SPELLING", - "'$typo' may be misspelled - perhaps '$typo_fix'?\n" . $herecurr) && + "'$typo' may be misspelled - perhaps '$typo_fix'?\n" . $hereptr) && $fix) { $fixed[$fixlinenr] =~ s/(^|[^A-Za-z@])($typo)($|[^A-Za-z@])/$1$typo_fix$3/; } } } +# check for invalid commit id + if ($in_commit_log && $line =~ /(^fixes:|\bcommit)\s+([0-9a-f]{6,40})\b/i) { + my $id; + my $description; + ($id, $description) = git_commit_info($2, undef, undef); + if (!defined($id)) { + WARN("UNKNOWN_COMMIT_ID", + "Unknown commit id '$2', maybe rebased or not pulled?\n" . $herecurr); + } + } + +# check for repeated words separated by a single space +# avoid false positive from list command eg, '-rw-r--r-- 1 root root' + if (($rawline =~ /^\+/ || $in_commit_log) && + $rawline !~ /[bcCdDlMnpPs\?-][rwxsStT-]{9}/) { + pos($rawline) = 1 if (!$in_commit_log); + while ($rawline =~ /\b($word_pattern) (?=($word_pattern))/g) { + + my $first = $1; + my $second = $2; + my $start_pos = $-[1]; + my $end_pos = $+[2]; + if ($first =~ /(?:struct|union|enum)/) { + pos($rawline) += length($first) + length($second) + 1; + next; + } + + next if (lc($first) ne lc($second)); + next if ($first eq 'long'); + + # check for character before and after the word matches + my $start_char = ''; + my $end_char = ''; + $start_char = substr($rawline, $start_pos - 1, 1) if ($start_pos > ($in_commit_log ? 0 : 1)); + $end_char = substr($rawline, $end_pos, 1) if ($end_pos < length($rawline)); + + next if ($start_char =~ /^\S$/); + next if (index(" \t.,;?!", $end_char) == -1); + + # avoid repeating hex occurrences like 'ff ff fe 09 ...' + if ($first =~ /\b[0-9a-f]{2,}\b/i) { + next if (!exists($allow_repeated_words{lc($first)})); + } + + if (WARN("REPEATED_WORD", + "Possible repeated word: '$first'\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\b$first $second\b/$first/; + } + } + + # if it's a repeated word on consecutive lines in a comment block + if ($prevline =~ /$;+\s*$/ && + $prevrawline =~ /($word_pattern)\s*$/) { + my $last_word = $1; + if ($rawline =~ /^\+\s*\*\s*$last_word /) { + if (WARN("REPEATED_WORD", + "Possible repeated word: '$last_word'\n" . $hereprev) && + $fix) { + $fixed[$fixlinenr] =~ s/(\+\s*\*\s*)$last_word /$1/; + } + } + } + } + # ignore non-hunk lines and lines being removed next if (!$hunk_line || $line =~ /^-/); @@ -2776,11 +3503,26 @@ sub process { $rpt_cleaners = 1; } +# Check for FSF mailing addresses. + if ($rawline =~ /\bwrite to the Free/i || + $rawline =~ /\b675\s+Mass\s+Ave/i || + $rawline =~ /\b59\s+Temple\s+Pl/i || + $rawline =~ /\b51\s+Franklin\s+St/i) { + my $herevet = "$here\n" . cat_vet($rawline) . "\n"; + my $msg_level = \&ERROR; + $msg_level = \&CHK if ($file); + &{$msg_level}("FSF_MAILING_ADDRESS", + "Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.\n" . $herevet) + } + # check for Kconfig help text having a real description # Only applies when adding the entry originally, after that we do not have # sufficient context to determine whether it is indeed long enough. if ($realfile =~ /Kconfig/ && - $line =~ /^\+\s*config\s+/) { + # 'choice' is usually the last thing on the line (though + # Kconfig supports named choices), so use a word boundary + # (\b) rather than a whitespace character (\s) + $line =~ /^\+\s*(?:config|menuconfig|choice)\b/) { my $length = 0; my $cnt = $realcnt; my $ln = $linenr + 1; @@ -2795,7 +3537,7 @@ sub process { next if ($f =~ /^-/); last if (!$file && $f =~ /^\@\@/); - if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate)\s*\"/) { + if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|prompt)\s*["']/) { $is_start = 1; } elsif ($lines[$ln - 1] =~ /^\+\s*(?:---)?help(?:---)?$/) { $length = -1; @@ -2805,7 +3547,13 @@ sub process { $f =~ s/#.*//; $f =~ s/^\s+//; next if ($f =~ /^$/); - if ($f =~ /^\s*config\s/) { + + # This only checks context lines in the patch + # and so hopefully shouldn't trigger false + # positives, even though some of these are + # common words in help texts + if ($f =~ /^\s*(?:config|menuconfig|choice|endchoice| + if|endif|menu|endmenu|source)\b/x) { $is_end = 1; last; } @@ -2818,22 +3566,44 @@ sub process { #print "is_start<$is_start> is_end<$is_end> length<$length>\n"; } -# check for MAINTAINERS entries that don't have the right form - if ($realfile =~ /^MAINTAINERS$/ && - $rawline =~ /^\+[A-Z]:/ && - $rawline !~ /^\+[A-Z]:\t\S/) { - if (WARN("MAINTAINERS_STYLE", - "MAINTAINERS entries use one tab after TYPE:\n" . $herecurr) && - $fix) { - $fixed[$fixlinenr] =~ s/^(\+[A-Z]):\s*/$1:\t/; +# check MAINTAINERS entries + if ($realfile =~ /^MAINTAINERS$/) { +# check MAINTAINERS entries for the right form + if ($rawline =~ /^\+[A-Z]:/ && + $rawline !~ /^\+[A-Z]:\t\S/) { + if (WARN("MAINTAINERS_STYLE", + "MAINTAINERS entries use one tab after TYPE:\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/^(\+[A-Z]):\s*/$1:\t/; + } + } +# check MAINTAINERS entries for the right ordering too + my $preferred_order = 'MRLSWQBCPTFXNK'; + if ($rawline =~ /^\+[A-Z]:/ && + $prevrawline =~ /^[\+ ][A-Z]:/) { + $rawline =~ /^\+([A-Z]):\s*(.*)/; + my $cur = $1; + my $curval = $2; + $prevrawline =~ /^[\+ ]([A-Z]):\s*(.*)/; + my $prev = $1; + my $prevval = $2; + my $curindex = index($preferred_order, $cur); + my $previndex = index($preferred_order, $prev); + if ($curindex < 0) { + WARN("MAINTAINERS_STYLE", + "Unknown MAINTAINERS entry type: '$cur'\n" . $herecurr); + } else { + if ($previndex >= 0 && $curindex < $previndex) { + WARN("MAINTAINERS_STYLE", + "Misordered MAINTAINERS entry - list '$cur:' before '$prev:'\n" . $hereprev); + } elsif ((($prev eq 'F' && $cur eq 'F') || + ($prev eq 'X' && $cur eq 'X')) && + ($prevval cmp $curval) > 0) { + WARN("MAINTAINERS_STYLE", + "Misordered MAINTAINERS entry - list file patterns in alphabetic order\n" . $hereprev); + } + } } - } - -# discourage the use of boolean for type definition attributes of Kconfig options - if ($realfile =~ /Kconfig/ && - $line =~ /^\+\s*\bboolean\b/) { - WARN("CONFIG_TYPE_BOOLEAN", - "Use of boolean is deprecated, please use bool instead.\n" . $herecurr); } if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) && @@ -2858,7 +3628,7 @@ sub process { my @compats = $rawline =~ /\"([a-zA-Z0-9\-\,\.\+_]+)\"/g; my $dt_path = $root . "/Documentation/devicetree/bindings/"; - my $vp_file = $dt_path . "vendor-prefixes.txt"; + my $vp_file = $dt_path . "vendor-prefixes.yaml"; foreach my $compat (@compats) { my $compat2 = $compat; @@ -2873,7 +3643,7 @@ sub process { next if $compat !~ /^([a-zA-Z0-9\-]+)\,/; my $vendor = $1; - `grep -Eq "^$vendor\\b" $vp_file`; + `grep -Eq "\\"\\^\Q$vendor\E,\\.\\*\\":" $vp_file`; if ( $? >> 8 ) { WARN("UNDOCUMENTED_DT_STRING", "DT compatible string vendor \"$vendor\" appears un-documented -- check $vp_file\n" . $herecurr); @@ -2881,15 +3651,83 @@ sub process { } } +# check for using SPDX license tag at beginning of files + if ($realline == $checklicenseline) { + if ($rawline =~ /^[ \+]\s*\#\!\s*\//) { + $checklicenseline = 2; + } elsif ($rawline =~ /^\+/) { + my $comment = ""; + if (!$frr && + $realfile =~ /\.(h|s|S)$/) { + $comment = '/*'; + } elsif ($frr && + $realfile =~ /\.(h|s|S)$/) { + $comment = '//'; + } elsif ($realfile =~ /\.(c|dts|dtsi)$/) { + $comment = '//'; + } elsif (($checklicenseline == 2) || $realfile =~ /\.(sh|pl|py|awk|tc|yaml)$/) { + $comment = '#'; + } elsif ($realfile =~ /\.rst$/) { + $comment = '..'; + } + +# check SPDX comment style for .[chsS] files + if ($realfile =~ /\.[chsS]$/ && + $rawline =~ /SPDX-License-Identifier:/ && + $rawline !~ m@^\+\s*\Q$comment\E\s*@) { + WARN("SPDX_LICENSE_TAG", + "Improper SPDX comment style for '$realfile', please use '$comment' instead\n" . $herecurr); + } + + if ($comment !~ /^$/ && + $rawline !~ m@^\+\Q$comment\E SPDX-License-Identifier: @) { + WARN("SPDX_LICENSE_TAG", + "Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr); + } elsif ($rawline =~ /(SPDX-License-Identifier: .*)/) { + my $spdx_license = $1; + if (!is_SPDX_License_valid($spdx_license)) { + WARN("SPDX_LICENSE_TAG", + "'$spdx_license' is not supported in LICENSES/...\n" . $herecurr); + } + if ($realfile =~ m@^Documentation/devicetree/bindings/@ && + not $spdx_license =~ /GPL-2\.0.*BSD-2-Clause/) { + my $msg_level = \&WARN; + $msg_level = \&CHK if ($file); + if (&{$msg_level}("SPDX_LICENSE_TAG", + + "DT binding documents should be licensed (GPL-2.0-only OR BSD-2-Clause)\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/SPDX-License-Identifier: .*/SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)/; + } + } + } + } + } + +# check for embedded filenames + if ($rawline =~ /^\+.*\Q$realfile\E/) { + WARN("EMBEDDED_FILENAME", + "It's generally not useful to have the filename in the file\n" . $herecurr); + } + # check we are in a valid source file if not then ignore this hunk next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/); +# check for using SPDX-License-Identifier on the wrong line number + if ($realline != $checklicenseline && + $rawline =~ /\bSPDX-License-Identifier:/ && + substr($line, @-, @+ - @-) eq "$;" x (@+ - @-)) { + WARN("SPDX_LICENSE_TAG", + "Misplaced SPDX-License-Identifier tag - use line $checklicenseline instead\n" . $herecurr); + } + # line length limit (with some exclusions) # # There are a few types of lines that may extend beyond $max_line_length: # logging functions like pr_info that end in a string # lines with a single string # #defines that are a single string +# lines with an RFC3986 like URL # # There are 3 different line length message types: # LONG_LINE_COMMENT a comment starts before but extends beyond $max_line_length @@ -2921,6 +3759,10 @@ sub process { $line =~ /^\+\s*(?:\w+)?\s*DEFINE_PER_CPU/) { $msg_type = ""; + # URL ($rawline is used in case the URL is in a comment) + } elsif ($rawline =~ /^\+.*\b[a-z][\w\.\+\-]*:\/\/\S+/i) { + $msg_type = ""; + # Otherwise set the alternate message types # a comment starts before $max_line_length @@ -2936,36 +3778,34 @@ sub process { if ($msg_type ne "" && (show_type("LONG_LINE") || show_type($msg_type))) { - WARN($msg_type, - "line over $max_line_length characters\n" . $herecurr); + my $msg_level = \&WARN; + $msg_level = \&CHK if ($file); + &{$msg_level}($msg_type, + "line length of $length exceeds $max_line_length columns\n" . $herecurr); } } # check for adding lines without a newline. if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) { - WARN("MISSING_EOF_NEWLINE", - "adding a line without newline at end of file\n" . $herecurr); + if (WARN("MISSING_EOF_NEWLINE", + "adding a line without newline at end of file\n" . $herecurr) && + $fix) { + fix_delete_line($fixlinenr+1, "No newline at end of file"); + } } -# Blackfin: use hi/lo macros - if ($realfile =~ m@arch/blackfin/.*\.S$@) { - if ($line =~ /\.[lL][[:space:]]*=.*&[[:space:]]*0x[fF][fF][fF][fF]/) { - my $herevet = "$here\n" . cat_vet($line) . "\n"; - ERROR("LO_MACRO", - "use the LO() macro, not (... & 0xFFFF)\n" . $herevet); - } - if ($line =~ /\.[hH][[:space:]]*=.*>>[[:space:]]*16/) { - my $herevet = "$here\n" . cat_vet($line) . "\n"; - ERROR("HI_MACRO", - "use the HI() macro, not (... >> 16)\n" . $herevet); - } +# check for .L prefix local symbols in .S files + if ($realfile =~ /\.S$/ && + $line =~ /^\+\s*(?:[A-Z]+_)?SYM_[A-Z]+_(?:START|END)(?:_[A-Z_]+)?\s*\(\s*\.L/) { + WARN("AVOID_L_PREFIX", + "Avoid using '.L' prefixed local symbol names for denoting a range of code via 'SYM_*_START/END' annotations; see Documentation/asm-annotations.rst\n" . $herecurr); } # check we are in a valid source file C or perl if not then ignore this hunk next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/); # at the beginning of a line any tabs must come first and anything -# more than 8 must use tabs. +# more than $tabsize must use tabs. if ($rawline =~ /^\+\s* \t\s*\S/ || $rawline =~ /^\+\s* \s*/) { my $herevet = "$here\n" . cat_vet($rawline) . "\n"; @@ -2984,33 +3824,53 @@ sub process { "please, no space before tabs\n" . $herevet) && $fix) { while ($fixed[$fixlinenr] =~ - s/(^\+.*) {8,8}\t/$1\t\t/) {} + s/(^\+.*) {$tabsize,$tabsize}\t/$1\t\t/) {} while ($fixed[$fixlinenr] =~ s/(^\+.*) +\t/$1\t/) {} } } +# check for assignments on the start of a line + if ($sline =~ /^\+\s+($Assignment)[^=]/) { + my $operator = $1; + if (CHK("ASSIGNMENT_CONTINUATIONS", + "Assignment operator '$1' should be on the previous line\n" . $hereprev) && + $fix && $prevrawline =~ /^\+/) { + # add assignment operator to the previous line, remove from current line + $fixed[$fixlinenr - 1] .= " $operator"; + $fixed[$fixlinenr] =~ s/\Q$operator\E\s*//; + } + } + # check for && or || at the start of a line if ($rawline =~ /^\+\s*(&&|\|\|)/) { - CHK("LOGICAL_CONTINUATIONS", - "Logical continuations should be on the previous line\n" . $hereprev); + my $operator = $1; + if (CHK("LOGICAL_CONTINUATIONS", + "Logical continuations should be on the previous line\n" . $hereprev) && + $fix && $prevrawline =~ /^\+/) { + # insert logical operator at last non-comment, non-whitepsace char on previous line + $prevline =~ /[\s$;]*$/; + my $line_end = substr($prevrawline, $-[0]); + $fixed[$fixlinenr - 1] =~ s/\Q$line_end\E$/ $operator$line_end/; + $fixed[$fixlinenr] =~ s/\Q$operator\E\s*//; + } } # check indentation starts on a tab stop - if ($^V && $^V ge 5.10.0 && - $sline =~ /^\+\t+( +)(?:$c90_Keywords\b|\{\s*$|\}\s*(?:else\b|while\b|\s*$))/) { + if ($perl_version_ok && + $sline =~ /^\+\t+( +)(?:$c90_Keywords\b|\{\s*$|\}\s*(?:else\b|while\b|\s*$)|$Declare\s*$Ident\s*[;=])/) { my $indent = length($1); - if ($indent % 8) { + if ($indent % $tabsize) { if (WARN("TABSTOP", "Statements should start on a tabstop\n" . $herecurr) && $fix) { - $fixed[$fixlinenr] =~ s@(^\+\t+) +@$1 . "\t" x ($indent/8)@e; + $fixed[$fixlinenr] =~ s@(^\+\t+) +@$1 . "\t" x ($indent/$tabsize)@e; } } } # check multi-line statement indentation matches previous line - if ($^V && $^V ge 5.10.0 && + if ($perl_version_ok && $prevline =~ /^\+([ \t]*)((?:$c90_Keywords(?:\s+if)\s*)|(?:$Declare\s*)?(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*|(?:\*\s*)*$Lval\s*=\s*$Ident\s*)\(.*(\&\&|\|\||,)\s*$/) { $prevline =~ /^\+(\t*)(.*)$/; my $oldindent = $1; @@ -3022,8 +3882,8 @@ sub process { my $newindent = $2; my $goodtabindent = $oldindent . - "\t" x ($pos / 8) . - " " x ($pos % 8); + "\t" x ($pos / $tabsize) . + " " x ($pos % $tabsize); my $goodspaceindent = $oldindent . " " x $pos; if ($newindent ne $goodtabindent && @@ -3061,7 +3921,7 @@ sub process { if ($realfile =~ m@^(drivers/net/|net/)@ && $prevrawline =~ /^\+[ \t]*\/\*[ \t]*$/ && $rawline =~ /^\+[ \t]*\*/ && - $realline > 2) { + $realline > 3) { # Do not warn about the initial copyright comment block after SPDX-License-Identifier WARN("NETWORKING_BLOCK_COMMENT_STYLE", "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev); } @@ -3143,43 +4003,48 @@ sub process { } # check for missing blank lines after declarations - if ($sline =~ /^\+\s+\S/ && #Not at char 1 - # actual declarations - ($prevline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ || +# (declarations must have the same indentation and not be at the start of line) + if (($prevline =~ /\+(\s+)\S/) && $sline =~ /^\+$1\S/) { + # use temporaries + my $sl = $sline; + my $pl = $prevline; + # remove $Attribute/$Sparse uses to simplify comparisons + $sl =~ s/\b(?:$Attribute|$Sparse)\b//g; + $pl =~ s/\b(?:$Attribute|$Sparse)\b//g; + if (($pl =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ || # function pointer declarations - $prevline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ || + $pl =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ || # foo bar; where foo is some local typedef or #define - $prevline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ || + $pl =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ || # known declaration macros - $prevline =~ /^\+\s+$declaration_macros/) && + $pl =~ /^\+\s+$declaration_macros/) && # for "else if" which can look like "$Ident $Ident" - !($prevline =~ /^\+\s+$c90_Keywords\b/ || + !($pl =~ /^\+\s+$c90_Keywords\b/ || # other possible extensions of declaration lines - $prevline =~ /(?:$Compare|$Assignment|$Operators)\s*$/ || + $pl =~ /(?:$Compare|$Assignment|$Operators)\s*$/ || # not starting a section or a macro "\" extended line - $prevline =~ /(?:\{\s*|\\)$/) && + $pl =~ /(?:\{\s*|\\)$/) && # looks like a declaration - !($sline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ || + !($sl =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ || # function pointer declarations - $sline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ || + $sl =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ || # foo bar; where foo is some local typedef or #define - $sline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ || + $sl =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ || # known declaration macros - $sline =~ /^\+\s+$declaration_macros/ || + $sl =~ /^\+\s+$declaration_macros/ || # start of struct or union or enum - $sline =~ /^\+\s+(?:union|struct|enum|typedef)\b/ || + $sl =~ /^\+\s+(?:static\s+)?(?:const\s+)?(?:union|struct|enum|typedef)\b/ || # start or end of block or continuation of declaration - $sline =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ || + $sl =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ || # bitfield continuation - $sline =~ /^\+\s+$Ident\s*:\s*\d+\s*[,;]/ || + $sl =~ /^\+\s+$Ident\s*:\s*\d+\s*[,;]/ || # other possible extensions of declaration lines - $sline =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/) && - # indentation of previous and current line are the same - (($prevline =~ /\+(\s+)\S/) && $sline =~ /^\+$1\S/)) { - if (WARN("LINE_SPACING", - "Missing a blank line after declarations\n" . $hereprev) && - $fix) { - fix_insert_line($fixlinenr, "\+"); + $sl =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/)) { + if (WARN("LINE_SPACING", + "Missing a blank line after declarations\n" . $hereprev) && + $fix) { + fix_insert_line($fixlinenr, "\+"); + } } } @@ -3232,12 +4097,16 @@ sub process { } # check indentation of a line with a break; -# if the previous line is a goto or return and is indented the same # of tabs +# if the previous line is a goto, return or break +# and is indented the same # of tabs if ($sline =~ /^\+([\t]+)break\s*;\s*$/) { my $tabs = $1; - if ($prevline =~ /^\+$tabs(?:goto|return)\b/) { - WARN("UNNECESSARY_BREAK", - "break is not useful after a goto or return\n" . $hereprev); + if ($prevline =~ /^\+$tabs(goto|return|break)\b/) { + if (WARN("UNNECESSARY_BREAK", + "break is not useful after a $1\n" . $hereprev) && + $fix) { + fix_delete_line($fixlinenr, $rawline); + } } } @@ -3247,18 +4116,6 @@ sub process { "CVS style keyword markers, these will _not_ be updated\n". $herecurr); } -# Blackfin: don't use __builtin_bfin_[cs]sync - if ($line =~ /__builtin_bfin_csync/) { - my $herevet = "$here\n" . cat_vet($line) . "\n"; - ERROR("CSYNC", - "use the CSYNC() macro in asm/blackfin.h\n" . $herevet); - } - if ($line =~ /__builtin_bfin_ssync/) { - my $herevet = "$here\n" . cat_vet($line) . "\n"; - ERROR("SSYNC", - "use the SSYNC() macro in asm/blackfin.h\n" . $herevet); - } - # check for old HOTPLUG __dev<foo> section markings if ($line =~ /\b(__dev(init|exit)(data|const|))\b/) { WARN("HOTPLUG_SECTION", @@ -3506,11 +4363,11 @@ sub process { #print "line<$line> prevline<$prevline> indent<$indent> sindent<$sindent> check<$check> continuation<$continuation> s<$s> cond_lines<$cond_lines> stat_real<$stat_real> stat<$stat>\n"; if ($check && $s ne '' && - (($sindent % 8) != 0 || + (($sindent % $tabsize) != 0 || ($sindent < $indent) || ($sindent == $indent && ($s !~ /^\s*(?:\}|\{|else\b)/)) || - ($sindent > $indent + 8))) { + ($sindent > $indent + $tabsize))) { WARN("SUSPECT_CODE_INDENT", "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n"); } @@ -3532,6 +4389,17 @@ sub process { #ignore lines not being added next if ($line =~ /^[^\+]/); +# check for self assignments used to avoid compiler warnings +# e.g.: int foo = foo, *bar = NULL; +# struct foo bar = *(&(bar)); + if ($line =~ /^\+\s*(?:$Declare)?([A-Za-z_][A-Za-z\d_]*)\s*=/) { + my $var = $1; + if ($line =~ /^\+\s*(?:$Declare)?$var\s*=\s*(?:$var|\*\s*\(?\s*&\s*\(?\s*$var\s*\)?\s*\)?)\s*[;,]/) { + WARN("SELF_ASSIGNMENT", + "Do not use self-assignments to avoid compiler warnings\n" . $herecurr); + } + } + # check for dereferences that span multiple lines if ($prevline =~ /^\+.*$Lval\s*(?:\.|->)\s*$/ && $line =~ /^\+\s*(?!\#\s*(?!define\s+|if))\s*$Lval/) { @@ -3627,17 +4495,13 @@ sub process { # no C99 // comments if ($line =~ m{//}) { - if ($rawlines[$linenr - 1] =~ /SPDX-License-Identifier:/) { - # ignore - } elsif (!$allow_c99_comments) { - if(ERROR("C99_COMMENTS", - "do not use C99 // comments\n" . $herecurr) && - $fix) { - my $line = $fixed[$fixlinenr]; - if ($line =~ /\/\/(.*)$/) { - my $comment = trim($1); - $fixed[$fixlinenr] =~ s@\/\/(.*)$@/\* $comment \*/@; - } + if (!$allow_c99_comments && ERROR("C99_COMMENTS", + "do not use C99 // comments\n" . $herecurr) && + $fix) { + my $line = $fixed[$fixlinenr]; + if ($line =~ /\/\/(.*)$/) { + my $comment = trim($1); + $fixed[$fixlinenr] =~ s@\/\/(.*)$@/\* $comment \*/@; } } else { WARN("C99_COMMENTS", @@ -3654,13 +4518,13 @@ sub process { if (defined $realline_next && exists $lines[$realline_next - 1] && !defined $suppress_export{$realline_next} && - ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ || - $lines[$realline_next - 1] =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) { + ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/)) { # Handle definitions which produce identifiers with # a prefix: # XXX(foo); # EXPORT_SYMBOL(something_foo); my $name = $1; + $name =~ s/^\s*($Ident).*/$1/; if ($stat =~ /^(?:.\s*}\s*\n)?.([A-Z_]+)\s*\(\s*($Ident)/ && $name =~ /^${Ident}_$2/) { #print "FOO C name<$name>\n"; @@ -3682,8 +4546,7 @@ sub process { } if (!defined $suppress_export{$linenr} && $prevline =~ /^.\s*$/ && - ($line =~ /EXPORT_SYMBOL.*\((.*)\)/ || - $line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) { + ($line =~ /EXPORT_SYMBOL.*\((.*)\)/)) { #print "FOO B <$lines[$linenr - 1]>\n"; $suppress_export{$linenr} = 2; } @@ -3694,7 +4557,8 @@ sub process { } # check for global initialisers. - if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*\s*=\s*($zero_initializer)\s*;/) { + if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*\s*=\s*($zero_initializer)\s*;/ && + !exclude_global_initialisers($realfile)) { if (ERROR("GLOBAL_INITIALISERS", "do not initialise globals to $1\n" . $herecurr) && $fix) { @@ -3718,19 +4582,48 @@ sub process { "type '$tmp' should be specified in [[un]signed] [short|int|long|long long] order\n" . $herecurr); } +# check for unnecessary <signed> int declarations of short/long/long long + while ($sline =~ m{\b($TypeMisordered(\s*\*)*|$C90_int_types)\b}g) { + my $type = trim($1); + next if ($type !~ /\bint\b/); + next if ($type !~ /\b(?:short|long\s+long|long)\b/); + my $new_type = $type; + $new_type =~ s/\b\s*int\s*\b/ /; + $new_type =~ s/\b\s*(?:un)?signed\b\s*/ /; + $new_type =~ s/^const\s+//; + $new_type = "unsigned $new_type" if ($type =~ /\bunsigned\b/); + $new_type = "const $new_type" if ($type =~ /^const\b/); + $new_type =~ s/\s+/ /g; + $new_type = trim($new_type); + if (WARN("UNNECESSARY_INT", + "Prefer '$new_type' over '$type' as the int is unnecessary\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\b\Q$type\E\b/$new_type/; + } + } + # check for static const char * arrays. if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) { WARN("STATIC_CONST_CHAR_ARRAY", "static const char * array should probably be static const char * const\n" . $herecurr); - } + } + +# check for initialized const char arrays that should be static const + if ($line =~ /^\+\s*const\s+(char|unsigned\s+char|_*u8|(?:[us]_)?int8_t)\s+\w+\s*\[\s*(?:\w+\s*)?\]\s*=\s*"/) { + if (WARN("STATIC_CONST_CHAR_ARRAY", + "const array should probably be static const\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/(^.\s*)const\b/${1}static const/; + } + } # check for static char foo[] = "bar" declarations. if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) { WARN("STATIC_CONST_CHAR_ARRAY", "static char array declaration should probably be static const char\n" . $herecurr); - } + } # check for const <foo> const where <foo> is not a pointer or array type if ($sline =~ /\bconst\s+($BasicType)\s+const\b/) { @@ -3744,12 +4637,24 @@ sub process { } } +# check for const static or static <non ptr type> const declarations +# prefer 'static const <foo>' over 'const static <foo>' and 'static <foo> const' + if ($sline =~ /^\+\s*const\s+static\s+($Type)\b/ || + $sline =~ /^\+\s*static\s+($BasicType)\s+const\b/) { + if (WARN("STATIC_CONST", + "Move const after static - use 'static const $1'\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\bconst\s+static\b/static const/; + $fixed[$fixlinenr] =~ s/\bstatic\s+($BasicType)\s+const\b/static const $1/; + } + } + # check for non-global char *foo[] = {"bar", ...} declarations. if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) { WARN("STATIC_CONST_CHAR_ARRAY", "char * array declaration might be better as static const\n" . $herecurr); - } + } # check for sizeof(foo)/sizeof(foo[0]) that could be ARRAY_SIZE(foo) if ($line =~ m@\bsizeof\s*\(\s*($Lval)\s*\)@) { @@ -3765,7 +4670,7 @@ sub process { } # check for function declarations without arguments like "int foo()" - if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) { + if ($line =~ /(\b$Type\s*$Ident)\s*\(\s*\)/) { if (ERROR("FUNCTION_WITHOUT_ARGS", "Bad function definition - $1() should probably be $1(void)\n" . $herecurr) && $fix) { @@ -3866,25 +4771,23 @@ sub process { "printk() should include KERN_<LEVEL> facility level\n" . $herecurr); } - if ($line =~ /\bprintk\s*\(\s*KERN_([A-Z]+)/) { - my $orig = $1; +# prefer variants of (subsystem|netdev|dev|pr)_<level> to printk(KERN_<LEVEL> + if ($line =~ /\b(printk(_once|_ratelimited)?)\s*\(\s*KERN_([A-Z]+)/) { + my $printk = $1; + my $modifier = $2; + my $orig = $3; + $modifier = "" if (!defined($modifier)); my $level = lc($orig); $level = "warn" if ($level eq "warning"); my $level2 = $level; $level2 = "dbg" if ($level eq "debug"); + $level .= $modifier; + $level2 .= $modifier; WARN("PREFER_PR_LEVEL", - "Prefer [subsystem eg: netdev]_$level2([subsystem]dev, ... then dev_$level2(dev, ... then pr_$level(... to printk(KERN_$orig ...\n" . $herecurr); - } - - if ($line =~ /\bpr_warning\s*\(/) { - if (WARN("PREFER_PR_LEVEL", - "Prefer pr_warn(... to pr_warning(...\n" . $herecurr) && - $fix) { - $fixed[$fixlinenr] =~ - s/\bpr_warning\b/pr_warn/; - } + "Prefer [subsystem eg: netdev]_$level2([subsystem]dev, ... then dev_$level2(dev, ... then pr_$level(... to $printk(KERN_$orig ...\n" . $herecurr); } +# prefer dev_<level> to dev_printk(KERN_<LEVEL> if ($line =~ /\bdev_printk\s*\(\s*KERN_([A-Z]+)/) { my $orig = $1; my $level = lc($orig); @@ -3894,6 +4797,12 @@ sub process { "Prefer dev_$level(... to dev_printk(KERN_$orig, ...\n" . $herecurr); } +# trace_printk should not be used in production code. + if ($line =~ /\b(trace_printk|trace_puts|ftrace_vprintk)\s*\(/) { + WARN("TRACE_PRINTK", + "Do not use $1() in production code (this can be ignored if built only with a debug config option)\n" . $herecurr); + } + # ENOSYS means "bad syscall nr" and nothing else. This will have a small # number of false positives, but assembly files are not checked, so at # least the arch entry code will not trigger this warning. @@ -3902,16 +4811,29 @@ sub process { "ENOSYS means 'invalid syscall nr' and nothing else\n" . $herecurr); } +# ENOTSUPP is not a standard error code and should be avoided in new patches. +# Folks usually mean EOPNOTSUPP (also called ENOTSUP), when they type ENOTSUPP. +# Similarly to ENOSYS warning a small number of false positives is expected. + if (!$file && $line =~ /\bENOTSUPP\b/) { + if (WARN("ENOTSUPP", + "ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\bENOTSUPP\b/EOPNOTSUPP/; + } + } + # function brace can't be on same line, except for #defines of do while, # or if closed on same line - if (($line=~/$Type\s*$Ident\(.*\).*\s*{/) and - !($line=~/\#\s*define.*do\s\{/) and !($line=~/}/)) { + if ($perl_version_ok && + $sline =~ /$Type\s*$Ident\s*$balanced_parens\s*\{/ && + $sline !~ /\#\s*define\b.*do\s*\{/ && + $sline !~ /}/) { if (ERROR("OPEN_BRACE", - "open brace '{' following function declarations go on the next line\n" . $herecurr) && + "open brace '{' following function definitions go on the next line\n" . $herecurr) && $fix) { fix_delete_line($fixlinenr, $rawline); my $fixed_line = $rawline; - $fixed_line =~ /(^..*$Type\s*$Ident\(.*\)\s*){(.*)$/; + $fixed_line =~ /(^..*$Type\s*$Ident\(.*\)\s*)\{(.*)$/; my $line1 = $1; my $line2 = $2; fix_insert_line($fixlinenr, ltrim($line1)); @@ -4028,7 +4950,7 @@ sub process { my ($where, $prefix) = ($-[1], $1); if ($prefix !~ /$Type\s+$/ && ($where != 0 || $prefix !~ /^.\s+$/) && - $prefix !~ /[{,]\s+$/) { + $prefix !~ /[{,:]\s+$/) { if (ERROR("BRACKET_SPACE", "space prohibited before open square bracket '['\n" . $herecurr) && $fix) { @@ -4205,7 +5127,7 @@ sub process { my $rtrim_before = 0; my $space_after = 0; if ($line=~/\#\s*define/) { - # ignore , spacing in macros + # FRR: ignore , spacing in macros } elsif ($ctx =~ /Wx./) { if (ERROR("SPACING", "space prohibited before that '$op' $at\n" . $hereptr)) { @@ -4329,7 +5251,7 @@ sub process { # A colon needs no spaces before when it is # terminating a case value or a label. } elsif ($opv eq ':C' || $opv eq ':L') { - if ($ctx =~ /Wx./) { + if ($ctx =~ /Wx./ and $realfile !~ m@.*\.lds\.h$@) { if (ERROR("SPACING", "space prohibited before that '$op' $at\n" . $hereptr)) { $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]); @@ -4347,7 +5269,7 @@ sub process { ($op eq '>' && $ca =~ /<\S+\@\S+$/)) { - $ok = 1; + $ok = 1; } # for asm volatile statements @@ -4413,7 +5335,7 @@ sub process { ## $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) { ## ## # Remove any bracketed sections to ensure we do not -## # falsly report the parameters of functions. +## # falsely report the parameters of functions. ## my $ln = $line; ## while ($ln =~ s/\([^\(\)]*\)//g) { ## } @@ -4425,11 +5347,11 @@ sub process { #need space before brace following if, while, etc if (($line =~ /\(.*\)\{/ && $line !~ /\($Type\)\{/) || - $line =~ /do\{/) { + $line =~ /\b(?:else|do)\{/) { if (ERROR("SPACING", "space required before the open brace '{'\n" . $herecurr) && $fix) { - $fixed[$fixlinenr] =~ s/^(\+.*(?:do|\)))\{/$1 {/; + $fixed[$fixlinenr] =~ s/^(\+.*(?:do|else|\)))\{/$1 {/; } } @@ -4443,7 +5365,7 @@ sub process { # closing brace should have a space following it when it has anything # on the line - if ($line =~ /}(?!(?:,|;|\)))\S/) { + if ($line =~ /}(?!(?:,|;|\)|\}))\S/) { if (ERROR("SPACING", "space required after that close brace '}'\n" . $herecurr) && $fix) { @@ -4518,7 +5440,9 @@ sub process { } # check for unnecessary parentheses around comparisons in if uses - if ($^V && $^V ge 5.10.0 && defined($stat) && +# when !drivers/staging or command-line uses --strict + if (($realfile !~ m@^(?:drivers/staging/)@ || $check_orig) && + $perl_version_ok && defined($stat) && $stat =~ /(^.\s*if\s*($balanced_parens))/) { my $if_stat = $1; my $test = substr($2, 1, -1); @@ -4541,10 +5465,38 @@ sub process { } } +# check that goto labels aren't indented (allow a single space indentation) +# and ignore bitfield definitions like foo:1 +# Strictly, labels can have whitespace after the identifier and before the : +# but this is not allowed here as many ?: uses would appear to be labels + # FRR: has indented labels + if (!$frr && + $sline =~ /^.\s+[A-Za-z_][A-Za-z\d_]*:(?!\s*\d+)/ && + $sline !~ /^. [A-Za-z\d_][A-Za-z\d_]*:/ && + $sline !~ /^.\s+default:/) { + if (WARN("INDENTED_LABEL", + "labels should not be indented\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ + s/^(.)\s+/$1/; + } + } + +# check if a statement with a comma should be two statements like: +# foo = bar(), /* comma should be semicolon */ +# bar = baz(); + if (defined($stat) && + $stat =~ /^\+\s*(?:$Lval\s*$Assignment\s*)?$FuncArg\s*,\s*(?:$Lval\s*$Assignment\s*)?$FuncArg\s*;\s*$/) { + my $cnt = statement_rawlines($stat); + my $herectx = get_stat_here($linenr, $cnt, $here); + WARN("SUSPECT_COMMA_SEMICOLON", + "Possible comma where semicolon could be used\n" . $herectx); + } + # return is not a function if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) { my $spacing = $1; - if ($^V && $^V ge 5.10.0 && + if ($perl_version_ok && $stat =~ /^.\s*return\s*($balanced_parens)\s*;\s*$/) { my $value = $1; $value = deparenthesize($value); @@ -4568,10 +5520,10 @@ sub process { $lines[$linenr - 3] !~ /^[ +]\s*$Ident\s*:/) { WARN("RETURN_VOID", "void function return statements are not generally useful\n" . $hereprev); - } + } # if statements using unnecessary parentheses - ie: if ((foo == bar)) - if ($^V && $^V ge 5.10.0 && + if ($perl_version_ok && $line =~ /\bif\s*((?:\(\s*){2,})/) { my $openparens = $1; my $count = $openparens =~ tr@\(@\(@; @@ -4588,7 +5540,7 @@ sub process { # avoid cases like "foo + BAR < baz" # only fix matches surrounded by parentheses to avoid incorrect # conversions like "FOO < baz() + 5" being "misfixed" to "baz() > FOO + 5" - if ($^V && $^V ge 5.10.0 && + if ($perl_version_ok && $line =~ /^\+(.*)\b($Constant|[A-Z_][A-Z0-9_]*)\s*($Compare)\s*($LvalOrFunc)/) { my $lead = $1; my $const = $2; @@ -4616,7 +5568,7 @@ sub process { # Return of what appears to be an errno should normally be negative if ($sline =~ /\breturn(?:\s*\(+\s*|\s+)(E[A-Z]+)(?:\s*\)+\s*|\s*)[;:,]/) { my $name = $1; - if ($name ne 'EOF' && $name ne 'ERROR') { + if ($name ne 'EOF' && $name ne 'ERROR' && $name !~ /^EPOLL/) { WARN("USE_NEGATIVE_ERRNO", "return of an errno should typically be negative (ie: return -$1)\n" . $herecurr); } @@ -4661,15 +5613,37 @@ sub process { my ($s, $c) = ($stat, $cond); if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) { - ERROR("ASSIGN_IN_IF", - "do not use assignment in if condition\n" . $herecurr); + if (ERROR("ASSIGN_IN_IF", + "do not use assignment in if condition\n" . $herecurr) && + $fix && $perl_version_ok) { + if ($rawline =~ /^\+(\s+)if\s*\(\s*(\!)?\s*\(\s*(($Lval)\s*=\s*$LvalOrFunc)\s*\)\s*(?:($Compare)\s*($FuncArg))?\s*\)\s*(\{)?\s*$/) { + my $space = $1; + my $not = $2; + my $statement = $3; + my $assigned = $4; + my $test = $8; + my $against = $9; + my $brace = $15; + fix_delete_line($fixlinenr, $rawline); + fix_insert_line($fixlinenr, "$space$statement;"); + my $newline = "${space}if ("; + $newline .= '!' if defined($not); + $newline .= '(' if (defined $not && defined($test) && defined($against)); + $newline .= "$assigned"; + $newline .= " $test $against" if (defined($test) && defined($against)); + $newline .= ')' if (defined $not && defined($test) && defined($against)); + $newline .= ')'; + $newline .= " {" if (defined($brace)); + fix_insert_line($fixlinenr + 1, $newline); + } + } } # Find out what is on the end of the line after the # conditional. substr($s, 0, length($c), ''); $s =~ s/\n.*//g; - $s =~ s/$;//g; # Remove any comments + $s =~ s/$;//g; # Remove any comments if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ && $c !~ /}\s*while\s*/) { @@ -4708,7 +5682,7 @@ sub process { # if and else should not have general statements after it if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) { my $s = $1; - $s =~ s/$;//g; # Remove any comments + $s =~ s/$;//g; # Remove any comments if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) { ERROR("TRAILING_STATEMENTS", "trailing statements should be on next line\n" . $herecurr); @@ -4780,24 +5754,16 @@ sub process { while ($line =~ m{($Constant|$Lval)}g) { my $var = $1; -#gcc binary extension - if ($var =~ /^$Binary$/) { - if (WARN("GCC_BINARY_CONSTANT", - "Avoid gcc v4.3+ binary constant extension: <$var>\n" . $herecurr) && - $fix) { - my $hexval = sprintf("0x%x", oct($var)); - $fixed[$fixlinenr] =~ - s/\b$var\b/$hexval/; - } - } - #CamelCase if ($var !~ /^$Constant$/ && $var =~ /[A-Z][a-z]|[a-z][A-Z]/ && +#Ignore some autogenerated defines and enum values + $var !~ /^(?:[A-Z]+_){1,5}[A-Z]{1,3}[a-z]/ && #Ignore Page<foo> variants $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ && -#Ignore SI style variants like nS, mV and dB (ie: max_uV, regulator_min_uA_show) - $var !~ /^(?:[a-z_]*?)_?[a-z][A-Z](?:_[a-z_]+)?$/ && +#Ignore SI style variants like nS, mV and dB +#(ie: max_uV, regulator_min_uA_show, RANGE_mA_VALUE) + $var !~ /^(?:[a-z0-9_]*|[A-Z0-9_]*)?_?[a-z][A-Z](?:_[a-z0-9_]+|_[A-Z0-9_]+)?$/ && #Ignore some three character SI units explicitly, like MiB and KHz $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) { while ($var =~ m{($Ident)}g) { @@ -4879,6 +5845,7 @@ sub process { if (defined $define_args && $define_args ne "") { $define_args = substr($define_args, 1, length($define_args) - 2); $define_args =~ s/\s*//g; + $define_args =~ s/\\\+?//g; @def_args = split(",", $define_args); $complex = 1; } @@ -4889,13 +5856,13 @@ sub process { $dstat =~ s/\s*$//s; # Flatten any parentheses and braces - while ($dstat =~ s/\([^\(\)]*\)/1/ || - $dstat =~ s/\{[^\{\}]*\}/1/ || - $dstat =~ s/.\[[^\[\]]*\]/1/) + while ($dstat =~ s/\([^\(\)]*\)/1u/ || + $dstat =~ s/\{[^\{\}]*\}/1u/ || + $dstat =~ s/.\[[^\[\]]*\]/1u/) { } - # Flatten any obvious string concatentation. + # Flatten any obvious string concatenation. while ($dstat =~ s/($String)\s*$Ident/$1/ || $dstat =~ s/$Ident\s*($String)/$1/) { @@ -4920,12 +5887,8 @@ sub process { #print "REST<$rest> dstat<$dstat> ctx<$ctx>\n"; $ctx =~ s/\n*$//; - my $herectx = $here . "\n"; my $stmt_cnt = statement_rawlines($ctx); - - for (my $n = 0; $n < $stmt_cnt; $n++) { - $herectx .= raw_line($linenr, $n) . "\n"; - } + my $herectx = get_stat_here($linenr, $stmt_cnt, $here); if ($dstat ne '' && $dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(), @@ -4936,6 +5899,7 @@ sub process { $dstat !~ /^\.$Ident\s*=/ && # .foo = $dstat !~ /^(?:\#\s*$Ident|\#\s*$Constant)\s*$/ && # stringification #foo $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ && # do {...} while (...); // do {...} while (...) + $dstat !~ /^while\s*$Constant\s*$Constant\s*$/ && # while (...) {...} $dstat !~ /^for\s*$Constant$/ && # for (...) $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar() $dstat !~ /^do\s*{/ && # do {... @@ -4977,10 +5941,10 @@ sub process { next if ($arg =~ /\.\.\./); next if ($arg =~ /^type$/i); my $tmp_stmt = $define_stmt; - $tmp_stmt =~ s/\b(typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g; + $tmp_stmt =~ s/\b(__must_be_array|offsetof|sizeof|sizeof_field|__stringify|typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g; $tmp_stmt =~ s/\#+\s*$arg\b//g; $tmp_stmt =~ s/\b$arg\s*\#\#//g; - my $use_cnt = $tmp_stmt =~ s/\b$arg\b//g; + my $use_cnt = () = $tmp_stmt =~ /\b$arg\b/g; if ($use_cnt > 1) { CHK("MACRO_ARG_REUSE", "Macro argument reuse '$arg' - possible side-effects?\n" . "$herectx"); @@ -4997,12 +5961,9 @@ sub process { # check for macros with flow control, but without ## concatenation # ## concatenation is commonly a macro that defines a function so ignore those if ($has_flow_statement && !$has_arg_concat) { - my $herectx = $here . "\n"; my $cnt = statement_rawlines($ctx); + my $herectx = get_stat_here($linenr, $cnt, $here); - for (my $n = 0; $n < $cnt; $n++) { - $herectx .= raw_line($linenr, $n) . "\n"; - } WARN("MACRO_WITH_FLOW_CONTROL", "Macros with flow control statements should be avoided\n" . "$herectx"); } @@ -5022,7 +5983,7 @@ sub process { # do {} while (0) macro tests: # single-statement macros do not need to be enclosed in do while (0) loop, # macro should not end with a semicolon - if ($^V && $^V ge 5.10.0 && + if ($perl_version_ok && $realfile !~ m@/vmlinux.lds.h$@ && $line =~ /^.\s*\#\s*define\s+$Ident(\()?/) { my $ln = $linenr; @@ -5042,11 +6003,7 @@ sub process { $ctx =~ s/\n*$//; my $cnt = statement_rawlines($ctx); - my $herectx = $here . "\n"; - - for (my $n = 0; $n < $cnt; $n++) { - $herectx .= raw_line($linenr, $n) . "\n"; - } + my $herectx = get_stat_here($linenr, $cnt, $here); if (($stmts =~ tr/;/;/) == 1 && $stmts !~ /^\s*(if|while|for|switch)\b/) { @@ -5060,27 +6017,13 @@ sub process { } elsif ($dstat =~ /^\+\s*#\s*define\s+$Ident.*;\s*$/) { $ctx =~ s/\n*$//; my $cnt = statement_rawlines($ctx); - my $herectx = $here . "\n"; - - for (my $n = 0; $n < $cnt; $n++) { - $herectx .= raw_line($linenr, $n) . "\n"; - } + my $herectx = get_stat_here($linenr, $cnt, $here); WARN("TRAILING_SEMICOLON", "macros should not use a trailing semicolon\n" . "$herectx"); } } -# make sure symbols are always wrapped with VMLINUX_SYMBOL() ... -# all assignments may have only one of the following with an assignment: -# . -# ALIGN(...) -# VMLINUX_SYMBOL(...) - if ($realfile eq 'vmlinux.lds.h' && $line =~ /(?:(?:^|\s)$Ident\s*=|=\s*$Ident(?:\s|$))/) { - WARN("MISSING_VMLINUX_SYMBOL", - "vmlinux.lds.h needs VMLINUX_SYMBOL() around C-visible symbols\n" . $herecurr); - } - # check for redundant bracing round if etc if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) { my ($level, $endln, @chunks) = @@ -5187,12 +6130,8 @@ sub process { } } if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) { - my $herectx = $here . "\n"; my $cnt = statement_rawlines($block); - - for (my $n = 0; $n < $cnt; $n++) { - $herectx .= raw_line($linenr, $n) . "\n"; - } + my $herectx = get_stat_here($linenr, $cnt, $here); WARN("BRACES", "braces {} are not necessary for single statement blocks\n" . $herectx); @@ -5200,28 +6139,28 @@ sub process { } if (!defined $suppress_ifbraces{$linenr - 1} && - $line =~ /\b(frr_with_)/) { - my ($level, $endln, @chunks) = - ctx_statement_full($linenr, $realcnt, $-[0]); + $line =~ /\b(frr_with_)/) { + my ($level, $endln, @chunks) = + ctx_statement_full($linenr, $realcnt, $-[0]); + + # Check the condition. + my ($cond, $block) = @{$chunks[0]}; + #print "CHECKING<$linenr> cond<$cond> block<$block>\n"; + if (defined $cond) { + substr($block, 0, length($cond), ''); + } + + if ($level == 0 && $block !~ /^\s*\{/) { + my $herectx = $here . "\n"; + my $cnt = statement_rawlines($block); - # Check the condition. - my ($cond, $block) = @{$chunks[0]}; - #print "CHECKING<$linenr> cond<$cond> block<$block>\n"; - if (defined $cond) { - substr($block, 0, length($cond), ''); + for (my $n = 0; $n < $cnt; $n++) { + $herectx .= raw_line($linenr, $n) . "\n"; } - if ($level == 0 && $block !~ /^\s*\{/) { - my $herectx = $here . "\n"; - my $cnt = statement_rawlines($block); - - for (my $n = 0; $n < $cnt; $n++) { - $herectx .= raw_line($linenr, $n) . "\n"; - } - - WARN("BRACES", - "braces {} are mandatory for frr_with_* blocks\n" . $herectx); - } + WARN("BRACES", + "braces {} are mandatory for frr_with_* blocks\n" . $herectx); + } } # check for single line unbalanced braces @@ -5304,6 +6243,17 @@ sub process { "Prefer using '\"%s...\", __func__' to using '$context_function', this function's name, in a string\n" . $herecurr); } +# check for unnecessary function tracing like uses +# This does not use $logFunctions because there are many instances like +# 'dprintk(FOO, "%s()\n", __func__);' which do not match $logFunctions + if ($rawline =~ /^\+.*\([^"]*"$tracing_logging_tags{0,3}%s(?:\s*\(\s*\)\s*)?$tracing_logging_tags{0,3}(?:\\n)?"\s*,\s*__func__\s*\)\s*;/) { + if (WARN("TRACING_LOGGING", + "Unnecessary ftrace-like logging - prefer using ftrace\n" . $herecurr) && + $fix) { + fix_delete_line($fixlinenr, $rawline); + } + } + # check for spaces before a quoted newline if ($rawline =~ /^.*\".*\s\\n/) { if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE", @@ -5315,15 +6265,30 @@ sub process { } # concatenated string without spaces between elements - if ($line =~ /$String[A-Z_]/ || $line =~ /[A-Za-z0-9_]$String/) { - CHK("CONCATENATED_STRING", - "Concatenated strings should use spaces between elements\n" . $herecurr); + if ($line =~ /$String[A-Z_]/ || + ($line =~ /([A-Za-z0-9_]+)$String/ && $1 !~ /^[Lu]$/)) { + if (CHK("CONCATENATED_STRING", + "Concatenated strings should use spaces between elements\n" . $herecurr) && + $fix) { + while ($line =~ /($String)/g) { + my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]); + $fixed[$fixlinenr] =~ s/\Q$extracted_string\E([A-Za-z0-9_])/$extracted_string $1/; + $fixed[$fixlinenr] =~ s/([A-Za-z0-9_])\Q$extracted_string\E/$1 $extracted_string/; + } + } } # uncoalesced string fragments - if ($line =~ /$String\s*"/) { - CHK("STRING_FRAGMENTS", - "Consecutive strings are generally better as a single string\n" . $herecurr); + if ($line =~ /$String\s*[Lu]?"/) { + # FRR: WARN -> CHK + if (CHK("STRING_FRAGMENTS", + "Consecutive strings are generally better as a single string\n" . $herecurr) && + $fix) { + while ($line =~ /($String)(?=\s*")/g) { + my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]); + $fixed[$fixlinenr] =~ s/\Q$extracted_string\E\s*"/substr($extracted_string, 0, -1)/e; + } + } } # check for non-standard and hex prefixed decimal printf formats @@ -5352,16 +6317,21 @@ sub process { } # check for line continuations in quoted strings with odd counts of " - if ($rawline =~ /\\$/ && $rawline =~ tr/"/"/ % 2) { + if ($rawline =~ /\\$/ && $sline =~ tr/"/"/ % 2) { WARN("LINE_CONTINUATIONS", "Avoid line continuations in quoted strings\n" . $herecurr); } # warn about #if 0 if ($line =~ /^.\s*\#\s*if\s+0\b/) { - CHK("REDUNDANT_CODE", - "if this code is redundant consider removing it\n" . - $herecurr); + WARN("IF_0", + "Consider removing the code enclosed by this #if 0 and its #endif\n" . $herecurr); + } + +# warn about #if 1 + if ($line =~ /^.\s*\#\s*if\s+1\b/) { + WARN("IF_1", + "Consider removing the #if 1 and its #endif\n" . $herecurr); } # check for needless "if (<foo>) fn(<foo>)" uses @@ -5408,7 +6378,8 @@ sub process { my ($s, $c) = ctx_statement_block($linenr - 3, $realcnt, 0); # print("line: <$line>\nprevline: <$prevline>\ns: <$s>\nc: <$c>\n\n\n"); - if ($s =~ /(?:^|\n)[ \+]\s*(?:$Type\s*)?\Q$testval\E\s*=\s*(?:\([^\)]*\)\s*)?\s*(?:devm_)?(?:[kv][czm]alloc(?:_node|_array)?\b|kstrdup|kmemdup|(?:dev_)?alloc_skb)/) { + if ($s =~ /(?:^|\n)[ \+]\s*(?:$Type\s*)?\Q$testval\E\s*=\s*(?:\([^\)]*\)\s*)?\s*$allocFunctions\s*\(/ && + $s !~ /\b__GFP_NOWARN\b/ ) { WARN("OOM_MESSAGE", "Possible unnecessary 'out of memory' message\n" . $hereprev); } @@ -5431,8 +6402,30 @@ sub process { "Avoid logging continuation uses where feasible\n" . $herecurr); } +# check for unnecessary use of %h[xudi] and %hh[xudi] in logging functions + if (defined $stat && + $line =~ /\b$logFunctions\s*\(/ && + index($stat, '"') >= 0) { + my $lc = $stat =~ tr@\n@@; + $lc = $lc + $linenr; + my $stat_real = get_stat_real($linenr, $lc); + pos($stat_real) = index($stat_real, '"'); + while ($stat_real =~ /[^\"%]*(%[\#\d\.\*\-]*(h+)[idux])/g) { + my $pspec = $1; + my $h = $2; + my $lineoff = substr($stat_real, 0, $-[1]) =~ tr@\n@@; + if (WARN("UNNECESSARY_MODIFIER", + "Integer promotion: Using '$h' in '$pspec' is unnecessary\n" . "$here\n$stat_real\n") && + $fix && $fixed[$fixlinenr + $lineoff] =~ /^\+/) { + my $nspec = $pspec; + $nspec =~ s/h//g; + $fixed[$fixlinenr + $lineoff] =~ s/\Q$pspec\E/$nspec/; + } + } + } + # check for mask then right shift without a parentheses - if ($^V && $^V ge 5.10.0 && + if ($perl_version_ok && $line =~ /$LvalOrFunc\s*\&\s*($LvalOrFunc)\s*>>/ && $4 !~ /^\&/) { # $LvalOrFunc may be &foo, ignore if so WARN("MASK_THEN_SHIFT", @@ -5440,7 +6433,7 @@ sub process { } # check for pointer comparisons to NULL - if ($^V && $^V ge 5.10.0) { + if ($perl_version_ok) { while ($line =~ /\b$LvalOrFunc\s*(==|\!=)\s*NULL\b/g) { my $val = $1; my $equal = "!"; @@ -5529,7 +6522,7 @@ sub process { # ignore udelay's < 10, however if (! ($delay < 10) ) { CHK("USLEEP_RANGE", - "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $herecurr); + "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.rst\n" . $herecurr); } if ($delay > 2000) { WARN("LONG_UDELAY", @@ -5541,7 +6534,7 @@ sub process { if ($line =~ /\bmsleep\s*\((\d+)\);/) { if ($1 < 20) { WARN("MSLEEP", - "msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $herecurr); + "msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.rst\n" . $herecurr); } } @@ -5589,8 +6582,7 @@ sub process { my $barriers = qr{ mb| rmb| - wmb| - read_barrier_depends + wmb }x; my $barrier_stems = qr{ mb__before_atomic| @@ -5631,6 +6623,14 @@ sub process { } } +# check for data_race without a comment. + if ($line =~ /\bdata_race\s*\(/) { + if (!ctx_has_comment($first_line, $linenr)) { + WARN("DATA_RACE", + "data_race without comment\n" . $herecurr); + } + } + # check of hardware specific defines if ($line =~ m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) { CHK("ARCH_DEFINES", @@ -5670,55 +6670,86 @@ sub process { } } -# -# Kernel macros unnused for FRR -# -# Check for __attribute__ packed, prefer __packed -# if ($realfile !~ m@\binclude/uapi/@ && -# $line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) { -# WARN("PREFER_PACKED", -# "__packed is preferred over __attribute__((packed))\n" . $herecurr); -# } - -# Check for __attribute__ aligned, prefer __aligned -# if ($realfile !~ m@\binclude/uapi/@ && -# $line =~ /\b__attribute__\s*\(\s*\(.*aligned/) { -# WARN("PREFER_ALIGNED", -# "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr); -# } - -# Check for __attribute__ format(printf, prefer __printf -# if ($realfile !~ m@\binclude/uapi/@ && -# $line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf/) { -# if (WARN("PREFER_PRINTF", -# "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr) && -# $fix) { -# $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf\s*,\s*(.*)\)\s*\)\s*\)/"__printf(" . trim($1) . ")"/ex; - -# } -# } +# Check for compiler attributes + # FRR: doesn't use kernel macro replacements for compiler attributes. + if (!$frr && + $realfile !~ m@\binclude/uapi/@ && + $rawline =~ /\b__attribute__\s*\(\s*($balanced_parens)\s*\)/) { + my $attr = $1; + $attr =~ s/\s*\(\s*(.*)\)\s*/$1/; + + my %attr_list = ( + "alias" => "__alias", + "aligned" => "__aligned", + "always_inline" => "__always_inline", + "assume_aligned" => "__assume_aligned", + "cold" => "__cold", + "const" => "__attribute_const__", + "copy" => "__copy", + "designated_init" => "__designated_init", + "externally_visible" => "__visible", + "format" => "printf|scanf", + "gnu_inline" => "__gnu_inline", + "malloc" => "__malloc", + "mode" => "__mode", + "no_caller_saved_registers" => "__no_caller_saved_registers", + "noclone" => "__noclone", + "noinline" => "noinline", + "nonstring" => "__nonstring", + "noreturn" => "__noreturn", + "packed" => "__packed", + "pure" => "__pure", + "section" => "__section", + "used" => "__used", + "weak" => "__weak" + ); + + while ($attr =~ /\s*(\w+)\s*(${balanced_parens})?/g) { + my $orig_attr = $1; + my $params = ''; + $params = $2 if defined($2); + my $curr_attr = $orig_attr; + $curr_attr =~ s/^[\s_]+|[\s_]+$//g; + if (exists($attr_list{$curr_attr})) { + my $new = $attr_list{$curr_attr}; + if ($curr_attr eq "format" && $params) { + $params =~ /^\s*\(\s*(\w+)\s*,\s*(.*)/; + $new = "__$1\($2"; + } else { + $new = "$new$params"; + } + if (WARN("PREFER_DEFINED_ATTRIBUTE_MACRO", + "Prefer $new over __attribute__(($orig_attr$params))\n" . $herecurr) && + $fix) { + my $remove = "\Q$orig_attr\E" . '\s*' . "\Q$params\E" . '(?:\s*,\s*)?'; + $fixed[$fixlinenr] =~ s/$remove//; + $fixed[$fixlinenr] =~ s/\b__attribute__/$new __attribute__/; + $fixed[$fixlinenr] =~ s/\}\Q$new\E/} $new/; + $fixed[$fixlinenr] =~ s/ __attribute__\s*\(\s*\(\s*\)\s*\)//; + } + } + } -# Check for __attribute__ format(scanf, prefer __scanf -# if ($realfile !~ m@\binclude/uapi/@ && -# $line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) { -# if (WARN("PREFER_SCANF", -# "__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr) && -# $fix) { -# $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\s*,\s*(.*)\)\s*\)\s*\)/"__scanf(" . trim($1) . ")"/ex; -# } -# } + # Check for __attribute__ unused, prefer __always_unused or __maybe_unused + if ($attr =~ /^_*unused/) { + WARN("PREFER_DEFINED_ATTRIBUTE_MACRO", + "__always_unused or __maybe_unused is preferred over __attribute__((__unused__))\n" . $herecurr); + } + } # Check for __attribute__ weak, or __weak declarations (may have link issues) -# if ($^V && $^V ge 5.10.0 && -# $line =~ /(?:$Declare|$DeclareMisordered)\s*$Ident\s*$balanced_parens\s*(?:$Attribute)?\s*;/ && -# ($line =~ /\b__attribute__\s*\(\s*\(.*\bweak\b/ || -# $line =~ /\b__weak\b/)) { -# ERROR("WEAK_DECLARATION", -# "Using weak declarations can have unintended link defects\n" . $herecurr); -# } + if (!$frr && + $perl_version_ok && + $line =~ /(?:$Declare|$DeclareMisordered)\s*$Ident\s*$balanced_parens\s*(?:$Attribute)?\s*;/ && + ($line =~ /\b__attribute__\s*\(\s*\(.*\bweak\b/ || + $line =~ /\b__weak\b/)) { + ERROR("WEAK_DECLARATION", + "Using weak declarations can have unintended link defects\n" . $herecurr); + } # check for c99 types like uint8_t used outside of uapi/ and tools/ - if ($realfile !~ m@\binclude/uapi/@ && + if (!$frr && + $realfile !~ m@\binclude/uapi/@ && $realfile !~ m@\btools/@ && $line =~ /\b($Declare)\s*$Ident\s*[=;,\[]/) { my $type = $1; @@ -5740,18 +6771,18 @@ sub process { if ($line =~ /(\(\s*$C90_int_types\s*\)\s*)($Constant)\b/) { my $cast = $1; my $const = $2; + my $suffix = ""; + my $newconst = $const; + $newconst =~ s/${Int_type}$//; + $suffix .= 'U' if ($cast =~ /\bunsigned\b/); + if ($cast =~ /\blong\s+long\b/) { + $suffix .= 'LL'; + } elsif ($cast =~ /\blong\b/) { + $suffix .= 'L'; + } if (WARN("TYPECAST_INT_CONSTANT", - "Unnecessary typecast of c90 int constant\n" . $herecurr) && + "Unnecessary typecast of c90 int constant - '$cast$const' could be '$const$suffix'\n" . $herecurr) && $fix) { - my $suffix = ""; - my $newconst = $const; - $newconst =~ s/${Int_type}$//; - $suffix .= 'U' if ($cast =~ /\bunsigned\b/); - if ($cast =~ /\blong\s+long\b/) { - $suffix .= 'LL'; - } elsif ($cast =~ /\blong\b/) { - $suffix .= 'L'; - } $fixed[$fixlinenr] =~ s/\Q$cast\E$const\b/$newconst$suffix/; } } @@ -5790,34 +6821,61 @@ sub process { } } - # check for vsprintf extension %p<foo> misuses - if (0 && $^V && $^V ge 5.10.0 && +# check for vsprintf extension %p<foo> misuses + if (!$frr && + $perl_version_ok && defined $stat && $stat =~ /^\+(?![^\{]*\{\s*).*\b(\w+)\s*\(.*$String\s*,/s && $1 !~ /^_*volatile_*$/) { - my $bad_extension = ""; + my $stat_real; + my $lc = $stat =~ tr@\n@@; $lc = $lc + $linenr; for (my $count = $linenr; $count <= $lc; $count++) { + my $specifier; + my $extension; + my $qualifier; + my $bad_specifier = ""; my $fmt = get_quoted_string($lines[$count - 1], raw_line($count, 0)); $fmt =~ s/%%//g; - if ($fmt =~ /(\%[\*\d\.]*p(?![\WFfSsBKRraEhMmIiUDdgVCbGNOx]).)/) { - $bad_extension = $1; - last; + + while ($fmt =~ /(\%[\*\d\.]*p(\w)(\w*))/g) { + $specifier = $1; + $extension = $2; + $qualifier = $3; + if ($extension !~ /[4SsBKRraEehMmIiUDdgVCbGNOxtf]/ || + ($extension eq "f" && + defined $qualifier && $qualifier !~ /^w/) || + ($extension eq "4" && + defined $qualifier && $qualifier !~ /^cc/)) { + $bad_specifier = $specifier; + last; + } + if ($extension eq "x" && !defined($stat_real)) { + if (!defined($stat_real)) { + $stat_real = get_stat_real($linenr, $lc); + } + WARN("VSPRINTF_SPECIFIER_PX", + "Using vsprintf specifier '\%px' potentially exposes the kernel memory layout, if you don't really need the address please consider using '\%p'.\n" . "$here\n$stat_real\n"); + } } - } - if ($bad_extension ne "") { - my $stat_real = raw_line($linenr, 0); - for (my $count = $linenr + 1; $count <= $lc; $count++) { - $stat_real = $stat_real . "\n" . raw_line($count, 0); + if ($bad_specifier ne "") { + my $stat_real = get_stat_real($linenr, $lc); + my $ext_type = "Invalid"; + my $use = ""; + if ($bad_specifier =~ /p[Ff]/) { + $use = " - use %pS instead"; + $use =~ s/pS/ps/ if ($bad_specifier =~ /pf/); + } + + WARN("VSPRINTF_POINTER_EXTENSION", + "$ext_type vsprintf pointer extension '$bad_specifier'$use\n" . "$here\n$stat_real\n"); } - WARN("VSPRINTF_POINTER_EXTENSION", - "Invalid vsprintf pointer extension '$bad_extension'\n" . "$here\n$stat_real\n"); } } # Check for misused memsets - if ($^V && $^V ge 5.10.0 && + if ($perl_version_ok && defined $stat && $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/) { @@ -5835,7 +6893,7 @@ sub process { } # Check for memcpy(foo, bar, ETH_ALEN) that could be ether_addr_copy(foo, bar) -# if ($^V && $^V ge 5.10.0 && +# if ($perl_version_ok && # defined $stat && # $stat =~ /^\+(?:.*?)\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) { # if (WARN("PREFER_ETHER_ADDR_COPY", @@ -5846,7 +6904,7 @@ sub process { # } # Check for memcmp(foo, bar, ETH_ALEN) that could be ether_addr_equal*(foo, bar) -# if ($^V && $^V ge 5.10.0 && +# if ($perl_version_ok && # defined $stat && # $stat =~ /^\+(?:.*?)\bmemcmp\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) { # WARN("PREFER_ETHER_ADDR_EQUAL", @@ -5855,7 +6913,7 @@ sub process { # check for memset(foo, 0x0, ETH_ALEN) that could be eth_zero_addr # check for memset(foo, 0xFF, ETH_ALEN) that could be eth_broadcast_addr -# if ($^V && $^V ge 5.10.0 && +# if ($perl_version_ok && # defined $stat && # $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) { # @@ -5876,8 +6934,15 @@ sub process { # } # } +# strlcpy uses that should likely be strscpy + if (!$frr && + $line =~ /\bstrlcpy\s*\(/) { + WARN("STRLCPY", + "Prefer strscpy over strlcpy - see: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw\@mail.gmail.com/\n" . $herecurr); + } + # typecasts on min/max could be min_t/max_t - if ($^V && $^V ge 5.10.0 && + if ($perl_version_ok && defined $stat && $stat =~ /^\+(?:.*?)\b(min|max)\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/) { if (defined $2 || defined $7) { @@ -5901,23 +6966,23 @@ sub process { } # check usleep_range arguments - if ($^V && $^V ge 5.10.0 && + if ($perl_version_ok && defined $stat && $stat =~ /^\+(?:.*?)\busleep_range\s*\(\s*($FuncArg)\s*,\s*($FuncArg)\s*\)/) { my $min = $1; my $max = $7; if ($min eq $max) { WARN("USLEEP_RANGE", - "usleep_range should not use min == max args; see Documentation/timers/timers-howto.txt\n" . "$here\n$stat\n"); + "usleep_range should not use min == max args; see Documentation/timers/timers-howto.rst\n" . "$here\n$stat\n"); } elsif ($min =~ /^\d+$/ && $max =~ /^\d+$/ && $min > $max) { WARN("USLEEP_RANGE", - "usleep_range args reversed, use min then max; see Documentation/timers/timers-howto.txt\n" . "$here\n$stat\n"); + "usleep_range args reversed, use min then max; see Documentation/timers/timers-howto.rst\n" . "$here\n$stat\n"); } } # check for naked sscanf - if ($^V && $^V ge 5.10.0 && + if ($perl_version_ok && defined $stat && $line =~ /\bsscanf\b/ && ($stat !~ /$Ident\s*=\s*sscanf\s*$balanced_parens/ && @@ -5925,14 +6990,30 @@ sub process { $stat !~ /(?:$Compare)\s*\bsscanf\s*$balanced_parens/)) { my $lc = $stat =~ tr@\n@@; $lc = $lc + $linenr; - my $stat_real = raw_line($linenr, 0); - for (my $count = $linenr + 1; $count <= $lc; $count++) { - $stat_real = $stat_real . "\n" . raw_line($count, 0); - } + my $stat_real = get_stat_real($linenr, $lc); WARN("NAKED_SSCANF", "unchecked sscanf return value\n" . "$here\n$stat_real\n"); } +# check for simple sscanf that should be kstrto<foo> + if (!$frr && + $perl_version_ok && + defined $stat && + $line =~ /\bsscanf\b/) { + my $lc = $stat =~ tr@\n@@; + $lc = $lc + $linenr; + my $stat_real = get_stat_real($linenr, $lc); + if ($stat_real =~ /\bsscanf\b\s*\(\s*$FuncArg\s*,\s*("[^"]+")/) { + my $format = $6; + my $count = $format =~ tr@%@%@; + if ($count == 1 && + $format =~ /^"\%(?i:ll[udxi]|[udxi]ll|ll|[hl]h?[udxi]|[udxi][hl]h?|[hl]h?|[udxi])"$/) { + WARN("SSCANF_TO_KSTRTO", + "Prefer kstrto<type> to single variable sscanf\n" . "$here\n$stat_real\n"); + } + } + } + # check for new externs in .h files. if ($realfile =~ /\.h$/ && $line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) { @@ -5954,8 +7035,7 @@ sub process { if (defined $cond) { substr($s, 0, length($cond), ''); } - if ($s =~ /^\s*;/ && - $function_name ne 'uninitialized_var') + if ($s =~ /^\s*;/) { WARN("AVOID_EXTERNS", "externs should be avoided in .c files\n" . $herecurr); @@ -5988,7 +7068,7 @@ sub process { } # check for function definitions - if ($^V && $^V ge 5.10.0 && + if ($perl_version_ok && defined $stat && $stat =~ /^.\s*(?:$Storage\s+)?$Type\s*($Ident)\s*$balanced_parens\s*{/s) { $context_function = $1; @@ -6016,26 +7096,26 @@ sub process { if (!grep(/$name/, @setup_docs)) { CHK("UNDOCUMENTED_SETUP", - "__setup appears un-documented -- check Documentation/admin-guide/kernel-parameters.rst\n" . $herecurr); + "__setup appears un-documented -- check Documentation/admin-guide/kernel-parameters.txt\n" . $herecurr); } } -# check for pointless casting of kmalloc return - if ($line =~ /\*\s*\)\s*[kv][czm]alloc(_node){0,1}\b/) { +# check for pointless casting of alloc functions + if ($line =~ /\*\s*\)\s*$allocFunctions\b/) { WARN("UNNECESSARY_CASTS", "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr); } # alloc style # p = alloc(sizeof(struct foo), ...) should be p = alloc(sizeof(*p), ...) - if ($^V && $^V ge 5.10.0 && - $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*([kv][mz]alloc(?:_node)?)\s*\(\s*(sizeof\s*\(\s*struct\s+$Lval\s*\))/) { + if ($perl_version_ok && + $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k|v)[mz]alloc(?:_node)?)\s*\(\s*(sizeof\s*\(\s*struct\s+$Lval\s*\))/) { CHK("ALLOC_SIZEOF_STRUCT", "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr); } # check for k[mz]alloc with multiplies that could be kmalloc_array/kcalloc - if ($^V && $^V ge 5.10.0 && + if ($perl_version_ok && defined $stat && $stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) { my $oldfunc = $3; @@ -6051,12 +7131,9 @@ sub process { } if ($r1 !~ /^sizeof\b/ && $r2 =~ /^sizeof\s*\S/ && !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*$/)) { - my $ctx = ''; - my $herectx = $here . "\n"; my $cnt = statement_rawlines($stat); - for (my $n = 0; $n < $cnt; $n++) { - $herectx .= raw_line($linenr, $n) . "\n"; - } + my $herectx = get_stat_here($linenr, $cnt, $here); + if (WARN("ALLOC_WITH_MULTIPLY", "Prefer $newfunc over $oldfunc with multiply\n" . $herectx) && $cnt == 1 && @@ -6067,14 +7144,15 @@ sub process { } # check for krealloc arg reuse - if ($^V && $^V ge 5.10.0 && - $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*\1\s*,/) { + if ($perl_version_ok && + $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*($Lval)\s*,/ && + $1 eq $3) { WARN("KREALLOC_ARG_REUSE", "Reusing the krealloc arg is almost always a bug\n" . $herecurr); } # check for alloc argument mismatch - if ($line =~ /\b(kcalloc|kmalloc_array)\s*\(\s*sizeof\b/) { + if ($line =~ /\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\(\s*sizeof\b/) { WARN("ALLOC_ARRAY_ARGS", "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr); } @@ -6100,51 +7178,51 @@ sub process { } } +# check for IS_ENABLED() without CONFIG_<FOO> ($rawline for comments too) + if ($rawline =~ /\bIS_ENABLED\s*\(\s*(\w+)\s*\)/ && $1 !~ /^${CONFIG_}/) { + WARN("IS_ENABLED_CONFIG", + "IS_ENABLED($1) is normally used as IS_ENABLED(${CONFIG_}$1)\n" . $herecurr); + } + # check for #if defined CONFIG_<FOO> || defined CONFIG_<FOO>_MODULE - if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(CONFIG_[A-Z_]+)\s*\)?\s*\|\|\s*defined(?:\s*\(?\s*|\s+)\1_MODULE\s*\)?\s*$/) { + if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(${CONFIG_}[A-Z_]+)\s*\)?\s*\|\|\s*defined(?:\s*\(?\s*|\s+)\1_MODULE\s*\)?\s*$/) { my $config = $1; if (WARN("PREFER_IS_ENABLED", - "Prefer IS_ENABLED(<FOO>) to CONFIG_<FOO> || CONFIG_<FOO>_MODULE\n" . $herecurr) && + "Prefer IS_ENABLED(<FOO>) to ${CONFIG_}<FOO> || ${CONFIG_}<FOO>_MODULE\n" . $herecurr) && $fix) { $fixed[$fixlinenr] = "\+#if IS_ENABLED($config)"; } } -# check for case / default statements not preceded by break/fallthrough/switch - if ($line =~ /^.\s*(?:case\s+(?:$Ident|$Constant)\s*|default):/) { - my $has_break = 0; - my $has_statement = 0; - my $count = 0; - my $prevline = $linenr; - while ($prevline > 1 && ($file || $count < 3) && !$has_break) { - $prevline--; - my $rline = $rawlines[$prevline - 1]; - my $fline = $lines[$prevline - 1]; - last if ($fline =~ /^\@\@/); - next if ($fline =~ /^\-/); - next if ($fline =~ /^.(?:\s*(?:case\s+(?:$Ident|$Constant)[\s$;]*|default):[\s$;]*)*$/); - $has_break = 1 if ($rline =~ /fall[\s_-]*(through|thru)/i); - next if ($fline =~ /^.[\s$;]*$/); - $has_statement = 1; - $count++; - $has_break = 1 if ($fline =~ /\bswitch\b|\b(?:break\s*;[\s$;]*$|exit\s*\(\b|return\b|goto\b|continue\b)/); - } - if (!$has_break && $has_statement) { - WARN("MISSING_BREAK", - "Possible switch case/default not preceded by break or fallthrough comment\n" . $herecurr); +# check for /* fallthrough */ like comment, prefer fallthrough; + my @fallthroughs = ( + 'fallthrough', + '@fallthrough@', + 'lint -fallthrough[ \t]*', + 'intentional(?:ly)?[ \t]*fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)', + '(?:else,?\s*)?FALL(?:S | |-)?THR(?:OUGH|U|EW)[ \t.!]*(?:-[^\n\r]*)?', + 'Fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?', + 'fall(?:s | |-)?thr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?', + ); + if ($raw_comment ne '') { + foreach my $ft (@fallthroughs) { + if ($raw_comment =~ /$ft/) { + my $msg_level = \&WARN; + $msg_level = \&CHK if ($file); + &{$msg_level}("PREFER_FALLTHROUGH", + "Prefer 'fallthrough;' over fallthrough comment\n" . $herecurr); + last; + } } } # check for switch/default statements without a break; - if ($^V && $^V ge 5.10.0 && + if ($perl_version_ok && defined $stat && $stat =~ /^\+[$;\s]*(?:case[$;\s]+\w+[$;\s]*:[$;\s]*|)*[$;\s]*\bdefault[$;\s]*:[$;\s]*;/g) { - my $ctx = ''; - my $herectx = $here . "\n"; my $cnt = statement_rawlines($stat); - for (my $n = 0; $n < $cnt; $n++) { - $herectx .= raw_line($linenr, $n) . "\n"; - } + my $herectx = get_stat_here($linenr, $cnt, $here); + WARN("DEFAULT_NO_BREAK", "switch default: should use break\n" . $herectx); } @@ -6203,20 +7281,53 @@ sub process { "consider using a completion\n" . $herecurr); } +# recommend kstrto* over simple_strto* and strict_strto* + if (!$frr && + $line =~ /\b((simple|strict)_(strto(l|ll|ul|ull)))\s*\(/) { + WARN("CONSIDER_KSTRTO", + "$1 is obsolete, use k$3 instead\n" . $herecurr); + } + # check for __initcall(), use device_initcall() explicitly or more appropriate function please if ($line =~ /^.\s*__initcall\s*\(/) { WARN("USE_DEVICE_INITCALL", "please use device_initcall() or more appropriate function instead of __initcall() (see include/linux/init.h)\n" . $herecurr); } +# check for spin_is_locked(), suggest lockdep instead + if ($line =~ /\bspin_is_locked\(/) { + WARN("USE_LOCKDEP", + "Where possible, use lockdep_assert_held instead of assertions based on spin_is_locked\n" . $herecurr); + } + +# check for deprecated apis + if ($line =~ /\b($deprecated_apis_search)\b\s*\(/) { + my $deprecated_api = $1; + my $new_api = $deprecated_apis{$deprecated_api}; + WARN("DEPRECATED_API", + "Deprecated use of '$deprecated_api', prefer '$new_api' instead\n" . $herecurr); + } + +# check for various structs that are normally const (ops, kgdb, device_tree) +# and avoid what seem like struct definitions 'struct foo {' + if (!$frr && + defined($const_structs) && + $line !~ /\bconst\b/ && + $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) { + WARN("CONST_STRUCT", + "struct $1 should normally be const\n" . $herecurr); + } + # use of NR_CPUS is usually wrong # ignore definitions of NR_CPUS and usage to define arrays as likely right +# ignore designated initializers using NR_CPUS if ($line =~ /\bNR_CPUS\b/ && $line !~ /^.\s*\s*#\s*if\b.*\bNR_CPUS\b/ && $line !~ /^.\s*\s*#\s*define\b.*\bNR_CPUS\b/ && $line !~ /^.\s*$Declare\s.*\[[^\]]*NR_CPUS[^\]]*\]/ && $line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ && - $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/) + $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/ && + $line !~ /^.\s*\.\w+\s*=\s*.*\bNR_CPUS\b/) { WARN("NR_CPUS", "usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr); @@ -6229,12 +7340,29 @@ sub process { } # likely/unlikely comparisons similar to "(likely(foo) > 0)" - if ($^V && $^V ge 5.10.0 && + if ($perl_version_ok && $line =~ /\b((?:un)?likely)\s*\(\s*$FuncArg\s*\)\s*$Compare/) { WARN("LIKELY_MISUSE", "Using $1 should generally have parentheses around the comparison\n" . $herecurr); } +# return sysfs_emit(foo, fmt, ...) fmt without newline + if ($line =~ /\breturn\s+sysfs_emit\s*\(\s*$FuncArg\s*,\s*($String)/ && + substr($rawline, $-[6], $+[6] - $-[6]) !~ /\\n"$/) { + my $offset = $+[6] - 1; + if (WARN("SYSFS_EMIT", + "return sysfs_emit(...) formats should include a terminating newline\n" . $herecurr) && + $fix) { + substr($fixed[$fixlinenr], $offset, 0) = '\\n'; + } + } + +# nested likely/unlikely calls + if ($line =~ /\b(?:(?:un)?likely)\s*\(\s*!?\s*(IS_ERR(?:_OR_NULL|_VALUE)?|WARN)/) { + WARN("LIKELY_MISUSE", + "nested (un)?likely() calls, $1 already uses unlikely() internally\n" . $herecurr); + } + # whine mightly about in_atomic if ($line =~ /\bin_atomic\s*\(/) { if ($realfile =~ m@^drivers/@) { @@ -6246,34 +7374,6 @@ sub process { } } -# whine about ACCESS_ONCE - if ($^V && $^V ge 5.10.0 && - $line =~ /\bACCESS_ONCE\s*$balanced_parens\s*(=(?!=))?\s*($FuncArg)?/) { - my $par = $1; - my $eq = $2; - my $fun = $3; - $par =~ s/^\(\s*(.*)\s*\)$/$1/; - if (defined($eq)) { - if (WARN("PREFER_WRITE_ONCE", - "Prefer WRITE_ONCE(<FOO>, <BAR>) over ACCESS_ONCE(<FOO>) = <BAR>\n" . $herecurr) && - $fix) { - $fixed[$fixlinenr] =~ s/\bACCESS_ONCE\s*\(\s*\Q$par\E\s*\)\s*$eq\s*\Q$fun\E/WRITE_ONCE($par, $fun)/; - } - } else { - if (WARN("PREFER_READ_ONCE", - "Prefer READ_ONCE(<FOO>) over ACCESS_ONCE(<FOO>)\n" . $herecurr) && - $fix) { - $fixed[$fixlinenr] =~ s/\bACCESS_ONCE\s*\(\s*\Q$par\E\s*\)/READ_ONCE($par)/; - } - } - } - -# check for mutex_trylock_recursive usage - if ($line =~ /mutex_trylock_recursive/) { - ERROR("LOCKING", - "recursive locking is bad, do not use this ever.\n" . $herecurr); - } - # check for lockdep_set_novalidate_class if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ || $line =~ /__lockdep_no_validate__\s*\)/ ) { @@ -6291,9 +7391,70 @@ sub process { "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr); } +# check for DEVICE_ATTR uses that could be DEVICE_ATTR_<FOO> +# and whether or not function naming is typical and if +# DEVICE_ATTR permissions uses are unusual too + if ($perl_version_ok && + defined $stat && + $stat =~ /\bDEVICE_ATTR\s*\(\s*(\w+)\s*,\s*\(?\s*(\s*(?:${multi_mode_perms_string_search}|0[0-7]{3,3})\s*)\s*\)?\s*,\s*(\w+)\s*,\s*(\w+)\s*\)/) { + my $var = $1; + my $perms = $2; + my $show = $3; + my $store = $4; + my $octal_perms = perms_to_octal($perms); + if ($show =~ /^${var}_show$/ && + $store =~ /^${var}_store$/ && + $octal_perms eq "0644") { + if (WARN("DEVICE_ATTR_RW", + "Use DEVICE_ATTR_RW\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*$show\s*,\s*$store\s*\)/DEVICE_ATTR_RW(${var})/; + } + } elsif ($show =~ /^${var}_show$/ && + $store =~ /^NULL$/ && + $octal_perms eq "0444") { + if (WARN("DEVICE_ATTR_RO", + "Use DEVICE_ATTR_RO\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*$show\s*,\s*NULL\s*\)/DEVICE_ATTR_RO(${var})/; + } + } elsif ($show =~ /^NULL$/ && + $store =~ /^${var}_store$/ && + $octal_perms eq "0200") { + if (WARN("DEVICE_ATTR_WO", + "Use DEVICE_ATTR_WO\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*NULL\s*,\s*$store\s*\)/DEVICE_ATTR_WO(${var})/; + } + } elsif ($octal_perms eq "0644" || + $octal_perms eq "0444" || + $octal_perms eq "0200") { + my $newshow = "$show"; + $newshow = "${var}_show" if ($show ne "NULL" && $show ne "${var}_show"); + my $newstore = $store; + $newstore = "${var}_store" if ($store ne "NULL" && $store ne "${var}_store"); + my $rename = ""; + if ($show ne $newshow) { + $rename .= " '$show' to '$newshow'"; + } + if ($store ne $newstore) { + $rename .= " '$store' to '$newstore'"; + } + WARN("DEVICE_ATTR_FUNCTIONS", + "Consider renaming function(s)$rename\n" . $herecurr); + } else { + WARN("DEVICE_ATTR_PERMS", + "DEVICE_ATTR unusual permissions '$perms' used\n" . $herecurr); + } + } + # Mode permission misuses where it seems decimal should be octal # This uses a shortcut match to avoid unnecessary uses of a slow foreach loop - if ($^V && $^V ge 5.10.0 && +# o Ignore module_param*(...) uses with a decimal 0 permission as that has a +# specific definition of not visible in sysfs. +# o Ignore proc_create*(...) uses with a decimal 0 permission as that means +# use the default permissions + if ($perl_version_ok && defined $stat && $line =~ /$mode_perms_search/) { foreach my $entry (@mode_permission_funcs) { @@ -6302,10 +7463,7 @@ sub process { my $lc = $stat =~ tr@\n@@; $lc = $lc + $linenr; - my $stat_real = raw_line($linenr, 0); - for (my $count = $linenr + 1; $count <= $lc; $count++) { - $stat_real = $stat_real . "\n" . raw_line($count, 0); - } + my $stat_real = get_stat_real($linenr, $lc); my $skip_args = ""; if ($arg_pos > 1) { @@ -6316,8 +7474,9 @@ sub process { if ($stat =~ /$test/) { my $val = $1; $val = $6 if ($skip_args ne ""); - if (($val =~ /^$Int$/ && $val !~ /^$Octal$/) || - ($val =~ /^$Octal$/ && length($val) ne 4)) { + if (!($func =~ /^(?:module_param|proc_create)/ && $val eq "0") && + (($val =~ /^$Int$/ && $val !~ /^$Octal$/) || + ($val =~ /^$Octal$/ && length($val) ne 4))) { ERROR("NON_OCTAL_PERMISSIONS", "Use 4 digit octal (0777) not decimal permissions\n" . "$here\n" . $stat_real); } @@ -6330,30 +7489,13 @@ sub process { } # check for uses of S_<PERMS> that could be octal for readability - if ($line =~ /\b$mode_perms_string_search\b/) { - my $val = ""; - my $oval = ""; - my $to = 0; - my $curpos = 0; - my $lastpos = 0; - while ($line =~ /\b(($mode_perms_string_search)\b(?:\s*\|\s*)?\s*)/g) { - $curpos = pos($line); - my $match = $2; - my $omatch = $1; - last if ($lastpos > 0 && ($curpos - length($omatch) != $lastpos)); - $lastpos = $curpos; - $to |= $mode_permission_string_types{$match}; - $val .= '\s*\|\s*' if ($val ne ""); - $val .= $match; - $oval .= $omatch; - } - $oval =~ s/^\s*\|\s*//; - $oval =~ s/\s*\|\s*$//; - my $octal = sprintf("%04o", $to); + while ($line =~ m{\b($multi_mode_perms_string_search)\b}g) { + my $oval = $1; + my $octal = perms_to_octal($oval); if (WARN("SYMBOLIC_PERMS", "Symbolic permissions '$oval' are not preferred. Consider using octal permissions '$octal'.\n" . $herecurr) && $fix) { - $fixed[$fixlinenr] =~ s/$val/$octal/; + $fixed[$fixlinenr] =~ s/\Q$oval\E/$octal/; } } @@ -6375,6 +7517,12 @@ sub process { } } +# check for sysctl duplicate constants + if ($line =~ /\.extra[12]\s*=\s*&(zero|one|int_max)\b/) { + WARN("DUPLICATED_SYSCTL_CONST", + "duplicated sysctl range checking value '$1', consider using the shared one in include/linux/sysctl.h\n" . $herecurr); + } + # check for usage of nonstandard fixed-width integral types if ($line =~ /u_int8_t/ || $line =~ /u_int32_t/ || @@ -6437,7 +7585,7 @@ sub process { exit(0); } - # This is not a patch, and we are are in 'no-patch' mode so + # This is not a patch, and we are in 'no-patch' mode so # just keep quiet. if (!$chk_patch && !$is_patch) { exit(0); @@ -6447,9 +7595,38 @@ sub process { ERROR("NOT_UNIFIED_DIFF", "Does not appear to be a unified-diff format patch\n"); } - if ($is_patch && $has_commit_log && $chk_signoff && $signoff == 0) { - ERROR("MISSING_SIGN_OFF", - "Missing Signed-off-by: line(s)\n"); + if ($is_patch && $has_commit_log && $chk_signoff) { + if ($signoff == 0) { + ERROR("MISSING_SIGN_OFF", + "Missing Signed-off-by: line(s)\n"); + } elsif ($authorsignoff != 1) { + # authorsignoff values: + # 0 -> missing sign off + # 1 -> sign off identical + # 2 -> names and addresses match, comments mismatch + # 3 -> addresses match, names different + # 4 -> names match, addresses different + # 5 -> names match, addresses excluding subaddress details (refer RFC 5233) match + + my $sob_msg = "'From: $author' != 'Signed-off-by: $author_sob'"; + + if ($authorsignoff == 0) { + ERROR("NO_AUTHOR_SIGN_OFF", + "Missing Signed-off-by: line by nominal patch author '$author'\n"); + } elsif ($authorsignoff == 2) { + CHK("FROM_SIGN_OFF_MISMATCH", + "From:/Signed-off-by: email comments mismatch: $sob_msg\n"); + } elsif ($authorsignoff == 3) { + WARN("FROM_SIGN_OFF_MISMATCH", + "From:/Signed-off-by: email name mismatch: $sob_msg\n"); + } elsif ($authorsignoff == 4) { + WARN("FROM_SIGN_OFF_MISMATCH", + "From:/Signed-off-by: email address mismatch: $sob_msg\n"); + } elsif ($authorsignoff == 5) { + WARN("FROM_SIGN_OFF_MISMATCH", + "From:/Signed-off-by: email subaddress mismatch: $sob_msg\n"); + } + } } print report_dump(); diff --git a/tools/checkpatch.sh b/tools/checkpatch.sh index 6071f4804d..bf63057b02 100755 --- a/tools/checkpatch.sh +++ b/tools/checkpatch.sh @@ -3,7 +3,8 @@ usage="./checkpatch.sh <patch> <tree>" patch=$1 tree=$2 -checkpatch="$tree/tools/checkpatch.pl --no-tree -f" +scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)" +checkpatch="$scriptdir/checkpatch.pl --no-tree -f" ignore="ldpd\|babeld" cwd=${PWD##*/} dirty=0 diff --git a/tools/etc/frr/support_bundle_commands.conf b/tools/etc/frr/support_bundle_commands.conf index 914363157a..b3889e8784 100644 --- a/tools/etc/frr/support_bundle_commands.conf +++ b/tools/etc/frr/support_bundle_commands.conf @@ -34,6 +34,8 @@ show bgp nexthop show bgp vrf all summary show bgp vrf all ipv4 show bgp vrf all ipv6 +show bgp vrf all ipv4 vpn +show bgp vrf all ipv6 vpn show bgp vrf all neighbors show bgp evpn route @@ -68,6 +70,8 @@ show ip nht vrf all show ipv6 nht vrf all show ip route vrf all show ipv6 route vrf all +show ip fib +show ipv6 fib show nexthop-group rib show route-map show memory @@ -76,9 +80,9 @@ show vrf show work-queues show debugging hashtable show running-config -show thread cpu -show thread poll -show thread timers +show event cpu +show event poll +show event timers show daemons show version CMD_LIST_END @@ -173,7 +177,7 @@ CMD_LIST_END PROC_NAME:ospf6 CMD_LIST_START show ipv6 ospf6 vrf all -show ipv6 ospf6 vrfs +show ipv6 ospf6 vrfs show ipv6 ospf6 vrf all border-routers show ipv6 ospf6 vrf all border-routers detail show ipv6 ospf6 vrf all database @@ -239,3 +243,19 @@ show ipv6 pim bsr show ipv6 pim bsrp-info show ipv6 pim bsm-databases CMD_LIST_END + +#MGMT Support Bundle Command List +PROC_NAME:mgmt +CMD_LIST_START +show mgmt backend-adapter all +show mgmt backend-yang-xpath-registry +show mgmt commit-history +show mgmt datastore all +show mgmt datastore-contents candidate json +show mgmt datastore-contents running json +show mgmt frontend-adapter all detail +show mgmt get-config candidate / +show mgmt get-config running / +show mgmt transaction all +show mgmt yang-xpath-subscription / +CMD_LIST_END diff --git a/tools/frr-llvm-cg.c b/tools/frr-llvm-cg.c index 3a7222e421..f366ba62f9 100644 --- a/tools/frr-llvm-cg.c +++ b/tools/frr-llvm-cg.c @@ -231,7 +231,7 @@ static void walk_const_fptrs(struct json_object *js_call, LLVMValueRef value, "%s: calls function pointer from unhandled const GEP\n", prefix); *hdr_written = true; - /* fallthru */ + fallthrough; default: /* to help the user / development */ if (!*hdr_written) { diff --git a/tools/frr-reload.py b/tools/frr-reload.py index 0e0aec9839..73479c634b 100755 --- a/tools/frr-reload.py +++ b/tools/frr-reload.py @@ -25,6 +25,7 @@ from ipaddress import IPv6Address, ip_network from pprint import pformat + # Python 3 def iteritems(d): return iter(d.items()) @@ -219,6 +220,53 @@ def get_normalized_mac_ip_line(line): return line +# This dictionary contains a tree of all commands that we know start a +# new multi-line context. All other commands are treated either as +# commands inside a multi-line context or as single-line contexts. This +# dictionary should be updated whenever a new node is added to FRR. +ctx_keywords = { + "router bgp ": { + "address-family ": { + "vni ": {}, + }, + "vnc defaults": {}, + "vnc nve-group ": {}, + "vnc l2-group ": {}, + "vrf-policy ": {}, + "bmp targets ": {}, + "segment-routing srv6": {}, + }, + "router rip": {}, + "router ripng": {}, + "router isis ": {}, + "router openfabric ": {}, + "router ospf": {}, + "router ospf6": {}, + "router eigrp ": {}, + "router babel": {}, + "mpls ldp": {"address-family ": {"interface ": {}}}, + "l2vpn ": {"member pseudowire ": {}}, + "key chain ": {"key ": {}}, + "vrf ": {}, + "interface ": {"link-params": {}}, + "pseudowire ": {}, + "segment-routing": { + "traffic-eng": { + "segment-list ": {}, + "policy ": {"candidate-path ": {}}, + "pcep": {"pcc": {}, "pce ": {}, "pce-config ": {}}, + }, + "srv6": {"locators": {"locator ": {}}}, + }, + "nexthop-group ": {}, + "route-map ": {}, + "pbr-map ": {}, + "rpki": {}, + "bfd": {"peer ": {}, "profile ": {}}, + "line vty": {}, +} + + class Config(object): """ A frr configuration is stored in a Config object. A Config object @@ -315,7 +363,7 @@ def get_contexts(self): """ Return the parsed context as strings for display, log etc. """ - for (_, ctx) in sorted(iteritems(self.contexts)): + for _, ctx in sorted(iteritems(self.contexts)): print(str(ctx)) def save_contexts(self, key, lines): @@ -490,54 +538,7 @@ def load_contexts(self): key of the context. So "router bgp 10" is the key for the non-address family part of bgp, "router bgp 10, address-family ipv6 unicast" is the key for the subcontext and so on. - - This dictionary contains a tree of all commands that we know start a - new multi-line context. All other commands are treated either as - commands inside a multi-line context or as single-line contexts. This - dictionary should be updated whenever a new node is added to FRR. """ - ctx_keywords = { - "router bgp ": { - "address-family ": { - "vni ": {}, - }, - "vnc defaults": {}, - "vnc nve-group ": {}, - "vnc l2-group ": {}, - "vrf-policy ": {}, - "bmp targets ": {}, - "segment-routing srv6": {}, - }, - "router rip": {}, - "router ripng": {}, - "router isis ": {}, - "router openfabric ": {}, - "router ospf": {}, - "router ospf6": {}, - "router eigrp ": {}, - "router babel": {}, - "mpls ldp": {"address-family ": {"interface ": {}}}, - "l2vpn ": {"member pseudowire ": {}}, - "key chain ": {"key ": {}}, - "vrf ": {}, - "interface ": {"link-params": {}}, - "pseudowire ": {}, - "segment-routing": { - "traffic-eng": { - "segment-list ": {}, - "policy ": {"candidate-path ": {}}, - "pcep": {"pcc": {}, "pce ": {}, "pce-config ": {}}, - }, - "srv6": {"locators": {"locator ": {}}}, - }, - "nexthop-group ": {}, - "route-map ": {}, - "pbr-map ": {}, - "rpki": {}, - "bfd": {"peer ": {}, "profile ": {}}, - "line vty": {}, - } - # stack of context keys ctx_keys = [] # stack of context keywords @@ -546,7 +547,6 @@ def load_contexts(self): cur_ctx_lines = [] for line in self.lines: - if not line: continue @@ -632,8 +632,22 @@ def lines_to_config(ctx_keys, line, delete): """ cmd = [] + # If there's no `line` and `ctx_keys` length is 1, then it may be a single-line command. + # In this case, we should treat it as a single command in an empty context. + if len(ctx_keys) == 1 and not line: + single = True + + for k, v in ctx_keywords.items(): + if ctx_keys[0].startswith(k): + single = False + break + + if single: + line = ctx_keys[0] + ctx_keys = [] + if line: - for (i, ctx_key) in enumerate(ctx_keys): + for i, ctx_key in enumerate(ctx_keys): cmd.append(" " * i + ctx_key) line = line.lstrip() @@ -652,6 +666,9 @@ def lines_to_config(ctx_keys, line, delete): else: cmd.append(indent + line) + for i in reversed(range(len(ctx_keys))): + cmd.append(" " * i + "exit") + # If line is None then we are typically deleting an entire # context ('no router ospf' for example) else: @@ -666,6 +683,10 @@ def lines_to_config(ctx_keys, line, delete): cmd.append("%sno %s" % (" " * (len(ctx_keys) - 1), ctx_keys[-1])) else: cmd.append("%s%s" % (" " * (len(ctx_keys) - 1), ctx_keys[-1])) + cmd.append("%sexit" % (" " * (len(ctx_keys) - 1))) + + for i in reversed(range(len(ctx_keys) - 1)): + cmd.append(" " * i + "exit") return cmd @@ -704,7 +725,7 @@ def get_normalized_ipv6_line(line): def line_exist(lines, target_ctx_keys, target_line, exact_match=True): - for (ctx_keys, line) in lines: + for ctx_keys, line in lines: if ctx_keys == target_ctx_keys: if exact_match: if line == target_line: @@ -715,38 +736,6 @@ def line_exist(lines, target_ctx_keys, target_line, exact_match=True): return False -def check_for_exit_vrf(lines_to_add, lines_to_del): - - # exit-vrf is a bit tricky. If the new config is missing it but we - # have configs under a vrf, we need to add it at the end to do the - # right context changes. If exit-vrf exists in both the running and - # new config, we cannot delete it or it will break context changes. - add_exit_vrf = False - index = 0 - - for (ctx_keys, line) in lines_to_add: - if add_exit_vrf == True: - if ctx_keys[0] != prior_ctx_key: - insert_key = ((prior_ctx_key),) - lines_to_add.insert(index, ((insert_key, "exit-vrf"))) - add_exit_vrf = False - - if ctx_keys[0].startswith("vrf") and line: - if line != "exit-vrf": - add_exit_vrf = True - prior_ctx_key = ctx_keys[0] - else: - add_exit_vrf = False - index += 1 - - for (ctx_keys, line) in lines_to_del: - if line == "exit-vrf": - if line_exist(lines_to_add, ctx_keys, line): - lines_to_del.remove((ctx_keys, line)) - - return (lines_to_add, lines_to_del) - - def bgp_delete_inst_move_line(lines_to_del): # Deletion of bgp default inst followed by # bgp vrf inst leads to issue of default @@ -755,7 +744,7 @@ def bgp_delete_inst_move_line(lines_to_del): bgp_defult_inst = False bgp_vrf_inst = False - for (ctx_keys, line) in lines_to_del: + for ctx_keys, line in lines_to_del: # Find bgp default inst if ( ctx_keys[0].startswith("router bgp") @@ -768,7 +757,7 @@ def bgp_delete_inst_move_line(lines_to_del): bgp_vrf_inst = True if bgp_defult_inst and bgp_vrf_inst: - for (ctx_keys, line) in lines_to_del: + for ctx_keys, line in lines_to_del: # move bgp default inst to end if ( ctx_keys[0].startswith("router bgp") @@ -864,7 +853,6 @@ def bgp_delete_nbr_remote_as_line(lines_to_add): def bgp_remove_neighbor_cfg(lines_to_del, del_nbr_dict): - # This method handles deletion of bgp neighbor configs, # if there is neighbor to peer-group cmd is in delete list. # As 'no neighbor .* peer-group' deletes the neighbor, @@ -872,7 +860,7 @@ def bgp_remove_neighbor_cfg(lines_to_del, del_nbr_dict): # in error. lines_to_del_to_del = [] - for (ctx_keys, line) in lines_to_del: + for ctx_keys, line in lines_to_del: if ( ctx_keys[0].startswith("router bgp") and line @@ -887,11 +875,11 @@ def bgp_remove_neighbor_cfg(lines_to_del, del_nbr_dict): if re_nb: lines_to_del_to_del.append((ctx_keys, line)) - for (ctx_keys, line) in lines_to_del_to_del: + for ctx_keys, line in lines_to_del_to_del: lines_to_del.remove((ctx_keys, line)) -def delete_move_lines(lines_to_add, lines_to_del): +def bgp_delete_move_lines(lines_to_add, lines_to_del): # This method handles deletion of bgp peer group config. # The objective is to delete config lines related to peers # associated with the peer-group and move the peer-group @@ -953,7 +941,7 @@ def delete_move_lines(lines_to_add, lines_to_del): # "router bgp 200 no neighbor uplink1 interface remote-as internal" # "router bgp 200 no neighbor underlay peer-group" - for (ctx_keys, line) in lines_to_del: + for ctx_keys, line in lines_to_del: if ( ctx_keys[0].startswith("router bgp") and line @@ -1010,13 +998,13 @@ def delete_move_lines(lines_to_add, lines_to_del): bgp_remove_neighbor_cfg(lines_to_del, del_nbr_dict) return (lines_to_add, lines_to_del) - for (ctx_keys, line) in lines_to_del_to_app: + for ctx_keys, line in lines_to_del_to_app: lines_to_del.remove((ctx_keys, line)) lines_to_del.append((ctx_keys, line)) # {'router bgp 65001': {'PG': ['10.1.1.2'], 'PG1': ['10.1.1.21']}, # 'router bgp 65001 vrf vrf1': {'PG': ['10.1.1.2'], 'PG1': ['10.1.1.21']}} - for (ctx_keys, line) in lines_to_del: + for ctx_keys, line in lines_to_del: if ( ctx_keys[0].startswith("router bgp") and line @@ -1034,7 +1022,7 @@ def delete_move_lines(lines_to_add, lines_to_del): del_dict[ctx_keys[0]][pg_key].append(re_nbr_pg.group(1)) lines_to_del_to_app = [] - for (ctx_keys, line) in lines_to_del: + for ctx_keys, line in lines_to_del: if ( ctx_keys[0].startswith("router bgp") and line @@ -1054,10 +1042,10 @@ def delete_move_lines(lines_to_add, lines_to_del): if re_pg: lines_to_del_to_app.append((ctx_keys, line)) - for (ctx_keys, line) in lines_to_del_to_del: + for ctx_keys, line in lines_to_del_to_del: lines_to_del.remove((ctx_keys, line)) - for (ctx_keys, line) in lines_to_del_to_app: + for ctx_keys, line in lines_to_del_to_app: lines_to_del.remove((ctx_keys, line)) lines_to_del.append((ctx_keys, line)) @@ -1066,19 +1054,73 @@ def delete_move_lines(lines_to_add, lines_to_del): return (lines_to_add, lines_to_del) -def ignore_delete_re_add_lines(lines_to_add, lines_to_del): +def pim_delete_move_lines(lines_to_add, lines_to_del): + # Under interface context, if 'no ip pim' is present + # remove subsequent 'no ip pim <blah>' options as it + # they are implicitly deleted by 'no ip pim'. + # Remove all such depdendent options from delete + # pending list. + pim_disable = False + + for ctx_keys, line in lines_to_del: + if ctx_keys[0].startswith("interface") and line and line == "ip pim": + pim_disable = True + + if pim_disable: + for ctx_keys, line in lines_to_del: + if ( + ctx_keys[0].startswith("interface") + and line + and line.startswith("ip pim ") + ): + lines_to_del.remove((ctx_keys, line)) + return (lines_to_add, lines_to_del) + + +def delete_move_lines(lines_to_add, lines_to_del): + lines_to_add, lines_to_del = bgp_delete_move_lines(lines_to_add, lines_to_del) + lines_to_add, lines_to_del = pim_delete_move_lines(lines_to_add, lines_to_del) + + return (lines_to_add, lines_to_del) + + +def ignore_delete_re_add_lines(lines_to_add, lines_to_del): # Quite possibly the most confusing (while accurate) variable names in history lines_to_add_to_del = [] lines_to_del_to_del = [] - for (ctx_keys, line) in lines_to_del: + index = -1 + for ctx_keys, line in lines_to_del: deleted = False + # no form of route-map description command only + # accept 'no description', replace 'no description blah' + # to just 'no description'. + index = index + 1 + if ( + ctx_keys[0].startswith("route-map") + and line + and line.startswith("description ") + ): + lines_to_del.remove((ctx_keys, line)) + lines_to_del.insert(index, (ctx_keys, "description")) + + # interface x ; description blah + # no form of description does not accept any argument, + # strip arg before rendering + if ( + ctx_keys[0].startswith("interface ") + and line + and line.startswith("description ") + ): + lines_to_del.remove((ctx_keys, line)) + lines_to_del.insert(index, (ctx_keys, "description")) + # If there is a change in the segment routing block ranges, do it # in-place, to avoid requesting spurious label chunks which might fail if line and "segment-routing global-block" in line: - for (add_key, add_line) in lines_to_add: + for add_key, add_line in lines_to_add: if ( ctx_keys[0] == add_key[0] and add_line @@ -1089,7 +1131,6 @@ def ignore_delete_re_add_lines(lines_to_add, lines_to_del): continue if ctx_keys[0].startswith("router bgp") and line: - if line.startswith("neighbor "): # BGP changed how it displays swpX peers that are part of peer-group. Older # versions of frr would display these on separate lines: @@ -1171,7 +1212,7 @@ def ignore_delete_re_add_lines(lines_to_add, lines_to_del): bfd_nbr = "neighbor %s" % nbr bfd_search_string = bfd_nbr + r" bfd (\S+) (\S+) (\S+)" - for (ctx_keys, add_line) in lines_to_add: + for ctx_keys, add_line in lines_to_add: if ctx_keys[0].startswith("router bgp"): re_add_nbr_bfd_timers = re.search( bfd_search_string, add_line @@ -1201,7 +1242,7 @@ def ignore_delete_re_add_lines(lines_to_add, lines_to_del): dir = re_nbr_rm.group(3) search = "neighbor%sroute-map(.*)%s" % (neighbor_name, dir) save_line = "EMPTY" - for (ctx_keys_al, add_line) in lines_to_add: + for ctx_keys_al, add_line in lines_to_add: if ctx_keys_al[0].startswith("router bgp"): if add_line: rm_match = re.search(search, add_line) @@ -1221,7 +1262,7 @@ def ignore_delete_re_add_lines(lines_to_add, lines_to_del): lines_to_del_to_del.append((ctx_keys_al, line)) if adjust_for_bgp_node == 1: - for (ctx_keys_dl, dl_line) in lines_to_del: + for ctx_keys_dl, dl_line in lines_to_del: if ( ctx_keys_dl[0].startswith("router bgp") and len(ctx_keys_dl) > 1 @@ -1403,7 +1444,6 @@ def ignore_delete_re_add_lines(lines_to_add, lines_to_del): and ctx_keys[1] == "address-family l2vpn evpn" and ctx_keys[2].startswith("vni") ): - re_route_target = ( re.search("^route-target import (.*)$", line) if line is not None @@ -1479,13 +1519,17 @@ def ignore_delete_re_add_lines(lines_to_add, lines_to_del): lines_to_del_to_del.append((ctx_keys, line)) lines_to_add_to_del.append((tmp_ctx_keys, line)) - for (ctx_keys, line) in lines_to_del_to_del: - if line is not None: + for ctx_keys, line in lines_to_del_to_del: + try: lines_to_del.remove((ctx_keys, line)) + except ValueError: + pass - for (ctx_keys, line) in lines_to_add_to_del: - if line is not None: + for ctx_keys, line in lines_to_add_to_del: + try: lines_to_add.remove((ctx_keys, line)) + except ValueError: + pass return (lines_to_add, lines_to_del) @@ -1497,8 +1541,7 @@ def ignore_unconfigurable_lines(lines_to_add, lines_to_del): """ lines_to_del_to_del = [] - for (ctx_keys, line) in lines_to_del: - + for ctx_keys, line in lines_to_del: # The integrated-vtysh-config one is technically "no"able but if we did # so frr-reload would stop working so do not let the user shoot # themselves in the foot by removing this. @@ -1519,7 +1562,7 @@ def ignore_unconfigurable_lines(lines_to_add, lines_to_del): log.info('"%s" cannot be removed' % (ctx_keys[-1],)) lines_to_del_to_del.append((ctx_keys, line)) - for (ctx_keys, line) in lines_to_del_to_del: + for ctx_keys, line in lines_to_del_to_del: lines_to_del.remove((ctx_keys, line)) return (lines_to_add, lines_to_del) @@ -1539,13 +1582,32 @@ def compare_context_objects(newconf, running): pcclist_to_del = [] candidates_to_add = [] delete_bgpd = False + area_stub_no_sum = "area (\S+) stub no-summary" + deleted_keychains = [] # Find contexts that are in newconf but not in running # Find contexts that are in running but not in newconf - for (running_ctx_keys, running_ctx) in iteritems(running.contexts): + for running_ctx_keys, running_ctx in iteritems(running.contexts): + if running_ctx_keys in newconf.contexts: + newconf_ctx = newconf.contexts[running_ctx_keys] - if running_ctx_keys not in newconf.contexts: + for line in running_ctx.lines: + # ospf area <> stub no-summary line removal requires + # to remoe area <> stub as no form of original + # retains the stub form. + # lines_to_del will contain: + # no area <x> stub no-summary and + # no area <x> stub + if ( + running_ctx_keys[0].startswith("router ospf") + and line not in newconf_ctx.dlines + ): + re_area_stub_no_sum = re.search(area_stub_no_sum, line) + if re_area_stub_no_sum: + new_del_line = "area %s stub" % re_area_stub_no_sum.group(1) + lines_to_del.append((running_ctx_keys, new_del_line)) + if running_ctx_keys not in newconf.contexts: # We check that the len is 1 here so that we only look at ('router bgp 10') # and not ('router bgp 10', 'address-family ipv4 unicast'). The # latter could cause a false delete_bgpd positive if ipv4 unicast is in @@ -1570,6 +1632,22 @@ def compare_context_objects(newconf, running): ): continue + # Check if key chain is being deleted: + # - If it is being deleted then avoid deleting its contexts + # - Else delete its configuration without removing the root node + elif ( + running_ctx_keys[0].startswith("key chain ") + and len(running_ctx_keys) == 1 + ): + deleted_keychains.append(running_ctx_keys[0]) + lines_to_del.append((running_ctx_keys, None)) + elif ( + running_ctx_keys[0].startswith("key chain ") + and len(running_ctx_keys) > 1 + and running_ctx_keys[0] in deleted_keychains + ): + continue + # Delete an entire vni sub-context under "address-family l2vpn evpn" elif ( "router bgp" in running_ctx_keys[0] @@ -1700,14 +1778,12 @@ def compare_context_objects(newconf, running): # Find the lines within each context to add # Find the lines within each context to del - for (newconf_ctx_keys, newconf_ctx) in iteritems(newconf.contexts): - + for newconf_ctx_keys, newconf_ctx in iteritems(newconf.contexts): if newconf_ctx_keys in running.contexts: running_ctx = running.contexts[newconf_ctx_keys] for line in newconf_ctx.lines: if line not in running_ctx.dlines: - # candidate paths can only be added after the policy and segment list, # so add them to a separate array that is going to be appended at the end if ( @@ -1725,10 +1801,8 @@ def compare_context_objects(newconf, running): if line not in newconf_ctx.dlines: lines_to_del.append((newconf_ctx_keys, line)) - for (newconf_ctx_keys, newconf_ctx) in iteritems(newconf.contexts): - + for newconf_ctx_keys, newconf_ctx in iteritems(newconf.contexts): if newconf_ctx_keys not in running.contexts: - # candidate paths can only be added after the policy and segment list, # so add them to a separate array that is going to be appended at the end if ( @@ -1750,7 +1824,6 @@ def compare_context_objects(newconf, running): if len(candidates_to_add) > 0: lines_to_add.extend(candidates_to_add) - (lines_to_add, lines_to_del) = check_for_exit_vrf(lines_to_add, lines_to_del) (lines_to_add, lines_to_del) = ignore_delete_re_add_lines( lines_to_add, lines_to_del ) @@ -1964,7 +2037,6 @@ def compare_context_objects(newconf, running): reload_ok = False if args.test: - # Create a Config object from the running config running = Config(vtysh) @@ -1980,8 +2052,7 @@ def compare_context_objects(newconf, running): print("\nLines To Delete") print("===============") - for (ctx_keys, line) in lines_to_del: - + for ctx_keys, line in lines_to_del: if line == "!": continue @@ -2007,8 +2078,7 @@ def compare_context_objects(newconf, running): print("\nLines To Add") print("============") - for (ctx_keys, line) in lines_to_add: - + for ctx_keys, line in lines_to_add: if line == "!": continue @@ -2096,8 +2166,7 @@ def compare_context_objects(newconf, running): # apply to other scenarios as well where configuring FOO adds BAR # to the config. if lines_to_del and x == 0: - for (ctx_keys, line) in lines_to_del: - + for ctx_keys, line in lines_to_del: if line == "!": continue @@ -2127,12 +2196,11 @@ def compare_context_objects(newconf, running): vtysh(["configure"] + cmd, stdouts) except VtyshException: - # - Pull the last entry from cmd (this would be # 'no ip ospf authentication message-digest 1.1.1.1' in # our example above # - Split that last entry by whitespace and drop the last word - log.info("Failed to execute %s", " ".join(cmd)) + log.error("Failed to execute %s", " ".join(cmd)) last_arg = cmd[-1].split(" ") if len(last_arg) <= 2: @@ -2155,8 +2223,7 @@ def compare_context_objects(newconf, running): if lines_to_add: lines_to_configure = [] - for (ctx_keys, line) in lines_to_add: - + for ctx_keys, line in lines_to_add: if line == "!": continue diff --git a/tools/frr_babeltrace.py b/tools/frr_babeltrace.py index 4d974ad356..9832568b37 100755 --- a/tools/frr_babeltrace.py +++ b/tools/frr_babeltrace.py @@ -157,6 +157,46 @@ def parse_frr_bgp_evpn_mh_local_es_evi_del_zrecv(event): parse_event(event, field_parsers) +def parse_frr_bgp_evpn_mh_es_evi_vtep_add(event): + """ + bgp evpn remote ead evi remote vtep add; raw format - + ctf_array(unsigned char, esi, esi, sizeof(esi_t)) + """ + field_parsers = {"esi": print_esi, + "vtep": print_net_ipv4_addr} + + parse_event(event, field_parsers) + +def parse_frr_bgp_evpn_mh_es_evi_vtep_del(event): + """ + bgp evpn remote ead evi remote vtep del; raw format - + ctf_array(unsigned char, esi, esi, sizeof(esi_t)) + """ + field_parsers = {"esi": print_esi, + "vtep": print_net_ipv4_addr} + + parse_event(event, field_parsers) + +def parse_frr_bgp_evpn_mh_local_ead_es_evi_route_upd(event): + """ + bgp evpn local ead evi vtep; raw format - + ctf_array(unsigned char, esi, esi, sizeof(esi_t)) + """ + field_parsers = {"esi": print_esi, + "vtep": print_net_ipv4_addr} + + parse_event(event, field_parsers) + +def parse_frr_bgp_evpn_mh_local_ead_es_evi_route_del(event): + """ + bgp evpn local ead evi vtep del; raw format - + ctf_array(unsigned char, esi, esi, sizeof(esi_t)) + """ + field_parsers = {"esi": print_esi, + "vtep": print_net_ipv4_addr} + + parse_event(event, field_parsers) + def parse_frr_bgp_evpn_local_vni_add_zrecv(event): """ bgp evpn local-vni parser; raw format - @@ -205,6 +245,24 @@ def parse_frr_bgp_evpn_local_macip_del_zrecv(event): parse_event(event, field_parsers) +def parse_frr_bgp_evpn_advertise_type5(event): + """ + local originated type-5 route + """ + field_parsers = {"ip": print_ip_addr, + "rmac": print_mac, + "vtep": print_net_ipv4_addr} + + parse_event(event, field_parsers) + +def parse_frr_bgp_evpn_withdraw_type5(event): + """ + local originated type-5 route withdraw + """ + field_parsers = {"ip": print_ip_addr} + + parse_event(event, field_parsers) + ############################ evpn parsers - end *############################# def main(): @@ -225,6 +283,14 @@ def main(): parse_frr_bgp_evpn_mh_local_es_evi_add_zrecv, "frr_bgp:evpn_mh_local_es_evi_del_zrecv": parse_frr_bgp_evpn_mh_local_es_evi_del_zrecv, + "frr_bgp:evpn_mh_es_evi_vtep_add": + parse_frr_bgp_evpn_mh_es_evi_vtep_add, + "frr_bgp:evpn_mh_es_evi_vtep_del": + parse_frr_bgp_evpn_mh_es_evi_vtep_del, + "frr_bgp:evpn_mh_local_ead_es_evi_route_upd": + parse_frr_bgp_evpn_mh_local_ead_es_evi_route_upd, + "frr_bgp:evpn_mh_local_ead_es_evi_route_del": + parse_frr_bgp_evpn_mh_local_ead_es_evi_route_del, "frr_bgp:evpn_local_vni_add_zrecv": parse_frr_bgp_evpn_local_vni_add_zrecv, "frr_bgp:evpn_local_l3vni_add_zrecv": @@ -233,6 +299,10 @@ def main(): parse_frr_bgp_evpn_local_macip_add_zrecv, "frr_bgp:evpn_local_macip_del_zrecv": parse_frr_bgp_evpn_local_macip_del_zrecv, + "frr_bgp:evpn_advertise_type5": + parse_frr_bgp_evpn_advertise_type5, + "frr_bgp:evpn_withdraw_type5": + parse_frr_bgp_evpn_withdraw_type5, } # get the trace path from the first command line argument diff --git a/tools/frrcommon.sh.in b/tools/frrcommon.sh.in index f1f7011909..00b63a78e2 100755 --- a/tools/frrcommon.sh.in +++ b/tools/frrcommon.sh.in @@ -207,8 +207,8 @@ daemon_stop() { [ -z "$fail" -a -z "$pid" ] && fail="pid file is empty" [ -n "$fail" ] || kill -0 "$pid" 2>/dev/null || fail="pid $pid not running" - if [ -n "$fail" ] && [ "$2" != "--quiet" ]; then - log_failure_msg "Cannot stop $dmninst: $fail" + if [ -n "$fail" ]; then + [ "$2" = "--quiet" ] || log_failure_msg "Cannot stop $dmninst: $fail" return 1 fi @@ -220,11 +220,11 @@ daemon_stop() { [ $(( cnt -= 1 )) -gt 0 ] || break done if kill -0 "$pid" 2>/dev/null; then - log_failure_msg "Failed to stop $dmninst, pid $pid still running" + [ "$2" = "--quiet" ] || log_failure_msg "Failed to stop $dmninst, pid $pid still running" still_running=1 return 1 else - log_success_msg "Stopped $dmninst" + [ "$2" = "--quiet" ] || log_success_msg "Stopped $dmninst" rm -f "$pidfile" return 0 fi diff --git a/tools/frrinit.sh.in b/tools/frrinit.sh.in index 42adefb9ea..428d57c55b 100644 --- a/tools/frrinit.sh.in +++ b/tools/frrinit.sh.in @@ -123,7 +123,7 @@ reload) NEW_CONFIG_FILE="${2:-$C_PATH/frr.conf}" [ ! -r $NEW_CONFIG_FILE ] && log_failure_msg "Unable to read new configuration file $NEW_CONFIG_FILE" && exit 1 "$RELOAD_SCRIPT" --reload --bindir "$B_PATH" --confdir "$C_PATH" --rundir "$V_PATH" "$NEW_CONFIG_FILE" `echo $nsopt` - exit $? + exit 0 ;; *) diff --git a/tools/gcc-plugins/Makefile b/tools/gcc-plugins/Makefile index d6edd745ce..2af28fe2b1 100644 --- a/tools/gcc-plugins/Makefile +++ b/tools/gcc-plugins/Makefile @@ -5,11 +5,15 @@ CXX=g++-9 PLUGBASE=`$(CXX) -print-file-name=plugin` CPPFLAGS=-I$(PLUGBASE)/include -I$(PLUGBASE)/include/c-family +# NB: compiler flags must match those used to build gcc, otherwise inlining +# behavior is different and linker errors will result due to missing symbols +# (which should in fact be inlined) + frr-format.so: frr-format.o - $(CXX) -g -shared -o $@ $^ + $(CXX) -fno-rtti -fno-exceptions -fasynchronous-unwind-tables -ggdb -shared -o $@ $^ frr-format.o: frr-format.c gcc-common.h - $(CXX) -g $(CPPFLAGS) -fPIC -Wall -Wextra -Wno-unused-parameter -c -o $@ $< + $(CXX) -fno-rtti -fno-exceptions -fasynchronous-unwind-tables -ggdb $(CPPFLAGS) -fPIC -Wall -Wextra -Wno-unused-parameter -c -o $@ $< install: install -d $(DESTDIR)$(PLUGBASE) diff --git a/tools/gcc-plugins/frr-format.c b/tools/gcc-plugins/frr-format.c index 2240a171b4..4e2c2d3ba9 100644 --- a/tools/gcc-plugins/frr-format.c +++ b/tools/gcc-plugins/frr-format.c @@ -486,7 +486,7 @@ static const format_char_info print_char_table[] = /* C89 conversion specifiers. */ /* none, hh, h, l, ll, L, z, t, j, H, D, DD */ { "di", 0, STD_C89, { T89_I, T99_SC, T89_S, T89_L, T9L_LL, TEX_S64, T99_SST, T99_PD, T99_IM, BADLEN, BADLEN, BADLEN }, "-wp0 +'I", "i", NULL, ext_d }, - { "oxX", 0, STD_C89, { T89_UI, T99_UC, T89_US, T89_UL, T9L_ULL, TEX_U64, T99_ST, T99_UPD, T99_UIM, BADLEN, BADLEN, BADLEN }, "-wp0#", "i", NULL, NULL }, + { "oxXb",0, STD_C89, { T89_UI, T99_UC, T89_US, T89_UL, T9L_ULL, TEX_U64, T99_ST, T99_UPD, T99_UIM, BADLEN, BADLEN, BADLEN }, "-wp0#", "i", NULL, NULL }, { "u", 0, STD_C89, { T89_UI, T99_UC, T89_US, T89_UL, T9L_ULL, TEX_U64, T99_ST, T99_UPD, T99_UIM, BADLEN, BADLEN, BADLEN }, "-wp0'I", "i", NULL, NULL }, { "fgG", 0, STD_C89, { T89_D, BADLEN, BADLEN, T99_D, BADLEN, T89_LD, BADLEN, BADLEN, BADLEN, TEX_D32, TEX_D64, TEX_D128 }, "-wp0 +#'I", "", NULL, NULL }, { "eE", 0, STD_C89, { T89_D, BADLEN, BADLEN, T99_D, BADLEN, T89_LD, BADLEN, BADLEN, BADLEN, TEX_D32, TEX_D64, TEX_D128 }, "-wp0 +#I", "", NULL, NULL }, @@ -3464,7 +3464,7 @@ class frr_range_label_for_type_mismatch : public range_label { } - label_text get_text (unsigned range_idx) const OVERRIDE; + label_text get_text (unsigned range_idx) const override; protected: tree m_labelled_type; @@ -3564,19 +3564,26 @@ class range_label_for_format_type_mismatch { } - label_text get_text (unsigned range_idx) const FINAL OVERRIDE +#if BUILDING_GCC_VERSION >= 13000 +#define text_get(text) text.get() +#define text_return(text, result) return label_text::take(result) +#else +#define text_get(text) text.m_buffer +#define text_return(text, result) text.maybe_free(); return label_take(result) +#endif + + label_text get_text (unsigned range_idx) const final override { label_text text = range_label_for_type_mismatch::get_text (range_idx); - if (text.m_buffer == NULL) + if (text_get(text) == NULL) return text; indirection_suffix suffix (m_pointer_count); char *p = (char *) alloca (suffix.get_buffer_size ()); suffix.fill_buffer (p); - char *result = concat (text.m_buffer, p, NULL); - text.maybe_free (); - return label_take(result); + char *result = concat (text_get(text), p, NULL); + text_return(text, result); } private: diff --git a/tools/gcc-plugins/gcc-common.h b/tools/gcc-plugins/gcc-common.h index 9f59447d63..6eaea9bf74 100644 --- a/tools/gcc-plugins/gcc-common.h +++ b/tools/gcc-plugins/gcc-common.h @@ -111,6 +111,10 @@ #include "varasm.h" #include "stor-layout.h" #include "internal-fn.h" +#if BUILDING_GCC_VERSION >= 13000 +#include "gimple.h" +#include "gimple-iterator.h" +#endif #include "gimple-expr.h" #include "gimple-fold.h" #include "context.h" diff --git a/tools/gen_northbound_callbacks.c b/tools/gen_northbound_callbacks.c index 5b778a1585..550058bfec 100644 --- a/tools/gen_northbound_callbacks.c +++ b/tools/gen_northbound_callbacks.c @@ -7,6 +7,7 @@ #define REALLY_NEED_PLAIN_GETOPT 1 #include <zebra.h> +#include <sys/stat.h> #include <unistd.h> @@ -30,62 +31,62 @@ static struct nb_callback_info { char arguments[128]; } nb_callbacks[] = { { - .operation = NB_OP_CREATE, + .operation = NB_CB_CREATE, .return_type = "int ", .return_value = "NB_OK", .arguments = "struct nb_cb_create_args *args", }, { - .operation = NB_OP_MODIFY, + .operation = NB_CB_MODIFY, .return_type = "int ", .return_value = "NB_OK", .arguments = "struct nb_cb_modify_args *args", }, { - .operation = NB_OP_DESTROY, + .operation = NB_CB_DESTROY, .return_type = "int ", .return_value = "NB_OK", .arguments = "struct nb_cb_destroy_args *args", }, { - .operation = NB_OP_MOVE, + .operation = NB_CB_MOVE, .return_type = "int ", .return_value = "NB_OK", .arguments = "struct nb_cb_move_args *args", }, { - .operation = NB_OP_APPLY_FINISH, + .operation = NB_CB_APPLY_FINISH, .optional = true, .return_type = "void ", .return_value = "", .arguments = "struct nb_cb_apply_finish_args *args", }, { - .operation = NB_OP_GET_ELEM, + .operation = NB_CB_GET_ELEM, .return_type = "struct yang_data *", .return_value = "NULL", .arguments = "struct nb_cb_get_elem_args *args", }, { - .operation = NB_OP_GET_NEXT, + .operation = NB_CB_GET_NEXT, .return_type = "const void *", .return_value = "NULL", .arguments = "struct nb_cb_get_next_args *args", }, { - .operation = NB_OP_GET_KEYS, + .operation = NB_CB_GET_KEYS, .return_type = "int ", .return_value = "NB_OK", .arguments = "struct nb_cb_get_keys_args *args", }, { - .operation = NB_OP_LOOKUP_ENTRY, + .operation = NB_CB_LOOKUP_ENTRY, .return_type = "const void *", .return_value = "NULL", .arguments = "struct nb_cb_lookup_entry_args *args", }, { - .operation = NB_OP_RPC, + .operation = NB_CB_RPC, .return_type = "int ", .return_value = "NB_OK", .arguments = "struct nb_cb_rpc_args *args", @@ -106,7 +107,7 @@ static void replace_hyphens_by_underscores(char *str) } static void generate_callback_name(const struct lysc_node *snode, - enum nb_operation operation, char *buffer, + enum nb_cb_operation operation, char *buffer, size_t size) { struct list *snodes; @@ -128,7 +129,7 @@ static void generate_callback_name(const struct lysc_node *snode, strlcat(buffer, snode->name, size); strlcat(buffer, "_", size); } - strlcat(buffer, nb_operation_name(operation), size); + strlcat(buffer, nb_cb_operation_name(operation), size); list_delete(&snodes); replace_hyphens_by_underscores(buffer); @@ -159,7 +160,7 @@ static int generate_prototypes(const struct lysc_node *snode, void *arg) char cb_name[BUFSIZ]; if (cb->optional - || !nb_operation_is_valid(cb->operation, snode)) + || !nb_cb_operation_is_valid(cb->operation, snode)) continue; generate_callback_name(snode, cb->operation, cb_name, @@ -177,10 +178,10 @@ static void generate_callback(const struct nb_callback_info *ncinfo, ncinfo->return_type, cb_name, ncinfo->arguments); switch (ncinfo->operation) { - case NB_OP_CREATE: - case NB_OP_MODIFY: - case NB_OP_DESTROY: - case NB_OP_MOVE: + case NB_CB_CREATE: + case NB_CB_MODIFY: + case NB_CB_DESTROY: + case NB_CB_MOVE: printf("\tswitch (args->event) {\n" "\tcase NB_EV_VALIDATE:\n" "\tcase NB_EV_PREPARE:\n" @@ -221,7 +222,7 @@ static int generate_callbacks(const struct lysc_node *snode, void *arg) char cb_name[BUFSIZ]; if (cb->optional - || !nb_operation_is_valid(cb->operation, snode)) + || !nb_cb_operation_is_valid(cb->operation, snode)) continue; if (first) { @@ -266,7 +267,7 @@ static int generate_nb_nodes(const struct lysc_node *snode, void *arg) char cb_name[BUFSIZ]; if (cb->optional - || !nb_operation_is_valid(cb->operation, snode)) + || !nb_cb_operation_is_valid(cb->operation, snode)) continue; if (first) { @@ -284,7 +285,8 @@ static int generate_nb_nodes(const struct lysc_node *snode, void *arg) generate_callback_name(snode, cb->operation, cb_name, sizeof(cb_name)); - printf("\t\t\t\t.%s = %s,\n", nb_operation_name(cb->operation), + printf("\t\t\t\t.%s = %s,\n", + nb_cb_operation_name(cb->operation), cb_name); } diff --git a/tools/valgrind.supp b/tools/valgrind.supp index da3d4a8d6d..d2cb4118de 100644 --- a/tools/valgrind.supp +++ b/tools/valgrind.supp @@ -23,6 +23,15 @@ fun:cap_init fun:zprivs_caps_init } +{ + <zprivs_init leak in library code we do not control> + Memcheck:Leak + match-leak-kinds: reachable + ... + fun:getgrouplist + fun:zprivs_init + fun:frr_init +} { <sqlite3 leak in a function we do not control> Memcheck:Leak diff --git a/vrrpd/vrrp.c b/vrrpd/vrrp.c index 7a779307d9..017387924c 100644 --- a/vrrpd/vrrp.c +++ b/vrrpd/vrrp.c @@ -700,10 +700,9 @@ static int vrrp_bind_to_primary_connected(struct vrrp_router *r) */ ifp = r->family == AF_INET ? r->vr->ifp : r->mvl_ifp; - struct listnode *ln; struct connected *c = NULL; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, ln, c)) + frr_each (if_connected, ifp->connected, c) if (c->address->family == r->family) { if (r->family == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&c->address->u.prefix6)) @@ -1171,9 +1170,15 @@ static int vrrp_socket(struct vrrp_router *r) r->vr->vrid, family2str(r->family)); /* Join Rx socket to VRRP IPv4 multicast group */ - assert(listhead(r->vr->ifp->connected)); - struct connected *c = listhead(r->vr->ifp->connected)->data; - struct in_addr v4 = c->address->u.prefix4; + struct connected *c; + struct in_addr v4; + + frr_each (if_connected, r->vr->ifp->connected, c) + if (c->address->family == AF_INET) + break; + + assert(c); + v4 = c->address->u.prefix4; ret = setsockopt_ipv4_multicast(r->sock_rx, IP_ADD_MEMBERSHIP, v4, htonl(VRRP_MCASTV4_GROUP), @@ -1240,7 +1245,13 @@ static int vrrp_socket(struct vrrp_router *r) } /* Turn off multicast loop on Tx */ - setsockopt_ipv6_multicast_loop(r->sock_tx, 0); + if (setsockopt_ipv6_multicast_loop(r->sock_tx, 0) < 0) { + zlog_warn(VRRP_LOGPFX VRRP_LOGPFX_VRID VRRP_LOGPFX_FAM + "Failed to turn off IPv6 multicast", + r->vr->vrid, family2str(r->family)); + failed = true; + goto done; + } /* Bind Rx socket to exact interface */ frr_with_privs(&vrrp_privs) { @@ -1697,7 +1708,6 @@ int vrrp_event(struct vrrp_router *r, int event) */ static void vrrp_autoconfig_autoaddrupdate(struct vrrp_router *r) { - struct listnode *ln; struct connected *c = NULL; bool is_v6_ll; @@ -1708,7 +1718,7 @@ static void vrrp_autoconfig_autoaddrupdate(struct vrrp_router *r) VRRP_LOGPFX VRRP_LOGPFX_VRID VRRP_LOGPFX_FAM "Setting Virtual IP list to match IPv4 addresses on %s", r->vr->vrid, family2str(r->family), r->mvl_ifp->name); - for (ALL_LIST_ELEMENTS_RO(r->mvl_ifp->connected, ln, c)) { + frr_each (if_connected, r->mvl_ifp->connected, c) { is_v6_ll = (c->address->family == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&c->address->u.prefix6)); if (c->address->family == r->family && !is_v6_ll) { diff --git a/vrrpd/vrrp_northbound.c b/vrrpd/vrrp_northbound.c index 1f8da4cf20..2947a416d8 100644 --- a/vrrpd/vrrp_northbound.c +++ b/vrrpd/vrrp_northbound.c @@ -27,8 +27,8 @@ static int lib_interface_vrrp_vrrp_group_create(struct nb_cb_create_args *args) uint8_t version = 3; struct vrrp_vrouter *vr; - vrid = yang_dnode_get_uint8(args->dnode, "./virtual-router-id"); - version = yang_dnode_get_enum(args->dnode, "./version"); + vrid = yang_dnode_get_uint8(args->dnode, "virtual-router-id"); + version = yang_dnode_get_enum(args->dnode, "version"); switch (args->event) { case NB_EV_VALIDATE: diff --git a/vrrpd/vrrp_vty.c b/vrrpd/vrrp_vty.c index 7a17de747c..bbdf48b326 100644 --- a/vrrpd/vrrp_vty.c +++ b/vrrpd/vrrp_vty.c @@ -62,11 +62,11 @@ DEFPY_YANG(vrrp_vrid, void cli_show_vrrp(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - const char *vrid = yang_dnode_get_string(dnode, "./virtual-router-id"); - const char *ver = yang_dnode_get_string(dnode, "./version"); + const char *vrid = yang_dnode_get_string(dnode, "virtual-router-id"); + const char *ver = yang_dnode_get_string(dnode, "version"); vty_out(vty, " vrrp %s", vrid); - if (show_defaults || !yang_dnode_is_default(dnode, "./version")) + if (show_defaults || !yang_dnode_is_default(dnode, "version")) vty_out(vty, " version %s", ver); vty_out(vty, "\n"); } @@ -398,6 +398,7 @@ static struct json_object *vrrp_build_json(struct vrrp_vrouter *vr) json_object_string_add(j, "interface", vr->ifp->name); json_object_int_add(j, "advertisementInterval", vr->advertisement_interval * CS2MS); + json_object_int_add(j, "priority", vr->priority); /* v4 */ json_object_string_add(v4, "interface", vr->v4->mvl_ifp ? vr->v4->mvl_ifp->name : ""); diff --git a/vrrpd/vrrp_zebra.c b/vrrpd/vrrp_zebra.c index 6d753d2e47..009432b217 100644 --- a/vrrpd/vrrp_zebra.c +++ b/vrrpd/vrrp_zebra.c @@ -36,11 +36,10 @@ static void vrrp_zebra_debug_if_dump_address(struct interface *ifp, const char *func) { struct connected *ifc; - struct listnode *node; DEBUGD(&vrrp_dbg_zebra, "%s: interface %s addresses:", func, ifp->name); - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { + frr_each (if_connected, ifp->connected, ifc) { struct prefix *p = ifc->address; DEBUGD(&vrrp_dbg_zebra, "%s: interface %s address %pFX %s", @@ -183,8 +182,10 @@ static zclient_handler *const vrrp_handlers[] = { void vrrp_zebra_init(void) { - if_zapi_callbacks(vrrp_ifp_create, vrrp_ifp_up, - vrrp_ifp_down, vrrp_ifp_destroy); + hook_register_prio(if_real, 0, vrrp_ifp_create); + hook_register_prio(if_up, 0, vrrp_ifp_up); + hook_register_prio(if_down, 0, vrrp_ifp_down); + hook_register_prio(if_unreal, 0, vrrp_ifp_destroy); /* Socket for receiving updates from Zebra daemon */ zclient = zclient_new(master, &zclient_options_default, vrrp_handlers, diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 04f7ff65e9..2888403e62 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -5,6 +5,9 @@ #include <zebra.h> +#include <pwd.h> +#include <grp.h> + #include <sys/un.h> #include <setjmp.h> #include <sys/wait.h> @@ -880,6 +883,13 @@ int vtysh_config_from_file(struct vty *vty, FILE *fp) if (strmatch(vty_buf_trimmed, "end")) continue; + if (strmatch(vty_buf_trimmed, "exit") && + vty->node == CONFIG_NODE) { + fprintf(stderr, "line %d: Warning[%d]...: %s\n", lineno, + vty->node, "early exit from config file"); + break; + } + ret = command_config_read_one_line(vty, &cmd, lineno, 1); switch (ret) { @@ -1182,6 +1192,20 @@ static struct cmd_node isis_flex_algo_node = { .parent_node = ISIS_NODE, .prompt = "%s(config-router-flex-algo)# ", }; + +static struct cmd_node isis_srv6_node = { + .name = "isis-srv6", + .node = ISIS_SRV6_NODE, + .parent_node = ISIS_NODE, + .prompt = "%s(config-router-srv6)# ", +}; + +static struct cmd_node isis_srv6_node_msd_node = { + .name = "isis-srv6-node-msd", + .node = ISIS_SRV6_NODE_MSD_NODE, + .parent_node = ISIS_SRV6_NODE, + .prompt = "%s(config-router-srv6-node-msd)# ", +}; #endif /* HAVE_ISISD */ #ifdef HAVE_FABRICD @@ -1314,6 +1338,13 @@ static struct cmd_node srv6_loc_node = { .prompt = "%s(config-srv6-locator)# ", }; +static struct cmd_node srv6_encap_node = { + .name = "srv6-encap", + .node = SRV6_ENCAP_NODE, + .parent_node = SRV6_NODE, + .prompt = "%s(config-srv6-encap)# " +}; + #ifdef HAVE_PBRD static struct cmd_node pbr_map_node = { .name = "pbr-map", @@ -1631,6 +1662,7 @@ static int vtysh_end(void) /* Nothing to do. */ break; default: + vty->vtysh_file_locked = false; vty->node = ENABLE_NODE; break; } @@ -1670,6 +1702,14 @@ DEFUNSH(VTYSH_ZEBRA, srv6_locator, srv6_locator_cmd, return CMD_SUCCESS; } +DEFUNSH(VTYSH_ZEBRA, srv6_encap, srv6_encap_cmd, + "encapsulation", + "Segment Routing SRv6 encapsulation\n") +{ + vty->node = SRV6_ENCAP_NODE; + return CMD_SUCCESS; +} + #ifdef HAVE_BGPD DEFUNSH(VTYSH_BGPD, router_bgp, router_bgp_cmd, "router bgp [ASNUM [<view|vrf> VIEWVRFNAME] [as-notation <dot|dot+|plain>]]", @@ -2110,6 +2150,23 @@ DEFUNSH(VTYSH_ISISD, isis_flex_algo, isis_flex_algo_cmd, "flex-algo (128-255)", vty->node = ISIS_FLEX_ALGO_NODE; return CMD_SUCCESS; } + +DEFUNSH(VTYSH_ISISD, isis_srv6_enable, isis_srv6_enable_cmd, + "segment-routing srv6", + SR_STR + "Enable Segment Routing over IPv6 (SRv6)\n") +{ + vty->node = ISIS_SRV6_NODE; + return CMD_SUCCESS; +} + +DEFUNSH(VTYSH_ISISD, isis_srv6_node_msd, isis_srv6_node_msd_cmd, + "node-msd", + "Segment Routing over IPv6 (SRv6) Maximum SRv6 SID Depths\n") +{ + vty->node = ISIS_SRV6_NODE_MSD_NODE; + return CMD_SUCCESS; +} #endif /* HAVE_ISISD */ #ifdef HAVE_FABRICD @@ -2334,6 +2391,18 @@ DEFUNSH(VTYSH_REALLYALL, vtysh_config_terminal, vtysh_config_terminal_cmd, return CMD_SUCCESS; } +DEFUNSH(VTYSH_REALLYALL, vtysh_config_terminal_file_lock, + vtysh_config_terminal_file_lock_cmd, + "configure terminal file-lock", + "Configuration from vty interface\n" + "Configuration terminal\n" + "Configuration with locked datastores\n") +{ + vty->node = CONFIG_NODE; + vty->vtysh_file_locked = true; + return CMD_SUCCESS; +} + static int vtysh_exit(struct vty *vty) { struct cmd_node *cnode = vector_lookup(cmdvec, vty->node); @@ -2346,10 +2415,20 @@ static int vtysh_exit(struct vty *vty) vty->node = cnode->parent_node; if (vty->node == CONFIG_NODE) { + bool locked = vty->vtysh_file_locked; + /* resync in case one of the daemons is somewhere else */ vtysh_execute("end"); - vtysh_execute("configure"); + /* NOTE: a rather expensive thing to do, can we avoid it? */ + + if (locked) + vtysh_execute("configure terminal file-lock"); + else + vtysh_execute("configure terminal"); + } else if (vty->node == ENABLE_NODE) { + vty->vtysh_file_locked = false; } + return CMD_SUCCESS; } @@ -2446,6 +2525,14 @@ DEFUNSH(VTYSH_ZEBRA, exit_srv6_loc_config, exit_srv6_loc_config_cmd, "exit", return CMD_SUCCESS; } +DEFUNSH(VTYSH_ZEBRA, exit_srv6_encap, exit_srv6_encap_cmd, "exit", + "Exit from SRv6-encapsulation configuration mode\n") +{ + if (vty->node == SRV6_ENCAP_NODE) + vty->node = SRV6_NODE; + return CMD_SUCCESS; +} + #ifdef HAVE_RIPD DEFUNSH(VTYSH_RIPD, vtysh_exit_ripd, vtysh_exit_ripd_cmd, "exit", "Exit current mode and down to previous mode\n") @@ -2605,6 +2692,30 @@ DEFUNSH(VTYSH_ISISD, vtysh_quit_isis_flex_algo, vtysh_quit_isis_flex_algo_cmd, { return vtysh_exit_isisd(self, vty, argc, argv); } + +DEFUNSH(VTYSH_ISISD, vtysh_exit_isis_srv6_enable, vtysh_exit_isis_srv6_enable_cmd, + "exit", "Exit current mode and down to previous mode\n") +{ + return vtysh_exit_isisd(self, vty, argc, argv); +} + +DEFUNSH(VTYSH_ISISD, vtysh_quit_isis_srv6_enable, vtysh_quit_isis_srv6_enable_cmd, + "quit", "Exit current mode and down to previous mode\n") +{ + return vtysh_exit_isisd(self, vty, argc, argv); +} + +DEFUNSH(VTYSH_ISISD, vtysh_exit_isis_srv6_node_msd, vtysh_exit_isis_srv6_node_msd_cmd, + "exit", "Exit current mode and down to previous mode\n") +{ + return vtysh_exit(vty); +} + +DEFUNSH(VTYSH_ISISD, vtysh_quit_isis_srv6_node_msd, vtysh_quit_isis_srv6_node_msd_cmd, + "quit", "Exit current mode and down to previous mode\n") +{ + return vtysh_exit_isisd(self, vty, argc, argv); +} #endif /* HAVE_ISISD */ #if HAVE_BFDD > 0 @@ -2832,35 +2943,38 @@ static int show_one_daemon(struct vty *vty, struct cmd_token **argv, int argc, return ret; } -DEFUN (vtysh_show_thread_timer, - vtysh_show_thread_timer_cmd, - "show thread timers", +#if CONFDATE > 20240707 + CPP_NOTICE("Remove `show thread ...` commands") +#endif +DEFUN (vtysh_show_event_timer, + vtysh_show_event_timer_cmd, + "show event timers", SHOW_STR - "Thread information\n" + "Event information\n" "Show all timers and how long they have in the system\n") { - return show_per_daemon(vty, argv, argc, "Thread timers for %s:\n"); + return show_per_daemon(vty, argv, argc, "Event timers for %s:\n"); } -DEFUN (vtysh_show_poll, - vtysh_show_poll_cmd, - "show thread poll", +DEFUN (vtysh_show_event_poll, + vtysh_show_event_poll_cmd, + "show event poll", SHOW_STR - "Thread information\n" - "Thread Poll Information\n") + "Event information\n" + "Event Poll Information\n") { - return show_per_daemon(vty, argv, argc, "Thread statistics for %s:\n"); + return show_per_daemon(vty, argv, argc, "Event statistics for %s:\n"); } -DEFUN (vtysh_show_thread, - vtysh_show_thread_cmd, - "show thread cpu [FILTER]", +DEFUN (vtysh_show_event, + vtysh_show_event_cpu_cmd, + "show event cpu [FILTER]", SHOW_STR - "Thread information\n" - "Thread CPU usage\n" + "Event information\n" + "Event CPU usage\n" "Display filter (rwtexb)\n") { - return show_per_daemon(vty, argv, argc, "Thread statistics for %s:\n"); + return show_per_daemon(vty, argv, argc, "Event statistics for %s:\n"); } DEFUN (vtysh_show_work_queues, @@ -3311,6 +3425,63 @@ DEFUN (vtysh_show_running_config, return vtysh_write_terminal(self, vty, argc, argv); } +static void show_route_map_send(const char *route_map, bool json) +{ + unsigned int i; + bool first = true; + char command_line[128]; + + snprintf(command_line, sizeof(command_line), "show route-map "); + if (route_map) + strlcat(command_line, route_map, sizeof(command_line)); + if (json) + strlcat(command_line, " json", sizeof(command_line)); + + if (json) + vty_out(vty, "{"); + + for (i = 0; i < array_size(vtysh_client); i++) { + const struct vtysh_client *client = &vtysh_client[i]; + bool is_connected = true; + + if (!CHECK_FLAG(client->flag, VTYSH_RMAP)) + continue; + + for (; client; client = client->next) + if (client->fd < 0) + is_connected = false; + + if (!is_connected) + continue; + + if (json && !first) + vty_out(vty, ","); + else + first = false; + + if (json) + vty_out(vty, "\"%s\":", vtysh_client[i].name); + + vtysh_client_execute_name(vtysh_client[i].name, command_line); + } + + if (json) + vty_out(vty, "}\n"); +} + +DEFPY (show_route_map, + show_route_map_cmd, + "show route-map [WORD]$route_map [json]$json", + SHOW_STR + "route-map information\n" + "route-map name\n" + JSON_STR) +{ + show_route_map_send(route_map, !!json); + + return CMD_SUCCESS; +} + DEFUN (vtysh_integrated_config, vtysh_integrated_config_cmd, "service integrated-vtysh-config", @@ -4735,6 +4906,19 @@ void vtysh_init_vty(void) install_element(ISIS_FLEX_ALGO_NODE, &vtysh_exit_isis_flex_algo_cmd); install_element(ISIS_FLEX_ALGO_NODE, &vtysh_quit_isis_flex_algo_cmd); install_element(ISIS_FLEX_ALGO_NODE, &vtysh_end_all_cmd); + + install_node(&isis_srv6_node); + install_element(ISIS_NODE, &isis_srv6_enable_cmd); + install_element(ISIS_SRV6_NODE, &isis_srv6_node_msd_cmd); + install_element(ISIS_SRV6_NODE, &vtysh_exit_isis_srv6_enable_cmd); + install_element(ISIS_SRV6_NODE, &vtysh_quit_isis_srv6_enable_cmd); + install_element(ISIS_SRV6_NODE, &vtysh_end_all_cmd); + install_node(&isis_srv6_node_msd_node); + install_element(ISIS_SRV6_NODE_MSD_NODE, + &vtysh_exit_isis_srv6_node_msd_cmd); + install_element(ISIS_SRV6_NODE_MSD_NODE, + &vtysh_quit_isis_srv6_node_msd_cmd); + install_element(ISIS_SRV6_NODE_MSD_NODE, &vtysh_end_all_cmd); #endif /* HAVE_ISISD */ /* fabricd */ @@ -4916,6 +5100,7 @@ void vtysh_init_vty(void) if (!user_mode) install_element(VIEW_NODE, &vtysh_enable_cmd); install_element(ENABLE_NODE, &vtysh_config_terminal_cmd); + install_element(ENABLE_NODE, &vtysh_config_terminal_file_lock_cmd); install_element(ENABLE_NODE, &vtysh_disable_cmd); /* "exit" command. */ @@ -4934,6 +5119,7 @@ void vtysh_init_vty(void) install_element(SRV6_NODE, &srv6_locators_cmd); install_element(SRV6_NODE, &exit_srv6_config_cmd); install_element(SRV6_NODE, &vtysh_end_all_cmd); + install_element(SRV6_NODE, &srv6_encap_cmd); install_node(&srv6_locs_node); install_element(SRV6_LOCS_NODE, &srv6_locator_cmd); @@ -4944,10 +5130,16 @@ void vtysh_init_vty(void) install_element(SRV6_LOC_NODE, &exit_srv6_loc_config_cmd); install_element(SRV6_LOC_NODE, &vtysh_end_all_cmd); + install_node(&srv6_encap_node); + install_element(SRV6_ENCAP_NODE, &exit_srv6_encap_cmd); + install_element(SRV6_ENCAP_NODE, &vtysh_end_all_cmd); + install_element(ENABLE_NODE, &vtysh_show_running_config_cmd); install_element(ENABLE_NODE, &vtysh_copy_running_config_cmd); install_element(ENABLE_NODE, &vtysh_copy_to_running_cmd); + install_element(ENABLE_NODE, &show_route_map_cmd); + /* "write terminal" command. */ install_element(ENABLE_NODE, &vtysh_write_terminal_cmd); @@ -5013,9 +5205,9 @@ void vtysh_init_vty(void) install_element(VIEW_NODE, &vtysh_show_modules_cmd); install_element(VIEW_NODE, &vtysh_show_work_queues_cmd); install_element(VIEW_NODE, &vtysh_show_work_queues_daemon_cmd); - install_element(VIEW_NODE, &vtysh_show_thread_cmd); - install_element(VIEW_NODE, &vtysh_show_poll_cmd); - install_element(VIEW_NODE, &vtysh_show_thread_timer_cmd); + install_element(VIEW_NODE, &vtysh_show_event_cpu_cmd); + install_element(VIEW_NODE, &vtysh_show_event_poll_cmd); + install_element(VIEW_NODE, &vtysh_show_event_timer_cmd); /* Logging */ install_element(VIEW_NODE, &vtysh_show_logging_cmd); diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h index 1c2cca9d90..65733ca61b 100644 --- a/vtysh/vtysh.h +++ b/vtysh/vtysh.h @@ -58,8 +58,8 @@ extern struct event_loop *master; VTYSH_EIGRPD | VTYSH_BABELD | VTYSH_PBRD | VTYSH_FABRICD | \ VTYSH_VRRPD #define VTYSH_INTERFACE VTYSH_INTERFACE_SUBSET | VTYSH_BGPD -#define VTYSH_VRF VTYSH_INTERFACE_SUBSET | VTYSH_STATICD | VTYSH_MGMTD -#define VTYSH_KEYS VTYSH_RIPD | VTYSH_EIGRPD | VTYSH_OSPF6D +#define VTYSH_VRF VTYSH_INTERFACE_SUBSET | VTYSH_MGMTD +#define VTYSH_KEYS VTYSH_RIPD | VTYSH_EIGRPD | VTYSH_OSPF6D | VTYSH_OSPFD /* Daemons who can process nexthop-group configs */ #define VTYSH_NH_GROUP VTYSH_PBRD|VTYSH_SHARPD #define VTYSH_SR VTYSH_ZEBRA|VTYSH_PATHD diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c index 2949faa427..c02f27c876 100644 --- a/vtysh/vtysh_config.c +++ b/vtysh/vtysh_config.c @@ -455,6 +455,12 @@ void vtysh_config_parse_line(void *arg, const char *line) else if (strncmp(line, "debug resolver", strlen("debug resolver")) == 0) config = config_get(RESOLVER_DEBUG_NODE, line); + else if (strncmp(line, "debug mgmt client frontend", + strlen("debug mgmt client frontend")) == 0) + config = config_get(MGMT_FE_DEBUG_NODE, line); + else if (strncmp(line, "debug mgmt client backend", + strlen("debug mgmt client backend")) == 0) + config = config_get(MGMT_BE_DEBUG_NODE, line); else if (strncmp(line, "debug", strlen("debug")) == 0) config = config_get(DEBUG_NODE, line); else if (strncmp(line, "password", strlen("password")) == 0 @@ -484,8 +490,7 @@ void vtysh_config_parse_line(void *arg, const char *line) config = config_get(RPKI_NODE, line); else { if (strncmp(line, "log", strlen("log")) == 0 || - strncmp(line, "hostname", strlen("hostname")) == - 0 || + strncmp(line, "hostname", strlen("hostname")) == 0 || strncmp(line, "domainname", strlen("domainname")) == 0 || strncmp(line, "allow-reserved-ranges", @@ -497,12 +502,9 @@ void vtysh_config_parse_line(void *arg, const char *line) strlen("no ip prefix-list")) == 0 || strncmp(line, "no ipv6 prefix-list", strlen("no ipv6 prefix-list")) == 0 || - strncmp(line, "service ", strlen("service ")) == - 0 || - strncmp(line, "no service cputime-stats", - strlen("no service cputime-stats")) == 0 || - strncmp(line, "service cputime-warning", - strlen("service cputime-warning")) == 0) + strncmp(line, "service ", strlen("service ")) == 0 || + strncmp(line, "no service ", + strlen("no service ")) == 0) config_add_line_uniq(config_top, line); else config_add_line(config_top, line); @@ -548,9 +550,7 @@ static void configvec_dump(vector vec, bool nested) * are not under the VRF node. */ if (config->index == INTERFACE_NODE - && (listcount(config->line) == 1) - && (line = listnode_head(config->line)) - && strmatch(line, "exit")) { + && list_isempty(config->line)) { config_del(config); continue; } @@ -607,7 +607,8 @@ static int vtysh_read_file(FILE *confp, bool dry_run) vty->node = CONFIG_NODE; vtysh_execute_no_pager("enable"); - vtysh_execute_no_pager("configure terminal"); + vtysh_execute_no_pager("conf term file-lock"); + vty->vtysh_file_locked = true; if (!dry_run) vtysh_execute_no_pager("XFRR_start_configuration"); @@ -619,6 +620,7 @@ static int vtysh_read_file(FILE *confp, bool dry_run) vtysh_execute_no_pager("XFRR_end_configuration"); vtysh_execute_no_pager("end"); + vty->vtysh_file_locked = false; vtysh_execute_no_pager("disable"); vty_close(vty); diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index 20254fcd53..6065776f11 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -5,6 +5,8 @@ #include <zebra.h> +#include <signal.h> +#include <sys/stat.h> #include <sys/un.h> #include <setjmp.h> #include <pwd.h> @@ -221,7 +223,9 @@ static struct event *vtysh_rl_read_thread; static void vtysh_rl_read(struct event *thread) { - event_add_read(master, vtysh_rl_read, NULL, STDIN_FILENO, + bool *suppress_warnings = EVENT_ARG(thread); + + event_add_read(master, vtysh_rl_read, suppress_warnings, STDIN_FILENO, &vtysh_rl_read_thread); rl_callback_read_char(); } @@ -230,11 +234,12 @@ static void vtysh_rl_read(struct event *thread) static void vtysh_rl_run(void) { struct event thread; + bool suppress_warnings = true; master = event_master_create(NULL); rl_callback_handler_install(vtysh_prompt(), vtysh_rl_callback); - event_add_read(master, vtysh_rl_read, NULL, STDIN_FILENO, + event_add_read(master, vtysh_rl_read, &suppress_warnings, STDIN_FILENO, &vtysh_rl_read_thread); while (!vtysh_loop_exited && event_fetch(master, &thread)) diff --git a/watchfrr/watchfrr.c b/watchfrr/watchfrr.c index 89199da1af..707e01f4ef 100644 --- a/watchfrr/watchfrr.c +++ b/watchfrr/watchfrr.c @@ -6,6 +6,11 @@ */ #include <zebra.h> + +#include <signal.h> +#include <sys/stat.h> +#include <fcntl.h> + #include "frrevent.h" #include <log.h> #include <network.h> @@ -600,6 +605,9 @@ static void daemon_restarting_operational(struct event *thread) static void daemon_down(struct daemon *dmn, const char *why) { + if (dmn->ignore_timeout) + return; + if (IS_UP(dmn) || (dmn->state == DAEMON_INIT)) flog_err(EC_WATCHFRR_CONNECTION, "%s state -> down : %s", dmn->name, why); @@ -908,7 +916,7 @@ static void phase_check(void) "Phased restart: all routing daemon stop jobs have completed."); set_phase(PHASE_WAITING_DOWN); - /*FALLTHRU*/ + fallthrough; case PHASE_WAITING_DOWN: if (gs.numdown + IS_UP(gs.special) < gs.numdaemons) break; @@ -918,7 +926,7 @@ static void phase_check(void) 1); set_phase(PHASE_ZEBRA_RESTART_PENDING); - /*FALLTHRU*/ + fallthrough; case PHASE_ZEBRA_RESTART_PENDING: if (gs.special->restart.pid) break; @@ -927,7 +935,7 @@ static void phase_check(void) gs.special->name); set_phase(PHASE_WAITING_ZEBRA_UP); - /*FALLTHRU*/ + fallthrough; case PHASE_WAITING_ZEBRA_UP: if (!IS_UP(gs.special)) break; diff --git a/watchfrr/watchfrr_vty.c b/watchfrr/watchfrr_vty.c index 3afc76761d..0547c1e8b3 100644 --- a/watchfrr/watchfrr_vty.c +++ b/watchfrr/watchfrr_vty.c @@ -6,6 +6,8 @@ */ #include <zebra.h> + +#include <signal.h> #include <sys/wait.h> #include "memory.h" diff --git a/yang/frr-bgp-neighbor.yang b/yang/frr-bgp-neighbor.yang index 5a4c37974f..b199ab9469 100644 --- a/yang/frr-bgp-neighbor.yang +++ b/yang/frr-bgp-neighbor.yang @@ -76,7 +76,7 @@ submodule frr-bgp-neighbor { leaf enforce-first-as { type boolean; - default "false"; + default "true"; description "When set to 'true' it will enforce the first AS for EBGP routes."; } diff --git a/yang/frr-bgp-route-map.yang b/yang/frr-bgp-route-map.yang index b557cabb22..c50c51389e 100644 --- a/yang/frr-bgp-route-map.yang +++ b/yang/frr-bgp-route-map.yang @@ -214,6 +214,12 @@ module frr-bgp-route-map { "Set BGP extended community attribute"; } +identity set-extcommunity-color { + base frr-route-map:rmap-set-type; + description + "Set BGP extended community attribute"; + } + identity set-ipv4-nexthop { base frr-route-map:rmap-set-type; description @@ -346,6 +352,12 @@ module frr-bgp-route-map { "Set BGP large community list (for deletion)"; } + identity extended-comm-list-delete { + base frr-route-map:rmap-set-type; + description + "Set BGP extended community list (for deletion)"; + } + identity set-evpn-gateway-ip-ipv4 { base frr-route-map:rmap-set-type; description @@ -511,6 +523,22 @@ module frr-bgp-route-map { } } + typedef color-list { + type string { + pattern '((429496729[0-5]|42949672[0-8][0-9]|' + + '4294967[0-1][0-9]{2}|429496[0-6][0-9]{3}|' + + '42949[0-5][0-9]{4}|4294[0-8][0-9]{5}|' + + '429[0-3][0-9]{6}|42[0-8][0-9]{7}|' + + '4[0-1][0-9]{8}|[1-3][0-9]{9}|' + + '[1-9][0-9]{0,8})(\s*))+'; + } + description + "The color-list type represent a set of colors of value (1..4294967295) + values are separated by white spaces"; + reference + "RFC 9012 - The BGP Tunnel Encapsulation Attribute"; + } + augment "/frr-route-map:lib/frr-route-map:route-map/frr-route-map:entry/frr-route-map:match-condition/frr-route-map:rmap-match-condition/frr-route-map:match-condition" { case local-preference { when "derived-from-or-self(/frr-route-map:lib/frr-route-map:route-map/frr-route-map:entry/frr-route-map:match-condition/frr-route-map:condition, 'frr-bgp-route-map:match-local-preference')"; @@ -749,6 +777,13 @@ module frr-bgp-route-map { description "Do exact matching of communities"; } + + leaf comm-list-name-any { + type boolean; + description + "Do matching of any community"; + } + } } @@ -852,6 +887,19 @@ module frr-bgp-route-map { } } + case extcommunity-color { + when "derived-from-or-self(/frr-route-map:lib/frr-route-map:route-map/frr-route-map:entry/frr-route-map:set-action/frr-route-map:action, 'frr-bgp-route-map:set-extcommunity-color')"; + description + "Value of the ext-community"; + leaf extcommunity-color { + type color-list; + description + "Set BGP ext-community color attribute with a list of colors"; + reference + "RFC9012"; + } + } + case ipv4-address { when "derived-from-or-self(/frr-route-map:lib/frr-route-map:route-map/frr-route-map:entry/frr-route-map:set-action/frr-route-map:action, 'frr-bgp-route-map:ipv4-vpn-address')"; description @@ -1074,7 +1122,9 @@ module frr-bgp-route-map { case comm-list-name { when "derived-from-or-self(/frr-route-map:lib/frr-route-map:route-map/frr-route-map:entry/frr-route-map:set-action/frr-route-map:action, 'frr-bgp-route-map:comm-list-delete') or " - + "derived-from-or-self(/frr-route-map:lib/frr-route-map:route-map/frr-route-map:entry/frr-route-map:set-action/frr-route-map:action, 'frr-bgp-route-map:large-comm-list-delete')"; + + "derived-from-or-self(/frr-route-map:lib/frr-route-map:route-map/frr-route-map:entry/frr-route-map:set-action/frr-route-map:action, 'frr-bgp-route-map:large-comm-list-delete') or " + + "derived-from-or-self(/frr-route-map:lib/frr-route-map:route-map/frr-route-map:entry/frr-route-map:set-action/frr-route-map:action, +'frr-bgp-route-map:extended-comm-list-delete')"; leaf comm-list-name { type bgp-filter:bgp-list-name; } diff --git a/yang/frr-gmp.yang b/yang/frr-gmp.yang index a18651db28..c8a05a2bdb 100644 --- a/yang/frr-gmp.yang +++ b/yang/frr-gmp.yang @@ -107,7 +107,7 @@ module frr-gmp { range "1..max"; } units seconds; - must ". * 10 >= ../query-max-response-time"; + must ". * 10 > ../query-max-response-time"; default "125"; description "The Query Interval is the interval between General Queries diff --git a/yang/frr-isisd.yang b/yang/frr-isisd.yang index ae69d53ccc..5d7c739c05 100644 --- a/yang/frr-isisd.yang +++ b/yang/frr-isisd.yang @@ -1495,9 +1495,32 @@ module frr-isisd { "IS-IS level into which the routes should be redistributed."; } - uses redistribute-attributes; - } + choice protocol-type { + case protocol-table { + when "./protocol = \"table\""; + list table { + key "table"; + when "../protocol = \"table\""; + description + "Routing table number"; + + leaf table { + type uint16 { + range "1..65535"; + } + description + "Routing table number."; + } + + uses redistribute-attributes; + } + } + case protocol-other { + uses redistribute-attributes; + } + } + } list ipv6 { key "protocol level"; description @@ -1516,7 +1539,29 @@ module frr-isisd { "IS-IS level into which the routes should be redistributed."; } - uses redistribute-attributes; + choice protocol-type { + case protocol-table { + when "./protocol = \"table\""; + list table { + key "table"; + when "../protocol = \"table\""; + + leaf table { + type uint16 { + range "1..65535"; + } + description + "Routing table number."; + } + + uses redistribute-attributes; + } + } + case protocol-other { + uses redistribute-attributes; + } + } + } } @@ -1949,6 +1994,71 @@ module frr-isisd { } } + container segment-routing-srv6 { + description + "Segment Routing over IPv6 (SRv6) global configuration."; + leaf enabled { + type boolean; + default "false"; + description + "Enable IS-IS extensions to support Segment Routing over + IPv6 data plane (SRv6)."; + reference + "RFC 9352"; + } + leaf locator { + type string; + description + "SRv6 locator."; + } + container msd { + description + "SRv6 Maximum SRv6 SID Depths."; + container node-msd { + description + "SRv6 Node Maximum SRv6 SID Depths."; + leaf max-segs-left { + type uint8 { + range "0..255"; + } + default 3; + description + "Maximum Segments Left MSD."; + } + leaf max-end-pop { + type uint8 { + range "0..255"; + } + default 3; + description + "Maximum End Pop MSD."; + } + leaf max-h-encaps { + type uint8 { + range "0..255"; + } + default 2; + description + "Maximum H.Encaps MSD."; + } + leaf max-end-d { + type uint8 { + range "0..255"; + } + default 5; + description + "Maximum End D MSD."; + } + } + } + leaf interface { + type string; + description + "Dummy interface used to install SRv6 SIDs into the Linux data plane."; + default "sr0"; + } + } + container mpls { description "Configuration of MPLS parameters"; diff --git a/yang/frr-nexthop.yang b/yang/frr-nexthop.yang index d73fdb8bd3..175487d78b 100644 --- a/yang/frr-nexthop.yang +++ b/yang/frr-nexthop.yang @@ -201,6 +201,11 @@ module frr-nexthop { description "Nexthop's MPLS label stack."; } + + uses srv6-segs-stack { + description + "Nexthop's SRv6 segs SIDs stack."; + } } /* @@ -298,6 +303,32 @@ module frr-nexthop { } } + /* Contaner for SRv6 segs SIDs */ + grouping srv6-segs-stack { + description + "This grouping specifies an SRv6 segs SIDs stack. The segs + SIDs stack is encoded as a list of SID entries. The + list key is an identifier that indicates the relative + ordering of each entry."; + container srv6-segs-stack { + description + "Container for a list of SRv6 segs SIDs entries."; + list entry { + key "id"; + description + "List of SRv6 segs SIDs entries."; + leaf id { + type uint8; + description + "Identifies the entry in a sequence of SRv6 segs SIDs + entries."; + } + leaf seg { + type inet:ipv6-address; + } + } + } + } container frr-nexthop-group { description "A nexthop-group, represented as a list of nexthop objects."; diff --git a/yang/frr-pim.yang b/yang/frr-pim.yang index 105dab895d..e9b3f67507 100644 --- a/yang/frr-pim.yang +++ b/yang/frr-pim.yang @@ -343,7 +343,7 @@ module frr-pim { } leaf hello-interval { - type uint8 { + type uint16 { range "1..max"; } default "30"; diff --git a/yang/frr-route-types.yang b/yang/frr-route-types.yang index 728607cabe..aa676cebc2 100644 --- a/yang/frr-route-types.yang +++ b/yang/frr-route-types.yang @@ -54,44 +54,47 @@ module frr-route-types { enum connected { value 2; } - enum static { + enum local { value 3; } - enum rip { + enum static { value 4; } + enum rip { + value 5; + } enum ospf { - value 6; + value 7; } enum isis { - value 8; + value 9; } enum bgp { - value 9; + value 10; } enum eigrp { - value 11; + value 12; } enum nhrp { - value 12; + value 13; } enum table { - value 15; + value 16; } enum vnc { - value 17; + value 18; } enum vnc-direct { - value 18; + value 19; } enum babel { - value 22; + value 23; } enum sharp { - value 23; + value 24; } enum openfabric { - value 26; + value 27; } } } @@ -104,41 +107,44 @@ module frr-route-types { enum connected { value 2; } - enum static { + enum local { value 3; } + enum static { + value 4; + } enum ripng { - value 5; + value 6; } enum ospf6 { - value 7; + value 8; } enum isis { - value 8; + value 9; } enum bgp { - value 9; + value 10; } enum nhrp { - value 12; + value 13; } enum table { - value 15; + value 16; } enum vnc { - value 17; + value 18; } enum vnc-direct { - value 18; + value 19; } enum babel { - value 22; + value 23; } enum sharp { - value 23; + value 24; } enum openfabric { - value 26; + value 27; } } } diff --git a/yang/frr-test-module.yang b/yang/frr-test-module.yang index d6e7188240..6cc60e8665 100644 --- a/yang/frr-test-module.yang +++ b/yang/frr-test-module.yang @@ -82,5 +82,23 @@ module frr-test-module { } } } + choice achoice { + description "a choice statement"; + case case1 { + leaf c1value { + type uint8; + description "A uint8 value for case 1"; + } + } + case case2 { + container c2cont { + description "case 2 container"; + leaf c2value { + type uint32; + description "A uint32 value for case 2"; + } + } + } + } } } diff --git a/yang/frr-zebra.yang b/yang/frr-zebra.yang index 7f4254cd41..3c6e45126a 100644 --- a/yang/frr-zebra.yang +++ b/yang/frr-zebra.yang @@ -1982,6 +1982,12 @@ module frr-zebra { "Interface admin status."; } + leaf mpls { + type boolean; + description + "Interface MPLS status."; + } + leaf bandwidth { type uint32 { range "1..100000"; diff --git a/zebra/connected.c b/zebra/connected.c index ee0823f56f..404f892f6e 100644 --- a/zebra/connected.c +++ b/zebra/connected.c @@ -48,7 +48,7 @@ static void connected_withdraw(struct connected *ifc) UNSET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED); if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED)) { - listnode_delete(ifc->ifp->connected, ifc); + if_connected_del(ifc->ifp->connected, ifc); connected_free(&ifc); } } @@ -65,7 +65,7 @@ static void connected_announce(struct interface *ifp, struct connected *ifc) UNSET_FLAG(ifc->flags, ZEBRA_IFA_UNNUMBERED); } - listnode_add(ifp->connected, ifc); + if_connected_add_tail(ifp->connected, ifc); /* Update interface address information to protocol daemon. */ if (ifc->address->family == AF_INET) @@ -84,9 +84,8 @@ struct connected *connected_check(struct interface *ifp, { const struct prefix *p = pu.p; struct connected *ifc; - struct listnode *node; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) + frr_each (if_connected, ifp->connected, ifc) if (prefix_same(ifc->address, p)) return ifc; @@ -101,9 +100,8 @@ struct connected *connected_check_ptp(struct interface *ifp, const struct prefix *p = pu.p; const struct prefix *d = du.p; struct connected *ifc; - struct listnode *node; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { + frr_each (if_connected, ifp->connected, ifc) { if (!prefix_same(ifc->address, p)) continue; if (!CONNECTED_PEER(ifc) && !d) @@ -182,7 +180,7 @@ static void connected_update(struct interface *ifp, struct connected *ifc) void connected_up(struct interface *ifp, struct connected *ifc) { afi_t afi; - struct prefix p; + struct prefix p, plocal; struct nexthop nh = { .type = NEXTHOP_TYPE_IFINDEX, .ifindex = ifp->ifindex, @@ -192,8 +190,8 @@ void connected_up(struct interface *ifp, struct connected *ifc) uint32_t metric; uint32_t flags = 0; uint32_t count = 0; - struct listnode *cnode; struct connected *c; + bool install_local = true; zvrf = ifp->vrf->info; if (!zvrf) { @@ -210,6 +208,7 @@ void connected_up(struct interface *ifp, struct connected *ifc) UNSET_FLAG(ifc->conf, ZEBRA_IFC_DOWN); prefix_copy(&p, CONNECTED_PREFIX(ifc)); + prefix_copy(&plocal, ifc->address); /* Apply mask to the network. */ apply_mask(&p); @@ -224,6 +223,8 @@ void connected_up(struct interface *ifp, struct connected *ifc) */ if (prefix_ipv4_any((struct prefix_ipv4 *)&p)) return; + + plocal.prefixlen = IPV4_MAX_BITLEN; break; case AFI_IP6: #ifndef GNU_LINUX @@ -231,6 +232,11 @@ void connected_up(struct interface *ifp, struct connected *ifc) if (IN6_IS_ADDR_UNSPECIFIED(&p.u.prefix6)) return; #endif + + if (IN6_IS_ADDR_LINKLOCAL(&plocal.u.prefix6)) + install_local = false; + + plocal.prefixlen = IPV6_MAX_BITLEN; break; case AFI_UNSPEC: case AFI_L2VPN: @@ -262,7 +268,7 @@ void connected_up(struct interface *ifp, struct connected *ifc) * for all the addresses on an interface that * resolve to the same network and mask */ - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) { + frr_each (if_connected, ifp->connected, c) { struct prefix cp; prefix_copy(&cp, CONNECTED_PREFIX(c)); @@ -276,13 +282,24 @@ void connected_up(struct interface *ifp, struct connected *ifc) return; } - rib_add(afi, SAFI_UNICAST, zvrf->vrf->vrf_id, ZEBRA_ROUTE_CONNECT, 0, - flags, &p, NULL, &nh, 0, zvrf->table_id, metric, 0, 0, 0, - false); + if (!CHECK_FLAG(ifc->flags, ZEBRA_IFA_NOPREFIXROUTE)) { + rib_add(afi, SAFI_UNICAST, zvrf->vrf->vrf_id, + ZEBRA_ROUTE_CONNECT, 0, flags, &p, NULL, &nh, 0, + zvrf->table_id, metric, 0, 0, 0, false); - rib_add(afi, SAFI_MULTICAST, zvrf->vrf->vrf_id, ZEBRA_ROUTE_CONNECT, 0, - flags, &p, NULL, &nh, 0, zvrf->table_id, metric, 0, 0, 0, - false); + rib_add(afi, SAFI_MULTICAST, zvrf->vrf->vrf_id, + ZEBRA_ROUTE_CONNECT, 0, flags, &p, NULL, &nh, 0, + zvrf->table_id, metric, 0, 0, 0, false); + } + + if (install_local) { + rib_add(afi, SAFI_UNICAST, zvrf->vrf->vrf_id, ZEBRA_ROUTE_LOCAL, + 0, flags, &plocal, NULL, &nh, 0, zvrf->table_id, 0, 0, + 0, 0, false); + rib_add(afi, SAFI_MULTICAST, zvrf->vrf->vrf_id, + ZEBRA_ROUTE_LOCAL, 0, flags, &plocal, NULL, &nh, 0, + zvrf->table_id, 0, 0, 0, 0, false); + } /* Schedule LSP forwarding entries for processing, if appropriate. */ if (zvrf->vrf->vrf_id == VRF_DEFAULT) { @@ -368,7 +385,7 @@ void connected_add_ipv4(struct interface *ifp, int flags, void connected_down(struct interface *ifp, struct connected *ifc) { afi_t afi; - struct prefix p; + struct prefix p, plocal; struct nexthop nh = { .type = NEXTHOP_TYPE_IFINDEX, .ifindex = ifp->ifindex, @@ -376,8 +393,8 @@ void connected_down(struct interface *ifp, struct connected *ifc) }; struct zebra_vrf *zvrf; uint32_t count = 0; - struct listnode *cnode; struct connected *c; + bool remove_local = true; zvrf = ifp->vrf->info; if (!zvrf) { @@ -403,6 +420,7 @@ void connected_down(struct interface *ifp, struct connected *ifc) } prefix_copy(&p, CONNECTED_PREFIX(ifc)); + prefix_copy(&plocal, ifc->address); /* Apply mask to the network. */ apply_mask(&p); @@ -417,10 +435,18 @@ void connected_down(struct interface *ifp, struct connected *ifc) */ if (prefix_ipv4_any((struct prefix_ipv4 *)&p)) return; + + plocal.prefixlen = IPV4_MAX_BITLEN; break; case AFI_IP6: if (IN6_IS_ADDR_UNSPECIFIED(&p.u.prefix6)) return; + + plocal.prefixlen = IPV6_MAX_BITLEN; + + if (IN6_IS_ADDR_LINKLOCAL(&plocal.u.prefix6)) + remove_local = false; + break; case AFI_UNSPEC: case AFI_L2VPN: @@ -439,7 +465,7 @@ void connected_down(struct interface *ifp, struct connected *ifc) * allow the deletion when are removing the last * one. */ - for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) { + frr_each (if_connected, ifp->connected, c) { struct prefix cp; prefix_copy(&cp, CONNECTED_PREFIX(c)); @@ -457,11 +483,25 @@ void connected_down(struct interface *ifp, struct connected *ifc) * Same logic as for connected_up(): push the changes into the * head. */ - rib_delete(afi, SAFI_UNICAST, zvrf->vrf->vrf_id, ZEBRA_ROUTE_CONNECT, 0, - 0, &p, NULL, &nh, 0, zvrf->table_id, 0, 0, false); + if (!CHECK_FLAG(ifc->flags, ZEBRA_IFA_NOPREFIXROUTE)) { + rib_delete(afi, SAFI_UNICAST, zvrf->vrf->vrf_id, + ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, &nh, 0, + zvrf->table_id, 0, 0, false); + + rib_delete(afi, SAFI_MULTICAST, zvrf->vrf->vrf_id, + ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, &nh, 0, + zvrf->table_id, 0, 0, false); + } + + if (remove_local) { + rib_delete(afi, SAFI_UNICAST, zvrf->vrf->vrf_id, + ZEBRA_ROUTE_LOCAL, 0, 0, &plocal, NULL, &nh, 0, + zvrf->table_id, 0, 0, false); - rib_delete(afi, SAFI_MULTICAST, zvrf->vrf->vrf_id, ZEBRA_ROUTE_CONNECT, - 0, 0, &p, NULL, &nh, 0, zvrf->table_id, 0, 0, false); + rib_delete(afi, SAFI_MULTICAST, zvrf->vrf->vrf_id, + ZEBRA_ROUTE_LOCAL, 0, 0, &plocal, NULL, &nh, 0, + zvrf->table_id, 0, 0, false); + } /* Schedule LSP forwarding entries for processing, if appropriate. */ if (zvrf->vrf->vrf_id == VRF_DEFAULT) { @@ -616,9 +656,8 @@ void connected_delete_ipv6(struct interface *ifp, int connected_is_unnumbered(struct interface *ifp) { struct connected *connected; - struct listnode *node; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) { + frr_each (if_connected, ifp->connected, connected) { if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL) && connected->address->family == AF_INET) return CHECK_FLAG(connected->flags, diff --git a/zebra/debug.c b/zebra/debug.c index 68bedaf057..cf1701be19 100644 --- a/zebra/debug.c +++ b/zebra/debug.c @@ -7,6 +7,7 @@ #include <zebra.h> #include "command.h" #include "debug.h" +#include "mgmt_be_client.h" #include "zebra/debug_clippy.c" @@ -846,4 +847,7 @@ void zebra_debug_init(void) install_element(CONFIG_NODE, &no_debug_zebra_pbr_cmd); install_element(CONFIG_NODE, &debug_zebra_mlag_cmd); install_element(CONFIG_NODE, &debug_zebra_evpn_mh_cmd); + + /* Init mgmtd backend client debug commands. */ + mgmt_be_client_lib_vty_init(); } diff --git a/zebra/debug_nl.c b/zebra/debug_nl.c index df0b5aae7b..a7cccdb98f 100644 --- a/zebra/debug_nl.c +++ b/zebra/debug_nl.c @@ -983,6 +983,7 @@ static void nllink_dump(struct ifinfomsg *ifi, size_t msglen) zlog_debug(" rta [len=%d (payload=%zu) type=(%d) %s]", rta->rta_len, plen, rta_type, rta_type2str(rta_type)); switch (rta_type) { + case IFLA_IFNAME: case IFLA_IFALIAS: if (plen == 0) { zlog_debug(" invalid length"); diff --git a/zebra/dpdk/zebra_dplane_dpdk.c b/zebra/dpdk/zebra_dplane_dpdk.c index fc140b07a3..4c32044251 100644 --- a/zebra/dpdk/zebra_dplane_dpdk.c +++ b/zebra/dpdk/zebra_dplane_dpdk.c @@ -611,11 +611,11 @@ static void zd_dpdk_port_init(void) if (rte_flow_isolate(port_id, 1, &error)) { if (IS_ZEBRA_DEBUG_DPLANE_DPDK) zlog_debug( - "Flow isolate on port %u failed %d\n", + "Flow isolate on port %u failed %d", port_id, error.type); } else { if (IS_ZEBRA_DEBUG_DPLANE_DPDK) - zlog_debug("Flow isolate on port %u\n", + zlog_debug("Flow isolate on port %u", port_id); } rc = rte_eth_dev_start(port_id); diff --git a/zebra/dplane_fpm_nl.c b/zebra/dplane_fpm_nl.c index be2f55120c..0931cc788f 100644 --- a/zebra/dplane_fpm_nl.c +++ b/zebra/dplane_fpm_nl.c @@ -19,6 +19,9 @@ #include <string.h> #include "lib/zebra.h" + +#include <linux/rtnetlink.h> + #include "lib/json.h" #include "lib/libfrr.h" #include "lib/frratomic.h" @@ -44,6 +47,12 @@ #define SOUTHBOUND_DEFAULT_ADDR INADDR_LOOPBACK #define SOUTHBOUND_DEFAULT_PORT 2620 +/* + * Time in seconds that if the other end is not responding + * something terrible has gone wrong. Let's fix that. + */ +#define DPLANE_FPM_NL_WEDGIE_TIME 15 + /** * FPM header: * { @@ -65,6 +74,7 @@ struct fpm_nl_ctx { bool disabled; bool connecting; bool use_nhg; + bool use_route_replace; struct sockaddr_storage addr; /* data plane buffers. */ @@ -89,6 +99,7 @@ struct fpm_nl_ctx { struct event *t_event; struct event *t_nhg; struct event *t_dequeue; + struct event *t_wedged; /* zebra events. */ struct event *t_lspreset; @@ -282,6 +293,25 @@ DEFUN(no_fpm_use_nhg, no_fpm_use_nhg_cmd, return CMD_SUCCESS; } +DEFUN(fpm_use_route_replace, fpm_use_route_replace_cmd, + "fpm use-route-replace", + FPM_STR + "Use netlink route replace semantics\n") +{ + gfnc->use_route_replace = true; + return CMD_SUCCESS; +} + +DEFUN(no_fpm_use_route_replace, no_fpm_use_route_replace_cmd, + "no fpm use-route-replace", + NO_STR + FPM_STR + "Use netlink route replace semantics\n") +{ + gfnc->use_route_replace = false; + return CMD_SUCCESS; +} + DEFUN(fpm_reset_counters, fpm_reset_counters_cmd, "clear fpm counters", CLEAR_STR @@ -396,6 +426,11 @@ static int fpm_write_config(struct vty *vty) written = 1; } + if (!gfnc->use_route_replace) { + vty_out(vty, "no fpm use-route-replace\n"); + written = 1; + } + return written; } @@ -587,7 +622,8 @@ static void fpm_read(struct event *t) switch (hdr->nlmsg_type) { case RTM_NEWROUTE: ctx = dplane_ctx_alloc(); - dplane_ctx_set_op(ctx, DPLANE_OP_ROUTE_NOTIFY); + dplane_ctx_route_init(ctx, DPLANE_OP_ROUTE_NOTIFY, NULL, + NULL); if (netlink_route_change_read_unicast_internal( hdr, 0, false, ctx) != 1) { dplane_ctx_fini(&ctx); @@ -806,12 +842,20 @@ static int fpm_nl_enqueue(struct fpm_nl_ctx *fnc, struct zebra_dplane_ctx *ctx) frr_mutex_lock_autounlock(&fnc->obuf_mutex); + /* + * If route replace is enabled then directly encode the install which + * is going to use `NLM_F_REPLACE` (instead of delete/add operations). + */ + if (fnc->use_route_replace && op == DPLANE_OP_ROUTE_UPDATE) + op = DPLANE_OP_ROUTE_INSTALL; + switch (op) { case DPLANE_OP_ROUTE_UPDATE: case DPLANE_OP_ROUTE_DELETE: rv = netlink_route_multipath_msg_encode(RTM_DELROUTE, ctx, nl_buf, sizeof(nl_buf), - true, fnc->use_nhg); + true, fnc->use_nhg, + false); if (rv <= 0) { zlog_err( "%s: netlink_route_multipath_msg_encode failed", @@ -825,11 +869,14 @@ static int fpm_nl_enqueue(struct fpm_nl_ctx *fnc, struct zebra_dplane_ctx *ctx) if (op == DPLANE_OP_ROUTE_DELETE) break; - /* FALL THROUGH */ + fallthrough; case DPLANE_OP_ROUTE_INSTALL: - rv = netlink_route_multipath_msg_encode( - RTM_NEWROUTE, ctx, &nl_buf[nl_buf_len], - sizeof(nl_buf) - nl_buf_len, true, fnc->use_nhg); + rv = netlink_route_multipath_msg_encode(RTM_NEWROUTE, ctx, + &nl_buf[nl_buf_len], + sizeof(nl_buf) - + nl_buf_len, + true, fnc->use_nhg, + fnc->use_route_replace); if (rv <= 0) { zlog_err( "%s: netlink_route_multipath_msg_encode failed", @@ -932,7 +979,9 @@ static int fpm_nl_enqueue(struct fpm_nl_ctx *fnc, struct zebra_dplane_ctx *ctx) case DPLANE_OP_TC_FILTER_ADD: case DPLANE_OP_TC_FILTER_DELETE: case DPLANE_OP_TC_FILTER_UPDATE: + case DPLANE_OP_SRV6_ENCAP_SRCADDR_SET: case DPLANE_OP_NONE: + case DPLANE_OP_STARTUP_STAGE: break; } @@ -1326,6 +1375,18 @@ static void fpm_rmac_reset(struct event *t) &fnc->t_rmacwalk); } +static void fpm_process_wedged(struct event *t) +{ + struct fpm_nl_ctx *fnc = EVENT_ARG(t); + + zlog_warn("%s: Connection unable to write to peer for over %u seconds, resetting", + __func__, DPLANE_FPM_NL_WEDGIE_TIME); + + atomic_fetch_add_explicit(&fnc->counters.connection_errors, 1, + memory_order_relaxed); + FPM_RECONNECT(fnc); +} + static void fpm_process_queue(struct event *t) { struct fpm_nl_ctx *fnc = EVENT_ARG(t); @@ -1370,9 +1431,13 @@ static void fpm_process_queue(struct event *t) processed_contexts, memory_order_relaxed); /* Re-schedule if we ran out of buffer space */ - if (no_bufs) - event_add_timer(fnc->fthread->master, fpm_process_queue, fnc, 0, + if (no_bufs) { + event_add_event(fnc->fthread->master, fpm_process_queue, fnc, 0, &fnc->t_dequeue); + event_add_timer(fnc->fthread->master, fpm_process_wedged, fnc, + DPLANE_FPM_NL_WEDGIE_TIME, &fnc->t_wedged); + } else + EVENT_OFF(fnc->t_wedged); /* * Let the dataplane thread know if there are items in the @@ -1467,6 +1532,7 @@ static int fpm_nl_start(struct zebra_dplane_provider *prov) /* Set default values. */ fnc->use_nhg = true; + fnc->use_route_replace = true; return 0; } @@ -1575,7 +1641,7 @@ static int fpm_nl_process(struct zebra_dplane_provider *prov) if (atomic_load_explicit(&fnc->counters.ctxqueue_len, memory_order_relaxed) > 0) - event_add_timer(fnc->fthread->master, fpm_process_queue, fnc, 0, + event_add_event(fnc->fthread->master, fpm_process_queue, fnc, 0, &fnc->t_dequeue); /* Ensure dataplane thread is rescheduled if we hit the work limit */ @@ -1607,6 +1673,8 @@ static int fpm_nl_new(struct event_loop *tm) install_element(CONFIG_NODE, &no_fpm_set_address_cmd); install_element(CONFIG_NODE, &fpm_use_nhg_cmd); install_element(CONFIG_NODE, &no_fpm_use_nhg_cmd); + install_element(CONFIG_NODE, &fpm_use_route_replace_cmd); + install_element(CONFIG_NODE, &no_fpm_use_route_replace_cmd); return 0; } diff --git a/zebra/ge_netlink.c b/zebra/ge_netlink.c new file mode 100644 index 0000000000..e7d2e6b12a --- /dev/null +++ b/zebra/ge_netlink.c @@ -0,0 +1,369 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Generic Netlink functions. + * Copyright (C) 2022, Carmine Scarpitta + */ + +#include <zebra.h> + +#ifdef HAVE_NETLINK + +/* The following definition is to workaround an issue in the Linux kernel + * header files with redefinition of 'struct in6_addr' in both + * netinet/in.h and linux/in6.h. + * Reference - https://sourceware.org/ml/libc-alpha/2013-01/msg00599.html + */ +#define _LINUX_IN6_H + +#include <linux/genetlink.h> +#include <linux/rtnetlink.h> +#include <linux/seg6_genl.h> + +#include "lib/ns.h" +#include "zebra/ge_netlink.h" +#include "zebra/debug.h" +#include "zebra/kernel_netlink.h" +#include "zebra/zebra_router.h" +#include "zebra/zebra_srv6.h" + + +/** + * This file provides an implementation of the functionality exposed by the + * kernel through the Generic Netlink mechanism. + * + * Supported features include the ability to configure the source address used + * for SRv6 encapsulation ('sr tunsrc' in kernel terminology). + * + * At the time of writing this code, the kernel does not send us any asynchronous + * notifications when someone changes the 'sr tunsrc' under us. As a result, we + * are currently unable to detect when the source address changes and update the + * SRv6 encapsulation source address configured in zebra. + * + * In the future, when the kernel supports async notifications, the implementation + * can be improved by listening on the Generic Netlink socket and adding a handler + * to process/parse incoming 'sr tunsrc' change messages and update the SRv6 zebra + * configuration with the new encap source address. + */ + + +/* + * Numeric family identifier used to configure SRv6 internal parameters through Generic Netlink. + */ +static int16_t seg6_genl_family = -1; + +static int genl_parse_getfamily(struct nlmsghdr *h, ns_id_t ns_id, int startup) +{ + int len; + struct rtattr *tb[CTRL_ATTR_MAX + 1]; + struct genlmsghdr *ghdr = NLMSG_DATA(h); + struct rtattr *attrs; + const char *family; + + if (h->nlmsg_type != GENL_ID_CTRL) { + zlog_err( + "Not a controller message, nlmsg_len=%d nlmsg_type=0x%x", + h->nlmsg_len, h->nlmsg_type); + return 0; + } + + len = h->nlmsg_len - NLMSG_LENGTH(GENL_HDRLEN); + if (len < 0) { + zlog_err( + "Message received from netlink is of a broken size %d %zu", + h->nlmsg_len, (size_t)NLMSG_LENGTH(GENL_HDRLEN)); + return -1; + } + + if (ghdr->cmd != CTRL_CMD_NEWFAMILY) { + zlog_err("Unknown controller command %d", ghdr->cmd); + return -1; + } + + attrs = (struct rtattr *)((char *)ghdr + GENL_HDRLEN); + netlink_parse_rtattr(tb, CTRL_ATTR_MAX, attrs, len); + + if (tb[CTRL_ATTR_FAMILY_ID] == NULL) { + zlog_err("Missing family id TLV"); + return -1; + } + + if (tb[CTRL_ATTR_FAMILY_NAME] == NULL) { + zlog_err("Missing family name TLV"); + return -1; + } + + family = (char *)RTA_DATA(tb[CTRL_ATTR_FAMILY_NAME]); + + if (strmatch(family, "SEG6")) + seg6_genl_family = + *(int16_t *)RTA_DATA(tb[CTRL_ATTR_FAMILY_ID]); + else { + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_err("Unsupported Generic Netlink family '%s'", + family); + return -1; + } + + return 0; +} + +int genl_resolve_family(const char *family) +{ + struct zebra_ns *zns; + struct genl_request req; + + memset(&req, 0, sizeof(req)); + + zns = zebra_ns_lookup(NS_DEFAULT); + + req.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); + req.n.nlmsg_flags = NLM_F_REQUEST; + req.n.nlmsg_type = GENL_ID_CTRL; + + req.n.nlmsg_pid = zns->ge_netlink_cmd.snl.nl_pid; + + req.g.cmd = CTRL_CMD_GETFAMILY; + req.g.version = 0; + + if (!nl_attr_put(&req.n, sizeof(req), CTRL_ATTR_FAMILY_NAME, family, + strlen(family) + 1)) + return -1; + + return ge_netlink_talk(genl_parse_getfamily, &req.n, zns, false); +} + +/* + * sr tunsrc change via netlink interface, using a dataplane context object + * + * Returns -1 on failure, 0 when the msg doesn't fit entirely in the buffer + * otherwise the number of bytes written to buf. + */ +ssize_t netlink_sr_tunsrc_set_msg_encode(int cmd, struct zebra_dplane_ctx *ctx, + void *buf, size_t buflen) +{ + struct nlsock *nl; + const struct in6_addr *tunsrc_addr; + struct genl_request *req = buf; + + if (seg6_genl_family < 0) { + zlog_err( + "Failed to set SRv6 source address: kernel does not support 'SEG6' Generic Netlink family."); + return -1; + } + + tunsrc_addr = dplane_ctx_get_srv6_encap_srcaddr(ctx); + if (!tunsrc_addr) + return -1; + + if (buflen < sizeof(*req)) + return 0; + + nl = kernel_netlink_nlsock_lookup(dplane_ctx_get_ns_sock(ctx)); + + memset(req, 0, sizeof(*req)); + + req->n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); + req->n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; + + /* Prepare Netlink request to set tunsrc addr */ + req->n.nlmsg_type = seg6_genl_family; + req->n.nlmsg_pid = nl->snl.nl_pid; + + req->g.cmd = cmd; + req->g.version = SEG6_GENL_VERSION; + + switch (cmd) { + case SEG6_CMD_SET_TUNSRC: + if (!nl_attr_put(&req->n, buflen, SEG6_ATTR_DST, tunsrc_addr, + sizeof(struct in6_addr))) + return 0; + break; + default: + zlog_err("Unsupported command (%u)", cmd); + return -1; + } + + return NLMSG_ALIGN(req->n.nlmsg_len); +} + +ssize_t netlink_sr_tunsrc_set_msg_encoder(struct zebra_dplane_ctx *ctx, + void *buf, size_t buflen) +{ + enum dplane_op_e op; + int cmd = 0; + + op = dplane_ctx_get_op(ctx); + + /* Call to netlink layer based on type of operation */ + if (op == DPLANE_OP_SRV6_ENCAP_SRCADDR_SET) { + /* Validate */ + if (dplane_ctx_get_srv6_encap_srcaddr(ctx) == NULL) { + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug( + "sr tunsrc set failed: SRv6 encap source address not set"); + return -1; + } + + cmd = SEG6_CMD_SET_TUNSRC; + } else { + /* Invalid op */ + zlog_err("Context received for kernel sr tunsrc update with incorrect OP code (%u)", + op); + return -1; + } + + return netlink_sr_tunsrc_set_msg_encode(cmd, ctx, buf, buflen); +} + +enum netlink_msg_status +netlink_put_sr_tunsrc_set_msg(struct nl_batch *bth, struct zebra_dplane_ctx *ctx) +{ + enum dplane_op_e op; + struct zebra_ns *zns; + struct genl_request req; + + op = dplane_ctx_get_op(ctx); + assert(op == DPLANE_OP_SRV6_ENCAP_SRCADDR_SET); + + netlink_sr_tunsrc_set_msg_encoder(ctx, &req, sizeof(req)); + + zns = zebra_ns_lookup(dplane_ctx_get_ns_sock(ctx)); + + return ge_netlink_talk(netlink_talk_filter, &req.n, zns, false); +} + +/** + * netlink_sr_tunsrc_reply_read() - Read in SR tunsrc reply from the kernel + * + * @h: Netlink message header + * @ns_id: Namspace id + * @startup: Are we reading under startup conditions? + * + * Return: Result status + */ +int netlink_sr_tunsrc_reply_read(struct nlmsghdr *h, ns_id_t ns_id, int startup) +{ + int len; + struct genlmsghdr *ghdr; + struct rtattr *tb[SEG6_ATTR_MAX + 1] = {}; + struct rtattr *attrs; + + if (h->nlmsg_type != seg6_genl_family) + return 0; + + len = h->nlmsg_len - NLMSG_LENGTH(GENL_HDRLEN); + if (len < 0) { + zlog_warn("%s: Message received from netlink is of a broken size %d %zu", + __func__, h->nlmsg_len, + (size_t)NLMSG_LENGTH(GENL_HDRLEN)); + return -1; + } + + ghdr = NLMSG_DATA(h); + + if (ghdr->cmd != SEG6_CMD_GET_TUNSRC) + return 0; + + attrs = (struct rtattr *)((char *)ghdr + GENL_HDRLEN); + netlink_parse_rtattr(tb, SEG6_ATTR_MAX, attrs, len); + + if (tb[SEG6_ATTR_DST] == NULL) { + zlog_err("Missing tunsrc addr"); + return -1; + } + + zebra_srv6_encap_src_addr_set( + (struct in6_addr *)RTA_DATA(tb[SEG6_ATTR_DST])); + + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug("%s: SRv6 encap source address received from kernel: '%pI6'", + __func__, + (struct in6_addr *)RTA_DATA(tb[SEG6_ATTR_DST])); + + return 0; +} + +/** + * netlink_request_sr_tunsrc() - Request SR tunsrc from the kernel + * @zns: Zebra namespace + * + * Return: Result status + */ +static int netlink_request_sr_tunsrc(struct zebra_ns *zns) +{ + struct genl_request req; + + if (zns->ge_netlink_cmd.sock < 0) + return -1; + + if (seg6_genl_family < 0) { + zlog_err( + "Failed to get SRv6 encap source address: kernel does not support 'SEG6' Generic Netlink family."); + return -1; + } + + /* Form the request, specifying filter (rtattr) if needed. */ + memset(&req, 0, sizeof(req)); + req.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN); + req.n.nlmsg_flags = NLM_F_REQUEST; + req.n.nlmsg_type = seg6_genl_family; + req.g.cmd = SEG6_CMD_GET_TUNSRC; + req.g.version = SEG6_GENL_VERSION; + + return netlink_request(&zns->ge_netlink_cmd, &req); +} + +/** + * SR tunsrc read function using netlink interface. Only called + * on bootstrap time. + */ +int netlink_sr_tunsrc_read(struct zebra_ns *zns) +{ + int ret; + struct zebra_dplane_info dp_info; + + if (zns->ge_netlink_cmd.sock < 0) + return -1; + + /* Capture info in intermediate info struct */ + dp_info.ns_id = zns->ns_id; + dp_info.is_cmd = true; + dp_info.sock = zns->ge_netlink_cmd.sock; + dp_info.seq = zns->ge_netlink_cmd.seq; + + /* Get SR tunsrc. */ + ret = netlink_request_sr_tunsrc(zns); + if (ret < 0) + return ret; + ret = netlink_parse_info(netlink_sr_tunsrc_reply_read, + &zns->ge_netlink_cmd, &dp_info, 0, true); + if (ret < 0) + return ret; + + return 0; +} + +void ge_netlink_init(struct zebra_ns *zns) +{ + if (zns->ge_netlink_cmd.sock < 0) + return; + + /* + * Resolves the 'seg6' Generic Netlink family name to the corresponding numeric family identifier. + * This will give us the numeric family identifier required to send 'seg6' commands to the kernel + * over the Generic Netlink socket. 'seg6' commands are used to configure SRv6 internal parameters + * such as the address to use as source for encapsulated packets. + */ + if (genl_resolve_family("SEG6")) + zlog_warn( + "Kernel does not support 'SEG6' Generic Netlink family. Any attempt to set the encapsulation parameters under the SRv6 configuration will fail"); + + /** + * Retrieve the actual SRv6 encap source address from the kernel + * (default namespace) and save it to zebra SRv6 config + */ + if (zns->ns_id == NS_DEFAULT) + netlink_sr_tunsrc_read(zns); +} + +#endif /* HAVE_NETLINK */ diff --git a/zebra/ge_netlink.h b/zebra/ge_netlink.h new file mode 100644 index 0000000000..20d09116c0 --- /dev/null +++ b/zebra/ge_netlink.h @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Header file exported by ge_netlink.c to zebra. + * Copyright (C) 2022, Carmine Scarpitta + */ + +#ifndef _ZEBRA_GE_NETLINK_H +#define _ZEBRA_GE_NETLINK_H + +#include "zebra_dplane.h" + +#ifdef HAVE_NETLINK + +#include <linux/genetlink.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* Generic Netlink request message */ +struct genl_request { + struct nlmsghdr n; + struct genlmsghdr g; + char buf[1024]; +}; + +extern int genl_resolve_family(const char *family); +extern ssize_t netlink_sr_tunsrc_set_msg_encode(int cmd, + struct zebra_dplane_ctx *ctx, + void *buf, size_t buflen); +extern ssize_t netlink_sr_tunsrc_set_msg_encoder(struct zebra_dplane_ctx *ctx, + void *buf, size_t buflen); +struct nl_batch; +extern enum netlink_msg_status +netlink_put_sr_tunsrc_set_msg(struct nl_batch *bth, + struct zebra_dplane_ctx *ctx); + +int netlink_sr_tunsrc_reply_read(struct nlmsghdr *h, ns_id_t ns_id, int startup); +int netlink_sr_tunsrc_read(struct zebra_ns *zns); + +extern void ge_netlink_init(struct zebra_ns *zns); + +#ifdef __cplusplus +} +#endif + +#endif /* HAVE_NETLINK */ + +#endif /* _ZEBRA_GE_NETLINK_H */ diff --git a/zebra/if_ioctl.c b/zebra/if_ioctl.c index b3cf865122..d0aa2167fe 100644 --- a/zebra/if_ioctl.c +++ b/zebra/if_ioctl.c @@ -5,6 +5,7 @@ */ #include <zebra.h> +#include <sys/ioctl.h> #ifdef OPEN_BSD diff --git a/zebra/if_netlink.c b/zebra/if_netlink.c index fcb692b715..551ef6533e 100644 --- a/zebra/if_netlink.c +++ b/zebra/if_netlink.c @@ -17,6 +17,8 @@ #define _LINUX_IF_H #define _LINUX_IP_H +#include <linux/netlink.h> +#include <linux/rtnetlink.h> #include <netinet/if_ether.h> #include <linux/if_bridge.h> #include <linux/if_link.h> @@ -63,66 +65,22 @@ #include "zebra/zebra_trace.h" extern struct zebra_privs_t zserv_privs; -uint8_t frr_protodown_r_bit = FRR_PROTODOWN_REASON_DEFAULT_BIT; - -/* Note: on netlink systems, there should be a 1-to-1 mapping between interface - names and ifindex values. */ -static void set_ifindex(struct interface *ifp, ifindex_t ifi_index, - struct zebra_ns *zns) -{ - struct interface *oifp; - - if (((oifp = if_lookup_by_index_per_ns(zns, ifi_index)) != NULL) - && (oifp != ifp)) { - if (ifi_index == IFINDEX_INTERNAL) - flog_err( - EC_LIB_INTERFACE, - "Netlink is setting interface %s ifindex to reserved internal value %u", - ifp->name, ifi_index); - else { - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug( - "interface index %d was renamed from %s to %s", - ifi_index, oifp->name, ifp->name); - if (if_is_up(oifp)) - flog_err( - EC_LIB_INTERFACE, - "interface rename detected on up interface: index %d was renamed from %s to %s, results are uncertain!", - ifi_index, oifp->name, ifp->name); - if_delete_update(&oifp); - } - } - if_set_index(ifp, ifi_index); -} /* Utility function to parse hardware link-layer address and update ifp */ static void netlink_interface_update_hw_addr(struct rtattr **tb, - struct interface *ifp) + struct zebra_dplane_ctx *ctx) { - int i; - if (tb[IFLA_ADDRESS]) { int hw_addr_len; hw_addr_len = RTA_PAYLOAD(tb[IFLA_ADDRESS]); if (hw_addr_len > INTERFACE_HWADDR_MAX) - zlog_debug("Hardware address is too large: %d", - hw_addr_len); - else { - ifp->hw_addr_len = hw_addr_len; - memcpy(ifp->hw_addr, RTA_DATA(tb[IFLA_ADDRESS]), - hw_addr_len); - - for (i = 0; i < hw_addr_len; i++) - if (ifp->hw_addr[i] != 0) - break; - - if (i == hw_addr_len) - ifp->hw_addr_len = 0; - else - ifp->hw_addr_len = hw_addr_len; - } + zlog_warn("Hardware address is too large: %d", + hw_addr_len); + else + dplane_ctx_set_ifp_hw_addr(ctx, hw_addr_len, + RTA_DATA(tb[IFLA_ADDRESS])); } } @@ -237,26 +195,6 @@ static enum zebra_link_type netlink_to_zebra_link_type(unsigned int hwt) } } -static inline void zebra_if_set_ziftype(struct interface *ifp, - enum zebra_iftype zif_type, - enum zebra_slave_iftype zif_slave_type) -{ - struct zebra_if *zif; - - zif = (struct zebra_if *)ifp->info; - zif->zif_slave_type = zif_slave_type; - - if (zif->zif_type != zif_type) { - zif->zif_type = zif_type; - /* If the if_type has been set to bond initialize ES info - * against it. XXX - note that we don't handle the case where - * a zif changes from bond to non-bond; it is really - * an unexpected/error condition. - */ - zebra_evpn_if_init(zif); - } -} - static void netlink_determine_zebra_iftype(const char *kind, enum zebra_iftype *zif_type) { @@ -279,23 +217,18 @@ static void netlink_determine_zebra_iftype(const char *kind, *zif_type = ZEBRA_IF_VETH; else if (strcmp(kind, "bond") == 0) *zif_type = ZEBRA_IF_BOND; - else if (strcmp(kind, "bond_slave") == 0) - *zif_type = ZEBRA_IF_BOND_SLAVE; + else if (strcmp(kind, "team") == 0) + *zif_type = ZEBRA_IF_BOND; else if (strcmp(kind, "gre") == 0) *zif_type = ZEBRA_IF_GRE; } static void netlink_vrf_change(struct nlmsghdr *h, struct rtattr *tb, - uint32_t ns_id, const char *name) + uint32_t ns_id, const char *name, + struct zebra_dplane_ctx *ctx) { - struct ifinfomsg *ifi; struct rtattr *linkinfo[IFLA_INFO_MAX + 1]; struct rtattr *attr[IFLA_VRF_MAX + 1]; - struct vrf *vrf = NULL; - struct zebra_vrf *zvrf; - uint32_t nl_table_id; - - ifi = NLMSG_DATA(h); netlink_parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb); @@ -317,74 +250,8 @@ static void netlink_vrf_change(struct nlmsghdr *h, struct rtattr *tb, return; } - nl_table_id = *(uint32_t *)RTA_DATA(attr[IFLA_VRF_TABLE]); - - if (h->nlmsg_type == RTM_NEWLINK) { - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("RTM_NEWLINK for VRF %s(%u) table %u", name, - ifi->ifi_index, nl_table_id); - - if (!vrf_lookup_by_id((vrf_id_t)ifi->ifi_index)) { - vrf_id_t exist_id; - - exist_id = vrf_lookup_by_table(nl_table_id, ns_id); - if (exist_id != VRF_DEFAULT) { - vrf = vrf_lookup_by_id(exist_id); - - flog_err( - EC_ZEBRA_VRF_MISCONFIGURED, - "VRF %s id %u table id overlaps existing vrf %s, misconfiguration exiting", - name, ifi->ifi_index, vrf->name); - exit(-1); - } - } - - vrf = vrf_update((vrf_id_t)ifi->ifi_index, name); - if (!vrf) { - flog_err(EC_LIB_INTERFACE, "VRF %s id %u not created", - name, ifi->ifi_index); - return; - } - - /* - * This is the only place that we get the actual kernel table_id - * being used. We need it to set the table_id of the routes - * we are passing to the kernel.... And to throw some totally - * awesome parties. that too. - * - * At this point we *must* have a zvrf because the vrf_create - * callback creates one. We *must* set the table id - * before the vrf_enable because of( at the very least ) - * static routes being delayed for installation until - * during the vrf_enable callbacks. - */ - zvrf = (struct zebra_vrf *)vrf->info; - zvrf->table_id = nl_table_id; - - /* Enable the created VRF. */ - if (!vrf_enable(vrf)) { - flog_err(EC_LIB_INTERFACE, - "Failed to enable VRF %s id %u", name, - ifi->ifi_index); - return; - } - - } else // h->nlmsg_type == RTM_DELLINK - { - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("RTM_DELLINK for VRF %s(%u)", name, - ifi->ifi_index); - - vrf = vrf_lookup_by_id((vrf_id_t)ifi->ifi_index); - - if (!vrf) { - flog_warn(EC_ZEBRA_VRF_NOT_FOUND, "%s: vrf not found", - __func__); - return; - } - - vrf_delete(vrf); - } + dplane_ctx_set_ifp_table_id( + ctx, *(uint32_t *)RTA_DATA(attr[IFLA_VRF_TABLE])); } static uint32_t get_iflink_speed(struct interface *interface, int *error) @@ -665,62 +532,59 @@ static int netlink_extract_vxlan_info(struct rtattr *link_data, * bridge interface is added or updated, take further actions to map * its members. Likewise, for VxLAN interface. */ -static void netlink_interface_update_l2info(struct interface *ifp, +static void netlink_interface_update_l2info(struct zebra_dplane_ctx *ctx, + enum zebra_iftype zif_type, struct rtattr *link_data, int add, ns_id_t link_nsid) { + struct zebra_l2info_bridge bridge_info; + struct zebra_l2info_vlan vlan_info; + struct zebra_l2info_vxlan vxlan_info; + struct zebra_l2info_gre gre_info; + if (!link_data) return; - if (IS_ZEBRA_IF_BRIDGE(ifp)) { - struct zebra_l2info_bridge bridge_info; - + switch (zif_type) { + case ZEBRA_IF_BRIDGE: netlink_extract_bridge_info(link_data, &bridge_info); - zebra_l2_bridge_add_update(ifp, &bridge_info, add); - } else if (IS_ZEBRA_IF_VLAN(ifp)) { - struct zebra_l2info_vlan vlan_info; - + dplane_ctx_set_ifp_bridge_info(ctx, &bridge_info); + break; + case ZEBRA_IF_VLAN: netlink_extract_vlan_info(link_data, &vlan_info); - zebra_l2_vlanif_update(ifp, &vlan_info); - zebra_evpn_acc_bd_svi_set(ifp->info, NULL, - !!if_is_operative(ifp)); - } else if (IS_ZEBRA_IF_VXLAN(ifp)) { - struct zebra_l2info_vxlan vxlan_info; - + dplane_ctx_set_ifp_vlan_info(ctx, &vlan_info); + break; + case ZEBRA_IF_VXLAN: netlink_extract_vxlan_info(link_data, &vxlan_info); vxlan_info.link_nsid = link_nsid; - zebra_l2_vxlanif_add_update(ifp, &vxlan_info, add); - if (link_nsid != NS_UNKNOWN && - vxlan_info.ifindex_link) - zebra_if_update_link(ifp, vxlan_info.ifindex_link, - link_nsid); - } else if (IS_ZEBRA_IF_GRE(ifp)) { - struct zebra_l2info_gre gre_info; - + dplane_ctx_set_ifp_vxlan_info(ctx, &vxlan_info); + break; + case ZEBRA_IF_GRE: netlink_extract_gre_info(link_data, &gre_info); gre_info.link_nsid = link_nsid; - zebra_l2_greif_add_update(ifp, &gre_info, add); - if (link_nsid != NS_UNKNOWN && - gre_info.ifindex_link) - zebra_if_update_link(ifp, gre_info.ifindex_link, - link_nsid); + dplane_ctx_set_ifp_gre_info(ctx, &gre_info); + break; + case ZEBRA_IF_OTHER: + case ZEBRA_IF_VRF: + case ZEBRA_IF_MACVLAN: + case ZEBRA_IF_VETH: + case ZEBRA_IF_BOND: + break; } } -static int netlink_bridge_vxlan_vlan_vni_map_update(struct interface *ifp, - struct rtattr *af_spec) +static int +netlink_bridge_vxlan_vlan_vni_map_update(struct zebra_dplane_ctx *ctx, + struct rtattr *af_spec) { int rem; - vni_t vni_id; - vlanid_t vid; uint16_t flags; struct rtattr *i; - struct zebra_vxlan_vni vni; - struct zebra_vxlan_vni *vnip; - struct hash *vni_table = NULL; + struct zebra_vxlan_vni_array *vniarray = NULL; struct zebra_vxlan_vni vni_end; struct zebra_vxlan_vni vni_start; struct rtattr *aftb[IFLA_BRIDGE_VLAN_TUNNEL_MAX + 1]; + int32_t count = 0; memset(&vni_start, 0, sizeof(vni_start)); memset(&vni_end, 0, sizeof(vni_end)); @@ -739,204 +603,126 @@ static int netlink_bridge_vxlan_vlan_vni_map_update(struct interface *ifp, /* vlan-vni info missing */ return 0; + count++; flags = 0; - memset(&vni, 0, sizeof(vni)); + vniarray = XREALLOC( + MTYPE_TMP, vniarray, + sizeof(struct zebra_vxlan_vni_array) + + count * sizeof(struct zebra_vxlan_vni)); + + memset(&vniarray->vnis[count - 1], 0, + sizeof(struct zebra_vxlan_vni)); - vni.vni = *(vni_t *)RTA_DATA(aftb[IFLA_BRIDGE_VLAN_TUNNEL_ID]); - vni.access_vlan = *(vlanid_t *)RTA_DATA( + vniarray->vnis[count - 1].vni = + *(vni_t *)RTA_DATA(aftb[IFLA_BRIDGE_VLAN_TUNNEL_ID]); + vniarray->vnis[count - 1].access_vlan = *(vlanid_t *)RTA_DATA( aftb[IFLA_BRIDGE_VLAN_TUNNEL_VID]); if (aftb[IFLA_BRIDGE_VLAN_TUNNEL_FLAGS]) flags = *(uint16_t *)RTA_DATA( aftb[IFLA_BRIDGE_VLAN_TUNNEL_FLAGS]); - if (flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) { - vni_start = vni; - continue; - } - - if (flags & BRIDGE_VLAN_INFO_RANGE_END) - vni_end = vni; - - if (!(flags & BRIDGE_VLAN_INFO_RANGE_END)) { - vni_start = vni; - vni_end = vni; - } - - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug( - "Vlan-Vni(%d:%d-%d:%d) update for VxLAN IF %s(%u)", - vni_start.access_vlan, vni_end.access_vlan, - vni_start.vni, vni_end.vni, ifp->name, - ifp->ifindex); - - if (!vni_table) { - vni_table = zebra_vxlan_vni_table_create(); - if (!vni_table) - return 0; - } - - for (vid = vni_start.access_vlan, vni_id = vni_start.vni; - vid <= vni_end.access_vlan; vid++, vni_id++) { - - memset(&vni, 0, sizeof(vni)); - vni.vni = vni_id; - vni.access_vlan = vid; - vnip = hash_get(vni_table, &vni, zebra_vxlan_vni_alloc); - if (!vnip) - return 0; - } - - memset(&vni_start, 0, sizeof(vni_start)); - memset(&vni_end, 0, sizeof(vni_end)); + vniarray->vnis[count - 1].flags = flags; } - if (vni_table) - zebra_vxlan_if_vni_table_add_update(ifp, vni_table); - + if (count) { + vniarray->count = count; + dplane_ctx_set_ifp_vxlan_vni_array(ctx, vniarray); + } return 0; } -static int netlink_bridge_vxlan_update(struct interface *ifp, - struct rtattr *af_spec) +static int netlink_bridge_vxlan_update(struct zebra_dplane_ctx *ctx, + struct rtattr *af_spec) { struct rtattr *aftb[IFLA_BRIDGE_MAX + 1]; struct bridge_vlan_info *vinfo; - struct zebra_if *zif; - vlanid_t access_vlan; + struct zebra_dplane_bridge_vlan_info bvinfo; - if (!af_spec) + if (!af_spec) { + dplane_ctx_set_ifp_no_afspec(ctx); return 0; + } - zif = (struct zebra_if *)ifp->info; - - /* Single vxlan devices has vni-vlan range to update */ - if (IS_ZEBRA_VXLAN_IF_SVD(zif)) - return netlink_bridge_vxlan_vlan_vni_map_update(ifp, af_spec); + netlink_bridge_vxlan_vlan_vni_map_update(ctx, af_spec); /* There is a 1-to-1 mapping of VLAN to VxLAN - hence * only 1 access VLAN is accepted. */ netlink_parse_rtattr_nested(aftb, IFLA_BRIDGE_MAX, af_spec); - if (!aftb[IFLA_BRIDGE_VLAN_INFO]) + if (!aftb[IFLA_BRIDGE_VLAN_INFO]) { + dplane_ctx_set_ifp_no_bridge_vlan_info(ctx); return 0; + } vinfo = RTA_DATA(aftb[IFLA_BRIDGE_VLAN_INFO]); - if (!(vinfo->flags & BRIDGE_VLAN_INFO_PVID)) - return 0; + bvinfo.flags = vinfo->flags; + bvinfo.vid = vinfo->vid; - access_vlan = (vlanid_t)vinfo->vid; - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("Access VLAN %u for VxLAN IF %s(%u)", access_vlan, - ifp->name, ifp->ifindex); - zebra_l2_vxlanif_update_access_vlan(ifp, access_vlan); + dplane_ctx_set_ifp_bridge_vlan_info(ctx, &bvinfo); return 0; } -static void netlink_bridge_vlan_update(struct interface *ifp, - struct rtattr *af_spec) +static void netlink_bridge_vlan_update(struct zebra_dplane_ctx *ctx, + struct rtattr *af_spec) { struct rtattr *i; int rem; - uint16_t vid_range_start = 0; - struct zebra_if *zif; - bitfield_t old_vlan_bitmap; struct bridge_vlan_info *vinfo; - - zif = (struct zebra_if *)ifp->info; - - /* cache the old bitmap addrs */ - old_vlan_bitmap = zif->vlan_bitmap; - /* create a new bitmap space for re-eval */ - bf_init(zif->vlan_bitmap, IF_VLAN_BITMAP_MAX); + struct zebra_dplane_bridge_vlan_info_array *bvarray = NULL; + int32_t count = 0; if (af_spec) { for (i = RTA_DATA(af_spec), rem = RTA_PAYLOAD(af_spec); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) { - if (i->rta_type != IFLA_BRIDGE_VLAN_INFO) continue; - vinfo = RTA_DATA(i); - - if (vinfo->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) { - vid_range_start = vinfo->vid; - continue; - } - - if (!(vinfo->flags & BRIDGE_VLAN_INFO_RANGE_END)) - vid_range_start = vinfo->vid; + count++; + bvarray = XREALLOC( + MTYPE_TMP, bvarray, + sizeof(struct + zebra_dplane_bridge_vlan_info_array) + + count * sizeof(struct + zebra_dplane_bridge_vlan_info)); - zebra_vlan_bitmap_compute(ifp, vid_range_start, - vinfo->vid); + vinfo = RTA_DATA(i); + bvarray->array[count - 1].flags = vinfo->flags; + bvarray->array[count - 1].vid = vinfo->vid; } } - zebra_vlan_mbr_re_eval(ifp, old_vlan_bitmap); - - bf_free(old_vlan_bitmap); + if (count) { + bvarray->count = count; + dplane_ctx_set_ifp_bridge_vlan_info_array(ctx, bvarray); + } } -static int netlink_bridge_interface(struct nlmsghdr *h, int len, ns_id_t ns_id, - int startup) +static int netlink_bridge_interface(struct zebra_dplane_ctx *ctx, + struct rtattr *af_spec, int startup) { - char *name = NULL; - struct ifinfomsg *ifi; - struct rtattr *tb[IFLA_MAX + 1]; - struct interface *ifp; - struct zebra_if *zif; - struct rtattr *af_spec; - - /* Fetch name and ifindex */ - ifi = NLMSG_DATA(h); - netlink_parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len); - - if (tb[IFLA_IFNAME] == NULL) - return -1; - name = (char *)RTA_DATA(tb[IFLA_IFNAME]); - - /* The interface should already be known, if not discard. */ - ifp = if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id), ifi->ifi_index); - if (!ifp) { - zlog_debug("Cannot find bridge IF %s(%u)", name, - ifi->ifi_index); - return 0; - } - - /* We are only interested in the access VLAN i.e., AF_SPEC */ - af_spec = tb[IFLA_AF_SPEC]; - if (IS_ZEBRA_IF_VXLAN(ifp)) - return netlink_bridge_vxlan_update(ifp, af_spec); + netlink_bridge_vxlan_update(ctx, af_spec); /* build vlan bitmap associated with this interface if that * device type is interested in the vlans */ - zif = (struct zebra_if *)ifp->info; - if (bf_is_inited(zif->vlan_bitmap)) - netlink_bridge_vlan_update(ifp, af_spec); + netlink_bridge_vlan_update(ctx, af_spec); + dplane_provider_enqueue_to_zebra(ctx); return 0; } -static bool is_if_protodown_reason_only_frr(uint32_t rc_bitfield) -{ - /* This shouldn't be possible */ - assert(frr_protodown_r_bit < 32); - return (rc_bitfield == (((uint32_t)1) << frr_protodown_r_bit)); -} - /* * Process interface protodown dplane update. * * If the interface is an es bond member then it must follow EVPN's * protodown setting. */ -static void netlink_proc_dplane_if_protodown(struct zebra_if *zif, +static void netlink_proc_dplane_if_protodown(struct zebra_dplane_ctx *ctx, struct rtattr **tb) { bool protodown; - bool old_protodown; uint32_t rc_bitfield = 0; struct rtattr *pd_reason_info[IFLA_MAX + 1]; @@ -951,59 +737,9 @@ static void netlink_proc_dplane_if_protodown(struct zebra_if *zif, pd_reason_info[IFLA_PROTO_DOWN_REASON_VALUE]); } - /* - * Set our reason code to note it wasn't us. - * If the reason we got from the kernel is ONLY frr though, don't - * set it. - */ - COND_FLAG(zif->protodown_rc, ZEBRA_PROTODOWN_EXTERNAL, - protodown && rc_bitfield && - !is_if_protodown_reason_only_frr(rc_bitfield)); - - - old_protodown = !!ZEBRA_IF_IS_PROTODOWN(zif); - if (protodown == old_protodown) - return; - - if (IS_ZEBRA_DEBUG_EVPN_MH_ES || IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("interface %s dplane change, protdown %s", - zif->ifp->name, protodown ? "on" : "off"); - - /* Set protodown, respectively */ - COND_FLAG(zif->flags, ZIF_FLAG_PROTODOWN, protodown); - - if (zebra_evpn_is_es_bond_member(zif->ifp)) { - /* Check it's not already being sent to the dplane first */ - if (protodown && - CHECK_FLAG(zif->flags, ZIF_FLAG_SET_PROTODOWN)) { - if (IS_ZEBRA_DEBUG_EVPN_MH_ES || IS_ZEBRA_DEBUG_KERNEL) - zlog_debug( - "bond mbr %s protodown on recv'd but already sent protodown on to the dplane", - zif->ifp->name); - return; - } - - if (!protodown && - CHECK_FLAG(zif->flags, ZIF_FLAG_UNSET_PROTODOWN)) { - if (IS_ZEBRA_DEBUG_EVPN_MH_ES || IS_ZEBRA_DEBUG_KERNEL) - zlog_debug( - "bond mbr %s protodown off recv'd but already sent protodown off to the dplane", - zif->ifp->name); - return; - } - - if (IS_ZEBRA_DEBUG_EVPN_MH_ES || IS_ZEBRA_DEBUG_KERNEL) - zlog_debug( - "bond mbr %s reinstate protodown %s in the dplane", - zif->ifp->name, old_protodown ? "on" : "off"); - - if (old_protodown) - SET_FLAG(zif->flags, ZIF_FLAG_SET_PROTODOWN); - else - SET_FLAG(zif->flags, ZIF_FLAG_UNSET_PROTODOWN); - - dplane_intf_update(zif->ifp); - } + dplane_ctx_set_ifp_rc_bitfield(ctx, rc_bitfield); + dplane_ctx_set_ifp_protodown(ctx, protodown); + dplane_ctx_set_ifp_protodown_set(ctx, true); } static uint8_t netlink_parse_lacp_bypass(struct rtattr **linkinfo) @@ -1020,201 +756,6 @@ static uint8_t netlink_parse_lacp_bypass(struct rtattr **linkinfo) return bypass; } -/* - * Only called at startup to cleanup leftover protodown reasons we may - * have not cleaned up. We leave protodown set though. - */ -static void if_sweep_protodown(struct zebra_if *zif) -{ - bool protodown; - - protodown = !!ZEBRA_IF_IS_PROTODOWN(zif); - - if (!protodown) - return; - - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("interface %s sweeping protodown %s reason 0x%x", - zif->ifp->name, protodown ? "on" : "off", - zif->protodown_rc); - - /* Only clear our reason codes, leave external if it was set */ - UNSET_FLAG(zif->protodown_rc, ZEBRA_PROTODOWN_ALL); - dplane_intf_update(zif->ifp); -} - -/* - * Called from interface_lookup_netlink(). This function is only used - * during bootstrap. - */ -static int netlink_interface(struct nlmsghdr *h, ns_id_t ns_id, int startup) -{ - int len; - struct ifinfomsg *ifi; - struct rtattr *tb[IFLA_MAX + 1]; - struct rtattr *linkinfo[IFLA_MAX + 1]; - struct interface *ifp; - char *name = NULL; - char *kind = NULL; - char *desc = NULL; - char *slave_kind = NULL; - struct zebra_ns *zns = NULL; - vrf_id_t vrf_id = VRF_DEFAULT; - enum zebra_iftype zif_type = ZEBRA_IF_OTHER; - enum zebra_slave_iftype zif_slave_type = ZEBRA_IF_SLAVE_NONE; - ifindex_t bridge_ifindex = IFINDEX_INTERNAL; - ifindex_t link_ifindex = IFINDEX_INTERNAL; - ifindex_t bond_ifindex = IFINDEX_INTERNAL; - struct zebra_if *zif; - ns_id_t link_nsid = ns_id; - uint8_t bypass = 0; - - frrtrace(3, frr_zebra, netlink_interface, h, ns_id, startup); - - zns = zebra_ns_lookup(ns_id); - ifi = NLMSG_DATA(h); - - if (h->nlmsg_type != RTM_NEWLINK) - return 0; - - len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifinfomsg)); - if (len < 0) { - zlog_err( - "%s: Message received from netlink is of a broken size: %d %zu", - __func__, h->nlmsg_len, - (size_t)NLMSG_LENGTH(sizeof(struct ifinfomsg))); - return -1; - } - - /* We are interested in some AF_BRIDGE notifications. */ - if (ifi->ifi_family == AF_BRIDGE) - return netlink_bridge_interface(h, len, ns_id, startup); - - /* Looking up interface name. */ - memset(linkinfo, 0, sizeof(linkinfo)); - netlink_parse_rtattr_flags(tb, IFLA_MAX, IFLA_RTA(ifi), len, - NLA_F_NESTED); - - /* check for wireless messages to ignore */ - if ((tb[IFLA_WIRELESS] != NULL) && (ifi->ifi_change == 0)) { - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("%s: ignoring IFLA_WIRELESS message", - __func__); - return 0; - } - - if (tb[IFLA_IFNAME] == NULL) - return -1; - name = (char *)RTA_DATA(tb[IFLA_IFNAME]); - - if (tb[IFLA_IFALIAS]) - desc = (char *)RTA_DATA(tb[IFLA_IFALIAS]); - - if (tb[IFLA_LINKINFO]) { - netlink_parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, - tb[IFLA_LINKINFO]); - - if (linkinfo[IFLA_INFO_KIND]) - kind = RTA_DATA(linkinfo[IFLA_INFO_KIND]); - - if (linkinfo[IFLA_INFO_SLAVE_KIND]) - slave_kind = RTA_DATA(linkinfo[IFLA_INFO_SLAVE_KIND]); - - if ((slave_kind != NULL) && strcmp(slave_kind, "bond") == 0) - netlink_determine_zebra_iftype("bond_slave", &zif_type); - else - netlink_determine_zebra_iftype(kind, &zif_type); - } - - /* If VRF, create the VRF structure itself. */ - if (zif_type == ZEBRA_IF_VRF && !vrf_is_backend_netns()) { - netlink_vrf_change(h, tb[IFLA_LINKINFO], ns_id, name); - vrf_id = (vrf_id_t)ifi->ifi_index; - } - - if (tb[IFLA_MASTER]) { - if (slave_kind && (strcmp(slave_kind, "vrf") == 0) - && !vrf_is_backend_netns()) { - zif_slave_type = ZEBRA_IF_SLAVE_VRF; - vrf_id = *(uint32_t *)RTA_DATA(tb[IFLA_MASTER]); - } else if (slave_kind && (strcmp(slave_kind, "bridge") == 0)) { - zif_slave_type = ZEBRA_IF_SLAVE_BRIDGE; - bridge_ifindex = - *(ifindex_t *)RTA_DATA(tb[IFLA_MASTER]); - } else if (slave_kind && (strcmp(slave_kind, "bond") == 0)) { - zif_slave_type = ZEBRA_IF_SLAVE_BOND; - bond_ifindex = *(ifindex_t *)RTA_DATA(tb[IFLA_MASTER]); - bypass = netlink_parse_lacp_bypass(linkinfo); - } else - zif_slave_type = ZEBRA_IF_SLAVE_OTHER; - } - if (vrf_is_backend_netns()) - vrf_id = (vrf_id_t)ns_id; - - /* If linking to another interface, note it. */ - if (tb[IFLA_LINK]) - link_ifindex = *(ifindex_t *)RTA_DATA(tb[IFLA_LINK]); - - if (tb[IFLA_LINK_NETNSID]) { - link_nsid = *(ns_id_t *)RTA_DATA(tb[IFLA_LINK_NETNSID]); - link_nsid = ns_id_get_absolute(ns_id, link_nsid); - } - - ifp = if_get_by_name(name, vrf_id, NULL); - set_ifindex(ifp, ifi->ifi_index, zns); /* add it to ns struct */ - - ifp->flags = ifi->ifi_flags & 0x0000fffff; - ifp->mtu6 = ifp->mtu = *(uint32_t *)RTA_DATA(tb[IFLA_MTU]); - ifp->metric = 0; - ifp->speed = get_iflink_speed(ifp, NULL); - ifp->ptm_status = ZEBRA_PTM_STATUS_UNKNOWN; - - /* Set zebra interface type */ - zebra_if_set_ziftype(ifp, zif_type, zif_slave_type); - if (IS_ZEBRA_IF_VRF(ifp)) - SET_FLAG(ifp->status, ZEBRA_INTERFACE_VRF_LOOPBACK); - - /* - * Just set the @link/lower-device ifindex. During nldump interfaces are - * not ordered in any fashion so we may end up getting upper devices - * before lower devices. We will setup the real linkage once the dump - * is complete. - */ - zif = (struct zebra_if *)ifp->info; - zif->link_ifindex = link_ifindex; - - if (desc) { - XFREE(MTYPE_ZIF_DESC, zif->desc); - zif->desc = XSTRDUP(MTYPE_ZIF_DESC, desc); - } - - /* Hardware type and address. */ - ifp->ll_type = netlink_to_zebra_link_type(ifi->ifi_type); - - netlink_interface_update_hw_addr(tb, ifp); - - if_add_update(ifp); - - /* Extract and save L2 interface information, take additional actions. - */ - netlink_interface_update_l2info(ifp, linkinfo[IFLA_INFO_DATA], - 1, link_nsid); - if (IS_ZEBRA_IF_BOND(ifp)) - zebra_l2if_update_bond(ifp, true); - if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp)) - zebra_l2if_update_bridge_slave(ifp, bridge_ifindex, ns_id, - ZEBRA_BRIDGE_NO_ACTION); - else if (IS_ZEBRA_IF_BOND_SLAVE(ifp)) - zebra_l2if_update_bond_slave(ifp, bond_ifindex, !!bypass); - - if (tb[IFLA_PROTO_DOWN]) { - netlink_proc_dplane_if_protodown(zif, tb); - if_sweep_protodown(zif); - } - - return 0; -} - /* Request for specific interface or address information from the kernel */ static int netlink_request_intf_addr(struct nlsock *netlink_cmd, int family, int type, uint32_t filter_mask) @@ -1261,7 +802,7 @@ int interface_lookup_netlink(struct zebra_ns *zns) { int ret; struct zebra_dplane_info dp_info; - struct nlsock *netlink_cmd = &zns->netlink_cmd; + struct nlsock *netlink_cmd = &zns->netlink_dplane_out; /* Capture key info from ns struct */ zebra_dplane_info_from_zns(&dp_info, zns, true /*is_cmd*/); @@ -1270,7 +811,7 @@ int interface_lookup_netlink(struct zebra_ns *zns) ret = netlink_request_intf_addr(netlink_cmd, AF_PACKET, RTM_GETLINK, 0); if (ret < 0) return ret; - ret = netlink_parse_info(netlink_interface, netlink_cmd, &dp_info, 0, + ret = netlink_parse_info(netlink_link_change, netlink_cmd, &dp_info, 0, true); if (ret < 0) return ret; @@ -1280,11 +821,18 @@ int interface_lookup_netlink(struct zebra_ns *zns) RTEXT_FILTER_BRVLAN); if (ret < 0) return ret; - ret = netlink_parse_info(netlink_interface, netlink_cmd, &dp_info, 0, + ret = netlink_parse_info(netlink_link_change, netlink_cmd, &dp_info, 0, true); if (ret < 0) return ret; + return ret; +} + +void interface_list_tunneldump(struct zebra_ns *zns) +{ + int ret; + /* * So netlink_tunneldump_read will initiate a request * per tunnel to get data. If we are on a kernel that @@ -1297,13 +845,12 @@ int interface_lookup_netlink(struct zebra_ns *zns) */ ret = netlink_tunneldump_read(zns); if (ret < 0) - return ret; + return; - /* fixup linkages */ - zebra_if_update_all_links(zns); - return 0; + zebra_dplane_startup_stage(zns, ZEBRA_DPLANE_TUNNELS_READ); } + /** * interface_addr_lookup_netlink() - Look up interface addresses * @@ -1323,8 +870,8 @@ static int interface_addr_lookup_netlink(struct zebra_ns *zns) ret = netlink_request_intf_addr(netlink_cmd, AF_INET, RTM_GETADDR, 0); if (ret < 0) return ret; - ret = netlink_parse_info(netlink_interface_addr, netlink_cmd, &dp_info, - 0, true); + ret = netlink_parse_info(netlink_interface_addr_dplane, netlink_cmd, + &dp_info, 0, true); if (ret < 0) return ret; @@ -1332,8 +879,8 @@ static int interface_addr_lookup_netlink(struct zebra_ns *zns) ret = netlink_request_intf_addr(netlink_cmd, AF_INET6, RTM_GETADDR, 0); if (ret < 0) return ret; - ret = netlink_parse_info(netlink_interface_addr, netlink_cmd, &dp_info, - 0, true); + ret = netlink_parse_info(netlink_interface_addr_dplane, netlink_cmd, + &dp_info, 0, true); if (ret < 0) return ret; @@ -1455,67 +1002,13 @@ static ssize_t netlink_intf_msg_encoder(struct zebra_dplane_ctx *ctx, void *buf, op = dplane_ctx_get_op(ctx); - switch (op) { - case DPLANE_OP_INTF_UPDATE: + if (op == DPLANE_OP_INTF_UPDATE) cmd = RTM_SETLINK; - break; - case DPLANE_OP_INTF_INSTALL: + else if (op == DPLANE_OP_INTF_INSTALL) cmd = RTM_NEWLINK; - break; - case DPLANE_OP_INTF_DELETE: + else if (op == DPLANE_OP_INTF_DELETE) cmd = RTM_DELLINK; - break; - case DPLANE_OP_NONE: - case DPLANE_OP_ROUTE_INSTALL: - case DPLANE_OP_ROUTE_UPDATE: - case DPLANE_OP_ROUTE_DELETE: - case DPLANE_OP_ROUTE_NOTIFY: - case DPLANE_OP_NH_INSTALL: - case DPLANE_OP_NH_UPDATE: - case DPLANE_OP_NH_DELETE: - case DPLANE_OP_LSP_INSTALL: - case DPLANE_OP_LSP_DELETE: - case DPLANE_OP_LSP_NOTIFY: - case DPLANE_OP_LSP_UPDATE: - case DPLANE_OP_PW_INSTALL: - case DPLANE_OP_PW_UNINSTALL: - case DPLANE_OP_SYS_ROUTE_ADD: - case DPLANE_OP_SYS_ROUTE_DELETE: - case DPLANE_OP_ADDR_INSTALL: - case DPLANE_OP_ADDR_UNINSTALL: - case DPLANE_OP_MAC_INSTALL: - case DPLANE_OP_MAC_DELETE: - case DPLANE_OP_NEIGH_INSTALL: - case DPLANE_OP_NEIGH_UPDATE: - case DPLANE_OP_NEIGH_DELETE: - case DPLANE_OP_NEIGH_DISCOVER: - case DPLANE_OP_VTEP_ADD: - case DPLANE_OP_VTEP_DELETE: - case DPLANE_OP_RULE_ADD: - case DPLANE_OP_RULE_DELETE: - case DPLANE_OP_RULE_UPDATE: - case DPLANE_OP_BR_PORT_UPDATE: - case DPLANE_OP_IPTABLE_ADD: - case DPLANE_OP_IPTABLE_DELETE: - case DPLANE_OP_IPSET_ADD: - case DPLANE_OP_IPSET_ENTRY_ADD: - case DPLANE_OP_IPSET_ENTRY_DELETE: - case DPLANE_OP_IPSET_DELETE: - case DPLANE_OP_NEIGH_IP_INSTALL: - case DPLANE_OP_NEIGH_IP_DELETE: - case DPLANE_OP_NEIGH_TABLE_UPDATE: - case DPLANE_OP_GRE_SET: - case DPLANE_OP_INTF_ADDR_ADD: - case DPLANE_OP_INTF_ADDR_DEL: - case DPLANE_OP_INTF_NETCONFIG: - case DPLANE_OP_TC_QDISC_INSTALL: - case DPLANE_OP_TC_QDISC_UNINSTALL: - case DPLANE_OP_TC_CLASS_ADD: - case DPLANE_OP_TC_CLASS_DELETE: - case DPLANE_OP_TC_CLASS_UPDATE: - case DPLANE_OP_TC_FILTER_ADD: - case DPLANE_OP_TC_FILTER_DELETE: - case DPLANE_OP_TC_FILTER_UPDATE: + else { flog_err( EC_ZEBRA_NHG_FIB_UPDATE, "Context received for kernel interface update with incorrect OP code (%u)", @@ -1930,6 +1423,9 @@ int netlink_interface_addr_dplane(struct nlmsghdr *h, ns_id_t ns_id, if (kernel_flags & IFA_F_SECONDARY) dplane_ctx_intf_set_secondary(ctx); + if (kernel_flags & IFA_F_NOPREFIXROUTE) + dplane_ctx_intf_set_noprefixroute(ctx); + /* Label */ if (tb[IFA_LABEL]) { label = (char *)RTA_DATA(tb[IFA_LABEL]); @@ -1943,7 +1439,6 @@ int netlink_interface_addr_dplane(struct nlmsghdr *h, ns_id_t ns_id, /* Enqueue ctx for main pthread to process */ dplane_provider_enqueue_to_zebra(ctx); - return 0; } @@ -1953,25 +1448,22 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) struct ifinfomsg *ifi; struct rtattr *tb[IFLA_MAX + 1]; struct rtattr *linkinfo[IFLA_MAX + 1]; - struct interface *ifp; char *name = NULL; char *kind = NULL; - char *desc = NULL; char *slave_kind = NULL; - struct zebra_ns *zns; vrf_id_t vrf_id = VRF_DEFAULT; enum zebra_iftype zif_type = ZEBRA_IF_OTHER; enum zebra_slave_iftype zif_slave_type = ZEBRA_IF_SLAVE_NONE; ifindex_t bridge_ifindex = IFINDEX_INTERNAL; ifindex_t bond_ifindex = IFINDEX_INTERNAL; ifindex_t link_ifindex = IFINDEX_INTERNAL; - uint8_t old_hw_addr[INTERFACE_HWADDR_MAX]; - struct zebra_if *zif; ns_id_t link_nsid = ns_id; ifindex_t master_infindex = IFINDEX_INTERNAL; uint8_t bypass = 0; + uint32_t txqlen = 0; + + frrtrace(3, frr_zebra, netlink_interface, h, ns_id, startup); - zns = zebra_ns_lookup(ns_id); ifi = NLMSG_DATA(h); /* assume if not default zns, then new VRF */ @@ -2000,10 +1492,6 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) return -1; } - /* We are interested in some AF_BRIDGE notifications. */ - if (ifi->ifi_family == AF_BRIDGE) - return netlink_bridge_interface(h, len, ns_id, startup); - /* Looking up interface name. */ memset(linkinfo, 0, sizeof(linkinfo)); netlink_parse_rtattr_flags(tb, IFLA_MAX, IFLA_RTA(ifi), len, @@ -2050,18 +1538,52 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) link_nsid = *(ns_id_t *)RTA_DATA(tb[IFLA_LINK_NETNSID]); link_nsid = ns_id_get_absolute(ns_id, link_nsid); } - if (tb[IFLA_IFALIAS]) { - desc = (char *)RTA_DATA(tb[IFLA_IFALIAS]); - } - /* See if interface is present. */ - ifp = if_lookup_by_name_per_ns(zns, name); + if (tb[IFLA_TXQLEN]) + txqlen = *(uint32_t *)RTA_DATA(tb[IFLA_TXQLEN]); + + struct zebra_dplane_ctx *ctx = dplane_ctx_alloc(); + dplane_ctx_set_ns_id(ctx, ns_id); + dplane_ctx_set_ifp_link_nsid(ctx, link_nsid); + dplane_ctx_set_ifp_zif_type(ctx, zif_type); + dplane_ctx_set_ifindex(ctx, ifi->ifi_index); + dplane_ctx_set_ifname(ctx, name); + dplane_ctx_set_ifp_startup(ctx, startup); + dplane_ctx_set_ifp_family(ctx, ifi->ifi_family); + dplane_ctx_set_intf_txqlen(ctx, txqlen); + + /* We are interested in some AF_BRIDGE notifications. */ +#ifndef AF_BRIDGE +#define AF_BRIDGE 7 +#endif + if (ifi->ifi_family == AF_BRIDGE) { + dplane_ctx_set_op(ctx, DPLANE_OP_INTF_INSTALL); + return netlink_bridge_interface(ctx, tb[IFLA_AF_SPEC], startup); + } if (h->nlmsg_type == RTM_NEWLINK) { + dplane_ctx_set_ifp_link_ifindex(ctx, link_ifindex); + dplane_ctx_set_op(ctx, DPLANE_OP_INTF_INSTALL); + dplane_ctx_set_status(ctx, ZEBRA_DPLANE_REQUEST_QUEUED); + if (tb[IFLA_IFALIAS]) { + dplane_ctx_set_ifp_desc(ctx, + RTA_DATA(tb[IFLA_IFALIAS])); + } + if (!tb[IFLA_MTU]) { + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug( + "RTM_NEWLINK for interface %s(%u) without MTU set", + name, ifi->ifi_index); + dplane_ctx_fini(&ctx); + return 0; + } + dplane_ctx_set_ifp_mtu(ctx, *(int *)RTA_DATA(tb[IFLA_MTU])); + /* If VRF, create or update the VRF structure itself. */ if (zif_type == ZEBRA_IF_VRF && !vrf_is_backend_netns()) { - netlink_vrf_change(h, tb[IFLA_LINKINFO], ns_id, name); - vrf_id = (vrf_id_t)ifi->ifi_index; + netlink_vrf_change(h, tb[IFLA_LINKINFO], ns_id, name, + ctx); + vrf_id = ifi->ifi_index; } if (tb[IFLA_MASTER]) { @@ -2084,262 +1606,45 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) } else zif_slave_type = ZEBRA_IF_SLAVE_OTHER; } + dplane_ctx_set_ifp_zif_slave_type(ctx, zif_slave_type); + dplane_ctx_set_ifp_vrf_id(ctx, vrf_id); + dplane_ctx_set_ifp_master_ifindex(ctx, master_infindex); + dplane_ctx_set_ifp_bridge_ifindex(ctx, bridge_ifindex); + dplane_ctx_set_ifp_bond_ifindex(ctx, bond_ifindex); + dplane_ctx_set_ifp_bypass(ctx, bypass); + dplane_ctx_set_ifp_zltype( + ctx, netlink_to_zebra_link_type(ifi->ifi_type)); + if (vrf_is_backend_netns()) - vrf_id = (vrf_id_t)ns_id; - if (ifp == NULL - || !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) { - /* Add interface notification from kernel */ - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug( - "RTM_NEWLINK ADD for %s(%u) vrf_id %u type %d sl_type %d master %u flags 0x%x", - name, ifi->ifi_index, vrf_id, zif_type, - zif_slave_type, master_infindex, - ifi->ifi_flags); - - if (ifp == NULL) { - /* unknown interface */ - ifp = if_get_by_name(name, vrf_id, NULL); - } else { - /* pre-configured interface, learnt now */ - if (ifp->vrf->vrf_id != vrf_id) - if_update_to_new_vrf(ifp, vrf_id); - } - - /* Update interface information. */ - set_ifindex(ifp, ifi->ifi_index, zns); - ifp->flags = ifi->ifi_flags & 0x0000fffff; - if (!tb[IFLA_MTU]) { - zlog_debug( - "RTM_NEWLINK for interface %s(%u) without MTU set", - name, ifi->ifi_index); - return 0; - } - ifp->mtu6 = ifp->mtu = *(int *)RTA_DATA(tb[IFLA_MTU]); - ifp->metric = 0; - ifp->ptm_status = ZEBRA_PTM_STATUS_UNKNOWN; - - /* Set interface type */ - zebra_if_set_ziftype(ifp, zif_type, zif_slave_type); - if (IS_ZEBRA_IF_VRF(ifp)) - SET_FLAG(ifp->status, - ZEBRA_INTERFACE_VRF_LOOPBACK); - - /* Update link. */ - zebra_if_update_link(ifp, link_ifindex, link_nsid); - - ifp->ll_type = - netlink_to_zebra_link_type(ifi->ifi_type); - netlink_interface_update_hw_addr(tb, ifp); - - /* Inform clients, install any configured addresses. */ - if_add_update(ifp); - - /* Extract and save L2 interface information, take - * additional actions. */ - netlink_interface_update_l2info( - ifp, linkinfo[IFLA_INFO_DATA], - 1, link_nsid); - if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp)) - zebra_l2if_update_bridge_slave( - ifp, bridge_ifindex, ns_id, - ZEBRA_BRIDGE_NO_ACTION); - else if (IS_ZEBRA_IF_BOND_SLAVE(ifp)) - zebra_l2if_update_bond_slave(ifp, bond_ifindex, - !!bypass); - - if (tb[IFLA_PROTO_DOWN]) - netlink_proc_dplane_if_protodown(ifp->info, tb); - if (IS_ZEBRA_IF_BRIDGE(ifp)) { - zif = ifp->info; - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug( - "RTM_NEWLINK ADD for %s(%u), vlan-aware %d", - name, ifp->ifindex, - IS_ZEBRA_IF_BRIDGE_VLAN_AWARE( - zif)); - } - } else if (ifp->vrf->vrf_id != vrf_id) { - /* VRF change for an interface. */ - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug( - "RTM_NEWLINK vrf-change for %s(%u) vrf_id %u -> %u flags 0x%x", - name, ifp->ifindex, ifp->vrf->vrf_id, - vrf_id, ifi->ifi_flags); + dplane_ctx_set_ifp_vrf_id(ctx, ns_id); - if_handle_vrf_change(ifp, vrf_id); - } else { - bool was_bridge_slave, was_bond_slave; - uint8_t chgflags = ZEBRA_BRIDGE_NO_ACTION; - zif = ifp->info; + dplane_ctx_set_ifp_flags(ctx, ifi->ifi_flags & 0x0000fffff); - /* Interface update. */ - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug( - "RTM_NEWLINK update for %s(%u) sl_type %d master %u flags 0x%x", - name, ifp->ifindex, zif_slave_type, - master_infindex, ifi->ifi_flags); + if (tb[IFLA_PROTO_DOWN]) { + dplane_ctx_set_ifp_protodown_set(ctx, true); + netlink_proc_dplane_if_protodown(ctx, tb); + } else + dplane_ctx_set_ifp_protodown_set(ctx, false); - set_ifindex(ifp, ifi->ifi_index, zns); - if (!tb[IFLA_MTU]) { - zlog_debug( - "RTM_NEWLINK for interface %s(%u) without MTU set", - name, ifi->ifi_index); - return 0; - } - ifp->mtu6 = ifp->mtu = *(int *)RTA_DATA(tb[IFLA_MTU]); - ifp->metric = 0; - - /* Update interface type - NOTE: Only slave_type can - * change. */ - was_bridge_slave = IS_ZEBRA_IF_BRIDGE_SLAVE(ifp); - was_bond_slave = IS_ZEBRA_IF_BOND_SLAVE(ifp); - zebra_if_set_ziftype(ifp, zif_type, zif_slave_type); - - memcpy(old_hw_addr, ifp->hw_addr, INTERFACE_HWADDR_MAX); - - /* Update link. */ - zebra_if_update_link(ifp, link_ifindex, link_nsid); - - ifp->ll_type = - netlink_to_zebra_link_type(ifi->ifi_type); - netlink_interface_update_hw_addr(tb, ifp); - - if (tb[IFLA_PROTO_DOWN]) - netlink_proc_dplane_if_protodown(ifp->info, tb); - - if (if_is_no_ptm_operative(ifp)) { - bool is_up = if_is_operative(ifp); - ifp->flags = ifi->ifi_flags & 0x0000fffff; - if (!if_is_no_ptm_operative(ifp) || - CHECK_FLAG(zif->flags, - ZIF_FLAG_PROTODOWN)) { - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug( - "Intf %s(%u) has gone DOWN", - name, ifp->ifindex); - if_down(ifp); - rib_update(RIB_UPDATE_KERNEL); - } else if (if_is_operative(ifp)) { - bool mac_updated = false; - - /* Must notify client daemons of new - * interface status. */ - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug( - "Intf %s(%u) PTM up, notifying clients", - name, ifp->ifindex); - if_up(ifp, !is_up); - - /* Update EVPN VNI when SVI MAC change - */ - if (memcmp(old_hw_addr, ifp->hw_addr, - INTERFACE_HWADDR_MAX)) - mac_updated = true; - if (IS_ZEBRA_IF_VLAN(ifp) - && mac_updated) { - struct interface *link_if; - - link_if = - if_lookup_by_index_per_ns( - zebra_ns_lookup(NS_DEFAULT), - link_ifindex); - if (link_if) - zebra_vxlan_svi_up(ifp, - link_if); - } else if (mac_updated - && IS_ZEBRA_IF_BRIDGE(ifp)) { - zlog_debug( - "Intf %s(%u) bridge changed MAC address", - name, ifp->ifindex); - chgflags = - ZEBRA_BRIDGE_MASTER_MAC_CHANGE; - } - } - } else { - ifp->flags = ifi->ifi_flags & 0x0000fffff; - if (if_is_operative(ifp) && - !CHECK_FLAG(zif->flags, - ZIF_FLAG_PROTODOWN)) { - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug( - "Intf %s(%u) has come UP", - name, ifp->ifindex); - if_up(ifp, true); - if (IS_ZEBRA_IF_BRIDGE(ifp)) - chgflags = - ZEBRA_BRIDGE_MASTER_UP; - } else { - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug( - "Intf %s(%u) has gone DOWN", - name, ifp->ifindex); - if_down(ifp); - rib_update(RIB_UPDATE_KERNEL); - } - } - - /* Extract and save L2 interface information, take - * additional actions. */ - netlink_interface_update_l2info( - ifp, linkinfo[IFLA_INFO_DATA], - 0, link_nsid); - if (IS_ZEBRA_IF_BRIDGE(ifp)) - zebra_l2if_update_bridge(ifp, chgflags); - if (IS_ZEBRA_IF_BOND(ifp)) - zebra_l2if_update_bond(ifp, true); - if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp) || was_bridge_slave) - zebra_l2if_update_bridge_slave( - ifp, bridge_ifindex, ns_id, chgflags); - else if (IS_ZEBRA_IF_BOND_SLAVE(ifp) || was_bond_slave) - zebra_l2if_update_bond_slave(ifp, bond_ifindex, - !!bypass); - if (IS_ZEBRA_IF_BRIDGE(ifp)) { - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug( - "RTM_NEWLINK update for %s(%u), vlan-aware %d", - name, ifp->ifindex, - IS_ZEBRA_IF_BRIDGE_VLAN_AWARE( - zif)); - } - } + netlink_interface_update_hw_addr(tb, ctx); - zif = ifp->info; - if (zif) { - XFREE(MTYPE_ZIF_DESC, zif->desc); - if (desc) - zif->desc = XSTRDUP(MTYPE_ZIF_DESC, desc); - } + /* Extract and save L2 interface information, take + * additional actions. */ + netlink_interface_update_l2info( + ctx, zif_type, linkinfo[IFLA_INFO_DATA], 1, link_nsid); } else { - /* Delete interface notification from kernel */ - if (ifp == NULL) { - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug( - "RTM_DELLINK for unknown interface %s(%u)", - name, ifi->ifi_index); - return 0; - } - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("RTM_DELLINK for %s(%u)", name, - ifp->ifindex); - - if (IS_ZEBRA_IF_BOND(ifp)) - zebra_l2if_update_bond(ifp, false); - if (IS_ZEBRA_IF_BOND_SLAVE(ifp)) - zebra_l2if_update_bond_slave(ifp, bond_ifindex, false); - /* Special handling for bridge or VxLAN interfaces. */ - if (IS_ZEBRA_IF_BRIDGE(ifp)) - zebra_l2_bridge_del(ifp); - else if (IS_ZEBRA_IF_VXLAN(ifp)) - zebra_l2_vxlanif_del(ifp); - - if_delete_update(&ifp); - - /* If VRF, delete the VRF structure itself. */ - if (zif_type == ZEBRA_IF_VRF && !vrf_is_backend_netns()) - netlink_vrf_change(h, tb[IFLA_LINKINFO], ns_id, name); + zlog_debug("RTM_DELLINK for %s(%u), enqueuing to zebra", + name, ifi->ifi_index); + + dplane_ctx_set_op(ctx, DPLANE_OP_INTF_DELETE); + dplane_ctx_set_status(ctx, ZEBRA_DPLANE_REQUEST_QUEUED); + + dplane_ctx_set_ifp_bond_ifindex(ctx, bond_ifindex); } + dplane_provider_enqueue_to_zebra(ctx); + return 0; } @@ -2397,9 +1702,10 @@ ssize_t netlink_intf_msg_encode(uint16_t cmd, return -1; nl_attr_put32(&req->n, buflen, IFLA_PROTO_DOWN_REASON_MASK, - (1 << frr_protodown_r_bit)); + (1 << if_netlink_get_frr_protodown_r_bit())); nl_attr_put32(&req->n, buflen, IFLA_PROTO_DOWN_REASON_VALUE, - ((int)pd_reason_val) << frr_protodown_r_bit); + ((int)pd_reason_val) + << if_netlink_get_frr_protodown_r_bit()); nl_attr_nest_end(&req->n, nest_protodown_reason); @@ -2415,6 +1721,13 @@ ssize_t netlink_intf_msg_encode(uint16_t cmd, void interface_list(struct zebra_ns *zns) { interface_lookup_netlink(zns); + + zebra_dplane_startup_stage(zns, ZEBRA_DPLANE_INTERFACES_READ); +} + +void interface_list_second(struct zebra_ns *zns) +{ + zebra_if_update_all_links(zns); /* We add routes for interface address, * so we need to get the nexthop info * from the kernel before we can do that @@ -2422,37 +1735,8 @@ void interface_list(struct zebra_ns *zns) netlink_nexthop_read(zns); interface_addr_lookup_netlink(zns); -} - -void if_netlink_set_frr_protodown_r_bit(uint8_t bit) -{ - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug( - "Protodown reason bit index changed: bit-index %u -> bit-index %u", - frr_protodown_r_bit, bit); - - frr_protodown_r_bit = bit; -} -void if_netlink_unset_frr_protodown_r_bit(void) -{ - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug( - "Protodown reason bit index changed: bit-index %u -> bit-index %u", - frr_protodown_r_bit, FRR_PROTODOWN_REASON_DEFAULT_BIT); - - frr_protodown_r_bit = FRR_PROTODOWN_REASON_DEFAULT_BIT; -} - - -bool if_netlink_frr_protodown_r_bit_is_set(void) -{ - return (frr_protodown_r_bit != FRR_PROTODOWN_REASON_DEFAULT_BIT); -} - -uint8_t if_netlink_get_frr_protodown_r_bit(void) -{ - return frr_protodown_r_bit; + zebra_dplane_startup_stage(zns, ZEBRA_DPLANE_ADDRESSES_READ); } /** @@ -2512,7 +1796,7 @@ int netlink_tunneldump_read(struct zebra_ns *zns) if (ret < 0) return ret; - ret = netlink_parse_info(netlink_interface, netlink_cmd, + ret = netlink_parse_info(netlink_link_change, netlink_cmd, &dp_info, 0, true); if (ret < 0) diff --git a/zebra/if_netlink.h b/zebra/if_netlink.h index ede6224188..9b31906a17 100644 --- a/zebra/if_netlink.h +++ b/zebra/if_netlink.h @@ -42,17 +42,6 @@ extern int netlink_tunneldump_read(struct zebra_ns *zns); extern enum netlink_msg_status netlink_put_intf_update_msg(struct nl_batch *bth, struct zebra_dplane_ctx *ctx); -#define FRR_PROTODOWN_REASON_DEFAULT_BIT 7 -/* Protodown bit setter/getter - * - * Allow users to change the bit if it conflicts with another - * on their system. - */ -extern void if_netlink_set_frr_protodown_r_bit(uint8_t bit); -extern void if_netlink_unset_frr_protodown_r_bit(void); -extern bool if_netlink_frr_protodown_r_bit_is_set(void); -extern uint8_t if_netlink_get_frr_protodown_r_bit(void); - #ifdef __cplusplus } #endif diff --git a/zebra/if_sysctl.c b/zebra/if_sysctl.c index ae292689ed..9db959896e 100644 --- a/zebra/if_sysctl.c +++ b/zebra/if_sysctl.c @@ -6,6 +6,8 @@ #include <zebra.h> +#include <net/route.h> + #if !defined(GNU_LINUX) && !defined(OPEN_BSD) #include "if.h" diff --git a/zebra/interface.c b/zebra/interface.c index ccf1a0a204..f38e150d73 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -135,6 +135,7 @@ static int if_zebra_new_hook(struct interface *ifp) zebra_if->ifp = ifp; zebra_if->multicast = IF_ZEBRA_DATA_UNSPEC; + zebra_if->mpls_config = IF_ZEBRA_DATA_UNSPEC; zebra_if->shutdown = IF_ZEBRA_DATA_OFF; zebra_if->link_nsid = NS_UNKNOWN; @@ -199,6 +200,7 @@ static void if_nhg_dependents_release(const struct interface *ifp) static int if_zebra_delete_hook(struct interface *ifp) { struct zebra_if *zebra_if; + struct zebra_l2info_bond *bond; if (ifp->info) { zebra_if = ifp->info; @@ -216,6 +218,10 @@ static int if_zebra_delete_hook(struct interface *ifp) rtadv_if_fini(zebra_if); + bond = &zebra_if->bond_info; + if (bond && bond->mbr_zifs) + list_delete(&bond->mbr_zifs); + zebra_l2_bridge_if_cleanup(ifp); zebra_evpn_if_cleanup(zebra_if); zebra_evpn_mac_ifp_del(ifp); @@ -483,12 +489,11 @@ void if_flags_update(struct interface *ifp, uint64_t newflags) address. */ void if_addr_wakeup(struct interface *ifp) { - struct listnode *node, *nnode; struct connected *ifc; struct prefix *p; enum zebra_dplane_result dplane_res; - for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, ifc)) { + frr_each_safe (if_connected, ifp->connected, ifc) { p = ifc->address; if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED) @@ -609,6 +614,11 @@ void if_add_update(struct interface *ifp) if_addr_wakeup(ifp); + if (if_data->mpls_config == IF_ZEBRA_DATA_ON) + dplane_intf_mpls_modify_state(ifp, true); + else if (if_data->mpls_config == IF_ZEBRA_DATA_OFF) + dplane_intf_mpls_modify_state(ifp, false); + if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( "interface %s vrf %s(%u) index %d becomes active.", @@ -626,32 +636,24 @@ void if_add_update(struct interface *ifp) /* Install connected routes corresponding to an interface. */ static void if_install_connected(struct interface *ifp) { - struct listnode *node; - struct listnode *next; struct connected *ifc; - if (ifp->connected) { - for (ALL_LIST_ELEMENTS(ifp->connected, node, next, ifc)) { - if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL)) - zebra_interface_address_add_update(ifp, ifc); + frr_each (if_connected, ifp->connected, ifc) { + if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL)) + zebra_interface_address_add_update(ifp, ifc); - connected_up(ifp, ifc); - } + connected_up(ifp, ifc); } } /* Uninstall connected routes corresponding to an interface. */ static void if_uninstall_connected(struct interface *ifp) { - struct listnode *node; - struct listnode *next; struct connected *ifc; - if (ifp->connected) { - for (ALL_LIST_ELEMENTS(ifp->connected, node, next, ifc)) { - zebra_interface_address_delete_update(ifp, ifc); - connected_down(ifp, ifc); - } + frr_each_safe (if_connected, ifp->connected, ifc) { + zebra_interface_address_delete_update(ifp, ifc); + connected_down(ifp, ifc); } } @@ -659,20 +661,15 @@ static void if_uninstall_connected(struct interface *ifp) /* TODO - Check why IPv4 handling here is different from install or if_down */ static void if_delete_connected(struct interface *ifp) { - struct connected *ifc; + struct connected *ifc, *ifc_next; struct prefix cp; struct route_node *rn; struct zebra_if *zebra_if; - struct listnode *node; - struct listnode *last = NULL; zebra_if = ifp->info; - if (!ifp->connected) - return; - - while ((node = (last ? last->next : listhead(ifp->connected)))) { - ifc = listgetdata(node); + for (ifc = if_connected_first(ifp->connected); ifc; ifc = ifc_next) { + ifc_next = if_connected_next(ifp->connected, ifc); cp = *CONNECTED_PREFIX(ifc); apply_mask(&cp); @@ -721,11 +718,15 @@ static void if_delete_connected(struct interface *ifp) * (unconditionally). */ if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED)) { - listnode_delete(ifp->connected, + if (ifc == ifc_next) + ifc_next = if_connected_next( + ifp->connected, ifc); + + if_connected_del(ifp->connected, + ifc); connected_free(&ifc); - } else - last = node; + } } /* Free chain list and respective route node. */ @@ -740,14 +741,10 @@ static void if_delete_connected(struct interface *ifp) UNSET_FLAG(ifc->conf, ZEBRA_IFC_REAL); UNSET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED); - if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED)) - last = node; - else { - listnode_delete(ifp->connected, ifc); + if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED)) { + if_connected_del(ifp->connected, ifc); connected_free(&ifc); } - } else { - last = node; } } } @@ -781,6 +778,15 @@ void if_delete_update(struct interface **pifp) /* Delete connected routes from the kernel. */ if_delete_connected(ifp); + /* if the ifp is in a vrf, move it to default so vrf can be deleted if + * desired. This operation is not done for netns implementation to avoid + * collision with interface with the same name in the default vrf (can + * occur with this implementation whereas it is not possible with + * vrf-lite). + */ + if (ifp->vrf->vrf_id && !vrf_is_backend_netns()) + if_handle_vrf_change(ifp, VRF_DEFAULT); + /* Send out notification on interface delete. */ zebra_interface_delete_update(ifp); @@ -794,15 +800,6 @@ void if_delete_update(struct interface **pifp) if_set_index(ifp, IFINDEX_INTERNAL); ifp->node = NULL; - /* if the ifp is in a vrf, move it to default so vrf can be deleted if - * desired. This operation is not done for netns implementation to avoid - * collision with interface with the same name in the default vrf (can - * occur with this implementation whereas it is not possible with - * vrf-lite). - */ - if (ifp->vrf->vrf_id && !vrf_is_backend_netns()) - if_handle_vrf_change(ifp, VRF_DEFAULT); - UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_VRF_LOOPBACK); /* Reset some zebra interface params to default values. */ @@ -842,7 +839,7 @@ void if_handle_vrf_change(struct interface *ifp, vrf_id_t vrf_id) if_down_del_nbr_connected(ifp); /* Send out notification on interface VRF change. */ - /* This is to issue an UPDATE or a DELETE, as appropriate. */ + /* This is to issue a DELETE, as appropriate. */ zebra_interface_vrf_update_del(ifp, vrf_id); if (if_is_vrf(ifp)) @@ -1057,6 +1054,8 @@ void if_up(struct interface *ifp, bool install_connected) event_add_timer(zrouter.master, if_zebra_speed_update, ifp, 0, &zif->speed_update); event_ignore_late_timer(zif->speed_update); + + if_addr_wakeup(ifp); } /* Interface goes down. We have to manage different behavior of based @@ -1120,8 +1119,6 @@ void zebra_if_update_link(struct interface *ifp, ifindex_t link_ifindex, { struct zebra_if *zif; - if (IS_ZEBRA_IF_VETH(ifp)) - return; zif = (struct zebra_if *)ifp->info; zif->link_nsid = ns_id; zif->link_ifindex = link_ifindex; @@ -1184,6 +1181,12 @@ static bool if_ignore_set_protodown(const struct interface *ifp, bool new_down, zif = ifp->info; + /* + * FRR does not have enough data to make this request + */ + if (ifp->ifindex == IFINDEX_INTERNAL) + return true; + /* Current state as we know it */ old_down = !!(ZEBRA_IF_IS_PROTODOWN(zif)); old_set_down = !!CHECK_FLAG(zif->flags, ZIF_FLAG_SET_PROTODOWN); @@ -1293,6 +1296,9 @@ static void zebra_if_addr_update_ctx(struct zebra_dplane_ctx *ctx, const struct prefix *addr, *dest = NULL; enum dplane_op_e op; + if (!ifp) + return; + op = dplane_ctx_get_op(ctx); addr = dplane_ctx_get_intf_addr(ctx); @@ -1313,6 +1319,9 @@ static void zebra_if_addr_update_ctx(struct zebra_dplane_ctx *ctx, if (dplane_ctx_intf_is_secondary(ctx)) SET_FLAG(flags, ZEBRA_IFA_SECONDARY); + if (dplane_ctx_intf_is_noprefixroute(ctx)) + SET_FLAG(flags, ZEBRA_IFA_NOPREFIXROUTE); + /* Label? */ if (dplane_ctx_intf_has_label(ctx)) label = dplane_ctx_get_intf_label(ctx); @@ -1364,6 +1373,13 @@ static void zebra_if_update_ctx(struct zebra_dplane_ctx *ctx, bool pd_reason_val; bool down; + if (!ifp) { + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug("%s: Can't find ifp", __func__); + + return; + } + dp_res = dplane_ctx_get_status(ctx); pd_reason_val = dplane_ctx_get_intf_pd_reason_val(ctx); down = dplane_ctx_intf_is_protodown(ctx); @@ -1411,6 +1427,13 @@ static void zebra_if_netconf_update_ctx(struct zebra_dplane_ctx *ctx, enum dplane_netconf_status_e mpls, mcast_on, linkdown; bool *mcast_set, *linkdown_set; + if (!ifp && ifindex != -1 && ifindex != -2) { + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug("%s: Can't find ifp(%u)", __func__, ifindex); + + return; + } + afi = dplane_ctx_get_afi(ctx); mpls = dplane_ctx_get_netconf_mpls(ctx); linkdown = dplane_ctx_get_netconf_linkdown(ctx); @@ -1433,7 +1456,7 @@ static void zebra_if_netconf_update_ctx(struct zebra_dplane_ctx *ctx, linkdown_set = &zrouter.default_linkdownv6; } } else { - zif = ifp ? ifp->info : NULL; + zif = ifp->info; if (!zif) { if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( @@ -1480,6 +1503,759 @@ static void zebra_if_netconf_update_ctx(struct zebra_dplane_ctx *ctx, (*linkdown_set ? "ON" : "OFF")); } +static void interface_vrf_change(enum dplane_op_e op, ifindex_t ifindex, + const char *name, uint32_t tableid, + ns_id_t ns_id) +{ + struct vrf *vrf; + struct zebra_vrf *zvrf = NULL; + + if (op == DPLANE_OP_INTF_DELETE) { + if (IS_ZEBRA_DEBUG_DPLANE) + zlog_debug("DPLANE_OP_INTF_DELETE for VRF %s(%u)", name, + ifindex); + + vrf = vrf_lookup_by_id((vrf_id_t)ifindex); + if (!vrf) { + flog_warn(EC_ZEBRA_VRF_NOT_FOUND, + "%s(%u): vrf not found", name, ifindex); + return; + } + + vrf_delete(vrf); + } else { + if (IS_ZEBRA_DEBUG_DPLANE) + zlog_debug( + "DPLANE_OP_INTF_UPDATE for VRF %s(%u) table %u", + name, ifindex, tableid); + + if (!vrf_lookup_by_id((vrf_id_t)ifindex)) { + vrf_id_t exist_id; + + exist_id = zebra_vrf_lookup_by_table(tableid, ns_id); + if (exist_id != VRF_DEFAULT) { + vrf = vrf_lookup_by_id(exist_id); + + if (vrf) + flog_err(EC_ZEBRA_VRF_MISCONFIGURED, + "VRF %s id %u table id overlaps existing vrf %s(%d), misconfiguration exiting", + name, ifindex, vrf->name, + vrf->vrf_id); + else + flog_err(EC_ZEBRA_VRF_NOT_FOUND, + "VRF %s id %u does not exist", + name, ifindex); + + exit(-1); + } + } + + vrf = vrf_update((vrf_id_t)ifindex, name); + if (!vrf) { + flog_err(EC_LIB_INTERFACE, "VRF %s id %u not created", + name, ifindex); + return; + } + + /* + * This is the only place that we get the actual kernel table_id + * being used. We need it to set the table_id of the routes + * we are passing to the kernel.... And to throw some totally + * awesome parties. that too. + * + * At this point we *must* have a zvrf because the vrf_create + * callback creates one. We *must* set the table id + * before the vrf_enable because of( at the very least ) + * static routes being delayed for installation until + * during the vrf_enable callbacks. + */ + zvrf = (struct zebra_vrf *)vrf->info; + zvrf->table_id = tableid; + + /* Enable the created VRF. */ + if (!vrf_enable(vrf)) { + flog_err(EC_LIB_INTERFACE, + "Failed to enable VRF %s id %u", name, + ifindex); + return; + } + } +} + +/* + * Note: on netlink systems, there should be a 1-to-1 mapping + * between interface names and ifindex values. + */ +static void set_ifindex(struct interface *ifp, ifindex_t ifi_index, + struct zebra_ns *zns) +{ + struct interface *oifp; + + oifp = if_lookup_by_index_per_ns(zns, ifi_index); + if ((oifp != NULL) && (oifp != ifp)) { + if (ifi_index == IFINDEX_INTERNAL) + flog_err( + EC_LIB_INTERFACE, + "Netlink is setting interface %s ifindex to reserved internal value %u", + ifp->name, ifi_index); + else { + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug( + "interface index %d was renamed from %s to %s", + ifi_index, oifp->name, ifp->name); + if (if_is_up(oifp)) + flog_err( + EC_LIB_INTERFACE, + "interface rename detected on up interface: index %d was renamed from %s to %s, results are uncertain!", + ifi_index, oifp->name, ifp->name); + if_delete_update(&oifp); + } + } + if_set_index(ifp, ifi_index); +} + +static inline void zebra_if_set_ziftype(struct interface *ifp, + enum zebra_iftype zif_type, + enum zebra_slave_iftype zif_slave_type) +{ + struct zebra_if *zif; + + zif = (struct zebra_if *)ifp->info; + zif->zif_slave_type = zif_slave_type; + + if (zif->zif_type != zif_type) { + zif->zif_type = zif_type; + /* If the if_type has been set to bond initialize ES info + * against it. XXX - note that we don't handle the case where + * a zif changes from bond to non-bond; it is really + * an unexpected/error condition. + */ + zebra_evpn_if_init(zif); + } +} + +static void interface_update_hw_addr(struct zebra_dplane_ctx *ctx, + struct interface *ifp) +{ + int i; + + ifp->hw_addr_len = dplane_ctx_get_ifp_hw_addr_len(ctx); + memcpy(ifp->hw_addr, dplane_ctx_get_ifp_hw_addr(ctx), ifp->hw_addr_len); + + for (i = 0; i < ifp->hw_addr_len; i++) + if (ifp->hw_addr[i] != 0) + break; + + if (i == ifp->hw_addr_len) + ifp->hw_addr_len = 0; +} + +static void interface_update_l2info(struct zebra_dplane_ctx *ctx, + struct interface *ifp, + enum zebra_iftype zif_type, int add, + ns_id_t link_nsid) +{ + const struct zebra_l2info_vxlan *vxlan_info; + const struct zebra_l2info_gre *gre_info; + + switch (zif_type) { + case ZEBRA_IF_BRIDGE: + zebra_l2_bridge_add_update(ifp, + dplane_ctx_get_ifp_bridge_info(ctx)); + break; + case ZEBRA_IF_VLAN: + zebra_l2_vlanif_update(ifp, dplane_ctx_get_ifp_vlan_info(ctx)); + zebra_evpn_acc_bd_svi_set(ifp->info, NULL, + !!if_is_operative(ifp)); + break; + case ZEBRA_IF_VXLAN: + vxlan_info = dplane_ctx_get_ifp_vxlan_info(ctx); + zebra_l2_vxlanif_add_update(ifp, vxlan_info, add); + if (link_nsid != NS_UNKNOWN && vxlan_info->ifindex_link) + zebra_if_update_link(ifp, vxlan_info->ifindex_link, + link_nsid); + break; + case ZEBRA_IF_GRE: + gre_info = dplane_ctx_get_ifp_gre_info(ctx); + zebra_l2_greif_add_update(ifp, gre_info, add); + if (link_nsid != NS_UNKNOWN && gre_info->ifindex_link) + zebra_if_update_link(ifp, gre_info->ifindex_link, + link_nsid); + break; + case ZEBRA_IF_OTHER: + case ZEBRA_IF_VRF: + case ZEBRA_IF_MACVLAN: + case ZEBRA_IF_VETH: + case ZEBRA_IF_BOND: + break; + } +} + +static bool is_if_protodown_reason_only_frr(uint32_t rc_bitfield) +{ + uint8_t frr_protodown_r_bit = if_netlink_get_frr_protodown_r_bit(); + + return (rc_bitfield == (((uint32_t)1) << frr_protodown_r_bit)); +} + +static void interface_if_protodown(struct interface *ifp, bool protodown, + uint32_t rc_bitfield) +{ + struct zebra_if *zif = ifp->info; + bool old_protodown; + + /* + * Set our reason code to note it wasn't us. + * If the reason we got from the kernel is ONLY frr though, don't + * set it. + */ + COND_FLAG(zif->protodown_rc, ZEBRA_PROTODOWN_EXTERNAL, + protodown && rc_bitfield && + !is_if_protodown_reason_only_frr(rc_bitfield)); + + + old_protodown = !!ZEBRA_IF_IS_PROTODOWN(zif); + if (protodown == old_protodown) + return; + + if (IS_ZEBRA_DEBUG_EVPN_MH_ES || IS_ZEBRA_DEBUG_DPLANE) + zlog_debug("interface %s dplane change, protodown %s", + ifp->name, protodown ? "on" : "off"); + + /* Set protodown, respectively */ + COND_FLAG(zif->flags, ZIF_FLAG_PROTODOWN, protodown); + + if (zebra_evpn_is_es_bond_member(ifp)) { + /* Check it's not already being sent to the dplane first */ + if (protodown && + CHECK_FLAG(zif->flags, ZIF_FLAG_SET_PROTODOWN)) { + if (IS_ZEBRA_DEBUG_EVPN_MH_ES || IS_ZEBRA_DEBUG_KERNEL) + zlog_debug( + "bond mbr %s protodown on recv'd but already sent protodown on to the dplane", + ifp->name); + return; + } + + if (!protodown && + CHECK_FLAG(zif->flags, ZIF_FLAG_UNSET_PROTODOWN)) { + if (IS_ZEBRA_DEBUG_EVPN_MH_ES || IS_ZEBRA_DEBUG_KERNEL) + zlog_debug( + "bond mbr %s protodown off recv'd but already sent protodown off to the dplane", + ifp->name); + return; + } + + if (IS_ZEBRA_DEBUG_EVPN_MH_ES || IS_ZEBRA_DEBUG_KERNEL) + zlog_debug( + "bond mbr %s reinstate protodown %s in the dplane", + ifp->name, old_protodown ? "on" : "off"); + + if (old_protodown) + SET_FLAG(zif->flags, ZIF_FLAG_SET_PROTODOWN); + else + SET_FLAG(zif->flags, ZIF_FLAG_UNSET_PROTODOWN); + + dplane_intf_update(zif->ifp); + } +} + +static void if_sweep_protodown(struct zebra_if *zif) +{ + bool protodown; + + protodown = !!ZEBRA_IF_IS_PROTODOWN(zif); + + if (!protodown) + return; + + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug("interface %s sweeping protodown %s reason 0x%x", + zif->ifp->name, protodown ? "on" : "off", + zif->protodown_rc); + + /* Only clear our reason codes, leave external if it was set */ + UNSET_FLAG(zif->protodown_rc, ZEBRA_PROTODOWN_ALL); + dplane_intf_update(zif->ifp); +} + +static void +interface_bridge_vxlan_vlan_vni_map_update(struct zebra_dplane_ctx *ctx, + struct interface *ifp) +{ + const struct zebra_vxlan_vni_array *vniarray = + dplane_ctx_get_ifp_vxlan_vni_array(ctx); + struct zebra_vxlan_vni vni_start, vni_end; + struct hash *vni_table = NULL; + struct zebra_vxlan_vni vni, *vnip; + vni_t vni_id; + vlanid_t vid; + int i; + + memset(&vni_start, 0, sizeof(vni_start)); + memset(&vni_end, 0, sizeof(vni_end)); + + for (i = 0; i < vniarray->count; i++) { + uint16_t flags = vniarray->vnis[i].flags; + + if (flags & DPLANE_BRIDGE_VLAN_INFO_RANGE_BEGIN) { + vni_start = vniarray->vnis[i]; + continue; + } + + if (flags & DPLANE_BRIDGE_VLAN_INFO_RANGE_END) + vni_end = vniarray->vnis[i]; + + if (!(flags & DPLANE_BRIDGE_VLAN_INFO_RANGE_END)) { + vni_start = vniarray->vnis[i]; + vni_end = vniarray->vnis[i]; + } + + if (IS_ZEBRA_DEBUG_DPLANE) + zlog_debug( + "Vlan-Vni(%d:%d-%d:%d) update for VxLAN IF %s(%u)", + vni_start.access_vlan, vni_end.access_vlan, + vni_start.vni, vni_end.vni, ifp->name, + ifp->ifindex); + + if (!vni_table) { + vni_table = zebra_vxlan_vni_table_create(); + if (!vni_table) + return; + } + + for (vid = vni_start.access_vlan, vni_id = vni_start.vni; + vid <= vni_end.access_vlan; vid++, vni_id++) { + + memset(&vni, 0, sizeof(vni)); + vni.vni = vni_id; + vni.access_vlan = vid; + vnip = hash_get(vni_table, &vni, zebra_vxlan_vni_alloc); + if (!vnip) + return; + } + + memset(&vni_start, 0, sizeof(vni_start)); + memset(&vni_end, 0, sizeof(vni_end)); + } + + if (vni_table) + zebra_vxlan_if_vni_table_add_update(ifp, vni_table); +} + +static void interface_bridge_vxlan_update(struct zebra_dplane_ctx *ctx, + struct interface *ifp) +{ + struct zebra_if *zif = ifp->info; + const struct zebra_dplane_bridge_vlan_info *bvinfo; + + if (dplane_ctx_get_ifp_no_afspec(ctx)) + return; + + if (IS_ZEBRA_VXLAN_IF_SVD(zif)) + interface_bridge_vxlan_vlan_vni_map_update(ctx, ifp); + + if (dplane_ctx_get_ifp_no_bridge_vlan_info(ctx)) + return; + + bvinfo = dplane_ctx_get_ifp_bridge_vlan_info(ctx); + + if (!(bvinfo->flags & DPLANE_BRIDGE_VLAN_INFO_PVID)) + return; + + if (IS_ZEBRA_DEBUG_DPLANE) + zlog_debug("Access VLAN %u for VxLAN IF %s(%u)", bvinfo->vid, + ifp->name, ifp->ifindex); + + zebra_l2_vxlanif_update_access_vlan(ifp, bvinfo->vid); +} + +static void interface_bridge_vlan_update(struct zebra_dplane_ctx *ctx, + struct interface *ifp) +{ + struct zebra_if *zif = ifp->info; + const struct zebra_dplane_bridge_vlan_info_array *bvarray; + struct zebra_dplane_bridge_vlan_info bvinfo; + bitfield_t old_vlan_bitmap; + uint16_t vid_range_start = 0; + int32_t i; + + /* cache the old bitmap addrs */ + old_vlan_bitmap = zif->vlan_bitmap; + /* create a new bitmap space for re-eval */ + bf_init(zif->vlan_bitmap, IF_VLAN_BITMAP_MAX); + + /* Could we have multiple bridge vlan infos? */ + bvarray = dplane_ctx_get_ifp_bridge_vlan_info_array(ctx); + if (!bvarray) + return; + + for (i = 0; i < bvarray->count; i++) { + bvinfo = bvarray->array[i]; + + if (bvinfo.flags & DPLANE_BRIDGE_VLAN_INFO_RANGE_BEGIN) { + vid_range_start = bvinfo.vid; + continue; + } + + if (!(bvinfo.flags & DPLANE_BRIDGE_VLAN_INFO_RANGE_END)) + vid_range_start = bvinfo.vid; + + zebra_vlan_bitmap_compute(ifp, vid_range_start, bvinfo.vid); + } + + zebra_vlan_mbr_re_eval(ifp, old_vlan_bitmap); + bf_free(old_vlan_bitmap); +} + +static void interface_bridge_handling(struct zebra_dplane_ctx *ctx, + struct interface *ifp, + enum zebra_iftype zif_type) +{ + struct zebra_if *zif; + + if (!ifp) { + zlog_warn("Cannot find bridge if %s(%u)", + dplane_ctx_get_ifname(ctx), + dplane_ctx_get_ifindex(ctx)); + return; + } + + if (IS_ZEBRA_IF_VXLAN(ifp)) + return interface_bridge_vxlan_update(ctx, ifp); + + /* + * build vlan bitmap associated with this interface if that + * device type is interested in the vlans + */ + zif = ifp->info; + if (bf_is_inited(zif->vlan_bitmap)) + interface_bridge_vlan_update(ctx, ifp); +} + +static void zebra_if_dplane_ifp_handling(struct zebra_dplane_ctx *ctx) +{ + enum dplane_op_e op = dplane_ctx_get_op(ctx); + const char *name = dplane_ctx_get_ifname(ctx); + ns_id_t ns_id = dplane_ctx_get_ns_id(ctx); + ifindex_t ifindex = dplane_ctx_get_ifindex(ctx); + ifindex_t bond_ifindex = dplane_ctx_get_ifp_bond_ifindex(ctx); + uint32_t tableid = dplane_ctx_get_ifp_table_id(ctx); + enum zebra_iftype zif_type = dplane_ctx_get_ifp_zif_type(ctx); + struct interface *ifp; + struct zebra_ns *zns; + + zns = zebra_ns_lookup(ns_id); + if (!zns) { + zlog_err("Where is our namespace?"); + return; + } + + if (IS_ZEBRA_DEBUG_DPLANE) + zlog_debug("%s for %s(%u)", dplane_op2str(op), name, ifindex); + + ifp = if_lookup_by_name_per_ns(zns, name); + if (op == DPLANE_OP_INTF_DELETE) { + /* Delete interface notification from kernel */ + if (ifp == NULL) { + if (IS_ZEBRA_DEBUG_EVENT) + zlog_debug( + "Delete LINK received for unknown interface %s(%u)", + name, ifindex); + return; + } + + if (IS_ZEBRA_IF_BOND(ifp)) + zebra_l2if_update_bond(ifp, false); + if (IS_ZEBRA_IF_BOND_SLAVE(ifp)) + zebra_l2if_update_bond_slave(ifp, bond_ifindex, false); + /* Special handling for bridge or VxLAN interfaces. */ + if (IS_ZEBRA_IF_BRIDGE(ifp)) + zebra_l2_bridge_del(ifp); + else if (IS_ZEBRA_IF_VXLAN(ifp)) + zebra_l2_vxlanif_del(ifp); + + if_delete_update(&ifp); + + if (zif_type == ZEBRA_IF_VRF && !vrf_is_backend_netns()) + interface_vrf_change(op, ifindex, name, tableid, ns_id); + } else { + ifindex_t master_ifindex, bridge_ifindex, bond_ifindex, + link_ifindex; + enum zebra_slave_iftype zif_slave_type; + uint8_t bypass; + uint64_t flags; + vrf_id_t vrf_id; + uint32_t mtu; + ns_id_t link_nsid; + struct zebra_if *zif; + bool protodown, protodown_set, startup; + uint32_t rc_bitfield; + uint8_t old_hw_addr[INTERFACE_HWADDR_MAX]; + char *desc; + uint8_t family; + + /* If VRF, create or update the VRF structure itself. */ + if (zif_type == ZEBRA_IF_VRF && !vrf_is_backend_netns()) + interface_vrf_change(op, ifindex, name, tableid, ns_id); + + master_ifindex = dplane_ctx_get_ifp_master_ifindex(ctx); + zif_slave_type = dplane_ctx_get_ifp_zif_slave_type(ctx); + bridge_ifindex = dplane_ctx_get_ifp_bridge_ifindex(ctx); + bond_ifindex = dplane_ctx_get_ifp_bond_ifindex(ctx); + bypass = dplane_ctx_get_ifp_bypass(ctx); + flags = dplane_ctx_get_ifp_flags(ctx); + vrf_id = dplane_ctx_get_ifp_vrf_id(ctx); + mtu = dplane_ctx_get_ifp_mtu(ctx); + link_ifindex = dplane_ctx_get_ifp_link_ifindex(ctx); + link_nsid = dplane_ctx_get_ifp_link_nsid(ctx); + protodown_set = dplane_ctx_get_ifp_protodown_set(ctx); + protodown = dplane_ctx_get_ifp_protodown(ctx); + rc_bitfield = dplane_ctx_get_ifp_rc_bitfield(ctx); + startup = dplane_ctx_get_ifp_startup(ctx); + desc = dplane_ctx_get_ifp_desc(ctx); + family = dplane_ctx_get_ifp_family(ctx); + +#ifndef AF_BRIDGE + /* + * Work around to make free bsd happy at the moment + */ +#define AF_BRIDGE 7 +#endif + if (family == AF_BRIDGE) + return interface_bridge_handling(ctx, ifp, zif_type); + + if (ifp == NULL || + !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) { + /* Add interface notification from kernel */ + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug( + "RTM_NEWLINK ADD for %s(%u) vrf_id %u type %d sl_type %d master %u", + name, ifindex, vrf_id, zif_type, + zif_slave_type, master_ifindex); + + if (ifp == NULL) { + /* unknown interface */ + ifp = if_get_by_name(name, vrf_id, NULL); + } else { + /* pre-configured interface, learnt now */ + if (ifp->vrf->vrf_id != vrf_id) + if_update_to_new_vrf(ifp, vrf_id); + } + + zif = ifp->info; + + /* Update interface information. */ + set_ifindex(ifp, ifindex, zns); + ifp->flags = flags; + ifp->mtu6 = ifp->mtu = mtu; + ifp->metric = 0; + ifp->speed = kernel_get_speed(ifp, NULL); + ifp->ptm_status = ZEBRA_PTM_STATUS_UNKNOWN; + ifp->txqlen = dplane_ctx_get_intf_txqlen(ctx); + + /* Set interface type */ + zebra_if_set_ziftype(ifp, zif_type, zif_slave_type); + if (IS_ZEBRA_IF_VRF(ifp)) + SET_FLAG(ifp->status, + ZEBRA_INTERFACE_VRF_LOOPBACK); + + /* Update link. */ + zebra_if_update_link(ifp, link_ifindex, link_nsid); + + ifp->ll_type = dplane_ctx_get_ifp_zltype(ctx); + interface_update_hw_addr(ctx, ifp); + + /* Inform clients, install any configured addresses. */ + if_add_update(ifp); + + /* + * Extract and save L2 interface information, take + * additional actions. + */ + interface_update_l2info(ctx, ifp, zif_type, 1, + link_nsid); + if (IS_ZEBRA_IF_BOND(ifp)) + zebra_l2if_update_bond(ifp, true); + if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp)) + zebra_l2if_update_bridge_slave( + ifp, bridge_ifindex, ns_id, + ZEBRA_BRIDGE_NO_ACTION); + else if (IS_ZEBRA_IF_BOND_SLAVE(ifp)) + zebra_l2if_update_bond_slave(ifp, bond_ifindex, + !!bypass); + + if (protodown_set) { + interface_if_protodown(ifp, protodown, + rc_bitfield); + if (startup) + if_sweep_protodown(zif); + } + + if (IS_ZEBRA_IF_BRIDGE(ifp)) { + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug( + "RTM_NEWLINK ADD for %s(%u), vlan-aware %d", + name, ifp->ifindex, + IS_ZEBRA_IF_BRIDGE_VLAN_AWARE( + zif)); + } + } else if (ifp->vrf->vrf_id != vrf_id) { + /* VRF change for an interface. */ + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug( + "RTM_NEWLINK vrf-change for %s(%u) vrf_id %u -> %u", + name, ifp->ifindex, ifp->vrf->vrf_id, + vrf_id); + + if_handle_vrf_change(ifp, vrf_id); + } else { + bool was_bridge_slave, was_bond_slave; + uint8_t chgflags = ZEBRA_BRIDGE_NO_ACTION; + + zif = ifp->info; + + /* Interface update. */ + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug( + "RTM_NEWLINK update for %s(%u) sl_type %d master %u", + name, ifp->ifindex, zif_slave_type, + master_ifindex); + + set_ifindex(ifp, ifindex, zns); + ifp->mtu6 = ifp->mtu = mtu; + ifp->metric = 0; + ifp->txqlen = dplane_ctx_get_intf_txqlen(ctx); + + /* + * Update interface type - NOTE: Only slave_type can + * change. + */ + was_bridge_slave = IS_ZEBRA_IF_BRIDGE_SLAVE(ifp); + was_bond_slave = IS_ZEBRA_IF_BOND_SLAVE(ifp); + zebra_if_set_ziftype(ifp, zif_type, zif_slave_type); + + memcpy(old_hw_addr, ifp->hw_addr, INTERFACE_HWADDR_MAX); + + /* Update link. */ + zebra_if_update_link(ifp, link_ifindex, link_nsid); + + ifp->ll_type = dplane_ctx_get_ifp_zltype(ctx); + interface_update_hw_addr(ctx, ifp); + + if (protodown_set) + interface_if_protodown(ifp, protodown, + rc_bitfield); + + if (if_is_no_ptm_operative(ifp)) { + bool is_up = if_is_operative(ifp); + + ifp->flags = flags; + if (!if_is_no_ptm_operative(ifp) || + CHECK_FLAG(zif->flags, + ZIF_FLAG_PROTODOWN)) { + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug( + "Intf %s(%u) has gone DOWN", + name, ifp->ifindex); + if_down(ifp); + rib_update(RIB_UPDATE_KERNEL); + } else if (if_is_operative(ifp)) { + bool mac_updated = false; + + /* + * Must notify client daemons of new + * interface status. + */ + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug( + "Intf %s(%u) PTM up, notifying clients", + name, ifp->ifindex); + if_up(ifp, !is_up); + + /* + * Update EVPN VNI when SVI MAC change + */ + if (memcmp(old_hw_addr, ifp->hw_addr, + INTERFACE_HWADDR_MAX)) + mac_updated = true; + if (IS_ZEBRA_IF_VLAN(ifp) && + mac_updated) { + struct interface *link_if; + + link_if = if_lookup_by_index_per_ns( + zebra_ns_lookup( + NS_DEFAULT), + link_ifindex); + if (link_if) + zebra_vxlan_svi_up( + ifp, link_if); + } else if (mac_updated && + IS_ZEBRA_IF_BRIDGE(ifp)) { + zlog_debug( + "Intf %s(%u) bridge changed MAC address", + name, ifp->ifindex); + chgflags = + ZEBRA_BRIDGE_MASTER_MAC_CHANGE; + } + } + } else { + ifp->flags = flags; + if (if_is_operative(ifp) && + !CHECK_FLAG(zif->flags, + ZIF_FLAG_PROTODOWN)) { + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug( + "Intf %s(%u) has come UP", + name, ifp->ifindex); + if_up(ifp, true); + if (IS_ZEBRA_IF_BRIDGE(ifp)) + chgflags = + ZEBRA_BRIDGE_MASTER_UP; + } else { + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug( + "Intf %s(%u) has gone DOWN", + name, ifp->ifindex); + if_down(ifp); + rib_update(RIB_UPDATE_KERNEL); + } + } + + /* + * Extract and save L2 interface information, take + * additional actions. + */ + interface_update_l2info(ctx, ifp, zif_type, 0, + link_nsid); + if (IS_ZEBRA_IF_BRIDGE(ifp)) + zebra_l2if_update_bridge(ifp, chgflags); + if (IS_ZEBRA_IF_BOND(ifp)) + zebra_l2if_update_bond(ifp, true); + if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp) || was_bridge_slave) + zebra_l2if_update_bridge_slave( + ifp, bridge_ifindex, ns_id, chgflags); + else if (IS_ZEBRA_IF_BOND_SLAVE(ifp) || was_bond_slave) + zebra_l2if_update_bond_slave(ifp, bond_ifindex, + !!bypass); + if (IS_ZEBRA_IF_BRIDGE(ifp)) { + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug( + "RTM_NEWLINK update for %s(%u), vlan-aware %d", + name, ifp->ifindex, + IS_ZEBRA_IF_BRIDGE_VLAN_AWARE( + zif)); + } + } + + zif = ifp->info; + if (zif) { + XFREE(MTYPE_ZIF_DESC, zif->desc); + if (desc[0]) + zif->desc = XSTRDUP(MTYPE_ZIF_DESC, desc); + } + } +} + void zebra_if_dplane_result(struct zebra_dplane_ctx *ctx) { struct zebra_ns *zns; @@ -1509,83 +2285,22 @@ void zebra_if_dplane_result(struct zebra_dplane_ctx *ctx) } ifp = if_lookup_by_index_per_ns(zns, ifindex); - if (ifp == NULL) { - if (op != DPLANE_OP_INTF_NETCONFIG || - (ifindex != -1 && ifindex != -2)) { - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug( - "%s: can't find ifp at nsid %u index %d", - __func__, ns_id, ifindex); - - return; - } - } - switch (op) { - case DPLANE_OP_INTF_ADDR_ADD: - case DPLANE_OP_INTF_ADDR_DEL: + if (op == DPLANE_OP_INTF_ADDR_ADD || op == DPLANE_OP_INTF_ADDR_DEL) { zebra_if_addr_update_ctx(ctx, ifp); - break; - - case DPLANE_OP_INTF_INSTALL: - case DPLANE_OP_INTF_UPDATE: - case DPLANE_OP_INTF_DELETE: - zebra_if_update_ctx(ctx, ifp); - break; - - case DPLANE_OP_INTF_NETCONFIG: + } else if (op == DPLANE_OP_INTF_INSTALL || + op == DPLANE_OP_INTF_UPDATE || op == DPLANE_OP_INTF_DELETE) { + /* + * Queued from the dplane means it is something + * that we need to handle( create/delete the + * interface as needed ) + */ + if (dp_res == ZEBRA_DPLANE_REQUEST_QUEUED) + zebra_if_dplane_ifp_handling(ctx); + else + zebra_if_update_ctx(ctx, ifp); + } else if (op == DPLANE_OP_INTF_NETCONFIG) { zebra_if_netconf_update_ctx(ctx, ifp, ifindex); - break; - - case DPLANE_OP_ROUTE_INSTALL: - case DPLANE_OP_ROUTE_UPDATE: - case DPLANE_OP_ROUTE_DELETE: - case DPLANE_OP_NH_DELETE: - case DPLANE_OP_NH_INSTALL: - case DPLANE_OP_NH_UPDATE: - case DPLANE_OP_ROUTE_NOTIFY: - case DPLANE_OP_LSP_INSTALL: - case DPLANE_OP_LSP_UPDATE: - case DPLANE_OP_LSP_DELETE: - case DPLANE_OP_LSP_NOTIFY: - case DPLANE_OP_PW_INSTALL: - case DPLANE_OP_PW_UNINSTALL: - case DPLANE_OP_SYS_ROUTE_ADD: - case DPLANE_OP_SYS_ROUTE_DELETE: - case DPLANE_OP_ADDR_INSTALL: - case DPLANE_OP_ADDR_UNINSTALL: - case DPLANE_OP_MAC_INSTALL: - case DPLANE_OP_MAC_DELETE: - case DPLANE_OP_NEIGH_INSTALL: - case DPLANE_OP_NEIGH_UPDATE: - case DPLANE_OP_NEIGH_DELETE: - case DPLANE_OP_NEIGH_IP_INSTALL: - case DPLANE_OP_NEIGH_IP_DELETE: - case DPLANE_OP_VTEP_ADD: - case DPLANE_OP_VTEP_DELETE: - case DPLANE_OP_RULE_ADD: - case DPLANE_OP_RULE_DELETE: - case DPLANE_OP_RULE_UPDATE: - case DPLANE_OP_NEIGH_DISCOVER: - case DPLANE_OP_BR_PORT_UPDATE: - case DPLANE_OP_NONE: - case DPLANE_OP_IPTABLE_ADD: - case DPLANE_OP_IPTABLE_DELETE: - case DPLANE_OP_IPSET_ADD: - case DPLANE_OP_IPSET_DELETE: - case DPLANE_OP_IPSET_ENTRY_ADD: - case DPLANE_OP_IPSET_ENTRY_DELETE: - case DPLANE_OP_NEIGH_TABLE_UPDATE: - case DPLANE_OP_GRE_SET: - case DPLANE_OP_TC_QDISC_INSTALL: - case DPLANE_OP_TC_QDISC_UNINSTALL: - case DPLANE_OP_TC_CLASS_ADD: - case DPLANE_OP_TC_CLASS_DELETE: - case DPLANE_OP_TC_CLASS_UPDATE: - case DPLANE_OP_TC_FILTER_ADD: - case DPLANE_OP_TC_FILTER_DELETE: - case DPLANE_OP_TC_FILTER_UPDATE: - break; /* should never hit here */ } } @@ -1624,6 +2339,12 @@ static void connected_dump_vty(struct vty *vty, json_object *json, else if (CHECK_FLAG(connected->flags, ZEBRA_IFA_SECONDARY)) vty_out(vty, " secondary"); + if (json) + json_object_boolean_add(json_addr, "noPrefixRoute", + CHECK_FLAG(connected->flags, ZEBRA_IFA_NOPREFIXROUTE)); + else if (CHECK_FLAG(connected->flags, ZEBRA_IFA_NOPREFIXROUTE)) + vty_out(vty, " noprefixroute"); + if (json) json_object_boolean_add( json_addr, "unnumbered", @@ -1700,9 +2421,6 @@ static const char *zebra_ziftype_2str(enum zebra_iftype zif_type) case ZEBRA_IF_BOND: return "bond"; - case ZEBRA_IF_BOND_SLAVE: - return "bond_slave"; - case ZEBRA_IF_MACVLAN: return "macvlan"; @@ -1776,34 +2494,27 @@ static void ifs_dump_brief_vty(struct vty *vty, struct vrf *vrf) } uint32_t v6_list_size = 0; - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) { + frr_each (if_connected, ifp->connected, connected) { if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL) && (connected->address->family == AF_INET6)) v6_list_size++; } - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) { - if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL) - && !CHECK_FLAG(connected->flags, - ZEBRA_IFA_SECONDARY) - && (connected->address->family == AF_INET6)) { + frr_each (if_connected, ifp->connected, connected) { + if (!CHECK_FLAG(connected->flags, ZEBRA_IFA_SECONDARY) && + (connected->address->family == AF_INET6)) { p = connected->address; - /* Don't print link local pfx */ - if (!IN6_IS_ADDR_LINKLOCAL(&p->u.prefix6)) { - if (first_pfx_printed) { - /* padding to prepare row only - * for ip addr */ - vty_out(vty, "%-40s", ""); - if (v6_list_size > 1) - vty_out(vty, "+ "); - vty_out(vty, "%pFX\n", p); - } else { - if (v6_list_size > 1) - vty_out(vty, "+ "); - vty_out(vty, "%pFX\n", p); - } - first_pfx_printed = true; - break; + if (first_pfx_printed) { + vty_out(vty, "%-40s", ""); + if (v6_list_size > 1) + vty_out(vty, "+ "); + vty_out(vty, "%pFX\n", p); + } else { + if (v6_list_size > 1) + vty_out(vty, "+ "); + vty_out(vty, "%pFX\n", p); } + first_pfx_printed = true; + break; } } if (!first_pfx_printed) @@ -1815,7 +2526,6 @@ static void ifs_dump_brief_vty(struct vty *vty, struct vrf *vrf) static void ifs_dump_brief_vty_json(json_object *json, struct vrf *vrf) { struct connected *connected; - struct listnode *node; struct interface *ifp; FOR_ALL_INTERFACES (vrf, ifp) { @@ -1831,13 +2541,8 @@ static void ifs_dump_brief_vty_json(json_object *json, struct vrf *vrf) json_addrs = json_object_new_array(); json_object_object_add(json_if, "addresses", json_addrs); - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) { - if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL) - && !CHECK_FLAG(connected->flags, - ZEBRA_IFA_SECONDARY) - && !(connected->address->family == AF_INET6 - && IN6_IS_ADDR_LINKLOCAL( - &connected->address->u.prefix6))) { + frr_each (if_connected, ifp->connected, connected) { + if (!CHECK_FLAG(connected->flags, ZEBRA_IFA_SECONDARY)) { char buf[PREFIX2STR_BUFFER]; json_array_string_add( @@ -1998,8 +2703,8 @@ static void if_dump_vty(struct vty *vty, struct interface *ifp) return; } - vty_out(vty, " index %d metric %d mtu %d speed %u ", ifp->ifindex, - ifp->metric, ifp->mtu, ifp->speed); + vty_out(vty, " index %d metric %d mtu %d speed %u txqlen %u", + ifp->ifindex, ifp->metric, ifp->mtu, ifp->speed, ifp->txqlen); if (ifp->mtu6 != ifp->mtu) vty_out(vty, "mtu6 %d ", ifp->mtu6); vty_out(vty, "\n flags: %s\n", if_flag_dump(ifp->flags)); @@ -2044,9 +2749,8 @@ static void if_dump_vty(struct vty *vty, struct interface *ifp) connected_dump_vty(vty, NULL, connected); } - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) { - if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL) - && (connected->address->family == AF_INET6)) + frr_each (if_connected, ifp->connected, connected) { + if (connected->address->family == AF_INET6) connected_dump_vty(vty, NULL, connected); } @@ -2353,7 +3057,7 @@ static void if_dump_vty_json(struct vty *vty, struct interface *ifp, json_object_string_add(json_if, "lastLinkDown", zebra_if->down_last); - zebra_ptm_show_status(vty, json, ifp); + zebra_ptm_show_status(vty, json_if, ifp); json_object_string_add(json_if, "vrfName", ifp->vrf->name); @@ -2386,6 +3090,7 @@ static void if_dump_vty_json(struct vty *vty, struct interface *ifp, if (ifp->mtu6 != ifp->mtu) json_object_int_add(json_if, "mtu6", ifp->mtu6); json_object_int_add(json_if, "speed", ifp->speed); + json_object_int_add(json_if, "txqlen", ifp->txqlen); json_object_string_add(json_if, "flags", if_flag_dump(ifp->flags)); /* Hardware address. */ @@ -2420,9 +3125,8 @@ static void if_dump_vty_json(struct vty *vty, struct interface *ifp, connected_dump_vty(vty, json_addrs, connected); } - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) { - if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL) - && (connected->address->family == AF_INET6)) + frr_each (if_connected, ifp->connected, connected) { + if (connected->address->family == AF_INET6) connected_dump_vty(vty, json_addrs, connected); } @@ -3006,23 +3710,20 @@ DEFUN (multicast, DEFPY (mpls, mpls_cmd, - "[no] mpls enable", + "[no] mpls <enable$on|disable$off>", NO_STR MPLS_STR - "Set mpls to be on for the interface\n") + "Set mpls to be on for the interface\n" + "Set mpls to be off for the interface\n") { - VTY_DECLVAR_CONTEXT(interface, ifp); - struct zebra_if *if_data = ifp->info; - - if (no) { - dplane_intf_mpls_modify_state(ifp, false); - if_data->mpls = IF_ZEBRA_DATA_UNSPEC; - } else { - dplane_intf_mpls_modify_state(ifp, true); - if_data->mpls = IF_ZEBRA_DATA_ON; - } + if (!no) + nb_cli_enqueue_change(vty, "./frr-zebra:zebra/mpls", + NB_OP_CREATE, on ? "true" : "false"); + else + nb_cli_enqueue_change(vty, "./frr-zebra:zebra/mpls", + NB_OP_DESTROY, NULL); - return CMD_SUCCESS; + return nb_cli_apply_changes(vty, NULL); } int if_multicast_unset(struct interface *ifp) @@ -4100,11 +4801,11 @@ static int ag_iter_cb(const struct lyd_node *dnode, void *arg) void cli_show_legacy_admin_group(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - if (!yang_dnode_exists(dnode, "./legacy-admin-group")) + if (!yang_dnode_exists(dnode, "legacy-admin-group")) return; vty_out(vty, " admin-group 0x%x\n", - yang_dnode_get_uint32(dnode, "./legacy-admin-group")); + yang_dnode_get_uint32(dnode, "legacy-admin-group")); } void cli_show_affinity_mode(struct vty *vty, const struct lyd_node *dnode, @@ -4121,11 +4822,11 @@ void cli_show_affinity_mode(struct vty *vty, const struct lyd_node *dnode, void cli_show_affinity(struct vty *vty, const struct lyd_node *dnode, bool show_defaults) { - if (!yang_dnode_exists(dnode, "./affinity")) + if (!yang_dnode_exists(dnode, "affinity")) return; vty_out(vty, " affinity"); - yang_dnode_iterate(ag_iter_cb, vty, dnode, "./affinity"); + yang_dnode_iterate(ag_iter_cb, vty, dnode, "affinity"); vty_out(vty, "\n"); } @@ -4167,7 +4868,7 @@ int if_ip_address_install(struct interface *ifp, struct prefix *prefix, ifc->label = XSTRDUP(MTYPE_CONNECTED_LABEL, label); /* Add to linked list. */ - listnode_add(ifp->connected, ifc); + if_connected_add_tail(ifp->connected, ifc); } /* This address is configured from zebra. */ @@ -4262,7 +4963,7 @@ static int ip_address_install(struct vty *vty, struct interface *ifp, ifc->label = XSTRDUP(MTYPE_CONNECTED_LABEL, label); /* Add to linked list. */ - listnode_add(ifp->connected, ifc); + if_connected_add_tail(ifp->connected, ifc); } /* This address is configured from zebra. */ @@ -4324,7 +5025,7 @@ int if_ip_address_uinstall(struct interface *ifp, struct prefix *prefix) /* This is not real address or interface is not active. */ if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED) || !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) { - listnode_delete(ifp->connected, ifc); + if_connected_del(ifp->connected, ifc); connected_free(&ifc); return CMD_WARNING_CONFIG_FAILED; } @@ -4387,7 +5088,7 @@ static int ip_address_uninstall(struct vty *vty, struct interface *ifp, /* This is not real address or interface is not active. */ if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED) || !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) { - listnode_delete(ifp->connected, ifc); + if_connected_del(ifp->connected, ifc); connected_free(&ifc); return CMD_WARNING_CONFIG_FAILED; } @@ -4525,7 +5226,7 @@ int if_ipv6_address_install(struct interface *ifp, struct prefix *prefix, ifc->label = XSTRDUP(MTYPE_CONNECTED_LABEL, label); /* Add to linked list. */ - listnode_add(ifp->connected, ifc); + if_connected_add_tail(ifp->connected, ifc); } /* This address is configured from zebra. */ @@ -4598,7 +5299,7 @@ static int ipv6_address_install(struct vty *vty, struct interface *ifp, ifc->label = XSTRDUP(MTYPE_CONNECTED_LABEL, label); /* Add to linked list. */ - listnode_add(ifp->connected, ifc); + if_connected_add_tail(ifp->connected, ifc); } /* This address is configured from zebra. */ @@ -4631,20 +5332,6 @@ static int ipv6_address_install(struct vty *vty, struct interface *ifp, return CMD_SUCCESS; } -/* Return true if an ipv6 address is configured on ifp */ -int ipv6_address_configured(struct interface *ifp) -{ - struct connected *connected; - struct listnode *node; - - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) - if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL) - && (connected->address->family == AF_INET6)) - return 1; - - return 0; -} - static int ipv6_address_uninstall(struct vty *vty, struct interface *ifp, const char *addr_str, const char *peer_str, const char *label) @@ -4677,7 +5364,7 @@ static int ipv6_address_uninstall(struct vty *vty, struct interface *ifp, /* This is not real address or interface is not active. */ if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED) || !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) { - listnode_delete(ifp->connected, ifc); + if_connected_del(ifp->connected, ifc); connected_free(&ifc); return CMD_WARNING_CONFIG_FAILED; } @@ -4794,7 +5481,6 @@ static int if_config_write(struct vty *vty) RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) FOR_ALL_INTERFACES (vrf, ifp) { struct zebra_if *if_data; - struct listnode *addrnode; struct connected *ifc; struct prefix *p; @@ -4822,8 +5508,7 @@ static int if_config_write(struct vty *vty) ZEBRA_INTERFACE_LINKDETECTION)) vty_out(vty, " no link-detect\n"); - for (ALL_LIST_ELEMENTS_RO(ifp->connected, addrnode, - ifc)) { + frr_each (if_connected, ifp->connected, ifc) { if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED)) { char buf[INET6_ADDRSTRLEN]; @@ -4859,8 +5544,12 @@ static int if_config_write(struct vty *vty) IF_ZEBRA_DATA_ON ? "" : "no "); - if (if_data->mpls == IF_ZEBRA_DATA_ON) + + if (if_data->mpls_config == IF_ZEBRA_DATA_ON) vty_out(vty, " mpls enable\n"); + else if (if_data->mpls_config == + IF_ZEBRA_DATA_OFF) + vty_out(vty, " mpls disable\n"); } hook_call(zebra_if_config_wr, vty, ifp); @@ -4882,11 +5571,6 @@ void zebra_if_init(void) /* Install configuration write function. */ if_cmd_init(if_config_write); install_node(&link_params_node); - /* - * This is *intentionally* setting this to NULL, signaling - * that interface creation for zebra acts differently - */ - if_zapi_callbacks(NULL, NULL, NULL, NULL); install_element(VIEW_NODE, &show_interface_cmd); install_element(VIEW_NODE, &show_interface_vrf_all_cmd); diff --git a/zebra/interface.h b/zebra/interface.h index e5545d6ba0..62de2abc80 100644 --- a/zebra/interface.h +++ b/zebra/interface.h @@ -39,7 +39,6 @@ enum zebra_iftype { ZEBRA_IF_MACVLAN, /* MAC VLAN interface*/ ZEBRA_IF_VETH, /* VETH interface*/ ZEBRA_IF_BOND, /* Bond */ - ZEBRA_IF_BOND_SLAVE, /* Bond */ ZEBRA_IF_GRE, /* GRE interface */ }; @@ -114,6 +113,9 @@ struct zebra_if { /* MPLS status. */ bool mpls; + /* MPLS configuration */ + uint8_t mpls_config; + /* Linkdown status */ bool linkdown, linkdownv6; @@ -281,7 +283,6 @@ extern void if_refresh(struct interface *); extern void if_flags_update(struct interface *, uint64_t); extern int if_subnet_add(struct interface *, struct connected *); extern int if_subnet_delete(struct interface *, struct connected *); -extern int ipv6_address_configured(struct interface *ifp); extern void if_handle_vrf_change(struct interface *ifp, vrf_id_t vrf_id); extern void zebra_if_update_link(struct interface *ifp, ifindex_t link_ifindex, ns_id_t ns_id); diff --git a/zebra/ioctl.c b/zebra/ioctl.c index 8da1ae37c6..a35784cd36 100644 --- a/zebra/ioctl.c +++ b/zebra/ioctl.c @@ -6,6 +6,8 @@ #include <zebra.h> +#include <sys/ioctl.h> + #include "linklist.h" #include "if.h" #include "prefix.h" diff --git a/zebra/irdp_interface.c b/zebra/irdp_interface.c index 253e6a8dd6..591236d680 100644 --- a/zebra/irdp_interface.c +++ b/zebra/irdp_interface.c @@ -87,12 +87,12 @@ static const char *inet_2a(uint32_t a, char *b, size_t b_len) static struct prefix *irdp_get_prefix(struct interface *ifp) { - struct listnode *node; struct connected *ifc; - if (ifp->connected) - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) + frr_each (if_connected, ifp->connected, ifc) { + if (ifc->address->family == AF_INET) return ifc->address; + } return NULL; } @@ -198,7 +198,6 @@ static void irdp_if_start(struct interface *ifp, int multicast, { struct zebra_if *zi = ifp->info; struct irdp_interface *irdp = zi->irdp; - struct listnode *node; struct connected *ifc; uint32_t timer, seed; @@ -247,11 +246,12 @@ static void irdp_if_start(struct interface *ifp, int multicast, /* The spec suggests this for randomness */ seed = 0; - if (ifp->connected) - for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { + frr_each (if_connected, ifp->connected, ifc) { + if (ifc->address->family == AF_INET) { seed = ifc->address->u.prefix4.s_addr; break; } + } srandom(seed); timer = (frr_weak_random() % IRDP_DEFAULT_INTERVAL) + 1; diff --git a/zebra/irdp_main.c b/zebra/irdp_main.c index 6548790e9a..349ae1a191 100644 --- a/zebra/irdp_main.c +++ b/zebra/irdp_main.c @@ -197,7 +197,6 @@ void irdp_send_thread(struct event *t_advert) struct zebra_if *zi = ifp->info; struct irdp_interface *irdp = zi->irdp; struct prefix *p; - struct listnode *node, *nnode; struct connected *ifc; if (!irdp) @@ -205,16 +204,15 @@ void irdp_send_thread(struct event *t_advert) irdp->flags &= ~IF_SOLICIT; - if (ifp->connected) - for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, ifc)) { - p = ifc->address; + frr_each (if_connected, ifp->connected, ifc) { + p = ifc->address; - if (p->family != AF_INET) - continue; + if (p->family != AF_INET) + continue; - irdp_advertisement(ifp, p); - irdp->irdp_sent++; - } + irdp_advertisement(ifp, p); + irdp->irdp_sent++; + } tmp = irdp->MaxAdvertInterval - irdp->MinAdvertInterval; timer = frr_weak_random() % (tmp + 1); @@ -237,7 +235,6 @@ void irdp_advert_off(struct interface *ifp) { struct zebra_if *zi = ifp->info; struct irdp_interface *irdp = zi->irdp; - struct listnode *node, *nnode; int i; struct connected *ifc; struct prefix *p; @@ -247,19 +244,21 @@ void irdp_advert_off(struct interface *ifp) EVENT_OFF(irdp->t_advertise); - if (ifp->connected) - for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, ifc)) { - p = ifc->address; + frr_each (if_connected, ifp->connected, ifc) { + p = ifc->address; - /* Output some packets with Lifetime 0 - we should add a wait... - */ + if (p->family != AF_INET) + continue; - for (i = 0; i < IRDP_LAST_ADVERT_MESSAGES; i++) { - irdp->irdp_sent++; - irdp_advertisement(ifp, p); - } + /* Output some packets with Lifetime 0 + we should add a wait... + */ + + for (i = 0; i < IRDP_LAST_ADVERT_MESSAGES; i++) { + irdp->irdp_sent++; + irdp_advertisement(ifp, p); } + } } diff --git a/zebra/kernel_netlink.c b/zebra/kernel_netlink.c index 78b1dfe276..8a64a1ea48 100644 --- a/zebra/kernel_netlink.c +++ b/zebra/kernel_netlink.c @@ -4,8 +4,12 @@ */ #include <zebra.h> +#include <fcntl.h> #ifdef HAVE_NETLINK +#include <linux/netlink.h> +#include <linux/rtnetlink.h> +#include <linux/filter.h> #include "linklist.h" #include "if.h" @@ -35,6 +39,7 @@ #include "zebra/tc_netlink.h" #include "zebra/netconf_netlink.h" #include "zebra/zebra_errors.h" +#include "zebra/ge_netlink.h" #ifndef SO_RCVBUFFORCE #define SO_RCVBUFFORCE (33) @@ -76,43 +81,48 @@ */ #define NL_DEFAULT_BATCH_SEND_THRESHOLD (15 * NL_PKT_BUF_SIZE) -static const struct message nlmsg_str[] = {{RTM_NEWROUTE, "RTM_NEWROUTE"}, - {RTM_DELROUTE, "RTM_DELROUTE"}, - {RTM_GETROUTE, "RTM_GETROUTE"}, - {RTM_NEWLINK, "RTM_NEWLINK"}, - {RTM_SETLINK, "RTM_SETLINK"}, - {RTM_DELLINK, "RTM_DELLINK"}, - {RTM_GETLINK, "RTM_GETLINK"}, - {RTM_NEWADDR, "RTM_NEWADDR"}, - {RTM_DELADDR, "RTM_DELADDR"}, - {RTM_GETADDR, "RTM_GETADDR"}, - {RTM_NEWNEIGH, "RTM_NEWNEIGH"}, - {RTM_DELNEIGH, "RTM_DELNEIGH"}, - {RTM_GETNEIGH, "RTM_GETNEIGH"}, - {RTM_NEWRULE, "RTM_NEWRULE"}, - {RTM_DELRULE, "RTM_DELRULE"}, - {RTM_GETRULE, "RTM_GETRULE"}, - {RTM_NEWNEXTHOP, "RTM_NEWNEXTHOP"}, - {RTM_DELNEXTHOP, "RTM_DELNEXTHOP"}, - {RTM_GETNEXTHOP, "RTM_GETNEXTHOP"}, - {RTM_NEWNETCONF, "RTM_NEWNETCONF"}, - {RTM_DELNETCONF, "RTM_DELNETCONF"}, - {RTM_NEWTUNNEL, "RTM_NEWTUNNEL"}, - {RTM_DELTUNNEL, "RTM_DELTUNNEL"}, - {RTM_GETTUNNEL, "RTM_GETTUNNEL"}, - {RTM_NEWQDISC, "RTM_NEWQDISC"}, - {RTM_DELQDISC, "RTM_DELQDISC"}, - {RTM_GETQDISC, "RTM_GETQDISC"}, - {RTM_NEWTCLASS, "RTM_NEWTCLASS"}, - {RTM_DELTCLASS, "RTM_DELTCLASS"}, - {RTM_GETTCLASS, "RTM_GETTCLASS"}, - {RTM_NEWTFILTER, "RTM_NEWTFILTER"}, - {RTM_DELTFILTER, "RTM_DELTFILTER"}, - {RTM_GETTFILTER, "RTM_GETTFILTER"}, - {RTM_NEWVLAN, "RTM_NEWVLAN"}, - {RTM_DELVLAN, "RTM_DELVLAN"}, - {RTM_GETVLAN, "RTM_GETVLAN"}, - {0}}; +static const struct message nlmsg_str[] = { + { RTM_NEWROUTE, "RTM_NEWROUTE" }, + { RTM_DELROUTE, "RTM_DELROUTE" }, + { RTM_GETROUTE, "RTM_GETROUTE" }, + { RTM_NEWLINK, "RTM_NEWLINK" }, + { RTM_SETLINK, "RTM_SETLINK" }, + { RTM_DELLINK, "RTM_DELLINK" }, + { RTM_GETLINK, "RTM_GETLINK" }, + { RTM_NEWADDR, "RTM_NEWADDR" }, + { RTM_DELADDR, "RTM_DELADDR" }, + { RTM_GETADDR, "RTM_GETADDR" }, + { RTM_NEWNEIGH, "RTM_NEWNEIGH" }, + { RTM_DELNEIGH, "RTM_DELNEIGH" }, + { RTM_GETNEIGH, "RTM_GETNEIGH" }, + { RTM_NEWRULE, "RTM_NEWRULE" }, + { RTM_DELRULE, "RTM_DELRULE" }, + { RTM_GETRULE, "RTM_GETRULE" }, + { RTM_NEWNEXTHOP, "RTM_NEWNEXTHOP" }, + { RTM_DELNEXTHOP, "RTM_DELNEXTHOP" }, + { RTM_GETNEXTHOP, "RTM_GETNEXTHOP" }, + { RTM_NEWNETCONF, "RTM_NEWNETCONF" }, + { RTM_DELNETCONF, "RTM_DELNETCONF" }, + { RTM_NEWTUNNEL, "RTM_NEWTUNNEL" }, + { RTM_DELTUNNEL, "RTM_DELTUNNEL" }, + { RTM_GETTUNNEL, "RTM_GETTUNNEL" }, + { RTM_NEWQDISC, "RTM_NEWQDISC" }, + { RTM_DELQDISC, "RTM_DELQDISC" }, + { RTM_GETQDISC, "RTM_GETQDISC" }, + { RTM_NEWTCLASS, "RTM_NEWTCLASS" }, + { RTM_DELTCLASS, "RTM_DELTCLASS" }, + { RTM_GETTCLASS, "RTM_GETTCLASS" }, + { RTM_NEWTFILTER, "RTM_NEWTFILTER" }, + { RTM_DELTFILTER, "RTM_DELTFILTER" }, + { RTM_GETTFILTER, "RTM_GETTFILTER" }, + { RTM_NEWVLAN, "RTM_NEWVLAN" }, + { RTM_DELVLAN, "RTM_DELVLAN" }, + { RTM_GETVLAN, "RTM_GETVLAN" }, + { RTM_NEWCHAIN, "RTM_NEWCHAIN" }, + { RTM_DELCHAIN, "RTM_DELCHAIN" }, + { RTM_GETCHAIN, "RTM_GETCHAIN" }, + { 0 } +}; static const struct message rtproto_str[] = { {RTPROT_REDIRECT, "redirect"}, @@ -301,7 +311,7 @@ static const char *group2str(uint32_t group) /* Make socket for Linux netlink interface. */ static int netlink_socket(struct nlsock *nl, unsigned long groups, uint32_t ext_groups[], uint8_t ext_group_size, - ns_id_t ns_id) + ns_id_t ns_id, int nl_family) { int ret; struct sockaddr_nl snl; @@ -309,7 +319,7 @@ static int netlink_socket(struct nlsock *nl, unsigned long groups, int namelen; frr_with_privs(&zserv_privs) { - sock = ns_socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE, ns_id); + sock = ns_socket(AF_NETLINK, SOCK_RAW, nl_family, ns_id); if (sock < 0) { zlog_err("Can't open %s socket: %s", nl->name, safe_strerror(errno)); @@ -398,7 +408,7 @@ static int netlink_information_fetch(struct nlmsghdr *h, ns_id_t ns_id, case RTM_NEWLINK: return netlink_link_change(h, ns_id, startup); case RTM_DELLINK: - return netlink_link_change(h, ns_id, startup); + return 0; case RTM_NEWNEIGH: case RTM_DELNEIGH: case RTM_GETNEIGH: @@ -425,6 +435,12 @@ static int netlink_information_fetch(struct nlmsghdr *h, ns_id_t ns_id, case RTM_DELVLAN: return netlink_vlan_change(h, ns_id, startup); + /* Messages we may receive, but ignore */ + case RTM_NEWCHAIN: + case RTM_DELCHAIN: + case RTM_GETCHAIN: + return 0; + /* Messages handled in the dplane thread */ case RTM_NEWADDR: case RTM_DELADDR: @@ -474,6 +490,7 @@ static int dplane_netlink_information_fetch(struct nlmsghdr *h, ns_id_t ns_id, case RTM_NEWLINK: case RTM_DELLINK: + return netlink_link_change(h, ns_id, startup); default: break; @@ -740,58 +757,6 @@ void nl_attr_rtnh_end(struct nlmsghdr *n, struct rtnexthop *rtnh) rtnh->rtnh_len = (uint8_t *)NLMSG_TAIL(n) - (uint8_t *)rtnh; } -bool nl_rta_put(struct rtattr *rta, unsigned int maxlen, int type, - const void *data, int alen) -{ - struct rtattr *subrta; - int len = RTA_LENGTH(alen); - - if (RTA_ALIGN(rta->rta_len) + RTA_ALIGN(len) > maxlen) { - zlog_err("ERROR max allowed bound %d exceeded for rtattr", - maxlen); - return false; - } - subrta = (struct rtattr *)(((char *)rta) + RTA_ALIGN(rta->rta_len)); - subrta->rta_type = type; - subrta->rta_len = len; - if (alen) - memcpy(RTA_DATA(subrta), data, alen); - rta->rta_len = NLMSG_ALIGN(rta->rta_len) + RTA_ALIGN(len); - - return true; -} - -bool nl_rta_put16(struct rtattr *rta, unsigned int maxlen, int type, - uint16_t data) -{ - return nl_rta_put(rta, maxlen, type, &data, sizeof(uint16_t)); -} - -bool nl_rta_put64(struct rtattr *rta, unsigned int maxlen, int type, - uint64_t data) -{ - return nl_rta_put(rta, maxlen, type, &data, sizeof(uint64_t)); -} - -struct rtattr *nl_rta_nest(struct rtattr *rta, unsigned int maxlen, int type) -{ - struct rtattr *nest = RTA_TAIL(rta); - - if (nl_rta_put(rta, maxlen, type, NULL, 0)) - return NULL; - - nest->rta_type |= NLA_F_NESTED; - - return nest; -} - -int nl_rta_nest_end(struct rtattr *rta, struct rtattr *nest) -{ - nest->rta_len = (uint8_t *)RTA_TAIL(rta) - (uint8_t *)nest; - - return rta->rta_len; -} - const char *nl_msg_type_to_str(uint16_t msg_type) { return lookup_msg(nlmsg_str, msg_type, ""); @@ -1169,7 +1134,6 @@ int netlink_parse_info(int (*filter)(struct nlmsghdr *, ns_id_t, int), h->nlmsg_type, h->nlmsg_len, h->nlmsg_seq, h->nlmsg_pid); - /* * Ignore messages that maybe sent from * other actors besides the kernel @@ -1265,6 +1229,33 @@ int netlink_talk(int (*filter)(struct nlmsghdr *, ns_id_t, int startup), return netlink_talk_info(filter, n, &dp_info, startup); } +/* + * Synchronous version of netlink_talk_info. Converts args to suit the + * common version, which is suitable for both sync and async use. + */ +int ge_netlink_talk(int (*filter)(struct nlmsghdr *, ns_id_t, int startup), + struct nlmsghdr *n, struct zebra_ns *zns, bool startup) +{ + struct zebra_dplane_info dp_info; + + if (zns->ge_netlink_cmd.sock < 0) + return -1; + + /* Increment sequence number before capturing snapshot of ns socket + * info. + */ + zns->ge_netlink_cmd.seq = zebra_router_get_next_sequence(); + + /* Capture info in intermediate info struct */ + dp_info.ns_id = zns->ns_id; + + dp_info.is_cmd = true; + dp_info.sock = zns->ge_netlink_cmd.sock; + dp_info.seq = zns->ge_netlink_cmd.seq; + + return netlink_talk_info(filter, n, &dp_info, startup); +} + /* Issue request message to kernel via netlink socket. GET messages * are issued through this interface. */ @@ -1289,18 +1280,15 @@ int netlink_request(struct nlsock *nl, void *req) return 0; } -static int nl_batch_read_resp(struct nl_batch *bth) +static int nl_batch_read_resp(struct nl_batch *bth, struct nlsock *nl) { struct nlmsghdr *h; struct sockaddr_nl snl; struct msghdr msg = {}; int status, seq; - struct nlsock *nl; struct zebra_dplane_ctx *ctx; bool ignore_msg; - nl = kernel_netlink_nlsock_lookup(bth->zns->sock); - msg.msg_name = (void *)&snl; msg.msg_namelen = sizeof(snl); @@ -1493,7 +1481,7 @@ static void nl_batch_send(struct nl_batch *bth) err = true; if (!err) { - if (nl_batch_read_resp(bth) == -1) + if (nl_batch_read_resp(bth, nl) == -1) err = true; } } @@ -1631,6 +1619,7 @@ static enum netlink_msg_status nl_put_msg(struct nl_batch *bth, case DPLANE_OP_IPSET_DELETE: case DPLANE_OP_IPSET_ENTRY_ADD: case DPLANE_OP_IPSET_ENTRY_DELETE: + case DPLANE_OP_STARTUP_STAGE: return FRR_NETLINK_ERROR; case DPLANE_OP_GRE_SET: @@ -1660,6 +1649,9 @@ static enum netlink_msg_status nl_put_msg(struct nl_batch *bth, case DPLANE_OP_TC_FILTER_DELETE: case DPLANE_OP_TC_FILTER_UPDATE: return netlink_put_tc_filter_update_msg(bth, ctx); + + case DPLANE_OP_SRV6_ENCAP_SRCADDR_SET: + return netlink_put_sr_tunsrc_set_msg(bth, ctx); } return FRR_NETLINK_ERROR; @@ -1777,17 +1769,11 @@ void kernel_init(struct zebra_ns *zns) * groups are added further below after SOL_NETLINK is verified to * exist. */ - groups = RTMGRP_LINK | - RTMGRP_IPV4_ROUTE | - RTMGRP_IPV4_IFADDR | - RTMGRP_IPV6_ROUTE | - RTMGRP_IPV6_IFADDR | - RTMGRP_IPV4_MROUTE | - RTMGRP_NEIGH | - ((uint32_t) 1 << (RTNLGRP_IPV4_RULE - 1)) | - ((uint32_t) 1 << (RTNLGRP_IPV6_RULE - 1)) | - ((uint32_t) 1 << (RTNLGRP_NEXTHOP - 1)) | - ((uint32_t) 1 << (RTNLGRP_TC - 1)); + groups = RTMGRP_IPV4_ROUTE | RTMGRP_IPV6_ROUTE | RTMGRP_IPV4_MROUTE | + RTMGRP_NEIGH | ((uint32_t)1 << (RTNLGRP_IPV4_RULE - 1)) | + ((uint32_t)1 << (RTNLGRP_IPV6_RULE - 1)) | + ((uint32_t)1 << (RTNLGRP_NEXTHOP - 1)) | + ((uint32_t)1 << (RTNLGRP_TC - 1)); dplane_groups = (RTMGRP_LINK | RTMGRP_IPV4_IFADDR | @@ -1802,8 +1788,8 @@ void kernel_init(struct zebra_ns *zns) snprintf(zns->netlink.name, sizeof(zns->netlink.name), "netlink-listen (NS %u)", zns->ns_id); zns->netlink.sock = -1; - if (netlink_socket(&zns->netlink, groups, &ext_groups, 1, zns->ns_id) < - 0) { + if (netlink_socket(&zns->netlink, groups, &ext_groups, 1, zns->ns_id, + NETLINK_ROUTE) < 0) { zlog_err("Failure to create %s socket", zns->netlink.name); exit(-1); @@ -1814,7 +1800,8 @@ void kernel_init(struct zebra_ns *zns) snprintf(zns->netlink_cmd.name, sizeof(zns->netlink_cmd.name), "netlink-cmd (NS %u)", zns->ns_id); zns->netlink_cmd.sock = -1; - if (netlink_socket(&zns->netlink_cmd, 0, 0, 0, zns->ns_id) < 0) { + if (netlink_socket(&zns->netlink_cmd, 0, 0, 0, zns->ns_id, + NETLINK_ROUTE) < 0) { zlog_err("Failure to create %s socket", zns->netlink_cmd.name); exit(-1); @@ -1827,7 +1814,8 @@ void kernel_init(struct zebra_ns *zns) sizeof(zns->netlink_dplane_out.name), "netlink-dp (NS %u)", zns->ns_id); zns->netlink_dplane_out.sock = -1; - if (netlink_socket(&zns->netlink_dplane_out, 0, 0, 0, zns->ns_id) < 0) { + if (netlink_socket(&zns->netlink_dplane_out, 0, 0, 0, zns->ns_id, + NETLINK_ROUTE) < 0) { zlog_err("Failure to create %s socket", zns->netlink_dplane_out.name); exit(-1); @@ -1841,7 +1829,7 @@ void kernel_init(struct zebra_ns *zns) zns->ns_id); zns->netlink_dplane_in.sock = -1; if (netlink_socket(&zns->netlink_dplane_in, dplane_groups, 0, 0, - zns->ns_id) < 0) { + zns->ns_id, NETLINK_ROUTE) < 0) { zlog_err("Failure to create %s socket", zns->netlink_dplane_in.name); exit(-1); @@ -1849,6 +1837,19 @@ void kernel_init(struct zebra_ns *zns) kernel_netlink_nlsock_insert(&zns->netlink_dplane_in); + /* Generic Netlink socket. */ + snprintf(zns->ge_netlink_cmd.name, sizeof(zns->ge_netlink_cmd.name), + "generic-netlink-cmd (NS %u)", zns->ns_id); + zns->ge_netlink_cmd.sock = -1; + if (netlink_socket(&zns->ge_netlink_cmd, 0, 0, 0, zns->ns_id, + NETLINK_GENERIC) < 0) { + zlog_warn("Failure to create %s socket", + zns->ge_netlink_cmd.name); + } + + if (zns->ge_netlink_cmd.sock >= 0) + kernel_netlink_nlsock_insert(&zns->ge_netlink_cmd); + /* * SOL_NETLINK is not available on all platforms yet * apparently. It's in bits/socket.h which I am not @@ -1887,6 +1888,15 @@ void kernel_init(struct zebra_ns *zns) zlog_notice("Registration for extended dp ACK failed : %d %s", errno, safe_strerror(errno)); + if (zns->ge_netlink_cmd.sock >= 0) { + one = 1; + ret = setsockopt(zns->ge_netlink_cmd.sock, SOL_NETLINK, + NETLINK_EXT_ACK, &one, sizeof(one)); + if (ret < 0) + zlog_err("Registration for extended generic netlink cmd ACK failed : %d %s", + errno, safe_strerror(errno)); + } + /* * Trim off the payload of the original netlink message in the * acknowledgment. This option is available since Linux 4.2, so if @@ -1919,12 +1929,22 @@ void kernel_init(struct zebra_ns *zns) zns->netlink_dplane_in.name, safe_strerror(errno), errno); + if (zns->ge_netlink_cmd.sock >= 0) { + if (fcntl(zns->ge_netlink_cmd.sock, F_SETFL, O_NONBLOCK) < 0) + zlog_err("Can't set %s socket error: %s(%d)", + zns->ge_netlink_cmd.name, safe_strerror(errno), + errno); + } + /* Set receive buffer size if it's set from command line */ if (rcvbufsize) { netlink_recvbuf(&zns->netlink, rcvbufsize); netlink_recvbuf(&zns->netlink_cmd, rcvbufsize); netlink_recvbuf(&zns->netlink_dplane_out, rcvbufsize); netlink_recvbuf(&zns->netlink_dplane_in, rcvbufsize); + + if (zns->ge_netlink_cmd.sock >= 0) + netlink_recvbuf(&zns->ge_netlink_cmd, rcvbufsize); } /* Set filter for inbound sockets, to exclude events we've generated @@ -1943,6 +1963,8 @@ void kernel_init(struct zebra_ns *zns) &zns->t_netlink); rt_netlink_init(); + + ge_netlink_init(zns); } /* Helper to clean up an nlsock */ @@ -1967,11 +1989,16 @@ void kernel_terminate(struct zebra_ns *zns, bool complete) kernel_nlsock_fini(&zns->netlink_dplane_in); + kernel_nlsock_fini(&zns->ge_netlink_cmd); + /* During zebra shutdown, we need to leave the dataplane socket * around until all work is done. */ - if (complete) + if (complete) { kernel_nlsock_fini(&zns->netlink_dplane_out); + + XFREE(MTYPE_NL_BUF, nl_batch_tx_buf); + } } /* diff --git a/zebra/kernel_netlink.h b/zebra/kernel_netlink.h index 446c860327..e37bba0cf6 100644 --- a/zebra/kernel_netlink.h +++ b/zebra/kernel_netlink.h @@ -85,35 +85,6 @@ extern void netlink_parse_rtattr_nested(struct rtattr **tb, int max, */ extern bool nl_addraw_l(struct nlmsghdr *n, unsigned int maxlen, const void *data, unsigned int len); -/* - * nl_rta_put - add an additional optional attribute(rtattr) to the - * Netlink message buffer. - * - * Returns true if the attribute could be added to the message (fits into the - * buffer), otherwise false is returned. - */ -extern bool nl_rta_put(struct rtattr *rta, unsigned int maxlen, int type, - const void *data, int alen); -extern bool nl_rta_put16(struct rtattr *rta, unsigned int maxlen, int type, - uint16_t data); -extern bool nl_rta_put64(struct rtattr *rta, unsigned int maxlen, int type, - uint64_t data); -/* - * nl_rta_nest - start an additional optional attribute (rtattr) nest. - * - * Returns a valid pointer to the beginning of the nest if the attribute - * describing the nest could be added to the message (fits into the buffer), - * otherwise NULL is returned. - */ -extern struct rtattr *nl_rta_nest(struct rtattr *rta, unsigned int maxlen, - int type); -/* - * nl_rta_nest_end - finalize nesting of an aditionl optionl attributes. - * - * Updates the length field of the attribute header to include the appeneded - * attributes. Returns a total length of the Netlink message. - */ -extern int nl_rta_nest_end(struct rtattr *rta, struct rtattr *nest); extern const char *nl_msg_type_to_str(uint16_t msg_type); extern const char *nl_rtproto_to_str(uint8_t rtproto); extern const char *nl_family_to_str(uint8_t family); @@ -127,6 +98,9 @@ extern int netlink_talk_filter(struct nlmsghdr *h, ns_id_t ns, int startup); extern int netlink_talk(int (*filter)(struct nlmsghdr *, ns_id_t, int startup), struct nlmsghdr *n, struct nlsock *nl, struct zebra_ns *zns, bool startup); +extern int +ge_netlink_talk(int (*filter)(struct nlmsghdr *, ns_id_t, int startup), + struct nlmsghdr *n, struct zebra_ns *zns, bool startup); extern int netlink_request(struct nlsock *nl, void *req); enum netlink_msg_status { diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index b8dc92b2e9..d50e7de229 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -5,6 +5,8 @@ #include <zebra.h> +#include <net/route.h> + #ifndef HAVE_NETLINK #include <net/if_types.h> @@ -48,11 +50,7 @@ extern struct zebra_privs_t zserv_privs; * 0). We follow this practice without questioning it, but it is a * bug if frr calls ROUNDUP with 0. */ -#ifdef __APPLE__ -#define ROUNDUP_TYPE int -#else -#define ROUNDUP_TYPE long -#endif +#define ROUNDUP_TYPE long /* * Because of these varying conventions, the only sane approach is for @@ -834,12 +832,12 @@ int ifam_read(struct ifa_msghdr *ifam) struct interface *ifp = NULL; union sockunion addr, mask, brd; bool dest_same = false; - char ifname[INTERFACE_NAMSIZ]; + char ifname[IFNAMSIZ]; short ifnlen = 0; bool isalias = false; uint32_t flags = 0; - ifname[0] = ifname[INTERFACE_NAMSIZ - 1] = '\0'; + ifname[0] = ifname[IFNAMSIZ - 1] = '\0'; /* Allocate and read address information. */ ifam_read_mesg(ifam, &addr, &mask, &brd, ifname, &ifnlen); @@ -851,7 +849,7 @@ int ifam_read(struct ifa_msghdr *ifam) return -1; } - if (ifnlen && strncmp(ifp->name, ifname, INTERFACE_NAMSIZ)) + if (ifnlen && strncmp(ifp->name, ifname, IFNAMSIZ)) isalias = true; /* @@ -995,7 +993,7 @@ void rtm_read(struct rt_msghdr *rtm) int flags; uint32_t zebra_flags; union sockunion dest, mask, gate; - char ifname[INTERFACE_NAMSIZ + 1]; + char ifname[IFNAMSIZ + 1]; short ifnlen = 0; struct nexthop nh; struct prefix p; @@ -1100,11 +1098,11 @@ void rtm_read(struct rt_msghdr *rtm) if (rtm->rtm_type == RTM_GET || rtm->rtm_type == RTM_ADD || rtm->rtm_type == RTM_CHANGE) rib_add(afi, SAFI_UNICAST, VRF_DEFAULT, proto, 0, zebra_flags, - &p, NULL, &nh, 0, RT_TABLE_MAIN, 0, 0, distance, 0, + &p, NULL, &nh, 0, rt_table_main_id, 0, 0, distance, 0, false); else rib_delete(afi, SAFI_UNICAST, VRF_DEFAULT, proto, 0, - zebra_flags, &p, NULL, &nh, 0, RT_TABLE_MAIN, 0, + zebra_flags, &p, NULL, &nh, 0, rt_table_main_id, 0, distance, true); } @@ -1468,6 +1466,14 @@ static void routing_socket(struct zebra_ns *zns) event_add_read(zrouter.master, kernel_read, NULL, routing_sock, NULL); } +void interface_list_second(struct zebra_ns *zns) +{ +} + +void interface_list_tunneldump(struct zebra_ns *zns) +{ +} + /* Exported interface function. This function simply calls routing_socket (). */ void kernel_init(struct zebra_ns *zns) @@ -1617,6 +1623,8 @@ void kernel_update_multi(struct dplane_ctx_list_head *ctx_list) case DPLANE_OP_GRE_SET: case DPLANE_OP_INTF_ADDR_ADD: case DPLANE_OP_INTF_ADDR_DEL: + case DPLANE_OP_STARTUP_STAGE: + case DPLANE_OP_SRV6_ENCAP_SRCADDR_SET: zlog_err("Unhandled dplane data for %s", dplane_op2str(dplane_ctx_get_op(ctx))); res = ZEBRA_DPLANE_REQUEST_FAILURE; diff --git a/zebra/label_manager.c b/zebra/label_manager.c index c77470a701..c97beb6af8 100644 --- a/zebra/label_manager.c +++ b/zebra/label_manager.c @@ -28,6 +28,8 @@ #include "zebra/zapi_msg.h" #include "zebra/debug.h" +#include "zebra/label_manager_clippy.c" + #define CONNECTION_DELAY 5 struct label_manager lbl_mgr; @@ -49,10 +51,14 @@ DEFINE_HOOK(lm_get_chunk, DEFINE_HOOK(lm_release_chunk, (struct zserv *client, uint32_t start, uint32_t end), (client, start, end)); +/* show running-config needs an API for dynamic-block */ +DEFINE_HOOK(lm_write_label_block_config, + (struct vty *vty, struct zebra_vrf *zvrf), + (vty, zvrf)); DEFINE_HOOK(lm_cbs_inited, (), ()); -/* define wrappers to be called in zapi_msg.c (as hooks must be called in - * source file where they were defined) +/* define wrappers to be called in zapi_msg.c or zebra_mpls_vty.c (as hooks + * must be called in source file where they were defined) */ void lm_client_connect_call(struct zserv *client, vrf_id_t vrf_id) { @@ -69,6 +75,11 @@ void lm_release_chunk_call(struct zserv *client, uint32_t start, uint32_t end) hook_call(lm_release_chunk, client, start, end); } +int lm_write_label_block_config_call(struct vty *vty, struct zebra_vrf *zvrf) +{ + return hook_call(lm_write_label_block_config, vty, zvrf); +} + /* forward declarations of the static functions to be used for some hooks */ static int label_manager_connect(struct zserv *client, vrf_id_t vrf_id); static int label_manager_disconnect(struct zserv *client); @@ -78,6 +89,8 @@ static int label_manager_get_chunk(struct label_manager_chunk **lmc, vrf_id_t vrf_id); static int label_manager_release_label_chunk(struct zserv *client, uint32_t start, uint32_t end); +static int label_manager_write_label_block_config(struct vty *vty, + struct zebra_vrf *zvrf); void delete_label_chunk(void *val) { @@ -96,7 +109,7 @@ void delete_label_chunk(void *val) */ int release_daemon_label_chunks(struct zserv *client) { - struct listnode *node; + struct listnode *node, *nnode; struct label_manager_chunk *lmc; int count = 0; int ret; @@ -106,7 +119,7 @@ int release_daemon_label_chunks(struct zserv *client) __func__, zebra_route_string(client->proto), client->instance, client->session_id); - for (ALL_LIST_ELEMENTS_RO(lbl_mgr.lc_list, node, lmc)) { + for (ALL_LIST_ELEMENTS(lbl_mgr.lc_list, node, nnode, lmc)) { if (lmc->proto == client->proto && lmc->instance == client->instance && lmc->session_id == client->session_id && lmc->keep == 0) { @@ -136,6 +149,8 @@ void lm_hooks_register(void) hook_register(lm_client_disconnect, label_manager_disconnect); hook_register(lm_get_chunk, label_manager_get_chunk); hook_register(lm_release_chunk, label_manager_release_label_chunk); + hook_register(lm_write_label_block_config, + label_manager_write_label_block_config); } void lm_hooks_unregister(void) { @@ -143,6 +158,127 @@ void lm_hooks_unregister(void) hook_unregister(lm_client_disconnect, label_manager_disconnect); hook_unregister(lm_get_chunk, label_manager_get_chunk); hook_unregister(lm_release_chunk, label_manager_release_label_chunk); + hook_unregister(lm_write_label_block_config, + label_manager_write_label_block_config); +} + +static json_object *lmc_json(struct label_manager_chunk *lmc) +{ + json_object *json = json_object_new_object(); + + json_object_string_add(json, "protocol", zebra_route_string(lmc->proto)); + json_object_int_add(json, "instance", lmc->instance); + json_object_int_add(json, "sessionId", lmc->session_id); + json_object_int_add(json, "start", lmc->start); + json_object_int_add(json, "end", lmc->end); + json_object_boolean_add(json, "dynamic", lmc->is_dynamic); + return json; +} + +DEFPY(show_label_table, show_label_table_cmd, "show debugging label-table [json$uj]", + SHOW_STR + DEBUG_STR + "Display allocated label chunks\n" + JSON_STR) +{ + struct label_manager_chunk *lmc; + struct listnode *node; + json_object *json_array = NULL, *json_global = NULL, *json_dyn_block; + + if (uj) { + json_array = json_object_new_array(); + json_global = json_object_new_object(); + json_dyn_block = json_object_new_object(); + json_object_int_add(json_dyn_block, "lowerBound", + lbl_mgr.dynamic_block_start); + json_object_int_add(json_dyn_block, "upperBound", + lbl_mgr.dynamic_block_end); + json_object_object_add(json_global, "dynamicBlock", + json_dyn_block); + } else + vty_out(vty, "Dynamic block: lower-bound %u, upper-bound %u\n", + lbl_mgr.dynamic_block_start, lbl_mgr.dynamic_block_end); + + for (ALL_LIST_ELEMENTS_RO(lbl_mgr.lc_list, node, lmc)) { + if (uj) { + json_object_array_add(json_array, lmc_json(lmc)); + continue; + } + vty_out(vty, "Proto %s: [%u/%u]\n", + zebra_route_string(lmc->proto), lmc->start, lmc->end); + } + if (uj) { + json_object_object_add(json_global, "chunks", json_array); + vty_json(vty, json_global); + } + return CMD_SUCCESS; +} + +DEFPY(mpls_label_dynamic_block, mpls_label_dynamic_block_cmd, + "[no$no] mpls label dynamic-block [(16-1048575)$start (16-1048575)$end]", + NO_STR + MPLS_STR + "Label configuration\n" + "Configure dynamic label block\n" + "Start label\n" + "End label\n") +{ + struct listnode *node; + struct label_manager_chunk *lmc; + + /* unset dynamic range */ + if (no || + (start == MPLS_LABEL_UNRESERVED_MIN && end == MPLS_LABEL_MAX)) { + lbl_mgr.dynamic_block_start = MPLS_LABEL_UNRESERVED_MIN; + lbl_mgr.dynamic_block_end = MPLS_LABEL_MAX; + return CMD_SUCCESS; + } + if (!start || !end) { + vty_out(vty, + "%% label dynamic-block, range missing, aborting\n"); + return CMD_WARNING_CONFIG_FAILED; + } + if (start > end) { + vty_out(vty, + "%% label dynamic-block, wrong range (%ld > %ld), aborting\n", + start, end); + return CMD_WARNING_CONFIG_FAILED; + } + + for (ALL_LIST_ELEMENTS_RO(lbl_mgr.lc_list, node, lmc)) { + if (lmc->proto == NO_PROTO) + continue; + if (!lmc->is_dynamic && lmc->start >= (uint32_t)start && + lmc->end <= (uint32_t)end) { + vty_out(vty, + "%% Found a static label chunk [%u-%u] for %s in conflict with the dynamic label block\n", + lmc->start, lmc->end, + zebra_route_string(lmc->proto)); + return CMD_WARNING_CONFIG_FAILED; + } else if (lmc->is_dynamic && (lmc->end > (uint32_t)end || + lmc->start < (uint32_t)start)) { + vty_out(vty, + "%% Found a dynamic label chunk [%u-%u] for %s outside the new dynamic label block, consider restart the service\n", + lmc->start, lmc->end, + zebra_route_string(lmc->proto)); + } + } + lbl_mgr.dynamic_block_start = start; + lbl_mgr.dynamic_block_end = end; + return CMD_SUCCESS; +} + +static int label_manager_write_label_block_config(struct vty *vty, + struct zebra_vrf *zvrf) +{ + if (zvrf_id(zvrf) != VRF_DEFAULT) + return 0; + if (lbl_mgr.dynamic_block_start == MPLS_LABEL_UNRESERVED_MIN && + lbl_mgr.dynamic_block_end == MPLS_LABEL_MAX) + return 0; + vty_out(vty, "mpls label dynamic-block %u %u\n", + lbl_mgr.dynamic_block_start, lbl_mgr.dynamic_block_end); + return 1; } /** @@ -152,6 +288,8 @@ void label_manager_init(void) { lbl_mgr.lc_list = list_new(); lbl_mgr.lc_list->del = delete_label_chunk; + lbl_mgr.dynamic_block_start = MPLS_LABEL_UNRESERVED_MIN; + lbl_mgr.dynamic_block_end = MPLS_LABEL_MAX; hook_register(zserv_client_close, lm_client_disconnect_cb); /* register default hooks for the label manager actions */ @@ -159,12 +297,20 @@ void label_manager_init(void) /* notify any external module that we are done */ hook_call(lm_cbs_inited); + + install_element(VIEW_NODE, &show_label_table_cmd); + install_element(CONFIG_NODE, &mpls_label_dynamic_block_cmd); +} + +void label_manager_terminate(void) +{ + list_delete(&lbl_mgr.lc_list); } /* alloc and fill a label chunk */ struct label_manager_chunk * create_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id, - uint8_t keep, uint32_t start, uint32_t end) + uint8_t keep, uint32_t start, uint32_t end, bool is_dynamic) { /* alloc chunk, fill it and return it */ struct label_manager_chunk *lmc = @@ -176,6 +322,7 @@ create_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id, lmc->instance = instance; lmc->session_id = session_id; lmc->keep = keep; + lmc->is_dynamic = is_dynamic; return lmc; } @@ -203,6 +350,15 @@ assign_specific_label_chunk(uint8_t proto, unsigned short instance, return NULL; } + if ((lbl_mgr.dynamic_block_start != MPLS_LABEL_UNRESERVED_MIN || + lbl_mgr.dynamic_block_end != MPLS_LABEL_MAX) && + base >= lbl_mgr.dynamic_block_start && + end <= lbl_mgr.dynamic_block_end) { + zlog_warn("Invalid LM request arguments: base: %u, size: %u for %s in conflict with the dynamic label block", + base, size, zebra_route_string(proto)); + return NULL; + } + /* Scan the existing chunks to see if the requested range of labels * falls inside any of such chunks */ for (ALL_LIST_ELEMENTS_RO(lbl_mgr.lc_list, node, lmc)) { @@ -234,7 +390,7 @@ assign_specific_label_chunk(uint8_t proto, unsigned short instance, /* insert chunk between existing chunks */ if (insert_node) { lmc = create_label_chunk(proto, instance, session_id, keep, - base, end); + base, end, false); listnode_add_before(lbl_mgr.lc_list, insert_node, lmc); return lmc; } @@ -257,7 +413,7 @@ assign_specific_label_chunk(uint8_t proto, unsigned short instance, } lmc = create_label_chunk(proto, instance, session_id, keep, - base, end); + base, end, false); if (last_node) listnode_add_before(lbl_mgr.lc_list, last_node, lmc); else @@ -268,7 +424,7 @@ assign_specific_label_chunk(uint8_t proto, unsigned short instance, /* create a new chunk past all the existing ones and link at * tail */ lmc = create_label_chunk(proto, instance, session_id, keep, - base, end); + base, end, false); listnode_add(lbl_mgr.lc_list, lmc); return lmc; } @@ -293,9 +449,13 @@ assign_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id, { struct label_manager_chunk *lmc; struct listnode *node; - uint32_t prev_end = MPLS_LABEL_UNRESERVED_MIN; + uint32_t prev_end = lbl_mgr.dynamic_block_start - 1; + struct label_manager_chunk *lmc_block_last = NULL; - /* handle chunks request with a specific base label */ + /* handle chunks request with a specific base label + * - static label requests: BGP hardset value, Pathd + * - segment routing label requests + */ if (base != MPLS_LABEL_BASE_ANY) return assign_specific_label_chunk(proto, instance, session_id, keep, size, base); @@ -305,37 +465,44 @@ assign_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id, /* first check if there's one available */ for (ALL_LIST_ELEMENTS_RO(lbl_mgr.lc_list, node, lmc)) { - if (lmc->proto == NO_PROTO - && lmc->end - lmc->start + 1 == size) { + if (lmc->start <= prev_end) + continue; + if (lmc->proto == NO_PROTO && + lmc->end - lmc->start + 1 == size && + lmc->end <= lbl_mgr.dynamic_block_end) { lmc->proto = proto; lmc->instance = instance; lmc->session_id = session_id; lmc->keep = keep; + lmc->is_dynamic = true; return lmc; } /* check if we hadve a "hole" behind us that we can squeeze into */ - if ((lmc->start > prev_end) && (lmc->start - prev_end > size)) { + if (lmc->start - prev_end > size && + prev_end + 1 + size <= lbl_mgr.dynamic_block_end) { lmc = create_label_chunk(proto, instance, session_id, keep, prev_end + 1, - prev_end + size); + prev_end + size, true); listnode_add_before(lbl_mgr.lc_list, node, lmc); return lmc; } prev_end = lmc->end; + + /* check if we have a chunk that goes over the end block */ + if (lmc->end > lbl_mgr.dynamic_block_end) + continue; + lmc_block_last = lmc; } /* otherwise create a new one */ uint32_t start_free; - if (list_isempty(lbl_mgr.lc_list)) - start_free = MPLS_LABEL_UNRESERVED_MIN; + if (lmc_block_last == NULL) + start_free = lbl_mgr.dynamic_block_start; else - start_free = ((struct label_manager_chunk *)listgetdata( - listtail(lbl_mgr.lc_list))) - ->end - + 1; + start_free = lmc_block_last->end + 1; - if (start_free > MPLS_LABEL_UNRESERVED_MAX - size + 1) { + if (start_free > lbl_mgr.dynamic_block_end - size + 1) { flog_err(EC_ZEBRA_LM_EXHAUSTED_LABELS, "Reached max labels. Start: %u, size: %u", start_free, size); @@ -344,7 +511,7 @@ assign_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id, /* create chunk and link at tail */ lmc = create_label_chunk(proto, instance, session_id, keep, start_free, - start_free + size - 1); + start_free + size - 1, true); listnode_add(lbl_mgr.lc_list, lmc); return lmc; } @@ -399,13 +566,14 @@ int release_label_chunk(uint8_t proto, unsigned short instance, "%s: Daemon mismatch!!", __func__); continue; } - lmc->proto = NO_PROTO; - lmc->instance = 0; - lmc->session_id = 0; - lmc->keep = 0; ret = 0; break; } + if (lmc) { + list_delete_node(lbl_mgr.lc_list, node); + delete_label_chunk(lmc); + } + if (ret != 0) flog_err(EC_ZEBRA_LM_UNRELEASED_CHUNK, "%s: Label chunk not released!!", __func__); @@ -435,7 +603,25 @@ static int label_manager_get_chunk(struct label_manager_chunk **lmc, { *lmc = assign_label_chunk(client->proto, client->instance, client->session_id, keep, size, base); - return lm_get_chunk_response(*lmc, client, vrf_id); + /* Respond to a get_chunk request */ + if (!*lmc) { + if (base == MPLS_LABEL_BASE_ANY) + flog_err(EC_ZEBRA_LM_CANNOT_ASSIGN_CHUNK, + "Unable to assign Label Chunk size %u to %s instance %u", + size, zebra_route_string(client->proto), + client->instance); + else + flog_err(EC_ZEBRA_LM_CANNOT_ASSIGN_CHUNK, + "Unable to assign Label Chunk %u - %u to %s instance %u", + base, base + size - 1, + zebra_route_string(client->proto), + client->instance); + } else if (IS_ZEBRA_DEBUG_PACKET) + zlog_debug("Assigned Label Chunk %u - %u to %s instance %u", + (*lmc)->start, (*lmc)->end, + zebra_route_string(client->proto), client->instance); + + return zsend_assign_label_chunk_response(client, vrf_id, *lmc); } /* Respond to a connect request */ @@ -454,22 +640,6 @@ int lm_client_connect_response(uint8_t proto, uint16_t instance, return zsend_label_manager_connect_response(client, vrf_id, result); } -/* Respond to a get_chunk request */ -int lm_get_chunk_response(struct label_manager_chunk *lmc, struct zserv *client, - vrf_id_t vrf_id) -{ - if (!lmc) - flog_err(EC_ZEBRA_LM_CANNOT_ASSIGN_CHUNK, - "Unable to assign Label Chunk to %s instance %u", - zebra_route_string(client->proto), client->instance); - else if (IS_ZEBRA_DEBUG_PACKET) - zlog_debug("Assigned Label Chunk %u - %u to %s instance %u", - lmc->start, lmc->end, - zebra_route_string(client->proto), client->instance); - - return zsend_assign_label_chunk_response(client, vrf_id, lmc); -} - void label_manager_close(void) { list_delete(&lbl_mgr.lc_list); diff --git a/zebra/label_manager.h b/zebra/label_manager.h index cfbb4bd169..03cf6a6813 100644 --- a/zebra/label_manager.h +++ b/zebra/label_manager.h @@ -42,6 +42,7 @@ struct label_manager_chunk { unsigned short instance; uint32_t session_id; uint8_t keep; + uint8_t is_dynamic; /* Tell if chunk is dynamic or static */ uint32_t start; /* First label of the chunk */ uint32_t end; /* Last label of the chunk */ }; @@ -61,11 +62,14 @@ DECLARE_HOOK(lm_get_chunk, DECLARE_HOOK(lm_release_chunk, (struct zserv *client, uint32_t start, uint32_t end), (client, start, end)); +DECLARE_HOOK(lm_write_label_block_config, + (struct vty *vty, struct zebra_vrf *zvrf), + (vty, zvrf)); DECLARE_HOOK(lm_cbs_inited, (), ()); -/* declare wrappers to be called in zapi_msg.c (as hooks must be called in - * source file where they were defined) +/* declare wrappers to be called in zapi_msg.c or zebra_mpls_vty.c (as hooks + * must be called in source file where they were defined) */ void lm_client_connect_call(struct zserv *client, vrf_id_t vrf_id); void lm_get_chunk_call(struct label_manager_chunk **lmc, struct zserv *client, @@ -73,18 +77,17 @@ void lm_get_chunk_call(struct label_manager_chunk **lmc, struct zserv *client, vrf_id_t vrf_id); void lm_release_chunk_call(struct zserv *client, uint32_t start, uint32_t end); +int lm_write_label_block_config_call(struct vty *vty, struct zebra_vrf *zvrf); /* API for an external LM to return responses for requests */ int lm_client_connect_response(uint8_t proto, uint16_t instance, uint32_t session_id, vrf_id_t vrf_id, uint8_t result); -int lm_get_chunk_response(struct label_manager_chunk *lmc, struct zserv *client, - vrf_id_t vrf_id); /* convenience function to allocate an lmc to be consumed by the above API */ struct label_manager_chunk * create_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id, - uint8_t keep, uint32_t start, uint32_t end); + uint8_t keep, uint32_t start, uint32_t end, bool is_dynamic); void delete_label_chunk(void *val); /* register/unregister callbacks for hooks */ @@ -97,9 +100,13 @@ void lm_hooks_unregister(void); */ struct label_manager { struct list *lc_list; + uint32_t dynamic_block_start; + uint32_t dynamic_block_end; }; void label_manager_init(void); +void label_manager_terminate(void); + struct label_manager_chunk * assign_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id, uint8_t keep, uint32_t size, uint32_t base); diff --git a/zebra/main.c b/zebra/main.c index 81a3066445..f3e4bf50d5 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -5,6 +5,10 @@ #include <zebra.h> +#ifdef GNU_LINUX +#include <linux/rtnetlink.h> +#endif + #include <lib/version.h> #include "getopt.h" #include "command.h" @@ -21,6 +25,7 @@ #include "affinitymap.h" #include "routemap.h" #include "routing_nb.h" +#include "mgmt_be_client.h" #include "zebra/zebra_router.h" #include "zebra/zebra_errors.h" @@ -54,13 +59,13 @@ pid_t pid; /* Pacify zclient.o in libfrr, which expects this variable. */ struct event_loop *master; +struct mgmt_be_client *mgmt_be_client; + /* Route retain mode flag. */ int retain_mode = 0; int graceful_restart; -bool v6_rr_semantics = false; - /* Receive buffer size for kernel control sockets */ #define RCVBUFSIZE_MIN 4194304 #ifdef HAVE_NETLINK @@ -69,24 +74,30 @@ uint32_t rcvbufsize = RCVBUFSIZE_MIN; uint32_t rcvbufsize = 128 * 1024; #endif +uint32_t rt_table_main_id = RT_TABLE_MAIN; + #define OPTION_V6_RR_SEMANTICS 2000 #define OPTION_ASIC_OFFLOAD 2001 +#define OPTION_V6_WITH_V4_NEXTHOP 2002 /* Command line options. */ const struct option longopts[] = { - {"batch", no_argument, NULL, 'b'}, - {"allow_delete", no_argument, NULL, 'a'}, - {"socket", required_argument, NULL, 'z'}, - {"ecmp", required_argument, NULL, 'e'}, - {"retain", no_argument, NULL, 'r'}, - {"graceful_restart", required_argument, NULL, 'K'}, - {"asic-offload", optional_argument, NULL, OPTION_ASIC_OFFLOAD}, + { "batch", no_argument, NULL, 'b' }, + { "allow_delete", no_argument, NULL, 'a' }, + { "socket", required_argument, NULL, 'z' }, + { "ecmp", required_argument, NULL, 'e' }, + { "retain", no_argument, NULL, 'r' }, + { "graceful_restart", required_argument, NULL, 'K' }, + { "asic-offload", optional_argument, NULL, OPTION_ASIC_OFFLOAD }, + { "v6-with-v4-nexthops", no_argument, NULL, OPTION_V6_WITH_V4_NEXTHOP }, #ifdef HAVE_NETLINK - {"vrfwnetns", no_argument, NULL, 'n'}, - {"nl-bufsize", required_argument, NULL, 's'}, - {"v6-rr-semantics", no_argument, NULL, OPTION_V6_RR_SEMANTICS}, + { "vrfwnetns", no_argument, NULL, 'n' }, + { "nl-bufsize", required_argument, NULL, 's' }, + { "v6-rr-semantics", no_argument, NULL, OPTION_V6_RR_SEMANTICS }, #endif /* HAVE_NETLINK */ - {0}}; + {"routing-table", optional_argument, NULL, 'R'}, + { 0 } +}; zebra_capabilities_t _caps_p[] = {ZCAP_NET_ADMIN, ZCAP_SYS_ADMIN, ZCAP_NET_RAW, @@ -134,6 +145,10 @@ static void sigint(void) zlog_notice("Terminating on signal"); + nb_oper_cancel_all_walks(); + mgmt_be_client_destroy(mgmt_be_client); + mgmt_be_client = NULL; + atomic_store_explicit(&zrouter.in_shutdown, true, memory_order_relaxed); @@ -206,17 +221,31 @@ void zebra_finalize(struct event *dummy) vrf_terminate(); + /* + * Stop dplane thread and finish any cleanup + * This is before the zebra_ns_early_shutdown call + * because sockets that the dplane depends on are closed + * in those functions + */ + zebra_dplane_shutdown(); + ns_walk_func(zebra_ns_early_shutdown, NULL, NULL); zebra_ns_notify_close(); - /* Stop dplane thread and finish any cleanup */ - zebra_dplane_shutdown(); - /* Final shutdown of ns resources */ ns_walk_func(zebra_ns_final_shutdown, NULL, NULL); + zebra_rib_terminate(); zebra_router_terminate(); + zebra_mpls_terminate(); + + zebra_pw_terminate(); + + zebra_srv6_terminate(); + + label_manager_terminate(); + ns_terminate(); frr_fini(); exit(0); @@ -282,6 +311,7 @@ int main(int argc, char **argv) struct sockaddr_storage dummy; socklen_t dummylen; bool asic_offload = false; + bool v6_with_v4_nexthop = false; bool notify_on_ack = true; graceful_restart = 0; @@ -289,27 +319,28 @@ int main(int argc, char **argv) frr_preinit(&zebra_di, argc, argv); - frr_opt_add( - "baz:e:rK:s:" + frr_opt_add("baz:e:rK:s:R:" #ifdef HAVE_NETLINK - "n" + "n" #endif - , - longopts, - " -b, --batch Runs in batch mode\n" - " -a, --allow_delete Allow other processes to delete zebra routes\n" - " -z, --socket Set path of zebra socket\n" - " -e, --ecmp Specify ECMP to use.\n" - " -r, --retain When program terminates, retain added route by zebra.\n" - " -K, --graceful_restart Graceful restart at the kernel level, timer in seconds for expiration\n" - " -A, --asic-offload FRR is interacting with an asic underneath the linux kernel\n" + , + longopts, + " -b, --batch Runs in batch mode\n" + " -a, --allow_delete Allow other processes to delete zebra routes\n" + " -z, --socket Set path of zebra socket\n" + " -e, --ecmp Specify ECMP to use.\n" + " -r, --retain When program terminates, retain added route by zebra.\n" + " -K, --graceful_restart Graceful restart at the kernel level, timer in seconds for expiration\n" + " -A, --asic-offload FRR is interacting with an asic underneath the linux kernel\n" + " --v6-with-v4-nexthops Underlying dataplane supports v6 routes with v4 nexthops" #ifdef HAVE_NETLINK - " -s, --nl-bufsize Set netlink receive buffer size\n" - " -n, --vrfwnetns Use NetNS as VRF backend\n" - " --v6-rr-semantics Use v6 RR semantics\n" + " -s, --nl-bufsize Set netlink receive buffer size\n" + " -n, --vrfwnetns Use NetNS as VRF backend\n" + " --v6-rr-semantics Use v6 RR semantics\n" #else - " -s, Set kernel socket receive buffer size\n" + " -s, Set kernel socket receive buffer size\n" #endif /* HAVE_NETLINK */ + " -R, --routing-table Set kernel routing table\n" ); while (1) { @@ -364,12 +395,15 @@ int main(int argc, char **argv) "Rcvbufsize is smaller than recommended value: %d\n", RCVBUFSIZE_MIN); break; + case 'R': + rt_table_main_id = atoi(optarg); + break; #ifdef HAVE_NETLINK case 'n': vrf_configure_backend(VRF_BACKEND_NETNS); break; case OPTION_V6_RR_SEMANTICS: - v6_rr_semantics = true; + zrouter.v6_rr_semantics = true; break; case OPTION_ASIC_OFFLOAD: if (!strcmp(optarg, "notify_on_offload")) @@ -378,6 +412,9 @@ int main(int argc, char **argv) notify_on_ack = true; asic_offload = true; break; + case OPTION_V6_WITH_V4_NEXTHOP: + v6_with_v4_nexthop = true; + break; #endif /* HAVE_NETLINK */ default: frr_help_exit(1); @@ -387,9 +424,9 @@ int main(int argc, char **argv) zrouter.master = frr_init(); /* Zebra related initialize. */ - zebra_router_init(asic_offload, notify_on_ack); + zebra_router_init(asic_offload, notify_on_ack, v6_with_v4_nexthop); zserv_init(); - rib_init(); + zebra_rib_init(); zebra_if_init(); zebra_debug_init(); @@ -399,8 +436,12 @@ int main(int argc, char **argv) zebra_ns_init(); router_id_cmd_init(); zebra_vty_init(); + mgmt_be_client = mgmt_be_client_create("zebra", NULL, 0, + zrouter.master); access_list_init(); prefix_list_init(); + + rtadv_init(); rtadv_cmd_init(); /* PTM socket */ #ifdef ZEBRA_PTM_SUPPORT diff --git a/zebra/netconf_netlink.c b/zebra/netconf_netlink.c index 7352dfb2ee..002d2c7bf6 100644 --- a/zebra/netconf_netlink.c +++ b/zebra/netconf_netlink.c @@ -6,11 +6,14 @@ * Donald Sharp */ #include <zebra.h> +#include <fcntl.h> #ifdef HAVE_NETLINK /* Netlink OSes only */ #include <ns.h> +#include <linux/netlink.h> +#include <linux/rtnetlink.h> #include "linux/netconf.h" #include "lib/lib_errors.h" diff --git a/zebra/redistribute.c b/zebra/redistribute.c index 6767000f3b..70ace35a86 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -16,6 +16,7 @@ #include "log.h" #include "vrf.h" #include "srcdest_table.h" +#include "frrdistance.h" #include "zebra/rib.h" #include "zebra/zebra_router.h" @@ -28,6 +29,7 @@ #include "zebra/zapi_msg.h" #include "zebra/zebra_vxlan.h" #include "zebra/zebra_errors.h" +#include "zebra/zebra_neigh.h" #define ZEBRA_PTM_SUPPORT @@ -60,7 +62,7 @@ static void zebra_redistribute_default(struct zserv *client, vrf_id_t vrf_id) for (afi = AFI_IP; afi <= AFI_IP6; afi++) { - if (!vrf_bitmap_check(client->redist_default[afi], vrf_id)) + if (!vrf_bitmap_check(&client->redist_default[afi], vrf_id)) continue; /* Lookup table. */ @@ -77,9 +79,8 @@ static void zebra_redistribute_default(struct zserv *client, vrf_id_t vrf_id) RNODE_FOREACH_RE (rn, newre) { if (CHECK_FLAG(newre->flags, ZEBRA_FLAG_SELECTED)) - zsend_redistribute_route( - ZEBRA_REDISTRIBUTE_ROUTE_ADD, client, - rn, newre); + zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD, + client, rn, newre, false); } route_unlock_node(rn); @@ -88,14 +89,26 @@ static void zebra_redistribute_default(struct zserv *client, vrf_id_t vrf_id) /* Redistribute routes. */ static void zebra_redistribute(struct zserv *client, int type, - unsigned short instance, vrf_id_t vrf_id, + unsigned short instance, struct zebra_vrf *zvrf, int afi) { struct route_entry *newre; struct route_table *table; struct route_node *rn; + bool is_table_direct = false; + vrf_id_t vrf_id = zvrf_id(zvrf); + + if (type == ZEBRA_ROUTE_TABLE_DIRECT) { + if (vrf_id == VRF_DEFAULT) { + table = zebra_router_find_table(zvrf, instance, afi, + SAFI_UNICAST); + type = ZEBRA_ROUTE_ALL; + is_table_direct = true; + } else + return; + } else + table = zebra_vrf_table(afi, SAFI_UNICAST, vrf_id); - table = zebra_vrf_table(afi, SAFI_UNICAST, vrf_id); if (!table) return; @@ -125,10 +138,25 @@ static void zebra_redistribute(struct zserv *client, int type, continue; zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD, - client, rn, newre); + client, rn, newre, is_table_direct); } } +/* + * Function to return a valid table id value if table-direct is used + * return 0 otherwise + * This function can be called only if zebra_redistribute_check returns TRUE + */ +static bool zebra_redistribute_is_table_direct(const struct route_entry *re) +{ + struct zebra_vrf *zvrf; + + zvrf = zebra_vrf_lookup_by_id(re->vrf_id); + if (re->vrf_id == VRF_DEFAULT && zvrf->table_id != re->table) + return true; + return false; +} + /* * Function to check if prefix is candidate for * redistribute. @@ -146,16 +174,27 @@ static bool zebra_redistribute_check(const struct route_node *rn, afi = family2afi(rn->p.family); zvrf = zebra_vrf_lookup_by_id(re->vrf_id); - if (re->vrf_id == VRF_DEFAULT && zvrf->table_id != re->table) + if (re->vrf_id == VRF_DEFAULT && zvrf->table_id != re->table) { + if (re->table && + redist_check_instance(&client->mi_redist + [afi][ZEBRA_ROUTE_TABLE_DIRECT], + re->table)) { + /* table-direct redistribution only for route entries which + * are on the default vrf, and that have table id different + * from the default table. + */ + return true; + } return false; + } /* If default route and redistributed */ if (is_default_prefix(&rn->p) && - vrf_bitmap_check(client->redist_default[afi], re->vrf_id)) + vrf_bitmap_check(&client->redist_default[afi], re->vrf_id)) return true; /* If redistribute in enabled for zebra route all */ - if (vrf_bitmap_check(client->redist[afi][ZEBRA_ROUTE_ALL], re->vrf_id)) + if (vrf_bitmap_check(&client->redist[afi][ZEBRA_ROUTE_ALL], re->vrf_id)) return true; /* @@ -171,7 +210,7 @@ static bool zebra_redistribute_check(const struct route_node *rn, } /* If redistribution is enabled for give route type. */ - if (vrf_bitmap_check(client->redist[afi][re->type], re->vrf_id)) + if (vrf_bitmap_check(&client->redist[afi][re->type], re->vrf_id)) return true; return false; @@ -185,6 +224,7 @@ void redistribute_update(const struct route_node *rn, { struct listnode *node, *nnode; struct zserv *client; + bool is_table_direct; if (IS_ZEBRA_DEBUG_RIB) zlog_debug( @@ -210,11 +250,16 @@ void redistribute_update(const struct route_node *rn, re->vrf_id, re->table, re->type, re->distance, re->metric); } + is_table_direct = zebra_redistribute_is_table_direct(re); zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_ADD, - client, rn, re); - } else if (zebra_redistribute_check(rn, prev_re, client)) + client, rn, re, + is_table_direct); + } else if (zebra_redistribute_check(rn, prev_re, client)) { + is_table_direct = zebra_redistribute_is_table_direct(prev_re); zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL, - client, rn, prev_re); + client, rn, prev_re, + is_table_direct); + } } } @@ -233,6 +278,7 @@ void redistribute_delete(const struct route_node *rn, struct listnode *node, *nnode; struct zserv *client; vrf_id_t vrfid; + bool is_table_direct; if (old_re) vrfid = old_re->vrf_id; @@ -256,12 +302,11 @@ void redistribute_delete(const struct route_node *rn, table = new_re->table; } - zlog_debug( - "%u:%u%pRN: Redist del: re %p (%u:%s), new re %p (%u:%s)", - vrfid, table, rn, old_re, old_inst, - old_re ? zebra_route_string(old_re->type) : "None", - new_re, new_inst, - new_re ? zebra_route_string(new_re->type) : "None"); + zlog_debug("(%u:%u):%pRN: Redist del: re %p (%u:%s), new re %p (%u:%s)", + vrfid, table, rn, old_re, old_inst, + old_re ? zebra_route_string(old_re->type) : "None", + new_re, new_inst, + new_re ? zebra_route_string(new_re->type) : "None"); } /* Skip invalid (e.g. linklocal) prefix */ @@ -286,9 +331,20 @@ void redistribute_delete(const struct route_node *rn, continue; /* Send a delete for the 'old' re to any subscribed client. */ - if (zebra_redistribute_check(rn, old_re, client)) + if (zebra_redistribute_check(rn, old_re, client)) { + /* + * SA is complaining that old_re could be false + * SA is wrong because old_re is checked for NULL + * in zebra_redistribute_check and false is + * returned in that case. Let's just make SA + * happy. + */ + assert(old_re); + is_table_direct = zebra_redistribute_is_table_direct(old_re); zsend_redistribute_route(ZEBRA_REDISTRIBUTE_ROUTE_DEL, - client, rn, old_re); + client, rn, old_re, + is_table_direct); + } } } @@ -327,20 +383,19 @@ void zebra_redistribute_add(ZAPI_HANDLER_ARGS) instance)) { redist_add_instance(&client->mi_redist[afi][type], instance); - zebra_redistribute(client, type, instance, - zvrf_id(zvrf), afi); + zebra_redistribute(client, type, instance, zvrf, afi); } } else { - if (!vrf_bitmap_check(client->redist[afi][type], + if (!vrf_bitmap_check(&client->redist[afi][type], zvrf_id(zvrf))) { if (IS_ZEBRA_DEBUG_EVENT) zlog_debug( "%s: setting vrf %s(%u) redist bitmap", __func__, VRF_LOGNAME(zvrf->vrf), zvrf_id(zvrf)); - vrf_bitmap_set(client->redist[afi][type], + vrf_bitmap_set(&client->redist[afi][type], zvrf_id(zvrf)); - zebra_redistribute(client, type, 0, zvrf_id(zvrf), afi); + zebra_redistribute(client, type, 0, zvrf, afi); } } @@ -387,7 +442,7 @@ void zebra_redistribute_delete(ZAPI_HANDLER_ARGS) if (instance) redist_del_instance(&client->mi_redist[afi][type], instance); else - vrf_bitmap_unset(client->redist[afi][type], zvrf_id(zvrf)); + vrf_bitmap_unset(&client->redist[afi][type], zvrf_id(zvrf)); stream_failure: return; @@ -405,7 +460,7 @@ void zebra_redistribute_default_add(ZAPI_HANDLER_ARGS) return; } - vrf_bitmap_set(client->redist_default[afi], zvrf_id(zvrf)); + vrf_bitmap_set(&client->redist_default[afi], zvrf_id(zvrf)); zebra_redistribute_default(client, zvrf_id(zvrf)); stream_failure: @@ -424,7 +479,7 @@ void zebra_redistribute_default_delete(ZAPI_HANDLER_ARGS) return; } - vrf_bitmap_unset(client->redist_default[afi], zvrf_id(zvrf)); + vrf_bitmap_unset(&client->redist_default[afi], zvrf_id(zvrf)); stream_failure: return; @@ -473,6 +528,8 @@ void zebra_interface_down_update(struct interface *ifp) zsend_interface_update(ZEBRA_INTERFACE_DOWN, client, ifp); } + + zebra_neigh_del_all(ifp); } /* Interface information update. */ @@ -593,9 +650,8 @@ void zebra_interface_vrf_update_del(struct interface *ifp, vrf_id_t new_vrf_id) struct zserv *client; if (IS_ZEBRA_DEBUG_EVENT) - zlog_debug( - "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/DEL %s VRF Id %u -> %u", - ifp->name, ifp->vrf->vrf_id, new_vrf_id); + zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s VRF Id %u -> %u", + ifp->name, ifp->vrf->vrf_id, new_vrf_id); for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) { /* Do not send unsolicited messages to synchronous clients. */ @@ -607,7 +663,6 @@ void zebra_interface_vrf_update_del(struct interface *ifp, vrf_id_t new_vrf_id) zsend_interface_update(ZEBRA_INTERFACE_DOWN, client, ifp); client->ifdel_cnt++; zsend_interface_delete(client, ifp); - zsend_interface_vrf_update(client, ifp, new_vrf_id); } } @@ -620,9 +675,8 @@ void zebra_interface_vrf_update_add(struct interface *ifp, vrf_id_t old_vrf_id) struct zserv *client; if (IS_ZEBRA_DEBUG_EVENT) - zlog_debug( - "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/ADD %s VRF Id %u -> %u", - ifp->name, old_vrf_id, ifp->vrf->vrf_id); + zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s VRF Id %u -> %u", + ifp->name, old_vrf_id, ifp->vrf->vrf_id); for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) { /* Do not send unsolicited messages to synchronous clients. */ @@ -648,10 +702,9 @@ int zebra_add_import_table_entry(struct zebra_vrf *zvrf, struct route_node *rn, afi = family2afi(rn->p.family); if (rmap_name) - ret = zebra_import_table_route_map_check( - afi, re->type, re->instance, &rn->p, - re->nhe->nhg.nexthop, - zvrf->vrf->vrf_id, re->tag, rmap_name); + ret = zebra_import_table_route_map_check(afi, re, &rn->p, + re->nhe->nhg.nexthop, + rmap_name); if (ret != RMAP_PERMITMATCH) { UNSET_FLAG(re->flags, ZEBRA_FLAG_SELECTED); @@ -665,9 +718,10 @@ int zebra_add_import_table_entry(struct zebra_vrf *zvrf, struct route_node *rn, if (CHECK_FLAG(same->status, ROUTE_ENTRY_REMOVED)) continue; - if (same->type == re->type && same->instance == re->instance - && same->table == re->table - && same->type != ZEBRA_ROUTE_CONNECT) + if (same->type == re->type && same->instance == re->instance && + same->table == re->table && + (same->type != ZEBRA_ROUTE_CONNECT && + same->type != ZEBRA_ROUTE_LOCAL)) break; } @@ -676,6 +730,8 @@ int zebra_add_import_table_entry(struct zebra_vrf *zvrf, struct route_node *rn, zebra_del_import_table_entry(zvrf, rn, same); } + UNSET_FLAG(re->flags, ZEBRA_FLAG_RR_USE_DISTANCE); + newre = zebra_rib_route_entry_new( 0, ZEBRA_ROUTE_TABLE, re->table, re->flags, re->nhe_id, zvrf->table_id, re->metric, re->mtu, @@ -685,6 +741,7 @@ int zebra_add_import_table_entry(struct zebra_vrf *zvrf, struct route_node *rn, copy_nexthops(&ng->nexthop, re->nhe->nhg.nexthop, NULL); rib_add_multipath(afi, SAFI_UNICAST, &p, NULL, newre, ng, false); + nexthop_group_delete(&ng); return 0; } @@ -716,7 +773,7 @@ int zebra_import_table(afi_t afi, vrf_id_t vrf_id, uint32_t table_id, struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(vrf_id); if (!is_zebra_valid_kernel_table(table_id) - || (table_id == RT_TABLE_MAIN)) + || (table_id == rt_table_main_id)) return -1; if (afi >= AFI_MAX) diff --git a/zebra/rib.h b/zebra/rib.h index a56bb05d68..4c817eca71 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -167,6 +167,10 @@ struct route_entry { #define RIB_KERNEL_ROUTE(R) RKERNEL_ROUTE((R)->type) +/* Define route types that are equivalent to "connected". */ +#define RIB_CONNECTED_ROUTE(R) \ + ((R)->type == ZEBRA_ROUTE_CONNECT || (R)->type == ZEBRA_ROUTE_LOCAL || (R)->type == ZEBRA_ROUTE_NHRP) + /* meta-queue structure: * sub-queue 0: nexthop group objects * sub-queue 1: EVPN/VxLAN objects @@ -181,6 +185,10 @@ struct route_entry { * don't generate routes */ #define MQ_SIZE 11 + +/* For checking that an object has already queued in some sub-queue */ +#define MQ_BIT_MASK ((1 << MQ_SIZE) - 1) + struct meta_queue { struct list *subq[MQ_SIZE]; uint32_t size; /* sum of lengths of all subqueues */ @@ -329,14 +337,16 @@ int route_entry_update_nhe(struct route_entry *re, struct nhg_hash_entry *new_nhghe); /* NHG replace has happend, we have to update route_entry pointers to new one */ -void rib_handle_nhg_replace(struct nhg_hash_entry *old_entry, - struct nhg_hash_entry *new_entry); +int rib_handle_nhg_replace(struct nhg_hash_entry *old_entry, + struct nhg_hash_entry *new_entry); #define route_entry_dump(prefix, src, re) _route_entry_dump(__func__, prefix, src, re) extern void _route_entry_dump(const char *func, union prefixconstptr pp, union prefixconstptr src_pp, const struct route_entry *re); +void zebra_rib_route_entry_free(struct route_entry *re); + struct route_entry * zebra_rib_route_entry_new(vrf_id_t vrf_id, int type, uint8_t instance, uint32_t flags, uint32_t nhe_id, uint32_t table_id, @@ -406,7 +416,8 @@ extern void rib_update_table(struct route_table *table, extern void rib_sweep_route(struct event *t); extern void rib_sweep_table(struct route_table *table); extern void rib_close_table(struct route_table *table); -extern void rib_init(void); +extern void zebra_rib_init(void); +extern void zebra_rib_terminate(void); extern unsigned long rib_score_proto(uint8_t proto, unsigned short instance); extern unsigned long rib_score_proto_table(uint8_t proto, unsigned short instance, @@ -421,6 +432,7 @@ extern int rib_queue_nhg_ctx_add(struct nhg_ctx *ctx); /* Enqueue incoming nhg from proto daemon for processing */ extern int rib_queue_nhe_add(struct nhg_hash_entry *nhe); +extern int rib_queue_nhe_del(struct nhg_hash_entry *nhe); /* Enqueue evpn route for processing */ int zebra_rib_queue_evpn_route_add(vrf_id_t vrf_id, const struct ethaddr *rmac, @@ -465,6 +477,13 @@ extern uint8_t route_distance(int type); extern void zebra_rib_evaluate_rn_nexthops(struct route_node *rn, uint32_t seq, bool rt_delete); +/* + * rib_find_rn_from_ctx + * + * Returns a lock increased route_node for the appropriate + * table and prefix specified by the context. Developer + * should unlock the node when done. + */ extern struct route_node * rib_find_rn_from_ctx(const struct zebra_dplane_ctx *ctx); @@ -612,7 +631,7 @@ extern void zebra_vty_init(void); extern pid_t pid; -extern bool v6_rr_semantics; +extern uint32_t rt_table_main_id; /* Name of hook calls */ #define ZEBRA_ON_RIB_PROCESS_HOOK_CALL "on_rib_process_dplane_results" diff --git a/zebra/rt.h b/zebra/rt.h index 2e3495a037..e5dc26150a 100644 --- a/zebra/rt.h +++ b/zebra/rt.h @@ -25,7 +25,8 @@ extern "C" { #define RKERNEL_ROUTE(type) ((type) == ZEBRA_ROUTE_KERNEL) #define RSYSTEM_ROUTE(type) \ - ((RKERNEL_ROUTE(type)) || (type) == ZEBRA_ROUTE_CONNECT) + ((RKERNEL_ROUTE(type)) || (type) == ZEBRA_ROUTE_CONNECT || \ + (type) == ZEBRA_ROUTE_LOCAL) #ifndef HAVE_NETLINK /* @@ -84,6 +85,8 @@ extern int kernel_get_ipmr_sg_stats(struct zebra_vrf *zvrf, void *mroute); * state. */ extern void interface_list(struct zebra_ns *zns); +extern void interface_list_tunneldump(struct zebra_ns *zns); +extern void interface_list_second(struct zebra_ns *zns); extern void kernel_init(struct zebra_ns *zns); extern void kernel_terminate(struct zebra_ns *zns, bool complete); extern void macfdb_read(struct zebra_ns *zns); diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index de01ced411..98bb890eb6 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -66,6 +66,7 @@ #include "zebra/zebra_evpn_mh.h" #include "zebra/zebra_trace.h" #include "zebra/zebra_neigh.h" +#include "lib/srv6.h" #ifndef AF_MPLS #define AF_MPLS 28 @@ -77,6 +78,8 @@ #define BR_SPH_LIST_SIZE 10 #endif +DEFINE_MTYPE_STATIC(LIB, NH_SRV6, "Nexthop srv6"); + static vlanid_t filter_vlan = 0; /* We capture whether the current kernel supports nexthop ids; by @@ -275,6 +278,7 @@ int zebra2proto(int proto) proto = RTPROT_ZEBRA; break; case ZEBRA_ROUTE_CONNECT: + case ZEBRA_ROUTE_LOCAL: case ZEBRA_ROUTE_KERNEL: proto = RTPROT_KERNEL; break; @@ -363,7 +367,8 @@ static inline int proto2zebra(int proto, int family, bool is_nexthop) proto = ZEBRA_ROUTE_NHG; break; } - /* Intentional fall thru */ + proto = ZEBRA_ROUTE_KERNEL; + break; default: /* * When a user adds a new protocol this will show up @@ -380,33 +385,6 @@ static inline int proto2zebra(int proto, int family, bool is_nexthop) return proto; } -/* -Pending: create an efficient table_id (in a tree/hash) based lookup) - */ -vrf_id_t vrf_lookup_by_table(uint32_t table_id, ns_id_t ns_id) -{ - struct vrf *vrf; - struct zebra_vrf *zvrf; - - RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) { - zvrf = vrf->info; - if (zvrf == NULL) - continue; - /* case vrf with netns : match the netnsid */ - if (vrf_is_backend_netns()) { - if (ns_id == zvrf_id(zvrf)) - return zvrf_id(zvrf); - } else { - /* VRF is VRF_BACKEND_VRF_LITE */ - if (zvrf->table_id != table_id) - continue; - return zvrf_id(zvrf); - } - } - - return VRF_DEFAULT; -} - /** * @parse_encap_mpls() - Parses encapsulated mpls attributes * @tb: Pointer to rtattr to look for nested items in. @@ -434,6 +412,36 @@ static int parse_encap_mpls(struct rtattr *tb, mpls_label_t *labels) return num_labels; } +/** + * @parse_encap_seg6local_flavors() - Parses encapsulated SRv6 flavors + * attributes + * @tb: Pointer to rtattr to look for nested items in. + * @flv: Pointer to store SRv6 flavors info in. + * + * Return: 0 on success, non-zero on error + */ +static int parse_encap_seg6local_flavors(struct rtattr *tb, + struct seg6local_flavors_info *flv) +{ + struct rtattr *tb_encap[SEG6_LOCAL_FLV_MAX + 1] = {}; + + netlink_parse_rtattr_nested(tb_encap, SEG6_LOCAL_FLV_MAX, tb); + + if (tb_encap[SEG6_LOCAL_FLV_OPERATION]) + flv->flv_ops = *(uint32_t *)RTA_DATA( + tb_encap[SEG6_LOCAL_FLV_OPERATION]); + + if (tb_encap[SEG6_LOCAL_FLV_LCBLOCK_BITS]) + flv->lcblock_len = *(uint8_t *)RTA_DATA( + tb_encap[SEG6_LOCAL_FLV_LCBLOCK_BITS]); + + if (tb_encap[SEG6_LOCAL_FLV_LCNODE_FN_BITS]) + flv->lcnode_func_len = *(uint8_t *)RTA_DATA( + tb_encap[SEG6_LOCAL_FLV_LCNODE_FN_BITS]); + + return 0; +} + static enum seg6local_action_t parse_encap_seg6local(struct rtattr *tb, struct seg6local_context *ctx) @@ -461,6 +469,11 @@ parse_encap_seg6local(struct rtattr *tb, ctx->table = *(uint32_t *)RTA_DATA(tb_encap[SEG6_LOCAL_VRFTABLE]); + if (tb_encap[SEG6_LOCAL_FLAVORS]) { + parse_encap_seg6local_flavors(tb_encap[SEG6_LOCAL_FLAVORS], + &ctx->flv); + } + return act; } @@ -468,19 +481,19 @@ static int parse_encap_seg6(struct rtattr *tb, struct in6_addr *segs) { struct rtattr *tb_encap[SEG6_IPTUNNEL_MAX + 1] = {}; struct seg6_iptunnel_encap *ipt = NULL; - struct in6_addr *segments = NULL; + int i; netlink_parse_rtattr_nested(tb_encap, SEG6_IPTUNNEL_MAX, tb); - /* - * TODO: It's not support multiple SID list. - */ if (tb_encap[SEG6_IPTUNNEL_SRH]) { ipt = (struct seg6_iptunnel_encap *) RTA_DATA(tb_encap[SEG6_IPTUNNEL_SRH]); - segments = ipt->srh[0].segments; - *segs = segments[0]; - return 1; + + for (i = ipt->srh[0].first_segment; i >= 0; i--) + memcpy(&segs[i], &ipt->srh[0].segments[i], + sizeof(struct in6_addr)); + + return ipt->srh[0].first_segment + 1; } return 0; @@ -498,7 +511,7 @@ parse_nexthop_unicast(ns_id_t ns_id, struct rtmsg *rtm, struct rtattr **tb, int num_labels = 0; enum seg6local_action_t seg6l_act = ZEBRA_SEG6_LOCAL_ACTION_UNSPEC; struct seg6local_context seg6l_ctx = {}; - struct in6_addr seg6_segs = {}; + struct in6_addr segs[SRV6_MAX_SIDS] = {}; int num_segs = 0; vrf_id_t nh_vrf_id = vrf_id; @@ -547,7 +560,7 @@ parse_nexthop_unicast(ns_id_t ns_id, struct rtmsg *rtm, struct rtattr **tb, if (tb[RTA_ENCAP] && tb[RTA_ENCAP_TYPE] && *(uint16_t *)RTA_DATA(tb[RTA_ENCAP_TYPE]) == LWTUNNEL_ENCAP_SEG6) { - num_segs = parse_encap_seg6(tb[RTA_ENCAP], &seg6_segs); + num_segs = parse_encap_seg6(tb[RTA_ENCAP], segs); } if (rtm->rtm_flags & RTNH_F_ONLINK) @@ -559,11 +572,21 @@ parse_nexthop_unicast(ns_id_t ns_id, struct rtmsg *rtm, struct rtattr **tb, if (num_labels) nexthop_add_labels(&nh, ZEBRA_LSP_STATIC, num_labels, labels); + /* Resolve default values for SRv6 flavors */ + if (seg6l_ctx.flv.flv_ops != ZEBRA_SEG6_LOCAL_FLV_OP_UNSPEC) { + if (seg6l_ctx.flv.lcblock_len == 0) + seg6l_ctx.flv.lcblock_len = + ZEBRA_DEFAULT_SEG6_LOCAL_FLV_LCBLOCK_LEN; + if (seg6l_ctx.flv.lcnode_func_len == 0) + seg6l_ctx.flv.lcnode_func_len = + ZEBRA_DEFAULT_SEG6_LOCAL_FLV_LCNODE_FN_LEN; + } + if (seg6l_act != ZEBRA_SEG6_LOCAL_ACTION_UNSPEC) nexthop_add_srv6_seg6local(&nh, seg6l_act, &seg6l_ctx); if (num_segs) - nexthop_add_srv6_seg6(&nh, &seg6_segs); + nexthop_add_srv6_seg6(&nh, segs, num_segs); return nh; } @@ -583,7 +606,7 @@ static uint8_t parse_multipath_nexthops_unicast(ns_id_t ns_id, int num_labels = 0; enum seg6local_action_t seg6l_act = ZEBRA_SEG6_LOCAL_ACTION_UNSPEC; struct seg6local_context seg6l_ctx = {}; - struct in6_addr seg6_segs = {}; + struct in6_addr segs[SRV6_MAX_SIDS] = {}; int num_segs = 0; struct rtattr *rtnh_tb[RTA_MAX + 1] = {}; @@ -639,7 +662,7 @@ static uint8_t parse_multipath_nexthops_unicast(ns_id_t ns_id, && *(uint16_t *)RTA_DATA(rtnh_tb[RTA_ENCAP_TYPE]) == LWTUNNEL_ENCAP_SEG6) { num_segs = parse_encap_seg6(rtnh_tb[RTA_ENCAP], - &seg6_segs); + segs); } } @@ -666,12 +689,23 @@ static uint8_t parse_multipath_nexthops_unicast(ns_id_t ns_id, nexthop_add_labels(nh, ZEBRA_LSP_STATIC, num_labels, labels); + /* Resolve default values for SRv6 flavors */ + if (seg6l_ctx.flv.flv_ops != + ZEBRA_SEG6_LOCAL_FLV_OP_UNSPEC) { + if (seg6l_ctx.flv.lcblock_len == 0) + seg6l_ctx.flv.lcblock_len = + ZEBRA_DEFAULT_SEG6_LOCAL_FLV_LCBLOCK_LEN; + if (seg6l_ctx.flv.lcnode_func_len == 0) + seg6l_ctx.flv.lcnode_func_len = + ZEBRA_DEFAULT_SEG6_LOCAL_FLV_LCNODE_FN_LEN; + } + if (seg6l_act != ZEBRA_SEG6_LOCAL_ACTION_UNSPEC) nexthop_add_srv6_seg6local(nh, seg6l_act, &seg6l_ctx); if (num_segs) - nexthop_add_srv6_seg6(nh, &seg6_segs); + nexthop_add_srv6_seg6(nh, segs, num_segs); if (rtnh->rtnh_flags & RTNH_F_ONLINK) SET_FLAG(nh->flags, NEXTHOP_FLAG_ONLINK); @@ -790,7 +824,7 @@ int netlink_route_change_read_unicast_internal(struct nlmsghdr *h, table = rtm->rtm_table; /* Map to VRF */ - vrf_id = vrf_lookup_by_table(table, ns_id); + vrf_id = zebra_vrf_lookup_by_table(table, ns_id); if (vrf_id == VRF_DEFAULT) { if (!is_zebra_valid_kernel_table(table) && !is_zebra_main_routing_table(table)) @@ -993,6 +1027,8 @@ int netlink_route_change_read_unicast_internal(struct nlmsghdr *h, re, ng, startup, ctx); if (ng) nexthop_group_delete(&ng); + if (ctx) + zebra_rib_route_entry_free(re); } else { /* * I really don't see how this is possible @@ -1079,7 +1115,7 @@ static int netlink_route_change_read_multicast(struct nlmsghdr *h, else table = rtm->rtm_table; - vrf = vrf_lookup_by_table(table, ns_id); + vrf = zebra_vrf_lookup_by_table(table, ns_id); if (tb[RTA_IIF]) iif = *(int *)RTA_DATA(tb[RTA_IIF]); @@ -1485,37 +1521,80 @@ static bool _netlink_route_encode_nexthop_src(const struct nexthop *nexthop, } static ssize_t fill_seg6ipt_encap(char *buffer, size_t buflen, - const struct in6_addr *seg) + struct seg6_seg_stack *segs) { struct seg6_iptunnel_encap *ipt; struct ipv6_sr_hdr *srh; - const size_t srhlen = 24; + size_t srhlen; + int i; - /* - * Caution: Support only SINGLE-SID, not MULTI-SID - * This function only supports the case where segs represents - * a single SID. If you want to extend the SRv6 functionality, - * you should improve the Boundary Check. - * Ex. In case of set a SID-List include multiple-SIDs as an - * argument of the Transit Behavior, we must support variable - * boundary check for buflen. - */ - if (buflen < (sizeof(struct seg6_iptunnel_encap) + - sizeof(struct ipv6_sr_hdr) + 16)) + if (segs->num_segs > SRV6_MAX_SEGS) { + /* Exceeding maximum supported SIDs */ + return -1; + } + + srhlen = SRH_BASE_HEADER_LENGTH + SRH_SEGMENT_LENGTH * segs->num_segs; + + if (buflen < (sizeof(struct seg6_iptunnel_encap) + srhlen)) return -1; memset(buffer, 0, buflen); ipt = (struct seg6_iptunnel_encap *)buffer; ipt->mode = SEG6_IPTUN_MODE_ENCAP; - srh = ipt->srh; + + srh = (struct ipv6_sr_hdr *)&ipt->srh; srh->hdrlen = (srhlen >> 3) - 1; srh->type = 4; - srh->segments_left = 0; - srh->first_segment = 0; - memcpy(&srh->segments[0], seg, sizeof(struct in6_addr)); + srh->segments_left = segs->num_segs - 1; + srh->first_segment = segs->num_segs - 1; + + for (i = 0; i < segs->num_segs; i++) { + memcpy(&srh->segments[i], &segs->seg[i], + sizeof(struct in6_addr)); + } + + return sizeof(struct seg6_iptunnel_encap) + srhlen; +} + +static bool +_netlink_nexthop_encode_seg6local_flavor(const struct nexthop *nexthop, + struct nlmsghdr *nlmsg, size_t buflen) +{ + struct rtattr *nest; + struct seg6local_flavors_info *flv; + + assert(nexthop); + + if (!nexthop->nh_srv6) + return false; + + flv = &nexthop->nh_srv6->seg6local_ctx.flv; + + if (flv->flv_ops == ZEBRA_SEG6_LOCAL_FLV_OP_UNSPEC) + return true; + + nest = nl_attr_nest(nlmsg, buflen, SEG6_LOCAL_FLAVORS); + if (!nest) + return false; + + if (!nl_attr_put32(nlmsg, buflen, SEG6_LOCAL_FLV_OPERATION, + flv->flv_ops)) + return false; + + if (flv->lcblock_len) + if (!nl_attr_put8(nlmsg, buflen, SEG6_LOCAL_FLV_LCBLOCK_BITS, + flv->lcblock_len)) + return false; + + if (flv->lcnode_func_len) + if (!nl_attr_put8(nlmsg, buflen, SEG6_LOCAL_FLV_LCNODE_FN_BITS, + flv->lcnode_func_len)) + return false; - return srhlen + 4; + nl_attr_nest_end(nlmsg, nest); + + return true; } /* This function takes a nexthop as argument and adds @@ -1649,10 +1728,17 @@ static bool _netlink_route_build_singlepath(const struct prefix *p, nexthop->nh_srv6->seg6local_action); return false; } + + if (!_netlink_nexthop_encode_seg6local_flavor( + nexthop, nlmsg, req_size)) + return false; + nl_attr_nest_end(nlmsg, nest); } - if (!sid_zero(&nexthop->nh_srv6->seg6_segs)) { + if (nexthop->nh_srv6->seg6_segs && + nexthop->nh_srv6->seg6_segs->num_segs && + !sid_zero(nexthop->nh_srv6->seg6_segs)) { char tun_buf[4096]; ssize_t tun_len; struct rtattr *nest; @@ -1663,8 +1749,9 @@ static bool _netlink_route_build_singlepath(const struct prefix *p, nest = nl_attr_nest(nlmsg, req_size, RTA_ENCAP); if (!nest) return false; - tun_len = fill_seg6ipt_encap(tun_buf, sizeof(tun_buf), - &nexthop->nh_srv6->seg6_segs); + tun_len = + fill_seg6ipt_encap(tun_buf, sizeof(tun_buf), + nexthop->nh_srv6->seg6_segs); if (tun_len < 0) return false; if (!nl_attr_put(nlmsg, req_size, SEG6_IPTUNNEL_SRH, @@ -2087,10 +2174,10 @@ static int netlink_route_nexthop_encap(struct nlmsghdr *n, size_t nlen, * Returns -1 on failure, 0 when the msg doesn't fit entirely in the buffer * otherwise the number of bytes written to buf. */ -ssize_t netlink_route_multipath_msg_encode(int cmd, - struct zebra_dplane_ctx *ctx, +ssize_t netlink_route_multipath_msg_encode(int cmd, struct zebra_dplane_ctx *ctx, uint8_t *data, size_t datalen, - bool fpm, bool force_nhg) + bool fpm, bool force_nhg, + bool force_rr) { int bytelen; struct nexthop *nexthop = NULL; @@ -2124,8 +2211,10 @@ ssize_t netlink_route_multipath_msg_encode(int cmd, req->n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); req->n.nlmsg_flags = NLM_F_CREATE | NLM_F_REQUEST; - if ((cmd == RTM_NEWROUTE) && - ((p->family == AF_INET) || v6_rr_semantics)) + if (((cmd == RTM_NEWROUTE) && + ((p->family == AF_INET) || kernel_nexthops_supported() || + zrouter.v6_rr_semantics)) || + force_rr) req->n.nlmsg_flags |= NLM_F_REPLACE; req->n.nlmsg_type = cmd; @@ -2328,19 +2417,21 @@ ssize_t netlink_route_multipath_msg_encode(int cmd, p, routedesc, bytelen, nexthop, &req->n, &req->r, datalen, cmd)) return 0; + + /* + * Add encapsulation information when + * installing via FPM. + */ + if (fpm) { + if (!netlink_route_nexthop_encap(&req->n, + datalen, + nexthop)) + return 0; + } + nexthop_num++; break; } - - /* - * Add encapsulation information when installing via - * FPM. - */ - if (fpm) { - if (!netlink_route_nexthop_encap( - &req->n, datalen, nexthop)) - return 0; - } } if (setsrc) { @@ -2387,6 +2478,16 @@ ssize_t netlink_route_multipath_msg_encode(int cmd, tag)) return 0; + /* + * Add encapsulation information when installing via + * FPM. + */ + if (fpm) { + if (!netlink_route_nexthop_encap( + &req->n, datalen, nexthop)) + return 0; + } + if (!setsrc && src1) { if (p->family == AF_INET) src.ipv4 = src1->ipv4; @@ -2400,23 +2501,6 @@ ssize_t netlink_route_multipath_msg_encode(int cmd, nl_attr_nest_end(&req->n, nest); - /* - * Add encapsulation information when installing via - * FPM. - */ - if (fpm) { - for (ALL_NEXTHOPS_PTR(dplane_ctx_get_ng(ctx), - nexthop)) { - if (CHECK_FLAG(nexthop->flags, - NEXTHOP_FLAG_RECURSIVE)) - continue; - if (!netlink_route_nexthop_encap( - &req->n, datalen, nexthop)) - return 0; - } - } - - if (setsrc) { if (p->family == AF_INET) { if (!nl_attr_put(&req->n, datalen, RTA_PREFSRC, @@ -2503,7 +2587,7 @@ int kernel_get_ipmr_sg_stats(struct zebra_vrf *zvrf, void *in) * are trying to give me. So now we have this little hack. */ if (mroute->family == AF_INET) - actual_table = (zvrf->table_id == RT_TABLE_MAIN) + actual_table = (zvrf->table_id == rt_table_main_id) ? RT_TABLE_DEFAULT : zvrf->table_id; else @@ -2543,7 +2627,7 @@ static bool _netlink_nexthop_build_group(struct nlmsghdr *n, size_t req_size, if (IS_ZEBRA_DEBUG_KERNEL) { if (i == 0) - snprintf(buf, sizeof(buf1), "group %u", + snprintf(buf, sizeof(buf), "group %u", grp[i].id); else { snprintf(buf1, sizeof(buf1), "/%u", @@ -2888,10 +2972,17 @@ ssize_t netlink_nexthop_msg_encode(uint16_t cmd, __func__, action); return 0; } + + if (!_netlink_nexthop_encode_seg6local_flavor( + nh, &req->n, buflen)) + return false; + nl_attr_nest_end(&req->n, nest); } - if (!sid_zero(&nh->nh_srv6->seg6_segs)) { + if (nh->nh_srv6->seg6_segs && + nh->nh_srv6->seg6_segs->num_segs && + !sid_zero(nh->nh_srv6->seg6_segs)) { char tun_buf[4096]; ssize_t tun_len; struct rtattr *nest; @@ -2904,9 +2995,9 @@ ssize_t netlink_nexthop_msg_encode(uint16_t cmd, NHA_ENCAP | NLA_F_NESTED); if (!nest) return 0; - tun_len = fill_seg6ipt_encap(tun_buf, - sizeof(tun_buf), - &nh->nh_srv6->seg6_segs); + tun_len = fill_seg6ipt_encap( + tun_buf, sizeof(tun_buf), + nh->nh_srv6->seg6_segs); if (tun_len < 0) return 0; if (!nl_attr_put(&req->n, buflen, @@ -2980,14 +3071,14 @@ static ssize_t netlink_newroute_msg_encoder(struct zebra_dplane_ctx *ctx, void *buf, size_t buflen) { return netlink_route_multipath_msg_encode(RTM_NEWROUTE, ctx, buf, - buflen, false, false); + buflen, false, false, false); } static ssize_t netlink_delroute_msg_encoder(struct zebra_dplane_ctx *ctx, void *buf, size_t buflen) { return netlink_route_multipath_msg_encode(RTM_DELROUTE, ctx, buf, - buflen, false, false); + buflen, false, false, false); } enum netlink_msg_status @@ -3001,8 +3092,8 @@ netlink_put_route_update_msg(struct nl_batch *bth, struct zebra_dplane_ctx *ctx) } else if (dplane_ctx_get_op(ctx) == DPLANE_OP_ROUTE_INSTALL) { cmd = RTM_NEWROUTE; } else if (dplane_ctx_get_op(ctx) == DPLANE_OP_ROUTE_UPDATE) { - - if (p->family == AF_INET || v6_rr_semantics) { + if (p->family == AF_INET || kernel_nexthops_supported() || + zrouter.v6_rr_semantics) { /* Single 'replace' operation */ /* @@ -4631,76 +4722,24 @@ static ssize_t netlink_neigh_msg_encoder(struct zebra_dplane_ctx *ctx, void *buf, size_t buflen) { ssize_t ret = 0; + enum dplane_op_e op; - switch (dplane_ctx_get_op(ctx)) { - case DPLANE_OP_NEIGH_INSTALL: - case DPLANE_OP_NEIGH_UPDATE: - case DPLANE_OP_NEIGH_DISCOVER: - case DPLANE_OP_NEIGH_IP_INSTALL: + op = dplane_ctx_get_op(ctx); + if (op == DPLANE_OP_NEIGH_INSTALL || op == DPLANE_OP_NEIGH_UPDATE || + op == DPLANE_OP_NEIGH_DISCOVER || op == DPLANE_OP_NEIGH_IP_INSTALL) ret = netlink_neigh_update_ctx(ctx, RTM_NEWNEIGH, buf, buflen); - break; - case DPLANE_OP_NEIGH_DELETE: - case DPLANE_OP_NEIGH_IP_DELETE: + else if (op == DPLANE_OP_NEIGH_DELETE || op == DPLANE_OP_NEIGH_IP_DELETE) ret = netlink_neigh_update_ctx(ctx, RTM_DELNEIGH, buf, buflen); - break; - case DPLANE_OP_VTEP_ADD: + else if (op == DPLANE_OP_VTEP_ADD) ret = netlink_vxlan_flood_update_ctx(ctx, RTM_NEWNEIGH, buf, buflen); - break; - case DPLANE_OP_VTEP_DELETE: + else if (op == DPLANE_OP_VTEP_DELETE) ret = netlink_vxlan_flood_update_ctx(ctx, RTM_DELNEIGH, buf, buflen); - break; - case DPLANE_OP_NEIGH_TABLE_UPDATE: + else if (op == DPLANE_OP_NEIGH_TABLE_UPDATE) ret = netlink_neigh_table_update_ctx(ctx, buf, buflen); - break; - case DPLANE_OP_ROUTE_INSTALL: - case DPLANE_OP_ROUTE_UPDATE: - case DPLANE_OP_ROUTE_DELETE: - case DPLANE_OP_ROUTE_NOTIFY: - case DPLANE_OP_NH_INSTALL: - case DPLANE_OP_NH_UPDATE: - case DPLANE_OP_NH_DELETE: - case DPLANE_OP_LSP_INSTALL: - case DPLANE_OP_LSP_UPDATE: - case DPLANE_OP_LSP_DELETE: - case DPLANE_OP_LSP_NOTIFY: - case DPLANE_OP_PW_INSTALL: - case DPLANE_OP_PW_UNINSTALL: - case DPLANE_OP_SYS_ROUTE_ADD: - case DPLANE_OP_SYS_ROUTE_DELETE: - case DPLANE_OP_ADDR_INSTALL: - case DPLANE_OP_ADDR_UNINSTALL: - case DPLANE_OP_MAC_INSTALL: - case DPLANE_OP_MAC_DELETE: - case DPLANE_OP_RULE_ADD: - case DPLANE_OP_RULE_DELETE: - case DPLANE_OP_RULE_UPDATE: - case DPLANE_OP_BR_PORT_UPDATE: - case DPLANE_OP_IPTABLE_ADD: - case DPLANE_OP_IPTABLE_DELETE: - case DPLANE_OP_IPSET_ADD: - case DPLANE_OP_IPSET_DELETE: - case DPLANE_OP_IPSET_ENTRY_ADD: - case DPLANE_OP_IPSET_ENTRY_DELETE: - case DPLANE_OP_GRE_SET: - case DPLANE_OP_INTF_ADDR_ADD: - case DPLANE_OP_INTF_ADDR_DEL: - case DPLANE_OP_INTF_NETCONFIG: - case DPLANE_OP_INTF_INSTALL: - case DPLANE_OP_INTF_UPDATE: - case DPLANE_OP_INTF_DELETE: - case DPLANE_OP_TC_QDISC_INSTALL: - case DPLANE_OP_TC_QDISC_UNINSTALL: - case DPLANE_OP_TC_CLASS_ADD: - case DPLANE_OP_TC_CLASS_DELETE: - case DPLANE_OP_TC_CLASS_UPDATE: - case DPLANE_OP_TC_FILTER_ADD: - case DPLANE_OP_TC_FILTER_DELETE: - case DPLANE_OP_TC_FILTER_UPDATE: - case DPLANE_OP_NONE: + else ret = -1; - } return ret; } @@ -4785,7 +4824,7 @@ ssize_t netlink_mpls_multipath_msg_encode(int cmd, struct zebra_dplane_ctx *ctx, req->n.nlmsg_pid = nl->snl.nl_pid; req->r.rtm_family = AF_MPLS; - req->r.rtm_table = RT_TABLE_MAIN; + req->r.rtm_table = rt_table_main_id; req->r.rtm_dst_len = MPLS_LABEL_LEN_BITS; req->r.rtm_scope = RT_SCOPE_UNIVERSE; req->r.rtm_type = RTN_UNICAST; diff --git a/zebra/rt_netlink.h b/zebra/rt_netlink.h index 3ca59ce676..d51944f1a4 100644 --- a/zebra/rt_netlink.h +++ b/zebra/rt_netlink.h @@ -56,7 +56,8 @@ extern ssize_t netlink_mpls_multipath_msg_encode(int cmd, extern ssize_t netlink_route_multipath_msg_encode(int cmd, struct zebra_dplane_ctx *ctx, uint8_t *data, size_t datalen, - bool fpm, bool force_nhg); + bool fpm, bool force_nhg, + bool force_rr); extern ssize_t netlink_macfdb_update_ctx(struct zebra_dplane_ctx *ctx, void *data, size_t datalen); @@ -90,7 +91,6 @@ extern int netlink_macfdb_read_specific_mac(struct zebra_ns *zns, uint16_t vid); extern int netlink_neigh_read_specific_ip(const struct ipaddr *ip, struct interface *vlan_if); -extern vrf_id_t vrf_lookup_by_table(uint32_t table_id, ns_id_t ns_id); struct nl_batch; extern enum netlink_msg_status diff --git a/zebra/rt_socket.c b/zebra/rt_socket.c index f9888b12d4..0bfcd518ca 100644 --- a/zebra/rt_socket.c +++ b/zebra/rt_socket.c @@ -6,6 +6,8 @@ #include <zebra.h> +#include <net/route.h> + #ifndef HAVE_NETLINK #ifdef __OpenBSD__ diff --git a/zebra/rtadv.c b/zebra/rtadv.c index 9af41cbc39..00f018d192 100644 --- a/zebra/rtadv.c +++ b/zebra/rtadv.c @@ -6,6 +6,7 @@ */ #include <zebra.h> +#include <netinet/icmp6.h> #include "memory.h" #include "sockopt.h" @@ -33,6 +34,7 @@ extern struct zebra_privs_t zserv_privs; static uint32_t interfaces_configured_for_ra_from_bgp; +#define RTADV_ADATA_SIZE 1024 #if defined(HAVE_RTADV) @@ -58,7 +60,7 @@ DEFINE_MTYPE_STATIC(ZEBRA, ADV_IF, "Advertised Interface"); /* adv list node */ struct adv_if { - char name[INTERFACE_NAMSIZ]; + char name[IFNAMSIZ]; struct adv_if_list_item list_item; }; @@ -187,8 +189,9 @@ static void rtadv_send_packet(int sock, struct interface *ifp, struct cmsghdr *cmsgptr; struct in6_pktinfo *pkt; struct sockaddr_in6 addr; - static void *adata = NULL; unsigned char buf[RTADV_MSG_SIZE]; + char adata[RTADV_ADATA_SIZE]; + struct nd_router_advert *rtadv; int ret; int len = 0; @@ -199,22 +202,6 @@ static void rtadv_send_packet(int sock, struct interface *ifp, struct listnode *node; uint16_t pkt_RouterLifetime; - /* - * Allocate control message bufffer. This is dynamic because - * CMSG_SPACE is not guaranteed not to call a function. Note that - * the size will be different on different architectures due to - * differing alignment rules. - */ - if (adata == NULL) { - /* XXX Free on shutdown. */ - adata = calloc(1, CMSG_SPACE(sizeof(struct in6_pktinfo))); - - if (adata == NULL) { - zlog_debug("%s: can't malloc control data", __func__); - exit(-1); - } - } - /* Logging of packet. */ if (IS_ZEBRA_DEBUG_PACKET) zlog_debug("%s(%s:%u): Tx RA, socket %u", ifp->name, @@ -3069,3 +3056,13 @@ uint32_t rtadv_get_interfaces_configured_from_bgp(void) { return interfaces_configured_for_ra_from_bgp; } + +void rtadv_init(void) +{ + if (CMSG_SPACE(sizeof(struct in6_pktinfo)) > RTADV_ADATA_SIZE) { + zlog_debug("%s: RTADV_ADATA_SIZE choosen will not work on this platform, please use a larger size", + __func__); + + exit(-1); + } +} diff --git a/zebra/rtadv.h b/zebra/rtadv.h index 1ec376a106..9d358d4b0d 100644 --- a/zebra/rtadv.h +++ b/zebra/rtadv.h @@ -435,6 +435,7 @@ extern void zebra_interface_radv_enable(ZAPI_HANDLER_ARGS); extern uint32_t rtadv_get_interfaces_configured_from_bgp(void); extern bool rtadv_compiled_in(void); +extern void rtadv_init(void); #ifdef __cplusplus } diff --git a/zebra/rtread_sysctl.c b/zebra/rtread_sysctl.c index ef1e21b4f7..8e2d13faff 100644 --- a/zebra/rtread_sysctl.c +++ b/zebra/rtread_sysctl.c @@ -6,6 +6,8 @@ #include <zebra.h> +#include <net/route.h> + #if !defined(GNU_LINUX) #include "memory.h" diff --git a/zebra/rule_netlink.c b/zebra/rule_netlink.c index c7832992ea..05282793d7 100644 --- a/zebra/rule_netlink.c +++ b/zebra/rule_netlink.c @@ -9,6 +9,9 @@ #ifdef HAVE_NETLINK +#include <linux/netlink.h> +#include <linux/rtnetlink.h> + #include "if.h" #include "prefix.h" #include "vrf.h" @@ -116,9 +119,9 @@ static ssize_t netlink_rule_msg_encode( return 0; } - /* dsfield, if specified */ - if (filter_bm & PBR_FILTER_DSFIELD) - req->frh.tos = dsfield; + /* dsfield, if specified; mask off the ECN bits */ + if (filter_bm & PBR_FILTER_DSCP) + req->frh.tos = dsfield & PBR_DSFIELD_DSCP; /* protocol to match on */ if (filter_bm & PBR_FILTER_IP_PROTOCOL) @@ -174,6 +177,17 @@ static ssize_t netlink_oldrule_msg_encoder(struct zebra_dplane_ctx *ctx, dplane_ctx_rule_get_old_ipproto(ctx), buf, buflen); } +/* + * Identify valid rule actions for netlink - other actions can't be installed + */ +static bool nl_rule_valid_action(uint32_t action) +{ + if (action == PBR_ACTION_TABLE) + return true; + else + return false; +} + /* Public functions */ enum netlink_msg_status @@ -181,6 +195,7 @@ netlink_put_rule_update_msg(struct nl_batch *bth, struct zebra_dplane_ctx *ctx) { enum dplane_op_e op; enum netlink_msg_status ret; + struct pbr_rule rule = {}; op = dplane_ctx_get_op(ctx); if (!(op == DPLANE_OP_RULE_ADD || op == DPLANE_OP_RULE_UPDATE @@ -192,6 +207,18 @@ netlink_put_rule_update_msg(struct nl_batch *bth, struct zebra_dplane_ctx *ctx) return FRR_NETLINK_ERROR; } + /* TODO -- special handling for rules that include actions that + * netlink cannot install. Some of the rule attributes are not + * available in netlink: only try to install valid actions. + */ + dplane_ctx_rule_get(ctx, &rule, NULL); + if (!nl_rule_valid_action(rule.action.flags)) { + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug("%s: skip invalid action %#x", __func__, + rule.action.flags); + return 0; + } + ret = netlink_batch_add_msg(bth, ctx, netlink_rule_msg_encoder, false); /** @@ -400,6 +427,7 @@ int netlink_rules_read(struct zebra_ns *zns) ret = netlink_parse_info(netlink_rule_change, &zns->netlink_cmd, &dp_info, 0, true); + return ret; } diff --git a/zebra/subdir.am b/zebra/subdir.am index 1060e38785..a59515d3a8 100644 --- a/zebra/subdir.am +++ b/zebra/subdir.am @@ -52,6 +52,7 @@ zebra_zebra_SOURCES = \ zebra/redistribute.c \ zebra/router-id.c \ zebra/rt_netlink.c \ + zebra/ge_netlink.c \ zebra/rt_socket.c \ zebra/rtadv.c \ zebra/rtread_netlink.c \ @@ -124,6 +125,7 @@ clippy_scan += \ zebra/zebra_srv6_vty.c \ zebra/zebra_vrf.c \ zebra/dpdk/zebra_dplane_dpdk_vty.c \ + zebra/label_manager.c \ # end noinst_HEADERS += \ @@ -143,6 +145,7 @@ noinst_HEADERS += \ zebra/router-id.h \ zebra/rt.h \ zebra/rt_netlink.h \ + zebra/ge_netlink.h \ zebra/rtadv.h \ zebra/rule_netlink.h \ zebra/table_manager.h \ diff --git a/zebra/table_manager.c b/zebra/table_manager.c index 77ec42e64b..512508b79f 100644 --- a/zebra/table_manager.c +++ b/zebra/table_manager.c @@ -63,8 +63,7 @@ void table_manager_enable(struct zebra_vrf *zvrf) && strcmp(zvrf_name(zvrf), VRF_DEFAULT_NAME)) { struct zebra_vrf *def = zebra_vrf_lookup_by_id(VRF_DEFAULT); - if (def) - zvrf->tbl_mgr = def->tbl_mgr; + zvrf->tbl_mgr = def->tbl_mgr; return; } zvrf->tbl_mgr = XCALLOC(MTYPE_TM_TABLE, sizeof(struct table_manager)); diff --git a/zebra/tc_netlink.c b/zebra/tc_netlink.c index 679dc80a58..19667e66ac 100644 --- a/zebra/tc_netlink.c +++ b/zebra/tc_netlink.c @@ -9,6 +9,7 @@ #ifdef HAVE_NETLINK +#include <linux/rtnetlink.h> #include <linux/pkt_cls.h> #include <linux/pkt_sched.h> #include <netinet/if_ether.h> @@ -160,7 +161,7 @@ static ssize_t netlink_qdisc_msg_encode(int cmd, struct zebra_dplane_ctx *ctx, struct nlmsghdr n; struct tcmsg t; char buf[0]; - } *req = (void *)data; + } *req = data; if (datalen < sizeof(*req)) return 0; @@ -236,7 +237,7 @@ static ssize_t netlink_tclass_msg_encode(int cmd, struct zebra_dplane_ctx *ctx, struct nlmsghdr n; struct tcmsg t; char buf[0]; - } *req = (void *)data; + } *req = data; if (datalen < sizeof(*req)) return 0; @@ -486,7 +487,7 @@ static ssize_t netlink_tfilter_msg_encode(int cmd, struct zebra_dplane_ctx *ctx, struct nlmsghdr n; struct tcmsg t; char buf[0]; - } *req = (void *)data; + } *req = data; if (datalen < sizeof(*req)) return 0; @@ -703,6 +704,8 @@ int netlink_qdisc_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) { struct tcmsg *tcm; struct zebra_tc_qdisc qdisc = {}; + enum tc_qdisc_kind kind = TC_QDISC_UNSPEC; + const char *kind_str = "Unknown"; int len; struct rtattr *tb[TCA_MAX + 1]; @@ -722,9 +725,11 @@ int netlink_qdisc_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) tcm = NLMSG_DATA(h); netlink_parse_rtattr(tb, TCA_MAX, TCA_RTA(tcm), len); - const char *kind_str = (const char *)RTA_DATA(tb[TCA_KIND]); + if (RTA_DATA(tb[TCA_KIND])) { + kind_str = (const char *)RTA_DATA(tb[TCA_KIND]); - enum tc_qdisc_kind kind = tc_qdisc_str2kind(kind_str); + kind = tc_qdisc_str2kind(kind_str); + } qdisc.qdisc.ifindex = tcm->tcm_ifindex; diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index 4c6c336d41..761eafeb13 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -5,6 +5,8 @@ * Copyright (C) 1997-1999 Kunihiro Ishiguro * Copyright (C) 2015-2018 Cumulus Networks, Inc. * et al. + * Copyright (c) 2021 The MITRE Corporation. + * Copyright (c) 2023 LabN Consulting, L.L.C. */ #include <zebra.h> @@ -22,6 +24,7 @@ #include "lib/vrf.h" #include "lib/libfrr.h" #include "lib/lib_errors.h" +#include "lib/frrdistance.h" #include "zebra/zebra_router.h" #include "zebra/rib.h" @@ -61,7 +64,7 @@ static void zserv_encode_interface(struct stream *s, struct interface *ifp) /* Interface information. */ struct zebra_if *zif = ifp->info; - stream_put(s, ifp->name, INTERFACE_NAMSIZ); + stream_put(s, ifp->name, IFNAMSIZ); stream_putl(s, ifp->ifindex); stream_putc(s, ifp->status); stream_putq(s, ifp->flags); @@ -69,6 +72,7 @@ static void zserv_encode_interface(struct stream *s, struct interface *ifp) stream_putc(s, ifp->ptm_status); stream_putl(s, ifp->metric); stream_putl(s, ifp->speed); + stream_putl(s, ifp->txqlen); stream_putl(s, ifp->mtu); stream_putl(s, ifp->mtu6); stream_putl(s, ifp->bandwidth); @@ -411,7 +415,7 @@ int zsend_interface_addresses(struct zserv *client, struct interface *ifp) struct nbr_connected *nc; /* Send interface addresses. */ - for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, c)) { + frr_each (if_connected, ifp->connected, c) { if (!CHECK_FLAG(c->conf, ZEBRA_IFC_REAL)) continue; @@ -432,27 +436,6 @@ int zsend_interface_addresses(struct zserv *client, struct interface *ifp) return 0; } -/* Notify client about interface moving from one VRF to another. - * Whether client is interested in old and new VRF is checked by caller. - */ -int zsend_interface_vrf_update(struct zserv *client, struct interface *ifp, - vrf_id_t vrf_id) -{ - struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ); - - zclient_create_header(s, ZEBRA_INTERFACE_VRF_UPDATE, ifp->vrf->vrf_id); - - /* Fill in the name of the interface and its new VRF (id) */ - stream_put(s, ifp->name, INTERFACE_NAMSIZ); - stream_putl(s, vrf_id); - - /* Write packet size. */ - stream_putw_at(s, 0, stream_get_endp(s)); - - client->if_vrfchg_cnt++; - return zserv_send_message(client, s); -} - /* Add new nbr connected IPv6 address */ void nbr_connected_add_ipv6(struct interface *ifp, struct in6_addr *address) { @@ -528,7 +511,7 @@ int zsend_interface_update(int cmd, struct zserv *client, struct interface *ifp) int zsend_redistribute_route(int cmd, struct zserv *client, const struct route_node *rn, - const struct route_entry *re) + const struct route_entry *re, bool is_table_direct) { struct zapi_route api; struct zapi_nexthop *api_nh; @@ -544,7 +527,11 @@ int zsend_redistribute_route(int cmd, struct zserv *client, api.vrf_id = re->vrf_id; api.type = re->type; api.safi = SAFI_UNICAST; - api.instance = re->instance; + if (is_table_direct) { + api.instance = re->table; + api.type = ZEBRA_ROUTE_TABLE_DIRECT; + } else + api.instance = re->instance; api.flags = re->flags; afi = family2afi(p->family); @@ -611,7 +598,10 @@ int zsend_redistribute_route(int cmd, struct zserv *client, /* Attributes. */ SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE); - api.distance = re->distance; + if (is_table_direct) + api.distance = ZEBRA_TABLEDIRECT_DISTANCE_DEFAULT; + else + api.distance = re->distance; SET_FLAG(api.message, ZAPI_MESSAGE_METRIC); api.metric = re->metric; if (re->tag) { @@ -801,11 +791,17 @@ int zsend_route_notify_owner(const struct route_node *rn, int zsend_route_notify_owner_ctx(const struct zebra_dplane_ctx *ctx, enum zapi_route_notify_owner note) { - return (route_notify_internal( - rib_find_rn_from_ctx(ctx), dplane_ctx_get_type(ctx), - dplane_ctx_get_instance(ctx), dplane_ctx_get_vrf(ctx), - dplane_ctx_get_table(ctx), note, dplane_ctx_get_afi(ctx), - dplane_ctx_get_safi(ctx))); + int result; + struct route_node *rn = rib_find_rn_from_ctx(ctx); + + result = route_notify_internal( + rn, dplane_ctx_get_type(ctx), dplane_ctx_get_instance(ctx), + dplane_ctx_get_vrf(ctx), dplane_ctx_get_table(ctx), note, + dplane_ctx_get_afi(ctx), dplane_ctx_get_safi(ctx)); + + route_unlock_node(rn); + + return result; } static void zread_route_notify_request(ZAPI_HANDLER_ARGS) @@ -839,12 +835,14 @@ void zsend_rule_notify_owner(const struct zebra_dplane_ctx *ctx, s = stream_new(ZEBRA_MAX_PACKET_SIZ); - zclient_create_header(s, ZEBRA_RULE_NOTIFY_OWNER, VRF_DEFAULT); + zclient_create_header(s, ZEBRA_RULE_NOTIFY_OWNER, + dplane_ctx_rule_get_vrfid(ctx)); + stream_put(s, ¬e, sizeof(note)); stream_putl(s, dplane_ctx_rule_get_seq(ctx)); stream_putl(s, dplane_ctx_rule_get_priority(ctx)); stream_putl(s, dplane_ctx_rule_get_unique(ctx)); - stream_put(s, dplane_ctx_rule_get_ifname(ctx), INTERFACE_NAMSIZ); + stream_put(s, dplane_ctx_rule_get_ifname(ctx), IFNAMSIZ); stream_putw_at(s, 0, stream_get_endp(s)); @@ -989,7 +987,7 @@ void zsend_nhrp_neighbor_notify(int cmd, struct interface *ifp, family2addrsize(sockunion_family(&ip))); for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) { - if (!vrf_bitmap_check(client->nhrp_neighinfo[afi], + if (!vrf_bitmap_check(&client->nhrp_neighinfo[afi], ifp->vrf->vrf_id)) continue; @@ -1010,7 +1008,7 @@ int zsend_router_id_update(struct zserv *client, afi_t afi, struct prefix *p, struct stream *s; /* Check this client need interface information. */ - if (!vrf_bitmap_check(client->ridinfo[afi], vrf_id)) + if (!vrf_bitmap_check(&client->ridinfo[afi], vrf_id)) return 0; s = stream_new(ZEBRA_MAX_PACKET_SIZ); @@ -1038,7 +1036,7 @@ int zsend_pw_update(struct zserv *client, struct zebra_pw *pw) struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ); zclient_create_header(s, ZEBRA_PW_STATUS_UPDATE, pw->vrf_id); - stream_write(s, pw->ifname, INTERFACE_NAMSIZ); + stream_write(s, pw->ifname, IFNAMSIZ); stream_putl(s, pw->ifindex); stream_putl(s, pw->status); @@ -1331,8 +1329,6 @@ static void zread_fec_register(ZAPI_HANDLER_ARGS) s = msg; zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - if (!zvrf) - return; /* * The minimum amount of data that can be sent for one fec @@ -1394,8 +1390,6 @@ static void zread_fec_unregister(ZAPI_HANDLER_ARGS) s = msg; zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - if (!zvrf) - return; /* * The minimum amount of data that can be sent for one @@ -1554,7 +1548,6 @@ static struct nexthop *nexthop_from_zapi(const struct zapi_nexthop *api_nh, uint16_t backup_nexthop_num) { struct nexthop *nexthop = NULL; - struct ipaddr vtep_ip; struct interface *ifp; int i; char nhbuf[INET6_ADDRSTRLEN] = ""; @@ -1590,13 +1583,8 @@ static struct nexthop *nexthop_from_zapi(const struct zapi_nexthop *api_nh, * the nexthop and associated MAC need to be installed. */ if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_EVPN)) { - memset(&vtep_ip, 0, sizeof(vtep_ip)); - vtep_ip.ipa_type = IPADDR_V4; - memcpy(&(vtep_ip.ipaddr_v4), &(api_nh->gate.ipv4), - sizeof(struct in_addr)); - zebra_rib_queue_evpn_route_add( - api_nh->vrf_id, &api_nh->rmac, &vtep_ip, p); SET_FLAG(nexthop->flags, NEXTHOP_FLAG_EVPN); + nexthop->rmac = api_nh->rmac; } break; case NEXTHOP_TYPE_IPV6: @@ -1624,13 +1612,8 @@ static struct nexthop *nexthop_from_zapi(const struct zapi_nexthop *api_nh, * the nexthop and associated MAC need to be installed. */ if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_EVPN)) { - memset(&vtep_ip, 0, sizeof(vtep_ip)); - vtep_ip.ipa_type = IPADDR_V6; - memcpy(&vtep_ip.ipaddr_v6, &(api_nh->gate.ipv6), - sizeof(struct in6_addr)); - zebra_rib_queue_evpn_route_add( - api_nh->vrf_id, &api_nh->rmac, &vtep_ip, p); SET_FLAG(nexthop->flags, NEXTHOP_FLAG_EVPN); + nexthop->rmac = api_nh->rmac; } break; case NEXTHOP_TYPE_BLACKHOLE: @@ -1704,10 +1687,14 @@ static bool zapi_read_nexthops(struct zserv *client, struct prefix *p, struct nexthop_group **png, struct nhg_backup_info **pbnhg) { + struct zapi_nexthop *znh; struct nexthop_group *ng = NULL; struct nhg_backup_info *bnhg = NULL; uint16_t i; struct nexthop *last_nh = NULL; + bool same_weight = true; + uint64_t max_weight = 0; + uint64_t tmp; assert(!(png && pbnhg)); @@ -1722,6 +1709,41 @@ static bool zapi_read_nexthops(struct zserv *client, struct prefix *p, bnhg = zebra_nhg_backup_alloc(); } + for (i = 0; i < nexthop_num; i++) { + znh = &nhops[i]; + + if (max_weight < znh->weight) { + if (i != 0 || znh->weight != 1) + same_weight = false; + + max_weight = znh->weight; + } + } + + /* + * Let's convert the weights to a scaled value + * between 1 and zrouter.nexthop_weight_scale_value + * This is a simple application of a ratio: + * scaled_weight/zrouter.nexthop_weight_scale_value = + * weight/max_weight + * This translates to: + * scaled_weight = weight * zrouter.nexthop_weight_scale_value + * ------------------------------------------- + * max_weight + * + * This same formula is applied to both the nexthops + * and the backup nexthops + */ + if (!same_weight) { + for (i = 0; i < nexthop_num; i++) { + znh = &nhops[i]; + + tmp = (uint64_t)znh->weight * + zrouter.nexthop_weight_scale_value; + znh->weight = MAX(1, ((uint32_t)(tmp / max_weight))); + } + } + /* * TBD should _all_ of the nexthop add operations use * api_nh->vrf_id instead of re->vrf_id ? I only changed @@ -1800,7 +1822,8 @@ static bool zapi_read_nexthops(struct zserv *client, struct prefix *p, if (IS_ZEBRA_DEBUG_RECV) zlog_debug("%s: adding seg6", __func__); - nexthop_add_srv6_seg6(nexthop, &api_nh->seg6_segs); + nexthop_add_srv6_seg6(nexthop, &api_nh->seg6_segs[0], + api_nh->seg_num); } if (IS_ZEBRA_DEBUG_RECV) { @@ -1936,20 +1959,21 @@ static void zread_nhg_del(ZAPI_HANDLER_ARGS) return; } - /* - * Delete the received nhg id - */ - nhe = zebra_nhg_proto_del(api_nhg.id, api_nhg.proto); + /* Create a temporary nhe */ + nhe = zebra_nhg_alloc(); + nhe->id = api_nhg.id; + nhe->type = api_nhg.proto; + nhe->zapi_instance = client->instance; + nhe->zapi_session = client->session_id; - if (nhe) { - zebra_nhg_decrement_ref(nhe); - zsend_nhg_notify(api_nhg.proto, client->instance, - client->session_id, api_nhg.id, - ZAPI_NHG_REMOVED); - } else - zsend_nhg_notify(api_nhg.proto, client->instance, - client->session_id, api_nhg.id, - ZAPI_NHG_REMOVE_FAIL); + /* Sanity check - Empty nexthop and group */ + nhe->nhg.nexthop = NULL; + + /* Enqueue to workqueue for processing */ + rib_queue_nhe_del(nhe); + + /* Stats */ + client->nhg_del_cnt++; } static void zread_nhg_add(ZAPI_HANDLER_ARGS) @@ -1958,7 +1982,7 @@ static void zread_nhg_add(ZAPI_HANDLER_ARGS) struct zapi_nhg api_nhg = {}; struct nexthop_group *nhg = NULL; struct nhg_backup_info *bnhg = NULL; - struct nhg_hash_entry *nhe; + struct nhg_hash_entry *nhe, *nhe_tmp; s = msg; if (zapi_nhg_decode(s, hdr->command, &api_nhg) < 0) { @@ -2016,6 +2040,12 @@ static void zread_nhg_add(ZAPI_HANDLER_ARGS) nexthop_group_delete(&nhg); zebra_nhg_backup_free(&bnhg); + /* Stats */ + nhe_tmp = zebra_nhg_lookup_id(api_nhg.id); + if (nhe_tmp) + client->nhg_upd8_cnt++; + else + client->nhg_add_cnt++; } static void zread_route_add(ZAPI_HANDLER_ARGS) @@ -2275,7 +2305,7 @@ static void zread_router_id_add(ZAPI_HANDLER_ARGS) } /* Router-id information is needed. */ - vrf_bitmap_set(client->ridinfo[afi], zvrf_id(zvrf)); + vrf_bitmap_set(&client->ridinfo[afi], zvrf_id(zvrf)); router_id_get(afi, &p, zvrf); @@ -2311,7 +2341,7 @@ static void zread_router_id_delete(ZAPI_HANDLER_ARGS) goto stream_failure; } - vrf_bitmap_unset(client->ridinfo[afi], zvrf_id(zvrf)); + vrf_bitmap_unset(&client->ridinfo[afi], zvrf_id(zvrf)); stream_failure: return; @@ -2326,7 +2356,7 @@ static void zsend_capabilities(struct zserv *client, struct zebra_vrf *zvrf) stream_putc(s, mpls_enabled); stream_putl(s, zrouter.multipath_num); stream_putc(s, zebra_mlag_get_role()); - + stream_putc(s, zrouter.v6_with_v4_nexthop); stream_putw_at(s, 0, stream_get_endp(s)); zserv_send_message(client, s); } @@ -2353,23 +2383,19 @@ static void zread_hello(ZAPI_HANDLER_ARGS) /* type of protocol (lib/zebra.h) */ uint8_t proto; unsigned short instance; - uint8_t notify; uint8_t synchronous; uint32_t session_id; STREAM_GETC(msg, proto); STREAM_GETW(msg, instance); STREAM_GETL(msg, session_id); - STREAM_GETC(msg, notify); STREAM_GETC(msg, synchronous); - if (notify) - client->notify_owner = true; if (synchronous) client->synchronous = true; /* accept only dynamic routing protocols */ - if ((proto < ZEBRA_ROUTE_MAX) && (proto > ZEBRA_ROUTE_CONNECT)) { + if ((proto < ZEBRA_ROUTE_MAX) && (proto > ZEBRA_ROUTE_LOCAL)) { zlog_notice( "client %d says hello and bids fair to announce only %s routes vrf=%u", client->sock, zebra_route_string(proto), @@ -2401,10 +2427,11 @@ static void zread_vrf_unregister(ZAPI_HANDLER_ARGS) for (afi = AFI_IP; afi < AFI_MAX; afi++) { for (i = 0; i < ZEBRA_ROUTE_MAX; i++) - vrf_bitmap_unset(client->redist[afi][i], zvrf_id(zvrf)); - vrf_bitmap_unset(client->redist_default[afi], zvrf_id(zvrf)); - vrf_bitmap_unset(client->ridinfo[afi], zvrf_id(zvrf)); - vrf_bitmap_unset(client->nhrp_neighinfo[afi], zvrf_id(zvrf)); + vrf_bitmap_unset(&client->redist[afi][i], + zvrf_id(zvrf)); + vrf_bitmap_unset(&client->redist_default[afi], zvrf_id(zvrf)); + vrf_bitmap_unset(&client->ridinfo[afi], zvrf_id(zvrf)); + vrf_bitmap_unset(&client->nhrp_neighinfo[afi], zvrf_id(zvrf)); } } @@ -2984,7 +3011,7 @@ static void zread_srv6_manager_request(ZAPI_HANDLER_ARGS) static void zread_pseudowire(ZAPI_HANDLER_ARGS) { struct stream *s; - char ifname[INTERFACE_NAMSIZ]; + char ifname[IFNAMSIZ]; ifindex_t ifindex; int type; int af; @@ -3000,8 +3027,8 @@ static void zread_pseudowire(ZAPI_HANDLER_ARGS) s = msg; /* Get data. */ - STREAM_GET(ifname, s, INTERFACE_NAMSIZ); - ifname[INTERFACE_NAMSIZ - 1] = '\0'; + STREAM_GET(ifname, s, IFNAMSIZ); + ifname[IFNAMSIZ - 1] = '\0'; STREAM_GETL(s, ifindex); STREAM_GETL(s, type); STREAM_GETL(s, af); @@ -3179,7 +3206,6 @@ static inline void zread_rule(ZAPI_HANDLER_ARGS) struct zebra_pbr_rule zpr; struct stream *s; uint32_t total, i; - char ifname[INTERFACE_NAMSIZ + 1] = {}; s = msg; STREAM_GETL(s, total); @@ -3189,59 +3215,38 @@ static inline void zread_rule(ZAPI_HANDLER_ARGS) zpr.sock = client->sock; zpr.rule.vrf_id = hdr->vrf_id; - STREAM_GETL(s, zpr.rule.seq); - STREAM_GETL(s, zpr.rule.priority); - STREAM_GETL(s, zpr.rule.unique); - STREAM_GETC(s, zpr.rule.filter.ip_proto); - STREAM_GETC(s, zpr.rule.filter.src_ip.family); - STREAM_GETC(s, zpr.rule.filter.src_ip.prefixlen); - STREAM_GET(&zpr.rule.filter.src_ip.u.prefix, s, - prefix_blen(&zpr.rule.filter.src_ip)); - STREAM_GETW(s, zpr.rule.filter.src_port); - STREAM_GETC(s, zpr.rule.filter.dst_ip.family); - STREAM_GETC(s, zpr.rule.filter.dst_ip.prefixlen); - STREAM_GET(&zpr.rule.filter.dst_ip.u.prefix, s, - prefix_blen(&zpr.rule.filter.dst_ip)); - STREAM_GETW(s, zpr.rule.filter.dst_port); - STREAM_GETC(s, zpr.rule.filter.dsfield); - STREAM_GETL(s, zpr.rule.filter.fwmark); - - STREAM_GETL(s, zpr.rule.action.queue_id); - STREAM_GETW(s, zpr.rule.action.vlan_id); - STREAM_GETW(s, zpr.rule.action.vlan_flags); - STREAM_GETW(s, zpr.rule.action.pcp); - - STREAM_GETL(s, zpr.rule.action.table); - STREAM_GET(ifname, s, INTERFACE_NAMSIZ); - - strlcpy(zpr.ifname, ifname, sizeof(zpr.ifname)); - strlcpy(zpr.rule.ifname, ifname, sizeof(zpr.rule.ifname)); - - if (!is_default_prefix(&zpr.rule.filter.src_ip)) - zpr.rule.filter.filter_bm |= PBR_FILTER_SRC_IP; - - if (!is_default_prefix(&zpr.rule.filter.dst_ip)) - zpr.rule.filter.filter_bm |= PBR_FILTER_DST_IP; - - if (zpr.rule.filter.src_port) - zpr.rule.filter.filter_bm |= PBR_FILTER_SRC_PORT; - - if (zpr.rule.filter.dst_port) - zpr.rule.filter.filter_bm |= PBR_FILTER_DST_PORT; - - if (zpr.rule.filter.dsfield) - zpr.rule.filter.filter_bm |= PBR_FILTER_DSFIELD; - - if (zpr.rule.filter.ip_proto) - zpr.rule.filter.filter_bm |= PBR_FILTER_IP_PROTOCOL; - - if (zpr.rule.filter.fwmark) - zpr.rule.filter.filter_bm |= PBR_FILTER_FWMARK; + if (!zapi_pbr_rule_decode(s, &zpr.rule)) + goto stream_failure; + + strlcpy(zpr.ifname, zpr.rule.ifname, sizeof(zpr.ifname)); + + if ((zpr.rule.family != AF_INET) && + (zpr.rule.family != AF_INET6)) { + zlog_warn("Unsupported PBR source IP family: %s (%hhu)", + family2str(zpr.rule.family), zpr.rule.family); + return; + } + + /* + * Fixup filter src/dst IP addresses if they are unset + * because the netlink code currently obtains address family + * from them. Address family is used to specify which + * kernel database to use when adding/deleting rule. + * + * TBD: propagate zpr.rule.family into dataplane and + * netlink code so they can stop using filter src/dst addrs. + */ + if (!CHECK_FLAG(zpr.rule.filter.filter_bm, PBR_FILTER_SRC_IP)) + zpr.rule.filter.src_ip.family = zpr.rule.family; + if (!CHECK_FLAG(zpr.rule.filter.filter_bm, PBR_FILTER_DST_IP)) + zpr.rule.filter.dst_ip.family = zpr.rule.family; + + /* TBD delete below block when netlink code gets family from zpr.rule.family */ if (!(zpr.rule.filter.src_ip.family == AF_INET || zpr.rule.filter.src_ip.family == AF_INET6)) { zlog_warn( - "Unsupported PBR source IP family: %s (%hhu)", + "Unsupported PBR source IP family: %s (%u)", family2str(zpr.rule.filter.src_ip.family), zpr.rule.filter.src_ip.family); return; @@ -3249,11 +3254,12 @@ static inline void zread_rule(ZAPI_HANDLER_ARGS) if (!(zpr.rule.filter.dst_ip.family == AF_INET || zpr.rule.filter.dst_ip.family == AF_INET6)) { zlog_warn( - "Unsupported PBR destination IP family: %s (%hhu)", + "Unsupported PBR destination IP family: %s (%u)", family2str(zpr.rule.filter.dst_ip.family), zpr.rule.filter.dst_ip.family); return; } + /* TBD delete above block when netlink code gets family from zpr.rule.family */ zpr.vrf_id = zvrf->vrf->vrf_id; @@ -3508,7 +3514,7 @@ static inline void zread_ipset_entry(ZAPI_HANDLER_ARGS) if (zpi.src_port_max != 0) zpi.filter_bm |= PBR_FILTER_SRC_PORT_RANGE; if (zpi.proto != 0) - zpi.filter_bm |= PBR_FILTER_PROTO; + zpi.filter_bm |= PBR_FILTER_IP_PROTOCOL; if (!(zpi.dst.family == AF_INET || zpi.dst.family == AF_INET6)) { @@ -3557,7 +3563,7 @@ static inline void zebra_neigh_register(ZAPI_HANDLER_ARGS) afi); goto stream_failure; } - vrf_bitmap_set(client->nhrp_neighinfo[afi], zvrf_id(zvrf)); + vrf_bitmap_set(&client->nhrp_neighinfo[afi], zvrf_id(zvrf)); stream_failure: return; } @@ -3573,7 +3579,7 @@ static inline void zebra_neigh_unregister(ZAPI_HANDLER_ARGS) afi); goto stream_failure; } - vrf_bitmap_unset(client->nhrp_neighinfo[afi], zvrf_id(zvrf)); + vrf_bitmap_unset(&client->nhrp_neighinfo[afi], zvrf_id(zvrf)); stream_failure: return; } @@ -3976,8 +3982,7 @@ void zserv_handle_commands(struct zserv *client, struct stream_fifo *fifo) hdr.length -= ZEBRA_HEADER_SIZE; /* Before checking for a handler function, check for - * special messages that are handled in another module; - * we'll treat these as opaque. + * special messages that are handled the 'opaque zapi' module. */ if (zebra_opaque_handles_msgid(hdr.command)) { /* Reset message buffer */ diff --git a/zebra/zapi_msg.h b/zebra/zapi_msg.h index ce8e154465..def1e8a1bd 100644 --- a/zebra/zapi_msg.h +++ b/zebra/zapi_msg.h @@ -53,12 +53,11 @@ extern int zsend_interface_update(int cmd, struct zserv *client, struct interface *ifp); extern int zsend_redistribute_route(int cmd, struct zserv *zclient, const struct route_node *rn, - const struct route_entry *re); + const struct route_entry *re, + bool is_table_direct); extern int zsend_router_id_update(struct zserv *zclient, afi_t afi, struct prefix *p, vrf_id_t vrf_id); -extern int zsend_interface_vrf_update(struct zserv *zclient, - struct interface *ifp, vrf_id_t vrf_id); extern int zsend_interface_link_params(struct zserv *zclient, struct interface *ifp); extern int zsend_pw_update(struct zserv *client, struct zebra_pw *pw); diff --git a/zebra/zebra_dplane.c b/zebra/zebra_dplane.c index a768c33a30..99693a5874 100644 --- a/zebra/zebra_dplane.c +++ b/zebra/zebra_dplane.c @@ -2,6 +2,8 @@ /* * Zebra dataplane layer. * Copyright (c) 2018 Volta Networks, Inc. + * Portions: + * Copyright (c) 2021 The MITRE Corporation. */ #ifdef HAVE_CONFIG_H @@ -180,10 +182,47 @@ struct dplane_br_port_info { */ struct dplane_intf_info { + enum zebra_iftype zif_type; + ifindex_t bond_ifindex; + ifindex_t link_ifindex; + int32_t mtu; + vrf_id_t vrf_id; + enum zebra_slave_iftype zif_slave_type; + ifindex_t master_ifindex; + ifindex_t bridge_ifindex; + ns_id_t link_nsid; + enum zebra_slave_iftype zslave_type; + uint8_t bypass; + enum zebra_link_type zltype; + bool startup; + uint8_t family; + struct zebra_vxlan_vni_array *vniarray; + bool no_bvinfo_avail; + bool no_afspec_avail; + struct zebra_dplane_bridge_vlan_info bvinfo; + struct zebra_dplane_bridge_vlan_info_array *bvarray; + + char desc[128]; + + int32_t hw_addr_len; + uint8_t hw_addr[INTERFACE_HWADDR_MAX]; + + uint32_t table_id; + + struct zebra_l2info_bridge binfo; + struct zebra_l2info_vlan vinfo; + struct zebra_l2info_vxlan vxinfo; + struct zebra_l2info_gre grinfo; + + uint32_t rc_bitfield; + + uint32_t txqlen; + uint32_t metric; uint32_t flags; bool protodown; + bool protodown_set; bool pd_reason_val; #define DPLANE_INTF_CONNECTED (1 << 0) /* Connected peer, p2p */ @@ -191,6 +230,7 @@ struct dplane_intf_info { #define DPLANE_INTF_BROADCAST (1 << 2) #define DPLANE_INTF_HAS_DEST DPLANE_INTF_CONNECTED #define DPLANE_INTF_HAS_LABEL (1 << 4) +#define DPLANE_INTF_NOPREFIXROUTE (1 << 5) /* Interface address/prefix */ struct prefix prefix; @@ -245,28 +285,8 @@ struct dplane_neigh_table { * Policy based routing rule info for the dataplane */ struct dplane_ctx_rule { - uint32_t priority; - - /* The route table pointed by this rule */ - uint32_t table; - - /* Filter criteria */ - uint32_t filter_bm; - uint32_t fwmark; - uint8_t dsfield; - struct prefix src_ip; - struct prefix dst_ip; - uint8_t ip_proto; - uint16_t src_port; - uint16_t dst_port; - - uint8_t action_pcp; - uint16_t action_vlan_id; - uint16_t action_vlan_flags; + struct pbr_rule prule; - uint32_t action_queue_id; - - char ifname[INTERFACE_NAMSIZ + 1]; struct ethaddr smac; struct ethaddr dmac; int out_ifindex; @@ -336,6 +356,13 @@ struct dplane_tc_filter_info { uint32_t classid; }; +/* + * SRv6 encapsulation params context for the dataplane + */ +struct dplane_srv6_encap_ctx { + struct in6_addr srcaddr; +}; + /* * The context block used to exchange info about route updates across * the boundary between the zebra main context (and pthread) and the @@ -372,7 +399,7 @@ struct zebra_dplane_ctx { vrf_id_t zd_vrf_id; uint32_t zd_table_id; - char zd_ifname[INTERFACE_NAMSIZ]; + char zd_ifname[IFNAMSIZ]; ifindex_t zd_ifindex; /* Support info for different kinds of updates */ @@ -397,6 +424,8 @@ struct zebra_dplane_ctx { struct dplane_neigh_table neightable; struct dplane_gre_ctx gre; struct dplane_netconf_info netconf; + enum zebra_dplane_startup_notifications spot; + struct dplane_srv6_encap_ctx srv6_encap; } u; /* Namespace info, used especially for netlink kernel communication */ @@ -578,6 +607,9 @@ static struct zebra_dplane_globals { _Atomic uint32_t dg_tcs_in; _Atomic uint32_t dg_tcs_errors; + _Atomic uint32_t dg_srv6_encap_srcaddr_set_in; + _Atomic uint32_t dg_srv6_encap_srcaddr_set_errors; + /* Dataplane pthread */ struct frr_pthread *dg_pthread; @@ -808,8 +840,14 @@ static void dplane_ctx_free_internal(struct zebra_dplane_ctx *ctx) case DPLANE_OP_NONE: case DPLANE_OP_IPSET_ADD: case DPLANE_OP_IPSET_DELETE: + break; case DPLANE_OP_INTF_INSTALL: case DPLANE_OP_INTF_UPDATE: + if (ctx->u.intf.vniarray) + XFREE(MTYPE_TMP, ctx->u.intf.vniarray); + if (ctx->u.intf.bvarray) + XFREE(MTYPE_TMP, ctx->u.intf.bvarray); + break; case DPLANE_OP_INTF_DELETE: case DPLANE_OP_TC_QDISC_INSTALL: case DPLANE_OP_TC_QDISC_UNINSTALL: @@ -833,6 +871,8 @@ static void dplane_ctx_free_internal(struct zebra_dplane_ctx *ctx) break; case DPLANE_OP_GRE_SET: case DPLANE_OP_INTF_NETCONFIG: + case DPLANE_OP_STARTUP_STAGE: + case DPLANE_OP_SRV6_ENCAP_SRCADDR_SET: break; } } @@ -1156,6 +1196,13 @@ const char *dplane_op2str(enum dplane_op_e op) case DPLANE_OP_TC_FILTER_UPDATE: ret = "TC__FILTER_UPDATE"; break; + case DPLANE_OP_STARTUP_STAGE: + ret = "STARTUP_STAGE"; + break; + + case DPLANE_OP_SRV6_ENCAP_SRCADDR_SET: + ret = "SRV6_ENCAP_SRCADDR_SET"; + break; } return ret; @@ -1218,83 +1265,527 @@ const struct prefix *dplane_ctx_get_src(const struct zebra_dplane_ctx *ctx) } } -bool dplane_ctx_is_update(const struct zebra_dplane_ctx *ctx) +bool dplane_ctx_is_update(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->zd_is_update; +} + +uint32_t dplane_ctx_get_seq(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->zd_seq; +} + +uint32_t dplane_ctx_get_old_seq(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->zd_old_seq; +} + +void dplane_ctx_set_vrf(struct zebra_dplane_ctx *ctx, vrf_id_t vrf) +{ + DPLANE_CTX_VALID(ctx); + + ctx->zd_vrf_id = vrf; +} + +vrf_id_t dplane_ctx_get_vrf(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->zd_vrf_id; +} + +/* In some paths we have only a namespace id */ +void dplane_ctx_set_ns_id(struct zebra_dplane_ctx *ctx, ns_id_t nsid) +{ + DPLANE_CTX_VALID(ctx); + + ctx->zd_ns_info.ns_id = nsid; +} + +ns_id_t dplane_ctx_get_ns_id(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->zd_ns_info.ns_id; +} + +bool dplane_ctx_is_from_notif(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return (ctx->zd_notif_provider != 0); +} + +uint32_t dplane_ctx_get_notif_provider(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->zd_notif_provider; +} + +void dplane_ctx_set_notif_provider(struct zebra_dplane_ctx *ctx, + uint32_t id) +{ + DPLANE_CTX_VALID(ctx); + + ctx->zd_notif_provider = id; +} + +const char *dplane_ctx_get_ifname(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->zd_ifname; +} + +void dplane_ctx_set_ifp_bridge_vlan_info_array( + struct zebra_dplane_ctx *ctx, + struct zebra_dplane_bridge_vlan_info_array *bvarray) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.bvarray = bvarray; +} + +const struct zebra_dplane_bridge_vlan_info_array * +dplane_ctx_get_ifp_bridge_vlan_info_array(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.bvarray; +} + +void dplane_ctx_set_ifp_vxlan_vni_array(struct zebra_dplane_ctx *ctx, + struct zebra_vxlan_vni_array *vniarray) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.vniarray = vniarray; +} + +const struct zebra_vxlan_vni_array * +dplane_ctx_get_ifp_vxlan_vni_array(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.vniarray; +} + +void dplane_ctx_set_ifp_no_afspec(struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.no_afspec_avail = true; +} + +bool dplane_ctx_get_ifp_no_afspec(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.no_afspec_avail; +} + +void dplane_ctx_set_ifp_no_bridge_vlan_info(struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.no_bvinfo_avail = true; +} + +bool dplane_ctx_get_ifp_no_bridge_vlan_info(struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.no_bvinfo_avail; +} + +void dplane_ctx_set_ifp_bridge_vlan_info( + struct zebra_dplane_ctx *ctx, + struct zebra_dplane_bridge_vlan_info *bvinfo) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.bvinfo = *bvinfo; +} + +const struct zebra_dplane_bridge_vlan_info * +dplane_ctx_get_ifp_bridge_vlan_info(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return &ctx->u.intf.bvinfo; +} + +void dplane_ctx_set_ifp_family(struct zebra_dplane_ctx *ctx, uint8_t family) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.family = family; +} + +uint8_t dplane_ctx_get_ifp_family(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.family; +} + +void dplane_ctx_set_ifp_zltype(struct zebra_dplane_ctx *ctx, + enum zebra_link_type zltype) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.zltype = zltype; +} + +enum zebra_link_type +dplane_ctx_get_ifp_zltype(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.zltype; +} + +void dplane_ctx_set_ifp_link_ifindex(struct zebra_dplane_ctx *ctx, + ifindex_t link_ifindex) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.link_ifindex = link_ifindex; +} + +ifindex_t dplane_ctx_get_ifp_link_ifindex(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.link_ifindex; +} + +void dplane_ctx_set_ifp_desc(struct zebra_dplane_ctx *ctx, const char *desc) +{ + DPLANE_CTX_VALID(ctx); + + strlcpy(ctx->u.intf.desc, desc, sizeof(ctx->u.intf.desc)); +} + +char *dplane_ctx_get_ifp_desc(struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.desc; +} + +void dplane_ctx_set_ifp_flags(struct zebra_dplane_ctx *ctx, uint64_t flags) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.flags = flags; +} + +uint64_t dplane_ctx_get_ifp_flags(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.flags; +} + +void dplane_ctx_set_ifp_bypass(struct zebra_dplane_ctx *ctx, uint8_t bypass) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.bypass = bypass; +} + +uint8_t dplane_ctx_get_ifp_bypass(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.bypass; +} + +void dplane_ctx_set_ifp_bridge_ifindex(struct zebra_dplane_ctx *ctx, + ifindex_t bridge_ifindex) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.bridge_ifindex = bridge_ifindex; +} + +ifindex_t dplane_ctx_get_ifp_bridge_ifindex(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.bridge_ifindex; +} + +void dplane_ctx_set_ifp_zif_slave_type(struct zebra_dplane_ctx *ctx, + enum zebra_slave_iftype zslave_type) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.zslave_type = zslave_type; +} + +enum zebra_slave_iftype +dplane_ctx_get_ifp_zif_slave_type(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.zslave_type; +} + +void dplane_ctx_set_ifp_master_ifindex(struct zebra_dplane_ctx *ctx, + ifindex_t master_ifindex) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.master_ifindex = master_ifindex; +} + +ifindex_t dplane_ctx_get_ifp_master_ifindex(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.master_ifindex; +} + +void dplane_ctx_set_ifp_mtu(struct zebra_dplane_ctx *ctx, uint32_t mtu) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.mtu = mtu; +} + +uint32_t dplane_ctx_get_ifp_mtu(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.mtu; +} + +void dplane_ctx_set_ifp_vrf_id(struct zebra_dplane_ctx *ctx, vrf_id_t vrf_id) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.vrf_id = vrf_id; +} + +vrf_id_t dplane_ctx_get_ifp_vrf_id(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.vrf_id; +} + +void dplane_ctx_set_ifp_link_nsid(struct zebra_dplane_ctx *ctx, + ns_id_t link_nsid) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.link_nsid = link_nsid; +} + +ns_id_t dplane_ctx_get_ifp_link_nsid(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.link_nsid; +} + +void dplane_ctx_set_ifp_startup(struct zebra_dplane_ctx *ctx, bool startup) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.startup = startup; +} + +bool dplane_ctx_get_ifp_startup(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.startup; +} + +void dplane_ctx_set_ifp_protodown_set(struct zebra_dplane_ctx *ctx, bool set) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.protodown_set = set; +} + +bool dplane_ctx_get_ifp_protodown_set(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.protodown_set; +} + +void dplane_ctx_set_ifp_protodown(struct zebra_dplane_ctx *ctx, bool protodown) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.protodown = protodown; +} + +bool dplane_ctx_get_ifp_protodown(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.protodown; +} + +ifindex_t dplane_ctx_get_ifp_bond_ifindex(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.bond_ifindex; +} + +void dplane_ctx_set_ifp_rc_bitfield(struct zebra_dplane_ctx *ctx, + uint32_t rc_bitfield) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.rc_bitfield = rc_bitfield; +} + +uint32_t dplane_ctx_get_ifp_rc_bitfield(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.rc_bitfield; +} + +void dplane_ctx_set_ifp_gre_info(struct zebra_dplane_ctx *ctx, + struct zebra_l2info_gre *grinfo) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.grinfo = *grinfo; +} + +const struct zebra_l2info_gre * +dplane_ctx_get_ifp_gre_info(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return &ctx->u.intf.grinfo; +} + +void dplane_ctx_set_ifp_vxlan_info(struct zebra_dplane_ctx *ctx, + struct zebra_l2info_vxlan *vxinfo) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.vxinfo = *vxinfo; +} + +const struct zebra_l2info_vxlan * +dplane_ctx_get_ifp_vxlan_info(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return &ctx->u.intf.vxinfo; +} + +void dplane_ctx_set_ifp_vlan_info(struct zebra_dplane_ctx *ctx, + struct zebra_l2info_vlan *vinfo) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.vinfo = *vinfo; +} + +const struct zebra_l2info_vlan * +dplane_ctx_get_ifp_vlan_info(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->zd_is_update; + return &ctx->u.intf.vinfo; } -uint32_t dplane_ctx_get_seq(const struct zebra_dplane_ctx *ctx) +void dplane_ctx_set_ifp_bridge_info(struct zebra_dplane_ctx *ctx, + struct zebra_l2info_bridge *binfo) { DPLANE_CTX_VALID(ctx); - return ctx->zd_seq; + ctx->u.intf.binfo = *binfo; } -uint32_t dplane_ctx_get_old_seq(const struct zebra_dplane_ctx *ctx) +const struct zebra_l2info_bridge * +dplane_ctx_get_ifp_bridge_info(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->zd_old_seq; + return &ctx->u.intf.binfo; } -void dplane_ctx_set_vrf(struct zebra_dplane_ctx *ctx, vrf_id_t vrf) +void dplane_ctx_set_ifp_table_id(struct zebra_dplane_ctx *ctx, + uint32_t table_id) { DPLANE_CTX_VALID(ctx); - ctx->zd_vrf_id = vrf; + ctx->u.intf.table_id = table_id; } -vrf_id_t dplane_ctx_get_vrf(const struct zebra_dplane_ctx *ctx) +uint32_t dplane_ctx_get_ifp_table_id(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->zd_vrf_id; + return ctx->u.intf.table_id; } -/* In some paths we have only a namespace id */ -void dplane_ctx_set_ns_id(struct zebra_dplane_ctx *ctx, ns_id_t nsid) +void dplane_ctx_set_ifp_hw_addr(struct zebra_dplane_ctx *ctx, + int32_t hw_addr_len, uint8_t *hw_addr) { DPLANE_CTX_VALID(ctx); - ctx->zd_ns_info.ns_id = nsid; + ctx->u.intf.hw_addr_len = hw_addr_len; + memcpy(ctx->u.intf.hw_addr, hw_addr, hw_addr_len); } -ns_id_t dplane_ctx_get_ns_id(const struct zebra_dplane_ctx *ctx) +int32_t dplane_ctx_get_ifp_hw_addr_len(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->zd_ns_info.ns_id; + return ctx->u.intf.hw_addr_len; } -bool dplane_ctx_is_from_notif(const struct zebra_dplane_ctx *ctx) +const uint8_t *dplane_ctx_get_ifp_hw_addr(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_notif_provider != 0); + return ctx->u.intf.hw_addr; } -uint32_t dplane_ctx_get_notif_provider(const struct zebra_dplane_ctx *ctx) +void dplane_ctx_set_ifp_bond_ifindex(struct zebra_dplane_ctx *ctx, + ifindex_t bond_ifindex) { DPLANE_CTX_VALID(ctx); - return ctx->zd_notif_provider; + ctx->u.intf.bond_ifindex = bond_ifindex; } -void dplane_ctx_set_notif_provider(struct zebra_dplane_ctx *ctx, - uint32_t id) +enum zebra_iftype +dplane_ctx_get_ifp_zif_type(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - ctx->zd_notif_provider = id; + return ctx->u.intf.zif_type; } -const char *dplane_ctx_get_ifname(const struct zebra_dplane_ctx *ctx) +void dplane_ctx_set_ifp_zif_type(struct zebra_dplane_ctx *ctx, + enum zebra_iftype zif_type) { DPLANE_CTX_VALID(ctx); - return ctx->zd_ifname; + ctx->u.intf.zif_type = zif_type; } void dplane_ctx_set_ifname(struct zebra_dplane_ctx *ctx, const char *ifname) @@ -2068,6 +2559,13 @@ bool dplane_ctx_intf_is_connected(const struct zebra_dplane_ctx *ctx) return (ctx->u.intf.flags & DPLANE_INTF_CONNECTED); } +bool dplane_ctx_intf_is_noprefixroute(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return (ctx->u.intf.flags & DPLANE_INTF_NOPREFIXROUTE); +} + bool dplane_ctx_intf_is_secondary(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); @@ -2096,6 +2594,13 @@ void dplane_ctx_intf_set_secondary(struct zebra_dplane_ctx *ctx) ctx->u.intf.flags |= DPLANE_INTF_SECONDARY; } +void dplane_ctx_intf_set_noprefixroute(struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.flags |= DPLANE_INTF_NOPREFIXROUTE; +} + void dplane_ctx_intf_set_broadcast(struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); @@ -2111,6 +2616,16 @@ const struct prefix *dplane_ctx_get_intf_addr( return &(ctx->u.intf.prefix); } + +/* Accessors for SRv6 encapsulation source address information */ +const struct in6_addr * +dplane_ctx_get_srv6_encap_srcaddr(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return &(ctx->u.srv6_encap.srcaddr); +} + void dplane_ctx_set_intf_addr(struct zebra_dplane_ctx *ctx, const struct prefix *p) { @@ -2185,6 +2700,20 @@ void dplane_ctx_set_intf_label(struct zebra_dplane_ctx *ctx, const char *label) } } +void dplane_ctx_set_intf_txqlen(struct zebra_dplane_ctx *ctx, uint32_t txqlen) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.intf.txqlen = txqlen; +} + +uint32_t dplane_ctx_get_intf_txqlen(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.intf.txqlen; +} + /* Accessors for MAC information */ vlanid_t dplane_ctx_mac_get_vlan(const struct zebra_dplane_ctx *ctx) { @@ -2307,6 +2836,25 @@ dplane_ctx_gre_get_info(const struct zebra_dplane_ctx *ctx) return &ctx->u.gre.info; } +/*********************************************************************** + * PBR RULE ACCESSORS - start + **********************************************************************/ + +/* + * This accessor fills one or two lib/pbr structs from the PBR context. + * New dataplane modules should use this interface where possible instead + * of adding more accessors that return fields from 'struct pbr_rule'. + */ +void dplane_ctx_rule_get(const struct zebra_dplane_ctx *ctx, + struct pbr_rule *pNew, struct pbr_rule *pOld) +{ + DPLANE_CTX_VALID(ctx); + if (pNew) + *pNew = ctx->u.rule.new.prule; + if (pOld) + *pOld = ctx->u.rule.old.prule; +} + /* Accessors for PBR rule information */ int dplane_ctx_rule_get_sock(const struct zebra_dplane_ctx *ctx) { @@ -2319,7 +2867,7 @@ const char *dplane_ctx_rule_get_ifname(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->u.rule.new.ifname; + return ctx->u.rule.new.prule.ifname; } int dplane_ctx_rule_get_unique(const struct zebra_dplane_ctx *ctx) @@ -2340,112 +2888,112 @@ uint32_t dplane_ctx_rule_get_priority(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->u.rule.new.priority; + return ctx->u.rule.new.prule.priority; } uint32_t dplane_ctx_rule_get_old_priority(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->u.rule.old.priority; + return ctx->u.rule.old.prule.priority; } uint32_t dplane_ctx_rule_get_table(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->u.rule.new.table; + return ctx->u.rule.new.prule.action.table; } uint32_t dplane_ctx_rule_get_old_table(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->u.rule.old.table; + return ctx->u.rule.old.prule.action.table; } uint32_t dplane_ctx_rule_get_filter_bm(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->u.rule.new.filter_bm; + return ctx->u.rule.new.prule.filter.filter_bm; } uint32_t dplane_ctx_rule_get_old_filter_bm(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->u.rule.old.filter_bm; + return ctx->u.rule.old.prule.filter.filter_bm; } uint32_t dplane_ctx_rule_get_fwmark(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->u.rule.new.fwmark; + return ctx->u.rule.new.prule.filter.fwmark; } uint32_t dplane_ctx_rule_get_old_fwmark(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->u.rule.old.fwmark; + return ctx->u.rule.old.prule.filter.fwmark; } uint8_t dplane_ctx_rule_get_ipproto(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->u.rule.new.ip_proto; + return ctx->u.rule.new.prule.filter.ip_proto; } uint8_t dplane_ctx_rule_get_old_ipproto(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->u.rule.old.ip_proto; + return ctx->u.rule.old.prule.filter.ip_proto; } uint16_t dplane_ctx_rule_get_src_port(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->u.rule.new.src_port; + return ctx->u.rule.new.prule.filter.src_port; } uint16_t dplane_ctx_rule_get_old_src_port(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->u.rule.old.src_port; + return ctx->u.rule.old.prule.filter.src_port; } uint16_t dplane_ctx_rule_get_dst_port(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->u.rule.new.dst_port; + return ctx->u.rule.new.prule.filter.dst_port; } uint16_t dplane_ctx_rule_get_old_dst_port(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->u.rule.old.dst_port; + return ctx->u.rule.old.prule.filter.dst_port; } uint8_t dplane_ctx_rule_get_dsfield(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->u.rule.new.dsfield; + return ctx->u.rule.new.prule.filter.dsfield; } uint8_t dplane_ctx_rule_get_old_dsfield(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return ctx->u.rule.old.dsfield; + return ctx->u.rule.old.prule.filter.dsfield; } const struct prefix * @@ -2453,7 +3001,7 @@ dplane_ctx_rule_get_src_ip(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return &(ctx->u.rule.new.src_ip); + return &(ctx->u.rule.new.prule.filter.src_ip); } const struct prefix * @@ -2461,7 +3009,7 @@ dplane_ctx_rule_get_old_src_ip(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return &(ctx->u.rule.old.src_ip); + return &(ctx->u.rule.old.prule.filter.src_ip); } const struct prefix * @@ -2469,7 +3017,7 @@ dplane_ctx_rule_get_dst_ip(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return &(ctx->u.rule.new.dst_ip); + return &(ctx->u.rule.new.prule.filter.dst_ip); } const struct prefix * @@ -2477,9 +3025,65 @@ dplane_ctx_rule_get_old_dst_ip(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); - return &(ctx->u.rule.old.dst_ip); + return &(ctx->u.rule.old.prule.filter.dst_ip); +} + +const struct ethaddr * +dplane_ctx_rule_get_smac(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return &(ctx->u.rule.new.smac); +} + +const struct ethaddr * +dplane_ctx_rule_get_dmac(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return &(ctx->u.rule.new.dmac); +} + +int dplane_ctx_rule_get_out_ifindex(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.rule.new.out_ifindex; +} + +intptr_t dplane_ctx_rule_get_old_dp_flow_ptr(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.rule.old.dp_flow_ptr; +} + +intptr_t dplane_ctx_rule_get_dp_flow_ptr(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.rule.new.dp_flow_ptr; +} + +void dplane_ctx_rule_set_dp_flow_ptr(struct zebra_dplane_ctx *ctx, + intptr_t dp_flow_ptr) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.rule.new.dp_flow_ptr = dp_flow_ptr; +} + +vrf_id_t dplane_ctx_rule_get_vrfid(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.rule.new.prule.vrf_id; } +/*********************************************************************** + * PBR RULE ACCESSORS - end + **********************************************************************/ + uint32_t dplane_ctx_get_br_port_flags(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); @@ -2548,55 +3152,6 @@ void dplane_ctx_get_pbr_ipset_entry(const struct zebra_dplane_ctx *ctx, memcpy(entry, &ctx->u.ipset_entry.entry, sizeof(struct zebra_pbr_ipset_entry)); } -const struct ethaddr * -dplane_ctx_rule_get_smac(const struct zebra_dplane_ctx *ctx) -{ - DPLANE_CTX_VALID(ctx); - - return &(ctx->u.rule.new.smac); -} - -const struct ethaddr * -dplane_ctx_rule_get_dmac(const struct zebra_dplane_ctx *ctx) -{ - DPLANE_CTX_VALID(ctx); - - return &(ctx->u.rule.new.dmac); -} - -int dplane_ctx_rule_get_out_ifindex(const struct zebra_dplane_ctx *ctx) -{ - DPLANE_CTX_VALID(ctx); - - return ctx->u.rule.new.out_ifindex; -} - -intptr_t dplane_ctx_rule_get_old_dp_flow_ptr(const struct zebra_dplane_ctx *ctx) -{ - DPLANE_CTX_VALID(ctx); - - return ctx->u.rule.old.dp_flow_ptr; -} - -intptr_t dplane_ctx_rule_get_dp_flow_ptr(const struct zebra_dplane_ctx *ctx) -{ - DPLANE_CTX_VALID(ctx); - - return ctx->u.rule.new.dp_flow_ptr; -} - -void dplane_ctx_rule_set_dp_flow_ptr(struct zebra_dplane_ctx *ctx, - intptr_t dp_flow_ptr) -{ - DPLANE_CTX_VALID(ctx); - - ctx->u.rule.new.dp_flow_ptr = dp_flow_ptr; -} - -/* - * End of dplane context accessors - */ - /* Optional extra info about interfaces in nexthops - a plugin must enable * this extra info. */ @@ -2798,7 +3353,7 @@ int dplane_ctx_route_init_basic(struct zebra_dplane_ctx *ctx, { int ret = EINVAL; - if (!ctx || !re) + if (!ctx) return ret; dplane_intf_extra_list_init(&ctx->u.rinfo.intf_extra_list); @@ -2806,6 +3361,13 @@ int dplane_ctx_route_init_basic(struct zebra_dplane_ctx *ctx, ctx->zd_op = op; ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; + /* This function may be called to create/init a dplane context, not + * necessarily to copy a route object. Let's return if there is no route + * object to copy. + */ + if (!re) + return AOK; + ctx->u.rinfo.zd_type = re->type; ctx->u.rinfo.zd_old_type = re->type; @@ -2837,6 +3399,8 @@ int dplane_ctx_route_init_basic(struct zebra_dplane_ctx *ctx, /* * Initialize a context block for a route update from zebra data structs. + * If the `rn` or `re` parameters are NULL, this function only initializes the + * dplane context without copying a route object into it. */ int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op, struct route_node *rn, struct route_entry *re) @@ -2853,9 +3417,17 @@ int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op, const struct interface *ifp; struct dplane_intf_extra *if_extra; - if (!ctx || !rn || !re) + if (!ctx) return ret; + /* + * Initialize the dplane context and return, if there is no route + * object to copy + */ + if (!re || !rn) + return dplane_ctx_route_init_basic(ctx, op, NULL, NULL, NULL, + AFI_UNSPEC, SAFI_UNSPEC); + /* * Let's grab the data from the route_node * so that we can call a helper function @@ -3414,24 +3986,8 @@ static void dplane_ctx_rule_init_single(struct dplane_ctx_rule *dplane_rule, { struct zebra_neigh_ent *n; - dplane_rule->priority = rule->rule.priority; - dplane_rule->table = rule->rule.action.table; - - dplane_rule->filter_bm = rule->rule.filter.filter_bm; - dplane_rule->fwmark = rule->rule.filter.fwmark; - dplane_rule->dsfield = rule->rule.filter.dsfield; - dplane_rule->ip_proto = rule->rule.filter.ip_proto; - dplane_rule->src_port = rule->rule.filter.src_port; - dplane_rule->dst_port = rule->rule.filter.dst_port; - prefix_copy(&(dplane_rule->dst_ip), &rule->rule.filter.dst_ip); - prefix_copy(&(dplane_rule->src_ip), &rule->rule.filter.src_ip); + dplane_rule->prule = rule->rule; - dplane_rule->action_pcp = rule->rule.action.pcp; - dplane_rule->action_vlan_flags = rule->rule.action.vlan_flags; - dplane_rule->action_vlan_id = rule->rule.action.vlan_id; - dplane_rule->action_queue_id = rule->rule.action.queue_id; - - strlcpy(dplane_rule->ifname, rule->ifname, INTERFACE_NAMSIZ); dplane_rule->dp_flow_ptr = rule->action.dp_flow_ptr; n = rule->action.neigh; if (n && (n->flags & ZEBRA_NEIGH_ENT_ACTIVE)) { @@ -3533,6 +4089,7 @@ static int dplane_ctx_iptable_init(struct zebra_dplane_ctx *ctx, ctx->zd_vrf_id = iptable->vrf_id; memcpy(&ctx->u.iptable, iptable, sizeof(struct zebra_pbr_iptable)); + ctx->u.iptable.interface_name_list = NULL; if (iptable->nb_interface > 0) { ctx->u.iptable.interface_name_list = list_new(); ctx->u.iptable.interface_name_list->del = @@ -4601,18 +5158,6 @@ enum zebra_dplane_result dplane_intf_update(const struct interface *ifp) return ret; } -/* - * Enqueue a interface delete for the dataplane. - */ -enum zebra_dplane_result dplane_intf_delete(const struct interface *ifp) -{ - enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE; - - if (ifp) - ret = dplane_intf_update_internal(ifp, DPLANE_OP_INTF_DELETE); - return ret; -} - /* * Enqueue vxlan/evpn mac add (or update). */ @@ -5354,6 +5899,59 @@ dplane_gre_set(struct interface *ifp, struct interface *ifp_link, return result; } +/* + * Common helper api for SRv6 encapsulation source address set + */ +enum zebra_dplane_result +dplane_srv6_encap_srcaddr_set(const struct in6_addr *addr, ns_id_t ns_id) +{ + enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; + struct zebra_dplane_ctx *ctx = NULL; + enum dplane_op_e op = DPLANE_OP_SRV6_ENCAP_SRCADDR_SET; + int ret; + struct zebra_ns *zns; + + if (!addr) + return result; + + if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) { + zlog_debug("init dplane ctx %s: addr %pI6", dplane_op2str(op), + addr); + } + + zns = zebra_ns_lookup(ns_id); + if (!zns) + return result; + + ctx = dplane_ctx_alloc(); + + ctx->zd_op = op; + ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; + + dplane_ctx_ns_init(ctx, zns, false); + + /* Init the SRv6 encap source address specific data area */ + memcpy(&ctx->u.srv6_encap.srcaddr, addr, + sizeof(ctx->u.srv6_encap.srcaddr)); + + /* Update counter */ + atomic_fetch_add_explicit(&zdplane_info.dg_srv6_encap_srcaddr_set_in, 1, + memory_order_relaxed); + + /* Enqueue context for processing */ + ret = dplane_update_enqueue(ctx); + + if (ret == AOK) + result = ZEBRA_DPLANE_REQUEST_QUEUED; + else { + atomic_fetch_add_explicit(&zdplane_info + .dg_srv6_encap_srcaddr_set_errors, + 1, memory_order_relaxed); + dplane_ctx_free(&ctx); + } + return result; +} + /* * Handler for 'show dplane' */ @@ -5546,7 +6144,7 @@ int dplane_provider_register(const char *name, struct zebra_dplane_provider **prov_p) { int ret = 0; - struct zebra_dplane_provider *p = NULL, *last; + struct zebra_dplane_provider *p = NULL, *last, *prev = NULL; /* Validate */ if (fp == NULL) { @@ -5589,10 +6187,11 @@ int dplane_provider_register(const char *name, frr_each (dplane_prov_list, &zdplane_info.dg_providers, last) { if (last->dp_priority > p->dp_priority) break; + prev = last; } if (last) - dplane_prov_list_add_after(&zdplane_info.dg_providers, last, p); + dplane_prov_list_add_after(&zdplane_info.dg_providers, prev, p); else dplane_prov_list_add_tail(&zdplane_info.dg_providers, p); @@ -6076,6 +6675,13 @@ static void kernel_dplane_log_detail(struct zebra_dplane_ctx *ctx) case DPLANE_OP_TC_FILTER_ADD: case DPLANE_OP_TC_FILTER_DELETE: case DPLANE_OP_TC_FILTER_UPDATE: + case DPLANE_OP_STARTUP_STAGE: + break; + + case DPLANE_OP_SRV6_ENCAP_SRCADDR_SET: + zlog_debug("Dplane SRv6 encap source address set op %s, addr %pI6", + dplane_op2str(dplane_ctx_get_op(ctx)), + &ctx->u.srv6_encap.srcaddr); break; } } @@ -6247,7 +6853,15 @@ static void kernel_dplane_handle_result(struct zebra_dplane_ctx *ctx) case DPLANE_OP_INTF_NETCONFIG: break; + case DPLANE_OP_SRV6_ENCAP_SRCADDR_SET: + if (res != ZEBRA_DPLANE_REQUEST_SUCCESS) + atomic_fetch_add_explicit(&zdplane_info + .dg_srv6_encap_srcaddr_set_errors, + 1, memory_order_relaxed); + break; + case DPLANE_OP_NONE: + case DPLANE_OP_STARTUP_STAGE: if (res != ZEBRA_DPLANE_REQUEST_SUCCESS) atomic_fetch_add_explicit(&zdplane_info.dg_other_errors, 1, memory_order_relaxed); @@ -6354,6 +6968,31 @@ static int kernel_dplane_process_func(struct zebra_dplane_provider *prov) return 0; } +static int kernel_dplane_shutdown_func(struct zebra_dplane_provider *prov, + bool early) +{ + struct zebra_dplane_ctx *ctx; + + if (early) + return 1; + + ctx = dplane_provider_dequeue_in_ctx(prov); + while (ctx) { + dplane_ctx_free(&ctx); + + ctx = dplane_provider_dequeue_in_ctx(prov); + } + + ctx = dplane_provider_dequeue_out_ctx(prov); + while (ctx) { + dplane_ctx_free(&ctx); + + ctx = dplane_provider_dequeue_out_ctx(prov); + } + + return 1; +} + #ifdef DPLANE_TEST_PROVIDER /* @@ -6426,12 +7065,10 @@ static void dplane_provider_init(void) { int ret; - ret = dplane_provider_register("Kernel", - DPLANE_PRIO_KERNEL, + ret = dplane_provider_register("Kernel", DPLANE_PRIO_KERNEL, DPLANE_PROV_FLAGS_DEFAULT, NULL, kernel_dplane_process_func, - NULL, - NULL, NULL); + kernel_dplane_shutdown_func, NULL, NULL); if (ret != AOK) zlog_err("Unable to register kernel dplane provider: %d", @@ -6832,6 +7469,7 @@ static void dplane_thread_loop(struct event *event) void zebra_dplane_shutdown(void) { struct zebra_dplane_provider *dp; + struct zebra_dplane_ctx *ctx; if (IS_ZEBRA_DEBUG_DPLANE) zlog_debug("Zebra dataplane shutdown called"); @@ -6859,8 +7497,25 @@ void zebra_dplane_shutdown(void) } /* TODO -- Clean-up provider objects */ + dp = dplane_prov_list_first(&zdplane_info.dg_providers); + while (dp) { + dplane_prov_list_del(&zdplane_info.dg_providers, dp); + XFREE(MTYPE_DP_PROV, dp); + + dp = dplane_prov_list_first(&zdplane_info.dg_providers); + } /* TODO -- Clean queue(s), free memory */ + DPLANE_LOCK(); + { + ctx = dplane_ctx_list_pop(&zdplane_info.dg_update_list); + while (ctx) { + dplane_ctx_free(&ctx); + + ctx = dplane_ctx_list_pop(&zdplane_info.dg_update_list); + } + } + DPLANE_UNLOCK(); } /* @@ -6938,6 +7593,25 @@ void zebra_dplane_start(void) frr_pthread_run(zdplane_info.dg_pthread, NULL); } +enum zebra_dplane_startup_notifications +dplane_ctx_get_startup_spot(struct zebra_dplane_ctx *ctx) +{ + return ctx->u.spot; +} + +void zebra_dplane_startup_stage(struct zebra_ns *zns, + enum zebra_dplane_startup_notifications spot) +{ + struct zebra_dplane_ctx *ctx = dplane_ctx_alloc(); + + ctx->zd_op = DPLANE_OP_STARTUP_STAGE; + ctx->zd_status = ZEBRA_DPLANE_REQUEST_QUEUED; + + ctx->u.spot = spot; + dplane_ctx_set_ns_id(ctx, zns->ns_id); + + dplane_provider_enqueue_to_zebra(ctx); +} /* * Initialize the dataplane module at startup; called by zebra rib_init() */ diff --git a/zebra/zebra_dplane.h b/zebra/zebra_dplane.h index 6716c0ffb6..2f7d218508 100644 --- a/zebra/zebra_dplane.h +++ b/zebra/zebra_dplane.h @@ -11,12 +11,14 @@ #include "lib/prefix.h" #include "lib/nexthop.h" #include "lib/nexthop_group.h" +#include "lib/pbr.h" #include "lib/vlan.h" #include "zebra/zebra_ns.h" #include "zebra/rib.h" #include "zebra/zserv.h" #include "zebra/zebra_mpls.h" #include "zebra/zebra_nhg.h" +#include "zebra/ge_netlink.h" #ifdef __cplusplus extern "C" { @@ -87,6 +89,11 @@ enum zebra_dplane_result { ZEBRA_DPLANE_REQUEST_FAILURE, }; +enum zebra_dplane_startup_notifications { + ZEBRA_DPLANE_INTERFACES_READ, + ZEBRA_DPLANE_TUNNELS_READ, + ZEBRA_DPLANE_ADDRESSES_READ, +}; /* * API between the zebra dataplane system and the main zebra processing * context. @@ -188,7 +195,13 @@ enum dplane_op_e { DPLANE_OP_TC_CLASS_UPDATE, DPLANE_OP_TC_FILTER_ADD, DPLANE_OP_TC_FILTER_DELETE, - DPLANE_OP_TC_FILTER_UPDATE + DPLANE_OP_TC_FILTER_UPDATE, + + /* Startup Control */ + DPLANE_OP_STARTUP_STAGE, + + /* Source address for SRv6 encapsulation */ + DPLANE_OP_SRV6_ENCAP_SRCADDR_SET, }; /* @@ -323,6 +336,122 @@ const char *dplane_ctx_get_ifname(const struct zebra_dplane_ctx *ctx); void dplane_ctx_set_ifname(struct zebra_dplane_ctx *ctx, const char *ifname); ifindex_t dplane_ctx_get_ifindex(const struct zebra_dplane_ctx *ctx); void dplane_ctx_set_ifindex(struct zebra_dplane_ctx *ctx, ifindex_t ifindex); +void dplane_ctx_set_ifp_bond_ifindex(struct zebra_dplane_ctx *ctx, + ifindex_t ifindex); +ifindex_t dplane_ctx_get_ifp_bond_ifindex(const struct zebra_dplane_ctx *ctx); +enum zebra_iftype +dplane_ctx_get_ifp_zif_type(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_ifp_zif_type(struct zebra_dplane_ctx *ctx, + enum zebra_iftype zif_type); +void dplane_ctx_set_ifp_table_id(struct zebra_dplane_ctx *ctx, + uint32_t table_id); +uint32_t dplane_ctx_get_ifp_table_id(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_ifp_hw_addr(struct zebra_dplane_ctx *ctx, + int32_t hw_addr_len, uint8_t *hw_addr); +int32_t dplane_ctx_get_ifp_hw_addr_len(const struct zebra_dplane_ctx *ctx); +const uint8_t *dplane_ctx_get_ifp_hw_addr(const struct zebra_dplane_ctx *ctx); +struct zebra_l2info_bridge; +void dplane_ctx_set_ifp_bridge_info(struct zebra_dplane_ctx *ctx, + struct zebra_l2info_bridge *binfo); +const struct zebra_l2info_bridge * +dplane_ctx_get_ifp_bridge_info(const struct zebra_dplane_ctx *ctx); +struct zebra_l2info_vlan; +void dplane_ctx_set_ifp_vlan_info(struct zebra_dplane_ctx *ctx, + struct zebra_l2info_vlan *vinfo); +const struct zebra_l2info_vlan * +dplane_ctx_get_ifp_vlan_info(const struct zebra_dplane_ctx *ctx); +struct zebra_l2info_vxlan; +void dplane_ctx_set_ifp_vxlan_info(struct zebra_dplane_ctx *ctx, + struct zebra_l2info_vxlan *vxinfo); +const struct zebra_l2info_vxlan * +dplane_ctx_get_ifp_vxlan_info(const struct zebra_dplane_ctx *ctx); +struct zebra_l2info_gre; +void dplane_ctx_set_ifp_gre_info(struct zebra_dplane_ctx *ctx, + struct zebra_l2info_gre *greinfo); +const struct zebra_l2info_gre * +dplane_ctx_get_ifp_gre_info(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_ifp_zltype(struct zebra_dplane_ctx *ctx, + enum zebra_link_type zlt); +enum zebra_link_type +dplane_ctx_get_ifp_zltype(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_ifp_link_nsid(struct zebra_dplane_ctx *ctx, ns_id_t ns_id); +ns_id_t dplane_ctx_get_ifp_link_nsid(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_ifp_desc(struct zebra_dplane_ctx *ctx, const char *desc); +char *dplane_ctx_get_ifp_desc(struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_ifp_mtu(struct zebra_dplane_ctx *ctx, uint32_t mtu); +uint32_t dplane_ctx_get_ifp_mtu(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_ifp_vrf_id(struct zebra_dplane_ctx *ctx, vrf_id_t vrf_id); +vrf_id_t dplane_ctx_get_ifp_vrf_id(const struct zebra_dplane_ctx *ctx); +enum zebra_slave_iftype; +void dplane_ctx_set_ifp_zif_slave_type(struct zebra_dplane_ctx *ctx, + enum zebra_slave_iftype zslave_type); +enum zebra_slave_iftype +dplane_ctx_get_ifp_zif_slave_type(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_ifp_master_ifindex(struct zebra_dplane_ctx *ctx, + ifindex_t master_ifindex); +ifindex_t dplane_ctx_get_ifp_master_ifindex(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_ifp_bridge_ifindex(struct zebra_dplane_ctx *ctx, + ifindex_t bridge_ifindex); +ifindex_t dplane_ctx_get_ifp_bridge_ifindex(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_ifp_bypass(struct zebra_dplane_ctx *ctx, uint8_t bypass); +uint8_t dplane_ctx_get_ifp_bypass(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_ifp_flags(struct zebra_dplane_ctx *ctx, uint64_t flags); +uint64_t dplane_ctx_get_ifp_flags(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_ifp_protodown(struct zebra_dplane_ctx *ctx, bool protodown); +bool dplane_ctx_get_ifp_protodown(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_ifp_startup(struct zebra_dplane_ctx *ctx, bool startup); +bool dplane_ctx_get_ifp_startup(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_ifp_protodown_set(struct zebra_dplane_ctx *ctx, bool set); +bool dplane_ctx_get_ifp_protodown_set(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_ifp_rc_bitfield(struct zebra_dplane_ctx *ctx, + uint32_t rc_bitfield); +uint32_t dplane_ctx_get_ifp_rc_bitfield(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_ifp_link_ifindex(struct zebra_dplane_ctx *ctx, + ifindex_t link_ifindex); +ifindex_t dplane_ctx_get_ifp_link_ifindex(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_ifp_family(struct zebra_dplane_ctx *ctx, uint8_t family); +uint8_t dplane_ctx_get_ifp_family(const struct zebra_dplane_ctx *ctx); +struct zebra_vxlan_vni_array; +void dplane_ctx_set_ifp_vxlan_vni_array(struct zebra_dplane_ctx *ctx, + struct zebra_vxlan_vni_array *vniarray); + +/* + * These defines mirror the values for bridge values in linux + * at this point since we only have a linux implementation + * we don't need to do any type of translation. Let's just + * pass these through and use them + */ +#define DPLANE_BRIDGE_VLAN_INFO_PVID \ + (1 << 1) /* VLAN is PVID, ingress untagged */ +#define DPLANE_BRIDGE_VLAN_INFO_RANGE_BEGIN \ + (1 << 3) /* VLAN is start of vlan range */ +#define DPLANE_BRIDGE_VLAN_INFO_RANGE_END \ + (1 << 4) /* VLAN is end of vlan range */ +const struct zebra_vxlan_vni_array * +dplane_ctx_get_ifp_vxlan_vni_array(const struct zebra_dplane_ctx *ctx); +struct zebra_dplane_bridge_vlan_info { + uint16_t flags; + uint16_t vid; +}; +void dplane_ctx_set_ifp_no_afspec(struct zebra_dplane_ctx *ctx); +bool dplane_ctx_get_ifp_no_afspec(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_ifp_no_bridge_vlan_info(struct zebra_dplane_ctx *ctx); +bool dplane_ctx_get_ifp_no_bridge_vlan_info(struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_ifp_bridge_vlan_info( + struct zebra_dplane_ctx *ctx, + struct zebra_dplane_bridge_vlan_info *bvinfo); +const struct zebra_dplane_bridge_vlan_info * +dplane_ctx_get_ifp_bridge_vlan_info(const struct zebra_dplane_ctx *ctx); + +struct zebra_dplane_bridge_vlan_info_array { + int count; + struct zebra_dplane_bridge_vlan_info array[0]; +}; +void dplane_ctx_set_ifp_bridge_vlan_info_array( + struct zebra_dplane_ctx *ctx, + struct zebra_dplane_bridge_vlan_info_array *bvarray); +const struct zebra_dplane_bridge_vlan_info_array * +dplane_ctx_get_ifp_bridge_vlan_info_array(const struct zebra_dplane_ctx *ctx); /* Retrieve last/current provider id */ uint32_t dplane_ctx_get_provider(const struct zebra_dplane_ctx *ctx); @@ -533,10 +662,14 @@ bool dplane_ctx_intf_is_connected(const struct zebra_dplane_ctx *ctx); void dplane_ctx_intf_set_connected(struct zebra_dplane_ctx *ctx); bool dplane_ctx_intf_is_secondary(const struct zebra_dplane_ctx *ctx); void dplane_ctx_intf_set_secondary(struct zebra_dplane_ctx *ctx); +bool dplane_ctx_intf_is_noprefixroute(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_intf_set_noprefixroute(struct zebra_dplane_ctx *ctx); bool dplane_ctx_intf_is_broadcast(const struct zebra_dplane_ctx *ctx); void dplane_ctx_intf_set_broadcast(struct zebra_dplane_ctx *ctx); const struct prefix *dplane_ctx_get_intf_addr( const struct zebra_dplane_ctx *ctx); +const struct in6_addr * +dplane_ctx_get_srv6_encap_srcaddr(const struct zebra_dplane_ctx *ctx); void dplane_ctx_set_intf_addr(struct zebra_dplane_ctx *ctx, const struct prefix *p); bool dplane_ctx_intf_has_dest(const struct zebra_dplane_ctx *ctx); @@ -547,6 +680,8 @@ void dplane_ctx_set_intf_dest(struct zebra_dplane_ctx *ctx, bool dplane_ctx_intf_has_label(const struct zebra_dplane_ctx *ctx); const char *dplane_ctx_get_intf_label(const struct zebra_dplane_ctx *ctx); void dplane_ctx_set_intf_label(struct zebra_dplane_ctx *ctx, const char *label); +void dplane_ctx_set_intf_txqlen(struct zebra_dplane_ctx *ctx, uint32_t txqlen); +uint32_t dplane_ctx_get_intf_txqlen(const struct zebra_dplane_ctx *ctx); /* Accessors for MAC information */ vlanid_t dplane_ctx_mac_get_vlan(const struct zebra_dplane_ctx *ctx); @@ -573,6 +708,8 @@ uint16_t dplane_ctx_neigh_get_state(const struct zebra_dplane_ctx *ctx); uint32_t dplane_ctx_neigh_get_update_flags(const struct zebra_dplane_ctx *ctx); /* Accessors for policy based routing rule information */ +void dplane_ctx_rule_get(const struct zebra_dplane_ctx *ctx, + struct pbr_rule *pNew, struct pbr_rule *pOld); int dplane_ctx_rule_get_sock(const struct zebra_dplane_ctx *ctx); int dplane_ctx_rule_get_unique(const struct zebra_dplane_ctx *ctx); int dplane_ctx_rule_get_seq(const struct zebra_dplane_ctx *ctx); @@ -611,6 +748,8 @@ intptr_t dplane_ctx_rule_get_old_dp_flow_ptr(const struct zebra_dplane_ctx *ctx); void dplane_ctx_rule_set_dp_flow_ptr(struct zebra_dplane_ctx *ctx, intptr_t dp_flow_ptr); +vrf_id_t dplane_ctx_rule_get_vrfid(const struct zebra_dplane_ctx *ctx); + /* Accessors for policy based routing iptable information */ struct zebra_pbr_iptable; void dplane_ctx_get_pbr_iptable(const struct zebra_dplane_ctx *ctx, @@ -747,7 +886,6 @@ enum zebra_dplane_result dplane_intf_addr_unset(const struct interface *ifp, */ enum zebra_dplane_result dplane_intf_add(const struct interface *ifp); enum zebra_dplane_result dplane_intf_update(const struct interface *ifp); -enum zebra_dplane_result dplane_intf_delete(const struct interface *ifp); /* * Enqueue tc link changes for the dataplane. @@ -860,6 +998,13 @@ enum zebra_dplane_result dplane_gre_set(struct interface *ifp, struct interface *ifp_link, unsigned int mtu, const struct zebra_l2info_gre *gre_info); +/* + * Enqueue an SRv6 encap source address set + */ +enum zebra_dplane_result +dplane_srv6_encap_srcaddr_set(const struct in6_addr *addr, ns_id_t ns_id); + + /* Forward ref of zebra_pbr_rule */ struct zebra_pbr_rule; @@ -1067,6 +1212,9 @@ void zebra_dplane_pre_finish(void); void zebra_dplane_finish(void); void zebra_dplane_shutdown(void); +void zebra_dplane_startup_stage(struct zebra_ns *zns, + enum zebra_dplane_startup_notifications spot); + /* * decision point for sending a routing update through the old * straight to zebra master pthread or through the dplane to @@ -1077,6 +1225,9 @@ void dplane_rib_add_multipath(afi_t afi, safi_t safi, struct prefix *p, struct nexthop_group *ng, int startup, struct zebra_dplane_ctx *ctx); +enum zebra_dplane_startup_notifications +dplane_ctx_get_startup_spot(struct zebra_dplane_ctx *ctx); + #ifdef __cplusplus } #endif diff --git a/zebra/zebra_evpn.c b/zebra/zebra_evpn.c index ce5e639928..147f5b93fa 100644 --- a/zebra/zebra_evpn.c +++ b/zebra/zebra_evpn.c @@ -310,13 +310,12 @@ void zebra_evpn_print_hash_detail(struct hash_bucket *bucket, void *data) int zebra_evpn_del_macip_for_intf(struct interface *ifp, struct zebra_evpn *zevpn) { - struct listnode *cnode = NULL, *cnnode = NULL; struct connected *c = NULL; struct ethaddr macaddr; memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN); - for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, c)) { + frr_each_safe (if_connected, ifp->connected, c) { struct ipaddr ip; memset(&ip, 0, sizeof(struct ipaddr)); @@ -344,13 +343,12 @@ int zebra_evpn_del_macip_for_intf(struct interface *ifp, int zebra_evpn_add_macip_for_intf(struct interface *ifp, struct zebra_evpn *zevpn) { - struct listnode *cnode = NULL, *cnnode = NULL; struct connected *c = NULL; struct ethaddr macaddr; memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN); - for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, c)) { + frr_each_safe (if_connected, ifp->connected, c) { struct ipaddr ip; if (!CHECK_FLAG(c->conf, ZEBRA_IFC_REAL)) @@ -409,13 +407,12 @@ static int ip_prefix_send_to_client(vrf_id_t vrf_id, struct prefix *p, int zebra_evpn_advertise_subnet(struct zebra_evpn *zevpn, struct interface *ifp, int advertise) { - struct listnode *cnode = NULL, *cnnode = NULL; struct connected *c = NULL; struct ethaddr macaddr; memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN); - for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, c)) { + frr_each (if_connected, ifp->connected, c) { struct prefix p; memcpy(&p, c->address, sizeof(struct prefix)); diff --git a/zebra/zebra_evpn_neigh.c b/zebra/zebra_evpn_neigh.c index 74141e4f34..81705d4e85 100644 --- a/zebra/zebra_evpn_neigh.c +++ b/zebra/zebra_evpn_neigh.c @@ -6,6 +6,10 @@ #include <zebra.h> +#ifdef GNU_LINUX +#include <linux/neighbour.h> +#endif + #include "hash.h" #include "interface.h" #include "jhash.h" @@ -1038,11 +1042,10 @@ static inline void zebra_evpn_local_neigh_update_log( * from MAC. */ static int zebra_evpn_ip_inherit_dad_from_mac(struct zebra_vrf *zvrf, - struct zebra_mac *old_zmac, + bool is_old_mac_dup, struct zebra_mac *new_zmac, struct zebra_neigh *nbr) { - bool is_old_mac_dup = false; bool is_new_mac_dup = false; if (!zebra_evpn_do_dup_addr_detect(zvrf)) @@ -1050,9 +1053,6 @@ static int zebra_evpn_ip_inherit_dad_from_mac(struct zebra_vrf *zvrf, /* Check old or new MAC is detected as duplicate * mark this neigh as duplicate */ - if (old_zmac) - is_old_mac_dup = - CHECK_FLAG(old_zmac->flags, ZEBRA_MAC_DUPLICATE); if (new_zmac) is_new_mac_dup = CHECK_FLAG(new_zmac->flags, ZEBRA_MAC_DUPLICATE); @@ -1262,6 +1262,7 @@ int zebra_evpn_local_neigh_update(struct zebra_evpn *zevpn, bool new_static = false; bool old_bgp_ready = false; bool new_bgp_ready; + bool is_old_mac_dup = false; /* Check if the MAC exists. */ zmac = zebra_evpn_mac_lookup(zevpn, macaddr); @@ -1408,6 +1409,7 @@ int zebra_evpn_local_neigh_update(struct zebra_evpn *zevpn, old_bgp_ready = false; } if (old_zmac) { + is_old_mac_dup = CHECK_FLAG(old_zmac->flags, ZEBRA_MAC_DUPLICATE); old_mac_seq = CHECK_FLAG(old_zmac->flags, ZEBRA_MAC_REMOTE) ? old_zmac->rem_seq @@ -1437,6 +1439,7 @@ int zebra_evpn_local_neigh_update(struct zebra_evpn *zevpn, != 0) { old_zmac = n->mac; if (old_zmac) { + is_old_mac_dup = CHECK_FLAG(old_zmac->flags, ZEBRA_MAC_DUPLICATE); old_mac_seq = CHECK_FLAG(old_zmac->flags, ZEBRA_MAC_REMOTE) @@ -1499,7 +1502,7 @@ int zebra_evpn_local_neigh_update(struct zebra_evpn *zevpn, /* Check old and/or new MAC detected as duplicate mark * the neigh as duplicate */ - if (zebra_evpn_ip_inherit_dad_from_mac(zvrf, old_zmac, zmac, n)) { + if (zebra_evpn_ip_inherit_dad_from_mac(zvrf, is_old_mac_dup, zmac, n)) { flog_warn( EC_ZEBRA_DUP_IP_INHERIT_DETECTED, "VNI %u: MAC %pEA IP %pIA detected as duplicate during local update, inherit duplicate from MAC", @@ -2034,6 +2037,7 @@ void zebra_evpn_neigh_remote_macip_add(struct zebra_evpn *zevpn, bool do_dad = false; bool is_dup_detect = false; bool is_router; + bool is_old_mac_dup = false; assert(mac); is_router = !!CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG); @@ -2086,6 +2090,7 @@ void zebra_evpn_neigh_remote_macip_add(struct zebra_evpn *zevpn, old_mac = zebra_evpn_mac_lookup(zevpn, &n->emac); if (old_mac) { + is_old_mac_dup = CHECK_FLAG(old_mac->flags, ZEBRA_MAC_DUPLICATE); listnode_delete(old_mac->neigh_list, n); n->mac = NULL; zebra_evpn_deref_ip2mac(zevpn, old_mac); @@ -2128,7 +2133,7 @@ void zebra_evpn_neigh_remote_macip_add(struct zebra_evpn *zevpn, /* Check old or new MAC detected as duplicate, * inherit duplicate flag to this neigh. */ - if (zebra_evpn_ip_inherit_dad_from_mac(zvrf, old_mac, mac, n)) { + if (zebra_evpn_ip_inherit_dad_from_mac(zvrf, is_old_mac_dup, mac, n)) { flog_warn( EC_ZEBRA_DUP_IP_INHERIT_DETECTED, "VNI %u: MAC %pEA IP %pIA detected as duplicate during remote update, inherit duplicate from MAC", diff --git a/zebra/zebra_fpm.c b/zebra/zebra_fpm.c index 699f3ed110..92dc591d40 100644 --- a/zebra/zebra_fpm.c +++ b/zebra/zebra_fpm.c @@ -8,6 +8,10 @@ #include <zebra.h> +#ifdef GNU_LINUX +#include <linux/rtnetlink.h> +#endif + #include "log.h" #include "libfrr.h" #include "stream.h" diff --git a/zebra/zebra_fpm_dt.c b/zebra/zebra_fpm_dt.c index 94308a961b..ce5eb6fe15 100644 --- a/zebra/zebra_fpm_dt.c +++ b/zebra/zebra_fpm_dt.c @@ -22,6 +22,10 @@ */ #include <zebra.h> + +#ifdef GNU_LINUX +#include <linux/rtnetlink.h> +#endif #include "log.h" #include "vrf.h" diff --git a/zebra/zebra_fpm_netlink.c b/zebra/zebra_fpm_netlink.c index ba34951e76..1dd96347f3 100644 --- a/zebra/zebra_fpm_netlink.c +++ b/zebra/zebra_fpm_netlink.c @@ -11,6 +11,9 @@ #ifdef HAVE_NETLINK +#include <linux/rtnetlink.h> +#include <linux/neighbour.h> + #include "log.h" #include "rib.h" #include "vty.h" @@ -287,6 +290,8 @@ static int netlink_route_info_fill(struct netlink_route_info *ri, int cmd, if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) continue; + if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_DUPLICATE)) + continue; if (nexthop->type == NEXTHOP_TYPE_BLACKHOLE) { switch (nexthop->bh_type) { diff --git a/zebra/zebra_gr.c b/zebra/zebra_gr.c index cf2056b7ac..f4241f1d72 100644 --- a/zebra/zebra_gr.c +++ b/zebra/zebra_gr.c @@ -80,13 +80,12 @@ void zebra_gr_stale_client_cleanup(struct list *client_list) /* Cancel the stale timer */ if (info->t_stale_removal != NULL) { EVENT_OFF(info->t_stale_removal); - info->t_stale_removal = NULL; info->do_delete = true; /* Process the stale routes */ event_execute( zrouter.master, zebra_gr_route_stale_delete_timer_expiry, - info, 0); + info, 0, NULL); } } } @@ -328,7 +327,7 @@ void zread_client_capabilities(ZAPI_HANDLER_ARGS) return; /* GR only for dynamic clients */ - if (client->proto <= ZEBRA_ROUTE_CONNECT) { + if (client->proto <= ZEBRA_ROUTE_LOCAL) { LOG_GR("%s: GR capabilities for client %s not supported", __func__, zebra_route_string(client->proto)); return; diff --git a/zebra/zebra_l2.c b/zebra/zebra_l2.c index 2eea772f9f..4f7a1cd4ce 100644 --- a/zebra/zebra_l2.c +++ b/zebra/zebra_l2.c @@ -244,8 +244,7 @@ void zebra_l2if_update_bond(struct interface *ifp, bool add) * map slaves (if any) to the bridge. */ void zebra_l2_bridge_add_update(struct interface *ifp, - struct zebra_l2info_bridge *bridge_info, - int add) + const struct zebra_l2info_bridge *bridge_info) { struct zebra_if *zif; struct zebra_l2_bridge_if *br; @@ -284,7 +283,7 @@ void zebra_l2if_update_bridge(struct interface *ifp, uint8_t chgflags) * VLAN Id and this cannot change. */ void zebra_l2_vlanif_update(struct interface *ifp, - struct zebra_l2info_vlan *vlan_info) + const struct zebra_l2info_vlan *vlan_info) { struct zebra_if *zif; @@ -301,7 +300,7 @@ void zebra_l2_vlanif_update(struct interface *ifp, * clients about GRE information. */ void zebra_l2_greif_add_update(struct interface *ifp, - struct zebra_l2info_gre *gre_info, int add) + const struct zebra_l2info_gre *gre_info, int add) { struct zebra_if *zif; struct in_addr old_vtep_ip; @@ -328,7 +327,8 @@ void zebra_l2_greif_add_update(struct interface *ifp, * IP and VLAN mapping, but the latter is handled separately. */ void zebra_l2_vxlanif_add_update(struct interface *ifp, - struct zebra_l2info_vxlan *vxlan_info, int add) + const struct zebra_l2info_vxlan *vxlan_info, + int add) { struct zebra_if *zif; uint16_t chgflags = 0; @@ -383,7 +383,8 @@ void zebra_l2_vxlanif_update_access_vlan(struct interface *ifp, assert(zif); /* This would be called only in non svd case */ - assert(IS_ZEBRA_VXLAN_IF_VNI(zif)); + if (!IS_ZEBRA_VXLAN_IF_VNI(zif)) + return; old_access_vlan = zif->l2info.vxl.vni_info.vni.access_vlan; ; diff --git a/zebra/zebra_l2.h b/zebra/zebra_l2.h index 3be002656a..588917f4c0 100644 --- a/zebra/zebra_l2.h +++ b/zebra/zebra_l2.h @@ -80,6 +80,12 @@ struct zebra_vxlan_vni { vni_t vni; /* VNI */ vlanid_t access_vlan; /* Access VLAN - for VLAN-aware bridge. */ struct in_addr mcast_grp; + uint16_t flags; +}; + +struct zebra_vxlan_vni_array { + uint16_t count; + struct zebra_vxlan_vni vnis[0]; }; enum { @@ -159,18 +165,19 @@ extern void zebra_l2_map_slave_to_bridge(struct zebra_l2info_brslave *br_slave, struct zebra_ns *zns); extern void zebra_l2_unmap_slave_from_bridge(struct zebra_l2info_brslave *br_slave); -extern void zebra_l2_bridge_add_update(struct interface *ifp, - struct zebra_l2info_bridge *bridge_info, - int add); +extern void +zebra_l2_bridge_add_update(struct interface *ifp, + const struct zebra_l2info_bridge *bridge_info); extern void zebra_l2_bridge_del(struct interface *ifp); extern void zebra_l2_vlanif_update(struct interface *ifp, - struct zebra_l2info_vlan *vlan_info); + const struct zebra_l2info_vlan *vlan_info); extern void zebra_l2_greif_add_update(struct interface *ifp, - struct zebra_l2info_gre *vxlan_info, + const struct zebra_l2info_gre *vxlan_info, int add); -extern void zebra_l2_vxlanif_add_update(struct interface *ifp, - struct zebra_l2info_vxlan *vxlan_info, - int add); +extern void +zebra_l2_vxlanif_add_update(struct interface *ifp, + const struct zebra_l2info_vxlan *vxlan_info, + int add); extern void zebra_l2_vxlanif_update_access_vlan(struct interface *ifp, vlanid_t access_vlan); extern void zebra_l2_greif_del(struct interface *ifp); diff --git a/zebra/zebra_mlag.c b/zebra/zebra_mlag.c index 6713dbc967..8fd373cb19 100644 --- a/zebra/zebra_mlag.c +++ b/zebra/zebra_mlag.c @@ -338,8 +338,6 @@ static void zebra_mlag_post_data_from_main_thread(struct event *thread) } } - stream_free(s); - return; stream_failure: stream_free(s); if (zebra_s) @@ -629,6 +627,8 @@ void zebra_mlag_init(void) void zebra_mlag_terminate(void) { + stream_fifo_free(zrouter.mlag_info.mlag_fifo); + zrouter.mlag_info.mlag_fifo = NULL; } @@ -985,8 +985,7 @@ int zebra_mlag_protobuf_decode_message(struct stream *s, uint8_t *data, /* No Batching */ stream_putw(s, MLAG_MSG_NO_BATCH); /* Actual Data */ - zebra_fill_protobuf_msg(s, msg->peerlink, - INTERFACE_NAMSIZ); + zebra_fill_protobuf_msg(s, msg->peerlink, IFNAMSIZ); stream_putl(s, msg->my_role); stream_putl(s, msg->peer_state); zebra_mlag_status_update__free_unpacked(msg, NULL); @@ -1034,9 +1033,9 @@ int zebra_mlag_protobuf_decode_message(struct stream *s, uint8_t *data, stream_putl(s, msg->vrf_id); if (msg->owner_id == MLAG_OWNER_INTERFACE) zebra_fill_protobuf_msg(s, msg->intf_name, - INTERFACE_NAMSIZ); + IFNAMSIZ); else - stream_put(s, NULL, INTERFACE_NAMSIZ); + stream_put(s, NULL, IFNAMSIZ); zebra_mlag_mroute_add__free_unpacked(msg, NULL); } break; case ZEBRA_MLAG__HEADER__MESSAGE_TYPE__ZEBRA_MLAG_MROUTE_DEL: { @@ -1061,9 +1060,9 @@ int zebra_mlag_protobuf_decode_message(struct stream *s, uint8_t *data, stream_putl(s, msg->vrf_id); if (msg->owner_id == MLAG_OWNER_INTERFACE) zebra_fill_protobuf_msg(s, msg->intf_name, - INTERFACE_NAMSIZ); + IFNAMSIZ); else - stream_put(s, NULL, INTERFACE_NAMSIZ); + stream_put(s, NULL, IFNAMSIZ); zebra_mlag_mroute_del__free_unpacked(msg, NULL); } break; case ZEBRA_MLAG__HEADER__MESSAGE_TYPE__ZEBRA_MLAG_MROUTE_ADD_BULK: { @@ -1085,8 +1084,7 @@ int zebra_mlag_protobuf_decode_message(struct stream *s, uint8_t *data, /* Actual Data */ for (i = 0; i < Bulk_msg->n_mroute_add; i++) { - if (STREAM_SIZE(s) - < VRF_NAMSIZ + 22 + INTERFACE_NAMSIZ) { + if (STREAM_SIZE(s) < VRF_NAMSIZ + 22 + IFNAMSIZ) { zlog_warn( "We have received more messages than we can parse at this point in time: %zu", Bulk_msg->n_mroute_add); @@ -1105,11 +1103,11 @@ int zebra_mlag_protobuf_decode_message(struct stream *s, uint8_t *data, stream_putc(s, msg->am_i_dual_active); stream_putl(s, msg->vrf_id); if (msg->owner_id == MLAG_OWNER_INTERFACE) - zebra_fill_protobuf_msg( - s, msg->intf_name, - INTERFACE_NAMSIZ); + zebra_fill_protobuf_msg(s, + msg->intf_name, + IFNAMSIZ); else - stream_put(s, NULL, INTERFACE_NAMSIZ); + stream_put(s, NULL, IFNAMSIZ); } stream_putw_at(s, length_spot, i + 1); @@ -1136,8 +1134,7 @@ int zebra_mlag_protobuf_decode_message(struct stream *s, uint8_t *data, /* Actual Data */ for (i = 0; i < Bulk_msg->n_mroute_del; i++) { - if (STREAM_SIZE(s) - < VRF_NAMSIZ + 16 + INTERFACE_NAMSIZ) { + if (STREAM_SIZE(s) < VRF_NAMSIZ + 16 + IFNAMSIZ) { zlog_warn( "We have received more messages than we can parse at this time"); break; @@ -1152,11 +1149,11 @@ int zebra_mlag_protobuf_decode_message(struct stream *s, uint8_t *data, stream_putl(s, msg->owner_id); stream_putl(s, msg->vrf_id); if (msg->owner_id == MLAG_OWNER_INTERFACE) - zebra_fill_protobuf_msg( - s, msg->intf_name, - INTERFACE_NAMSIZ); + zebra_fill_protobuf_msg(s, + msg->intf_name, + IFNAMSIZ); else - stream_put(s, NULL, INTERFACE_NAMSIZ); + stream_put(s, NULL, IFNAMSIZ); } stream_putw_at(s, length_spot, i + 1); diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c index 47d5b64a3f..15e36acda8 100644 --- a/zebra/zebra_mpls.c +++ b/zebra/zebra_mpls.c @@ -616,8 +616,9 @@ static int nhlfe_nexthop_active_ipv4(struct zebra_nhlfe *nhlfe, for (match_nh = match->nhe->nhg.nexthop; match_nh; match_nh = match_nh->next) { - if (match->type == ZEBRA_ROUTE_CONNECT - || nexthop->ifindex == match_nh->ifindex) { + if ((match->type == ZEBRA_ROUTE_CONNECT || + match->type == ZEBRA_ROUTE_LOCAL) || + nexthop->ifindex == match_nh->ifindex) { nexthop->ifindex = match_nh->ifindex; return 1; } @@ -659,9 +660,10 @@ static int nhlfe_nexthop_active_ipv6(struct zebra_nhlfe *nhlfe, /* Locate a valid connected route. */ RNODE_FOREACH_RE (rn, match) { - if ((match->type == ZEBRA_ROUTE_CONNECT) - && !CHECK_FLAG(match->status, ROUTE_ENTRY_REMOVED) - && CHECK_FLAG(match->flags, ZEBRA_FLAG_SELECTED)) + if (((match->type == ZEBRA_ROUTE_CONNECT || + match->type == ZEBRA_ROUTE_LOCAL)) && + !CHECK_FLAG(match->status, ROUTE_ENTRY_REMOVED) && + CHECK_FLAG(match->flags, ZEBRA_FLAG_SELECTED)) break; } @@ -1029,8 +1031,6 @@ static void lsp_processq_del(struct work_queue *wq, void *data) return; zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - assert(zvrf); - lsp_table = zvrf->lsp_table; if (!lsp_table) // unexpected return; @@ -1184,6 +1184,7 @@ static char *nhlfe2str(const struct zebra_nhlfe *nhlfe, char *buf, int size) break; case NEXTHOP_TYPE_IFINDEX: snprintf(buf, size, "Ifindex: %u", nexthop->ifindex); + break; case NEXTHOP_TYPE_BLACKHOLE: break; } @@ -1771,14 +1772,9 @@ void zebra_mpls_lsp_dplane_result(struct zebra_dplane_ctx *ctx) label = dplane_ctx_get_in_label(ctx); - switch (op) { - case DPLANE_OP_LSP_INSTALL: - case DPLANE_OP_LSP_UPDATE: + if (op == DPLANE_OP_LSP_INSTALL || op == DPLANE_OP_LSP_UPDATE) { /* Look for zebra LSP object */ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - if (zvrf == NULL) - break; - lsp_table = zvrf->lsp_table; tmp_ile.in_label = label; @@ -1787,7 +1783,7 @@ void zebra_mpls_lsp_dplane_result(struct zebra_dplane_ctx *ctx) if (IS_ZEBRA_DEBUG_DPLANE) zlog_debug("LSP ctx %p: in-label %u not found", ctx, dplane_ctx_get_in_label(ctx)); - break; + return; } /* TODO -- Confirm that this result is still 'current' */ @@ -1798,7 +1794,7 @@ void zebra_mpls_lsp_dplane_result(struct zebra_dplane_ctx *ctx) flog_warn(EC_ZEBRA_LSP_INSTALL_FAILURE, "LSP Install Failure: in-label %u", lsp->ile.in_label); - break; + return; } /* Update zebra object */ @@ -1819,73 +1815,16 @@ void zebra_mpls_lsp_dplane_result(struct zebra_dplane_ctx *ctx) ? ZEBRA_SR_POLICY_LABEL_CREATED : ZEBRA_SR_POLICY_LABEL_UPDATED; zebra_sr_policy_label_update(label, update_mode); - break; - - case DPLANE_OP_LSP_DELETE: + } else if (op == DPLANE_OP_LSP_DELETE) { if (status != ZEBRA_DPLANE_REQUEST_SUCCESS) { flog_warn(EC_ZEBRA_LSP_DELETE_FAILURE, "LSP Deletion Failure: in-label %u", dplane_ctx_get_in_label(ctx)); - break; + return; } zebra_sr_policy_label_update(label, ZEBRA_SR_POLICY_LABEL_REMOVED); - break; - - case DPLANE_OP_LSP_NOTIFY: - case DPLANE_OP_NONE: - case DPLANE_OP_ROUTE_INSTALL: - case DPLANE_OP_ROUTE_UPDATE: - case DPLANE_OP_ROUTE_DELETE: - case DPLANE_OP_ROUTE_NOTIFY: - case DPLANE_OP_NH_INSTALL: - case DPLANE_OP_NH_UPDATE: - case DPLANE_OP_NH_DELETE: - case DPLANE_OP_PW_INSTALL: - case DPLANE_OP_PW_UNINSTALL: - case DPLANE_OP_SYS_ROUTE_ADD: - case DPLANE_OP_SYS_ROUTE_DELETE: - case DPLANE_OP_ADDR_INSTALL: - case DPLANE_OP_ADDR_UNINSTALL: - case DPLANE_OP_MAC_INSTALL: - case DPLANE_OP_MAC_DELETE: - case DPLANE_OP_NEIGH_INSTALL: - case DPLANE_OP_NEIGH_UPDATE: - case DPLANE_OP_NEIGH_DELETE: - case DPLANE_OP_VTEP_ADD: - case DPLANE_OP_VTEP_DELETE: - case DPLANE_OP_RULE_ADD: - case DPLANE_OP_RULE_DELETE: - case DPLANE_OP_RULE_UPDATE: - case DPLANE_OP_NEIGH_DISCOVER: - case DPLANE_OP_BR_PORT_UPDATE: - case DPLANE_OP_IPTABLE_ADD: - case DPLANE_OP_IPTABLE_DELETE: - case DPLANE_OP_IPSET_ADD: - case DPLANE_OP_IPSET_DELETE: - case DPLANE_OP_IPSET_ENTRY_ADD: - case DPLANE_OP_IPSET_ENTRY_DELETE: - case DPLANE_OP_NEIGH_IP_INSTALL: - case DPLANE_OP_NEIGH_IP_DELETE: - case DPLANE_OP_NEIGH_TABLE_UPDATE: - case DPLANE_OP_GRE_SET: - case DPLANE_OP_INTF_ADDR_ADD: - case DPLANE_OP_INTF_ADDR_DEL: - case DPLANE_OP_INTF_NETCONFIG: - case DPLANE_OP_INTF_INSTALL: - case DPLANE_OP_INTF_UPDATE: - case DPLANE_OP_INTF_DELETE: - case DPLANE_OP_TC_QDISC_INSTALL: - case DPLANE_OP_TC_QDISC_UNINSTALL: - case DPLANE_OP_TC_CLASS_ADD: - case DPLANE_OP_TC_CLASS_DELETE: - case DPLANE_OP_TC_CLASS_UPDATE: - case DPLANE_OP_TC_FILTER_ADD: - case DPLANE_OP_TC_FILTER_DELETE: - case DPLANE_OP_TC_FILTER_UPDATE: - break; - - } /* Switch */ + } } /* @@ -2092,9 +2031,6 @@ void zebra_mpls_process_dplane_notify(struct zebra_dplane_ctx *ctx) /* Look for zebra LSP object */ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - if (zvrf == NULL) - return; - lsp_table = zvrf->lsp_table; tmp_ile.in_label = dplane_ctx_get_in_label(ctx); @@ -4100,10 +4036,12 @@ void zebra_mpls_turned_on(void) if (!mpls_enabled) { mpls_processq_init(); mpls_enabled = true; - } - hook_register(zserv_client_close, zebra_mpls_cleanup_fecs_for_client); - hook_register(zserv_client_close, zebra_mpls_cleanup_zclient_labels); + hook_register(zserv_client_close, + zebra_mpls_cleanup_fecs_for_client); + hook_register(zserv_client_close, + zebra_mpls_cleanup_zclient_labels); + } } /* @@ -4122,3 +4060,9 @@ void zebra_mpls_init(void) zebra_mpls_turned_on(); } + +void zebra_mpls_terminate(void) +{ + hook_unregister(zserv_client_close, zebra_mpls_cleanup_fecs_for_client); + hook_unregister(zserv_client_close, zebra_mpls_cleanup_zclient_labels); +} diff --git a/zebra/zebra_mpls.h b/zebra/zebra_mpls.h index 7feace56b5..1ed2f9b41c 100644 --- a/zebra/zebra_mpls.h +++ b/zebra/zebra_mpls.h @@ -400,9 +400,10 @@ void zebra_mpls_init_tables(struct zebra_vrf *zvrf); void zebra_mpls_turned_on(void); /* - * Global MPLS initialization. + * Global MPLS initialization/termination. */ void zebra_mpls_init(void); +void zebra_mpls_terminate(void); /* * MPLS VTY. diff --git a/zebra/zebra_mpls_netlink.c b/zebra/zebra_mpls_netlink.c index 4bc676f392..f0f2c4b7a3 100644 --- a/zebra/zebra_mpls_netlink.c +++ b/zebra/zebra_mpls_netlink.c @@ -4,9 +4,13 @@ */ #include <zebra.h> +#include <sys/stat.h> #ifdef HAVE_NETLINK +#include <linux/netlink.h> +#include <linux/rtnetlink.h> + #include "zebra/debug.h" #include "zebra/rt.h" #include "zebra/rt_netlink.h" diff --git a/zebra/zebra_mpls_openbsd.c b/zebra/zebra_mpls_openbsd.c index ee6f7045f5..9cbe6a2e70 100644 --- a/zebra/zebra_mpls_openbsd.c +++ b/zebra/zebra_mpls_openbsd.c @@ -4,6 +4,8 @@ */ #include <zebra.h> +#include <sys/ioctl.h> +#include <sys/uio.h> #ifdef OPEN_BSD @@ -229,70 +231,18 @@ static int kernel_lsp_cmd(struct zebra_dplane_ctx *ctx) const struct nexthop *nexthop = NULL; unsigned int nexthop_num = 0; int action; + enum dplane_op_e op; - switch (dplane_ctx_get_op(ctx)) { - case DPLANE_OP_LSP_DELETE: + op = dplane_ctx_get_op(ctx); + + if (op == DPLANE_OP_LSP_DELETE) action = RTM_DELETE; - break; - case DPLANE_OP_LSP_INSTALL: + else if (op == DPLANE_OP_LSP_INSTALL) action = RTM_ADD; - break; - case DPLANE_OP_LSP_UPDATE: + else if (op == DPLANE_OP_LSP_UPDATE) action = RTM_CHANGE; - break; - case DPLANE_OP_NONE: - case DPLANE_OP_ROUTE_INSTALL: - case DPLANE_OP_ROUTE_UPDATE: - case DPLANE_OP_ROUTE_DELETE: - case DPLANE_OP_ROUTE_NOTIFY: - case DPLANE_OP_NH_INSTALL: - case DPLANE_OP_NH_UPDATE: - case DPLANE_OP_NH_DELETE: - case DPLANE_OP_LSP_NOTIFY: - case DPLANE_OP_PW_INSTALL: - case DPLANE_OP_PW_UNINSTALL: - case DPLANE_OP_SYS_ROUTE_ADD: - case DPLANE_OP_SYS_ROUTE_DELETE: - case DPLANE_OP_ADDR_INSTALL: - case DPLANE_OP_ADDR_UNINSTALL: - case DPLANE_OP_MAC_INSTALL: - case DPLANE_OP_MAC_DELETE: - case DPLANE_OP_NEIGH_INSTALL: - case DPLANE_OP_NEIGH_UPDATE: - case DPLANE_OP_NEIGH_DELETE: - case DPLANE_OP_VTEP_ADD: - case DPLANE_OP_VTEP_DELETE: - case DPLANE_OP_RULE_ADD: - case DPLANE_OP_RULE_DELETE: - case DPLANE_OP_RULE_UPDATE: - case DPLANE_OP_NEIGH_DISCOVER: - case DPLANE_OP_BR_PORT_UPDATE: - case DPLANE_OP_IPTABLE_ADD: - case DPLANE_OP_IPTABLE_DELETE: - case DPLANE_OP_IPSET_ADD: - case DPLANE_OP_IPSET_DELETE: - case DPLANE_OP_IPSET_ENTRY_ADD: - case DPLANE_OP_IPSET_ENTRY_DELETE: - case DPLANE_OP_NEIGH_IP_INSTALL: - case DPLANE_OP_NEIGH_IP_DELETE: - case DPLANE_OP_NEIGH_TABLE_UPDATE: - case DPLANE_OP_GRE_SET: - case DPLANE_OP_INTF_ADDR_ADD: - case DPLANE_OP_INTF_ADDR_DEL: - case DPLANE_OP_INTF_NETCONFIG: - case DPLANE_OP_INTF_INSTALL: - case DPLANE_OP_INTF_UPDATE: - case DPLANE_OP_INTF_DELETE: - case DPLANE_OP_TC_QDISC_INSTALL: - case DPLANE_OP_TC_QDISC_UNINSTALL: - case DPLANE_OP_TC_CLASS_ADD: - case DPLANE_OP_TC_CLASS_DELETE: - case DPLANE_OP_TC_CLASS_UPDATE: - case DPLANE_OP_TC_FILTER_ADD: - case DPLANE_OP_TC_FILTER_DELETE: - case DPLANE_OP_TC_FILTER_UPDATE: + else return -1; - } head = dplane_ctx_get_nhlfe_list(ctx); frr_each(nhlfe_list_const, head, nhlfe) { @@ -442,68 +392,14 @@ static enum zebra_dplane_result kmpw_uninstall(struct zebra_dplane_ctx *ctx) enum zebra_dplane_result kernel_pw_update(struct zebra_dplane_ctx *ctx) { enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; + enum dplane_op_e op; - switch (dplane_ctx_get_op(ctx)) { - case DPLANE_OP_PW_INSTALL: + op = dplane_ctx_get_op(ctx); + + if (op == DPLANE_OP_PW_INSTALL) result = kmpw_install(ctx); - break; - case DPLANE_OP_PW_UNINSTALL: + else if (op == DPLANE_OP_PW_UNINSTALL) result = kmpw_uninstall(ctx); - break; - case DPLANE_OP_NONE: - case DPLANE_OP_ROUTE_INSTALL: - case DPLANE_OP_ROUTE_UPDATE: - case DPLANE_OP_ROUTE_DELETE: - case DPLANE_OP_ROUTE_NOTIFY: - case DPLANE_OP_NH_INSTALL: - case DPLANE_OP_NH_UPDATE: - case DPLANE_OP_NH_DELETE: - case DPLANE_OP_LSP_INSTALL: - case DPLANE_OP_LSP_UPDATE: - case DPLANE_OP_LSP_DELETE: - case DPLANE_OP_LSP_NOTIFY: - case DPLANE_OP_SYS_ROUTE_ADD: - case DPLANE_OP_SYS_ROUTE_DELETE: - case DPLANE_OP_ADDR_INSTALL: - case DPLANE_OP_ADDR_UNINSTALL: - case DPLANE_OP_MAC_INSTALL: - case DPLANE_OP_MAC_DELETE: - case DPLANE_OP_NEIGH_INSTALL: - case DPLANE_OP_NEIGH_UPDATE: - case DPLANE_OP_NEIGH_DELETE: - case DPLANE_OP_VTEP_ADD: - case DPLANE_OP_VTEP_DELETE: - case DPLANE_OP_RULE_ADD: - case DPLANE_OP_RULE_DELETE: - case DPLANE_OP_RULE_UPDATE: - case DPLANE_OP_NEIGH_DISCOVER: - case DPLANE_OP_BR_PORT_UPDATE: - case DPLANE_OP_IPTABLE_ADD: - case DPLANE_OP_IPTABLE_DELETE: - case DPLANE_OP_IPSET_ADD: - case DPLANE_OP_IPSET_DELETE: - case DPLANE_OP_IPSET_ENTRY_ADD: - case DPLANE_OP_IPSET_ENTRY_DELETE: - case DPLANE_OP_NEIGH_IP_INSTALL: - case DPLANE_OP_NEIGH_IP_DELETE: - case DPLANE_OP_NEIGH_TABLE_UPDATE: - case DPLANE_OP_GRE_SET: - case DPLANE_OP_INTF_ADDR_ADD: - case DPLANE_OP_INTF_ADDR_DEL: - case DPLANE_OP_INTF_NETCONFIG: - case DPLANE_OP_INTF_INSTALL: - case DPLANE_OP_INTF_UPDATE: - case DPLANE_OP_INTF_DELETE: - case DPLANE_OP_TC_QDISC_INSTALL: - case DPLANE_OP_TC_QDISC_UNINSTALL: - case DPLANE_OP_TC_CLASS_ADD: - case DPLANE_OP_TC_CLASS_DELETE: - case DPLANE_OP_TC_CLASS_UPDATE: - case DPLANE_OP_TC_FILTER_ADD: - case DPLANE_OP_TC_FILTER_DELETE: - case DPLANE_OP_TC_FILTER_UPDATE: - break; - } return result; } diff --git a/zebra/zebra_mpls_vty.c b/zebra/zebra_mpls_vty.c index 6b8859e0ca..fd09e6b444 100644 --- a/zebra/zebra_mpls_vty.c +++ b/zebra/zebra_mpls_vty.c @@ -22,6 +22,7 @@ #include "zebra/zebra_rnh.h" #include "zebra/redistribute.h" #include "zebra/zebra_routemap.h" +#include "zebra/label_manager.h" static int zebra_mpls_transit_lsp(struct vty *vty, int add_cmd, const char *inlabel_str, const char *gate_str, @@ -42,10 +43,6 @@ static int zebra_mpls_transit_lsp(struct vty *vty, int add_cmd, } zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - if (!zvrf) { - vty_out(vty, "%% Default VRF does not exist\n"); - return CMD_WARNING_CONFIG_FAILED; - } if (!inlabel_str) { vty_out(vty, "%% No Label Information\n"); @@ -186,10 +183,6 @@ static int zebra_mpls_bind(struct vty *vty, int add_cmd, const char *prefix, int ret; zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - if (!zvrf) { - vty_out(vty, "%% Default VRF does not exist\n"); - return CMD_WARNING_CONFIG_FAILED; - } memset(&p, 0, sizeof(p)); ret = str2prefix(prefix, &p); @@ -274,12 +267,12 @@ static int zebra_mpls_config(struct vty *vty) struct zebra_vrf *zvrf; zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - if (!zvrf) - return 0; write += zebra_mpls_write_lsp_config(vty, zvrf); write += zebra_mpls_write_fec_config(vty, zvrf); write += zebra_mpls_write_label_block_config(vty, zvrf); + write += lm_write_label_block_config_call(vty, zvrf); + return write; } @@ -297,8 +290,6 @@ DEFUN (show_mpls_fec, int ret; zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - if (!zvrf) - return 0; if (argc == 3) zebra_mpls_print_fec_table(vty, zvrf); @@ -373,10 +364,6 @@ static int zebra_mpls_global_block(struct vty *vty, int add_cmd, struct zebra_vrf *zvrf; zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - if (!zvrf) { - vty_out(vty, "%% Default VRF does not exist\n"); - return CMD_WARNING_CONFIG_FAILED; - } if (add_cmd) { if (!start_label_str || !end_label_str) { diff --git a/zebra/zebra_nb.c b/zebra/zebra_nb.c index d94547cffc..7cdcaedd7e 100644 --- a/zebra/zebra_nb.c +++ b/zebra/zebra_nb.c @@ -338,6 +338,13 @@ const struct frr_yang_module_info frr_zebra_info = { .destroy = lib_interface_zebra_bandwidth_destroy, } }, + { + .xpath = "/frr-interface:lib/interface/frr-zebra:zebra/mpls", + .cbs = { + .modify = lib_interface_zebra_mpls_modify, + .destroy = lib_interface_zebra_mpls_destroy, + } + }, { .xpath = "/frr-interface:lib/interface/frr-zebra:zebra/bandwidth", .cbs = { @@ -427,6 +434,7 @@ const struct frr_yang_module_info frr_zebra_info = { .get_next = lib_vrf_zebra_ribs_rib_get_next, .get_keys = lib_vrf_zebra_ribs_rib_get_keys, .lookup_entry = lib_vrf_zebra_ribs_rib_lookup_entry, + .lookup_next = lib_vrf_zebra_ribs_rib_lookup_next, } }, { @@ -447,6 +455,7 @@ const struct frr_yang_module_info frr_zebra_info = { .get_next = lib_vrf_zebra_ribs_rib_route_get_next, .get_keys = lib_vrf_zebra_ribs_rib_route_get_keys, .lookup_entry = lib_vrf_zebra_ribs_rib_route_lookup_entry, + .lookup_next = lib_vrf_zebra_ribs_rib_route_lookup_next, } }, { @@ -591,6 +600,28 @@ const struct frr_yang_module_info frr_zebra_info = { .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_color_get_elem, } }, + + { + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/srv6-segs-stack/entry", + .cbs = { + .get_next = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_srv6_segs_stack_entry_get_next, + .get_keys = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_srv6_segs_stack_entry_get_keys, + .lookup_entry = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_srv6_segs_stack_entry_lookup_entry, + } + }, + { + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/srv6-segs-stack/entry/id", + .cbs = { + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_srv6_segs_stack_entry_id_get_elem, + } + }, + { + .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/srv6-segs-stack/entry/seg", + .cbs = { + .get_elem = lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_srv6_segs_stack_entry_seg_get_elem, + } + }, + { .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/mpls-label-stack/entry", .cbs = { diff --git a/zebra/zebra_nb.h b/zebra/zebra_nb.h index fa576ec3f4..6762ebd314 100644 --- a/zebra/zebra_nb.h +++ b/zebra/zebra_nb.h @@ -96,6 +96,8 @@ int lib_interface_zebra_shutdown_modify(struct nb_cb_modify_args *args); int lib_interface_zebra_shutdown_destroy(struct nb_cb_destroy_args *args); int lib_interface_zebra_bandwidth_modify(struct nb_cb_modify_args *args); int lib_interface_zebra_bandwidth_destroy(struct nb_cb_destroy_args *args); +int lib_interface_zebra_mpls_modify(struct nb_cb_modify_args *args); +int lib_interface_zebra_mpls_destroy(struct nb_cb_destroy_args *args); int lib_interface_zebra_legacy_admin_group_modify( struct nb_cb_modify_args *args); int lib_interface_zebra_legacy_admin_group_destroy( @@ -123,6 +125,8 @@ const void *lib_vrf_zebra_ribs_rib_get_next(struct nb_cb_get_next_args *args); int lib_vrf_zebra_ribs_rib_get_keys(struct nb_cb_get_keys_args *args); const void * lib_vrf_zebra_ribs_rib_lookup_entry(struct nb_cb_lookup_entry_args *args); +const void * +lib_vrf_zebra_ribs_rib_lookup_next(struct nb_cb_lookup_entry_args *args); struct yang_data * lib_vrf_zebra_ribs_rib_afi_safi_name_get_elem(struct nb_cb_get_elem_args *args); struct yang_data * @@ -132,6 +136,8 @@ lib_vrf_zebra_ribs_rib_route_get_next(struct nb_cb_get_next_args *args); int lib_vrf_zebra_ribs_rib_route_get_keys(struct nb_cb_get_keys_args *args); const void * lib_vrf_zebra_ribs_rib_route_lookup_entry(struct nb_cb_lookup_entry_args *args); +const void * +lib_vrf_zebra_ribs_rib_route_lookup_next(struct nb_cb_lookup_entry_args *args); struct yang_data * lib_vrf_zebra_ribs_rib_route_prefix_get_elem(struct nb_cb_get_elem_args *args); struct yang_data *lib_vrf_zebra_ribs_rib_route_protocol_get_elem( @@ -238,6 +244,20 @@ struct yang_data * lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_color_get_elem( struct nb_cb_get_elem_args *args); const void * +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_srv6_segs_stack_entry_get_next( + struct nb_cb_get_next_args *args); +int lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_srv6_segs_stack_entry_get_keys( + struct nb_cb_get_keys_args *args); +const void * +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_srv6_segs_stack_entry_lookup_entry( + struct nb_cb_lookup_entry_args *args); +struct yang_data * +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_srv6_segs_stack_entry_id_get_elem( + struct nb_cb_get_elem_args *args); +struct yang_data * +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_srv6_segs_stack_entry_seg_get_elem( + struct nb_cb_get_elem_args *args); +const void * lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_mpls_label_stack_entry_get_next( struct nb_cb_get_next_args *args); int lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_mpls_label_stack_entry_get_keys( diff --git a/zebra/zebra_nb_config.c b/zebra/zebra_nb_config.c index 336669a49b..50caaa819e 100644 --- a/zebra/zebra_nb_config.c +++ b/zebra/zebra_nb_config.c @@ -830,8 +830,8 @@ int lib_interface_zebra_ip_addrs_create(struct nb_cb_create_args *args) struct interface *ifp; struct prefix prefix; - // addr_family = yang_dnode_get_enum(dnode, "./address-family"); - yang_dnode_get_prefix(&prefix, args->dnode, "./ip-prefix"); + // addr_family = yang_dnode_get_enum(dnode, "address-family"); + yang_dnode_get_prefix(&prefix, args->dnode, "ip-prefix"); apply_mask(&prefix); switch (args->event) { @@ -870,7 +870,7 @@ int lib_interface_zebra_ip_addrs_destroy(struct nb_cb_destroy_args *args) struct prefix prefix; struct connected *ifc; - yang_dnode_get_prefix(&prefix, args->dnode, "./ip-prefix"); + yang_dnode_get_prefix(&prefix, args->dnode, "ip-prefix"); apply_mask(&prefix); switch (args->event) { @@ -910,7 +910,7 @@ int lib_interface_zebra_ip_addrs_destroy(struct nb_cb_destroy_args *args) /* This is not real address or interface is not active. */ if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED) || !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) { - listnode_delete(ifp->connected, ifc); + if_connected_del(ifp->connected, ifc); connected_free(&ifc); return NB_ERR_VALIDATION; } @@ -1033,7 +1033,7 @@ int lib_interface_zebra_link_detect_modify(struct nb_cb_modify_args *args) bool link_detect; ifp = nb_running_get_entry(args->dnode, NULL, true); - link_detect = yang_dnode_get_bool(args->dnode, "./link-detect"); + link_detect = yang_dnode_get_bool(args->dnode, "link-detect"); if_linkdetect(ifp, link_detect); @@ -1049,7 +1049,7 @@ int lib_interface_zebra_link_detect_destroy(struct nb_cb_destroy_args *args) bool link_detect; ifp = nb_running_get_entry(args->dnode, NULL, true); - link_detect = yang_dnode_get_bool(args->dnode, "./link-detect"); + link_detect = yang_dnode_get_bool(args->dnode, "link-detect"); if_linkdetect(ifp, link_detect); @@ -1087,6 +1087,50 @@ int lib_interface_zebra_shutdown_destroy(struct nb_cb_destroy_args *args) return NB_OK; } +/* + * XPath: /frr-interface:lib/interface/frr-zebra:zebra/mpls + */ +int lib_interface_zebra_mpls_modify(struct nb_cb_modify_args *args) +{ + struct interface *ifp; + bool mpls; + struct zebra_if *zif; + + if (args->event != NB_EV_APPLY) + return NB_OK; + + ifp = nb_running_get_entry(args->dnode, NULL, true); + zif = ifp->info; + mpls = yang_dnode_get_bool(args->dnode, NULL); + + if (mpls) + zif->mpls_config = IF_ZEBRA_DATA_ON; + else + zif->mpls_config = IF_ZEBRA_DATA_OFF; + + dplane_intf_mpls_modify_state(ifp, mpls); + + return NB_OK; +} + +int lib_interface_zebra_mpls_destroy(struct nb_cb_destroy_args *args) +{ + struct interface *ifp; + struct zebra_if *zif; + + if (args->event != NB_EV_APPLY) + return NB_OK; + + ifp = nb_running_get_entry(args->dnode, NULL, true); + zif = ifp->info; + + zif->mpls_config = IF_ZEBRA_DATA_UNSPEC; + + /* keep the state as it is */ + + return NB_OK; +} + /* * XPath: /frr-interface:lib/interface/frr-zebra:zebra/bandwidth */ @@ -1099,7 +1143,7 @@ int lib_interface_zebra_bandwidth_modify(struct nb_cb_modify_args *args) uint32_t bandwidth; ifp = nb_running_get_entry(args->dnode, NULL, true); - bandwidth = yang_dnode_get_uint32(args->dnode, "./bandwidth"); + bandwidth = yang_dnode_get_uint32(args->dnode, "bandwidth"); ifp->bandwidth = bandwidth; @@ -1421,7 +1465,7 @@ int lib_vrf_zebra_l3vni_id_modify(struct nb_cb_modify_args *args) * if zebra vrf already mapped to different vni id. */ pn_dnode = yang_dnode_get_parent(args->dnode, "vrf"); - vrfname = yang_dnode_get_string(pn_dnode, "./name"); + vrfname = yang_dnode_get_string(pn_dnode, "name"); zvrf = zebra_vrf_lookup_by_name(vrfname); if (!zvrf) { snprintf(args->errmsg, args->errmsg_len, diff --git a/zebra/zebra_nb_state.c b/zebra/zebra_nb_state.c index acf0b80aca..00df9bfc55 100644 --- a/zebra/zebra_nb_state.c +++ b/zebra/zebra_nb_state.c @@ -156,6 +156,8 @@ const void *lib_vrf_zebra_ribs_rib_get_next(struct nb_cb_get_next_args *args) safi_t safi; zvrf = zebra_vrf_lookup_by_id(vrf->vrf_id); + if (!zvrf) + return NULL; if (args->list_entry == NULL) { afi = AFI_IP; @@ -167,7 +169,8 @@ const void *lib_vrf_zebra_ribs_rib_get_next(struct nb_cb_get_next_args *args) } else { zrt = RB_NEXT(zebra_router_table_head, zrt); /* vrf_id/ns_id do not match, only walk for the given VRF */ - while (zrt && zrt->ns_id != zvrf->zns->ns_id) + while (zrt && (zrt->tableid != zvrf->table_id || + zrt->ns_id != zvrf->zns->ns_id)) zrt = RB_NEXT(zebra_router_table_head, zrt); } @@ -198,6 +201,8 @@ lib_vrf_zebra_ribs_rib_lookup_entry(struct nb_cb_lookup_entry_args *args) uint32_t table_id = 0; zvrf = zebra_vrf_lookup_by_id(vrf->vrf_id); + if (!zvrf) + return NULL; yang_afi_safi_identity2value(args->keys->key[0], &afi, &safi); table_id = yang_str2uint32(args->keys->key[1]); @@ -208,6 +213,28 @@ lib_vrf_zebra_ribs_rib_lookup_entry(struct nb_cb_lookup_entry_args *args) return zebra_router_find_zrt(zvrf, table_id, afi, safi); } +const void * +lib_vrf_zebra_ribs_rib_lookup_next(struct nb_cb_lookup_entry_args *args) +{ + struct vrf *vrf = (struct vrf *)args->parent_list_entry; + struct zebra_vrf *zvrf; + afi_t afi; + safi_t safi; + uint32_t table_id = 0; + + zvrf = zebra_vrf_lookup_by_id(vrf->vrf_id); + if (!zvrf) + return NULL; + + yang_afi_safi_identity2value(args->keys->key[0], &afi, &safi); + table_id = yang_str2uint32(args->keys->key[1]); + /* table_id 0 assume vrf's table_id. */ + if (!table_id) + table_id = zvrf->table_id; + + return zebra_router_find_next_zrt(zvrf, table_id, afi, safi); +} + /* * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/afi-safi-name */ @@ -285,6 +312,25 @@ lib_vrf_zebra_ribs_rib_route_lookup_entry(struct nb_cb_lookup_entry_args *args) return rn; } +const void * +lib_vrf_zebra_ribs_rib_route_lookup_next(struct nb_cb_lookup_entry_args *args) +{ + const struct zebra_router_table *zrt = args->parent_list_entry; + struct prefix p; + struct route_node *rn; + + yang_str2prefix(args->keys->key[0], &p); + + rn = route_table_get_next(zrt->table, &p); + + if (!rn) + return NULL; + + route_unlock_node(rn); + + return rn; +} + /* * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/prefix */ @@ -840,6 +886,58 @@ lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_color_get_elem( return NULL; } +/* + * XPath: + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/srv6-segs-stack/entry + */ +const void * +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_srv6_segs_stack_entry_get_next( + struct nb_cb_get_next_args *args) +{ + /* TODO: implement me. */ + return NULL; +} + +int lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_srv6_segs_stack_entry_get_keys( + struct nb_cb_get_keys_args *args) +{ + /* TODO: implement me. */ + return NB_OK; +} + +const void * +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_srv6_segs_stack_entry_lookup_entry( + struct nb_cb_lookup_entry_args *args) +{ + /* TODO: implement me. */ + return NULL; +} + +/* + * XPath: + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/srv6-segs-stack/entry/id + */ +struct yang_data * +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_srv6_segs_stack_entry_id_get_elem( + struct nb_cb_get_elem_args *args) +{ + /* TODO: implement me. */ + return NULL; +} + +/* + * XPath: + * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/srv6-segs-stack/entry/seg + */ +struct yang_data * +lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_srv6_segs_stack_entry_seg_get_elem( + struct nb_cb_get_elem_args *args) +{ + /* TODO: implement me. */ + return NULL; +} + + /* * XPath: * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/mpls-label-stack/entry diff --git a/zebra/zebra_neigh.c b/zebra/zebra_neigh.c index 0c3fb97afd..941088afd6 100644 --- a/zebra/zebra_neigh.c +++ b/zebra/zebra_neigh.c @@ -152,6 +152,19 @@ void zebra_neigh_del(struct interface *ifp, struct ipaddr *ip) zebra_neigh_free(n); } +/* kernel neigh delete all for a given interface */ +void zebra_neigh_del_all(struct interface *ifp) +{ + struct zebra_neigh_ent *n, *nn; + + if (IS_ZEBRA_DEBUG_NEIGH) + zlog_debug("zebra neigh delete all for interface %s/%d", + ifp->name, ifp->ifindex); + + RB_FOREACH_SAFE (n, zebra_neigh_rb_head, &zneigh_info->neigh_rb_tree, nn) + zebra_neigh_del(ifp, &n->ip); +} + /* kernel neigh add */ void zebra_neigh_add(struct interface *ifp, struct ipaddr *ip, struct ethaddr *mac) diff --git a/zebra/zebra_neigh.h b/zebra/zebra_neigh.h index b957b5efe5..adc5f94f76 100644 --- a/zebra/zebra_neigh.h +++ b/zebra/zebra_neigh.h @@ -43,6 +43,7 @@ struct zebra_neigh_info { extern void zebra_neigh_add(struct interface *ifp, struct ipaddr *ip, struct ethaddr *mac); extern void zebra_neigh_del(struct interface *ifp, struct ipaddr *ip); +extern void zebra_neigh_del_all(struct interface *ifp); extern void zebra_neigh_show(struct vty *vty); extern void zebra_neigh_init(void); extern void zebra_neigh_terminate(void); diff --git a/zebra/zebra_netns_id.c b/zebra/zebra_netns_id.c index 0531ab9591..1af3a3e857 100644 --- a/zebra/zebra_netns_id.c +++ b/zebra/zebra_netns_id.c @@ -5,6 +5,12 @@ */ #include <zebra.h> +#include <sys/stat.h> +#include <fcntl.h> + +#ifdef GNU_LINUX +#include <linux/if_link.h> +#endif #include "ns.h" #include "vrf.h" diff --git a/zebra/zebra_netns_notify.c b/zebra/zebra_netns_notify.c index 4260d29c43..1bb1292e34 100644 --- a/zebra/zebra_netns_notify.c +++ b/zebra/zebra_netns_notify.c @@ -5,6 +5,7 @@ */ #include <zebra.h> +#include <fcntl.h> #ifdef HAVE_NETLINK #ifdef HAVE_NETNS diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index 96e021292b..93758cca20 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -1310,6 +1310,7 @@ int nhg_ctx_process(struct nhg_ctx *ctx) break; case NHG_CTX_OP_DEL: ret = nhg_ctx_process_del(ctx); + break; case NHG_CTX_OP_NONE: break; } @@ -1525,7 +1526,13 @@ zebra_nhg_rib_find_nhe(struct nhg_hash_entry *rt_nhe, afi_t rt_afi) { struct nhg_hash_entry *nhe = NULL; - if (!(rt_nhe && rt_nhe->nhg.nexthop)) { + if (!rt_nhe) { + flog_err(EC_ZEBRA_TABLE_LOOKUP_FAILED, + "No nhg_hash_entry passed to %s", __func__); + return NULL; + } + + if (!rt_nhe->nhg.nexthop) { flog_err(EC_ZEBRA_TABLE_LOOKUP_FAILED, "No nexthop passed to %s", __func__); return NULL; @@ -1868,11 +1875,18 @@ static struct nexthop *nexthop_set_resolved(afi_t afi, labels); if (nexthop->nh_srv6) { - nexthop_add_srv6_seg6local(resolved_hop, - nexthop->nh_srv6->seg6local_action, - &nexthop->nh_srv6->seg6local_ctx); - nexthop_add_srv6_seg6(resolved_hop, - &nexthop->nh_srv6->seg6_segs); + if (nexthop->nh_srv6->seg6local_action != + ZEBRA_SEG6_LOCAL_ACTION_UNSPEC) + nexthop_add_srv6_seg6local(resolved_hop, + nexthop->nh_srv6 + ->seg6local_action, + &nexthop->nh_srv6 + ->seg6local_ctx); + if (nexthop->nh_srv6->seg6_segs) + nexthop_add_srv6_seg6(resolved_hop, + &nexthop->nh_srv6->seg6_segs->seg[0], + nexthop->nh_srv6->seg6_segs + ->num_segs); } resolved_hop->rparent = nexthop; @@ -2121,7 +2135,8 @@ zebra_nhg_connected_ifindex(struct route_node *rn, struct route_entry *match, * of those ifindexes match as well. */ RNODE_FOREACH_RE (rn, re) { - if (re->type != ZEBRA_ROUTE_CONNECT) + if (re->type != ZEBRA_ROUTE_CONNECT && + re->type != ZEBRA_ROUTE_LOCAL) continue; if (CHECK_FLAG(re->status, ROUTE_ENTRY_REMOVED)) @@ -2181,11 +2196,7 @@ static int nexthop_active(struct nexthop *nexthop, struct nhg_hash_entry *nhe, case NEXTHOP_TYPE_IFINDEX: ifp = if_lookup_by_index(nexthop->ifindex, nexthop->vrf_id); - /* - * If the interface exists and its operative or its a kernel - * route and interface is up, its active. We trust kernel routes - * to be good. - */ + /* If the interface exists and its operative, it's active */ if (ifp && (if_is_operative(ifp))) return 1; else @@ -2244,20 +2255,6 @@ static int nexthop_active(struct nexthop *nexthop, struct nhg_hash_entry *nhe, return 1; } - if (top && - ((top->family == AF_INET && top->prefixlen == IPV4_MAX_BITLEN && - nexthop->gate.ipv4.s_addr == top->u.prefix4.s_addr) || - (top->family == AF_INET6 && top->prefixlen == IPV6_MAX_BITLEN && - memcmp(&nexthop->gate.ipv6, &top->u.prefix6, IPV6_MAX_BYTELEN) == - 0)) && - nexthop->vrf_id == vrf_id) { - if (IS_ZEBRA_DEBUG_RIB_DETAILED) - zlog_debug( - " :%s: Attempting to install a max prefixlength route through itself", - __func__); - return 0; - } - /* Validation for ipv4 mapped ipv6 nexthop. */ if (IS_MAPPED_IPV6(&nexthop->gate.ipv6)) { afi = AFI_IP; @@ -2360,7 +2357,7 @@ static int nexthop_active(struct nexthop *nexthop, struct nhg_hash_entry *nhe, zlog_debug( " %s: Matched against ourself and prefix length is not max bit length", __func__); - return 0; + goto continue_up_tree; } /* Pick up selected route. */ @@ -2370,60 +2367,58 @@ static int nexthop_active(struct nexthop *nexthop, struct nhg_hash_entry *nhe, if (is_default_prefix(&rn->p) && !rnh_resolve_via_default(zvrf, p.family)) { if (IS_ZEBRA_DEBUG_RIB_DETAILED) - zlog_debug( - " :%s: Resolved against default route", - __func__); + zlog_debug(" :%s: %pFX Resolved against default route", + __func__, &p); return 0; } dest = rib_dest_from_rnode(rn); - if (dest && dest->selected_fib - && !CHECK_FLAG(dest->selected_fib->status, - ROUTE_ENTRY_REMOVED) - && dest->selected_fib->type != ZEBRA_ROUTE_TABLE) + if (dest && dest->selected_fib && + (!CHECK_FLAG(dest->selected_fib->status, + ROUTE_ENTRY_REMOVED) || + CHECK_FLAG(dest->selected_fib->status, + ROUTE_ENTRY_ROUTE_REPLACING)) && + dest->selected_fib->type != ZEBRA_ROUTE_TABLE) match = dest->selected_fib; /* If there is no selected route or matched route is EGP, go up * tree. */ - if (!match) { - do { - rn = rn->parent; - } while (rn && rn->info == NULL); - if (rn) - route_lock_node(rn); - - continue; - } - if ((match->type == ZEBRA_ROUTE_CONNECT) || - (RIB_SYSTEM_ROUTE(match) && RSYSTEM_ROUTE(type))) { + /* If the candidate match's type is considered "connected", + * we consider it first. + */ + if (match && (RIB_CONNECTED_ROUTE(match) || + (RIB_SYSTEM_ROUTE(match) && RSYSTEM_ROUTE(type)))) { match = zebra_nhg_connected_ifindex(rn, match, nexthop->ifindex); newhop = match->nhe->nhg.nexthop; - if (nexthop->type == NEXTHOP_TYPE_IPV4 || - nexthop->type == NEXTHOP_TYPE_IPV6) + if (nexthop->type == NEXTHOP_TYPE_IPV4) { nexthop->ifindex = newhop->ifindex; - else if (nexthop->ifindex != newhop->ifindex) { + nexthop->type = NEXTHOP_TYPE_IPV4_IFINDEX; + } else if (nexthop->type == NEXTHOP_TYPE_IPV6) { + nexthop->ifindex = newhop->ifindex; + nexthop->type = NEXTHOP_TYPE_IPV6_IFINDEX; + } else if (nexthop->ifindex != newhop->ifindex) { if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug( "%s: %pNHv given ifindex does not match nexthops ifindex found: %pNHv", __func__, nexthop, newhop); - /* - * NEXTHOP_TYPE_*_IFINDEX but ifindex - * doesn't match what we found. - */ - return 0; + goto continue_up_tree; } + /* NHRP special case: need to indicate onlink */ + if (match->type == ZEBRA_ROUTE_NHRP) + SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ONLINK); + if (IS_ZEBRA_DEBUG_NHG_DETAIL) zlog_debug( "%s: CONNECT match %p (%pNG), newhop %pNHv", __func__, match, match->nhe, newhop); return 1; - } else if (CHECK_FLAG(flags, ZEBRA_FLAG_ALLOW_RECURSION)) { + } else if (match && CHECK_FLAG(flags, ZEBRA_FLAG_ALLOW_RECURSION)) { struct nexthop_group *nhg; struct nexthop *resolver; struct backup_nh_map_s map = {}; @@ -2459,6 +2454,10 @@ static int nexthop_active(struct nexthop *nexthop, struct nhg_hash_entry *nhe, "%s: match %p (%pNG) not installed or being Route Replaced", __func__, match, match->nhe); + if (CHECK_FLAG(match->status, + ROUTE_ENTRY_QUEUED)) + goto continue_up_tree; + goto done_with_match; } @@ -2527,25 +2526,37 @@ static int nexthop_active(struct nexthop *nexthop, struct nhg_hash_entry *nhe, if (pmtu) *pmtu = match->mtu; - } else if (IS_ZEBRA_DEBUG_RIB_DETAILED) - zlog_debug( - " %s: Recursion failed to find", - __func__); - - return resolved; - } else { - if (IS_ZEBRA_DEBUG_RIB_DETAILED) { - zlog_debug( - " %s: Route Type %s has not turned on recursion", - __func__, zebra_route_string(type)); - if (type == ZEBRA_ROUTE_BGP - && !CHECK_FLAG(flags, ZEBRA_FLAG_IBGP)) + } else { + if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug( - " EBGP: see \"disable-ebgp-connected-route-check\" or \"disable-connected-check\""); + " %s: Recursion failed to find while looking at %pRN", + __func__, rn); + goto continue_up_tree; } - return 0; + + return 1; + } else if (IS_ZEBRA_DEBUG_RIB_DETAILED) { + zlog_debug( + " %s: Route Type %s has not turned on recursion %pRN failed to match", + __func__, zebra_route_string(type), rn); + if (type == ZEBRA_ROUTE_BGP + && !CHECK_FLAG(flags, ZEBRA_FLAG_IBGP)) + zlog_debug( + " EBGP: see \"disable-ebgp-connected-route-check\" or \"disable-connected-check\""); } + + continue_up_tree: + /* + * If there is no selected route or matched route is EGP, go up + * tree. + */ + do { + rn = rn->parent; + } while (rn && rn->info == NULL); + if (rn) + route_lock_node(rn); } + if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug(" %s: Nexthop did not lookup in table", __func__); @@ -2586,6 +2597,8 @@ static unsigned nexthop_active_check(struct route_node *rn, if (IS_ZEBRA_DEBUG_NHG_DETAIL) zlog_debug("%s: re %p, nexthop %pNHv", __func__, re, nexthop); + vrf_id = zvrf_id(rib_dest_vrf(rib_dest_from_rnode(rn))); + /* * If this is a kernel route, then if the interface is *up* then * by golly gee whiz it's a good route. @@ -2595,13 +2608,12 @@ static unsigned nexthop_active_check(struct route_node *rn, ifp = if_lookup_by_index(nexthop->ifindex, nexthop->vrf_id); - if (ifp && (if_is_operative(ifp) || if_is_up(ifp))) { + if (ifp && ifp->vrf->vrf_id == vrf_id && if_is_up(ifp)) { SET_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE); goto skip_check; } } - vrf_id = zvrf_id(rib_dest_vrf(rib_dest_from_rnode(rn))); switch (nexthop->type) { case NEXTHOP_TYPE_IFINDEX: if (nexthop_active(nexthop, nhe, &rn->p, re->type, re->flags, @@ -2696,8 +2708,7 @@ static unsigned nexthop_active_check(struct route_node *rn, } /* It'll get set if required inside */ - ret = zebra_route_map_check(family, re->type, re->instance, p, nexthop, - zvrf, re->tag); + ret = zebra_route_map_check(family, re, p, nexthop, zvrf); if (ret == RMAP_DENYMATCH) { if (IS_ZEBRA_DEBUG_RIB) { zlog_debug( @@ -3169,8 +3180,7 @@ void zebra_nhg_dplane_result(struct zebra_dplane_ctx *ctx) "Nexthop dplane ctx %p, op %s, nexthop ID (%u), result %s", ctx, dplane_op2str(op), id, dplane_res2str(status)); - switch (op) { - case DPLANE_OP_NH_DELETE: + if (op == DPLANE_OP_NH_DELETE) { if (status != ZEBRA_DPLANE_REQUEST_SUCCESS) flog_err( EC_ZEBRA_DP_DELETE_FAIL, @@ -3178,18 +3188,15 @@ void zebra_nhg_dplane_result(struct zebra_dplane_ctx *ctx) id); /* We already free'd the data, nothing to do */ - break; - case DPLANE_OP_NH_INSTALL: - case DPLANE_OP_NH_UPDATE: + } else if (op == DPLANE_OP_NH_INSTALL || op == DPLANE_OP_NH_UPDATE) { nhe = zebra_nhg_lookup_id(id); if (!nhe) { if (IS_ZEBRA_DEBUG_NHG) - zlog_debug( - "%s operation preformed on Nexthop ID (%u) in the kernel, that we no longer have in our table", - dplane_op2str(op), id); + zlog_debug("%s operation performed on Nexthop ID (%u) in the kernel, that we no longer have in our table", + dplane_op2str(op), id); - break; + return; } UNSET_FLAG(nhe->flags, NEXTHOP_GROUP_QUEUED); @@ -3217,60 +3224,6 @@ void zebra_nhg_dplane_result(struct zebra_dplane_ctx *ctx) "Failed to install Nexthop (%pNG) into the kernel", nhe); } - break; - - case DPLANE_OP_ROUTE_INSTALL: - case DPLANE_OP_ROUTE_UPDATE: - case DPLANE_OP_ROUTE_DELETE: - case DPLANE_OP_ROUTE_NOTIFY: - case DPLANE_OP_LSP_INSTALL: - case DPLANE_OP_LSP_UPDATE: - case DPLANE_OP_LSP_DELETE: - case DPLANE_OP_LSP_NOTIFY: - case DPLANE_OP_PW_INSTALL: - case DPLANE_OP_PW_UNINSTALL: - case DPLANE_OP_SYS_ROUTE_ADD: - case DPLANE_OP_SYS_ROUTE_DELETE: - case DPLANE_OP_ADDR_INSTALL: - case DPLANE_OP_ADDR_UNINSTALL: - case DPLANE_OP_MAC_INSTALL: - case DPLANE_OP_MAC_DELETE: - case DPLANE_OP_NEIGH_INSTALL: - case DPLANE_OP_NEIGH_UPDATE: - case DPLANE_OP_NEIGH_DELETE: - case DPLANE_OP_NEIGH_IP_INSTALL: - case DPLANE_OP_NEIGH_IP_DELETE: - case DPLANE_OP_VTEP_ADD: - case DPLANE_OP_VTEP_DELETE: - case DPLANE_OP_RULE_ADD: - case DPLANE_OP_RULE_DELETE: - case DPLANE_OP_RULE_UPDATE: - case DPLANE_OP_NEIGH_DISCOVER: - case DPLANE_OP_BR_PORT_UPDATE: - case DPLANE_OP_NONE: - case DPLANE_OP_IPTABLE_ADD: - case DPLANE_OP_IPTABLE_DELETE: - case DPLANE_OP_IPSET_ADD: - case DPLANE_OP_IPSET_DELETE: - case DPLANE_OP_IPSET_ENTRY_ADD: - case DPLANE_OP_IPSET_ENTRY_DELETE: - case DPLANE_OP_NEIGH_TABLE_UPDATE: - case DPLANE_OP_GRE_SET: - case DPLANE_OP_INTF_ADDR_ADD: - case DPLANE_OP_INTF_ADDR_DEL: - case DPLANE_OP_INTF_NETCONFIG: - case DPLANE_OP_INTF_INSTALL: - case DPLANE_OP_INTF_UPDATE: - case DPLANE_OP_INTF_DELETE: - case DPLANE_OP_TC_QDISC_INSTALL: - case DPLANE_OP_TC_QDISC_UNINSTALL: - case DPLANE_OP_TC_CLASS_ADD: - case DPLANE_OP_TC_CLASS_DELETE: - case DPLANE_OP_TC_CLASS_UPDATE: - case DPLANE_OP_TC_FILTER_ADD: - case DPLANE_OP_TC_FILTER_DELETE: - case DPLANE_OP_TC_FILTER_UPDATE: - break; } } @@ -3413,6 +3366,7 @@ struct nhg_hash_entry *zebra_nhg_proto_add(uint32_t id, int type, struct nhg_connected *rb_node_dep = NULL; struct nexthop *newhop; bool replace = false; + int ret = 0; if (!nhg->nexthop) { if (IS_ZEBRA_DEBUG_NHG) @@ -3510,22 +3464,31 @@ struct nhg_hash_entry *zebra_nhg_proto_add(uint32_t id, int type, if (CHECK_FLAG(old->flags, NEXTHOP_GROUP_PROTO_RELEASED)) zebra_nhg_increment_ref(old); - rib_handle_nhg_replace(old, new); + ret = rib_handle_nhg_replace(old, new); + if (ret) + /* + * if ret > 0, some previous re->nhe has freed the + * address to which old_entry is pointing. Hence mark + * the old NHE as NULL + */ + old = NULL; + else { + /* We have to decrement its singletons + * because some might not exist in NEW. + */ + if (!zebra_nhg_depends_is_empty(old)) { + frr_each (nhg_connected_tree, &old->nhg_depends, + rb_node_dep) + zebra_nhg_decrement_ref( + rb_node_dep->nhe); + } - /* We have to decrement its singletons - * because some might not exist in NEW. - */ - if (!zebra_nhg_depends_is_empty(old)) { - frr_each (nhg_connected_tree, &old->nhg_depends, - rb_node_dep) - zebra_nhg_decrement_ref(rb_node_dep->nhe); + /* Dont call the dec API, we dont want to uninstall the ID */ + old->refcnt = 0; + EVENT_OFF(old->timer); + zebra_nhg_free(old); + old = NULL; } - - /* Dont call the dec API, we dont want to uninstall the ID */ - old->refcnt = 0; - EVENT_OFF(old->timer); - zebra_nhg_free(old); - old = NULL; } if (IS_ZEBRA_DEBUG_NHG_DETAIL) @@ -3630,7 +3593,18 @@ unsigned long zebra_nhg_score_proto(int type) * This should be the last ref if we remove client routes too, * and thus should remove and free them. */ - zebra_nhg_decrement_ref(nhe); + if (!CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_PROTO_RELEASED)) + zebra_nhg_decrement_ref(nhe); + else { + + /* protocol sends explicit delete of nhg, the + * nhe->refcount is decremented in zread_nhg_del() + */ + if (IS_ZEBRA_DEBUG_RIB_DETAILED) + zlog_debug( + "%s: nhe %u (%p) refcount %u already decremented in zread_nhg_del", + __func__, nhe->id, nhe, nhe->refcnt); + } } count = iter.found->count; @@ -3713,8 +3687,13 @@ void zebra_interface_nhg_reinstall(struct interface *ifp) rb_node_dep->nhe->flags); zebra_nhg_install_kernel(rb_node_dep->nhe); - /* mark depedent uninstall, when interface associated - * singleton is installed, install depedent + /* Don't need to modify dependents if installed */ + if (CHECK_FLAG(rb_node_dep->nhe->flags, + NEXTHOP_GROUP_INSTALLED)) + continue; + + /* mark dependent uninstalled; when interface associated + * singleton is installed, install dependent */ frr_each_safe (nhg_connected_tree, &rb_node_dep->nhe->nhg_dependents, diff --git a/zebra/zebra_ns.c b/zebra/zebra_ns.c index 6bb5e971e6..f74b30a6ce 100644 --- a/zebra/zebra_ns.c +++ b/zebra/zebra_ns.c @@ -23,6 +23,7 @@ #include "rib.h" #include "table_manager.h" #include "zebra_errors.h" +#include "zebra_dplane.h" extern struct zebra_privs_t zserv_privs; @@ -41,11 +42,6 @@ struct zebra_ns *zebra_ns_lookup(ns_id_t ns_id) return (info == NULL) ? dzns : info; } -static struct zebra_ns *zebra_ns_alloc(void) -{ - return XCALLOC(MTYPE_ZEBRA_NS, sizeof(struct zebra_ns)); -} - static int zebra_ns_new(struct ns *ns) { struct zebra_ns *zns; @@ -56,7 +52,7 @@ static int zebra_ns_new(struct ns *ns) if (IS_ZEBRA_DEBUG_EVENT) zlog_info("ZNS %s with id %u (created)", ns->name, ns->ns_id); - zns = zebra_ns_alloc(); + zns = XCALLOC(MTYPE_ZEBRA_NS, sizeof(struct zebra_ns)); ns->info = zns; zns->ns = ns; zns->ns_id = ns->ns_id; @@ -101,6 +97,36 @@ int zebra_ns_disabled(struct ns *ns) return zebra_ns_disable_internal(zns, true); } +void zebra_ns_startup_continue(struct zebra_dplane_ctx *ctx) +{ + struct zebra_ns *zns = zebra_ns_lookup(dplane_ctx_get_ns_id(ctx)); + enum zebra_dplane_startup_notifications spot; + + if (!zns) { + zlog_err("%s: No Namespace associated with %u", __func__, + dplane_ctx_get_ns_id(ctx)); + return; + } + + spot = dplane_ctx_get_startup_spot(ctx); + + switch (spot) { + case ZEBRA_DPLANE_INTERFACES_READ: + interface_list_tunneldump(zns); + break; + case ZEBRA_DPLANE_TUNNELS_READ: + interface_list_second(zns); + break; + case ZEBRA_DPLANE_ADDRESSES_READ: + route_read(zns); + + vlan_read(zns); + kernel_read_pbr_rules(zns); + kernel_read_tc_qdisc(zns); + break; + } +} + /* Do global enable actions - open sockets, read kernel config etc. */ int zebra_ns_enable(ns_id_t ns_id, void **info) { @@ -111,11 +137,6 @@ int zebra_ns_enable(ns_id_t ns_id, void **info) kernel_init(zns); zebra_dplane_ns_enable(zns, true); interface_list(zns); - route_read(zns); - - vlan_read(zns); - kernel_read_pbr_rules(zns); - kernel_read_tc_qdisc(zns); return 0; } @@ -168,6 +189,8 @@ int zebra_ns_final_shutdown(struct ns *ns, kernel_terminate(zns, true); + zebra_ns_delete(ns); + return NS_WALK_CONTINUE; } diff --git a/zebra/zebra_ns.h b/zebra/zebra_ns.h index e759d522fa..55cbb95528 100644 --- a/zebra/zebra_ns.h +++ b/zebra/zebra_ns.h @@ -18,6 +18,8 @@ extern "C" { #endif #ifdef HAVE_NETLINK +#include <linux/netlink.h> + /* Socket interface to kernel */ struct nlsock { int sock; @@ -47,6 +49,8 @@ struct zebra_ns { struct nlsock netlink_dplane_out; struct nlsock netlink_dplane_in; struct event *t_netlink; + + struct nlsock ge_netlink_cmd; /* command channel for generic netlink */ #endif struct route_table *if_table; @@ -68,6 +72,8 @@ int zebra_ns_final_shutdown(struct ns *ns, void **param_out __attribute__((unused))); int zebra_ns_config_write(struct vty *vty, struct ns *ns); +void zebra_ns_startup_continue(struct zebra_dplane_ctx *ctx); + #ifdef __cplusplus } #endif diff --git a/zebra/zebra_opaque.c b/zebra/zebra_opaque.c index 8ceb1f8dc5..90533955a4 100644 --- a/zebra/zebra_opaque.c +++ b/zebra/zebra_opaque.c @@ -26,10 +26,16 @@ struct opq_client_reg { int instance; uint32_t session_id; + int flags; + struct opq_client_reg *next; struct opq_client_reg *prev; }; +/* Registration is for receiving or for notifications */ +#define OPQ_CLIENT_FLAG_RECV 0x01 +#define OPQ_CLIENT_FLAG_NOTIFY 0x02 + /* Opaque message registration info */ struct opq_msg_reg { struct opq_regh_item item; @@ -99,14 +105,18 @@ static int handle_opq_registration(const struct zmsghdr *hdr, struct stream *msg); static int handle_opq_unregistration(const struct zmsghdr *hdr, struct stream *msg); +static int handle_opq_notif_req(const struct zmsghdr *hdr, struct stream *msg); +static int handle_opq_notif_unreg(const struct zapi_opaque_notif_info *info); static int dispatch_opq_messages(struct stream_fifo *msg_fifo); static struct opq_msg_reg *opq_reg_lookup(uint32_t type); static bool opq_client_match(const struct opq_client_reg *client, const struct zapi_opaque_reg_info *info); +static bool opq_client_notif_match(const struct opq_client_reg *client, + const struct zapi_opaque_notif_info *info); static struct opq_msg_reg *opq_reg_alloc(uint32_t type); static void opq_reg_free(struct opq_msg_reg **reg); -static struct opq_client_reg *opq_client_alloc( - const struct zapi_opaque_reg_info *info); +static struct opq_client_reg *opq_client_alloc(uint8_t proto, uint16_t instance, + uint32_t session_id); static void opq_client_free(struct opq_client_reg **client); static const char *opq_client2str(char *buf, size_t buflen, const struct opq_client_reg *client); @@ -213,6 +223,7 @@ bool zebra_opaque_handles_msgid(uint16_t id) case ZEBRA_OPAQUE_MESSAGE: case ZEBRA_OPAQUE_REGISTER: case ZEBRA_OPAQUE_UNREGISTER: + case ZEBRA_OPAQUE_NOTIFY: ret = true; break; default: @@ -243,7 +254,7 @@ uint32_t zebra_opaque_enqueue_batch(struct stream_fifo *batch) } } - /* Schedule module pthread to process the batch */ + /* Schedule module's pthread to process the batch */ if (counter > 0) { if (IS_ZEBRA_DEBUG_RECV && IS_ZEBRA_DEBUG_DETAIL) zlog_debug("%s: received %u messages", @@ -325,6 +336,38 @@ static void process_messages(struct event *event) stream_fifo_deinit(&fifo); } +/* + * Helper to acquire/lock a client session and send the message in 's'. + * Note that 's' is enqueued for an io pthread, so don't free it + * or touch it if this returns 'true'. + */ +static bool opq_send_message(uint8_t proto, uint16_t instance, + uint32_t session_id, struct stream *s) +{ + bool ret = false; + struct zserv *zclient; + + /* + * TODO -- this isn't ideal: we're going through an + * acquire/release cycle for each client for each + * message. Replace this with a batching version. + */ + zclient = zserv_acquire_client(proto, instance, session_id); + if (zclient) { + /* + * Sending a message actually means enqueuing + * it for a zapi io pthread to send - so we + * don't touch the message after this call. + */ + zserv_send_message(zclient, s); + + zserv_release_client(zclient); + ret = true; + } + + return ret; +} + /* * Process (dispatch) or drop opaque messages. */ @@ -336,7 +379,6 @@ static int dispatch_opq_messages(struct stream_fifo *msg_fifo) struct opq_msg_reg *reg; int ret; struct opq_client_reg *client; - struct zserv *zclient; char buf[50]; while ((msg = stream_fifo_pop(msg_fifo)) != NULL) { @@ -350,6 +392,9 @@ static int dispatch_opq_messages(struct stream_fifo *msg_fifo) } else if (hdr.command == ZEBRA_OPAQUE_UNREGISTER) { handle_opq_unregistration(&hdr, msg); continue; + } else if (hdr.command == ZEBRA_OPAQUE_NOTIFY) { + handle_opq_notif_req(&hdr, msg); + continue; } /* We only process OPAQUE messages - drop anything else */ @@ -381,9 +426,9 @@ static int dispatch_opq_messages(struct stream_fifo *msg_fifo) if (CHECK_FLAG(info.flags, ZAPI_OPAQUE_FLAG_UNICAST)) { - if (client->proto != info.proto || - client->instance != info.instance || - client->session_id != info.session_id) + if (client->proto != info.dest_proto || + client->instance != info.dest_instance || + client->session_id != info.dest_session_id) continue; if (IS_ZEBRA_DEBUG_RECV && @@ -400,36 +445,25 @@ static int dispatch_opq_messages(struct stream_fifo *msg_fifo) dup = stream_dup(msg); } + if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_DETAIL) + zlog_debug("%s: sending %s to client %s", + __func__, (dup ? "dup" : "msg"), + opq_client2str(buf, sizeof(buf), + client)); + /* * TODO -- this isn't ideal: we're going through an * acquire/release cycle for each client for each * message. Replace this with a batching version. */ - zclient = zserv_acquire_client(client->proto, - client->instance, - client->session_id); - if (zclient) { - if (IS_ZEBRA_DEBUG_SEND && - IS_ZEBRA_DEBUG_DETAIL) - zlog_debug("%s: sending %s to client %s", - __func__, - (dup ? "dup" : "msg"), - opq_client2str(buf, - sizeof(buf), - client)); - - /* - * Sending a message actually means enqueuing - * it for a zapi io pthread to send - so we - * don't touch the message after this call. - */ - zserv_send_message(zclient, dup ? dup : msg); + if (opq_send_message(client->proto, client->instance, + client->session_id, + (dup ? dup : msg))) { + /* Message is gone - don't touch it */ if (dup) dup = NULL; else msg = NULL; - - zserv_release_client(zclient); } else { if (IS_ZEBRA_DEBUG_RECV && IS_ZEBRA_DEBUG_DETAIL) @@ -457,6 +491,66 @@ static int dispatch_opq_messages(struct stream_fifo *msg_fifo) return 0; } +/* Enqueue registration client object */ +static void opq_enqueue_client(struct opq_msg_reg *reg, + struct opq_client_reg *client) +{ + client->next = reg->clients; + if (reg->clients) + reg->clients->prev = client; + reg->clients = client; +} + +/* Dequeue registration client object */ +static void opq_dequeue_client(struct opq_msg_reg *reg, + struct opq_client_reg *client) +{ + if (client->prev) + client->prev->next = client->next; + if (client->next) + client->next->prev = client->prev; + if (reg->clients == client) + reg->clients = client->next; +} + +/* + * Send notification messages to any interested clients in 'reg', + * about 'server'; the sense is 'registered' (or not). + * The 'server' is not required for un-registrations. + */ +static void opq_send_notifications(const struct opq_msg_reg *reg, + const struct opq_client_reg *server, + bool registered) +{ + const struct opq_client_reg *client; + struct stream *msg = NULL; + + /* If there are any notification clients, send them a message */ + for (client = reg->clients; client; client = client->next) { + if (CHECK_FLAG(client->flags, OPQ_CLIENT_FLAG_NOTIFY)) { + msg = stream_new(ZEBRA_SMALL_PACKET_SIZE); + + if (registered) { + zclient_opaque_notif_encode(msg, reg->type, + registered, + server->proto, + server->instance, + server->session_id); + } else { + zclient_opaque_notif_encode(msg, reg->type, + registered, 0, 0, 0); + } + + /* Locate zebra client and enqueue message to it */ + if (!opq_send_message(client->proto, client->instance, + client->session_id, msg)) { + /* Error - need to free the message */ + stream_free(msg); + } + } + } +} + /* * Process a register/unregister message */ @@ -499,7 +593,9 @@ static int handle_opq_registration(const struct zmsghdr *hdr, goto done; } - client = opq_client_alloc(&info); + client = opq_client_alloc(info.proto, info.instance, + info.session_id); + SET_FLAG(client->flags, OPQ_CLIENT_FLAG_RECV); if (IS_ZEBRA_DEBUG_RECV) zlog_debug("%s: client %s registers for %u", @@ -508,17 +604,20 @@ static int handle_opq_registration(const struct zmsghdr *hdr, info.type); /* Link client into registration */ - client->next = reg->clients; - if (reg->clients) - reg->clients->prev = client; - reg->clients = client; + opq_enqueue_client(reg, client); + + /* Send notifications to any clients who want them */ + opq_send_notifications(reg, client, true); + } else { /* * No existing registrations - create one, add the * client, and add registration to hash. */ reg = opq_reg_alloc(info.type); - client = opq_client_alloc(&info); + client = opq_client_alloc(info.proto, info.instance, + info.session_id); + SET_FLAG(client->flags, OPQ_CLIENT_FLAG_RECV); if (IS_ZEBRA_DEBUG_RECV) zlog_debug("%s: client %s registers for new reg %u", @@ -545,8 +644,9 @@ static int handle_opq_unregistration(const struct zmsghdr *hdr, { int ret = 0; struct zapi_opaque_reg_info info; - struct opq_client_reg *client; + struct opq_client_reg *client, *tclient; struct opq_msg_reg key, *reg; + int scount; char buf[50]; memset(&info, 0, sizeof(info)); @@ -571,11 +671,16 @@ static int handle_opq_unregistration(const struct zmsghdr *hdr, goto done; } - /* Look for client */ - for (client = reg->clients; client != NULL; - client = client->next) { - if (opq_client_match(client, &info)) - break; + /* Look for client info, count servers and notif clients too */ + client = NULL; + scount = 0; + + for (tclient = reg->clients; tclient != NULL; tclient = tclient->next) { + if (opq_client_match(tclient, &info)) + client = tclient; + + if (CHECK_FLAG(tclient->flags, OPQ_CLIENT_FLAG_RECV)) + scount++; } if (client == NULL) { @@ -592,19 +697,18 @@ static int handle_opq_unregistration(const struct zmsghdr *hdr, __func__, opq_client2str(buf, sizeof(buf), client), info.type); - if (client->prev) - client->prev->next = client->next; - if (client->next) - client->next->prev = client->prev; - if (reg->clients == client) - reg->clients = client->next; - + opq_dequeue_client(reg, client); opq_client_free(&client); + scount--; /* Is registration empty now? */ if (reg->clients == NULL) { + opq_regh_del(&opq_reg_hash, reg); opq_reg_free(®); + } else if (scount == 0) { + /* Send notifications if no more servers for the message. */ + opq_send_notifications(reg, NULL, false); } done: @@ -613,13 +717,182 @@ static int handle_opq_unregistration(const struct zmsghdr *hdr, return ret; } +/* + * Handle requests about opaque notifications. + */ +static int handle_opq_notif_req(const struct zmsghdr *hdr, struct stream *msg) +{ + int ret; + struct zapi_opaque_notif_info info = {}; + struct opq_client_reg *client; + struct opq_msg_reg key, *reg; + char buf[50]; + + ret = zclient_opaque_notif_decode(msg, &info); + if (ret < 0) + goto done; + + /* Handle deregistration */ + if (!info.reg) { + ret = handle_opq_notif_unreg(&info); + goto done; + } + + memset(&key, 0, sizeof(key)); + + key.type = info.msg_type; + + reg = opq_regh_find(&opq_reg_hash, &key); + if (reg) { + /* Look for dup client */ + for (client = reg->clients; client != NULL; + client = client->next) { + if (opq_client_notif_match(client, &info)) + break; + } + + if (client) { + /* Oops - duplicate ? */ + if (IS_ZEBRA_DEBUG_RECV) + zlog_debug("%s: duplicate opq notif reg client %s", + __func__, opq_client2str(buf, + sizeof(buf), + client)); + goto done; + } + + client = opq_client_alloc(info.proto, info.instance, + info.session_id); + SET_FLAG(client->flags, OPQ_CLIENT_FLAG_NOTIFY); + + if (IS_ZEBRA_DEBUG_RECV) + zlog_debug("%s: client %s registers for notif %u", + __func__, + opq_client2str(buf, sizeof(buf), client), + info.msg_type); + + /* Link client into registration */ + opq_enqueue_client(reg, client); + + /* Send notification if any registered servers */ + /* Look for a server */ + for (client = reg->clients; client != NULL; + client = client->next) { + if (CHECK_FLAG(client->flags, OPQ_CLIENT_FLAG_RECV)) + break; + } + if (client) + opq_send_notifications(reg, client, true); + + } else if (info.reg) { + /* + * No existing registrations - create one, add the + * client, and add registration to hash. + */ + reg = opq_reg_alloc(info.msg_type); + client = opq_client_alloc(info.proto, info.instance, + info.session_id); + SET_FLAG(client->flags, OPQ_CLIENT_FLAG_NOTIFY); + + if (IS_ZEBRA_DEBUG_RECV) + zlog_debug("%s: client %s registers for new notif %u", + __func__, + opq_client2str(buf, sizeof(buf), client), + info.msg_type); + + reg->clients = client; + + opq_regh_add(&opq_reg_hash, reg); + } + +done: + stream_free(msg); + return ret; +} + +/* + * Unregister notification + */ +static int handle_opq_notif_unreg(const struct zapi_opaque_notif_info *info) +{ + int ret = 0; + struct opq_client_reg *client; + struct opq_msg_reg key, *reg; + char buf[50]; + + memset(&key, 0, sizeof(key)); + + key.type = info->msg_type; + + reg = opq_regh_find(&opq_reg_hash, &key); + if (reg == NULL) { + /* Weird: unregister for unknown message? */ + if (IS_ZEBRA_DEBUG_RECV) + zlog_debug("%s: unknown client %s/%u/%u unregisters notif for unknown type %u", + __func__, zebra_route_string(info->proto), + info->instance, info->session_id, + info->msg_type); + goto done; + } + + /* Look for client */ + for (client = reg->clients; client != NULL; client = client->next) { + if (opq_client_notif_match(client, info)) + break; + } + + if (client == NULL) { + /* Oops - unregister for unknown client? */ + if (IS_ZEBRA_DEBUG_RECV) + zlog_debug("%s: unknown client %s/%u/%u unregisters notif for %u", + __func__, zebra_route_string(info->proto), + info->instance, info->session_id, + info->msg_type); + goto done; + } + + if (IS_ZEBRA_DEBUG_RECV) + zlog_debug("%s: client %s unregisters notif for %u", __func__, + opq_client2str(buf, sizeof(buf), client), + info->msg_type); + + /* Dequeue client object */ + opq_dequeue_client(reg, client); + + opq_client_free(&client); + + /* Is registration empty now? */ + if (reg->clients == NULL) { + opq_regh_del(&opq_reg_hash, reg); + opq_reg_free(®); + } + +done: + + return ret; +} + /* Compare utility for registered clients */ static bool opq_client_match(const struct opq_client_reg *client, const struct zapi_opaque_reg_info *info) { - if (client->proto == info->proto && - client->instance == info->instance && - client->session_id == info->session_id) + /* look for matching client, skip notifications */ + if (client->proto == info->proto && client->instance == info->instance && + client->session_id == info->session_id && + CHECK_FLAG(client->flags, OPQ_CLIENT_FLAG_RECV)) + return true; + else + return false; +} + +/* Compare helper for clients registered for notifications */ +static bool opq_client_notif_match(const struct opq_client_reg *client, + const struct zapi_opaque_notif_info *info) +{ + /* look for matching client, only for notifications */ + if (client->proto == info->proto && client->instance == info->instance && + client->session_id == info->session_id && + CHECK_FLAG(client->flags, OPQ_CLIENT_FLAG_NOTIFY)) return true; else return false; @@ -655,16 +928,16 @@ static void opq_reg_free(struct opq_msg_reg **reg) XFREE(MTYPE_OPQ, (*reg)); } -static struct opq_client_reg *opq_client_alloc( - const struct zapi_opaque_reg_info *info) +static struct opq_client_reg *opq_client_alloc(uint8_t proto, uint16_t instance, + uint32_t session_id) { struct opq_client_reg *client; client = XCALLOC(MTYPE_OPQ, sizeof(struct opq_client_reg)); - client->proto = info->proto; - client->instance = info->instance; - client->session_id = info->session_id; + client->proto = proto; + client->instance = instance; + client->session_id = session_id; return client; } diff --git a/zebra/zebra_pbr.c b/zebra/zebra_pbr.c index 56cac1342e..7f3635702f 100644 --- a/zebra/zebra_pbr.c +++ b/zebra/zebra_pbr.c @@ -1,6 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* Zebra Policy Based Routing (PBR) main handling. * Copyright (C) 2018 Cumulus Networks, Inc. + * Portions: + * Copyright (c) 2021 The MITRE Corporation. + * Copyright (c) 2023 LabN Consulting, L.L.C. */ #include <zebra.h> @@ -166,10 +169,16 @@ uint32_t zebra_pbr_rules_hash_key(const void *arg) key = jhash(rule->ifname, strlen(rule->ifname), key); - return jhash_3words(rule->rule.filter.src_port, - rule->rule.filter.dst_port, - prefix_hash_key(&rule->rule.filter.dst_ip), - jhash_1word(rule->rule.unique, key)); + key = jhash_3words(rule->rule.filter.pcp, rule->rule.filter.vlan_id, + rule->rule.filter.vlan_flags, key); + + key = jhash_3words(rule->rule.filter.src_port, + rule->rule.filter.dst_port, + prefix_hash_key(&rule->rule.filter.dst_ip), key); + + key = jhash_2words(rule->rule.unique, rule->sock, key); + + return key; } bool zebra_pbr_rules_hash_equal(const void *arg1, const void *arg2) @@ -185,6 +194,9 @@ bool zebra_pbr_rules_hash_equal(const void *arg1, const void *arg2) if (r1->rule.priority != r2->rule.priority) return false; + if (r1->sock != r2->sock) + return false; + if (r1->rule.unique != r2->rule.unique) return false; @@ -220,8 +232,9 @@ bool zebra_pbr_rules_hash_equal(const void *arg1, const void *arg2) struct pbr_rule_unique_lookup { struct zebra_pbr_rule *rule; + int sock; uint32_t unique; - char ifname[INTERFACE_NAMSIZ + 1]; + char ifname[IFNAMSIZ + 1]; vrf_id_t vrf_id; }; @@ -230,9 +243,9 @@ static int pbr_rule_lookup_unique_walker(struct hash_bucket *b, void *data) struct pbr_rule_unique_lookup *pul = data; struct zebra_pbr_rule *rule = b->data; - if (pul->unique == rule->rule.unique - && strncmp(pul->ifname, rule->rule.ifname, INTERFACE_NAMSIZ) == 0 - && pul->vrf_id == rule->vrf_id) { + if (pul->sock == rule->sock && pul->unique == rule->rule.unique && + strmatch(pul->ifname, rule->rule.ifname) && + pul->vrf_id == rule->vrf_id) { pul->rule = rule; return HASHWALK_ABORT; } @@ -246,9 +259,10 @@ pbr_rule_lookup_unique(struct zebra_pbr_rule *zrule) struct pbr_rule_unique_lookup pul; pul.unique = zrule->rule.unique; - strlcpy(pul.ifname, zrule->rule.ifname, INTERFACE_NAMSIZ); + strlcpy(pul.ifname, zrule->rule.ifname, IFNAMSIZ); pul.rule = NULL; pul.vrf_id = zrule->vrf_id; + pul.sock = zrule->sock; hash_walk(zrouter.rules_hash, &pbr_rule_lookup_unique_walker, &pul); return pul.rule; @@ -501,6 +515,7 @@ void zebra_pbr_show_rule_unit(struct zebra_pbr_rule *rule, struct vty *vty) { struct pbr_rule *prule = &rule->rule; struct zebra_pbr_action *zaction = &rule->action; + struct pbr_action *pa = &prule->action; vty_out(vty, "Rules if %s\n", rule->ifname); vty_out(vty, " Seq %u pri %u\n", prule->seq, prule->priority); @@ -516,15 +531,55 @@ void zebra_pbr_show_rule_unit(struct zebra_pbr_rule *rule, struct vty *vty) if (prule->filter.filter_bm & PBR_FILTER_DST_PORT) vty_out(vty, " DST Port Match: %u\n", prule->filter.dst_port); - if (prule->filter.filter_bm & PBR_FILTER_DSFIELD) { + if (prule->filter.filter_bm & PBR_FILTER_DSCP) vty_out(vty, " DSCP Match: %u\n", (prule->filter.dsfield & PBR_DSFIELD_DSCP) >> 2); + if (prule->filter.filter_bm & PBR_FILTER_ECN) vty_out(vty, " ECN Match: %u\n", prule->filter.dsfield & PBR_DSFIELD_ECN); - } if (prule->filter.filter_bm & PBR_FILTER_FWMARK) vty_out(vty, " MARK Match: %u\n", prule->filter.fwmark); + if (prule->filter.filter_bm & PBR_FILTER_PCP) + vty_out(vty, " PCP Match: %u\n", prule->filter.pcp); + if (prule->filter.filter_bm & PBR_FILTER_VLAN_ID) + vty_out(vty, " VLAN ID Match: %u\n", prule->filter.vlan_id); + if (prule->filter.filter_bm & PBR_FILTER_VLAN_FLAGS) { + vty_out(vty, " VLAN Flags Match:"); + if (CHECK_FLAG(prule->filter.vlan_flags, PBR_VLAN_FLAGS_TAGGED)) + vty_out(vty, " tagged"); + if (CHECK_FLAG(prule->filter.vlan_flags, + PBR_VLAN_FLAGS_UNTAGGED)) + vty_out(vty, " untagged"); + if (CHECK_FLAG(prule->filter.vlan_flags, + PBR_VLAN_FLAGS_UNTAGGED_0)) + vty_out(vty, " untagged-or-zero"); + vty_out(vty, "\n"); + } + + if (CHECK_FLAG(pa->flags, PBR_ACTION_ECN)) + vty_out(vty, " Action: Set ECN: %u\n", pa->ecn); + if (CHECK_FLAG(pa->flags, PBR_ACTION_DSCP)) + vty_out(vty, " Action: Set DSCP: %u\n", pa->dscp >> 2); + + if (CHECK_FLAG(pa->flags, PBR_ACTION_SRC_IP)) + vty_out(vty, " Action: Set SRC IP: %pSU\n", &pa->src_ip); + if (CHECK_FLAG(pa->flags, PBR_ACTION_DST_IP)) + vty_out(vty, " Action: Set DST IP: %pSU\n", &pa->dst_ip); + if (CHECK_FLAG(pa->flags, PBR_ACTION_SRC_PORT)) + vty_out(vty, " Action: Set SRC PORT: %u\n", pa->src_port); + if (CHECK_FLAG(pa->flags, PBR_ACTION_DST_PORT)) + vty_out(vty, " Action: Set DST PORT: %u\n", pa->dst_port); + + if (CHECK_FLAG(pa->flags, PBR_ACTION_QUEUE_ID)) + vty_out(vty, " Action: Set Queue ID: %u\n", pa->queue_id); + + if (CHECK_FLAG(pa->flags, PBR_ACTION_PCP)) + vty_out(vty, " Action: Set PCP: %u\n", pa->pcp); + if (CHECK_FLAG(pa->flags, PBR_ACTION_VLAN_ID)) + vty_out(vty, " Action: Set VLAN ID: %u\n", pa->vlan_id); + if (CHECK_FLAG(pa->flags, PBR_ACTION_VLAN_STRIP_INNER_ANY)) + vty_out(vty, " Action: Strip VLAN ID\n"); vty_out(vty, " Tableid: %u\n", prule->action.table); if (zaction->afi == AFI_IP) @@ -1118,7 +1173,7 @@ static void zebra_pbr_display_port(struct vty *vty, uint32_t filter_bm, uint16_t port_min, uint16_t port_max, uint8_t proto) { - if (!(filter_bm & PBR_FILTER_PROTO)) { + if (!(filter_bm & PBR_FILTER_IP_PROTOCOL)) { if (port_max) vty_out(vty, ":udp/tcp:%d-%d", port_min, port_max); diff --git a/zebra/zebra_pbr.h b/zebra/zebra_pbr.h index 15ad4e35cf..1e4b5cd0f3 100644 --- a/zebra/zebra_pbr.h +++ b/zebra/zebra_pbr.h @@ -46,7 +46,7 @@ struct zebra_pbr_rule { struct pbr_rule rule; - char ifname[INTERFACE_NAMSIZ]; + char ifname[IFNAMSIZ]; struct zebra_pbr_action action; @@ -61,8 +61,6 @@ struct zebra_pbr_rule { (r->rule.filter.filter_bm & PBR_FILTER_SRC_PORT) #define IS_RULE_FILTERING_ON_DST_PORT(r) \ (r->rule.filter.filter_bm & PBR_FILTER_DST_PORT) -#define IS_RULE_FILTERING_ON_DSFIELD(r) \ - (r->rule.filter.filter_bm & PBR_FILTER_DSFIELD) #define IS_RULE_FILTERING_ON_FWMARK(r) \ (r->rule.filter.filter_bm & PBR_FILTER_FWMARK) diff --git a/zebra/zebra_ptm.c b/zebra/zebra_ptm.c index a678e71734..40630d7890 100644 --- a/zebra/zebra_ptm.c +++ b/zebra/zebra_ptm.c @@ -678,7 +678,7 @@ void zebra_ptm_bfd_dst_register(ZAPI_HANDLER_ARGS) uint8_t detect_mul; unsigned int min_rx_timer; unsigned int min_tx_timer; - char if_name[INTERFACE_NAMSIZ]; + char if_name[IFNAMSIZ]; uint8_t len; void *out_ctxt; char buf[INET6_ADDRSTRLEN]; @@ -841,7 +841,7 @@ void zebra_ptm_bfd_dst_deregister(ZAPI_HANDLER_ARGS) struct prefix src_p; struct prefix dst_p; uint8_t multi_hop; - char if_name[INTERFACE_NAMSIZ]; + char if_name[IFNAMSIZ]; uint8_t len; char buf[INET6_ADDRSTRLEN]; char tmp_buf[64]; diff --git a/zebra/zebra_pw.c b/zebra/zebra_pw.c index 12dcac1de5..deed3b6ad3 100644 --- a/zebra/zebra_pw.c +++ b/zebra/zebra_pw.c @@ -377,15 +377,18 @@ static int zebra_pw_client_close(struct zserv *client) return 0; } -void zebra_pw_init(struct zebra_vrf *zvrf) +static void zebra_pw_init(void) +{ + hook_register(zserv_client_close, zebra_pw_client_close); +} + +void zebra_pw_init_vrf(struct zebra_vrf *zvrf) { RB_INIT(zebra_pw_head, &zvrf->pseudowires); RB_INIT(zebra_static_pw_head, &zvrf->static_pseudowires); - - hook_register(zserv_client_close, zebra_pw_client_close); } -void zebra_pw_exit(struct zebra_vrf *zvrf) +void zebra_pw_exit_vrf(struct zebra_vrf *zvrf) { struct zebra_pw *pw; @@ -396,6 +399,11 @@ void zebra_pw_exit(struct zebra_vrf *zvrf) } } +void zebra_pw_terminate(void) +{ + hook_unregister(zserv_client_close, zebra_pw_client_close); +} + DEFUN_NOSH (pseudowire_if, pseudowire_if_cmd, "pseudowire IFNAME", @@ -408,8 +416,6 @@ DEFUN_NOSH (pseudowire_if, int idx = 0; zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - if (!zvrf) - return CMD_WARNING; argv_find(argv, argc, "IFNAME", &idx); ifname = argv[idx]->arg; @@ -440,8 +446,6 @@ DEFUN (no_pseudowire_if, int idx = 0; zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - if (!zvrf) - return CMD_WARNING; argv_find(argv, argc, "IFNAME", &idx); ifname = argv[idx]->arg; @@ -564,8 +568,6 @@ DEFUN (show_pseudowires, struct zebra_pw *pw; zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - if (!zvrf) - return 0; vty_out(vty, "%-16s %-24s %-12s %-8s %-10s\n", "Interface", "Neighbor", "Labels", "Protocol", "Status"); @@ -603,8 +605,6 @@ static void vty_show_mpls_pseudowire_detail(struct vty *vty) struct nexthop_group *nhg; zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - if (!zvrf) - return; RB_FOREACH (pw, zebra_pw_head, &zvrf->pseudowires) { char buf_nbr[INET6_ADDRSTRLEN]; @@ -759,8 +759,6 @@ static void vty_show_mpls_pseudowire_detail_json(struct vty *vty) struct zebra_pw *pw; zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - if (!zvrf) - return; json = json_object_new_object(); json_pws = json_object_new_array(); @@ -795,8 +793,6 @@ static int zebra_pw_config(struct vty *vty) struct zebra_pw *pw; zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - if (!zvrf) - return 0; RB_FOREACH (pw, zebra_static_pw_head, &zvrf->static_pseudowires) { vty_out(vty, "pseudowire %s\n", pw->ifname); @@ -849,4 +845,6 @@ void zebra_pw_vty_init(void) install_element(VIEW_NODE, &show_pseudowires_cmd); install_element(VIEW_NODE, &show_pseudowires_detail_cmd); + + zebra_pw_init(); } diff --git a/zebra/zebra_pw.h b/zebra/zebra_pw.h index fd94d5e5ed..431d663f7c 100644 --- a/zebra/zebra_pw.h +++ b/zebra/zebra_pw.h @@ -24,7 +24,7 @@ extern "C" { struct zebra_pw { RB_ENTRY(zebra_pw) pw_entry, static_pw_entry; vrf_id_t vrf_id; - char ifname[INTERFACE_NAMSIZ]; + char ifname[IFNAMSIZ]; ifindex_t ifindex; int type; int af; @@ -60,8 +60,9 @@ void zebra_pw_change(struct zebra_pw *, ifindex_t, int, int, union g_addr *, struct zebra_pw *zebra_pw_find(struct zebra_vrf *, const char *); void zebra_pw_update(struct zebra_pw *); void zebra_pw_install_failure(struct zebra_pw *pw, int pwstatus); -void zebra_pw_init(struct zebra_vrf *); -void zebra_pw_exit(struct zebra_vrf *); +void zebra_pw_init_vrf(struct zebra_vrf *); +void zebra_pw_exit_vrf(struct zebra_vrf *); +void zebra_pw_terminate(void); void zebra_pw_vty_init(void); #ifdef __cplusplus diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 357f112821..4b5f81a3df 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -5,6 +5,10 @@ #include <zebra.h> +#ifdef GNU_LINUX +#include <linux/rtnetlink.h> +#endif + #include "command.h" #include "if.h" #include "linklist.h" @@ -25,6 +29,7 @@ #include "frr_pthread.h" #include "printfrr.h" #include "frrscript.h" +#include "frrdistance.h" #include "zebra/zebra_router.h" #include "zebra/connected.h" @@ -103,6 +108,9 @@ static const struct { [ZEBRA_ROUTE_CONNECT] = {ZEBRA_ROUTE_CONNECT, ZEBRA_CONNECT_DISTANCE_DEFAULT, META_QUEUE_CONNECTED}, + [ZEBRA_ROUTE_LOCAL] = {ZEBRA_ROUTE_LOCAL, + ZEBRA_CONNECT_DISTANCE_DEFAULT, + META_QUEUE_CONNECTED}, [ZEBRA_ROUTE_STATIC] = {ZEBRA_ROUTE_STATIC, ZEBRA_STATIC_DISTANCE_DEFAULT, META_QUEUE_STATIC}, @@ -130,6 +138,7 @@ static const struct { [ZEBRA_ROUTE_OLSR] = {ZEBRA_ROUTE_OLSR, ZEBRA_MAX_DISTANCE_DEFAULT, META_QUEUE_OTHER}, [ZEBRA_ROUTE_TABLE] = {ZEBRA_ROUTE_TABLE, ZEBRA_TABLE_DISTANCE_DEFAULT, META_QUEUE_STATIC}, + [ZEBRA_ROUTE_TABLE_DIRECT] = {ZEBRA_ROUTE_TABLE_DIRECT, ZEBRA_TABLEDIRECT_DISTANCE_DEFAULT, META_QUEUE_STATIC}, [ZEBRA_ROUTE_LDP] = {ZEBRA_ROUTE_LDP, ZEBRA_LDP_DISTANCE_DEFAULT, META_QUEUE_OTHER}, [ZEBRA_ROUTE_VNC] = {ZEBRA_ROUTE_VNC, ZEBRA_EBGP_DISTANCE_DEFAULT, @@ -177,6 +186,7 @@ struct wq_nhg_wrapper { struct nhg_ctx *ctx; struct nhg_hash_entry *nhe; } u; + bool deletion; }; #define WQ_NHG_WRAPPER_TYPE_CTX 0x01 @@ -330,7 +340,7 @@ static char *_dump_re_status(const struct route_entry *re, char *buf, : "", CHECK_FLAG(re->status, ROUTE_ENTRY_QUEUED) ? "Queued " : "", CHECK_FLAG(re->status, ROUTE_ENTRY_ROUTE_REPLACING) - ? "Replacing" + ? "Replacing " : "", CHECK_FLAG(re->status, ROUTE_ENTRY_INSTALLED) ? "Installed " : "", @@ -365,7 +375,7 @@ int is_zebra_valid_kernel_table(uint32_t table_id) int is_zebra_main_routing_table(uint32_t table_id) { - if (table_id == RT_TABLE_MAIN) + if (table_id == rt_table_main_id) return 1; return 0; } @@ -428,18 +438,29 @@ int route_entry_update_nhe(struct route_entry *re, done: /* Detach / deref previous nhg */ - if (old_nhg) + + if (old_nhg) { + /* + * Return true if we are deleting the previous NHE + * Note: we dont check the return value of the function anywhere + * except at rib_handle_nhg_replace(). + */ + if (old_nhg->refcnt == 1) + ret = 1; + zebra_nhg_decrement_ref(old_nhg); + } return ret; } -void rib_handle_nhg_replace(struct nhg_hash_entry *old_entry, - struct nhg_hash_entry *new_entry) +int rib_handle_nhg_replace(struct nhg_hash_entry *old_entry, + struct nhg_hash_entry *new_entry) { struct zebra_router_table *zrt; struct route_node *rn; struct route_entry *re, *next; + int ret = 0; if (IS_ZEBRA_DEBUG_RIB_DETAILED || IS_ZEBRA_DEBUG_NHG_DETAIL) zlog_debug("%s: replacing routes nhe (%u) OLD %p NEW %p", @@ -451,10 +472,17 @@ void rib_handle_nhg_replace(struct nhg_hash_entry *old_entry, rn = srcdest_route_next(rn)) { RNODE_FOREACH_RE_SAFE (rn, re, next) { if (re->nhe && re->nhe == old_entry) - route_entry_update_nhe(re, new_entry); + ret += route_entry_update_nhe(re, + new_entry); } } } + + /* + * if ret > 0, some previous re->nhe has freed the address to which + * old_entry is pointing. + */ + return ret; } struct route_entry *rib_match(afi_t afi, safi_t safi, vrf_id_t vrf_id, @@ -503,7 +531,8 @@ struct route_entry *rib_match(afi_t afi, safi_t safi, vrf_id_t vrf_id, if (rn) route_lock_node(rn); } else { - if (match->type != ZEBRA_ROUTE_CONNECT) { + if (match->type != ZEBRA_ROUTE_CONNECT && + match->type != ZEBRA_ROUTE_LOCAL) { if (!CHECK_FLAG(match->status, ROUTE_ENTRY_INSTALLED)) return NULL; @@ -605,7 +634,8 @@ struct route_entry *rib_lookup_ipv4(struct prefix_ipv4 *p, vrf_id_t vrf_id) if (!match) return NULL; - if (match->type == ZEBRA_ROUTE_CONNECT) + if (match->type == ZEBRA_ROUTE_CONNECT || + match->type == ZEBRA_ROUTE_LOCAL) return match; if (CHECK_FLAG(match->status, ROUTE_ENTRY_INSTALLED)) @@ -1104,27 +1134,15 @@ static void rib_process_update_fib(struct zebra_vrf *zvrf, UNSET_FLAG(new->status, ROUTE_ENTRY_CHANGED); } -/* Check if 'alternate' RIB entry is better than 'current'. */ -static struct route_entry *rib_choose_best(struct route_entry *current, - struct route_entry *alternate) +static struct route_entry *rib_choose_best_type(uint8_t route_type, + struct route_entry *current, + struct route_entry *alternate) { - if (current == NULL) - return alternate; - - /* filter route selection in following order: - * - connected beats other types - * - if both connected, loopback or vrf wins - * - lower distance beats higher - * - lower metric beats higher for equal distance - * - last, hence oldest, route wins tie break. - */ - - /* Connected routes. Check to see if either are a vrf - * or loopback interface. If not, pick the last connected - * route of the set of lowest metric connected routes. + /* + * We know that alternate and current are now non-NULL */ - if (alternate->type == ZEBRA_ROUTE_CONNECT) { - if (current->type != ZEBRA_ROUTE_CONNECT) + if (alternate->type == route_type) { + if (current->type != route_type) return alternate; /* both are connected. are either loop or vrf? */ @@ -1153,7 +1171,41 @@ static struct route_entry *rib_choose_best(struct route_entry *current, return current; } - if (current->type == ZEBRA_ROUTE_CONNECT) + return NULL; +} + +/* Check if 'alternate' RIB entry is better than 'current'. */ +static struct route_entry *rib_choose_best(struct route_entry *current, + struct route_entry *alternate) +{ + struct route_entry *possible; + + if (current == NULL) + return alternate; + + /* filter route selection in following order: + * - Local beats Connected + * - connected beats other types + * - if both connected, loopback or vrf wins + * - lower distance beats higher + * - lower metric beats higher for equal distance + * - last, hence oldest, route wins tie break. + */ + + /* Connected or Local routes. Check to see if either are a vrf + * or loopback interface. If not, pick the last connected + * route of the set of lowest metric connected routes. + */ + possible = rib_choose_best_type(ZEBRA_ROUTE_LOCAL, current, alternate); + if (possible) + return possible; + + possible = rib_choose_best_type(ZEBRA_ROUTE_CONNECT, current, alternate); + if (possible) + return possible; + + if (current->type == ZEBRA_ROUTE_CONNECT || + current->type == ZEBRA_ROUTE_LOCAL) return current; /* higher distance loses */ @@ -1182,6 +1234,7 @@ static void rib_process(struct route_node *rn) rib_dest_t *dest; struct zebra_vrf *zvrf = NULL; struct vrf *vrf; + struct route_entry *proto_re_changed = NULL; vrf_id_t vrf_id = VRF_UNKNOWN; @@ -1251,6 +1304,7 @@ static void rib_process(struct route_node *rn) * skip it. */ if (CHECK_FLAG(re->status, ROUTE_ENTRY_CHANGED)) { + proto_re_changed = re; if (!nexthop_active_update(rn, re)) { const struct prefix *p; struct rib_table_info *info; @@ -1336,6 +1390,8 @@ static void rib_process(struct route_node *rn) * new_selected --- RE entry that is newly SELECTED * old_fib --- RE entry currently in kernel FIB * new_fib --- RE entry that is newly to be in kernel FIB + * proto_re_changed -- RE that is the last changed entry in the + * list of RE's. * * new_selected will get SELECTED flag, and is going to be redistributed * the zclients. new_fib (which can be new_selected) will be installed @@ -1390,6 +1446,22 @@ static void rib_process(struct route_node *rn) } } + /* + * If zebra has a new_selected and a proto_re_changed + * entry that was not the old selected and the protocol + * is different, zebra should notify the upper level + * protocol that the sent down entry was not selected + */ + if (new_selected && proto_re_changed && + proto_re_changed != old_selected && + new_selected->type != proto_re_changed->type) { + struct rib_table_info *info = srcdest_rnode_table_info(rn); + + zsend_route_notify_owner(rn, proto_re_changed, + ZAPI_ROUTE_BETTER_ADMIN_WON, info->afi, + info->safi); + } + /* Update fib according to selection results */ if (new_fib && old_fib) rib_process_update_fib(zvrf, rn, old_fib, new_fib); @@ -1438,7 +1510,7 @@ static void zebra_rib_evaluate_mpls(struct route_node *rn) */ static bool rib_route_match_ctx(const struct route_entry *re, const struct zebra_dplane_ctx *ctx, - bool is_update) + bool is_update, bool async) { bool result = false; @@ -1454,13 +1526,12 @@ static bool rib_route_match_ctx(const struct route_entry *re, /* We use an extra test for statics, and another for * kernel routes. */ - if (re->type == ZEBRA_ROUTE_STATIC && + if (re->type == ZEBRA_ROUTE_STATIC && !async && (re->distance != dplane_ctx_get_old_distance(ctx) || re->tag != dplane_ctx_get_old_tag(ctx))) { result = false; } else if (re->type == ZEBRA_ROUTE_KERNEL && - re->metric != - dplane_ctx_get_old_metric(ctx)) { + re->metric != dplane_ctx_get_old_metric(ctx)) { result = false; } } @@ -1482,14 +1553,15 @@ static bool rib_route_match_ctx(const struct route_entry *re, /* We use an extra test for statics, and another for * kernel routes. */ - if (re->type == ZEBRA_ROUTE_STATIC && + if (re->type == ZEBRA_ROUTE_STATIC && !async && (re->distance != dplane_ctx_get_distance(ctx) || re->tag != dplane_ctx_get_tag(ctx))) { result = false; } else if (re->type == ZEBRA_ROUTE_KERNEL && re->metric != dplane_ctx_get_metric(ctx)) { result = false; - } else if (re->type == ZEBRA_ROUTE_CONNECT) { + } else if (re->type == ZEBRA_ROUTE_CONNECT || + re->type == ZEBRA_ROUTE_LOCAL) { result = nexthop_group_equal_no_recurse( &re->nhe->nhg, dplane_ctx_get_ng(ctx)); } @@ -1547,7 +1619,7 @@ static bool rib_compare_routes(const struct route_entry *re1, * v6 link-locals, and we also support multiple addresses in the same * subnet on a single interface. */ - if (re1->type != ZEBRA_ROUTE_CONNECT) + if (re1->type != ZEBRA_ROUTE_CONNECT && re1->type != ZEBRA_ROUTE_LOCAL) return true; return false; @@ -1946,13 +2018,13 @@ static void rib_process_result(struct zebra_dplane_ctx *ctx) RNODE_FOREACH_RE(rn, rib) { if (re == NULL) { - if (rib_route_match_ctx(rib, ctx, false)) + if (rib_route_match_ctx(rib, ctx, false, false)) re = rib; } /* Check for old route match */ if (is_update && (old_re == NULL)) { - if (rib_route_match_ctx(rib, ctx, true /*is_update*/)) + if (rib_route_match_ctx(rib, ctx, true, false)) old_re = rib; } @@ -1997,9 +2069,7 @@ static void rib_process_result(struct zebra_dplane_ctx *ctx) UNSET_FLAG(old_re->status, ROUTE_ENTRY_QUEUED); } - switch (op) { - case DPLANE_OP_ROUTE_INSTALL: - case DPLANE_OP_ROUTE_UPDATE: + if (op == DPLANE_OP_ROUTE_INSTALL || op == DPLANE_OP_ROUTE_UPDATE) { if (status == ZEBRA_DPLANE_REQUEST_SUCCESS) { if (re) { UNSET_FLAG(re->status, ROUTE_ENTRY_FAILED); @@ -2090,8 +2160,7 @@ static void rib_process_result(struct zebra_dplane_ctx *ctx) VRF_LOGNAME(vrf), dplane_ctx_get_vrf(ctx), dplane_ctx_get_table(ctx), rn); } - break; - case DPLANE_OP_ROUTE_DELETE: + } else if (op == DPLANE_OP_ROUTE_DELETE) { rt_delete = true; if (re) SET_FLAG(re->status, ROUTE_ENTRY_FAILED); @@ -2130,60 +2199,6 @@ static void rib_process_result(struct zebra_dplane_ctx *ctx) if ((re && RIB_SYSTEM_ROUTE(re)) || (old_re && RIB_SYSTEM_ROUTE(old_re))) zebra_rib_fixup_system(rn); - break; - - case DPLANE_OP_NONE: - case DPLANE_OP_ROUTE_NOTIFY: - case DPLANE_OP_NH_INSTALL: - case DPLANE_OP_NH_UPDATE: - case DPLANE_OP_NH_DELETE: - case DPLANE_OP_LSP_INSTALL: - case DPLANE_OP_LSP_UPDATE: - case DPLANE_OP_LSP_DELETE: - case DPLANE_OP_LSP_NOTIFY: - case DPLANE_OP_PW_INSTALL: - case DPLANE_OP_PW_UNINSTALL: - case DPLANE_OP_SYS_ROUTE_ADD: - case DPLANE_OP_SYS_ROUTE_DELETE: - case DPLANE_OP_ADDR_INSTALL: - case DPLANE_OP_ADDR_UNINSTALL: - case DPLANE_OP_MAC_INSTALL: - case DPLANE_OP_MAC_DELETE: - case DPLANE_OP_NEIGH_INSTALL: - case DPLANE_OP_NEIGH_UPDATE: - case DPLANE_OP_NEIGH_DELETE: - case DPLANE_OP_VTEP_ADD: - case DPLANE_OP_VTEP_DELETE: - case DPLANE_OP_RULE_ADD: - case DPLANE_OP_RULE_DELETE: - case DPLANE_OP_RULE_UPDATE: - case DPLANE_OP_NEIGH_DISCOVER: - case DPLANE_OP_BR_PORT_UPDATE: - case DPLANE_OP_IPTABLE_ADD: - case DPLANE_OP_IPTABLE_DELETE: - case DPLANE_OP_IPSET_ADD: - case DPLANE_OP_IPSET_DELETE: - case DPLANE_OP_IPSET_ENTRY_ADD: - case DPLANE_OP_IPSET_ENTRY_DELETE: - case DPLANE_OP_NEIGH_IP_INSTALL: - case DPLANE_OP_NEIGH_IP_DELETE: - case DPLANE_OP_NEIGH_TABLE_UPDATE: - case DPLANE_OP_GRE_SET: - case DPLANE_OP_INTF_ADDR_ADD: - case DPLANE_OP_INTF_ADDR_DEL: - case DPLANE_OP_INTF_NETCONFIG: - case DPLANE_OP_INTF_INSTALL: - case DPLANE_OP_INTF_UPDATE: - case DPLANE_OP_INTF_DELETE: - case DPLANE_OP_TC_QDISC_INSTALL: - case DPLANE_OP_TC_QDISC_UNINSTALL: - case DPLANE_OP_TC_CLASS_ADD: - case DPLANE_OP_TC_CLASS_DELETE: - case DPLANE_OP_TC_CLASS_UPDATE: - case DPLANE_OP_TC_FILTER_ADD: - case DPLANE_OP_TC_FILTER_DELETE: - case DPLANE_OP_TC_FILTER_UPDATE: - break; } zebra_rib_evaluate_rn_nexthops(rn, seq, rt_delete); @@ -2271,7 +2286,7 @@ static void rib_process_dplane_notify(struct zebra_dplane_ctx *ctx) * info. */ RNODE_FOREACH_RE(rn, re) { - if (rib_route_match_ctx(re, ctx, false /*!update*/)) + if (rib_route_match_ctx(re, ctx, false, true)) break; } @@ -2517,7 +2532,7 @@ static void process_subq_evpn(struct listnode *lnode) static void process_subq_nhg(struct listnode *lnode) { struct nhg_ctx *ctx; - struct nhg_hash_entry *nhe, *newnhe; + struct nhg_hash_entry *nhe, *newnhe, *oldnhe; struct wq_nhg_wrapper *w; uint8_t qindex = META_QUEUE_NHG; @@ -2549,15 +2564,33 @@ static void process_subq_nhg(struct listnode *lnode) subqueue2str(qindex)); /* Process incoming nhg update, probably from a proto daemon */ - newnhe = zebra_nhg_proto_add(nhe->id, nhe->type, - nhe->zapi_instance, - nhe->zapi_session, &nhe->nhg, 0); + if (w->deletion) { + /* + * Delete the received nhg id + */ + oldnhe = zebra_nhg_proto_del(nhe->id, nhe->type); + if (oldnhe) { + zsend_nhg_notify(nhe->type, nhe->zapi_instance, + nhe->zapi_session, nhe->id, + ZAPI_NHG_REMOVED); + zebra_nhg_decrement_ref(oldnhe); + } else + zsend_nhg_notify(nhe->type, nhe->zapi_instance, + nhe->zapi_session, nhe->id, + ZAPI_NHG_REMOVE_FAIL); - /* Report error to daemon via ZAPI */ - if (newnhe == NULL) - zsend_nhg_notify(nhe->type, nhe->zapi_instance, - nhe->zapi_session, nhe->id, - ZAPI_NHG_FAIL_INSTALL); + } else { + newnhe = zebra_nhg_proto_add(nhe->id, nhe->type, + nhe->zapi_instance, + nhe->zapi_session, + &nhe->nhg, 0); + + /* Report error to daemon via ZAPI */ + if (newnhe == NULL) + zsend_nhg_notify(nhe->type, nhe->zapi_instance, + nhe->zapi_session, nhe->id, + ZAPI_NHG_FAIL_INSTALL); + } /* Free temp nhe - we own that memory. */ zebra_nhg_free(nhe); @@ -2706,6 +2739,8 @@ static void process_subq_early_route_add(struct zebra_early_route *ere) return; } } else { + struct nexthop *tmp_nh; + /* Lookup nhe from route information */ nhe = zebra_nhg_rib_find_nhe(ere->re_nhe, ere->afi); if (!nhe) { @@ -2723,6 +2758,22 @@ static void process_subq_early_route_add(struct zebra_early_route *ere) early_route_memory_free(ere); return; } + for (ALL_NEXTHOPS(nhe->nhg, tmp_nh)) { + if (CHECK_FLAG(tmp_nh->flags, NEXTHOP_FLAG_EVPN)) { + struct ipaddr vtep_ip = {}; + + if (ere->afi == AFI_IP) { + vtep_ip.ipa_type = IPADDR_V4; + vtep_ip.ipaddr_v4 = tmp_nh->gate.ipv4; + } else { + vtep_ip.ipa_type = IPADDR_V6; + vtep_ip.ipaddr_v6 = tmp_nh->gate.ipv6; + } + zebra_rib_queue_evpn_route_add( + re->vrf_id, &tmp_nh->rmac, &vtep_ip, + &ere->p); + } + } } /* @@ -2824,8 +2875,13 @@ static void process_subq_early_route_add(struct zebra_early_route *ere) rib_addnode(rn, re, 1); /* Free implicit route.*/ - if (same) + if (same) { + rib_dest_t *dest = rn->info; + + if (same == dest->selected_fib) + SET_FLAG(same->status, ROUTE_ENTRY_ROUTE_REPLACING); rib_delnode(rn, same); + } /* See if we can remove some RE entries that are queued for * removal, but won't be considered in rib processing. @@ -2907,8 +2963,8 @@ static void process_subq_early_route_delete(struct zebra_early_route *ere) struct nexthop *nh = NULL; - if (ere->re->nhe) - nh = ere->re->nhe->nhg.nexthop; + if (ere->re_nhe) + nh = ere->re_nhe->nhg.nexthop; /* Lookup same type route. */ RNODE_FOREACH_RE (rn, re) { @@ -2926,7 +2982,9 @@ static void process_subq_early_route_delete(struct zebra_early_route *ere) if (re->type == ZEBRA_ROUTE_KERNEL && re->metric != ere->re->metric) continue; - if (re->type == ZEBRA_ROUTE_CONNECT && (rtnh = nh) && + if ((re->type == ZEBRA_ROUTE_CONNECT || + re->type == ZEBRA_ROUTE_LOCAL) && + (rtnh = re->nhe->nhg.nexthop) && rtnh->type == NEXTHOP_TYPE_IFINDEX && nh) { if (rtnh->ifindex != nh->ifindex) continue; @@ -3232,12 +3290,26 @@ static int rib_meta_queue_add(struct meta_queue *mq, void *data) return -1; /* Invariant: at this point we always have rn->info set. */ - if (CHECK_FLAG(rib_dest_from_rnode(rn)->flags, - RIB_ROUTE_QUEUED(qindex))) { - if (IS_ZEBRA_DEBUG_RIB_DETAILED) + /* A route node must only be in one sub-queue at a time. */ + if (CHECK_FLAG(rib_dest_from_rnode(rn)->flags, MQ_BIT_MASK)) { + if (IS_ZEBRA_DEBUG_RIB_DETAILED) { + /* + * curr_qindex_bitmask is power of 2, because a route node must only be in one sub-queue at a time, + * so for getting current sub-queue index from bitmask we may use part of classic msb function + * (find most significant set bit). + */ + const uint32_t curr_qindex_bitmask = CHECK_FLAG(rib_dest_from_rnode(rn)->flags, MQ_BIT_MASK); + static const uint8_t pos[32] = { 0, 1, 28, 2, 29, 14, 24, 3, + 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, + 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 }; + + curr_qindex = pos[(uint32_t)(curr_qindex_bitmask * 0x077CB531UL) >> 27]; + rnode_debug(rn, re->vrf_id, "rn %p is already queued in sub-queue %s", - (void *)rn, subqueue2str(qindex)); + (void *)rn, subqueue2str(curr_qindex)); + } + return -1; } @@ -3286,7 +3358,8 @@ static int rib_meta_queue_nhg_ctx_add(struct meta_queue *mq, void *data) return 0; } -static int rib_meta_queue_nhg_add(struct meta_queue *mq, void *data) +static int rib_meta_queue_nhg_process(struct meta_queue *mq, void *data, + bool deletion) { struct nhg_hash_entry *nhe = NULL; uint8_t qindex = META_QUEUE_NHG; @@ -3301,6 +3374,7 @@ static int rib_meta_queue_nhg_add(struct meta_queue *mq, void *data) w->type = WQ_NHG_WRAPPER_TYPE_NHG; w->u.nhe = nhe; + w->deletion = deletion; listnode_add(mq->subq[qindex], w); mq->size++; @@ -3312,6 +3386,16 @@ static int rib_meta_queue_nhg_add(struct meta_queue *mq, void *data) return 0; } +static int rib_meta_queue_nhg_add(struct meta_queue *mq, void *data) +{ + return rib_meta_queue_nhg_process(mq, data, false); +} + +static int rib_meta_queue_nhg_del(struct meta_queue *mq, void *data) +{ + return rib_meta_queue_nhg_process(mq, data, true); +} + static int rib_meta_queue_evpn_add(struct meta_queue *mq, void *data) { listnode_add(mq->subq[META_QUEUE_EVPN], data); @@ -3419,6 +3503,17 @@ int rib_queue_nhe_add(struct nhg_hash_entry *nhe) return mq_add_handler(nhe, rib_meta_queue_nhg_add); } +/* + * Enqueue incoming nhg from proto daemon for processing + */ +int rib_queue_nhe_del(struct nhg_hash_entry *nhe) +{ + if (nhe == NULL) + return -1; + + return mq_add_handler(nhe, rib_meta_queue_nhg_del); +} + /* * Enqueue evpn route for processing */ @@ -3978,6 +4073,10 @@ void rib_delnode(struct route_node *rn, struct route_entry *re) if (IS_ZEBRA_DEBUG_RIB) rnode_debug(rn, re->vrf_id, "rn %p, re %p, removing", (void *)rn, (void *)re); + + if (IS_ZEBRA_DEBUG_RIB_DETAILED) + route_entry_dump(&rn->p, NULL, re); + SET_FLAG(re->status, ROUTE_ENTRY_REMOVED); afi = (rn->p.family == AF_INET) @@ -4023,7 +4122,6 @@ static void _route_entry_dump_nh(const struct route_entry *re, ifp ? ifp->name : "Unknown"); break; case NEXTHOP_TYPE_IPV4: - /* fallthrough */ case NEXTHOP_TYPE_IPV4_IFINDEX: inet_ntop(AF_INET, &nexthop->gate, nhname, INET6_ADDRSTRLEN); break; @@ -4123,8 +4221,8 @@ void _route_entry_dump(const char *func, union prefixconstptr pp, zclient_dump_route_flags(re->flags, flags_buf, sizeof(flags_buf)), _dump_re_status(re, status_buf, sizeof(status_buf))); - zlog_debug("%s: nexthop_num == %u, nexthop_active_num == %u", straddr, - nexthop_group_nexthop_num(&(re->nhe->nhg)), + zlog_debug("%s: tag == %u, nexthop_num == %u, nexthop_active_num == %u", + straddr, re->tag, nexthop_group_nexthop_num(&(re->nhe->nhg)), nexthop_group_active_nexthop_num(&(re->nhe->nhg))); /* Dump nexthops */ @@ -4161,10 +4259,10 @@ static int rib_meta_queue_early_route_add(struct meta_queue *mq, void *data) mq->size++; if (IS_ZEBRA_DEBUG_RIB_DETAILED) - zlog_debug( - "Route %pFX(%u) queued for processing into sub-queue %s", - &ere->p, ere->re->vrf_id, - subqueue2str(META_QUEUE_EARLY_ROUTE)); + zlog_debug("Route %pFX(%u) (%s) queued for processing into sub-queue %s", + &ere->p, ere->re->vrf_id, + ere->deletion ? "delete" : "add", + subqueue2str(META_QUEUE_EARLY_ROUTE)); return 0; } @@ -4207,6 +4305,12 @@ struct route_entry *zebra_rib_route_entry_new(vrf_id_t vrf_id, int type, return re; } + +void zebra_rib_route_entry_free(struct route_entry *re) +{ + XFREE(MTYPE_RE, re); +} + /* * Internal route-add implementation; there are a couple of different public * signatures. Callers in this path are responsible for the memory they @@ -4857,8 +4961,12 @@ static void rib_process_dplane_results(struct event *thread) case DPLANE_OP_BR_PORT_UPDATE: case DPLANE_OP_NEIGH_TABLE_UPDATE: case DPLANE_OP_GRE_SET: + case DPLANE_OP_SRV6_ENCAP_SRCADDR_SET: case DPLANE_OP_NONE: break; + case DPLANE_OP_STARTUP_STAGE: + zebra_ns_startup_continue(ctx); + break; } /* Dispatch by op code */ @@ -4916,7 +5024,7 @@ static void check_route_info(void) } /* Routing information base initialize. */ -void rib_init(void) +void zebra_rib_init(void) { check_route_info(); @@ -4928,6 +5036,20 @@ void rib_init(void) zebra_dplane_init(rib_dplane_results); } +void zebra_rib_terminate(void) +{ + struct zebra_dplane_ctx *ctx; + + EVENT_OFF(t_dplane); + + ctx = dplane_ctx_dequeue(&rib_dplane_q); + while (ctx) { + dplane_ctx_fini(&ctx); + + ctx = dplane_ctx_dequeue(&rib_dplane_q); + } +} + /* * vrf_id_get_next * @@ -4981,7 +5103,7 @@ struct route_table *rib_tables_iter_next(rib_tables_iter_t *iter) iter->vrf_id = VRF_DEFAULT; iter->afi_safi_ix = -1; - /* Fall through */ + fallthrough; case RIB_TABLES_ITER_S_ITERATING: iter->afi_safi_ix++; diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c index 28b83ce8b6..b387e9949b 100644 --- a/zebra/zebra_rnh.c +++ b/zebra/zebra_rnh.c @@ -513,10 +513,14 @@ static bool rnh_check_re_nexthops(const struct route_entry *re, goto done; } - /* Some special checks if registration asked for them. */ + /* + * Some special checks if registration asked for them. + * LOCAL routes are by their definition not CONNECTED + * and as such should not be considered here + */ if (CHECK_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED)) { - if ((re->type == ZEBRA_ROUTE_CONNECT) - || (re->type == ZEBRA_ROUTE_STATIC)) + if ((re->type == ZEBRA_ROUTE_CONNECT) || + (re->type == ZEBRA_ROUTE_STATIC)) ret = true; if (re->type == ZEBRA_ROUTE_NHRP) { @@ -1268,6 +1272,7 @@ void show_nexthop_json_helper(json_object *json_nexthop, json_object *json_backups = NULL; json_object *json_seg6local = NULL; json_object *json_seg6 = NULL; + json_object *json_segs = NULL; int i; json_object_int_add(json_nexthop, "flags", nexthop->flags); @@ -1425,11 +1430,31 @@ void show_nexthop_json_helper(json_object *json_nexthop, nexthop->nh_srv6->seg6local_action)); json_object_object_add(json_nexthop, "seg6local", json_seg6local); - - json_seg6 = json_object_new_object(); - json_object_string_addf(json_seg6, "segs", "%pI6", - &nexthop->nh_srv6->seg6_segs); - json_object_object_add(json_nexthop, "seg6", json_seg6); + if (nexthop->nh_srv6->seg6_segs && + nexthop->nh_srv6->seg6_segs->num_segs == 1) { + json_seg6 = json_object_new_object(); + json_object_string_addf(json_seg6, "segs", "%pI6", + &nexthop->nh_srv6->seg6_segs + ->seg[0]); + json_object_object_add(json_nexthop, "seg6", json_seg6); + } else { + if (nexthop->nh_srv6->seg6_segs) { + json_segs = json_object_new_array(); + for (int seg_idx = 0; + seg_idx < + nexthop->nh_srv6->seg6_segs->num_segs; + seg_idx++) + json_object_array_add( + json_segs, + json_object_new_stringf( + "%pI6", + &nexthop->nh_srv6 + ->seg6_segs + ->seg[seg_idx])); + json_object_object_add(json_nexthop, "seg6", + json_segs); + } + } } } @@ -1440,7 +1465,9 @@ void show_route_nexthop_helper(struct vty *vty, const struct route_entry *re, const struct nexthop *nexthop) { char buf[MPLS_LABEL_STRLEN]; - int i; + char seg_buf[SRV6_SEG_STRLEN]; + struct seg6_segs segs; + uint8_t i; switch (nexthop->type) { case NEXTHOP_TYPE_IPV4: @@ -1538,9 +1565,17 @@ void show_route_nexthop_helper(struct vty *vty, const struct route_entry *re, seg6local_action2str( nexthop->nh_srv6->seg6local_action), buf); - if (IPV6_ADDR_CMP(&nexthop->nh_srv6->seg6_segs, &in6addr_any)) - vty_out(vty, ", seg6 %pI6", - &nexthop->nh_srv6->seg6_segs); + if (nexthop->nh_srv6->seg6_segs && + IPV6_ADDR_CMP(&nexthop->nh_srv6->seg6_segs->seg[0], + &in6addr_any)) { + segs.num_segs = nexthop->nh_srv6->seg6_segs->num_segs; + for (i = 0; i < segs.num_segs; i++) + memcpy(&segs.segs[i], + &nexthop->nh_srv6->seg6_segs->seg[i], + sizeof(struct in6_addr)); + snprintf_seg6_segs(seg_buf, SRV6_SEG_STRLEN, &segs); + vty_out(vty, ", seg6 %s", seg_buf); + } } if (nexthop->weight) diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c index 142501b149..21aaf1d066 100644 --- a/zebra/zebra_routemap.c +++ b/zebra/zebra_routemap.c @@ -31,13 +31,9 @@ static uint32_t zebra_rmap_update_timer = ZEBRA_RMAP_DEFAULT_UPDATE_TIMER; static struct event *zebra_t_rmap_update = NULL; char *zebra_import_table_routemap[AFI_MAX][ZEBRA_KERNEL_TABLE_MAX]; -struct nh_rmap_obj { +struct zebra_rmap_obj { struct nexthop *nexthop; - vrf_id_t vrf_id; - uint32_t source_protocol; - uint8_t instance; - int metric; - route_tag_t tag; + struct route_entry *re; }; static void zebra_route_map_set_delay_timer(uint32_t value); @@ -49,12 +45,12 @@ static enum route_map_cmd_result_t route_match_tag(void *rule, const struct prefix *prefix, void *object) { route_tag_t *tag; - struct nh_rmap_obj *nh_data; + struct zebra_rmap_obj *rm_data; tag = rule; - nh_data = object; + rm_data = object; - if (nh_data->tag == *tag) + if (rm_data->re->tag == *tag) return RMAP_MATCH; return RMAP_NOMATCH; @@ -74,19 +70,19 @@ static const struct route_map_rule_cmd route_match_tag_cmd = { static enum route_map_cmd_result_t route_match_interface(void *rule, const struct prefix *prefix, void *object) { - struct nh_rmap_obj *nh_data; + struct zebra_rmap_obj *rm_data; char *ifname = rule; ifindex_t ifindex; if (strcasecmp(ifname, "any") == 0) return RMAP_MATCH; - nh_data = object; - if (!nh_data || !nh_data->nexthop) + rm_data = object; + if (!rm_data || !rm_data->nexthop) return RMAP_NOMATCH; - ifindex = ifname2ifindex(ifname, nh_data->vrf_id); + ifindex = ifname2ifindex(ifname, rm_data->nexthop->vrf_id); if (ifindex == 0) return RMAP_NOMATCH; - if (nh_data->nexthop->ifindex == ifindex) + if (rm_data->nexthop->ifindex == ifindex) return RMAP_MATCH; return RMAP_NOMATCH; @@ -367,7 +363,7 @@ static int ip_nht_rm_add(struct zebra_vrf *zvrf, const char *rmap, int rtype, route_map_counter_increment(NHT_RM_MAP(zvrf, afi, rtype)); if (NHT_RM_MAP(zvrf, afi, rtype)) - zebra_evaluate_rnh(zvrf, AFI_IP, 1, NULL, SAFI_UNICAST); + zebra_evaluate_rnh(zvrf, afi, 1, NULL, SAFI_UNICAST); return CMD_SUCCESS; } @@ -388,7 +384,7 @@ static int ip_nht_rm_del(struct zebra_vrf *zvrf, const char *rmap, int rtype, zvrf->vrf->vrf_id, rtype); NHT_RM_MAP(zvrf, afi, rtype) = NULL; - zebra_evaluate_rnh(zvrf, AFI_IP, 1, NULL, SAFI_UNICAST); + zebra_evaluate_rnh(zvrf, afi, 1, NULL, SAFI_UNICAST); } XFREE(MTYPE_ROUTE_MAP_NAME, NHT_RM_NAME(zvrf, afi, rtype)); } @@ -1017,21 +1013,21 @@ static enum route_map_cmd_result_t route_match_ip_next_hop(void *rule, const struct prefix *prefix, void *object) { struct access_list *alist; - struct nh_rmap_obj *nh_data; + struct zebra_rmap_obj *rm_data; struct prefix_ipv4 p; - nh_data = object; - if (!nh_data) + rm_data = object; + if (!rm_data) return RMAP_NOMATCH; - switch (nh_data->nexthop->type) { + switch (rm_data->nexthop->type) { case NEXTHOP_TYPE_IFINDEX: /* Interface routes can't match ip next-hop */ return RMAP_NOMATCH; case NEXTHOP_TYPE_IPV4_IFINDEX: case NEXTHOP_TYPE_IPV4: p.family = AF_INET; - p.prefix = nh_data->nexthop->gate.ipv4; + p.prefix = rm_data->nexthop->gate.ipv4; p.prefixlen = IPV4_MAX_BITLEN; break; case NEXTHOP_TYPE_IPV6: @@ -1080,21 +1076,21 @@ route_match_ip_next_hop_prefix_list(void *rule, const struct prefix *prefix, void *object) { struct prefix_list *plist; - struct nh_rmap_obj *nh_data; + struct zebra_rmap_obj *rm_data; struct prefix_ipv4 p; - nh_data = (struct nh_rmap_obj *)object; - if (!nh_data) + rm_data = (struct zebra_rmap_obj *)object; + if (!rm_data) return RMAP_NOMATCH; - switch (nh_data->nexthop->type) { + switch (rm_data->nexthop->type) { case NEXTHOP_TYPE_IFINDEX: /* Interface routes can't match ip next-hop */ return RMAP_NOMATCH; case NEXTHOP_TYPE_IPV4_IFINDEX: case NEXTHOP_TYPE_IPV4: p.family = AF_INET; - p.prefix = nh_data->nexthop->gate.ipv4; + p.prefix = rm_data->nexthop->gate.ipv4; p.prefixlen = IPV4_MAX_BITLEN; break; case NEXTHOP_TYPE_IPV6: @@ -1264,14 +1260,14 @@ static enum route_map_cmd_result_t route_match_ipv6_next_hop_type(void *rule, const struct prefix *prefix, void *object) { - struct nh_rmap_obj *nh_data; + struct zebra_rmap_obj *rm_data; if (prefix->family == AF_INET6) { - nh_data = (struct nh_rmap_obj *)object; - if (!nh_data) + rm_data = (struct zebra_rmap_obj *)object; + if (!rm_data) return RMAP_NOMATCH; - if (nh_data->nexthop->type == NEXTHOP_TYPE_BLACKHOLE) + if (rm_data->nexthop->type == NEXTHOP_TYPE_BLACKHOLE) return RMAP_MATCH; } @@ -1356,21 +1352,21 @@ route_match_ip_nexthop_prefix_len(void *rule, const struct prefix *prefix, void *object) { uint32_t *prefixlen = (uint32_t *)rule; - struct nh_rmap_obj *nh_data; + struct zebra_rmap_obj *rm_data; struct prefix_ipv4 p; - nh_data = (struct nh_rmap_obj *)object; - if (!nh_data || !nh_data->nexthop) + rm_data = (struct zebra_rmap_obj *)object; + if (!rm_data || !rm_data->nexthop) return RMAP_NOMATCH; - switch (nh_data->nexthop->type) { + switch (rm_data->nexthop->type) { case NEXTHOP_TYPE_IFINDEX: /* Interface routes can't match ip next-hop */ return RMAP_NOMATCH; case NEXTHOP_TYPE_IPV4_IFINDEX: case NEXTHOP_TYPE_IPV4: p.family = AF_INET; - p.prefix = nh_data->nexthop->gate.ipv4; + p.prefix = rm_data->nexthop->gate.ipv4; p.prefixlen = IPV4_MAX_BITLEN; break; case NEXTHOP_TYPE_IPV6: @@ -1395,14 +1391,14 @@ static enum route_map_cmd_result_t route_match_ip_next_hop_type(void *rule, const struct prefix *prefix, void *object) { - struct nh_rmap_obj *nh_data; + struct zebra_rmap_obj *rm_data; if (prefix->family == AF_INET) { - nh_data = (struct nh_rmap_obj *)object; - if (!nh_data) + rm_data = (struct zebra_rmap_obj *)object; + if (!rm_data) return RMAP_NOMATCH; - if (nh_data->nexthop->type == NEXTHOP_TYPE_BLACKHOLE) + if (rm_data->nexthop->type == NEXTHOP_TYPE_BLACKHOLE) return RMAP_MATCH; } @@ -1432,15 +1428,14 @@ static const struct route_map_rule_cmd static enum route_map_cmd_result_t route_match_source_protocol(void *rule, const struct prefix *p, void *object) { - uint32_t *rib_type = (uint32_t *)rule; - struct nh_rmap_obj *nh_data; + int32_t *rib_type = (int32_t *)rule; + struct zebra_rmap_obj *rm_data; - nh_data = (struct nh_rmap_obj *)object; - if (!nh_data) + rm_data = (struct zebra_rmap_obj *)object; + if (!rm_data) return RMAP_NOMATCH; - return ((nh_data->source_protocol == *rib_type) ? RMAP_MATCH - : RMAP_NOMATCH); + return ((rm_data->re->type == *rib_type) ? RMAP_MATCH : RMAP_NOMATCH); } static void *route_match_source_protocol_compile(const char *arg) @@ -1473,13 +1468,13 @@ static enum route_map_cmd_result_t route_match_source_instance(void *rule, const struct prefix *p, void *object) { uint8_t *instance = (uint8_t *)rule; - struct nh_rmap_obj *nh_data; + struct zebra_rmap_obj *rm_data; - nh_data = (struct nh_rmap_obj *)object; - if (!nh_data) + rm_data = (struct zebra_rmap_obj *)object; + if (!rm_data) return RMAP_NOMATCH; - return (nh_data->instance == *instance) ? RMAP_MATCH : RMAP_NOMATCH; + return (rm_data->re->instance == *instance) ? RMAP_MATCH : RMAP_NOMATCH; } static void *route_match_source_instance_compile(const char *arg) @@ -1513,10 +1508,10 @@ static const struct route_map_rule_cmd route_match_source_instance_cmd = { static enum route_map_cmd_result_t route_set_src(void *rule, const struct prefix *prefix, void *object) { - struct nh_rmap_obj *nh_data; + struct zebra_rmap_obj *rm_data; - nh_data = (struct nh_rmap_obj *)object; - nh_data->nexthop->rmap_src = *(union g_addr *)rule; + rm_data = (struct zebra_rmap_obj *)object; + rm_data->nexthop->rmap_src = *(union g_addr *)rule; return RMAP_OKAY; } @@ -1703,7 +1698,7 @@ static void zebra_nht_rm_update(const char *rmap) afi_ipv6 = 1; zebra_evaluate_rnh( - zvrf, AFI_IP, 1, NULL, + zvrf, AFI_IP6, 1, NULL, SAFI_UNICAST); } } @@ -1761,26 +1756,22 @@ void zebra_routemap_finish(void) route_map_finish(); } -route_map_result_t -zebra_route_map_check(afi_t family, int rib_type, uint8_t instance, - const struct prefix *p, struct nexthop *nexthop, - struct zebra_vrf *zvrf, route_tag_t tag) +route_map_result_t zebra_route_map_check(afi_t family, struct route_entry *re, + const struct prefix *p, + struct nexthop *nexthop, + struct zebra_vrf *zvrf) { struct route_map *rmap = NULL; char *rm_name; route_map_result_t ret = RMAP_PERMITMATCH; - struct nh_rmap_obj nh_obj; + struct zebra_rmap_obj rm_obj; - nh_obj.nexthop = nexthop; - nh_obj.vrf_id = nexthop->vrf_id; - nh_obj.source_protocol = rib_type; - nh_obj.instance = instance; - nh_obj.metric = 0; - nh_obj.tag = tag; + rm_obj.nexthop = nexthop; + rm_obj.re = re; - if (rib_type >= 0 && rib_type < ZEBRA_ROUTE_MAX) { - rm_name = PROTO_RM_NAME(zvrf, family, rib_type); - rmap = PROTO_RM_MAP(zvrf, family, rib_type); + if (re->type >= 0 && re->type < ZEBRA_ROUTE_MAX) { + rm_name = PROTO_RM_NAME(zvrf, family, re->type); + rmap = PROTO_RM_MAP(zvrf, family, re->type); if (rm_name && !rmap) return RMAP_DENYMATCH; @@ -1793,7 +1784,7 @@ zebra_route_map_check(afi_t family, int rib_type, uint8_t instance, return RMAP_DENYMATCH; } if (rmap) { - ret = route_map_apply(rmap, p, &nh_obj); + ret = route_map_apply(rmap, p, &rm_obj); } return (ret); @@ -1816,28 +1807,23 @@ void zebra_del_import_table_route_map(afi_t afi, uint32_t table) XFREE(MTYPE_ROUTE_MAP_NAME, zebra_import_table_routemap[afi][table]); } -route_map_result_t -zebra_import_table_route_map_check(int family, int re_type, uint8_t instance, - const struct prefix *p, - struct nexthop *nexthop, - vrf_id_t vrf_id, route_tag_t tag, - const char *rmap_name) +route_map_result_t zebra_import_table_route_map_check(int family, + struct route_entry *re, + const struct prefix *p, + struct nexthop *nexthop, + const char *rmap_name) { struct route_map *rmap = NULL; route_map_result_t ret = RMAP_DENYMATCH; - struct nh_rmap_obj nh_obj; + struct zebra_rmap_obj rm_obj; - nh_obj.nexthop = nexthop; - nh_obj.vrf_id = vrf_id; - nh_obj.source_protocol = re_type; - nh_obj.instance = instance; - nh_obj.metric = 0; - nh_obj.tag = tag; + rm_obj.nexthop = nexthop; + rm_obj.re = re; - if (re_type >= 0 && re_type < ZEBRA_ROUTE_MAX) + if (re->type >= 0 && re->type < ZEBRA_ROUTE_MAX) rmap = route_map_lookup_by_name(rmap_name); if (rmap) { - ret = route_map_apply(rmap, p, &nh_obj); + ret = route_map_apply(rmap, p, &rm_obj); } return (ret); @@ -1851,21 +1837,17 @@ route_map_result_t zebra_nht_route_map_check(afi_t afi, int client_proto, { struct route_map *rmap = NULL; route_map_result_t ret = RMAP_PERMITMATCH; - struct nh_rmap_obj nh_obj; + struct zebra_rmap_obj rm_obj; - nh_obj.nexthop = nexthop; - nh_obj.vrf_id = nexthop->vrf_id; - nh_obj.source_protocol = re->type; - nh_obj.instance = re->instance; - nh_obj.metric = re->metric; - nh_obj.tag = re->tag; + rm_obj.nexthop = nexthop; + rm_obj.re = re; if (client_proto >= 0 && client_proto < ZEBRA_ROUTE_MAX) rmap = NHT_RM_MAP(zvrf, afi, client_proto); if (!rmap && NHT_RM_MAP(zvrf, afi, ZEBRA_ROUTE_MAX)) rmap = NHT_RM_MAP(zvrf, afi, ZEBRA_ROUTE_MAX); if (rmap) - ret = route_map_apply(rmap, p, &nh_obj); + ret = route_map_apply(rmap, p, &rm_obj); return ret; } diff --git a/zebra/zebra_routemap.h b/zebra/zebra_routemap.h index f77735edc2..fceb53c841 100644 --- a/zebra/zebra_routemap.h +++ b/zebra/zebra_routemap.h @@ -21,19 +21,19 @@ extern void zebra_add_import_table_route_map(afi_t afi, const char *rmap_name, uint32_t table); extern void zebra_del_import_table_route_map(afi_t afi, uint32_t table); -extern route_map_result_t -zebra_import_table_route_map_check(int family, int rib_type, uint8_t instance, - const struct prefix *p, - struct nexthop *nexthop, vrf_id_t vrf_id, - route_tag_t tag, const char *rmap_name); -extern route_map_result_t -zebra_route_map_check(afi_t family, int rib_type, uint8_t instance, - const struct prefix *p, struct nexthop *nexthop, - struct zebra_vrf *zvrf, route_tag_t tag); -extern route_map_result_t -zebra_nht_route_map_check(afi_t afi, int client_proto, const struct prefix *p, - struct zebra_vrf *zvrf, struct route_entry *, - struct nexthop *nexthop); +extern route_map_result_t zebra_import_table_route_map_check( + int family, struct route_entry *re, const struct prefix *p, + struct nexthop *nexthop, const char *rmap_name); +extern route_map_result_t zebra_route_map_check(afi_t family, + struct route_entry *re, + const struct prefix *p, + struct nexthop *nexthop, + struct zebra_vrf *zvrf); +extern route_map_result_t zebra_nht_route_map_check(afi_t afi, int client_proto, + const struct prefix *p, + struct zebra_vrf *zvrf, + struct route_entry *re, + struct nexthop *nexthop); extern void zebra_routemap_vrf_delete(struct zebra_vrf *zvrf); diff --git a/zebra/zebra_router.c b/zebra/zebra_router.c index a477287913..3fd4e6eb1f 100644 --- a/zebra/zebra_router.c +++ b/zebra/zebra_router.c @@ -70,6 +70,26 @@ struct zebra_router_table *zebra_router_find_zrt(struct zebra_vrf *zvrf, return zrt; } +struct zebra_router_table *zebra_router_find_next_zrt(struct zebra_vrf *zvrf, + uint32_t tableid, + afi_t afi, safi_t safi) +{ + struct zebra_router_table finder; + struct zebra_router_table *zrt; + + memset(&finder, 0, sizeof(finder)); + finder.afi = afi; + finder.safi = safi; + finder.tableid = tableid; + finder.ns_id = zvrf->zns->ns_id; + zrt = RB_NFIND(zebra_router_table_head, &zrouter.tables, &finder); + if (zrt->afi == afi && zrt->safi == safi && zrt->tableid == tableid && + zrt->ns_id == finder.ns_id) + zrt = RB_NEXT(zebra_router_table_head, zrt); + + return zrt; +} + struct route_table *zebra_router_find_table(struct zebra_vrf *zvrf, uint32_t tableid, afi_t afi, safi_t safi) @@ -241,11 +261,15 @@ void zebra_router_terminate(void) zebra_pbr_ipset_entry_free); hash_clean_and_free(&zrouter.ipset_hash, zebra_pbr_ipset_free); hash_clean_and_free(&zrouter.iptable_hash, zebra_pbr_iptable_free); + hash_clean_and_free(&zrouter.filter_hash, (void (*)(void *)) zebra_tc_filter_free); + hash_clean_and_free(&zrouter.qdisc_hash, (void (*)(void *)) zebra_tc_qdisc_free); + hash_clean_and_free(&zrouter.class_hash, (void (*)(void *)) zebra_tc_class_free); #ifdef HAVE_SCRIPTING zebra_script_destroy(); #endif + zebra_vxlan_terminate(); /* OS-specific deinit */ kernel_router_terminate(); } @@ -255,10 +279,13 @@ bool zebra_router_notify_on_ack(void) return !zrouter.asic_offloaded || zrouter.notify_on_ack; } -void zebra_router_init(bool asic_offload, bool notify_on_ack) +void zebra_router_init(bool asic_offload, bool notify_on_ack, + bool v6_with_v4_nexthop) { zrouter.sequence_num = 0; + zrouter.protodown_r_bit = FRR_PROTODOWN_REASON_DEFAULT_BIT; + zrouter.allow_delete = false; zrouter.packets_to_process = ZEBRA_ZAPI_PACKETS_TO_PROCESS; @@ -292,10 +319,6 @@ void zebra_router_init(bool asic_offload, bool notify_on_ack) hash_create_size(8, zebra_nhg_id_key, zebra_nhg_hash_id_equal, "Zebra Router Nexthop Groups ID index"); - zrouter.rules_hash = - hash_create_size(8, zebra_pbr_rules_hash_key, - zebra_pbr_rules_hash_equal, "Rules Hash"); - zrouter.qdisc_hash = hash_create_size(8, zebra_tc_qdisc_hash_key, zebra_tc_qdisc_hash_equal, "TC (qdisc) Hash"); @@ -308,7 +331,7 @@ void zebra_router_init(bool asic_offload, bool notify_on_ack) zrouter.asic_offloaded = asic_offload; zrouter.notify_on_ack = notify_on_ack; - + zrouter.v6_with_v4_nexthop = v6_with_v4_nexthop; /* * If you start using asic_notification_nexthop_control * come talk to the FRR community about what you are doing @@ -320,6 +343,8 @@ void zebra_router_init(bool asic_offload, bool notify_on_ack) #endif zrouter.asic_notification_nexthop_control = false; + zrouter.nexthop_weight_scale_value = 255; + #ifdef HAVE_SCRIPTING zebra_script_init(); #endif diff --git a/zebra/zebra_router.h b/zebra/zebra_router.h index d81c7df589..3041707439 100644 --- a/zebra/zebra_router.h +++ b/zebra/zebra_router.h @@ -207,6 +207,9 @@ struct zebra_router { */ bool asic_offloaded; bool notify_on_ack; + bool v6_with_v4_nexthop; + + bool v6_rr_semantics; /* * If the asic is notifying us about successful nexthop @@ -228,6 +231,10 @@ struct zebra_router { /* Should we allow non FRR processes to delete our routes */ bool allow_delete; + + uint8_t protodown_r_bit; + + uint64_t nexthop_weight_scale_value; }; #define GRACEFUL_RESTART_TIME 60 @@ -235,13 +242,17 @@ struct zebra_router { extern struct zebra_router zrouter; extern uint32_t rcvbufsize; -extern void zebra_router_init(bool asic_offload, bool notify_on_ack); +extern void zebra_router_init(bool asic_offload, bool notify_on_ack, + bool v6_with_v4_nexthop); extern void zebra_router_cleanup(void); extern void zebra_router_terminate(void); extern struct zebra_router_table *zebra_router_find_zrt(struct zebra_vrf *zvrf, uint32_t tableid, afi_t afi, safi_t safi); +extern struct zebra_router_table * +zebra_router_find_next_zrt(struct zebra_vrf *zvrf, uint32_t tableid, afi_t afi, + safi_t safi); extern struct route_table *zebra_router_find_table(struct zebra_vrf *zvrf, uint32_t tableid, afi_t afi, safi_t safi); @@ -286,6 +297,32 @@ static inline bool zebra_router_in_shutdown(void) return atomic_load_explicit(&zrouter.in_shutdown, memory_order_relaxed); } +#define FRR_PROTODOWN_REASON_DEFAULT_BIT 7 +/* Protodown bit setter/getter + * + * Allow users to change the bit if it conflicts with another + * on their system. + */ +static inline void if_netlink_set_frr_protodown_r_bit(uint8_t bit) +{ + zrouter.protodown_r_bit = bit; +} + +static inline void if_netlink_unset_frr_protodown_r_bit(void) +{ + zrouter.protodown_r_bit = FRR_PROTODOWN_REASON_DEFAULT_BIT; +} + +static inline bool if_netlink_frr_protodown_r_bit_is_set(void) +{ + return (zrouter.protodown_r_bit != FRR_PROTODOWN_REASON_DEFAULT_BIT); +} + +static inline uint8_t if_netlink_get_frr_protodown_r_bit(void) +{ + return zrouter.protodown_r_bit; +} + /* zebra_northbound.c */ extern const struct frr_yang_module_info frr_zebra_info; diff --git a/zebra/zebra_script.c b/zebra/zebra_script.c index 3f107cb48d..6c34d12c64 100644 --- a/zebra/zebra_script.c +++ b/zebra/zebra_script.c @@ -396,6 +396,7 @@ void lua_pushzebra_dplane_ctx(lua_State *L, const struct zebra_dplane_ctx *ctx) lua_setfield(L, -2, "mtu"); } lua_setfield(L, -2, "gre"); + break; case DPLANE_OP_ADDR_INSTALL: case DPLANE_OP_ADDR_UNINSTALL: @@ -414,7 +415,9 @@ void lua_pushzebra_dplane_ctx(lua_State *L, const struct zebra_dplane_ctx *ctx) case DPLANE_OP_TC_FILTER_UPDATE: /* Not currently handled */ case DPLANE_OP_INTF_NETCONFIG: /*NYI*/ + case DPLANE_OP_SRV6_ENCAP_SRCADDR_SET: case DPLANE_OP_NONE: + case DPLANE_OP_STARTUP_STAGE: break; } /* Dispatch by op code */ } diff --git a/zebra/zebra_snmp.c b/zebra/zebra_snmp.c index e06733cb8c..1c6d58159e 100644 --- a/zebra/zebra_snmp.c +++ b/zebra/zebra_snmp.c @@ -223,6 +223,8 @@ static int proto_trans(int type) return 1; /* other */ case ZEBRA_ROUTE_CONNECT: return 2; /* local interface */ + case ZEBRA_ROUTE_LOCAL: + return 2; case ZEBRA_ROUTE_STATIC: return 3; /* static route */ case ZEBRA_ROUTE_RIP: @@ -353,7 +355,7 @@ static void get_fwtable_route_node(struct variable *v, oid objid[], if (policy) /* Not supported (yet?) */ return; for (*np = route_top(table); *np; *np = route_next(*np)) { - if (!in_addr_cmp(&(*np)->p.u.prefix, + if (!in_addr_cmp((uint8_t *)&(*np)->p.u.prefix4, (uint8_t *)&dest)) { RNODE_FOREACH_RE (*np, *re) { if (!in_addr_cmp((uint8_t *)&(*re)->nhe @@ -374,13 +376,14 @@ static void get_fwtable_route_node(struct variable *v, oid objid[], for (np2 = route_top(table); np2; np2 = route_next(np2)) { /* Check destination first */ - if (in_addr_cmp(&np2->p.u.prefix, (uint8_t *)&dest) > 0) + if (in_addr_cmp((uint8_t *)&np2->p.u.prefix4, + (uint8_t *)&dest) > 0) RNODE_FOREACH_RE (np2, re2) { check_replace(np2, re2, np, re); } - if (in_addr_cmp(&np2->p.u.prefix, (uint8_t *)&dest) - == 0) { /* have to look at each re individually */ + if (in_addr_cmp((uint8_t *)&np2->p.u.prefix4, (uint8_t *)&dest) == + 0) { /* have to look at each re individually */ RNODE_FOREACH_RE (np2, re2) { int proto2, policy2; diff --git a/zebra/zebra_srv6.c b/zebra/zebra_srv6.c index 94b93e5e8d..bb872ef91c 100644 --- a/zebra/zebra_srv6.c +++ b/zebra/zebra_srv6.c @@ -17,6 +17,7 @@ #include "zebra/zebra_router.h" #include "zebra/zebra_srv6.h" #include "zebra/zebra_errors.h" +#include "zebra/ge_netlink.h" #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -216,9 +217,10 @@ void zebra_notify_srv6_locator_delete(struct srv6_locator *locator) } } +struct zebra_srv6 srv6; + struct zebra_srv6 *zebra_srv6_get_default(void) { - static struct zebra_srv6 srv6; static bool first_execution = true; if (first_execution) { @@ -408,6 +410,40 @@ int release_daemon_srv6_locator_chunks(struct zserv *client) return count; } +void zebra_srv6_encap_src_addr_set(struct in6_addr *encap_src_addr) +{ + struct zebra_srv6 *srv6 = zebra_srv6_get_default(); + + if (!encap_src_addr) + return; + + memcpy(&srv6->encap_src_addr, encap_src_addr, sizeof(struct in6_addr)); +} + +void zebra_srv6_encap_src_addr_unset(void) +{ + struct zebra_srv6 *srv6 = zebra_srv6_get_default(); + + memset(&srv6->encap_src_addr, 0, sizeof(struct in6_addr)); +} + +void zebra_srv6_terminate(void) +{ + struct srv6_locator *locator; + + if (!srv6.locators) + return; + + while (listcount(srv6.locators)) { + locator = listnode_head(srv6.locators); + + listnode_delete(srv6.locators, locator); + srv6_locator_free(locator); + } + + list_delete(&srv6.locators); +} + void zebra_srv6_init(void) { hook_register(zserv_client_close, zebra_srv6_cleanup); diff --git a/zebra/zebra_srv6.h b/zebra/zebra_srv6.h index 51db83d6fb..21936c3323 100644 --- a/zebra/zebra_srv6.h +++ b/zebra/zebra_srv6.h @@ -19,6 +19,9 @@ /* SRv6 instance structure. */ struct zebra_srv6 { struct list *locators; + + /* Source address for SRv6 encapsulation */ + struct in6_addr encap_src_addr; }; /* declare hooks for the basic API, so that it can be specialized or served @@ -52,6 +55,7 @@ void zebra_notify_srv6_locator_add(struct srv6_locator *locator); void zebra_notify_srv6_locator_delete(struct srv6_locator *locator); extern void zebra_srv6_init(void); +extern void zebra_srv6_terminate(void); extern struct zebra_srv6 *zebra_srv6_get_default(void); extern bool zebra_srv6_is_enable(void); @@ -67,4 +71,7 @@ extern void srv6_manager_release_locator_chunk_call(struct zserv *client, extern int srv6_manager_client_disconnect_cb(struct zserv *client); extern int release_daemon_srv6_locator_chunks(struct zserv *client); +extern void zebra_srv6_encap_src_addr_set(struct in6_addr *src_addr); +extern void zebra_srv6_encap_src_addr_unset(void); + #endif /* _ZEBRA_SRV6_H */ diff --git a/zebra/zebra_srv6_vty.c b/zebra/zebra_srv6_vty.c index 3775d3dcdf..c5b8505992 100644 --- a/zebra/zebra_srv6_vty.c +++ b/zebra/zebra_srv6_vty.c @@ -61,6 +61,52 @@ static struct cmd_node srv6_loc_node = { .prompt = "%s(config-srv6-locator)# " }; +static struct cmd_node srv6_encap_node = { + .name = "srv6-encap", + .node = SRV6_ENCAP_NODE, + .parent_node = SRV6_NODE, + .prompt = "%s(config-srv6-encap)# " +}; + +DEFPY (show_srv6_manager, + show_srv6_manager_cmd, + "show segment-routing srv6 manager [json]", + SHOW_STR + "Segment Routing\n" + "Segment Routing SRv6\n" + "Verify SRv6 Manager\n" + JSON_STR) +{ + const bool uj = use_json(argc, argv); + struct zebra_srv6 *srv6 = zebra_srv6_get_default(); + json_object *json = NULL; + json_object *json_parameters = NULL; + json_object *json_encapsulation = NULL; + json_object *json_source_address = NULL; + + if (uj) { + json = json_object_new_object(); + json_parameters = json_object_new_object(); + json_object_object_add(json, "parameters", json_parameters); + json_encapsulation = json_object_new_object(); + json_object_object_add(json_parameters, "encapsulation", + json_encapsulation); + json_source_address = json_object_new_object(); + json_object_object_add(json_encapsulation, "sourceAddress", + json_source_address); + json_object_string_addf(json_source_address, "configured", + "%pI6", &srv6->encap_src_addr); + vty_json(vty, json); + } else { + vty_out(vty, "Parameters:\n"); + vty_out(vty, " Encapsulation:\n"); + vty_out(vty, " Source Address:\n"); + vty_out(vty, " Configured: %pI6\n", &srv6->encap_src_addr); + } + + return CMD_SUCCESS; +} + DEFUN (show_srv6_locator, show_srv6_locator_cmd, "show segment-routing srv6 locator [json]", @@ -391,6 +437,38 @@ DEFPY (locator_behavior, return CMD_SUCCESS; } +DEFUN_NOSH (srv6_encap, + srv6_encap_cmd, + "encapsulation", + "Segment Routing SRv6 encapsulation\n") +{ + vty->node = SRV6_ENCAP_NODE; + return CMD_SUCCESS; +} + +DEFPY (srv6_src_addr, + srv6_src_addr_cmd, + "source-address X:X::X:X$encap_src_addr", + "Segment Routing SRv6 source address\n" + "Specify source address for SRv6 encapsulation\n") +{ + zebra_srv6_encap_src_addr_set(&encap_src_addr); + dplane_srv6_encap_srcaddr_set(&encap_src_addr, NS_DEFAULT); + return CMD_SUCCESS; +} + +DEFPY (no_srv6_src_addr, + no_srv6_src_addr_cmd, + "no source-address [X:X::X:X$encap_src_addr]", + NO_STR + "Segment Routing SRv6 source address\n" + "Specify source address for SRv6 encapsulation\n") +{ + zebra_srv6_encap_src_addr_unset(); + dplane_srv6_encap_srcaddr_set(&in6addr_any, NS_DEFAULT); + return CMD_SUCCESS; +} + static int zebra_sr_config(struct vty *vty) { struct zebra_srv6 *srv6 = zebra_srv6_get_default(); @@ -402,6 +480,11 @@ static int zebra_sr_config(struct vty *vty) if (zebra_srv6_is_enable()) { vty_out(vty, "segment-routing\n"); vty_out(vty, " srv6\n"); + if (!IPV6_ADDR_SAME(&srv6->encap_src_addr, &in6addr_any)) { + vty_out(vty, " encapsulation\n"); + vty_out(vty, " source-address %pI6\n", + &srv6->encap_src_addr); + } vty_out(vty, " locators\n"); for (ALL_LIST_ELEMENTS_RO(srv6->locators, node, locator)) { inet_ntop(AF_INET6, &locator->prefix.prefix, @@ -444,24 +527,30 @@ void zebra_srv6_vty_init(void) install_node(&srv6_node); install_node(&srv6_locs_node); install_node(&srv6_loc_node); + install_node(&srv6_encap_node); install_default(SEGMENT_ROUTING_NODE); install_default(SRV6_NODE); install_default(SRV6_LOCS_NODE); install_default(SRV6_LOC_NODE); + install_default(SRV6_ENCAP_NODE); /* Command for change node */ install_element(CONFIG_NODE, &segment_routing_cmd); install_element(SEGMENT_ROUTING_NODE, &srv6_cmd); install_element(SEGMENT_ROUTING_NODE, &no_srv6_cmd); install_element(SRV6_NODE, &srv6_locators_cmd); + install_element(SRV6_NODE, &srv6_encap_cmd); install_element(SRV6_LOCS_NODE, &srv6_locator_cmd); install_element(SRV6_LOCS_NODE, &no_srv6_locator_cmd); /* Command for configuration */ install_element(SRV6_LOC_NODE, &locator_prefix_cmd); install_element(SRV6_LOC_NODE, &locator_behavior_cmd); + install_element(SRV6_ENCAP_NODE, &srv6_src_addr_cmd); + install_element(SRV6_ENCAP_NODE, &no_srv6_src_addr_cmd); /* Command for operation */ install_element(VIEW_NODE, &show_srv6_locator_cmd); install_element(VIEW_NODE, &show_srv6_locator_detail_cmd); + install_element(VIEW_NODE, &show_srv6_manager_cmd); } diff --git a/zebra/zebra_tc.c b/zebra/zebra_tc.c index 3d7e03b63e..1b5a57ae53 100644 --- a/zebra/zebra_tc.c +++ b/zebra/zebra_tc.c @@ -132,13 +132,18 @@ static void *tc_qdisc_alloc_intern(void *arg) return new; } +void zebra_tc_qdisc_free(struct zebra_tc_qdisc *qdisc) +{ + XFREE(MTYPE_TC_QDISC, qdisc); +} + static struct zebra_tc_qdisc *tc_qdisc_free(struct zebra_tc_qdisc *hash_data, bool free_data) { hash_release(zrouter.qdisc_hash, hash_data); if (free_data) { - XFREE(MTYPE_TC_QDISC, hash_data); + zebra_tc_qdisc_free(hash_data); return NULL; } @@ -178,7 +183,7 @@ void zebra_tc_qdisc_install(struct zebra_tc_qdisc *qdisc) new = hash_get(zrouter.qdisc_hash, qdisc, tc_qdisc_alloc_intern); (void)dplane_tc_qdisc_install(new); - XFREE(MTYPE_TC_QDISC, old); + zebra_tc_qdisc_free(old); } } else { new = hash_get(zrouter.qdisc_hash, qdisc, @@ -243,13 +248,18 @@ static void *tc_class_alloc_intern(void *arg) return new; } +void zebra_tc_class_free(struct zebra_tc_class *class) +{ + XFREE(MTYPE_TC_CLASS, class); +} + static struct zebra_tc_class *tc_class_free(struct zebra_tc_class *hash_data, bool free_data) { hash_release(zrouter.class_hash, hash_data); if (free_data) { - XFREE(MTYPE_TC_CLASS, hash_data); + zebra_tc_class_free(hash_data); return NULL; } @@ -353,13 +363,18 @@ bool zebra_tc_filter_hash_equal(const void *arg1, const void *arg2) return true; } +void zebra_tc_filter_free(struct zebra_tc_filter *filter) +{ + XFREE(MTYPE_TC_FILTER, filter); +} + static struct zebra_tc_filter *tc_filter_free(struct zebra_tc_filter *hash_data, bool free_data) { hash_release(zrouter.filter_hash, hash_data); if (free_data) { - XFREE(MTYPE_TC_FILTER, hash_data); + zebra_tc_filter_free(hash_data); return NULL; } diff --git a/zebra/zebra_tc.h b/zebra/zebra_tc.h index 335430c93d..814b453ec5 100644 --- a/zebra/zebra_tc.h +++ b/zebra/zebra_tc.h @@ -42,16 +42,19 @@ uint32_t zebra_tc_qdisc_hash_key(const void *arg); bool zebra_tc_qdisc_hash_equal(const void *arg1, const void *arg2); void zebra_tc_qdisc_install(struct zebra_tc_qdisc *qdisc); void zebra_tc_qdisc_uninstall(struct zebra_tc_qdisc *qdisc); +void zebra_tc_qdisc_free(struct zebra_tc_qdisc *qdisc); uint32_t zebra_tc_class_hash_key(const void *arg); bool zebra_tc_class_hash_equal(const void *arg1, const void *arg2); void zebra_tc_class_add(struct zebra_tc_class *class); void zebra_tc_class_delete(struct zebra_tc_class *class); +void zebra_tc_class_free(struct zebra_tc_class *class); const char *tc_filter_kind2str(uint32_t type); enum tc_qdisc_kind tc_filter_str2kind(const char *type); void zebra_tc_filter_add(struct zebra_tc_filter *filter); void zebra_tc_filter_delete(struct zebra_tc_filter *filter); +void zebra_tc_filter_free(struct zebra_tc_filter *filter); void zebra_tc_filters_free(void *arg); uint32_t zebra_tc_filter_hash_key(const void *arg); diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c index 3365cdcdba..92982f25c8 100644 --- a/zebra/zebra_vrf.c +++ b/zebra/zebra_vrf.c @@ -195,7 +195,7 @@ static int zebra_vrf_disable(struct vrf *vrf) /* Cleanup Vxlan, MPLS and PW tables. */ zebra_vxlan_cleanup_tables(zvrf); zebra_mpls_cleanup_tables(zvrf); - zebra_pw_exit(zvrf); + zebra_pw_exit_vrf(zvrf); /* Remove link-local IPv4 addresses created for BGP unnumbered peering. */ @@ -265,6 +265,12 @@ static int zebra_vrf_delete(struct vrf *vrf) otable_fini(&zvrf->other_tables); XFREE(MTYPE_ZEBRA_VRF, zvrf); + + if (vrf->ns_ctxt) { + ns_delete(vrf->ns_ctxt); + vrf->ns_ctxt = NULL; + } + vrf->info = NULL; return 0; @@ -370,12 +376,45 @@ struct zebra_vrf *zebra_vrf_alloc(struct vrf *vrf) zebra_vxlan_init_tables(zvrf); zebra_mpls_init_tables(zvrf); - zebra_pw_init(zvrf); - zvrf->table_id = RT_TABLE_MAIN; + zebra_pw_init_vrf(zvrf); + zvrf->table_id = rt_table_main_id; /* by default table ID is default one */ + + if (DFLT_ZEBRA_IP_NHT_RESOLVE_VIA_DEFAULT) { + zvrf->zebra_rnh_ip_default_route = true; + zvrf->zebra_rnh_ipv6_default_route = true; + } + return zvrf; } +/* + * Pending: create an efficient table_id (in a tree/hash) based lookup) + */ +vrf_id_t zebra_vrf_lookup_by_table(uint32_t table_id, ns_id_t ns_id) +{ + struct vrf *vrf; + struct zebra_vrf *zvrf; + + RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) { + zvrf = vrf->info; + if (zvrf == NULL) + continue; + /* case vrf with netns : match the netnsid */ + if (vrf_is_backend_netns()) { + if (ns_id == zvrf_id(zvrf)) + return zvrf_id(zvrf); + } else { + /* VRF is VRF_BACKEND_VRF_LITE */ + if (zvrf->table_id != table_id) + continue; + return zvrf_id(zvrf); + } + } + + return VRF_DEFAULT; +} + /* Lookup VRF by identifier. */ struct zebra_vrf *zebra_vrf_lookup_by_id(vrf_id_t vrf_id) { @@ -429,11 +468,20 @@ static int vrf_config_write(struct vty *vty) zvrf->l3vni) ? " prefix-routes-only" : ""); - if (zvrf->zebra_rnh_ip_default_route) - vty_out(vty, "ip nht resolve-via-default\n"); - if (zvrf->zebra_rnh_ipv6_default_route) - vty_out(vty, "ipv6 nht resolve-via-default\n"); + if (zvrf->zebra_rnh_ip_default_route != + SAVE_ZEBRA_IP_NHT_RESOLVE_VIA_DEFAULT) + vty_out(vty, "%sip nht resolve-via-default\n", + zvrf->zebra_rnh_ip_default_route + ? "" + : "no "); + + if (zvrf->zebra_rnh_ipv6_default_route != + SAVE_ZEBRA_IP_NHT_RESOLVE_VIA_DEFAULT) + vty_out(vty, "%sipv6 nht resolve-via-default\n", + zvrf->zebra_rnh_ipv6_default_route + ? "" + : "no "); if (zvrf->tbl_mgr && (zvrf->tbl_mgr->start || zvrf->tbl_mgr->end)) @@ -449,11 +497,19 @@ static int vrf_config_write(struct vty *vty) ? " prefix-routes-only" : ""); zebra_ns_config_write(vty, (struct ns *)vrf->ns_ctxt); - if (zvrf->zebra_rnh_ip_default_route) - vty_out(vty, " ip nht resolve-via-default\n"); - - if (zvrf->zebra_rnh_ipv6_default_route) - vty_out(vty, " ipv6 nht resolve-via-default\n"); + if (zvrf->zebra_rnh_ip_default_route != + SAVE_ZEBRA_IP_NHT_RESOLVE_VIA_DEFAULT) + vty_out(vty, " %sip nht resolve-via-default\n", + zvrf->zebra_rnh_ip_default_route + ? "" + : "no "); + + if (zvrf->zebra_rnh_ipv6_default_route != + SAVE_ZEBRA_IP_NHT_RESOLVE_VIA_DEFAULT) + vty_out(vty, " %sipv6 nht resolve-via-default\n", + zvrf->zebra_rnh_ipv6_default_route + ? "" + : "no "); if (zvrf->tbl_mgr && vrf_is_backend_netns() && (zvrf->tbl_mgr->start || zvrf->tbl_mgr->end)) diff --git a/zebra/zebra_vrf.h b/zebra/zebra_vrf.h index b23b728261..5cbfab1ddc 100644 --- a/zebra/zebra_vrf.h +++ b/zebra/zebra_vrf.h @@ -13,11 +13,17 @@ #include <zebra/zebra_pw.h> #include <zebra/rtadv.h> #include <lib/vxlan.h> +#include "defaults.h" #ifdef __cplusplus extern "C" { #endif +FRR_CFG_DEFAULT_BOOL(ZEBRA_IP_NHT_RESOLVE_VIA_DEFAULT, + { .val_bool = true, .match_profile = "traditional", }, + { .val_bool = false }, +); + /* MPLS (Segment Routing) global block */ struct mpls_srgb { uint32_t start_label; @@ -237,6 +243,7 @@ extern struct route_table *zebra_vrf_get_table_with_table_id(afi_t afi, extern void zebra_vrf_update_all(struct zserv *client); extern struct zebra_vrf *zebra_vrf_lookup_by_id(vrf_id_t vrf_id); extern struct zebra_vrf *zebra_vrf_lookup_by_name(const char *); +extern vrf_id_t zebra_vrf_lookup_by_table(uint32_t table_id, ns_id_t ns_id); extern struct zebra_vrf *zebra_vrf_alloc(struct vrf *vrf); extern struct route_table *zebra_vrf_table(afi_t, safi_t, vrf_id_t); diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index d100dc0e69..b778b39508 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -20,6 +20,7 @@ #include "vxlan.h" #include "termtable.h" #include "affinitymap.h" +#include "frrdistance.h" #include "zebra/zebra_router.h" #include "zebra/zserv.h" @@ -764,9 +765,10 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn, } /* Distance and metric display. */ - if (((re->type == ZEBRA_ROUTE_CONNECT) && + if (((re->type == ZEBRA_ROUTE_CONNECT || + re->type == ZEBRA_ROUTE_LOCAL) && (re->distance || re->metric)) || - (re->type != ZEBRA_ROUTE_CONNECT)) + (re->type != ZEBRA_ROUTE_CONNECT && re->type != ZEBRA_ROUTE_LOCAL)) len += vty_out(vty, " [%u/%u]", re->distance, re->metric); @@ -962,8 +964,12 @@ static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf, } } + /* + * This is an extremely expensive operation at scale + * and non-pretty reduces memory footprint significantly. + */ if (use_json) - vty_json(vty, json); + vty_json_no_pretty(vty, json); } static void do_show_ip_route_all(struct vty *vty, struct zebra_vrf *zvrf, @@ -1063,16 +1069,22 @@ DEFPY (show_ip_nht, json_object *json = NULL; json_object *json_vrf = NULL; json_object *json_nexthop = NULL; + struct zebra_vrf *zvrf; + bool resolve_via_default = false; if (uj) json = json_object_new_object(); if (vrf_all) { struct vrf *vrf; - struct zebra_vrf *zvrf; RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { if ((zvrf = vrf->info) != NULL) { + resolve_via_default = + (afi == AFI_IP) + ? zvrf->zebra_rnh_ip_default_route + : zvrf->zebra_rnh_ipv6_default_route; + if (uj) { json_vrf = json_object_new_object(); json_nexthop = json_object_new_object(); @@ -1084,9 +1096,16 @@ DEFPY (show_ip_nht, ? "ipv4" : "ipv6", json_nexthop); + json_object_boolean_add(json_nexthop, + "resolveViaDefault", + resolve_via_default); } else { vty_out(vty, "\nVRF %s:\n", zvrf_name(zvrf)); + vty_out(vty, + " Resolve via default: %s\n", + resolve_via_default ? "on" + : "off"); } zebra_print_rnh_table(zvrf_id(zvrf), afi, safi, vty, NULL, json_nexthop); @@ -1111,6 +1130,11 @@ DEFPY (show_ip_nht, } } + zvrf = zebra_vrf_lookup_by_id(vrf_id); + resolve_via_default = (afi == AFI_IP) + ? zvrf->zebra_rnh_ip_default_route + : zvrf->zebra_rnh_ipv6_default_route; + if (uj) { json_vrf = json_object_new_object(); json_nexthop = json_object_new_object(); @@ -1122,6 +1146,13 @@ DEFPY (show_ip_nht, json_object_object_add(json_vrf, (afi == AFI_IP) ? "ipv4" : "ipv6", json_nexthop); + + json_object_boolean_add(json_nexthop, "resolveViaDefault", + resolve_via_default); + } else { + vty_out(vty, "VRF %s:\n", zvrf_name(zvrf)); + vty_out(vty, " Resolve via default: %s\n", + resolve_via_default ? "on" : "off"); } zebra_print_rnh_table(vrf_id, afi, safi, vty, p, json_nexthop); @@ -2222,7 +2253,8 @@ static void show_ip_route_dump_vty(struct vty *vty, struct route_table *table) vrf_id_to_name(re->vrf_id)); vty_out(vty, " flags: %u\n", re->flags); - if (re->type != ZEBRA_ROUTE_CONNECT) { + if (re->type != ZEBRA_ROUTE_CONNECT && + re->type != ZEBRA_ROUTE_LOCAL) { vty_out(vty, " distance: %u\n", re->distance); vty_out(vty, " metric: %u\n", re->metric); } @@ -2703,13 +2735,8 @@ DEFUN (default_vrf_vni_mapping, "Prefix routes only \n") { char xpath[XPATH_MAXLEN]; - struct zebra_vrf *zvrf = NULL; int filter = 0; - zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - if (!zvrf) - return CMD_WARNING; - if (argc == 3) filter = 1; @@ -2746,8 +2773,6 @@ DEFUN (no_default_vrf_vni_mapping, struct zebra_vrf *zvrf = NULL; zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); - if (!zvrf) - return CMD_WARNING; if (argc == 4) filter = 1; @@ -4006,6 +4031,17 @@ static int config_write_protocol(struct vty *vty) return 1; } +static inline bool zebra_vty_v6_rr_semantics_used(void) +{ + if (zebra_nhg_kernel_nexthops_enabled()) + return true; + + if (zrouter.v6_rr_semantics) + return true; + + return false; +} + DEFUN (show_zebra, show_zebra_cmd, "show zebra", @@ -4025,7 +4061,9 @@ DEFUN (show_zebra, ttable_add_row(table, "MPLS|%s", mpls_enabled ? "On" : "Off"); ttable_add_row(table, "EVPN|%s", is_evpn_enabled() ? "On" : "Off"); ttable_add_row(table, "Kernel socket buffer size|%d", rcvbufsize); - + ttable_add_row(table, "v6 Route Replace Semantics|%s", + zebra_vty_v6_rr_semantics_used() ? "Replace" + : "Delete then Add"); #ifdef GNU_LINUX if (!vrf_is_backend_netns()) @@ -4036,6 +4074,9 @@ DEFUN (show_zebra, ttable_add_row(table, "VRF|Not Available"); #endif + ttable_add_row(table, "v6 with v4 nexthop|%s", + zrouter.v6_with_v4_nexthop ? "Used" : "Unavaliable"); + ttable_add_row(table, "ASIC offload|%s", zrouter.asic_offloaded ? "Used" : "Unavailable"); diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c index babd93ab20..7d0c82a437 100644 --- a/zebra/zebra_vxlan.c +++ b/zebra/zebra_vxlan.c @@ -82,7 +82,7 @@ static int zl3vni_nh_uninstall(struct zebra_l3vni *zl3vni, struct zebra_neigh *n); static struct zebra_neigh *svd_nh_add(const struct ipaddr *vtep_ip, const struct ethaddr *rmac); -static int svd_nh_del(struct zebra_neigh *n); +static void svd_nh_del(struct zebra_neigh *n); static int svd_nh_install(struct zebra_l3vni *zl3vni, struct zebra_neigh *n); static int svd_nh_uninstall(struct zebra_l3vni *zl3vni, struct zebra_neigh *n); @@ -194,7 +194,7 @@ static int l3vni_rmac_nh_list_cmp(void *p1, void *p2) const struct ipaddr *vtep_ip1 = p1; const struct ipaddr *vtep_ip2 = p2; - return !ipaddr_cmp(vtep_ip1, vtep_ip2); + return ipaddr_cmp(vtep_ip1, vtep_ip2); } static void l3vni_rmac_nh_free(struct ipaddr *vtep_ip) @@ -308,7 +308,7 @@ static void zevpn_print_neigh_hash_all_evpn_detail(struct hash_bucket *bucket, zevpn = (struct zebra_evpn *)bucket->data; if (!zevpn) { if (json) - vty_out(vty, "{}\n"); + vty_json_empty(vty, json); return; } num_neigh = hashcount(zevpn->neigh_table); @@ -515,7 +515,7 @@ static void zevpn_print_mac_hash_all_evpn_detail(struct hash_bucket *bucket, zevpn = (struct zebra_evpn *)bucket->data; if (!zevpn) { if (json) - vty_out(vty, "{}\n"); + vty_json_empty(vty, json); return; } wctx->zevpn = zevpn; @@ -891,6 +891,7 @@ static int zvni_map_to_svi_ns(struct ns *ns, if (vl->vid == in_param->vid) { *p_ifp = tmp_if; + route_unlock_node(rn); return NS_WALK_STOP; } } @@ -1589,17 +1590,24 @@ static struct zebra_neigh *svd_nh_add(const struct ipaddr *ip, /* * Del Single VXlan Device neighbor entry. */ -static int svd_nh_del(struct zebra_neigh *n) +static void svd_nh_del(struct zebra_neigh *n) { if (n->refcnt > 0) - return -1; + return; hash_release(svd_nh_table, n); XFREE(MTYPE_L3NEIGH, n); +} - return 0; +static void svd_nh_del_terminate(void *ptr) +{ + struct zebra_neigh *n = ptr; + + n->refcnt = 0; + svd_nh_del(n); } + /* * Common code to install remote nh as neigh into the kernel. */ @@ -2005,6 +2013,7 @@ static int zl3vni_map_to_vxlan_if_ns(struct ns *ns, zl3vni->local_vtep_ip = zif->l2info.vxl.vtep_ip; *_pifp = (void *)ifp; + route_unlock_node(rn); return NS_WALK_STOP; } @@ -2116,6 +2125,7 @@ static int zl3vni_from_svi_ns(struct ns *ns, void *_in_param, void **_p_zl3vni) zif, in_param->br_if); if (vni_id) { found = 1; + route_unlock_node(rn); break; } } @@ -2255,14 +2265,13 @@ static int zl3vni_send_add_to_client(struct zebra_l3vni *zl3vni) stream_putw_at(s, 0, stream_get_endp(s)); if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug( - "Send L3_VNI_ADD %u VRF %s RMAC %pEA VRR %pEA local-ip %pI4 filter %s to %s", - zl3vni->vni, vrf_id_to_name(zl3vni_vrf_id(zl3vni)), - &svi_rmac, &vrr_rmac, &zl3vni->local_vtep_ip, - CHECK_FLAG(zl3vni->filter, PREFIX_ROUTES_ONLY) - ? "prefix-routes-only" - : "none", - zebra_route_string(client->proto)); + zlog_debug("Send L3VNI ADD %u VRF %s RMAC %pEA VRR %pEA local-ip %pI4 filter %s to %s", + zl3vni->vni, vrf_id_to_name(zl3vni_vrf_id(zl3vni)), + &svi_rmac, &vrr_rmac, &zl3vni->local_vtep_ip, + CHECK_FLAG(zl3vni->filter, PREFIX_ROUTES_ONLY) + ? "prefix-routes-only" + : "none", + zebra_route_string(client->proto)); client->l3vniadd_cnt++; return zserv_send_message(client, s); @@ -2290,7 +2299,7 @@ static int zl3vni_send_del_to_client(struct zebra_l3vni *zl3vni) stream_putw_at(s, 0, stream_get_endp(s)); if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("Send L3_VNI_DEL %u VRF %s to %s", zl3vni->vni, + zlog_debug("Send L3VNI DEL %u VRF %s to %s", zl3vni->vni, vrf_id_to_name(zl3vni_vrf_id(zl3vni)), zebra_route_string(client->proto)); @@ -2402,6 +2411,7 @@ static int zebra_vxlan_handle_vni_transition(struct zebra_vrf *zvrf, vni_t vni, vnip = zebra_vxlan_if_vni_find(zif, vni); if (vnip) { found = true; + route_unlock_node(rn); break; } } @@ -2586,14 +2596,15 @@ void zebra_vxlan_print_specific_rmac_l3vni(struct vty *vty, vni_t l3vni, json = json_object_new_object(); if (!is_evpn_enabled()) { - vty_json(vty, json); + if (use_json) + vty_json_empty(vty, json); return; } zl3vni = zl3vni_lookup(l3vni); if (!zl3vni) { if (use_json) - vty_json(vty, json); + vty_json_empty(vty, json); else vty_out(vty, "%% L3-VNI %u doesn't exist\n", l3vni); return; @@ -2627,14 +2638,15 @@ void zebra_vxlan_print_rmacs_l3vni(struct vty *vty, vni_t l3vni, bool use_json) json = json_object_new_object(); if (!is_evpn_enabled()) { - vty_json(vty, json); + if (use_json) + vty_json_empty(vty, json); return; } zl3vni = zl3vni_lookup(l3vni); if (!zl3vni) { if (use_json) - vty_json(vty, json); + vty_json_empty(vty, json); else vty_out(vty, "%% L3-VNI %u does not exist\n", l3vni); return; @@ -2668,7 +2680,8 @@ void zebra_vxlan_print_rmacs_all_l3vni(struct vty *vty, bool use_json) json = json_object_new_object(); if (!is_evpn_enabled()) { - vty_json(vty, json); + if (use_json) + vty_json_empty(vty, json); return; } @@ -2694,7 +2707,8 @@ void zebra_vxlan_print_specific_nh_l3vni(struct vty *vty, vni_t l3vni, json = json_object_new_object(); if (!is_evpn_enabled()) { - vty_json(vty, json); + if (use_json) + vty_json_empty(vty, json); return; } @@ -2705,7 +2719,7 @@ void zebra_vxlan_print_specific_nh_l3vni(struct vty *vty, vni_t l3vni, zl3vni = zl3vni_lookup(l3vni); if (!zl3vni) { if (use_json) - vty_out(vty, "{}\n"); + vty_json(vty, json); else vty_out(vty, "%% L3-VNI %u does not exist\n", l3vni); @@ -2717,7 +2731,7 @@ void zebra_vxlan_print_specific_nh_l3vni(struct vty *vty, vni_t l3vni, if (!n) { if (use_json) - vty_out(vty, "{}\n"); + vty_json_empty(vty, json); else vty_out(vty, "%% Requested next-hop not present for L3-VNI %u\n", @@ -2738,13 +2752,16 @@ static void l3vni_print_nh_table(struct hash *nh_table, struct vty *vty, struct nh_walk_ctx wctx; json_object *json = NULL; - num_nh = hashcount(nh_table); - if (!num_nh) - return; - if (use_json) json = json_object_new_object(); + num_nh = hashcount(nh_table); + if (!num_nh) { + if (use_json) + vty_json_empty(vty, json); + return; + } + wctx.vty = vty; wctx.json = json; if (!use_json) { @@ -2766,14 +2783,14 @@ void zebra_vxlan_print_nh_l3vni(struct vty *vty, vni_t l3vni, bool use_json) if (!is_evpn_enabled()) { if (use_json) - vty_out(vty, "{}\n"); + vty_json_empty(vty, NULL); return; } zl3vni = zl3vni_lookup(l3vni); if (!zl3vni) { if (use_json) - vty_out(vty, "{}\n"); + vty_json_empty(vty, NULL); else vty_out(vty, "%% L3-VNI %u does not exist\n", l3vni); return; @@ -2786,7 +2803,7 @@ void zebra_vxlan_print_nh_svd(struct vty *vty, bool use_json) { if (!is_evpn_enabled()) { if (use_json) - vty_out(vty, "{}\n"); + vty_json_empty(vty, NULL); return; } @@ -2802,7 +2819,8 @@ void zebra_vxlan_print_nh_all_l3vni(struct vty *vty, bool use_json) json = json_object_new_object(); if (!is_evpn_enabled()) { - vty_json(vty, json); + if (use_json) + vty_json_empty(vty, json); return; } @@ -2830,14 +2848,15 @@ void zebra_vxlan_print_l3vni(struct vty *vty, vni_t vni, bool use_json) json = json_object_new_object(); if (!is_evpn_enabled()) { - vty_json(vty, json); + if (use_json) + vty_json_empty(vty, json); return; } zl3vni = zl3vni_lookup(vni); if (!zl3vni) { if (use_json) - vty_json(vty, json); + vty_json_empty(vty, json); else vty_out(vty, "%% VNI %u does not exist\n", vni); return; @@ -2901,14 +2920,15 @@ void zebra_vxlan_print_neigh_vni(struct vty *vty, struct zebra_vrf *zvrf, json = json_object_new_object(); if (!is_evpn_enabled()) { - vty_json(vty, json); + if (use_json) + vty_json_empty(vty, json); return; } zevpn = zebra_evpn_lookup(vni); if (!zevpn) { if (use_json) - vty_json(vty, json); + vty_json_empty(vty, json); else vty_out(vty, "%% VNI %u does not exist\n", vni); return; @@ -2955,7 +2975,8 @@ void zebra_vxlan_print_neigh_all_vni(struct vty *vty, struct zebra_vrf *zvrf, json = json_object_new_object(); if (!is_evpn_enabled()) { - vty_json(vty, json); + if (use_json) + vty_json_empty(vty, json); return; } @@ -2985,7 +3006,8 @@ void zebra_vxlan_print_neigh_all_vni_detail(struct vty *vty, json = json_object_new_object(); if (!is_evpn_enabled()) { - vty_json(vty, json); + if (use_json) + vty_json_empty(vty, json); return; } @@ -3016,14 +3038,15 @@ void zebra_vxlan_print_specific_neigh_vni(struct vty *vty, json = json_object_new_object(); if (!is_evpn_enabled()) { - vty_json(vty, json); + if (use_json) + vty_json_empty(vty, json); return; } zevpn = zebra_evpn_lookup(vni); if (!zevpn) { if (use_json) - vty_json(vty, json); + vty_json_empty(vty, json); else vty_out(vty, "%% VNI %u does not exist\n", vni); return; @@ -3060,14 +3083,15 @@ void zebra_vxlan_print_neigh_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf, json = json_object_new_object(); if (!is_evpn_enabled()) { - vty_json(vty, json); + if (use_json) + vty_json_empty(vty, json); return; } zevpn = zebra_evpn_lookup(vni); if (!zevpn) { if (use_json) - vty_json(vty, json); + vty_json_empty(vty, json); else vty_out(vty, "%% VNI %u does not exist\n", vni); return; @@ -3109,14 +3133,15 @@ void zebra_vxlan_print_neigh_vni_dad(struct vty *vty, json = json_object_new_object(); if (!is_evpn_enabled()) { - vty_json(vty, json); + if (use_json) + vty_json_empty(vty, json); return; } zevpn = zebra_evpn_lookup(vni); if (!zevpn) { if (use_json) - vty_json(vty, json); + vty_json_empty(vty, json); else vty_out(vty, "%% VNI %u does not exist\n", vni); return; @@ -3173,21 +3198,24 @@ void zebra_vxlan_print_macs_vni(struct vty *vty, struct zebra_vrf *zvrf, if (!is_evpn_enabled()) { if (use_json) - vty_out(vty, "{}\n"); + vty_json_empty(vty, NULL); return; } zevpn = zebra_evpn_lookup(vni); if (!zevpn) { if (use_json) - vty_out(vty, "{}\n"); + vty_json_empty(vty, NULL); else vty_out(vty, "%% VNI %u does not exist\n", vni); return; } num_macs = num_valid_macs(zevpn); - if (!num_macs) + if (!num_macs) { + if (use_json) + vty_json_empty(vty, NULL); return; + } if (use_json) { json = json_object_new_object(); @@ -3225,7 +3253,11 @@ void zebra_vxlan_print_macs_vni(struct vty *vty, struct zebra_vrf *zvrf, if (use_json) { json_object_object_add(json, "macs", json_mac); - vty_json(vty, json); + /* + * This is an extremely expensive operation at scale + * and non-pretty reduces memory footprint significantly. + */ + vty_json_no_pretty(vty, json); } } @@ -3242,7 +3274,8 @@ void zebra_vxlan_print_macs_all_vni(struct vty *vty, struct zebra_vrf *zvrf, json = json_object_new_object(); if (!is_evpn_enabled()) { - vty_json(vty, json); + if (use_json) + vty_json_empty(vty, json); return; } @@ -3270,7 +3303,8 @@ void zebra_vxlan_print_macs_all_vni_detail(struct vty *vty, json = json_object_new_object(); if (!is_evpn_enabled()) { - vty_json(vty, json); + if (use_json) + vty_json_empty(vty, json); return; } @@ -3299,7 +3333,8 @@ void zebra_vxlan_print_macs_all_vni_vtep(struct vty *vty, json = json_object_new_object(); if (!is_evpn_enabled()) { - vty_json(vty, json); + if (use_json) + vty_json_empty(vty, json); return; } @@ -3329,7 +3364,8 @@ void zebra_vxlan_print_specific_mac_vni(struct vty *vty, struct zebra_vrf *zvrf, json = json_object_new_object(); if (!is_evpn_enabled()) { - vty_json(vty, json); + if (use_json) + vty_json_empty(vty, json); return; } @@ -3369,22 +3405,34 @@ void zebra_vxlan_print_macs_vni_dad(struct vty *vty, json_object *json = NULL; json_object *json_mac = NULL; - if (!is_evpn_enabled()) + if (!is_evpn_enabled()) { + if (use_json) + vty_json_empty(vty, NULL); return; + } zevpn = zebra_evpn_lookup(vni); if (!zevpn) { - vty_out(vty, "%% VNI %u does not exist\n", vni); + if (use_json) + vty_json_empty(vty, NULL); + else + vty_out(vty, "%% VNI %u does not exist\n", vni); return; } num_macs = num_valid_macs(zevpn); - if (!num_macs) + if (!num_macs) { + if (use_json) + vty_json_empty(vty, NULL); return; + } num_macs = num_dup_detected_macs(zevpn); - if (!num_macs) + if (!num_macs) { + if (use_json) + vty_json_empty(vty, NULL); return; + } if (use_json) { json = json_object_new_object(); @@ -3719,21 +3767,25 @@ void zebra_vxlan_print_macs_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf, json_object *json_mac = NULL; if (!is_evpn_enabled()) { - vty_json(vty, json); + if (use_json) + vty_json_empty(vty, NULL); return; } zevpn = zebra_evpn_lookup(vni); if (!zevpn) { if (use_json) - vty_out(vty, "{}\n"); + vty_json_empty(vty, NULL); else vty_out(vty, "%% VNI %u does not exist\n", vni); return; } num_macs = num_valid_macs(zevpn); - if (!num_macs) + if (!num_macs) { + if (use_json) + vty_json_empty(vty, NULL); return; + } if (use_json) { json = json_object_new_object(); @@ -3777,7 +3829,8 @@ void zebra_vxlan_print_vni(struct vty *vty, struct zebra_vrf *zvrf, vni_t vni, json = json_object_new_object(); if (!is_evpn_enabled()) { - vty_json(vty, json); + if (use_json) + vty_json_empty(vty, json); return; } @@ -3821,7 +3874,8 @@ void zebra_vxlan_print_evpn(struct vty *vty, bool uj) json = json_object_new_object(); if (!is_evpn_enabled()) { - vty_json(vty, json); + if (uj) + vty_json(vty, json); return; } @@ -3898,7 +3952,8 @@ void zebra_vxlan_print_vnis(struct vty *vty, struct zebra_vrf *zvrf, json = json_object_new_object(); if (!is_evpn_enabled()) { - vty_json(vty, json); + if (use_json) + vty_json_empty(vty, json); return; } @@ -3982,7 +4037,7 @@ void zebra_vxlan_print_vnis_detail(struct vty *vty, struct zebra_vrf *zvrf, if (!is_evpn_enabled()) { if (use_json) - vty_out(vty, "{}\n"); + vty_json_empty(vty, NULL); return; } @@ -4010,8 +4065,12 @@ void zebra_vxlan_print_vnis_detail(struct vty *vty, struct zebra_vrf *zvrf, void *))zl3vni_print_hash_detail, &zes); + /* + * This is an extremely expensive operation at scale + * and non-pretty reduces memory footprint significantly. + */ if (use_json) - vty_json(vty, json_array); + vty_json_no_pretty(vty, json_array); } /* @@ -5760,6 +5819,11 @@ void zebra_vxlan_init(void) zebra_evpn_mh_init(); } +void zebra_vxlan_terminate(void) +{ + hash_clean_and_free(&svd_nh_table, svd_nh_del_terminate); +} + /* free l3vni table */ void zebra_vxlan_disable(void) { @@ -5937,8 +6001,6 @@ static void zebra_vxlan_sg_del(struct zebra_vxlan_sg *vxlan_sg) struct zebra_vrf *zvrf; zvrf = vrf_info_lookup(VRF_DEFAULT); - if (!zvrf) - return; /* On SG entry deletion remove the reference to its parent XG * entry @@ -6008,8 +6070,6 @@ void zebra_vxlan_sg_deref(struct in_addr local_vtep_ip, return; zvrf = vrf_info_lookup(VRF_DEFAULT); - if (!zvrf) - return; zebra_vxlan_sg_do_deref(zvrf, local_vtep_ip, mcast_grp); } @@ -6023,8 +6083,7 @@ void zebra_vxlan_sg_ref(struct in_addr local_vtep_ip, struct in_addr mcast_grp) return; zvrf = vrf_info_lookup(VRF_DEFAULT); - if (!zvrf) - return; + zebra_vxlan_sg_do_ref(zvrf, local_vtep_ip, mcast_grp); } diff --git a/zebra/zebra_vxlan.h b/zebra/zebra_vxlan.h index 98c2767eb2..5785e0b3c3 100644 --- a/zebra/zebra_vxlan.h +++ b/zebra/zebra_vxlan.h @@ -185,6 +185,7 @@ extern void zebra_vxlan_init_tables(struct zebra_vrf *zvrf); extern void zebra_vxlan_close_tables(struct zebra_vrf *); extern void zebra_vxlan_cleanup_tables(struct zebra_vrf *); extern void zebra_vxlan_init(void); +extern void zebra_vxlan_terminate(void); extern void zebra_vxlan_disable(void); extern void zebra_vxlan_evpn_vrf_route_add(vrf_id_t vrf_id, const struct ethaddr *rmac, diff --git a/zebra/zserv.c b/zebra/zserv.c index 6abd49310c..1d3989dc73 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -181,9 +181,10 @@ void zserv_log_message(const char *errmsg, struct stream *msg, */ static void zserv_client_fail(struct zserv *client) { - flog_warn(EC_ZEBRA_CLIENT_IO_ERROR, - "Client '%s' encountered an error and is shutting down.", - zebra_route_string(client->proto)); + flog_warn( + EC_ZEBRA_CLIENT_IO_ERROR, + "Client '%s' (session id %d) encountered an error and is shutting down.", + zebra_route_string(client->proto), client->session_id); atomic_store_explicit(&client->pthread->running, false, memory_order_relaxed); @@ -507,8 +508,6 @@ static void zserv_process_messages(struct event *thread) stream_fifo_push(cache, msg); } - msg = NULL; - /* Need to reschedule processing work if there are still * packets in the fifo. */ @@ -583,23 +582,27 @@ static void zserv_client_free(struct zserv *client) /* Close file descriptor. */ if (client->sock) { - unsigned long nroutes; - unsigned long nnhgs; + unsigned long nroutes = 0; + unsigned long nnhgs = 0; close(client->sock); if (DYNAMIC_CLIENT_GR_DISABLED(client)) { - zebra_mpls_client_cleanup_vrf_label(client->proto); + if (!client->synchronous) { + zebra_mpls_client_cleanup_vrf_label( + client->proto); - nroutes = rib_score_proto(client->proto, - client->instance); + nroutes = rib_score_proto(client->proto, + client->instance); + } zlog_notice( "client %d disconnected %lu %s routes removed from the rib", client->sock, nroutes, zebra_route_string(client->proto)); /* Not worrying about instance for now */ - nnhgs = zebra_nhg_score_proto(client->proto); + if (!client->synchronous) + nnhgs = zebra_nhg_score_proto(client->proto); zlog_notice( "client %d disconnected %lu %s nhgs removed from the rib", client->sock, nnhgs, @@ -628,13 +631,13 @@ static void zserv_client_free(struct zserv *client) /* Free bitmaps. */ for (afi_t afi = AFI_IP; afi < AFI_MAX; afi++) { for (int i = 0; i < ZEBRA_ROUTE_MAX; i++) { - vrf_bitmap_free(client->redist[afi][i]); + vrf_bitmap_free(&client->redist[afi][i]); redist_del_all_instances(&client->mi_redist[afi][i]); } - vrf_bitmap_free(client->redist_default[afi]); - vrf_bitmap_free(client->ridinfo[afi]); - vrf_bitmap_free(client->nhrp_neighinfo[afi]); + vrf_bitmap_free(&client->redist_default[afi]); + vrf_bitmap_free(&client->ridinfo[afi]); + vrf_bitmap_free(&client->nhrp_neighinfo[afi]); } /* @@ -752,10 +755,10 @@ static struct zserv *zserv_client_create(int sock) /* Initialize flags */ for (afi = AFI_IP; afi < AFI_MAX; afi++) { for (i = 0; i < ZEBRA_ROUTE_MAX; i++) - client->redist[afi][i] = vrf_bitmap_init(); - client->redist_default[afi] = vrf_bitmap_init(); - client->ridinfo[afi] = vrf_bitmap_init(); - client->nhrp_neighinfo[afi] = vrf_bitmap_init(); + vrf_bitmap_init(&client->redist[afi][i]); + vrf_bitmap_init(&client->redist_default[afi]); + vrf_bitmap_init(&client->ridinfo[afi]); + vrf_bitmap_init(&client->nhrp_neighinfo[afi]); } /* Add this client to linked list. */ @@ -1058,6 +1061,8 @@ static void zebra_show_client_detail(struct vty *vty, struct zserv *client) 0, client->redist_v4_del_cnt); vty_out(vty, "Redist:v6 %-12u%-12u%-12u\n", client->redist_v6_add_cnt, 0, client->redist_v6_del_cnt); + vty_out(vty, "NHG %-12u%-12u%-12u\n", client->nhg_add_cnt, + client->nhg_upd8_cnt, client->nhg_del_cnt); vty_out(vty, "VRF %-12u%-12u%-12u\n", client->vrfadd_cnt, 0, client->vrfdel_cnt); vty_out(vty, "Connected %-12u%-12u%-12u\n", client->ifadd_cnt, 0, diff --git a/zebra/zserv.h b/zebra/zserv.h index 90aa4d53f4..5e15d1fbc2 100644 --- a/zebra/zserv.h +++ b/zebra/zserv.h @@ -185,6 +185,9 @@ struct zserv { uint32_t local_es_evi_add_cnt; uint32_t local_es_evi_del_cnt; uint32_t error_cnt; + uint32_t nhg_add_cnt; + uint32_t nhg_upd8_cnt; + uint32_t nhg_del_cnt; time_t nh_reg_time; time_t nh_dereg_time; @@ -237,8 +240,7 @@ DECLARE_HOOK(zserv_client_connect, (struct zserv *client), (client)); DECLARE_KOOH(zserv_client_close, (struct zserv *client), (client)); #define DYNAMIC_CLIENT_GR_DISABLED(_client) \ - ((_client->proto <= ZEBRA_ROUTE_CONNECT) \ - || !(_client->gr_instance_count)) + ((_client->proto <= ZEBRA_ROUTE_LOCAL) || !(_client->gr_instance_count)) /* * Initialize Zebra API server.